Search in sources :

Example 56 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.

the class VcpcAltRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    Parameters searchParams = getParams();
    Parameters params = searchParams;
    VcpcAlt VcpcAlt = new VcpcAlt(getIndependenceTest());
    VcpcAlt.setKnowledge(knowledge);
    VcpcAlt.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles());
    VcpcAlt.setDepth(params.getInt("depth", -1));
    Graph graph = VcpcAlt.search();
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (knowledge.isDefaultToKnowledgeLayout()) {
        SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Parameters(edu.cmu.tetrad.util.Parameters) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 57 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.

the class VcpcRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    Parameters searchParams = getParams();
    Parameters params = searchParams;
    Vcpc vcpc = new Vcpc(getIndependenceTest());
    vcpc.setKnowledge(knowledge);
    vcpc.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles());
    vcpc.setDepth(params.getInt("depth", -1));
    if (independenceFactsModel != null) {
        vcpc.setFacts(independenceFactsModel.getFacts());
    }
    Graph graph = vcpc.search();
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (knowledge.isDefaultToKnowledgeLayout()) {
        SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
    setVcpcFields(vcpc);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Parameters(edu.cmu.tetrad.util.Parameters) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 58 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.

the class TestDagInPatternIterator method test5.

@Test
public void test5() {
    RandomUtil.getInstance().setSeed(34828384L);
    List<Node> nodes1 = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        nodes1.add(new ContinuousVariable("X" + (i + 1)));
    }
    Dag dag1 = new Dag(GraphUtils.randomGraph(nodes1, 0, 3, 30, 15, 15, false));
    Graph pattern = SearchGraphUtils.patternForDag(dag1);
    List<Node> nodes = pattern.getNodes();
    // Make random knowedge.
    int numTiers = 6;
    IKnowledge knowledge = new Knowledge2();
    for (Node node : nodes) {
        int tier = RandomUtil.getInstance().nextInt(numTiers);
        if (tier < 2)
            continue;
        knowledge.addToTier(tier, node.getName());
    }
    if (!knowledge.isViolatedBy(pattern)) {
        DagInPatternIterator iterator1 = new DagInPatternIterator(pattern);
        Graph dag0 = null;
        while (iterator1.hasNext()) {
            Graph dag = iterator1.next();
            if (!knowledge.isViolatedBy(dag)) {
                dag0 = dag;
            }
        }
        if (dag0 == null) {
            fail("Inconsistent knowledge.");
        }
    }
    if (!knowledge.isViolatedBy(pattern)) {
        DagInPatternIterator iterator2 = new DagInPatternIterator(pattern, knowledge);
        while (iterator2.hasNext()) {
            Graph dag = iterator2.next();
            if (knowledge.isViolatedBy(dag)) {
                throw new IllegalArgumentException("Knowledge violated");
            }
        }
    }
    DagInPatternIterator iterator3 = new DagInPatternIterator(pattern);
    int count = 0;
    while (iterator3.hasNext()) {
        iterator3.next();
        count++;
    }
    assertEquals(6, count);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) IKnowledge(edu.cmu.tetrad.data.IKnowledge) ArrayList(java.util.ArrayList) Knowledge2(edu.cmu.tetrad.data.Knowledge2) DagInPatternIterator(edu.cmu.tetrad.search.DagInPatternIterator) Test(org.junit.Test)

Aggregations

IKnowledge (edu.cmu.tetrad.data.IKnowledge)58 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)46 Parameters (edu.cmu.tetrad.util.Parameters)18 Graph (edu.cmu.tetrad.graph.Graph)12 ArrayList (java.util.ArrayList)10 GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)8 IOException (java.io.IOException)7 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)5 CharArrayWriter (java.io.CharArrayWriter)5 DataReader (edu.cmu.tetrad.data.DataReader)4 DataSet (edu.cmu.tetrad.data.DataSet)4 Node (edu.cmu.tetrad.graph.Node)4 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)4 File (java.io.File)4 PrintWriter (java.io.PrintWriter)4 List (java.util.List)4 KnowledgeBoxInput (edu.cmu.tetrad.data.KnowledgeBoxInput)3 KnowledgeEdge (edu.cmu.tetrad.data.KnowledgeEdge)3 Test (org.junit.Test)3 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2