Search in sources :

Example 1 with FeatureDictWeighter

use of edu.cmu.ml.proppr.prove.FeatureDictWeighter in project ProPPR by TeamCohen.

the class ProverTestTemplate method testProveState.

@Test
public void testProveState() throws LogicProgramException {
    log.info("testProveState");
    FeatureDictWeighter w = new InnerProductWeighter();
    SymbolTable<Feature> featureTab = new SimpleSymbolTable<Feature>();
    int milk = featureTab.getId(new Feature("milk"));
    w.put(featureTab.getSymbol(milk), 2);
    prover.setWeighter(w);
    ProofGraph pg = prover.makeProofGraph(new InferenceExample(Query.parse("isa(elsie,X)"), null, null), apr, featureTab, lpMilk, fMilk);
    //("isa","elsie","X"));
    Map<State, Double> dist = prover.prove(pg, new StatusLogger());
    double query = 0.0;
    double platypus = 0.0;
    double others = 0.0;
    double all = 0.0;
    for (Map.Entry<State, Double> s : dist.entrySet()) {
        Query q = pg.fill(s.getKey());
        String arg2 = q.getRhs()[0].getArg(1).getName();
        if ("platypus".equals(arg2)) {
            platypus = Math.max(platypus, s.getValue());
        } else if ("X1".equals(arg2)) {
            query = Math.max(query, s.getValue());
        } else {
            others = Math.max(others, s.getValue());
        }
        System.out.println(q + "\t" + s.getValue());
        all += s.getValue();
    }
    System.out.println();
    System.out.println("query    weight: " + query);
    System.out.println("platypus weight: " + platypus);
    System.out.println("others   weight: " + others);
    //		assertTrue("query should retain most weight",query > Math.max(platypus,others));
    assertTrue("milk-featured paths should score higher than others", platypus > others);
    assertEquals("Total weight of all states should be around 1.0", 1.0, all, 10 * this.apr.epsilon);
    assertEquals("Known features", 1, prover.weighter.numKnownFeatures);
    assertEquals("Unknown features", 5, prover.weighter.numUnknownFeatures);
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Query(edu.cmu.ml.proppr.prove.wam.Query) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) ProofGraph(edu.cmu.ml.proppr.prove.wam.ProofGraph) Feature(edu.cmu.ml.proppr.prove.wam.Feature) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) FeatureDictWeighter(edu.cmu.ml.proppr.prove.FeatureDictWeighter) SimpleSymbolTable(edu.cmu.ml.proppr.util.SimpleSymbolTable) State(edu.cmu.ml.proppr.prove.wam.State) Map(java.util.Map) InnerProductWeighter(edu.cmu.ml.proppr.prove.InnerProductWeighter) Test(org.junit.Test)

Aggregations

InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)1 FeatureDictWeighter (edu.cmu.ml.proppr.prove.FeatureDictWeighter)1 InnerProductWeighter (edu.cmu.ml.proppr.prove.InnerProductWeighter)1 Feature (edu.cmu.ml.proppr.prove.wam.Feature)1 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)1 Query (edu.cmu.ml.proppr.prove.wam.Query)1 State (edu.cmu.ml.proppr.prove.wam.State)1 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)1 SimpleSymbolTable (edu.cmu.ml.proppr.util.SimpleSymbolTable)1 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)1 Map (java.util.Map)1 Test (org.junit.Test)1