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);
}
}
}
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);
}
}
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);
}
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();
}
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);
}
Aggregations