Search in sources :

Example 71 with Knowledge2

use of edu.cmu.tetrad.data.Knowledge2 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 72 with Knowledge2

use of edu.cmu.tetrad.data.Knowledge2 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 73 with Knowledge2

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

the class FasDci method search.

// ==========================PUBLIC METHODS===========================//
/**
 * Discovers all adjacencies in data.  The procedure is to remove edges in the graph which connect pairs of
 * variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are
 * removed in tiers.  First, edges which are independent conditional on zero other variables are removed, then edges
 * which are independent conditional on one other variable are removed, then two, then three, and so on, until no
 * more edges can be removed from the graph.  The edges which remain in the graph after this procedure are the
 * adjacencies in the data.
 *
 * @return a SepSet, which indicates which variables are independent conditional on which other variables
 */
public SepsetMapDci search() {
    this.logger.log("info", "Starting Fast Adjacency Search (DCI).");
    // Remove edges forbidden both ways.
    Set<Edge> edges = graph.getEdges();
    for (Edge _edge : edges) {
        String name1 = _edge.getNode1().getName();
        String name2 = _edge.getNode2().getName();
        if (knowledge.isForbidden(name1, name2) && knowledge.isForbidden(name2, name1)) {
            graph.removeEdge(_edge);
            this.logger.log("edgeRemoved", "Removed " + _edge + " because it was " + "forbidden by background knowledge.");
        }
    }
    // this.logger.info("Depth = " + ((depth == Integer
    // .MAX_VALUE) ? "Unlimited" : Integer.toString(depth)));
    SepsetMapDci sepset = new SepsetMapDci();
    int _depth = depth;
    if (_depth == -1) {
        _depth = 1000;
    }
    for (int d = 0; d <= _depth; d++) {
        boolean more = searchAtDepth(graph, independenceTest, new Knowledge2(), sepset, d);
        if (!more) {
            break;
        }
    }
    // verifySepsetIntegrity(sepset);
    this.logger.log("info", "Finishing Fast Adjacency Search.");
    return sepset;
}
Also used : Knowledge2(edu.cmu.tetrad.data.Knowledge2) Edge(edu.cmu.tetrad.graph.Edge)

Example 74 with Knowledge2

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

the class TestKnowledge method test2.

@Test
public final void test2() {
    List<Node> nodes1 = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        nodes1.add(new ContinuousVariable("X" + (i + 1)));
    }
    Graph g = GraphUtils.randomGraph(nodes1, 0, 100, 3, 3, 3, false);
    List<Node> nodes = g.getNodes();
    List<String> names = new ArrayList<>();
    for (Node node : nodes) names.add(node.getName());
    Knowledge2 knowledge = new Knowledge2(names);
    knowledge.addToTier(0, "X1*");
    knowledge.addToTier(1, "X2*");
    knowledge.setRequired("X4*,X6*", "X5*");
    knowledge.setRequired("X6*", "X5*");
    assertTrue(knowledge.isForbidden("X20", "X10"));
    assertTrue(knowledge.isRequired("X6", "X5"));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) Knowledge2(edu.cmu.tetrad.data.Knowledge2) Test(org.junit.Test)

Example 75 with Knowledge2

use of edu.cmu.tetrad.data.Knowledge2 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

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