parameters = new LinkedList<>();
parameters.addAll(new SemBicScore().getParameters());
- parameters.addAll((new Fges()).getParameters());
+ parameters.addAll((new FGES()).getParameters());
parameters.add(Params.RANDOM_SELECTION_SIZE);
parameters.add(Params.TIME_LAG);
parameters.add(Params.IMAGES_META_ALG);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesBDeu.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesBDeu.java
deleted file mode 100644
index 66e36ca0d4..0000000000
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesBDeu.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package edu.cmu.tetrad.algcomparison.algorithm.multi;
-
-import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges;
-import edu.cmu.tetrad.algcomparison.score.BdeuScore;
-import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
-import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
-import edu.cmu.tetrad.annotation.Bootstrapping;
-import edu.cmu.tetrad.annotation.Experimental;
-import edu.cmu.tetrad.data.*;
-import edu.cmu.tetrad.graph.EdgeListGraph;
-import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.BdeuScoreImages;
-import edu.cmu.tetrad.search.SearchGraphUtils;
-import edu.cmu.tetrad.util.Parameters;
-import edu.cmu.tetrad.util.Params;
-import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Wraps the IMaGES algorithm for discrete variables.
- *
- * Requires that the parameter 'randomSelectionSize' be set to indicate how many
- * datasets should be taken at a time (randomly). This cannot given multiple
- * values.
- *
- * @author jdramsey
- */
-//@edu.cmu.tetrad.annotation.Algorithm(
-// name = "IMaGES Discrete",
-// command = "imgs_disc",
-// algoType = AlgType.forbid_latent_common_causes,
-// dataType = DataType.Discrete
-//)
-@Bootstrapping
-@Experimental
-public class ImagesBDeu implements MultiDataSetAlgorithm, HasKnowledge {
-
- static final long serialVersionUID = 23L;
- private Knowledge knowledge = new Knowledge();
-
- public ImagesBDeu() {
- }
-
- @Override
- public Graph search(List dataSets, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- BdeuScoreImages score = new BdeuScoreImages(dataSets);
- score.setSamplePrior(parameters.getDouble(Params.PRIOR_EQUIVALENT_SAMPLE_SIZE));
- score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR));
- edu.cmu.tetrad.search.Fges search = new edu.cmu.tetrad.search.Fges(score);
- search.setFaithfulnessAssumed(true);
- search.setKnowledge(this.knowledge);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
-
- return search.search();
- } else {
- ImagesBDeu imagesBDeu = new ImagesBDeu();
-
- List datasets = new ArrayList<>();
-
- for (DataModel dataModel : dataSets) {
- datasets.add((DataSet) dataModel);
- }
- GeneralResamplingTest search = new GeneralResamplingTest(
- datasets,
- imagesBDeu,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public void setScoreWrapper(ScoreWrapper score) {
-
- }
-
- @Override
- public Graph search(DataModel dataSet, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- return search(Collections.singletonList(SimpleDataLoader.getDiscreteDataSet(dataSet)), parameters);
- } else {
- ImagesBDeu imagesBDeu = new ImagesBDeu();
-
- List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet));
- GeneralResamplingTest search = new GeneralResamplingTest(dataSets,
- imagesBDeu,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public Graph getComparisonGraph(Graph graph) {
- return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph));
- }
-
- @Override
- public String getDescription() {
- return "IMaGES for discrete variables (using the BDeu score)";
- }
-
- @Override
- public DataType getDataType() {
- return DataType.Discrete;
- }
-
- @Override
- public List getParameters() {
- List parameters = new LinkedList<>();
- parameters.addAll((new Fges()).getParameters());
- parameters.addAll((new BdeuScore()).getParameters());
- parameters.add(Params.NUM_RUNS);
- parameters.add(Params.RANDOM_SELECTION_SIZE);
- parameters.add(Params.VERBOSE);
-
- return parameters;
- }
-
- @Override
- public Knowledge getKnowledge() {
- return this.knowledge;
- }
-
- @Override
- public void setKnowledge(Knowledge knowledge) {
- this.knowledge = new Knowledge((Knowledge) knowledge);
- }
-}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesPcStableMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesPcStableMax.java
deleted file mode 100644
index bcfe2287b8..0000000000
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesPcStableMax.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package edu.cmu.tetrad.algcomparison.algorithm.multi;
-
-import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm;
-import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
-import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
-import edu.cmu.tetrad.annotation.Bootstrapping;
-import edu.cmu.tetrad.data.*;
-import edu.cmu.tetrad.graph.EdgeListGraph;
-import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.IndTestScore;
-import edu.cmu.tetrad.search.IndependenceTest;
-import edu.cmu.tetrad.search.PcStableMax;
-import edu.cmu.tetrad.search.SemBicScoreImages;
-import edu.cmu.tetrad.util.Parameters;
-import edu.cmu.tetrad.util.Params;
-import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Wraps the IMaGES algorithm for continuous variables.
- *
- * Requires that the parameter 'randomSelectionSize' be set to indicate how many
- * datasets should be taken at a time (randomly). This cannot given multiple values.
- *
- * @author jdramsey
- */
-@Bootstrapping
-public class ImagesPcStableMax implements MultiDataSetAlgorithm, HasKnowledge {
- static final long serialVersionUID = 23L;
- private Knowledge knowledge = new Knowledge();
-
- public ImagesPcStableMax() {
- }
-
- @Override
- public Graph search(List dataModels, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- List dataSets = new ArrayList<>();
-
- for (DataModel dataModel : dataModels) {
- dataSets.add(dataModel);
- }
-
- SemBicScoreImages score = new SemBicScoreImages(dataSets);
- score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT));
- IndependenceTest test = new IndTestScore(score);
- PcStableMax search = new PcStableMax(test);
- search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC));
- search.setMaxPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH));
- search.setKnowledge(this.knowledge);
- search.setDepth(parameters.getInt(Params.DEPTH));
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- } else {
- ImagesPcStableMax imagesPcStableMax = new ImagesPcStableMax();
-
- List datasets = new ArrayList<>();
-
- for (DataModel dataModel : dataModels) {
- datasets.add((DataSet) dataModel);
- }
- GeneralResamplingTest search = new GeneralResamplingTest(datasets,
- imagesPcStableMax,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public void setScoreWrapper(ScoreWrapper score) {
-
- }
-
- @Override
- public Graph search(DataModel dataSet, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters);
- } else {
- ImagesPcStableMax imagesPcStableMax = new ImagesPcStableMax();
-
- List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet));
- GeneralResamplingTest search = new GeneralResamplingTest(dataSets,
- imagesPcStableMax,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public Graph getComparisonGraph(Graph graph) {
- return new EdgeListGraph(graph);
- }
-
- @Override
- public String getDescription() {
- return "PC-Max using the IMaGES score for continuous variables";
- }
-
- @Override
- public DataType getDataType() {
- return DataType.Continuous;
- }
-
- @Override
- public List getParameters() {
- List parameters = new ArrayList<>();
- parameters.add(Params.PENALTY_DISCOUNT);
-
- parameters.add(Params.DEPTH);
- parameters.add(Params.ORIENT_VISIBLE_FEEDBACK_LOOPS);
- parameters.add(Params.USE_MAX_P_ORIENTATION_HEURISTIC);
- parameters.add(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH);
- parameters.add(Params.APPLY_R1);
- parameters.add(Params.ORIENT_TOWARD_DCONNECTIONS);
-
- parameters.add(Params.NUM_RUNS);
- parameters.add(Params.RANDOM_SELECTION_SIZE);
-
- parameters.add(Params.VERBOSE);
-
- return parameters;
- }
-
- @Override
- public Knowledge getKnowledge() {
- return this.knowledge;
- }
-
- @Override
- public void setKnowledge(Knowledge knowledge) {
- this.knowledge = new Knowledge((Knowledge) knowledge);
- }
-}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesSemBic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesSemBic.java
deleted file mode 100644
index d2c4485805..0000000000
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesSemBic.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package edu.cmu.tetrad.algcomparison.algorithm.multi;
-
-import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges;
-import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
-import edu.cmu.tetrad.algcomparison.score.SemBicScore;
-import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
-import edu.cmu.tetrad.annotation.Bootstrapping;
-import edu.cmu.tetrad.annotation.Experimental;
-import edu.cmu.tetrad.data.*;
-import edu.cmu.tetrad.graph.EdgeListGraph;
-import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.SemBicScoreImages;
-import edu.cmu.tetrad.search.TimeSeriesUtils;
-import edu.cmu.tetrad.util.Parameters;
-import edu.cmu.tetrad.util.Params;
-import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Wraps the IMaGES algorithm for continuous variables.
- *
- * Requires that the parameter 'randomSelectionSize' be set to indicate how many
- * datasets should be taken at a time (randomly). This cannot given multiple
- * values.
- *
- * @author jdramsey
- */
-//@edu.cmu.tetrad.annotation.Algorithm(
-// name = "IMaGES Continuous",
-// command = "imgs_cont",
-// algoType = AlgType.forbid_latent_common_causes,
-// dataType = DataType.Continuous
-//)
-@Bootstrapping
-@Experimental
-public class ImagesSemBic implements MultiDataSetAlgorithm, HasKnowledge {
-
- static final long serialVersionUID = 23L;
- private Knowledge knowledge = new Knowledge();
-
- public ImagesSemBic() {
- }
-
- @Override
- public Graph search(List dataSets, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- List _dataSets = new ArrayList<>();
-
- if (parameters.getInt(Params.TIME_LAG) > 0) {
- for (DataModel dataSet : dataSets) {
- DataSet timeSeries = TimeSeriesUtils.createLagData((DataSet) dataSet, parameters.getInt(Params.TIME_LAG));
- if (dataSet.getName() != null) {
- timeSeries.setName(dataSet.getName());
- }
- _dataSets.add(timeSeries);
- }
-
- dataSets = _dataSets;
- this.knowledge = _dataSets.get(0).getKnowledge();
- }
-
- SemBicScoreImages score = new SemBicScoreImages(dataSets);
- score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT));
- edu.cmu.tetrad.search.Fges search = new edu.cmu.tetrad.search.Fges(score);
- search.setKnowledge(this.knowledge);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- } else {
- ImagesSemBic imagesSemBic = new ImagesSemBic();
-
- List dataSets2 = new ArrayList<>();
-
- for (DataModel dataModel : dataSets) {
- dataSets2.add((DataSet) dataModel);
- }
-
- List _dataSets = new ArrayList<>();
-
- if (parameters.getInt(Params.TIME_LAG) > 0) {
- for (DataModel dataSet : dataSets2) {
- DataSet timeSeries = TimeSeriesUtils.createLagData((DataSet) dataSet, parameters.getInt(Params.TIME_LAG));
- if (dataSet.getName() != null) {
- timeSeries.setName(dataSet.getName());
- }
- _dataSets.add(timeSeries);
- }
-
- dataSets2 = _dataSets;
- this.knowledge = _dataSets.get(0).getKnowledge();
- }
-
- GeneralResamplingTest search = new GeneralResamplingTest(
- dataSets2,
- imagesSemBic,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- search.setKnowledge(knowledge);
- return search.search();
- }
- }
-
- @Override
- public void setScoreWrapper(ScoreWrapper score) {
-
- }
-
- @Override
- public Graph search(DataModel dataSet, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters);
- } else {
- ImagesSemBic imagesSemBic = new ImagesSemBic();
-
- List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet));
- GeneralResamplingTest search = new GeneralResamplingTest(dataSets,
- imagesSemBic,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public Graph getComparisonGraph(Graph graph) {
- return new EdgeListGraph(graph);
- }
-
- @Override
- public String getDescription() {
- return "IMaGES for continuous variables (using the SEM BIC score)";
- }
-
- @Override
- public DataType getDataType() {
- return DataType.Continuous;
- }
-
- @Override
- public List getParameters() {
- List parameters = new LinkedList<>();
- parameters.addAll(new SemBicScore().getParameters());
-
- parameters.addAll((new Fges()).getParameters());
- parameters.add(Params.PENALTY_DISCOUNT);
- parameters.add(Params.RANDOM_SELECTION_SIZE);
- parameters.add(Params.TIME_LAG);
-
- parameters.add(Params.VERBOSE);
-
- return parameters;
- }
-
- @Override
- public Knowledge getKnowledge() {
- return this.knowledge;
- }
-
- @Override
- public void setKnowledge(Knowledge knowledge) {
- this.knowledge = new Knowledge((Knowledge) knowledge);
- }
-}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/MultiFaskV1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/MultiFaskV1.java
deleted file mode 100644
index f3a5ba0888..0000000000
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/MultiFaskV1.java
+++ /dev/null
@@ -1,161 +0,0 @@
-package edu.cmu.tetrad.algcomparison.algorithm.multi;
-
-import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges;
-import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
-import edu.cmu.tetrad.algcomparison.score.SemBicScore;
-import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
-import edu.cmu.tetrad.annotation.Bootstrapping;
-import edu.cmu.tetrad.data.*;
-import edu.cmu.tetrad.graph.EdgeListGraph;
-import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.SemBicScoreMultiFas;
-import edu.cmu.tetrad.util.Parameters;
-import edu.cmu.tetrad.util.Params;
-import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Wraps the MultiFask algorithm for continuous variables.
- *
- * Requires that the parameter 'randomSelectionSize' be set to indicate how many
- * datasets should be taken at a time (randomly). This cannot given multiple
- * values.
- *
- * @author jdramsey
- */
-
-// Using FaskVote now in place of MultiFask. Keeping the name "MultiFask" in the interface.
-//@edu.cmu.tetrad.annotation.Algorithm(
-// name = "MultiFask",
-// command = "multi-fask",
-// algoType = AlgType.forbid_latent_common_causes,
-// dataType = DataType.Continuous
-//)
-@Bootstrapping
-public class MultiFaskV1 implements MultiDataSetAlgorithm, HasKnowledge {
-
- static final long serialVersionUID = 23L;
- private Knowledge knowledge = new Knowledge();
-
- public MultiFaskV1() {
-
- }
-
- @Override
- public Graph search(List dataSets, Parameters parameters) {
- for (DataModel d : dataSets) {
- DataSet _data = (DataSet) d;
-
- for (int j = 0; j < _data.getNumColumns(); j++) {
- for (int i = 0; i < _data.getNumRows(); i++) {
- if (Double.isNaN(_data.getDouble(i, j))) {
- throw new IllegalArgumentException("Please remove or impute missing values.");
- }
- }
- }
- }
-
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- List _dataSets = new ArrayList<>();
- for (DataModel d : dataSets) {
- _dataSets.add((DataSet) d);
- }
- SemBicScoreMultiFas score = new SemBicScoreMultiFas(dataSets);
- score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT));
- edu.cmu.tetrad.search.MultiFaskV1 search = new edu.cmu.tetrad.search.MultiFaskV1(_dataSets, score);
- search.setKnowledge(this.knowledge);
- return search.search();
- } else {
- MultiFaskV1 imagesSemBic = new MultiFaskV1();
-
- List datasets = new ArrayList<>();
-
- for (DataModel dataModel : dataSets) {
- datasets.add((DataSet) dataModel);
- }
- GeneralResamplingTest search = new GeneralResamplingTest(
- datasets,
- imagesSemBic,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public void setScoreWrapper(ScoreWrapper score) {
-
- }
-
- @Override
- public Graph search(DataModel dataSet, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters);
- } else {
- MultiFaskV1 imagesSemBic = new MultiFaskV1();
-
- List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet));
- GeneralResamplingTest search = new GeneralResamplingTest(dataSets,
- imagesSemBic,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public Graph getComparisonGraph(Graph graph) {
- return new EdgeListGraph(graph);
- }
-
- @Override
- public String getDescription() {
- return "IMaGES for continuous variables (using the SEM BIC score)";
- }
-
- @Override
- public DataType getDataType() {
- return DataType.Continuous;
- }
-
- @Override
- public List getParameters() {
- // MultiFask uses SemBicScore internally, so we'll need to add the score parameters too - Zhou
- List parameters = new LinkedList<>();
- parameters.addAll((new Fges()).getParameters());
- parameters.addAll((new SemBicScore()).getParameters());
- parameters.add(Params.NUM_RUNS);
- parameters.add(Params.RANDOM_SELECTION_SIZE);
-
- parameters.add(Params.VERBOSE);
-
- return parameters;
- }
-
- @Override
- public Knowledge getKnowledge() {
- return this.knowledge;
- }
-
- @Override
- public void setKnowledge(Knowledge knowledge) {
- this.knowledge = new Knowledge((Knowledge) knowledge);
- }
-}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/PcStableMaxConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/PcStableMaxConcatenated.java
deleted file mode 100644
index b1f5c9c24e..0000000000
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/PcStableMaxConcatenated.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package edu.cmu.tetrad.algcomparison.algorithm.multi;
-
-import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
-import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm;
-import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
-import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
-import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
-import edu.cmu.tetrad.annotation.Bootstrapping;
-import edu.cmu.tetrad.data.*;
-import edu.cmu.tetrad.graph.EdgeListGraph;
-import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.PcStableMax;
-import edu.cmu.tetrad.search.SearchGraphUtils;
-import edu.cmu.tetrad.util.Parameters;
-import edu.cmu.tetrad.util.Params;
-import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Requires that the parameter 'randomSelectionSize' be set to indicate how many
- * datasets should be taken at a time (randomly). This cannot given multiple
- * values.
- *
- * @author jdramsey
- */
-@Bootstrapping
-public class PcStableMaxConcatenated implements MultiDataSetAlgorithm, HasKnowledge {
-
- static final long serialVersionUID = 23L;
- private boolean compareToTrue;
- private final IndependenceWrapper test;
- private final Algorithm externalGraph = null;
- private Knowledge knowledge = new Knowledge();
-
- public PcStableMaxConcatenated(IndependenceWrapper test, boolean compareToTrue) {
- this.test = test;
- this.compareToTrue = compareToTrue;
- }
-
- public PcStableMaxConcatenated(IndependenceWrapper test) {
- this.test = test;
- }
-
- @Override
- public Graph search(List dataModels, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- List dataSets = new ArrayList<>();
-
- for (DataModel dataModel : dataModels) {
- dataSets.add((DataSet) dataModel);
- }
-
- DataSet dataSet = DataUtils.concatenate(dataSets);
- PcStableMax search = new PcStableMax(
- this.test.getTest(dataSet, parameters));
- search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC));
- search.setMaxPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH));
- search.setKnowledge(this.knowledge);
- search.setDepth(parameters.getInt(Params.DEPTH));
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- } else {
- PcStableMaxConcatenated pcStableMaxConcatenated = new PcStableMaxConcatenated(this.test, this.compareToTrue);
-
- List datasets = new ArrayList<>();
-
- for (DataModel dataModel : dataModels) {
- datasets.add((DataSet) dataModel);
- }
- GeneralResamplingTest search = new GeneralResamplingTest(
- datasets,
- pcStableMaxConcatenated,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public void setScoreWrapper(ScoreWrapper score) {
-
- }
-
- @Override
- public Graph search(DataModel dataSet, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters);
- } else {
- PcStableMaxConcatenated pcStableMaxConcatenated = new PcStableMaxConcatenated(this.test, this.compareToTrue);
-
- List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet));
- GeneralResamplingTest search = new GeneralResamplingTest(dataSets,
- pcStableMaxConcatenated,
- parameters.getInt(Params.NUMBER_RESAMPLING),
- parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE),
- parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
- search.setScoreWrapper(null);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public Graph getComparisonGraph(Graph graph) {
- if (this.compareToTrue) {
- return new EdgeListGraph(graph);
- } else {
- return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph));
- }
- }
-
- @Override
- public String getDescription() {
- return "PC-Max (\"Peter and Clark\") on concatenating datasets using " + this.test.getDescription()
- + "";
- }
-
- @Override
- public DataType getDataType() {
- return DataType.Continuous;
- }
-
- @Override
- public List getParameters() {
- List parameters = new LinkedList<>();
- if (this.test != null) {
- parameters.addAll(this.test.getParameters());
- }
- parameters.add(Params.DEPTH);
- parameters.add(Params.USE_MAX_P_ORIENTATION_HEURISTIC);
- parameters.add(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH);
-
- parameters.add(Params.NUM_RUNS);
- parameters.add(Params.RANDOM_SELECTION_SIZE);
-
- parameters.add(Params.VERBOSE);
-
- return parameters;
- }
-
- @Override
- public Knowledge getKnowledge() {
- return this.knowledge;
- }
-
- @Override
- public void setKnowledge(Knowledge knowledge) {
- this.knowledge = new Knowledge((Knowledge) knowledge);
- }
-
-}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java
index 5b88cea39e..f44d6a766a 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
import edu.cmu.tetrad.annotation.Bootstrapping;
@@ -33,6 +34,8 @@
public class BDCE implements Algorithm, UsesScoreWrapper {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
+ private List bootstrapGraphs = new ArrayList<>();
+
public BDCE() {
// Used in reflection; do not delete.
@@ -93,5 +96,4 @@ public ScoreWrapper getScoreWrapper() {
public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
-
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java
index f982d44a4c..7cfb5930d5 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
@@ -8,15 +9,15 @@
import edu.cmu.tetrad.annotation.Bootstrapping;
import edu.cmu.tetrad.annotation.Experimental;
import edu.cmu.tetrad.data.DataModel;
+import edu.cmu.tetrad.data.DataSet;
import edu.cmu.tetrad.data.DataType;
import edu.cmu.tetrad.data.Knowledge;
import edu.cmu.tetrad.graph.EdgeListGraph;
import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.Boss;
-import edu.cmu.tetrad.search.PermutationSearch;
-import edu.cmu.tetrad.search.Score;
+import edu.cmu.tetrad.search.*;
import edu.cmu.tetrad.util.Parameters;
import edu.cmu.tetrad.util.Params;
+import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
import java.util.ArrayList;
import java.util.List;
@@ -34,10 +35,13 @@
)
@Bootstrapping
@Experimental
-public class BOSS implements Algorithm, UsesScoreWrapper, HasKnowledge {
+public class BOSS implements Algorithm, UsesScoreWrapper, HasKnowledge,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public BOSS() {
// Used in reflection; do not delete.
@@ -50,17 +54,41 @@ public BOSS(ScoreWrapper score) {
@Override
public Graph search(DataModel dataModel, Parameters parameters) {
- Score score = this.score.getScore(dataModel, parameters);
-
- Boss boss = new Boss(score);
- boss.setDepth(parameters.getInt(Params.DEPTH));
- boss.setNumStarts(parameters.getInt(Params.NUM_STARTS));
- PermutationSearch permutationSearch = new PermutationSearch(boss);
- permutationSearch.setKnowledge(this.knowledge);
-
- permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE));
-
- return permutationSearch.search();
+ if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
+ if (parameters.getInt(Params.TIME_LAG) > 0) {
+ DataSet dataSet = (DataSet) dataModel;
+ DataSet timeSeries = TimeSeriesUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG));
+ if (dataSet.getName() != null) {
+ timeSeries.setName(dataSet.getName());
+ }
+ dataModel = timeSeries;
+ knowledge = timeSeries.getKnowledge();
+ }
+
+ Score score = this.score.getScore(dataModel, parameters);
+
+ Boss boss = new Boss(score);
+ boss.setDepth(parameters.getInt(Params.DEPTH));
+ boss.setNumStarts(parameters.getInt(Params.NUM_STARTS));
+ PermutationSearch permutationSearch = new PermutationSearch(boss);
+ permutationSearch.setKnowledge(this.knowledge);
+
+ permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE));
+
+ return permutationSearch.search();
+ } else {
+ BOSS algorithm = new BOSS(this.score);
+
+ DataSet data = (DataSet) dataModel;
+ GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
+ search.setKnowledge(this.knowledge);
+
+ search.setParameters(parameters);
+ search.setVerbose(parameters.getBoolean(Params.VERBOSE));
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
+ }
}
@Override
@@ -111,4 +139,9 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = knowledge;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java
index f8ed8cb404..86e1a06273 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
@@ -35,12 +36,15 @@
//)
@Bootstrapping
@Experimental
-public class BOSS_MB implements Algorithm, HasKnowledge, UsesScoreWrapper {
+public class BOSS_MB implements Algorithm, HasKnowledge, UsesScoreWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
private String targets;
+ private List bootstrapGraphs = new ArrayList<>();
+
public BOSS_MB() {
}
@@ -85,7 +89,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -143,4 +149,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java
index ef5e0bb134..1468be1959 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
@@ -31,11 +32,14 @@
//)
//@Bootstrapping
//@Experimental
-public class BOSS_MB2 implements Algorithm, HasKnowledge, UsesScoreWrapper {
+public class BOSS_MB2 implements Algorithm, HasKnowledge, UsesScoreWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public BOSS_MB2() {
}
@@ -65,7 +69,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -117,4 +123,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java
index cf922aee8b..79b94c1fef 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
@@ -33,12 +34,15 @@
//)
//@Bootstrapping
//@Experimental
-public class BRIDGES implements Algorithm, HasKnowledge, UsesScoreWrapper {
+public class BRIDGES implements Algorithm, HasKnowledge, UsesScoreWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public BRIDGES() {
@@ -94,7 +98,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -149,4 +155,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java
index f00a755db5..cfe1f18dbe 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
@@ -33,12 +34,15 @@
//)
//@Bootstrapping
//@Experimental
-public class BRIDGES2 implements Algorithm, HasKnowledge, UsesScoreWrapper {
+public class BRIDGES2 implements Algorithm, HasKnowledge, UsesScoreWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public BRIDGES2() {
@@ -87,7 +91,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -142,4 +148,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java
index 48d8b72b2a..d0d1c24f59 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -33,11 +34,14 @@
algoType = AlgType.forbid_latent_common_causes
)
@Bootstrapping
-public class CPC implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class CPC implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public CPC() {
}
@@ -63,7 +67,8 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setDepth(parameters.getInt(Params.DEPTH));
search.setAggressivelyPreventCycles(true);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS));
+ search.setKnowledge(knowledge);
+// search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS));
search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC));
search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH));
return search.search();
@@ -76,7 +81,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -99,7 +106,7 @@ public DataType getDataType() {
public List getParameters() {
List parameters = new ArrayList<>();
parameters.add(Params.STABLE_FAS);
- parameters.add(Params.CONCURRENT_FAS);
+// parameters.add(Params.CONCURRENT_FAS);
// parameters.add(Params.COLLIDER_DISCOVERY_RULE);
parameters.add(Params.CONFLICT_RULE);
parameters.add(Params.DEPTH);
@@ -132,4 +139,8 @@ public void setIndependenceWrapper(IndependenceWrapper test) {
this.test = test;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java
similarity index 81%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java
index 6f8c3ea910..73c9ebbb5e 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -26,21 +27,24 @@
* @author jdramsey
*/
@Bootstrapping
-public class CpcStable implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class CPC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Algorithm algorithm;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public CpcStable() {
+
+ public CPC_STABLE() {
}
- public CpcStable(IndependenceWrapper test) {
+ public CPC_STABLE(IndependenceWrapper test) {
this.test = test;
}
- public CpcStable(IndependenceWrapper test, Algorithm algorithm) {
+ public CPC_STABLE(IndependenceWrapper test, Algorithm algorithm) {
this.test = test;
this.algorithm = algorithm;
}
@@ -53,13 +57,14 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setDepth(parameters.getInt(Params.DEPTH));
search.setKnowledge(this.knowledge);
search.setFasType(PcAll.FasType.STABLE);
- search.setConcurrent(PcAll.Concurrent.NO);
+ search.setKnowledge(knowledge);
+// search.setConcurrent(PcAll.Concurrent.NO);
search.setColliderDiscovery(PcAll.ColliderDiscovery.CONSERVATIVE);
search.setConflictRule(PcAll.ConflictRule.PRIORITY);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
return search.search();
} else {
- CpcStable cpcStable = new CpcStable(this.test, this.algorithm);
+ CPC_STABLE cpcStable = new CPC_STABLE(this.test, this.algorithm);
DataSet data = (DataSet) dataSet;
GeneralResamplingTest search = new GeneralResamplingTest(data, cpcStable, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -67,7 +72,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -114,4 +121,9 @@ public void setIndependenceWrapper(IndependenceWrapper independenceWrapper) {
public IndependenceWrapper getIndependenceWrapper() {
return this.test;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java
index 6364478975..fe4f7bcbe9 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -33,11 +34,14 @@
algoType = AlgType.produce_undirected_graphs
)
@Bootstrapping
-public class FAS implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class FAS implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public FAS() {
}
@@ -71,7 +75,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -119,4 +125,9 @@ public IndependenceWrapper getIndependenceWrapper() {
public void setIndependenceWrapper(IndependenceWrapper test) {
this.test = test;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java
similarity index 89%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Fges.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java
index d0d1829513..95ecf03b76 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Fges.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesExternalGraph;
@@ -34,7 +35,7 @@
algoType = AlgType.forbid_latent_common_causes
)
@Bootstrapping
-public class Fges implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExternalGraph {
+public class FGES implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExternalGraph, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
@@ -44,12 +45,13 @@ public class Fges implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExt
private Graph externalGraph = null;
private Algorithm algorithm = null;
+ private List bootstrapGraphs = new ArrayList<>();
- public Fges() {
+ public FGES() {
}
- public Fges(ScoreWrapper score) {
+ public FGES(ScoreWrapper score) {
this.score = score;
}
@@ -98,7 +100,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return graph;
} else {
- Fges fges = new Fges(this.score);
+ FGES fges = new FGES(this.score);
if (this.algorithm != null) {
fges.setExternalGraph(this.algorithm);
}
@@ -111,7 +113,10 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -169,4 +174,9 @@ public void setScoreWrapper(ScoreWrapper score) {
public void setExternalGraph(Algorithm algorithm) {
this.algorithm = algorithm;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java
similarity index 87%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java
index bed3584b83..5ba19bb41a 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
@@ -35,17 +36,20 @@
algoType = AlgType.search_for_Markov_blankets
)
@Bootstrapping
-public class FgesMb implements Algorithm, HasKnowledge, UsesScoreWrapper {
+public class FGES_MB implements Algorithm, HasKnowledge, UsesScoreWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
private String targetName;
+ private List bootstrapGraphs = new ArrayList<>();
- public FgesMb() {
+
+ public FGES_MB() {
}
- public FgesMb(ScoreWrapper score) {
+ public FGES_MB(ScoreWrapper score) {
this.score = score;
}
@@ -69,14 +73,16 @@ public Graph search(DataModel dataSet, Parameters parameters) {
return search.search(Collections.singletonList(target));
} else {
- FgesMb fgesMb = new FgesMb(this.score);
+ FGES_MB fgesMb = new FGES_MB(this.score);
DataSet data = (DataSet) dataSet;
GeneralResamplingTest search = new GeneralResamplingTest(data, fgesMb, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -127,4 +133,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java
similarity index 86%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java
index 2fff224afb..0b25e9b308 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.annotation.Bootstrapping;
@@ -25,13 +26,15 @@
* @author jdramsey
*/
@Bootstrapping
-public class FgesMeasurement implements Algorithm, HasKnowledge {
+public class FGES_MEASUREMENT implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private final ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public FgesMeasurement(ScoreWrapper score) {
+
+ public FGES_MEASUREMENT(ScoreWrapper score) {
this.score = score;
}
@@ -66,7 +69,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return search.search();
} else {
- FgesMeasurement fgesMeasurement = new FgesMeasurement(this.score);
+ FGES_MEASUREMENT fgesMeasurement = new FGES_MEASUREMENT(this.score);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, fgesMeasurement, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -74,7 +77,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -114,4 +119,8 @@ public void setKnowledge(Knowledge knowledge) {
this.knowledge = new Knowledge((Knowledge) knowledge);
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java
similarity index 93%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java
index 75e8662fdc..45367e8ea8 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.score.SemBicScoreDeterministic;
import edu.cmu.tetrad.annotation.Bootstrapping;
@@ -30,17 +31,19 @@
*/
@Bootstrapping
@Experimental
-public class GesMe implements Algorithm {
+public class GES_ME implements Algorithm, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private boolean compareToTrue;
private final ScoreWrapper score = new SemBicScoreDeterministic();
+ private List bootstrapGraphs = new ArrayList<>();
- public GesMe() {
+
+ public GES_ME() {
setCompareToTrue(false);
}
- public GesMe(boolean compareToTrueGraph) {
+ public GES_ME(boolean compareToTrueGraph) {
setCompareToTrue(compareToTrueGraph);
}
@@ -170,14 +173,16 @@ public Graph search(DataModel dataSet, Parameters parameters) {
return search.search();
} else {
- GesMe algorithm = new GesMe(this.compareToTrue);
+ GES_ME algorithm = new GES_ME(this.compareToTrue);
DataSet data = (DataSet) dataSet;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -244,4 +249,8 @@ private String tableString(Matrix matrix, NumberFormat nf, double threshold) {
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java
similarity index 89%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSP.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java
index fb9d17ad67..ec27882df1 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSP.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -32,22 +33,25 @@
* @author josephramsey
*/
@edu.cmu.tetrad.annotation.Algorithm(
- name = "GRaSP",
+ name = "GRASP",
command = "grasp",
algoType = AlgType.forbid_latent_common_causes
)
@Bootstrapping
-public class GRaSP implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge {
+public class GRASP implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper,
+ HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public GRaSP() {
+
+ public GRASP() {
// Used in reflection; do not delete.
}
- public GRaSP(ScoreWrapper score, IndependenceWrapper test) {
+ public GRASP(IndependenceWrapper test, ScoreWrapper score) {
this.score = score;
this.test = test;
}
@@ -79,14 +83,13 @@ public Graph search(DataModel dataModel, Parameters parameters) {
grasp.setUseRaskuttiUhler(parameters.getBoolean(Params.GRASP_USE_RASKUTTI_UHLER));
grasp.setUseDataOrder(parameters.getBoolean(Params.GRASP_USE_DATA_ORDER));
grasp.setVerbose(parameters.getBoolean(Params.VERBOSE));
- grasp.setCacheScores(parameters.getBoolean(Params.CACHE_SCORES));
grasp.setNumStarts(parameters.getInt(Params.NUM_STARTS));
grasp.setKnowledge(this.knowledge);
grasp.bestOrder(score.getVariables());
return grasp.getGraph(parameters.getBoolean(Params.OUTPUT_CPDAG));
} else {
- GRaSP algorithm = new GRaSP(this.score, this.test);
+ GRASP algorithm = new GRASP(this.test, this.score);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -95,7 +98,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -126,7 +131,6 @@ public List getParameters() {
params.add(Params.GRASP_ORDERED_ALG);
params.add(Params.GRASP_USE_RASKUTTI_UHLER);
params.add(Params.GRASP_USE_DATA_ORDER);
- params.add(Params.CACHE_SCORES);
params.add(Params.TIME_LAG);
params.add(Params.VERBOSE);
@@ -165,4 +169,9 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = new Knowledge((Knowledge) knowledge);
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java
similarity index 90%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java
index 6070e35441..25c1664216 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -39,17 +40,20 @@
)
@Bootstrapping
@Experimental
-public class GRaSPTol implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge {
+public class GRASP_TOL implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper,
+ HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public GRaSPTol() {
+
+ public GRASP_TOL() {
// Used in reflection; do not delete.
}
- public GRaSPTol(ScoreWrapper score, IndependenceWrapper test) {
+ public GRASP_TOL(ScoreWrapper score, IndependenceWrapper test) {
this.score = score;
this.test = test;
}
@@ -83,14 +87,13 @@ public Graph search(DataModel dataModel, Parameters parameters) {
grasp.setToleranceDepth(parameters.getInt(Params.GRASP_TOLERANCE_DEPTH));
grasp.setAllowRandomnessInsideAlgorithm(parameters.getBoolean(Params.GRASP_ALLOW_RANDOMNESS_INSIDE_ALGORITHM));
grasp.setVerbose(parameters.getBoolean(Params.VERBOSE));
- grasp.setCacheScores(parameters.getBoolean(Params.CACHE_SCORES));
grasp.setNumStarts(parameters.getInt(Params.NUM_STARTS));
grasp.setKnowledge(this.knowledge);
grasp.bestOrder(score.getVariables());
return grasp.getGraph(parameters.getBoolean(Params.OUTPUT_CPDAG));
} else {
- GRaSPTol algorithm = new GRaSPTol(this.score, this.test);
+ GRASP_TOL algorithm = new GRASP_TOL(this.score, this.test);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -99,7 +102,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -172,4 +177,9 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = new Knowledge((Knowledge) knowledge);
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java
index 06ce9f26a8..a5638cc26c 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -33,13 +34,16 @@
algoType = AlgType.forbid_latent_common_causes
)
@Bootstrapping
-public class PC implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class PC implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
private Graph externalGraph = null;
+ private List bootstrapGraphs = new ArrayList<>();
+
public PC() {
}
@@ -65,7 +69,8 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setDepth(parameters.getInt(Params.DEPTH));
search.setAggressivelyPreventCycles(true);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS));
+ dataModel.setKnowledge(this.knowledge);
+// search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS));
search.setUseMaxP(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC));
search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH));
return search.search();
@@ -78,7 +83,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -101,7 +108,7 @@ public DataType getDataType() {
public List getParameters() {
List parameters = new ArrayList<>();
parameters.add(Params.STABLE_FAS);
- parameters.add(Params.CONCURRENT_FAS);
+// parameters.add(Params.CONCURRENT_FAS);
// parameters.add(Params.COLLIDER_DISCOVERY_RULE);
parameters.add(Params.CONFLICT_RULE);
parameters.add(Params.DEPTH);
@@ -137,4 +144,9 @@ public void setIndependenceWrapper(IndependenceWrapper test) {
public void setExternalGraph(Graph externalGraph) {
this.externalGraph = externalGraph;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java
similarity index 88%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java
index 8abc4cd458..d46df5b6ae 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.annotation.Bootstrapping;
import edu.cmu.tetrad.data.*;
@@ -21,11 +22,12 @@
* @author jdramsey
*/
@Bootstrapping
-public class Pcd implements Algorithm, HasKnowledge {
+public class PCD implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public Pcd() {
+ public PCD() {
}
@Override
@@ -53,7 +55,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
return search.search();
} else {
- Pcd algorithm = new Pcd();
+ PCD algorithm = new PCD();
DataSet data = (DataSet) dataSet;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -61,7 +63,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -101,4 +105,9 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = new Knowledge((Knowledge) knowledge);
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java
index d7d64eb97b..d04bcd95ee 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -33,13 +34,16 @@
algoType = AlgType.forbid_latent_common_causes
)
@Bootstrapping
-public class PCMAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class PCMAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
private Graph externalGraph = null;
+ private List bootstrapGraphs = new ArrayList<>();
+
public PCMAX() {
}
@@ -65,7 +69,8 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setDepth(parameters.getInt(Params.DEPTH));
search.setAggressivelyPreventCycles(true);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS));
+ dataModel.setKnowledge(this.knowledge);
+// search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS));
search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC));
search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH));
return search.search();
@@ -78,7 +83,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -101,7 +108,7 @@ public DataType getDataType() {
public List getParameters() {
List parameters = new ArrayList<>();
parameters.add(Params.STABLE_FAS);
- parameters.add(Params.CONCURRENT_FAS);
+// parameters.add(Params.CONCURRENT_FAS);
// parameters.add(Params.COLLIDER_DISCOVERY_RULE);
parameters.add(Params.CONFLICT_RULE);
parameters.add(Params.DEPTH);
@@ -137,4 +144,9 @@ public void setIndependenceWrapper(IndependenceWrapper test) {
public void setExternalGraph(Graph externalGraph) {
this.externalGraph = externalGraph;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java
index 2d08574a10..bc05498271 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -35,12 +36,14 @@
algoType = AlgType.search_for_Markov_blankets
)
@Bootstrapping
-public class PC_MB implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class PC_MB implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
private List targets;
+ private List bootstrapGraphs = new ArrayList<>();
public PC_MB() {
}
@@ -69,7 +72,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -130,4 +135,9 @@ public void setIndependenceWrapper(IndependenceWrapper test) {
public IndependenceWrapper getIndependenceWrapper() {
return this.test;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java
similarity index 83%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java
index 47415da71b..6013c46198 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -26,16 +27,19 @@
* @author jdramsey
*/
@Bootstrapping
-public class PcStable implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class PC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public PcStable() {
+
+ public PC_STABLE() {
}
- public PcStable(IndependenceWrapper test) {
+ public PC_STABLE(IndependenceWrapper test) {
this.test = test;
}
@@ -46,13 +50,13 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setDepth(parameters.getInt(Params.DEPTH));
search.setKnowledge(this.knowledge);
search.setFasType(PcAll.FasType.STABLE);
- search.setConcurrent(PcAll.Concurrent.NO);
+// search.setConcurrent(PcAll.Concurrent.NO);
search.setColliderDiscovery(PcAll.ColliderDiscovery.FAS_SEPSETS);
search.setConflictRule(PcAll.ConflictRule.PRIORITY);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
return search.search();
} else {
- PcStable pcStable = new PcStable(this.test);
+ PC_STABLE pcStable = new PC_STABLE(this.test);
DataSet data = (DataSet) dataSet;
GeneralResamplingTest search = new GeneralResamplingTest(data, pcStable, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -60,7 +64,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -108,4 +114,9 @@ public void setIndependenceWrapper(IndependenceWrapper independenceWrapper) {
public IndependenceWrapper getIndependenceWrapper() {
return this.test;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcAll.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcAll.java
deleted file mode 100644
index f349b7fa31..0000000000
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcAll.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
-
-import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
-import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
-import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
-import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
-import edu.cmu.tetrad.annotation.Bootstrapping;
-import edu.cmu.tetrad.annotation.Experimental;
-import edu.cmu.tetrad.data.DataModel;
-import edu.cmu.tetrad.data.DataSet;
-import edu.cmu.tetrad.data.DataType;
-import edu.cmu.tetrad.data.Knowledge;
-import edu.cmu.tetrad.graph.EdgeListGraph;
-import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.SearchGraphUtils;
-import edu.cmu.tetrad.util.Parameters;
-import edu.cmu.tetrad.util.Params;
-import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * CPC.
- *
- * @author jdramsey
- */
-//@edu.cmu.tetrad.annotation.Algorithm(
-// name = "PC Variants",
-// command = "pc-all",
-// algoType = AlgType.forbid_latent_common_causes
-//)
-@Experimental
-@Bootstrapping
-public class PcAll implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
-
- static final long serialVersionUID = 23L;
- private IndependenceWrapper test;
- private Knowledge knowledge = new Knowledge();
-
- public PcAll() {
- }
-
- public PcAll(IndependenceWrapper test) {
- this.test = test;
- }
-
- @Override
- public Graph search(DataModel dataSet, Parameters parameters) {
- if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
- edu.cmu.tetrad.search.PcAll.ColliderDiscovery colliderDiscovery;
-
- switch (parameters.getInt(Params.COLLIDER_DISCOVERY_RULE)) {
- case 1:
- colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.FAS_SEPSETS;
- break;
- case 2:
- colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.CONSERVATIVE;
- break;
- case 3:
- colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.MAX_P;
- break;
- default:
- throw new IllegalArgumentException("Not a choice.");
- }
-
- edu.cmu.tetrad.search.PcAll.ConflictRule conflictRule;
-
- switch (parameters.getInt(Params.CONFLICT_RULE)) {
- case 1:
- conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.OVERWRITE;
- break;
- case 2:
- conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.BIDIRECTED;
- break;
- case 3:
- conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.PRIORITY;
- break;
- default:
- throw new IllegalArgumentException("Not a choice.");
- }
-
- edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(this.test.getTest(dataSet, parameters));
- search.setDepth(parameters.getInt(Params.DEPTH));
- search.setHeuristic(parameters.getInt(Params.FAS_HEURISTIC));
- search.setKnowledge(this.knowledge);
-
- if (parameters.getBoolean(Params.STABLE_FAS)) {
- search.setFasType(edu.cmu.tetrad.search.PcAll.FasType.STABLE);
- } else {
- search.setFasType(edu.cmu.tetrad.search.PcAll.FasType.REGULAR);
- }
-
- if (parameters.getBoolean(Params.CONCURRENT_FAS)) {
- search.setConcurrent(edu.cmu.tetrad.search.PcAll.Concurrent.YES);
- } else {
- search.setConcurrent(edu.cmu.tetrad.search.PcAll.Concurrent.NO);
- }
-
- search.setColliderDiscovery(colliderDiscovery);
- search.setConflictRule(conflictRule);
- search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC));
- search.setMaxPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH));
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
-
- return search.search();
- } else {
- PcAll pcAll = new PcAll(this.test);
-
- DataSet data = (DataSet) dataSet;
- GeneralResamplingTest search = new GeneralResamplingTest(data, pcAll, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(this.knowledge);
-
- search.setParameters(parameters);
- search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
- }
- }
-
- @Override
- public Graph getComparisonGraph(Graph graph) {
- return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph));
- }
-
- @Override
- public String getDescription() {
- return "PC using " + this.test.getDescription();
- }
-
- @Override
- public DataType getDataType() {
- return this.test.getDataType();
- }
-
- @Override
- public List getParameters() {
- List parameters = new ArrayList<>();
- parameters.add(Params.STABLE_FAS);
- parameters.add(Params.CONCURRENT_FAS);
- parameters.add(Params.COLLIDER_DISCOVERY_RULE);
- parameters.add(Params.CONFLICT_RULE);
- parameters.add(Params.DEPTH);
- parameters.add(Params.FAS_HEURISTIC);
- parameters.add(Params.USE_MAX_P_ORIENTATION_HEURISTIC);
- parameters.add(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH);
-
- parameters.add(Params.VERBOSE);
- return parameters;
- }
-
- @Override
- public Knowledge getKnowledge() {
- return this.knowledge;
- }
-
- @Override
- public void setKnowledge(Knowledge knowledge) {
- this.knowledge = new Knowledge((Knowledge) knowledge);
- }
-
- @Override
- public IndependenceWrapper getIndependenceWrapper() {
- return this.test;
- }
-
- @Override
- public void setIndependenceWrapper(IndependenceWrapper test) {
- this.test = test;
- }
-
-}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SINGLE_GRAPH_ALG.java
similarity index 92%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SINGLE_GRAPH_ALG.java
index 9993219c6a..14340cb72c 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SINGLE_GRAPH_ALG.java
@@ -17,12 +17,12 @@
*
* @author jdramsey
*/
-public class SingleGraphAlg implements Algorithm, HasKnowledge {
+public class SINGLE_GRAPH_ALG implements Algorithm, HasKnowledge {
static final long serialVersionUID = 23L;
private final Graph graph;
- public SingleGraphAlg(Graph graph) {
+ public SINGLE_GRAPH_ALG(Graph graph) {
this.graph = graph;
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java
index 17714b7e91..391a340df4 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
@@ -8,15 +9,15 @@
import edu.cmu.tetrad.annotation.Bootstrapping;
import edu.cmu.tetrad.annotation.Experimental;
import edu.cmu.tetrad.data.DataModel;
+import edu.cmu.tetrad.data.DataSet;
import edu.cmu.tetrad.data.DataType;
import edu.cmu.tetrad.data.Knowledge;
import edu.cmu.tetrad.graph.EdgeListGraph;
import edu.cmu.tetrad.graph.Graph;
-import edu.cmu.tetrad.search.PermutationSearch;
-import edu.cmu.tetrad.search.Score;
-import edu.cmu.tetrad.search.Sp;
+import edu.cmu.tetrad.search.*;
import edu.cmu.tetrad.util.Parameters;
import edu.cmu.tetrad.util.Params;
+import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
import java.util.ArrayList;
import java.util.List;
@@ -34,10 +35,12 @@
)
@Bootstrapping
@Experimental
-public class SP implements Algorithm, UsesScoreWrapper, HasKnowledge {
+public class SP implements Algorithm, UsesScoreWrapper, HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public SP() {
// Used in reflection; do not delete.
@@ -50,12 +53,37 @@ public SP(ScoreWrapper score) {
@Override
public Graph search(DataModel dataModel, Parameters parameters) {
- Score score = this.score.getScore(dataModel, parameters);
- PermutationSearch permutationSearch = new PermutationSearch(new Sp(score));
- permutationSearch.setKnowledge(this.knowledge);
- permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE));
-
- return permutationSearch.search();
+ if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) {
+ if (parameters.getInt(Params.TIME_LAG) > 0) {
+ DataSet dataSet = (DataSet) dataModel;
+ DataSet timeSeries = TimeSeriesUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG));
+ if (dataSet.getName() != null) {
+ timeSeries.setName(dataSet.getName());
+ }
+ dataModel = timeSeries;
+ knowledge = timeSeries.getKnowledge();
+ }
+
+ Score score = this.score.getScore(dataModel, parameters);
+ PermutationSearch permutationSearch = new PermutationSearch(new Sp(score));
+ permutationSearch.setKnowledge(this.knowledge);
+ permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE));
+
+ return permutationSearch.search();
+ } else {
+ SP algorithm = new SP(this.score);
+
+ DataSet data = (DataSet) dataModel;
+ GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
+ search.setKnowledge(this.knowledge);
+
+
+ search.setParameters(parameters);
+ search.setVerbose(parameters.getBoolean(Params.VERBOSE));
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
+ }
}
@Override
@@ -103,4 +131,9 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = knowledge;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java
index 08ad58d539..226fe914f9 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -45,12 +46,15 @@
)
@Bootstrapping
@Experimental
-public class BFCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge {
+public class BFCI implements Algorithm, UsesScoreWrapper,
+ TakesIndependenceWrapper, HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public BFCI() {
// Used for reflection; do not delete.
@@ -97,10 +101,12 @@ public Graph search(DataModel dataModel, Parameters parameters) {
BFCI algorithm = new BFCI(this.test, this.score);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(data.getKnowledge());
+ search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -168,4 +174,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java
index 30b0852d49..79f79d590a 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -42,12 +43,15 @@
//)
//@Bootstrapping
//@Experimental
-public class BFCITR implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge {
+public class BFCITR implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper,
+ HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public BFCITR() {
// Used for reflection; do not delete.
@@ -76,7 +80,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setMaxPathLength(parameters.getInt(Params.MAX_PATH_LENGTH));
search.setCompleteRuleSetUsed(parameters.getBoolean(Params.COMPLETE_RULE_SET_USED));
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- search.setKnowledge(knowledge);
+ dataModel.setKnowledge(this.knowledge);
Object obj = parameters.get(Params.PRINT_STREAM);
@@ -89,10 +93,12 @@ public Graph search(DataModel dataModel, Parameters parameters) {
BFCITR algorithm = new BFCITR(this.test, this.score);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(data.getKnowledge());
+ search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -165,4 +171,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java
index c31da6d72f..9b893df318 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
import edu.cmu.tetrad.annotation.AlgType;
@@ -15,6 +16,7 @@
import edu.cmu.tetrad.util.Params;
import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -28,10 +30,12 @@
algoType = AlgType.forbid_latent_common_causes
)
@Bootstrapping
-@Experimental
-public class CCD implements Algorithm, TakesIndependenceWrapper {
+//@Experimental
+public class CCD implements Algorithm, TakesIndependenceWrapper, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
+ private List bootstrapGraphs = new ArrayList<>();
+
public CCD() {
// Used in reflection; do not delete.
@@ -58,7 +62,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -97,4 +103,9 @@ public IndependenceWrapper getIndependenceWrapper() {
public void setIndependenceWrapper(IndependenceWrapper independenceWrapper) {
this.test = independenceWrapper;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java
similarity index 87%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java
index f47f0d8221..99c94ad1b4 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.annotation.Bootstrapping;
@@ -15,6 +16,7 @@
import edu.cmu.tetrad.util.Params;
import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -29,13 +31,15 @@
oracleType = OracleType.Test
)*/
@Bootstrapping
-public class CcdMax implements Algorithm, HasKnowledge {
+public class CCD_MAX implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private final IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public CcdMax(IndependenceWrapper test) {
+
+ public CCD_MAX(IndependenceWrapper test) {
this.test = test;
}
@@ -53,7 +57,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setUseOrientTowardDConnections(parameters.getBoolean(Params.ORIENT_TOWARD_DCONNECTIONS));
return search.search();
} else {
- CcdMax algorithm = new CcdMax(this.test);
+ CCD_MAX algorithm = new CCD_MAX(this.test);
DataSet data = (DataSet) dataSet;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -61,7 +65,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -107,4 +113,9 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = new Knowledge((Knowledge) knowledge);
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java
similarity index 85%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Cfci.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java
index ace07f86e1..924b881e88 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Cfci.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.annotation.Bootstrapping;
@@ -14,6 +15,7 @@
import edu.cmu.tetrad.util.Params;
import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest;
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -25,13 +27,15 @@
* @author jdramsey
*/
@Bootstrapping
-public class Cfci implements Algorithm, HasKnowledge {
+public class CFCI implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private final IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public Cfci(IndependenceWrapper test) {
+
+ public CFCI(IndependenceWrapper test) {
this.test = test;
}
@@ -46,7 +50,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setDoDiscriminatingPathRule(parameters.getBoolean(Params.DO_DISCRIMINATING_PATH_RULE));
return search.search();
} else {
- Cfci algorithm = new Cfci(this.test);
+ CFCI algorithm = new CFCI(this.test);
DataSet data = (DataSet) dataSet;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -54,7 +58,9 @@ public Graph search(DataModel dataSet, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -96,4 +102,9 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = new Knowledge((Knowledge) knowledge);
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java
similarity index 89%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Fci.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java
index a9ea4e9e97..ca47ca337d 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Fci.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -33,16 +34,19 @@
algoType = AlgType.allow_latent_common_causes
)
@Bootstrapping
-public class Fci implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public Fci() {
+
+ public FCI() {
}
- public Fci(IndependenceWrapper test) {
+ public FCI(IndependenceWrapper test) {
this.test = test;
}
@@ -72,7 +76,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return search.search();
} else {
- Fci algorithm = new Fci(this.test);
+ FCI algorithm = new FCI(this.test);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -80,7 +84,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -135,4 +141,8 @@ public void setIndependenceWrapper(IndependenceWrapper test) {
this.test = test;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java
similarity index 88%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java
index c7fc7a0602..d12c2069aa 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -33,16 +34,19 @@
algoType = AlgType.allow_latent_common_causes
)
@Bootstrapping
-public class FciMax implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class FCI_MAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public FciMax() {
+
+ public FCI_MAX() {
}
- public FciMax(IndependenceWrapper test) {
+ public FCI_MAX(IndependenceWrapper test) {
this.test = test;
}
@@ -70,7 +74,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return search.search();
} else {
- FciMax algorithm = new FciMax(this.test);
+ FCI_MAX algorithm = new FCI_MAX(this.test);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -78,7 +82,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -131,4 +137,8 @@ public void setIndependenceWrapper(IndependenceWrapper test) {
this.test = test;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java
index 9d130c6925..f138cf04ed 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -37,12 +38,14 @@
algoType = AlgType.allow_latent_common_causes
)
@Bootstrapping
-public class GFCI implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper {
+public class GFCI implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
public GFCI() {
}
@@ -91,7 +94,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -157,4 +162,8 @@ public IndependenceWrapper getIndependenceWrapper() {
return this.test;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java
index 6b25c232c8..774e3dea67 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -45,12 +46,15 @@
algoType = AlgType.allow_latent_common_causes
)
@Bootstrapping
-public class GRASP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge {
+public class GRASP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper,
+ HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
public GRASP_FCI() {
// Used for reflection; do not delete.
@@ -88,7 +92,6 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setUseScore(parameters.getBoolean(Params.GRASP_USE_SCORE));
search.setUseRaskuttiUhler(parameters.getBoolean(Params.GRASP_USE_RASKUTTI_UHLER));
search.setUseDataOrder(parameters.getBoolean(Params.GRASP_USE_DATA_ORDER));
- search.setCacheScores(parameters.getBoolean(Params.CACHE_SCORES));
search.setNumStarts(parameters.getInt(Params.NUM_STARTS));
// FCI
@@ -114,11 +117,13 @@ public Graph search(DataModel dataModel, Parameters parameters) {
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(data.getKnowledge());
+ search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -149,7 +154,6 @@ public List getParameters() {
params.add(Params.GRASP_ORDERED_ALG);
params.add(Params.GRASP_USE_RASKUTTI_UHLER);
params.add(Params.GRASP_USE_DATA_ORDER);
- params.add(Params.CACHE_SCORES);
params.add(Params.NUM_STARTS);
// FCI
@@ -197,4 +201,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSamplingRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java
similarity index 94%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSamplingRfci.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java
index 5d9cd41e2f..06dbdcbf13 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSamplingRfci.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.independence.ProbabilisticTest;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -14,6 +15,7 @@
import edu.cmu.tetrad.util.Parameters;
import edu.cmu.tetrad.util.Params;
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -30,7 +32,7 @@
algoType = AlgType.allow_latent_common_causes
)
//@Experimental
-public class PagSamplingRfci implements Algorithm, HasKnowledge {
+public class PAG_SAMPLING_RFCI implements Algorithm, HasKnowledge{
public static final List PAG_SAMPLING_RFCI_PARAMETERS = new LinkedList<>();
public static final List RFCI_PARAMETERS = new LinkedList<>();
@@ -54,6 +56,8 @@ public class PagSamplingRfci implements Algorithm, HasKnowledge {
static final long serialVersionUID = 23L;
private final IndependenceWrapper test = new ProbabilisticTest();
private Knowledge knowledge;
+ private List bootstrapGraphs = new ArrayList<>();
+
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
@@ -111,5 +115,4 @@ public Knowledge getKnowledge() {
public void setKnowledge(Knowledge knowledge) {
this.knowledge = knowledge;
}
-
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java
similarity index 87%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Rfci.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java
index 9dab978c3c..c000d8bfc0 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Rfci.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -33,16 +34,18 @@
algoType = AlgType.allow_latent_common_causes
)
@Bootstrapping
-public class Rfci implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class RFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public Rfci() {
+
+ public RFCI() {
}
- public Rfci(IndependenceWrapper test) {
+ public RFCI(IndependenceWrapper test) {
this.test = test;
}
@@ -66,14 +69,16 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
return search.search();
} else {
- Rfci algorithm = new Rfci(this.test);
+ RFCI algorithm = new RFCI(this.test);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -122,4 +127,9 @@ public IndependenceWrapper getIndependenceWrapper() {
public void setIndependenceWrapper(IndependenceWrapper test) {
this.test = test;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java
similarity index 95%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java
index 83ef2a3a94..e9edeefa15 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.independence.ProbabilisticTest;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -31,11 +32,13 @@
dataType = DataType.Discrete
)
@Experimental
-public class RfciBsc implements Algorithm, HasKnowledge {
+public class RFCI_BSC implements Algorithm, HasKnowledge {
static final long serialVersionUID = 23L;
private final IndependenceWrapper test = new ProbabilisticTest();
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
+
@Override
public Knowledge getKnowledge() {
@@ -108,5 +111,4 @@ public List getParameters() {
return parameters;
}
-
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SPFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java
similarity index 86%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SPFCI.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java
index 08c9cbe01e..9d2b2d9e05 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SPFCI.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -42,18 +43,21 @@
algoType = AlgType.allow_latent_common_causes
)
@Bootstrapping
-public class SPFCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge {
+public class SP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper,
+ HasKnowledge, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private ScoreWrapper score;
private Knowledge knowledge = new Knowledge();
+ private List bootstrapGraphs = new ArrayList<>();
- public SPFCI() {
+
+ public SP_FCI() {
// Used for reflection; do not delete.
}
- public SPFCI(ScoreWrapper score, IndependenceWrapper test) {
+ public SP_FCI(IndependenceWrapper test, ScoreWrapper score) {
this.test = test;
this.score = score;
}
@@ -66,7 +70,6 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setMaxPathLength(parameters.getInt(Params.MAX_PATH_LENGTH));
search.setCompleteRuleSetUsed(parameters.getBoolean(Params.COMPLETE_RULE_SET_USED));
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- search.setKnowledge(search.getKnowledge());
Object obj = parameters.get(Params.PRINT_STREAM);
@@ -76,13 +79,15 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return search.search();
} else {
- SPFCI algorithm = new SPFCI(this.score, this.test);
+ SP_FCI algorithm = new SP_FCI(this.test, this.score);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
- search.setKnowledge(data.getKnowledge());
+ search.setKnowledge(this.knowledge);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -150,4 +155,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java
similarity index 85%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java
index b96ceed770..442772741b 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
@@ -35,16 +36,19 @@
)
@TimeSeries
@Bootstrapping
-public class SvarFci implements Algorithm, HasKnowledge, TakesIndependenceWrapper {
+public class SVAR_FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private Knowledge knowledge;
+ private List bootstrapGraphs = new ArrayList<>();
- public SvarFci() {
+
+ public SVAR_FCI() {
}
- public SvarFci(IndependenceWrapper test) {
+ public SVAR_FCI(IndependenceWrapper test) {
this.test = test;
}
@@ -61,9 +65,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
knowledge = timeSeries.getKnowledge();
}
- if (this.knowledge != null) {
- dataModel.setKnowledge(this.knowledge);
- }
+ dataModel.setKnowledge(this.knowledge);
edu.cmu.tetrad.search.SvarFci search = new edu.cmu.tetrad.search.SvarFci(this.test.getTest(dataModel, parameters));
search.setDepth(parameters.getInt(Params.DEPTH));
search.setKnowledge(this.knowledge);
@@ -71,7 +73,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return search.search();
} else {
- SvarFci svarFci = new SvarFci(this.test);
+ SVAR_FCI svarFci = new SVAR_FCI(this.test);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, svarFci, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -79,7 +81,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -125,4 +129,9 @@ public IndependenceWrapper getIndependenceWrapper() {
public void setIndependenceWrapper(IndependenceWrapper test) {
this.test = test;
}
+
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java
similarity index 86%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java
index af4071c333..3e836986ea 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java
@@ -1,6 +1,7 @@
package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithm;
+import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.utils.HasKnowledge;
@@ -37,17 +38,20 @@
)
@TimeSeries
@Bootstrapping
-public class SvarGfci implements Algorithm, HasKnowledge, TakesIndependenceWrapper, UsesScoreWrapper {
+public class SVAR_GFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper,
+ UsesScoreWrapper, ReturnsBootstrapGraphs {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private ScoreWrapper score;
private Knowledge knowledge;
+ private List bootstrapGraphs = new ArrayList<>();
- public SvarGfci() {
+
+ public SVAR_GFCI() {
}
- public SvarGfci(IndependenceWrapper type, ScoreWrapper score) {
+ public SVAR_GFCI(IndependenceWrapper type, ScoreWrapper score) {
this.test = type;
this.score = score;
}
@@ -66,9 +70,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
knowledge = timeSeries.getKnowledge();
}
- if (this.knowledge != null) {
- dataModel.setKnowledge(this.knowledge);
- }
+ dataModel.setKnowledge(this.knowledge);
edu.cmu.tetrad.search.SvarGFci search = new edu.cmu.tetrad.search.SvarGFci(this.test.getTest(dataModel, parameters),
this.score.getScore(dataModel, parameters));
search.setKnowledge(this.knowledge);
@@ -77,7 +79,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return search.search();
} else {
- SvarGfci algorithm = new SvarGfci(this.test, this.score);
+ SVAR_GFCI algorithm = new SVAR_GFCI(this.test, this.score);
DataSet data = (DataSet) dataModel;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
@@ -85,7 +87,9 @@ public Graph search(DataModel dataModel, Parameters parameters) {
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean(Params.VERBOSE));
- return search.search();
+ Graph graph = search.search();
+ this.bootstrapGraphs = search.getGraphs();
+ return graph;
}
}
@@ -146,4 +150,8 @@ public void setScoreWrapper(ScoreWrapper score) {
this.score = score;
}
+ @Override
+ public List getBootstrapGraphs() {
+ return this.bootstrapGraphs;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CStaR.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CSTAR.java
similarity index 98%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CStaR.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CSTAR.java
index 5306829bf1..6b90b526bd 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CStaR.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CSTAR.java
@@ -26,12 +26,12 @@
command = "cstar",
algoType = AlgType.forbid_latent_common_causes
)
-public class CStaR implements Algorithm, TakesIndependenceWrapper {
+public class CSTAR implements Algorithm, TakesIndependenceWrapper {
static final long serialVersionUID = 23L;
private IndependenceWrapper test;
private LinkedList records;
- public CStaR() {
+ public CSTAR() {
}
@Override
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FACTOR_ANALYSIS.java
similarity index 98%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FACTOR_ANALYSIS.java
index 5f13cd9133..080bfdcf48 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FACTOR_ANALYSIS.java
@@ -20,7 +20,7 @@
* @author jdramsey
*/
@Bootstrapping
-public class FactorAnalysis implements Algorithm {
+public class FACTOR_ANALYSIS implements Algorithm {
static final long serialVersionUID = 23L;
public Graph search(DataModel ds, Parameters parameters) {
@@ -102,7 +102,7 @@ public Graph search(DataModel ds, Parameters parameters) {
return graph;
} else {
- FactorAnalysis algorithm = new FactorAnalysis();
+ FACTOR_ANALYSIS algorithm = new FACTOR_ANALYSIS();
DataSet data = (DataSet) ds;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/GLASSO.java
similarity index 97%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/GLASSO.java
index 5530be2377..8bc7500bc2 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/GLASSO.java
@@ -33,7 +33,7 @@
)
@Bootstrapping
@Experimental
-public class Glasso implements Algorithm {
+public class GLASSO implements Algorithm {
static final long serialVersionUID = 23L;
@@ -77,7 +77,7 @@ public Graph search(DataModel ds, Parameters parameters) {
return resultGraph;
} else {
- Glasso algorithm = new Glasso();
+ GLASSO algorithm = new GLASSO();
DataSet data = (DataSet) ds;
GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET));
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPW.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FASK_PW.java
similarity index 95%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPW.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FASK_PW.java
index 75185b33bf..921e3a97dd 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPW.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FASK_PW.java
@@ -32,16 +32,16 @@
dataType = DataType.Continuous
)
@Bootstrapping
-public class FaskPW implements Algorithm, TakesExternalGraph {
+public class FASK_PW implements Algorithm, TakesExternalGraph {
static final long serialVersionUID = 23L;
private Algorithm algorithm;
private Graph externalGraph;
- public FaskPW() {
+ public FASK_PW() {
}
- public FaskPW(Algorithm algorithm) {
+ public FASK_PW(Algorithm algorithm) {
this.algorithm = algorithm;
}
@@ -67,7 +67,7 @@ public Graph search(DataModel dataModel, Parameters parameters) {
return fask.search();
} else {
- FaskPW rSkew = new FaskPW(this.algorithm);
+ FASK_PW rSkew = new FASK_PW(this.algorithm);
if (this.externalGraph != null) {
rSkew.setExternalGraph(this.algorithm);
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkew.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW.java
similarity index 95%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkew.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW.java
index 75db35741b..b4929bd146 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkew.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW.java
@@ -30,16 +30,16 @@
dataType = DataType.Continuous
)
@Bootstrapping
-public class RSkew implements Algorithm, TakesExternalGraph {
+public class RSKEW implements Algorithm, TakesExternalGraph {
static final long serialVersionUID = 23L;
private Algorithm algorithm;
private Graph externalGraph;
- public RSkew() {
+ public RSKEW() {
}
- public RSkew(Algorithm algorithm) {
+ public RSKEW(Algorithm algorithm) {
this.algorithm = algorithm;
}
@@ -63,7 +63,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
return lofs.orient();
} else {
- RSkew rSkew = new RSkew(this.algorithm);
+ RSKEW rSkew = new RSKEW(this.algorithm);
if (this.externalGraph != null) {
rSkew.setExternalGraph(this.algorithm);
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkewE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW_E.java
similarity index 95%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkewE.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW_E.java
index d28ebdf0c9..29d7819bee 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkewE.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW_E.java
@@ -30,18 +30,18 @@
// algoType = AlgType.orient_pairwise
//)
@Bootstrapping
-public class RSkewE implements Algorithm, TakesExternalGraph {
+public class RSKEW_E implements Algorithm, TakesExternalGraph {
static final long serialVersionUID = 23L;
private Algorithm algorithm;
private Graph externalGraph;
- public RSkewE() {
+ public RSKEW_E() {
}
- public RSkewE(Algorithm algorithm) {
+ public RSKEW_E(Algorithm algorithm) {
this.algorithm = algorithm;
}
@@ -65,7 +65,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
return lofs.orient();
} else {
- RSkewE rSkewE = new RSkewE(this.algorithm);
+ RSKEW_E rSkewE = new RSKEW_E(this.algorithm);
if (this.externalGraph != null) {
rSkewE.setExternalGraph(this.algorithm);
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW.java
similarity index 95%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW.java
index 2c9871e465..1d954eec89 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW.java
@@ -31,16 +31,16 @@
)
@Bootstrapping
-public class Skew implements Algorithm, TakesExternalGraph {
+public class SKEW implements Algorithm, TakesExternalGraph {
static final long serialVersionUID = 23L;
private Algorithm algorithm;
private Graph externalGraph;
- public Skew() {
+ public SKEW() {
}
- public Skew(Algorithm algorithm) {
+ public SKEW(Algorithm algorithm) {
this.algorithm = algorithm;
}
@@ -64,7 +64,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
return lofs.orient();
} else {
- Skew skew = new Skew(this.algorithm);
+ SKEW skew = new SKEW(this.algorithm);
if (this.externalGraph != null) {
skew.setExternalGraph(this.algorithm);
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW_E.java
similarity index 95%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW_E.java
index f3642b96da..33cfe5ec75 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW_E.java
@@ -30,16 +30,16 @@
// algoType = AlgType.orient_pairwise
//)
@Bootstrapping
-public class SkewE implements Algorithm, TakesExternalGraph {
+public class SKEW_E implements Algorithm, TakesExternalGraph {
static final long serialVersionUID = 23L;
private Algorithm algorithm;
private Graph externalGraph;
- public SkewE() {
+ public SKEW_E() {
}
- public SkewE(Algorithm algorithm) {
+ public SKEW_E(Algorithm algorithm) {
this.algorithm = algorithm;
}
@@ -63,7 +63,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
return lofs.orient();
} else {
- SkewE skewE = new SkewE(this.algorithm);
+ SKEW_E skewE = new SKEW_E(this.algorithm);
if (this.externalGraph != null) {
skewE.setExternalGraph(this.algorithm);
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/TAHN.java
similarity index 95%
rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java
rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/TAHN.java
index 6e84ae7447..1f0bdcb36a 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/TAHN.java
@@ -24,14 +24,14 @@
* @author jdramsey
*/
@Bootstrapping
-public class Tanh implements Algorithm, TakesExternalGraph {
+public class TAHN implements Algorithm, TakesExternalGraph {
static final long serialVersionUID = 23L;
private Algorithm algorithm;
private Graph externalGraph;
- public Tanh(Algorithm algorithm) {
+ public TAHN(Algorithm algorithm) {
this.algorithm = algorithm;
}
@@ -55,7 +55,7 @@ public Graph search(DataModel dataSet, Parameters parameters) {
return lofs.orient();
} else {
- Tanh tanh = new Tanh(this.algorithm);
+ TAHN tanh = new TAHN(this.algorithm);
if (this.externalGraph != null) {
tanh.setExternalGraph(this.algorithm);
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java
index b653456b7e..3196942e1f 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java
@@ -23,7 +23,7 @@
import edu.cmu.tetrad.algcomparison.Comparison;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithms;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES;
import edu.cmu.tetrad.algcomparison.graph.RandomForward;
import edu.cmu.tetrad.algcomparison.score.ConditionalGaussianBicScore;
import edu.cmu.tetrad.algcomparison.simulation.BayesNetSimulation;
@@ -57,7 +57,7 @@ public static void main(String... args) {
Algorithms algorithms = new Algorithms();
- algorithms.add(new Fges(new ConditionalGaussianBicScore()));
+ algorithms.add(new FGES(new ConditionalGaussianBicScore()));
Simulations simulations = new Simulations();
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java
index 91bf2a369d..2fabfb7e5d 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java
@@ -23,8 +23,8 @@
import edu.cmu.tetrad.algcomparison.Comparison;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithms;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SvarFci;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SvarGfci;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SVAR_FCI;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SVAR_GFCI;
import edu.cmu.tetrad.algcomparison.graph.RandomForward;
import edu.cmu.tetrad.algcomparison.independence.FisherZ;
import edu.cmu.tetrad.algcomparison.score.SemBicScore;
@@ -66,8 +66,8 @@ public static void main(String... args) {
Algorithms algorithms = new Algorithms();
- algorithms.add(new SvarFci(new FisherZ()));
- algorithms.add(new SvarGfci(new FisherZ(), new SemBicScore()));
+ algorithms.add(new SVAR_FCI(new FisherZ()));
+ algorithms.add(new SVAR_GFCI(new FisherZ(), new SemBicScore()));
Simulations simulations = new Simulations();
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java
index 82dfcad89a..4250fe537e 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java
@@ -23,7 +23,7 @@
import edu.cmu.tetrad.algcomparison.Comparison;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithms;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES;
import edu.cmu.tetrad.algcomparison.score.MVPBicScore;
import edu.cmu.tetrad.algcomparison.statistic.*;
import edu.cmu.tetrad.util.Parameters;
@@ -72,7 +72,7 @@ public static void main(String... args) {
Algorithms algorithms = new Algorithms();
- algorithms.add(new Fges(new MVPBicScore()));
+ algorithms.add(new FGES(new MVPBicScore()));
Comparison comparison = new Comparison();
comparison.setShowAlgorithmIndices(true);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java
index 930fd7fb4b..c312835186 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java
@@ -24,9 +24,10 @@
import edu.cmu.tetrad.algcomparison.Comparison;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithms;
import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.BOSS;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.SP;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.GRASP;
import edu.cmu.tetrad.algcomparison.graph.RandomForward;
+import edu.cmu.tetrad.algcomparison.independence.FisherZ;
import edu.cmu.tetrad.algcomparison.score.SemBicScore;
import edu.cmu.tetrad.algcomparison.simulation.SemSimulation;
import edu.cmu.tetrad.algcomparison.simulation.Simulations;
@@ -42,21 +43,21 @@
public class TestBoss {
public static void main(String... args) {
Parameters parameters = new Parameters();
- parameters.set(Params.NUM_RUNS, 1);
+ parameters.set(Params.NUM_RUNS, 10);
parameters.set(Params.DIFFERENT_GRAPHS, true);
- parameters.set(Params.NUM_MEASURES, 10);
- parameters.set(Params.AVG_DEGREE, 5);
+ parameters.set(Params.NUM_MEASURES, 60);
+ parameters.set(Params.AVG_DEGREE, 6);
parameters.set(Params.SAMPLE_SIZE, 1000);
parameters.set(Params.COEF_LOW, 0);
parameters.set(Params.COEF_HIGH, 1);
- parameters.set(Params.BOSS_ALG, 1);
+// parameters.set(Params.BOSS_ALG, 1);
parameters.set(Params.PENALTY_DISCOUNT, 2);
parameters.set(Params.SEM_BIC_STRUCTURE_PRIOR, 0);
parameters.set(Params.ALPHA, 1e-2);
- parameters.set(Params.VERBOSE, true);
+ parameters.set(Params.VERBOSE, false);
Statistics statistics = new Statistics();
statistics.add(new AdjacencyPrecision());
@@ -66,9 +67,10 @@ public static void main(String... args) {
statistics.add(new ElapsedCpuTime());
Algorithms algorithms = new Algorithms();
- algorithms.add(new Fges(new SemBicScore()));
+ algorithms.add(new FGES(new SemBicScore()));
algorithms.add(new BOSS(new SemBicScore()));
- algorithms.add(new SP(new SemBicScore()));
+ algorithms.add(new GRASP(new FisherZ(), new SemBicScore()));
+// algorithms.add(new SP(new SemBicScore()));
Simulations simulations = new Simulations();
simulations.add(new SemSimulation(new RandomForward()));
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java
index 4bc86b99e1..ed8d64ecf1 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java
@@ -23,8 +23,8 @@
import edu.cmu.tetrad.algcomparison.Comparison;
import edu.cmu.tetrad.algcomparison.algorithm.Algorithms;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges;
-import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PcStable;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES;
+import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC_STABLE;
import edu.cmu.tetrad.algcomparison.graph.RandomForward;
import edu.cmu.tetrad.algcomparison.independence.DegenerateGaussianLRT;
import edu.cmu.tetrad.algcomparison.score.ConditionalGaussianBicScore;
@@ -77,9 +77,9 @@ public static void main(String... args) {
Algorithms algorithms = new Algorithms();
- algorithms.add(new Fges(new ConditionalGaussianBicScore()));
- algorithms.add(new Fges(new DegenerateGaussianBicScore()));
- algorithms.add(new PcStable(new DegenerateGaussianLRT()));
+ algorithms.add(new FGES(new ConditionalGaussianBicScore()));
+ algorithms.add(new FGES(new DegenerateGaussianBicScore()));
+ algorithms.add(new PC_STABLE(new DegenerateGaussianLRT()));
Simulations simulations = new Simulations();
simulations.add(new ConditionalGaussianSimulation(new RandomForward()));
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DegenerateGaussianBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DegenerateGaussianBicScore.java
index 2738fa19b8..a2fe62b423 100755
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DegenerateGaussianBicScore.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DegenerateGaussianBicScore.java
@@ -8,6 +8,7 @@
import edu.cmu.tetrad.search.DegenerateGaussianScore;
import edu.cmu.tetrad.search.Score;
import edu.cmu.tetrad.util.Parameters;
+import edu.cmu.tetrad.util.Params;
import java.util.ArrayList;
import java.util.List;
@@ -51,8 +52,8 @@ public DataType getDataType() {
@Override
public List getParameters() {
List parameters = new ArrayList<>();
- parameters.add("penaltyDiscount");
- parameters.add("structurePrior");
+ parameters.add(Params.PENALTY_DISCOUNT);
+ parameters.add(Params.STRUCTURE_PRIOR);
return parameters;
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java
index 8fd844fc1d..d6dcca4c3d 100755
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java
@@ -8,6 +8,7 @@
import edu.cmu.tetrad.search.MVPScore;
import edu.cmu.tetrad.search.Score;
import edu.cmu.tetrad.util.Parameters;
+import edu.cmu.tetrad.util.Params;
import java.util.ArrayList;
import java.util.List;
@@ -48,9 +49,9 @@ public DataType getDataType() {
@Override
public List getParameters() {
List parameters = new ArrayList<>();
- parameters.add("structurePrior");
+ parameters.add(Params.STRUCTURE_PRIOR);
parameters.add("fDegree");
- parameters.add("discretize");
+ parameters.add(Params.DISCRETIZE);
return parameters;
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java
index 1a1d6cf7e2..e32a9e05c7 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java
@@ -23,6 +23,8 @@
import edu.cmu.tetrad.util.MultiDimIntTable;
+import java.util.Arrays;
+
/**
* Stores a cell count table of arbitrary dimension. Provides methods for
@@ -34,10 +36,10 @@
public final class CellTable {
- /**
- * Stores a copy of coordinates for temporary use. (Reused.)
- */
- private int[] coordCopy;
+// /**
+// * Stores a copy of coordinates for temporary use. (Reused.)
+// */
+// private int[] coordCopy;
/**
* The value used in the data for missing values.
@@ -56,7 +58,7 @@ public CellTable(int[] dims) {
this.table = new MultiDimIntTable(dims);
}
- public synchronized void addToTable(DataSet dataSet, int[] indices) {
+ public void addToTable(DataSet dataSet, int[] indices) {
int[] dims = new int[indices.length];
for (int i = 0; i < indices.length; i++) {
@@ -107,25 +109,25 @@ public int getNumValues(int varIndex) {
* @param coords an array of the sort described above.
* @return the marginal sum specified.
*/
- public synchronized long calcMargin(int[] coords) {
- internalCoordCopy(coords);
+ public long calcMargin(int[] coords) {
+ int[] coordCopy = internalCoordCopy(coords);
int sum = 0;
int i = -1;
- while (++i < this.coordCopy.length) {
- if (this.coordCopy[i] == -1) {
+ while (++i < coordCopy.length) {
+ if (coordCopy[i] == -1) {
for (int j = 0; j < this.table.getDimension(i); j++) {
- this.coordCopy[i] = j;
- sum += calcMargin(this.coordCopy);
+ coordCopy[i] = j;
+ sum += calcMargin(coordCopy);
}
- this.coordCopy[i] = -1;
+ coordCopy[i] = -1;
return sum;
}
}
- return this.table.getValue(this.coordCopy);
+ return this.table.getValue(coordCopy);
}
/**
@@ -140,27 +142,31 @@ public synchronized long calcMargin(int[] coords) {
* @param marginVars an int[]
value
* @return an int
value
*/
- public synchronized long calcMargin(int[] coords, int[] marginVars) {
- internalCoordCopy(coords);
+ public long calcMargin(int[] coords, int[] marginVars) {
+ int[] coordCopy = internalCoordCopy(coords);
for (int marginVar : marginVars) {
- this.coordCopy[marginVar] = -1;
+ coordCopy[marginVar] = -1;
}
- return calcMargin(this.coordCopy);
+ return calcMargin(coordCopy);
}
/**
* Makes a copy of the coordinate array so that the original is not messed
* up.
*/
- private synchronized void internalCoordCopy(int[] coords) {
- if ((this.coordCopy == null) ||
- (this.coordCopy.length != coords.length)) {
- this.coordCopy = new int[coords.length];
- }
+ private int[] internalCoordCopy(int[] coords) {
+ int[] coordCopy = Arrays.copyOf(coords, coords.length);
+
+// if ((this.coordCopy == null) ||
+// (this.coordCopy.length != coords.length)) {
+// this.coordCopy = new int[coords.length];
+// }
+//
+// System.arraycopy(coords, 0, this.coordCopy, 0, coords.length);
- System.arraycopy(coords, 0, this.coordCopy, 0, coords.length);
+ return coordCopy;
}
private int getMissingValue() {
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java
index 60f25dd40e..4ad8c4f7d1 100755
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java
@@ -156,7 +156,7 @@ public static void saveKnowledge(Knowledge knowledge, Writer out) throws IOExcep
String forbiddenWithin = knowledge.isTierForbiddenWithin(i) ? "*" : "";
String onlyCanCauseNextTier = knowledge.isOnlyCanCauseNextTier(i) ? "-" : "";
- buf.append("\n").append(i + 1).append(forbiddenWithin).append(onlyCanCauseNextTier).append(" ");
+ buf.append("\n").append(i).append(forbiddenWithin).append(onlyCanCauseNextTier).append(" ");
List tier = knowledge.getTier(i);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java
index b8ee725352..c3f636839e 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java
@@ -9,6 +9,8 @@
import nu.xom.*;
import java.io.*;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -511,22 +513,29 @@ public static Graph readerToGraphJson(Reader reader) throws IOException {
public static String graphToDot(Graph graph) {
StringBuilder builder = new StringBuilder();
builder.append("digraph g {\n");
- for (Edge edge : graph.getEdges()) {
+ List edges = new ArrayList<>(graph.getEdges());
+ Collections.sort(edges);
+
+ for (Edge edge : edges) {
String n1 = edge.getNode1().getName();
String n2 = edge.getNode2().getName();
Endpoint end1 = edge.getEndpoint1();
Endpoint end2 = edge.getEndpoint2();
- if (n1.compareTo(n2) > 0) {
- String temp = n1;
- n1 = n2;
- n2 = temp;
-
- Endpoint tmp = end1;
- end1 = end2;
- end2 = tmp;
- }
+ // These may be in the graph but they represent edges not in the ensemble for which
+ // bootstrap information is available.
+ if (end1 == Endpoint.NULL || end2 == Endpoint.NULL) continue;
+
+// if (n1.compareTo(n2) > 0) {
+// String temp = n1;
+// n1 = n2;
+// n2 = temp;
+//
+// Endpoint tmp = end1;
+// end1 = end2;
+// end2 = tmp;
+// }
builder.append(" \"").append(n1).append("\" -> \"").append(n2).append("\" [");
if (end1 != Endpoint.TAIL) {
@@ -540,6 +549,8 @@ public static String graphToDot(Graph graph) {
builder.append("none");
} else if (end1 == Endpoint.CIRCLE) {
builder.append("odot");
+ } else {
+ builder.append("xdot");
}
builder.append(", arrowhead=");
if (end2 == Endpoint.ARROW) {
@@ -548,6 +559,8 @@ public static String graphToDot(Graph graph) {
builder.append("none");
} else if (end2 == Endpoint.CIRCLE) {
builder.append("odot");
+ } else {
+ builder.append("xdot");
}
// Bootstrapping
@@ -593,7 +606,9 @@ public static String graphToDot(Graph graph) {
}
}
- label.append("\\n[").append(edgeTypeString).append("]:").append(edgeTypeProbability.getProbability());
+ NumberFormat nf = new DecimalFormat("0.000");
+
+ label.append("\\n[").append(edgeTypeString).append("]:").append(nf.format(edgeTypeProbability.getProbability()));
}
}
builder.append(", label=\"").append(label).append("\", fontname=courier");
@@ -708,6 +723,59 @@ public static String graphToXml(Graph graph) {
return out.toString();
}
+ public static String graphToLavaan(Graph g) {
+ boolean includeIntercepts = true;
+ boolean includeErrors = true;
+
+ Map> parents = new HashMap<>();
+ Map> siblings = new HashMap<>();
+
+ StringBuilder lavaan = new StringBuilder();
+ for (Node a : g.getNodes()) {
+ if (includeIntercepts) lavaan.append(a.getName()).append(" ~ 1\n");
+ parents.put(a, new ArrayList<>());
+ siblings.put(a, new ArrayList<>());
+ for (Edge e : g.getEdges(a)) {
+ Node b = e.getDistalNode(a);
+ if (e.getProximalEndpoint(a) != Endpoint.ARROW) continue;
+ if (e.getProximalEndpoint(b) == Endpoint.TAIL) parents.get(a).add(b);
+ if (siblings.containsKey(b)) continue;
+ if (e.getProximalEndpoint(b) == Endpoint.ARROW) siblings.get(a).add(b);
+ }
+ }
+
+ if (includeIntercepts) lavaan.append("\n");
+ boolean hasDirected = false;
+ for (Node a : g.getNodes()) {
+ Iterator itr = parents.get(a).iterator();
+ if (itr.hasNext()) {
+ hasDirected = true;
+ lavaan.append(a.getName()).append(" ~ ").append(itr.next().getName());
+ } else continue;
+ while (itr.hasNext()) lavaan.append(" + ").append(itr.next().getName());
+ lavaan.append("\n");
+ }
+
+ if (hasDirected) lavaan.append("\n");
+ boolean hasBidirected = false;
+ for (Node a : g.getNodes()) {
+ Iterator itr = siblings.get(a).iterator();
+ if (itr.hasNext()) {
+ hasBidirected = true;
+ lavaan.append(a.getName()).append(" ~~ ").append(itr.next().getName());
+ } else continue;
+ while (itr.hasNext()) lavaan.append(" + ").append(itr.next().getName());
+ lavaan.append("\n");
+ }
+
+ if (hasBidirected) lavaan.append("\n");
+ for (Node a : g.getNodes()) {
+ if (includeErrors) lavaan.append(a.getName()).append(" ~~ ").append(a.getName()).append("\n");
+ }
+
+ return lavaan.toString();
+ }
+
public static String graphToPcalg(Graph g) {
Map mark2Int = new HashMap();
mark2Int.put(Endpoint.NULL, 0);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java
index a422ef51fc..579c91a384 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java
@@ -188,17 +188,17 @@ private static void triangleReduce1(Graph graph, TeyssierScorer scorer, Knowledg
}
}
- private static void triangleReduce2(Graph graph, TeyssierScorer scorer0, Knowledge knowledge) {
- TeyssierScorer scorer = new TeyssierScorer(scorer0);
- Graph origGaph = new EdgeListGraph(graph);
-
- for (Edge edge : graph.getEdges()) {
- Node a = edge.getNode1();
- Node b = edge.getNode2();
- t2visit(origGaph, graph, scorer0, knowledge, scorer, a, b);
- t2visit(origGaph, graph, scorer0, knowledge, scorer, b, a);
- }
- }
+// private static void triangleReduce2(Graph graph, TeyssierScorer scorer0, Knowledge knowledge) {
+// TeyssierScorer scorer = new TeyssierScorer(scorer0);
+// Graph origGaph = new EdgeListGraph(graph);
+//
+// for (Edge edge : graph.getEdges()) {
+// Node a = edge.getNode1();
+// Node b = edge.getNode2();
+// t2visit(origGaph, graph, scorer0, knowledge, scorer, a, b);
+// t2visit(origGaph, graph, scorer0, knowledge, scorer, b, a);
+// }
+// }
private static boolean t2visit(Graph origGraph, Graph graph, TeyssierScorer scorer0, Knowledge knowledge, TeyssierScorer scorer,
Node a, Node b) {
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java
index d079d59a76..8582a96f75 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java
@@ -28,7 +28,7 @@
* @see PermutationSearch
*/
public class Boss implements SuborderSearch {
- private final Bes bes;
+ private final PermutationBes bes;
private final Score score;
private final List variables;
private final Map> parents;
@@ -52,7 +52,7 @@ public Boss(Score score) {
this.parents.put(x, new HashSet<>());
}
- this.bes = new Bes(score);
+ this.bes = new PermutationBes(score);
this.bes.setVerbose(false);
this.numStarts = 1;
}
@@ -93,8 +93,8 @@ public void searchSuborder(List prefix, List suborder, Map Z = new ArrayList<>(prefix);
Z.addAll(suborder);
- Graph graph = PermutationSearch.getGraph(Z, parents, true);
- this.bes.bes(graph, Z);
+ Graph graph = PermutationSearch.getGraph(Z, parents, this.knowledge, true);
+ this.bes.bes(graph, Z, suborder);
graph.paths().makeValidOrder(suborder);
s1 = update(prefix, suborder);
} while (s1 > s3);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java
index 77b7f455fa..98abe1c5cc 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java
@@ -37,7 +37,6 @@ public class BossOrig {
private int depth = -1;
private int numStarts = 1;
private AlgType algType = AlgType.BOSS1;
- private boolean caching = true;
private double epsilon = 1e-10;
public BossOrig(@NotNull IndependenceTest test, Score score) {
@@ -64,7 +63,6 @@ public BossOrig(TeyssierScorer scorer) {
public List bestOrder(@NotNull List order) {
- scorer.setCachingScores(caching);
scorer.setKnowledge(knowledge);
List bestPerm;
@@ -598,9 +596,5 @@ public void setAlgType(AlgType algType) {
this.algType = algType;
}
- public void setCaching(boolean caching) {
- this.caching = caching;
- }
-
public enum AlgType {BOSS1, BOSS2, BOSS3}
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java
index 01507d16e8..3fe43781bb 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java
@@ -47,7 +47,7 @@ public final class Ccd implements GraphSearch {
private boolean applyR1;
public Ccd(IndependenceTest test) {
- if (test == null) throw new NullPointerException();
+ if (test == null) throw new NullPointerException("Test is not provided");
this.independenceTest = test;
this.nodes = test.getVariables();
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java
index ad78ec4abf..ea73280c5b 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java
@@ -200,7 +200,7 @@ public void setApplyOrientAwayFromCollider(boolean applyOrientAwayFromCollider)
private Graph fastAdjacencySearch() {
long start = MillisecondTimes.timeMillis();
- FasConcurrent fas = new FasConcurrent(this.independenceTest);
+ Fas fas = new Fas(this.independenceTest);
fas.setStable(true);
fas.setDepth(getDepth());
fas.setKnowledge(this.knowledge);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java
index f1e6371d5e..e0292b5f78 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java
@@ -91,7 +91,7 @@ public ChiSquareTest(DataSet dataSet, double alpha) {
* by summing up chi square and degrees of freedom for each conditional table in turn, where rows or columns that
* consist entirely of zeros have been removed.
*/
- public synchronized Result calcChiSquare(int[] testIndices) {
+ public Result calcChiSquare(int[] testIndices) {
// Reset the cell table for the columns referred to in
// 'testIndices.' Do cell coefs for those columns.
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java
index ac146e9b08..c5817ce05d 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java
@@ -101,7 +101,7 @@ public final class Cpc implements GraphSearch {
private boolean verbose;
private boolean stable;
- private boolean concurrent;
+// private boolean concurrent;
private boolean useHeuristic = false;
private int maxPPathLength = -1;
private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE;
@@ -261,11 +261,11 @@ public Graph search() {
search.setFasType(PcAll.FasType.REGULAR);
}
- if (concurrent) {
- search.setConcurrent(PcAll.Concurrent.YES);
- } else {
- search.setConcurrent(PcAll.Concurrent.NO);
- }
+// if (concurrent) {
+// search.setConcurrent(PcAll.Concurrent.YES);
+// } else {
+// search.setConcurrent(PcAll.Concurrent.NO);
+// }
search.setColliderDiscovery(PcAll.ColliderDiscovery.CONSERVATIVE);
search.setConflictRule(conflictRule);
@@ -358,9 +358,9 @@ public void setStable(boolean stable) {
this.stable = stable;
}
- public void setConcurrent(boolean concurrent) {
- this.concurrent = concurrent;
- }
+// public void setConcurrent(boolean concurrent) {
+// this.concurrent = concurrent;
+// }
public void setUseHeuristic(boolean useHeuristic) {
this.useHeuristic = useHeuristic;
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java
index 6dbef27fb0..3de5fe6b38 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java
@@ -195,7 +195,7 @@ public Graph search(List nodes) {
this.graph = new EdgeListGraph(nodes);
- FasConcurrent fas = new FasConcurrent(getIndependenceTest());
+ Fas fas = new Fas(getIndependenceTest());
fas.setStable(true);
fas.setOut(this.out);
return search(fas, nodes);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java
index 77c299a0ee..c279362b66 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java
@@ -27,6 +27,9 @@
import java.util.List;
+import static org.apache.commons.math3.util.FastMath.abs;
+import static org.apache.commons.math3.util.FastMath.log;
+
/**
* Calculates the discrete BIC score.
*/
@@ -167,10 +170,19 @@ public double localScore(int node, int[] parents) {
}
}
- private double getPriorForStructure(int numParents) {
- double e = getStructurePrior();
- int vm = this.data.length - 1;
- return numParents * FastMath.log(e / (vm)) + (vm - numParents) * FastMath.log(1.0 - (e / (vm)));
+// private double getPriorForStructure(int numParents) {
+// double e = getStructurePrior();
+// int vm = this.data.length - 1;
+// return numParents * FastMath.log(e / (vm)) + (vm - numParents) * FastMath.log(1.0 - (e / (vm)));
+// }
+
+ private double getPriorForStructure(int parents) {
+ if (abs(getStructurePrior()) <= 0) {
+ return 0;
+ } else {
+ double p = (getStructurePrior()) / (this.variables.size());
+ return -((parents) * log(p) + (this.variables.size() - (parents)) * log(1.0 - p));
+ }
}
@Override
@@ -214,6 +226,7 @@ public double getStructurePrior() {
return this.structurePrior;
}
+
@Override
public double getSamplePrior() {
throw new UnsupportedOperationException();
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java
index ccf60b91bd..9d448c1c24 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java
@@ -43,6 +43,7 @@
* It uses a slightly different algorithm from FasStableConcurrent, probably better.
*
* @author Joseph Ramsey.
+ * @deprecated Use Fas instead; this is non-deterministic and gives problems with GSquare and ChiSquare.
*/
public class FasConcurrent implements IFas {
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java
index 96826cc463..2d0995d566 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java
@@ -1,6 +1,6 @@
package edu.cmu.tetrad.search;
-import edu.cmu.tetrad.algcomparison.algorithm.multi.ImagesSemBic;
+import edu.cmu.tetrad.algcomparison.algorithm.multi.IMAGES;
import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper;
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.data.DataModel;
@@ -43,7 +43,7 @@ public Graph search(Parameters parameters) {
_dataSets.add(DataUtils.standardizeData(dataSet));
}
- ImagesSemBic imagesSemBic = new ImagesSemBic();
+ IMAGES imagesSemBic = new IMAGES();
imagesSemBic.setKnowledge(this.knowledge);
Graph G0 = imagesSemBic.search(_dataSets, parameters);
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java
index dbaf66689c..c75923a27d 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java
@@ -21,9 +21,12 @@
package edu.cmu.tetrad.search;
+import edu.cmu.tetrad.data.CellTable;
import edu.cmu.tetrad.data.DataSet;
+import edu.cmu.tetrad.data.DiscreteVariable;
import edu.cmu.tetrad.util.CombinationIterator;
import edu.cmu.tetrad.util.ProbUtils;
+import org.apache.commons.math3.util.FastMath;
import java.util.ArrayList;
import java.util.Arrays;
@@ -38,18 +41,59 @@
* @author Frank Wimberly original version
* @author Joseph Ramsey revision 10/01
*/
-public final class GSquareTest extends ChiSquareTest {
+public final class GSquareTest {
+
+ /**
+ * The data set this test uses.
+ */
+ private final DataSet dataSet;
+
+ /**
+ * The number of values for each variable in the data.
+ */
+ private final int[] dims;
+
+ /**
+ * Stores the data in the form of a cell table.
+ */
+ private final CellTable cellTable;
+
+ /**
+ * The significance level of the test.
+ */
+ private double alpha;
+
public GSquareTest(DataSet dataSet, double alpha) {
- super(dataSet, alpha);
+ if (alpha < 0.0 || alpha > 1.0) {
+ throw new IllegalArgumentException("Significance level must be in " +
+ "[0, 1]: " + alpha);
+ }
+
+ this.dims = new int[dataSet.getNumColumns()];
+
+ for (int i = 0; i < getDims().length; i++) {
+ DiscreteVariable variable =
+ (DiscreteVariable) dataSet.getVariable(i);
+ this.getDims()[i] = variable.getNumCategories();
+ }
+
+ this.dataSet = dataSet;
+ this.alpha = alpha;
+ this.cellTable = new CellTable(null);
+ this.getCellTable().setMissingValue(DiscreteVariable.MISSING_VALUE);
}
+// public GSquareTest(DataSet dataSet, double alpha) {
+// super(dataSet, alpha);
+// }
+
/**
* Calculates g square for a conditional crosstabulation table for independence question 0 _||_ 1 | 2, 3, ...max by
* summing up g square and degrees of freedom for each conditional table in turn, where rows or columns that consist
* entirely of zeros have been removed.
*/
- public synchronized Result calcGSquare(int[] testIndices) {
+ public Result calcGSquare(int[] testIndices) {
// Reset the cell table for the columns referred to in
// 'testIndices.' Do cell coefs for those columns.
@@ -128,7 +172,7 @@ public synchronized Result calcGSquare(int[] testIndices) {
double expected = e.get(i) / (double) total;
if (o.get(i) != 0) {
- _gSquare += 2.0 * o.get(i) * log(o.get(i) / expected);
+ _gSquare += 2.0 * o.get(i) * FastMath.log(o.get(i) / expected);
}
}
@@ -222,6 +266,100 @@ public boolean isIndep() {
return this.isIndep;
}
}
+
+
+ public int[] getDims() {
+ return this.dims;
+ }
+
+ public CellTable getCellTable() {
+ return this.cellTable;
+ }
+
+ /**
+ * @return the getModel significance level being used for tests.
+ */
+ public double getAlpha() {
+ return this.alpha;
+ }
+
+ /**
+ * Sets the significance level to be used for tests.
+ */
+ public void setAlpha(double alpha) {
+ if (alpha < 0.0 || alpha > 1.0) {
+ throw new IllegalArgumentException("Significance level must be in " +
+ "[0, 1]: " + alpha);
+ }
+
+ this.alpha = alpha;
+ }
+
+ public int[] selectFromArray(int[] arr, int[] indices) {
+ int[] retArr = new int[indices.length];
+
+ for (int i = 0; i < indices.length; i++) {
+ retArr[i] = arr[indices[i]];
+ }
+
+ return retArr;
+ }
+
+ public DataSet getDataSet() {
+ return this.dataSet;
+ }
+
+ public boolean isDetermined(int[] testIndices, double p) {
+
+ // Reset the cell table for the columns referred to in
+ // 'testIndices.' Do cell coefs for those columns.
+ this.getCellTable().addToTable(getDataSet(), testIndices);
+
+ // Indicator arrays to tell the cell table which margins
+ // to calculate. For x _||_ y | z1, z2, ..., we want to
+ // calculate the margin for x, the margin for y, and the
+ // margin for x and y. (These will be used later.)
+ int[] firstVar = {0};
+
+ int[] condDims = new int[testIndices.length - 1];
+ System.arraycopy(selectFromArray(getDims(), testIndices), 1, condDims, 0,
+ condDims.length);
+
+ int[] coords = new int[testIndices.length];
+ int numValues = this.getCellTable().getNumValues(0);
+
+ CombinationIterator combinationIterator =
+ new CombinationIterator(condDims);
+
+ while (combinationIterator.hasNext()) {
+ int[] combination = combinationIterator.next();
+ System.arraycopy(combination, 0, coords, 1, combination.length);
+
+ long total = this.getCellTable().calcMargin(coords, firstVar);
+
+ if (total == 0) {
+ continue;
+ }
+
+ boolean dominates = false;
+
+ for (int i = 0; i < numValues; i++) {
+ coords[0] = i;
+
+ long numi = this.getCellTable().getValue(coords);
+
+ if ((double) numi / total >= p) {
+ dominates = true;
+ }
+ }
+
+ if (!dominates) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java
index 797a90c18e..88e8eced5f 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java
@@ -35,13 +35,12 @@ public class Grasp {
private boolean useRaskuttiUhler;
private boolean ordered;
private boolean verbose;
- private boolean cachingScores = true;
private int uncoveredDepth = 1;
private int nonSingularDepth = 1;
private boolean useDataOrder = true;
// other params
- private int depth = 4;
+ private int depth = 3;
private int numStarts = 1;
public Grasp(@NotNull Score score) {
@@ -79,8 +78,6 @@ public List bestOrder(@NotNull List order) {
this.scorer.clearBookmarks();
- this.scorer.setCachingScores(this.cachingScores);
-
List bestPerm = null;
double best = NEGATIVE_INFINITY;
@@ -125,47 +122,61 @@ public int getNumEdges() {
return this.scorer.getNumEdges();
}
+
private void makeValidKnowledgeOrder(List order) {
if (!this.knowledge.isEmpty()) {
- order.sort((o1, o2) -> {
- if (o1.getName().equals(o2.getName())) {
- return 0;
- } else if (this.knowledge.isRequired(o1.getName(), o2.getName())) {
- return -1;
- } else if (this.knowledge.isRequired(o2.getName(), o1.getName())) {
- return 1;
- } else if (this.knowledge.isForbidden(o1.getName(), o2.getName())) {
- return 1;
- } else if (this.knowledge.isForbidden(o2.getName(), o1.getName())) {
- return -1;
- } else {
- return 0;
- }
+ order.sort((a, b) -> {
+ if (a.getName().equals(b.getName())) return 0;
+ else if (this.knowledge.isRequired(a.getName(), b.getName())) return -1;
+ else if (this.knowledge.isRequired(b.getName(), a.getName())) return 1;
+ else return 0;
});
}
+ }
- System.out.println("Initial knowledge sort order = " + order);
-
- if (violatesKnowledge(order)) {
- Edge edge = violatesForbiddenKnowledge(order);
- if (edge != null) {
- JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
- "The initial sorting procedure could not find a permutation consistent with that \n" +
- "knowledge; this edge was in the DAG: " + edge + " in the initial sort,\n" +
- "but this edge was forbidden.");
- }
+// private void makeValidKnowledgeOrder(List order) {
+// if (!this.knowledge.isEmpty()) {
+// order.sort((o1, o2) -> {
+// if (o1.getName().equals(o2.getName())) {
+// return 0;
+// } else if (this.knowledge.isRequired(o1.getName(), o2.getName())) {
+// return -1;
+// } else if (this.knowledge.isRequired(o2.getName(), o1.getName())) {
+// return 1;
+// } else if (this.knowledge.isForbidden(o1.getName(), o2.getName())) {
+// return 1;
+// } else if (this.knowledge.isForbidden(o2.getName(), o1.getName())) {
+// return -1;
+// } else {
+// return 0;
+// }
+// });
+// }
+//
+// System.out.println("Initial knowledge sort order = " + order);
+//
+// if (violatesKnowledge(order)) {
+// Edge edge = violatesForbiddenKnowledge(order);
+//
+// if (edge != null) {
+// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
+// "The initial sorting procedure could not find a permutation consistent with that \n" +
+// "knowledge; this edge was in the DAG: " + edge + " in the initial sort,\n" +
+// "but this edge was forbidden.");
+// }
+//
+// Edge edge2 = violatesRequiredKnowledge(order);
+//
+// if (edge2 != null) {
+// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
+// "The initial sorting procedure could not find a permutation consistent with that \n" +
+// "knowledge; this edge was not in the DAG: " + edge2 + " in the initial sorted," +
+// "but this edge was required.");
+// }
+// }
+// }
- Edge edge2 = violatesRequiredKnowledge(order);
-
- if (edge2 != null) {
- JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
- "The initial sorting procedure could not find a permutation consistent with that \n" +
- "knowledge; this edge was not in the DAG: " + edge2 + " in the initial sorted," +
- "but this edge was required.");
- }
- }
- }
public List grasp(@NotNull TeyssierScorer scorer) {
scorer.clearBookmarks();
@@ -249,7 +260,6 @@ private void graspDfs(@NotNull TeyssierScorer scorer, double sOld, int[] depth,
} while (zItr.hasNext());
// scorer.updateScores(idcs[0], idcs[1]);
-
if (currentDepth > depth[2] && !singular) {
scorer.goToBookmark(currentDepth);
continue;
@@ -299,10 +309,6 @@ public Graph getGraph(boolean cpDag) {
return graph;
}
- public void setCacheScores(boolean cachingScores) {
- this.cachingScores = cachingScores;
- }
-
public void setNumStarts(int numStarts) {
this.numStarts = numStarts;
}
@@ -346,18 +352,12 @@ public void setUseScore(boolean useScore) {
}
private boolean violatesKnowledge(List order) {
- if (!this.knowledge.isEmpty()) {
- scorer.score(order);
+ if (this.knowledge.isEmpty()) return false;
- for (int i = 0; i < order.size(); i++) {
- for (int j = i + 1; j < order.size(); j++) {
- if (this.knowledge.isForbidden(order.get(i).getName(), order.get(j).getName()) && scorer.parent(order.get(i), order.get(j))) {
- return true;
- }
-
- if (this.knowledge.isRequired(order.get(j).getName(), order.get(i).getName()) && !scorer.parent(order.get(i), order.get(j))) {
- return true;
- }
+ for (int i = 0; i < order.size(); i++) {
+ for (int j = 0; j < i; j++) {
+ if (this.knowledge.isRequired(order.get(i).getName(), order.get(j).getName())) {
+ return true;
}
}
}
@@ -365,37 +365,37 @@ private boolean violatesKnowledge(List order) {
return false;
}
- private Edge violatesForbiddenKnowledge(List order) {
- if (!this.knowledge.isEmpty()) {
- scorer.score(order);
-
- for (int i = 0; i < order.size(); i++) {
- for (int j = i + 1; j < order.size(); j++) {
- if (this.knowledge.isForbidden(order.get(i).getName(), order.get(j).getName()) && scorer.parent(order.get(i), order.get(j))) {
- return Edges.directedEdge(order.get(i), order.get(j));
- }
- }
- }
- }
-
- return null;
- }
-
- private Edge violatesRequiredKnowledge(List order) {
- if (!this.knowledge.isEmpty()) {
- scorer.score(order);
-
- for (int i = 0; i < order.size(); i++) {
- for (int j = i + 1; j < order.size(); j++) {
- if (this.knowledge.isRequired(order.get(j).getName(), order.get(i).getName()) && !scorer.parent(order.get(i), order.get(j))) {
- return Edges.directedEdge(order.get(j), order.get(i));
- }
- }
- }
- }
-
- return null;
- }
+// private Edge violatesForbiddenKnowledge(List order) {
+// if (!this.knowledge.isEmpty()) {
+// scorer.score(order);
+//
+// for (int i = 0; i < order.size(); i++) {
+// for (int j = i + 1; j < order.size(); j++) {
+// if (this.knowledge.isForbidden(order.get(i).getName(), order.get(j).getName()) && scorer.parent(order.get(i), order.get(j))) {
+// return Edges.directedEdge(order.get(i), order.get(j));
+// }
+// }
+// }
+// }
+//
+// return null;
+// }
+
+// private Edge violatesRequiredKnowledge(List order) {
+// if (!this.knowledge.isEmpty()) {
+// scorer.score(order);
+//
+// for (int i = 0; i < order.size(); i++) {
+// for (int j = i + 1; j < order.size(); j++) {
+// if (this.knowledge.isRequired(order.get(j).getName(), order.get(i).getName()) && !scorer.parent(order.get(i), order.get(j))) {
+// return Edges.directedEdge(order.get(j), order.get(i));
+// }
+// }
+// }
+// }
+//
+// return null;
+// }
public void setOrdered(boolean ordered) {
this.ordered = ordered;
@@ -413,135 +413,4 @@ public void setUseDataOrder(boolean useDataOrder) {
this.useDataOrder = useDataOrder;
}
- public void orientbk(Knowledge bk, Graph graph, List variables) {
- for (Iterator it = bk.forbiddenEdgesIterator(); it.hasNext(); ) {
- if (Thread.currentThread().isInterrupted()) {
- break;
- }
-
- KnowledgeEdge edge = it.next();
-
- //match strings to variables in the graph.
- Node from = SearchGraphUtils.translate(edge.getFrom(), variables);
- Node to = SearchGraphUtils.translate(edge.getTo(), variables);
-
- if (from == null || to == null) {
- continue;
- }
-
- if (graph.getEdge(from, to) == null) {
- continue;
- }
-
- // Orient to*->from
- graph.setEndpoint(to, from, Endpoint.ARROW);
-// graph.setEndpoint(from, to, Endpoint.CIRCLE);
-// this.changeFlag = true;
-// this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to)));
- }
-
- for (Iterator it = bk.requiredEdgesIterator(); it.hasNext(); ) {
- if (Thread.currentThread().isInterrupted()) {
- break;
- }
-
- KnowledgeEdge edge = it.next();
-
- //match strings to variables in the graph.
- Node from = SearchGraphUtils.translate(edge.getFrom(), variables);
- Node to = SearchGraphUtils.translate(edge.getTo(), variables);
-
- if (from == null || to == null) {
- continue;
- }
-
- if (graph.getEdge(from, to) == null) {
- continue;
- }
-
- // Orient to*->from
- graph.setEndpoint(from, to, Endpoint.ARROW);
-// graph.setEndpoint(from, to, Endpoint.CIRCLE);
-// this.changeFlag = true;
-// this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to)));
- }
- }
-
- private void addRequiredEdges(Graph graph) {
- for (Iterator it = knowledge.requiredEdgesIterator(); it.hasNext() && !Thread.currentThread().isInterrupted(); ) {
- KnowledgeEdge next = it.next();
-
- Node nodeA = graph.getNode(next.getFrom());
- Node nodeB = graph.getNode(next.getTo());
-
- if (!graph.paths().isAncestorOf(nodeB, nodeA)) {
- graph.removeEdges(nodeA, nodeB);
- graph.addDirectedEdge(nodeA, nodeB);
-
- if (verbose) {
- TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeA, nodeB));
- }
- }
- }
- for (Edge edge : graph.getEdges()) {
- if (Thread.currentThread().isInterrupted()) {
- break;
- }
-
- final String A = edge.getNode1().getName();
- final String B = edge.getNode2().getName();
-
- if (knowledge.isForbidden(A, B)) {
- Node nodeA = edge.getNode1();
- Node nodeB = edge.getNode2();
-
- if (graph.isAdjacentTo(nodeA, nodeB) && !graph.isChildOf(nodeA, nodeB)) {
- if (!graph.paths().isAncestorOf(nodeA, nodeB)) {
- graph.removeEdges(nodeA, nodeB);
- graph.addDirectedEdge(nodeB, nodeA);
-
- if (verbose) {
- TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
- }
- }
- }
-
- if (!graph.isChildOf(nodeA, nodeB) && knowledge.isForbidden(nodeA.getName(), nodeB.getName())) {
- if (!graph.paths().isAncestorOf(nodeA, nodeB)) {
- graph.removeEdges(nodeA, nodeB);
- graph.addDirectedEdge(nodeB, nodeA);
-
- if (verbose) {
- TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
- }
- }
- }
- } else if (knowledge.isForbidden(B, A)) {
- Node nodeA = edge.getNode2();
- Node nodeB = edge.getNode1();
-
- if (graph.isAdjacentTo(nodeA, nodeB) && !graph.isChildOf(nodeA, nodeB)) {
- if (!graph.paths().isAncestorOf(nodeA, nodeB)) {
- graph.removeEdges(nodeA, nodeB);
- graph.addDirectedEdge(nodeB, nodeA);
-
- if (verbose) {
- TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
- }
- }
- }
- if (!graph.isChildOf(nodeA, nodeB) && knowledge.isForbidden(nodeA.getName(), nodeB.getName())) {
- if (!graph.paths().isAncestorOf(nodeA, nodeB)) {
- graph.removeEdges(nodeA, nodeB);
- graph.addDirectedEdge(nodeB, nodeA);
-
- if (verbose) {
- TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
- }
- }
- }
- }
- }
- }
-
}
\ No newline at end of file
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java
index 9d514d8822..ccca654a03 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java
@@ -87,7 +87,6 @@ public final class GraspFci implements GraphSearch {
private boolean possibleDsepSearchDone = true;
private boolean ordered = false;
- private boolean cachingScores = true;
private int graspDepth = 3;
private int uncoveredDepth = 1;
private int nonSingularDepth = 1;
@@ -127,7 +126,6 @@ public Graph search() {
alg.setSingularDepth(uncoveredDepth);
alg.setNonSingularDepth(nonSingularDepth);
alg.setNumStarts(numStarts);
- alg.setCacheScores(cachingScores);
alg.setVerbose(verbose);
List variables = this.score.getVariables();
@@ -422,9 +420,4 @@ public void setOrdered(boolean ordered) {
this.ordered = ordered;
}
-
- public void setCacheScores(boolean cachingScores) {
- this.cachingScores = cachingScores;
- }
-
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java
index 19b7d15473..15d1ca4ce9 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java
@@ -33,7 +33,6 @@ public class GraspTol {
private boolean usePearl;
private boolean ordered;
private boolean verbose;
- private boolean cachingScores = true;
private int uncoveredDepth = 1;
private int nonSingularDepth = 1;
private int toleranceDepth;
@@ -82,8 +81,6 @@ public List bestOrder(@NotNull List order) {
this.scorer.setKnowledge(this.knowledge);
this.scorer.clearBookmarks();
- this.scorer.setCachingScores(this.cachingScores);
-
List bestPerm = null;
double best = NEGATIVE_INFINITY;
@@ -388,10 +385,6 @@ public Graph getGraph(boolean cpDag) {
return graph;
}
- public void setCacheScores(boolean cachingScores) {
- this.cachingScores = cachingScores;
- }
-
public void setNumStarts(int numStarts) {
this.numStarts = numStarts;
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java
index d490823f66..1ac1d93b64 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java
@@ -1,5 +1,6 @@
package edu.cmu.tetrad.search;
+import edu.cmu.tetrad.data.Knowledge;
import edu.cmu.tetrad.graph.Node;
import org.jetbrains.annotations.NotNull;
@@ -10,22 +11,18 @@ public class GrowShrinkTree {
private final Map index;
private final Node node;
private final int nodeIndex;
- private final List required;
- private final List forbidden;
- private final GSTNode root;
+ private List required;
+ private List forbidden;
+ private GSTNode root;
- public GrowShrinkTree(Score score, Map index, Node node, List required, List forbidden) {
+ public GrowShrinkTree(Score score, Map index, Node node) {
this.score = score;
this.index = index;
this.node = node;
this.nodeIndex = index.get(node);
this.root = new GSTNode(this);
- this.required = required;
- this.forbidden = forbidden;
- }
-
- public GrowShrinkTree(Score score, Map index, Node node) {
- this(score, index, node, new ArrayList<>(), new ArrayList<>());
+ this.required = new ArrayList<>();
+ this.forbidden = new ArrayList<>();
}
public double trace(Set prefix, Set parents) {
@@ -60,6 +57,16 @@ public List getVariables() {
return this.score.getVariables();
}
+ public List getRequired() { return this.required; }
+
+ public List getForbidden() { return this.forbidden; }
+
+ public void setKnowledge(List required, List forbidden) {
+ this.root = new GSTNode(this);
+ this.required = required;
+ this.forbidden = forbidden;
+ }
+
private static class GSTNode implements Comparable {
private final GrowShrinkTree tree;
private final Node add;
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java
index dbcceda433..7e403d8f8d 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java
@@ -40,7 +40,6 @@ public class OtherPermAlgs {
private boolean useScore = true;
private boolean usePearl = false;
private boolean verbose = false;
- private boolean cachingScores = true;
private boolean useDataOrder = false;
private int numVars;
@@ -84,8 +83,6 @@ public List bestOrder(@NotNull List _order) {
scorer.setKnowledge(knowledge);
scorer.clearBookmarks();
- scorer.setCachingScores(cachingScores);
-
List bestPerm = new ArrayList<>(order);
double best = Float.NEGATIVE_INFINITY;
@@ -437,10 +434,6 @@ public Graph getGraph(boolean cpDag) {
return graph;
}
- public void setCacheScores(boolean cachingScores) {
- this.cachingScores = cachingScores;
- }
-
public void setNumStarts(int numStarts) {
this.numStarts = numStarts;
}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java
index 40aaacebcd..752439ec5c 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java
@@ -91,7 +91,7 @@ public class Pc implements GraphSearch {
private boolean verbose;
private boolean stable;
- private boolean concurrent;
+// private boolean concurrent;
private boolean useMaxP = false;
private int maxPPathLength = -1;
private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE;
@@ -244,11 +244,11 @@ public Graph search(IFas fas, List nodes) {
search.setFasType(PcAll.FasType.REGULAR);
}
- if (concurrent) {
- search.setConcurrent(PcAll.Concurrent.YES);
- } else {
- search.setConcurrent(PcAll.Concurrent.NO);
- }
+// if (concurrent) {
+// search.setConcurrent(PcAll.Concurrent.YES);
+// } else {
+// search.setConcurrent(PcAll.Concurrent.NO);
+// }
search.setColliderDiscovery(PcAll.ColliderDiscovery.FAS_SEPSETS);
search.setConflictRule(conflictRule);
@@ -315,9 +315,9 @@ public void setStable(boolean stable) {
this.stable = stable;
}
- public void setConcurrent(boolean concurrent) {
- this.concurrent = concurrent;
- }
+// public void setConcurrent(boolean concurrent) {
+// this.concurrent = concurrent;
+// }
public void setUseMaxP(boolean useMaxP) {
this.useMaxP = useMaxP;
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java
index 2a32f02b52..02adbffd28 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java
@@ -92,7 +92,7 @@ public final class PcAll implements GraphSearch {
private boolean useHeuristic;
private int maxPathLength;
private FasType fasType = FasType.REGULAR;
- private Concurrent concurrent = Concurrent.YES;
+// private Concurrent concurrent = Concurrent.YES;
private ColliderDiscovery colliderDiscovery = ColliderDiscovery.FAS_SEPSETS;
private ConflictRule conflictRule = ConflictRule.OVERWRITE;
private Graph externalGraph = null;
@@ -169,9 +169,9 @@ public void setFasType(FasType fasType) {
this.fasType = fasType;
}
- public void setConcurrent(Concurrent concurrent) {
- this.concurrent = concurrent;
- }
+// public void setConcurrent(Concurrent concurrent) {
+// this.concurrent = concurrent;
+// }
public void setHeuristic(int heuristic) {
this.heuristic = heuristic;
@@ -320,21 +320,21 @@ public Graph search(List nodes) {
IFas fas;
if (this.fasType == FasType.REGULAR) {
- if (this.concurrent == Concurrent.NO) {
+// if (this.concurrent == Concurrent.NO) {
fas = new Fas(getIndependenceTest());
((Fas) fas).setHeuristic(this.heuristic);
- } else {
- fas = new FasConcurrent(getIndependenceTest());
- ((FasConcurrent) fas).setStable(false);
- }
+// } else {
+// fas = new FasConcurrent(getIndependenceTest());
+// ((FasConcurrent) fas).setStable(false);
+// }
} else {
- if (this.concurrent == Concurrent.NO) {
+// if (this.concurrent == Concurrent.NO) {
fas = new Fas(getIndependenceTest());
((Fas) fas).setStable(true);
- } else {
- fas = new FasConcurrent(getIndependenceTest());
- ((FasConcurrent) fas).setStable(true);
- }
+// } else {
+// fas = new FasConcurrent(getIndependenceTest());
+// ((FasConcurrent) fas).setStable(true);
+// }
}
fas.setKnowledge(getKnowledge());
@@ -605,7 +605,7 @@ public void setExternalGraph(Graph externalGraph) {
public enum FasType {REGULAR, STABLE}
- public enum Concurrent {YES, NO}
+ public enum Concurrent {NO};//, NO}
public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P}
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java
index 5e05bb77d9..7752f00a06 100644
--- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java
@@ -244,12 +244,12 @@ public Graph search(IFas fas, List nodes) {
search.setFasType(PcAll.FasType.REGULAR);
}
- if (concurrent) {
- search.setConcurrent(PcAll.Concurrent.YES);
- } else {
- search.setConcurrent(PcAll.Concurrent.NO);
- }
-
+// if (concurrent) {
+// search.setConcurrent(PcAll.Concurrent.YES);
+// } else {
+// search.setConcurrent(PcAll.Concurrent.NO);
+// }
+//
search.setColliderDiscovery(PcAll.ColliderDiscovery.MAX_P);
search.setConflictRule(conflictRule);
search.setUseHeuristic(useHeuristic);
@@ -311,9 +311,9 @@ public void setStable(boolean stable) {
this.stable = stable;
}
- public void setConcurrent(boolean concurrent) {
- this.concurrent = concurrent;
- }
+// public void setConcurrent(boolean concurrent) {
+// this.concurrent = concurrent;
+// }
public void setUseHeuristic(boolean useHeuristic) {
this.useHeuristic = useHeuristic;
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java
new file mode 100644
index 0000000000..05e5034006
--- /dev/null
+++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java
@@ -0,0 +1,550 @@
+package edu.cmu.tetrad.search;
+
+import edu.cmu.tetrad.data.Knowledge;
+import edu.cmu.tetrad.graph.*;
+import edu.cmu.tetrad.util.SublistGenerator;
+import edu.cmu.tetrad.util.TetradLogger;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.RecursiveTask;
+
+import static edu.cmu.tetrad.graph.Edges.directedEdge;
+import static org.apache.commons.math3.util.FastMath.min;
+
+
+/**
+ * Implements the backward equivalence search of FGES.
+ *
+ * @author bryanandrews
+ * @author josephramsey
+ */
+public class PermutationBes {
+ private final List variables;
+ private final Score score;
+ private Knowledge knowledge = new Knowledge();
+ private boolean verbose = true;
+ private int depth = 4;
+
+ public PermutationBes(@NotNull Score score) {
+ this.score = score;
+ this.variables = score.getVariables();
+ }
+
+ @NotNull
+ public List getVariables() {
+ return this.variables;
+ }
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public void setKnowledge(Knowledge knowledge) {
+ this.knowledge = new Knowledge((Knowledge) knowledge);
+ }
+
+ public void setDepth(int depth) {
+ if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1.");
+ this.depth = depth;
+ }
+
+ private void buildIndexing(List nodes, Map hashIndices) {
+
+ int i = -1;
+
+ for (Node n : nodes) {
+ hashIndices.put(n, ++i);
+ }
+ }
+
+ public void bes(Graph graph, List order, List suborder) {
+ Map hashIndices = new HashMap<>();
+ SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>();
+ Map arrowsMapBackward = new ConcurrentHashMap<>();
+ int[] arrowIndex = new int[1];
+
+ buildIndexing(order, hashIndices);
+
+ reevaluateBackward(new HashSet<>(order), graph, hashIndices, arrowIndex, sortedArrowsBack, arrowsMapBackward);
+
+ while (!sortedArrowsBack.isEmpty()) {
+ Arrow arrow = sortedArrowsBack.first();
+ sortedArrowsBack.remove(arrow);
+
+ Node x = arrow.getA();
+ Node y = arrow.getB();
+
+ if (!graph.isAdjacentTo(x, y)) {
+ continue;
+ }
+
+ Edge edge = graph.getEdge(x, y);
+
+ if (edge.pointsTowards(x)) {
+ continue;
+ }
+
+ if (!getNaYX(x, y, graph).equals(arrow.getNaYX())) {
+ continue;
+ }
+
+ if (!new HashSet<>(graph.getParents(y)).equals(new HashSet<>(arrow.getParents()))) {
+ continue;
+ }
+
+ if (!validDelete(x, y, arrow.getHOrT(), arrow.getNaYX(), graph, suborder)) {
+ continue;
+ }
+
+ Set complement = new HashSet<>(arrow.getNaYX());
+ complement.removeAll(arrow.getHOrT());
+
+ double _bump = deleteEval(x, y, complement, arrow.parents, hashIndices);
+
+ delete(x, y, arrow.getHOrT(), _bump, arrow.getNaYX(), graph);
+
+ Set process = revertToCPDAG(graph);
+ process.add(x);
+ process.add(y);
+ process.addAll(graph.getAdjacentNodes(x));
+ process.addAll(graph.getAdjacentNodes(y));
+
+ reevaluateBackward(new HashSet<>(process), graph, hashIndices, arrowIndex, sortedArrowsBack, arrowsMapBackward);
+ }
+ }
+
+ private void delete(Node x, Node y, Set H, double bump, Set naYX, Graph graph) {
+ Edge oldxy = graph.getEdge(x, y);
+
+ Set diff = new HashSet<>(naYX);
+ diff.removeAll(H);
+
+ graph.removeEdge(oldxy);
+
+ int numEdges = graph.getNumEdges();
+ if (numEdges % 1000 == 0 && numEdges > 0) {
+ System.out.println("Num edges (backwards) = " + numEdges);
+ }
+
+ if (verbose) {
+ int cond = diff.size() + graph.getParents(y).size();
+
+ String message = (graph.getNumEdges()) + ". DELETE " + x + " --> " + y + " H = " + H + " NaYX = " + naYX + " degree = " + GraphUtils.getDegree(graph) + " indegree = " + GraphUtils.getIndegree(graph) + " diff = " + diff + " (" + bump + ") " + " cond = " + cond;
+ TetradLogger.getInstance().forceLogMessage(message);
+ }
+
+ for (Node h : H) {
+ if (graph.isParentOf(h, y) || graph.isParentOf(h, x)) {
+ continue;
+ }
+
+ Edge oldyh = graph.getEdge(y, h);
+
+ graph.removeEdge(oldyh);
+
+ graph.addEdge(directedEdge(y, h));
+
+ if (verbose) {
+ TetradLogger.getInstance().forceLogMessage("--- Directing " + oldyh + " to " + graph.getEdge(y, h));
+ }
+
+ Edge oldxh = graph.getEdge(x, h);
+
+ if (Edges.isUndirectedEdge(oldxh)) {
+ graph.removeEdge(oldxh);
+
+ graph.addEdge(directedEdge(x, h));
+
+ if (verbose) {
+ TetradLogger.getInstance().forceLogMessage("--- Directing " + oldxh + " to " + graph.getEdge(x, h));
+ }
+ }
+ }
+ }
+
+ private double deleteEval(Node x, Node
+ y, Set complement, Set parents, Map hashIndices) {
+ Set set = new HashSet<>(complement);
+ set.addAll(parents);
+ set.remove(x);
+
+ return -scoreGraphChange(x, y, set, hashIndices);
+ }
+
+ private double scoreGraphChange(Node x, Node y, Set parents, Map hashIndices) {
+ int xIndex = hashIndices.get(x);
+ int yIndex = hashIndices.get(y);
+
+ if (x == y) {
+ throw new IllegalArgumentException();
+ }
+
+ if (parents.contains(y)) {
+ throw new IllegalArgumentException();
+ }
+
+ int[] parentIndices = new int[parents.size()];
+
+ int count = 0;
+ for (Node parent : parents) {
+ parentIndices[count++] = hashIndices.get(parent);
+ }
+
+ return score.localScoreDiff(xIndex, yIndex, parentIndices);
+ }
+
+ public Knowledge getKnowledge() {
+ return knowledge;
+ }
+
+ private Set revertToCPDAG(Graph graph) {
+ MeekRules rules = new MeekRules();
+ rules.setKnowledge(getKnowledge());
+ rules.setAggressivelyPreventCycles(true);
+ boolean meekVerbose = false;
+ rules.setVerbose(meekVerbose);
+ return rules.orientImplied(graph);
+ }
+
+ private boolean validDelete(Node x, Node y, Set H, Set naYX, Graph graph, List suborder) {
+ if (existsKnowledge()) {
+ for (Node h : H) {
+ if (knowledge.isForbidden(x.getName(), h.getName())) return false;
+ if (knowledge.isForbidden(y.getName(), h.getName())) return false;
+ }
+ }
+
+ Set diff = new HashSet<>(naYX);
+ diff.removeAll(H);
+ if (!isClique(diff, graph)) return false;
+
+ if (existsKnowledge()) {
+ graph = new EdgeListGraph(graph);
+ Edge oldxy = graph.getEdge(x, y);
+ graph.removeEdge(oldxy);
+
+ for (Node h : H) {
+ if (graph.isParentOf(h, y) || graph.isParentOf(h, x)) continue;
+ Edge oldyh = graph.getEdge(y, h);
+ graph.removeEdge(oldyh);
+ graph.addEdge(directedEdge(y, h));
+
+ Edge oldxh = graph.getEdge(x, h);
+ if (!Edges.isUndirectedEdge(oldxh)) continue;
+ graph.removeEdge(oldxh);
+ graph.addEdge(directedEdge(x, h));
+ }
+
+ revertToCPDAG(graph);
+ List initialOrder = new ArrayList<>(suborder);
+ Collections.reverse(initialOrder);
+
+ while (!initialOrder.isEmpty()) {
+ Iterator itr = initialOrder.iterator();
+ Node b;
+ do {
+ if (itr.hasNext()) b = itr.next();
+ else return false;
+ } while (invalidSink(b, graph));
+ graph.removeNode(b);
+ itr.remove();
+ }
+
+ }
+
+ return true;
+ }
+
+ private boolean invalidSink(Node x, Graph graph) {
+ LinkedList neighbors = new LinkedList<>();
+
+ for (Edge edge : graph.getEdges(x)) {
+ if (edge.getDistalEndpoint(x) == Endpoint.ARROW) return true;
+ if (edge.getProximalEndpoint(x) == Endpoint.TAIL) neighbors.add(edge.getDistalNode(x));
+ }
+
+ while (!neighbors.isEmpty()) {
+ Node y = neighbors.pop();
+ for (Node z : neighbors) if (!graph.isAdjacentTo(y, z)) return true;
+ }
+
+ return false;
+ }
+
+ private boolean existsKnowledge() {
+ return !knowledge.isEmpty();
+ }
+
+ private boolean isClique(Set nodes, Graph graph) {
+ List _nodes = new ArrayList<>(nodes);
+ for (int i = 0; i < _nodes.size(); i++) {
+ for (int j = i + 1; j < _nodes.size(); j++) {
+ if (!graph.isAdjacentTo(_nodes.get(i), _nodes.get(j))) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private Set getNaYX(Node x, Node y, Graph graph) {
+ List adj = graph.getAdjacentNodes(y);
+ Set nayx = new HashSet<>();
+
+ for (Node z : adj) {
+ if (z == x) {
+ continue;
+ }
+ Edge yz = graph.getEdge(y, z);
+ if (!Edges.isUndirectedEdge(yz)) {
+ continue;
+ }
+ if (!graph.isAdjacentTo(z, x)) {
+ continue;
+ }
+ nayx.add(z);
+ }
+
+ return nayx;
+ }
+
+ private void reevaluateBackward(Set toProcess, Graph graph, Map hashIndices,
+ int[] arrowIndex, SortedSet sortedArrowsBack, Map arrowsMapBackward) {
+
+ class BackwardTask extends RecursiveTask {
+ private final Node r;
+ private final List adj;
+ private final Map hashIndices;
+ private final int chunk;
+ private final int from;
+ private final int to;
+ private final SortedSet sortedArrowsBack;
+ final Map arrowsMapBackward;
+
+ private BackwardTask(Node r, List