use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class ExampleCompareFromFiles method main.
public static void main(String... args) {
Parameters parameters = new Parameters();
// Can leave the simulation parameters out since
// we're loading from file here.
parameters.set("alpha", 1e-4);
parameters.set("numRuns", 10);
Statistics statistics = new Statistics();
statistics.add(new ParameterColumn("avgDegree"));
statistics.add(new ParameterColumn("sampleSize"));
statistics.add(new AdjacencyPrecision());
statistics.add(new AdjacencyRecall());
statistics.add(new ArrowheadPrecision());
statistics.add(new ArrowheadRecall());
statistics.add(new MathewsCorrAdj());
statistics.add(new MathewsCorrArrow());
statistics.add(new F1Adj());
statistics.add(new F1Arrow());
statistics.add(new SHD());
statistics.add(new ElapsedTime());
statistics.setWeight("AP", 1.0);
statistics.setWeight("AR", 0.5);
statistics.setWeight("AHP", 1.0);
statistics.setWeight("AHR", 0.5);
Algorithms algorithms = new Algorithms();
algorithms.add(new Pc(new FisherZ()));
algorithms.add(new Cpc(new FisherZ()));
algorithms.add(new PcStable(new FisherZ()));
algorithms.add(new CpcStable(new FisherZ()));
Comparison comparison = new Comparison();
comparison.setShowAlgorithmIndices(false);
comparison.setShowSimulationIndices(false);
comparison.setSortByUtility(true);
comparison.setShowUtilities(true);
comparison.setParallelized(true);
comparison.compareFromFiles("comparison", algorithms, statistics, parameters);
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class ExampleCompareSimulationTimeSeries method main.
public static void main(String... args) {
Parameters parameters = new Parameters();
parameters.set("numRuns", 10);
parameters.set("numMeasures", 10);
parameters.set("avgDegree", 4);
parameters.set("sampleSize", 500);
parameters.set("alpha", 1e-4, 1e-3, 1e-2);
Statistics statistics = new Statistics();
statistics.add(new AdjacencyPrecision());
statistics.add(new AdjacencyRecall());
statistics.add(new ArrowheadPrecision());
statistics.add(new ArrowheadRecall());
statistics.add(new MathewsCorrAdj());
statistics.add(new MathewsCorrArrow());
statistics.add(new F1Adj());
statistics.add(new F1Arrow());
statistics.add(new SHD());
statistics.add(new ElapsedTime());
statistics.setWeight("AP", 1.0);
statistics.setWeight("AR", 0.5);
Algorithms algorithms = new Algorithms();
algorithms.add(new TsFci(new FisherZ()));
algorithms.add(new TsGfci(new FisherZ(), new SemBicScore()));
algorithms.add(new TsImages(new SemBicScore()));
Simulations simulations = new Simulations();
simulations.add(new TimeSeriesSemSimulation(new RandomForward()));
Comparison comparison = new Comparison();
comparison.setSortByUtility(true);
comparison.setShowUtilities(true);
comparison.compareFromSimulations("comparison", simulations, algorithms, statistics, parameters);
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class ExampleSave method main.
public static void main(String... args) {
Parameters parameters = new Parameters();
parameters.set("numRuns", 10);
parameters.set("numMeasures", 100);
parameters.set("avgDegree", 4);
parameters.set("sampleSize", 100, 500, 1000);
Simulation simulation = new SemSimulation(new RandomForward());
Comparison comparison = new Comparison();
comparison.setShowAlgorithmIndices(true);
comparison.saveToFiles("comparison", simulation, parameters);
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class FgesMbRunner 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());
String targetName = getParams().getString("targetName", null);
Object model = getDataModel();
if (model == null && getSourceGraph() != null) {
model = getSourceGraph();
}
if (model == null) {
throw new RuntimeException("Data source is unspecified. You may need to double click all your data boxes, \n" + "then click Save, and then right click on them and select Propagate Downstream. \n" + "The issue is that we use a seed to simulate from IM's, so your data is not saved to \n" + "file when you save the session. It can, however, be recreated from the saved seed.");
}
Parameters params = getParams();
Node target = null;
if (model instanceof Graph) {
GraphScore gesScore = new GraphScore((Graph) model);
target = gesScore.getVariable(targetName);
fges = new FgesMb(gesScore);
fges.setKnowledge((IKnowledge) getParams().get("knowledge", new Knowledge2()));
fges.setNumPatternsToStore(params.getInt("numPatternsToSave", 1));
fges.setVerbose(true);
} else if (model instanceof DataSet) {
DataSet dataSet = (DataSet) model;
if (dataSet.isContinuous()) {
SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly((DataSet) model));
target = score.getVariable(targetName);
score.setPenaltyDiscount(params.getDouble("penaltyDiscount", 4));
fges = new FgesMb(score);
} else if (dataSet.isDiscrete()) {
// ((Parameters) getParameters()).getSamplePrior();
double samplePrior = 1;
// ((Parameters) getParameters()).getStructurePrior();
double structurePrior = 1;
BDeuScore score = new BDeuScore(dataSet);
score.setSamplePrior(samplePrior);
score.setStructurePrior(structurePrior);
target = score.getVariable(targetName);
fges = new FgesMb(score);
} else {
throw new IllegalStateException("Data set must either be continuous or discrete.");
}
} else if (model instanceof ICovarianceMatrix) {
SemBicScore gesScore = new SemBicScore((ICovarianceMatrix) model);
gesScore.setPenaltyDiscount(params.getDouble("alpha", 0.001));
gesScore.setPenaltyDiscount(params.getDouble("penaltyDiscount", 4));
target = gesScore.getVariable(targetName);
fges = new FgesMb(gesScore);
} else if (model instanceof DataModelList) {
DataModelList list = (DataModelList) model;
for (DataModel dataModel : list) {
if (!(dataModel instanceof DataSet || dataModel instanceof ICovarianceMatrix)) {
throw new IllegalArgumentException("Need a combination of all continuous data sets or " + "covariance matrices, or else all discrete data sets, or else a single initialGraph.");
}
}
if (allContinuous(list)) {
double penalty = getParams().getDouble("penaltyDiscount", 4);
if (params.getBoolean("firstNontriangular", false)) {
SemBicScoreImages fgesScore = new SemBicScoreImages(list);
fgesScore.setPenaltyDiscount(penalty);
target = fgesScore.getVariable(targetName);
fges = new FgesMb(fgesScore);
} else {
SemBicScoreImages fgesScore = new SemBicScoreImages(list);
fgesScore.setPenaltyDiscount(penalty);
target = fgesScore.getVariable(targetName);
fges = new FgesMb(fgesScore);
}
} else if (allDiscrete(list)) {
double structurePrior = getParams().getDouble("structurePrior", 1);
double samplePrior = getParams().getDouble("samplePrior", 1);
BdeuScoreImages fgesScore = new BdeuScoreImages(list);
fgesScore.setSamplePrior(samplePrior);
fgesScore.setStructurePrior(structurePrior);
target = fgesScore.getVariable(targetName);
if (params.getBoolean("firstNontriangular", false)) {
fges = new FgesMb(fgesScore);
} else {
fges = new FgesMb(fgesScore);
}
} else {
throw new IllegalArgumentException("Data must be either all discrete or all continuous.");
}
} else {
System.out.println("No viable input.");
}
// Graph searchGraph;
//
// if (true) {
// DataModel dataModel = getDataModelList().getSelectedModel();
// ICovarianceMatrix cov;
// Node target;
// FgesMb fges;
//
// if (dataModel instanceof DataSet) {
// DataSet dataSet = (DataSet) dataModel;
// target = dataSet.getVariable(targetName);
//
// if (dataSet.isContinuous()) {
// SemBicScore gesScore = new SemBicScore(new CovarianceMatrixOnTheFly((DataSet) dataModel),
// getParameters().getDepErrorsAlpha());
// fges = new FgesMb(gesScore, target);
// } else if (dataSet.isDiscrete()) {
// double structurePrior = 1;
// double samplePrior = getParameters().getDepErrorsAlpha();
// BDeuScore score = new BDeuScore(dataSet);
// score.setSamplePrior(samplePrior);
// score.setStructurePrior(structurePrior);
// fges = new FgesMb(score, target);
// } else {
// throw new IllegalStateException("Data set must either be continuous or discrete.");
// }
// } else if (dataModel instanceof ICovarianceMatrix) {
// cov = (ICovarianceMatrix) dataModel;
// SemBicScore score = new SemBicScore(cov,
// getParameters().getDepErrorsAlpha());
// target = cov.getVariable(targetName);
// fges = new FgesMb(score, target);
// } else {
// throw new IllegalArgumentException("Expecting a data set or a covariance matrix.");
// }
//
// fges.setVerbose(true);
// fges.setHeuristicSpeedup(true);
// searchGraph = fges.search();
// } else {
// Node target = getIndependenceTest().getVariable(targetName);
// System.out.println("Target = " + target);
//
// int depth = getParameters().getMaxDegree();
//
// ScoredIndTest fgesScore = new ScoredIndTest(getIndependenceTest());
// fgesScore.setParameter1(getParameters().getDepErrorsAlpha());
// FgesMb search = new FgesMb(fgesScore, target);
// search.setKnowledge(knowledge);
// search.setMaxDegree(depth);
// search.setVerbose(true);
// search.setHeuristicSpeedup(true);
// searchGraph = search.search();
// }
// if (getSourceGraph() != null) {
// GraphUtils.arrangeBySourceGraph(searchGraph, getSourceGraph());
// } else if (knowledge.isDefaultToKnowledgeLayout()) {
// SearchGraphUtils.arrangeByKnowledgeTiers(searchGraph, knowledge);
// } else {
// GraphUtils.circleLayout(searchGraph, 200, 200, 150);
// }
// fges.setInitialGraph(initialGraph);
fges.setKnowledge((IKnowledge) getParams().get("knowledge", new Knowledge2()));
fges.setNumPatternsToStore(params.getInt("numPatternsToSave", 1));
fges.setVerbose(true);
// fges.setHeuristicSpeedup(((Parameters) params.getIndTestParams()).isFaithfulnessAssumed());
fges.setMaxIndegree(params.getInt("depth", -1));
Graph graph = fges.search(target);
if (getSourceGraph() != null) {
GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
} else if (((IKnowledge) getParams().get("knowledge", new Knowledge2())).isDefaultToKnowledgeLayout()) {
SearchGraphUtils.arrangeByKnowledgeTiers(graph, (IKnowledge) getParams().get("knowledge", new Knowledge2()));
} else {
GraphUtils.circleLayout(graph, 200, 200, 150);
}
this.topGraphs = new ArrayList<>(fges.getTopGraphs());
if (topGraphs.isEmpty()) {
topGraphs.add(new ScoredGraph(getResultGraph(), Double.NaN));
}
setIndex(topGraphs.size() - 1);
setResultGraph(graph);
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class GlassoRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
Object dataModel = getDataModel();
Parameters params = getParams();
if (dataModel instanceof DataSet) {
DataSet dataSet = (DataSet) dataModel;
DoubleMatrix2D cov = new DenseDoubleMatrix2D(dataSet.getCovarianceMatrix().toArray());
Glasso glasso = new Glasso(cov);
glasso.setMaxit((int) params.get("maxit", 10000));
glasso.setIa(params.getBoolean("ia", false));
glasso.setIs(params.getBoolean("is", false));
glasso.setItr(params.getBoolean("itr", false));
glasso.setIpen(params.getBoolean("ipen", false));
glasso.setThr(params.getDouble("thr", 1e-4));
glasso.setRhoAllEqual(1.0);
Glasso.Result result = glasso.search();
TetradMatrix wwi = new TetradMatrix(result.getWwi().toArray());
List<Node> variables = dataSet.getVariables();
Graph resultGraph = new EdgeListGraph(variables);
for (int i = 0; i < variables.size(); i++) {
for (int j = i + 1; j < variables.size(); j++) {
if (wwi.get(i, j) != 0.0 && wwi.get(i, j) != 0.0) {
resultGraph.addUndirectedEdge(variables.get(i), variables.get(j));
}
}
}
setResultGraph(resultGraph);
}
}
Aggregations