Factor maxPot = inf.lookupMarginal(var); Factor trueMaxPot = joint.extractMax(var); if (maxPot.argmax() != trueMaxPot.argmax()) { logger.warning("Argmax not equal on model " + mdlIdx + " inferencer " + inf + " !\n Factors:\nReturned: " + maxPot + System.err.println("Dump of model " + mdlIdx + " ***"); mdl.dump (); assertTrue (maxPot.argmax() == trueMaxPot.argmax());
Factor maxPot = inf.lookupMarginal(var); Factor trueMaxPot = joint.extractMax(var); if (maxPot.argmax() != trueMaxPot.argmax()) { logger.warning("Argmax not equal on model " + mdlIdx + " inferencer " + inf + " !\n Factors:\nReturned: " + maxPot + System.err.println("Dump of model " + mdlIdx + " ***"); mdl.dump (); assertTrue (maxPot.argmax() == trueMaxPot.argmax());
/** * Returns the highest-score Assignment in a model according to a given inferencer. * @param mdl Factor graph to use * @param inf Inferencer to use. No need to call <tt>computeMarginals</tt> first. * @return An Assignment */ public static Assignment bestAssignment (FactorGraph mdl, Inferencer inf) { inf.computeMarginals (mdl); int[] outcomes = new int [mdl.numVariables ()]; for (int i = 0; i < outcomes.length; i++) { Variable var = mdl.get (i); int best = inf.lookupMarginal (var).argmax (); outcomes[i] = best; } return new Assignment (mdl, outcomes); }
/** * Returns the highest-score Assignment in a model according to a given inferencer. * @param mdl Factor graph to use * @param inf Inferencer to use. No need to call <tt>computeMarginals</tt> first. * @return An Assignment */ public static Assignment bestAssignment (FactorGraph mdl, Inferencer inf) { inf.computeMarginals (mdl); int[] outcomes = new int [mdl.numVariables ()]; for (int i = 0; i < outcomes.length; i++) { Variable var = mdl.get (i); int best = inf.lookupMarginal (var).argmax (); outcomes[i] = best; } return new Assignment (mdl, outcomes); }
/** * Returns the highest-score Assignment in a model according to a given inferencer. * @param mdl Factor graph to use * @param inf Inferencer to use. No need to call <tt>computeMarginals</tt> first. * @return An Assignment */ public static Assignment bestAssignment (FactorGraph mdl, Inferencer inf) { inf.computeMarginals (mdl); int[] outcomes = new int [mdl.numVariables ()]; for (int i = 0; i < outcomes.length; i++) { Variable var = mdl.get (i); int best = inf.lookupMarginal (var).argmax (); outcomes[i] = best; } return new Assignment (mdl, outcomes); }
/** * Returns ths value of -log Z in mdl according to the given inferencer. * If inf is exact, the answer will be exact; otherwise the answer will be * approximation * * @param mdl * @param inf An inferencer. <tt>inf.computeMarginals (mdl)</tt> must already have * been called. * @return The value of -logZ */ public static double lookupMinusLogZ (FactorGraph mdl, Inferencer inf) { // heuristically try to find a reasonable assignment (not numerically 0 prob) int [] vals = new int[mdl.numVariables()]; for (int vi = 0; vi < vals.length; vi++) { Variable var = mdl.getVariable (vi); Factor mrg = inf.lookupMarginal (var); vals[vi] = mrg.argmax(); } Assignment assn = new Assignment (mdl, vals); double prob = inf.lookupLogJoint (assn); double energy = mdl.logValue (assn); return prob - energy; }
/** * Returns ths value of -log Z in mdl according to the given inferencer. * If inf is exact, the answer will be exact; otherwise the answer will be * approximation * * @param mdl * @param inf An inferencer. <tt>inf.computeMarginals (mdl)</tt> must already have * been called. * @return The value of -logZ */ public static double lookupMinusLogZ (FactorGraph mdl, Inferencer inf) { // heuristically try to find a reasonable assignment (not numerically 0 prob) int [] vals = new int[mdl.numVariables()]; for (int vi = 0; vi < vals.length; vi++) { Variable var = mdl.getVariable (vi); Factor mrg = inf.lookupMarginal (var); vals[vi] = mrg.argmax(); } Assignment assn = new Assignment (mdl, vals); double prob = inf.lookupLogJoint (assn); double energy = mdl.logValue (assn); return prob - energy; }
/** * Returns ths value of -log Z in mdl according to the given inferencer. * If inf is exact, the answer will be exact; otherwise the answer will be * approximation * * @param mdl * @param inf An inferencer. <tt>inf.computeMarginals (mdl)</tt> must already have * been called. * @return The value of -logZ */ public static double lookupMinusLogZ (FactorGraph mdl, Inferencer inf) { // heuristically try to find a reasonable assignment (not numerically 0 prob) int [] vals = new int[mdl.numVariables()]; for (int vi = 0; vi < vals.length; vi++) { Variable var = mdl.getVariable (vi); Factor mrg = inf.lookupMarginal (var); vals[vi] = mrg.argmax(); } Assignment assn = new Assignment (mdl, vals); double prob = inf.lookupLogJoint (assn); double energy = mdl.logValue (assn); return prob - energy; }