Example #1
0
int pc_compute_inside_2(void)
{
    int gid;
    double prob;
    EG_NODE_PTR eg_ptr;

    gid = bpx_get_integer(bpx_get_call_arg(1,2));

    initialize_egraph_index();
    alloc_sorted_egraph(1);
    RET_ON_ERR(sort_one_egraph(gid, 0, 1));

    if (verb_graph) {
        print_egraph(0, PRINT_NEUTRAL);
    }

    eg_ptr = expl_graph[gid];

	if (log_scale) {
        RET_ON_ERR(compute_inside_scaling_log_exp());
        prob = eg_ptr->inside;
	}
	else {
        RET_ON_ERR(compute_inside_scaling_none());
        prob = eg_ptr->inside;
	}

    return bpx_unify(bpx_get_call_arg(2,2), bpx_build_float(prob));
}
Example #2
0
int pc_crf_prepare_4(void) {
	TERM  p_fact_list;
	int   size;

	p_fact_list        = bpx_get_call_arg(1,4);
	size               = bpx_get_integer(bpx_get_call_arg(2,4));
	num_goals          = bpx_get_integer(bpx_get_call_arg(3,4));
	failure_root_index = bpx_get_integer(bpx_get_call_arg(4,4));

	failure_observed = (failure_root_index != -1);

	if (failure_root_index != -1) {
		failure_subgoal_id = prism_goal_id_get(failure_atom);
		if (failure_subgoal_id == -1) {
			emit_internal_error("no subgoal ID allocated to `failure'");
			RET_INTERNAL_ERR;
		}
	}

	initialize_egraph_index();
	alloc_sorted_egraph(size);
	RET_ON_ERR(sort_crf_egraphs(p_fact_list));
#ifndef MPI
	if (verb_graph) {
		print_egraph(0, PRINT_NEUTRAL);
	}
#endif /* !(MPI) */

	alloc_occ_switches();
	alloc_num_sw_vals();

	return BP_TRUE;
}
Example #3
0
/*
 * Note: parameters are always refreshed in advance by $pc_export_sw_info/1,
 *       so it causes no problem to overwrite them temporarily
 */
int pc_compute_n_viterbi_rerank_4(void)
{
    TERM p_n_viterbi_list;
    int n,l,goal_id;

    n       = bpx_get_integer(bpx_get_call_arg(1,4));
    l       = bpx_get_integer(bpx_get_call_arg(2,4));
    goal_id = bpx_get_integer(bpx_get_call_arg(3,4));

    initialize_egraph_index();
    alloc_sorted_egraph(1);
    /* INIT_MIN_MAX_NODE_NOS; */
    RET_ON_ERR(sort_one_egraph(goal_id,0,1));
    if (verb_graph) print_egraph(0,PRINT_NEUTRAL);

    alloc_occ_switches();
    transfer_hyperparams_prolog();
	get_param_means();

    compute_n_max(l);

    get_n_most_likely_path_rerank(n,l,goal_id,&p_n_viterbi_list);

    release_occ_switches();

    return bpx_unify(bpx_get_call_arg(4,4),p_n_viterbi_list);
}
Example #4
0
/* [Note] node copying is not required here even in computation without
 * inter-goal sharing, but we need to declare it explicitly.
 */
int pc_compute_viterbi_5(void)
{
    TERM p_goal_path,p_subpath_goal,p_subpath_sw;
    int goal_id;
    double viterbi_prob;

    goal_id = bpx_get_integer(bpx_get_call_arg(1,5));

    initialize_egraph_index();
    alloc_sorted_egraph(1);
    /* INIT_MIN_MAX_NODE_NOS; */
    RET_ON_ERR(sort_one_egraph(goal_id,0,1));
    if (verb_graph) print_egraph(0,PRINT_NEUTRAL);

    compute_max();

    if (debug_level) print_egraph(1,PRINT_VITERBI);

    get_most_likely_path(goal_id,&p_goal_path,&p_subpath_goal,
                         &p_subpath_sw,&viterbi_prob);

    return
        bpx_unify(bpx_get_call_arg(2,5), p_goal_path)    &&
        bpx_unify(bpx_get_call_arg(3,5), p_subpath_goal) &&
        bpx_unify(bpx_get_call_arg(4,5), p_subpath_sw)   &&
        bpx_unify(bpx_get_call_arg(5,5), bpx_build_float(viterbi_prob));
}
Example #5
0
int pc_compute_n_viterbi_3(void)
{
    TERM p_n_viterbi_list;
    int n,goal_id;

    n       = bpx_get_integer(bpx_get_call_arg(1,3));
    goal_id = bpx_get_integer(bpx_get_call_arg(2,3));

    initialize_egraph_index();
    alloc_sorted_egraph(1);
    /* INIT_MIN_MAX_NODE_NOS; */
    RET_ON_ERR(sort_one_egraph(goal_id,0,1));
    if (verb_graph) print_egraph(0,PRINT_NEUTRAL);

    compute_n_max(n);

    if (debug_level) print_egraph(1,PRINT_VITERBI);

    get_n_most_likely_path(n,goal_id,&p_n_viterbi_list);

    return bpx_unify(bpx_get_call_arg(3,3),p_n_viterbi_list);
}
int pc_compute_hindsight_4(void)
{
    TERM p_subgoal,p_hindsight_pairs,t,t1,p_pair;
    int goal_id,is_cond,j;

    goal_id   = bpx_get_integer(bpx_get_call_arg(1,4));
    p_subgoal = bpx_get_call_arg(2,4);
    is_cond   = bpx_get_integer(bpx_get_call_arg(3,4));

    initialize_egraph_index();
    alloc_sorted_egraph(1);
    RET_ON_ERR(sort_one_egraph(goal_id,0,1));
    if (verb_graph) print_egraph(0,PRINT_NEUTRAL);

    alloc_hindsight_goals();

    if (log_scale) {
        RET_ON_ERR(compute_inside_scaling_log_exp());
        RET_ON_ERR(compute_outside_scaling_log_exp());
        RET_ON_ERR(get_hindsight_goals_scaling_log_exp(p_subgoal,is_cond));
    }
    else {
        RET_ON_ERR(compute_inside_scaling_none());
        RET_ON_ERR(compute_outside_scaling_none());
        RET_ON_ERR(get_hindsight_goals_scaling_none(p_subgoal,is_cond));
    }

    if (hindsight_goal_size > 0) {
        /* Build the list of pairs of a subgoal and its hindsight probability */
        p_hindsight_pairs = bpx_build_list();
        t = p_hindsight_pairs;

        for (j = 0; j < hindsight_goal_size; j++) {
            p_pair = bpx_build_list();

            t1 = p_pair;
            bpx_unify(bpx_get_car(t1),
                      bpx_build_integer(hindsight_goals[j]));
            bpx_unify(bpx_get_cdr(t1),bpx_build_list());

            t1 = bpx_get_cdr(t1);
            bpx_unify(bpx_get_car(t1),bpx_build_float(hindsight_probs[j]));
            bpx_unify(bpx_get_cdr(t1),bpx_build_nil());

            bpx_unify(bpx_get_car(t),p_pair);

            if (j == hindsight_goal_size - 1) {
                bpx_unify(bpx_get_cdr(t),bpx_build_nil());
            }
            else {
                bpx_unify(bpx_get_cdr(t),bpx_build_list());
                t = bpx_get_cdr(t);
            }
        }
    }
    else {
        p_hindsight_pairs = bpx_build_nil();
    }

    FREE(hindsight_goals);
    FREE(hindsight_probs);

    return bpx_unify(bpx_get_call_arg(4,4),p_hindsight_pairs);
}