void calc_model(mcmc * m, const gsl_vector * old_values) { unsigned int i; unsigned int j; unsigned int n_par = get_n_par(m); double eta_i; double p_i; double l_i; double prior = 0; double prob = 0; (void) old_values; for (j = 1; j < m->data->size2; j++) { prior += -pow(get_params_for(m, j) / SIGMA, 2) / 2; } set_prior(m, prior); assert(n_par == m->data->size2 - 1 + 1); /* eta = [1,x] . params (matrix product) */ for (i = 0; i < m->data->size1; i++) { eta_i = get_params_for(m, 0); for (j = 1; j < n_par; j++) { eta_i += gsl_matrix_get(m->data, i, j) * get_params_for(m, j); } if (eta_i > 0) p_i = 1 / (1 + exp(-eta_i)); else p_i = exp(eta_i) / (1 + exp(eta_i)); if (gsl_matrix_get(m->data, i, 0) == 0) l_i = log(1 - p_i); else l_i = log(p_i); prob += l_i; } set_prob(m, prior + get_beta(m) * prob); }
Naive::Naive(int max_quality, int over, int max_steps, double prior_of_B) { max_qual = max_quality; over -= 1; num_steps = max_steps; prior = new double[num_steps]; // denotes the belief that the two reads are coming from the same location double step = 1.0 / num_steps; for(int i=0; i<num_steps; i++) prior[i] = step * i; p_correct = new double[max_qual]; p_error = new double[max_qual]; log_correct = new double[max_qual]; log_error = new double[max_qual]; log_same = new double*[max_qual]; log_diff = new double*[max_qual]; prior_same = new double*[max_qual]; prior_diff = new double*[max_qual]; not_prior = new double*[max_qual]; for(int i=0; i<max_qual; i++) { int s = (i<1) ? 1 : i; // if quality score is 0, pretend it is 1 p_correct[i] = (1 - pow(0.1, s/10.0)); p_error[i] = pow(0.1, s/10.0)/over; log_correct[i] = 0 - log10( 1 - pow(0.1, s/10.0) ); log_error[i] = 0 - log10( pow(0.1, s/10.0)/over ); log_same[i] = new double[num_steps]; log_diff[i] = new double[num_steps]; prior_same[i] = new double[max_qual]; prior_diff[i] = new double[max_qual]; not_prior[i] = new double[max_qual]; for(int j=0; j<num_steps; j++) { log_same[i][j] = log_correct[i]; log_diff[i][j] = 0 - log10( p_error[i] * prior[j] + p_correct[i] * (1 - prior[j]) ); } } for(int i=0; i<max_qual; i++) { for(int k=0; k<max_qual; k++) { prior_same[i][k] = log10( p_correct[i]*p_correct[k] + over*p_error[i]*p_error[k] ); prior_diff[i][k] = log10( p_correct[i]*p_error[k] + p_error[i]*p_correct[k] + (over-1)*p_error[i]*p_error[k] ); not_prior[i][k] = 0 - log_correct[i] - log_correct[k]; } } set_prior(prior_of_B); }