Search in sources :

Example 21 with StatusLogger

use of edu.cmu.ml.proppr.util.StatusLogger in project ProPPR by TeamCohen.

the class CachingTrainer method train.

@Override
public ParamVector<String, ?> train(SymbolTable<String> masterFeatures, Iterable<String> exampleFile, LearningGraphBuilder builder, ParamVector<String, ?> initialParamVec, int numEpochs) {
    ArrayList<PosNegRWExample> examples = new ArrayList<PosNegRWExample>();
    RWExampleParser parser = new RWExampleParser();
    if (masterFeatures.size() > 0)
        LearningGraphBuilder.setFeatures(masterFeatures);
    int id = 0;
    StatusLogger stattime = new StatusLogger();
    TrainingStatistics total = new TrainingStatistics();
    boolean logged = false;
    for (String s : exampleFile) {
        total.updateReadingStatistics(stattime.sinceLast());
        id++;
        try {
            stattime.tick();
            PosNegRWExample ex = parser.parse(s, builder, masterLearner);
            total.updateParsingStatistics(stattime.sinceLast());
            examples.add(ex);
            if (status.due()) {
                log.info("Parsed " + id + " ...");
                logged = true;
            }
        } catch (GraphFormatException e) {
            log.error("Trouble with #" + id, e);
        }
        stattime.tick();
    }
    if (logged)
        log.info("Total parsed: " + id);
    return trainCached(examples, builder, initialParamVec, numEpochs, total);
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) PosNegRWExample(edu.cmu.ml.proppr.examples.PosNegRWExample) ArrayList(java.util.ArrayList) GraphFormatException(edu.cmu.ml.proppr.graph.GraphFormatException) RWExampleParser(edu.cmu.ml.proppr.learn.tools.RWExampleParser)

Example 22 with StatusLogger

use of edu.cmu.ml.proppr.util.StatusLogger in project ProPPR by TeamCohen.

the class SimpleProgramProverTest method test.

@Test
public void test() throws IOException, LogicProgramException {
    WamProgram program = WamBaseProgram.load(new File(PROGRAM));
    Query q = new Query(new Goal("coworker", new ConstantArgument("steve"), new ConstantArgument("X")));
    System.out.println("Query: " + q.toString());
    ProofGraph p = new StateProofGraph(q, apr, program);
    Prover prover = new DfsProver(apr);
    Map<String, Double> sols = prover.solutions(p, new StatusLogger());
    assertEquals(2, sols.size());
    HashMap<String, Integer> expected = new HashMap<String, Integer>();
    expected.put("steve", 0);
    expected.put("sven", 0);
    System.out.println("Query: " + q.toString());
    for (String pair : sols.keySet()) {
        System.out.println(pair);
        String[] parts = pair.split(":");
        String v = parts[1];
        System.out.println("Got solution: " + v);
        if (expected.containsKey(v))
            expected.put(v, expected.get(v) + 1);
    }
    for (Map.Entry<String, Integer> e : expected.entrySet()) assertEquals(e.getKey(), 1, e.getValue().intValue());
}
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) HashMap(java.util.HashMap) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) Prover(edu.cmu.ml.proppr.prove.Prover) 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) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 23 with StatusLogger

use of edu.cmu.ml.proppr.util.StatusLogger in project ProPPR by TeamCohen.

the class FactsPluginTest method test.

@Test
public void test() throws LogicProgramException {
    APROptions apr = new APROptions();
    FactsPlugin p = FactsPlugin.load(apr, new File(GrounderTest.FACTS), false);
    WamProgram program = new WamBaseProgram();
    Query q = Query.parse("validClass(X)");
    StateProofGraph pg = new StateProofGraph(q, apr, program, p);
    Prover prover = new DprProver();
    Map<String, Double> sols = prover.solutions(pg, new StatusLogger());
    assertEquals(2, sols.size());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Query(edu.cmu.ml.proppr.prove.wam.Query) 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) FactsPlugin(edu.cmu.ml.proppr.prove.wam.plugins.FactsPlugin) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) WamBaseProgram(edu.cmu.ml.proppr.prove.wam.WamBaseProgram) Test(org.junit.Test) GrounderTest(edu.cmu.ml.proppr.GrounderTest)

Aggregations

StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)23 Test (org.junit.Test)13 Query (edu.cmu.ml.proppr.prove.wam.Query)11 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)11 File (java.io.File)10 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)9 Prover (edu.cmu.ml.proppr.prove.Prover)8 APROptions (edu.cmu.ml.proppr.util.APROptions)8 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)6 PosNegRWExample (edu.cmu.ml.proppr.examples.PosNegRWExample)4 DprProver (edu.cmu.ml.proppr.prove.DprProver)4 State (edu.cmu.ml.proppr.prove.wam.State)4 Map (java.util.Map)4 DfsProver (edu.cmu.ml.proppr.prove.DfsProver)3 ConstantArgument (edu.cmu.ml.proppr.prove.wam.ConstantArgument)3 Goal (edu.cmu.ml.proppr.prove.wam.Goal)3 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)3 ArrayList (java.util.ArrayList)3 GrounderTest (edu.cmu.ml.proppr.GrounderTest)2 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)2