Search in sources :

Example 11 with WamProgram

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

the class PathDprProverTest method test.

@Test
public void test() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    apr.epsilon = 1e-5;
    apr.alpha = 0.01;
    WamProgram program = WamBaseProgram.load(new File(RULES));
    WamPlugin[] plugins = new WamPlugin[] { SparseGraphPlugin.load(apr, new File(SparseGraphPluginTest.PLUGIN)) };
    PathDprProver p = new PathDprProver(apr);
    Query query = Query.parse("kids(bette,Y)");
    StateProofGraph pg = new StateProofGraph(query, apr, program, plugins);
    p.prove(pg, new StatusLogger());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) Query(edu.cmu.ml.proppr.prove.wam.Query) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test) GrounderTest(edu.cmu.ml.proppr.GrounderTest) SparseGraphPluginTest(edu.cmu.ml.proppr.prove.wam.plugins.SparseGraphPluginTest)

Example 12 with WamProgram

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

the class SimpleProgramProofGraphTest method test.

@Test
public void test() throws LogicProgramException, IOException {
    WamProgram program = WamBaseProgram.load(new File(SimpleProgramProverTest.PROGRAM));
    Query q = new Query(new Goal("coworker", new ConstantArgument("steve"), new ConstantArgument("X")));
    StateProofGraph pg = new StateProofGraph(q, new APROptions(), program);
    HashMap<String, Integer> solutions = new HashMap<String, Integer>();
    solutions.put("steve", 0);
    solutions.put("sven", 0);
    Map<State, Double> vec = new HashMap<State, Double>();
    vec.put(pg.getStartState(), 1.0);
    // step 1: coworker -> employee,boss
    System.out.println("Step 1");
    for (State s : vec.keySet()) System.out.println(s);
    List<Outlink> outlinks = pg.pgOutlinks(pg.getStartState(), false);
    assertEquals("1. coworker :- employee,boss", 2, outlinks.size());
    vec = nextVec(vec, normalized(outlinks));
    vec.remove(pg.getStartState());
    assertEquals("1. statecount", 1, vec.size());
    // step 2: 
    System.out.println("Step 2");
    for (State s : vec.keySet()) System.out.println(s);
    outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
    assertEquals("2. employee :- management,boss", 2, outlinks.size());
    vec = nextVec(vec, normalized(outlinks));
    vec.remove(pg.getStartState());
    assertEquals("2. statecount", 1, vec.size());
    // step 3: 
    System.out.println("Step 3");
    for (State s : vec.keySet()) System.out.println(s);
    outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
    assertEquals("3. management :- sookie", 2, outlinks.size());
    vec = nextVec(vec, normalized(outlinks));
    vec.remove(pg.getStartState());
    assertEquals("3. statecount", 1, vec.size());
    // step 4: 
    System.out.println("Step 4");
    for (State s : vec.keySet()) System.out.println(s);
    outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
    assertEquals("4. boss(sookie,X) :- _steve_ + sven", 2, outlinks.size());
    vec = nextVec(vec, normalized(outlinks));
    vec.remove(pg.getStartState());
    assertEquals("4. statecount", 1, vec.size());
    // step 5: 
    System.out.println("Step 5");
    for (State s : vec.keySet()) {
        System.out.println(s);
        System.out.println(Dictionary.buildString(pg.asDict(s), new StringBuilder(), "\n\t").substring(1));
    }
    outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
    assertEquals("5. boss(sookie,X) :- steve + sven", 3, outlinks.size());
    vec = nextVec(vec, normalized(outlinks));
    vec.remove(pg.getStartState());
    assertEquals("5. statecount", 2, vec.size());
    // step 6: 
    System.out.println("Step 6");
    for (State s : vec.keySet()) {
        System.out.println(s);
        Map<Argument, String> dict = pg.asDict(s);
        System.out.println(Dictionary.buildString(dict, new StringBuilder(), "\n\t").substring(1));
        assertTrue(s.isCompleted());
        for (String v : dict.values()) {
            if (solutions.containsKey(v))
                solutions.put(v, solutions.get(v) + 1);
        }
    }
    for (Map.Entry<String, Integer> e : solutions.entrySet()) assertEquals(e.getKey(), 1, e.getValue().intValue());
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink) Query(edu.cmu.ml.proppr.prove.wam.Query) Argument(edu.cmu.ml.proppr.prove.wam.Argument) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) HashMap(java.util.HashMap) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) Goal(edu.cmu.ml.proppr.prove.wam.Goal) State(edu.cmu.ml.proppr.prove.wam.State) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with WamProgram

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

the class GrounderTest method doGroundExampleTest.

public void doGroundExampleTest(String msg, Prover p, int nodes, int edges, double value, String npos, String nneg, double alpha) throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    WamProgram program = WamBaseProgram.load(new File(RULES));
    WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, new File(FACTS), false) };
    Grounder grounder = new Grounder(apr, p, program, plugins);
    Query query = Query.parse("predict(howard,Y)");
    GroundedExample ex = grounder.groundExample(p, new InferenceExample(query, new Query[] { Query.parse("predict(howard,bird)") }, new Query[] { Query.parse("predict(howard,mammal)") }));
    makeAssertions(ex, msg, nodes, edges, value, 1, npos, 1, nneg);
// predict(howard,Y)	+predict(howard,bird)	-predict(howard,mammal)
}
Also used : WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) Query(edu.cmu.ml.proppr.prove.wam.Query) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample)

Example 14 with WamProgram

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

the class GrounderTest method noNegativeExamplesTest.

@Test
public void noNegativeExamplesTest() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    WamProgram program = WamBaseProgram.load(new File(RULES));
    WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, new File(FACTS), false) };
    Prover p = new DprProver(apr);
    Grounder grounder = new Grounder(apr, p, program, plugins);
    InferenceExample ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
    GroundedExample ex = grounder.groundExample(p, ix);
    makeAssertions(ex, "dpr+", 10, 23, 1.0, 1, "7", 0, "");
    ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
    ProofGraph pg = p.makeProofGraph(ix, apr, program, plugins);
    State pos = null;
    Map<State, Double> sols = p.prove(pg, new StatusLogger());
    System.out.println(pg.serialize(ex));
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) Query(edu.cmu.ml.proppr.prove.wam.Query) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) ProofGraph(edu.cmu.ml.proppr.prove.wam.ProofGraph) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) PprProver(edu.cmu.ml.proppr.prove.PprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) Prover(edu.cmu.ml.proppr.prove.Prover) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) State(edu.cmu.ml.proppr.prove.wam.State) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test)

Example 15 with WamProgram

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

the class GrounderTest method unboundLabelsTest.

@Test(expected = IllegalArgumentException.class)
public void unboundLabelsTest() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    WamProgram program = WamBaseProgram.load(new File(RULES));
    WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, new File(FACTS), false) };
    Prover p = new DprProver(apr);
    Grounder grounder = new Grounder(apr, p, program, plugins);
    InferenceExample ix = new InferenceExample(Query.parse("predict(howard,Bird)"), new Query[] { Query.parse("predict(howard,Bird)") }, new Query[] {});
    GroundedExample ex = grounder.groundExample(p, ix);
}
Also used : WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) PprProver(edu.cmu.ml.proppr.prove.PprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) Prover(edu.cmu.ml.proppr.prove.Prover) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) Test(org.junit.Test)

Aggregations

WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)21 Query (edu.cmu.ml.proppr.prove.wam.Query)18 Test (org.junit.Test)17 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)16 Prover (edu.cmu.ml.proppr.prove.Prover)15 APROptions (edu.cmu.ml.proppr.util.APROptions)15 File (java.io.File)14 DprProver (edu.cmu.ml.proppr.prove.DprProver)11 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)11 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)9 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)9 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)9 Feature (edu.cmu.ml.proppr.prove.wam.Feature)7 State (edu.cmu.ml.proppr.prove.wam.State)6 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)6 Grounder (edu.cmu.ml.proppr.Grounder)5 ConstantArgument (edu.cmu.ml.proppr.prove.wam.ConstantArgument)5 Goal (edu.cmu.ml.proppr.prove.wam.Goal)5 Map (java.util.Map)4 DfsProver (edu.cmu.ml.proppr.prove.DfsProver)3