use of edu.cmu.tetrad.algcomparison.simulation.Simulation in project tetrad by cmu-phil.
the class Comparison method printStats.
private void printStats(double[][][] statTables, Statistics statistics, Mode mode, int[] newOrder, List<AlgorithmSimulationWrapper> algorithmSimulationWrappers, List<AlgorithmWrapper> algorithmWrappers, List<SimulationWrapper> simulationWrappers, double[] utilities, Parameters parameters) {
if (mode == Mode.Average) {
out.println("AVERAGE STATISTICS");
} else if (mode == Mode.StandardDeviation) {
out.println("STANDARD DEVIATIONS");
} else if (mode == Mode.WorstCase) {
out.println("WORST CASE");
} else {
throw new IllegalStateException();
}
int numTables = statTables.length;
int numStats = statistics.size();
NumberFormat nf = new DecimalFormat("0.00");
NumberFormat smallNf = new DecimalFormat("0.00E0");
out.println();
for (int u = 0; u < numTables; u++) {
if (!graphTypeUsed[u])
continue;
int rows = algorithmSimulationWrappers.size() + 1;
int cols = (isShowSimulationIndices() ? 1 : 0) + (isShowAlgorithmIndices() ? 1 : 0) + numStats + (isShowUtilities() ? 1 : 0);
TextTable table = new TextTable(rows, cols);
table.setTabDelimited(isTabDelimitedTables());
int initialColumn = 0;
if (isShowSimulationIndices()) {
table.setToken(0, initialColumn, "Sim");
for (int t = 0; t < algorithmSimulationWrappers.size(); t++) {
Simulation simulation = algorithmSimulationWrappers.get(newOrder[t]).getSimulationWrapper();
table.setToken(t + 1, initialColumn, "" + (simulationWrappers.indexOf(simulation) + 1));
}
initialColumn++;
}
if (isShowAlgorithmIndices()) {
table.setToken(0, initialColumn, "Alg");
for (int t = 0; t < algorithmSimulationWrappers.size(); t++) {
AlgorithmWrapper algorithm = algorithmSimulationWrappers.get(newOrder[t]).getAlgorithmWrapper();
table.setToken(t + 1, initialColumn, "" + (algorithmWrappers.indexOf(algorithm) + 1));
}
initialColumn++;
}
for (int statIndex = 0; statIndex < numStats; statIndex++) {
String statLabel = statistics.getStatistics().get(statIndex).getAbbreviation();
table.setToken(0, initialColumn + statIndex, statLabel);
}
if (isShowUtilities()) {
table.setToken(0, initialColumn + numStats, "U");
}
for (int t = 0; t < algorithmSimulationWrappers.size(); t++) {
for (int statIndex = 0; statIndex < numStats; statIndex++) {
Statistic statistic = statistics.getStatistics().get(statIndex);
final AlgorithmWrapper algorithmWrapper = algorithmSimulationWrappers.get(newOrder[t]).getAlgorithmWrapper();
final SimulationWrapper simulationWrapper = algorithmSimulationWrappers.get(newOrder[t]).getSimulationWrapper();
Algorithm algorithm = algorithmWrapper.getAlgorithm();
Simulation simulation = simulationWrapper.getSimulation();
if (algorithm instanceof HasParameterValues) {
parameters.putAll(((HasParameterValues) algorithm).getParameterValues());
}
if (simulation instanceof HasParameterValues) {
parameters.putAll(((HasParameterValues) simulation).getParameterValues());
}
final String abbreviation = statistic.getAbbreviation();
Object[] o = parameters.getValues(abbreviation);
if (o.length == 1 && o[0] instanceof String) {
table.setToken(t + 1, initialColumn + statIndex, (String) o[0]);
continue;
}
double stat = statTables[u][newOrder[t]][statIndex];
if (stat == 0.0) {
table.setToken(t + 1, initialColumn + statIndex, "-");
} else if (stat == Double.POSITIVE_INFINITY) {
table.setToken(t + 1, initialColumn + statIndex, "Yes");
} else if (stat == Double.NEGATIVE_INFINITY) {
table.setToken(t + 1, initialColumn + statIndex, "No");
} else if (Double.isNaN(stat)) {
table.setToken(t + 1, initialColumn + statIndex, "*");
} else {
table.setToken(t + 1, initialColumn + statIndex, Math.abs(stat) < Math.pow(10, -smallNf.getMaximumFractionDigits()) && stat != 0 ? smallNf.format(stat) : nf.format(stat));
}
}
if (isShowUtilities()) {
table.setToken(t + 1, initialColumn + numStats, nf.format(utilities[newOrder[t]]));
}
}
out.println(getHeader(u));
out.println();
out.println(table);
}
}
use of edu.cmu.tetrad.algcomparison.simulation.Simulation 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