Search in sources :

Example 21 with IKnowledge

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

the class VcpcFastRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    Parameters searchParams = getParams();
    Parameters params = searchParams;
    VcpcFast fvcpc = new VcpcFast(getIndependenceTest());
    fvcpc.setKnowledge(knowledge);
    fvcpc.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles());
    fvcpc.setDepth(params.getInt("depth", -1));
    if (independenceFactsModel != null) {
        fvcpc.setFacts(independenceFactsModel.getFacts());
    }
    Graph graph = fvcpc.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);
    setVcpcFastFields(fvcpc);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Parameters(edu.cmu.tetrad.util.Parameters) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 22 with IKnowledge

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

the class PcRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    int depth = getParams().getInt("depth", -1);
    Graph graph;
    Pc pc = new Pc(getIndependenceTest());
    pc.setKnowledge(knowledge);
    pc.setAggressivelyPreventCycles(isAggressivelyPreventCycles());
    pc.setDepth(depth);
    pc.setInitialGraph(initialGraph);
    graph = pc.search();
    System.out.println(graph);
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (knowledge.isDefaultToKnowledgeLayout()) {
        SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
    setPcFields(pc);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 23 with IKnowledge

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

the class PcStableMaxRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    int depth = getParams().getInt("depth", -1);
    // PC pc = new PC(getIndependenceTest());
    PcStableMax pc = new PcStableMax(getIndependenceTest());
    pc.setKnowledge(knowledge);
    pc.setDepth(depth);
    pc.setInitialGraph(initialGraph);
    Graph graph = pc.search();
    System.out.println(graph);
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (knowledge.isDefaultToKnowledgeLayout()) {
        SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
    setPcFields(pc);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 24 with IKnowledge

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

the class RequiredGraphModel method createKnowledge.

private void createKnowledge(Parameters params) {
    IKnowledge knwl = getKnowledge();
    if (knwl == null) {
        return;
    }
    knwl.clear();
    List<String> varNames = getVarNames();
    getKnowledgeBoxInput().getVariableNames().stream().filter(e -> !e.startsWith("E_")).forEach(e -> {
        varNames.add(e);
        knwl.addVariable(e);
    });
    if (resultGraph == null) {
        throw new NullPointerException("I couldn't find a parent graph.");
    }
    List<Node> nodes = resultGraph.getNodes();
    int numOfNodes = nodes.size();
    for (int i = 0; i < numOfNodes; i++) {
        for (int j = i + 1; j < numOfNodes; j++) {
            Node n1 = nodes.get(i);
            Node n2 = nodes.get(j);
            if (n1.getName().startsWith("E_") || n2.getName().startsWith("E_")) {
                continue;
            }
            Edge edge = resultGraph.getEdge(n1, n2);
            if (edge == null) {
                continue;
            } else if (edge.isDirected()) {
                knwl.setRequired(edge.getNode1().getName(), edge.getNode2().getName());
            } else if (Edges.isUndirectedEdge(edge)) {
                knwl.setRequired(n1.getName(), n2.getName());
                knwl.setRequired(n2.getName(), n1.getName());
            }
        }
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) SortedSet(java.util.SortedSet) IKnowledge(edu.cmu.tetrad.data.IKnowledge) TetradLogger(edu.cmu.tetrad.util.TetradLogger) Graph(edu.cmu.tetrad.graph.Graph) Parameters(edu.cmu.tetrad.util.Parameters) TetradSerializableUtils(edu.cmu.tetrad.util.TetradSerializableUtils) Node(edu.cmu.tetrad.graph.Node) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Edges(edu.cmu.tetrad.graph.Edges) List(java.util.List) KnowledgeBoxInput(edu.cmu.tetrad.data.KnowledgeBoxInput) Edge(edu.cmu.tetrad.graph.Edge) Knowledge2(edu.cmu.tetrad.data.Knowledge2) IKnowledge(edu.cmu.tetrad.data.IKnowledge) Node(edu.cmu.tetrad.graph.Node) Edge(edu.cmu.tetrad.graph.Edge)

Example 25 with IKnowledge

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

the class SampleVcpcRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    Parameters searchParams = getParams();
    Parameters params = searchParams;
    SampleVcpc svcpc = new SampleVcpc(getIndependenceTest());
    svcpc.setKnowledge(knowledge);
    svcpc.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles());
    svcpc.setDepth(params.getInt("depth", -1));
    if (independenceFactsModel != null) {
        svcpc.setFacts(independenceFactsModel.getFacts());
    }
    // vcpc.setSemPm(semPm);
    // 
    // if (semPm != null) {
    // vcpc.setSemPm(getSemPm());
    // }
    svcpc.setSemIm(semIm);
    if (semIm != null) {
        svcpc.setSemIm(this.semIm);
    }
    Graph graph = svcpc.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);
    setSvcpcFields(svcpc);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Parameters(edu.cmu.tetrad.util.Parameters) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

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