std::string BaseQuality::average_base_qualities(std::vector<const std::string*> qualities){ assert(qualities.size() > 0); // Check that all base quality strings are of the same length for (unsigned int i = 0; i < qualities.size(); i++){ if (qualities[i]->size() != qualities[0]->size()) printErrorAndDie("All base quality strings must be of the same length when averaging probabilities"); } // Average raw error probabilities for each base and convert // to the closest quality score std::string avg_qualities('N', qualities[0]->size()); std::vector<double> log_probs(qualities.size()); for (unsigned int i = 0; i < qualities[0]->size(); i++){ for (unsigned int j = 0; j < qualities.size(); j++) log_probs[j] = log_prob_error(qualities[j]->at(i)); double log_mean_prob = log_sum_exp(log_probs) - log(qualities.size()); avg_qualities[i] = closest_char(log_mean_prob); } return avg_qualities; }
void rl_act_perm::act_sample( void ) { // printf( "perm sample %d dim\n", dim ); log_probs = params; grad = 1; for ( int i=0; i<dim; i++ ) { ll_to_prob( log_probs, probs ); // probs.Print(); int a = sample( probs, &rng_state ); vals[i] = a; // computation of grad = grad + -1*probs Add( -1, probs, grad ); log_probs(a) = MFMIN; } // printf( "Gradient: " ); grad.Print(); }