Skip to content

Instantly share code, notes, and snippets.

@madaan
Last active August 29, 2015 14:22
Show Gist options
  • Save madaan/b7d8f0336ca9fe3925d2 to your computer and use it in GitHub Desktop.
Save madaan/b7d8f0336ca9fe3925d2 to your computer and use it in GitHub Desktop.
Relevant snippet from full inference to show the agreeing k.
/*
* Now start the agreeing k
*/
//Different deltas for different relations
double delta = GoldDbInference.marginMap.get(lrg.relation);
int leastFlips = Integer.MAX_VALUE;
double bestCentralValue = -1;
/**
* Find the optimal central value
*/
for (int n_i = 0; n_i < numN; n_i++) {
if(p.n_states[n_i]) { //potential central value?
int flipsCaused = 0;
double centralValue = lrg.n[n_i].value;
for (int n_c = 0; n_c < numN; n_c++) {
if(p.n_states[n_c] && !(MathUtils.within(lrg.n[n_c].value, centralValue, delta))) { //check if this guy must be turned off
flipsCaused++;
}
}
if(flipsCaused < leastFlips) {
leastFlips = flipsCaused;
bestCentralValue = centralValue;
}
}
}
assert(bestCentralValue != -1);
//complete by actually flipping the n nodes that do not agree
for (int n_i = 0; n_i < numN; n_i++) {
if(p.n_states[n_i] && !(MathUtils.within(lrg.n[n_i].value, bestCentralValue, delta))) { //check if this guy must be turned off
p.n_states[n_i] = false;
}
}
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment