use of edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper in project tetrad by cmu-phil.
the class TestKunMeasurementError method TestCycles_Data_fMRI_FASK.
public void TestCycles_Data_fMRI_FASK() {
Parameters parameters = new Parameters();
parameters.set("numRuns", 20);
parameters.set("penaltyDiscount", 1);
parameters.set("depth", -1);
parameters.set("determinismThreshold", .1);
parameters.set("verbose", true);
parameters.set("symmetricFirstStep", false);
parameters.set("faithfulnessAssumed", false);
parameters.set("maxDegree", 100);
Statistics statistics = new Statistics();
// statistics.add(new ParameterColumn("determinismThreshold"));
statistics.add(new AdjacencyPrecision());
statistics.add(new AdjacencyRecall());
statistics.add(new ArrowheadPrecision());
statistics.add(new ArrowheadRecall());
Simulations simulations = new Simulations();
// String dir = "/Users/user/Downloads/Simul1_T500";
String dir = "/Users/user/Downloads/Simul1_T2000";
// String dir = "/Users/user/Downloads/Simul2_T500";
// String dir = "/Users/user/Downloads/Simul2_T2000";
simulations.add(new LoadContinuousDataAndSingleGraphKun(dir, "Cov_X"));
simulations.add(new LoadContinuousDataAndSingleGraphKun(dir, "Cov_tilde"));
simulations.add(new LoadContinuousDataAndSingleGraphKun(dir, "Cov_tilde_hat"));
//
Algorithms algorithms = new Algorithms();
IndependenceWrapper test = new SemBicTest();
ScoreWrapper score = new SemBicScore();
algorithms.add(new Pc(test));
algorithms.add(new Fges(score));
algorithms.add(new Pcd());
algorithms.add(new FgesD());
Comparison comparison = new Comparison();
comparison.setShowAlgorithmIndices(true);
comparison.setShowSimulationIndices(true);
comparison.setSortByUtility(false);
comparison.setShowUtilities(false);
comparison.setParallelized(false);
comparison.setSaveGraphs(false);
comparison.setTabDelimitedTables(false);
comparison.compareFromSimulations("comparison", simulations, algorithms, statistics, parameters);
}
use of edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper in project tetrad by cmu-phil.
the class TimeoutComparison method configuration.
/**
*/
public void configuration(String path) {
try {
new File(path).mkdirs();
PrintStream out = new PrintStream(new FileOutputStream(new File(path, "Configuration.txt")));
Parameters allParams = new Parameters();
List<Class> algorithms = new ArrayList<>();
List<Class> statistics = new ArrayList<>();
List<Class> independenceWrappers = new ArrayList<>();
List<Class> scoreWrappers = new ArrayList<>();
List<Class> simulations = new ArrayList<>();
algorithms.addAll(getClasses(Algorithm.class));
statistics.addAll(getClasses(Statistic.class));
independenceWrappers.addAll(getClasses(IndependenceWrapper.class));
scoreWrappers.addAll(getClasses(ScoreWrapper.class));
simulations.addAll(getClasses(Simulation.class));
out.println("Available Algorithms:");
out.println();
out.println("Algorithms that take an independence test (using an example independence test):");
out.println();
for (Class clazz : new ArrayList<>(algorithms)) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == IndependenceWrapper.class) {
Algorithm algorithm = (Algorithm) constructor.newInstance(FisherZ.class.newInstance());
out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(algorithm.getParameters(), allParams, out);
}
if (TakesInitialGraph.class.isAssignableFrom(clazz)) {
out.println("\t" + clazz.getSimpleName() + " can take an initial graph from some other algorithm as input");
}
}
}
}
out.println();
out.println("Algorithms that take a score (using an example score):");
out.println();
for (Class clazz : new ArrayList<>(algorithms)) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == ScoreWrapper.class) {
Algorithm algorithm = (Algorithm) constructor.newInstance(BdeuScore.class.newInstance());
out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(algorithm.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Algorithms with blank constructor:");
out.println();
for (Class clazz : new ArrayList<>(algorithms)) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
Algorithm algorithm = (Algorithm) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(algorithm.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Available Statistics:");
out.println();
for (Class clazz : statistics) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
Statistic statistic = (Statistic) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + statistic.getDescription());
}
}
}
out.println();
out.println("Available Independence Tests:");
out.println();
for (Class clazz : independenceWrappers) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
IndependenceWrapper independence = (IndependenceWrapper) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + independence.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(independence.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Available Scores:");
out.println();
for (Class clazz : scoreWrappers) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
ScoreWrapper score = (ScoreWrapper) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + score.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(score.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Available Simulations:");
out.println();
for (Class clazz : simulations) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
Simulation simulation = (Simulation) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + simulation.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(simulation.getParameters(), allParams, out);
}
}
}
}
out.println();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper in project tetrad by cmu-phil.
the class AlgorithmFactory method create.
public static Algorithm create(Class<? extends Algorithm> algoClass, Class<? extends IndependenceWrapper> indTestClass, Class<? extends ScoreWrapper> scoreClass) throws IllegalAccessException, InstantiationException {
if (algoClass == null) {
throw new IllegalArgumentException("Algorithm class cannot be null.");
}
IndependenceWrapper test = (indTestClass == null) ? null : indTestClass.newInstance();
ScoreWrapper score = (scoreClass == null) ? null : scoreClass.newInstance();
return create(algoClass, test, score);
}
use of edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper in project tetrad by cmu-phil.
the class Comparison method configuration.
/**
*/
public void configuration(String path) {
try {
new File(path).mkdirs();
PrintStream out = new PrintStream(new FileOutputStream(new File(path, "Configuration.txt")));
Parameters allParams = new Parameters();
List<Class> algorithms = new ArrayList<>();
List<Class> statistics = new ArrayList<>();
List<Class> independenceWrappers = new ArrayList<>();
List<Class> scoreWrappers = new ArrayList<>();
List<Class> simulations = new ArrayList<>();
algorithms.addAll(getClasses(Algorithm.class));
statistics.addAll(getClasses(Statistic.class));
independenceWrappers.addAll(getClasses(IndependenceWrapper.class));
scoreWrappers.addAll(getClasses(ScoreWrapper.class));
simulations.addAll(getClasses(Simulation.class));
out.println("Available Algorithms:");
out.println();
out.println("Algorithms that take an independence test (using an example independence test):");
out.println();
for (Class clazz : new ArrayList<>(algorithms)) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == IndependenceWrapper.class) {
Algorithm algorithm = (Algorithm) constructor.newInstance(FisherZ.class.newInstance());
out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(algorithm.getParameters(), allParams, out);
}
if (TakesInitialGraph.class.isAssignableFrom(clazz)) {
out.println("\t" + clazz.getSimpleName() + " can take an initial graph from some other algorithm as input");
}
}
}
}
out.println();
out.println("Algorithms that take a score (using an example score):");
out.println();
for (Class clazz : new ArrayList<>(algorithms)) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == ScoreWrapper.class) {
Algorithm algorithm = (Algorithm) constructor.newInstance(BdeuScore.class.newInstance());
out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(algorithm.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Algorithms with blank constructor:");
out.println();
for (Class clazz : new ArrayList<>(algorithms)) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
Algorithm algorithm = (Algorithm) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(algorithm.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Available Statistics:");
out.println();
for (Class clazz : statistics) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
Statistic statistic = (Statistic) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + statistic.getDescription());
}
}
}
out.println();
out.println("Available Independence Tests:");
out.println();
for (Class clazz : independenceWrappers) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
IndependenceWrapper independence = (IndependenceWrapper) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + independence.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(independence.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Available Scores:");
out.println();
for (Class clazz : scoreWrappers) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
ScoreWrapper score = (ScoreWrapper) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + score.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(score.getParameters(), allParams, out);
}
}
}
}
out.println();
out.println("Available Simulations:");
out.println();
for (Class clazz : simulations) {
if (Experimental.class.isAssignableFrom(clazz)) {
continue;
}
Constructor[] constructors = clazz.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
Simulation simulation = (Simulation) constructor.newInstance();
out.println(clazz.getSimpleName() + ": " + simulation.getDescription());
if (HasParameters.class.isAssignableFrom(clazz)) {
printParameters(simulation.getParameters(), allParams, out);
}
}
}
}
out.println();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper in project tetrad by cmu-phil.
the class TestFges method clarkTest.
@Test
public void clarkTest() {
RandomGraph randomGraph = new RandomForward();
Simulation simulation = new LinearFisherModel(randomGraph);
Parameters parameters = new Parameters();
parameters.set("numMeasures", 100);
parameters.set("numLatents", 0);
parameters.set("coefLow", 0.2);
parameters.set("coefHigh", 0.8);
parameters.set("avgDegree", 2);
parameters.set("maxDegree", 100);
parameters.set("maxIndegree", 100);
parameters.set("maxOutdegree", 100);
parameters.set("connected", false);
parameters.set("numRuns", 1);
parameters.set("differentGraphs", false);
parameters.set("sampleSize", 1000);
parameters.set("faithfulnessAssumed", false);
parameters.set("maxDegree", -1);
parameters.set("verbose", false);
parameters.set("alpha", 0.01);
simulation.createData(parameters);
DataSet dataSet = (DataSet) simulation.getDataModel(0);
Graph trueGraph = simulation.getTrueGraph(0);
// trueGraph = SearchGraphUtils.patternForDag(trueGraph);
ScoreWrapper score = new edu.cmu.tetrad.algcomparison.score.SemBicScore();
IndependenceWrapper test = new FisherZ();
Algorithm fges = new edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges(score, false);
Graph fgesGraph = fges.search(dataSet, parameters);
clarkTestForAlpha(0.05, parameters, dataSet, trueGraph, fgesGraph, test);
clarkTestForAlpha(0.01, parameters, dataSet, trueGraph, fgesGraph, test);
}
Aggregations