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); }
void get_bounds(idxint node_idx, ecos_bb_pwork* prob){ idxint i, ret_code, branchable, viable_rounded_sol; viable_rounded_sol = 0; set_prob( prob, get_bool_node_id(node_idx,prob), get_int_node_id(node_idx, prob) ); ret_code = ECOS_solve(prob->ecos_prob); #if MI_PRINTLEVEL > 1 if (prob->stgs->verbose){ print_ecos_solution(prob); } if (ret_code != ECOS_OPTIMAL && ret_code != ECOS_PINF && ret_code != ECOS_DINF){ PRINTTEXT("1Exit code: %u\n", ret_code); } #endif if (ret_code >= 0 || ret_code == ECOS_MAXIT || ret_code == ECOS_NUMERICS ) { prob->nodes[node_idx].L = eddot(prob->ecos_prob->n, prob->ecos_prob->x, prob->ecos_prob->c); /* Figure out if x is already an integer solution if the solution had no numerical errors*/ branchable = 1; for (i=0; i<prob->num_bool_vars; ++i){ prob->tmp_bool_node_id[i] = (char) pfloat_round( prob->ecos_prob->x[prob->bool_vars_idx[i]] ); branchable &= float_eqls( prob->ecos_prob->x[i] , (pfloat) prob->tmp_bool_node_id[i], prob->stgs->integer_tol ); } for (i=0; i<prob->num_int_vars; ++i){ prob->tmp_int_node_id[2 * i + 1] = pfloat_round(prob->ecos_prob->x[prob->int_vars_idx[i]] ); prob->tmp_int_node_id[2*i] = -(prob->tmp_int_node_id[2*i + 1]); branchable &= float_eqls( prob->ecos_prob->x[i] , prob->tmp_int_node_id[2*i + 1], prob->stgs->integer_tol ); } branchable = !branchable; #if MI_PRINTLEVEL > 1 if (prob->stgs->verbose){ PRINTTEXT("Is branchable: %u\n",branchable); } #endif if (branchable){ /* pfloat_round and check feasibility*/ get_branch_var(prob, &(prob->nodes[node_idx].split_idx), &(prob->nodes[node_idx].split_val) ); prob->nodes[node_idx].status = MI_SOLVED_BRANCHABLE; #if MI_PRINTLEVEL > 1 if (prob->stgs->verbose){ print_node(prob,-1); PRINTTEXT("Rounded Solution:\n"); } #endif set_prob(prob, prob->tmp_bool_node_id, prob->tmp_int_node_id); ret_code = ECOS_solve(prob->ecos_prob); #if MI_PRINTLEVEL > 1 if (prob->stgs->verbose){ print_ecos_solution(prob); } if (ret_code != ECOS_OPTIMAL && ret_code != ECOS_PINF && ret_code != ECOS_DINF){ PRINTTEXT("2Exit code: %u\n", ret_code); } #endif if (ret_code == ECOS_OPTIMAL){ /* Use the node's U as tmp storage */ prob->nodes[node_idx].U = eddot(prob->ecos_prob->n, prob->ecos_prob->x, prob->ecos_prob->c); viable_rounded_sol = 1; } }else{ /* This is already an integer solution*/ prob->nodes[node_idx].status = MI_SOLVED_NON_BRANCHABLE; prob->nodes[node_idx].U = eddot(prob->ecos_prob->n, prob->ecos_prob->x, prob->ecos_prob->c); } if (prob->nodes[node_idx].U < prob->global_U){ #if MI_PRINTLEVEL > 1 if (prob->stgs->verbose){ PRINTTEXT("New optimal solution, U: %.2f\n", prob->nodes[node_idx].U); print_ecos_xequil(prob); print_ecos_c(prob); print_ecos_solution(prob); } #endif store_solution(prob); prob->global_U = prob->nodes[node_idx].U; } if (viable_rounded_sol){ /* Reset the node's U back to INF because it was not originally feasible */ prob->nodes[node_idx].U = INFINITY; } }else { /*Assume node infeasible*/ prob->nodes[node_idx].L = INFINITY; prob->nodes[node_idx].U = INFINITY; prob->nodes[node_idx].status = MI_SOLVED_NON_BRANCHABLE; } }
void BM::mle(){ double p = suf()->sum()/(n_*suf()->nobs()); set_prob(p); }