use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.
the class FciRunner method execute.
// =================PUBLIC METHODS OVERRIDING ABSTRACT=================//
/**
* Executes the algorithm, producing (at least) a result workbench. Must be
* implemented in the extending class.
*/
public void execute() {
IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
Graph graph;
if (getParams().getBoolean("rfciUsed", false)) {
Rfci fci = new Rfci(getIndependenceTest());
fci.setKnowledge(knowledge);
fci.setCompleteRuleSetUsed(getParams().getBoolean("completeRuleSetUsed", false));
fci.setMaxPathLength(getParams().getInt("maxReachablePathLength", -1));
fci.setDepth(getParams().getInt("depth", -1));
graph = fci.search();
} else {
Fci fci = new Fci(getIndependenceTest());
fci.setKnowledge(knowledge);
fci.setCompleteRuleSetUsed(getParams().getBoolean("completeRuleSetUsed", false));
fci.setPossibleDsepSearchDone(getParams().getBoolean("possibleDsepDone", true));
fci.setMaxPathLength(getParams().getInt("maxReachablePathLength", -1));
fci.setDepth(getParams().getInt("depth", -1));
graph = fci.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);
}
use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.
the class PcStableRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
int depth = getParams().getInt("depth", -1);
PcStable pc = new PcStable(getIndependenceTest());
pc.setKnowledge(knowledge);
pc.setAggressivelyPreventCycles(isAggressivelyPreventCycles());
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);
}
use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.
the class YeastPcCcdSearchWrapper method main.
public static void main(String[] args) {
int[][] yeastReg = { { 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0 }, { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 }, { 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1 }, { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1 }, { 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0 }, { 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1 }, { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }, { 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, { 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1 } };
List listOfNames = new ArrayList();
// get the file containing the file names
DataSet cds = null;
try {
DataReader reader = new DataReader();
cds = reader.parseTabular(new File(args[0]));
} catch (IOException e) {
e.printStackTrace();
}
String outfileprefix = args[1];
String outverbosefile = outfileprefix + ".doc";
String outsummaryfile = outfileprefix + ".xls";
OutputStream s1 = null;
OutputStream s2 = null;
boolean verbose = true;
try {
s1 = new FileOutputStream(outverbosefile);
} catch (IOException e) {
System.out.println("Cannot open file file " + outverbosefile);
System.exit(0);
}
DataOutputStream d1 = new DataOutputStream(s1);
try {
s2 = new FileOutputStream(outsummaryfile);
} catch (IOException e) {
System.out.println("Cannot open file file " + outsummaryfile);
System.exit(0);
}
DataOutputStream d2 = new DataOutputStream(s2);
try {
// if(!verbose) {
d2.writeBytes("File\tPC05 FP\tPC05 FN\tPC10 FP\tPC10 FN\tPC15 FP\t");
d2.writeBytes("PC15 FN\tPC20 FP\tPC20 FN\tPC30 FP\tPC30 FN\t");
d2.writeBytes("CCD05 FP\tCCD05 FN\tCCD10 FP\tCCD10 FN\tCCD 15 FP\t");
d2.writeBytes("CCD15 FN\tCCD20 FP\tCCD20 FN\tCCD30 FP\tCCD 30 FN\n");
// }
// read in variable name and set up DataSet.
// RectangularDataSet dataSet = DataLoaders.loadContinuousData(
// new File(args[0]), DelimiterType.WHITESPACE,
// "//"
// );
// int ngenes = 6;
int ngenes = Integer.valueOf(args[2]);
IKnowledge bk = new Knowledge2();
bk.addToTiersByVarNames(listOfNames);
// if(verbose) {
d1.writeBytes("\n \n**Results for data in file yeastTRN**\n \n");
d1.writeBytes(" Acutal adj matrix: \n");
printAdjMatrix(yeastReg, listOfNames, d1);
// }
int[] PC05Accuracy;
PC05Accuracy = PCAccuracy(0.05, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] PC10Accuracy;
PC10Accuracy = PCAccuracy(0.10, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] PC15Accuracy;
PC15Accuracy = PCAccuracy(0.15, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] PC20Accuracy;
PC20Accuracy = PCAccuracy(0.20, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] PC30Accuracy;
PC30Accuracy = PCAccuracy(0.30, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] CCD05Accuracy;
CCD05Accuracy = CcdAccuracy(0.05, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] CCD10Accuracy;
CCD10Accuracy = CcdAccuracy(0.10, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] CCD15Accuracy;
CCD15Accuracy = CcdAccuracy(0.15, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] CCD20Accuracy;
CCD20Accuracy = CcdAccuracy(0.20, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] CCD30Accuracy;
CCD30Accuracy = CcdAccuracy(0.30, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
/*
int[] FCI05Accuracy;
FCI05Accuracy =
FCIAccuracy(0.05, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] FCI10Accuracy;
FCI10Accuracy =
FCIAccuracy(0.10, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] FCI15Accuracy;
FCI15Accuracy =
FCIAccuracy(0.15, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] FCI20Accuracy;
FCI20Accuracy =
FCIAccuracy(0.20, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
int[] FCI30Accuracy;
FCI30Accuracy =
FCIAccuracy(0.30, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
*/
// if(!verbose) {
d2.writeBytes("yeastTRN \t");
d2.writeBytes(PC05Accuracy[0] + "\t");
d2.writeBytes(PC05Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(PC10Accuracy[0] + "\t");
d2.writeBytes(PC10Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(PC15Accuracy[0] + "\t");
d2.writeBytes(PC15Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(PC20Accuracy[0] + "\t");
d2.writeBytes(PC20Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(PC30Accuracy[0] + "\t");
d2.writeBytes(PC30Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(CCD05Accuracy[0] + "\t");
d2.writeBytes(CCD05Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(CCD10Accuracy[0] + "\t");
d2.writeBytes(CCD10Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(CCD15Accuracy[0] + "\t");
d2.writeBytes(CCD15Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(CCD20Accuracy[0] + "\t");
d2.writeBytes(CCD20Accuracy[1] + "\t");
// }
// if(!verbose) {
d2.writeBytes(CCD30Accuracy[0] + "\t");
d2.writeBytes(CCD30Accuracy[1] + "\n");
// }
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.
the class KnowledgeBoxEditor method resetEdgeDisplayOld.
/**
* This is an old method that needs to be removed when cleaning up code.
*/
private void resetEdgeDisplayOld() {
List<String> varNames = getVarNames();
IKnowledge knowledge = getKnowledge();
for (String name : varNames) {
knowledge.addVariable(name);
}
KnowledgeGraph graph = new KnowledgeGraph(getKnowledge());
for (String varName : varNames) {
graph.addNode(new KnowledgeModelNode(varName));
}
if (this.showRequiredByGroups) {
for (Iterator<KnowledgeEdge> i = knowledge.requiredEdgesIterator(); i.hasNext(); ) {
KnowledgeEdge edge = i.next();
String from = edge.getFrom();
String to = edge.getTo();
if (knowledge.isRequiredByGroups(from, to)) {
KnowledgeModelNode fromNode = (KnowledgeModelNode) graph.getNode(from);
KnowledgeModelNode toNode = (KnowledgeModelNode) graph.getNode(to);
graph.addEdge(new KnowledgeModelEdge(fromNode, toNode, KnowledgeModelEdge.REQUIRED_BY_GROUPS));
}
}
}
if (this.showForbiddenByGroups) {
for (Iterator<KnowledgeEdge> i = knowledge.forbiddenEdgesIterator(); i.hasNext(); ) {
KnowledgeEdge edge = i.next();
String from = edge.getFrom();
String to = edge.getTo();
if (knowledge.isForbiddenByGroups(from, to)) {
KnowledgeModelNode fromNode = (KnowledgeModelNode) graph.getNode(from);
KnowledgeModelNode toNode = (KnowledgeModelNode) graph.getNode(to);
graph.addEdge(new KnowledgeModelEdge(fromNode, toNode, KnowledgeModelEdge.FORBIDDEN_BY_GROUPS));
}
}
}
if (showRequired) {
for (Iterator<KnowledgeEdge> i = knowledge.explicitlyRequiredEdgesIterator(); i.hasNext(); ) {
KnowledgeEdge pair = i.next();
String from = pair.getFrom();
String to = pair.getTo();
KnowledgeModelNode fromNode = (KnowledgeModelNode) graph.getNode(from);
KnowledgeModelNode toNode = (KnowledgeModelNode) graph.getNode(to);
if (fromNode == null || toNode == null) {
continue;
}
graph.addEdge(new KnowledgeModelEdge(fromNode, toNode, KnowledgeModelEdge.REQUIRED));
}
}
if (showForbiddenByTiers) {
for (Iterator<KnowledgeEdge> i = knowledge.forbiddenEdgesIterator(); i.hasNext(); ) {
KnowledgeEdge pair = i.next();
String from = pair.getFrom();
String to = pair.getTo();
if (!knowledge.isForbiddenByTiers(from, to)) {
continue;
}
KnowledgeModelNode fromNode = (KnowledgeModelNode) graph.getNode(from);
KnowledgeModelNode toNode = (KnowledgeModelNode) graph.getNode(to);
if (fromNode == null) {
graph.addNode(new KnowledgeModelNode(from));
fromNode = (KnowledgeModelNode) graph.getNode(from);
}
if (toNode == null) {
graph.addNode(new KnowledgeModelNode(to));
toNode = (KnowledgeModelNode) graph.getNode(to);
}
KnowledgeModelEdge knowledgeModelEdge = new KnowledgeModelEdge(fromNode, toNode, KnowledgeModelEdge.FORBIDDEN_BY_TIERS);
graph.addEdge(knowledgeModelEdge);
// Hacked fix. Jdramsey.
// if (!graph.containsEdge(knowledgeModelEdge)) {
// graph.addEdge(knowledgeModelEdge);
// }
}
}
if (showForbiddenExplicitly) {
for (Iterator<KnowledgeEdge> i = knowledge.explicitlyForbiddenEdgesIterator(); i.hasNext(); ) {
KnowledgeEdge pair = i.next();
String from = pair.getFrom();
String to = pair.getTo();
KnowledgeModelNode fromNode = (KnowledgeModelNode) graph.getNode(from);
KnowledgeModelNode toNode = (KnowledgeModelNode) graph.getNode(to);
KnowledgeModelEdge edge = new KnowledgeModelEdge(fromNode, toNode, KnowledgeModelEdge.FORBIDDEN_EXPLICITLY);
if (!graph.containsEdge(edge)) {
graph.addEdge(edge);
}
}
}
boolean arrangedAll = GraphUtils.arrangeBySourceGraph(graph, edgeWorkbench.getGraph());
if (!arrangedAll) {
GraphUtils.circleLayout(graph, 200, 200, 150);
}
edgeWorkbench.setGraph(graph);
if (knowledgeBoxModel != null) {
notifyKnowledge();
}
}
use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.
the class CfciRunner method execute.
// =================PUBLIC METHODS OVERRIDING ABSTRACT=================//
/**
* Executes the algorithm, producing (at least) a result workbench. Must be
* implemented in the extending class.
*/
public void execute() {
IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
Parameters searchParams = getParams();
Parameters params = searchParams;
Cfci cfci = new Cfci(getIndependenceTest());
cfci.setKnowledge(knowledge);
cfci.setDepth(params.getInt("depth", -1));
Graph graph = cfci.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);
}
Aggregations