From 5a205f2a69252d4dbc624d05cefb59d631746e08 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Mon, 13 Jun 2016 05:04:04 -0400 Subject: [PATCH] Revert "Committing algcomparison stuff to this branch." --- causal-cmd/causal-cmd.iml | 7 +- .../cmu/tetrad/algcomparison/Algorithm.java | 17 - .../cmu/tetrad/algcomparison/Comparison.java | 584 ------------------ .../java/edu/cmu/tetrad/algcomparison/README | 7 - .../cmu/tetrad/algcomparison/Simulation.java | 21 - .../continuous/cyclic_pag/ContinuousCcd.java | 29 - .../continuous/pag/ContinuousCfci.java | 29 - .../continuous/pag/ContinuousFci.java | 27 - .../continuous/pag/ContinuousGfci.java | 29 - .../continuous/pag/ContinuousRfci.java | 27 - .../continuous/pattern/ContinuousCpc.java | 26 - .../continuous/pattern/ContinuousFgs.java | 28 - .../continuous/pattern/ContinuousMmhc.java | 31 - .../continuous/pattern/ContinuousPc.java | 26 - .../continuous/pattern/ContinuousPcs.java | 26 - .../discrete/cyclic_pag/DiscreteCcd.java | 28 - .../discrete/pag/DiscreteCfci.java | 28 - .../discrete/pag/DiscreteFci.java | 28 - .../discrete/pag/DiscreteGfci.java | 29 - .../discrete/pag/DiscreteRfci.java | 30 - .../pattern/DiscreteCpcChiSquare.java | 30 - .../discrete/pattern/DiscreteCpcGSquare.java | 27 - .../discrete/pattern/DiscreteFgsBdeu.java | 32 - .../discrete/pattern/DiscreteFgsBic.java | 29 - .../discrete/pattern/DiscretePcChiSquare.java | 30 - .../discrete/pattern/DiscretePcGSquare.java | 27 - .../discrete/pattern/DiscretePcs.java | 27 - .../explorations/RunContinuousComparison.java | 120 ---- .../explorations/RunDiscreteComparison.java | 112 ---- .../explorations/RunMixedComparison.java | 130 ---- .../explorations/TestAJData.java | 98 --- .../algcomparison/mixed/pag/MixedFci.java | 31 - .../algcomparison/mixed/pag/MixedGfci.java | 28 - .../algcomparison/mixed/pag/MixedWgfci.java | 29 - .../mixed/pag/MixedWgfciFci.java | 33 - .../mixed/pattern/MixedBdeuFgs.java | 75 --- .../algcomparison/mixed/pattern/MixedCpc.java | 30 - .../mixed/pattern/MixedFgsMixedScore.java | 40 -- .../mixed/pattern/MixedFgsMixedScore2.java | 35 -- .../mixed/pattern/MixedMGMCpc.java | 38 -- .../mixed/pattern/MixedMGMFgs.java | 70 --- .../mixed/pattern/MixedMGMPc.java | 41 -- .../algcomparison/mixed/pattern/MixedPc.java | 28 - .../algcomparison/mixed/pattern/MixedPcs.java | 30 - .../mixed/pattern/MixedSemFgs.java | 62 -- .../mixed/pattern/MixedWfgs.java | 28 - .../mixed/pattern/MixedWfgsCpc.java | 33 - .../ContinuousCyclicSemSimulation.java | 51 -- ...tinuousNonlinearNongaussianSimulation.java | 131 ---- .../DiscreteBayesNetSimulation.java | 55 -- .../LinearGaussianSemSimulation.java | 56 -- .../simulation/MixedLeeHastieSimulation.java | 74 --- .../MixedSemThenDiscretizeHalfSimulation.java | 68 -- .../edu/cmu/tetrad/search/MixedBicScore2.java | 402 ------------ 54 files changed, 5 insertions(+), 3182 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Algorithm.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/README delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Simulation.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/cyclic_pag/ContinuousCcd.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousCfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousFci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousGfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousRfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousCpc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousFgs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousMmhc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPcs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/cyclic_pag/DiscreteCcd.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteCfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteFci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteGfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteRfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcChiSquare.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcGSquare.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBdeu.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBic.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcChiSquare.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcGSquare.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunContinuousComparison.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunDiscreteComparison.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunMixedComparison.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/TestAJData.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedFci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedGfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfciFci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedBdeuFgs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedCpc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore2.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMCpc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMFgs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMPc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPcs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedSemFgs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgsCpc.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousCyclicSemSimulation.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousNonlinearNongaussianSimulation.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/DiscreteBayesNetSimulation.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearGaussianSemSimulation.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedLeeHastieSimulation.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedSemThenDiscretizeHalfSimulation.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/MixedBicScore2.java diff --git a/causal-cmd/causal-cmd.iml b/causal-cmd/causal-cmd.iml index b14567c19f..810a18e556 100644 --- a/causal-cmd/causal-cmd.iml +++ b/causal-cmd/causal-cmd.iml @@ -3,18 +3,21 @@ + - + + + + - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Algorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Algorithm.java deleted file mode 100644 index 8852bdb61e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Algorithm.java +++ /dev/null @@ -1,17 +0,0 @@ -package edu.cmu.tetrad.algcomparison; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public interface Algorithm { - Graph search(DataSet dataSet, Map parameters); - - Graph getComparisonGraph(Graph dag); - - String getDescription(); -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java deleted file mode 100644 index 6c915ce7d9..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java +++ /dev/null @@ -1,584 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.algcomparison; - -import edu.cmu.tetrad.data.ContinuousVariable; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DiscreteVariable; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.io.PrintStream; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.*; - -/** - * @author Joseph Ramsey - */ -public class Comparison { - private boolean[] graphTypeUsed; - private PrintStream out; - - private Graph getSubgraph(Graph graph, boolean discrete1, boolean discrete2, DataSet dataSet) { - if (discrete1 && discrete2) { - Graph newGraph = new EdgeListGraph(graph.getNodes()); - - for (Edge edge : graph.getEdges()) { - Node node1 = dataSet.getVariable(edge.getNode1().getName()); - Node node2 = dataSet.getVariable(edge.getNode2().getName()); - - if (node1 instanceof DiscreteVariable && - node2 instanceof DiscreteVariable) { - newGraph.addEdge(edge); - } - } - - return newGraph; - } else if (!discrete1 && !discrete2) { - Graph newGraph = new EdgeListGraph(graph.getNodes()); - - for (Edge edge : graph.getEdges()) { - Node node1 = dataSet.getVariable(edge.getNode1().getName()); - Node node2 = dataSet.getVariable(edge.getNode2().getName()); - - if (node1 instanceof ContinuousVariable && - node2 instanceof ContinuousVariable) { - newGraph.addEdge(edge); - } - } - - return newGraph; - } else { - Graph newGraph = new EdgeListGraph(graph.getNodes()); - - for (Edge edge : graph.getEdges()) { - Node node1 = dataSet.getVariable(edge.getNode1().getName()); - Node node2 = dataSet.getVariable(edge.getNode2().getName()); - - if (node1 instanceof DiscreteVariable && - node2 instanceof ContinuousVariable) { - newGraph.addEdge(edge); - } - - if (node2 instanceof ContinuousVariable && - node1 instanceof DiscreteVariable) { - newGraph.addEdge(edge); - } - } - - return newGraph; - } - } - - public void testBestAlgorithms(Map _parameters, Map stats, - List algorithms, Simulation simulation, PrintStream out) { - Map parameters = new LinkedHashMap<>(); - parameters.put("numMeasures", 100); - parameters.put("numEdges", 100); - parameters.put("numLatents", 0); - parameters.put("maxDegree", 10); - parameters.put("maxIndegree", 10); - parameters.put("maxOutdegree", 10); - parameters.put("connected", 0); - parameters.put("sampleSize", 1000); - parameters.put("numRuns", 5); - parameters.put("alpha", 0.001); - parameters.put("penaltyDiscount", 4); - - parameters.put("percentDiscreteForMixedSimulation", 50); - parameters.put("ofInterestCutoff", 0.05); - - parameters.putAll(_parameters); - - this.out = out; - double[][][] allRet = printStats(algorithms, stats, parameters, simulation); - - - System.out.println(); - out.println("Algorithms:"); - out.println(); - - for (int i = 0; i < algorithms.size(); i++) { - out.println((i + 1) + ". " + algorithms.get(i).getDescription()); - } - - out.println(); - out.println("Statistics:"); - out.println(); - - for (String stat : stats.keySet()) { - out.println(stat + " = " + stats.get(stat)); - } - - out.println(); - out.println("Parameters:"); - out.println(); - - for (String param : parameters.keySet()) { - out.println(param + " = " + parameters.get(param)); - } - - out.println(); - out.println("Simulation:"); - out.println(); - out.println(simulation); - out.println(); - - printBestStats(allRet, algorithms, stats, parameters, simulation); - - out.close(); - } - - private double[][][] printStats(List algorithms, Map stats, - Map parameters, Simulation simulation) { - int numGraphTypes = 4; - - graphTypeUsed = new boolean[4]; - - NumberFormat nf = new DecimalFormat("0.00"); - - double[][][] statSums = new double[algorithms.size()][stats.size()][4]; - int[][][] countStat = new int[algorithms.size()][stats.size()][4]; - - for (int i = 0; i < parameters.get("numRuns").intValue(); i++) { - System.out.println(); - System.out.println("Run " + (i + 1)); - System.out.println(); - - simulation.simulate(parameters); - Graph dag = simulation.getDag(); - DataSet data = simulation.getData(); - - boolean isMixed = data.isMixed(); - - for (int t = 0; t < algorithms.size(); t++) { - System.out.println((t + 1) + ". " + algorithms.get(t).getDescription()); - - long start = System.currentTimeMillis(); - - Graph out = algorithms.get(t).search(data, parameters); - - long stop = System.currentTimeMillis(); - - long elapsed = stop - start; - - out = GraphUtils.replaceNodes(out, dag.getNodes()); - - Graph[] est = new Graph[numGraphTypes]; - - Graph comparisonGraph = algorithms.get(t).getComparisonGraph(dag); - dag = GraphUtils.replaceNodes(dag, out.getNodes()); - - est[0] = out; - graphTypeUsed[0] = true; - - if (isMixed) { - est[1] = getSubgraph(out, true, true, data); - est[2] = getSubgraph(out, true, false, data); - est[3] = getSubgraph(out, false, false, data); - - graphTypeUsed[1] = true; - graphTypeUsed[2] = true; - graphTypeUsed[3] = true; - } - - Graph[] truth = new Graph[numGraphTypes]; - - truth[0] = comparisonGraph; - - if (isMixed) { - truth[1] = getSubgraph(comparisonGraph, true, true, data); - truth[2] = getSubgraph(comparisonGraph, true, false, data); - truth[3] = getSubgraph(comparisonGraph, false, false, data); - } - - for (int u = 0; u < numGraphTypes; u++) { - if (!graphTypeUsed[u]) continue; - - EdgeStats edgeStats = new EdgeStats(est[u], truth[u], elapsed).invoke(); - - int j = -1; - - for (String statName : stats.keySet()) { - j++; - double stat = edgeStats.getStat(statName); - - if (!Double.isNaN(stat)) { - statSums[t][j][u] += stat; - countStat[t][j][u]++; - } - } - } - } - } - - double[][][] avgStat = new double[algorithms.size()][stats.size()][numGraphTypes]; - - for (int t = 0; t < algorithms.size(); t++) { - for (int u = 0; u < 4; u++) { - for (int j = 0; j < stats.size(); j++) { - avgStat[t][j][u] = statSums[t][j][u] / (double) countStat[t][j][u]; - } - } - } - - return avgStat; - } - - private String getHeader(int u) { - String header; - - switch (u) { - case 0: - header = "All edges"; - break; - case 1: - header = "Discrete-discrete"; - break; - case 2: - header = "Discrete-continuous"; - break; - case 3: - header = "Continuous-continuous"; - break; - default: - throw new IllegalStateException(); - } - return header; - } - - private void printBestStats(double[][][] allAllRet, List algorithms, Map stats, - Map parameters, Simulation simulation) { - class Pair { - private int algorithm; - private double stat; - - public Pair(int algorithm, double stat) { - this.algorithm = algorithm; - this.stat = stat; - } - - public int getAlgorithm() { - return algorithm; - } - - public double getStat() { - return stat; - } - } - - out.println("And the winners are... !"); - - if (simulation.isMixed()) { - for (int u = 0; u < 4; u++) { - out.println(); - - out.println("====== " + getHeader(u) + - " (listing high to low, top to top - " + - parameters.get("ofInterestCutoff").doubleValue() + ")"); - - out.println(); - Set keySet = stats.keySet(); - int statIndex = -1; - - for (String statName : keySet) { - String maxAlg; - statIndex++; - - List algStats = new ArrayList<>(); - - for (int t = 0; t < algorithms.size(); t++) { - double stat = allAllRet[t][statIndex][u]; - if (!Double.isNaN(stat)) { - algStats.add(new Pair(t + 1, stat)); - } - } - - if (algStats.isEmpty()) { - maxAlg = "-"; - } else { - Collections.sort(algStats, new Comparator() { - - @Override - public int compare(Pair o1, Pair o2) { - return -Double.compare(o1.getStat(), o2.getStat()); - } - }); - - double maxStat = algStats.get(0).getStat(); - maxAlg = "" + algStats.get(0).getAlgorithm()/*.getName()*/; - double ofInterest = maxStat - parameters.get("ofInterestCutoff").doubleValue(); - - for (int i = 1; i < algStats.size(); i++) { - if (algStats.get(i).getStat() == algStats.get(i - 1).getStat()) { - maxAlg += "==" + algStats.get(i).getAlgorithm()/*.getName()*/; - } else if (algStats.get(i).getStat() >= ofInterest) { - maxAlg += "," + algStats.get(i).getAlgorithm()/*.getName()*/; - } else { - break; - } - } - } - - out.println(statName + ": " + maxAlg); - } - } - } else { - int u = 0; - out.println(); - - out.println("====== " + getHeader(u) + - " (listing high to low, top to top - " + - parameters.get("ofInterestCutoff").doubleValue() + ")"); - - out.println(); - Set keySet = stats.keySet(); - int statIndex = -1; - - for (String statName : keySet) { - String maxAlg; - statIndex++; - - List algStats = new ArrayList<>(); - - for (int t = 0; t < algorithms.size(); t++) { - double stat = allAllRet[t][statIndex][u]; - if (!Double.isNaN(stat)) { - algStats.add(new Pair(t + 1, stat)); - } - } - - if (algStats.isEmpty()) { - maxAlg = "-"; - } else { - Collections.sort(algStats, new Comparator() { - - @Override - public int compare(Pair o1, Pair o2) { - return -Double.compare(o1.getStat(), o2.getStat()); - } - }); - - double maxStat = algStats.get(0).getStat(); - maxAlg = "" + algStats.get(0).getAlgorithm()/*.getName()*/; - double ofInterest = maxStat - parameters.get("ofInterestCutoff").doubleValue(); - - for (int i = 1; i < algStats.size(); i++) { - if (algStats.get(i).getStat() == algStats.get(i - 1).getStat()) { - maxAlg += "==" + algStats.get(i).getAlgorithm(); - } else if (algStats.get(i).getStat() >= ofInterest) { - maxAlg += "," + algStats.get(i).getAlgorithm(); - } else { - break; - } - } - } - - out.println(statName + ": " + maxAlg); - } - } - - - NumberFormat nf = new DecimalFormat("0.00"); - - out.println(); - out.println("DETAILS:"); - out.println(); - out.println("AVERAGE STATISTICS"); - - for (int u = 0; u < 4; u++) { - if (!graphTypeUsed[u]) continue; - for (int t = 0; t < algorithms.size(); t++) { - String algorithm = "" + (t + 1); - out.println(); - - out.println(getHeader(u) + " Algorithm = " + algorithm); - out.println(); - Set keySet = stats.keySet(); - Iterator iterator = keySet.iterator(); - - for (int statIndex = 0; statIndex < stats.size(); statIndex++) { - String statLabel = iterator.next(); - double stat = allAllRet[t][statIndex][u]; - out.println("\tAverage " + statLabel + " = " + nf.format(stat)); - } - } - } - - } - - private class EdgeStats { - private Graph est; - private Graph truth; - private double adjPrecision; - private double adjRecall; - private double arrowPrecision; - private double arrowRecall; - private double mcAdj; - private double mcOr; - private double f1Adj; - private double f1Arrows; - private int shd; - private double elapsed; - - public EdgeStats(Graph est, Graph truth, long elapsed) { - this.est = est; - this.truth = GraphUtils.replaceNodes(truth, est.getNodes()); - this.elapsed = elapsed / 1000.0; - } - - public double getStat(String stat) { - switch (stat) { - case "AP": - return adjPrecision; - case "AR": - return adjRecall; - case "OP": - return arrowPrecision; - case "OR": - return arrowRecall; - case "McAdj": - return mcAdj; - case "McOr": - return mcOr; - case "F1Adj": - return f1Adj; - case "F1Or": - return f1Arrows; - case "SHD": - return -shd; - case "E": - return -elapsed; - default: - throw new IllegalArgumentException(); - } - } - - public EdgeStats invoke() { - int adjTp = 0; - int adjFp = 0; - int adjFn = 0; - int arrowsTp = 0; - int arrowsFp = 0; - int arrowsFn = 0; - - Set allUnoriented = new HashSet<>(); - for (Edge edge : truth.getEdges()) { - allUnoriented.add(Edges.undirectedEdge(edge.getNode1(), edge.getNode2())); - } - - for (Edge edge : est.getEdges()) { - allUnoriented.add(Edges.undirectedEdge(edge.getNode1(), edge.getNode2())); - } - - for (Edge edge : allUnoriented) { - if (est.isAdjacentTo(edge.getNode1(), edge.getNode2()) && - !truth.isAdjacentTo(edge.getNode1(), edge.getNode2())) { - adjFp++; - } - - if (truth.isAdjacentTo(edge.getNode1(), edge.getNode2()) && - !est.isAdjacentTo(edge.getNode1(), edge.getNode2())) { - adjFn++; - } - - if (truth.isAdjacentTo(edge.getNode1(), edge.getNode2()) && - est.isAdjacentTo(edge.getNode1(), edge.getNode2())) { - adjTp++; - } - } - - Set allOriented = new HashSet<>(); - allOriented.addAll(truth.getEdges()); - allOriented.addAll(est.getEdges()); - - for (Edge edge : allOriented) { - Endpoint e1Est = edge.getProximalEndpoint(edge.getNode1()); - Endpoint e2Est = edge.getProximalEndpoint(edge.getNode2()); - - Edge edge2 = truth.getEdge(edge.getNode1(), edge.getNode2()); - - Endpoint e1True = null; - Endpoint e2True = null; - - if (edge2 != null) { - e1True = edge2.getProximalEndpoint(edge.getNode1()); - e2True = edge2.getProximalEndpoint(edge.getNode2()); - } - - if (e1Est == Endpoint.ARROW && e1True != Endpoint.ARROW) { - arrowsFp++; - } - - if (e2Est == Endpoint.ARROW && e2True != Endpoint.ARROW) { - arrowsFp++; - } - - if (e1True == Endpoint.ARROW && e1Est != Endpoint.ARROW) { - arrowsFn++; - } - - if (e2True == Endpoint.ARROW && e2Est != Endpoint.ARROW) { - arrowsFn++; - } - - if (e1True == Endpoint.ARROW && e1Est == Endpoint.ARROW) { - arrowsTp++; - } - - if (e2True == Endpoint.ARROW && e2Est == Endpoint.ARROW) { - arrowsTp++; - } - } - - GraphUtils.GraphComparison comparison = SearchGraphUtils.getGraphComparison3(est, truth, System.out); - - int allEdges = truth.getNumNodes() * (truth.getNumNodes() - 1); - - int adjTn = allEdges / 2 - (adjFn + adjFp + adjTp); - int arrowsTn = allEdges - (arrowsFn + arrowsFp + arrowsTp); - - adjPrecision = adjTp / (double) (adjTp + adjFp); - adjRecall = adjTp / (double) (adjTp + adjFn); - - arrowPrecision = arrowsTp / (double) (arrowsTp + arrowsFp); - arrowRecall = arrowsTp / (double) (arrowsTp + arrowsFn); - - mcAdj = (adjTp * adjTn - adjFp * adjFn) / - Math.sqrt((adjTp + adjFp) * (adjTp + adjFn) * (adjTn + adjFp) * (adjTn + adjFn)); - mcOr = (arrowsTp * arrowsTn - arrowsFp * arrowsFn) / - Math.sqrt((arrowsTp + arrowsFp) * (arrowsTp + arrowsFn) * - (arrowsTn + arrowsFp) * (arrowsTn + arrowsFn)); - f1Adj = 2 * (adjPrecision * adjRecall) / (adjPrecision + adjRecall); - f1Arrows = 2 * (arrowPrecision * arrowRecall) / (arrowPrecision + arrowRecall); - - shd = comparison.getShd(); - - return this; - } - } -} - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/README b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/README deleted file mode 100644 index 1f068bfc96..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/README +++ /dev/null @@ -1,7 +0,0 @@ -Warning! This is an incomplete implementation! - -Do not use for anything serious! - -It will change frequently in the near future! - -JR 6/8/20165 \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Simulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Simulation.java deleted file mode 100644 index e12ba25883..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Simulation.java +++ /dev/null @@ -1,21 +0,0 @@ -package edu.cmu.tetrad.algcomparison; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public interface Simulation { - void simulate(Map parameters); - - Graph getDag(); - - DataSet getData(); - - String toString(); - - boolean isMixed(); -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/cyclic_pag/ContinuousCcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/cyclic_pag/ContinuousCcd.java deleted file mode 100644 index 7e78f048c5..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/cyclic_pag/ContinuousCcd.java +++ /dev/null @@ -1,29 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.cyclic_pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.CovarianceMatrixOnTheFly; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousCcd implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet)); - score.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - Ccd2 pc = new Ccd2(score); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "CCD using the SEM BIC score."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousCfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousCfci.java deleted file mode 100644 index 554da7b98b..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousCfci.java +++ /dev/null @@ -1,29 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousCfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestFisherZ(dataSet, parameters.get("alpha").doubleValue()); - Cfci pc = new Cfci(test); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - @Override - public String getDescription() { - return "CFCI, using the Fisher Z test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousFci.java deleted file mode 100644 index f56dcf46e8..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousFci.java +++ /dev/null @@ -1,27 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousFci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestFisherZ(dataSet, parameters.get("alpha").doubleValue()); - Fci pc = new Fci(test); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "FCI using the Fisher Z test."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousGfci.java deleted file mode 100644 index 8495f40bfc..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousGfci.java +++ /dev/null @@ -1,29 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.CovarianceMatrixOnTheFly; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousGfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet)); - score.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - GFci pc = new GFci(score); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "GFCI using the SEM BIC score."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousRfci.java deleted file mode 100644 index 95de54ed3d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pag/ContinuousRfci.java +++ /dev/null @@ -1,27 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousRfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestFisherZ(dataSet, parameters.get("alpha").doubleValue()); - Rfci pc = new Rfci(test); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "RFCI using the Fisher Z test."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousCpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousCpc.java deleted file mode 100644 index 34ee4e3949..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousCpc.java +++ /dev/null @@ -1,26 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousCpc implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestFisherZ(dataSet, parameters.get("alpha").doubleValue()); - Cpc pc = new Cpc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "CPC using the Fisher Z test."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousFgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousFgs.java deleted file mode 100644 index 07edbb5246..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousFgs.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.CovarianceMatrixOnTheFly; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousFgs implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet)); - score.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - Fgs2 fgs = new Fgs2(score); - return fgs.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "FGS using the SEM BIC score."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousMmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousMmhc.java deleted file mode 100644 index 38b62eba12..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousMmhc.java +++ /dev/null @@ -1,31 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.CovarianceMatrixOnTheFly; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.mb.Mmhc; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousMmhc implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet)); - score.setPenaltyDiscount(parameters.get("alpha").doubleValue()); - IndependenceTest test = new IndTestScore(score); - Mmhc pc = new Mmhc(test, dataSet); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "MMHC using the SEM BIC score. (Not optimized.)"; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPc.java deleted file mode 100644 index 7f6c25996a..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPc.java +++ /dev/null @@ -1,26 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousPc implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestFisherZ(dataSet, parameters.get("alpha").doubleValue()); - Pc pc = new Pc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "PC using the Fisher Z test."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPcs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPcs.java deleted file mode 100644 index 59fd384615..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/continuous/pattern/ContinuousPcs.java +++ /dev/null @@ -1,26 +0,0 @@ -package edu.cmu.tetrad.algcomparison.continuous.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousPcs implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestFisherZ(dataSet, parameters.get("alpha").doubleValue()); - PcStable pc = new PcStable(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "PC-Stable using the Fisher Z test."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/cyclic_pag/DiscreteCcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/cyclic_pag/DiscreteCcd.java deleted file mode 100644 index a83cb025b2..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/cyclic_pag/DiscreteCcd.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.cyclic_pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.CovarianceMatrixOnTheFly; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteCcd implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - Score score = new BDeScore(dataSet); - Ccd2 pc = new Ccd2(score); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "CCD using the BDeu score (incorrect)."; - }} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteCfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteCfci.java deleted file mode 100644 index 075b16c9ec..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteCfci.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteCfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestChiSquare(dataSet, parameters.get("alpha").doubleValue()); - Cfci pc = new Cfci(test); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "CFCI ising the Chi Square test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteFci.java deleted file mode 100644 index 61e3e81bff..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteFci.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteFci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestChiSquare(dataSet, parameters.get("alpha").doubleValue()); - Fci pc = new Fci(test); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "FCI using the Chi Square test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteGfci.java deleted file mode 100644 index 0aa97068fb..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteGfci.java +++ /dev/null @@ -1,29 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteGfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - BDeuScore score = new BDeuScore(dataSet); - score.setSamplePrior(parameters.get("samplePrior").doubleValue()); - score.setSamplePrior(parameters.get("structurePrior").doubleValue()); - GFci pc = new GFci(score); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "GFCI using the BDeu score."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteRfci.java deleted file mode 100644 index 76c7bf4d18..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pag/DiscreteRfci.java +++ /dev/null @@ -1,30 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteRfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestChiSquare(dataSet, parameters.get("alpha").doubleValue()); - Rfci pc = new Rfci(test); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "RFCI using the Chi Square test."; - } - - -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcChiSquare.java deleted file mode 100644 index 82a17f7a5d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcChiSquare.java +++ /dev/null @@ -1,30 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Cpc; -import edu.cmu.tetrad.search.IndTestChiSquare; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteCpcChiSquare implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestChiSquare(dataSet, parameters.get("alpha").doubleValue()); - Cpc pc = new Cpc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "CPC using the Chi Square test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcGSquare.java deleted file mode 100644 index b9c3b055c1..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteCpcGSquare.java +++ /dev/null @@ -1,27 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteCpcGSquare implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestGSquare(dataSet, parameters.get("alpha").doubleValue()); - Cpc pc = new Cpc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "CPC using the G Square test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBdeu.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBdeu.java deleted file mode 100644 index 57a08f861a..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBdeu.java +++ /dev/null @@ -1,32 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.BDeuScore; -import edu.cmu.tetrad.search.BicScore; -import edu.cmu.tetrad.search.DagToPag; -import edu.cmu.tetrad.search.Fgs2; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteFgsBdeu implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - BDeuScore score = new BDeuScore(dataSet); - score.setSamplePrior(parameters.get("samplePrior").doubleValue()); - score.setSamplePrior(parameters.get("structurePrior").doubleValue()); - Fgs2 fgs = new Fgs2(score); - return fgs.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "FGS using the BDeu score."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBic.java deleted file mode 100644 index 2e467872f7..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscreteFgsBic.java +++ /dev/null @@ -1,29 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteFgsBic implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - BicScore score = new BicScore(dataSet); - score.setSamplePrior(parameters.get("samplePrior").doubleValue()); - score.setSamplePrior(parameters.get("structurePrior").doubleValue()); - Fgs2 fgs = new Fgs2(score); - return fgs.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "FGS using the BIC score."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcChiSquare.java deleted file mode 100644 index bf1cfa37e3..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcChiSquare.java +++ /dev/null @@ -1,30 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndTestChiSquare; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.Pc; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscretePcChiSquare implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestChiSquare(dataSet, parameters.get("alpha").doubleValue()); - Pc pc = new Pc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "PC using the G Square test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcGSquare.java deleted file mode 100644 index aa407f9b1d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcGSquare.java +++ /dev/null @@ -1,27 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscretePcGSquare implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestChiSquare(dataSet, parameters.get("alpha").doubleValue()); - Pc pc = new Pc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "PC using the Chi Square test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcs.java deleted file mode 100644 index 9ea0b5fdeb..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/discrete/pattern/DiscretePcs.java +++ /dev/null @@ -1,27 +0,0 @@ -package edu.cmu.tetrad.algcomparison.discrete.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscretePcs implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestChiSquare(dataSet, parameters.get("alpha").doubleValue()); - PcStable pc = new PcStable(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "PC-Stable using the Chi Square test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunContinuousComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunContinuousComparison.java deleted file mode 100644 index c422f58869..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunContinuousComparison.java +++ /dev/null @@ -1,120 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.algcomparison.explorations; - -import edu.cmu.tetrad.algcomparison.Comparison; -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.algcomparison.continuous.cyclic_pag.ContinuousCcd; -import edu.cmu.tetrad.algcomparison.continuous.pag.ContinuousCfci; -import edu.cmu.tetrad.algcomparison.continuous.pag.ContinuousFci; -import edu.cmu.tetrad.algcomparison.continuous.pag.ContinuousGfci; -import edu.cmu.tetrad.algcomparison.continuous.pag.ContinuousRfci; -import edu.cmu.tetrad.algcomparison.continuous.pattern.*; -import edu.cmu.tetrad.algcomparison.mixed.pag.MixedFci; -import edu.cmu.tetrad.algcomparison.mixed.pag.MixedGfci; -import edu.cmu.tetrad.algcomparison.mixed.pag.MixedWgfci; -import edu.cmu.tetrad.algcomparison.mixed.pattern.*; -import edu.cmu.tetrad.algcomparison.simulation.ContinuousCyclicSemSimulation; -import edu.cmu.tetrad.algcomparison.simulation.ContinuousNonlinearNongaussianSimulation; -import edu.cmu.tetrad.algcomparison.simulation.LinearGaussianSemSimulation; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Joseph Ramsey - */ -public class RunContinuousComparison { - public static void main(String... args) { - Map parameters = new LinkedHashMap<>(); - // parameters.put("numCategories", 5); - - Map stats = new LinkedHashMap<>(); - stats.put("AP", "Adjacency Precision"); - stats.put("AR", "Adjacency Recall"); - stats.put("OP", "Orientation (Arrow) precision"); - stats.put("OR", "Orientation (Arrow) recall"); - stats.put("McAdj", "Matthew's correlation coeffficient for adjacencies"); - stats.put("McOr", "Matthew's correlation coefficient for arrow"); - stats.put("F1Adj", "F1 statistic for adjacencies"); - stats.put("F1Or", "F1 statistic for arrows"); - stats.put("SHD", "Structural Hamming Distance"); - stats.put("E", "Elapsed time in seconds"); - - List algorithms = new ArrayList<>(); - - // Pattern - algorithms.add(new ContinuousPc()); - algorithms.add(new ContinuousCpc()); - algorithms.add(new ContinuousPcs()); - algorithms.add(new MixedSemFgs()); - algorithms.add(new MixedWfgs()); - algorithms.add(new MixedPc()); - algorithms.add(new MixedPcs()); - algorithms.add(new MixedCpc()); - algorithms.add(new ContinuousFgs()); - - // PAG - algorithms.add(new ContinuousFci()); - algorithms.add(new MixedFci()); - algorithms.add(new ContinuousRfci()); - algorithms.add(new ContinuousGfci()); - algorithms.add(new MixedGfci()); - algorithms.add(new MixedWgfci()); - - // Cyclic PAG - algorithms.add(new ContinuousCcd()); - - String baseFileName = "Continuous"; - -// Simulation simulation = new LinearGaussianSemSimulation(); -// Simulation simulation = new ContinuousCyclicSemSimulation(); - Simulation simulation = new ContinuousNonlinearNongaussianSimulation(); -// Simulation simulation = new CyclicGeneralizedSemSimulation(); - - try { - File dir = new File("comparison"); - dir.mkdirs(); - - for (int index = 1; ; index++) { - File comparison = new File("comparison", baseFileName + "." + index + ".txt"); - if (!comparison.exists()) { - PrintStream out = new PrintStream(new FileOutputStream(comparison)); - new Comparison().testBestAlgorithms(parameters, stats, algorithms, simulation, out); - break; - } - } - } catch (Exception e) { - throw new RuntimeException(e); - } } - -} - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunDiscreteComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunDiscreteComparison.java deleted file mode 100644 index 8874557169..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunDiscreteComparison.java +++ /dev/null @@ -1,112 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.algcomparison.explorations; - -import edu.cmu.tetrad.algcomparison.Comparison; -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.algcomparison.discrete.pattern.*; -import edu.cmu.tetrad.algcomparison.mixed.pattern.MixedBdeuFgs; -import edu.cmu.tetrad.algcomparison.mixed.pattern.MixedSemFgs; -import edu.cmu.tetrad.algcomparison.mixed.pattern.MixedWfgs; -import edu.cmu.tetrad.algcomparison.simulation.DiscreteBayesNetSimulation; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Joseph Ramsey - */ -public class RunDiscreteComparison { - public static void main(String... args) { - Map parameters = new LinkedHashMap<>(); - parameters.put("samplePrior", 1); - parameters.put("structurePrior", 1); - parameters.put("numCategories", 5); - - Map stats = new LinkedHashMap<>(); - stats.put("AP", "Adjacency Precision"); - stats.put("AR", "Adjacency Recall"); - stats.put("OP", "Orientation (Arrow) precision"); - stats.put("OR", "Orientation (Arrow) recall"); - stats.put("McAdj", "Matthew's correlation coeffficient for adjacencies"); - stats.put("McOr", "Matthew's correlation coefficient for arrow"); - stats.put("F1Adj", "F1 statistic for adjacencies"); - stats.put("F1Or", "F1 statistic for arrows"); - stats.put("SHD", "Structural Hamming Distance"); - stats.put("E", "Elapsed time in seconds"); - - List algorithms = new ArrayList<>(); - - // Pattern -// algorithms.add(new DiscretePcChiSquare()); -// algorithms.add(new DiscreteCpcChiSquare()); -// algorithms.add(new DiscretePcGSquare()); -// algorithms.add(new DiscreteCpcGSquare()); - algorithms.add(new DiscreteFgsBdeu()); - algorithms.add(new DiscreteFgsBic()); -// algorithms.add(new DiscretePcs()); // crashes -// algorithms.add(new MixedSemFgs()); -// algorithms.add(new MixedBdeuFgs()); -// algorithms.add(new MixedWfgs()); - - // PAG -// algorithms.add(new DiscreteFci()); -// algorithms.add(new DiscreteRfci()); -// algorithms.add(new DiscreteCfci()); -// algorithms.add(new DiscreteGfci()); -// algorithms.add(new MixedWgfci()); -// algorithms.add(new MixedGfci()); - - // Cyclic PAG -// algorithms.add(new DiscreteCcd()); - - String baseFileName = "Discrete"; - - Simulation simulation = new DiscreteBayesNetSimulation(); - try { - File dir = new File("comparison"); - dir.mkdirs(); - - for (int index = 1; ; index++) { - File comparison = new File("comparison", baseFileName + "." + index + ".txt"); - if (!comparison.exists()) { - PrintStream out = new PrintStream(new FileOutputStream(comparison)); - new Comparison().testBestAlgorithms(parameters, stats, algorithms, simulation, out); - break; - } - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunMixedComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunMixedComparison.java deleted file mode 100644 index 597616514c..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/RunMixedComparison.java +++ /dev/null @@ -1,130 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.algcomparison.explorations; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.algcomparison.Comparison; -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.algcomparison.mixed.pag.MixedWgfciFci; -import edu.cmu.tetrad.algcomparison.mixed.pattern.*; -import edu.cmu.tetrad.algcomparison.simulation.MixedLeeHastieSimulation; -import edu.cmu.tetrad.algcomparison.simulation.MixedSemThenDiscretizeHalfSimulation; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Joseph Ramsey - */ -public class RunMixedComparison { - public static void main(String... args) { - Map parameters = new LinkedHashMap<>(); - parameters.put("numCategories", 2); - parameters.put("mgmParam1", 0.01); - parameters.put("mgmParam2", 0.01); - parameters.put("mgmParam3", 0.01); - parameters.put("numLatents", 0); - parameters.put("numRuns", 1); - parameters.put("numSamples", 1000); - parameters.put("numMeasures", 30); - parameters.put("numEdges", 30); - parameters.put("penaltyDiscount", 4); - parameters.put("percentDiscreteForMixedSimulation", 50); - - Map stats = new LinkedHashMap<>(); - stats.put("AP", "Adjacency Precision"); - stats.put("AR", "Adjacency Recall"); - stats.put("OP", "Orientation (Arrow) precision"); - stats.put("OR", "Orientation (Arrow) recall"); - stats.put("McAdj", "Matthew's correlation coeffficient for adjacencies"); - stats.put("McOr", "Matthew's correlation coefficient for arrow"); - stats.put("F1Adj", "F1 statistic for adjacencies"); - stats.put("F1Or", "F1 statistic for arrows"); - stats.put("SHD", "Structural hamming distance"); - stats.put("E", "Elapsed time in seconds"); - - List algorithms = new ArrayList<>(); - - // Pattern -// algorithms.add(new MixedSemFgs()); -// algorithms.add(new MixedFgsMixedScore()); - algorithms.add(new MixedFgsMixedScore2()); -// algorithms.add(new MixedBdeuFgs()); -// algorithms.add(new MixedWfgs()); -// algorithms.add(new MixedWfgs()); -// algorithms.add(new MixedPc()); -// algorithms.add(new MixedPcs()); -// algorithms.add(new MixedCpc()); -// algorithms.add(new MixedMGMFgs()); -// algorithms.add(new MixedMGMPc()); -// algorithms.add(new MixedMGMCpc()); -// algorithms.add(new MixedWgfciFci()); - - - // - - //PAG - - //algorithms.add(new MixedWgfci()); - - //algorithms.add(new MixedFci()); - - //algorithms.add(new MixedGfci()); - - Simulation simulation = new MixedLeeHastieSimulation(); -// Simulation simulation = new MixedSemThenDiscretizeHalfSimulation(); -// Simulation simulation = new DiscreteBayesNetSimulation(); - - String baseFileName = "Mixed"; - - try { -// File dir = new File("comparison"); -// dir.mkdirs(); -// -// for (int index = 1; ; index++) { -// File comparison = new File("comparison", baseFileName + "." + index + ".txt"); -// if (!comparison.exists()) { -// PrintStream out = new PrintStream(new FileOutputStream(comparison)); -// new Comparison().testBestAlgorithms(parameters, stats, algorithms, simulation, out); -// break; -// } -// } - - File comparison = new File("comparison", baseFileName + ".txt"); - PrintStream out = new PrintStream(new FileOutputStream(comparison)); - new Comparison().testBestAlgorithms(parameters, stats, algorithms, simulation, out); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/TestAJData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/TestAJData.java deleted file mode 100644 index fb7cff1198..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/explorations/TestAJData.java +++ /dev/null @@ -1,98 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.algcomparison.explorations; - -import edu.cmu.tetrad.algcomparison.mixed.pattern.MixedSemFgs; -import edu.cmu.tetrad.data.DataReader; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.io.File; -import java.io.IOException; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.*; - -/** - * @author Joseph Ramsey - */ -public class TestAJData { - public void testAjData() { - double penalty = 4; - - try { - - for (int i = 0; i < 50; i++) { - File dataPath = new File("/Users/jdramsey/Documents/LAB_NOTEBOOK.2012.04.20/2016.05.25/" + - "Simulated_data_for_Madelyn/simulation/data/DAG_" + i + "_data.txt"); - DataReader reader = new DataReader(); - DataSet Dk = reader.parseTabular(dataPath); - - File graphPath = new File("/Users/jdramsey/Documents/LAB_NOTEBOOK.2012.04.20/2016.05.25/" + - "Simulated_data_for_Madelyn/simulation/networks/DAG_" + i + "_graph.txt"); - - Graph dag = GraphUtils.loadGraphTxt(graphPath); - - long start = System.currentTimeMillis(); - -// Graph pattern = searchSemFgs(Dk); -// Graph pattern = searchBdeuFgs(Dk, k); -// Graph pattern = searchMixedFgs1(Dk, penalty); - - - Map parameters = new LinkedHashMap<>(); - parameters.put("alpha", 0.001); - parameters.put("penaltyDiscount", 4); - parameters.put("mgmParam1", 0.1); - parameters.put("mgmParam2", 0.1); - parameters.put("mgmParam3", 0.1); - parameters.put("OfInterestCutoff", 0.05); - - Graph pattern = new MixedSemFgs().search(Dk, parameters); - - long stop = System.currentTimeMillis(); - - long elapsed = stop - start; - long elapsedSeconds = elapsed / 1000; - - Graph truePattern = SearchGraphUtils.patternForDag(dag); - - GraphUtils.GraphComparison comparison = SearchGraphUtils.getGraphComparison3(pattern, truePattern, System.out); - NumberFormat nf = new DecimalFormat("0.00"); - - System.out.println(i + - "\t" + nf.format(comparison.getAdjPrec()) + - "\t" + nf.format(comparison.getAdjRec()) + - "\t" + nf.format(comparison.getAhdPrec()) + - "\t" + nf.format(comparison.getAhdRec()) + - "\t" + elapsedSeconds); - } - } catch (IOException e) { - e.printStackTrace(); - } - } -} - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedFci.java deleted file mode 100644 index acce65439d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedFci.java +++ /dev/null @@ -1,31 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.DagToPag; -import edu.cmu.tetrad.search.Fci; -import edu.cmu.tetrad.search.IndTestMixedLrt; -import edu.cmu.tetrad.search.IndependenceTest; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedFci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestMixedLrt(dataSet, parameters.get("alpha").doubleValue()); - Fci pc = new Fci(test); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "FCI using the Mixed LRT test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedGfci.java deleted file mode 100644 index f0790e510d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedGfci.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedGfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - MixedBicScore score = new MixedBicScore(dataSet); - GFci pc = new GFci(score); - return pc.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "GFCI using the Mixed BIC score."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfci.java deleted file mode 100644 index ba8796069d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfci.java +++ /dev/null @@ -1,29 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.DagToPag; -import edu.cmu.tetrad.search.WGfci; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedWgfci implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - WGfci fgs = new WGfci(dataSet); - fgs.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - return fgs.search(); - } - - @Override - public Graph getComparisonGraph(Graph dag) { - return new DagToPag(dag).convert(); - } - - public String getDescription() { - return "WGFCI using the SEM BIC score."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfciFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfciFci.java deleted file mode 100644 index bde1fb2c2e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pag/MixedWgfciFci.java +++ /dev/null @@ -1,33 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pag; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; -import edu.pitt.csb.mgm.MGM; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedWgfciFci implements Algorithm { - public Graph search(DataSet ds, Map parameters) { - WGfci fgs = new WGfci(ds); - fgs.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - Graph g = fgs.search(); - IndependenceTest test = new IndTestMixedLrt(ds, parameters.get("alpha").doubleValue()); - Fci pc = new Fci(test); - pc.setInitialGraph(g); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "WGFCI-FCI: uses the output of WGFCI as an intial graph " + - "for PC-Stable, using the Mixed LRT test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedBdeuFgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedBdeuFgs.java deleted file mode 100644 index 245689ca30..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedBdeuFgs.java +++ /dev/null @@ -1,75 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.ContinuousVariable; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.Discretizer; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.BDeuScore; -import edu.cmu.tetrad.search.Fgs; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.util.List; -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedBdeuFgs implements Algorithm { - public Graph search(DataSet Dk, Map parameters) { - Discretizer discretizer = new Discretizer(Dk); - List nodes = Dk.getVariables(); - - for (Node node : nodes) { - if (node instanceof ContinuousVariable) { - discretizer.equalIntervals(node, parameters.get("numCategories").intValue()); - } - } - - Dk = discretizer.discretize(); - - BDeuScore score = new BDeuScore(Dk); - score.setSamplePrior(1.0); - score.setStructurePrior(1.0); - Fgs fgs = new Fgs(score); - Graph p = fgs.search(); - return convertBack(Dk, p); - } - - - @Override - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - @Override - public String getDescription() { - return "Discretizes the continuous variables in the data set, then runs FGS using the BDeu score."; - } - - private Graph convertBack(DataSet Dk, Graph p) { - Graph p2 = new EdgeListGraph(Dk.getVariables()); - - for (int i = 0; i < p.getNodes().size(); i++) { - for (int j = i + 1; j < p.getNodes().size(); j++) { - Node v1 = p.getNodes().get(i); - Node v2 = p.getNodes().get(j); - - Edge e = p.getEdge(v1, v2); - - if (e != null) { - Node w1 = Dk.getVariable(e.getNode1().getName()); - Node w2 = Dk.getVariable(e.getNode2().getName()); - - Edge e2 = new Edge(w1, w2, e.getEndpoint1(), e.getEndpoint2()); - - p2.addEdge(e2); - } - } - } - return p2; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedCpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedCpc.java deleted file mode 100644 index 1480bd0566..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedCpc.java +++ /dev/null @@ -1,30 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Cpc; -import edu.cmu.tetrad.search.IndTestMixedLrt; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedCpc implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestMixedLrt(dataSet, parameters.get("alpha").doubleValue()); - Cpc pc = new Cpc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "CPC using the Mixed LRT test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore.java deleted file mode 100644 index 8d63d17154..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore.java +++ /dev/null @@ -1,40 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.ContinuousVariable; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.Discretizer; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.BDeuScore; -import edu.cmu.tetrad.search.Fgs; -import edu.cmu.tetrad.search.MixedBicScore; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.util.List; -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedFgsMixedScore implements Algorithm { - public Graph search(DataSet Dk, Map parameters) { - MixedBicScore score = new MixedBicScore(Dk); - Fgs fgs = new Fgs(score); - return fgs.search(); - } - - - @Override - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - @Override - public String getDescription() { - return "Runs FGS using a mixed BIC score that uses logistic regression for discrete targets and " + - "linear regression for continuous targets."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore2.java deleted file mode 100644 index f9c10cba16..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedFgsMixedScore2.java +++ /dev/null @@ -1,35 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Fgs; -import edu.cmu.tetrad.search.MixedBicScore; -import edu.cmu.tetrad.search.MixedBicScore2; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - * @deprecated Doesn't work. - */ -public class MixedFgsMixedScore2 implements Algorithm { - public Graph search(DataSet Dk, Map parameters) { - MixedBicScore2 score = new MixedBicScore2(Dk); - score.setPenaltyDiscount(1);//parameters.get("penaltyDiscount").doubleValue()); - Fgs fgs = new Fgs(score); - return fgs.search(); - } - - - @Override - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - @Override - public String getDescription() { - return "Runs FGS using a mixed BIC score assuming conditional Gaussian."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMCpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMCpc.java deleted file mode 100644 index e3174ffff6..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMCpc.java +++ /dev/null @@ -1,38 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; -import edu.pitt.csb.mgm.MGM; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedMGMCpc implements Algorithm { - public Graph search(DataSet ds, Map parameters) { - MGM m = new MGM(ds, new double[]{ - parameters.get("mgmParam1").doubleValue(), - parameters.get("mgmParam2").doubleValue(), - parameters.get("mgmParam3").doubleValue() - }); - Graph gm = m.search(); - IndependenceTest indTest = new IndTestMixedLrt(ds, parameters.get("alpha").doubleValue()); - Cpc pcs = new Cpc(indTest); - pcs.setDepth(-1); - pcs.setInitialGraph(gm); - pcs.setVerbose(false); - return pcs.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "MGM-CPC: uses the output of MGM as an intial graph " + - "for CPC-Stable, using the Mixed LRT test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMFgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMFgs.java deleted file mode 100644 index 9b001a187c..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMFgs.java +++ /dev/null @@ -1,70 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.CovarianceMatrixOnTheFly; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Fgs; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.SemBicScore2; -import edu.pitt.csb.mgm.MGM; -import edu.pitt.csb.mgm.MixedUtils; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedMGMFgs implements Algorithm { - public Graph search(DataSet ds, Map parameters) { - MGM m = new MGM(ds, new double[]{ - parameters.get("mgmParam1").doubleValue(), - parameters.get("mgmParam2").doubleValue(), - parameters.get("mgmParam3").doubleValue() - }); - Graph gm = m.search(); - DataSet dataSet = MixedUtils.makeContinuousData(ds); - SemBicScore2 score = new SemBicScore2(new CovarianceMatrixOnTheFly(dataSet)); - score.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - Fgs fg = new Fgs(score); - fg.setBoundGraph(gm); - fg.setVerbose(false); - Graph p = fg.search(); - return convertBack(ds, p); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - private Graph convertBack(DataSet Dk, Graph p) { - Graph p2 = new EdgeListGraph(Dk.getVariables()); - - for (int i = 0; i < p.getNodes().size(); i++) { - for (int j = i + 1; j < p.getNodes().size(); j++) { - Node v1 = p.getNodes().get(i); - Node v2 = p.getNodes().get(j); - - Edge e = p.getEdge(v1, v2); - - if (e != null) { - Node w1 = Dk.getVariable(e.getNode1().getName()); - Node w2 = Dk.getVariable(e.getNode2().getName()); - - Edge e2 = new Edge(w1, w2, e.getEndpoint1(), e.getEndpoint2()); - - p2.addEdge(e2); - } - } - } - return p2; - } - - public String getDescription() { - return "MGM-FGS: uses the output of MGM as an intial graph for FGS, treating discrete " + - "variables as continuous."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMPc.java deleted file mode 100644 index f0a654bd37..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedMGMPc.java +++ /dev/null @@ -1,41 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndTestMixedLrt; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.PcStable; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.pitt.csb.mgm.MGM; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedMGMPc implements Algorithm { - public Graph search(DataSet ds, Map parameters) { - MGM m = new MGM(ds, new double[]{ - parameters.get("mgmParam1").doubleValue(), - parameters.get("mgmParam2").doubleValue(), - parameters.get("mgmParam3").doubleValue() - }); - Graph gm = m.search(); - IndependenceTest indTest = new IndTestMixedLrt(ds, parameters.get("alpha").doubleValue()); - PcStable pcs = new PcStable(indTest); - pcs.setDepth(-1); - pcs.setInitialGraph(gm); - pcs.setVerbose(false); - return pcs.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "MGM-PC: uses the output of MGM as an intial graph " + - "for PC-Stable, using the Mixed LRT test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPc.java deleted file mode 100644 index 340d3bbd4f..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPc.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedPc implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestMixedLrt(dataSet, parameters.get("alpha").doubleValue()); - Pc pc = new Pc(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - - public String getDescription() { - return "PC using the Mixed LRT test"; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPcs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPcs.java deleted file mode 100644 index 436376b52f..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedPcs.java +++ /dev/null @@ -1,30 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndTestMixedLrt; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.PcStable; -import edu.cmu.tetrad.search.SearchGraphUtils; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedPcs implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - IndependenceTest test = new IndTestMixedLrt(dataSet, parameters.get("alpha").doubleValue()); - PcStable pc = new PcStable(test); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "PC-Stable using the Mixed LRT test"; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedSemFgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedSemFgs.java deleted file mode 100644 index f9b4ce109e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedSemFgs.java +++ /dev/null @@ -1,62 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.CovarianceMatrixOnTheFly; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Fgs; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.SemBicScore; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedSemFgs implements Algorithm { - public Graph search(DataSet Dk, Map parameters) { - Dk = DataUtils.convertNumericalDiscreteToContinuous(Dk); - SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(Dk)); - score.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - Fgs fgs = new Fgs(score); - Graph p = fgs.search(); - return convertBack(Dk, p); - } - - private Graph convertBack(DataSet Dk, Graph p) { - Graph p2 = new EdgeListGraph(Dk.getVariables()); - - for (int i = 0; i < p.getNodes().size(); i++) { - for (int j = i + 1; j < p.getNodes().size(); j++) { - Node v1 = p.getNodes().get(i); - Node v2 = p.getNodes().get(j); - - Edge e = p.getEdge(v1, v2); - - if (e != null) { - Node w1 = Dk.getVariable(e.getNode1().getName()); - Node w2 = Dk.getVariable(e.getNode2().getName()); - - Edge e2 = new Edge(w1, w2, e.getEndpoint1(), e.getEndpoint2()); - - p2.addEdge(e2); - } - } - } - return p2; - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "FGS, using the SEM BIC score, treating all variables as continuous."; - } -} - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgs.java deleted file mode 100644 index c4626a07b1..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgs.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.WFgs; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedWfgs implements Algorithm { - public Graph search(DataSet dataSet, Map parameters) { - WFgs fgs = new WFgs(dataSet); - fgs.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - return fgs.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "WFGS using the SEM BIC score."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgsCpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgsCpc.java deleted file mode 100644 index 467abff1f3..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/mixed/pattern/MixedWfgsCpc.java +++ /dev/null @@ -1,33 +0,0 @@ -package edu.cmu.tetrad.algcomparison.mixed.pattern; - -import edu.cmu.tetrad.algcomparison.Algorithm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedWfgsCpc implements Algorithm { - public Graph search(DataSet ds, Map parameters) { - WFgs fgs = new WFgs(ds); - fgs.setPenaltyDiscount(parameters.get("penaltyDiscount").doubleValue()); - Graph g = fgs.search(); - IndependenceTest test = new IndTestMixedLrt(ds, parameters.get("alpha").doubleValue()); - Cpc pc = new Cpc(test); - pc.setInitialGraph(g); - return pc.search(); - } - - public Graph getComparisonGraph(Graph dag) { - return new Pc(new IndTestDSep(dag)).search(); -// return SearchGraphUtils.patternForDag(dag); - } - - public String getDescription() { - return "WFGS-CPC: uses the output of WFGS as an intial graph " + - "for CPC, using the Mixed LRT test."; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousCyclicSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousCyclicSemSimulation.java deleted file mode 100644 index b03b9f03f0..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousCyclicSemSimulation.java +++ /dev/null @@ -1,51 +0,0 @@ -package edu.cmu.tetrad.algcomparison.simulation; - -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.sem.SemIm; -import edu.cmu.tetrad.sem.SemImInitializationParams; -import edu.cmu.tetrad.sem.SemPm; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousCyclicSemSimulation implements Simulation { - private Graph graph; - private DataSet dataSet; - - public ContinuousCyclicSemSimulation() { - } - - public void simulate(Map parameters) { - this.graph = GraphUtils.cyclicGraph2(parameters.get("numMeasures").intValue(), - parameters.get("numEdges").intValue()); - SemPm pm = new SemPm(graph); - - SemImInitializationParams params = new SemImInitializationParams(); - params.setCoefRange(.2, .9); - params.setCoefSymmetric(true); - SemIm im = new SemIm(pm, params); - this.dataSet = im.simulateData(parameters.get("sampleSize").intValue(), false); - } - - public Graph getDag() { - return graph; - } - - public DataSet getData() { - return dataSet; - } - - public String toString() { - return "Cyclic SEM simulation"; - } - - @Override - public boolean isMixed() { - return false; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousNonlinearNongaussianSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousNonlinearNongaussianSimulation.java deleted file mode 100644 index 94edd4cc58..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ContinuousNonlinearNongaussianSimulation.java +++ /dev/null @@ -1,131 +0,0 @@ -package edu.cmu.tetrad.algcomparison.simulation; - -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.BuildPureClusters; -import edu.cmu.tetrad.search.FindOneFactorClusters; -import edu.cmu.tetrad.search.MimUtils; -import edu.cmu.tetrad.search.TestType; -import edu.cmu.tetrad.sem.*; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.text.ParseException; -import java.util.*; - -/** - * Created by jdramsey on 6/4/16. - */ -public class ContinuousNonlinearNongaussianSimulation implements Simulation { - private Graph graph; - private DataSet dataSet; - - public ContinuousNonlinearNongaussianSimulation() { - } - - public void simulate(Map parameters) { - this.graph = GraphUtils.randomGraphRandomForwardEdges( - parameters.get("numMeasures").intValue(), - parameters.get("numLatents").intValue(), - parameters.get("numEdges").intValue(), - parameters.get("maxDegree").intValue(), - parameters.get("maxIndegree").intValue(), - parameters.get("maxOutdegree").intValue(), - parameters.get("connected").intValue() == 1); - GeneralizedSemPm pm = getPm(graph); - GeneralizedSemIm im = new GeneralizedSemIm(pm); - this.dataSet = im.simulateData(parameters.get("sampleSize").intValue(), false); - } - - public Graph getDag() { - return graph; - } - - public DataSet getData() { - return dataSet; - } - - public String toString() { - return "Nonlinear, non-Gaussian SEM simulation"; - } - - private GeneralizedSemPm getPm(Graph graph) { - - GeneralizedSemPm pm = new GeneralizedSemPm(graph); - - List variablesNodes = pm.getVariableNodes(); - List errorNodes = pm.getErrorNodes(); - - Map paramMap = new HashMap(); - String[] funcs = {"TSUM(NEW(B)*$)", "TSUM(NEW(B)*$+NEW(C)*sin(NEW(T)*$+NEW(A)))", - "TSUM(NEW(B)*(.5*$ + .5*(sqrt(abs(NEW(b)*$+NEW(exoErrorType))) ) ) )"}; - paramMap.put("s", "U(1,3)"); - paramMap.put("B", "Split(-1.5,-.5,.5,1.5)"); - paramMap.put("C", "Split(-1.5,-.5,.5,1.5)"); - paramMap.put("T", "U(.5,1.5)"); - paramMap.put("A", "U(0,.25)"); - paramMap.put("exoErrorType", "U(-.5,.5)"); - paramMap.put("funcType", "U(1,5)"); - - String nonlinearStructuralEdgesFunction = funcs[0]; - String nonlinearFactorMeasureEdgesFunction = funcs[0]; - - try { - for (Node node : variablesNodes) { - if (node.getNodeType() == NodeType.LATENT) { - String _template = TemplateExpander.getInstance().expandTemplate( - nonlinearStructuralEdgesFunction, pm, node); - pm.setNodeExpression(node, _template); - } - else { - String _template = TemplateExpander.getInstance().expandTemplate( - nonlinearFactorMeasureEdgesFunction, pm, node); - pm.setNodeExpression(node, _template); - } - } - - for (Node node : errorNodes) { - String _template = TemplateExpander.getInstance().expandTemplate("U(-.5,.5)", pm, node); - pm.setNodeExpression(node, _template); - } - - Set parameters = pm.getParameters(); - - for (String parameter : parameters) { - for (String type : paramMap.keySet()) { - if (parameter.startsWith(type)) { - pm.setParameterExpression(parameter, paramMap.get(type)); - } - } - } - } catch (ParseException e) { - System.out.println(e); - } - - return pm; - } - - private Graph getMim(Graph structuralGraph, int clusterSize, int numClusters) { - - // addImpurities(numClusters, clusterSize, impuritiesOption, graph); - return DataGraphUtils.randomMim(structuralGraph, clusterSize, 0, 0, 0, true); - } - - private Graph getStructuralGraph(int numClusters) { - return new Dag(GraphUtils.randomGraph(numClusters, 0, numClusters, 30, 15, 15, false)); - } - - - public static void main(String[] args) { -// new ExploreKummerfeldRamseyTetradPaper().loop1c(); -// new ExploreKummerfeldRamseyTetradPaper2().testOMSSpecial(); -// new ExploreKummerfeldRamseyTetradPaper().testOMS(); - } - - public boolean isMixed() { - return false; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/DiscreteBayesNetSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/DiscreteBayesNetSimulation.java deleted file mode 100644 index 675252ebc2..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/DiscreteBayesNetSimulation.java +++ /dev/null @@ -1,55 +0,0 @@ -package edu.cmu.tetrad.algcomparison.simulation; - -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.bayes.BayesIm; -import edu.cmu.tetrad.bayes.BayesPm; -import edu.cmu.tetrad.bayes.MlBayesIm; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.sem.SemIm; -import edu.cmu.tetrad.sem.SemPm; - -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class DiscreteBayesNetSimulation implements Simulation { - private Graph graph; - private DataSet dataSet; - - public DiscreteBayesNetSimulation() { - } - - public void simulate(Map parameters) { - this.graph = GraphUtils.randomGraphRandomForwardEdges( - parameters.get("numMeasures").intValue(), - parameters.get("numLatents").intValue(), - parameters.get("numEdges").intValue(), - parameters.get("maxDegree").intValue(), - parameters.get("maxIndegree").intValue(), - parameters.get("maxOutdegree").intValue(), - parameters.get("connected").intValue() == 1); - int numCategories = parameters.get("numCategories").intValue(); - BayesPm pm = new BayesPm(graph, numCategories, numCategories); - BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM); - this.dataSet = im.simulateData(parameters.get("sampleSize").intValue(), false); - } - - public Graph getDag() { - return graph; - } - - public DataSet getData() { - return dataSet; - } - - public String toString() { - return "Bayes net simulation"; - } - - public boolean isMixed() { - return false; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearGaussianSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearGaussianSemSimulation.java deleted file mode 100644 index 6ca5880e3a..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearGaussianSemSimulation.java +++ /dev/null @@ -1,56 +0,0 @@ -package edu.cmu.tetrad.algcomparison.simulation; - -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.Discretizer; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.sem.SemIm; -import edu.cmu.tetrad.sem.SemPm; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class LinearGaussianSemSimulation implements Simulation { - private Graph graph; - private DataSet dataSet; - - public LinearGaussianSemSimulation() { - } - - public void simulate(Map parameters) { - this.graph = GraphUtils.randomGraphRandomForwardEdges( - parameters.get("numMeasures").intValue(), - parameters.get("numLatents").intValue(), - parameters.get("numEdges").intValue(), - parameters.get("maxDegree").intValue(), - parameters.get("maxIndegree").intValue(), - parameters.get("maxOutdegree").intValue(), - parameters.get("connected").intValue() == 1); - SemPm pm = new SemPm(graph); - SemIm im = new SemIm(pm); - this.dataSet = im.simulateData(parameters.get("sampleSize").intValue(), false); - } - - public Graph getDag() { - return graph; - } - - public DataSet getData() { - return dataSet; - } - - public String toString() { - return "Linear, Gaussian SEM simulation"; - } - - public boolean isMixed() { - return false; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedLeeHastieSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedLeeHastieSimulation.java deleted file mode 100644 index 48618a5909..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedLeeHastieSimulation.java +++ /dev/null @@ -1,74 +0,0 @@ -package edu.cmu.tetrad.algcomparison.simulation; - -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.sem.GeneralizedSemIm; -import edu.cmu.tetrad.sem.GeneralizedSemPm; -import edu.pitt.csb.mgm.MixedUtils; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedLeeHastieSimulation implements Simulation { - private Graph dag; - private DataSet dataSet; - - public MixedLeeHastieSimulation() { - } - - public void simulate(Map parameters) { - this.dag = GraphUtils.randomGraphRandomForwardEdges( - parameters.get("numMeasures").intValue(), parameters.get("numLatents").intValue(), - parameters.get("numEdges").intValue(), - parameters.get("maxDegree").intValue(), - parameters.get("maxIndegree").intValue(), - parameters.get("maxOutdegree").intValue(), - parameters.get("connected").intValue() == 1); - - HashMap nd = new HashMap<>(); - - List nodes = dag.getNodes(); - - Collections.shuffle(nodes); - - for (int i = 0; i < nodes.size(); i++) { - if (i < nodes.size() * parameters.get("percentDiscreteForMixedSimulation").doubleValue() * 0.01) { - nd.put(nodes.get(i).getName(), parameters.get("numCategories").intValue()); - } else { - nd.put(nodes.get(i).getName(), 0); - } - } - - Graph graph = MixedUtils.makeMixedGraph(dag, nd); - - GeneralizedSemPm pm = MixedUtils.GaussianCategoricalPm(graph, "Split(-1.5,-.5,.5,1.5)"); - GeneralizedSemIm im = MixedUtils.GaussianCategoricalIm(pm); - - DataSet ds = im.simulateDataAvoidInfinity(parameters.get("sampleSize").intValue(), false); - this.dataSet = MixedUtils.makeMixedData(ds, nd); - } - - public Graph getDag() { - return dag; - } - - public DataSet getData() { - return dataSet; - } - - public String toString() { - return "Lee & Hastie simulation"; - } - - public boolean isMixed() { - return true; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedSemThenDiscretizeHalfSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedSemThenDiscretizeHalfSimulation.java deleted file mode 100644 index 8750d613e1..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/MixedSemThenDiscretizeHalfSimulation.java +++ /dev/null @@ -1,68 +0,0 @@ -package edu.cmu.tetrad.algcomparison.simulation; - -import edu.cmu.tetrad.algcomparison.Simulation; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.Discretizer; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.sem.SemIm; -import edu.cmu.tetrad.sem.SemPm; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * Created by jdramsey on 6/4/16. - */ -public class MixedSemThenDiscretizeHalfSimulation implements Simulation { - private Graph graph; - private DataSet dataSet; - - public MixedSemThenDiscretizeHalfSimulation() { - } - - public void simulate(Map parameters) { - this.graph = GraphUtils.randomGraphRandomForwardEdges( - parameters.get("numMeasures").intValue(), - parameters.get("numLatents").intValue(), - parameters.get("numEdges").intValue(), - parameters.get("maxDegree").intValue(), - parameters.get("maxIndegree").intValue(), - parameters.get("maxOutdegree").intValue(), - parameters.get("connected").intValue() == 1); - - SemPm pm = new SemPm(graph); - SemIm im = new SemIm(pm); - DataSet continuousData = im.simulateData(parameters.get("sampleSize").intValue(), false); - - List shuffledNodes = new ArrayList<>(continuousData.getVariables()); - Collections.shuffle(shuffledNodes); - - Discretizer discretizer = new Discretizer(continuousData); - - for (int i = 0; i < shuffledNodes.size() * parameters.get("percentDiscreteForMixedSimulation").doubleValue() * 0.01; i++) { - discretizer.equalCounts(shuffledNodes.get(i), parameters.get("numCategories").intValue()); - } - - this.dataSet = discretizer.discretize(); - } - - public Graph getDag() { - return graph; - } - - public DataSet getData() { - return dataSet; - } - - public String toString() { - return "Simulation SEM data then discretizing some variables"; - } - - public boolean isMixed() { - return true; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MixedBicScore2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MixedBicScore2.java deleted file mode 100644 index d09c311e78..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MixedBicScore2.java +++ /dev/null @@ -1,402 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.CombinationIterator; -import edu.cmu.tetrad.util.TetradMatrix; -import org.apache.commons.math3.stat.correlation.Covariance; - -import java.util.*; - -/** - * Implements the continuous BIC score for FGS. - * - * @author Joseph Ramsey - * @deprecated Doesn't work. - */ -public class MixedBicScore2 implements Score { - - // The covariance matrix. - private DataSet dataSet; - - private TetradMatrix _data; - - // The variables of the continuousData set. - private List variables; - - private double penaltyDiscount = 2.0; - - // True if verbose output should be sent to out. - private boolean verbose = false; - - /** - * Constructs the score using a covariance matrix. - */ - public MixedBicScore2(DataSet dataSet) { - if (dataSet == null) { - throw new NullPointerException(); - } - - this.dataSet = dataSet; - this.variables = dataSet.getVariables(); - this.penaltyDiscount = 4; - - _data = dataSet.getDoubleData(); - } - - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model - */ - public double localScore(int i, int... parents) { - Node target = variables.get(i); - - List denominatorContinuous = new ArrayList<>(); - List denominatorDiscrete = new ArrayList<>(); - - for (int parent1 : parents) { - Node parent = variables.get(parent1); - - if (parent instanceof ContinuousVariable) { - denominatorContinuous.add((ContinuousVariable) parent); - } else { - denominatorDiscrete.add((DiscreteVariable) parent); - } - } - - List numeratorContinuous = new ArrayList<>(denominatorContinuous); - List numeratorDiscrete = new ArrayList<>(denominatorDiscrete); - - if (target instanceof ContinuousVariable) { - numeratorContinuous.add((ContinuousVariable) target); - } else if (target instanceof DiscreteVariable) { - numeratorDiscrete.add((DiscreteVariable) target); - } else { - throw new IllegalStateException(); - } - - int N = dataSet.getNumRows(); - - double C = .5 * N * (1.0 + Math.log(2 * Math.PI)); - - if (numeratorContinuous.isEmpty()) { - - // Discrete target, discrete predictors. - if (!(target instanceof DiscreteVariable)) throw new IllegalStateException(); - Ret ret = getProb((DiscreteVariable) target, denominatorDiscrete); - double lik = ret.getLik(); - double dof = ret.getDof(); - -// lik += C; - - return lik - dof * Math.log(N); - } else { - if (denominatorContinuous.isEmpty()) { - - // Continuous target, all discrete predictors. - Ret ret1 = getProb(numeratorContinuous, numeratorDiscrete); - double dof = ret1.getDof(); - double lik = ret1.getLik(); - - lik -= C; - - return lik - dof * Math.log(N); - } else if (numeratorContinuous.size() == denominatorContinuous.size()) { - - // Discrete target, mixed predictors. - Ret ret1 = getProb(numeratorContinuous, numeratorDiscrete); - Ret ret2 = getProb(denominatorContinuous, denominatorDiscrete); - double dof = ret1.getDof() - ret2.getDof(); - double lik = ret1.getLik() - ret2.getLik(); - - lik -= C; - - return lik - dof * Math.log(N); - } else if (numeratorDiscrete.size() == denominatorDiscrete.size()) { - - // Continuous target, mixed predictors. - Ret ret1 = getProb(numeratorContinuous, numeratorDiscrete); - Ret ret2 = getProb(denominatorContinuous, denominatorDiscrete); - double dof = ret1.getDof() - ret2.getDof(); - double lik = ret1.getLik() - ret2.getLik(); - - lik -= C; - - return lik - dof * Math.log(N); - } else { - throw new IllegalStateException(); - } - } - } - - private Ret getProb(List continuous, List discrete) { - if (continuous.isEmpty()) throw new IllegalArgumentException(); - int dof = 0; - - // For each combination of values for the discrete guys extract a subset of the data. - List variables = dataSet.getVariables(); - - if (continuous.isEmpty()) { - throw new IllegalArgumentException(); - } - - int p = continuous.size(); - int d = discrete.size(); - - int[] cols = new int[p]; - int[] dims = new int[d]; - - for (int i = 0; i < d; i++) { - dims[i] = discrete.get(i).getNumCategories(); - } - - for (int j = 0; j < p; j++) { - cols[j] = variables.indexOf(continuous.get(j)); - } - - CombinationIterator iterator = new CombinationIterator(dims); - int[] comb; - - int[] _cols = new int[d]; - for (int i = 0; i < d; i++) _cols[i] = dataSet.getColumn(discrete.get(i)); - - double lik = 0; - - while (iterator.hasNext()) { - comb = iterator.next(); - List rows = new ArrayList<>(); - - for (int i = 0; i < dataSet.getNumRows(); i++) { - boolean addRow = true; - - for (int c = 0; c < comb.length; c++) { - if (comb[c] != dataSet.getInt(i, _cols[c])) { - addRow = false; - break; - } - } - - if (addRow) { - rows.add(i); - } - } - - if (rows.isEmpty()) continue; - - int[] _rows = new int[rows.size()]; - for (int k = 0; k < rows.size(); k++) _rows[k] = rows.get(k); - - TetradMatrix subset = _data.getSelection(_rows, cols); - int n = rows.size(); - - if (n > p) { - TetradMatrix Sigma = new TetradMatrix(new Covariance(subset.getRealMatrix(), - false).getCovarianceMatrix()); - lik -= 0.5 * n * Math.log(Sigma.det()); - } else { - System.out.println("Skipped " + n); - } - - dof += p * (p + 1); - } - - return new Ret(lik, dof); - } - - private Ret getProb(DiscreteVariable target, List parents) { - if (parents.contains(target)) throw new IllegalArgumentException(); - - int dof = 0; - int numCategories = target.getNumCategories(); - - int d = parents.size(); - int[] dims = new int[d]; - - for (int i = 0; i < d; i++) { - dims[i] = parents.get(i).getNumCategories(); - } - - CombinationIterator iterator = new CombinationIterator(dims); - int[] comb; - - int[] _cols = new int[d]; - for (int i = 0; i < d; i++) _cols[i] = dataSet.getColumn(parents.get(i)); - - double lik = 0; - - while (iterator.hasNext()) { - comb = iterator.next(); - List rows = new ArrayList<>(); - - for (int i = 0; i < dataSet.getNumRows(); i++) { - boolean addRow = true; - - for (int c = 0; c < comb.length; c++) { - if (comb[c] != dataSet.getInt(i, _cols[c])) { - addRow = false; - break; - } - } - - if (addRow) { - rows.add(i); - } - } - - double[] counts = new double[numCategories]; - double cellPrior = 0; - Arrays.fill(counts, cellPrior); - double r = cellPrior * counts.length; - - for (int row : rows) { - int value = dataSet.getInt(row, dataSet.getColumn(target)); - counts[value]++; - r++; - } - - for (int c = 0; c < numCategories; c++) { - double count = counts[c]; - - if (count > 0) { - lik += count * Math.log(count / (double) r); - } - } - - dof += numCategories - 1; - } - - return new Ret(lik, dof); - } - - private class Ret { - private double lik; - private int dof; - - public Ret(double lik, int dof) { - this.lik = lik; - this.dof = dof; - } - - public double getLik() { - return lik; - } - - public int getDof() { - return dof; - } - } - - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - @Override - public double localScoreDiff(int x, int y) { - return localScore(y, x) - localScore(y); - } - - private int[] append(int[] parents, int extra) { - int[] all = new int[parents.length + 1]; - System.arraycopy(parents, 0, all, 0, parents.length); - all[parents.length] = extra; - return all; - } - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - public double localScore(int i, int parent) { - return localScore(i, new int[]{parent}); - } - - /** - * Specialized scoring method for no parents. Used to speed up the effect edges search. - */ - public double localScore(int i) { - return localScore(i, new int[0]); - } - - public double getPenaltyDiscount() { - return penaltyDiscount; - } - - public int getSampleSize() { - return dataSet.getNumRows(); - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > 0;//-0.25 * getPenaltyDiscount() * Math.log(sampleSize); - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public List getVariables() { - return variables; - } - - @Override - public boolean isDiscrete() { - return false; - } - - @Override - public double getParameter1() { - return penaltyDiscount; - } - - @Override - public void setParameter1(double alpha) { - this.penaltyDiscount = alpha; - } - - @Override - public Node getVariable(String targetName) { - for (Node node : variables) { - if (node.getName().equals(targetName)) { - return node; - } - } - - return null; - } - - @Override - public int getMaxIndegree() { - return (int) Math.ceil(Math.log(dataSet.getNumRows())); - } -} - - -