Search in sources :

Example 1 with IKnowledge

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

the class SaveKnowledgeAction method actionPerformed.

/**
 * Performs the action of loading a session from a file.
 */
public void actionPerformed(ActionEvent e) {
    Component comp = (this.knowledgeEditable instanceof Component) ? (Component) this.knowledgeEditable : null;
    File file = EditorUtils.getSaveFile("knowledge", "txt", comp, false, "Save Knowledge...");
    if (file != null) {
        try {
            FileWriter writer = new FileWriter(file);
            IKnowledge knowledge = this.knowledgeEditable.getKnowledge();
            Knowledge.saveKnowledge(knowledge, writer);
            writer.close();
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Saved knowledge as " + file.getAbsoluteFile() + ".");
        } catch (IOException e1) {
            String message = e1.getMessage() == null ? e1.getClass().getName() : e1.getMessage();
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), message);
        }
    }
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 2 with IKnowledge

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

the class PasteKnowledgeAction method actionPerformed.

/**
 * Copies a parentally closed selection of session nodes in the frontmost
 * session editor to the clipboard.
 */
public void actionPerformed(ActionEvent e) {
    Transferable transferable = InternalClipboard.getInstance().getContents(null);
    if (!(transferable instanceof KnowledgeSelection)) {
        return;
    }
    KnowledgeSelection selection = (KnowledgeSelection) transferable;
    DataFlavor flavor = new DataFlavor(KnowledgeSelection.class, "Knowledge");
    try {
        IKnowledge knowledge = (IKnowledge) selection.getTransferData(flavor);
        if (knowledge != null) {
            this.knowledgeEditable.setKnowledge(knowledge);
        }
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Transferable(java.awt.datatransfer.Transferable) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 3 with IKnowledge

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

the class TestCpc 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");
    knowledge.setForbidden("C", "B");
    checkWithKnowledge("A-->B,C-->B,B-->D", "A---B,B-->C,D", /*"A-->B,C-->B,A-->D,C-->D",*/
    knowledge);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Knowledge2(edu.cmu.tetrad.data.Knowledge2) Test(org.junit.Test)

Example 4 with IKnowledge

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

the class TsImages method search.

@Override
public Graph search(List<DataModel> dataSets, Parameters parameters) {
    List<DataModel> dataModels = new ArrayList<>();
    for (DataModel dataSet : dataSets) {
        dataModels.add(dataSet);
    }
    TsGFci search;
    if (score instanceof SemBicScore) {
        SemBicScoreImages gesScore = new SemBicScoreImages(dataModels);
        gesScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
        IndependenceTest test = new IndTestScore(gesScore);
        search = new TsGFci(test, gesScore);
    } else if (score instanceof BdeuScore) {
        double samplePrior = parameters.getDouble("samplePrior", 1);
        double structurePrior = parameters.getDouble("structurePrior", 1);
        BdeuScoreImages score = new BdeuScoreImages(dataModels);
        score.setSamplePrior(samplePrior);
        score.setStructurePrior(structurePrior);
        IndependenceTest test = new IndTestScore(score);
        search = new TsGFci(test, score);
    } else {
        throw new IllegalStateException("Sorry, data must either be all continuous or all discrete.");
    }
    IKnowledge knowledge = dataModels.get(0).getKnowledge();
    search.setKnowledge(knowledge);
    return search.search();
}
Also used : BdeuScoreImages(edu.cmu.tetrad.search.BdeuScoreImages) IKnowledge(edu.cmu.tetrad.data.IKnowledge) IndependenceTest(edu.cmu.tetrad.search.IndependenceTest) SemBicScoreImages(edu.cmu.tetrad.search.SemBicScoreImages) DataModel(edu.cmu.tetrad.data.DataModel) IndTestScore(edu.cmu.tetrad.search.IndTestScore) BdeuScore(edu.cmu.tetrad.algcomparison.score.BdeuScore) ArrayList(java.util.ArrayList) TsGFci(edu.cmu.tetrad.search.TsGFci) SemBicScore(edu.cmu.tetrad.algcomparison.score.SemBicScore)

Example 5 with IKnowledge

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

the class KpcRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    int depth = getParams().getInt("depth", -1);
    // Cpci pcSearch = new Cpci(getIndependenceTest(), knowledge, getIndependenceTest().getSimulatedData());
    Kpc kpc = new Kpc((DataSet) getDataModel(), getParams().getDouble("alpha", 0.001));
    kpc.setKnowledge(knowledge);
    kpc.setAggressivelyPreventCycles(isAggressivelyPreventCycles());
    kpc.setDepth(depth);
    Graph graph = kpc.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);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) 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