public static List createTestModels() { Random r = new Random(42); // These models are all small so that we can run the brute force // inferencer on them. FactorGraph[] mdls = new FactorGraph[]{ createTriangle(), createChainGraph(), createRandomGraph(3, 2, r), createRandomGraph(3, 3, r), createRandomGraph(6, 3, r), createRandomGraph(8, 2, r), createRandomGrid(3, 2, 4, r), createRandomGrid(4, 3, 2, r), }; return new ArrayList(Arrays.asList(mdls)); }
public static List createTestModels() { Random r = new Random(42); // These models are all small so that we can run the brute force // inferencer on them. FactorGraph[] mdls = new FactorGraph[]{ createTriangle(), createChainGraph(), createRandomGraph(3, 2, r), createRandomGraph(3, 3, r), createRandomGraph(6, 3, r), createRandomGraph(8, 2, r), createRandomGrid(3, 2, 4, r), createRandomGrid(4, 3, 2, r), }; return new ArrayList(Arrays.asList(mdls)); }
public void testTrpJoint() { FactorGraph model = createTriangle(); TRP trp = new TRP().setTerminator (new TRP.IterationTerminator(25)); trp.computeMarginals(model); // For each assignment to the model, check that // TRP.lookupLogJoint and TRP.lookupJoint are consistent VarSet all = new HashVarSet (model.variablesSet ()); for (Iterator it = all.assignmentIterator(); it.hasNext();) { Assignment assn = (Assignment) it.next(); double log = trp.lookupLogJoint(assn); double prob = trp.lookupJoint(assn); assertTrue(Maths.almostEquals(Math.exp(log), prob)); } logger.info("Test trpJoint passed."); }
public void testTrpJoint() { FactorGraph model = createTriangle(); TRP trp = new TRP().setTerminator (new TRP.IterationTerminator(25)); trp.computeMarginals(model); // For each assignment to the model, check that // TRP.lookupLogJoint and TRP.lookupJoint are consistent VarSet all = new HashVarSet (model.variablesSet ()); for (Iterator it = all.assignmentIterator(); it.hasNext();) { Assignment assn = (Assignment) it.next(); double log = trp.lookupLogJoint(assn); double prob = trp.lookupJoint(assn); assertTrue(Maths.almostEquals(Math.exp(log), prob)); } logger.info("Test trpJoint passed."); }
/** Tests that running TRP doesn't inadvertantly change potentials in the original graph. */ public void testTrpNonDestructivity() { FactorGraph model = createTriangle(); TRP trp = new TRP(new TRP.IterationTerminator(25)); BruteForceInferencer brute = new BruteForceInferencer(); Factor joint1 = brute.joint(model); trp.computeMarginals(model); Factor joint2 = brute.joint(model); assertTrue(joint1.almostEquals(joint2)); logger.info("Test trpNonDestructivity passed."); }
/** Tests that running TRP doesn't inadvertantly change potentials in the original graph. */ public void testTrpNonDestructivity() { FactorGraph model = createTriangle(); TRP trp = new TRP(new TRP.IterationTerminator(25)); BruteForceInferencer brute = new BruteForceInferencer(); Factor joint1 = brute.joint(model); trp.computeMarginals(model); Factor joint2 = brute.joint(model); assertTrue(joint1.almostEquals(joint2)); logger.info("Test trpNonDestructivity passed."); }
public void testTrpTreeList () { FactorGraph model = createTriangle(); model.getVariable (0).setLabel ("V0"); model.getVariable (1).setLabel ("V1"); model.getVariable (2).setLabel ("V2"); List readers = new ArrayList (); for (int i = 0; i < treeStrs.length; i++) { readers.add (new StringReader (treeStrs[i])); } TRP trp = new TRP().setTerminator (new TRP.DefaultConvergenceTerminator()) .setFactory (TRP.TreeListFactory.makeFromReaders (model, readers)); trp.computeMarginals(model); Inferencer jt = new BruteForceInferencer (); jt.computeMarginals (model); compareMarginals ("", model, trp, jt); }
public void testTrp() final UndirectedModel model = createTriangle(); TRP trp = new TRP().setTerminator (new TRP.IterationTerminator(200));
public void testTrp() final UndirectedModel model = createTriangle(); TRP trp = new TRP().setTerminator (new TRP.IterationTerminator(200));
public void testTrpTreeList () { FactorGraph model = createTriangle(); model.getVariable (0).setLabel ("V0"); model.getVariable (1).setLabel ("V1"); model.getVariable (2).setLabel ("V2"); List readers = new ArrayList (); for (int i = 0; i < treeStrs.length; i++) { readers.add (new StringReader (treeStrs[i])); } TRP trp = new TRP().setTerminator (new TRP.DefaultConvergenceTerminator()) .setFactory (TRP.TreeListFactory.makeFromReaders (model, readers)); trp.computeMarginals(model); Inferencer jt = new BruteForceInferencer (); jt.computeMarginals (model); compareMarginals ("", model, trp, jt); }