Search in sources :

Example 6 with DprProver

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

the class NodeMergingTest method doTest.

private void doTest(File rules, File facts, String squery, String[] spos, String[] sneg, int nodeSize, int posSize) throws LogicProgramException, IOException {
    APROptions apr = new APROptions();
    Prover p = new DprProver(apr);
    WamProgram program = WamBaseProgram.load(rules);
    WamPlugin[] plugins = null;
    if (facts.getName().endsWith(FactsPlugin.FILE_EXTENSION))
        plugins = new WamPlugin[] { FactsPlugin.load(apr, facts, false) };
    else if (facts.getName().endsWith(GraphlikePlugin.FILE_EXTENSION))
        plugins = new WamPlugin[] { LightweightGraphPlugin.load(apr, facts, -1) };
    Grounder grounder = new Grounder(apr, p, program, plugins);
    Query query = Query.parse(squery);
    Query[] pos = new Query[spos.length];
    for (int i = 0; i < spos.length; i++) pos[i] = Query.parse(spos[i]);
    Query[] neg = new Query[sneg.length];
    for (int i = 0; i < sneg.length; i++) neg[i] = Query.parse(sneg[i]);
    ProofGraph pg = new StateProofGraph(new InferenceExample(query, pos, neg), apr, new SimpleSymbolTable<Feature>(), program, plugins);
    GroundedExample ex = grounder.groundExample(pg);
    System.out.println(grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n"));
    if (nodeSize >= 0)
        assertEquals("improper node duplication", nodeSize, ex.getGraph().nodeSize());
    if (posSize >= 0)
        assertEquals("improper # solutions found", posSize, ex.getPosList().size());
}
Also used : 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) DprProver(edu.cmu.ml.proppr.prove.DprProver) Prover(edu.cmu.ml.proppr.prove.Prover) DprProver(edu.cmu.ml.proppr.prove.DprProver) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) Feature(edu.cmu.ml.proppr.prove.wam.Feature) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) APROptions(edu.cmu.ml.proppr.util.APROptions)

Example 7 with DprProver

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

the class GrounderTest method testGroundExample.

@Test
public void testGroundExample() throws IOException, LogicProgramException {
    doGroundExampleTest("dpr: ", new DprProver(), //nodes
    10, //edges
    23, //value
    1.0, //pos
    "7", //neg
    "8", APROptions.MINALPH_DEFAULT);
    doGroundExampleTest("ppr: ", new PprProver(), //nodes
    10, //edges
    23, //value
    1.0, //pos
    "9", //neg
    "10", APROptions.MINALPH_DEFAULT);
    doGroundExampleTest("dpr: ", new IdDprProver(), //nodes
    10, //edges
    23, //value
    1.0, //pos
    "7", //neg
    "8", APROptions.MINALPH_DEFAULT);
    doGroundExampleTest("ppr: ", new IdPprProver(), //nodes
    10, //edges
    23, //value
    1.0, //pos
    "9", //neg
    "10", APROptions.MINALPH_DEFAULT);
}
Also used : PprProver(edu.cmu.ml.proppr.prove.PprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) Test(org.junit.Test)

Example 8 with DprProver

use of edu.cmu.ml.proppr.prove.DprProver 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 9 with DprProver

use of edu.cmu.ml.proppr.prove.DprProver 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)

Example 10 with DprProver

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

the class DprProverTest method setup.

@Override
public void setup() throws IOException {
    super.setup();
    this.prover = new DprProver(new APROptions(new String[] { "eps=.00001", "alph=.03" }));
//		Logger.getLogger(DprProver.class).setLevel(Level.DEBUG);
}
Also used : DprProver(edu.cmu.ml.proppr.prove.DprProver) APROptions(edu.cmu.ml.proppr.util.APROptions)

Aggregations

DprProver (edu.cmu.ml.proppr.prove.DprProver)14 Prover (edu.cmu.ml.proppr.prove.Prover)11 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)11 APROptions (edu.cmu.ml.proppr.util.APROptions)11 Query (edu.cmu.ml.proppr.prove.wam.Query)10 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)10 Test (org.junit.Test)10 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)8 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)8 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)8 Grounder (edu.cmu.ml.proppr.Grounder)6 Feature (edu.cmu.ml.proppr.prove.wam.Feature)6 File (java.io.File)5 IdDprProver (edu.cmu.ml.proppr.prove.IdDprProver)4 IdPprProver (edu.cmu.ml.proppr.prove.IdPprProver)4 PprProver (edu.cmu.ml.proppr.prove.PprProver)4 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)4 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)3 TracingDfsProver (edu.cmu.ml.proppr.prove.TracingDfsProver)2 CachingTrainer (edu.cmu.ml.proppr.CachingTrainer)1