use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper in project tetrad by cmu-phil.
the class TestFges method main.
public static void main(String... args) {
if (args.length > 0) {
int numMeasures = Integer.parseInt(args[0]);
int avgDegree = Integer.parseInt(args[1]);
Parameters parameters = new Parameters();
parameters.set("numMeasures", numMeasures);
parameters.set("numLatents", 0);
parameters.set("avgDegree", avgDegree);
parameters.set("maxDegree", 20);
parameters.set("maxIndegree", 20);
parameters.set("maxOutdegree", 20);
parameters.set("connected", false);
parameters.set("coefLow", 0.2);
parameters.set("coefHigh", 0.9);
parameters.set("varLow", 1);
parameters.set("varHigh", 3);
parameters.set("verbose", false);
parameters.set("coefSymmetric", true);
parameters.set("numRuns", 1);
parameters.set("percentDiscrete", 0);
parameters.set("numCategories", 3);
parameters.set("differentGraphs", true);
parameters.set("sampleSize", 1000);
parameters.set("intervalBetweenShocks", 10);
parameters.set("intervalBetweenRecordings", 10);
parameters.set("fisherEpsilon", 0.001);
parameters.set("randomizeColumns", true);
RandomGraph graph = new RandomForward();
LinearFisherModel sim = new LinearFisherModel(graph);
sim.createData(parameters);
ScoreWrapper score = new FisherZScore();
Algorithm alg = new edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges(score);
parameters.set("alpha", 1e-8);
for (int i = 0; i < 5; i++) {
Graph out1 = alg.search(sim.getDataModel(0), parameters);
System.out.println(out1);
}
} else {
new TestFges().test9();
}
}
use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper 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.score.ScoreWrapper 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.score.ScoreWrapper 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.score.ScoreWrapper 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();
}
}
Aggregations