use of edu.cmu.tetrad.search.IndTestScore in project tetrad by cmu-phil.
the class TestAutisticClassification method testForBiwei.
// @Test
public void testForBiwei() {
Parameters parameters = new Parameters();
parameters.set("penaltyDiscount", 2);
parameters.set("depth", -1);
parameters.set("numRuns", 10);
parameters.set("randomSelectionSize", 1);
parameters.set("Structure", "Placeholder");
FaskGraphs files = new FaskGraphs("/Users/jdramsey/Downloads/USM_ABIDE", new Parameters());
List<DataSet> datasets = files.getDatasets();
List<String> filenames = files.getFilenames();
for (int i = 0; i < datasets.size(); i++) {
DataSet dataSet = datasets.get(i);
SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet));
Fas fas = new Fas(new IndTestScore(score));
Graph graph = fas.search();
System.out.println(graph);
List<Node> nodes = graph.getNodes();
StringBuilder b = new StringBuilder();
for (int j = 0; j < nodes.size(); j++) {
for (int k = 0; k < nodes.size(); k++) {
if (graph.isAdjacentTo(nodes.get(j), nodes.get(k))) {
b.append("1 ");
} else {
b.append("0 ");
}
}
b.append("\n");
}
try {
File dir = new File("/Users/jdramsey/Downloads/biwei/USM_ABIDE");
dir.mkdirs();
File file = new File(dir, filenames.get(i) + ".graph.txt");
PrintStream out = new PrintStream(file);
out.println(b);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
use of edu.cmu.tetrad.search.IndTestScore 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.search.IndTestScore in project tetrad by cmu-phil.
the class Pcd method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
IndTestScore test;
if (dataSet instanceof ICovarianceMatrix) {
SemBicScoreDeterministic score = new SemBicScoreDeterministic((ICovarianceMatrix) dataSet);
score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
score.setDeterminismThreshold(parameters.getDouble("determinismThreshold"));
test = new IndTestScore(score);
} else if (dataSet instanceof DataSet) {
SemBicScoreDeterministic score = new SemBicScoreDeterministic(new CovarianceMatrix((DataSet) dataSet));
score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
score.setDeterminismThreshold(parameters.getDouble("determinismThreshold"));
test = new IndTestScore(score);
} else {
throw new IllegalArgumentException("Expecting a dataset or a covariance matrix.");
}
edu.cmu.tetrad.search.Pcd search = new edu.cmu.tetrad.search.Pcd(test);
search.setDepth(parameters.getInt("depth"));
search.setKnowledge(knowledge);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
} else {
Pcd algorithm = new Pcd();
// algorithm.setKnowledge(knowledge);
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, 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.search.IndTestScore in project tetrad by cmu-phil.
the class SemBicDTest method getTest.
@Override
public IndependenceTest getTest(DataModel dataSet, Parameters parameters) {
SemBicScoreDeterministic score = new SemBicScoreDeterministic(new CovarianceMatrix((ICovarianceMatrix) dataSet));
score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
return new IndTestScore(score, dataSet);
}
use of edu.cmu.tetrad.search.IndTestScore in project tetrad by cmu-phil.
the class ImagesPcStableMax method search.
@Override
public Graph search(List<DataModel> dataModels, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
List<DataSet> dataSets = new ArrayList<>();
for (DataModel dataModel : dataModels) {
dataSets.add((DataSet) dataModel);
}
SemBicScoreImages3 score = new SemBicScoreImages3(dataSets);
score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
IndependenceTest test = new IndTestScore(score);
PcStableMax search = new PcStableMax(test);
search.setUseHeuristic(parameters.getBoolean("useMaxPOrientationHeuristic"));
search.setMaxPathLength(parameters.getInt("maxPOrientationMaxPathLength"));
search.setKnowledge(knowledge);
search.setDepth(parameters.getInt("depth"));
return search.search();
} else {
ImagesPcStableMax imagesPcStableMax = new ImagesPcStableMax();
// imagesPcStableMax.setKnowledge(knowledge);
List<DataSet> datasets = new ArrayList<>();
for (DataModel dataModel : dataModels) {
datasets.add((DataSet) dataModel);
}
GeneralBootstrapTest search = new GeneralBootstrapTest(datasets, imagesPcStableMax, 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();
}
}
Aggregations