Disable logging, add a "p=0" check on expectation computations

master
Oliver Kennedy 2023-07-13 23:24:05 -04:00
parent cff9918811
commit 3644574ac9
Signed by: okennedy
GPG Key ID: 3E5F9B3ABD3FDB60
3 changed files with 45 additions and 2 deletions

View File

@ -45,6 +45,6 @@ float8 pip_solve_bound(pip_atom *clause, pip_var *var, bool *isupper);
bool pip_solve_cdf_bounds(pip_atom **atoms, int num_atoms, pip_var *var, float8 bounds[2], bool tight);
/** Debugging tools **/
#define DPING() elog(NOTICE, "%s(%s:%d)", __FUNCTION__, __FILE__, __LINE__)
#define DPING() // elog(NOTICE, "%s(%s:%d)", __FUNCTION__, __FILE__, __LINE__)
#endif /* PIP_H */

View File

@ -89,7 +89,7 @@ static bool cdf_sample_var(pip_cset *set, pip_var *var, pip_sampler_state *state
return false;
}
elog(NOTICE, "Solving CDF with bounds: %lf, %lf", (double)bounds[0], (double)bounds[1]);
// elog(NOTICE, "Solving CDF with bounds: %lf, %lf", (double)bounds[0], (double)bounds[1]);
if(bounds[0] >= bounds[1]) return false;

View File

@ -26,6 +26,7 @@ typedef struct pip_prob_comp_info {
static float8 pip_integrate_by_sampling(pip_atom **atoms, int first_atom, int num_atoms, int64 num_samples, pip_atomset *constraints);
static int pip_compute_prob_group(pip_cset *variables, pip_cset_element *group, pip_prob_comp_info *info);
static float8 pip_integrate_by_cdf(pip_atom **atoms, int first_atom, int num_atoms, pip_var *var);
bool pip_clause_might_be_tractable(int clause_cnt, pip_atom **clause);
static float8 pip_integrate_by_cdf(pip_atom **atoms, int first_atom, int num_atoms, pip_var *var)
{
@ -131,6 +132,44 @@ float8 pip_compute_independent_probability(int clause_cnt, pip_atom **clause, in
{
return pip_compute_conditioned_probability(NULL, clause_cnt, clause, samples);
}
bool pip_clause_might_be_tractable(int clause_cnt, pip_atom **clause)
{
int64 i;
for(i = 0; i < clause_cnt; i++)
{
pip_eqn_component *left_eqn = DEREF_CMPNT(clause[i]->data, clause[i]->ptr_left);
pip_eqn_component *right_eqn = DEREF_CMPNT(clause[i]->data, clause[i]->ptr_right);
if(left_eqn->type == PIP_EQN_CONST && right_eqn->type == PIP_EQN_VAR)
{
pip_var *right_var = &right_eqn->val.var;
if(pip_distributions[right_var->vid.group]->cdf != NULL)
{
float8 right_cdf =
pip_distributions[right_var->vid.group]->cdf(right_var, left_eqn->val.c);
// if x.cdf(N) <= 0, then there's no possible way that N>x
if(right_cdf <= 0.0){ return false; }
}
} else
if(right_eqn->type == PIP_EQN_CONST && left_eqn->type == PIP_EQN_VAR)
{
pip_var *left_var = &left_eqn->val.var;
if(pip_distributions[left_var->vid.group]->cdf != NULL)
{
float8 left_cdf =
pip_distributions[left_var->vid.group]->cdf(left_var, right_eqn->val.c);
// if x.cdf(N) >= 1, then there's no possible way that x>N
if(left_cdf >= 1.0){ return false; }
}
}
}
return true;
}
float8 pip_compute_expectation(pip_eqn *eqn, int clause_cnt, pip_atom **clause, int64 samples)
{
float8 val = 0.0;
@ -140,6 +179,10 @@ float8 pip_compute_expectation(pip_eqn *eqn, int clause_cnt, pip_atom **clause,
//don't go through the overhead of sampling if we can avoid it.
if(clause_cnt <= 0) return pip_compute_expectation_conditionless(eqn, samples);
//don't go through the overhead of sampling if we can prove that a clause
//has zero probability mass
if(!pip_clause_might_be_tractable(clause_cnt, clause)) { return 0.0; }
set = pip_sample_by_clause(clause_cnt, clause, samples, &probability);
for(i = 0; i < samples; i++){