Search in sources :

Example 6 with Outlink

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

the class WamInterpreterTest method allSolutionsDFS.

public List<State> allSolutionsDFS(WamInterpreter wamInterp, Map<Feature, Double> fd, int depth, List<State> tail) {
    if (depth >= MAXDEPTH)
        return tail;
    if (wamInterp.getState().isCompleted()) {
        tail.add(wamInterp.getState());
        return tail;
    }
    for (Outlink o : outlinks(wamInterp)) {
        wamInterp.setState(o.child.mutableVersion());
        allSolutionsDFS(wamInterp, o.fd, depth + 1, tail);
    }
    return tail;
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink)

Example 7 with Outlink

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

the class SplitFactsPluginTest method test.

@Test
public void test() throws LogicProgramException {
    int input = 0;
    int output = 0;
    int constants = Configuration.USE_WAM;
    int modules = 0;
    Configuration c = new Configuration(("--programFiles " + GrounderTest.RULES + ":" + GrounderTest.FACTS + ":" + ADDLFACTS).split(" "), input, output, constants, modules);
    assertEquals("# of plugins", c.plugins.length, 1);
    assertEquals("# of members", ((SplitFactsPlugin) c.plugins[0]).plugins.size(), 2);
    assertTrue("claim", c.plugins[0]._claim("validClass/1"));
    Query q = Query.parse("validClass(X)");
    WamInterpreter interp = new WamInterpreter(c.program, c.plugins);
    int queryStartAddr = c.program.size();
    q.variabilize();
    c.program.append(q);
    interp.executeWithoutBranching(queryStartAddr);
    List<Outlink> outs = c.plugins[0].outlinks(interp.saveState(), interp, true);
    assertEquals("# outlinks", 6, outs.size());
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink) Configuration(edu.cmu.ml.proppr.util.Configuration) Query(edu.cmu.ml.proppr.prove.wam.Query) WamInterpreter(edu.cmu.ml.proppr.prove.wam.WamInterpreter) Test(org.junit.Test) GrounderTest(edu.cmu.ml.proppr.GrounderTest)

Example 8 with Outlink

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

the class InferenceGraphTestTemplate method test.

@Test
public void test() {
    InferenceGraph g = getGraph();
    MutableState a = new MutableState();
    a.setJumpTo("foo");
    a.setCanonicalHash(2);
    a.setCanonicalForm("a");
    MutableState b = new MutableState();
    b.setJumpTo("bar");
    b.setCanonicalHash(2);
    b.setCanonicalForm("b");
    MutableState b2 = new MutableState();
    b2.setJumpTo("bar");
    b2.setCanonicalHash(2);
    b2.setCanonicalForm("b");
    MutableState c = new MutableState();
    c.setJumpTo("baz");
    c.setCanonicalHash(3);
    c.setCanonicalForm("c");
    Map<Feature, Double> fd = new HashMap<Feature, Double>();
    fd.put(new Feature("quite"), 1.0);
    // a -> b
    List<Outlink> outlinks = new ArrayList<Outlink>();
    outlinks.add(new Outlink(fd, b));
    g.setOutlinks(g.getId(a), outlinks);
    // c -> b2 (=b)
    outlinks = new ArrayList<Outlink>();
    outlinks.add(new Outlink(fd, b2));
    g.setOutlinks(g.getId(c), outlinks);
    {
        String s = g.serialize(true);
        String[] parts = s.split("\t");
        assertEquals(6, parts.length);
        assertEquals("3", parts[0]);
        assertEquals("2", parts[1]);
        assertEquals("2", parts[2]);
        assertEquals("quite", parts[3]);
        String[] edges = new String[] { parts[4], parts[5] };
        Arrays.sort(edges);
        assertEquals("1->2:1@1.0", edges[0]);
        assertEquals("3->2:1@1.0", edges[1]);
    }
    {
        String s = g.serialize(false);
        String[] parts = s.split("\t");
        assertEquals(5, parts.length);
        assertEquals("3", parts[0]);
        assertEquals("2", parts[1]);
        assertEquals("2", parts[2]);
        String[] edges = new String[] { parts[3], parts[4] };
        Arrays.sort(edges);
        assertEquals("1->2:1@1.0", edges[0]);
        assertEquals("3->2:1@1.0", edges[1]);
    }
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink) MutableState(edu.cmu.ml.proppr.prove.wam.MutableState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Feature(edu.cmu.ml.proppr.prove.wam.Feature) Test(org.junit.Test)

Example 9 with Outlink

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

the class FilterPluginCollection method outlinks.

@Override
public List<Outlink> outlinks(State state, WamInterpreter wamInterp, boolean computeFeatures) throws LogicProgramException {
    String jumpTo = state.getJumpTo();
    PluginFunction fun = this.registry.get(jumpTo);
    wamInterp.restoreState(state);
    wamInterp.returnp();
    if (!fun.run(wamInterp)) {
        wamInterp.getState().setFailed(true);
    } else {
        wamInterp.executeWithoutBranching();
    }
    if (computeFeatures) {
        return Collections.singletonList(new Outlink(this.fd, wamInterp.saveState()));
    }
    return Collections.singletonList(new Outlink(Outlink.EMPTY_FD, wamInterp.saveState()));
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink)

Example 10 with Outlink

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

the class SimpleProgramProofGraphTest method normalized.

private Map<State, Double> normalized(List<Outlink> outlinks) {
    Map<State, Double> normalized = new HashMap<State, Double>();
    double total = 0;
    for (Outlink o : outlinks) {
        double wt = 0;
        for (Map.Entry<Feature, Double> e : o.fd.entrySet()) {
            wt += e.getValue();
        }
        normalized.put(o.child, wt);
        total += wt;
    }
    for (Map.Entry<State, Double> e : normalized.entrySet()) {
        e.setValue(e.getValue() / total);
    }
    return normalized;
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink) HashMap(java.util.HashMap) State(edu.cmu.ml.proppr.prove.wam.State) HashMap(java.util.HashMap) Map(java.util.Map) Feature(edu.cmu.ml.proppr.prove.wam.Feature)

Aggregations

Outlink (edu.cmu.ml.proppr.prove.wam.Outlink)14 State (edu.cmu.ml.proppr.prove.wam.State)6 Feature (edu.cmu.ml.proppr.prove.wam.Feature)5 HashMap (java.util.HashMap)5 Map (java.util.Map)4 LogicProgramException (edu.cmu.ml.proppr.prove.wam.LogicProgramException)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Query (edu.cmu.ml.proppr.prove.wam.Query)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 LinkedList (java.util.LinkedList)2 GrounderTest (edu.cmu.ml.proppr.GrounderTest)1 Argument (edu.cmu.ml.proppr.prove.wam.Argument)1 ConstantArgument (edu.cmu.ml.proppr.prove.wam.ConstantArgument)1 Goal (edu.cmu.ml.proppr.prove.wam.Goal)1 MutableState (edu.cmu.ml.proppr.prove.wam.MutableState)1 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)1 WamInterpreter (edu.cmu.ml.proppr.prove.wam.WamInterpreter)1 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)1 APROptions (edu.cmu.ml.proppr.util.APROptions)1