Search in sources :

Example 16 with Knowledge2

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

the class FciCcdSearchEditor method layoutByKnowledge.

public void layoutByKnowledge() {
    GraphWorkbench resultWorkbench = getWorkbench();
    Graph graph = resultWorkbench.getGraph();
    IKnowledge knowledge = (IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2());
    SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 17 with Knowledge2

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

the class TestKnowledge method test1.

@Test
public final void test1() {
    List<Node> nodes1 = new ArrayList<>();
    for (int i1 = 0; i1 < 10; i1++) {
        nodes1.add(new ContinuousVariable("X" + (i1 + 1)));
    }
    Graph g = GraphUtils.randomGraph(nodes1, 0, 10, 3, 3, 3, false);
    g.getNode("X1").setName("X1.1");
    g.getNode("X2").setName("X2-1");
    List<Node> nodes = g.getNodes();
    List<String> varNames = new ArrayList<>();
    for (Node node : nodes) {
        varNames.add(node.getName());
    }
    IKnowledge knowledge = new Knowledge2(varNames);
    knowledge.addToTier(0, "X1.*1");
    knowledge.addToTier(0, "X2-1");
    knowledge.addToTier(1, "X3");
    knowledge.setForbidden("X4", "X5");
    knowledge.setRequired("X6", "X7");
    knowledge.setRequired("X7", "X8");
    assertTrue(knowledge.isForbidden("X4", "X5"));
    assertFalse(knowledge.isForbidden("X1.1", "X2-1"));
    assertTrue(knowledge.isForbidden("X3", "X2-1"));
    assertTrue(knowledge.isRequired("X6", "X7"));
    IKnowledge copy = knowledge.copy();
    assertTrue(copy.isForbidden("X4", "X5"));
    assertFalse(copy.isForbidden("X1", "X2-1"));
    assertTrue(copy.isForbidden("X3", "X2-1"));
    knowledge.setTierForbiddenWithin(0, true);
    assertTrue(knowledge.isForbidden("X1.1", "X2-1"));
    assertTrue(knowledge.isForbidden("X2-1", "X1.1"));
    assertFalse(knowledge.isForbidden("X1.1", "X1.1"));
    boolean found = false;
    for (Iterator i = knowledge.forbiddenEdgesIterator(); i.hasNext(); ) {
        KnowledgeEdge edge = (KnowledgeEdge) i.next();
        if (edge.getFrom().equals("X1.1") && edge.getTo().equals("X2-1")) {
            found = true;
        }
    }
    assertTrue(found);
    knowledge.setTierForbiddenWithin(0, false);
    assertFalse(knowledge.isForbidden("X1.1", "X2-1"));
    assertFalse(knowledge.isForbidden("X2-1", "X1.1"));
    assertFalse(knowledge.isForbidden("X1.1", "X1.1"));
}
Also used : KnowledgeEdge(edu.cmu.tetrad.data.KnowledgeEdge) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) Knowledge2(edu.cmu.tetrad.data.Knowledge2) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) IKnowledge(edu.cmu.tetrad.data.IKnowledge) Graph(edu.cmu.tetrad.graph.Graph) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 18 with Knowledge2

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

the class TestKnowledge method test3.

@Test
public final void test3() {
    List<String> vars = new ArrayList<>();
    final int numVars = 1000;
    for (int i = 0; i < numVars; i++) {
        vars.add("X" + i);
    }
    IKnowledge knowledge = new Knowledge2(vars);
    knowledge.setForbidden("X1*", "X2*");
    knowledge.setForbidden("X3*", "X4*");
    knowledge.setForbidden("X5*", "X6*");
    knowledge.addToTier(0, "X7*");
    knowledge.addToTier(1, "X8*");
    knowledge.addToTier(2, "X9*");
    for (int i = 0; i < numVars; i++) {
        assertTrue(knowledge.isForbidden("X11", "X22"));
    }
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) ArrayList(java.util.ArrayList) Knowledge2(edu.cmu.tetrad.data.Knowledge2) Test(org.junit.Test)

Example 19 with Knowledge2

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

the class TestPcd method testSearch3.

/**
 * This will fail if the orientation loop doesn't continue after the first orientation.
 */
// @Test
public void testSearch3() {
    IKnowledge knowledge = new Knowledge2();
    knowledge.setForbidden("B", "D");
    knowledge.setForbidden("D", "B");
    checkWithKnowledge("A-->B,C-->B,B-->D", "A-->B,C-->B,D", knowledge);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 20 with Knowledge2

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

the class TimeLagGraphWrapper method getKnowledge.

public IKnowledge getKnowledge() {
    // need to fix this!
    int numLags = 1;
    List<Node> variables = graph.getNodes();
    List<Integer> laglist = new ArrayList<>();
    IKnowledge knowledge1 = new Knowledge2();
    int lag;
    for (Node node : variables) {
        String varName = node.getName();
        String tmp;
        if (varName.indexOf(':') == -1) {
            lag = 0;
            laglist.add(lag);
        } else {
            tmp = varName.substring(varName.indexOf(':') + 1, varName.length());
            lag = Integer.parseInt(tmp);
            laglist.add(lag);
        }
    }
    numLags = Collections.max(laglist);
    for (Node node : variables) {
        String varName = node.getName();
        String tmp;
        if (varName.indexOf(':') == -1) {
            lag = 0;
            laglist.add(lag);
        } else {
            tmp = varName.substring(varName.indexOf(':') + 1, varName.length());
            lag = Integer.parseInt(tmp);
            laglist.add(lag);
        }
        knowledge1.addToTier(numLags - lag, node.getName());
    }
    System.out.println("Knowledge in graph = " + knowledge1);
    return knowledge1;
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) ArrayList(java.util.ArrayList) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Aggregations

Knowledge2 (edu.cmu.tetrad.data.Knowledge2)75 IKnowledge (edu.cmu.tetrad.data.IKnowledge)43 Parameters (edu.cmu.tetrad.util.Parameters)17 Graph (edu.cmu.tetrad.graph.Graph)13 GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)5 DataSet (edu.cmu.tetrad.data.DataSet)4 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)4 MeekRules (edu.cmu.tetrad.search.MeekRules)4 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)4 CharArrayWriter (java.io.CharArrayWriter)4 PrintWriter (java.io.PrintWriter)4 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)3 Node (edu.cmu.tetrad.graph.Node)3 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)1 DataModel (edu.cmu.tetrad.data.DataModel)1 DataReader (edu.cmu.tetrad.data.DataReader)1 KnowledgeEdge (edu.cmu.tetrad.data.KnowledgeEdge)1 Edge (edu.cmu.tetrad.graph.Edge)1