use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class ExternalAlgorithmPcalgPc method search.
/**
* Reads in the relevant graph from the file (see above) and returns it.
*/
public Graph search(DataModel dataSet, Parameters parameters) {
int index = getIndex(dataSet);
File file = new File(path, "/results/" + extDir + "/" + (simIndex + 1) + "/graph." + index + ".txt");
System.out.println(file.getAbsolutePath());
try {
DataReader reader = new DataReader();
reader.setVariablesSupplied(true);
DataSet dataSet2 = reader.parseTabular(file);
System.out.println("Loading graph from " + file.getAbsolutePath());
Graph graph = loadGraphPcAlgMatrix(dataSet2);
GraphUtils.circleLayout(graph, 225, 200, 150);
return graph;
} catch (IOException e) {
throw new RuntimeException("Couldn't parse graph.");
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class Mgm method search.
@Override
public Graph search(DataModel ds, Parameters parameters) {
// Notify the user that you need at least one continuous and one discrete variable to run MGM
List<Node> variables = ds.getVariables();
boolean hasContinuous = false;
boolean hasDiscrete = false;
for (Node node : variables) {
if (node instanceof ContinuousVariable) {
hasContinuous = true;
}
if (node instanceof DiscreteVariable) {
hasDiscrete = true;
}
}
if (!hasContinuous || !hasDiscrete) {
throw new IllegalArgumentException("You need at least one continuous and one discrete variable to run MGM.");
}
if (parameters.getInt("bootstrapSampleSize") < 1) {
DataSet _ds = DataUtils.getMixedDataSet(ds);
double mgmParam1 = parameters.getDouble("mgmParam1");
double mgmParam2 = parameters.getDouble("mgmParam2");
double mgmParam3 = parameters.getDouble("mgmParam3");
double[] lambda = { mgmParam1, mgmParam2, mgmParam3 };
MGM m = new MGM(_ds, lambda);
return m.search();
} else {
Mgm algorithm = new Mgm();
DataSet data = (DataSet) ds;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
switch(parameters.getInt("bootstrapEnsemble", 1)) {
case 0:
edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
break;
case 1:
edgeEnsemble = BootstrapEdgeEnsemble.Highest;
break;
case 2:
edgeEnsemble = BootstrapEdgeEnsemble.Majority;
}
search.setEdgeEnsemble(edgeEnsemble);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class PcAll method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
if (algorithm != null) {
// initialGraph = algorithm.search(dataSet, parameters);
}
edu.cmu.tetrad.search.PcAll.FasRule fasRule;
switch(parameters.getInt("fasRule")) {
case 1:
fasRule = edu.cmu.tetrad.search.PcAll.FasRule.FAS;
break;
case 2:
fasRule = edu.cmu.tetrad.search.PcAll.FasRule.FAS_STABLE;
break;
case 3:
fasRule = edu.cmu.tetrad.search.PcAll.FasRule.FAS_STABLE_CONCURRENT;
break;
default:
throw new IllegalArgumentException("Not a choice.");
}
edu.cmu.tetrad.search.PcAll.ColliderDiscovery colliderDiscovery;
switch(parameters.getInt("colliderDiscoveryRule")) {
case 1:
colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.FAS_SEPSETS;
break;
case 2:
colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.CONSERVATIVE;
break;
case 3:
colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.MAX_P;
break;
default:
throw new IllegalArgumentException("Not a choice.");
}
edu.cmu.tetrad.search.PcAll.ConflictRule conflictRule;
switch(parameters.getInt("conflictRule")) {
case 1:
conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.OVERWRITE;
break;
case 2:
conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.BIDIRECTED;
break;
case 3:
conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.PRIORITY;
break;
default:
throw new IllegalArgumentException("Not a choice.");
}
edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(test.getTest(dataSet, parameters), initialGraph);
search.setDepth(parameters.getInt("depth"));
search.setKnowledge(knowledge);
search.setFasRule(fasRule);
search.setColliderDiscovery(colliderDiscovery);
search.setConflictRule(conflictRule);
search.setUseHeuristic(parameters.getBoolean("useMaxPOrientationHeuristic"));
search.setMaxPathLength(parameters.getInt("maxPOrientationMaxPathLength"));
return search.search();
} else {
PcAll pcAll = new PcAll(test, algorithm);
// pcAll.setKnowledge(knowledge);
if (initialGraph != null) {
pcAll.setInitialGraph(initialGraph);
}
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, pcAll, parameters.getInt("bootstrapSampleSize"));
search.setKnowledge(knowledge);
BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
switch(parameters.getInt("bootstrapEnsemble", 1)) {
case 0:
edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
break;
case 1:
edgeEnsemble = BootstrapEdgeEnsemble.Highest;
break;
case 2:
edgeEnsemble = BootstrapEdgeEnsemble.Majority;
}
search.setEdgeEnsemble(edgeEnsemble);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class PcStable method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
if (algorithm != null) {
// initialGraph = algorithm.search(dataSet, parameters);
}
edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(test.getTest(dataSet, parameters), initialGraph);
search.setDepth(parameters.getInt("depth"));
search.setKnowledge(knowledge);
search.setFasRule(PcAll.FasRule.FAS_STABLE);
search.setColliderDiscovery(edu.cmu.tetrad.search.PcAll.ColliderDiscovery.FAS_SEPSETS);
search.setConflictRule(PcAll.ConflictRule.PRIORITY);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
} else {
PcStable pcStable = new PcStable(test, algorithm);
// pcStable.setKnowledge(knowledge);
if (initialGraph != null) {
pcStable.setInitialGraph(initialGraph);
}
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, pcStable, parameters.getInt("bootstrapSampleSize"));
search.setKnowledge(knowledge);
BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
switch(parameters.getInt("bootstrapEnsemble", 1)) {
case 0:
edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
break;
case 1:
edgeEnsemble = BootstrapEdgeEnsemble.Highest;
break;
case 2:
edgeEnsemble = BootstrapEdgeEnsemble.Majority;
}
search.setEdgeEnsemble(edgeEnsemble);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class EB method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
initialGraph = algorithm.search(dataSet, parameters);
if (initialGraph != null) {
initialGraph = algorithm.search(dataSet, parameters);
} else {
throw new IllegalArgumentException("This EB algorithm needs both data and a graph source as inputs; it \n" + "will orient the edges in the input graph using the data.");
}
List<DataSet> dataSets = new ArrayList<>();
dataSets.add(DataUtils.getContinuousDataSet(dataSet));
Lofs2 lofs = new Lofs2(initialGraph, dataSets);
lofs.setRule(Lofs2.Rule.EB);
return lofs.orient();
} else {
EB eb = new EB(algorithm);
if (initialGraph != null) {
eb.setInitialGraph(initialGraph);
}
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, eb, parameters.getInt("bootstrapSampleSize"));
BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
switch(parameters.getInt("bootstrapEnsemble", 1)) {
case 0:
edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
break;
case 1:
edgeEnsemble = BootstrapEdgeEnsemble.Highest;
break;
case 2:
edgeEnsemble = BootstrapEdgeEnsemble.Majority;
}
search.setEdgeEnsemble(edgeEnsemble);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
}
}
Aggregations