From ac7372d908602df12a6bb6aa47480858ce8b4d43 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Thu, 13 Apr 2023 16:46:22 -0400 Subject: [PATCH 001/464] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e63fd7b56c..9dbba74b98 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You will need to set up Java on your machine. For setting up Java, see our Wiki To download the current jar you can use to launch the Tetrad GUI, click this link: -https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.3.3/tetrad-gui-7.3.3-launch.jar. +https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.3.4/tetrad-gui-7.3.4-launch.jar. You may be able to launch this jar by double clicking the jar file name, though on a Mac, this presents some [security challenges](https://github.com/cmu-phil/tetrad/wiki/Dealing-with-Tetrad-on-a-Mac:--Security-Issues). In From 3c8d9427fea34b403ccb83f0052309654478d0be Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Thu, 13 Apr 2023 17:05:55 -0400 Subject: [PATCH 002/464] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9dbba74b98..861c537665 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ our [Manual](https://htmlpreview.github.io/?https:///github.com/cmu-phil/tetrad/ If you like to watch thought-provoking lectures, here are some [lectures on the Center for Causal Discovery site](https://www.ccd.pitt.edu/video-tutorials/). -In addition, here are our [Javadocs](https://www.phil.cmu.edu/tetrad-javadocs/7.3.0/lib/). +In addition, here are our [Javadocs](https://www.phil.cmu.edu/tetrad-javadocs/7.3.4/lib/). ## Install From 9dcca40565db265db989eb13d1fd5c5c51619da6 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Thu, 13 Apr 2023 17:18:54 -0400 Subject: [PATCH 003/464] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 861c537665..e3ed450188 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ version of Tetrad and Causal Command. ## Setting up Java -You will need to set up Java on your machine. For setting up Java, see our Wiki artible, [Setting up Java for Tetrad](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java-for-Tetrad). +You will need to set up Java on your machine. For setting up Java, see our Wiki article, [Setting up Java for Tetrad](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java-for-Tetrad). ## Tetrad GUI Application From c0fcbd5861395db87430d1219f820fac639e61b1 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 15 Apr 2023 06:22:49 -0400 Subject: [PATCH 004/464] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e3ed450188..7216f708bb 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ our [Manual](https://htmlpreview.github.io/?https:///github.com/cmu-phil/tetrad/ If you like to watch thought-provoking lectures, here are some [lectures on the Center for Causal Discovery site](https://www.ccd.pitt.edu/video-tutorials/). -In addition, here are our [Javadocs](https://www.phil.cmu.edu/tetrad-javadocs/7.3.4/lib/). +In addition, here are our [Javadocs](https://www.phil.cmu.edu/tetrad-javadocs/7.3.4/). ## Install From 37ae69aa5d47b3e3edd679867a2a5af81d26bce0 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 15 Apr 2023 06:26:53 -0400 Subject: [PATCH 005/464] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7216f708bb..e3ed450188 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ our [Manual](https://htmlpreview.github.io/?https:///github.com/cmu-phil/tetrad/ If you like to watch thought-provoking lectures, here are some [lectures on the Center for Causal Discovery site](https://www.ccd.pitt.edu/video-tutorials/). -In addition, here are our [Javadocs](https://www.phil.cmu.edu/tetrad-javadocs/7.3.4/). +In addition, here are our [Javadocs](https://www.phil.cmu.edu/tetrad-javadocs/7.3.4/lib/). ## Install From 390ef5a5595e69a141460f4c42aa3929a14dfa52 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Tue, 18 Apr 2023 17:17:23 -0500 Subject: [PATCH 006/464] refactored the dg score so that it wraps sem bic --- .../search/DegenerateGaussianScore.java | 202 +++--------------- 1 file changed, 33 insertions(+), 169 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java index 859a5c5fdc..8817e73f8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java @@ -1,32 +1,9 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.RealMatrix; -import org.apache.commons.math3.util.FastMath; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -34,9 +11,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentSkipListMap; -import static org.apache.commons.math3.util.FastMath.log; /** * Implements a degenerate Gaussian BIC score for FGES. @@ -45,38 +20,24 @@ * * @author Bryan Andrews */ -public class DegenerateGaussianScore implements Score { - - private final BoxDataSet ddata; - private final DataSet dataSet; +public class DegenerateGaussianScore implements Score { // The mixed variables of the original dataset. private final List variables; - // The penalty discount. - private double penaltyDiscount = 1.0; - // The structure prior. private double structurePrior; // The embedding map. private final Map> embedding; - // A constant. - private static final double L2PE = log(2.0 * FastMath.PI * FastMath.E); + private final SemBicScore bic; - private final Map nodesHash; - - - /** - * Constructs the score using a covariance matrix. - */ public DegenerateGaussianScore(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException(); } - this.dataSet = dataSet; this.variables = dataSet.getVariables(); // The number of instances. int n = dataSet.getNumRows(); @@ -99,7 +60,7 @@ public DegenerateGaussianScore(DataSet dataSet) { Map> keysReverse = new HashMap<>(); for (int j = 0; j < n; j++) { List key = new ArrayList<>(); - key.add(this.dataSet.getInt(j, i_)); + key.add(dataSet.getInt(j, i_)); if (!keys.containsKey(key)) { keys.put(key, i); keysReverse.put(i, key); @@ -111,9 +72,7 @@ public DegenerateGaussianScore(DataSet dataSet) { B.get(keys.get(key))[j] = 1; } - /* - * Remove a degenerate dimension. - */ + // Remove a degenerate dimension. i--; keys.remove(keysReverse.get(i)); A.remove(i); @@ -126,7 +85,7 @@ public DegenerateGaussianScore(DataSet dataSet) { A.add(v); double[] b = new double[n]; for (int j = 0; j < n; j++) { - b[j] = this.dataSet.getDouble(j, i_); + b[j] = dataSet.getDouble(j, i_); } B.add(b); @@ -145,90 +104,58 @@ public DegenerateGaussianScore(DataSet dataSet) { } } - // The continuous variables of the post-embedding dataset. RealMatrix D = new BlockRealMatrix(B_); - this.ddata = new BoxDataSet(new DoubleDataBox(D.getData()), A); - this.nodesHash = new ConcurrentSkipListMap<>(); - - List variables = dataSet.getVariables(); - - for (int j = 0; j < variables.size(); j++) { - this.nodesHash.put(variables.get(j), j); - } - + this.bic = new SemBicScore(new BoxDataSet(new DoubleDataBox(D.getData()), A)); + this.bic.setStructurePrior(0); } /** * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model */ public double localScore(int i, int... parents) { + double score = 0; - List rows = getRows(i, parents); - int N = rows.size(); - - List B = new ArrayList<>(); List A = new ArrayList<>(this.embedding.get(i)); + List B = new ArrayList<>(); for (int i_ : parents) { B.addAll(this.embedding.get(i_)); } - int[] A_ = new int[A.size() + B.size()]; - int[] B_ = new int[B.size()]; - for (int i_ = 0; i_ < A.size(); i_++) { - A_[i_] = A.get(i_); - } + int[] parents_ = new int[B.size()]; for (int i_ = 0; i_ < B.size(); i_++) { - A_[A.size() + i_] = B.get(i_); - B_[i_] = B.get(i_); + parents_[i_] = B.get(i_); } - int dof = (A_.length * (A_.length + 1) - B_.length * (B_.length + 1)) / 2; - double ldetA = log(getCov(rows, A_).det()); - double ldetB = log(getCov(rows, B_).det()); - - double lik = N * (ldetB - ldetA + DegenerateGaussianScore.L2PE * (B_.length - A_.length)); - double score = 2 * lik + 2 * calculateStructurePrior(parents.length) - dof * getPenaltyDiscount() * log(N); - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; + for (Integer i_ : A) { + score += this.bic.localScore(i_, parents_); } - } - private double calculateStructurePrior(int k) { - if (this.structurePrior <= 0) { - return 0; - } else { - double n = this.variables.size() - 1; - double p = this.structurePrior / n; - return k * log(p) + (n - k) * log(1.0 - p); - } - } + return score; + } public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - - public int getSampleSize() { - return this.dataSet.getNumRows(); + @Override + public List getVariables() { + return this.variables; } @Override public boolean isEffectEdge(double bump) { - return bump > 0; + return this.bic.isEffectEdge(bump); } @Override - public List getVariables() { - return this.variables; + public int getSampleSize() { + return this.bic.getSampleSize(); } @Override public int getMaxDegree() { - return (int) FastMath.ceil(log(this.dataSet.getNumRows())); + return this.bic.getMaxDegree(); } @Override @@ -236,89 +163,26 @@ public boolean determines(List z, Node y) { return false; } + @Override + public String toString() { + NumberFormat nf = new DecimalFormat("0.00"); + return "Degenerate Gaussian Score Penalty " + nf.format(this.bic.getPenaltyDiscount()); + } + public double getPenaltyDiscount() { - return this.penaltyDiscount; + return this.bic.getPenaltyDiscount(); } public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; + this.bic.setPenaltyDiscount(penaltyDiscount); } public double getStructurePrior() { - return this.structurePrior; + return structurePrior; } public void setStructurePrior(double structurePrior) { + System.out.println("STRUCTURE PRIOR IS NOT IMPLEMENTED!"); this.structurePrior = structurePrior; } - - @Override - public String toString() { - NumberFormat nf = new DecimalFormat("0.00"); - return "Degenerate Gaussian Score Penalty " + nf.format(this.penaltyDiscount); - } - - // Subsample of the continuous mixedVariables conditioning on the given cols. - private Matrix getCov(List rows, int[] cols) { - if (rows.isEmpty()) return new Matrix(0, 0); - Matrix cov = new Matrix(cols.length, cols.length); - - for (int i = 0; i < cols.length; i++) { - for (int j = 0; j < cols.length; j++) { - double mui = 0.0; - double muj = 0.0; - - for (int k : rows) { - mui += this.ddata.getDouble(k, cols[i]); - muj += this.ddata.getDouble(k, cols[j]); - } - - mui /= rows.size() - 1; - muj /= rows.size() - 1; - - double _cov = 0.0; - - for (int k : rows) { - _cov += (this.ddata.getDouble(k, cols[i]) - mui) * (this.ddata.getDouble(k, cols[j]) - muj); - } - - double mean = _cov / (rows.size()); - cov.set(i, j, mean); - } - } - - return cov; - } - - private List getRows(int i, int[] parents) { - List rows = new ArrayList<>(); - - K: - for (int k = 0; k < this.dataSet.getNumRows(); k++) { - Node ii = this.variables.get(i); - - List A = new ArrayList<>(this.embedding.get(this.nodesHash.get(ii))); - - for (int j : A) { - if (Double.isNaN(this.ddata.getDouble(k, j))) continue K; - } - - for (int ignored : parents) { - Node pp = this.variables.get(i); - - List AA = new ArrayList<>(this.embedding.get(this.nodesHash.get(pp))); - - for (int j : AA) { - if (Double.isNaN(this.ddata.getDouble(k, j))) continue K; - } - } - - rows.add(k); - } - - return rows; - } -} - - - +} \ No newline at end of file From 4c1fc1d6995adf38807e6ca5456edc966a5cf735 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 21 Apr 2023 11:35:52 -0400 Subject: [PATCH 007/464] Adding preambles to some files. --- .../score/DegenerateGaussianBicScore.java | 21 +++++++++++++++++++ .../search/DegenerateGaussianScore.java | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) 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 a2fe62b423..b89c278f45 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 @@ -1,3 +1,24 @@ +/////////////////////////////////////////////////////////////////////////////// +// For information as to what this class does, see the Javadoc, below. // +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // +// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // +// Scheines, Joseph Ramsey, and Clark Glymour. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +/////////////////////////////////////////////////////////////////////////////// + package edu.cmu.tetrad.algcomparison.score; import edu.cmu.tetrad.annotation.Mixed; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java index 8817e73f8f..9ce5dfd88e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java @@ -1,3 +1,24 @@ +/////////////////////////////////////////////////////////////////////////////// +// For information as to what this class does, see the Javadoc, below. // +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // +// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // +// Scheines, Joseph Ramsey, and Clark Glymour. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +/////////////////////////////////////////////////////////////////////////////// + package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.*; From 03b9d29e7d9349b8645a5cea1b496cf3c8e989f2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 22 Apr 2023 16:29:48 -0400 Subject: [PATCH 008/464] Removing the LiNG algcomparison wrapper because LiNG doesn't return a single graph. --- .../algorithm/continuous/dag/Ling.java | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Ling.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Ling.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Ling.java deleted file mode 100644 index 3c9132448a..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Ling.java +++ /dev/null @@ -1,82 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.continuous.dag; - -import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.annotation.AlgType; -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.SimpleDataLoader; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -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; - -/** - * LiNGAM. - * - * @author jdramsey - */ -@edu.cmu.tetrad.annotation.Algorithm( - name = "LiNG", - command = "ling", - algoType = AlgType.forbid_latent_common_causes, - dataType = DataType.Continuous -) -@Bootstrapping -@Experimental -public class Ling implements Algorithm { - - static final long serialVersionUID = 23L; - - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - DataSet _dataSet = SimpleDataLoader.getContinuousDataSet(dataSet); - edu.cmu.tetrad.search.Ling lingam = new edu.cmu.tetrad.search.Ling(_dataSet); -// lingam.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - edu.cmu.tetrad.search.Ling.StoredGraphs search = lingam.search(); - - if (search.getNumGraphs() > 0) { - return search.getGraph(0); - } else { - return new EdgeListGraph(); - } - } else { - Ling algorithm = new Ling(); - - 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(); - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - public String getDescription() { - return "LiNGAM (Linear Non-Gaussian Acyclic Model"; - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.PENALTY_DISCOUNT); - parameters.add(Params.VERBOSE); - return parameters; - } -} \ No newline at end of file From d52c0ff21e90503257f7101373b752a455229fbe Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 23 Apr 2023 20:41:51 -0400 Subject: [PATCH 009/464] Some work on LiNG. --- .../java/edu/cmu/tetrad/search/Hungarian.java | 525 ---------- .../main/java/edu/cmu/tetrad/search/Ling.java | 907 ++++-------------- .../java/edu/cmu/tetrad/search/NRooks.java | 88 ++ .../tetrad/search/PermutationMatrixPair.java | 27 +- .../java/edu/cmu/tetrad/util/LingUtils.java | 15 +- .../java/edu/cmu/tetrad/util/MatrixUtils.java | 20 +- .../java/edu/cmu/tetrad/test/TestLing.java} | 68 +- 7 files changed, 331 insertions(+), 1319 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hungarian.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java rename tetrad-lib/src/{main/java/edu/cmu/tetrad/graph/GraphGroup.java => test/java/edu/cmu/tetrad/test/TestLing.java} (52%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hungarian.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hungarian.java deleted file mode 100644 index 4834d5d674..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hungarian.java +++ /dev/null @@ -1,525 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.util.RandomUtil; - -import java.util.Arrays; -import java.util.Scanner; - -import static org.apache.commons.math3.util.FastMath.floor; -import static org.apache.commons.math3.util.FastMath.round; - -/** - * The Hungarian algorithm for solving the N-Queens problem. - */ -public class Hungarian { - - //********************************// - //METHODS FOR CONSOLE INPUT-OUTPUT// - //********************************// - - public static int readInput(String prompt) //Reads input,returns double. - { - Scanner in = new Scanner(System.in); - System.out.print(prompt); - return in.nextInt(); - } - - public static void printTime(double time) //Formats time output. - { - String timeElapsed = ""; - int days = (int) floor(time) / (24 * 3600); - int hours = (int) floor(time % (24 * 3600)) / (3600); - int minutes = (int) floor((time % 3600) / 60); - int seconds = (int) round(time % 60); - - if (days > 0) - timeElapsed = days + "d:"; - if (hours > 0) - timeElapsed = timeElapsed + hours + "h:"; - if (minutes > 0) - timeElapsed = timeElapsed + minutes + "m:"; - - timeElapsed = timeElapsed + seconds + "s"; - System.out.print("\nTotal time required: " + timeElapsed + "\n\n"); - } - - //*******************************************// - //METHODS THAT PERFORM ARRAY-PROCESSING TASKS// - //*******************************************// - - public static void generateRandomArray //Generates random 2-D array. - (double[][] array, String randomMethod) { - for (int i = 0; i < array.length; i++) { - for (int j = 0; j < array[i].length; j++) { - if (randomMethod.equals("random")) { - array[i][j] = RandomUtil.getInstance().nextDouble(); - } - if (randomMethod.equals("gaussian")) { - array[i][j] = RandomUtil.getInstance().nextNormal(0, 1) / 4; //range length to 1. - if (array[i][j] > 0.5) { - array[i][j] = 0.5; - } //eliminate outliers. - if (array[i][j] < -0.5) { - array[i][j] = -0.5; - } //eliminate outliers. - array[i][j] = array[i][j] + 0.5; //make elements positive. - } - } - } - } - - public static double findLargest //Finds the largest element in a positive array. - (double[][] array) - //works for arrays where all values are >= 0. - { - double largest = 0; - for (double[] doubles : array) { - for (double aDouble : doubles) { - if (aDouble > largest) { - largest = aDouble; - } - } - } - - return largest; - } - - public static double[][] transpose //Transposes a double[][] array. - (double[][] array) { - double[][] transposedArray = new double[array[0].length][array.length]; - for (int i = 0; i < transposedArray.length; i++) { - for (int j = 0; j < transposedArray[i].length; j++) { - transposedArray[i][j] = array[j][i]; - } - } - return transposedArray; - } - - public static double[][] copyOf //Copies all elements of an array to a new array. - (double[][] original) { - double[][] copy = new double[original.length][original[0].length]; - for (int i = 0; i < original.length; i++) { - //Need to do it this way, otherwise it copies only memory location - System.arraycopy(original[i], 0, copy[i], 0, original[i].length); - } - - return copy; - } - - //**********************************// - //METHODS OF THE HUNGARIAN ALGORITHM// - //**********************************// - - public static int[][] hgAlgorithm(double[][] array, String sumType) { - double[][] cost = Hungarian.copyOf(array); //Create the cost matrix - - if (sumType.equalsIgnoreCase("max")) //Then array is weight array. Must change to cost. - { - double maxWeight = Hungarian.findLargest(cost); - for (int i = 0; i < cost.length; i++) //Generate cost by subtracting. - { - for (int j = 0; j < cost[i].length; j++) { - cost[i][j] = (maxWeight - cost[i][j]); - } - } - } - double maxCost = Hungarian.findLargest(cost); //Find largest cost matrix element (needed for step 6). - - int[][] mask = new int[cost.length][cost[0].length]; //The mask array. - int[] rowCover = new int[cost.length]; //The row covering vector. - int[] colCover = new int[cost[0].length]; //The column covering vector. - int[] zero_RC = new int[2]; //Position of last zero from Step 4. - int step = 1; - boolean done = false; - while (!done) //main execution loop - { - switch (step) { - case 1: - step = Hungarian.hg_step1(cost); - break; - case 2: - step = Hungarian.hg_step2(cost, mask, rowCover, colCover); - break; - case 3: - step = Hungarian.hg_step3(mask, colCover); - break; - case 4: - step = Hungarian.hg_step4(step, cost, mask, rowCover, colCover, zero_RC); - break; - case 5: - step = Hungarian.hg_step5(mask, rowCover, colCover, zero_RC); - break; - case 6: - step = Hungarian.hg_step6(cost, rowCover, colCover, maxCost); - break; - case 7: - done = true; - break; - } - }//end while - - int[][] assignment = new int[array.length][2]; //Create the returned array. - for (int i = 0; i < mask.length; i++) { - for (int j = 0; j < mask[i].length; j++) { - if (mask[i][j] == 1) { - assignment[i][0] = i; - assignment[i][1] = j; - } - } - } - - //If you want to return the min or max sum, in your own main method - //instead of the assignment array, then use the following code: - //Of course you must also change the header of the method to: - //public static double hgAlgorithm (double[][] array, String sumType) - - return assignment; - } - - public static int hg_step1(double[][] cost) { - //What STEP 1 does: - //For each row of the cost matrix, find the smallest element - //and subtract it from from every other element in its row. - - double minval; - - for (int i = 0; i < cost.length; i++) { - minval = cost[i][0]; - for (int j = 0; j < cost[i].length; j++) //1st inner loop finds min val in row. - { - if (minval > cost[i][j]) { - minval = cost[i][j]; - } - } - for (int j = 0; j < cost[i].length; j++) //2nd inner loop subtracts it. - { - cost[i][j] = cost[i][j] - minval; - } - } - - return 2; - } - - public static int hg_step2(double[][] cost, int[][] mask, int[] rowCover, int[] colCover) { - //What STEP 2 does: - //Marks uncovered zeros as starred and covers their row and column. - - for (int i = 0; i < cost.length; i++) { - for (int j = 0; j < cost[i].length; j++) { - if ((cost[i][j] == 0) && (colCover[j] == 0) && (rowCover[i] == 0)) { - mask[i][j] = 1; - colCover[j] = 1; - rowCover[i] = 1; - } - } - } - - Hungarian.clearCovers(rowCover, colCover); //Reset cover vectors. - - return 3; - } - - public static int hg_step3(int[][] mask, int[] colCover) { - //What STEP 3 does: - //Cover columns of starred zeros. Check if all columns are covered. - - //Cover columns of starred zeros. - for (int[] ints : mask) { - for (int j = 0; j < ints.length; j++) { - if (ints[j] == 1) { - colCover[j] = 1; - } - } - } - - int count = 0; - //Check if all columns are covered. - for (int i : colCover) { - count = count + i; - } - - int step; - if (count >= mask.length) //Should be cost.length but ok, because mask has same dimensions. - { - step = 7; - } else { - step = 4; - } - - return step; - } - - public static int hg_step4(int step, double[][] cost, int[][] mask, int[] rowCover, int[] colCover, int[] zero_RC) { - //What STEP 4 does: - //Find an uncovered zero in cost and prime it (if none go to step 6). Check for star in same row: - //if yes, cover the row and uncover the star's column. Repeat until no uncovered zeros are left - //and go to step 6. If not, save location of primed zero and go to step 5. - - int[] row_col = new int[2]; //Holds row and col of uncovered zero. - boolean done = false; - while (!done) { - Hungarian.findUncoveredZero(row_col, cost, rowCover, colCover); - if (row_col[0] == -1) { - done = true; - step = 6; - } else { - mask[row_col[0]][row_col[1]] = 2; //Prime the found uncovered zero. - - boolean starInRow = false; - for (int j = 0; j < mask[row_col[0]].length; j++) { - if (mask[row_col[0]][j] == 1) //If there is a star in the same row... - { - starInRow = true; - row_col[1] = j; //remember its column. - } - } - - if (starInRow) { - rowCover[row_col[0]] = 1; //Cover the star's row. - colCover[row_col[1]] = 0; //Uncover its column. - } else { - zero_RC[0] = row_col[0]; //Save row of primed zero. - zero_RC[1] = row_col[1]; //Save column of primed zero. - done = true; - step = 5; - } - } - } - - return step; - } - - public static void findUncoveredZero //Aux 1 for hg_step4. - (int[] row_col, double[][] cost, int[] rowCover, int[] colCover) { - row_col[0] = -1; //Just a check value. Not a real index. - row_col[1] = 0; - - int i = 0; - boolean done = false; - while (!done) { - int j = 0; - while (j < cost[i].length) { - if (cost[i][j] == 0 && rowCover[i] == 0 && colCover[j] == 0) { - row_col[0] = i; - row_col[1] = j; - done = true; - } - j = j + 1; - }//end inner while - i = i + 1; - if (i >= cost.length) { - done = true; - } - }//end outer while - - } - - public static int hg_step5(int[][] mask, int[] rowCover, int[] colCover, int[] zero_RC) { - //What STEP 5 does: - //Construct series of alternating primes and stars. Start with prime from step 4. - //Take star in the same column. Next take prime in the same row as the star. Finish - //at a prime with no star in its column. Unstar all stars and star the primes of the - //series. Erasy any other primes. Reset covers. Go to step 3. - - int count = 0; //Counts rows of the path matrix. - int[][] path = new int[(mask[0].length * mask.length)][2]; //Path matrix (stores row and col). - path[count][0] = zero_RC[0]; //Row of last prime. - path[count][1] = zero_RC[1]; //Column of last prime. - - boolean done = false; - while (!done) { - int r = Hungarian.findStarInCol(mask, path[count][1]); - if (r >= 0) { - count = count + 1; - path[count][0] = r; //Row of starred zero. - path[count][1] = path[count - 1][1]; //Column of starred zero. - } else { - done = true; - } - - if (!done) { - int c = Hungarian.findPrimeInRow(mask, path[count][0]); - count = count + 1; - path[count][0] = path[count - 1][0]; //Row of primed zero. - path[count][1] = c; //Col of primed zero. - } - }//end while - - Hungarian.convertPath(mask, path, count); - Hungarian.clearCovers(rowCover, colCover); - Hungarian.erasePrimes(mask); - - return 3; - - } - - public static int findStarInCol //Aux 1 for hg_step5. - (int[][] mask, int col) { - int r = -1; //Again this is a check value. - for (int i = 0; i < mask.length; i++) { - if (mask[i][col] == 1) { - r = i; - } - } - - return r; - } - - public static int findPrimeInRow //Aux 2 for hg_step5. - (int[][] mask, int row) { - int c = -1; - for (int j = 0; j < mask[row].length; j++) { - if (mask[row][j] == 2) { - c = j; - } - } - - return c; - } - - public static void convertPath //Aux 3 for hg_step5. - (int[][] mask, int[][] path, int count) { - for (int i = 0; i <= count; i++) { - if (mask[(path[i][0])][(path[i][1])] == 1) { - mask[(path[i][0])][(path[i][1])] = 0; - } else { - mask[(path[i][0])][(path[i][1])] = 1; - } - } - } - - public static void erasePrimes //Aux 4 for hg_step5. - (int[][] mask) { - for (int i = 0; i < mask.length; i++) { - for (int j = 0; j < mask[i].length; j++) { - if (mask[i][j] == 2) { - mask[i][j] = 0; - } - } - } - } - - public static void clearCovers //Aux 5 for hg_step5 (and not only). - (int[] rowCover, int[] colCover) { - Arrays.fill(rowCover, 0); - Arrays.fill(colCover, 0); - } - - public static int hg_step6(double[][] cost, int[] rowCover, int[] colCover, double maxCost) { - //What STEP 6 does: - //Find smallest uncovered value in cost: a. Add it to every element of covered rows - //b. Subtract it from every element of uncovered columns. Go to step 4. - - double minval = Hungarian.findSmallest(cost, rowCover, colCover, maxCost); - - for (int i = 0; i < rowCover.length; i++) { - for (int j = 0; j < colCover.length; j++) { - if (rowCover[i] == 1) { - cost[i][j] = cost[i][j] + minval; - } - if (colCover[j] == 0) { - cost[i][j] = cost[i][j] - minval; - } - } - } - - return 4; - } - - public static double findSmallest //Aux 1 for hg_step6. - (double[][] cost, int[] rowCover, int[] colCover, double maxCost) { - double minval = maxCost; //There cannot be a larger cost than this. - for (int i = 0; i < cost.length; i++) //Now find the smallest uncovered value. - { - for (int j = 0; j < cost[i].length; j++) { - if (rowCover[i] == 0 && colCover[j] == 0 && (minval > cost[i][j])) { - minval = cost[i][j]; - } - } - } - - return minval; - } - - //***********// - //MAIN METHOD// - //***********// - - public static void main(String[] args) { - //Below enter "max" or "min" to find maximum sum or minimum sum assignment. - final String sumType = "max"; - - //Hard-coded example. - //double[][] array = - //{ - // {1, 2, 3}, - // {2, 4, 6}, - // {3, 6, 9} - //}; - - // BELOW AND COMMENT BLOCK ABOVE TO USE A RANDOMLY GENERATED MATRIX - int numOfRows = Hungarian.readInput("How many rows for the matrix? "); - int numOfCols = Hungarian.readInput("How many columns for the matrix? "); - double[][] array = new double[numOfRows][numOfCols]; - Hungarian.generateRandomArray(array, "random"); //All elements within [0,1]. - // - - if (array.length > array[0].length) { - System.out.println("Array transposed (because rows>columns).\n"); //Cols must be >= Rows. - array = Hungarian.transpose(array); - } - - // TO AVOID PRINTING THE MATRIX FOR WHICH THE ASSIGNMENT IS CALCULATED - System.out.println("\n(Printing out only 2 decimals)\n"); - System.out.println("The matrix is:"); - for (double[] doubles : array) { - for (double aDouble : doubles) { - System.out.printf("%.2f\t", aDouble); - } - System.out.println(); - } - System.out.println(); - //*/ - - double startTime = System.nanoTime(); - int[][] assignment; - assignment = Hungarian.hgAlgorithm(array, sumType); //Call Hungarian algorithm. - double endTime = System.nanoTime(); - - System.out.println("The winning assignment (" + sumType + " sum) is:\n"); - double sum = 0; - for (int[] ints : assignment) { - System.out.printf("array(%d,%d) = %.2f\n", (ints[0] + 1), (ints[1] + 1), - array[ints[0]][ints[1]]); - sum = sum + array[ints[0]][ints[1]]; - } - - System.out.printf("\nThe %s is: %.2f\n", sumType, sum); - Hungarian.printTime((endTime - startTime) / 1000000000.0); - - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java index d0fd713ffa..5e18d9f919 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java @@ -21,67 +21,50 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.BoxDataSet; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DoubleDataBox; +import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphGroup; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.LingUtils; -import edu.cmu.tetrad.util.Matrix; -import edu.cmu.tetrad.util.TetradLogger; -import edu.cmu.tetrad.util.Vector; -import edu.cmu.tetrad.util.dist.Distribution; -import edu.cmu.tetrad.util.dist.GaussianPower; -import org.apache.commons.math3.analysis.MultivariateFunction; +import edu.cmu.tetrad.util.*; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; import org.apache.commons.math3.linear.QRDecomposition; import org.apache.commons.math3.linear.RealMatrix; -import org.apache.commons.math3.optim.InitialGuess; -import org.apache.commons.math3.optim.MaxEval; -import org.apache.commons.math3.optim.PointValuePair; -import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; -import org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer; -import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; -import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.PowellOptimizer; import java.util.ArrayList; -import java.util.Date; import java.util.List; import static org.apache.commons.math3.util.FastMath.*; /** - * The code used within this class is largely Gustave Lacerda's, which corresponds to his essay, Discovering Cyclic - * Causal Models by Independent Components Analysis. The code models the LiNG algorithm. - *

- *

Note: This code is currently broken; please do not use it until it's fixed. 11/24/2015> 0 + * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering cyclic causal models + * by independent components analysis. arXiv preprint arXiv:1206.3273. + * + * @author lacerda + * @author josephramsey */ public class Ling { /** - * Number of samples used when simulating data. + * The dataset being used for search. */ - private int numSamples; + private final DataSet dataSet; /** - * This algorithm uses thresholding to zero out small covariance values. This variable defines the value at which - * the thresholding occurs. - */ - private double threshold = .5; - - /** - * Time needed to process the search method. + * The variables in the dataset. */ - private long elapsedTime; + private final List variables; /** - * Either passed in through the constructor or simulated using a graph. + * This algorithm uses thresholding to zero out small covariance values. This variable defines the value at which + * the thresholding occurs. */ - private DataSet dataSet; + private double threshold = .5; -// private double pruneFactor = 1.0; + private double fastIcaA = 1.1; + private int fastIcaMaxIter = 2000; + private double fastIcaTolerance = 1e-6; //=============================CONSTRUCTORS============================// @@ -89,35 +72,11 @@ public class Ling { * The algorithm only requires a DataSet to process. Passing in a Dataset and then running the search algorithm is * an effetive way to use LiNG. * - * @param d a DataSet over which the algorithm can process + * @param dataSet a DataSet over which the algorithm can process */ - public Ling(DataSet d) { - this.dataSet = d; - } - - /** - * When you don't have a Dataset, supply a GraphWithParameters and the number of samples to draw and the algorithm - * will generate a DataSet. - * - * @param graphWP a graph with parameters from GraphWithParameters - * @param samples the number of samples the algorithm draws in order to generate a DataSet - */ - public Ling(GraphWithParameters graphWP, int samples) { - this.numSamples = samples; - makeDataSet(graphWP); - } - - /** - * When you don't have a Dataset, supply a Graph and the number of samples to draw and the algorithm will generate a - * DataSet. - * - * @param g a graph from Graph - * @param samples the number of samples the algorithm draws in order to generate a DataSet - */ - public Ling(Graph g, int samples) { - this.numSamples = samples; - GraphWithParameters graphWP = new GraphWithParameters(g); - makeDataSet(graphWP); + public Ling(DataSet dataSet) { + this.dataSet = dataSet; + this.variables = dataSet.getVariables(); } //==============================PUBLIC METHODS=========================// @@ -132,270 +91,220 @@ public DataSet getData() { /** * The search method is used to process LiNG. Call search when you want to run the algorithm. */ - public StoredGraphs search() { - Matrix W; - StoredGraphs graphs = new StoredGraphs(); - - try { - long sTime = (new Date()).getTime(); - - final boolean fastIca = true; - - if (fastIca) { - W = getWFastIca(); - - System.out.println("W = " + W); - - //this is the heart of our method: - graphs = findCandidateModels(this.dataSet.getVariables(), W); - } else { - List allMappings = createMappings(this.dataSet.getNumColumns()); - - W = estimateW(new Matrix(this.dataSet.getDoubleData().transpose()), - this.dataSet.getNumColumns(), allMappings); - - System.out.println("W = " + W); - - //this is the heart of our method: - graphs = findCandidateModel(this.dataSet.getVariables(), W); - } - - this.elapsedTime = (new Date()).getTime() - sTime; - } catch (Exception e) { - e.printStackTrace(); - } - - return graphs; + public List search() { + Matrix w = getWFastIca(); + return findCandidateModels(w); } - - private Matrix estimateW(Matrix matrix, int numNodes, List allMappings) { - Matrix W = initializeW(numNodes); - maxMappings(matrix, W, allMappings); - return W; + /** + * Sets the value at which thresholding occurs on Fast ICA data. Default is .05. + * + * @param t The value at which the thresholding is set + */ + public void setThreshold(double t) { + this.threshold = t; } - private void maxMappings(Matrix matrix, Matrix W, List allMappings) { - - int numNodes = W.rows(); + public static Graph getGraph(double[][] b, List variables) { + Graph graph = new EdgeListGraph(variables); - for (int i = 0; i < numNodes; i++) { - final double maxScore = Double.NEGATIVE_INFINITY; - double[] maxRow = new double[numNodes]; - - for (Mapping mapping : mappingsForRow(i, allMappings)) { - W.set(mapping.getI(), mapping.getJ(), 0); + for (int i = 0; i < variables.size(); i++) { + for (int j = 0; j < variables.size(); j++) { + if (i != j && b[j][i] != 0) { + graph.addDirectedEdge(variables.get(j), variables.get(i)); + } } + } - try { - optimizeNonGaussianity(i, matrix, W, allMappings); -// optimizeOrthogonality(i, min, max, W, allMappings, W.length); - } catch (IllegalStateException e) { - e.printStackTrace(); - continue; - } + return graph; + } - double v = ngFullData(i, matrix, W); + public static boolean isStable(double[][] matrix) { + EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(matrix)); + double[] realEigenvalues = eigen.getRealEigenvalues(); + double[] imagEigenvalues = eigen.getImagEigenvalues(); - if (Double.isNaN(v)) continue; - if (v >= 9999) continue; + for (int i = 0; i < realEigenvalues.length; i++) { + double realEigenvalue = realEigenvalues[i]; +// double imagEigenvalue = imagEigenvalues[i]; + double modulus = sqrt(pow(realEigenvalue, 2) /*+ pow(imagEigenvalue, 2)*/); - double[] row = new double[numNodes]; - for (int k = 0; k < numNodes; k++) row[k] = W.get(i, k); + System.out.println("modulus" + " " + modulus); - if (v > maxScore) { - maxRow = row; + if (realEigenvalue >= 1.0) { + return false; } - - for (int k = 0; k < numNodes; k++) W.set(i, k, maxRow[k]); } + + return true; } - private void optimizeNonGaussianity(int rowIndex, Matrix dataSetTetradMatrix, - Matrix W, List allMappings) { - List mappings = mappingsForRow(rowIndex, allMappings); + //==============================PRIVATE METHODS====================// - MultivariateFunction function = values -> { - for (int i = 0; i < values.length; i++) { - Mapping mapping = mappings.get(i); - W.set(mapping.getI(), mapping.getJ(), values[i]); + private List findCandidateModels(Matrix w) { + for (int i = 0; i < w.rows(); i++) { + for (int j = 0; j < w.columns(); j++) { + if (abs(w.get(i, j)) < threshold) w.set(i, j, 0.0); } + } - double v = ngFullData(rowIndex, dataSetTetradMatrix, W); - - if (Double.isNaN(v)) return 10000; + List models = new ArrayList<>(); + List perms = nRooks(w); - return -(v); - }; + for (PermutationMatrixPair perm : perms) { + Matrix bHat = Ling.computeBhat(perm.getW()); +// bHat = LingUtils.normalizeDiagonal(bHat); - { - double[] values = new double[mappings.size()]; + System.out.println("perm = " + perm.getPermutation() + "\nmodel = "); - for (int k = 0; k < mappings.size(); k++) { - Mapping mapping = mappings.get(k); - values[k] = W.get(mapping.getI(), mapping.getJ()); + for (int i = 0; i < w.rows(); i++) { + System.out.println(); + for (int j = 0; j < w.columns(); j++) { + int i1 = bHat.get(i, j) == 0 ? 0 : 1; + System.out.print(i1 + " "); + } } - MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7); - - PointValuePair pair = search.optimize( - new InitialGuess(values), - new ObjectiveFunction(function), - GoalType.MINIMIZE, - new MaxEval(100000)); - - values = pair.getPoint(); + System.out.println(); - for (int k = 0; k < mappings.size(); k++) { - Mapping mapping = mappings.get(k); - W.set(mapping.getI(), mapping.getJ(), values[k]); - } + models.add(bHat.toArray()); } + return models; } - public double ngFullData(int rowIndex, Matrix data, Matrix W) { - double[] col = new double[data.rows()]; + private List nRooks(Matrix w) { + List pairs = new java.util.ArrayList<>(); - for (int i = 0; i < data.rows(); i++) { - double d = 0.0; +// pruned = pruneEdgesByResampling(dataSet.getDoubleData()); - // Node _x given parents. Its coefficient is fixed at 1. Also, coefficients for all - // other variables not neighbors of _x are fixed at zero. - for (int j = 0; j < data.columns(); j++) { - double coef = W.get(rowIndex, j); - double value = data.get(i, j); - d += coef * value; - } +// w = removeZeroRowsAndCols(w); - col[i] = d; - } + System.out.println("w = " + w); - col = removeNaN(col); + //returns all zeroless-diagonal column-pairs + boolean[][] allowablePositions = new boolean[w.rows()][w.columns()]; + for (int i = 0; i < w.rows(); i++) { + for (int j = 0; j < w.columns(); j++) { + allowablePositions[i][j] = w.get(i, j) == 0; + } + } - if (col.length == 0) { + for (int i = 0; i < w.rows(); i++) { System.out.println(); - return Double.NaN; + for (int j = 0; j < w.columns(); j++) { + System.out.print((allowablePositions[i][j] ? 0 : 1) + " "); + } } - double sum = 0; + System.out.println(); - for (double v : col) { - sum += log(cosh(v)); + List nRookAssignments = NRooks.nRooks(allowablePositions); + + //for each assignment, add the corresponding permutation to 'pairs' + for (int[] assignment : nRookAssignments) { + List _assignment = new ArrayList<>(); + for (int j : assignment) _assignment.add(j); + + Matrix _w = Ling.permuteColumns(w, _assignment); + pairs.add(new PermutationMatrixPair(_assignment, _w)); } - return sum / col.length; -// return new AndersonDarlingTest(col).getASquaredStar(); + return pairs; } - private double[] removeNaN(double[] data) { - List _leaveOutMissing = new ArrayList<>(); + private Matrix removeZeroRowsAndCols(Matrix w) { - for (double datum : data) { - if (!Double.isNaN(datum)) { - _leaveOutMissing.add(datum); - } - } - - double[] _data = new double[_leaveOutMissing.size()]; + Matrix _W = w.copy(); + List _variables = new ArrayList<>(variables); + List remove = new ArrayList<>(); - for (int i = 0; i < _leaveOutMissing.size(); i++) _data[i] = _leaveOutMissing.get(i); + ROW: + for (int i = 0; i < _W.rows(); i++) { + Vector row = _W.getRow(i); - return _data; - } + for (int j = 0; j < row.size(); j++) { + if (row.get(j) != 0) continue ROW; + } - private List mappingsForRow(int rowIndex, List allMappings) { - List mappings = new ArrayList<>(); + remove.add(i); - for (Mapping mapping : allMappings) { - if (mapping.getI() == rowIndex) mappings.add(mapping); } - return mappings; - } - private Matrix initializeW(int numNodes) { + COLUMN: + for (int i = 0; i < _W.rows(); i++) { + Vector col = _W.getColumn(i); - // Initialize W to I. - Matrix W = new Matrix(numNodes, numNodes); + for (int j = 0; j < col.size(); j++) { + if (col.get(j) != 0) continue COLUMN; + } - for (int i = 0; i < numNodes; i++) { - for (int j = 0; j < numNodes; j++) { - if (i == j) { - W.set(i, j, 1.0); - } else { - W.set(i, j, 0.0); - } + if (!remove.contains((i))) { + remove.add(i); } } - return W; - } - private List createMappings(int numNodes) { - - // Mark as parameters all non-adjacencies from the graph, excluding self edges. - List allMappings = new ArrayList<>(); + int[] rows = new int[_W.rows() - remove.size()]; - for (int i = 0; i < numNodes; i++) { - for (int j = 0; j < numNodes; j++) { - if (i == j) continue; - allMappings.add(new Mapping(i, j)); + int count = -1; + for (int k = 0; k < w.rows(); k++) { + if (remove.contains(k)) { + variables.remove(_variables.get(k)); + } else { + if (!remove.contains(k)) rows[++count] = k; } } - return allMappings; + w = w.getSelection(rows, rows); + + return w; } - private static class Mapping { - private final int i; - private final int j; + private static Matrix permuteColumns(Matrix mat, List permutation) { + Matrix permutedMat = mat.like(); - public Mapping(int i, int j) { - this.i = i; - this.j = j; + for (int j = 0; j < mat.rows(); j++) { + Vector col = mat.getColumn(j); + permutedMat.assignColumn(permutation.get(j), col); } - public int getI() { - return this.i; - } + return permutedMat; + } - public int getJ() { - return this.j; - } + private static Matrix computeBhat(Matrix W) { + int size = W.rows(); + return Matrix.identity(size).minus(W); } private Matrix getWFastIca() { - Matrix W;// Using this Fast ICA to get the logging. - Matrix data = new Matrix(this.dataSet.getDoubleData().toArray()).transpose(); - FastIca fastIca = new FastIca(data, 30); +// Matrix data = new Matrix(this.dataSet.getDoubleData().toArray()).transpose(); +// FastIca fastIca = new FastIca(data, 30); +// fastIca.setVerbose(false); +// fastIca.setAlgorithmType(FastIca.DEFLATION); +// fastIca.setFunction(FastIca.LOGCOSH); +// fastIca.setTolerance(.001); +// fastIca.setMaxIterations(5000); +// fastIca.setAlpha(1.0); +// FastIca.IcaResult result = fastIca.findComponents(); +// Matrix W = new Matrix(result.getW()); + + + Matrix X = dataSet.getDoubleData(); + X = DataUtils.centerData(X).transpose(); + FastIca fastIca = new FastIca(X, X.rows()); fastIca.setVerbose(false); - fastIca.setAlgorithmType(FastIca.DEFLATION); - fastIca.setFunction(FastIca.LOGCOSH); - fastIca.setTolerance(.01); - fastIca.setMaxIterations(1000); - fastIca.setAlpha(1.0); - FastIca.IcaResult result = fastIca.findComponents(); - W = new Matrix(result.getW()); - return W.transpose(); - } + fastIca.setMaxIterations(this.fastIcaMaxIter); + fastIca.setAlgorithmType(FastIca.PARALLEL); + fastIca.setTolerance(this.fastIcaTolerance); + fastIca.setFunction(FastIca.EXP); + fastIca.setRowNorm(false); + fastIca.setAlpha(this.fastIcaA); + FastIca.IcaResult result11 = fastIca.findComponents(); + Matrix W = result11.getW(); - /** - * Calculates the time used when processing the search method. - */ - public long getElapsedTime() { - return this.elapsedTime; - } - - /** - * Sets the value at which thresholding occurs on Fast ICA data. Default is .05. - * - * @param t The value at which the thresholding is set - */ - public void setThreshold(double t) { - this.threshold = t; + return W; } - //==============================PRIVATE METHODS====================// - /** * This is the method used in Patrik's code. */ @@ -409,7 +318,7 @@ public Matrix pruneEdgesByResampling(Matrix data) { List bpieces = new ArrayList<>(); for (int p = 0; p < npieces; p++) { - Vector Xpm = new Vector(rows); + List Xpm = new ArrayList<>(); for (int i = 0; i < rows; i++) { double sum = 0.0; @@ -437,7 +346,7 @@ public Matrix pruneEdgesByResampling(Matrix data) { } } - boolean posDef = LingUtils.isPositiveDefinite(cov); + boolean posDef = MatrixUtils.isPositiveDefinite(cov); if (!posDef) { System.out.println("Covariance matrix is not positive definite."); @@ -452,11 +361,11 @@ public Matrix pruneEdgesByResampling(Matrix data) { QRDecomposition qr = new QRDecomposition(new BlockRealMatrix(invSqrt.toArray())); RealMatrix r = qr.getR(); - Vector newestdisturbancestd = new Vector(rows); - - for (int t = 0; t < rows; t++) { - newestdisturbancestd.set(t, 1.0 / abs(r.getEntry(t, t))); - } +// List newestdisturbancestd = new ArrayList<>(rows); +// +// for (int t = 0; t < rows; t++) { +// newestdisturbancestd.set(t, 1.0 / abs(r.getEntry(t, t))); +// } for (int s = 0; s < rows; s++) { for (int t = 0; t < min(s, cols); t++) { @@ -507,476 +416,6 @@ public Matrix pruneEdgesByResampling(Matrix data) { return BFinal; } - private void makeDataSet(GraphWithParameters graphWP) { - - //define the "Gaussian-squared" distribution - Distribution gp2 = new GaussianPower(2); - - //the coefficients of the error terms (here, all 1s) - Vector errorCoefficients = Ling.getErrorCoeffsIdentity(graphWP.getGraph().getNumNodes()); - - //generate data from the SEM - Matrix inVectors = Ling.simulateCyclic(graphWP, errorCoefficients, this.numSamples, gp2); - - //reformat it - this.dataSet = new BoxDataSet(new DoubleDataBox(inVectors.transpose().toArray()), graphWP.getGraph().getNodes()); - } - - /** - * Processes the search algorithm. - * - * @param n The number of variables. - * @return StoredGraphs - */ - private static Vector getErrorCoeffsIdentity(int n) { - Vector errorCoefficients = new Vector(n); - for (int i = 0; i < n; i++) { - errorCoefficients.set(i, 1); - } - return errorCoefficients; - } - - // used to produce dataset if one is not provided as the input to the constructor - - private static Matrix simulateCyclic(GraphWithParameters dwp, Vector errorCoefficients, int n, Distribution distribution) { - Matrix reducedForm = Ling.reducedForm(dwp); - - Matrix vectors = new Matrix(dwp.getGraph().getNumNodes(), n); - for (int j = 0; j < n; j++) { - Vector vector = Ling.simulateReducedForm(reducedForm, errorCoefficients, distribution); - vectors.assignColumn(j, vector); - } - return vectors; - } - - // graph matrix is B - // mixing matrix (reduced form) is A - - private static Matrix reducedForm(GraphWithParameters graph) { - Matrix graphMatrix = new Matrix(graph.getGraphMatrix().getDoubleData().toArray()); - int n = graphMatrix.rows(); -// TetradMatrix identityMinusGraphTetradMatrix = TetradMatrixUtils.linearCombination(TetradMatrixUtils.identityTetradMatrix(n), 1, graphTetradMatrix, -1); - Matrix identityMinusGraphTetradMatrix = Matrix.identity(n).minus(graphMatrix); - return identityMinusGraphTetradMatrix.inverse(); - } - - //check against model in which: A = ..... / (1 - xyzw) - - private static Vector simulateReducedForm(Matrix reducedForm, Vector errorCoefficients, Distribution distr) { - int n = reducedForm.rows(); - Vector vector = new Vector(n); - Vector samples = new Vector(n); - - for (int j = 0; j < n; j++) { //sample from each noise term - double sample = distr.nextRandom(); - double errorCoefficient = errorCoefficients.get(j); - samples.set(j, sample * errorCoefficient); - } - - for (int i = 0; i < n; i++) { //for each observed variable, i.e. dimension - double sum = 0; - for (int j = 0; j < n; j++) { - double coefficient = reducedForm.get(i, j); - double sample = samples.get(j); - sum += coefficient * sample; - } - vector.set(i, sum); - } - return vector; - } - - //given the W matrix, outputs the list of SEMs consistent with the observed distribution. - - private StoredGraphs findCandidateModels(List variables, Matrix matrixW) { - - Matrix normalizedZldW; - List zldPerms; - - StoredGraphs gs = new StoredGraphs(); - - System.out.println("Calculating zeroless diagonal permutations..."); - - TetradLogger.getInstance().log("lingDetails", "Calculating zeroless diagonal permutations."); - zldPerms = zerolessDiagonalPermutations(matrixW, variables, this.dataSet); - - System.out.println("Calculated zeroless diagonal permutations."); - - //for each W~, compute a candidate B, and score it - for (PermutationMatrixPair zldPerm : zldPerms) { - TetradLogger.getInstance().log("lingDetails", "" + zldPerm); - System.out.println(zldPerm); - - normalizedZldW = LingUtils.normalizeDiagonal(zldPerm.getMatrixW()); - // Note: add method to deal with this data - zldPerm.setMatrixBhat(Ling.computeBhatTetradMatrix(normalizedZldW, variables)); //B~ = I - W~ - Matrix doubleData = zldPerm.getMatrixBhat().getDoubleData(); - boolean isStableTetradMatrix = Ling.allEigenvaluesAreSmallerThanOneInModulus(new Matrix(doubleData.toArray())); - GraphWithParameters graph = new GraphWithParameters(zldPerm.getMatrixBhat()); - - gs.addGraph(graph.getGraph()); - gs.addStable(isStableTetradMatrix); - gs.addData(zldPerm.getMatrixBhat()); - - } - - TetradLogger.getInstance().log("stableGraphs", "Stable Graphs:"); - - for (int d = 0; d < gs.getNumGraphs(); d++) { - if (!gs.isStable(d)) { - continue; - } - - TetradLogger.getInstance().log("stableGraphs", "" + gs.getGraph(d)); - - if (TetradLogger.getInstance().getLoggerConfig() != null && - TetradLogger.getInstance().getLoggerConfig().isEventActive("stableGraphs")) { - TetradLogger.getInstance().log("wMatrices", "" + gs.getData(d)); - } - } - - TetradLogger.getInstance().log("unstableGraphs", "Unstable Graphs:"); - - for (int d = 0; d < gs.getNumGraphs(); d++) { - if (gs.isStable(d)) { - continue; - } - - TetradLogger.getInstance().log("unstableGraphs", "" + gs.getGraph(d)); - - if (TetradLogger.getInstance().getLoggerConfig() != null && - TetradLogger.getInstance().getLoggerConfig().isEventActive("unstableGraphs")) { - TetradLogger.getInstance().log("wMatrices", "" + gs.getData(d)); - } - } - - return gs; - } - - private StoredGraphs findCandidateModel(List variables, Matrix matrixW) { - - Matrix normalizedZldW; - List zldPerms; - - StoredGraphs gs = new StoredGraphs(); - - System.out.println("Calculating zeroless diagonal permutations..."); - - TetradLogger.getInstance().log("lingDetails", "Calculating zeroless diagonal permutations."); - zldPerms = zerolessDiagonalPermutation(matrixW, variables); - - -// zldPerms = zerolessDiagonalPermutations(matrixW, approximateZeros, variables, dataSet); - - System.out.println("Calculated zeroless diagonal permutations."); - - //for each W~, compute a candidate B, and score it - for (PermutationMatrixPair zldPerm : zldPerms) { - TetradLogger.getInstance().log("lingDetails", "" + zldPerm); - System.out.println(zldPerm); - - normalizedZldW = LingUtils.normalizeDiagonal(zldPerm.getMatrixW()); - // Note: add method to deal with this data - zldPerm.setMatrixBhat(Ling.computeBhatTetradMatrix(normalizedZldW, variables)); //B~ = I - W~ - Matrix doubleData = zldPerm.getMatrixBhat().getDoubleData(); - boolean isStableTetradMatrix = Ling.allEigenvaluesAreSmallerThanOneInModulus(new Matrix(doubleData.toArray())); - GraphWithParameters graph = new GraphWithParameters(zldPerm.getMatrixBhat()); - - gs.addGraph(graph.getGraph()); - gs.addStable(isStableTetradMatrix); - gs.addData(zldPerm.getMatrixBhat()); - - } - - TetradLogger.getInstance().log("stableGraphs", "Stable Graphs:"); - - for (int d = 0; d < gs.getNumGraphs(); d++) { - if (!gs.isStable(d)) { - continue; - } - - TetradLogger.getInstance().log("stableGraphs", "" + gs.getGraph(d)); - - if (TetradLogger.getInstance().getLoggerConfig() != null && - TetradLogger.getInstance().getLoggerConfig().isEventActive("stableGraphs")) { - TetradLogger.getInstance().log("wMatrices", "" + gs.getData(d)); - } - } - - TetradLogger.getInstance().log("unstableGraphs", "Unstable Graphs:"); - - for (int d = 0; d < gs.getNumGraphs(); d++) { - if (gs.isStable(d)) { - continue; - } - - TetradLogger.getInstance().log("unstableGraphs", "" + gs.getGraph(d)); - - if (TetradLogger.getInstance().getLoggerConfig() != null && - TetradLogger.getInstance().getLoggerConfig().isEventActive("unstableGraphs")) { - TetradLogger.getInstance().log("wMatrices", "" + gs.getData(d)); - } - } - - return gs; - } - - - private List zerolessDiagonalPermutations(Matrix ica_W, List vars, - DataSet dataSet) { - - List permutations = new java.util.Vector<>(); - - pruneEdgesByResampling(dataSet.getDoubleData()); - ica_W = removeZeroRowsAndCols(ica_W, vars); - - //find assignments - Matrix mat = ica_W.transpose(); - //returns all zeroless-diagonal column-permutations - - List> nRookAssignments = Ling.nRookColumnAssignments(mat, Ling.makeAllRows(mat.rows())); - - //for each assignment, add the corresponding permutation to 'permutations' - for (List permutation : nRookAssignments) { - Matrix matrixW = Ling.permuteRows(ica_W, permutation).transpose(); - PermutationMatrixPair permTetradMatrixPair = new PermutationMatrixPair(permutation, matrixW); - permutations.add(permTetradMatrixPair); - } - - return permutations; - } - - private List zerolessDiagonalPermutation(Matrix ica_W, List vars) { - - List permutations = new java.util.Vector<>(); - - ica_W = pruneEdgesByResampling(ica_W); - ica_W = removeZeroRowsAndCols(ica_W, vars); - - List perm = new ArrayList<>(); - - for (int i = 0; i < vars.size(); i++) perm.add(i); - - Matrix matrixW = ica_W.transpose(); - - PermutationMatrixPair pair = new PermutationMatrixPair(perm, matrixW); - permutations.add(pair); - - return permutations; - } - - private Matrix removeZeroRowsAndCols(Matrix w, List variables) { - - Matrix _W = w.copy(); - List _variables = new ArrayList<>(variables); - List remove = new ArrayList<>(); - - ROW: - for (int i = 0; i < _W.rows(); i++) { - Vector row = _W.getRow(i); - - for (int j = 0; j < row.size(); j++) { - if (row.get(j) != 0) continue ROW; - } - - remove.add(i); - - } - - COLUMN: - for (int i = 0; i < _W.rows(); i++) { - Vector col = _W.getColumn(i); - - for (int j = 0; j < col.size(); j++) { - if (col.get(j) != 0) continue COLUMN; - } - - if (!remove.contains((i))) { - remove.add(i); - } - } - - int[] rows = new int[_W.rows() - remove.size()]; - - int count = -1; - for (int k = 0; k < w.rows(); k++) { - if (remove.contains(k)) { - variables.remove(_variables.get(k)); - } else { - if (!remove.contains(k)) rows[++count] = k; - } - } - - w = w.getSelection(rows, rows); - - return w; - } - - // uses the thresholding criterion - - private static List makeAllRows(int n) { - List l = new ArrayList<>(); - for (int i = 0; i < n; i++) { - l.add(i); - } - return l; - } - - private static List> nRookColumnAssignments(Matrix mat, List availableRows) { - List> concats = new ArrayList<>(); - - System.out.println("mat = " + mat); - - int n = availableRows.size(); - - for (int i = 0; i < n; i++) { - int currentRowIndex = availableRows.get(i); - - if (mat.get(currentRowIndex, 0) != 0) { - if (mat.columns() > 1) { - java.util.Vector newAvailableRows = (new java.util.Vector<>(availableRows)); - newAvailableRows.removeElement(currentRowIndex); - Matrix subMat = mat.getPart(0, mat.rows() - 1, 1, mat.columns() - 2); - List> allLater = Ling.nRookColumnAssignments(subMat, newAvailableRows); - - for (List laterPerm : allLater) { - laterPerm.add(0, currentRowIndex); - concats.add(laterPerm); - } - } else { - List l = new ArrayList<>(); - l.add(currentRowIndex); - concats.add(l); - } - } - } - - return concats; - } - - private static Matrix permuteRows(Matrix mat, List permutation) { - Matrix permutedMat = mat.like(); - - for (int j = 0; j < mat.rows(); j++) { - Vector row = mat.getRow(j); - permutedMat.assignRow(permutation.get(j), row); - } - - return permutedMat; - } - - // B^ = I - W~' - - private static DataSet computeBhatTetradMatrix(Matrix normalizedZldW, List nodes) {//, List perm) { - int size = normalizedZldW.rows(); - Matrix mat = Matrix.identity(size).minus(normalizedZldW); - return new BoxDataSet(new DoubleDataBox(mat.toArray()), nodes); - } - - private static boolean allEigenvaluesAreSmallerThanOneInModulus(Matrix mat) { - - EigenDecomposition dec = new EigenDecomposition(new BlockRealMatrix(mat.toArray())); - double[] realEigenvalues = dec.getRealEigenvalues(); - double[] imagEigenvalues = dec.getImagEigenvalues(); - - for (int i = 0; i < realEigenvalues.length; i++) { - double realEigenvalue = realEigenvalues[i]; - double imagEigenvalue = imagEigenvalues[i]; - double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); - - if (modulus >= 1.5) { - return false; - } - } - - return true; - } - - /** - * This small class is used to store graph permutations. It contains basic methods for adding and accessing graphs. - *

- * It is likely that this class will move elesewhere once the role of algorithm that produce multiple graphs is - * better defined. - */ - - public static class StoredGraphs implements GraphGroup { - - /** - * Graph permutations are stored here. - */ - private final List graphs = new ArrayList<>(); - - /** - * Store data for each graph in case the data is needed later - */ - private final List dataSet = new ArrayList<>(); - - /** - * Boolean valued vector that contains the stability information for its corresponding graph. stable = true - * means the graph has all eigenvalues with modulus < 1. - */ - private final List stable = new ArrayList<>(); - - /** - * Gets the number of graphs stored by the class. - * - * @return Returns the number of graphs stored in the class - */ - public int getNumGraphs() { - return this.graphs.size(); - } - - /** - * @param g The index of the graph to be returned - * @return Returns a Graph - */ - public Graph getGraph(int g) { - return this.graphs.get(g); - } - - /** - * @param d The index of the graph for which the DataSet is being returned - * @return Returns a DataSet - */ - public DataSet getData(int d) { - return this.dataSet.get(d); - } - - /** - * @param s The index of the graph at which to return the boolean stability information for the permutation - * @return Returns the shriknig variable value for a specific graph. - */ - public boolean isStable(int s) { - return this.stable.get(s); - } - - /** - * Gives a method for adding classes to the class. - * - * @param g The graph to add - */ - public void addGraph(Graph g) { - this.graphs.add(g); - } - - /** - * A method for adding graph data to the class. - * - * @param d The graph to add - */ - public void addData(DataSet d) { - this.dataSet.add(d); - } - - /** - * Allows for the adding of shinking information to its corresponding graph. This should be used at the same time as - * addGraph() if it is to be used. Otherwise, add a method to add data at a specific index. - * - * @param s The stability value to set for a graph. - */ - public void addStable(Boolean s) { - this.stable.add(s); - } - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java new file mode 100644 index 0000000000..72e08f5772 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -0,0 +1,88 @@ +package edu.cmu.tetrad.search; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.IllformedLocaleException; +import java.util.List; + +/** + *

Returns row positions for placing rooks for an n x n matrix with a given + * boolean[][] specification of where rooks are allowed to be placed. For + * this spec, spec[i][j] = false iff a rook can be placed there.

+ *

Had some help from ChatGPT for this but it messed up one of the methods, + * so taking some credit.

+ * + * @author josephramsey + * @author ChatGPT + */ +public class NRooks { + + /** + * Solves the N-Rooks problem for the given allowable board. + * @param allowablePositions A matrix of allowable rook positions, should be + * true iff the position is allowable. + * @return A list of row indices for where to place the rooks for each solution. + */ + public static ArrayList nRooks(boolean[][] allowablePositions) { + for (boolean[] positions : allowablePositions) { + if (positions.length != allowablePositions[0].length) { + throw new IllformedLocaleException("Expecting a square matrix."); + } + } + + int p = allowablePositions.length; + boolean[][] _allowable = new boolean[p][p]; + ArrayList solutions = new ArrayList<>(); + dfs(_allowable, allowablePositions, 0, solutions); + return solutions; + } + + public static void printSolutions(List solutions) { + System.out.println("Number of solutions: " + solutions.size()); + for (int i = 0; i < solutions.size(); i++) { + int[] solution = solutions.get(i); + System.out.println((i + 1) + ". " + Arrays.toString(solution)); + } + } + + private static void dfs(boolean[][] board, boolean[][] allowablePositions, int row, ArrayList solutions) { + if (row == board.length) { + + // Base case: all rooks have been placed + int[] solution = new int[board.length]; + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board.length; j++) { + if (board[i][j]) { + solution[i] = j; + break; + } + } + } + solutions.add(solution); + return; + } + + for (int col = 0; col < board.length; col++) { + if (isValid(board, row, col)) { + if (!allowablePositions[row][col]) continue; + board[row][col] = true; + dfs(board, allowablePositions, row+1, solutions); + board[row][col] = false; + } + } + } + + private static boolean isValid(boolean[][] board, int row, int col) { + + // check if the current position is valid + for (int i = 0; i < row; i++) { + if (board[i][col]) { + for (boolean[] booleans : board) { + if (booleans[col]) return false; + } + } + } + + return true; + } +} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index eaf7b69a8b..ccd89256b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -21,40 +21,31 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.util.Matrix; +import java.util.ArrayList; import java.util.List; public class PermutationMatrixPair { - private final Matrix matrixW; - private DataSet matrixBhat; + private final Matrix w; private final List permutation; - public PermutationMatrixPair(List permutation, Matrix matrixW) { - this.permutation = permutation; - this.matrixW = matrixW; + public PermutationMatrixPair(List permutation, Matrix w) { + this.permutation = new ArrayList<>(permutation); + this.w = w.copy(); } - public Matrix getMatrixW() { - return this.matrixW; - } - - public DataSet getMatrixBhat() { - return this.matrixBhat; - } - - public void setMatrixBhat(DataSet matrixBhat) { - this.matrixBhat = matrixBhat; + public Matrix getW() { + return this.w.copy(); } public List getPermutation() { - return this.permutation; + return new ArrayList<>(this.permutation); } public String toString() { - return "Permutation: " + this.permutation + "matrix W : " + this.matrixW; + return "Permutation: " + this.permutation + "\nmatrix W : " + this.w; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java index cfe7e1759d..a19a249197 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java @@ -28,24 +28,19 @@ * Sundry utilities for the Ling algorithm. */ public class LingUtils { - //Gustavo 7 May 2007 - // - //makes the diagonal 1, scaling the remainder of each row appropriately - //pre: 'matrix' must be square + /** + * Makes the diagonal 1, scaling the remainder of each row appropriately. + * @param matrix A square matrix + */ public static Matrix normalizeDiagonal(Matrix matrix) { Matrix resultMatrix = matrix.copy(); for (int i = 0; i < resultMatrix.rows(); i++) { - double factor = 1 / resultMatrix.get(i, i); + double factor = 1.0 / resultMatrix.get(i, i); for (int j = 0; j < resultMatrix.columns(); j++) resultMatrix.set(i, j, factor * resultMatrix.get(i, j)); } return resultMatrix; } - - public static boolean isPositiveDefinite(Matrix matrix) { - return new CholeskyDecomposition(new DenseDoubleMatrix2D(matrix.toArray())).isSymmetricPositiveDefinite(); - } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java index bcdcff7d98..1def73dc36 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java @@ -641,12 +641,22 @@ public static double[][] zeros(int rows, int cols) { @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean isPositiveDefinite(Matrix matrix) { - try { - new RectangularCholeskyDecomposition(new BlockRealMatrix(matrix.toArray())); - } catch (NonPositiveDefiniteMatrixException e) { - return false; +// try { +// new CholeskyDecomposition(new BlockRealMatrix(matrix.toArray())); +// } catch (NonPositiveDefiniteMatrixException e) { +// return false; +// } + +// return true; + + RealMatrix realMatrix = new Array2DRowRealMatrix(matrix.toArray()); + EigenDecomposition eigenDecomposition = new EigenDecomposition(realMatrix); + double[] eigenvalues = eigenDecomposition.getRealEigenvalues(); + for (double eigenvalue : eigenvalues) { + if (eigenvalue <= 0) { + return false; + } } - return true; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphGroup.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java similarity index 52% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphGroup.java rename to tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 97603593b4..5ad5b84eeb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphGroup.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -19,41 +19,55 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.graph; +package edu.cmu.tetrad.test; + +import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.RandomGraph; +import edu.cmu.tetrad.search.Ling; +import edu.cmu.tetrad.search.NRooks; +import edu.cmu.tetrad.sem.SemIm; +import edu.cmu.tetrad.sem.SemPm; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; /** - * I couldn't find a mechanism in place to manage algorithm that return - * potentially more than 1 graph. As such, this interface helps with that. - *

- * Created by IntelliJ IDEA. - * User: Mark Whitehouse - * Date: Nov 28, 2008 - * Time: 7:55:55 PM - * To change this template use File | Settings | File Templates. + * @author Joseph Ramsey */ +public class TestLing { -public interface GraphGroup { + @Test + public void test1() { + Graph g = RandomGraph.randomGraph(6, 0, 6, 100, 100, 100, false); - /** - * @return int - */ - int getNumGraphs(); + System.out.println("True graph = " + g); - /** - * Gets a graph at a specific index - * - * @param g The index of the graph to return - * @return Graph - */ - Graph getGraph(int g); + SemPm pm = new SemPm(g); + SemIm im = new SemIm(pm); + DataSet dataSet = im.simulateData(5000, false); + Ling alg = new Ling(dataSet); + alg.setThreshold(0.5); + List models = alg.search(); - /** - * Adds a graph to the class. - * - * @param g The graph to add to the class. - */ - void addGraph(Graph g); + for (double[][] model : models) { + Graph graph = Ling.getGraph(model, dataSet.getVariables()); +// boolean stable = Ling.isStable(model); +// System.out.println((stable ? "Is Stable" : "Not stable") + " cyclic = " + graph.paths().existsDirectedCycle()); + System.out.println(graph); + } + } + @Test + public void testNRooks() { + int p = 3; + boolean[][] allowableBoard = new boolean[p][p]; + for (boolean[] row : allowableBoard) Arrays.fill(row, true); + allowableBoard[0][2] = false; + List solutions = NRooks.nRooks(allowableBoard); + NRooks.printSolutions(solutions); + } } From 73d55c06560afbef02b184496ebb8cf65faef26b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 23 Apr 2023 21:00:28 -0400 Subject: [PATCH 010/464] Some work on LiNG. --- .../main/java/edu/cmu/tetrad/search/Ling.java | 26 +++++-------------- .../tetrad/search/PermutationMatrixPair.java | 4 +-- .../java/edu/cmu/tetrad/test/TestLing.java | 4 +-- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java index 5e18d9f919..c82c1cf5cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java @@ -63,7 +63,7 @@ public class Ling { private double threshold = .5; private double fastIcaA = 1.1; - private int fastIcaMaxIter = 2000; + private int fastIcaMaxIter = 5000; private double fastIcaTolerance = 1e-6; //=============================CONSTRUCTORS============================// @@ -126,10 +126,10 @@ public static boolean isStable(double[][] matrix) { for (int i = 0; i < realEigenvalues.length; i++) { double realEigenvalue = realEigenvalues[i]; -// double imagEigenvalue = imagEigenvalues[i]; - double modulus = sqrt(pow(realEigenvalue, 2) /*+ pow(imagEigenvalue, 2)*/); + double imagEigenvalue = imagEigenvalues[i]; + double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); - System.out.println("modulus" + " " + modulus); +// System.out.println("modulus" + " " + modulus); if (realEigenvalue >= 1.0) { return false; @@ -277,18 +277,6 @@ private static Matrix computeBhat(Matrix W) { } private Matrix getWFastIca() { -// Matrix data = new Matrix(this.dataSet.getDoubleData().toArray()).transpose(); -// FastIca fastIca = new FastIca(data, 30); -// fastIca.setVerbose(false); -// fastIca.setAlgorithmType(FastIca.DEFLATION); -// fastIca.setFunction(FastIca.LOGCOSH); -// fastIca.setTolerance(.001); -// fastIca.setMaxIterations(5000); -// fastIca.setAlpha(1.0); -// FastIca.IcaResult result = fastIca.findComponents(); -// Matrix W = new Matrix(result.getW()); - - Matrix X = dataSet.getDoubleData(); X = DataUtils.centerData(X).transpose(); FastIca fastIca = new FastIca(X, X.rows()); @@ -296,13 +284,11 @@ private Matrix getWFastIca() { fastIca.setMaxIterations(this.fastIcaMaxIter); fastIca.setAlgorithmType(FastIca.PARALLEL); fastIca.setTolerance(this.fastIcaTolerance); - fastIca.setFunction(FastIca.EXP); + fastIca.setFunction(FastIca.LOGCOSH); fastIca.setRowNorm(false); fastIca.setAlpha(this.fastIcaA); FastIca.IcaResult result11 = fastIca.findComponents(); - Matrix W = result11.getW(); - - return W; + return result11.getW(); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index ccd89256b9..bdd8331dca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -37,11 +37,11 @@ public PermutationMatrixPair(List permutation, Matrix w) { } public Matrix getW() { - return this.w.copy(); + return this.w; } public List getPermutation() { - return new ArrayList<>(this.permutation); + return this.permutation; } public String toString() { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 5ad5b84eeb..d5a581260b 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -53,8 +53,8 @@ public void test1() { for (double[][] model : models) { Graph graph = Ling.getGraph(model, dataSet.getVariables()); -// boolean stable = Ling.isStable(model); -// System.out.println((stable ? "Is Stable" : "Not stable") + " cyclic = " + graph.paths().existsDirectedCycle()); + boolean stable = Ling.isStable(model); + System.out.println((stable ? "Is Stable" : "Not stable") + " cyclic = " + graph.paths().existsDirectedCycle()); System.out.println(graph); } } From 47b276046e1e564d3917d2b8424b4c50d773be54 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 19:58:06 -0400 Subject: [PATCH 011/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- .../algorithm/continuous/dag/Lingam.java | 9 +- .../java/edu/cmu/tetrad/search/FastIca.java | 11 +- .../main/java/edu/cmu/tetrad/search/Ling.java | 408 ------------------ .../java/edu/cmu/tetrad/search/LingD.java | 182 ++++++++ .../java/edu/cmu/tetrad/search/Lingam.java | 172 ++++---- .../tetrad/search/PermutationMatrixPair.java | 43 +- .../java/edu/cmu/tetrad/util/LingUtils.java | 47 -- .../java/edu/cmu/tetrad/test/TestLing.java | 90 +++- 8 files changed, 392 insertions(+), 570 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index b833bd95cb..2513925618 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -9,6 +9,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -35,12 +36,10 @@ public class Lingam implements Algorithm { public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { + DataSet data = SimpleDataLoader.getContinuousDataSet(dataSet); + Matrix W = edu.cmu.tetrad.search.Lingam.estimateW(data, 5000, 1e-6, 1.2); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - lingam.setFastIcaA(parameters.getDouble(Params.FAST_ICA_A)); - lingam.setFastMaxIter(parameters.getInt(Params.FAST_ICA_MAX_ITER)); - lingam.setFastIcaTolerance(parameters.getDouble(Params.FAST_ICA_TOLERANCE)); - return lingam.search(SimpleDataLoader.getContinuousDataSet(dataSet)); + return lingam.search(W, data.getVariables()); } else { Lingam algorithm = new Lingam(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index bfc36c7033..7a64f4a5e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -29,8 +29,7 @@ import org.apache.commons.math3.linear.SingularValueDecomposition; import org.apache.commons.math3.util.FastMath; -import static org.apache.commons.math3.util.FastMath.exp; -import static org.apache.commons.math3.util.FastMath.tanh; +import static org.apache.commons.math3.util.FastMath.*; /** * A Java implementation of FastIca following the R package fastICA. The only @@ -299,8 +298,8 @@ public void setAlpha(double alpha) { * A logical value indicating whether rows of the data matrix 'X' should be * standardized beforehand. */ - public void setRowNorm(boolean colNorm) { - this.rowNorm = colNorm; + public void setRowNorm(boolean rowNorm) { + this.rowNorm = rowNorm; } /** @@ -551,7 +550,7 @@ private Matrix icaDeflation(Matrix X, _tolerance += w1.get(k) * w.get(k); } - _tolerance = FastMath.abs(FastMath.abs(_tolerance) - 1.0); + _tolerance = abs(abs(_tolerance) - 1.0); if (verbose) { TetradLogger.getInstance().log("fastIcaDetails", "Iteration " + it + " tol = " + _tolerance); @@ -671,7 +670,7 @@ private Matrix icaParallel(Matrix X, int numComponents, _tolerance = Double.NEGATIVE_INFINITY; for (int i = 0; i < d.size(); i++) { - double m = FastMath.abs(FastMath.abs(d.get(i)) - 1); + double m = abs(abs(d.get(i)) - 1); if (m > _tolerance) _tolerance = m; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java deleted file mode 100644 index c82c1cf5cd..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ling.java +++ /dev/null @@ -1,408 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.*; -import org.apache.commons.math3.linear.BlockRealMatrix; -import org.apache.commons.math3.linear.EigenDecomposition; -import org.apache.commons.math3.linear.QRDecomposition; -import org.apache.commons.math3.linear.RealMatrix; - -import java.util.ArrayList; -import java.util.List; - -import static org.apache.commons.math3.util.FastMath.*; - -/** - * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering cyclic causal models - * by independent components analysis. arXiv preprint arXiv:1206.3273. - * - * @author lacerda - * @author josephramsey - */ -public class Ling { - - /** - * The dataset being used for search. - */ - private final DataSet dataSet; - - /** - * The variables in the dataset. - */ - private final List variables; - - /** - * This algorithm uses thresholding to zero out small covariance values. This variable defines the value at which - * the thresholding occurs. - */ - private double threshold = .5; - - private double fastIcaA = 1.1; - private int fastIcaMaxIter = 5000; - private double fastIcaTolerance = 1e-6; - - //=============================CONSTRUCTORS============================// - - /** - * The algorithm only requires a DataSet to process. Passing in a Dataset and then running the search algorithm is - * an effetive way to use LiNG. - * - * @param dataSet a DataSet over which the algorithm can process - */ - public Ling(DataSet dataSet) { - this.dataSet = dataSet; - this.variables = dataSet.getVariables(); - } - - //==============================PUBLIC METHODS=========================// - - /** - * @return DataSet Returns a dataset of the data used by the algorithm. - */ - public DataSet getData() { - return this.dataSet; - } - - /** - * The search method is used to process LiNG. Call search when you want to run the algorithm. - */ - public List search() { - Matrix w = getWFastIca(); - return findCandidateModels(w); - } - - /** - * Sets the value at which thresholding occurs on Fast ICA data. Default is .05. - * - * @param t The value at which the thresholding is set - */ - public void setThreshold(double t) { - this.threshold = t; - } - - public static Graph getGraph(double[][] b, List variables) { - Graph graph = new EdgeListGraph(variables); - - for (int i = 0; i < variables.size(); i++) { - for (int j = 0; j < variables.size(); j++) { - if (i != j && b[j][i] != 0) { - graph.addDirectedEdge(variables.get(j), variables.get(i)); - } - } - } - - return graph; - } - - public static boolean isStable(double[][] matrix) { - EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(matrix)); - double[] realEigenvalues = eigen.getRealEigenvalues(); - double[] imagEigenvalues = eigen.getImagEigenvalues(); - - for (int i = 0; i < realEigenvalues.length; i++) { - double realEigenvalue = realEigenvalues[i]; - double imagEigenvalue = imagEigenvalues[i]; - double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); - -// System.out.println("modulus" + " " + modulus); - - if (realEigenvalue >= 1.0) { - return false; - } - } - - return true; - } - - //==============================PRIVATE METHODS====================// - - private List findCandidateModels(Matrix w) { - for (int i = 0; i < w.rows(); i++) { - for (int j = 0; j < w.columns(); j++) { - if (abs(w.get(i, j)) < threshold) w.set(i, j, 0.0); - } - } - - List models = new ArrayList<>(); - List perms = nRooks(w); - - for (PermutationMatrixPair perm : perms) { - Matrix bHat = Ling.computeBhat(perm.getW()); -// bHat = LingUtils.normalizeDiagonal(bHat); - - System.out.println("perm = " + perm.getPermutation() + "\nmodel = "); - - for (int i = 0; i < w.rows(); i++) { - System.out.println(); - for (int j = 0; j < w.columns(); j++) { - int i1 = bHat.get(i, j) == 0 ? 0 : 1; - System.out.print(i1 + " "); - } - } - - System.out.println(); - - models.add(bHat.toArray()); - } - - return models; - } - - private List nRooks(Matrix w) { - List pairs = new java.util.ArrayList<>(); - -// pruned = pruneEdgesByResampling(dataSet.getDoubleData()); - -// w = removeZeroRowsAndCols(w); - - System.out.println("w = " + w); - - //returns all zeroless-diagonal column-pairs - boolean[][] allowablePositions = new boolean[w.rows()][w.columns()]; - for (int i = 0; i < w.rows(); i++) { - for (int j = 0; j < w.columns(); j++) { - allowablePositions[i][j] = w.get(i, j) == 0; - } - } - - for (int i = 0; i < w.rows(); i++) { - System.out.println(); - for (int j = 0; j < w.columns(); j++) { - System.out.print((allowablePositions[i][j] ? 0 : 1) + " "); - } - } - - System.out.println(); - - List nRookAssignments = NRooks.nRooks(allowablePositions); - - //for each assignment, add the corresponding permutation to 'pairs' - for (int[] assignment : nRookAssignments) { - List _assignment = new ArrayList<>(); - for (int j : assignment) _assignment.add(j); - - Matrix _w = Ling.permuteColumns(w, _assignment); - pairs.add(new PermutationMatrixPair(_assignment, _w)); - } - - return pairs; - } - - private Matrix removeZeroRowsAndCols(Matrix w) { - - Matrix _W = w.copy(); - List _variables = new ArrayList<>(variables); - List remove = new ArrayList<>(); - - ROW: - for (int i = 0; i < _W.rows(); i++) { - Vector row = _W.getRow(i); - - for (int j = 0; j < row.size(); j++) { - if (row.get(j) != 0) continue ROW; - } - - remove.add(i); - - } - - COLUMN: - for (int i = 0; i < _W.rows(); i++) { - Vector col = _W.getColumn(i); - - for (int j = 0; j < col.size(); j++) { - if (col.get(j) != 0) continue COLUMN; - } - - if (!remove.contains((i))) { - remove.add(i); - } - } - - int[] rows = new int[_W.rows() - remove.size()]; - - int count = -1; - for (int k = 0; k < w.rows(); k++) { - if (remove.contains(k)) { - variables.remove(_variables.get(k)); - } else { - if (!remove.contains(k)) rows[++count] = k; - } - } - - w = w.getSelection(rows, rows); - - return w; - } - - private static Matrix permuteColumns(Matrix mat, List permutation) { - Matrix permutedMat = mat.like(); - - for (int j = 0; j < mat.rows(); j++) { - Vector col = mat.getColumn(j); - permutedMat.assignColumn(permutation.get(j), col); - } - - return permutedMat; - } - - private static Matrix computeBhat(Matrix W) { - int size = W.rows(); - return Matrix.identity(size).minus(W); - } - - private Matrix getWFastIca() { - Matrix X = dataSet.getDoubleData(); - X = DataUtils.centerData(X).transpose(); - FastIca fastIca = new FastIca(X, X.rows()); - fastIca.setVerbose(false); - fastIca.setMaxIterations(this.fastIcaMaxIter); - fastIca.setAlgorithmType(FastIca.PARALLEL); - fastIca.setTolerance(this.fastIcaTolerance); - fastIca.setFunction(FastIca.LOGCOSH); - fastIca.setRowNorm(false); - fastIca.setAlpha(this.fastIcaA); - FastIca.IcaResult result11 = fastIca.findComponents(); - return result11.getW(); - } - - /** - * This is the method used in Patrik's code. - */ - public Matrix pruneEdgesByResampling(Matrix data) { - Matrix X = new Matrix(data.transpose().toArray()); - - final int npieces = 10; - int cols = X.columns(); - int rows = X.rows(); - - List bpieces = new ArrayList<>(); - - for (int p = 0; p < npieces; p++) { - List Xpm = new ArrayList<>(); - - for (int i = 0; i < rows; i++) { - double sum = 0.0; - - for (int j = 0; j < X.columns(); j++) { - sum += X.get(i, j); - } - - Xpm.set(i, sum / X.columns()); - } - - for (int i = 0; i < rows; i++) { - for (int j = 0; j < X.columns(); j++) { - X.set(i, j, X.get(i, j) - Xpm.get(i)); - } - } - - Matrix Xpt = X.transpose(); - - Matrix cov = X.times(Xpt); - - for (int i = 0; i < cov.rows(); i++) { - for (int j = 0; j < cov.columns(); j++) { - cov.set(i, j, cov.get(i, j) / X.columns()); - } - } - - boolean posDef = MatrixUtils.isPositiveDefinite(cov); - - if (!posDef) { - System.out.println("Covariance matrix is not positive definite."); - } - - Matrix sqrt = cov.sqrt(); - - Matrix I = Matrix.identity(rows); - I.copy(); - Matrix invSqrt = sqrt.inverse(); - - QRDecomposition qr = new QRDecomposition(new BlockRealMatrix(invSqrt.toArray())); - RealMatrix r = qr.getR(); - -// List newestdisturbancestd = new ArrayList<>(rows); -// -// for (int t = 0; t < rows; t++) { -// newestdisturbancestd.set(t, 1.0 / abs(r.getEntry(t, t))); -// } - - for (int s = 0; s < rows; s++) { - for (int t = 0; t < min(s, cols); t++) { - r.setEntry(s, t, r.getEntry(s, t) / r.getEntry(s, s)); - } - } - - Matrix bnewest = Matrix.identity(rows); - bnewest = bnewest.minus(new Matrix(r.getData())); - - bpieces.add(bnewest); - } - - Matrix means = new Matrix(rows, rows); - Matrix stds = new Matrix(rows, rows); - - Matrix BFinal = new Matrix(rows, rows); - - for (int i = 0; i < rows; i++) { - for (int j = 0; j < rows; j++) { - double sum = 0.0; - - for (int y = 0; y < npieces; y++) { - sum += bpieces.get(y).get(i, j); - } - - double themean = sum / (npieces); - - double sumVar = 0.0; - - for (int y = 0; y < npieces; y++) { - sumVar += pow((bpieces.get(y).get(i, j)) - themean, 2); - } - - double thestd = sqrt(sumVar / (npieces)); - - means.set(i, j, themean); - stds.set(i, j, thestd); - - if (abs(themean) < this.threshold * thestd) {// getPruneFactor() * thestd) { - BFinal.set(i, j, 0); - } else { - BFinal.set(i, j, themean); - } - } - } - - return BFinal; - } - - -} - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java new file mode 100644 index 0000000000..8ccc310923 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -0,0 +1,182 @@ +/////////////////////////////////////////////////////////////////////////////// +// For information as to what this class does, see the Javadoc, below. // +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // +// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // +// Scheines, Joseph Ramsey, and Clark Glymour. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +/////////////////////////////////////////////////////////////////////////////// + +package edu.cmu.tetrad.search; + +import edu.cmu.tetrad.graph.EdgeListGraph; +import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.util.Matrix; +import org.apache.commons.math3.linear.BlockRealMatrix; +import org.apache.commons.math3.linear.EigenDecomposition; + +import java.util.ArrayList; +import java.util.List; + +import static org.apache.commons.math3.util.FastMath.pow; +import static org.apache.commons.math3.util.FastMath.sqrt; + +/** + * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering cyclic causal models + * by independent components analysis. arXiv preprint arXiv:1206.3273. + * + * @author lacerda + * @author josephramsey + */ +public class LingD { + + private double wThreshold = .5; + + //=============================CONSTRUCTORS============================// + + /** + * The algorithm only requires a DataSet to process. Passing in a Dataset and then running the search algorithm is + * an effetive way to use LiNG. + */ + public LingD() { + } + + //==============================PUBLIC METHODS=========================// + + /** + * Searches given the W matrix from ICA. + * + * @param W the W matrix from ICA + * @return the LiNGAM graph. + */ + public List search(Matrix W) { + return nRooks(Lingam.threshold(W, wThreshold)); + } + + /** + * Sets the value at which thresholding occurs for the W matrix. + * @param wThreshold The value at which the thresholding is set. + */ + public void setWThreshold(double wThreshold) { + this.wThreshold = wThreshold; + } + + public static Matrix getBHat(PermutationMatrixPair pair) { + Matrix _w = pair.getPermutedMatrix(); + Matrix bHat = Matrix.identity(_w.rows()).minus(_w); + return Lingam.scale(bHat); + } + + public static Graph getGraph(PermutationMatrixPair pair, List variables) { + int[] perm = pair.getColPerm(); + + List permVars = new ArrayList<>(); + + for (int i = 0; i < variables.size(); i++) { + permVars.add(variables.get(perm[i])); + } + + return getGraph(getBHat(pair), permVars); + } + + /** + * Whether the BHat matrix represents a stable model. The eigenvalues are checked ot make sure they are + * all less than 1. + * @param pair The permutation pair. + * @return True iff the model is stable. + */ + public static boolean isStable(PermutationMatrixPair pair) { + EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(getBHat(pair).toArray())); + double[] realEigenvalues = eigen.getRealEigenvalues(); + double[] imagEigenvalues = eigen.getImagEigenvalues(); + + for (int i = 0; i < realEigenvalues.length; i++) { + double realEigenvalue = realEigenvalues[i]; + double imagEigenvalue = imagEigenvalues[i]; + double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); + + System.out.println("modulus" + " " + modulus); + + if (modulus >= 1.0) { + return false; + } + } + + return true; + } + + //==============================PRIVATE METHODS=========================// + + private List nRooks(Matrix W) { + List pairs = new java.util.ArrayList<>(); + + System.out.println("Listing permutation pairs, W = " + W); + + //returns all zeroless-diagonal column-pairs + boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; + + for (int i = 0; i < W.rows(); i++) { + for (int j = 0; j < W.columns(); j++) { + allowablePositions[i][j] = W.get(i, j) != 0; + } + } + + System.out.println("\nAllowable rook positions"); + + // Print allowable board. + for (int i = 0; i < W.rows(); i++) { + System.out.println(); + for (int j = 0; j < W.columns(); j++) { + System.out.print((allowablePositions[i][j] ? 1 : 0) + " "); + } + } + + System.out.println(); + System.out.println(); + + List colPermutations = NRooks.nRooks(allowablePositions); + + //for each assignment, add the corresponding permutation to 'pairs' + for (int[] colPermutation : colPermutations) { + pairs.add(new PermutationMatrixPair(null, colPermutation, W)); + } + + return pairs; + } + + + /** + * Returns the graph for the givem model. + * @param bHat The B Hat for the model. + * @param variables The variables for the model. + * @return The graph. + */ + private static Graph getGraph(Matrix bHat, List variables) { + Graph graph = new EdgeListGraph(variables); + + for (int i = 0; i < variables.size(); i++) { + for (int j = 0; j < variables.size(); j++) { + if (i != j && bHat.get(j, i) != 0) { + graph.addDirectedEdge(variables.get(i), variables.get(j)); + } + } + } + + return graph; + } +} + + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 119c138223..d95b648f0a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -21,34 +21,28 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.CovarianceMatrix; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.Knowledge; +import edu.cmu.tetrad.data.*; +import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.PermutationGenerator; +import org.apache.commons.math3.util.FastMath; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static java.lang.StrictMath.abs; /** - * Implements the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, and Kerminen, A linear nongaussian acyclic model for - * causal discovery, JMLR 7 (2006). Largely follows the Matlab code. - *

- * We use FGES with knowledge of causal order for the pruning step. + *

Implements the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, and Kerminen, A linear + * nongaussian acyclic model for causal discovery, JMLR 7 (2006).

* * @author Joseph Ramsey */ public class Lingam { - private double penaltyDiscount = 2; - private double fastIcaA = 1.1; - private int fastIcaMaxIter = 2000; - private double fastIcaTolerance = 1e-6; -// private double pruneFactor = 1; + private double pruneFactor = 0.5; //================================CONSTRUCTORS==========================// @@ -58,68 +52,61 @@ public class Lingam { public Lingam() { } - public Graph search(DataSet data) { - 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."); - } - } - } - - + /** + * Estimates the W matrix using FastICA. + * @param data The dataset to estimate W for. + * @param fastIcaMaxIter Maximum number of iterations of ICA. + * @param fastIcaTolerance Tolerance for ICA. + * @param fastIcaA Alpha for ICA. + * @return The estimated W matrix. + */ + public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, double fastIcaA) { Matrix X = data.getDoubleData(); X = DataUtils.centerData(X).transpose(); FastIca fastIca = new FastIca(X, X.rows()); fastIca.setVerbose(false); - fastIca.setMaxIterations(this.fastIcaMaxIter); - fastIca.setAlgorithmType(FastIca.PARALLEL); - fastIca.setTolerance(this.fastIcaTolerance); + fastIca.setMaxIterations(fastIcaMaxIter); + fastIca.setAlgorithmType(FastIca.DEFLATION); + fastIca.setTolerance(fastIcaTolerance); fastIca.setFunction(FastIca.EXP); fastIca.setRowNorm(false); - fastIca.setAlpha(this.fastIcaA); + fastIca.setAlpha(fastIcaA); FastIca.IcaResult result11 = fastIca.findComponents(); - Matrix W = result11.getW(); + return result11.getW(); + } - PermutationGenerator gen1 = new PermutationGenerator(W.columns()); - int[] perm1 = new int[0]; - double sum1 = Double.NEGATIVE_INFINITY; + /** + * Searches given the W matrix from ICA. + * @param W the W matrix from ICA. + * @return The graph returned. + */ + public Graph search(Matrix W, List variables) { + PermutationGenerator gen1 = new PermutationGenerator(W.rows()); + int[] rowPerm = new int[0]; + double sum1 = Double.POSITIVE_INFINITY; int[] choice1; while ((choice1 = gen1.next()) != null) { double sum = 0.0; - for (int i = 0; i < W.columns(); i++) { - double wii = W.get(choice1[i], i); - sum += abs(wii); + for (int j = 0; j < W.rows(); j++) { + sum += 1.0 / abs(W.get(choice1[j], j)); } - if (sum > sum1) { + if (sum < sum1) { sum1 = sum; - perm1 = Arrays.copyOf(choice1, choice1.length); + rowPerm = Arrays.copyOf(choice1, choice1.length); } } - int[] cols = new int[W.columns()]; - for (int i = 0; i < cols.length; i++) cols[i] = i; - - Matrix WTilde = W.getSelection(perm1, cols); - - Matrix WPrime = WTilde.copy(); + Matrix perm1W = new PermutationMatrixPair(rowPerm, null, W).getPermutedMatrix(); + perm1W = scale(perm1W); - for (int i = 0; i < WPrime.rows(); i++) { - for (int j = 0; j < WPrime.columns(); j++) { - WPrime.assignRow(i, WTilde.getRow(i).scalarMult(1.0 / WTilde.get(i, i))); - } - } - -// System.out.println("WPrime = " + WPrime); - - int m = data.getNumColumns(); - Matrix BHat = Matrix.identity(m).minus(WPrime); + int m = W.columns(); + Matrix BHat = Matrix.identity(m).minus(perm1W); PermutationGenerator gen2 = new PermutationGenerator(BHat.rows()); - int[] perm2 = new int[0]; + int[] perm = new int[0]; double sum2 = Double.NEGATIVE_INFINITY; int[] choice2; @@ -128,53 +115,80 @@ public Graph search(DataSet data) { for (int i = 0; i < W.rows(); i++) { for (int j = 0; j < i; j++) { - double c = BHat.get(choice2[i], choice2[j]); - sum += abs(c); + double b = BHat.get(choice2[i], choice2[j]); + sum += b * b; } } if (sum > sum2) { sum2 = sum; - perm2 = Arrays.copyOf(choice2, choice2.length); + perm = Arrays.copyOf(choice2, choice2.length); } } - SemBicScore score = new SemBicScore(new CovarianceMatrix(data)); - score.setPenaltyDiscount(this.penaltyDiscount); - Fges fges = new Fges(score); + Matrix permBHat = new PermutationMatrixPair(perm, perm, BHat).getPermutedMatrix(); - Knowledge knowledge = new Knowledge(); - List variables = data.getVariables(); + List varPerm = new ArrayList<>(); + for (int k : perm) varPerm.add(variables.get(k)); - for (int i = 0; i < variables.size(); i++) { - knowledge.addToTier(i, variables.get(perm2[i]).getName()); - } + Graph g = new EdgeListGraph(varPerm); - fges.setKnowledge(knowledge); + for (int j = 0; j < permBHat.columns(); j++) { + for (int i = j + 1; i < permBHat.rows(); i++) { + if (abs(permBHat.get(i, j)) > pruneFactor) { + g.addDirectedEdge(varPerm.get(j), varPerm.get(i)); + } - Graph graph = fges.search(); - System.out.println("graph Returning this graph: " + graph); + } + } - return graph; + return g; } - //================================PUBLIC METHODS========================// + /** + * Scares the given matrix M by diving each entry (i, j) by M(j, j) + * @param M The matrix to scale. + * @return The scaled matrix. + */ + public static Matrix scale(Matrix M) { + Matrix _M = M.like(); - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } + for (int i = 0; i < _M.rows(); i++) { + for (int j = 0; j < _M.columns(); j++) { + _M.set(i, j, M.get(i, j) / M.get(j, j)); + } + } - public void setFastIcaA(double fastIcaA) { - this.fastIcaA = fastIcaA; + return _M; } - public void setFastMaxIter(int maxIter) { - this.fastIcaMaxIter = maxIter; - } + /** + * Thresholds the givem matrix, sending any small entries to zero. + * @param M The matrix to threshold. + * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. + * @return The thresholded matrix. + */ + public static Matrix threshold(Matrix M, double threshold) { + if (threshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + threshold); + + Matrix _M = M.copy(); + + for (int i = 0; i < M.rows(); i++) { + for (int j = 0; j < M.columns(); j++) { + if (FastMath.abs(M.get(i, j)) < threshold) _M.set(i, j, 0.0); + } + } - public void setFastIcaTolerance(double tolerance) { - this.fastIcaTolerance = tolerance; + return _M; } + /** + * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. + * @param pruneFactor Some value >= 0. + */ + public void setPruneFactor(double pruneFactor) { + if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); + this.pruneFactor = pruneFactor; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index bdd8331dca..a0b3a82c9b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -23,29 +23,50 @@ import edu.cmu.tetrad.util.Matrix; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; public class PermutationMatrixPair { + private final int[] rowPerm; + private final int[] colPerm; private final Matrix w; - private final List permutation; - public PermutationMatrixPair(List permutation, Matrix w) { - this.permutation = new ArrayList<>(permutation); - this.w = w.copy(); + public PermutationMatrixPair(int[] rowPerm, int[] colPerm, Matrix w) { + if (rowPerm == null) { + rowPerm = new int[w.rows()]; + for (int i = 0; i < w.rows(); i++) rowPerm[i] = i; + } + + if (colPerm == null) { + colPerm = new int[w.columns()]; + for (int i = 0; i < w.columns(); i++) colPerm[i] = i; + } + + this.rowPerm = Arrays.copyOf(rowPerm, rowPerm.length); + this.colPerm = Arrays.copyOf(colPerm, colPerm.length); + this.w = w.getSelection(rowPerm, colPerm); } - public Matrix getW() { + /** + * Returns W, permuted rowwise by the permutation passed in throught he constructor. + * @return The row-permuted W. + */ + public Matrix getPermutedMatrix() { return this.w; } - public List getPermutation() { - return this.permutation; + public String toString() { + return "Row perm " + Arrays.toString(this.rowPerm) + + "\nCol perm = " + Arrays.toString(this.colPerm) + + "\nmatrix W : " + this.w; + } + + public int[] getRowPerm() { + return Arrays.copyOf(rowPerm, rowPerm.length); } - public String toString() { - return "Permutation: " + this.permutation + "\nmatrix W : " + this.w; + public int[] getColPerm() { + return Arrays.copyOf(colPerm, colPerm.length); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java deleted file mode 100644 index a19a249197..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LingUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.util; - -import cern.colt.matrix.impl.DenseDoubleMatrix2D; -import cern.colt.matrix.linalg.CholeskyDecomposition; - -/** - * Sundry utilities for the Ling algorithm. - */ -public class LingUtils { - /** - * Makes the diagonal 1, scaling the remainder of each row appropriately. - * @param matrix A square matrix - */ - public static Matrix normalizeDiagonal(Matrix matrix) { - Matrix resultMatrix = matrix.copy(); - for (int i = 0; i < resultMatrix.rows(); i++) { - double factor = 1.0 / resultMatrix.get(i, i); - for (int j = 0; j < resultMatrix.columns(); j++) - resultMatrix.set(i, j, factor * resultMatrix.get(i, j)); - } - return resultMatrix; - } -} - - - diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index d5a581260b..3fbb3d6cb8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -21,13 +21,18 @@ package edu.cmu.tetrad.test; +import edu.cmu.tetrad.algcomparison.graph.RandomForward; +import edu.cmu.tetrad.algcomparison.simulation.SemSimulation; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.Ling; +import edu.cmu.tetrad.search.LingD; +import edu.cmu.tetrad.search.Lingam; import edu.cmu.tetrad.search.NRooks; -import edu.cmu.tetrad.sem.SemIm; -import edu.cmu.tetrad.sem.SemPm; +import edu.cmu.tetrad.search.PermutationMatrixPair; +import edu.cmu.tetrad.util.Matrix; +import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetrad.util.Params; +import edu.cmu.tetrad.util.RandomUtil; import org.junit.Test; import java.util.Arrays; @@ -40,20 +45,54 @@ public class TestLing { @Test public void test1() { - Graph g = RandomGraph.randomGraph(6, 0, 6, 100, 100, 100, false); + long seed = 402030204L; + RandomUtil.getInstance().setSeed(seed); + System.out.println("Seed = " + seed + "L"); + System.out.println(); + Parameters parameters = new Parameters(); + parameters.set(Params.NUM_MEASURES, 6); + parameters.set(Params.AVG_DEGREE, 2); + parameters.set(Params.SIMULATION_ERROR_TYPE, 3); + parameters.set(Params.SIMULATION_PARAM1, 1); +// parameters.set(Params.SIMULATION_PARAM2, 1); + parameters.set(Params.PENALTY_DISCOUNT, 1); + + SemSimulation sim = new SemSimulation(new RandomForward()); + sim.createData(parameters, true); + DataSet dataSet = (DataSet) sim.getDataModel(0); + Graph g = sim.getTrueGraph(0); System.out.println("True graph = " + g); - SemPm pm = new SemPm(g); - SemIm im = new SemIm(pm); - DataSet dataSet = im.simulateData(5000, false); - Ling alg = new Ling(dataSet); - alg.setThreshold(0.5); - List models = alg.search(); + Matrix W = Lingam.estimateW(dataSet, 5000, 1e-6, 1.2); + + System.out.println("W = " + W); + + System.out.println("LiNGAM"); + + double pruneFactor = 0.3; + + System.out.println("Prune factor = " + pruneFactor); + + Lingam lingam = new Lingam(); + lingam.setPruneFactor(pruneFactor); + Graph g2 = lingam.search(W, dataSet.getVariables()); + System.out.println("Lingam graph = " + g2); - for (double[][] model : models) { - Graph graph = Ling.getGraph(model, dataSet.getVariables()); - boolean stable = Ling.isStable(model); + System.out.println("LiNG-D"); + + double wThreshold = 0.5; + System.out.println("wThreshold = " + wThreshold); + + LingD ling = new LingD(); + ling.setWThreshold(wThreshold); + List pairs = ling.search(W); + + for (PermutationMatrixPair pair : pairs) { + System.out.println("Model = " + LingD.getBHat(pair)); + + Graph graph = LingD.getGraph(pair, dataSet.getVariables()); + boolean stable = LingD.isStable(pair); System.out.println((stable ? "Is Stable" : "Not stable") + " cyclic = " + graph.paths().existsDirectedCycle()); System.out.println(graph); } @@ -68,6 +107,29 @@ public void testNRooks() { List solutions = NRooks.nRooks(allowableBoard); NRooks.printSolutions(solutions); } + + @Test + public void testNRooks2() { + int p = 3; + boolean[][] allowableBoard = new boolean[p][p]; + for (boolean[] row : allowableBoard) Arrays.fill(row, true); + allowableBoard[0][0] = false; +// allowableBoard[1][0] = false; +// allowableBoard[2][0] = false; + + + for (int i = 0; i < allowableBoard.length; i++) { + System.out.println(); + for (int j = 0; j < allowableBoard[0].length; j++) { + System.out.print((allowableBoard[i][j] ? 1 : 0) + " "); + } + } + + System.out.println(); + + List solutions = NRooks.nRooks(allowableBoard); + NRooks.printSolutions(solutions); + } } From 9cddb6dd83fddfc1fbeb863dafa2b715bead4e6a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 19:58:56 -0400 Subject: [PATCH 012/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- .../main/java/edu/cmu/tetrad/search/Lingam.java | 16 +++++++++++----- .../test/java/edu/cmu/tetrad/test/TestLing.java | 7 ++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index d95b648f0a..da73ba9c55 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -21,7 +21,8 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.*; +import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; @@ -54,10 +55,11 @@ public Lingam() { /** * Estimates the W matrix using FastICA. - * @param data The dataset to estimate W for. - * @param fastIcaMaxIter Maximum number of iterations of ICA. + * + * @param data The dataset to estimate W for. + * @param fastIcaMaxIter Maximum number of iterations of ICA. * @param fastIcaTolerance Tolerance for ICA. - * @param fastIcaA Alpha for ICA. + * @param fastIcaA Alpha for ICA. * @return The estimated W matrix. */ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, double fastIcaA) { @@ -77,6 +79,7 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT /** * Searches given the W matrix from ICA. + * * @param W the W matrix from ICA. * @return The graph returned. */ @@ -147,6 +150,7 @@ public Graph search(Matrix W, List variables) { /** * Scares the given matrix M by diving each entry (i, j) by M(j, j) + * * @param M The matrix to scale. * @return The scaled matrix. */ @@ -164,7 +168,8 @@ public static Matrix scale(Matrix M) { /** * Thresholds the givem matrix, sending any small entries to zero. - * @param M The matrix to threshold. + * + * @param M The matrix to threshold. * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. * @return The thresholded matrix. */ @@ -184,6 +189,7 @@ public static Matrix threshold(Matrix M, double threshold) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. + * * @param pruneFactor Some value >= 0. */ public void setPruneFactor(double pruneFactor) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 3fbb3d6cb8..0eba65e7bc 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -114,14 +114,11 @@ public void testNRooks2() { boolean[][] allowableBoard = new boolean[p][p]; for (boolean[] row : allowableBoard) Arrays.fill(row, true); allowableBoard[0][0] = false; -// allowableBoard[1][0] = false; -// allowableBoard[2][0] = false; - - for (int i = 0; i < allowableBoard.length; i++) { + for (boolean[] booleans : allowableBoard) { System.out.println(); for (int j = 0; j < allowableBoard[0].length; j++) { - System.out.print((allowableBoard[i][j] ? 1 : 0) + " "); + System.out.print((booleans[j] ? 1 : 0) + " "); } } From b43e8364c47587a7a3118fdfb8ec029d5d48bbfd Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 20:01:22 -0400 Subject: [PATCH 013/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 72e08f5772..d234e23502 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -37,6 +37,10 @@ public static ArrayList nRooks(boolean[][] allowablePositions) { return solutions; } + /** + * Prints the discovered N Rooks solutions. + * @param solutions The solutions. + */ public static void printSolutions(List solutions) { System.out.println("Number of solutions: " + solutions.size()); for (int i = 0; i < solutions.size(); i++) { From 5c5b5fbbf476be79730a0d8e5d587df27378c86a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 20:04:17 -0400 Subject: [PATCH 014/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index d234e23502..ba7659492e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -6,9 +6,10 @@ import java.util.List; /** - *

Returns row positions for placing rooks for an n x n matrix with a given - * boolean[][] specification of where rooks are allowed to be placed. For - * this spec, spec[i][j] = false iff a rook can be placed there.

+ *

Returns row positions for placing rooks for an n x n matrix so the rooks + * cannot attach each other, with a given boolean[][] specification of where rooks + * are allowed to be placed. For this spec, spec[i][j] = true iff a rook can be + * placed there.

*

Had some help from ChatGPT for this but it messed up one of the methods, * so taking some credit.

* From e03a6b229a39537fc6e1f470e3d51f332a32bc82 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 20:14:43 -0400 Subject: [PATCH 015/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 0eba65e7bc..d918860305 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -53,7 +53,7 @@ public void test1() { Parameters parameters = new Parameters(); parameters.set(Params.NUM_MEASURES, 6); parameters.set(Params.AVG_DEGREE, 2); - parameters.set(Params.SIMULATION_ERROR_TYPE, 3); + parameters.set(Params.SIMULATION_ERROR_TYPE, 3); // Exp(3) parameters.set(Params.SIMULATION_PARAM1, 1); // parameters.set(Params.SIMULATION_PARAM2, 1); parameters.set(Params.PENALTY_DISCOUNT, 1); From b88727bc826ae79b71a2b98a41d31986514bd559 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 20:14:50 -0400 Subject: [PATCH 016/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index d918860305..bc3b18c7ba 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -53,7 +53,7 @@ public void test1() { Parameters parameters = new Parameters(); parameters.set(Params.NUM_MEASURES, 6); parameters.set(Params.AVG_DEGREE, 2); - parameters.set(Params.SIMULATION_ERROR_TYPE, 3); // Exp(3) + parameters.set(Params.SIMULATION_ERROR_TYPE, 3); // Exp(1) parameters.set(Params.SIMULATION_PARAM1, 1); // parameters.set(Params.SIMULATION_PARAM2, 1); parameters.set(Params.PENALTY_DISCOUNT, 1); From c7d2bfeee533a7886c087ecd1dc7faa045fab3b4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 20:17:05 -0400 Subject: [PATCH 017/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- .../java/edu/cmu/tetrad/search/LingD.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 8ccc310923..e9a11a662f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -134,6 +134,19 @@ private List nRooks(Matrix W) { } } + printAllowablePositions(W, allowablePositions); + + List colPermutations = NRooks.nRooks(allowablePositions); + + //for each assignment, add the corresponding permutation to 'pairs' + for (int[] colPermutation : colPermutations) { + pairs.add(new PermutationMatrixPair(null, colPermutation, W)); + } + + return pairs; + } + + private static void printAllowablePositions(Matrix W, boolean[][] allowablePositions) { System.out.println("\nAllowable rook positions"); // Print allowable board. @@ -146,15 +159,6 @@ private List nRooks(Matrix W) { System.out.println(); System.out.println(); - - List colPermutations = NRooks.nRooks(allowablePositions); - - //for each assignment, add the corresponding permutation to 'pairs' - for (int[] colPermutation : colPermutations) { - pairs.add(new PermutationMatrixPair(null, colPermutation, W)); - } - - return pairs; } From e0348f6a8be55d9e3226f921f2b43964df14eae9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 20:17:47 -0400 Subject: [PATCH 018/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index e9a11a662f..fd8b936017 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -161,7 +161,6 @@ private static void printAllowablePositions(Matrix W, boolean[][] allowablePosit System.out.println(); } - /** * Returns the graph for the givem model. * @param bHat The B Hat for the model. From 8553a2858f8b0d7ca0d9375102d59156a1f53c67 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 20:21:24 -0400 Subject: [PATCH 019/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index da73ba9c55..58e53222ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -43,7 +43,7 @@ * @author Joseph Ramsey */ public class Lingam { - private double pruneFactor = 0.5; + private double pruneFactor = 0.3; //================================CONSTRUCTORS==========================// From 8c13f852e31e309a658adeea5009370fdbabff09 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 25 Apr 2023 21:35:10 -0400 Subject: [PATCH 020/464] Some work on LiNG-D. This version basically works for both Lingam and LingD. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 58e53222ba..2dd0318f0f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -40,7 +40,7 @@ *

Implements the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, and Kerminen, A linear * nongaussian acyclic model for causal discovery, JMLR 7 (2006).

* - * @author Joseph Ramsey + * @author josephramsey */ public class Lingam { private double pruneFactor = 0.3; From 3a6f8285497e65f3d2c89c180dcb3d91bfda6df5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 06:18:35 -0400 Subject: [PATCH 021/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../java/edu/cmu/tetrad/test/TestLing.java | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index bc3b18c7ba..abe844d7b7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -38,6 +38,8 @@ import java.util.Arrays; import java.util.List; +import static org.junit.Assert.assertEquals; + /** * @author Joseph Ramsey */ @@ -45,6 +47,11 @@ public class TestLing { @Test public void test1() { + + // Testing LiNGAM and LiNG-D on a simple 6-node 6-edge example. This + // uses Exp(1) non-Gaussian errors and otherwise default parameters. + // We're not using bootstrapping yet here, which could make the result + // more accurate. long seed = 402030204L; RandomUtil.getInstance().setSeed(seed); System.out.println("Seed = " + seed + "L"); @@ -56,7 +63,6 @@ public void test1() { parameters.set(Params.SIMULATION_ERROR_TYPE, 3); // Exp(1) parameters.set(Params.SIMULATION_PARAM1, 1); // parameters.set(Params.SIMULATION_PARAM2, 1); - parameters.set(Params.PENALTY_DISCOUNT, 1); SemSimulation sim = new SemSimulation(new RandomForward()); sim.createData(parameters, true); @@ -64,14 +70,18 @@ public void test1() { Graph g = sim.getTrueGraph(0); System.out.println("True graph = " + g); + // First we use ICA to estimate the W matrix. Matrix W = Lingam.estimateW(dataSet, 5000, 1e-6, 1.2); - System.out.println("W = " + W); + // We then apply LiNGAM with a prune factor of .3. We should get a mostly correct DAG + // back. The "prune factor" is a threshold for the B Hat matrix below which values are + // sent to zero in absolute value, so that only coefficients whose absolute values + // exceed the prune factor are reported as edges in the model. Self-loops are not reported + // in the printed graphs but are assumed ot exist for purposes of this algorithm. The + // B Hat matrices are scaled so that self-loops always have strength 1. System.out.println("LiNGAM"); - double pruneFactor = 0.3; - System.out.println("Prune factor = " + pruneFactor); Lingam lingam = new Lingam(); @@ -79,37 +89,44 @@ public void test1() { Graph g2 = lingam.search(W, dataSet.getVariables()); System.out.println("Lingam graph = " + g2); + // Next we try LiNG-D. System.out.println("LiNG-D"); + // Here we send any small value in W to 0 that has absolute value below a given threshold. double wThreshold = 0.5; System.out.println("wThreshold = " + wThreshold); LingD ling = new LingD(); ling.setWThreshold(wThreshold); + + // We generate pairs of column permutations (solving the constriained N Rooks problem) with their + // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we + // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. List pairs = ling.search(W); + // Then for each N Rook solution we print stuff. for (PermutationMatrixPair pair : pairs) { + + // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. System.out.println("Model = " + LingD.getBHat(pair)); + // We print the corresponding graph. Graph graph = LingD.getGraph(pair, dataSet.getVariables()); + + System.out.println("Graph = " + graph); boolean stable = LingD.isStable(pair); + + // Finally we print a judgment of whether the BHat model is stable and cyclic. System.out.println((stable ? "Is Stable" : "Not stable") + " cyclic = " + graph.paths().existsDirectedCycle()); - System.out.println(graph); } } @Test public void testNRooks() { - int p = 3; - boolean[][] allowableBoard = new boolean[p][p]; - for (boolean[] row : allowableBoard) Arrays.fill(row, true); - allowableBoard[0][2] = false; - List solutions = NRooks.nRooks(allowableBoard); - NRooks.printSolutions(solutions); - } - @Test - public void testNRooks2() { + // Print all N Rook solutions for a board of size 24 with one square marked + // as non-allowable. There should be 4 solutions. + int p = 3; boolean[][] allowableBoard = new boolean[p][p]; for (boolean[] row : allowableBoard) Arrays.fill(row, true); @@ -125,7 +142,13 @@ public void testNRooks2() { System.out.println(); List solutions = NRooks.nRooks(allowableBoard); + + // Each solution is a permutation of the columns of the board, one integer + // for each row indicating where to place the rook in that row. NRooks.printSolutions(solutions); + + // There should be 4 solutions. + assertEquals(4, solutions.size()); } } From c1e6aa79a57357101f5158894755418616410398 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 06:19:42 -0400 Subject: [PATCH 022/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index abe844d7b7..8ee8d052f7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -60,7 +60,9 @@ public void test1() { Parameters parameters = new Parameters(); parameters.set(Params.NUM_MEASURES, 6); parameters.set(Params.AVG_DEGREE, 2); - parameters.set(Params.SIMULATION_ERROR_TYPE, 3); // Exp(1) + + // Using Exp(1) for the non-Gaussian error for all variables. + parameters.set(Params.SIMULATION_ERROR_TYPE, 3); parameters.set(Params.SIMULATION_PARAM1, 1); // parameters.set(Params.SIMULATION_PARAM2, 1); From 63511172f84d5a00abefc133f0755bb2a5771814 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 06:29:47 -0400 Subject: [PATCH 023/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../java/edu/cmu/tetrad/search/NRooks.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index ba7659492e..87c53c0452 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -19,7 +19,7 @@ public class NRooks { /** - * Solves the N-Rooks problem for the given allowable board. + * Solves the N-Rooks problem for the given board or allowable positions. * @param allowablePositions A matrix of allowable rook positions, should be * true iff the position is allowable. * @return A list of row indices for where to place the rooks for each solution. @@ -39,7 +39,7 @@ public static ArrayList nRooks(boolean[][] allowablePositions) { } /** - * Prints the discovered N Rooks solutions. + * Prints the discovered N Rooks solutions given the constraint. * @param solutions The solutions. */ public static void printSolutions(List solutions) { @@ -51,9 +51,9 @@ public static void printSolutions(List solutions) { } private static void dfs(boolean[][] board, boolean[][] allowablePositions, int row, ArrayList solutions) { - if (row == board.length) { - // Base case: all rooks have been placed + // Base case: all rooks have been placed + if (row == board.length) { int[] solution = new int[board.length]; for (int i = 0; i < board.length; i++) { for (int j = 0; j < board.length; j++) { @@ -67,11 +67,21 @@ private static void dfs(boolean[][] board, boolean[][] allowablePositions, int r return; } + // Otherwise, for each column for (int col = 0; col < board.length; col++) { + + // If the current row is a valid position to place a rook (i.e., it can't attack + // any other rook)... if (isValid(board, row, col)) { + + // This constrains the problem to allowable positions on the board. if (!allowablePositions[row][col]) continue; + + // Otherwise place the rook and recurse through the rows of the board. board[row][col] = true; dfs(board, allowablePositions, row+1, solutions); + + // Backtrack and try another case... board[row][col] = false; } } @@ -79,7 +89,8 @@ private static void dfs(boolean[][] board, boolean[][] allowablePositions, int r private static boolean isValid(boolean[][] board, int row, int col) { - // check if the current position is valid + // Check if the current position is valid. ChatGPT had some clever condition here + // that didn't work, sorry ChatGPT. This is the non-clever condition. for (int i = 0; i < row; i++) { if (board[i][col]) { for (boolean[] booleans : board) { From 49ccdd2bf0a9278d6f9c83aa5dd71c61d2626e5f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 06:50:24 -0400 Subject: [PATCH 024/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../java/edu/cmu/tetrad/search/Lingam.java | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 2dd0318f0f..7b669071c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -44,6 +44,8 @@ */ public class Lingam { private double pruneFactor = 0.3; + private Matrix permutedBHat = null; + private List permutedVars = null; //================================CONSTRUCTORS==========================// @@ -81,10 +83,15 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT * Searches given the W matrix from ICA. * * @param W the W matrix from ICA. + * @param variables The variables from the original dataset used to generate the W matrix, + * in the order they occur in that dataset. * @return The graph returned. */ public Graph search(Matrix W, List variables) { PermutationGenerator gen1 = new PermutationGenerator(W.rows()); + + // The first task is to find a row permutation of the W matrix that maximizes + // the absolute values on its diagonal. We do this by minimizing SUM(1 / |Wii|). int[] rowPerm = new int[0]; double sum1 = Double.POSITIVE_INFINITY; int[] choice1; @@ -102,12 +109,20 @@ public Graph search(Matrix W, List variables) { } } - Matrix perm1W = new PermutationMatrixPair(rowPerm, null, W).getPermutedMatrix(); - perm1W = scale(perm1W); + // We grab the resulting diagonal-optimized matrix and scale it by divind each entry Wij + // by Wjj. How the diagonal should consist only of 1's. + Matrix WTilde = new PermutationMatrixPair(rowPerm, null, W).getPermutedMatrix(); + WTilde = scale(WTilde); - int m = W.columns(); - Matrix BHat = Matrix.identity(m).minus(perm1W); + // We calculate BHat as I - WTilde. + Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); + // The second task is to rearrange the BHat matrix by permuting rows and columns + // simultaneously so that the lower triangle is maximal--i.e., so that SUM(WTilde(i, j)^2) + // is maximal for j > i. The goal of this is to find a causal order for the variables. + // If all the big coefficients are in the lower triangle, we can interpret it as a + // DAG model. We will ignore any big coefficients left over in the upper triangle. + // We will assume the diagonal of the BHat matrix is zero--i.e., no self-loops. PermutationGenerator gen2 = new PermutationGenerator(BHat.rows()); int[] perm = new int[0]; double sum2 = Double.NEGATIVE_INFINITY; @@ -129,19 +144,33 @@ public Graph search(Matrix W, List variables) { } } - Matrix permBHat = new PermutationMatrixPair(perm, perm, BHat).getPermutedMatrix(); + // Grab that lower-triangle maximized version of the BHat matrix. + Matrix BHatTilde = new PermutationMatrixPair(perm, perm, BHat).getPermutedMatrix(); + + // Set the upper triangle now to zero, since we are ignoring it for this DAG algorithm. + for (int i = 0; i < BHatTilde.rows(); i++) { + for (int j = i + 1; j < BHatTilde.columns(); j++) { + BHatTilde.set(i, j, 0.0); + } + } + + // Permute the variables too for that order. List varPerm = new ArrayList<>(); for (int k : perm) varPerm.add(variables.get(k)); + // Grab the permuted BHat and variables. + this.permutedBHat = BHatTilde; + this.permutedVars = varPerm; + + // Make the graph and return it. Graph g = new EdgeListGraph(varPerm); - for (int j = 0; j < permBHat.columns(); j++) { - for (int i = j + 1; i < permBHat.rows(); i++) { - if (abs(permBHat.get(i, j)) > pruneFactor) { - g.addDirectedEdge(varPerm.get(j), varPerm.get(i)); + for (int j = 0; j < getPermutedBHat().columns(); j++) { + for (int i = j + 1; i < getPermutedBHat().rows(); i++) { + if (abs(getPermutedBHat().get(i, j)) > pruneFactor) { + g.addDirectedEdge(getPermutedVars().get(j), getPermutedVars().get(i)); } - } } @@ -189,12 +218,28 @@ public static Matrix threshold(Matrix M, double threshold) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. - * * @param pruneFactor Some value >= 0. */ public void setPruneFactor(double pruneFactor) { if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); this.pruneFactor = pruneFactor; } + + /** + * After search the permuted BHat matrix can be retrieved using this method. + * @return The permutated (lower triangle) BHat matrix. Here, BHat(i, j) != 0 means that + * there is an edge vars(j)-->vars(i) in the graph, where 'vars' means the permuted variables. + */ + public Matrix getPermutedBHat() { + return permutedBHat; + } + + /** + * The permuted variables of the graph. This is the estimated causal order of the models. + * @return This list of variables. + */ + public List getPermutedVars() { + return permutedVars; + } } From 2c47eeed3b91b29bb53bf4e162c58680f83f59b5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 06:56:54 -0400 Subject: [PATCH 025/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../java/edu/cmu/tetrad/search/LingD.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index fd8b936017..867903e7e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -74,12 +74,29 @@ public void setWThreshold(double wThreshold) { this.wThreshold = wThreshold; } + /** + * Returns the scaled BHat matrix (i.e., coefficient matrix for the linear + * model) for the given column permutation of the thresholded W matrix. + * @param pair The (column permutation, thresholded, column permuted W matrix) + * pair. + * @return The estimated B Hat matrix for this pair. + */ public static Matrix getBHat(PermutationMatrixPair pair) { Matrix _w = pair.getPermutedMatrix(); Matrix bHat = Matrix.identity(_w.rows()).minus(_w); return Lingam.scale(bHat); } + /** + * Returns the estimated graph for the given column permutation of the + * thresholded W matrix, with self-loops. (We are assuming for purposes of + * the LiNG-D algorithm that all variables have self-loops.) + * @param pair The (column permutation, thresholded, column permuted W matrix) + * pair. + * @param variables The variables in the order in which they occur in the + * original dataset being analyzed. + * @return The estimated graph for this pair. + */ public static Graph getGraph(PermutationMatrixPair pair, List variables) { int[] perm = pair.getColPerm(); @@ -162,7 +179,8 @@ private static void printAllowablePositions(Matrix W, boolean[][] allowablePosit } /** - * Returns the graph for the givem model. + * Returns the graph for the givem model, with self-loops. (We are assuming + * for purposes of the LiNG-D algorithm that all variables have self-loops.) * @param bHat The B Hat for the model. * @param variables The variables for the model. * @return The graph. @@ -172,7 +190,7 @@ private static Graph getGraph(Matrix bHat, List variables) { for (int i = 0; i < variables.size(); i++) { for (int j = 0; j < variables.size(); j++) { - if (i != j && bHat.get(j, i) != 0) { + if (bHat.get(j, i) != 0) { graph.addDirectedEdge(variables.get(i), variables.get(j)); } } From c98e8f75ba5583ecd8d12520c945e47a2be19ef4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 06:57:26 -0400 Subject: [PATCH 026/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 867903e7e1..ff4b3422b1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -38,7 +38,6 @@ * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering cyclic causal models * by independent components analysis. arXiv preprint arXiv:1206.3273. * - * @author lacerda * @author josephramsey */ public class LingD { From f44ed6528d1dc5475debbea9434bec18861eeef8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 07:01:28 -0400 Subject: [PATCH 027/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index ff4b3422b1..49a252e2ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -35,8 +35,9 @@ import static org.apache.commons.math3.util.FastMath.sqrt; /** - * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering cyclic causal models - * by independent components analysis. arXiv preprint arXiv:1206.3273. + * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering + * cyclic causal models by independent components analysis. arXiv preprint + * arXiv:1206.3273. * * @author josephramsey */ @@ -47,8 +48,9 @@ public class LingD { //=============================CONSTRUCTORS============================// /** - * The algorithm only requires a DataSet to process. Passing in a Dataset and then running the search algorithm is - * an effetive way to use LiNG. + * Constructor. The W matrix needs to be estimated separately (e.g., using + * the Lingam.estimateW(.) method using the ICA method in Tetrad, or some + * method in Python or R) and passed into the search(W) method. */ public LingD() { } @@ -56,9 +58,9 @@ public LingD() { //==============================PUBLIC METHODS=========================// /** - * Searches given the W matrix from ICA. + * Searches given the W matrix. * - * @param W the W matrix from ICA + * @param W the W matrix. * @return the LiNGAM graph. */ public List search(Matrix W) { From 0827cc0b36c1d3750417ad5532f340af6680626a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 07:09:48 -0400 Subject: [PATCH 028/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../java/edu/cmu/tetrad/search/LingD.java | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 49a252e2ea..a4ef137186 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -76,8 +76,8 @@ public void setWThreshold(double wThreshold) { } /** - * Returns the scaled BHat matrix (i.e., coefficient matrix for the linear - * model) for the given column permutation of the thresholded W matrix. + * Returns the BHat matrix, permuted to causal order (lower triangle) and + * scaled so that the diagonal consists only of 1's. * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. * @return The estimated B Hat matrix for this pair. @@ -107,7 +107,18 @@ public static Graph getGraph(PermutationMatrixPair pair, List variables) { permVars.add(variables.get(perm[i])); } - return getGraph(getBHat(pair), permVars); + Matrix bHat = getBHat(pair); + Graph graph = new EdgeListGraph(permVars); + + for (int i = 0; i < permVars.size(); i++) { + for (int j = 0; j < permVars.size(); j++) { + if (bHat.get(j, i) != 0) { + graph.addDirectedEdge(permVars.get(i), permVars.get(j)); + } + } + } + + return graph; } /** @@ -179,26 +190,6 @@ private static void printAllowablePositions(Matrix W, boolean[][] allowablePosit System.out.println(); } - /** - * Returns the graph for the givem model, with self-loops. (We are assuming - * for purposes of the LiNG-D algorithm that all variables have self-loops.) - * @param bHat The B Hat for the model. - * @param variables The variables for the model. - * @return The graph. - */ - private static Graph getGraph(Matrix bHat, List variables) { - Graph graph = new EdgeListGraph(variables); - - for (int i = 0; i < variables.size(); i++) { - for (int j = 0; j < variables.size(); j++) { - if (bHat.get(j, i) != 0) { - graph.addDirectedEdge(variables.get(i), variables.get(j)); - } - } - } - - return graph; - } } From c32209513dc77d2655f53a0556eec2879f3341ed Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 07:10:23 -0400 Subject: [PATCH 029/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index a4ef137186..72351b185e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -189,7 +189,6 @@ private static void printAllowablePositions(Matrix W, boolean[][] allowablePosit System.out.println(); System.out.println(); } - } From d111e4449cd4cdfae76fe5ae25b7a26c05659413 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 07:18:36 -0400 Subject: [PATCH 030/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../java/edu/cmu/tetrad/search/LingD.java | 27 ++++++++++++------- .../java/edu/cmu/tetrad/test/TestLing.java | 9 ++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 72351b185e..c648fa2cce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -82,12 +82,25 @@ public void setWThreshold(double wThreshold) { * pair. * @return The estimated B Hat matrix for this pair. */ - public static Matrix getBHat(PermutationMatrixPair pair) { + public static Matrix getPermutedBHat(PermutationMatrixPair pair) { Matrix _w = pair.getPermutedMatrix(); Matrix bHat = Matrix.identity(_w.rows()).minus(_w); return Lingam.scale(bHat); } + public static List getPermutedVariables(PermutationMatrixPair pair, + List variables) { + int[] perm = pair.getColPerm(); + + List permVars = new ArrayList<>(); + + for (int i = 0; i < variables.size(); i++) { + permVars.add(variables.get(perm[i])); + } + + return permVars; + } + /** * Returns the estimated graph for the given column permutation of the * thresholded W matrix, with self-loops. (We are assuming for purposes of @@ -99,15 +112,9 @@ public static Matrix getBHat(PermutationMatrixPair pair) { * @return The estimated graph for this pair. */ public static Graph getGraph(PermutationMatrixPair pair, List variables) { - int[] perm = pair.getColPerm(); - - List permVars = new ArrayList<>(); - - for (int i = 0; i < variables.size(); i++) { - permVars.add(variables.get(perm[i])); - } + List permVars = getPermutedVariables(pair, variables); - Matrix bHat = getBHat(pair); + Matrix bHat = getPermutedBHat(pair); Graph graph = new EdgeListGraph(permVars); for (int i = 0; i < permVars.size(); i++) { @@ -128,7 +135,7 @@ public static Graph getGraph(PermutationMatrixPair pair, List variables) { * @return True iff the model is stable. */ public static boolean isStable(PermutationMatrixPair pair) { - EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(getBHat(pair).toArray())); + EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(getPermutedBHat(pair).toArray())); double[] realEigenvalues = eigen.getRealEigenvalues(); double[] imagEigenvalues = eigen.getImagEigenvalues(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 8ee8d052f7..f457de4658 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -106,20 +106,21 @@ public void test1() { // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. List pairs = ling.search(W); - // Then for each N Rook solution we print stuff. + System.out.println("Then, for each constrained N Rooks solution (a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. - System.out.println("Model = " + LingD.getBHat(pair)); + System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); + System.out.println("\nPermuted Model = \n" + LingD.getPermutedBHat(pair)); // We print the corresponding graph. Graph graph = LingD.getGraph(pair, dataSet.getVariables()); - System.out.println("Graph = " + graph); + System.out.println("\nGraph = " + graph); boolean stable = LingD.isStable(pair); // Finally we print a judgment of whether the BHat model is stable and cyclic. - System.out.println((stable ? "Is Stable" : "Not stable") + " cyclic = " + graph.paths().existsDirectedCycle()); + System.out.println(stable ? "Is Stable" : "Not stable"); } } From 3611371fa787a5012533454252d7fb6775ce6606 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 07:42:44 -0400 Subject: [PATCH 031/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index c648fa2cce..7bbaee6266 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -159,7 +159,7 @@ public static boolean isStable(PermutationMatrixPair pair) { private List nRooks(Matrix W) { List pairs = new java.util.ArrayList<>(); - System.out.println("Listing permutation pairs, W = " + W); + System.out.println("\nThresholded W = \n" + W); //returns all zeroless-diagonal column-pairs boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index f457de4658..973051f8b3 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -106,7 +106,7 @@ public void test1() { // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. List pairs = ling.search(W); - System.out.println("Then, for each constrained N Rooks solution (a column permutation of thresholded W:"); + System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. From 4f5a0d0328adbd29e5323b22f51e95b3f954d5af Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 07:55:28 -0400 Subject: [PATCH 032/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../main/java/edu/cmu/tetrad/search/LingD.java | 18 +++++++++++++++--- .../java/edu/cmu/tetrad/test/TestLing.java | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 7bbaee6266..81e6b7644c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -82,12 +82,24 @@ public void setWThreshold(double wThreshold) { * pair. * @return The estimated B Hat matrix for this pair. */ - public static Matrix getPermutedBHat(PermutationMatrixPair pair) { + public static Matrix getPermutedScaledBHat(PermutationMatrixPair pair) { Matrix _w = pair.getPermutedMatrix(); Matrix bHat = Matrix.identity(_w.rows()).minus(_w); return Lingam.scale(bHat); } + /** + * Returns the BHat matrix, permuted to causal order (lower triangle), + * unscaled. + * @param pair The (column permutation, thresholded, column permuted W matrix) + * pair. + * @return The estimated B Hat matrix for this pair. + */ + public static Matrix getPermutedUnscaledBHat(PermutationMatrixPair pair) { + Matrix _w = pair.getPermutedMatrix(); + return Matrix.identity(_w.rows()).minus(_w); + } + public static List getPermutedVariables(PermutationMatrixPair pair, List variables) { int[] perm = pair.getColPerm(); @@ -114,7 +126,7 @@ public static List getPermutedVariables(PermutationMatrixPair pair, public static Graph getGraph(PermutationMatrixPair pair, List variables) { List permVars = getPermutedVariables(pair, variables); - Matrix bHat = getPermutedBHat(pair); + Matrix bHat = getPermutedScaledBHat(pair); Graph graph = new EdgeListGraph(permVars); for (int i = 0; i < permVars.size(); i++) { @@ -135,7 +147,7 @@ public static Graph getGraph(PermutationMatrixPair pair, List variables) { * @return True iff the model is stable. */ public static boolean isStable(PermutationMatrixPair pair) { - EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(getPermutedBHat(pair).toArray())); + EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(getPermutedScaledBHat(pair).toArray())); double[] realEigenvalues = eigen.getRealEigenvalues(); double[] imagEigenvalues = eigen.getImagEigenvalues(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 973051f8b3..7387588b86 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -111,7 +111,8 @@ public void test1() { // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); - System.out.println("\nPermuted Model = \n" + LingD.getPermutedBHat(pair)); + System.out.println("\nPermuted Scaled Model = \n" + LingD.getPermutedScaledBHat(pair)); + System.out.println("\nPermuted Unscaled Model = \n" + LingD.getPermutedUnscaledBHat(pair)); // We print the corresponding graph. Graph graph = LingD.getGraph(pair, dataSet.getVariables()); From d3c4073451111e9f5d202965f53b9ffdc1437ec3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 08:02:49 -0400 Subject: [PATCH 033/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 13 ++++++++++++- .../src/test/java/edu/cmu/tetrad/test/TestLing.java | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 81e6b7644c..c2f6adafdc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -89,7 +89,18 @@ public static Matrix getPermutedScaledBHat(PermutationMatrixPair pair) { } /** - * Returns the BHat matrix, permuted to causal order (lower triangle), + * Returns the thresholded W matrix, permuted to causal order (lower triangle), + * unscaled. + * @param pair The (column permutation, thresholded, column permuted W matrix) + * pair. + * @return The thresholded W matrix for this pair. + */ + public static Matrix getPermutedThresholdedW(PermutationMatrixPair pair) { + return pair.getPermutedMatrix(); + } + + /** + * Returns the BHat matrix, permuted to causal order (lower triangle) and * unscaled. * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 7387588b86..36cd09410a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -111,8 +111,9 @@ public void test1() { // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); - System.out.println("\nPermuted Scaled Model = \n" + LingD.getPermutedScaledBHat(pair)); + System.out.println("\nPermuted Thresholded W matrix = \n" + LingD.getPermutedThresholdedW(pair)); System.out.println("\nPermuted Unscaled Model = \n" + LingD.getPermutedUnscaledBHat(pair)); + System.out.println("\nPermuted Scaled Model = \n" + LingD.getPermutedScaledBHat(pair)); // We print the corresponding graph. Graph graph = LingD.getGraph(pair, dataSet.getVariables()); From ae1dcfcf81e13fe8794175e58c88cc1e0c89a8ab Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 08:04:44 -0400 Subject: [PATCH 034/464] Did some commenting on the unit test for LiNGAM and LiNG-D. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 36cd09410a..05db03e32f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -112,8 +112,8 @@ public void test1() { // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); System.out.println("\nPermuted Thresholded W matrix = \n" + LingD.getPermutedThresholdedW(pair)); - System.out.println("\nPermuted Unscaled Model = \n" + LingD.getPermutedUnscaledBHat(pair)); - System.out.println("\nPermuted Scaled Model = \n" + LingD.getPermutedScaledBHat(pair)); + System.out.println("\nPermuted Unscaled BHat = \n" + LingD.getPermutedUnscaledBHat(pair)); + System.out.println("\nPermuted Scaled BHat = \n" + LingD.getPermutedScaledBHat(pair)); // We print the corresponding graph. Graph graph = LingD.getGraph(pair, dataSet.getVariables()); From 7b95931d8079c9735e981e485935b2a1b58b0b9c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 09:36:04 -0400 Subject: [PATCH 035/464] Adding the LiNGAM parmameters to the interface. --- docs/manual/index.html | 23 +++++++++++++++++++ .../algorithm/continuous/dag/Lingam.java | 17 +++++++++++--- .../main/java/edu/cmu/tetrad/util/Params.java | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/manual/index.html b/docs/manual/index.html index d641943dd9..e4280e79ef 100755 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -5545,6 +5545,28 @@

fastIcaA

id="fastIcaTolerance_value_type">Double +

pruneFactor

+
    +
  • Short Description: LiNGAM Prune Factor. +
  • +
  • Long Description: The estimated coefficient matrix, BHat, + is pruned by setting small coefficients less than 'pruneFactor' + to zero. +
  • +
  • Default Value: 0.3
  • +
  • Lower Bound: + 0.0
  • +
  • Upper + Bound: Infinity
  • +
  • Value Type: Double
  • +
+

fisherEpsilon

    Trek + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 2513925618..ed7a325d97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -37,14 +37,24 @@ public class Lingam implements Algorithm { public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { DataSet data = SimpleDataLoader.getContinuousDataSet(dataSet); - Matrix W = edu.cmu.tetrad.search.Lingam.estimateW(data, 5000, 1e-6, 1.2); + + int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); + double alpha = parameters.getDouble(Params.FAST_ICA_A); + double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); + double pruneFactor = parameters.getDouble(Params.PRUNE_FACTOR); + + Matrix W = edu.cmu.tetrad.search.Lingam.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); + lingam.setPruneFactor(pruneFactor); return lingam.search(W, data.getVariables()); } else { Lingam algorithm = new Lingam(); 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)); + 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)); @@ -71,9 +81,10 @@ public List getParameters() { List parameters = new ArrayList<>(); parameters.add(Params.PENALTY_DISCOUNT); parameters.add(Params.VERBOSE); -// parameters.add(Params.FAST_ICA_A); + parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); + parameters.add(Params.PRUNE_FACTOR); return parameters; } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index 37de4e4085..0a0478c678 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -80,6 +80,7 @@ public final class Params { public static final String FAST_ICA_TOLERANCE = "fastIcaTolerance"; public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; + public static final String PRUNE_FACTOR = "pruneFactor"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; public static final String GENERAL_SEM_ERROR_TEMPLATE = "generalSemErrorTemplate"; From 741fd675129c8c67d66dbd0825da519ba7005d77 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 11:21:47 -0400 Subject: [PATCH 036/464] Adding the LiNGAM parmameters to the interface. --- .../algorithm/continuous/dag/Lingam.java | 37 +++- .../java/edu/cmu/tetrad/search/LingD.java | 162 ++++++++++-------- .../java/edu/cmu/tetrad/search/Lingam.java | 160 +++++++++-------- .../tetrad/search/PermutationMatrixPair.java | 57 ++++-- .../java/edu/cmu/tetrad/test/TestLing.java | 71 ++++---- 5 files changed, 281 insertions(+), 206 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index ed7a325d97..bcf80c4d7d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -9,14 +9,21 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.search.LingD; +import edu.cmu.tetrad.search.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; +import org.apache.commons.math3.linear.BlockRealMatrix; +import org.apache.commons.math3.linear.EigenDecomposition; import java.util.ArrayList; import java.util.List; +import static org.apache.commons.math3.util.FastMath.pow; +import static org.apache.commons.math3.util.FastMath.sqrt; + /** * LiNGAM. * @@ -34,6 +41,32 @@ public class Lingam implements Algorithm { static final long serialVersionUID = 23L; + /** + * Whether the BHat matrix represents a stable model. The eigenvalues are checked ot make sure they are + * all less than 1. + * @param pair The permutation pair. + * @return True iff the model is stable. + */ + public static boolean isStable(PermutationMatrixPair pair) { + EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(LingD.getPermutedScaledBHat(pair).toArray())); + double[] realEigenvalues = eigen.getRealEigenvalues(); + double[] imagEigenvalues = eigen.getImagEigenvalues(); + + for (int i = 0; i < realEigenvalues.length; i++) { + double realEigenvalue = realEigenvalues[i]; + double imagEigenvalue = imagEigenvalues[i]; + double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); + + System.out.println("modulus" + " " + modulus); + + if (modulus >= 1.0) { + return false; + } + } + + return true; + } + public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { DataSet data = SimpleDataLoader.getContinuousDataSet(dataSet); @@ -43,10 +76,10 @@ public Graph search(DataModel dataSet, Parameters parameters) { double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); double pruneFactor = parameters.getDouble(Params.PRUNE_FACTOR); - Matrix W = edu.cmu.tetrad.search.Lingam.estimateW(data, maxIter, tol, alpha); + Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); lingam.setPruneFactor(pruneFactor); - return lingam.search(W, data.getVariables()); + return lingam.search(W, data.getVariables(), 0.1); } else { Lingam algorithm = new Lingam(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index c2f6adafdc..9d05710925 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -21,18 +21,18 @@ package edu.cmu.tetrad.search; +import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; -import org.apache.commons.math3.linear.BlockRealMatrix; -import org.apache.commons.math3.linear.EigenDecomposition; import java.util.ArrayList; import java.util.List; +import static org.apache.commons.math3.util.FastMath.abs; import static org.apache.commons.math3.util.FastMath.pow; -import static org.apache.commons.math3.util.FastMath.sqrt; /** * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering @@ -43,10 +43,6 @@ */ public class LingD { - private double wThreshold = .5; - - //=============================CONSTRUCTORS============================// - /** * Constructor. The W matrix needs to be estimated separately (e.g., using * the Lingam.estimateW(.) method using the ICA method in Tetrad, or some @@ -55,24 +51,105 @@ public class LingD { public LingD() { } - //==============================PUBLIC METHODS=========================// - /** * Searches given the W matrix. * * @param W the W matrix. + * @param wThreshold The threshold below which entries in the W matrix are send to + * zero. * @return the LiNGAM graph. */ - public List search(Matrix W) { - return nRooks(Lingam.threshold(W, wThreshold)); + public List search(Matrix W, double wThreshold) { + return nRooks(threshold(W, wThreshold)); + } + + /** + * Estimates the W matrix using FastICA. + * + * @param data The dataset to estimate W for. + * @param fastIcaMaxIter Maximum number of iterations of ICA. + * @param fastIcaTolerance Tolerance for ICA. + * @param fastIcaA Alpha for ICA. + * @return The estimated W matrix. + */ + public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, double fastIcaA) { + Matrix X = data.getDoubleData(); + X = DataUtils.centerData(X).transpose(); + FastIca fastIca = new FastIca(X, X.rows()); + fastIca.setVerbose(false); + fastIca.setMaxIterations(fastIcaMaxIter); + fastIca.setAlgorithmType(FastIca.DEFLATION); + fastIca.setTolerance(fastIcaTolerance); + fastIca.setFunction(FastIca.EXP); + fastIca.setRowNorm(false); + fastIca.setAlpha(fastIcaA); + FastIca.IcaResult result11 = fastIca.findComponents(); + return result11.getW(); + } + + public static List nRooks(Matrix W) { + List pairs = new ArrayList<>(); + + System.out.println("\nThresholded W = \n" + W); + + //returns all zeroless-diagonal column-pairs + boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; + + for (int i = 0; i < W.rows(); i++) { + for (int j = 0; j < W.columns(); j++) { + allowablePositions[i][j] = W.get(i, j) != 0; + } + } + + printAllowablePositions(W, allowablePositions); + + List colPermutations = NRooks.nRooks(allowablePositions); + + //for each assignment, add the corresponding permutation to 'pairs' + for (int[] colPermutation : colPermutations) { + pairs.add(new PermutationMatrixPair(W, null, colPermutation)); + } + + return pairs; } /** - * Sets the value at which thresholding occurs for the W matrix. - * @param wThreshold The value at which the thresholding is set. + * Scares the given matrix M by diving each entry (i, j) by M(j, j) + * + * @param M The matrix to scale. + * @return The scaled matrix. */ - public void setWThreshold(double wThreshold) { - this.wThreshold = wThreshold; + public static Matrix scale(Matrix M) { + Matrix _M = M.like(); + + for (int i = 0; i < _M.rows(); i++) { + for (int j = 0; j < _M.columns(); j++) { + _M.set(i, j, M.get(i, j) / M.get(j, j)); + } + } + + return _M; + } + + /** + * Thresholds the givem matrix, sending any small entries to zero. + * + * @param M The matrix to threshold. + * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. + * @return The thresholded matrix. + */ + public static Matrix threshold(Matrix M, double threshold) { + if (threshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + threshold); + + Matrix _M = M.copy(); + + for (int i = 0; i < M.rows(); i++) { + for (int j = 0; j < M.columns(); j++) { + if (abs(M.get(i, j)) < threshold) _M.set(i, j, 0.0); + } + } + + return _M; } /** @@ -85,7 +162,7 @@ public void setWThreshold(double wThreshold) { public static Matrix getPermutedScaledBHat(PermutationMatrixPair pair) { Matrix _w = pair.getPermutedMatrix(); Matrix bHat = Matrix.identity(_w.rows()).minus(_w); - return Lingam.scale(bHat); + return scale(bHat); } /** @@ -151,59 +228,6 @@ public static Graph getGraph(PermutationMatrixPair pair, List variables) { return graph; } - /** - * Whether the BHat matrix represents a stable model. The eigenvalues are checked ot make sure they are - * all less than 1. - * @param pair The permutation pair. - * @return True iff the model is stable. - */ - public static boolean isStable(PermutationMatrixPair pair) { - EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(getPermutedScaledBHat(pair).toArray())); - double[] realEigenvalues = eigen.getRealEigenvalues(); - double[] imagEigenvalues = eigen.getImagEigenvalues(); - - for (int i = 0; i < realEigenvalues.length; i++) { - double realEigenvalue = realEigenvalues[i]; - double imagEigenvalue = imagEigenvalues[i]; - double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); - - System.out.println("modulus" + " " + modulus); - - if (modulus >= 1.0) { - return false; - } - } - - return true; - } - - //==============================PRIVATE METHODS=========================// - - private List nRooks(Matrix W) { - List pairs = new java.util.ArrayList<>(); - - System.out.println("\nThresholded W = \n" + W); - - //returns all zeroless-diagonal column-pairs - boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; - - for (int i = 0; i < W.rows(); i++) { - for (int j = 0; j < W.columns(); j++) { - allowablePositions[i][j] = W.get(i, j) != 0; - } - } - - printAllowablePositions(W, allowablePositions); - - List colPermutations = NRooks.nRooks(allowablePositions); - - //for each assignment, add the corresponding permutation to 'pairs' - for (int[] colPermutation : colPermutations) { - pairs.add(new PermutationMatrixPair(null, colPermutation, W)); - } - - return pairs; - } private static void printAllowablePositions(Matrix W, boolean[][] allowablePositions) { System.out.println("\nAllowable rook positions"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 7b669071c1..2e13bdc1d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -21,19 +21,17 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.PermutationGenerator; -import org.apache.commons.math3.util.FastMath; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static edu.cmu.tetrad.search.LingD.threshold; import static java.lang.StrictMath.abs; /** @@ -44,6 +42,7 @@ */ public class Lingam { private double pruneFactor = 0.3; + private double wThreshold = 0.0; private Matrix permutedBHat = null; private List permutedVars = null; @@ -55,66 +54,98 @@ public class Lingam { public Lingam() { } - /** - * Estimates the W matrix using FastICA. - * - * @param data The dataset to estimate W for. - * @param fastIcaMaxIter Maximum number of iterations of ICA. - * @param fastIcaTolerance Tolerance for ICA. - * @param fastIcaA Alpha for ICA. - * @return The estimated W matrix. - */ - public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, double fastIcaA) { - Matrix X = data.getDoubleData(); - X = DataUtils.centerData(X).transpose(); - FastIca fastIca = new FastIca(X, X.rows()); - fastIca.setVerbose(false); - fastIca.setMaxIterations(fastIcaMaxIter); - fastIca.setAlgorithmType(FastIca.DEFLATION); - fastIca.setTolerance(fastIcaTolerance); - fastIca.setFunction(FastIca.EXP); - fastIca.setRowNorm(false); - fastIca.setAlpha(fastIcaA); - FastIca.IcaResult result11 = fastIca.findComponents(); - return result11.getW(); - } - /** * Searches given the W matrix from ICA. * - * @param W the W matrix from ICA. + * @param W the W matrix from ICA. * @param variables The variables from the original dataset used to generate the W matrix, * in the order they occur in that dataset. * @return The graph returned. */ - public Graph search(Matrix W, List variables) { - PermutationGenerator gen1 = new PermutationGenerator(W.rows()); + public Graph search(Matrix W, List variables, double wThreshold) { + + wThreshold = 0.1; + Matrix thresholded = threshold(W, wThreshold); + W = thresholded; + + System.out.println("Thresholded W = " + thresholded); + + //////// ONE WAY + + + List pairs = LingD.nRooks(thresholded.transpose()); - // The first task is to find a row permutation of the W matrix that maximizes - // the absolute values on its diagonal. We do this by minimizing SUM(1 / |Wii|). - int[] rowPerm = new int[0]; + PermutationMatrixPair bestPair = null; double sum1 = Double.POSITIVE_INFINITY; - int[] choice1; - while ((choice1 = gen1.next()) != null) { + P: + for (PermutationMatrixPair pair : pairs) { + Matrix permutedMatrix = pair.getPermutedMatrix(); + +// System.out.println("Permuted = " + permutedMatrix); + double sum = 0.0; + for (int j = 0; j < permutedMatrix.rows(); j++) { + double a = permutedMatrix.get(j, j); - for (int j = 0; j < W.rows(); j++) { - sum += 1.0 / abs(W.get(choice1[j], j)); + if (a == 0) { + continue P; + } + + sum += 1.0 / abs(a); } if (sum < sum1) { sum1 = sum; - rowPerm = Arrays.copyOf(choice1, choice1.length); + bestPair = pair; } } - // We grab the resulting diagonal-optimized matrix and scale it by divind each entry Wij - // by Wjj. How the diagonal should consist only of 1's. - Matrix WTilde = new PermutationMatrixPair(rowPerm, null, W).getPermutedMatrix(); - WTilde = scale(WTilde); + if (bestPair == null) { + throw new NullPointerException("Could not find an N Rooks solution with that threshold."); + } + + Matrix WTilde = bestPair.getPermutedMatrix().transpose(); + + + //////// OTHER WAY + +// PermutationGenerator gen1 = new PermutationGenerator(W.rows()); +// +// // The first task is to find a row permutation of the W matrix that maximizes +// // the absolute values on its diagonal. We do this by minimizing SUM(1 / |Wii|). +// int[] rowPerm = new int[0]; +// double sum1 = Double.POSITIVE_INFINITY; +// int[] choice1; +// +// P: +// while ((choice1 = gen1.next()) != null) { +// double sum = 0.0; +// +// for (int j = 0; j < W.rows(); j++) { +//// double a = W.get(choice1[j], j); +//// sum += a == 0 ? Double.POSITIVE_INFINITY : 1.0 / abs(a); +// +// double a = W.get(choice1[j], j); +// +// if (a == 0) { +// continue P; +// } +// +// sum += 1.0 / abs(a); +// } +// +// if (sum < sum1) { +// sum1 = sum; +// rowPerm = Arrays.copyOf(choice1, choice1.length); +// } +// } +// +// Matrix WTilde = new PermutationMatrixPair(W, rowPerm, null).getPermutedMatrix(); + // We calculate BHat as I - WTilde. + WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); // The second task is to rearrange the BHat matrix by permuting rows and columns @@ -145,7 +176,7 @@ public Graph search(Matrix W, List variables) { } // Grab that lower-triangle maximized version of the BHat matrix. - Matrix BHatTilde = new PermutationMatrixPair(perm, perm, BHat).getPermutedMatrix(); + Matrix BHatTilde = new PermutationMatrixPair(BHat, perm, perm).getPermutedMatrix(); // Set the upper triangle now to zero, since we are ignoring it for this DAG algorithm. for (int i = 0; i < BHatTilde.rows(); i++) { @@ -154,7 +185,6 @@ public Graph search(Matrix W, List variables) { } } - // Permute the variables too for that order. List varPerm = new ArrayList<>(); for (int k : perm) varPerm.add(variables.get(k)); @@ -177,47 +207,9 @@ public Graph search(Matrix W, List variables) { return g; } - /** - * Scares the given matrix M by diving each entry (i, j) by M(j, j) - * - * @param M The matrix to scale. - * @return The scaled matrix. - */ - public static Matrix scale(Matrix M) { - Matrix _M = M.like(); - - for (int i = 0; i < _M.rows(); i++) { - for (int j = 0; j < _M.columns(); j++) { - _M.set(i, j, M.get(i, j) / M.get(j, j)); - } - } - - return _M; - } - - /** - * Thresholds the givem matrix, sending any small entries to zero. - * - * @param M The matrix to threshold. - * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. - * @return The thresholded matrix. - */ - public static Matrix threshold(Matrix M, double threshold) { - if (threshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + threshold); - - Matrix _M = M.copy(); - - for (int i = 0; i < M.rows(); i++) { - for (int j = 0; j < M.columns(); j++) { - if (FastMath.abs(M.get(i, j)) < threshold) _M.set(i, j, 0.0); - } - } - - return _M; - } - /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. + * * @param pruneFactor Some value >= 0. */ public void setPruneFactor(double pruneFactor) { @@ -227,6 +219,7 @@ public void setPruneFactor(double pruneFactor) { /** * After search the permuted BHat matrix can be retrieved using this method. + * * @return The permutated (lower triangle) BHat matrix. Here, BHat(i, j) != 0 means that * there is an edge vars(j)-->vars(i) in the graph, where 'vars' means the permuted variables. */ @@ -236,6 +229,7 @@ public Matrix getPermutedBHat() { /** * The permuted variables of the graph. This is the estimated causal order of the models. + * * @return This list of variables. */ public List getPermutedVars() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index a0b3a82c9b..f67e7e4c64 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -25,49 +25,74 @@ import java.util.Arrays; +/** + * Stores a matrix together with a row and column permutation. (if either + * of these is null, the identity permtuation will be used.) Returns + * the permuted matrix. + * + * @author josephramsey + */ public class PermutationMatrixPair { - private final int[] rowPerm; private final int[] colPerm; - private final Matrix w; + private final Matrix M; - public PermutationMatrixPair(int[] rowPerm, int[] colPerm, Matrix w) { + /** + * Constructs with a given matrix M and a row and column permutation (which + * may be null). + * @param M The matrix to be permuted. + * @param rowPerm The row permutation for M; if null the identity permutation + * ([0 1 2...#rows]) will be used. + * @param colPerm The row permutation for M; if null the identity permutation + * ([0 1 2...#cols]) will be used. + */ + public PermutationMatrixPair(Matrix M, int[] rowPerm, int[] colPerm) { if (rowPerm == null) { - rowPerm = new int[w.rows()]; - for (int i = 0; i < w.rows(); i++) rowPerm[i] = i; + rowPerm = new int[M.rows()]; + for (int i = 0; i < M.rows(); i++) rowPerm[i] = i; } if (colPerm == null) { - colPerm = new int[w.columns()]; - for (int i = 0; i < w.columns(); i++) colPerm[i] = i; + colPerm = new int[M.columns()]; + for (int i = 0; i < M.columns(); i++) colPerm[i] = i; } this.rowPerm = Arrays.copyOf(rowPerm, rowPerm.length); this.colPerm = Arrays.copyOf(colPerm, colPerm.length); - this.w = w.getSelection(rowPerm, colPerm); + this.M = M.copy(); } /** - * Returns W, permuted rowwise by the permutation passed in throught he constructor. + * Returns W, permuted rowwise by the permutation passed in through the constructor. * @return The row-permuted W. */ public Matrix getPermutedMatrix() { - return this.w; - } - - public String toString() { - return "Row perm " + Arrays.toString(this.rowPerm) - + "\nCol perm = " + Arrays.toString(this.colPerm) - + "\nmatrix W : " + this.w; + return M.getSelection(rowPerm, colPerm); } + /** + * @return The row permutation. + */ public int[] getRowPerm() { return Arrays.copyOf(rowPerm, rowPerm.length); } + /** + * @return The column permutation. + */ public int[] getColPerm() { return Arrays.copyOf(colPerm, colPerm.length); } + + /** + * Prints a string representation of this. + * @return The row and columns permutations, followed by the permuted matrix. + */ + public String toString() { + return "Row perm " + Arrays.toString(this.rowPerm) + + "\nCol perm = " + Arrays.toString(this.colPerm) + + "\nPermuted matrix : " + getPermutedMatrix(); + } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 05db03e32f..7911663470 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -73,7 +73,7 @@ public void test1() { System.out.println("True graph = " + g); // First we use ICA to estimate the W matrix. - Matrix W = Lingam.estimateW(dataSet, 5000, 1e-6, 1.2); + Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); System.out.println("W = " + W); // We then apply LiNGAM with a prune factor of .3. We should get a mostly correct DAG @@ -83,47 +83,46 @@ public void test1() { // in the printed graphs but are assumed ot exist for purposes of this algorithm. The // B Hat matrices are scaled so that self-loops always have strength 1. System.out.println("LiNGAM"); + + // We send any small value in W to 0 that has absolute value below a given threshold. + double wThreshold = 0.1; double pruneFactor = 0.3; - System.out.println("Prune factor = " + pruneFactor); + System.out.println("wThreshold = " + wThreshold); + System.out.println("LiNGAM Prune factor = " + pruneFactor); Lingam lingam = new Lingam(); lingam.setPruneFactor(pruneFactor); - Graph g2 = lingam.search(W, dataSet.getVariables()); + Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); System.out.println("Lingam graph = " + g2); - // Next we try LiNG-D. - System.out.println("LiNG-D"); - - // Here we send any small value in W to 0 that has absolute value below a given threshold. - double wThreshold = 0.5; - System.out.println("wThreshold = " + wThreshold); - - LingD ling = new LingD(); - ling.setWThreshold(wThreshold); - - // We generate pairs of column permutations (solving the constriained N Rooks problem) with their - // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we - // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. - List pairs = ling.search(W); - - System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); - for (PermutationMatrixPair pair : pairs) { - - // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. - System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); - System.out.println("\nPermuted Thresholded W matrix = \n" + LingD.getPermutedThresholdedW(pair)); - System.out.println("\nPermuted Unscaled BHat = \n" + LingD.getPermutedUnscaledBHat(pair)); - System.out.println("\nPermuted Scaled BHat = \n" + LingD.getPermutedScaledBHat(pair)); - - // We print the corresponding graph. - Graph graph = LingD.getGraph(pair, dataSet.getVariables()); - - System.out.println("\nGraph = " + graph); - boolean stable = LingD.isStable(pair); - - // Finally we print a judgment of whether the BHat model is stable and cyclic. - System.out.println(stable ? "Is Stable" : "Not stable"); - } +// // Next we try LiNG-D. +// System.out.println("LiNG-D"); +// +// LingD ling = new LingD(); +// +// // We generate pairs of column permutations (solving the constriained N Rooks problem) with their +// // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we +// // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. +// List pairs = ling.search(W, wThreshold); +// +// System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); +// for (PermutationMatrixPair pair : pairs) { +// +// // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. +// System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); +// System.out.println("\nPermuted Thresholded W matrix = \n" + LingD.getPermutedThresholdedW(pair)); +// System.out.println("\nPermuted Unscaled BHat = \n" + LingD.getPermutedUnscaledBHat(pair)); +// System.out.println("\nPermuted Scaled BHat = \n" + LingD.getPermutedScaledBHat(pair)); +// +// // We print the corresponding graph. +// Graph graph = LingD.getGraph(pair, dataSet.getVariables()); +// +// System.out.println("\nGraph = " + graph); +// boolean stable = edu.cmu.tetrad.algcomparison.algorithm.continuous.dag.Lingam.isStable(pair); +// +// // Finally we print a judgment of whether the BHat model is stable and cyclic. +// System.out.println(stable ? "Is Stable" : "Not stable"); +// } } @Test From bd2ebce6af7d68eb0f8a684c58f1a3d05004340c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 26 Apr 2023 14:34:13 -0400 Subject: [PATCH 037/464] Adding the LiNGAM parmameters to the interface. --- .../algorithm/continuous/dag/Lingam.java | 2 +- .../java/edu/cmu/tetrad/search/LingD.java | 4 +- .../java/edu/cmu/tetrad/search/Lingam.java | 44 -------- .../java/edu/cmu/tetrad/search/NRooks2.java | 104 ++++++++++++++++++ .../java/edu/cmu/tetrad/test/TestLing.java | 56 +++++----- 5 files changed, 135 insertions(+), 75 deletions(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index bcf80c4d7d..50960ce002 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -79,7 +79,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); lingam.setPruneFactor(pruneFactor); - return lingam.search(W, data.getVariables(), 0.1); + return lingam.search(W, data.getVariables(), pruneFactor); } else { Lingam algorithm = new Lingam(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 9d05710925..30c7a92d61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -60,7 +60,7 @@ public LingD() { * @return the LiNGAM graph. */ public List search(Matrix W, double wThreshold) { - return nRooks(threshold(W, wThreshold)); + return nRooks(threshold(W.transpose(), wThreshold)); } /** @@ -103,7 +103,7 @@ public static List nRooks(Matrix W) { printAllowablePositions(W, allowablePositions); - List colPermutations = NRooks.nRooks(allowablePositions); + List colPermutations = NRooks2.nRooks(allowablePositions); //for each assignment, add the corresponding permutation to 'pairs' for (int[] colPermutation : colPermutations) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 2e13bdc1d9..5ed7a7a37a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -63,16 +63,11 @@ public Lingam() { * @return The graph returned. */ public Graph search(Matrix W, List variables, double wThreshold) { - - wThreshold = 0.1; Matrix thresholded = threshold(W, wThreshold); W = thresholded; System.out.println("Thresholded W = " + thresholded); - //////// ONE WAY - - List pairs = LingD.nRooks(thresholded.transpose()); PermutationMatrixPair bestPair = null; @@ -82,8 +77,6 @@ public Graph search(Matrix W, List variables, double wThreshold) { for (PermutationMatrixPair pair : pairs) { Matrix permutedMatrix = pair.getPermutedMatrix(); -// System.out.println("Permuted = " + permutedMatrix); - double sum = 0.0; for (int j = 0; j < permutedMatrix.rows(); j++) { double a = permutedMatrix.get(j, j); @@ -107,43 +100,6 @@ public Graph search(Matrix W, List variables, double wThreshold) { Matrix WTilde = bestPair.getPermutedMatrix().transpose(); - - //////// OTHER WAY - -// PermutationGenerator gen1 = new PermutationGenerator(W.rows()); -// -// // The first task is to find a row permutation of the W matrix that maximizes -// // the absolute values on its diagonal. We do this by minimizing SUM(1 / |Wii|). -// int[] rowPerm = new int[0]; -// double sum1 = Double.POSITIVE_INFINITY; -// int[] choice1; -// -// P: -// while ((choice1 = gen1.next()) != null) { -// double sum = 0.0; -// -// for (int j = 0; j < W.rows(); j++) { -//// double a = W.get(choice1[j], j); -//// sum += a == 0 ? Double.POSITIVE_INFINITY : 1.0 / abs(a); -// -// double a = W.get(choice1[j], j); -// -// if (a == 0) { -// continue P; -// } -// -// sum += 1.0 / abs(a); -// } -// -// if (sum < sum1) { -// sum1 = sum; -// rowPerm = Arrays.copyOf(choice1, choice1.length); -// } -// } -// -// Matrix WTilde = new PermutationMatrixPair(W, rowPerm, null).getPermutedMatrix(); - - // We calculate BHat as I - WTilde. WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java new file mode 100644 index 0000000000..439ab2416b --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java @@ -0,0 +1,104 @@ +package edu.cmu.tetrad.search; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.IllformedLocaleException; +import java.util.List; + +/** + *

    Returns row positions for placing rooks for an n x n matrix so the rooks + * cannot attach each other, with a given boolean[][] specification of where rooks + * are allowed to be placed. For this spec, spec[i][j] = true iff a rook can be + * placed there.

    + *

    Had some help from ChatGPT for this but it messed up one of the methods, + * so taking some credit.

    + * + * @author josephramsey + * @author ChatGPT + */ +public class NRooks2 { + + /** + * Solves the N-Rooks problem for the given board or allowable positions. + * @param allowablePositions A matrix of allowable rook positions, should be + * true iff the position is allowable. + * @return A list of row indices for where to place the rooks for each solution. + */ + public static ArrayList nRooks(boolean[][] allowablePositions) { + for (boolean[] positions : allowablePositions) { + if (positions.length != allowablePositions[0].length) { + throw new IllformedLocaleException("Expecting a square matrix."); + } + } + + int p = allowablePositions.length; + boolean[][] _allowable = new boolean[p][p]; + ArrayList solutions = new ArrayList<>(); + dfs(_allowable, allowablePositions, 0, solutions); + return solutions; + } + + /** + * Prints the discovered N Rooks solutions given the constraint. + * @param solutions The solutions. + */ + public static void printSolutions(List solutions) { + System.out.println("Number of solutions: " + solutions.size()); + for (int i = 0; i < solutions.size(); i++) { + int[] solution = solutions.get(i); + System.out.println((i + 1) + ". " + Arrays.toString(solution)); + } + } + + private static void dfs(boolean[][] board, boolean[][] allowablePositions, int row, ArrayList solutions) { + + // Base case: all rooks have been placed + if (row == board.length) { + int[] solution = new int[board.length]; + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board.length; j++) { + if (board[j][i]) { + solution[j] = i; + break; + } + } + } + solutions.add(solution); + return; + } + + // Otherwise, for each column + for (int col = 0; col < board.length; col++) { + + // If the current row is a valid position to place a rook (i.e., it can't attack + // any other rook)... + if (isValid(board, row, col)) { + + // This constrains the problem to allowable positions on the board. + if (!allowablePositions[col][row]) continue; + + // Otherwise place the rook and recurse through the rows of the board. + board[col][row] = true; + dfs(board, allowablePositions, row+1, solutions); + + // Backtrack and try another case... + board[col][row] = false; + } + } + } + + private static boolean isValid(boolean[][] board, int row, int col) { + + // Check if the current position is valid. ChatGPT had some clever condition here + // that didn't work, sorry ChatGPT. This is the non-clever condition. + for (int i = 0; i < row; i++) { + if (board[col][i]) { + for (boolean[] booleans : board) { + if (booleans[row]) return false; + } + } + } + + return true; + } +} diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 7911663470..1591621757 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -95,34 +95,34 @@ public void test1() { Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); System.out.println("Lingam graph = " + g2); -// // Next we try LiNG-D. -// System.out.println("LiNG-D"); -// -// LingD ling = new LingD(); -// -// // We generate pairs of column permutations (solving the constriained N Rooks problem) with their -// // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we -// // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. -// List pairs = ling.search(W, wThreshold); -// -// System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); -// for (PermutationMatrixPair pair : pairs) { -// -// // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. -// System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); -// System.out.println("\nPermuted Thresholded W matrix = \n" + LingD.getPermutedThresholdedW(pair)); -// System.out.println("\nPermuted Unscaled BHat = \n" + LingD.getPermutedUnscaledBHat(pair)); -// System.out.println("\nPermuted Scaled BHat = \n" + LingD.getPermutedScaledBHat(pair)); -// -// // We print the corresponding graph. -// Graph graph = LingD.getGraph(pair, dataSet.getVariables()); -// -// System.out.println("\nGraph = " + graph); -// boolean stable = edu.cmu.tetrad.algcomparison.algorithm.continuous.dag.Lingam.isStable(pair); -// -// // Finally we print a judgment of whether the BHat model is stable and cyclic. -// System.out.println(stable ? "Is Stable" : "Not stable"); -// } + // Next we try LiNG-D. + System.out.println("LiNG-D"); + + LingD ling = new LingD(); + + // We generate pairs of column permutations (solving the constriained N Rooks problem) with their + // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we + // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. + List pairs = ling.search(W, wThreshold); + + System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); + for (PermutationMatrixPair pair : pairs) { + + // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. + System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); + System.out.println("\nPermuted Thresholded W matrix = \n" + LingD.getPermutedThresholdedW(pair)); + System.out.println("\nPermuted Unscaled BHat = \n" + LingD.getPermutedUnscaledBHat(pair)); + System.out.println("\nPermuted Scaled BHat = \n" + LingD.getPermutedScaledBHat(pair)); + + // We print the corresponding graph. + Graph graph = LingD.getGraph(pair, dataSet.getVariables()); + + System.out.println("\nGraph = " + graph); + boolean stable = edu.cmu.tetrad.algcomparison.algorithm.continuous.dag.Lingam.isStable(pair); + + // Finally we print a judgment of whether the BHat model is stable and cyclic. + System.out.println(stable ? "Is Stable" : "Not stable"); + } } @Test From 2a8be6927ce90008b23e6e3843553d943bbc6746 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 27 Apr 2023 14:49:24 -0400 Subject: [PATCH 038/464] This version of LiNGAM and LiNG basically works. --- .../algorithm/continuous/dag/Lingam.java | 30 ---- .../java/edu/cmu/tetrad/search/LingD.java | 169 +++++++++++++----- .../java/edu/cmu/tetrad/search/Lingam.java | 75 +------- .../java/edu/cmu/tetrad/search/NRooks2.java | 104 ----------- .../java/edu/cmu/tetrad/test/TestLing.java | 44 ++--- 5 files changed, 161 insertions(+), 261 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 50960ce002..40329cdf1a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -10,19 +10,15 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.LingD; -import edu.cmu.tetrad.search.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; -import org.apache.commons.math3.linear.BlockRealMatrix; -import org.apache.commons.math3.linear.EigenDecomposition; import java.util.ArrayList; import java.util.List; import static org.apache.commons.math3.util.FastMath.pow; -import static org.apache.commons.math3.util.FastMath.sqrt; /** * LiNGAM. @@ -41,32 +37,6 @@ public class Lingam implements Algorithm { static final long serialVersionUID = 23L; - /** - * Whether the BHat matrix represents a stable model. The eigenvalues are checked ot make sure they are - * all less than 1. - * @param pair The permutation pair. - * @return True iff the model is stable. - */ - public static boolean isStable(PermutationMatrixPair pair) { - EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(LingD.getPermutedScaledBHat(pair).toArray())); - double[] realEigenvalues = eigen.getRealEigenvalues(); - double[] imagEigenvalues = eigen.getImagEigenvalues(); - - for (int i = 0; i < realEigenvalues.length; i++) { - double realEigenvalue = realEigenvalues[i]; - double imagEigenvalue = imagEigenvalues[i]; - double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); - - System.out.println("modulus" + " " + modulus); - - if (modulus >= 1.0) { - return false; - } - } - - return true; - } - public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { DataSet data = SimpleDataLoader.getContinuousDataSet(dataSet); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 30c7a92d61..b3db0d8b19 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -27,12 +27,17 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; +import edu.cmu.tetrad.util.PermutationGenerator; +import org.apache.commons.math3.linear.BlockRealMatrix; +import org.apache.commons.math3.linear.EigenDecomposition; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import static org.apache.commons.math3.util.FastMath.abs; -import static org.apache.commons.math3.util.FastMath.pow; +import static org.apache.commons.math3.util.FastMath.*; /** * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering @@ -51,16 +56,128 @@ public class LingD { public LingD() { } + @NotNull + public static Graph makeGraph(Matrix bHat, List varPerm) { + Graph g = new EdgeListGraph(varPerm); + + for (int j = 0; j < bHat.columns(); j++) { + for (int i = 0; i < bHat.rows(); i++) { + if (i == j) continue; + if (bHat.get(i, j) != 0) { + g.addDirectedEdge(varPerm.get(j), varPerm.get(i)); + } + } + } + return g; + } + /** - * Searches given the W matrix. - * - * @param W the W matrix. - * @param wThreshold The threshold below which entries in the W matrix are send to - * zero. - * @return the LiNGAM graph. + * Returns the estimated graph for the given column permutation of the + * thresholded W matrix, with self-loops. (We are assuming for purposes of + * the LiNG-D algorithm that all variables have self-loops.) + * @param pair The (column permutation, thresholded, column permuted W matrix) + * pair. + * @param variables The variables in the order in which they occur in the + * original dataset being analyzed. + * @return The estimated graph for this pair. */ - public List search(Matrix W, double wThreshold) { - return nRooks(threshold(W.transpose(), wThreshold)); + public static Graph makeGraph1(PermutationMatrixPair pair, List variables) { + List permVars = getPermutedVariables(pair, variables); + Matrix bHat = getPermutedScaledBHat(pair); + Graph g = new EdgeListGraph(permVars); + + for (int i = 0; i < permVars.size(); i++) { + for (int j = 0; j < permVars.size(); j++) { + if (i == j) continue; + if (bHat.get(i, j) != 0) { + g.addDirectedEdge(permVars.get(j), permVars.get(i)); + } + } + } + + return g; + } + + @NotNull + public static int[] encourageLowerTriangular(Matrix W, Matrix BHat) { + PermutationGenerator gen2 = new PermutationGenerator(BHat.rows()); + int[] perm = new int[0]; + double sum2 = Double.NEGATIVE_INFINITY; + int[] choice2; + + while ((choice2 = gen2.next()) != null) { + double sum = 0.0; + + for (int i = 0; i < W.rows(); i++) { + for (int j = 0; j < i; j++) { + double b = BHat.get(choice2[i], choice2[j]); + sum += b * b; + } + } + + if (sum > sum2) { + sum2 = sum; + perm = Arrays.copyOf(choice2, choice2.length); + } + } + return perm; + } + + @Nullable + static PermutationMatrixPair strongestDiagonalByCols(Matrix thresholded) { + List pairs = nRooks(thresholded.transpose()); + + PermutationMatrixPair bestPair = null; + double sum1 = Double.POSITIVE_INFINITY; + + P: + for (PermutationMatrixPair pair : pairs) { + Matrix permutedMatrix = pair.getPermutedMatrix(); + + double sum = 0.0; + for (int j = 0; j < permutedMatrix.rows(); j++) { + double a = permutedMatrix.get(j, j); + + if (a == 0) { + continue P; + } + + sum += 1.0 / StrictMath.abs(a); + } + + if (sum < sum1) { + sum1 = sum; + bestPair = pair; + } + } + + return bestPair; + } + + /** + * Whether the BHat matrix represents a stable model. The eigenvalues are checked ot make sure they are + * all less than 1. + * @param bHat The bHat matrix. + * @return True iff the model is stable. + */ + public static boolean isStable(Matrix bHat) { + EigenDecomposition eigen = new EigenDecomposition(new BlockRealMatrix(bHat.toArray())); + double[] realEigenvalues = eigen.getRealEigenvalues(); + double[] imagEigenvalues = eigen.getImagEigenvalues(); + + for (int i = 0; i < realEigenvalues.length; i++) { + double realEigenvalue = realEigenvalues[i]; + double imagEigenvalue = imagEigenvalues[i]; + double modulus = sqrt(pow(realEigenvalue, 2) + pow(imagEigenvalue, 2)); + + System.out.println("Modulus for eigenvalue " + (i + 1) + " = " + modulus); + + if (modulus >= 1.0) { + return false; + } + } + + return true; } /** @@ -90,9 +207,6 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT public static List nRooks(Matrix W) { List pairs = new ArrayList<>(); - System.out.println("\nThresholded W = \n" + W); - - //returns all zeroless-diagonal column-pairs boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; for (int i = 0; i < W.rows(); i++) { @@ -101,9 +215,9 @@ public static List nRooks(Matrix W) { } } - printAllowablePositions(W, allowablePositions); +// printAllowablePositions(W, allowablePositions); - List colPermutations = NRooks2.nRooks(allowablePositions); + List colPermutations = NRooks.nRooks(allowablePositions); //for each assignment, add the corresponding permutation to 'pairs' for (int[] colPermutation : colPermutations) { @@ -201,32 +315,7 @@ public static List getPermutedVariables(PermutationMatrixPair pair, return permVars; } - /** - * Returns the estimated graph for the given column permutation of the - * thresholded W matrix, with self-loops. (We are assuming for purposes of - * the LiNG-D algorithm that all variables have self-loops.) - * @param pair The (column permutation, thresholded, column permuted W matrix) - * pair. - * @param variables The variables in the order in which they occur in the - * original dataset being analyzed. - * @return The estimated graph for this pair. - */ - public static Graph getGraph(PermutationMatrixPair pair, List variables) { - List permVars = getPermutedVariables(pair, variables); - - Matrix bHat = getPermutedScaledBHat(pair); - Graph graph = new EdgeListGraph(permVars); - for (int i = 0; i < permVars.size(); i++) { - for (int j = 0; j < permVars.size(); j++) { - if (bHat.get(j, i) != 0) { - graph.addDirectedEdge(permVars.get(i), permVars.get(j)); - } - } - } - - return graph; - } private static void printAllowablePositions(Matrix W, boolean[][] allowablePositions) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 5ed7a7a37a..650f181657 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -21,14 +21,11 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; -import edu.cmu.tetrad.util.PermutationGenerator; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static edu.cmu.tetrad.search.LingD.threshold; @@ -66,33 +63,7 @@ public Graph search(Matrix W, List variables, double wThreshold) { Matrix thresholded = threshold(W, wThreshold); W = thresholded; - System.out.println("Thresholded W = " + thresholded); - - List pairs = LingD.nRooks(thresholded.transpose()); - - PermutationMatrixPair bestPair = null; - double sum1 = Double.POSITIVE_INFINITY; - - P: - for (PermutationMatrixPair pair : pairs) { - Matrix permutedMatrix = pair.getPermutedMatrix(); - - double sum = 0.0; - for (int j = 0; j < permutedMatrix.rows(); j++) { - double a = permutedMatrix.get(j, j); - - if (a == 0) { - continue P; - } - - sum += 1.0 / abs(a); - } - - if (sum < sum1) { - sum1 = sum; - bestPair = pair; - } - } + PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(thresholded); if (bestPair == null) { throw new NullPointerException("Could not find an N Rooks solution with that threshold."); @@ -110,34 +81,15 @@ public Graph search(Matrix W, List variables, double wThreshold) { // If all the big coefficients are in the lower triangle, we can interpret it as a // DAG model. We will ignore any big coefficients left over in the upper triangle. // We will assume the diagonal of the BHat matrix is zero--i.e., no self-loops. - PermutationGenerator gen2 = new PermutationGenerator(BHat.rows()); - int[] perm = new int[0]; - double sum2 = Double.NEGATIVE_INFINITY; - int[] choice2; - - while ((choice2 = gen2.next()) != null) { - double sum = 0.0; - - for (int i = 0; i < W.rows(); i++) { - for (int j = 0; j < i; j++) { - double b = BHat.get(choice2[i], choice2[j]); - sum += b * b; - } - } - - if (sum > sum2) { - sum2 = sum; - perm = Arrays.copyOf(choice2, choice2.length); - } - } + int[] perm = LingD.encourageLowerTriangular(W, BHat); // Grab that lower-triangle maximized version of the BHat matrix. - Matrix BHatTilde = new PermutationMatrixPair(BHat, perm, perm).getPermutedMatrix(); + Matrix bHatPerm = new PermutationMatrixPair(BHat, perm, perm).getPermutedMatrix(); // Set the upper triangle now to zero, since we are ignoring it for this DAG algorithm. - for (int i = 0; i < BHatTilde.rows(); i++) { - for (int j = i + 1; j < BHatTilde.columns(); j++) { - BHatTilde.set(i, j, 0.0); + for (int i = 0; i < bHatPerm.rows(); i++) { + for (int j = i + 1; j < bHatPerm.columns(); j++) { + bHatPerm.set(i, j, 0.0); } } @@ -146,21 +98,12 @@ public Graph search(Matrix W, List variables, double wThreshold) { for (int k : perm) varPerm.add(variables.get(k)); // Grab the permuted BHat and variables. - this.permutedBHat = BHatTilde; + this.permutedBHat = bHatPerm; this.permutedVars = varPerm; // Make the graph and return it. - Graph g = new EdgeListGraph(varPerm); - - for (int j = 0; j < getPermutedBHat().columns(); j++) { - for (int i = j + 1; i < getPermutedBHat().rows(); i++) { - if (abs(getPermutedBHat().get(i, j)) > pruneFactor) { - g.addDirectedEdge(getPermutedVars().get(j), getPermutedVars().get(i)); - } - } - } - - return g; + return LingD.makeGraph(bHatPerm, varPerm); +// return LingD.makeGraph(LingD.threshold(bHatPerm, pruneFactor), varPerm); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java deleted file mode 100644 index 439ab2416b..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks2.java +++ /dev/null @@ -1,104 +0,0 @@ -package edu.cmu.tetrad.search; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.IllformedLocaleException; -import java.util.List; - -/** - *

    Returns row positions for placing rooks for an n x n matrix so the rooks - * cannot attach each other, with a given boolean[][] specification of where rooks - * are allowed to be placed. For this spec, spec[i][j] = true iff a rook can be - * placed there.

    - *

    Had some help from ChatGPT for this but it messed up one of the methods, - * so taking some credit.

    - * - * @author josephramsey - * @author ChatGPT - */ -public class NRooks2 { - - /** - * Solves the N-Rooks problem for the given board or allowable positions. - * @param allowablePositions A matrix of allowable rook positions, should be - * true iff the position is allowable. - * @return A list of row indices for where to place the rooks for each solution. - */ - public static ArrayList nRooks(boolean[][] allowablePositions) { - for (boolean[] positions : allowablePositions) { - if (positions.length != allowablePositions[0].length) { - throw new IllformedLocaleException("Expecting a square matrix."); - } - } - - int p = allowablePositions.length; - boolean[][] _allowable = new boolean[p][p]; - ArrayList solutions = new ArrayList<>(); - dfs(_allowable, allowablePositions, 0, solutions); - return solutions; - } - - /** - * Prints the discovered N Rooks solutions given the constraint. - * @param solutions The solutions. - */ - public static void printSolutions(List solutions) { - System.out.println("Number of solutions: " + solutions.size()); - for (int i = 0; i < solutions.size(); i++) { - int[] solution = solutions.get(i); - System.out.println((i + 1) + ". " + Arrays.toString(solution)); - } - } - - private static void dfs(boolean[][] board, boolean[][] allowablePositions, int row, ArrayList solutions) { - - // Base case: all rooks have been placed - if (row == board.length) { - int[] solution = new int[board.length]; - for (int i = 0; i < board.length; i++) { - for (int j = 0; j < board.length; j++) { - if (board[j][i]) { - solution[j] = i; - break; - } - } - } - solutions.add(solution); - return; - } - - // Otherwise, for each column - for (int col = 0; col < board.length; col++) { - - // If the current row is a valid position to place a rook (i.e., it can't attack - // any other rook)... - if (isValid(board, row, col)) { - - // This constrains the problem to allowable positions on the board. - if (!allowablePositions[col][row]) continue; - - // Otherwise place the rook and recurse through the rows of the board. - board[col][row] = true; - dfs(board, allowablePositions, row+1, solutions); - - // Backtrack and try another case... - board[col][row] = false; - } - } - } - - private static boolean isValid(boolean[][] board, int row, int col) { - - // Check if the current position is valid. ChatGPT had some clever condition here - // that didn't work, sorry ChatGPT. This is the non-clever condition. - for (int i = 0; i < row; i++) { - if (board[col][i]) { - for (boolean[] booleans : board) { - if (booleans[row]) return false; - } - } - } - - return true; - } -} diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 1591621757..ab92553be0 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.algcomparison.simulation.SemSimulation; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.LingD; import edu.cmu.tetrad.search.Lingam; import edu.cmu.tetrad.search.NRooks; @@ -38,6 +39,8 @@ import java.util.Arrays; import java.util.List; +import static edu.cmu.tetrad.search.LingD.getPermutedScaledBHat; +import static edu.cmu.tetrad.search.LingD.getPermutedVariables; import static org.junit.Assert.assertEquals; /** @@ -64,7 +67,6 @@ public void test1() { // Using Exp(1) for the non-Gaussian error for all variables. parameters.set(Params.SIMULATION_ERROR_TYPE, 3); parameters.set(Params.SIMULATION_PARAM1, 1); -// parameters.set(Params.SIMULATION_PARAM2, 1); SemSimulation sim = new SemSimulation(new RandomForward()); sim.createData(parameters, true); @@ -74,7 +76,6 @@ public void test1() { // First we use ICA to estimate the W matrix. Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); - System.out.println("W = " + W); // We then apply LiNGAM with a prune factor of .3. We should get a mostly correct DAG // back. The "prune factor" is a threshold for the B Hat matrix below which values are @@ -85,42 +86,43 @@ public void test1() { System.out.println("LiNGAM"); // We send any small value in W to 0 that has absolute value below a given threshold. - double wThreshold = 0.1; - double pruneFactor = 0.3; - System.out.println("wThreshold = " + wThreshold); - System.out.println("LiNGAM Prune factor = " + pruneFactor); + // We do no further pruning on the B matrix. (The algorithm spec wants us to do both + // but pruning the W matrix seems to be giving better results, and besides in LiNG-D + // the W matrix is pruned. Could switch though.) + double wThreshold = 0.25; + double bThreshold = 0; + System.out.println("W Threshold = " + wThreshold); + System.out.println("B threshold = " + bThreshold); Lingam lingam = new Lingam(); - lingam.setPruneFactor(pruneFactor); + lingam.setPruneFactor(bThreshold); Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); System.out.println("Lingam graph = " + g2); + Matrix lingamBhat = lingam.getPermutedBHat(); + boolean lingamStable = LingD.isStable(lingamBhat); + System.out.println(lingamStable ? "Is Stable" : "Not stable"); + // Next we try LiNG-D. System.out.println("LiNG-D"); - LingD ling = new LingD(); - + // For LiNG-D, we can just call the relevant public static methods. This was obviously written + // by a Matlab person. + // // We generate pairs of column permutations (solving the constriained N Rooks problem) with their // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. - List pairs = ling.search(W, wThreshold); + List pairs = LingD.nRooks(LingD.threshold(W, wThreshold)); System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { - - // We print the B Hat matrix; this is the matrix of coefficients for the implied linear moodel. - System.out.println("\nPermuted Variables = " + LingD.getPermutedVariables(pair, dataSet.getVariables())); - System.out.println("\nPermuted Thresholded W matrix = \n" + LingD.getPermutedThresholdedW(pair)); - System.out.println("\nPermuted Unscaled BHat = \n" + LingD.getPermutedUnscaledBHat(pair)); - System.out.println("\nPermuted Scaled BHat = \n" + LingD.getPermutedScaledBHat(pair)); - - // We print the corresponding graph. - Graph graph = LingD.getGraph(pair, dataSet.getVariables()); - + Matrix bHat = getPermutedScaledBHat(pair); + List permVars = getPermutedVariables(pair, dataSet.getVariables()); + Graph graph = LingD.makeGraph(bHat, permVars); System.out.println("\nGraph = " + graph); - boolean stable = edu.cmu.tetrad.algcomparison.algorithm.continuous.dag.Lingam.isStable(pair); // Finally we print a judgment of whether the BHat model is stable and cyclic. + boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); System.out.println(stable ? "Is Stable" : "Not stable"); } } From 3497c6d6e4b98a2d2973e8d9ecf21b59c991a528 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 27 Apr 2023 14:53:26 -0400 Subject: [PATCH 039/464] This version of LiNGAM and LiNG basically works. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 8 ++------ .../src/test/java/edu/cmu/tetrad/test/TestLing.java | 7 +++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index b3db0d8b19..d9206dc2d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -125,7 +125,7 @@ public static int[] encourageLowerTriangular(Matrix W, Matrix BHat) { @Nullable static PermutationMatrixPair strongestDiagonalByCols(Matrix thresholded) { - List pairs = nRooks(thresholded.transpose()); + List pairs = search(thresholded.transpose()); PermutationMatrixPair bestPair = null; double sum1 = Double.POSITIVE_INFINITY; @@ -204,9 +204,8 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT return result11.getW(); } - public static List nRooks(Matrix W) { + public static List search(Matrix W) { List pairs = new ArrayList<>(); - boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; for (int i = 0; i < W.rows(); i++) { @@ -215,11 +214,8 @@ public static List nRooks(Matrix W) { } } -// printAllowablePositions(W, allowablePositions); - List colPermutations = NRooks.nRooks(allowablePositions); - //for each assignment, add the corresponding permutation to 'pairs' for (int[] colPermutation : colPermutations) { pairs.add(new PermutationMatrixPair(W, null, colPermutation)); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index ab92553be0..15bb196a71 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -103,16 +103,15 @@ public void test1() { boolean lingamStable = LingD.isStable(lingamBhat); System.out.println(lingamStable ? "Is Stable" : "Not stable"); - // Next we try LiNG-D. - System.out.println("LiNG-D"); - // For LiNG-D, we can just call the relevant public static methods. This was obviously written // by a Matlab person. // // We generate pairs of column permutations (solving the constriained N Rooks problem) with their // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. - List pairs = LingD.nRooks(LingD.threshold(W, wThreshold)); + System.out.println("LiNG-D"); + + List pairs = LingD.search(LingD.threshold(W, wThreshold)); System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { From d12ce8476888981649ee4b13b47f56064806e7cc Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 27 Apr 2023 15:02:53 -0400 Subject: [PATCH 040/464] This version of LiNGAM and LiNG basically works. --- .../java/edu/cmu/tetrad/search/LingD.java | 84 ++++++++----------- .../java/edu/cmu/tetrad/search/Lingam.java | 5 -- .../java/edu/cmu/tetrad/test/TestLing.java | 6 +- 3 files changed, 36 insertions(+), 59 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index d9206dc2d7..e3629052ec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -48,6 +48,8 @@ */ public class LingD { + private double wThreshold; + /** * Constructor. The W matrix needs to be estimated separately (e.g., using * the Lingam.estimateW(.) method using the ICA method in Tetrad, or some @@ -56,49 +58,47 @@ public class LingD { public LingD() { } + public List search(Matrix W) { + W = LingD.threshold(W, wThreshold); + return nRooks(W); + } + @NotNull - public static Graph makeGraph(Matrix bHat, List varPerm) { - Graph g = new EdgeListGraph(varPerm); + private static List nRooks(Matrix W) { + List pairs = new ArrayList<>(); + boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; - for (int j = 0; j < bHat.columns(); j++) { - for (int i = 0; i < bHat.rows(); i++) { - if (i == j) continue; - if (bHat.get(i, j) != 0) { - g.addDirectedEdge(varPerm.get(j), varPerm.get(i)); - } + for (int i = 0; i < W.rows(); i++) { + for (int j = 0; j < W.columns(); j++) { + allowablePositions[i][j] = W.get(i, j) != 0; } } - return g; + + List colPermutations = NRooks.nRooks(allowablePositions); + + for (int[] colPermutation : colPermutations) { + pairs.add(new PermutationMatrixPair(W, null, colPermutation)); + } + + return pairs; } - /** - * Returns the estimated graph for the given column permutation of the - * thresholded W matrix, with self-loops. (We are assuming for purposes of - * the LiNG-D algorithm that all variables have self-loops.) - * @param pair The (column permutation, thresholded, column permuted W matrix) - * pair. - * @param variables The variables in the order in which they occur in the - * original dataset being analyzed. - * @return The estimated graph for this pair. - */ - public static Graph makeGraph1(PermutationMatrixPair pair, List variables) { - List permVars = getPermutedVariables(pair, variables); - Matrix bHat = getPermutedScaledBHat(pair); - Graph g = new EdgeListGraph(permVars); - for (int i = 0; i < permVars.size(); i++) { - for (int j = 0; j < permVars.size(); j++) { + @NotNull + public static Graph makeGraph(Matrix bHat, List varPerm) { + Graph g = new EdgeListGraph(varPerm); + + for (int j = 0; j < bHat.columns(); j++) { + for (int i = 0; i < bHat.rows(); i++) { if (i == j) continue; if (bHat.get(i, j) != 0) { - g.addDirectedEdge(permVars.get(j), permVars.get(i)); + g.addDirectedEdge(varPerm.get(j), varPerm.get(i)); } } } - return g; } - @NotNull public static int[] encourageLowerTriangular(Matrix W, Matrix BHat) { PermutationGenerator gen2 = new PermutationGenerator(BHat.rows()); int[] perm = new int[0]; @@ -125,7 +125,7 @@ public static int[] encourageLowerTriangular(Matrix W, Matrix BHat) { @Nullable static PermutationMatrixPair strongestDiagonalByCols(Matrix thresholded) { - List pairs = search(thresholded.transpose()); + List pairs = nRooks(thresholded.transpose()); PermutationMatrixPair bestPair = null; double sum1 = Double.POSITIVE_INFINITY; @@ -204,25 +204,6 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT return result11.getW(); } - public static List search(Matrix W) { - List pairs = new ArrayList<>(); - boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; - - for (int i = 0; i < W.rows(); i++) { - for (int j = 0; j < W.columns(); j++) { - allowablePositions[i][j] = W.get(i, j) != 0; - } - } - - List colPermutations = NRooks.nRooks(allowablePositions); - - for (int[] colPermutation : colPermutations) { - pairs.add(new PermutationMatrixPair(W, null, colPermutation)); - } - - return pairs; - } - /** * Scares the given matrix M by diving each entry (i, j) by M(j, j) * @@ -311,9 +292,6 @@ public static List getPermutedVariables(PermutationMatrixPair pair, return permVars; } - - - private static void printAllowablePositions(Matrix W, boolean[][] allowablePositions) { System.out.println("\nAllowable rook positions"); @@ -328,6 +306,10 @@ private static void printAllowablePositions(Matrix W, boolean[][] allowablePosit System.out.println(); System.out.println(); } + + public void setWThreshold(double wThreshold) { + this.wThreshold = wThreshold; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 650f181657..2139f4884d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -29,7 +29,6 @@ import java.util.List; import static edu.cmu.tetrad.search.LingD.threshold; -import static java.lang.StrictMath.abs; /** *

    Implements the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, and Kerminen, A linear @@ -38,8 +37,6 @@ * @author josephramsey */ public class Lingam { - private double pruneFactor = 0.3; - private double wThreshold = 0.0; private Matrix permutedBHat = null; private List permutedVars = null; @@ -103,7 +100,6 @@ public Graph search(Matrix W, List variables, double wThreshold) { // Make the graph and return it. return LingD.makeGraph(bHatPerm, varPerm); -// return LingD.makeGraph(LingD.threshold(bHatPerm, pruneFactor), varPerm); } /** @@ -113,7 +109,6 @@ public Graph search(Matrix W, List variables, double wThreshold) { */ public void setPruneFactor(double pruneFactor) { if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); - this.pruneFactor = pruneFactor; } /** diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 15bb196a71..a90da73d1f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -110,8 +110,9 @@ public void test1() { // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); - - List pairs = LingD.search(LingD.threshold(W, wThreshold)); + LingD lingD = new LingD(); + lingD.setWThreshold(wThreshold); + List pairs = lingD.search(W); System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { @@ -120,7 +121,6 @@ public void test1() { Graph graph = LingD.makeGraph(bHat, permVars); System.out.println("\nGraph = " + graph); - // Finally we print a judgment of whether the BHat model is stable and cyclic. boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); System.out.println(stable ? "Is Stable" : "Not stable"); } From b3c48509d62d3ed93e15a995505f3c1b62fe8629 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 27 Apr 2023 15:45:51 -0400 Subject: [PATCH 041/464] Fixed nodes sorting issue in graph to txt display, so that X1...X20 comes out in the right order, e.g. --- .../main/java/edu/cmu/tetrad/graph/Edges.java | 4 +- .../java/edu/cmu/tetrad/search/Lingam.java | 2 +- .../java/edu/cmu/tetrad/test/TestLing.java | 60 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java index b84853fcd0..af8b4e2ee1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java @@ -317,8 +317,8 @@ public static void sortEdges(List edges) { return compareProperty; } - int compareLeft = left1.toString().compareTo(left2.toString()); - int compareRight = right1.toString().compareTo(right2.toString()); + int compareLeft = left1.compareTo(left2); + int compareRight = right1.compareTo(right2); if (compareLeft != 0) { return compareLeft; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 2139f4884d..8ac810d31b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -58,7 +58,7 @@ public Lingam() { */ public Graph search(Matrix W, List variables, double wThreshold) { Matrix thresholded = threshold(W, wThreshold); - W = thresholded; +// W = thresholded; PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(thresholded); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index a90da73d1f..09e5ace3d2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -27,13 +27,11 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.LingD; -import edu.cmu.tetrad.search.Lingam; import edu.cmu.tetrad.search.NRooks; import edu.cmu.tetrad.search.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; -import edu.cmu.tetrad.util.RandomUtil; import org.junit.Test; import java.util.Arrays; @@ -55,13 +53,13 @@ public void test1() { // uses Exp(1) non-Gaussian errors and otherwise default parameters. // We're not using bootstrapping yet here, which could make the result // more accurate. - long seed = 402030204L; - RandomUtil.getInstance().setSeed(seed); - System.out.println("Seed = " + seed + "L"); - System.out.println(); +// long seed = 402030204L; +// RandomUtil.getInstance().setSeed(seed); +// System.out.println("Seed = " + seed + "L"); +// System.out.println(); Parameters parameters = new Parameters(); - parameters.set(Params.NUM_MEASURES, 6); + parameters.set(Params.NUM_MEASURES, 40); parameters.set(Params.AVG_DEGREE, 2); // Using Exp(1) for the non-Gaussian error for all variables. @@ -74,8 +72,14 @@ public void test1() { Graph g = sim.getTrueGraph(0); System.out.println("True graph = " + g); + double wThreshold = 0.4; + double bThreshold = 0; + + System.out.println("W Threshold = " + wThreshold); + System.out.println("B threshold = " + bThreshold); + // First we use ICA to estimate the W matrix. - Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); + Matrix W = LingD.estimateW(dataSet, 5000, 1e-8, 1.2); // We then apply LiNGAM with a prune factor of .3. We should get a mostly correct DAG // back. The "prune factor" is a threshold for the B Hat matrix below which values are @@ -83,25 +87,21 @@ public void test1() { // exceed the prune factor are reported as edges in the model. Self-loops are not reported // in the printed graphs but are assumed ot exist for purposes of this algorithm. The // B Hat matrices are scaled so that self-loops always have strength 1. - System.out.println("LiNGAM"); - - // We send any small value in W to 0 that has absolute value below a given threshold. - // We do no further pruning on the B matrix. (The algorithm spec wants us to do both - // but pruning the W matrix seems to be giving better results, and besides in LiNG-D - // the W matrix is pruned. Could switch though.) - double wThreshold = 0.25; - double bThreshold = 0; - System.out.println("W Threshold = " + wThreshold); - System.out.println("B threshold = " + bThreshold); - - Lingam lingam = new Lingam(); - lingam.setPruneFactor(bThreshold); - Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); - System.out.println("Lingam graph = " + g2); - - Matrix lingamBhat = lingam.getPermutedBHat(); - boolean lingamStable = LingD.isStable(lingamBhat); - System.out.println(lingamStable ? "Is Stable" : "Not stable"); + System.out.println("=====LiNGAM"); +// +// // We send any small value in W to 0 that has absolute value below a given threshold. +// // We do no further pruning on the B matrix. (The algorithm spec wants us to do both +// // but pruning the W matrix seems to be giving better results, and besides in LiNG-D +// // the W matrix is pruned. Could switch though.) +// +// Lingam lingam = new Lingam(); +// lingam.setPruneFactor(bThreshold); +// Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); +// System.out.println("Lingam graph = " + g2); +// +// Matrix lingamBhat = lingam.getPermutedBHat(); +// boolean lingamStable = LingD.isStable(lingamBhat); +// System.out.println(lingamStable ? "Is Stable" : "Not stable"); // For LiNG-D, we can just call the relevant public static methods. This was obviously written // by a Matlab person. @@ -109,7 +109,7 @@ public void test1() { // We generate pairs of column permutations (solving the constriained N Rooks problem) with their // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. - System.out.println("LiNG-D"); + System.out.println("\n\n=====LiNG-D"); LingD lingD = new LingD(); lingD.setWThreshold(wThreshold); List pairs = lingD.search(W); @@ -121,8 +121,8 @@ public void test1() { Graph graph = LingD.makeGraph(bHat, permVars); System.out.println("\nGraph = " + graph); - boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); - System.out.println(stable ? "Is Stable" : "Not stable"); +// boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); +// System.out.println(stable ? "Is Stable" : "Not stable"); } } From 1e324e466530234d4215ef3db4b4591614380db3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 27 Apr 2023 17:37:07 -0400 Subject: [PATCH 042/464] Fixing depth to -1 for BOSS in PermutationBes. Removing settings for it and removing the depth parameter for BOSS. --- .../algorithm/continuous/dag/Lingam.java | 1 - .../algorithm/oracle/cpdag/Boss.java | 4 +-- .../main/java/edu/cmu/tetrad/search/BFci.java | 2 +- .../main/java/edu/cmu/tetrad/search/Boss.java | 8 ++--- .../java/edu/cmu/tetrad/search/Lingam.java | 9 ------ .../edu/cmu/tetrad/search/PermutationBes.java | 10 +++--- .../java/edu/cmu/tetrad/test/TestLing.java | 31 ++++++++++--------- 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 40329cdf1a..c1bdaf6397 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -48,7 +48,6 @@ public Graph search(DataModel dataSet, Parameters parameters) { Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setPruneFactor(pruneFactor); return lingam.search(W, data.getVariables(), pruneFactor); } else { Lingam algorithm = new Lingam(); 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 78245d333d..921696b61c 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 @@ -68,7 +68,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { Score score = this.score.getScore(dataModel, parameters); edu.cmu.tetrad.search.Boss boss = new edu.cmu.tetrad.search.Boss(score); - boss.setDepth(parameters.getInt(Params.DEPTH)); +// boss.setDepth(parameters.getInt(Params.DEPTH)); boss.setNumStarts(parameters.getInt(Params.NUM_STARTS)); PermutationSearch permutationSearch = new PermutationSearch(boss); permutationSearch.setKnowledge(this.knowledge); @@ -115,7 +115,7 @@ public List getParameters() { // Parameters params.add(Params.NUM_STARTS); - params.add(Params.DEPTH); +// params.add(Params.DEPTH); return params; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index dbcbab2e5f..b8a9b42919 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -116,7 +116,7 @@ public Graph search() { // BOSS CPDAG learning step Boss subAlg = new Boss(this.score); - subAlg.setDepth(this.depth); +// subAlg.setDepth(this.depth); subAlg.setNumStarts(this.numStarts); PermutationSearch alg = new PermutationSearch(subAlg); alg.setKnowledge(this.knowledge); 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 8582a96f75..d713d84fbe 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 @@ -195,10 +195,10 @@ private void makeValidKnowledgeOrder(List order) { } } - public void setDepth(int depth) { - if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1."); - this.bes.setDepth(depth); - } +// public void setDepth(int depth) { +// if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1."); +// this.bes.setDepth(depth); +// } @Override public void setKnowledge(Knowledge knowledge) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 8ac810d31b..e80e2265e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -102,15 +102,6 @@ public Graph search(Matrix W, List variables, double wThreshold) { return LingD.makeGraph(bHatPerm, varPerm); } - /** - * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. - * - * @param pruneFactor Some value >= 0. - */ - public void setPruneFactor(double pruneFactor) { - if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); - } - /** * After search the permuted BHat matrix can be retrieved using this method. * 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 index 05e5034006..5cbfc9b610 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java @@ -27,7 +27,7 @@ public class PermutationBes { private final Score score; private Knowledge knowledge = new Knowledge(); private boolean verbose = true; - private int depth = 4; + private int depth = -1; public PermutationBes(@NotNull Score score) { this.score = score; @@ -47,10 +47,10 @@ 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; - } +// 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) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 09e5ace3d2..46d486f130 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.LingD; +import edu.cmu.tetrad.search.Lingam; import edu.cmu.tetrad.search.NRooks; import edu.cmu.tetrad.search.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; @@ -59,7 +60,7 @@ public void test1() { // System.out.println(); Parameters parameters = new Parameters(); - parameters.set(Params.NUM_MEASURES, 40); + parameters.set(Params.NUM_MEASURES, 10); parameters.set(Params.AVG_DEGREE, 2); // Using Exp(1) for the non-Gaussian error for all variables. @@ -79,7 +80,7 @@ public void test1() { System.out.println("B threshold = " + bThreshold); // First we use ICA to estimate the W matrix. - Matrix W = LingD.estimateW(dataSet, 5000, 1e-8, 1.2); + Matrix W = LingD.estimateW(dataSet, 5000, 1e-4, 2); // We then apply LiNGAM with a prune factor of .3. We should get a mostly correct DAG // back. The "prune factor" is a threshold for the B Hat matrix below which values are @@ -88,20 +89,20 @@ public void test1() { // in the printed graphs but are assumed ot exist for purposes of this algorithm. The // B Hat matrices are scaled so that self-loops always have strength 1. System.out.println("=====LiNGAM"); -// -// // We send any small value in W to 0 that has absolute value below a given threshold. -// // We do no further pruning on the B matrix. (The algorithm spec wants us to do both -// // but pruning the W matrix seems to be giving better results, and besides in LiNG-D -// // the W matrix is pruned. Could switch though.) -// -// Lingam lingam = new Lingam(); + + // We send any small value in W to 0 that has absolute value below a given threshold. + // We do no further pruning on the B matrix. (The algorithm spec wants us to do both + // but pruning the W matrix seems to be giving better results, and besides in LiNG-D + // the W matrix is pruned. Could switch though.) + + Lingam lingam = new Lingam(); // lingam.setPruneFactor(bThreshold); -// Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); -// System.out.println("Lingam graph = " + g2); -// -// Matrix lingamBhat = lingam.getPermutedBHat(); -// boolean lingamStable = LingD.isStable(lingamBhat); -// System.out.println(lingamStable ? "Is Stable" : "Not stable"); + Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); + System.out.println("Lingam graph = " + g2); + + Matrix lingamBhat = lingam.getPermutedBHat(); + boolean lingamStable = LingD.isStable(lingamBhat); + System.out.println(lingamStable ? "Is Stable" : "Not stable"); // For LiNG-D, we can just call the relevant public static methods. This was obviously written // by a Matlab person. From 8cb50c40cd3584b287a54dbe5e555de5e7fe6e8e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 02:41:13 -0400 Subject: [PATCH 043/464] Added a time lag parameter for BOSS. --- .../cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Boss.java | 2 ++ 1 file changed, 2 insertions(+) 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 921696b61c..325d5e39a9 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 @@ -116,6 +116,8 @@ public List getParameters() { // Parameters params.add(Params.NUM_STARTS); // params.add(Params.DEPTH); + params.add(Params.TIME_LAG); + return params; } From 24716cb015f65302033154f804fcf49bb213d916 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 03:39:31 -0400 Subject: [PATCH 044/464] Added a time lag parameter for BOSS. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 3 ++- .../src/test/java/edu/cmu/tetrad/test/TestLing.java | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index e3629052ec..94c2d6fee3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -55,7 +55,8 @@ public class LingD { * the Lingam.estimateW(.) method using the ICA method in Tetrad, or some * method in Python or R) and passed into the search(W) method. */ - public LingD() { + public LingD(double wThreshold) { + this.wThreshold = wThreshold; } public List search(Matrix W) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 46d486f130..48d935f617 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -64,8 +64,9 @@ public void test1() { parameters.set(Params.AVG_DEGREE, 2); // Using Exp(1) for the non-Gaussian error for all variables. - parameters.set(Params.SIMULATION_ERROR_TYPE, 3); + parameters.set(Params.SIMULATION_ERROR_TYPE, 4); parameters.set(Params.SIMULATION_PARAM1, 1); + parameters.set(Params.SIMULATION_PARAM2, 1); SemSimulation sim = new SemSimulation(new RandomForward()); sim.createData(parameters, true); @@ -73,7 +74,7 @@ public void test1() { Graph g = sim.getTrueGraph(0); System.out.println("True graph = " + g); - double wThreshold = 0.4; + double wThreshold = 0.3; double bThreshold = 0; System.out.println("W Threshold = " + wThreshold); @@ -111,8 +112,7 @@ public void test1() { // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("\n\n=====LiNG-D"); - LingD lingD = new LingD(); - lingD.setWThreshold(wThreshold); + LingD lingD = new LingD(wThreshold); List pairs = lingD.search(W); System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); From f86e126496052cead97a1be17d611841d2d7c469 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:02:55 -0400 Subject: [PATCH 045/464] Work on LiNG/LiNGAM. --- .../algorithm/continuous/dag/Lingam.java | 3 +- .../java/edu/cmu/tetrad/search/LingD.java | 13 +++--- .../java/edu/cmu/tetrad/search/Lingam.java | 21 ++++++++-- .../java/edu/cmu/tetrad/test/TestLing.java | 42 +++++++++---------- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index c1bdaf6397..667b8e9f8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -48,7 +48,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - return lingam.search(W, data.getVariables(), pruneFactor); + lingam.setWThreshold(pruneFactor); + return lingam.search(W, data.getVariables()); } else { Lingam algorithm = new Lingam(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 94c2d6fee3..6331db96a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -55,8 +55,7 @@ public class LingD { * the Lingam.estimateW(.) method using the ICA method in Tetrad, or some * method in Python or R) and passed into the search(W) method. */ - public LingD(double wThreshold) { - this.wThreshold = wThreshold; + public LingD() { } public List search(Matrix W) { @@ -91,7 +90,7 @@ public static Graph makeGraph(Matrix bHat, List varPerm) { for (int j = 0; j < bHat.columns(); j++) { for (int i = 0; i < bHat.rows(); i++) { - if (i == j) continue; +// if (i == j) continue; if (bHat.get(i, j) != 0) { g.addDirectedEdge(varPerm.get(j), varPerm.get(i)); } @@ -196,7 +195,7 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT FastIca fastIca = new FastIca(X, X.rows()); fastIca.setVerbose(false); fastIca.setMaxIterations(fastIcaMaxIter); - fastIca.setAlgorithmType(FastIca.DEFLATION); + fastIca.setAlgorithmType(FastIca.PARALLEL); fastIca.setTolerance(fastIcaTolerance); fastIca.setFunction(FastIca.EXP); fastIca.setRowNorm(false); @@ -253,8 +252,8 @@ public static Matrix threshold(Matrix M, double threshold) { */ public static Matrix getPermutedScaledBHat(PermutationMatrixPair pair) { Matrix _w = pair.getPermutedMatrix(); - Matrix bHat = Matrix.identity(_w.rows()).minus(_w); - return scale(bHat); + _w = scale(_w); + return Matrix.identity(_w.rows()).minus(_w); } /** @@ -281,7 +280,7 @@ public static Matrix getPermutedUnscaledBHat(PermutationMatrixPair pair) { } public static List getPermutedVariables(PermutationMatrixPair pair, - List variables) { + List variables) { int[] perm = pair.getColPerm(); List permVars = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index e80e2265e7..505e7f2bcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -39,6 +39,7 @@ public class Lingam { private Matrix permutedBHat = null; private List permutedVars = null; + private double wThreshold; //================================CONSTRUCTORS==========================// @@ -56,11 +57,10 @@ public Lingam() { * in the order they occur in that dataset. * @return The graph returned. */ - public Graph search(Matrix W, List variables, double wThreshold) { - Matrix thresholded = threshold(W, wThreshold); -// W = thresholded; + public Graph search(Matrix W, List variables) { + W = threshold(W, wThreshold); - PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(thresholded); + PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); if (bestPair == null) { throw new NullPointerException("Could not find an N Rooks solution with that threshold."); @@ -102,6 +102,15 @@ public Graph search(Matrix W, List variables, double wThreshold) { return LingD.makeGraph(bHatPerm, varPerm); } + /** + * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. + * + * @param pruneFactor Some value >= 0. + */ + public void setPruneFactor(double pruneFactor) { + if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); + } + /** * After search the permuted BHat matrix can be retrieved using this method. * @@ -120,5 +129,9 @@ public Matrix getPermutedBHat() { public List getPermutedVars() { return permutedVars; } + + public void setWThreshold(double wThreshold) { + this.wThreshold = wThreshold; + } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 48d935f617..00a98334a6 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -33,6 +33,7 @@ import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; +import edu.cmu.tetrad.util.RandomUtil; import org.junit.Test; import java.util.Arrays; @@ -54,19 +55,18 @@ public void test1() { // uses Exp(1) non-Gaussian errors and otherwise default parameters. // We're not using bootstrapping yet here, which could make the result // more accurate. -// long seed = 402030204L; -// RandomUtil.getInstance().setSeed(seed); -// System.out.println("Seed = " + seed + "L"); -// System.out.println(); + long seed = 402030204L; + RandomUtil.getInstance().setSeed(seed); + System.out.println("Seed = " + seed + "L"); + System.out.println(); Parameters parameters = new Parameters(); - parameters.set(Params.NUM_MEASURES, 10); + parameters.set(Params.NUM_MEASURES, 6); parameters.set(Params.AVG_DEGREE, 2); // Using Exp(1) for the non-Gaussian error for all variables. - parameters.set(Params.SIMULATION_ERROR_TYPE, 4); + parameters.set(Params.SIMULATION_ERROR_TYPE, 3); parameters.set(Params.SIMULATION_PARAM1, 1); - parameters.set(Params.SIMULATION_PARAM2, 1); SemSimulation sim = new SemSimulation(new RandomForward()); sim.createData(parameters, true); @@ -74,14 +74,8 @@ public void test1() { Graph g = sim.getTrueGraph(0); System.out.println("True graph = " + g); - double wThreshold = 0.3; - double bThreshold = 0; - - System.out.println("W Threshold = " + wThreshold); - System.out.println("B threshold = " + bThreshold); - // First we use ICA to estimate the W matrix. - Matrix W = LingD.estimateW(dataSet, 5000, 1e-4, 2); + Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); // We then apply LiNGAM with a prune factor of .3. We should get a mostly correct DAG // back. The "prune factor" is a threshold for the B Hat matrix below which values are @@ -89,16 +83,18 @@ public void test1() { // exceed the prune factor are reported as edges in the model. Self-loops are not reported // in the printed graphs but are assumed ot exist for purposes of this algorithm. The // B Hat matrices are scaled so that self-loops always have strength 1. - System.out.println("=====LiNGAM"); + System.out.println("LiNGAM"); // We send any small value in W to 0 that has absolute value below a given threshold. // We do no further pruning on the B matrix. (The algorithm spec wants us to do both // but pruning the W matrix seems to be giving better results, and besides in LiNG-D // the W matrix is pruned. Could switch though.) + double wThreshold = 0.25; + System.out.println("W Threshold = " + wThreshold); Lingam lingam = new Lingam(); -// lingam.setPruneFactor(bThreshold); - Graph g2 = lingam.search(W, dataSet.getVariables(), wThreshold); + lingam.setWThreshold(wThreshold); + Graph g2 = lingam.search(W, dataSet.getVariables()); System.out.println("Lingam graph = " + g2); Matrix lingamBhat = lingam.getPermutedBHat(); @@ -111,19 +107,23 @@ public void test1() { // We generate pairs of column permutations (solving the constriained N Rooks problem) with their // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. - System.out.println("\n\n=====LiNG-D"); - LingD lingD = new LingD(wThreshold); + System.out.println("LiNG-D"); + LingD lingD = new LingD(); + lingD.setWThreshold(wThreshold); List pairs = lingD.search(W); System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { Matrix bHat = getPermutedScaledBHat(pair); + + System.out.println("BHat = " + bHat); + List permVars = getPermutedVariables(pair, dataSet.getVariables()); Graph graph = LingD.makeGraph(bHat, permVars); System.out.println("\nGraph = " + graph); -// boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); -// System.out.println(stable ? "Is Stable" : "Not stable"); + boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); + System.out.println(stable ? "Is Stable" : "Not stable"); } } From a78837fa955d2c32e8e3a778bef75f5ba6fc2182 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:06:54 -0400 Subject: [PATCH 046/464] Work on LiNG/LiNGAM. --- .../algcomparison/algorithm/continuous/dag/Lingam.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 8 ++++---- .../src/main/java/edu/cmu/tetrad/search/Lingam.java | 9 +++------ .../src/test/java/edu/cmu/tetrad/test/TestLing.java | 8 ++++---- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 667b8e9f8f..c136c05b35 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -48,7 +48,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setWThreshold(pruneFactor); + lingam.setPruneFactor(pruneFactor); return lingam.search(W, data.getVariables()); } else { Lingam algorithm = new Lingam(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 6331db96a6..8b12dfb801 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -48,7 +48,7 @@ */ public class LingD { - private double wThreshold; + private double pruneThreshold; /** * Constructor. The W matrix needs to be estimated separately (e.g., using @@ -59,7 +59,7 @@ public LingD() { } public List search(Matrix W) { - W = LingD.threshold(W, wThreshold); + W = LingD.threshold(W, pruneThreshold); return nRooks(W); } @@ -307,8 +307,8 @@ private static void printAllowablePositions(Matrix W, boolean[][] allowablePosit System.out.println(); } - public void setWThreshold(double wThreshold) { - this.wThreshold = wThreshold; + public void setPruneFactor(double pruneFactor) { + this.pruneThreshold = pruneFactor; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 505e7f2bcf..26b46e2def 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -39,7 +39,7 @@ public class Lingam { private Matrix permutedBHat = null; private List permutedVars = null; - private double wThreshold; + private double pruneFactor; //================================CONSTRUCTORS==========================// @@ -58,7 +58,7 @@ public Lingam() { * @return The graph returned. */ public Graph search(Matrix W, List variables) { - W = threshold(W, wThreshold); + W = threshold(W, pruneFactor); PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); @@ -109,6 +109,7 @@ public Graph search(Matrix W, List variables) { */ public void setPruneFactor(double pruneFactor) { if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); + this.pruneFactor = pruneFactor; } /** @@ -129,9 +130,5 @@ public Matrix getPermutedBHat() { public List getPermutedVars() { return permutedVars; } - - public void setWThreshold(double wThreshold) { - this.wThreshold = wThreshold; - } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 00a98334a6..0305fa331f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -89,11 +89,11 @@ public void test1() { // We do no further pruning on the B matrix. (The algorithm spec wants us to do both // but pruning the W matrix seems to be giving better results, and besides in LiNG-D // the W matrix is pruned. Could switch though.) - double wThreshold = 0.25; - System.out.println("W Threshold = " + wThreshold); + double pruneThreshold = 0.25; + System.out.println("Prune threshold = " + pruneThreshold); Lingam lingam = new Lingam(); - lingam.setWThreshold(wThreshold); + lingam.setPruneFactor(pruneThreshold); Graph g2 = lingam.search(W, dataSet.getVariables()); System.out.println("Lingam graph = " + g2); @@ -109,7 +109,7 @@ public void test1() { // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); LingD lingD = new LingD(); - lingD.setWThreshold(wThreshold); + lingD.setPruneFactor(pruneThreshold); List pairs = lingD.search(W); System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); From d4c3053c9448363826f199f4bf65475c05ed82ac Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:07:08 -0400 Subject: [PATCH 047/464] Work on LiNG/LiNGAM. --- .../tetrad/algcomparison/algorithm/continuous/dag/Lingam.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index c136c05b35..953de38376 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -18,8 +18,6 @@ import java.util.ArrayList; import java.util.List; -import static org.apache.commons.math3.util.FastMath.pow; - /** * LiNGAM. * From 5463021ab817ea7194d306bd10c555bb69ff5bd8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:24:44 -0400 Subject: [PATCH 048/464] Work on LiNG/LiNGAM. --- .../java/edu/cmu/tetrad/search/LingD.java | 140 ++++++++++++------ .../java/edu/cmu/tetrad/search/Lingam.java | 2 +- 2 files changed, 97 insertions(+), 45 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 8b12dfb801..8933813e7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -58,49 +58,60 @@ public class LingD { public LingD() { } + /** + * Performs the LiNG-D algorithm given a W matrix, which needs to be discovered + * elsewhere. The local algorithm is assumed--in fact, the W matrix is simply + * thresholded without bootstrapping. + * @param W The W matrix to be used. + * @return A list of models, as PermutationMatrixPairs (see). + * @see PermutationMatrixPair + */ public List search(Matrix W) { W = LingD.threshold(W, pruneThreshold); return nRooks(W); } - @NotNull - private static List nRooks(Matrix W) { - List pairs = new ArrayList<>(); - boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; - - for (int i = 0; i < W.rows(); i++) { - for (int j = 0; j < W.columns(); j++) { - allowablePositions[i][j] = W.get(i, j) != 0; - } - } - - List colPermutations = NRooks.nRooks(allowablePositions); - - for (int[] colPermutation : colPermutations) { - pairs.add(new PermutationMatrixPair(W, null, colPermutation)); - } - - return pairs; + /** + * Sets the threshold used to prune the W matrix for the local algorithms. + * @param pruneFactor The treshold, a non-negative number. + */ + public void setPruneFactor(double pruneFactor) { + this.pruneThreshold = pruneFactor; } - + /** + * Returns a graph given a coefficient matrix and a list of variables. It is + * assumed that any non-zero entry in B corresponds to a directed edges, so + * that Bij != 0 implies that j->i in the graph. + * @param B The coefficient matrix. + * @param variables The list of variables. + * @return The built graph. + */ @NotNull - public static Graph makeGraph(Matrix bHat, List varPerm) { - Graph g = new EdgeListGraph(varPerm); - - for (int j = 0; j < bHat.columns(); j++) { - for (int i = 0; i < bHat.rows(); i++) { -// if (i == j) continue; - if (bHat.get(i, j) != 0) { - g.addDirectedEdge(varPerm.get(j), varPerm.get(i)); + public static Graph makeGraph(Matrix B, List variables) { + Graph g = new EdgeListGraph(variables); + + for (int j = 0; j < B.columns(); j++) { + for (int i = 0; i < B.rows(); i++) { + if (B.get(i, j) != 0) { + g.addDirectedEdge(variables.get(j), variables.get(i)); } } } return g; } - public static int[] encourageLowerTriangular(Matrix W, Matrix BHat) { - PermutationGenerator gen2 = new PermutationGenerator(BHat.rows()); + /** + * Finds a permutation of rows and columns simultaneously for a + * coefficient matrix B that maximizes the sum of Bij^2 values in + * the lower triangle. This is to help find a causal order for the + * variables assuming a DAG model. + * @param B The coefficient matrix B + * @return The permutation of rows and columns simultaneously that + * maximizes the lower triangle. + */ + public static int[] encourageLowerTriangular(Matrix B) { + PermutationGenerator gen2 = new PermutationGenerator(B.rows()); int[] perm = new int[0]; double sum2 = Double.NEGATIVE_INFINITY; int[] choice2; @@ -108,9 +119,9 @@ public static int[] encourageLowerTriangular(Matrix W, Matrix BHat) { while ((choice2 = gen2.next()) != null) { double sum = 0.0; - for (int i = 0; i < W.rows(); i++) { + for (int i = 0; i < B.rows(); i++) { for (int j = 0; j < i; j++) { - double b = BHat.get(choice2[i], choice2[j]); + double b = B.get(choice2[i], choice2[j]); sum += b * b; } } @@ -120,12 +131,21 @@ public static int[] encourageLowerTriangular(Matrix W, Matrix BHat) { perm = Arrays.copyOf(choice2, choice2.length); } } + return perm; } + /** + * Finds a column permutation of the W matrix that maximizes the sum + * of 1 / |Wii| for diagonal elements Wii in W. This will be speeded up + * if W is a thresholded matrix. + * @param W The (possibly thresholded) W matrix. + * @return The model with the strongest diagonal, as a permutation matrix pair. + * @see PermutationMatrixPair + */ @Nullable - static PermutationMatrixPair strongestDiagonalByCols(Matrix thresholded) { - List pairs = nRooks(thresholded.transpose()); + static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { + List pairs = nRooks(W.transpose()); PermutationMatrixPair bestPair = null; double sum1 = Double.POSITIVE_INFINITY; @@ -155,8 +175,8 @@ static PermutationMatrixPair strongestDiagonalByCols(Matrix thresholded) { } /** - * Whether the BHat matrix represents a stable model. The eigenvalues are checked ot make sure they are - * all less than 1. + * Whether the BHat matrix represents a stable model. The eigenvalues are + * checked ot make sure they are all less than 1 in modulus. * @param bHat The bHat matrix. * @return True iff the model is stable. */ @@ -181,7 +201,8 @@ public static boolean isStable(Matrix bHat) { } /** - * Estimates the W matrix using FastICA. + * Estimates the W matrix using FastICA. Assumes the "parallel" option, using + * the "exp" function. * * @param data The dataset to estimate W for. * @param fastIcaMaxIter Maximum number of iterations of ICA. @@ -189,7 +210,8 @@ public static boolean isStable(Matrix bHat) { * @param fastIcaA Alpha for ICA. * @return The estimated W matrix. */ - public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, double fastIcaA) { + public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, + double fastIcaA) { Matrix X = data.getDoubleData(); X = DataUtils.centerData(X).transpose(); FastIca fastIca = new FastIca(X, X.rows()); @@ -206,7 +228,6 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT /** * Scares the given matrix M by diving each entry (i, j) by M(j, j) - * * @param M The matrix to scale. * @return The scaled matrix. */ @@ -224,9 +245,9 @@ public static Matrix scale(Matrix M) { /** * Thresholds the givem matrix, sending any small entries to zero. - * * @param M The matrix to threshold. * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. + * Should be non-negative. * @return The thresholded matrix. */ public static Matrix threshold(Matrix M, double threshold) { @@ -249,6 +270,7 @@ public static Matrix threshold(Matrix M, double threshold) { * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. * @return The estimated B Hat matrix for this pair. + * @see PermutationMatrixPair */ public static Matrix getPermutedScaledBHat(PermutationMatrixPair pair) { Matrix _w = pair.getPermutedMatrix(); @@ -279,6 +301,13 @@ public static Matrix getPermutedUnscaledBHat(PermutationMatrixPair pair) { return Matrix.identity(_w.rows()).minus(_w); } + /** + * Returns the lsit of variables, permuted using the column permutation of + * the given PermutationMatrixPair. + * @param pair The pair whose column permutation is used. + * @param variables The list of variables. + * @return The permuted list of variables. + */ public static List getPermutedVariables(PermutationMatrixPair pair, List variables) { int[] perm = pair.getColPerm(); @@ -292,13 +321,19 @@ public static List getPermutedVariables(PermutationMatrixPair pair, return permVars; } - private static void printAllowablePositions(Matrix W, boolean[][] allowablePositions) { + /** + * Prints the allowable positions board for the NRooks class. + * @param allowablePositions The (boolean, rectangular) matrix of allowable + * positions. The (i, j) entry it true just in case + * a rook can be placed there. + */ + private static void printAllowablePositions(boolean[][] allowablePositions) { System.out.println("\nAllowable rook positions"); // Print allowable board. - for (int i = 0; i < W.rows(); i++) { + for (int i = 0; i < allowablePositions[0].length; i++) { System.out.println(); - for (int j = 0; j < W.columns(); j++) { + for (int j = 0; j < allowablePositions.length; j++) { System.out.print((allowablePositions[i][j] ? 1 : 0) + " "); } } @@ -307,9 +342,26 @@ private static void printAllowablePositions(Matrix W, boolean[][] allowablePosit System.out.println(); } - public void setPruneFactor(double pruneFactor) { - this.pruneThreshold = pruneFactor; + @NotNull + private static List nRooks(Matrix W) { + List pairs = new ArrayList<>(); + boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; + + for (int i = 0; i < W.rows(); i++) { + for (int j = 0; j < W.columns(); j++) { + allowablePositions[i][j] = W.get(i, j) != 0; + } + } + + List colPermutations = NRooks.nRooks(allowablePositions); + + for (int[] colPermutation : colPermutations) { + pairs.add(new PermutationMatrixPair(W, null, colPermutation)); + } + + return pairs; } + } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 26b46e2def..22ecdc428b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -78,7 +78,7 @@ public Graph search(Matrix W, List variables) { // If all the big coefficients are in the lower triangle, we can interpret it as a // DAG model. We will ignore any big coefficients left over in the upper triangle. // We will assume the diagonal of the BHat matrix is zero--i.e., no self-loops. - int[] perm = LingD.encourageLowerTriangular(W, BHat); + int[] perm = LingD.encourageLowerTriangular(BHat); // Grab that lower-triangle maximized version of the BHat matrix. Matrix bHatPerm = new PermutationMatrixPair(BHat, perm, perm).getPermutedMatrix(); From 14a4d68091e88b9241c3d56b8e730a4651e51c5b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:26:30 -0400 Subject: [PATCH 049/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 8933813e7a..b9a1caa2a9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -40,9 +40,11 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering + *

    This class implements the LiNG-D algorithm as well as a number of ancillary + * methods for LiNG-D and LiNGAM.

    + *

    Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering * cyclic causal models by independent components analysis. arXiv preprint - * arXiv:1206.3273. + * arXiv:1206.3273.

    * * @author josephramsey */ From afbe74ab450c8d6435691b877faeddc45a92eea1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:26:52 -0400 Subject: [PATCH 050/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index b9a1caa2a9..ad36129b78 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -363,7 +363,6 @@ private static List nRooks(Matrix W) { return pairs; } - } From e058a32c54e320e44d9153bd8f2faaf18e1fa27a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:27:26 -0400 Subject: [PATCH 051/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index ad36129b78..68eb94a74e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -50,7 +50,7 @@ */ public class LingD { - private double pruneThreshold; + private double pruneFactor; /** * Constructor. The W matrix needs to be estimated separately (e.g., using @@ -69,7 +69,7 @@ public LingD() { * @see PermutationMatrixPair */ public List search(Matrix W) { - W = LingD.threshold(W, pruneThreshold); + W = LingD.threshold(W, pruneFactor); return nRooks(W); } @@ -78,7 +78,7 @@ public List search(Matrix W) { * @param pruneFactor The treshold, a non-negative number. */ public void setPruneFactor(double pruneFactor) { - this.pruneThreshold = pruneFactor; + this.pruneFactor = pruneFactor; } /** From 56b94800b3e058a82ab6fbff04dea3cd8e28dcd4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:28:01 -0400 Subject: [PATCH 052/464] Work on LiNG/LiNGAM. --- .../src/test/java/edu/cmu/tetrad/test/TestLing.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 0305fa331f..14f8fb419b 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -89,11 +89,11 @@ public void test1() { // We do no further pruning on the B matrix. (The algorithm spec wants us to do both // but pruning the W matrix seems to be giving better results, and besides in LiNG-D // the W matrix is pruned. Could switch though.) - double pruneThreshold = 0.25; - System.out.println("Prune threshold = " + pruneThreshold); + double pruneFactor = 0.25; + System.out.println("Prune factor = " + pruneFactor); Lingam lingam = new Lingam(); - lingam.setPruneFactor(pruneThreshold); + lingam.setPruneFactor(pruneFactor); Graph g2 = lingam.search(W, dataSet.getVariables()); System.out.println("Lingam graph = " + g2); @@ -109,7 +109,7 @@ public void test1() { // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); LingD lingD = new LingD(); - lingD.setPruneFactor(pruneThreshold); + lingD.setPruneFactor(pruneFactor); List pairs = lingD.search(W); System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); From 3d73648e0a6310897dedc4c788553059878bb393 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:28:34 -0400 Subject: [PATCH 053/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 14f8fb419b..b362933042 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -115,7 +115,6 @@ public void test1() { System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { Matrix bHat = getPermutedScaledBHat(pair); - System.out.println("BHat = " + bHat); List permVars = getPermutedVariables(pair, dataSet.getVariables()); From df9f3b1588ef0e2173d6522d32a4b114db630064 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:31:12 -0400 Subject: [PATCH 054/464] Work on LiNG/LiNGAM. --- .../java/edu/cmu/tetrad/search/LingD.java | 21 ------------------- .../java/edu/cmu/tetrad/search/NRooks.java | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 68eb94a74e..5b8d22cb4e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -323,27 +323,6 @@ public static List getPermutedVariables(PermutationMatrixPair pair, return permVars; } - /** - * Prints the allowable positions board for the NRooks class. - * @param allowablePositions The (boolean, rectangular) matrix of allowable - * positions. The (i, j) entry it true just in case - * a rook can be placed there. - */ - private static void printAllowablePositions(boolean[][] allowablePositions) { - System.out.println("\nAllowable rook positions"); - - // Print allowable board. - for (int i = 0; i < allowablePositions[0].length; i++) { - System.out.println(); - for (int j = 0; j < allowablePositions.length; j++) { - System.out.print((allowablePositions[i][j] ? 1 : 0) + " "); - } - } - - System.out.println(); - System.out.println(); - } - @NotNull private static List nRooks(Matrix W) { List pairs = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 87c53c0452..7afd22383c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -101,4 +101,25 @@ private static boolean isValid(boolean[][] board, int row, int col) { return true; } + + /** + * Prints the allowable positions board for the NRooks class. + * @param allowablePositions The (boolean, rectangular) matrix of allowable + * positions. The (i, j) entry it true just in case + * a rook can be placed there. + */ + private static void printAllowablePositions(boolean[][] allowablePositions) { + System.out.println("\nAllowable rook positions"); + + // Print allowable board. + for (int i = 0; i < allowablePositions[0].length; i++) { + System.out.println(); + for (int j = 0; j < allowablePositions.length; j++) { + System.out.print((allowablePositions[i][j] ? 1 : 0) + " "); + } + } + + System.out.println(); + System.out.println(); + } } From 748301582310dedd3611d1c6db8083176371c63d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:31:56 -0400 Subject: [PATCH 055/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 5b8d22cb4e..25dd88cf21 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -146,7 +146,7 @@ public static int[] encourageLowerTriangular(Matrix B) { * @see PermutationMatrixPair */ @Nullable - static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { + public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { List pairs = nRooks(W.transpose()); PermutationMatrixPair bestPair = null; From 8b8db35357c89b378972bad1adaf86a479716ea5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:34:29 -0400 Subject: [PATCH 056/464] Work on LiNG/LiNGAM. --- .../java/edu/cmu/tetrad/search/Lingam.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 22ecdc428b..4c3eeee6f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -67,39 +67,28 @@ public Graph search(Matrix W, List variables) { } Matrix WTilde = bestPair.getPermutedMatrix().transpose(); - - // We calculate BHat as I - WTilde. WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); - - // The second task is to rearrange the BHat matrix by permuting rows and columns - // simultaneously so that the lower triangle is maximal--i.e., so that SUM(WTilde(i, j)^2) - // is maximal for j > i. The goal of this is to find a causal order for the variables. - // If all the big coefficients are in the lower triangle, we can interpret it as a - // DAG model. We will ignore any big coefficients left over in the upper triangle. - // We will assume the diagonal of the BHat matrix is zero--i.e., no self-loops. int[] perm = LingD.encourageLowerTriangular(BHat); - - // Grab that lower-triangle maximized version of the BHat matrix. - Matrix bHatPerm = new PermutationMatrixPair(BHat, perm, perm).getPermutedMatrix(); + Matrix permutedBHat = new PermutationMatrixPair(BHat, perm, perm).getPermutedMatrix(); // Set the upper triangle now to zero, since we are ignoring it for this DAG algorithm. - for (int i = 0; i < bHatPerm.rows(); i++) { - for (int j = i + 1; j < bHatPerm.columns(); j++) { - bHatPerm.set(i, j, 0.0); + for (int i = 0; i < permutedBHat.rows(); i++) { + for (int j = i + 1; j < permutedBHat.columns(); j++) { + permutedBHat.set(i, j, 0.0); } } // Permute the variables too for that order. - List varPerm = new ArrayList<>(); - for (int k : perm) varPerm.add(variables.get(k)); + List permutedVars = new ArrayList<>(); + for (int k : perm) permutedVars.add(variables.get(k)); // Grab the permuted BHat and variables. - this.permutedBHat = bHatPerm; - this.permutedVars = varPerm; + this.permutedBHat = permutedBHat; + this.permutedVars = permutedVars; // Make the graph and return it. - return LingD.makeGraph(bHatPerm, varPerm); + return LingD.makeGraph(permutedBHat, permutedVars); } /** From 9b4e76f4f0be24f97713ad7e2a0dbcb05058fc84 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:36:37 -0400 Subject: [PATCH 057/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 4c3eeee6f9..e6d0e1f027 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -63,7 +63,7 @@ public Graph search(Matrix W, List variables) { PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); if (bestPair == null) { - throw new NullPointerException("Could not find an N Rooks solution with that threshold."); + throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); } Matrix WTilde = bestPair.getPermutedMatrix().transpose(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index b362933042..5caa7fc63a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -112,6 +112,10 @@ public void test1() { lingD.setPruneFactor(pruneFactor); List pairs = lingD.search(W); + if (pairs.isEmpty()) { + throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); + } + System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { Matrix bHat = getPermutedScaledBHat(pair); From 36099b80e7231f2e87fd9244c01f468f6ccc6d4f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:37:41 -0400 Subject: [PATCH 058/464] Work on LiNG/LiNGAM. --- .../java/edu/cmu/tetrad/search/LingD.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 25dd88cf21..dfc581dce5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -81,6 +81,32 @@ public void setPruneFactor(double pruneFactor) { this.pruneFactor = pruneFactor; } + /** + * Estimates the W matrix using FastICA. Assumes the "parallel" option, using + * the "exp" function. + * + * @param data The dataset to estimate W for. + * @param fastIcaMaxIter Maximum number of iterations of ICA. + * @param fastIcaTolerance Tolerance for ICA. + * @param fastIcaA Alpha for ICA. + * @return The estimated W matrix. + */ + public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, + double fastIcaA) { + Matrix X = data.getDoubleData(); + X = DataUtils.centerData(X).transpose(); + FastIca fastIca = new FastIca(X, X.rows()); + fastIca.setVerbose(false); + fastIca.setMaxIterations(fastIcaMaxIter); + fastIca.setAlgorithmType(FastIca.PARALLEL); + fastIca.setTolerance(fastIcaTolerance); + fastIca.setFunction(FastIca.EXP); + fastIca.setRowNorm(false); + fastIca.setAlpha(fastIcaA); + FastIca.IcaResult result11 = fastIca.findComponents(); + return result11.getW(); + } + /** * Returns a graph given a coefficient matrix and a list of variables. It is * assumed that any non-zero entry in B corresponds to a directed edges, so @@ -202,32 +228,6 @@ public static boolean isStable(Matrix bHat) { return true; } - /** - * Estimates the W matrix using FastICA. Assumes the "parallel" option, using - * the "exp" function. - * - * @param data The dataset to estimate W for. - * @param fastIcaMaxIter Maximum number of iterations of ICA. - * @param fastIcaTolerance Tolerance for ICA. - * @param fastIcaA Alpha for ICA. - * @return The estimated W matrix. - */ - public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, - double fastIcaA) { - Matrix X = data.getDoubleData(); - X = DataUtils.centerData(X).transpose(); - FastIca fastIca = new FastIca(X, X.rows()); - fastIca.setVerbose(false); - fastIca.setMaxIterations(fastIcaMaxIter); - fastIca.setAlgorithmType(FastIca.PARALLEL); - fastIca.setTolerance(fastIcaTolerance); - fastIca.setFunction(FastIca.EXP); - fastIca.setRowNorm(false); - fastIca.setAlpha(fastIcaA); - FastIca.IcaResult result11 = fastIca.findComponents(); - return result11.getW(); - } - /** * Scares the given matrix M by diving each entry (i, j) by M(j, j) * @param M The matrix to scale. From b941e363fdc59ac14f9dbf0c1495a66bb59dfced Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:53:11 -0400 Subject: [PATCH 059/464] Work on LiNG/LiNGAM. --- .../java/edu/cmu/tetrad/test/TestLing.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 5caa7fc63a..799bfbc3e7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.algcomparison.simulation.SemSimulation; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.LingD; import edu.cmu.tetrad.search.Lingam; @@ -71,8 +72,8 @@ public void test1() { SemSimulation sim = new SemSimulation(new RandomForward()); sim.createData(parameters, true); DataSet dataSet = (DataSet) sim.getDataModel(0); - Graph g = sim.getTrueGraph(0); - System.out.println("True graph = " + g); + Graph trueGraph = sim.getTrueGraph(0); + System.out.println("True graph = " + trueGraph); // First we use ICA to estimate the W matrix. Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); @@ -94,13 +95,16 @@ public void test1() { Lingam lingam = new Lingam(); lingam.setPruneFactor(pruneFactor); - Graph g2 = lingam.search(W, dataSet.getVariables()); - System.out.println("Lingam graph = " + g2); + Graph lingamGraph = lingam.search(W, dataSet.getVariables()); + System.out.println("Lingam graph = " + lingamGraph); Matrix lingamBhat = lingam.getPermutedBHat(); boolean lingamStable = LingD.isStable(lingamBhat); System.out.println(lingamStable ? "Is Stable" : "Not stable"); + lingamGraph = GraphUtils.replaceNodes(lingamGraph, trueGraph.getNodes()); + assertEquals(trueGraph, lingamGraph); + // For LiNG-D, we can just call the relevant public static methods. This was obviously written // by a Matlab person. // @@ -122,11 +126,15 @@ public void test1() { System.out.println("BHat = " + bHat); List permVars = getPermutedVariables(pair, dataSet.getVariables()); - Graph graph = LingD.makeGraph(bHat, permVars); - System.out.println("\nGraph = " + graph); + Graph lingGraph = LingD.makeGraph(bHat, permVars); + System.out.println("\nGraph = " + lingGraph); boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); System.out.println(stable ? "Is Stable" : "Not stable"); + + // For this example, there is exactly one one graph (or should be, unless the example was changed). + lingGraph = GraphUtils.replaceNodes(lingGraph, trueGraph.getNodes()); + assertEquals(trueGraph, lingGraph); } } From d9bc2d5eee6862ec38786da03344dd066ecd3cf7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:53:51 -0400 Subject: [PATCH 060/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 799bfbc3e7..f74eea08d6 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -121,6 +121,7 @@ public void test1() { } System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); + for (PermutationMatrixPair pair : pairs) { Matrix bHat = getPermutedScaledBHat(pair); System.out.println("BHat = " + bHat); From 6d480bf6ecfb727de4590e946ca71a3de49cbd9b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:55:37 -0400 Subject: [PATCH 061/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index f74eea08d6..ac06198630 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -133,7 +133,7 @@ public void test1() { boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); System.out.println(stable ? "Is Stable" : "Not stable"); - // For this example, there is exactly one one graph (or should be, unless the example was changed). + // For this example, there is exactly one graph (or should be, unless the example was changed). lingGraph = GraphUtils.replaceNodes(lingGraph, trueGraph.getNodes()); assertEquals(trueGraph, lingGraph); } From 8403a747af0979d6735aba5b5860f42e4fec0222 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 05:56:45 -0400 Subject: [PATCH 062/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index ac06198630..34e0b20912 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -54,8 +54,8 @@ public void test1() { // Testing LiNGAM and LiNG-D on a simple 6-node 6-edge example. This // uses Exp(1) non-Gaussian errors and otherwise default parameters. - // We're not using bootstrapping yet here, which could make the result - // more accurate. + // Please don't change this seed--this is set up as an actual unit test + // for this example. long seed = 402030204L; RandomUtil.getInstance().setSeed(seed); System.out.println("Seed = " + seed + "L"); From 9e3f372bdaf91cf6d3bf4543fc5e12cd116a74a5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 28 Apr 2023 06:12:10 -0400 Subject: [PATCH 063/464] Work on LiNG/LiNGAM. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 - tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 4 ---- 2 files changed, 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index dfc581dce5..462611a132 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -84,7 +84,6 @@ public void setPruneFactor(double pruneFactor) { /** * Estimates the W matrix using FastICA. Assumes the "parallel" option, using * the "exp" function. - * * @param data The dataset to estimate W for. * @param fastIcaMaxIter Maximum number of iterations of ICA. * @param fastIcaTolerance Tolerance for ICA. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index e6d0e1f027..8054b36a70 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -51,7 +51,6 @@ public Lingam() { /** * Searches given the W matrix from ICA. - * * @param W the W matrix from ICA. * @param variables The variables from the original dataset used to generate the W matrix, * in the order they occur in that dataset. @@ -93,7 +92,6 @@ public Graph search(Matrix W, List variables) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. - * * @param pruneFactor Some value >= 0. */ public void setPruneFactor(double pruneFactor) { @@ -103,7 +101,6 @@ public void setPruneFactor(double pruneFactor) { /** * After search the permuted BHat matrix can be retrieved using this method. - * * @return The permutated (lower triangle) BHat matrix. Here, BHat(i, j) != 0 means that * there is an edge vars(j)-->vars(i) in the graph, where 'vars' means the permuted variables. */ @@ -113,7 +110,6 @@ public Matrix getPermutedBHat() { /** * The permuted variables of the graph. This is the estimated causal order of the models. - * * @return This list of variables. */ public List getPermutedVars() { From c3d34d0f12233d7ca2ea7b23c8a5d569e7b6b1f1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 29 Apr 2023 06:37:26 -0400 Subject: [PATCH 064/464] Work on LiNG/LiNGAM. --- docs/manual/index.html | 6 +- .../algorithm/continuous/dag/LingD.java | 113 ++++++++++++++++++ .../algorithm/continuous/dag/Lingam.java | 3 +- .../java/edu/cmu/tetrad/search/LingD.java | 43 +++++-- .../java/edu/cmu/tetrad/test/TestLing.java | 10 +- 5 files changed, 156 insertions(+), 19 deletions(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java diff --git a/docs/manual/index.html b/docs/manual/index.html index e4280e79ef..f0a231ac06 100755 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -5550,11 +5550,11 @@

    fastIcaA

    • Short Description: LiNGAM Prune Factor. + id="pruneFactor_short_desc">Threshold on the W matrix.
    • Long Description: The estimated coefficient matrix, BHat, - is pruned by setting small coefficients less than 'pruneFactor' + id="pruneFactor_long_desc">The estimated W matrix + is thresholded by setting small entries less than this threshold to zero.
    • Default Value: pairs = lingD.search(W); + + int count = 0; + + for (PermutationMatrixPair pair : pairs) { + Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); + Graph graph = edu.cmu.tetrad.search.LingD.makeGraph(bHat, data.getVariables()); + + System.out.println("LiNG-D Model #" + (++count)); + System.out.println(); + System.out.println("BHat = " + bHat); + System.out.println("Graph = " + graph); + } + + if (pairs.size() > 0) { + PermutationMatrixPair pair = pairs.get(0); + Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); + return edu.cmu.tetrad.search.LingD.makeGraph(bHat, data.getVariables()); + } else { + throw new IllegalArgumentException("LiNG-D couldn't find a model."); + } + } else { + LingD algorithm = new LingD(); + + 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(); + } + } + + @Override + public Graph getComparisonGraph(Graph graph) { + return new EdgeListGraph(graph); + } + + public String getDescription() { + return "LiNG-D (Linear Non-Gaussian Discovery"; + } + + @Override + public DataType getDataType() { + return DataType.Continuous; + } + + @Override + public List getParameters() { + List parameters = new ArrayList<>(); + parameters.add(Params.PENALTY_DISCOUNT); + parameters.add(Params.VERBOSE); + parameters.add(Params.FAST_ICA_A); + parameters.add(Params.FAST_ICA_MAX_ITER); + parameters.add(Params.FAST_ICA_TOLERANCE); + parameters.add(Params.PRUNE_FACTOR); + return parameters; + } +} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 953de38376..fbea48df67 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -3,6 +3,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.annotation.AlgType; 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; @@ -30,7 +31,7 @@ dataType = DataType.Continuous ) @Bootstrapping -//@Experimental +@Experimental public class Lingam implements Algorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 462611a132..6716f2e9d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -28,6 +28,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.PermutationGenerator; +import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; import org.jetbrains.annotations.NotNull; @@ -50,6 +51,7 @@ */ public class LingD { + private static PermutationMatrixPair pair; private double pruneFactor; /** @@ -65,8 +67,7 @@ public LingD() { * elsewhere. The local algorithm is assumed--in fact, the W matrix is simply * thresholded without bootstrapping. * @param W The W matrix to be used. - * @return A list of models, as PermutationMatrixPairs (see). - * @see PermutationMatrixPair + * @return A list of graphs generated by LiNG-D. */ public List search(Matrix W) { W = LingD.threshold(W, pruneFactor); @@ -99,7 +100,7 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT fastIca.setMaxIterations(fastIcaMaxIter); fastIca.setAlgorithmType(FastIca.PARALLEL); fastIca.setTolerance(fastIcaTolerance); - fastIca.setFunction(FastIca.EXP); + fastIca.setFunction(FastIca.LOGCOSH); fastIca.setRowNorm(false); fastIca.setAlpha(fastIcaA); FastIca.IcaResult result11 = fastIca.findComponents(); @@ -273,10 +274,14 @@ public static Matrix threshold(Matrix M, double threshold) { * @return The estimated B Hat matrix for this pair. * @see PermutationMatrixPair */ - public static Matrix getPermutedScaledBHat(PermutationMatrixPair pair) { + public static Matrix getScaledBHat(PermutationMatrixPair pair) { Matrix _w = pair.getPermutedMatrix(); _w = scale(_w); - return Matrix.identity(_w.rows()).minus(_w); + Matrix bHat = Matrix.identity(_w.rows()).minus(_w); + int[] perm = pair.getColPerm(); + int[] inverse = LingD.inversePermutation(perm); + PermutationMatrixPair inversePair = new PermutationMatrixPair(bHat, inverse, inverse); + return inversePair.getPermutedMatrix(); } /** @@ -286,8 +291,12 @@ public static Matrix getPermutedScaledBHat(PermutationMatrixPair pair) { * pair. * @return The thresholded W matrix for this pair. */ - public static Matrix getPermutedThresholdedW(PermutationMatrixPair pair) { - return pair.getPermutedMatrix(); + public static Matrix getThresholdedW(PermutationMatrixPair pair) { + Matrix permutedMatrix = pair.getPermutedMatrix(); + int[] perm = pair.getColPerm(); + int[] inverse = LingD.inversePermutation(perm); + PermutationMatrixPair inversePair = new PermutationMatrixPair(permutedMatrix, inverse, inverse); + return inversePair.getPermutedMatrix(); } /** @@ -297,9 +306,14 @@ public static Matrix getPermutedThresholdedW(PermutationMatrixPair pair) { * pair. * @return The estimated B Hat matrix for this pair. */ - public static Matrix getPermutedUnscaledBHat(PermutationMatrixPair pair) { + public static Matrix getUnscaledBHat(PermutationMatrixPair pair) { + LingD.pair = pair; Matrix _w = pair.getPermutedMatrix(); - return Matrix.identity(_w.rows()).minus(_w); + Matrix bHat = Matrix.identity(_w.rows()).minus(_w); + int[] perm = pair.getColPerm(); + int[] inverse = LingD.inversePermutation(perm); + PermutationMatrixPair inversePair = new PermutationMatrixPair(bHat, inverse, inverse); + return inversePair.getPermutedMatrix(); } /** @@ -341,6 +355,17 @@ private static List nRooks(Matrix W) { return pairs; } + + private static int[] inversePermutation(int[] perm) { + int[] inverse = new int[perm.length]; + + for (int i = 0; i < perm.length; i++) { + inverse[perm[i]] = i; + } + + return inverse; + } + } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 34e0b20912..9dae95923f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -40,8 +40,7 @@ import java.util.Arrays; import java.util.List; -import static edu.cmu.tetrad.search.LingD.getPermutedScaledBHat; -import static edu.cmu.tetrad.search.LingD.getPermutedVariables; +import static edu.cmu.tetrad.search.LingD.getScaledBHat; import static org.junit.Assert.assertEquals; /** @@ -123,14 +122,13 @@ public void test1() { System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); for (PermutationMatrixPair pair : pairs) { - Matrix bHat = getPermutedScaledBHat(pair); + Matrix bHat = getScaledBHat(pair); System.out.println("BHat = " + bHat); - List permVars = getPermutedVariables(pair, dataSet.getVariables()); - Graph lingGraph = LingD.makeGraph(bHat, permVars); + Graph lingGraph = LingD.makeGraph(bHat, dataSet.getVariables()); System.out.println("\nGraph = " + lingGraph); - boolean stable = LingD.isStable(LingD.getPermutedScaledBHat(pair)); + boolean stable = LingD.isStable(bHat); System.out.println(stable ? "Is Stable" : "Not stable"); // For this example, there is exactly one graph (or should be, unless the example was changed). From a80801c8121a18125aaf1228a5dd9b12fd629de8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 29 Apr 2023 06:44:09 -0400 Subject: [PATCH 065/464] Work on LiNG/LiNGAM. --- .../java/edu/cmu/tetrad/search/LingD.java | 39 +++++++------------ .../java/edu/cmu/tetrad/search/Lingam.java | 26 ++++--------- .../java/edu/cmu/tetrad/test/TestLing.java | 3 +- 3 files changed, 22 insertions(+), 46 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 6716f2e9d8..2fa2c17461 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -28,7 +28,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.PermutationGenerator; -import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; import org.jetbrains.annotations.NotNull; @@ -51,7 +50,6 @@ */ public class LingD { - private static PermutationMatrixPair pair; private double pruneFactor; /** @@ -66,6 +64,7 @@ public LingD() { * Performs the LiNG-D algorithm given a W matrix, which needs to be discovered * elsewhere. The local algorithm is assumed--in fact, the W matrix is simply * thresholded without bootstrapping. + * * @param W The W matrix to be used. * @return A list of graphs generated by LiNG-D. */ @@ -76,6 +75,7 @@ public List search(Matrix W) { /** * Sets the threshold used to prune the W matrix for the local algorithms. + * * @param pruneFactor The treshold, a non-negative number. */ public void setPruneFactor(double pruneFactor) { @@ -85,6 +85,7 @@ public void setPruneFactor(double pruneFactor) { /** * Estimates the W matrix using FastICA. Assumes the "parallel" option, using * the "exp" function. + * * @param data The dataset to estimate W for. * @param fastIcaMaxIter Maximum number of iterations of ICA. * @param fastIcaTolerance Tolerance for ICA. @@ -111,7 +112,8 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT * Returns a graph given a coefficient matrix and a list of variables. It is * assumed that any non-zero entry in B corresponds to a directed edges, so * that Bij != 0 implies that j->i in the graph. - * @param B The coefficient matrix. + * + * @param B The coefficient matrix. * @param variables The list of variables. * @return The built graph. */ @@ -134,6 +136,7 @@ public static Graph makeGraph(Matrix B, List variables) { * coefficient matrix B that maximizes the sum of Bij^2 values in * the lower triangle. This is to help find a causal order for the * variables assuming a DAG model. + * * @param B The coefficient matrix B * @return The permutation of rows and columns simultaneously that * maximizes the lower triangle. @@ -167,6 +170,7 @@ public static int[] encourageLowerTriangular(Matrix B) { * Finds a column permutation of the W matrix that maximizes the sum * of 1 / |Wii| for diagonal elements Wii in W. This will be speeded up * if W is a thresholded matrix. + * * @param W The (possibly thresholded) W matrix. * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair @@ -205,6 +209,7 @@ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { /** * Whether the BHat matrix represents a stable model. The eigenvalues are * checked ot make sure they are all less than 1 in modulus. + * * @param bHat The bHat matrix. * @return True iff the model is stable. */ @@ -230,6 +235,7 @@ public static boolean isStable(Matrix bHat) { /** * Scares the given matrix M by diving each entry (i, j) by M(j, j) + * * @param M The matrix to scale. * @return The scaled matrix. */ @@ -247,6 +253,7 @@ public static Matrix scale(Matrix M) { /** * Thresholds the givem matrix, sending any small entries to zero. + * * @param M The matrix to threshold. * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. * Should be non-negative. @@ -269,6 +276,7 @@ public static Matrix threshold(Matrix M, double threshold) { /** * Returns the BHat matrix, permuted to causal order (lower triangle) and * scaled so that the diagonal consists only of 1's. + * * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. * @return The estimated B Hat matrix for this pair. @@ -287,6 +295,7 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair) { /** * Returns the thresholded W matrix, permuted to causal order (lower triangle), * unscaled. + * * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. * @return The thresholded W matrix for this pair. @@ -302,12 +311,12 @@ public static Matrix getThresholdedW(PermutationMatrixPair pair) { /** * Returns the BHat matrix, permuted to causal order (lower triangle) and * unscaled. + * * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. * @return The estimated B Hat matrix for this pair. */ public static Matrix getUnscaledBHat(PermutationMatrixPair pair) { - LingD.pair = pair; Matrix _w = pair.getPermutedMatrix(); Matrix bHat = Matrix.identity(_w.rows()).minus(_w); int[] perm = pair.getColPerm(); @@ -316,26 +325,6 @@ public static Matrix getUnscaledBHat(PermutationMatrixPair pair) { return inversePair.getPermutedMatrix(); } - /** - * Returns the lsit of variables, permuted using the column permutation of - * the given PermutationMatrixPair. - * @param pair The pair whose column permutation is used. - * @param variables The list of variables. - * @return The permuted list of variables. - */ - public static List getPermutedVariables(PermutationMatrixPair pair, - List variables) { - int[] perm = pair.getColPerm(); - - List permVars = new ArrayList<>(); - - for (int i = 0; i < variables.size(); i++) { - permVars.add(variables.get(perm[i])); - } - - return permVars; - } - @NotNull private static List nRooks(Matrix W) { List pairs = new ArrayList<>(); @@ -356,7 +345,7 @@ private static List nRooks(Matrix W) { return pairs; } - private static int[] inversePermutation(int[] perm) { + static int[] inversePermutation(int[] perm) { int[] inverse = new int[perm.length]; for (int i = 0; i < perm.length; i++) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 8054b36a70..a117278f60 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -37,8 +37,7 @@ * @author josephramsey */ public class Lingam { - private Matrix permutedBHat = null; - private List permutedVars = null; + private Matrix bHat = null; private double pruneFactor; //================================CONSTRUCTORS==========================// @@ -78,16 +77,13 @@ public Graph search(Matrix W, List variables) { } } - // Permute the variables too for that order. - List permutedVars = new ArrayList<>(); - for (int k : perm) permutedVars.add(variables.get(k)); - // Grab the permuted BHat and variables. - this.permutedBHat = permutedBHat; - this.permutedVars = permutedVars; + int[] inverse = LingD.inversePermutation(perm); + PermutationMatrixPair inversePair = new PermutationMatrixPair(permutedBHat, inverse, inverse); + this.bHat = inversePair.getPermutedMatrix(); // Make the graph and return it. - return LingD.makeGraph(permutedBHat, permutedVars); + return LingD.makeGraph(this.bHat, variables); } /** @@ -104,16 +100,8 @@ public void setPruneFactor(double pruneFactor) { * @return The permutated (lower triangle) BHat matrix. Here, BHat(i, j) != 0 means that * there is an edge vars(j)-->vars(i) in the graph, where 'vars' means the permuted variables. */ - public Matrix getPermutedBHat() { - return permutedBHat; - } - - /** - * The permuted variables of the graph. This is the estimated causal order of the models. - * @return This list of variables. - */ - public List getPermutedVars() { - return permutedVars; + public Matrix getbHat() { + return bHat; } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 9dae95923f..0220c1213b 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -26,7 +26,6 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.LingD; import edu.cmu.tetrad.search.Lingam; import edu.cmu.tetrad.search.NRooks; @@ -97,7 +96,7 @@ public void test1() { Graph lingamGraph = lingam.search(W, dataSet.getVariables()); System.out.println("Lingam graph = " + lingamGraph); - Matrix lingamBhat = lingam.getPermutedBHat(); + Matrix lingamBhat = lingam.getbHat(); boolean lingamStable = LingD.isStable(lingamBhat); System.out.println(lingamStable ? "Is Stable" : "Not stable"); From 26da94cff39f5ca37a1314595b17bf414ef8b784 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 29 Apr 2023 18:58:23 -0400 Subject: [PATCH 066/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- .../cmu/tetradapp/editor/StatsListEditor.java | 1 + .../java/edu/cmu/tetrad/search/FastIca.java | 12 +-- .../java/edu/cmu/tetrad/search/LingD.java | 1 + .../java/edu/cmu/tetrad/search/NRooks.java | 96 ++++++++----------- .../main/java/edu/cmu/tetrad/util/Matrix.java | 31 ++++-- 5 files changed, 68 insertions(+), 73 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StatsListEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StatsListEditor.java index ff98b03f09..291cca1fcc 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StatsListEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StatsListEditor.java @@ -158,6 +158,7 @@ private List statistics() { statistics.add(new AverageDegreeTrue()); statistics.add(new DensityEst()); statistics.add(new DensityTrue()); + statistics.add(new Shd()); // Joe table. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index 7a64f4a5e8..c69f7fdf49 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -380,10 +380,10 @@ public IcaResult findComponents() { int n = this.X.columns(); int p = this.X.rows(); - if (this.numComponents > FastMath.min(n, p)) { + if (this.numComponents > min(n, p)) { TetradLogger.getInstance().log("info", "Requested number of components is too large."); - TetradLogger.getInstance().log("info", "Reset to " + FastMath.min(n, p)); - this.numComponents = FastMath.min(n, p); + TetradLogger.getInstance().log("info", "Reset to " + min(n, p)); + this.numComponents = min(n, p); } if (this.wInit == null) { @@ -654,9 +654,9 @@ private Matrix icaParallel(Matrix X, int numComponents, v2 = v2.times(W); W1 = v1.minus(v2); - SingularValueDecomposition sW1 = new SingularValueDecomposition(new BlockRealMatrix(W1.toArray())); - Matrix U = new Matrix(sW1.getU().getData()); - Matrix sD = new Matrix(sW1.getS().getData()); + SingularValueDecomposition sW1 = new SingularValueDecomposition(W1.getApacheData()); + Matrix U = new Matrix(sW1.getU()); + Matrix sD = new Matrix(sW1.getS()); for (int i = 0; i < sD.rows(); i++) sD.set(i, i, 1.0 / sD.get(i, i)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 2fa2c17461..7ca886fbd3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -69,6 +69,7 @@ public LingD() { * @return A list of graphs generated by LiNG-D. */ public List search(Matrix W) { + System.out.println("Starting LiNG-D"); W = LingD.threshold(W, pruneFactor); return nRooks(W); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 7afd22383c..23ddb9f870 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -1,9 +1,6 @@ package edu.cmu.tetrad.search; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.IllformedLocaleException; -import java.util.List; +import java.util.*; /** *

      Returns row positions for placing rooks for an n x n matrix so the rooks @@ -27,78 +24,63 @@ public class NRooks { public static ArrayList nRooks(boolean[][] allowablePositions) { for (boolean[] positions : allowablePositions) { if (positions.length != allowablePositions[0].length) { - throw new IllformedLocaleException("Expecting a square matrix."); + throw new IllegalArgumentException("Expecting a square matrix."); } } int p = allowablePositions.length; - boolean[][] _allowable = new boolean[p][p]; + boolean[][] board = new boolean[p][p]; ArrayList solutions = new ArrayList<>(); - dfs(_allowable, allowablePositions, 0, solutions); - return solutions; - } - /** - * Prints the discovered N Rooks solutions given the constraint. - * @param solutions The solutions. - */ - public static void printSolutions(List solutions) { - System.out.println("Number of solutions: " + solutions.size()); - for (int i = 0; i < solutions.size(); i++) { - int[] solution = solutions.get(i); - System.out.println((i + 1) + ". " + Arrays.toString(solution)); - } - } + Stack rows = new Stack<>(); + Stack cols = new Stack<>(); + int row = 0; + int col = 0; - private static void dfs(boolean[][] board, boolean[][] allowablePositions, int row, ArrayList solutions) { - - // Base case: all rooks have been placed - if (row == board.length) { - int[] solution = new int[board.length]; - for (int i = 0; i < board.length; i++) { - for (int j = 0; j < board.length; j++) { - if (board[i][j]) { - solution[i] = j; - break; - } + while (row < p) { + if (col >= p) { + if (rows.isEmpty()) { + break; } + row = rows.pop(); + col = cols.pop() + 1; + board[row][col - 1] = false; + continue; } - solutions.add(solution); - return; - } - - // Otherwise, for each column - for (int col = 0; col < board.length; col++) { - - // If the current row is a valid position to place a rook (i.e., it can't attack - // any other rook)... - if (isValid(board, row, col)) { - - // This constrains the problem to allowable positions on the board. - if (!allowablePositions[row][col]) continue; - - // Otherwise place the rook and recurse through the rows of the board. + if (allowablePositions[row][col] && isValid(board, row, col)) { board[row][col] = true; - dfs(board, allowablePositions, row+1, solutions); - - // Backtrack and try another case... - board[row][col] = false; + rows.push(row); + cols.push(col); + row++; + col = 0; + if (row == p) { + int[] solution = new int[p]; + for (int i = 0; i < p; i++) { + for (int j = 0; j < p; j++) { + if (board[i][j]) { + solution[i] = j; + break; + } + } + } + solutions.add(solution); + row = p - 1; + col = p; + } + } else { + col++; } } + + return solutions; } private static boolean isValid(boolean[][] board, int row, int col) { - - // Check if the current position is valid. ChatGPT had some clever condition here - // that didn't work, sorry ChatGPT. This is the non-clever condition. for (int i = 0; i < row; i++) { if (board[i][col]) { - for (boolean[] booleans : board) { - if (booleans[col]) return false; - } + return false; } } - return true; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java index af8d94870e..8a8eb7ddec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java @@ -53,6 +53,13 @@ public Matrix(double[][] data) { this.n = this.m == 0 ? 0 : data[0].length; } + public Matrix(RealMatrix data) { + this.apacheData = data; + + this.m = data.getRowDimension(); + this.n = data.getColumnDimension(); + } + public Matrix(int m, int n) { if (m == 0 || n == 0) { this.apacheData = new Array2DRowRealMatrix(); @@ -65,7 +72,7 @@ public Matrix(int m, int n) { } public Matrix(Matrix m) { - this(m.apacheData.copy().getData()); + this(m.apacheData.copy()); } public void assign(Matrix matrix) { @@ -115,7 +122,7 @@ public Matrix getSelection(int[] rows, int[] cols) { public Matrix copy() { if (zeroDimension()) return new Matrix(rows(), columns()); - return new Matrix(this.apacheData.copy().getData()); + return new Matrix(this.apacheData.copy()); } public Vector getColumn(int j) { @@ -130,7 +137,7 @@ public Matrix times(Matrix m) { if (this.zeroDimension() || m.zeroDimension()) return new Matrix(this.rows(), m.columns()); else { - return new Matrix(this.apacheData.multiply(m.apacheData).getData()); + return new Matrix(this.apacheData.multiply(m.apacheData)); } } @@ -158,6 +165,10 @@ public double[][] toArray() { return this.apacheData.getData(); } + public RealMatrix getApacheData() { + return this.apacheData; + } + public double get(int i, int j) { return this.apacheData.getEntry(i, j); } @@ -179,7 +190,7 @@ public Vector getRow(int i) { } public Matrix getPart(int i, int j, int k, int l) { - return new Matrix(this.apacheData.getSubMatrix(i, j, k, l).getData()); + return new Matrix(this.apacheData.getSubMatrix(i, j, k, l)); } public Matrix inverse() throws SingularMatrixException { @@ -189,14 +200,14 @@ public Matrix inverse() throws SingularMatrixException { return new Matrix(0, 0); } - return new Matrix(new LUDecomposition(this.apacheData, 1e-10).getSolver().getInverse().getData()); + return new Matrix(new LUDecomposition(this.apacheData, 1e-10).getSolver().getInverse()); } public Matrix symmetricInverse() { if (!isSquare()) throw new IllegalArgumentException(); if (rows() == 0) return new Matrix(0, 0); - return new Matrix(new CholeskyDecomposition(this.apacheData).getSolver().getInverse().getData()); + return new Matrix(new CholeskyDecomposition(this.apacheData).getSolver().getInverse()); } public Matrix ginverse() { @@ -233,7 +244,7 @@ public double det() { public Matrix transpose() { if (zeroDimension()) return new Matrix(columns(), rows()); - return new Matrix(this.apacheData.transpose().getData()); + return new Matrix(this.apacheData.transpose()); } @@ -260,7 +271,7 @@ public boolean isSymmetric(double tolerance) { public Matrix minus(Matrix mb) { if (mb.rows() == 0 || mb.columns() == 0) return this; - return new Matrix(this.apacheData.subtract(mb.apacheData).getData()); + return new Matrix(this.apacheData.subtract(mb.apacheData)); } public double norm1() { @@ -269,7 +280,7 @@ public double norm1() { public Matrix plus(Matrix mb) { if (mb.rows() == 0 || mb.columns() == 0) return this; - return new Matrix(this.apacheData.add(mb.apacheData).getData()); + return new Matrix(this.apacheData.add(mb.apacheData)); } public int rank() { @@ -301,7 +312,7 @@ public Matrix sqrt() { RealMatrix S = new BlockRealMatrix(s.length, s.length); for (int i = 0; i < s.length; i++) S.setEntry(i, i, s[i]); RealMatrix sqrt = U.multiply(S).multiply(V); - return new Matrix(sqrt.getData()); + return new Matrix(sqrt); } From 24aa997d6bf23011d48c152817ef1063b11e6b18 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 29 Apr 2023 19:00:37 -0400 Subject: [PATCH 067/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 23ddb9f870..81652d03f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -90,7 +90,7 @@ private static boolean isValid(boolean[][] board, int row, int col) { * positions. The (i, j) entry it true just in case * a rook can be placed there. */ - private static void printAllowablePositions(boolean[][] allowablePositions) { + public static void printAllowablePositions(boolean[][] allowablePositions) { System.out.println("\nAllowable rook positions"); // Print allowable board. diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 0220c1213b..56d36b5b94 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -158,10 +158,6 @@ public void testNRooks() { List solutions = NRooks.nRooks(allowableBoard); - // Each solution is a permutation of the columns of the board, one integer - // for each row indicating where to place the rook in that row. - NRooks.printSolutions(solutions); - // There should be 4 solutions. assertEquals(4, solutions.size()); } From e88bb034e224be70d22613db78f3febc23814e6c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 29 Apr 2023 19:07:39 -0400 Subject: [PATCH 068/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- .../java/edu/cmu/tetrad/search/NRooks.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 81652d03f2..92361d0443 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -83,25 +83,4 @@ private static boolean isValid(boolean[][] board, int row, int col) { } return true; } - - /** - * Prints the allowable positions board for the NRooks class. - * @param allowablePositions The (boolean, rectangular) matrix of allowable - * positions. The (i, j) entry it true just in case - * a rook can be placed there. - */ - public static void printAllowablePositions(boolean[][] allowablePositions) { - System.out.println("\nAllowable rook positions"); - - // Print allowable board. - for (int i = 0; i < allowablePositions[0].length; i++) { - System.out.println(); - for (int j = 0; j < allowablePositions.length; j++) { - System.out.print((allowablePositions[i][j] ? 1 : 0) + " "); - } - } - - System.out.println(); - System.out.println(); - } } From b072cce026af6ade2b2224aba0249b7bcec2ce45 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 29 Apr 2023 19:09:33 -0400 Subject: [PATCH 069/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 92361d0443..287099f73c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -7,8 +7,7 @@ * cannot attach each other, with a given boolean[][] specification of where rooks * are allowed to be placed. For this spec, spec[i][j] = true iff a rook can be * placed there.

      - *

      Had some help from ChatGPT for this but it messed up one of the methods, - * so taking some credit.

      + *

      Had some help from ChatGPT for this.

      * * @author josephramsey * @author ChatGPT From dda2a032ca87ee0e3123d27ec21f57534ee0ae40 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 29 Apr 2023 19:12:11 -0400 Subject: [PATCH 070/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index a117278f60..40b4388d0c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; -import java.util.ArrayList; import java.util.List; import static edu.cmu.tetrad.search.LingD.threshold; @@ -50,6 +49,7 @@ public Lingam() { /** * Searches given the W matrix from ICA. + * * @param W the W matrix from ICA. * @param variables The variables from the original dataset used to generate the W matrix, * in the order they occur in that dataset. @@ -88,6 +88,7 @@ public Graph search(Matrix W, List variables) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. + * * @param pruneFactor Some value >= 0. */ public void setPruneFactor(double pruneFactor) { @@ -97,6 +98,7 @@ public void setPruneFactor(double pruneFactor) { /** * After search the permuted BHat matrix can be retrieved using this method. + * * @return The permutated (lower triangle) BHat matrix. Here, BHat(i, j) != 0 means that * there is an edge vars(j)-->vars(i) in the graph, where 'vars' means the permuted variables. */ From 25b2713dc6d539e1900997f5823417413cce03b5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 04:47:22 -0400 Subject: [PATCH 071/464] Some refactoring. --- .../algorithm/continuous/dag/LingD.java | 17 ++++---- .../algorithm/continuous/dag/Lingam.java | 8 +++- .../java/edu/cmu/tetrad/search/LingD.java | 41 ++++++++++++++++++- .../java/edu/cmu/tetrad/search/Lingam.java | 34 +++------------ .../java/edu/cmu/tetrad/test/TestLing.java | 17 ++++---- 5 files changed, 66 insertions(+), 51 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index b9e46fb63f..ea9dfe4b65 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -10,7 +10,6 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -49,13 +48,13 @@ public Graph search(DataModel dataSet, Parameters parameters) { edu.cmu.tetrad.search.LingD lingD = new edu.cmu.tetrad.search.LingD(); lingD.setPruneFactor(pruneFactor); - List pairs = lingD.search(W); + List results = lingD.search(W, dataSet.getVariables()); int count = 0; - for (PermutationMatrixPair pair : pairs) { - Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); - Graph graph = edu.cmu.tetrad.search.LingD.makeGraph(bHat, data.getVariables()); + for (edu.cmu.tetrad.search.LingD.Result result : results) { + Matrix bHat = result.getBHat(); + Graph graph = result.getGraph(); System.out.println("LiNG-D Model #" + (++count)); System.out.println(); @@ -63,10 +62,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { System.out.println("Graph = " + graph); } - if (pairs.size() > 0) { - PermutationMatrixPair pair = pairs.get(0); - Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); - return edu.cmu.tetrad.search.LingD.makeGraph(bHat, data.getVariables()); + if (results.size() > 0) { + edu.cmu.tetrad.search.LingD.Result result = results.get(0); + return result.getGraph(); } else { throw new IllegalArgumentException("LiNG-D couldn't find a model."); } @@ -102,7 +100,6 @@ public DataType getDataType() { @Override public List getParameters() { List parameters = new ArrayList<>(); - parameters.add(Params.PENALTY_DISCOUNT); parameters.add(Params.VERBOSE); parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index fbea48df67..313f572e48 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -14,6 +14,7 @@ import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; +import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import java.util.ArrayList; @@ -48,7 +49,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); lingam.setPruneFactor(pruneFactor); - return lingam.search(W, data.getVariables()); + + LingD.Result result = lingam.search(W, data.getVariables()); + TetradLogger.getInstance().forceLogMessage(result.getBHat().toString()); + TetradLogger.getInstance().forceLogMessage(result.getGraph().toString()); + + return result.getGraph(); } else { Lingam algorithm = new Lingam(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 7ca886fbd3..69ced4d937 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -68,10 +68,43 @@ public LingD() { * @param W The W matrix to be used. * @return A list of graphs generated by LiNG-D. */ - public List search(Matrix W) { + public List search(Matrix W, List variables) { System.out.println("Starting LiNG-D"); W = LingD.threshold(W, pruneFactor); - return nRooks(W); + List pairs = nRooks(W); + + if (pairs.isEmpty()) { + throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); + } + + List results = new ArrayList<>(); + + for (PermutationMatrixPair pair : pairs) { + Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); + Graph graph = edu.cmu.tetrad.search.LingD.makeGraph(bHat, variables); + Result result = new Result(bHat, graph); + results.add(result); + } + + return results; + } + + public static class Result { + private Matrix bHat; + private Graph graph; + + public Result(Matrix bHat, Graph graph) { + this.bHat = bHat.copy(); + this.graph = new EdgeListGraph(graph); + } + + public Matrix getBHat() { + return bHat; + } + + public Graph getGraph() { + return graph; + } } /** @@ -180,6 +213,10 @@ public static int[] encourageLowerTriangular(Matrix B) { public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { List pairs = nRooks(W.transpose()); + if (pairs.isEmpty()) { + throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); + } + PermutationMatrixPair bestPair = null; double sum1 = Double.POSITIVE_INFINITY; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 40b4388d0c..e1849d8b1c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -21,7 +21,6 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; @@ -36,7 +35,6 @@ * @author josephramsey */ public class Lingam { - private Matrix bHat = null; private double pruneFactor; //================================CONSTRUCTORS==========================// @@ -55,35 +53,23 @@ public Lingam() { * in the order they occur in that dataset. * @return The graph returned. */ - public Graph search(Matrix W, List variables) { + public LingD.Result search(Matrix W, List variables) { W = threshold(W, pruneFactor); PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); - if (bestPair == null) { - throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); - } - Matrix WTilde = bestPair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); - int[] perm = LingD.encourageLowerTriangular(BHat); - Matrix permutedBHat = new PermutationMatrixPair(BHat, perm, perm).getPermutedMatrix(); - - // Set the upper triangle now to zero, since we are ignoring it for this DAG algorithm. - for (int i = 0; i < permutedBHat.rows(); i++) { - for (int j = i + 1; j < permutedBHat.columns(); j++) { - permutedBHat.set(i, j, 0.0); - } - } // Grab the permuted BHat and variables. + int[] perm = bestPair.getRowPerm(); int[] inverse = LingD.inversePermutation(perm); - PermutationMatrixPair inversePair = new PermutationMatrixPair(permutedBHat, inverse, inverse); - this.bHat = inversePair.getPermutedMatrix(); + PermutationMatrixPair inversePair = new PermutationMatrixPair(BHat, inverse, inverse); + Matrix _bHat = inversePair.getPermutedMatrix(); // Make the graph and return it. - return LingD.makeGraph(this.bHat, variables); + return new LingD.Result(BHat, LingD.makeGraph(_bHat, variables)); } /** @@ -95,15 +81,5 @@ public void setPruneFactor(double pruneFactor) { if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); this.pruneFactor = pruneFactor; } - - /** - * After search the permuted BHat matrix can be retrieved using this method. - * - * @return The permutated (lower triangle) BHat matrix. Here, BHat(i, j) != 0 means that - * there is an edge vars(j)-->vars(i) in the graph, where 'vars' means the permuted variables. - */ - public Matrix getbHat() { - return bHat; - } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 56d36b5b94..a2ad016782 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -29,7 +29,6 @@ import edu.cmu.tetrad.search.LingD; import edu.cmu.tetrad.search.Lingam; import edu.cmu.tetrad.search.NRooks; -import edu.cmu.tetrad.search.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -39,7 +38,6 @@ import java.util.Arrays; import java.util.List; -import static edu.cmu.tetrad.search.LingD.getScaledBHat; import static org.junit.Assert.assertEquals; /** @@ -93,10 +91,11 @@ public void test1() { Lingam lingam = new Lingam(); lingam.setPruneFactor(pruneFactor); - Graph lingamGraph = lingam.search(W, dataSet.getVariables()); + LingD.Result result = lingam.search(W, dataSet.getVariables()); + Graph lingamGraph = result.getGraph(); System.out.println("Lingam graph = " + lingamGraph); - Matrix lingamBhat = lingam.getbHat(); + Matrix lingamBhat = result.getBHat(); boolean lingamStable = LingD.isStable(lingamBhat); System.out.println(lingamStable ? "Is Stable" : "Not stable"); @@ -106,22 +105,22 @@ public void test1() { // For LiNG-D, we can just call the relevant public static methods. This was obviously written // by a Matlab person. // - // We generate pairs of column permutations (solving the constriained N Rooks problem) with their + // We generate results of column permutations (solving the constriained N Rooks problem) with their // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); LingD lingD = new LingD(); lingD.setPruneFactor(pruneFactor); - List pairs = lingD.search(W); + List results = lingD.search(W, dataSet.getVariables()); - if (pairs.isEmpty()) { + if (results.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); } System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); - for (PermutationMatrixPair pair : pairs) { - Matrix bHat = getScaledBHat(pair); + for (LingD.Result pair : results) { + Matrix bHat = pair.getBHat(); System.out.println("BHat = " + bHat); Graph lingGraph = LingD.makeGraph(bHat, dataSet.getVariables()); From 2d785fe677707d832b71a0b2c0216476a8752809 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 04:50:16 -0400 Subject: [PATCH 072/464] Some refactoring. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 69ced4d937..5d3f1520f1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -31,7 +31,6 @@ import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -209,7 +208,6 @@ public static int[] encourageLowerTriangular(Matrix B) { * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair */ - @Nullable public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { List pairs = nRooks(W.transpose()); @@ -241,6 +239,10 @@ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { } } + if (bestPair == null) { + throw new IllegalArgumentException("Could not find a best N Rooks solution with that threshold."); + } + return bestPair; } From 197706ee624e7bc7f39528e1fa2299427a774de2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 04:51:17 -0400 Subject: [PATCH 073/464] Some refactoring. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 5d3f1520f1..5a5e811fc2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -394,7 +394,6 @@ static int[] inversePermutation(int[] perm) { return inverse; } - } From d43cb31cc61cf420cb29c8c9bf072da3165e4819 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 05:01:52 -0400 Subject: [PATCH 074/464] Some refactoring. --- .../java/edu/cmu/tetrad/search/LingD.java | 70 ------------------- 1 file changed, 70 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 5a5e811fc2..d51f6f3ff1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -27,13 +27,11 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; -import edu.cmu.tetrad.util.PermutationGenerator; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static org.apache.commons.math3.util.FastMath.*; @@ -164,41 +162,6 @@ public static Graph makeGraph(Matrix B, List variables) { return g; } - /** - * Finds a permutation of rows and columns simultaneously for a - * coefficient matrix B that maximizes the sum of Bij^2 values in - * the lower triangle. This is to help find a causal order for the - * variables assuming a DAG model. - * - * @param B The coefficient matrix B - * @return The permutation of rows and columns simultaneously that - * maximizes the lower triangle. - */ - public static int[] encourageLowerTriangular(Matrix B) { - PermutationGenerator gen2 = new PermutationGenerator(B.rows()); - int[] perm = new int[0]; - double sum2 = Double.NEGATIVE_INFINITY; - int[] choice2; - - while ((choice2 = gen2.next()) != null) { - double sum = 0.0; - - for (int i = 0; i < B.rows(); i++) { - for (int j = 0; j < i; j++) { - double b = B.get(choice2[i], choice2[j]); - sum += b * b; - } - } - - if (sum > sum2) { - sum2 = sum; - perm = Arrays.copyOf(choice2, choice2.length); - } - } - - return perm; - } - /** * Finds a column permutation of the W matrix that maximizes the sum * of 1 / |Wii| for diagonal elements Wii in W. This will be speeded up @@ -332,39 +295,6 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair) { return inversePair.getPermutedMatrix(); } - /** - * Returns the thresholded W matrix, permuted to causal order (lower triangle), - * unscaled. - * - * @param pair The (column permutation, thresholded, column permuted W matrix) - * pair. - * @return The thresholded W matrix for this pair. - */ - public static Matrix getThresholdedW(PermutationMatrixPair pair) { - Matrix permutedMatrix = pair.getPermutedMatrix(); - int[] perm = pair.getColPerm(); - int[] inverse = LingD.inversePermutation(perm); - PermutationMatrixPair inversePair = new PermutationMatrixPair(permutedMatrix, inverse, inverse); - return inversePair.getPermutedMatrix(); - } - - /** - * Returns the BHat matrix, permuted to causal order (lower triangle) and - * unscaled. - * - * @param pair The (column permutation, thresholded, column permuted W matrix) - * pair. - * @return The estimated B Hat matrix for this pair. - */ - public static Matrix getUnscaledBHat(PermutationMatrixPair pair) { - Matrix _w = pair.getPermutedMatrix(); - Matrix bHat = Matrix.identity(_w.rows()).minus(_w); - int[] perm = pair.getColPerm(); - int[] inverse = LingD.inversePermutation(perm); - PermutationMatrixPair inversePair = new PermutationMatrixPair(bHat, inverse, inverse); - return inversePair.getPermutedMatrix(); - } - @NotNull private static List nRooks(Matrix W) { List pairs = new ArrayList<>(); From ec963166bf681b1a1c3f2e8747b577e40de67234 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 06:44:26 -0400 Subject: [PATCH 075/464] Some refactoring. --- .../main/java/edu/cmu/tetradapp/model/FgesRunner.java | 2 -- .../algcomparison/algorithm/continuous/dag/Lingam.java | 1 - .../src/main/java/edu/cmu/tetrad/search/FastIca.java | 10 +++++----- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 -- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java index 726023a90f..6385baeff1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java @@ -102,8 +102,6 @@ public static DataWrapper serializableInstance() { * implemented in the extending class. */ public void execute() { - System.out.println("A"); - Object model = getDataModel(); if (model == null && getSourceGraph() != null) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 313f572e48..6f6e68ad71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -87,7 +87,6 @@ public DataType getDataType() { @Override public List getParameters() { List parameters = new ArrayList<>(); - parameters.add(Params.PENALTY_DISCOUNT); parameters.add(Params.VERBOSE); parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index c69f7fdf49..26e73598fd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; import edu.cmu.tetrad.util.Vector; -import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.SingularValueDecomposition; import org.apache.commons.math3.util.FastMath; @@ -414,7 +413,7 @@ public IcaResult findComponents() { // Whiten. Matrix cov = this.X.times(this.X.transpose()).scalarMult(1.0 / n); - SingularValueDecomposition s = new SingularValueDecomposition(new BlockRealMatrix(cov.toArray())); + SingularValueDecomposition s = new SingularValueDecomposition(cov.getApacheData()); Matrix D = new Matrix(s.getS().getData()); Matrix U = new Matrix(s.getU().getData()); @@ -427,6 +426,7 @@ public IcaResult findComponents() { K = K.getPart(0, this.numComponents - 1, 0, p - 1); Matrix X1 = K.times(this.X); + Matrix b; if (this.algorithmType == FastIca.DEFLATION) { @@ -606,12 +606,12 @@ private Matrix icaParallel(Matrix X, int numComponents, int p = X.columns(); Matrix W = wInit; - SingularValueDecomposition sW = new SingularValueDecomposition(new BlockRealMatrix(W.toArray())); + SingularValueDecomposition sW = new SingularValueDecomposition(W.getApacheData()); Matrix D = new Matrix(sW.getS().getData()); for (int i = 0; i < D.rows(); i++) D.set(i, i, 1.0 / D.get(i, i)); - Matrix WTemp = new Matrix(sW.getU().getData()).times(D); - WTemp = WTemp.times(new Matrix(sW.getU().getData()).transpose()); + Matrix WTemp = new Matrix(sW.getU()).times(D); + WTemp = WTemp.times(new Matrix(sW.getU()).transpose()); WTemp = WTemp.times(W); W = WTemp; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index d51f6f3ff1..e861dc1ef8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -172,7 +172,10 @@ public static Graph makeGraph(Matrix B, List variables) { * @see PermutationMatrixPair */ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { + System.out.println("nrooks starting"); + List pairs = nRooks(W.transpose()); + System.out.println("nrooks finished"); if (pairs.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index e1849d8b1c..1eb26dc9e4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -55,9 +55,7 @@ public Lingam() { */ public LingD.Result search(Matrix W, List variables) { W = threshold(W, pruneFactor); - PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); - Matrix WTilde = bestPair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); From 06a69d64b185a27bee0789e2578a359f24924611 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 06:53:42 -0400 Subject: [PATCH 076/464] Some refactoring. --- docs/manual/index.html | 14 +++++++------- .../algorithm/continuous/dag/LingD.java | 4 ++-- .../algorithm/continuous/dag/Lingam.java | 4 ++-- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 10 +++++----- .../main/java/edu/cmu/tetrad/search/Lingam.java | 12 ++++++------ .../src/main/java/edu/cmu/tetrad/util/Params.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestLing.java | 14 +++++++------- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/manual/index.html b/docs/manual/index.html index f0a231ac06..3d3a25ae8a 100755 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -5546,25 +5546,25 @@

      fastIcaA

    pruneFactor

    + id="wThreshold">wThreshold
    • Short Description: Threshold on the W matrix. + id="wThreshold_short_desc">Threshold on the W matrix.
    • Long Description: The estimated W matrix + id="wThreshold_long_desc">The estimated W matrix is thresholded by setting small entries less than this threshold to zero.
    • Default Value: 0.3
    • + id="wThreshold_default_value">0.3
    • Lower Bound: - 0.0
    • + 0.0
    • Upper - Bound: Infinity
    • + Bound: Infinity
    • Value Type: Double
    • + id="wThreshold_value_type">Double

    results = lingD.search(W, dataSet.getVariables()); int count = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 6f6e68ad71..d7a7d479a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -44,11 +44,11 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double pruneFactor = parameters.getDouble(Params.PRUNE_FACTOR); + double wThreshold = parameters.getDouble(Params.PRUNE_FACTOR); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setPruneFactor(pruneFactor); + lingam.setPruneFactor(wThreshold); LingD.Result result = lingam.search(W, data.getVariables()); TetradLogger.getInstance().forceLogMessage(result.getBHat().toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index e861dc1ef8..7d49d14444 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -47,7 +47,7 @@ */ public class LingD { - private double pruneFactor; + private double wThreshold; /** * Constructor. The W matrix needs to be estimated separately (e.g., using @@ -67,7 +67,7 @@ public LingD() { */ public List search(Matrix W, List variables) { System.out.println("Starting LiNG-D"); - W = LingD.threshold(W, pruneFactor); + W = LingD.threshold(W, wThreshold); List pairs = nRooks(W); if (pairs.isEmpty()) { @@ -107,10 +107,10 @@ public Graph getGraph() { /** * Sets the threshold used to prune the W matrix for the local algorithms. * - * @param pruneFactor The treshold, a non-negative number. + * @param wThreshold The treshold, a non-negative number. */ - public void setPruneFactor(double pruneFactor) { - this.pruneFactor = pruneFactor; + public void setPruneFactor(double wThreshold) { + this.wThreshold = wThreshold; } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 1eb26dc9e4..bceba9ed81 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class Lingam { - private double pruneFactor; + private double wThreshold; //================================CONSTRUCTORS==========================// @@ -54,7 +54,7 @@ public Lingam() { * @return The graph returned. */ public LingD.Result search(Matrix W, List variables) { - W = threshold(W, pruneFactor); + W = threshold(W, wThreshold); PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); Matrix WTilde = bestPair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); @@ -73,11 +73,11 @@ public LingD.Result search(Matrix W, List variables) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. * - * @param pruneFactor Some value >= 0. + * @param wThreshold Some value >= 0. */ - public void setPruneFactor(double pruneFactor) { - if (pruneFactor < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + pruneFactor); - this.pruneFactor = pruneFactor; + public void setPruneFactor(double wThreshold) { + if (wThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + wThreshold); + this.wThreshold = wThreshold; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index 0a0478c678..b0f94c9dcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -80,7 +80,7 @@ public final class Params { public static final String FAST_ICA_TOLERANCE = "fastIcaTolerance"; public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; - public static final String PRUNE_FACTOR = "pruneFactor"; + public static final String PRUNE_FACTOR = "wThreshold"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; public static final String GENERAL_SEM_ERROR_TEMPLATE = "generalSemErrorTemplate"; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index a2ad016782..bbd2f20a88 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -74,10 +74,10 @@ public void test1() { // First we use ICA to estimate the W matrix. Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); - // We then apply LiNGAM with a prune factor of .3. We should get a mostly correct DAG - // back. The "prune factor" is a threshold for the B Hat matrix below which values are + // We then apply LiNGAM with a W threshold of .3. We should get a mostly correct DAG + // back. The "W threshold" is a threshold for the B Hat matrix below which values are // sent to zero in absolute value, so that only coefficients whose absolute values - // exceed the prune factor are reported as edges in the model. Self-loops are not reported + // exceed the W threshold are reported as edges in the model. Self-loops are not reported // in the printed graphs but are assumed ot exist for purposes of this algorithm. The // B Hat matrices are scaled so that self-loops always have strength 1. System.out.println("LiNGAM"); @@ -86,11 +86,11 @@ public void test1() { // We do no further pruning on the B matrix. (The algorithm spec wants us to do both // but pruning the W matrix seems to be giving better results, and besides in LiNG-D // the W matrix is pruned. Could switch though.) - double pruneFactor = 0.25; - System.out.println("Prune factor = " + pruneFactor); + double wThreshold = 0.25; + System.out.println("Prune factor = " + wThreshold); Lingam lingam = new Lingam(); - lingam.setPruneFactor(pruneFactor); + lingam.setPruneFactor(wThreshold); LingD.Result result = lingam.search(W, dataSet.getVariables()); Graph lingamGraph = result.getGraph(); System.out.println("Lingam graph = " + lingamGraph); @@ -110,7 +110,7 @@ public void test1() { // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); LingD lingD = new LingD(); - lingD.setPruneFactor(pruneFactor); + lingD.setPruneFactor(wThreshold); List results = lingD.search(W, dataSet.getVariables()); if (results.isEmpty()) { From aa7bb6f389a28236757cf9fa3b784c9f23890bd8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 06:57:17 -0400 Subject: [PATCH 077/464] Some refactoring. --- .../algcomparison/algorithm/continuous/dag/LingD.java | 6 +++--- .../algcomparison/algorithm/continuous/dag/Lingam.java | 6 +++--- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 7e5dabf607..6c694dad27 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -42,12 +42,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double wThreshold = parameters.getDouble(Params.PRUNE_FACTOR); + double wThreshold = parameters.getDouble(Params.W_THRESHOLD); Matrix W = edu.cmu.tetrad.search.LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.LingD lingD = new edu.cmu.tetrad.search.LingD(); - lingD.setPruneFactor(wThreshold); + lingD.setWThreshold(wThreshold); List results = lingD.search(W, dataSet.getVariables()); int count = 0; @@ -104,7 +104,7 @@ public List getParameters() { parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); - parameters.add(Params.PRUNE_FACTOR); + parameters.add(Params.W_THRESHOLD); return parameters; } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index d7a7d479a1..2684bf580e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -44,11 +44,11 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double wThreshold = parameters.getDouble(Params.PRUNE_FACTOR); + double wThreshold = parameters.getDouble(Params.W_THRESHOLD); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setPruneFactor(wThreshold); + lingam.setWThreshold(wThreshold); LingD.Result result = lingam.search(W, data.getVariables()); TetradLogger.getInstance().forceLogMessage(result.getBHat().toString()); @@ -91,7 +91,7 @@ public List getParameters() { parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); - parameters.add(Params.PRUNE_FACTOR); + parameters.add(Params.W_THRESHOLD); return parameters; } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 7d49d14444..f047aaec2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -109,7 +109,7 @@ public Graph getGraph() { * * @param wThreshold The treshold, a non-negative number. */ - public void setPruneFactor(double wThreshold) { + public void setWThreshold(double wThreshold) { this.wThreshold = wThreshold; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index bceba9ed81..57f731286a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -75,7 +75,7 @@ public LingD.Result search(Matrix W, List variables) { * * @param wThreshold Some value >= 0. */ - public void setPruneFactor(double wThreshold) { + public void setWThreshold(double wThreshold) { if (wThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + wThreshold); this.wThreshold = wThreshold; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index b0f94c9dcf..894f7ddde9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -80,7 +80,7 @@ public final class Params { public static final String FAST_ICA_TOLERANCE = "fastIcaTolerance"; public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; - public static final String PRUNE_FACTOR = "wThreshold"; + public static final String W_THRESHOLD = "wThreshold"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; public static final String GENERAL_SEM_ERROR_TEMPLATE = "generalSemErrorTemplate"; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index bbd2f20a88..7262883a12 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -87,10 +87,10 @@ public void test1() { // but pruning the W matrix seems to be giving better results, and besides in LiNG-D // the W matrix is pruned. Could switch though.) double wThreshold = 0.25; - System.out.println("Prune factor = " + wThreshold); + System.out.println("W threshold = " + wThreshold); Lingam lingam = new Lingam(); - lingam.setPruneFactor(wThreshold); + lingam.setWThreshold(wThreshold); LingD.Result result = lingam.search(W, dataSet.getVariables()); Graph lingamGraph = result.getGraph(); System.out.println("Lingam graph = " + lingamGraph); @@ -110,7 +110,7 @@ public void test1() { // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); LingD lingD = new LingD(); - lingD.setPruneFactor(wThreshold); + lingD.setWThreshold(wThreshold); List results = lingD.search(W, dataSet.getVariables()); if (results.isEmpty()) { From 3e33bcf5954d080015ff3c8d7e15944866fd377e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 07:00:45 -0400 Subject: [PATCH 078/464] Some refactoring. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index f047aaec2b..3a4f7aa26e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -110,6 +110,7 @@ public Graph getGraph() { * @param wThreshold The treshold, a non-negative number. */ public void setWThreshold(double wThreshold) { + if (wThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + wThreshold); this.wThreshold = wThreshold; } From c4d993b246370fac26db0efaaedc919600734bc3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 07:03:46 -0400 Subject: [PATCH 079/464] Made LiNG-D, LiNGAM non-experimental. --- .../tetrad/algcomparison/algorithm/continuous/dag/LingD.java | 2 -- .../tetrad/algcomparison/algorithm/continuous/dag/Lingam.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 6c694dad27..3a9d64c7c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -3,7 +3,6 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.annotation.AlgType; 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; @@ -30,7 +29,6 @@ dataType = DataType.Continuous ) @Bootstrapping -@Experimental public class LingD implements Algorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 2684bf580e..4c4107a84d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -3,7 +3,6 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.annotation.AlgType; 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; @@ -32,7 +31,6 @@ dataType = DataType.Continuous ) @Bootstrapping -@Experimental public class Lingam implements Algorithm { static final long serialVersionUID = 23L; From e325af676ef6c56abc03869556fae7e583925bc3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 07:05:58 -0400 Subject: [PATCH 080/464] Made LiNG-D, LiNGAM non-experimental. --- .../algcomparison/algorithm/continuous/dag/LingD.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 3a9d64c7c4..73099bc157 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -51,18 +51,14 @@ public Graph search(DataModel dataSet, Parameters parameters) { int count = 0; for (edu.cmu.tetrad.search.LingD.Result result : results) { - Matrix bHat = result.getBHat(); - Graph graph = result.getGraph(); - System.out.println("LiNG-D Model #" + (++count)); System.out.println(); - System.out.println("BHat = " + bHat); - System.out.println("Graph = " + graph); + System.out.println("BHat = " + result.getBHat()); + System.out.println("Graph = " + result.getGraph()); } if (results.size() > 0) { - edu.cmu.tetrad.search.LingD.Result result = results.get(0); - return result.getGraph(); + return results.get(0).getGraph(); } else { throw new IllegalArgumentException("LiNG-D couldn't find a model."); } From c30fc9319a7b78f5eb9552e2cf9ca84e35d98dd8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 07:14:07 -0400 Subject: [PATCH 081/464] Made LiNG-D, LiNGAM non-experimental. --- .../algcomparison/algorithm/continuous/dag/LingD.java | 8 ++++---- .../src/main/java/edu/cmu/tetrad/util/TetradLogger.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 73099bc157..498d8c07d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -12,6 +12,7 @@ import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; +import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import java.util.ArrayList; @@ -51,10 +52,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { int count = 0; for (edu.cmu.tetrad.search.LingD.Result result : results) { - System.out.println("LiNG-D Model #" + (++count)); - System.out.println(); - System.out.println("BHat = " + result.getBHat()); - System.out.println("Graph = " + result.getGraph()); + TetradLogger.getInstance().forceLogMessage("LiNG-D Model #" + (++count)); + TetradLogger.getInstance().forceLogMessage(result.getBHat().toString()); + TetradLogger.getInstance().forceLogMessage(result.getGraph().toString()); } if (results.size() > 0) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java index 081e56cdd1..46b019dfa8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java @@ -316,9 +316,9 @@ public void error(String message) { * will be logged if the logger has been turned off. */ public void forceLogMessage(String message) { - if (this.logging) { - System.out.println(message); + System.out.println(message); + if (this.logging) { if (this.config == null) { this.fireActived(new EmptyConfig(true)); } From a1f527980f15adc748f47b2a7b8bec362b615d87 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 13:37:17 -0400 Subject: [PATCH 082/464] Made LiNG-D, LiNGAM non-experimental. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 3a4f7aa26e..01164e0ec3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -173,10 +173,7 @@ public static Graph makeGraph(Matrix B, List variables) { * @see PermutationMatrixPair */ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { - System.out.println("nrooks starting"); - List pairs = nRooks(W.transpose()); - System.out.println("nrooks finished"); if (pairs.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); From 69b152a442234d9025410945b33411fb861783a3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 14:04:25 -0400 Subject: [PATCH 083/464] Made LiNG-D, LiNGAM non-experimental. --- .../algorithm/continuous/dag/LingD.java | 13 +++++----- .../algorithm/continuous/dag/Lingam.java | 9 ++++--- .../java/edu/cmu/tetrad/search/LingD.java | 26 +++---------------- .../java/edu/cmu/tetrad/search/Lingam.java | 15 +++-------- .../java/edu/cmu/tetrad/test/TestLing.java | 16 +++++------- 5 files changed, 25 insertions(+), 54 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 498d8c07d7..9c7322c0e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -47,18 +47,19 @@ public Graph search(DataModel dataSet, Parameters parameters) { edu.cmu.tetrad.search.LingD lingD = new edu.cmu.tetrad.search.LingD(); lingD.setWThreshold(wThreshold); - List results = lingD.search(W, dataSet.getVariables()); + List bHats = lingD.search(W); int count = 0; - for (edu.cmu.tetrad.search.LingD.Result result : results) { + for (Matrix bHat : bHats) { TetradLogger.getInstance().forceLogMessage("LiNG-D Model #" + (++count)); - TetradLogger.getInstance().forceLogMessage(result.getBHat().toString()); - TetradLogger.getInstance().forceLogMessage(result.getGraph().toString()); + Graph graph = edu.cmu.tetrad.search.LingD.makeGraph(bHat, dataSet.getVariables()); + TetradLogger.getInstance().forceLogMessage(bHat.toString()); + TetradLogger.getInstance().forceLogMessage(graph.toString()); } - if (results.size() > 0) { - return results.get(0).getGraph(); + if (bHats.size() > 0) { + return edu.cmu.tetrad.search.LingD.makeGraph(bHats.get(0), dataSet.getVariables()); } else { throw new IllegalArgumentException("LiNG-D couldn't find a model."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 4c4107a84d..a46d1b3493 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -48,11 +48,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); lingam.setWThreshold(wThreshold); - LingD.Result result = lingam.search(W, data.getVariables()); - TetradLogger.getInstance().forceLogMessage(result.getBHat().toString()); - TetradLogger.getInstance().forceLogMessage(result.getGraph().toString()); + Matrix bHat = lingam.search(W); + Graph graph = LingD.makeGraph(bHat, data.getVariables()); + TetradLogger.getInstance().forceLogMessage(bHat.toString()); + TetradLogger.getInstance().forceLogMessage(graph.toString()); - return result.getGraph(); + return graph; } else { Lingam algorithm = new Lingam(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 01164e0ec3..3edafb2a8b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -65,7 +65,7 @@ public LingD() { * @param W The W matrix to be used. * @return A list of graphs generated by LiNG-D. */ - public List search(Matrix W, List variables) { + public List search(Matrix W) { System.out.println("Starting LiNG-D"); W = LingD.threshold(W, wThreshold); List pairs = nRooks(W); @@ -74,36 +74,16 @@ public List search(Matrix W, List variables) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); } - List results = new ArrayList<>(); + List results = new ArrayList<>(); for (PermutationMatrixPair pair : pairs) { Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); - Graph graph = edu.cmu.tetrad.search.LingD.makeGraph(bHat, variables); - Result result = new Result(bHat, graph); - results.add(result); + results.add(bHat); } return results; } - public static class Result { - private Matrix bHat; - private Graph graph; - - public Result(Matrix bHat, Graph graph) { - this.bHat = bHat.copy(); - this.graph = new EdgeListGraph(graph); - } - - public Matrix getBHat() { - return bHat; - } - - public Graph getGraph() { - return graph; - } - } - /** * Sets the threshold used to prune the W matrix for the local algorithms. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 57f731286a..b5ab0a1198 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -21,11 +21,8 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; -import java.util.List; - import static edu.cmu.tetrad.search.LingD.threshold; /** @@ -47,13 +44,10 @@ public Lingam() { /** * Searches given the W matrix from ICA. - * * @param W the W matrix from ICA. - * @param variables The variables from the original dataset used to generate the W matrix, - * in the order they occur in that dataset. - * @return The graph returned. + * @return The estimated B Hat matrix. */ - public LingD.Result search(Matrix W, List variables) { + public Matrix search(Matrix W) { W = threshold(W, wThreshold); PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); Matrix WTilde = bestPair.getPermutedMatrix().transpose(); @@ -64,10 +58,7 @@ public LingD.Result search(Matrix W, List variables) { int[] perm = bestPair.getRowPerm(); int[] inverse = LingD.inversePermutation(perm); PermutationMatrixPair inversePair = new PermutationMatrixPair(BHat, inverse, inverse); - Matrix _bHat = inversePair.getPermutedMatrix(); - - // Make the graph and return it. - return new LingD.Result(BHat, LingD.makeGraph(_bHat, variables)); + return inversePair.getPermutedMatrix(); } /** diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 7262883a12..fcb780018d 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -84,18 +84,17 @@ public void test1() { // We send any small value in W to 0 that has absolute value below a given threshold. // We do no further pruning on the B matrix. (The algorithm spec wants us to do both - // but pruning the W matrix seems to be giving better results, and besides in LiNG-D + // but pruning the W matrix seems to be giving better bHats, and besides in LiNG-D // the W matrix is pruned. Could switch though.) double wThreshold = 0.25; System.out.println("W threshold = " + wThreshold); Lingam lingam = new Lingam(); lingam.setWThreshold(wThreshold); - LingD.Result result = lingam.search(W, dataSet.getVariables()); - Graph lingamGraph = result.getGraph(); + Matrix lingamBhat = lingam.search(W); + Graph lingamGraph = LingD.makeGraph(lingamBhat, dataSet.getVariables()); System.out.println("Lingam graph = " + lingamGraph); - Matrix lingamBhat = result.getBHat(); boolean lingamStable = LingD.isStable(lingamBhat); System.out.println(lingamStable ? "Is Stable" : "Not stable"); @@ -105,22 +104,21 @@ public void test1() { // For LiNG-D, we can just call the relevant public static methods. This was obviously written // by a Matlab person. // - // We generate results of column permutations (solving the constriained N Rooks problem) with their + // We generate bHats of column permutations (solving the constriained N Rooks problem) with their // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); LingD lingD = new LingD(); lingD.setWThreshold(wThreshold); - List results = lingD.search(W, dataSet.getVariables()); + List bHats = lingD.search(W); - if (results.isEmpty()) { + if (bHats.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); } System.out.println("Then, for each constrained N Rooks solution, a column permutation of thresholded W:"); - for (LingD.Result pair : results) { - Matrix bHat = pair.getBHat(); + for (Matrix bHat : bHats) { System.out.println("BHat = " + bHat); Graph lingGraph = LingD.makeGraph(bHat, dataSet.getVariables()); From 5c9081d0c209d1ba13eacc2fa6223b4f3b327f44 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 30 Apr 2023 14:07:23 -0400 Subject: [PATCH 084/464] Made LiNG-D, LiNGAM non-experimental. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 3edafb2a8b..59c6333a87 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -63,7 +63,7 @@ public LingD() { * thresholded without bootstrapping. * * @param W The W matrix to be used. - * @return A list of graphs generated by LiNG-D. + * @return A list of estimated B Hat matrices generated by LiNG-D. */ public List search(Matrix W) { System.out.println("Starting LiNG-D"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index b5ab0a1198..737f955f7d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -44,7 +44,7 @@ public Lingam() { /** * Searches given the W matrix from ICA. - * @param W the W matrix from ICA. + * @param W the W matrix from ICA. * @return The estimated B Hat matrix. */ public Matrix search(Matrix W) { From 8e864f4c2c404b15a1e19ffe2e4f1bd2e21be7ba Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 1 May 2023 06:53:12 -0400 Subject: [PATCH 085/464] Two threshold LiNGAM idea. --- docs/manual/index.html | 25 ++++++++++++++++++- .../algorithm/continuous/dag/LingD.java | 3 +++ .../algorithm/continuous/dag/Lingam.java | 3 +++ .../java/edu/cmu/tetrad/search/LingD.java | 20 +++++++++++---- .../java/edu/cmu/tetrad/search/Lingam.java | 10 +++++++- .../main/java/edu/cmu/tetrad/util/Params.java | 1 + .../java/edu/cmu/tetrad/test/TestLing.java | 2 ++ 7 files changed, 57 insertions(+), 7 deletions(-) diff --git a/docs/manual/index.html b/docs/manual/index.html index 3d3a25ae8a..9b51b27a97 100755 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -5558,7 +5558,7 @@

    fastIcaA

    to zero.
  • Default Value: 0.3
  • + id="wThreshold_default_value">0.1
  • Lower Bound: 0.0
  • Upper @@ -5567,6 +5567,29 @@

    fastIcaA

    id="wThreshold_value_type">Double
+

spineThreshold

+
    +
  • Short Description: Threshold on the diagonal of the W matrix. +
  • +
  • Long Description: The diagonal of the estimated W matrix + is thresholded by setting small entries less than this threshold + to zero. Should be >= W threshold. +
  • +
  • Default Value: 0.8
  • +
  • Lower Bound: + 0.0
  • +
  • Upper + Bound: Infinity
  • +
  • Value Type: Double
  • +
+ +

fisherEpsilon

    bHats = lingD.search(W); int count = 0; @@ -100,6 +102,7 @@ public List getParameters() { parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); parameters.add(Params.W_THRESHOLD); + parameters.add(Params.SPINE_THRESHOLD); return parameters; } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index a46d1b3493..adc494ebcd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -43,10 +43,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); double wThreshold = parameters.getDouble(Params.W_THRESHOLD); + double spineThreshold = parameters.getDouble(Params.SPINE_THRESHOLD); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); lingam.setWThreshold(wThreshold); + lingam.setSpineThreshold(spineThreshold); Matrix bHat = lingam.search(W); Graph graph = LingD.makeGraph(bHat, data.getVariables()); @@ -91,6 +93,7 @@ public List getParameters() { parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); parameters.add(Params.W_THRESHOLD); + parameters.add(Params.SPINE_THRESHOLD); return parameters; } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 59c6333a87..f7007548ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -48,6 +48,7 @@ public class LingD { private double wThreshold; + private double spineThreshold; /** * Constructor. The W matrix needs to be estimated separately (e.g., using @@ -68,7 +69,7 @@ public LingD() { public List search(Matrix W) { System.out.println("Starting LiNG-D"); W = LingD.threshold(W, wThreshold); - List pairs = nRooks(W); + List pairs = nRooks(W, spineThreshold); if (pairs.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); @@ -91,9 +92,17 @@ public List search(Matrix W) { */ public void setWThreshold(double wThreshold) { if (wThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + wThreshold); + if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); this.wThreshold = wThreshold; } + public void setSpineThreshold(double spineThreshold) { + if (spineThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); + if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); + this.spineThreshold = spineThreshold; + } + + /** * Estimates the W matrix using FastICA. Assumes the "parallel" option, using * the "exp" function. @@ -152,8 +161,8 @@ public static Graph makeGraph(Matrix B, List variables) { * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair */ - public static PermutationMatrixPair strongestDiagonalByCols(Matrix W) { - List pairs = nRooks(W.transpose()); + public static PermutationMatrixPair strongestDiagonalByCols(Matrix W, double spineThrehold) { + List pairs = nRooks(W.transpose(), spineThrehold); if (pairs.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); @@ -277,13 +286,13 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair) { } @NotNull - private static List nRooks(Matrix W) { + private static List nRooks(Matrix W, double spineThreshold) { List pairs = new ArrayList<>(); boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; for (int i = 0; i < W.rows(); i++) { for (int j = 0; j < W.columns(); j++) { - allowablePositions[i][j] = W.get(i, j) != 0; + allowablePositions[i][j] = abs(W.get(i, j)) > spineThreshold;// W.get(i, j) != 0; } } @@ -305,6 +314,7 @@ static int[] inversePermutation(int[] perm) { return inverse; } + } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 737f955f7d..36778a7275 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -33,6 +33,7 @@ */ public class Lingam { private double wThreshold; + private double spineThreshold; //================================CONSTRUCTORS==========================// @@ -49,7 +50,7 @@ public Lingam() { */ public Matrix search(Matrix W) { W = threshold(W, wThreshold); - PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W); + PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W, spineThreshold); Matrix WTilde = bestPair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); @@ -68,7 +69,14 @@ public Matrix search(Matrix W) { */ public void setWThreshold(double wThreshold) { if (wThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + wThreshold); + if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); this.wThreshold = wThreshold; } + + public void setSpineThreshold(double spineThreshold) { + if (spineThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); + if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); + this.spineThreshold = spineThreshold; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index 894f7ddde9..0aa3a96b2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -81,6 +81,7 @@ public final class Params { public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; public static final String W_THRESHOLD = "wThreshold"; + public static final String SPINE_THRESHOLD = "spineThreshold"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; public static final String GENERAL_SEM_ERROR_TEMPLATE = "generalSemErrorTemplate"; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index fcb780018d..7627b70e02 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -87,10 +87,12 @@ public void test1() { // but pruning the W matrix seems to be giving better bHats, and besides in LiNG-D // the W matrix is pruned. Could switch though.) double wThreshold = 0.25; + double spineThreshold = 0.5; System.out.println("W threshold = " + wThreshold); Lingam lingam = new Lingam(); lingam.setWThreshold(wThreshold); + lingam.setSpineThreshold(spineThreshold); Matrix lingamBhat = lingam.search(W); Graph lingamGraph = LingD.makeGraph(lingamBhat, dataSet.getVariables()); System.out.println("Lingam graph = " + lingamGraph); From c9e411b34b1a9e78881e41f24a7413346ff426e8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 1 May 2023 07:01:08 -0400 Subject: [PATCH 086/464] Two threshold LiNGAM idea. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 36778a7275..cf20bbd630 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -49,11 +49,12 @@ public Lingam() { * @return The estimated B Hat matrix. */ public Matrix search(Matrix W) { - W = threshold(W, wThreshold); +// W = threshold(W, wThreshold); PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W, spineThreshold); Matrix WTilde = bestPair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); + BHat = threshold(BHat, wThreshold); // Grab the permuted BHat and variables. int[] perm = bestPair.getRowPerm(); From a6b7fc23bf6455e081592158315c42750576ee09 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 1 May 2023 07:50:33 -0400 Subject: [PATCH 087/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- docs/manual/index.html | 14 ++++++------- .../algorithm/continuous/dag/LingD.java | 4 ++-- .../algorithm/continuous/dag/Lingam.java | 4 ++-- .../java/edu/cmu/tetrad/search/LingD.java | 20 +++++++++---------- .../java/edu/cmu/tetrad/search/Lingam.java | 19 ++++++++---------- .../main/java/edu/cmu/tetrad/util/Params.java | 2 +- .../java/edu/cmu/tetrad/test/TestLing.java | 9 +++++---- 7 files changed, 34 insertions(+), 38 deletions(-) diff --git a/docs/manual/index.html b/docs/manual/index.html index 9b51b27a97..4e648eb6eb 100755 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -5546,25 +5546,25 @@

    fastIcaA

wThreshold

+ id="bThreshold">bThreshold
  • Short Description: Threshold on the W matrix. + id="bThreshold_short_desc">Threshold on the W matrix.
  • Long Description: The estimated W matrix + id="bThreshold_long_desc">The estimated B matrix is thresholded by setting small entries less than this threshold to zero.
  • Default Value: 0.1
  • + id="bThreshold_default_value">0.1
  • Lower Bound: - 0.0
  • + 0.0
  • Upper - Bound: Infinity
  • + Bound: Infinity
  • Value Type: Double
  • + id="bThreshold_value_type">Double

bHats = lingD.search(W); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index adc494ebcd..babd21520c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -42,12 +42,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double wThreshold = parameters.getDouble(Params.W_THRESHOLD); + double bThreshold = parameters.getDouble(Params.W_THRESHOLD); double spineThreshold = parameters.getDouble(Params.SPINE_THRESHOLD); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setWThreshold(wThreshold); + lingam.setBThreshold(bThreshold); lingam.setSpineThreshold(spineThreshold); Matrix bHat = lingam.search(W); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index f7007548ba..d40b3f9bda 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -47,8 +47,8 @@ */ public class LingD { - private double wThreshold; - private double spineThreshold; + private double spineThreshold = 0.5; + private double bThreshold = 0.1; /** * Constructor. The W matrix needs to be estimated separately (e.g., using @@ -68,7 +68,6 @@ public LingD() { */ public List search(Matrix W) { System.out.println("Starting LiNG-D"); - W = LingD.threshold(W, wThreshold); List pairs = nRooks(W, spineThreshold); if (pairs.isEmpty()) { @@ -79,6 +78,7 @@ public List search(Matrix W) { for (PermutationMatrixPair pair : pairs) { Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); + bHat = LingD.threshold(bHat, bThreshold); results.add(bHat); } @@ -86,19 +86,17 @@ public List search(Matrix W) { } /** - * Sets the threshold used to prune the W matrix for the local algorithms. + * Sets the threshold used to prune the B matrix for the local algorithms. * - * @param wThreshold The treshold, a non-negative number. + * @param bThreshold The treshold, a non-negative number. */ - public void setWThreshold(double wThreshold) { - if (wThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + wThreshold); - if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); - this.wThreshold = wThreshold; + public void setBThreshold(double bThreshold) { + if (bThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + bThreshold); + this.bThreshold = bThreshold; } public void setSpineThreshold(double spineThreshold) { if (spineThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); - if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); this.spineThreshold = spineThreshold; } @@ -157,7 +155,7 @@ public static Graph makeGraph(Matrix B, List variables) { * of 1 / |Wii| for diagonal elements Wii in W. This will be speeded up * if W is a thresholded matrix. * - * @param W The (possibly thresholded) W matrix. + * @param W The W matrix, WX = e. * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index cf20bbd630..0932b38c11 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -32,8 +32,8 @@ * @author josephramsey */ public class Lingam { - private double wThreshold; - private double spineThreshold; + private double spineThreshold = 0.5; + private double bThreshold = 0.1; //================================CONSTRUCTORS==========================// @@ -45,16 +45,15 @@ public Lingam() { /** * Searches given the W matrix from ICA. - * @param W the W matrix from ICA. + * @param W the W matrix from ICA, WX = e. * @return The estimated B Hat matrix. */ public Matrix search(Matrix W) { -// W = threshold(W, wThreshold); PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W, spineThreshold); Matrix WTilde = bestPair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); - BHat = threshold(BHat, wThreshold); + BHat = threshold(BHat, bThreshold); // Grab the permuted BHat and variables. int[] perm = bestPair.getRowPerm(); @@ -66,17 +65,15 @@ public Matrix search(Matrix W) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. * - * @param wThreshold Some value >= 0. + * @param bThreshold Some value >= 0. */ - public void setWThreshold(double wThreshold) { - if (wThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + wThreshold); - if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); - this.wThreshold = wThreshold; + public void setBThreshold(double bThreshold) { + if (bThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + bThreshold); + this.bThreshold = bThreshold; } public void setSpineThreshold(double spineThreshold) { if (spineThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); - if (spineThreshold < this.wThreshold) throw new IllegalArgumentException("Spine threshold should be >= W threshold."); this.spineThreshold = spineThreshold; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index 0aa3a96b2b..c56f508499 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -80,7 +80,7 @@ public final class Params { public static final String FAST_ICA_TOLERANCE = "fastIcaTolerance"; public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; - public static final String W_THRESHOLD = "wThreshold"; + public static final String W_THRESHOLD = "bThreshold"; public static final String SPINE_THRESHOLD = "spineThreshold"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 7627b70e02..9df109dd45 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -86,12 +86,12 @@ public void test1() { // We do no further pruning on the B matrix. (The algorithm spec wants us to do both // but pruning the W matrix seems to be giving better bHats, and besides in LiNG-D // the W matrix is pruned. Could switch though.) - double wThreshold = 0.25; + double bThreshold = 0.25; double spineThreshold = 0.5; - System.out.println("W threshold = " + wThreshold); + System.out.println("W threshold = " + bThreshold); Lingam lingam = new Lingam(); - lingam.setWThreshold(wThreshold); + lingam.setBThreshold(bThreshold); lingam.setSpineThreshold(spineThreshold); Matrix lingamBhat = lingam.search(W); Graph lingamGraph = LingD.makeGraph(lingamBhat, dataSet.getVariables()); @@ -111,7 +111,8 @@ public void test1() { // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); LingD lingD = new LingD(); - lingD.setWThreshold(wThreshold); + lingD.setBThreshold(bThreshold); + lingD.setSpineThreshold(spineThreshold); List bHats = lingD.search(W); if (bHats.isEmpty()) { From af0aa7e8e1151bc4360ca9a7e9b87e3930ddafd1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 1 May 2023 08:22:46 -0400 Subject: [PATCH 088/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 9df109dd45..0617e12922 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -106,7 +106,7 @@ public void test1() { // For LiNG-D, we can just call the relevant public static methods. This was obviously written // by a Matlab person. // - // We generate bHats of column permutations (solving the constriained N Rooks problem) with their + // We generate bHats of column permutations (solving the constrained N Rooks problem) with their // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); From bf8ebc559d4207b8627480e51b29132e3a364f09 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 1 May 2023 08:24:09 -0400 Subject: [PATCH 089/464] Did some optimizations; this version will scale ot 100 variables average degree 4. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index d40b3f9bda..26374c8247 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -88,7 +88,7 @@ public List search(Matrix W) { /** * Sets the threshold used to prune the B matrix for the local algorithms. * - * @param bThreshold The treshold, a non-negative number. + * @param bThreshold The threshold, a non-negative number. */ public void setBThreshold(double bThreshold) { if (bThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + bThreshold); From c042170609242314fe5344a5e9e8d47d3e3e9164 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 1 May 2023 18:11:37 -0400 Subject: [PATCH 090/464] Final commit, ling PR. --- docs/manual/index.html | 28 +- .../algorithm/continuous/dag/LingD.java | 9 +- .../algorithm/continuous/dag/Lingam.java | 8 +- .../java/edu/cmu/tetrad/data/BoxDataSet.java | 2 +- .../cmu/tetrad/search/HungarianAlgorithm.java | 314 ++++++++++++++++++ .../java/edu/cmu/tetrad/search/LingD.java | 66 +++- .../java/edu/cmu/tetrad/search/NRooks.java | 3 +- .../main/java/edu/cmu/tetrad/util/Params.java | 4 +- 8 files changed, 403 insertions(+), 31 deletions(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java diff --git a/docs/manual/index.html b/docs/manual/index.html index 4e648eb6eb..15742d3997 100755 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -5546,47 +5546,47 @@

fastIcaA

bThreshold

+ id="thresholdBHat">thresholdBHat

  • Short Description: Threshold on the W matrix. + id="thresholdBHat_short_desc">Threshold on the B Hat matrix.
  • Long Description: The estimated B matrix + id="thresholdBHat_long_desc">The estimated B matrix is thresholded by setting small entries less than this threshold to zero.
  • Default Value: 0.1
  • + id="thresholdBHat_default_value">0.1
  • Lower Bound: - 0.0
  • + 0.0
  • Upper - Bound: Infinity
  • + Bound: Infinity
  • Value Type: Double
  • + id="thresholdBHat_value_type">Double

spineThreshold

+ id="thresholdSpine">thresholdSpine
  • Short Description: Threshold on the diagonal of the W matrix. + id="thresholdSpine_short_desc">Threshold on the diagonal of the W matrix.
  • Long Description: The diagonal of the estimated W matrix + id="thresholdSpine_long_desc">The diagonal of the estimated W matrix is thresholded by setting small entries less than this threshold to zero. Should be >= W threshold.
  • Default Value: 0.8
  • + id="thresholdSpine_default_value">0.8
  • Lower Bound: - 0.0
  • + 0.0
  • Upper - Bound: Infinity
  • + Bound: Infinity
  • Value Type: Double
  • + id="thresholdSpine_value_type">Double
diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index b43b8dcb63..c49681b533 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -41,8 +41,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double bThreshold = parameters.getDouble(Params.W_THRESHOLD); - double spineThreshold = parameters.getDouble(Params.SPINE_THRESHOLD); + double bThreshold = parameters.getDouble(Params.THRESHOLD_W); + double spineThreshold = parameters.getDouble(Params.THRESHOLD_SPINE); Matrix W = edu.cmu.tetrad.search.LingD.estimateW(data, maxIter, tol, alpha); @@ -58,6 +58,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { Graph graph = edu.cmu.tetrad.search.LingD.makeGraph(bHat, dataSet.getVariables()); TetradLogger.getInstance().forceLogMessage(bHat.toString()); TetradLogger.getInstance().forceLogMessage(graph.toString()); + TetradLogger.getInstance().forceLogMessage("Stable = " + edu.cmu.tetrad.search.LingD.isStable(bHat)); } if (bHats.size() > 0) { @@ -101,8 +102,8 @@ public List getParameters() { parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); - parameters.add(Params.W_THRESHOLD); - parameters.add(Params.SPINE_THRESHOLD); + parameters.add(Params.THRESHOLD_W); + parameters.add(Params.THRESHOLD_SPINE); return parameters; } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index babd21520c..9469668bd3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -42,8 +42,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double bThreshold = parameters.getDouble(Params.W_THRESHOLD); - double spineThreshold = parameters.getDouble(Params.SPINE_THRESHOLD); + double bThreshold = parameters.getDouble(Params.THRESHOLD_W); + double spineThreshold = parameters.getDouble(Params.THRESHOLD_SPINE); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); @@ -92,8 +92,8 @@ public List getParameters() { parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); - parameters.add(Params.W_THRESHOLD); - parameters.add(Params.SPINE_THRESHOLD); + parameters.add(Params.THRESHOLD_W); + parameters.add(Params.THRESHOLD_SPINE); return parameters; } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java index c9f4af0457..004f90da59 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java @@ -1018,7 +1018,7 @@ public void removeCols(int[] cols) { retainedVars.add(this.variables.get(retainedCol)); } - this.dataBox = viewSelection(rows, cols); + this.dataBox = viewSelection(rows, retainedCols); this.variables = retainedVars; this.selection = new HashSet<>(); this.multipliers = new HashMap<>(this.multipliers); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java new file mode 100644 index 0000000000..fc2d2b4cf0 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java @@ -0,0 +1,314 @@ +package edu.cmu.tetrad.search; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + *

An implemetation of the Kuhn–Munkres assignment algorithm of the year 1957. + * https://en.wikipedia.org/wiki/Hungarian_algorithm.

+ *

From: https://github.com/aalmi/HungarianAlgorithm

+ * + * @author https://github.com/aalmi | march 2014 + * @version 1.0 + */ +public class HungarianAlgorithm { + + double[][] costMatrix; // initial matrix (cost matrix) + + // markers in the matrix + int[] squareInRow, squareInCol, rowIsCovered, colIsCovered, staredZeroesInRow; + + /** + * Trying to find lowest-cost assignment. + */ + public HungarianAlgorithm(double[][] costMatrix) { + if (costMatrix.length != costMatrix[0].length) { + try { + throw new IllegalAccessException("The costMatrix is not square!"); + } catch (IllegalAccessException ex) { + System.err.println(ex); + System.exit(1); + } + } + + this.costMatrix = costMatrix; + squareInRow = new int[costMatrix.length]; // squareInRow & squareInCol indicate the position + squareInCol = new int[costMatrix[0].length]; // of the marked zeroes + + rowIsCovered = new int[costMatrix.length]; // indicates whether a row is covered + colIsCovered = new int[costMatrix[0].length]; // indicates whether a column is covered + staredZeroesInRow = new int[costMatrix.length]; // storage for the 0* + Arrays.fill(staredZeroesInRow, -1); + Arrays.fill(squareInRow, -1); + Arrays.fill(squareInCol, -1); + } + + /** + * find an optimal assignment + * + * @return optimal assignment + */ + public int[][] findOptimalAssignment() { + step1(); // reduce matrix + step2(); // mark independent zeroes + step3(); // cover columns which contain a marked zero + + while (!allColumnsAreCovered()) { + int[] mainZero = step4(); + while (mainZero == null) { // while no zero found in step4 + step7(); + mainZero = step4(); + } + if (squareInRow[mainZero[0]] == -1) { + // there is no square mark in the mainZero line + step6(mainZero); + step3(); // cover columns which contain a marked zero + } else { + // there is square mark in the mainZero line + // step 5 + rowIsCovered[mainZero[0]] = 1; // cover row of mainZero + colIsCovered[squareInRow[mainZero[0]]] = 0; // uncover column of mainZero + step7(); + } + } + + int[][] optimalAssignment = new int[costMatrix.length][]; + for (int i = 0; i < squareInCol.length; i++) { + optimalAssignment[i] = new int[]{i, squareInCol[i]}; + } + return optimalAssignment; + } + + /** + * Check if all columns are covered. If that's the case then the + * optimal solution is found + * + * @return true or false + */ + private boolean allColumnsAreCovered() { + for (int i : colIsCovered) { + if (i == 0) { + return false; + } + } + return true; + } + + /** + * Step 1: + * Reduce the matrix so that in each row and column at least one zero exists: + * 1. subtract each row minima from each element of the row + * 2. subtract each column minima from each element of the column + */ + private void step1() { + // rows + for (int i = 0; i < costMatrix.length; i++) { + // find the min value of the current row + double currentRowMin = Double.POSITIVE_INFINITY; + for (int j = 0; j < costMatrix[i].length; j++) { + if (costMatrix[i][j] < currentRowMin) { + currentRowMin = costMatrix[i][j]; + } + } + // subtract min value from each element of the current row + for (int k = 0; k < costMatrix[i].length; k++) { + costMatrix[i][k] -= currentRowMin; + } + } + + // cols + for (int i = 0; i < costMatrix[0].length; i++) { + // find the min value of the current column + double currentColMin = Double.POSITIVE_INFINITY; + for (double[] doubles : costMatrix) { + if (doubles[i] < currentColMin) { + currentColMin = doubles[i]; + } + } + // subtract min value from each element of the current column + for (int k = 0; k < costMatrix.length; k++) { + costMatrix[k][i] -= currentColMin; + } + } + } + + /** + * Step 2: + * mark each 0 with a "square", if there are no other marked zeroes in the same row or column + */ + private void step2() { + int[] rowHasSquare = new int[costMatrix.length]; + int[] colHasSquare = new int[costMatrix[0].length]; + + for (int i = 0; i < costMatrix.length; i++) { + for (int j = 0; j < costMatrix.length; j++) { + // mark if current value == 0 & there are no other marked zeroes in the same row or column + if (costMatrix[i][j] == 0 && rowHasSquare[i] == 0 && colHasSquare[j] == 0) { + rowHasSquare[i] = 1; + colHasSquare[j] = 1; + squareInRow[i] = j; // save the row-position of the zero + squareInCol[j] = i; // save the column-position of the zero + continue; // jump to next row + } + } + } + } + + /** + * Step 3: + * Cover all columns which are marked with a "square" + */ + private void step3() { + for (int i = 0; i < squareInCol.length; i++) { + colIsCovered[i] = squareInCol[i] != -1 ? 1 : 0; + } + } + + /** + * Step 7: + * 1. Find the smallest uncovered value in the matrix. + * 2. Subtract it from all uncovered values + * 3. Add it to all twice-covered values + */ + private void step7() { + // Find the smallest uncovered value in the matrix + double minUncoveredValue = Double.POSITIVE_INFINITY; + for (int i = 0; i < costMatrix.length; i++) { + if (rowIsCovered[i] == 1) { + continue; + } + for (int j = 0; j < costMatrix[0].length; j++) { + if (colIsCovered[j] == 0 && costMatrix[i][j] < minUncoveredValue) { + minUncoveredValue = costMatrix[i][j]; + } + } + } + + if (minUncoveredValue > 0) { + for (int i = 0; i < costMatrix.length; i++) { + for (int j = 0; j < costMatrix[0].length; j++) { + if (rowIsCovered[i] == 1 && colIsCovered[j] == 1) { + // Add min to all twice-covered values + costMatrix[i][j] += minUncoveredValue; + } else if (rowIsCovered[i] == 0 && colIsCovered[j] == 0) { + // Subtract min from all uncovered values + costMatrix[i][j] -= minUncoveredValue; + } + } + } + } + } + + /** + * Step 4: + * Find zero value Z_0 and mark it as "0*". + * + * @return position of Z_0 in the matrix + */ + private int[] step4() { + for (int i = 0; i < costMatrix.length; i++) { + if (rowIsCovered[i] == 0) { + for (int j = 0; j < costMatrix[i].length; j++) { + if (costMatrix[i][j] == 0 && colIsCovered[j] == 0) { + staredZeroesInRow[i] = j; // mark as 0* + return new int[]{i, j}; + } + } + } + } + return null; + } + + /** + * Step 6: + * Create a chain K of alternating "squares" and "0*" + * + * @param mainZero => Z_0 of Step 4 + */ + private void step6(int[] mainZero) { + int i = mainZero[0]; + int j = mainZero[1]; + + Set K = new LinkedHashSet<>(); + //(a) + // add Z_0 to K + K.add(mainZero); + boolean found = false; + do { + // (b) + // add Z_1 to K if + // there is a zero Z_1 which is marked with a "square " in the column of Z_0 + if (squareInCol[j] != -1) { + K.add(new int[]{squareInCol[j], j}); + found = true; + } else { + found = false; + } + + // if no zero element Z_1 marked with "square" exists in the column of Z_0, then cancel the loop + if (!found) { + break; + } + + // (c) + // replace Z_0 with the 0* in the row of Z_1 + i = squareInCol[j]; + j = staredZeroesInRow[i]; + // add the new Z_0 to K + if (j != -1) { + K.add(new int[]{i, j}); + found = true; + } else { + found = false; + } + + } while (found); // (d) as long as no new "square" marks are found + + // (e) + for (int[] zero : K) { + // remove all "square" marks in K + if (squareInCol[zero[1]] == zero[0]) { + squareInCol[zero[1]] = -1; + squareInRow[zero[0]] = -1; + } + // replace the 0* marks in K with "square" marks + if (staredZeroesInRow[zero[0]] == zero[1]) { + squareInRow[zero[0]] = zero[1]; + squareInCol[zero[1]] = zero[0]; + } + } + + // (f) + // remove all marks + Arrays.fill(staredZeroesInRow, -1); + Arrays.fill(rowIsCovered, 0); + Arrays.fill(colIsCovered, 0); + } + + public static void main(String[] args) { + + // the problem is written in the form of a matrix + double[][] dataMatrix = { + //col0 col1 col2 col3 + {70, 40, 20, 55}, //row0 + {65, 60, 45, 90}, //row1 + {30, 45, 50, 75}, //row2 + {25, 30, 55, 40} //row3 + }; + + //find optimal assignment + HungarianAlgorithm ha = new HungarianAlgorithm(dataMatrix); + int[][] assignment = ha.findOptimalAssignment(); + + if (assignment.length > 0) { + // print assignment + for (int[] ints : assignment) { + System.out.print("Col" + ints[0] + " => Row" + ints[1] + " (" + dataMatrix[ints[0]][ints[1]] + ")"); + System.out.println(); + } + } else { + System.out.println("no assignment found!"); + } + } +} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 26374c8247..aa24b06a96 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -21,16 +21,21 @@ package edu.cmu.tetrad.search; +import edu.cmu.tetrad.data.AndersonDarlingTest; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; +import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; +import org.apache.commons.math3.util.FastMath; import org.jetbrains.annotations.NotNull; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; @@ -96,7 +101,8 @@ public void setBThreshold(double bThreshold) { } public void setSpineThreshold(double spineThreshold) { - if (spineThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); + if (spineThreshold < 0) + throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); this.spineThreshold = spineThreshold; } @@ -113,6 +119,22 @@ public void setSpineThreshold(double spineThreshold) { */ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, double fastIcaA) { + data = data.copy(); + + double[][] _data = data.getDoubleData().transpose().toArray(); + TetradLogger.getInstance().forceLogMessage("Anderson Darling P-values Per Variables (p < alpha means Non-Guassian)"); + TetradLogger.getInstance().forceLogMessage(""); + + for (int i = 0; i < _data.length; i++) { + Node node = data.getVariable(i); + AndersonDarlingTest test = new AndersonDarlingTest(_data[i]); + double p = test.getP(); + NumberFormat nf = new DecimalFormat("0.000"); + TetradLogger.getInstance().forceLogMessage(node.getName() + ": p = " + nf.format(p)); + } + + TetradLogger.getInstance().forceLogMessage(""); + Matrix X = data.getDoubleData(); X = DataUtils.centerData(X).transpose(); FastIca fastIca = new FastIca(X, X.rows()); @@ -167,7 +189,7 @@ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W, double spi } PermutationMatrixPair bestPair = null; - double sum1 = Double.POSITIVE_INFINITY; + double sum1 = Double.NEGATIVE_INFINITY; P: for (PermutationMatrixPair pair : pairs) { @@ -181,10 +203,10 @@ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W, double spi continue P; } - sum += 1.0 / StrictMath.abs(a); + sum += FastMath.abs(a);//= 1.0 / StrictMath.abs(a); } - if (sum < sum1) { + if (sum > sum1) { sum1 = sum; bestPair = pair; } @@ -285,7 +307,41 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair) { @NotNull private static List nRooks(Matrix W, double spineThreshold) { + List pairs = pairNRook(W); +// List pairs = pairsNRook(W, spineThreshold); + + return pairs; + } + + @NotNull + private static List pairNRook(Matrix W) { + double[][] costMatrix = new double[W.rows()][W.columns()]; + + for (int i = 0; i < W.rows(); i++) { + for (int j = 0; j < W.columns(); j++) { + if (W.get(i, j) != 0) { + costMatrix[i][j] = 1.0 / abs(W.get(i, j)); + } else { + costMatrix[i][j] = 1000.0; + } + } + } + + HungarianAlgorithm alg = new HungarianAlgorithm(costMatrix); + int[][] assignment = alg.findOptimalAssignment(); + List pairs = new ArrayList<>(); + + int[] perm = new int[assignment.length]; + for (int i = 0; i < perm.length; i++) perm[i] = assignment[i][1]; + + PermutationMatrixPair pair = new PermutationMatrixPair(W, perm, null); + pairs.add(pair); + return pairs; + } + + @NotNull + private static List pairsNRook(Matrix W, double spineThreshold) { boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; for (int i = 0; i < W.rows(); i++) { @@ -294,12 +350,12 @@ private static List nRooks(Matrix W, double spineThreshol } } + List pairs = new ArrayList<>(); List colPermutations = NRooks.nRooks(allowablePositions); for (int[] colPermutation : colPermutations) { pairs.add(new PermutationMatrixPair(W, null, colPermutation)); } - return pairs; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 287099f73c..79f9d9a773 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -37,7 +37,7 @@ public static ArrayList nRooks(boolean[][] allowablePositions) { int col = 0; while (row < p) { - if (col >= p) { + if (col == p) { if (rows.isEmpty()) { break; } @@ -80,6 +80,7 @@ private static boolean isValid(boolean[][] board, int row, int col) { return false; } } + return true; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index c56f508499..4f09edf55b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -80,8 +80,8 @@ public final class Params { public static final String FAST_ICA_TOLERANCE = "fastIcaTolerance"; public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; - public static final String W_THRESHOLD = "bThreshold"; - public static final String SPINE_THRESHOLD = "spineThreshold"; + public static final String THRESHOLD_W = "thresholdBHat"; + public static final String THRESHOLD_SPINE = "thresholdSpine"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; public static final String GENERAL_SEM_ERROR_TEMPLATE = "generalSemErrorTemplate"; From 1dcde9ba6ad2e006b3fd60023e530a70d298fcc7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 1 May 2023 23:27:37 -0400 Subject: [PATCH 091/464] Fixed comment. --- .../main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index f67e7e4c64..a808034127 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -64,7 +64,8 @@ public PermutationMatrixPair(Matrix M, int[] rowPerm, int[] colPerm) { /** * Returns W, permuted rowwise by the permutation passed in through the constructor. - * @return The row-permuted W. + * @return The matrix, permuted columnwise and rowwise, by the specified column and + * row permutations. */ public Matrix getPermutedMatrix() { return M.getSelection(rowPerm, colPerm); From fa3f21041ac58e9cd8410f8a6cd19a79db899098 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 00:26:59 -0400 Subject: [PATCH 092/464] Fixed transposition problem. --- .../java/edu/cmu/tetrad/search/LingD.java | 34 +++++++++---------- .../java/edu/cmu/tetrad/search/Lingam.java | 15 +++----- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index aa24b06a96..eb8d522de2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -72,8 +72,7 @@ public LingD() { * @return A list of estimated B Hat matrices generated by LiNG-D. */ public List search(Matrix W) { - System.out.println("Starting LiNG-D"); - List pairs = nRooks(W, spineThreshold); + List pairs = nRooks(W.transpose(), spineThreshold); if (pairs.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); @@ -82,8 +81,7 @@ public List search(Matrix W) { List results = new ArrayList<>(); for (PermutationMatrixPair pair : pairs) { - Matrix bHat = edu.cmu.tetrad.search.LingD.getScaledBHat(pair); - bHat = LingD.threshold(bHat, bThreshold); + Matrix bHat = LingD.getScaledBHat(pair, bThreshold); results.add(bHat); } @@ -292,29 +290,29 @@ public static Matrix threshold(Matrix M, double threshold) { * * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. + * @param bThreshold Valued in the BHat matrix less than this in absolute + * value are set to 0. * @return The estimated B Hat matrix for this pair. * @see PermutationMatrixPair */ - public static Matrix getScaledBHat(PermutationMatrixPair pair) { - Matrix _w = pair.getPermutedMatrix(); - _w = scale(_w); - Matrix bHat = Matrix.identity(_w.rows()).minus(_w); - int[] perm = pair.getColPerm(); + public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold) { + Matrix WTilde = pair.getPermutedMatrix().transpose(); + WTilde = LingD.scale(WTilde); + Matrix BHat = Matrix.identity(WTilde.columns()).minus(WTilde); + BHat = threshold(BHat, bThreshold); + int[] perm = pair.getRowPerm(); int[] inverse = LingD.inversePermutation(perm); - PermutationMatrixPair inversePair = new PermutationMatrixPair(bHat, inverse, inverse); + PermutationMatrixPair inversePair = new PermutationMatrixPair(BHat, inverse, inverse); return inversePair.getPermutedMatrix(); } @NotNull - private static List nRooks(Matrix W, double spineThreshold) { - List pairs = pairNRook(W); -// List pairs = pairsNRook(W, spineThreshold); - - return pairs; + public static List nRooks(Matrix W, double spineThreshold) { + return pairsNRook(W, spineThreshold); } @NotNull - private static List pairNRook(Matrix W) { + private static List pairsHungarian(Matrix W) { double[][] costMatrix = new double[W.rows()][W.columns()]; for (int i = 0; i < W.rows(); i++) { @@ -346,7 +344,7 @@ private static List pairsNRook(Matrix W, double spineThre for (int i = 0; i < W.rows(); i++) { for (int j = 0; j < W.columns(); j++) { - allowablePositions[i][j] = abs(W.get(i, j)) > spineThreshold;// W.get(i, j) != 0; + allowablePositions[i][j] = abs(W.get(i, j)) > spineThreshold; } } @@ -356,6 +354,7 @@ private static List pairsNRook(Matrix W, double spineThre for (int[] colPermutation : colPermutations) { pairs.add(new PermutationMatrixPair(W, null, colPermutation)); } + return pairs; } @@ -368,7 +367,6 @@ static int[] inversePermutation(int[] perm) { return inverse; } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 0932b38c11..76e353b941 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -23,6 +23,10 @@ import edu.cmu.tetrad.util.Matrix; +import java.util.ArrayList; +import java.util.List; + +import static edu.cmu.tetrad.search.LingD.nRooks; import static edu.cmu.tetrad.search.LingD.threshold; /** @@ -50,16 +54,7 @@ public Lingam() { */ public Matrix search(Matrix W) { PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W, spineThreshold); - Matrix WTilde = bestPair.getPermutedMatrix().transpose(); - WTilde = LingD.scale(WTilde); - Matrix BHat = Matrix.identity(W.columns()).minus(WTilde); - BHat = threshold(BHat, bThreshold); - - // Grab the permuted BHat and variables. - int[] perm = bestPair.getRowPerm(); - int[] inverse = LingD.inversePermutation(perm); - PermutationMatrixPair inversePair = new PermutationMatrixPair(BHat, inverse, inverse); - return inversePair.getPermutedMatrix(); + return LingD.getScaledBHat(bestPair, bThreshold); } /** From 99ed702102fbbb2b182cf6a61f8e497ecf35cf3f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 00:34:24 -0400 Subject: [PATCH 093/464] Fixed some commenting. --- .../algorithm/continuous/dag/LingD.java | 3 +-- .../algorithm/continuous/dag/Lingam.java | 1 - .../main/java/edu/cmu/tetrad/search/LingD.java | 15 +++++---------- .../main/java/edu/cmu/tetrad/search/Lingam.java | 16 ++++++---------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index c49681b533..571d2f8db1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -19,8 +19,7 @@ import java.util.List; /** - * LiNGAM. - * + * LiNG-D. * @author jdramsey */ @edu.cmu.tetrad.annotation.Algorithm( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 9469668bd3..29b1382b8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -21,7 +21,6 @@ /** * LiNGAM. - * * @author jdramsey */ @edu.cmu.tetrad.annotation.Algorithm( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index eb8d522de2..7ff80b6fd4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -47,11 +47,9 @@ *

Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering * cyclic causal models by independent components analysis. arXiv preprint * arXiv:1206.3273.

- * * @author josephramsey */ public class LingD { - private double spineThreshold = 0.5; private double bThreshold = 0.1; @@ -90,7 +88,6 @@ public List search(Matrix W) { /** * Sets the threshold used to prune the B matrix for the local algorithms. - * * @param bThreshold The threshold, a non-negative number. */ public void setBThreshold(double bThreshold) { @@ -98,17 +95,19 @@ public void setBThreshold(double bThreshold) { this.bThreshold = bThreshold; } + /** + * Sets the threshold used to prune the matrix for purpose of searching for alterantive strong dia=gonals.. + * @param spineThreshold The threshold, a non-negative number. + */ public void setSpineThreshold(double spineThreshold) { if (spineThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); this.spineThreshold = spineThreshold; } - /** * Estimates the W matrix using FastICA. Assumes the "parallel" option, using * the "exp" function. - * * @param data The dataset to estimate W for. * @param fastIcaMaxIter Maximum number of iterations of ICA. * @param fastIcaTolerance Tolerance for ICA. @@ -151,7 +150,6 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT * Returns a graph given a coefficient matrix and a list of variables. It is * assumed that any non-zero entry in B corresponds to a directed edges, so * that Bij != 0 implies that j->i in the graph. - * * @param B The coefficient matrix. * @param variables The list of variables. * @return The built graph. @@ -174,8 +172,8 @@ public static Graph makeGraph(Matrix B, List variables) { * Finds a column permutation of the W matrix that maximizes the sum * of 1 / |Wii| for diagonal elements Wii in W. This will be speeded up * if W is a thresholded matrix. - * * @param W The W matrix, WX = e. + * @param spineThrehold The threshold used in NRooks to search for alternative strong diagonals. * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair */ @@ -246,7 +244,6 @@ public static boolean isStable(Matrix bHat) { /** * Scares the given matrix M by diving each entry (i, j) by M(j, j) - * * @param M The matrix to scale. * @return The scaled matrix. */ @@ -264,7 +261,6 @@ public static Matrix scale(Matrix M) { /** * Thresholds the givem matrix, sending any small entries to zero. - * * @param M The matrix to threshold. * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. * Should be non-negative. @@ -287,7 +283,6 @@ public static Matrix threshold(Matrix M, double threshold) { /** * Returns the BHat matrix, permuted to causal order (lower triangle) and * scaled so that the diagonal consists only of 1's. - * * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. * @param bThreshold Valued in the BHat matrix less than this in absolute diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 76e353b941..c2bc7db83d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -23,12 +23,6 @@ import edu.cmu.tetrad.util.Matrix; -import java.util.ArrayList; -import java.util.List; - -import static edu.cmu.tetrad.search.LingD.nRooks; -import static edu.cmu.tetrad.search.LingD.threshold; - /** *

Implements the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, and Kerminen, A linear * nongaussian acyclic model for causal discovery, JMLR 7 (2006).

@@ -39,8 +33,6 @@ public class Lingam { private double spineThreshold = 0.5; private double bThreshold = 0.1; - //================================CONSTRUCTORS==========================// - /** * Constructs a new LiNGAM algorithm with the given alpha level (used for pruning). */ @@ -59,7 +51,6 @@ public Matrix search(Matrix W) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. - * * @param bThreshold Some value >= 0. */ public void setBThreshold(double bThreshold) { @@ -67,8 +58,13 @@ public void setBThreshold(double bThreshold) { this.bThreshold = bThreshold; } + /** + * Sets the threshold used to prune the matrix for purpose of searching for alterantive strong dia=gonals.. + * @param spineThreshold The threshold, a non-negative number. + */ public void setSpineThreshold(double spineThreshold) { - if (spineThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); + if (spineThreshold < 0) + throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); this.spineThreshold = spineThreshold; } } From 01debf662a6421b9da50af8ae6ae1cca8cf2933a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 01:53:09 -0400 Subject: [PATCH 094/464] Fixed some commenting. --- .../algcomparison/algorithm/continuous/dag/LingD.java | 4 ++-- .../algcomparison/algorithm/continuous/dag/Lingam.java | 6 +++--- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 571d2f8db1..77304202d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -40,7 +40,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double bThreshold = parameters.getDouble(Params.THRESHOLD_W); + double bThreshold = parameters.getDouble(Params.THRESHOLD_B); double spineThreshold = parameters.getDouble(Params.THRESHOLD_SPINE); Matrix W = edu.cmu.tetrad.search.LingD.estimateW(data, maxIter, tol, alpha); @@ -101,7 +101,7 @@ public List getParameters() { parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); parameters.add(Params.FAST_ICA_TOLERANCE); - parameters.add(Params.THRESHOLD_W); + parameters.add(Params.THRESHOLD_B); parameters.add(Params.THRESHOLD_SPINE); return parameters; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 29b1382b8f..028e3cb7f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -41,7 +41,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double bThreshold = parameters.getDouble(Params.THRESHOLD_W); + double bThreshold = parameters.getDouble(Params.THRESHOLD_B); double spineThreshold = parameters.getDouble(Params.THRESHOLD_SPINE); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); @@ -88,10 +88,10 @@ public DataType getDataType() { public List getParameters() { List parameters = new ArrayList<>(); parameters.add(Params.VERBOSE); - parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_MAX_ITER); + parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_TOLERANCE); - parameters.add(Params.THRESHOLD_W); + parameters.add(Params.THRESHOLD_B); parameters.add(Params.THRESHOLD_SPINE); return parameters; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index 4f09edf55b..897a9722a9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -80,7 +80,7 @@ public final class Params { public static final String FAST_ICA_TOLERANCE = "fastIcaTolerance"; public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; - public static final String THRESHOLD_W = "thresholdBHat"; + public static final String THRESHOLD_B = "thresholdBHat"; public static final String THRESHOLD_SPINE = "thresholdSpine"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; From 62f6ec27248b24847e1a69fb2f32acfb311c88f7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 12:01:41 -0400 Subject: [PATCH 095/464] Fixed some commenting. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 7ff80b6fd4..ee06c42ad2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -165,6 +165,7 @@ public static Graph makeGraph(Matrix B, List variables) { } } } + return g; } @@ -194,12 +195,7 @@ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W, double spi double sum = 0.0; for (int j = 0; j < permutedMatrix.rows(); j++) { double a = permutedMatrix.get(j, j); - - if (a == 0) { - continue P; - } - - sum += FastMath.abs(a);//= 1.0 / StrictMath.abs(a); + sum += abs(a); } if (sum > sum1) { From ecea55c110e7c53bc46b40389254c1bd2886ef0c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 12:26:13 -0400 Subject: [PATCH 096/464] Fixed some commenting. --- .../main/java/edu/cmu/tetrad/search/LingD.java | 16 +++++++++++++++- .../main/java/edu/cmu/tetrad/search/Lingam.java | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index ee06c42ad2..693354ccef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -47,6 +47,19 @@ *

Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering * cyclic causal models by independent components analysis. arXiv preprint * arXiv:1206.3273.

+ *

The focus for this implementation was making super-simple code, not so much + * because the method was trivial (it's not) but out of an attempt to compartmentalize. + * Bootstrapping and other forms of improving the estimate of BHat were not addressed, + * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes + * for an acyclic model it does not tend to. No attempt was made to implement DirectLiNGAM + * since it was tangential to my effort to get LiNG-D to work. Also, only a passing effort + * to get either of these algorithms to handle real data. There are two tuning parameters--a + * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges + * in the final graph; these are finicky. So there's more work to do, and the implementation may + * improve in the future.

+ *

Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; + * these were not compared head to head, though the initial impression was that N Rooks was better, + * so this version uses it.

* @author josephramsey */ public class LingD { @@ -299,7 +312,8 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold @NotNull public static List nRooks(Matrix W, double spineThreshold) { - return pairsNRook(W, spineThreshold); +// return pairsNRook(W, spineThreshold); + return pairsHungarian(W); } @NotNull diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index c2bc7db83d..883a8ac32d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -24,8 +24,21 @@ import edu.cmu.tetrad.util.Matrix; /** - *

Implements the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, and Kerminen, A linear - * nongaussian acyclic model for causal discovery, JMLR 7 (2006).

+ *

Implements an interpretation of the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, + * and Kerminen, A linear nongaussian acyclic model for causal discovery, JMLR 7 (2006).

+ *

The focus for this implementation was making super-simple code, not so much + * because the method was trivial (it's not) but out of an attempt to compartmentalize. + * Bootstrapping and other forms of improving the estimate of BHat were not addressed, + * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes + * for an acyclic model it does not tend to. No attempt was made to implement DirectLiNGAM + * since it was tangential to my effort to get LiNG-D to work. Also, only a passing effort + * to get either of these algorithms to handle real data. There are two tuning parameters--a + * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges + * in the final graph; these are finicky. So there's more work to do, and the implementation may + * improve in the future.

+ *

Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; + * these were not compared head to head, though the initial impression was that N Rooks was better, + * so this version uses it.

* * @author josephramsey */ From 0fd44d16d0f68d2ff35bbb3c6058a32255dc4fbd Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 12:27:13 -0400 Subject: [PATCH 097/464] Fixed some commenting. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 693354ccef..c729d8b7b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -312,8 +312,8 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold @NotNull public static List nRooks(Matrix W, double spineThreshold) { -// return pairsNRook(W, spineThreshold); - return pairsHungarian(W); + return pairsNRook(W, spineThreshold); +// return pairsHungarian(W); } @NotNull From 3c582e5bc21e9526e348b8c55bb0f22ef9c476e6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 12:45:11 -0400 Subject: [PATCH 098/464] Fixed some commenting. --- .../tetrad/algcomparison/algorithm/continuous/dag/LingD.java | 2 +- .../tetrad/algcomparison/algorithm/continuous/dag/Lingam.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 3 +-- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 77304202d0..9cfcbd7076 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -48,7 +48,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { edu.cmu.tetrad.search.LingD lingD = new edu.cmu.tetrad.search.LingD(); lingD.setBThreshold(bThreshold); lingD.setSpineThreshold(spineThreshold); - List bHats = lingD.search(W); + List bHats = lingD.fit(W); int count = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 028e3cb7f2..35aeb12d27 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -49,7 +49,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { lingam.setBThreshold(bThreshold); lingam.setSpineThreshold(spineThreshold); - Matrix bHat = lingam.search(W); + Matrix bHat = lingam.fit(W); Graph graph = LingD.makeGraph(bHat, data.getVariables()); TetradLogger.getInstance().forceLogMessage(bHat.toString()); TetradLogger.getInstance().forceLogMessage(graph.toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index c729d8b7b4..e76d4f5df4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -31,7 +31,6 @@ import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; -import org.apache.commons.math3.util.FastMath; import org.jetbrains.annotations.NotNull; import java.text.DecimalFormat; @@ -82,7 +81,7 @@ public LingD() { * @param W The W matrix to be used. * @return A list of estimated B Hat matrices generated by LiNG-D. */ - public List search(Matrix W) { + public List fit(Matrix W) { List pairs = nRooks(W.transpose(), spineThreshold); if (pairs.isEmpty()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 883a8ac32d..01121019e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -57,7 +57,7 @@ public Lingam() { * @param W the W matrix from ICA, WX = e. * @return The estimated B Hat matrix. */ - public Matrix search(Matrix W) { + public Matrix fit(Matrix W) { PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W, spineThreshold); return LingD.getScaledBHat(bestPair, bThreshold); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 0617e12922..31a1f062bf 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -93,7 +93,7 @@ public void test1() { Lingam lingam = new Lingam(); lingam.setBThreshold(bThreshold); lingam.setSpineThreshold(spineThreshold); - Matrix lingamBhat = lingam.search(W); + Matrix lingamBhat = lingam.fit(W); Graph lingamGraph = LingD.makeGraph(lingamBhat, dataSet.getVariables()); System.out.println("Lingam graph = " + lingamGraph); @@ -113,7 +113,7 @@ public void test1() { LingD lingD = new LingD(); lingD.setBThreshold(bThreshold); lingD.setSpineThreshold(spineThreshold); - List bHats = lingD.search(W); + List bHats = lingD.fit(W); if (bHats.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); From cdb933d8431830c0581bb868be522c8753a3195b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 12:55:50 -0400 Subject: [PATCH 099/464] Fixed some commenting. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index e76d4f5df4..29bc296f2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -50,7 +50,7 @@ * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes - * for an acyclic model it does not tend to. No attempt was made to implement DirectLiNGAM + * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM * since it was tangential to my effort to get LiNG-D to work. Also, only a passing effort * to get either of these algorithms to handle real data. There are two tuning parameters--a * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 01121019e7..1ac1245d72 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -30,7 +30,7 @@ * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes - * for an acyclic model it does not tend to. No attempt was made to implement DirectLiNGAM + * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM * since it was tangential to my effort to get LiNG-D to work. Also, only a passing effort * to get either of these algorithms to handle real data. There are two tuning parameters--a * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges From f420e1f9cfe961167ca28d82ef6d3e60bb8e28f8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 12:58:51 -0400 Subject: [PATCH 100/464] Fixed some commenting. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 29bc296f2b..a1ddd6c7ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -51,7 +51,7 @@ * Bootstrapping and other forms of improving the estimate of BHat were not addressed, * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM - * since it was tangential to my effort to get LiNG-D to work. Also, only a passing effort + * since it was tangential to the effort to get LiNG-D to work. Also, only a passing effort * to get either of these algorithms to handle real data. There are two tuning parameters--a * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges * in the final graph; these are finicky. So there's more work to do, and the implementation may diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 1ac1245d72..ce8b5baa8a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -31,7 +31,7 @@ * Bootstrapping and other forms of improving the estimate of BHat were not addressed, * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM - * since it was tangential to my effort to get LiNG-D to work. Also, only a passing effort + * since it was tangential to the effort to get LiNG-D to work. Also, only a passing effort * to get either of these algorithms to handle real data. There are two tuning parameters--a * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges * in the final graph; these are finicky. So there's more work to do, and the implementation may From 9258e3e66bc739b1aba7bfcfd74b4c0bdb880542 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 13:01:02 -0400 Subject: [PATCH 101/464] Fixed some commenting. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index a1ddd6c7ea..0494be0b0b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -49,7 +49,7 @@ *

The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, - * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes + * and empt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM * since it was tangential to the effort to get LiNG-D to work. Also, only a passing effort * to get either of these algorithms to handle real data. There are two tuning parameters--a diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index ce8b5baa8a..93e629fd10 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -29,7 +29,7 @@ *

The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, - * and not attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes + * and no attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM * since it was tangential to the effort to get LiNG-D to work. Also, only a passing effort * to get either of these algorithms to handle real data. There are two tuning parameters--a From 2b69b633d209a25946186e27b5bdac72efda97ca Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 13:17:01 -0400 Subject: [PATCH 102/464] Fixed some commenting. --- .../algorithm/continuous/dag/LingD.java | 2 +- .../algorithm/continuous/dag/Lingam.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 11 ++++++++++- .../src/main/java/edu/cmu/tetrad/search/Lingam.java | 13 ++++++++++++- .../src/test/java/edu/cmu/tetrad/test/TestLing.java | 8 ++++---- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 9cfcbd7076..8c39609aa1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -48,7 +48,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { edu.cmu.tetrad.search.LingD lingD = new edu.cmu.tetrad.search.LingD(); lingD.setBThreshold(bThreshold); lingD.setSpineThreshold(spineThreshold); - List bHats = lingD.fit(W); + List bHats = lingD.fit(data); int count = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 35aeb12d27..2a6e2ec20d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -49,7 +49,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { lingam.setBThreshold(bThreshold); lingam.setSpineThreshold(spineThreshold); - Matrix bHat = lingam.fit(W); + Matrix bHat = lingam.fitW(W); Graph graph = LingD.makeGraph(bHat, data.getVariables()); TetradLogger.getInstance().forceLogMessage(bHat.toString()); TetradLogger.getInstance().forceLogMessage(graph.toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 0494be0b0b..c62a8c0d4b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -29,6 +29,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; +import edu.pitt.dbmi.data.reader.Data; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; import org.jetbrains.annotations.NotNull; @@ -59,6 +60,9 @@ *

Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; * these were not compared head to head, though the initial impression was that N Rooks was better, * so this version uses it.

+ *

This implementation has two parameters, a threshold (for N Rooks) on the minimum values + * in absolute value for including entries in a possible strong diagonal for W, and a threshold + * for BHat for including edges in the final graph.

* @author josephramsey */ public class LingD { @@ -73,6 +77,11 @@ public class LingD { public LingD() { } + public List fit(DataSet D) { + Matrix W = LingD.estimateW(D, 5000, 1e-6, 1.2); + return fitW(W); + } + /** * Performs the LiNG-D algorithm given a W matrix, which needs to be discovered * elsewhere. The local algorithm is assumed--in fact, the W matrix is simply @@ -81,7 +90,7 @@ public LingD() { * @param W The W matrix to be used. * @return A list of estimated B Hat matrices generated by LiNG-D. */ - public List fit(Matrix W) { + public List fitW(Matrix W) { List pairs = nRooks(W.transpose(), spineThreshold); if (pairs.isEmpty()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 93e629fd10..9e4ce2670a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -21,8 +21,11 @@ package edu.cmu.tetrad.search; +import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.util.Matrix; +import java.util.List; + /** *

Implements an interpretation of the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, * and Kerminen, A linear nongaussian acyclic model for causal discovery, JMLR 7 (2006).

@@ -39,6 +42,9 @@ *

Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; * these were not compared head to head, though the initial impression was that N Rooks was better, * so this version uses it.

+ *

This implementation has two parameters, a threshold (for N Rooks) on the minimum values + * in absolute value for including entries in a possible strong diagonal for W, and a threshold + * for BHat for including edges in the final graph.

* * @author josephramsey */ @@ -52,12 +58,17 @@ public class Lingam { public Lingam() { } + public Matrix fit(DataSet D) { + Matrix W = LingD.estimateW(D, 5000, 1e-6, 1.2); + return fitW(W); + } + /** * Searches given the W matrix from ICA. * @param W the W matrix from ICA, WX = e. * @return The estimated B Hat matrix. */ - public Matrix fit(Matrix W) { + public Matrix fitW(Matrix W) { PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W, spineThreshold); return LingD.getScaledBHat(bestPair, bThreshold); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 31a1f062bf..5d8fc28f37 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -71,8 +71,8 @@ public void test1() { Graph trueGraph = sim.getTrueGraph(0); System.out.println("True graph = " + trueGraph); - // First we use ICA to estimate the W matrix. - Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); +// // First we use ICA to estimate the W matrix. +// Matrix W = LingD.estimateW(dataSet, 5000, 1e-6, 1.2); // We then apply LiNGAM with a W threshold of .3. We should get a mostly correct DAG // back. The "W threshold" is a threshold for the B Hat matrix below which values are @@ -93,7 +93,7 @@ public void test1() { Lingam lingam = new Lingam(); lingam.setBThreshold(bThreshold); lingam.setSpineThreshold(spineThreshold); - Matrix lingamBhat = lingam.fit(W); + Matrix lingamBhat = lingam.fit(dataSet); Graph lingamGraph = LingD.makeGraph(lingamBhat, dataSet.getVariables()); System.out.println("Lingam graph = " + lingamGraph); @@ -113,7 +113,7 @@ public void test1() { LingD lingD = new LingD(); lingD.setBThreshold(bThreshold); lingD.setSpineThreshold(spineThreshold); - List bHats = lingD.fit(W); + List bHats = lingD.fit(dataSet); if (bHats.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); From d53cee180be4e4784d72055e0d4ff1551d690eae Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 13:18:42 -0400 Subject: [PATCH 103/464] Fixed some commenting. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index c62a8c0d4b..df768b8c95 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -50,7 +50,7 @@ *

The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, - * and empt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes + * and no attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM * since it was tangential to the effort to get LiNG-D to work. Also, only a passing effort * to get either of these algorithms to handle real data. There are two tuning parameters--a From 060ef3c83cca060c17cd9cbf3a255681b20dedc0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 13:21:42 -0400 Subject: [PATCH 104/464] Fixed some commenting. --- .../algorithm/continuous/dag/LingD.java | 2 +- .../main/java/edu/cmu/tetrad/search/LingD.java | 17 ++++++++++++----- .../main/java/edu/cmu/tetrad/search/Lingam.java | 5 +++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 8c39609aa1..4e5707e33b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -48,7 +48,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { edu.cmu.tetrad.search.LingD lingD = new edu.cmu.tetrad.search.LingD(); lingD.setBThreshold(bThreshold); lingD.setSpineThreshold(spineThreshold); - List bHats = lingD.fit(data); + List bHats = lingD.fitW(W); int count = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index df768b8c95..cd0f5ea034 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -29,7 +29,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; -import edu.pitt.dbmi.data.reader.Data; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.EigenDecomposition; import org.jetbrains.annotations.NotNull; @@ -63,6 +62,7 @@ *

This implementation has two parameters, a threshold (for N Rooks) on the minimum values * in absolute value for including entries in a possible strong diagonal for W, and a threshold * for BHat for including edges in the final graph.

+ * * @author josephramsey */ public class LingD { @@ -109,6 +109,7 @@ public List fitW(Matrix W) { /** * Sets the threshold used to prune the B matrix for the local algorithms. + * * @param bThreshold The threshold, a non-negative number. */ public void setBThreshold(double bThreshold) { @@ -118,6 +119,7 @@ public void setBThreshold(double bThreshold) { /** * Sets the threshold used to prune the matrix for purpose of searching for alterantive strong dia=gonals.. + * * @param spineThreshold The threshold, a non-negative number. */ public void setSpineThreshold(double spineThreshold) { @@ -129,6 +131,7 @@ public void setSpineThreshold(double spineThreshold) { /** * Estimates the W matrix using FastICA. Assumes the "parallel" option, using * the "exp" function. + * * @param data The dataset to estimate W for. * @param fastIcaMaxIter Maximum number of iterations of ICA. * @param fastIcaTolerance Tolerance for ICA. @@ -171,6 +174,7 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT * Returns a graph given a coefficient matrix and a list of variables. It is * assumed that any non-zero entry in B corresponds to a directed edges, so * that Bij != 0 implies that j->i in the graph. + * * @param B The coefficient matrix. * @param variables The list of variables. * @return The built graph. @@ -194,7 +198,8 @@ public static Graph makeGraph(Matrix B, List variables) { * Finds a column permutation of the W matrix that maximizes the sum * of 1 / |Wii| for diagonal elements Wii in W. This will be speeded up * if W is a thresholded matrix. - * @param W The W matrix, WX = e. + * + * @param W The W matrix, WX = e. * @param spineThrehold The threshold used in NRooks to search for alternative strong diagonals. * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair @@ -209,7 +214,6 @@ public static PermutationMatrixPair strongestDiagonalByCols(Matrix W, double spi PermutationMatrixPair bestPair = null; double sum1 = Double.NEGATIVE_INFINITY; - P: for (PermutationMatrixPair pair : pairs) { Matrix permutedMatrix = pair.getPermutedMatrix(); @@ -261,6 +265,7 @@ public static boolean isStable(Matrix bHat) { /** * Scares the given matrix M by diving each entry (i, j) by M(j, j) + * * @param M The matrix to scale. * @return The scaled matrix. */ @@ -278,6 +283,7 @@ public static Matrix scale(Matrix M) { /** * Thresholds the givem matrix, sending any small entries to zero. + * * @param M The matrix to threshold. * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. * Should be non-negative. @@ -300,8 +306,9 @@ public static Matrix threshold(Matrix M, double threshold) { /** * Returns the BHat matrix, permuted to causal order (lower triangle) and * scaled so that the diagonal consists only of 1's. - * @param pair The (column permutation, thresholded, column permuted W matrix) - * pair. + * + * @param pair The (column permutation, thresholded, column permuted W matrix) + * pair. * @param bThreshold Valued in the BHat matrix less than this in absolute * value are set to 0. * @return The estimated B Hat matrix for this pair. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 9e4ce2670a..a71fe3104f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -24,8 +24,6 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.util.Matrix; -import java.util.List; - /** *

Implements an interpretation of the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, * and Kerminen, A linear nongaussian acyclic model for causal discovery, JMLR 7 (2006).

@@ -65,6 +63,7 @@ public Matrix fit(DataSet D) { /** * Searches given the W matrix from ICA. + * * @param W the W matrix from ICA, WX = e. * @return The estimated B Hat matrix. */ @@ -75,6 +74,7 @@ public Matrix fitW(Matrix W) { /** * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. + * * @param bThreshold Some value >= 0. */ public void setBThreshold(double bThreshold) { @@ -84,6 +84,7 @@ public void setBThreshold(double bThreshold) { /** * Sets the threshold used to prune the matrix for purpose of searching for alterantive strong dia=gonals.. + * * @param spineThreshold The threshold, a non-negative number. */ public void setSpineThreshold(double spineThreshold) { From e6798d99379649d91cae80043799135733d5b9f7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 13:50:01 -0400 Subject: [PATCH 105/464] Fixed bootstrapping for py-tetrad --- .../algorithm/continuous/dag/LingD.java | 12 +++++++++++- .../algorithm/continuous/dag/Lingam.java | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 4e5707e33b..854e71980d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.continuous.dag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.annotation.AlgType; import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.DataModel; @@ -29,10 +30,12 @@ dataType = DataType.Continuous ) @Bootstrapping -public class LingD implements Algorithm { +public class LingD implements Algorithm, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; + private List bootstrapGraphs = new ArrayList<>(); + public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { DataSet data = SimpleDataLoader.getContinuousDataSet(dataSet); @@ -76,6 +79,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); + this.bootstrapGraphs = search.getGraphs(); return search.search(); } } @@ -105,4 +109,10 @@ public List getParameters() { parameters.add(Params.THRESHOLD_SPINE); return parameters; } + + @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/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 2a6e2ec20d..6faa4f06cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.continuous.dag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.annotation.AlgType; import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.DataModel; @@ -30,10 +31,12 @@ dataType = DataType.Continuous ) @Bootstrapping -public class Lingam implements Algorithm { +public class Lingam implements Algorithm, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; + private List bootstrapGraphs = new ArrayList<>(); + public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { DataSet data = SimpleDataLoader.getContinuousDataSet(dataSet); @@ -66,6 +69,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); + this.bootstrapGraphs = search.getGraphs(); return search.search(); } } @@ -95,4 +99,10 @@ public List getParameters() { parameters.add(Params.THRESHOLD_SPINE); return parameters; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } + } \ No newline at end of file From 2951671aa86c7e85f0833e1bfc9675f109ca2417 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 15:12:33 -0400 Subject: [PATCH 106/464] Fixing documentation etc. --- .../statistic/NumberOfEdgesEst.java | 2 +- .../main/java/edu/cmu/tetrad/search/Cpc.java | 108 ++++------ .../main/java/edu/cmu/tetrad/search/Pc.java | 56 +++--- .../java/edu/cmu/tetrad/search/PcAll.java | 190 ++++++++++-------- 4 files changed, 180 insertions(+), 176 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java index 40c0d5bba7..d3b92147a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java @@ -5,7 +5,7 @@ import org.apache.commons.math3.util.FastMath; /** - * Prints the number of edges in the true graph. + * Prints the number of edges in the estimated graph. * * @author jdramsey */ 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 c5817ce05d..2a2d7b13e0 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 @@ -37,9 +37,6 @@ */ public final class Cpc implements GraphSearch { -// private int NTHREDS = Runtime.getRuntime().availableProcessors() * 5; - - /** * The independence test used for the PC search. */ @@ -72,8 +69,6 @@ public final class Cpc implements GraphSearch { */ private Set noncolliderTriples; - private Graph externalGraph; - /** * Set of ambiguous unshielded triples. */ @@ -101,7 +96,6 @@ public final class Cpc implements GraphSearch { private boolean verbose; private boolean stable; -// private boolean concurrent; private boolean useHeuristic = false; private int maxPPathLength = -1; private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; @@ -214,10 +208,18 @@ public Set getNoncolliderTriples() { return new HashSet<>(this.noncolliderTriples); } + /** + * Returns the edges in the search graph. + * @return These edges. + */ public Set getAdjacencies() { return new HashSet<>(this.graph.getEdges()); } + /** + * Returns the non-adjacencies in the seaarch graph. + * @return These non-adjacencies. + */ public Set getNonadjacencies() { Graph complete = GraphUtils.completeGraph(this.graph); Set nonAdjacencies = complete.getEdges(); @@ -227,7 +229,7 @@ public Set getNonadjacencies() { } /** - * Runs PC starting with a fully connected graph over all of the variables in the domain of the independence test. + * Runs CPC starting with a fully connected graph over all of the variables in the domain of the independence test. * See PC for caveats. The number of possible cycles and bidirected edges is far less with CPC than with PC. */ public Graph search() { @@ -261,23 +263,12 @@ public Graph search() { search.setFasType(PcAll.FasType.REGULAR); } -// if (concurrent) { -// search.setConcurrent(PcAll.Concurrent.YES); -// } else { -// search.setConcurrent(PcAll.Concurrent.NO); -// } - search.setColliderDiscovery(PcAll.ColliderDiscovery.CONSERVATIVE); search.setConflictRule(conflictRule); search.setUseHeuristic(useHeuristic); search.setMaxPathLength(maxPPathLength); -// search.setExternalGraph(externalGraph); search.setVerbose(verbose); -// fas.setKnowledge(getKnowledge()); -// fas.setDepth(getDepth()); -// fas.setVerbose(this.verbose); - this.graph = search.search(); this.sepsets = fas.getSepsets(); @@ -298,35 +289,6 @@ public Graph search() { return this.graph; } - //==========================PRIVATE METHODS===========================// - - private void logTriples() { - TetradLogger.getInstance().log("info", "\nCollider triples:"); - - for (Triple triple : this.colliderTriples) { - TetradLogger.getInstance().log("info", "Collider: " + triple); - } - - TetradLogger.getInstance().log("info", "\nNoncollider triples:"); - - for (Triple triple : this.noncolliderTriples) { - TetradLogger.getInstance().log("info", "Noncollider: " + triple); - } - - TetradLogger.getInstance().log("info", "\nAmbiguous triples (i.e. list of triples for which " + - "\nthere is ambiguous data about whether they are colliders or not):"); - - for (Triple triple : getAmbiguousTriples()) { - TetradLogger.getInstance().log("info", "Ambiguous: " + triple); - } - } - - public static boolean isArrowpointAllowed1(Node from, Node to, - Knowledge knowledge) { - return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - public SepsetMap getSepsets() { return this.sepsets; } @@ -338,40 +300,56 @@ public Graph getGraph() { return this.graph; } - public void setGraph(Graph graph) { - this.graph = graph; - } - + /** + * @param verbose Whether verbose output should be printed. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } - public Graph getExternalGraph() { - return this.externalGraph; - } - - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } - + /** + * @param stable Whether the stable FAS search should be used. + */ public void setStable(boolean stable) { this.stable = stable; } -// public void setConcurrent(boolean concurrent) { -// this.concurrent = concurrent; -// } - + /** + * @param useHeuristic Whethe the heuristic should be used for max p. + */ public void setUseHeuristic(boolean useHeuristic) { this.useHeuristic = useHeuristic; } + /** + * Sets the max path length for the max p heuristic. + * @param maxPPathLength This length. + */ public void setMaxPPathLength(int maxPPathLength) { this.maxPPathLength = maxPPathLength; } - public void setConflictRule(PcAll.ConflictRule conflictRule) { - this.conflictRule = conflictRule; + //==========================PRIVATE METHODS===========================// + + private void logTriples() { + TetradLogger.getInstance().log("info", "\nCollider triples:"); + + for (Triple triple : this.colliderTriples) { + TetradLogger.getInstance().log("info", "Collider: " + triple); + } + + TetradLogger.getInstance().log("info", "\nNoncollider triples:"); + + for (Triple triple : this.noncolliderTriples) { + TetradLogger.getInstance().log("info", "Noncollider: " + triple); + } + + TetradLogger.getInstance().log("info", "\nAmbiguous triples (i.e. list of triples for which " + + "\nthere is ambiguous data about whether they are colliders or not):"); + + for (Triple triple : getAmbiguousTriples()) { + TetradLogger.getInstance().log("info", "Ambiguous: " + triple); + } } } 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 752439ec5c..66b355507a 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 @@ -35,9 +35,10 @@ import java.util.Set; /** - * Implements the PC ("Peter/Clark") algorithm, as specified in Chapter 6 of Spirtes, Glymour, and Scheines, "Causation, - * Prediction, and Search," 2nd edition, with a modified rule set in step D due to Chris Meek. For the modified rule - * set, see Chris Meek (1995), "Causal inference and causal explanation with background knowledge." + * Implements the PC ("Peter/Clark") algorithm, as specified in Chapter 6 of Spirtes, + * Glymour, and Scheines, "Causation, Prediction, and Search," 2nd edition, with a + * modified rule set in step D due to Chris Meek. For the modified rule set, see Chris + * Meek (1995), "Causal inference and causal explanation with background knowledge." * * @author Joseph Ramsey. */ @@ -217,7 +218,7 @@ public Graph search(List nodes) { return search(fas, nodes); } - public Graph search(IFas fas, List nodes) { + private Graph search(IFas fas, List nodes) { this.logger.log("info", "Starting PC algorithm"); this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); @@ -244,23 +245,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); -// } - search.setColliderDiscovery(PcAll.ColliderDiscovery.FAS_SEPSETS); search.setConflictRule(conflictRule); search.setUseHeuristic(useMaxP); search.setMaxPathLength(maxPPathLength); -// search.setExternalGraph(externalGraph); search.setVerbose(verbose); -// fas.setKnowledge(getKnowledge()); -// fas.setDepth(getDepth()); -// fas.setVerbose(this.verbose); - this.graph = search.search(); this.sepsets = fas.getSepsets(); @@ -287,10 +277,16 @@ public long getElapsedTime() { return this.elapsedTime; } + /** + * @return The edges of the searched graph. + */ public Set getAdjacencies() { return new HashSet<>(this.graph.getEdges()); } + /** + * @return the non-adjacencies of the searched graph. + */ public Set getNonadjacencies() { Graph complete = GraphUtils.completeGraph(this.graph); Set nonAdjacencies = complete.getEdges(); @@ -299,37 +295,51 @@ public Set getNonadjacencies() { return new HashSet<>(nonAdjacencies); } + /** + * @return the number of independence tests performed in the search. + */ public int getNumIndependenceTests() { return this.numIndependenceTests; } + /** + * @return the nodes of the search graph. + */ public List getNodes() { return this.graph.getNodes(); } + /** + * Sets whether verbose output should be given. + * @param verbose True iff the case. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Sets whether the stable adjacency search should be used. + * @param stable True iff the case. + */ public void setStable(boolean stable) { this.stable = stable; } -// public void setConcurrent(boolean concurrent) { -// this.concurrent = concurrent; -// } - + /** + * Sets whether the max p method should be used in the adjacency searc h. + * @param useMaxP iff the case. + */ public void setUseMaxP(boolean useMaxP) { this.useMaxP = useMaxP; } + /** + * Sets the maximum path length for the PC heuristic. + * @param maxPPathLength this length. + */ public void setMaxPPathLength(int maxPPathLength) { this.maxPPathLength = maxPPathLength; } - - public void setConflictRule(PcAll.ConflictRule conflictRule) { - this.conflictRule = conflictRule; - } } 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 4821b08ed7..e57fb1fd06 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 @@ -40,6 +40,9 @@ * @author Joseph Ramsey (this version). */ public final class PcAll implements GraphSearch { + public enum FasType {REGULAR, STABLE} + public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P} + public enum ConflictRule {PRIORITY, BIDIRECTED, OVERWRITE} /** * The independence test used for the PC search. @@ -84,18 +87,16 @@ public final class PcAll implements GraphSearch { * The sepsets. */ private SepsetMap sepsets; + /** * Whether verbose output about independencies is output. */ - private boolean verbose; private boolean useHeuristic; private int maxPathLength; private FasType fasType = FasType.REGULAR; -// private Concurrent concurrent = Concurrent.YES; private ColliderDiscovery colliderDiscovery = ColliderDiscovery.FAS_SEPSETS; private ConflictRule conflictRule = ConflictRule.OVERWRITE; - private Graph externalGraph = null; /** * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the @@ -109,31 +110,15 @@ public PcAll(IndependenceTest independenceTest) { this.independenceTest = independenceTest; } - private static void orientCollider(Node x, Node y, Node z, ConflictRule conflictRule, Graph graph) { - if (conflictRule == ConflictRule.PRIORITY) { - if (!(graph.getEndpoint(y, x) == Endpoint.ARROW || graph.getEndpoint(y, z) == Endpoint.ARROW)) { - graph.removeEdge(x, y); - graph.removeEdge(z, y); - graph.addDirectedEdge(x, y); - graph.addDirectedEdge(z, y); - } - } else if (conflictRule == ConflictRule.BIDIRECTED) { - graph.setEndpoint(x, y, Endpoint.ARROW); - graph.setEndpoint(z, y, Endpoint.ARROW); - - System.out.println("Orienting " + graph.getEdge(x, y) + " " + graph.getEdge(z, y)); - - System.out.println("graph = " + graph); - } else if (conflictRule == ConflictRule.OVERWRITE) { - graph.removeEdge(x, y); - graph.removeEdge(z, y); - graph.addDirectedEdge(x, y); - graph.addDirectedEdge(z, y); - } - - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); - } + /** + * For the edge from*-*to, return true iff an arrowpoint is allowed as 'to'. + * + * @param from the from edge. + * @param to the to edge. + * @param knowledge the knowledge. + * @return true iff an arrow point is allowed at 'to'. + */ public static boolean isArrowpointAllowed1(Node from, Node to, Knowledge knowledge) { return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && @@ -153,26 +138,31 @@ public static boolean isArrowpointAllowed(Object from, Object to, !knowledge.isForbidden(from.toString(), to.toString()); } + /** + * @param useHeuristic Whether the heuristic should be used for max P collider + * orientation. + */ public void setUseHeuristic(boolean useHeuristic) { this.useHeuristic = useHeuristic; } - public int getMaxPathLength() { - return this.maxPathLength; - } - + /** + * @param maxPathLength The max path length for the max p collider orientation heuristic. + */ public void setMaxPathLength(int maxPathLength) { this.maxPathLength = maxPathLength; } + /** + * @param fasType The type of FAS to be used. + */ public void setFasType(FasType fasType) { this.fasType = fasType; } -// public void setConcurrent(Concurrent concurrent) { -// this.concurrent = concurrent; -// } - + /** + * @param heuristic Whether to use the max p orientation heuristic. + */ public void setHeuristic(int heuristic) { this.heuristic = heuristic; } @@ -195,10 +185,18 @@ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { this.aggressivelyPreventCycles = aggressivelyPreventCycles; } + /** + * Sets the type of collider discovery to do. + * @param colliderDiscovery This type. + */ public void setColliderDiscovery(ColliderDiscovery colliderDiscovery) { this.colliderDiscovery = colliderDiscovery; } + /** + * Sets the conflict rule to use. + * @param conflictRule This rule. + */ public void setConflictRule(ConflictRule conflictRule) { this.conflictRule = conflictRule; } @@ -257,6 +255,18 @@ public void setDepth(int depth) { this.depth = depth; } + public SepsetMap getSepsets() { + return this.sepsets; + } + + /** + * Sets whether verbose output should be printed. + * @param verbose True iff the case. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + /** * @return the set of ambiguous triples found during the most recent run of the algorithm. Non-null after a call to * search(). @@ -281,10 +291,20 @@ public Set getNoncolliderTriples() { return new HashSet<>(this.noncolliderTriples); } + /** + * Returns the edges in the search graph. + * + * @return These edges. + */ public Set getAdjacencies() { return new HashSet<>(this.graph.getEdges()); } + /** + * Returns the non-adjacenices in the search graph. + * + * @return These non-adjacencies. + */ public Set getNonadjacencies() { Graph complete = GraphUtils.completeGraph(this.graph); Set nonAdjacencies = complete.getEdges(); @@ -293,10 +313,21 @@ public Set getNonadjacencies() { return new HashSet<>(nonAdjacencies); } + /** + * Runs the search and returns the search graph. + * + * @return This result graph. + */ public Graph search() { return search(getIndependenceTest().getVariables()); } + /** + * Runs the search over the given list of nodes only, returning the serach graph. + * + * @param nodes The nodes to search over. + * @return The result graph. + */ public Graph search(List nodes) { nodes = new ArrayList<>(nodes); @@ -312,29 +343,19 @@ public Graph search(List nodes) { List allNodes = getIndependenceTest().getVariables(); - if (!allNodes.containsAll(nodes)) { + if (!new HashSet<>(allNodes).containsAll(nodes)) { throw new IllegalArgumentException("All of the given nodes must " + "be in the domain of the independence test provided."); } - IFas fas; + Fas fas; if (this.fasType == FasType.REGULAR) { -// if (this.concurrent == Concurrent.NO) { - fas = new Fas(getIndependenceTest()); - ((Fas) fas).setHeuristic(this.heuristic); -// } else { -// fas = new FasConcurrent(getIndependenceTest()); -// ((FasConcurrent) fas).setStable(false); -// } + fas = new Fas(getIndependenceTest()); + fas.setHeuristic(this.heuristic); } else { -// if (this.concurrent == Concurrent.NO) { - fas = new Fas(getIndependenceTest()); - ((Fas) fas).setStable(true); -// } else { -// fas = new FasConcurrent(getIndependenceTest()); -// ((FasConcurrent) fas).setStable(true); -// } + fas = new Fas(getIndependenceTest()); + fas.setStable(true); } fas.setKnowledge(getKnowledge()); @@ -389,6 +410,34 @@ public Graph search(List nodes) { return this.graph; } + + //==========================PRIVATE METHODS===========================// + + private static void orientCollider(Node x, Node y, Node z, ConflictRule conflictRule, Graph graph) { + if (conflictRule == ConflictRule.PRIORITY) { + if (!(graph.getEndpoint(y, x) == Endpoint.ARROW || graph.getEndpoint(y, z) == Endpoint.ARROW)) { + graph.removeEdge(x, y); + graph.removeEdge(z, y); + graph.addDirectedEdge(x, y); + graph.addDirectedEdge(z, y); + } + } else if (conflictRule == ConflictRule.BIDIRECTED) { + graph.setEndpoint(x, y, Endpoint.ARROW); + graph.setEndpoint(z, y, Endpoint.ARROW); + + System.out.println("Orienting " + graph.getEdge(x, y) + " " + graph.getEdge(z, y)); + + System.out.println("graph = " + graph); + } else if (conflictRule == ConflictRule.OVERWRITE) { + graph.removeEdge(x, y); + graph.removeEdge(z, y); + graph.addDirectedEdge(x, y); + graph.addDirectedEdge(z, y); + } + + TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + } + private void logTriples() { TetradLogger.getInstance().log("info", "\nCollider triples:"); @@ -410,9 +459,7 @@ private void logTriples() { } } - //==========================PRIVATE METHODS===========================// - - private void orientUnshieldedTriplesConservative(Knowledge knowledge) { + private void orientUnshieldedTriplesConservative(Knowledge knowledge) { TetradLogger.getInstance().log("info", "Starting Collider Orientation:"); this.colliderTriples = new HashSet<>(); @@ -526,25 +573,6 @@ private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { PcAll.isArrowpointAllowed1(z, y, knowledge); } - public SepsetMap getSepsets() { - return this.sepsets; - } - - /** - * The graph that's constructed during the search. - */ - public Graph getGraph() { - return this.graph; - } - - public void setGraph(Graph graph) { - this.graph = graph; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - /** * Step C of PC; orients colliders using specified sepset. That is, orients x *-* y *-* z as x *-> y <-* z just in * case y is in Sepset({x, z}). @@ -586,7 +614,7 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra List s2 = new ArrayList<>(sepset); if (!s2.contains(b)) s2.add(b); -// + if (!sepset.contains(b) && PcAll.isArrowpointAllowed(a, b, knowledge) && PcAll.isArrowpointAllowed(c, b, knowledge)) { PcAll.orientCollider(a, b, c, conflictRule, graph); @@ -599,17 +627,5 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra } } } - - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } - - public enum FasType {REGULAR, STABLE} - - public enum Concurrent {NO};//, NO} - - public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P} - - public enum ConflictRule {PRIORITY, BIDIRECTED, OVERWRITE} -} + } From c66c850deb13d98639a668c5ea34e4eec71e91ce Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 16:01:38 -0400 Subject: [PATCH 107/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Fges.java | 80 ++++++++++++------- 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index eacbf9f853..af4500d0d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -39,14 +39,10 @@ import static org.apache.commons.math3.util.FastMath.min; /** - * GesSearch is an implementation of the GES algorithm, as specified in + * FGES is an implementation of the GES algorithm, as specified in * Chickering (2002) "Optimal structure identification with greedy search" * Journal of Machine Learning Research. It works for both BayesNets and SEMs. *

- * Some code optimization could be done for the scoring part of the graph for - * discrete models (method scoreGraphChange). Some of Andrew Moore's approaches - * for caching sufficient statistics, for instance. - *

* To speed things up, it has been assumed that variables X and Y with zero * correlation do not correspond to edges in the graph. This is a restricted * form of the heuristicSpeedup assumption, something GES does not assume. This @@ -60,10 +56,10 @@ * @author Joseph Ramsey, Revisions 5/2015 */ public final class Fges implements GraphSearch, GraphScorer { - - final Set emptySet = new HashSet<>(); - final int[] count = new int[1]; + private final Set emptySet = new HashSet<>(); + private final int[] count = new int[1]; private final int depth = 10000; + /** * The logger for this class. The config needs to be set. */ @@ -144,6 +140,10 @@ public final class Fges implements GraphSearch, GraphScorer { * case of conditional independence. See Chickering (2002), locally * consistent scoring criterion. This by default uses all the processors on * the machine. + * @param score The score to use. The score should yield better scores for + * more correct local models. The algorithm as given by + * Chickering assumes the score will be a BIC score of some + * sort. */ public Fges(Score score) { if (score == null) { @@ -154,21 +154,6 @@ public Fges(Score score) { this.graph = new EdgeListGraph(getVariables()); } - // Used to find semidirected paths for cycle checking. - private static Node traverseSemiDirected(Node node, Edge edge) { - if (node == edge.getNode1()) { - if (edge.getEndpoint1() == Endpoint.TAIL) { - return edge.getNode2(); - } - } else if (node == edge.getNode2()) { - if (edge.getEndpoint2() == Endpoint.TAIL) { - return edge.getNode1(); - } - } - - return null; - } - //==========================PUBLIC METHODS==========================// public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { @@ -247,6 +232,10 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } + /** + * Returns the elapsed time of the search. + * @return This elapsed time. + */ public long getElapsedTime() { return elapsedTime; } @@ -267,6 +256,7 @@ public LinkedList getTopGraphs() { /** * Sets the initial graph. + * @param initialGraph This graph. */ public void setInitialGraph(Graph initialGraph) { if (initialGraph == null) { @@ -289,14 +279,18 @@ public void setInitialGraph(Graph initialGraph) { } /** - * Sets whether verbose output should be produced. + * Sets whether verbose output should be produced. Verbose output generated + * by the Meek rules is treated separately. + * @param verbose True iff the case. + * @see #setMeekVerbose(boolean) */ public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * Sets whether verbose output should be produced. + * Sets whether verbose output should be produced for the Meek rules. + * @param meekVerbose True iff the case. */ public void setMeekVerbose(boolean meekVerbose) { this.meekVerbose = meekVerbose; @@ -313,6 +307,7 @@ public PrintStream getOut() { /** * Sets the output stream that output (except for log output) should be sent * to. By detault System.out. + * @param out This print stream. */ public void setOut(PrintStream out) { this.out = out; @@ -320,6 +315,7 @@ public void setOut(PrintStream out) { /** * If non-null, edges not adjacent in this graph will not be added. + * @param boundGraph This bound graph. */ public void setBoundGraph(Graph boundGraph) { if (boundGraph == null) { @@ -350,19 +346,49 @@ public void setMaxDegree(int maxDegree) { this.maxDegree = maxDegree; } + /** + * Sets whether the first step of the procedure will score both X->Y and Y->X and prefer the + * higher score (for adding X--Y to the graph). + * @param symmetricFirstStep True iff the case. + */ public void setSymmetricFirstStep(boolean symmetricFirstStep) { this.symmetricFirstStep = symmetricFirstStep; } + /** + * Makes a string for the edge Bayes factors to log. + * @param dag The DAG to logs the factors for. + * @return The string to log. + */ public String logEdgeBayesFactorsString(Graph dag) { Map factors = logEdgeBayesFactors(dag); return logBayesPosteriorFactorsString(factors); } + /** + * Returns the score of the final search model. + * @return This score. + */ + public double getModelScore() { + return modelScore; + } + //===========================PRIVATE METHODS========================// - double getModelScore() { - return modelScore; + + // Used to find semidirected paths for cycle checking. + private static Node traverseSemiDirected(Node node, Edge edge) { + if (node == edge.getNode1()) { + if (edge.getEndpoint1() == Endpoint.TAIL) { + return edge.getNode2(); + } + } else if (node == edge.getNode2()) { + if (edge.getEndpoint2() == Endpoint.TAIL) { + return edge.getNode1(); + } + } + + return null; } //Sets the discrete scoring function to use. From 35d5e8bf760bdb53d44ba66073d4cebbd2755277 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 16:29:16 -0400 Subject: [PATCH 108/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Fas.java | 248 ++++++++++++------ .../edu/cmu/tetrad/search/FasConcurrent.java | 5 - .../tetrad/search/FasStableConcurrentFdr.java | 5 - .../main/java/edu/cmu/tetrad/search/IFas.java | 2 - 4 files changed, 165 insertions(+), 95 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index 7923b8daff..7d703e288d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -24,11 +24,10 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.util.ChoiceGenerator; +import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import java.io.PrintStream; -import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.*; /** @@ -56,10 +55,7 @@ public class Fas implements IFas { * The logger, by default the empty logger. */ private final TetradLogger logger = TetradLogger.getInstance(); - /** - * Number formatter. - */ - private final NumberFormat nf = new DecimalFormat("0.00E0"); + /** * Specification of which edges are forbidden or required. */ @@ -73,10 +69,7 @@ public class Fas implements IFas { * The number of independence tests. */ private int numIndependenceTests; - /** - * The number of dependence judgements. Temporary. - */ - private int numDependenceJudgement; + /** * The sepsets found during the search. */ @@ -95,6 +88,7 @@ public class Fas implements IFas { * FAS-Stable. */ private boolean stable; + private long elapsedTime = 0L; //==========================CONSTRUCTORS=============================// @@ -118,6 +112,7 @@ public Fas(IndependenceTest test) { * @return a SepSet, which indicates which variables are independent conditional on which other variables */ public Graph search(List nodes) { + long startTime = MillisecondTimes.timeMillis(); nodes = new ArrayList<>(nodes); if (verbose) { @@ -135,7 +130,6 @@ public Graph search(List nodes) { this.sepset = new SepsetMap(); List edges = new ArrayList<>(); -// List nodes = new ArrayList<>(this.test.getVariables()); Map scores = new HashMap<>(); if (this.heuristic == 1) { @@ -220,13 +214,17 @@ public Graph search(List nodes) { this.logger.log("info", "Finishing Fast Adjacency Search."); } - return graph; - } + this.elapsedTime = MillisecondTimes.timeMillis() - startTime; - public int getDepth() { - return this.depth; + return graph; } + /** + * Sets the depth of the search, which is the maximum number of variables that ben be conditioned + * on in any conditional independence test. + * + * @param depth This maximum. + */ public void setDepth(int depth) { if (depth < -1) { throw new IllegalArgumentException( @@ -236,12 +234,161 @@ public void setDepth(int depth) { this.depth = depth; } + /** + * Sets the knowledge to be used int the search. + * + * @param knowledge This knoweldge. + * @see Knowledge + */ + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge(knowledge); + } + + /** + * Returns the nubmer of independence tests that were done. + * + * @return This number. + */ + public int getNumIndependenceTests() { + return this.numIndependenceTests; + } + + /** + * Returns the sepsets that were discovered in the search. A 'sepset' for test X _||_ Y | Z1,...,Zm would be + * {Z1,...,Zm} + * + * @return A map of these sepsets indexed by {X, Y}. + */ + public SepsetMap getSepsets() { + return this.sepset; + } + + /** + * Returns the depth of the search, which is the maximum number of conditioning variables allowed + * for any conditional independence test. + * + * @return This maximum. + */ + @Override + public int getDepth() { + return depth; + } + + /** + * Sets whether verbose output should be printed. + * + * @param verbose True iff the case. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * There are no cycles in this undirected result graph. + * + * @return False. + */ + @Override + public boolean isAggressivelyPreventCycles() { + return false; + } + + /** + * Returns the independence test being used to do the search. + * + * @return This test + */ + @Override + public IndependenceTest getIndependenceTest() { + return test; + } + + /** + * Returns the knowledge used in the search. + * + * @return this knowledge. + * @see Knowledge + */ + @Override public Knowledge getKnowledge() { - return this.knowledge; + return knowledge; } - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + /** + * Runs the search and returns the resulting (undirected) graph. + * + * @return This graph. + */ + @Override + public Graph search() { + return search(test.getVariables()); + } + + /** + * Returns the elapsed time of the search. + * + * @return This elapsed time. + */ + public long getElapsedTime() { + return elapsedTime; + } + + /** + * Returns the nodes from the test. + * + * @return These nodes. + */ + @Override + public List getNodes() { + return this.test.getVariables(); + } + + /** + * There are no ambiguous triples for this search, for any nodes. + * + * @param node The nodes in question. + * @return An empty list. + */ + @Override + public List getAmbiguousTriples(Node node) { + return new ArrayList<>(); + } + + /** + * Returns whether verbose output should be printed. + * + * @return True iff the case. + */ + @Override + public boolean isVerbose() { + return verbose; + } + + /** + * This is not used here. + * @param out This print stream. + */ + @Override + public void setOut(PrintStream out) { + throw new UnsupportedOperationException("Print to out for FAS is not used."); + } + + /** + * Sets the heuristic to use to fix variable order (1, 2, 3, or 0 = none). + * + * @param heuristic This heuristic. + */ + public void setHeuristic(int heuristic) { + this.heuristic = heuristic; + } + + /** + * Sets whether the stable algorithm shoudl be used. + * + * @param stable True iff the case. + */ + public void setStable(boolean stable) { + this.stable = stable; } //==============================PRIVATE METHODS======================/ @@ -320,10 +467,6 @@ private boolean checkSide(Map scores, IndependenceTest test, Map getNodes() { - return this.test.getVariables(); - } - - @Override - public List getAmbiguousTriples(Node node) { - return null; - } - - @Override - public void setOut(PrintStream out) { - } - - public void setHeuristic(int heuristic) { - this.heuristic = heuristic; - } - - public void setStable(boolean stable) { - this.stable = stable; - } } 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 9d448c1c24..0c08bd26da 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 @@ -511,11 +511,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - @Override - public int getNumDependenceJudgments() { - return 0; - } - public void setOut(PrintStream out) { if (out == null) throw new NullPointerException(); this.out = out; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java index 0bd331a854..1d97bddabc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java @@ -690,11 +690,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - @Override - public int getNumDependenceJudgments() { - return 0; - } - public void setOut(PrintStream out) { if (out == null) throw new NullPointerException(); this.out = out; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java index 3524de03d5..0cb2c00369 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java @@ -63,8 +63,6 @@ public interface IFas { void setVerbose(boolean verbose); - int getNumDependenceJudgments(); - void setOut(PrintStream out); } From c899b03070e36ad9ba97d4362212efce4a398794 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 16:31:24 -0400 Subject: [PATCH 109/464] Fixing documentation etc. --- .../tetrad/search/FasStableConcurrentFdr.java | 739 ------------------ 1 file changed, 739 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java deleted file mode 100644 index 1d97bddabc..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasStableConcurrentFdr.java +++ /dev/null @@ -1,739 +0,0 @@ -package edu.cmu.tetrad.search; - -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.ForkJoinPoolInstance; -import edu.cmu.tetrad.util.StatUtils; -import edu.cmu.tetrad.util.TetradLogger; - -import java.io.PrintStream; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.*; -import java.util.concurrent.ConcurrentSkipListMap; -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.RecursiveTask; - -/** - * Implements the "fast adjacency search" used in several causal algorithm in this package. In the fast adjacency - * search, at a given stage of the search, an edge X*-*Y is removed from the graph if X _||_ Y | S, where S is a subset - * of size d either of adj(X) or of adj(Y), where d is the depth of the search. The fast adjacency search performs this - * procedure for each pair of adjacent edges in the graph and for each depth d = 0, 1, 2, ..., d1, where d1 is either - * the maximum depth or else the first such depth at which no edges can be removed. The interpretation of this adjacency - * search is different for different algorithm, depending on the assumptions of the algorithm. A mapping from {x, y} to - * S({x, y}) is returned for edges x *-* y that have been removed. - *

- * This variant uses the PC-Stable modification, calculating independencies in parallel within each depth. - * It uses a slightly different algorithm from FasStableConcurrent, probably better. - * - * @author Joseph Ramsey. - */ -public class FasStableConcurrentFdr implements IFas { - - /** - * The independence test. This should be appropriate to the types - */ - private final IndependenceTest test; - - /** - * Specification of which edges are forbidden or required. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * The maximum number of variables conditioned on in any conditional independence test. If the depth is -1, it will - * be taken to be the maximum value, which is 1000. Otherwise, it should be set to a non-negative integer. - */ - private int depth = 1000; - - /** - * The number of independence tests. - */ - private int numIndependenceTests; - - - private TetradLogger logger = TetradLogger.getInstance(); - - /** - * The ns found during the search. - */ - private SepsetMap sepsets = new SepsetMap(); - - /** - * The depth 0 graph, specified initially. - */ - private Graph externalGraph; - - // Number formatter. - private final NumberFormat nf = new DecimalFormat("0.00E0"); - - /** - * Set to true if verbose output is desired. - */ - private boolean verbose; - - // The concurrency pool. - private final ForkJoinPool pool = ForkJoinPoolInstance.getInstance().getPool(); - - /** - * Where verbose output is sent. - */ - private PrintStream out = System.out; - - private final int chunk = 100; - - private final boolean recordSepsets = true; - - //==========================CONSTRUCTORS=============================// - - /** - * Constructs a new FastAdjacencySearch. wd - */ - public FasStableConcurrentFdr(IndependenceTest test) { - this.test = test; - } - - /** - * Constructs a new FastAdjacencySearch. - */ - public FasStableConcurrentFdr(Graph externalGraph, IndependenceTest test) { - this.test = test; - this.externalGraph = externalGraph; - } - - //==========================PUBLIC METHODS===========================// - - /** - * Discovers all adjacencies in data. The procedure is to remove edges in the graph which connect pairs of - * variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are - * removed in tiers. First, edges which are independent conditional on zero other variables are removed, then edges - * which are independent conditional on one other variable are removed, then two, then three, and so on, until no - * more edges can be removed from the graph. The edges which remain in the graph after this procedure are the - * adjacencies in the data. - * - * @return a SepSet, which indicates which variables are independent conditional on which other variables - */ - public Graph search() { - this.logger.log("info", "Starting Fast Adjacency Search."); - - // The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node - // x. It is hoped (i.e. true in the large sample limit) that true adjacencies are never removed. - Graph graph = new EdgeListGraph(this.test.getVariables()); - - this.sepsets = new SepsetMap(); - - //this is bad when starting from init graph --AJ -// sepsets.setReturnEmptyIfNotSet(true); - - int _depth = this.depth; - - if (_depth == -1) { - _depth = 1000; - } - - - Map> adjacencies = new ConcurrentSkipListMap<>(); - List nodes = graph.getNodes(); - - for (Node node : nodes) { - adjacencies.put(node, new HashSet<>()); - } - - - for (int d = 0; d <= _depth; d++) { - boolean more; - - if (d == 0) { - more = searchAtDepth0(nodes, this.test, adjacencies); - } else { - more = searchAtDepth(nodes, this.test, adjacencies, d); - } - - if (!more) { - break; - } - } - - if (this.verbose) { - this.out.println("Finished with search, constructing Graph..."); - } - - for (int i = 0; i < nodes.size(); i++) { - for (int j = i + 1; j < nodes.size(); j++) { - Node x = nodes.get(i); - Node y = nodes.get(j); - - if (adjacencies.get(x).contains(y)) { - graph.addUndirectedEdge(x, y); - } - } - } - - if (this.verbose) { - this.out.println("Finished constructing Graph."); - } - - if (this.verbose) { - this.logger.log("info", "Finishing Fast Adjacency Search."); - } - - return graph; - } - - @Override - public Graph search(List nodes) { - return null; - } - - @Override - public long getElapsedTime() { - return 0; - } - - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0."); - } - - this.depth = depth; - } - - @Override - public boolean isAggressivelyPreventCycles() { - return false; - } - - @Override - public IndependenceTest getIndependenceTest() { - return this.test; - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException("Cannot set knowledge to null"); - } - this.knowledge = knowledge; - } - - //==============================PRIVATE METHODS======================/ - - private boolean searchAtDepth0(List nodes, IndependenceTest test, Map> adjacencies) { - if (this.verbose) { - this.out.println("Searching at depth 0."); - System.out.println("Searching at depth 0."); - } - - List empty = Collections.emptyList(); - - List sorted = new ArrayList<>(); - - class Depth0Task extends RecursiveTask { - private final int chunk; - private final int from; - private final int to; - - public Depth0Task(int chunk, int from, int to) { - this.chunk = chunk; - this.from = from; - this.to = to; - } - - @Override - protected Boolean compute() { - if (this.to - this.from <= this.chunk) { - for (int i = this.from; i < this.to; i++) { - if (FasStableConcurrentFdr.this.verbose) { - if ((i + 1) % 1000 == 0) System.out.println("i = " + (i + 1)); - } - - Node x = nodes.get(i); - - for (int j = 0; j < i; j++) { - Node y = nodes.get(j); - - if (FasStableConcurrentFdr.this.externalGraph != null) { - Node x2 = FasStableConcurrentFdr.this.externalGraph.getNode(x.getName()); - Node y2 = FasStableConcurrentFdr.this.externalGraph.getNode(y.getName()); - - if (!FasStableConcurrentFdr.this.externalGraph.isAdjacentTo(x2, y2)) { - continue; - } - } - - IndependenceResult result = new IndependenceResult( - new IndependenceFact(x, y, empty), false, Double.NaN); - - try { - result = test.checkIndependence(x, y, empty); - } catch (Exception e) { - e.printStackTrace(); - } - - FasStableConcurrentFdr.this.numIndependenceTests++; - - double pValue = result.getPValue(); - - sorted.add(pValue); - } - } - - } else { - int mid = (this.to + this.from) / 2; - - Depth0Task left = new Depth0Task(this.chunk, this.from, mid); - Depth0Task right = new Depth0Task(this.chunk, mid, this.to); - - left.fork(); - right.compute(); - left.join(); - - } - return true; - } - } - - this.pool.invoke(new Depth0Task(this.chunk, 0, nodes.size())); - Collections.sort(sorted); - double cutoff = StatUtils.fdrCutoff(test.getAlpha(), sorted, false, true); - - class Depth0Task2 extends RecursiveTask { - private final int chunk; - private final int from; - private final int to; - - public Depth0Task2(int chunk, int from, int to) { - this.chunk = chunk; - this.from = from; - this.to = to; - } - - @Override - protected Boolean compute() { - if (this.to - this.from <= this.chunk) { - for (int i = this.from; i < this.to; i++) { - if (FasStableConcurrentFdr.this.verbose) { - if ((i + 1) % 1000 == 0) System.out.println("i = " + (i + 1)); - } - - Node x = nodes.get(i); - - for (int j = 0; j < i; j++) { - Node y = nodes.get(j); - - if (FasStableConcurrentFdr.this.externalGraph != null) { - Node x2 = FasStableConcurrentFdr.this.externalGraph.getNode(x.getName()); - Node y2 = FasStableConcurrentFdr.this.externalGraph.getNode(y.getName()); - - if (!FasStableConcurrentFdr.this.externalGraph.isAdjacentTo(x2, y2)) { - continue; - } - } - - IndependenceResult result = new IndependenceResult( - new IndependenceFact(x, y, empty), false, Double.NaN); - - try { - result = test.checkIndependence(x, y, empty); - } catch (Exception e) { - e.printStackTrace(); - } - - FasStableConcurrentFdr.this.numIndependenceTests++; - - boolean noEdgeRequired = - FasStableConcurrentFdr.this.knowledge.noEdgeRequired(x.getName(), y.getName()); - - if (result.getPValue() > cutoff && noEdgeRequired) { - if (FasStableConcurrentFdr.this.recordSepsets /*&& !sepsets.isReturnEmptyIfNotSet()*/) { - getSepsets().set(x, y, empty); - } - } else if (!forbiddenEdge(x, y)) { - adjacencies.get(x).add(y); - adjacencies.get(y).add(x); - - if (FasStableConcurrentFdr.this.verbose) { - TetradLogger.getInstance().log("dependencies", SearchLogUtils.independenceFact(x, y, empty) + " p = " + - FasStableConcurrentFdr.this.nf.format(result.getPValue())); - } - } - } - } - - } else { - int mid = (this.to + this.from) / 2; - - Depth0Task left = new Depth0Task(this.chunk, this.from, mid); - Depth0Task right = new Depth0Task(this.chunk, mid, this.to); - - left.fork(); - right.compute(); - left.join(); - - } - return true; - } - } - - this.pool.invoke(new Depth0Task2(this.chunk, 0, nodes.size())); - - return freeDegree(nodes, adjacencies) > 0; - } - - private boolean forbiddenEdge(Node x, Node y) { - String name1 = x.getName(); - String name2 = y.getName(); - - if (this.knowledge.isForbidden(name1, name2) && - this.knowledge.isForbidden(name2, name1)) { - if (this.verbose) { - this.logger.log("edgeRemoved", "Removed " + Edges.undirectedEdge(x, y) + " because it was " + - "forbidden by background knowledge."); - } - - return true; - } - - return false; - } - - private int freeDegree(List nodes, Map> adjacencies) { - int max = 0; - - for (Node x : nodes) { - Set opposites = adjacencies.get(x); - - for (Node y : opposites) { - Set adjx = new HashSet<>(opposites); - adjx.remove(y); - - if (adjx.size() > max) { - max = adjx.size(); - } - } - } - - return max; - } - - private boolean searchAtDepth(List nodes, IndependenceTest test, - Map> adjacencies, - int depth) { - - if (this.verbose) { - this.out.println("Searching at depth " + depth); - System.out.println("Searching at depth " + depth); - } - - Map> adjacenciesCopy = new HashMap<>(); - - for (Node node : adjacencies.keySet()) { - adjacenciesCopy.put(node, new HashSet<>(adjacencies.get(node))); - } - - List sorted = new ArrayList<>(); - - class DepthTask extends RecursiveTask { - private final int chunk; - private final int from; - private final int to; - - public DepthTask(int chunk, int from, int to) { - this.chunk = chunk; - this.from = from; - this.to = to; - } - - @Override - protected Boolean compute() { - if (this.to - this.from <= this.chunk) { - for (int i = this.from; i < this.to; i++) { - if (FasStableConcurrentFdr.this.verbose) { - if ((i + 1) % 1000 == 0) System.out.println("i = " + (i + 1)); - } - - Node x = nodes.get(i); - - List adjx = new ArrayList<>(adjacenciesCopy.get(x)); - - EDGE: - for (Node y : adjx) { - if (!existsShortPath(x, y, adjacencies)) { - continue; - } - - List _adjx = new ArrayList<>(adjx); - _adjx.remove(y); - List ppx = possibleParents(x, _adjx, FasStableConcurrentFdr.this.knowledge); - - if (ppx.size() >= depth) { - ChoiceGenerator cg = new ChoiceGenerator(ppx.size(), depth); - int[] choice; - - while ((choice = cg.next()) != null) { - List condSet = GraphUtils.asList(choice, ppx); - - IndependenceResult result; - - try { - FasStableConcurrentFdr.this.numIndependenceTests++; - result = test.checkIndependence(x, y, condSet); - } catch (Exception e) { - result = new IndependenceResult( - new IndependenceFact(x, y, condSet), - true, Double.NaN); - } - - boolean noEdgeRequired = - FasStableConcurrentFdr.this.knowledge.noEdgeRequired(x.getName(), y.getName()); - - if (result.independent() && noEdgeRequired) { - sorted.add(result.getPValue()); - continue EDGE; - } - } - } - } - } - - } else { - int mid = (this.to + this.from) / 2; - - DepthTask left = new DepthTask(this.chunk, this.from, mid); - DepthTask right = new DepthTask(this.chunk, mid, this.to); - - left.fork(); - right.compute(); - left.join(); - - } - return true; - } - } - - this.pool.invoke(new DepthTask(this.chunk, 0, nodes.size())); - - Collections.sort(sorted); - double cutoff = StatUtils.fdrCutoff(test.getAlpha(), sorted, false, true); - - System.out.println(); - - class DepthTask2 extends RecursiveTask { - private final int chunk; - private final int from; - private final int to; - - public DepthTask2(int chunk, int from, int to) { - this.chunk = chunk; - this.from = from; - this.to = to; - } - - @Override - protected Boolean compute() { - if (this.to - this.from <= this.chunk) { - for (int i = this.from; i < this.to; i++) { - if (FasStableConcurrentFdr.this.verbose) { - if ((i + 1) % 1000 == 0) System.out.println("i = " + (i + 1)); - } - - Node x = nodes.get(i); - - List adjx = new ArrayList<>(adjacenciesCopy.get(x)); - - EDGE: - for (Node y : adjx) { - List _adjx = new ArrayList<>(adjx); - _adjx.remove(y); - List ppx = possibleParents(x, _adjx, FasStableConcurrentFdr.this.knowledge); - - if (ppx.size() >= depth) { - ChoiceGenerator cg = new ChoiceGenerator(ppx.size(), depth); - int[] choice; - - while ((choice = cg.next()) != null) { - List condSet = GraphUtils.asList(choice, ppx); - - try { - FasStableConcurrentFdr.this.numIndependenceTests++; - IndependenceResult result = test.checkIndependence(x, y, condSet); - - if (result.getPValue() > cutoff) { - adjacencies.get(x).remove(y); - adjacencies.get(y).remove(x); - - if (FasStableConcurrentFdr.this.recordSepsets) { - getSepsets().set(x, y, condSet); - } - - continue EDGE; - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - } - } else { - int mid = (this.to + this.from) / 2; - - DepthTask left = new DepthTask(this.chunk, this.from, mid); - DepthTask right = new DepthTask(this.chunk, mid, this.to); - - left.fork(); - right.compute(); - left.join(); - - } - return true; - } - } - - this.pool.invoke(new DepthTask2(this.chunk, 0, nodes.size())); - - if (this.verbose) { - System.out.println("Done with depth"); - } - - return freeDegree(nodes, adjacencies) > depth; - } - - private List possibleParents(Node x, List adjx, - Knowledge knowledge) { - List possibleParents = new LinkedList<>(); - String _x = x.getName(); - - for (Node z : adjx) { - String _z = z.getName(); - - if (possibleParentOf(_z, _x, knowledge)) { - possibleParents.add(z); - } - } - - return possibleParents; - } - - private boolean possibleParentOf(String z, String x, Knowledge knowledge) { - return !knowledge.isForbidden(z, x) && !knowledge.isRequired(x, z); - } - - public int getNumIndependenceTests() { - return this.numIndependenceTests; - } - - @Override - public List getNodes() { - return null; - } - - @Override - public List getAmbiguousTriples(Node node) { - return null; - } - - public SepsetMap getSepsets() { - return this.sepsets; - } - - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } - - /** - * The logger, by default the empty logger. - */ - public TetradLogger getLogger() { - return this.logger; - } - - public void setLogger(TetradLogger logger) { - this.logger = logger; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setOut(PrintStream out) { - if (out == null) throw new NullPointerException(); - this.out = out; - } - - public PrintStream getOut() { - return this.out; - } - - private boolean existsShortPath(Node x, Node z, Map> adjacencies) { - Queue Q = new LinkedList<>(); - Set V = new HashSet<>(); - Q.offer(x); - V.add(x); - Node e = null; - int distance = 0; - - while (!Q.isEmpty()) { - Node t = Q.remove(); - - if (e == t) { - e = null; - distance++; - if (distance > 3) return false; - } - - for (Node c : adjacencies.get(t)) { - if (c == null) continue; -// if (t == y && c == z && distance > 2) continue; - if (t != x && t != z && c == z) return true; - - if (!V.contains(c)) { - V.add(c); - Q.offer(c); - - if (e == null) { - e = c; - } - } - } - } - - return false; - } -} - - From f1775fe49d34cb661a11be18e6a8d0c44fee594f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 16:37:50 -0400 Subject: [PATCH 110/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/FasConcurrent.java | 546 ------------------ 1 file changed, 546 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java 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 deleted file mode 100644 index 0c08bd26da..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java +++ /dev/null @@ -1,546 +0,0 @@ -package edu.cmu.tetrad.search; - -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.TetradLogger; - -import java.io.PrintStream; -import java.util.*; -import java.util.concurrent.*; - -/** - * Implements the "fast adjacency search" used in several causal algorithm in this package. In the fast adjacency - * search, at a given stage of the search, an edge X*-*Y is removed from the graph if X _||_ Y | S, where S is a subset - * of size d either of adj(X) or of adj(Y), where d is the depth of the search. The fast adjacency search performs this - * procedure for each pair of adjacent edges in the graph and for each depth d = 0, 1, 2, ..., d1, where d1 is either - * the maximum depth or else the first such depth at which no edges can be removed. The interpretation of this adjacency - * search is different for different algorithm, depending on the assumptions of the algorithm. A mapping from {x, y} to - * S({x, y}) is returned for edges x *-* y that have been removed. - *

- * This variant uses the PC-Stable modification, calculating independencies in parallel within each depth. - * 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 { - - /** - * The independence test. This should be appropriate to the types - */ - private final IndependenceTest test; - - /** - * Specification of which edges are forbidden or required. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * The maximum number of variables conditioned on in any conditional independence test. If the depth is -1, it will - * be taken to be the maximum value, which is 1000. Otherwise, it should be set to a non-negative integer. - */ - private int depth = 1000; - - /** - * The number of independence tests. - */ - private int numIndependenceTests; - - - private TetradLogger logger = TetradLogger.getInstance(); - - /** - * The ns found during the search. - */ - private SepsetMap sepsets = new SepsetMap(); - - /** - * Set to true if verbose output is desired. - */ - private boolean verbose; - - /** - * Where verbose output is sent. - */ - private PrintStream out = System.out; - - /** - * True if the "stable" adjustment should be made. - */ - private boolean stable = true; - - //==========================CONSTRUCTORS=============================// - - /** - * Constructs a new FastAdjacencySearch. wd - */ - public FasConcurrent(IndependenceTest test) { - this.test = test; - } - - //==========================PUBLIC METHODS===========================// - - /** - * Discovers all adjacencies in data. The procedure is to remove edges in the graph which connect pairs of - * variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are - * removed in tiers. First, edges which are independent conditional on zero other variables are removed, then edges - * which are independent conditional on one other variable are removed, then two, then three, and so on, until no - * more edges can be removed from the graph. The edges which remain in the graph after this procedure are the - * adjacencies in the data. - * - * @return a SepSet, which indicates which variables are independent conditional on which other variables - */ - public Graph search() { - this.logger.log("info", "Starting Fast Adjacency Search."); - - // The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node - // x. It is hoped (i.e. true in the large sample limit) that true adjacencies are never removed. - Graph graph = new EdgeListGraph(this.test.getVariables()); - - this.sepsets = new SepsetMap(); - - int _depth = this.depth; - - if (_depth == -1) { - _depth = 1000; - } - - - Map> adjacencies = new ConcurrentHashMap<>(); - List nodes = graph.getNodes(); - - for (Node node : nodes) { - adjacencies.put(node, new HashSet<>()); - } - - for (int d = 0; d <= _depth; d++) { - boolean more; - - if (d == 0) { - more = searchAtDepth0(nodes, adjacencies); - } else { - more = searchAtDepth(d, nodes, adjacencies); - } - - if (!more) { - break; - } - } - - if (this.verbose) { - this.out.println("Finished with search, constructing Graph..."); - } - - for (int i = 0; i < nodes.size(); i++) { - for (int j = i + 1; j < nodes.size(); j++) { - Node x = nodes.get(i); - Node y = nodes.get(j); - - if (adjacencies.get(x).contains(y)) { - graph.addUndirectedEdge(x, y); - } - } - } - - if (this.verbose) { - this.out.println("Finished constructing Graph."); - } - - if (this.verbose) { - this.logger.log("info", "Finishing Fast Adjacency Search."); - } - - return graph; - } - - private boolean searchAtDepth0(List nodes, Map> adjacencies) { - if (this.verbose) { - System.out.println("Searching at depth 0."); - } - - List empty = Collections.emptyList(); - - class Depth0Task implements Callable { - private final int i; - - private Depth0Task(int i) { - this.i = i; - } - - public Boolean call() { - doNodeDepth0(this.i, nodes, FasConcurrent.this.test, empty, adjacencies); - return true; - } - } - - List> tasks = new ArrayList<>(); - - for (int i = 0; i < nodes.size(); i++) { - tasks.add(new Depth0Task(i)); - } - - ExecutorService pool = Executors.newWorkStealingPool(Runtime.getRuntime().availableProcessors()); - - try { - pool.invokeAll(tasks); - } catch (InterruptedException exception) { - this.out.print("Task has been interrupted"); - Thread.currentThread().interrupt(); - } - - shutdownAndAwaitTermination(pool); - - return freeDegree(nodes, adjacencies) > this.depth; - } - - private boolean searchAtDepth(int depth, List nodes, - Map> adjacencies) { - if (this.verbose) { - System.out.println("Searching at depth " + depth); - } - - Map> adjacenciesCopy; - - if (this.stable) { - adjacenciesCopy = new ConcurrentHashMap<>(); - - for (Node node : adjacencies.keySet()) { - adjacenciesCopy.put(node, new HashSet<>(adjacencies.get(node))); - } - } else { - adjacenciesCopy = adjacencies; - } - - new ConcurrentHashMap<>(); - - for (Node node : adjacencies.keySet()) { - adjacenciesCopy.put(node, new HashSet<>(adjacencies.get(node))); - } - - class DepthTask implements Callable { - private final int i; - private final int depth; - - public DepthTask(int i, int depth) { - this.i = i; - this.depth = depth; - } - - public Boolean call() { - doNodeAtDepth(this.i, nodes, this.depth, FasConcurrent.this.test, adjacencies); - return true; - } - } - - List> tasks = new ArrayList<>(); - - for (int i = 0; i < nodes.size(); i++) { - tasks.add(new DepthTask(i, depth)); - } - - ExecutorService pool = Executors.newWorkStealingPool(Runtime.getRuntime().availableProcessors()); - - try { - pool.invokeAll(tasks); - } catch (InterruptedException exception) { - this.out.print("Task has been interrupted");//, dateTimeNow(), task.run.index + 1); - Thread.currentThread().interrupt(); - } - - shutdownAndAwaitTermination(pool); - - return freeDegree(nodes, adjacencies) > depth; - } - - @Override - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - return null; - } - - @Override - public long getElapsedTime() { - return 0; - } - - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0."); - } - - this.depth = depth; - } - - @Override - public boolean isAggressivelyPreventCycles() { - return false; - } - - @Override - public IndependenceTest getIndependenceTest() { - return this.test; - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - //==============================PRIVATE METHODS======================/ - - - private void doNodeDepth0(int i, List nodes, IndependenceTest test, List empty, Map> adjacencies) { - if (this.verbose) { - if ((i + 1) % 1000 == 0) System.out.println("i = " + (i + 1)); - } - - if (this.verbose) { - if ((i + 1) % 100 == 0) this.out.println("Node # " + (i + 1)); - } - - if (Thread.currentThread().isInterrupted()) { - return; - } - - Node x = nodes.get(i); - - for (int j = i + 1; j < nodes.size(); j++) { - - Node y = nodes.get(j); - - boolean independent; - - try { - this.numIndependenceTests++; - independent = test.checkIndependence(x, y, empty).independent(); - } catch (Exception e) { - e.printStackTrace(); - independent = false; - } - - boolean noEdgeRequired = - this.knowledge.noEdgeRequired(x.getName(), y.getName()); - - - if (independent && noEdgeRequired) { - getSepsets().set(x, y, empty); - } else if (!forbiddenEdge(x, y)) { - adjacencies.get(x).add(y); - adjacencies.get(y).add(x); - } - } - } - - private void doNodeAtDepth(int i, List nodes, int depth, IndependenceTest test, Map> adjacencies) { - if (this.verbose) { - if ((i + 1) % 1000 == 0) System.out.println("i = " + (i + 1)); - } - - Node x = nodes.get(i); - - if (Thread.currentThread().isInterrupted()) { - return; - } - - List adjx = new ArrayList<>(adjacencies.get(x)); - - EDGE: - for (Node y : adjx) { - List _adjx = new ArrayList<>(adjacencies.get(x)); - _adjx.remove(y); - List ppx = possibleParents(x, _adjx, this.knowledge); - - if (ppx.size() >= depth) { - ChoiceGenerator cg = new ChoiceGenerator(ppx.size(), depth); - int[] choice; - - while ((choice = cg.next()) != null) { - if (Thread.currentThread().isInterrupted()) { - return; - } - - List condSet = GraphUtils.asList(choice, ppx); - - boolean independent; - - try { - this.numIndependenceTests++; - independent = test.checkIndependence(x, y, condSet).independent(); - } catch (Exception e) { - independent = false; - } - - boolean noEdgeRequired = - this.knowledge.noEdgeRequired(x.getName(), y.getName()); - - if (independent && noEdgeRequired) { - adjacencies.get(x).remove(y); - adjacencies.get(y).remove(x); - - getSepsets().set(x, y, condSet); - - continue EDGE; - } - } - } - } - } - - private boolean forbiddenEdge(Node x, Node y) { - String name1 = x.getName(); - String name2 = y.getName(); - - if (this.knowledge.isForbidden(name1, name2) && - this.knowledge.isForbidden(name2, name1)) { - if (this.verbose) { - this.logger.log("edgeRemoved", "Removed " + Edges.undirectedEdge(x, y) + " because it was " + - "forbidden by background knowledge."); - } - - return true; - } - - return false; - } - - private int freeDegree(List nodes, Map> adjacencies) { - int max = 0; - - for (Node x : nodes) { - Set opposites = adjacencies.get(x); - - for (Node y : opposites) { - Set adjx = new HashSet<>(opposites); - adjx.remove(y); - - if (adjx.size() > max) { - max = adjx.size(); - } - } - } - - return max; - } - - - private List possibleParents(Node x, List adjx, - Knowledge knowledge) { - List possibleParents = new LinkedList<>(); - String _x = x.getName(); - - for (Node z : adjx) { - String _z = z.getName(); - - if (possibleParentOf(_z, _x, knowledge)) { - possibleParents.add(z); - } - } - - return possibleParents; - } - - private boolean possibleParentOf(String z, String x, Knowledge knowledge) { - return !knowledge.isForbidden(z, x) && !knowledge.isRequired(x, z); - } - - public int getNumIndependenceTests() { - return this.numIndependenceTests; - } - - @Override - public List getNodes() { - return null; - } - - @Override - public List getAmbiguousTriples(Node node) { - return null; - } - - public SepsetMap getSepsets() { - return this.sepsets; - } - - /** - * The logger, by default the empty logger. - */ - public TetradLogger getLogger() { - return this.logger; - } - - public void setLogger(TetradLogger logger) { - this.logger = logger; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setOut(PrintStream out) { - if (out == null) throw new NullPointerException(); - this.out = out; - } - - public PrintStream getOut() { - return this.out; - } - - private void shutdownAndAwaitTermination(ExecutorService pool) { - pool.shutdown(); // Disable new tasks from being submitted - try { - // Wait a while for existing tasks to terminate - if (!pool.awaitTermination(1, TimeUnit.SECONDS)) { - pool.shutdownNow(); // Cancel currently executing tasks - // Wait a while for tasks to respond to being cancelled - if (!pool.awaitTermination(1, TimeUnit.SECONDS)) { - System.err.println("Pool did not terminate"); - } - } - } catch (InterruptedException ie) { - // (Re-)Cancel if current thread also interrupted - pool.shutdownNow(); - // Preserve interrupt status - Thread.currentThread().interrupt(); - } - } - - public void setStable(boolean stable) { - this.stable = stable; - } -} - From 570f2e58513cc3b5019430613043be359e16b132 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 16:40:29 -0400 Subject: [PATCH 111/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/AdLeafTree.java | 8 ++++---- .../src/main/java/edu/cmu/tetrad/search/AdTrees.java | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java index e05db9fbb4..0cdcf039d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java @@ -33,6 +33,10 @@ public class AdLeafTree { // Dimensions of the discrete variables (otherwise 0). private final int[] dims; + /** + * Constructs an AD Leaf Tree for the given dataset. + * @param dataSet A discrete dataset. + */ public AdLeafTree(DataSet dataSet) { this.dataSet = dataSet; @@ -130,10 +134,6 @@ public List>> getCellLeaves(List A, Discret return rows; } - public void setColumn(DiscreteVariable var, int[] col) { - this.discreteData[this.dataSet.getColumn(var)] = col; - } - private List getVaries(List varies, int v) { List _varies = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java index b6b7085f1b..cee992dd57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java @@ -13,6 +13,12 @@ public class AdTrees { private static final Map adTrees = new HashMap<>(); + /** + * Returns an ADLeafTree for the given dataset. + * @param dataSet A discrete dataset. + * @return The AdLeafTree + * @see AdLeafTree + */ public static AdLeafTree getAdLeafTree(DataSet dataSet) { AdLeafTree tree = AdTrees.adTrees.get(dataSet); From 7444dcd9ddaee3071658b8cae507e1a990b3dade Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 17:47:08 -0400 Subject: [PATCH 112/464] Fixing documentation etc. --- .../tetrad/search/BayesUpdaterClassifier.java | 58 ++++--- .../java/edu/cmu/tetrad/search/BdeScore.java | 95 ++++++++++-- .../java/edu/cmu/tetrad/search/BdeuScore.java | 146 +++++++++++++----- 3 files changed, 227 insertions(+), 72 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java index 98854679f0..ade6c092c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java @@ -139,6 +139,10 @@ public static BayesUpdaterClassifier serializableInstance() { //==========================PUBLIC METHODS========================// + /** + * Sets the target variable. + * @param target This variable. + */ public void setTarget(String target) { //Find the target variable using its name. @@ -162,8 +166,9 @@ public void setTarget(String target) { } /** - * Computes and returns the crosstabulation of observed versus estimated + * Computes and returns the cross-tabulation of observed versus estimated * values of the target variable as described above. + * @return this cross-tabulation. */ public int[] classify() { if (this.targetVariable == null) { @@ -255,24 +260,6 @@ public int[] classify() { //Straw man values--to be replaced. int estimatedValue = -1; -// if (numTargetCategories == 2) { -// for (int j = 0; j < numTargetCategories; j++) { -// double marginal = -// bayesUpdater.getMarginal(indexTargetBN, j); -// probOfClassifiedValues[j][i] = marginal; -// probOfClassifiedValues[1 - j][i] = 1.0 - marginal; -// -// if (targetCategory == j) { -// if (marginal > binaryCutoff) { -// estimatedValue = j; -// } else { -// estimatedValue = 1 - j; -// } -// -// break; -// } -// } -// } else { double highestProb = -0.1; @@ -385,36 +372,67 @@ public double getPercentCorrect() { } /** - * @return the DiscreteVariable which is the target variable. + * @return the discrete variables which is the target variable. + * @see DiscreteVariable */ public DiscreteVariable getTargetVariable() { return this.targetVariable; } + /** + * Returns the Bayes IM being used. + * @return This IM + * @see BayesIm + */ public BayesIm getBayesIm() { return this.bayesIm; } + /** + * Returns the test data being used. + * @return This data. + */ public DataSet getTestData() { return this.testData; } + /** + * Returns the classification for the target variable. + * @return Thsi classification. + */ public int[] getClassifications() { return this.classifications; } + /** + * Returns the marginals. + * @return This. + */ public double[][] getMarginals() { return this.marginals; } + /** + * Returns the number of cases for the data. + * @return This number. + */ public int getNumCases() { return this.numCases; } + /** + * Returns the number of usable cases for the data. + * @return Thsi number. + */ public int getTotalUsableCases() { return this.totalUsableCases; } + /** + * Returns the variables of the Bayes IM. + * @return These variables as a list. + * @see BayesIm + */ public List getBayesImVars() { return this.bayesImVars; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java index 8365a9c5a7..db0334d3d3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java @@ -30,10 +30,16 @@ /** * Calculates the BDe score. + * + * @author josephramsey */ public class BdeScore implements LocalDiscreteScore { private final DataSet dataSet; + /** + * Constructs a BDe score for the given dataset. + * @param dataSet A discrete dataset. + */ public BdeScore(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException(); @@ -47,7 +53,11 @@ public BdeScore(DataSet dataSet) { } /** + * Returns the score for the given parent given its parents, where these are + * specified as column indices into the dataset. * @return the score, or NaN if the score can't be calculated. + * @param i The index of the variable. + * @param parents The indices of the parents of the variables. */ public double localScore(int i, int[] parents) { @@ -130,15 +140,24 @@ public double localScore(int i, int[] parents) { } } + /** + * Returns the different between localScore(y | z, x) and localScore(y | z) + * @param x The index of the x variable + * @param y The index of the y variable. + * @param z The indices of the z variables + * @return The differnece in scores. + */ @Override public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } + /** + * Returns the dataset being analyzed. + * @return This dataset. + */ @Override - - public DataSet getDataSet() { return this.dataSet; } @@ -152,53 +171,99 @@ private int getRowIndex(int[] dim, int[] values) { return rowIndex; } - private int sampleSize() { - return dataSet().getNumRows(); - } - - private int numCategories(int i) { - return ((DiscreteVariable) dataSet().getVariable(i)).getNumCategories(); - } - - private DataSet dataSet() { - return this.dataSet; - } - + /** + * BDe does not use a structure prior. + * @param structurePrior The structure prior (not used). + * @throws UnsupportedOperationException Since this method is not implemented for this score. + */ public void setStructurePrior(double structurePrior) { + throw new UnsupportedOperationException("BDe does not use a structure prior."); } + /** + * BDe does not use a sample prior. + * @param samplePrior The structure prior (not used). + * @throws UnsupportedOperationException Since this method is not implemented for this score. + */ public void setSamplePrior(double samplePrior) { + throw new UnsupportedOperationException("BDe does not use a sample prior."); } + /** + * Returns the variables of the dataset. + * @return These variables as list. + */ @Override public List getVariables() { return this.dataSet.getVariables(); } + /** + * Returns the sample size of the data. + * @return This size. + */ public int getSampleSize() { return this.dataSet.getNumRows(); } + /** + * Returns a judgment of whether the given bump in score allows one to conclude + * that the edge is an "effect edge" for FGES. + * @param bump The bump. + * @return True iff so. + * @see Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > -20; } + /** + * Returns the maximum degree of the graphs as they're searched. + * @return This maximum degree. + */ @Override public int getMaxDegree() { return 1000; } + /** + * A judgment of whether a node given its parents is determined is not available for this + * score. + * @param z The parents. + * @param y The node. + * @return The judgment + * @throws UnsupportedOperationException Since this method is not implemented for this score. + */ @Override public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException("The BDe score does not make judgments of " + + "determinacy of a node given its parents."); } + /** + * Returns "BDe Score". + * @return This string. + */ @Override public String toString() { return "BDe Score"; } + private int sampleSize() { + return dataSet().getNumRows(); + } + + private int numCategories(int i) { + return ((DiscreteVariable) dataSet().getVariable(i)).getNumCategories(); + } + + private DataSet dataSet() { + return this.dataSet; + } + + + } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java index d2fdbad184..b2ea304c06 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java @@ -37,15 +37,22 @@ public class BdeuScore implements LocalDiscreteScore, IBDeuScore { private final int[][] data; private final int sampleSize; private final int[] numCategories; + private final DataSet dataSet; private List variables; private double samplePrior = 1; private double structurePrior = 1; + /** + * Constructs a BDe score for the given dataset. + * @param dataSet A discrete dataset. + */ public BdeuScore(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException("Data was not provided."); } + this.dataSet = dataSet; + if (dataSet instanceof BoxDataSet && ((BoxDataSet) dataSet).getDataBox() instanceof VerticalIntDataBox) { DataBox dataBox = ((BoxDataSet) dataSet).getDataBox(); this.variables = dataSet.getVariables(); @@ -75,19 +82,12 @@ public BdeuScore(DataSet dataSet) { } } - private static int getRowIndex(int[] dim, int[] values) { - int rowIndex = 0; - for (int i = 0; i < dim.length; i++) { - rowIndex *= dim[i]; - rowIndex += values[i]; - } - return rowIndex; - } - - private DiscreteVariable getVariable(int i) { - return (DiscreteVariable) this.variables.get(i); - } - + /** + * Calculates the BDeu score of a node given its parents. + * @param node The index of the node. + * @param parents The indices of the node's parents. + * @return The score. + */ @Override public double localScore(int node, int[] parents) { @@ -169,87 +169,159 @@ public double localScore(int node, int[] parents) { } } - private double getPriorForStructure(int numParents, int N) { - double e = getStructurePrior(); - if (e == 0) return 0.0; - else { - int vm = N - 1; - return numParents * FastMath.log(e / (vm)) + (vm - numParents) * FastMath.log(1.0 - (e / (vm))); - } - } - + /** + * Calculates localScore(y | z, x) - localScore(y | z). + * @param x The index of x. + * @param y The index of y. + * @param z The indeces of the z variables. + * @return The score difference. + */ @Override public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } + /** + * Returns the variables of the data. + * @return These variables as a list. + */ @Override public List getVariables() { return this.variables; } - public void setVariables(List variables) { - for (int i = 0; i < variables.size(); i++) { - if (!variables.get(i).getName().equals(this.variables.get(i).getName())) { - throw new IllegalArgumentException("Variable in index " + (i + 1) + " does not have the same name " + - "as the variable being substituted for it."); - } - } - - this.variables = variables; - } - + /** + * Returns the sample size of the data. + * @return This size. + */ public int getSampleSize() { return this.sampleSize; } /** - * Must be called directly after the corresponding scoring call. + * For FGES, this determines whether an edge counts as an effect edge. + * @param bump The bump for the edge. + * @return True if so. + * @see Fges */ public boolean isEffectEdge(double bump) { - return bump > 0;//lastBumpThreshold; + return bump > 0; } + /** + * Returns the dataset being analyzed. + * @return This dataset + */ @Override public DataSet getDataSet() { - throw new UnsupportedOperationException(); + return dataSet; } + /** + * Returns the structure prior. + * @return This prior. + */ @Override public double getStructurePrior() { return this.structurePrior; } + /** + * Sets the structure prior + * @param structurePrior This prior. + */ @Override public void setStructurePrior(double structurePrior) { this.structurePrior = structurePrior; } + /** + * Returns the smaple prior. + * @return This prior. + */ @Override public double getSamplePrior() { return this.samplePrior; } + /** + * Set the sample prior + * @param samplePrior This prior. + */ @Override public void setSamplePrior(double samplePrior) { this.samplePrior = samplePrior; } + /** + * Returns a string representation of this score. + * @return This string. + */ @Override public String toString() { NumberFormat nf = new DecimalFormat("0.00"); return "BDeu Score SampP " + nf.format(this.samplePrior) + " StuctP " + nf.format(this.structurePrior); } + /** + * Sets the variables to another of the same names, in the same order. + * @param variables The new varialbe list. + * @see edu.cmu.tetrad.algcomparison.algorithm.multi.Images + */ + void setVariables(List variables) { + for (int i = 0; i < variables.size(); i++) { + if (!variables.get(i).getName().equals(this.variables.get(i).getName())) { + throw new IllegalArgumentException("Variable in index " + (i + 1) + " does not have the same name " + + "as the variable being substituted for it."); + } + } + + this.variables = variables; + } + + /** + * Returns the needed max degree for some searches. + * @return This max degree. + */ @Override public int getMaxDegree() { return (int) FastMath.ceil(FastMath.log(this.sampleSize)); } + /** + * This score does not implement a method to decide whehter a node is determined + * by its parents. + * @param z The parents. + * @param y The node. + * @return This determination + * @throws UnsupportedOperationException Since this method not implemented for this core. + */ @Override public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException("The BDeu score does not implement a 'determines' method."); + } + + private DiscreteVariable getVariable(int i) { + return (DiscreteVariable) this.variables.get(i); + } + + private double getPriorForStructure(int numParents, int N) { + double e = getStructurePrior(); + if (e == 0) return 0.0; + else { + int vm = N - 1; + return numParents * FastMath.log(e / (vm)) + (vm - numParents) * FastMath.log(1.0 - (e / (vm))); + } + } + + private static int getRowIndex(int[] dim, int[] values) { + int rowIndex = 0; + for (int i = 0; i < dim.length; i++) { + rowIndex *= dim[i]; + rowIndex += values[i]; + } + return rowIndex; } } From bce3ed81b514bc57668d687b445089bbbb36abd6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 17:55:04 -0400 Subject: [PATCH 113/464] Fixing documentation etc. --- .../edu/cmu/tetradapp/model/FgesRunner.java | 403 ------------------ .../edu/cmu/tetradapp/model/IFgesRunner.java | 23 - .../tetradapp/model/ScoredGraphsWrapper.java | 4 - .../tetrad/search/BayesUpdaterClassifier.java | 4 +- .../cmu/tetrad/search/BdeuScoreImages.java | 217 ---------- 5 files changed, 2 insertions(+), 649 deletions(-) delete mode 100644 tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java delete mode 100644 tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IFgesRunner.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScoreImages.java diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java deleted file mode 100644 index 6385baeff1..0000000000 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FgesRunner.java +++ /dev/null @@ -1,403 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetradapp.model; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.LayoutUtil; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.graph.Triple; -import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.session.DoNotAddOldModel; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.TetradSerializableUtils; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Extends AbstractAlgorithmRunner to produce a wrapper for the GES algorithm. - * - * @author Ricardo Silva - */ - -public class FgesRunner extends AbstractAlgorithmRunner implements IFgesRunner, - PropertyChangeListener, IGesRunner, Indexable, DoNotAddOldModel { - static final long serialVersionUID = 23L; - - public enum Type {CONTINUOUS, DISCRETE, MIXED, GRAPH} - - private transient List listeners; - private List topGraphs; - private int index; - private transient Fges fges; - private transient Graph externalGraph; - - //============================CONSTRUCTORS============================// - - public FgesRunner(DataWrapper[] dataWrappers, Parameters params, KnowledgeBoxModel knowledgeBoxModel) { - super(new MergeDatasetsWrapper(dataWrappers, params), params, knowledgeBoxModel); - } - - public FgesRunner(DataWrapper[] dataWrappers, Parameters params) { - super(new MergeDatasetsWrapper(dataWrappers, params), params, null); - } - - public FgesRunner(DataWrapper[] dataWrappers, GraphSource graph, Parameters params) { - super(new MergeDatasetsWrapper(dataWrappers, params), params, null); - if (graph == this) throw new IllegalArgumentException(); - this.externalGraph = graph.getGraph(); - } - - public FgesRunner(DataWrapper[] dataWrappers, GraphSource graph, Parameters params, KnowledgeBoxModel knowledgeBoxModel) { - super(new MergeDatasetsWrapper(dataWrappers, params), params, knowledgeBoxModel); - if (graph == this) throw new IllegalArgumentException(); - this.externalGraph = graph.getGraph(); - } - - public FgesRunner(GraphWrapper graphWrapper, Parameters params, KnowledgeBoxModel knowledgeBoxModel) { - super(graphWrapper.getGraph(), params, knowledgeBoxModel); - } - - public FgesRunner(GraphWrapper graphWrapper, Parameters params) { - super(graphWrapper.getGraph(), params, null); - } - - /** - * Generates a simple exemplar of this class to test serialization. - * - * @see TetradSerializableUtils - */ - public static DataWrapper serializableInstance() { - return new DataWrapper(new Parameters()); - } - - //============================PUBLIC METHODS==========================// - - /** - * Executes the algorithm, producing (at least) a result workbench. Must be - * implemented in the extending class. - */ - public void execute() { - Object model = getDataModel(); - - if (model == null && getSourceGraph() != null) { - model = getSourceGraph(); - } - - if (model == null) { - throw new RuntimeException("Data source is unspecified. You may need to double click all your data boxes, \n" + - "then click Save, and then right click on them and select Propagate Downstream. \n" + - "The issue is that we use a seed to simulate from IM's, so your data is not saved to \n" + - "file when you save the session. It can, however, be recreated from the saved seed."); - } - - Parameters params = getParams(); - - if (model instanceof Graph) { - GraphScore gesScore = new GraphScore((Graph) model); - this.fges = new Fges(gesScore); - this.fges.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); - this.fges.setVerbose(true); - } else { - double penaltyDiscount = params.getDouble("penaltyDiscount", 4); - - if (model instanceof DataSet) { - DataSet dataSet = (DataSet) model; - - if (dataSet.isContinuous()) { - SemBicScore gesScore = new SemBicScore(new CovarianceMatrix((DataSet) model)); - gesScore.setPenaltyDiscount(penaltyDiscount); - System.out.println("Score done"); - this.fges = new Fges(gesScore); - } else if (dataSet.isDiscrete()) { - double samplePrior = getParams().getDouble("samplePrior", 1); - double structurePrior = getParams().getDouble("structurePrior", 1); - BdeuScore score = new BdeuScore(dataSet); - score.setSamplePrior(samplePrior); - score.setStructurePrior(structurePrior); - this.fges = new Fges(score); - } else { - ConditionalGaussianScore gesScore = new ConditionalGaussianScore(dataSet, 1, false); - gesScore.setPenaltyDiscount(penaltyDiscount); - gesScore.setStructurePrior(1); - this.fges = new Fges(gesScore); - } - } else if (model instanceof ICovarianceMatrix) { - SemBicScore gesScore = new SemBicScore((ICovarianceMatrix) model); - gesScore.setPenaltyDiscount(penaltyDiscount); - gesScore.setPenaltyDiscount(penaltyDiscount); - this.fges = new Fges(gesScore); - } else if (model instanceof DataModelList) { - DataModelList list = (DataModelList) model; - - for (DataModel dataModel : list) { - if (!(dataModel instanceof DataSet || dataModel instanceof ICovarianceMatrix)) { - throw new IllegalArgumentException("Need a combination of all continuous data sets or " + - "covariance matrices, or else all discrete data sets, or else a single externalGraph."); - } - } - - if (list.size() != 1) { - throw new IllegalArgumentException("FGES takes exactly one data set, covariance matrix, or externalGraph " + - "as input. For multiple data sets as input, use IMaGES."); - } - - if (allContinuous(list)) { - double penalty = getParams().getDouble("penaltyDiscount", 4); - - if (params.getBoolean("firstNontriangular", false)) { - SemBicScoreImages fgesScore = new SemBicScoreImages(list); - fgesScore.setPenaltyDiscount(penalty); - this.fges = new Fges(fgesScore); - } else { - SemBicScoreImages fgesScore = new SemBicScoreImages(list); - fgesScore.setPenaltyDiscount(penalty); - this.fges = new Fges(fgesScore); - } - } else if (allDiscrete(list)) { - double structurePrior = getParams().getDouble("structurePrior", 1); - double samplePrior = getParams().getDouble("samplePrior", 1); - - BdeuScoreImages fgesScore = new BdeuScoreImages(list); - fgesScore.setSamplePrior(samplePrior); - fgesScore.setStructurePrior(structurePrior); - - if (params.getBoolean("firstNontriangular", false)) { - this.fges = new Fges(fgesScore); - } else { - this.fges = new Fges(fgesScore); - } - } else { - throw new IllegalArgumentException("Data must be either all discrete or all continuous."); - } - } else { - System.out.println("No viable input."); - } - } - - this.fges.setBoundGraph(this.externalGraph); - this.fges.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); - this.fges.setVerbose(true); - Graph graph = this.fges.search(); - - if (getSourceGraph() != null) { - LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); - } else if (((Knowledge) getParams().get("knowledge", new Knowledge())).isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, (Knowledge) getParams().get("knowledge", new Knowledge())); - } else { - LayoutUtil.circleLayout(graph, 200, 200, 150); - } - - setResultGraph(graph); - - this.topGraphs = new ArrayList<>(this.fges.getTopGraphs()); - - if (this.topGraphs.isEmpty()) { - - this.topGraphs.add(new ScoredGraph(getResultGraph(), Double.NaN)); - } - - setIndex(this.topGraphs.size() - 1); - } - - /** - * Executes the algorithm, producing (at least) a result workbench. Must be - * implemented in the extending class. - */ - public Type getType() { - Object model = getDataModel(); - - if (model == null && getSourceGraph() != null) { - model = getSourceGraph(); - } - - if (model == null) { - throw new RuntimeException("Data source is unspecified. You may need to double click all your data boxes, \n" + - "then click Save, and then right click on them and select Propagate Downstream. \n" + - "The issue is that we use a seed to simulate from IM's, so your data is not saved to \n" + - "file when you save the session. It can, however, be recreated from the saved seed."); - } - - Type type; - - if (model instanceof Graph) { - type = Type.GRAPH; - } else if (model instanceof DataSet) { - DataSet dataSet = (DataSet) model; - - if (dataSet.isContinuous()) { - type = Type.CONTINUOUS; - } else if (dataSet.isDiscrete()) { - type = Type.DISCRETE; - } else { - type = Type.MIXED; -// throw new IllegalStateException("Data set must either be continuous or discrete."); - } - } else if (model instanceof ICovarianceMatrix) { - type = Type.CONTINUOUS; - } else if (model instanceof DataModelList) { - DataModelList list = (DataModelList) model; - - if (allContinuous(list)) { - type = Type.CONTINUOUS; - } else if (allDiscrete(list)) { - type = Type.DISCRETE; - } else { - type = Type.MIXED; -// throw new IllegalArgumentException("Data must be either all discrete or all continuous."); - } - } else { - throw new IllegalArgumentException("Unrecognized data type."); - } - - return type; - } - - private boolean allContinuous(List dataModels) { - for (DataModel dataModel : dataModels) { - if (dataModel instanceof DataSet) { - if (!dataModel.isContinuous() || dataModel instanceof ICovarianceMatrix) { - return false; - } - } - } - - return true; - } - - private boolean allDiscrete(List dataModels) { - for (DataModel dataModel : dataModels) { - if (dataModel instanceof DataSet) { - if (!dataModel.isDiscrete()) { - return false; - } - } - } - - return true; - } - - public void setIndex(int index) { - if (index < -1) { - throw new IllegalArgumentException("Must be in >= -1: " + index); - } - - this.index = index; - } - - public int getIndex() { - return this.index; - } - - public Graph getGraph() { - if (getIndex() >= 0) { - return getTopGraphs().get(getIndex()).getGraph(); - } else { - return getResultGraph(); - } - } - - - /** - * @return the names of the triple classifications. Coordinates with - */ - public List getTriplesClassificationTypes() { - return new ArrayList<>(); - } - - /** - * @return the list of triples corresponding to getTripleClassificationNames. - */ - public List> getTriplesLists(Node node) { - return new ArrayList<>(); - } - - public boolean supportsKnowledge() { - return true; - } - - public ImpliedOrientation getMeekRules() { - MeekRules rules = new MeekRules(); - rules.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); - return rules; - } - - @Override - public Map getParamSettings() { - super.getParamSettings(); - Parameters params = getParams(); - this.paramSettings.put("Penalty Discount", new DecimalFormat("0.0").format(params.getDouble("penaltyDiscount", 4))); - return this.paramSettings; - } - - @Override - public String getAlgorithmName() { - return "FGES"; - } - - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(evt); - } - - private void firePropertyChange(PropertyChangeEvent evt) { - for (PropertyChangeListener l : getListeners()) { - l.propertyChange(evt); - } - } - - private List getListeners() { - if (this.listeners == null) { - this.listeners = new ArrayList<>(); - } - return this.listeners; - } - - public void addPropertyChangeListener(PropertyChangeListener l) { - if (!getListeners().contains(l)) getListeners().add(l); - } - - public List getTopGraphs() { - return this.topGraphs; - } - - public String getBayesFactorsReport(Graph dag) { - if (this.fges == null) { - return "Please re-run IMaGES."; - } else { - return this.fges.logEdgeBayesFactorsString(dag); - } - } - - public GraphScorer getGraphScorer() { - return this.fges; - } -} - - - - - diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IFgesRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IFgesRunner.java deleted file mode 100644 index 837fad563a..0000000000 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IFgesRunner.java +++ /dev/null @@ -1,23 +0,0 @@ -package edu.cmu.tetradapp.model; - -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.ScoredGraph; -import edu.cmu.tetrad.util.Parameters; - -import java.util.List; - -/** - * Created by jdramsey on 2/22/16. - */ -public interface IFgesRunner { - FgesRunner.Type getType(); - - List getTopGraphs(); - - Parameters getParams(); - - Graph getSourceGraph(); - - DataModel getDataModel(); -} diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java index 5a33152b57..50b1a1fb4c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java @@ -98,10 +98,6 @@ public ScoredGraphsWrapper(Graph graph, GraphScorer scorer) { log(); } - public ScoredGraphsWrapper(FgesRunner runner, Parameters parameters) { - this(runner.getTopGraphs().get(runner.getIndex()).getGraph(), runner.getGraphScorer()); - } - public ScoredGraphsWrapper(DagWrapper wrapper, Parameters parameters) { this(wrapper.getGraph(), null); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java index ade6c092c1..4494a07adf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java @@ -429,7 +429,7 @@ public int getTotalUsableCases() { } /** - * Returns the variables of the Bayes IM. + * Returns the variables of the BayesIM. * @return These variables as a list. * @see BayesIm */ @@ -445,7 +445,7 @@ public List getBayesImVars() { * version to version. A readObject method of this form may be added to any * class, even if Tetrad sessions were previously saved out using a version * of the class that didn't include it. (That's what the - * "s.defaultReadObject();" is for. See J. Bloch, Effective Java, for help. + * "s.defaultReadObject();" is for. See J. Bloch, Effective Java, for help.) */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScoreImages.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScoreImages.java deleted file mode 100644 index 762798346f..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScoreImages.java +++ /dev/null @@ -1,217 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Node; - -import java.util.ArrayList; -import java.util.List; - -/** - * Implements the continuous BIC score for FGES. - * - * @author Joseph Ramsey - */ -public class BdeuScoreImages implements IBDeuScore { - - // The covariance matrix. - private final List scores; - - // The variables of the covariance matrix. - private final List variables; - - // The sample size of the covariance matrix. - private int sampleSize; - - // True if verbose output should be sent to out. - private boolean verbose; - - private double samplePrior = 1.0; - - private double structurePrior = 1.0; - - /** - * Constructs the score using a covariance matrix. - */ - public BdeuScoreImages(List dataModels) { - if (dataModels == null) { - throw new NullPointerException(); - } - - List scores = new ArrayList<>(); - - for (DataModel model : dataModels) { - if (model instanceof DataSet) { - DataSet dataSet = (DataSet) model; - - if (!dataSet.isDiscrete()) { - throw new IllegalArgumentException("Datasets must be discrete."); - } - - scores.add(new BdeuScore(dataSet)); - } else { - throw new IllegalArgumentException("Only continuous data sets and covariance matrices may be used as input."); - } - } - - List variables = scores.get(0).getVariables(); - - for (int i = 2; i < scores.size(); i++) { - scores.get(i).setVariables(variables); - } - - this.scores = scores; - this.variables = variables; - } - - - public double localScoreDiff(int x, int y, int[] z) { - double sum = 0.0; - - for (BdeuScore score : this.scores) { - sum += score.localScoreDiff(x, y, z); - } - - return sum / this.scores.size(); - } - - - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model - */ - public double localScore(int i, int[] parents) { - double sum = 0.0; - - for (BdeuScore score : this.scores) { - sum += score.localScore(i, parents); - } - - double score = sum / this.scores.size(); - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; - } - } - - public double localScore(int i, int[] parents, int index) { - return localScoreOneDataSet(i, parents, index); - } - - private double localScoreOneDataSet(int i, int[] parents, int index) { - return this.scores.get(index).localScore(i, parents); - } - - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - public double localScore(int i, int parent) { - double sum = 0.0; - - for (BdeuScore score : this.scores) { - sum += score.localScore(i, parent); - } - - return sum / this.scores.size(); - - - } - - - public double localScore(int i) { - double sum = 0.0; - - for (BdeuScore score : this.scores) { - sum += score.localScore(i); - } - - return sum / this.scores.size(); - } - - - public DataSet getDataSet() { - throw new UnsupportedOperationException(); - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public List getVariables() { - return this.variables; - } - - @Override - public int getSampleSize() { - return this.scores.get(0).getSampleSize(); - } - - public double getSamplePrior() { - return this.samplePrior; - } - - public void setSamplePrior(double samplePrior) { - for (BdeuScore score : this.scores) { - score.setSamplePrior(samplePrior); - } - this.samplePrior = samplePrior; - } - - public double getStructurePrior() { - return this.structurePrior; - } - - public void setStructurePrior(double structurePrior) { - for (BdeuScore score : this.scores) { - score.setStructurePrior(structurePrior); - } - this.structurePrior = structurePrior; - } - - @Override - public int getMaxDegree() { - return 1000; - } - - @Override - public boolean determines(List z, Node y) { - return false; - } - - @Override - public String toString() { - return "BDeu Score Images"; - } - -} - - - From b9cd765a25173b0c61165cc366eadc2d732f5718 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 18:01:09 -0400 Subject: [PATCH 114/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Bes.java | 63 +++++++++++++------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java index ce0c20518f..549536ec10 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java @@ -21,6 +21,7 @@ * * @author bryanandrews * @author josephramsey + * @see Fges */ public class Bes { private final List variables; @@ -34,33 +35,46 @@ public Bes(@NotNull Score score) { this.variables = score.getVariables(); } + /** + * Returns the variables being searched over. + * @return These variables as a list. + */ @NotNull public List getVariables() { return this.variables; } + /** + * Sets whether verbose output should be printed. + * @param verbose True iff so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Sets the knowledge for the search. + * @param knowledge This knowledge. + * @see Knowledge + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } + /** + * Sets the depth for the search, which is the maximum number of variables conditioned on. + * @param depth This maximum; for unlimited depth use -1; otherwise, give a nonzero integer. + */ 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); - } - } - + /** + * Runs BES for a graph over the given list of variables + * @param graph The graph. + * @param variables The variables the search should be restricted to. + */ public void bes(Graph graph, List variables) { Map hashIndices = new HashMap<>(); SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>(); @@ -117,6 +131,10 @@ public void bes(Graph graph, List variables) { } } + private Knowledge getKnowledge() { + return knowledge; + } + private void delete(Node x, Node y, Set H, double bump, Set naYX, Graph graph) { Edge oldxy = graph.getEdge(x, y); @@ -166,15 +184,6 @@ private void delete(Node x, Node y, Set H, double bump, Set naYX, Gr } } - 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); @@ -197,8 +206,13 @@ private double scoreGraphChange(Node x, Node y, Set parents, Map complement, Set parents, Map hashIndices) { + Set set = new HashSet<>(complement); + set.addAll(parents); + set.remove(x); + + return -scoreGraphChange(x, y, set, hashIndices); } private Set revertToCPDAG(Graph graph) { @@ -210,6 +224,15 @@ private Set revertToCPDAG(Graph graph) { return rules.orientImplied(graph); } + private void buildIndexing(List nodes, Map hashIndices) { + + int i = -1; + + for (Node n : nodes) { + hashIndices.put(n, ++i); + } + } + private boolean validDelete(Node x, Node y, Set H, Set naYX, Graph graph) { boolean violatesKnowledge = false; From 2e90be0ef602fba34f55d71c5ab1e89d1627d936 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 18:02:19 -0400 Subject: [PATCH 115/464] Fixing documentation etc. --- .../algorithm/oracle/cpdag/Bdce.java | 97 --------------- .../main/java/edu/cmu/tetrad/search/Bdce.java | 114 ------------------ 2 files changed, 211 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Bdce.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bdce.java 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 deleted file mode 100644 index efae3be3a9..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Bdce.java +++ /dev/null @@ -1,97 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; - -import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; -import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.annotation.Experimental; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -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; - -/** - * BOSS-DC (Best Order Score Search Divide and Conquer Experimental) - * - * @author bryanandrews - * @author josephramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "BOSS-DCE", -// command = "boss-dce", -// algoType = AlgType.forbid_latent_common_causes -//) -@Bootstrapping -@Experimental -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. - } - - public Bdce(ScoreWrapper score) { - this.score = score; - } - - - @Override - public Graph search(DataModel dataModel, Parameters parameters) { - Score score = this.score.getScore(dataModel, parameters); - edu.cmu.tetrad.search.Bdce boss = new edu.cmu.tetrad.search.Bdce(score); - - boss.setDepth(parameters.getInt(Params.DEPTH)); - boss.setVerbose(parameters.getBoolean(Params.VERBOSE)); - boss.setNumStarts(parameters.getInt(Params.NUM_STARTS)); - - return boss.search(); - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "BOSSDC (Best Order Score Search Divide and Conquer Experimental) using " + this.score.getDescription(); - } - - @Override - public DataType getDataType() { - return this.score.getDataType(); - } - - @Override - public List getParameters() { - ArrayList params = new ArrayList<>(); - - // Flags - params.add(Params.VERBOSE); - - // Parameters - params.add(Params.NUM_STARTS); - params.add(Params.DEPTH); - - return params; - } - - @Override - public ScoreWrapper getScoreWrapper() { - return this.score; - } - - @Override - public void setScoreWrapper(ScoreWrapper score) { - this.score = score; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bdce.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bdce.java deleted file mode 100644 index 5c9f742783..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bdce.java +++ /dev/null @@ -1,114 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; - -import java.util.ArrayList; -import java.util.List; - -import static java.lang.Double.NEGATIVE_INFINITY; - -/** - * Implements the BOSS DC Experimental algorithm. - * - * @author bryanandrews - * @author josephramsey - */ -public class Bdce { - private final List variables; - private final TeyssierScorerExperimental scorer; - private final Bes bes; - private boolean verbose = true; - private int depth = -1; - private int numStarts = 1; - - - public Bdce(Score score) { - this.variables = new ArrayList<>(score.getVariables()); - this.scorer = new TeyssierScorerExperimental(score); - this.bes = new Bes(score); - this.bes.setDepth(this.depth); - this.bes.setVerbose(false); - } - - - public Graph search() { - Graph bestGraph = null; - double best = NEGATIVE_INFINITY; - - for (int r = 0; r < this.numStarts; r++) { - this.scorer.shuffleOrder(); - Graph graph; - - double s1, s2; - - s2 = this.scorer.getScore(); - do { -// System.out.println("dividing..."); -// do { - s1 = s2; - divide(0, this.scorer.size() / 2, this.scorer.size()); -// s2 = this.scorer.getScore(); -// } while (s2 > s1); -// System.out.println("bes..."); - graph = this.scorer.getGraph(true); - this.bes.bes(graph, this.variables); - this.scorer.setOrder(graph); - s2 = scorer.getScore(); - } while (s2 > s1); - - if (s2 < best) continue; - bestGraph = this.scorer.getGraph(true); - best = s2; - } - - return bestGraph; - } - - - public void divide(int a, int b, int c) { - if (a < (b - 1)) { - divide(a, (a + b) / 2, b); - } - if (b < (c - 1)) { - divide(b, (b + c) / 2, c); - } - conquer(a, b, c); - } - - - public void conquer(int a, int b, int c) { - for (int i = b; i < c; i++) { - for (int j = a; j < b; j++) { - if (!scorer.hasParent(i, j)) continue; - if (this.scorer.tuck(i, j)) break; - } - } - } - - - public void setNumStarts(int numStarts) { - this.numStarts = numStarts; - } - - - public List getVariables() { - return this.variables; - } - - - public boolean isVerbose() { - return this.verbose; - } - - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - - public void setDepth(int depth) { - if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1."); - this.depth = depth; - } -} \ No newline at end of file From f27a4380430b6fd0f6d600ef0662b61f1658e500 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 18:11:50 -0400 Subject: [PATCH 116/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Boss.java | 81 ++++++++++++------- 1 file changed, 50 insertions(+), 31 deletions(-) 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 d713d84fbe..0545dbca6c 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 @@ -37,7 +37,6 @@ public class Boss implements SuborderSearch { private int numStarts; private Knowledge knowledge = new Knowledge(); - /** * This algorithm will work with an arbitrary score. * @param score The Score to use. @@ -57,6 +56,13 @@ public Boss(Score score) { this.numStarts = 1; } + /** + * Searches over the given suborder using the given prefix. Useful if tiered knowledge is available. + * @param prefix The prefix--variables alwasys allowed for conditioning. + * @param suborder The suborder--these are the variables being searched over. + * @param gsts The grow-shrink tree used for caching. + * @see GrowShrinkTree + */ @Override public void searchSuborder(List prefix, List suborder, Map gsts) { this.gsts = gsts; @@ -112,6 +118,49 @@ public void searchSuborder(List prefix, List suborder, Map getVariables() { + return variables; + } + + /** + * Returns a map from nodes to their parents. + * @return This map. + */ + @Override + public Map> getParents() { + return parents; + } + + /** + * Returns the score being used for the search. + * @return This score. + * @see Score + */ + @Override + public Score getScore() { + return score; + } + private boolean betterMutation(List prefix, List suborder, Map> required, Node x) { ListIterator itr = suborder.listIterator(); double[] scores = new double[suborder.size() + 1]; @@ -194,36 +243,6 @@ private void makeValidKnowledgeOrder(List order) { }); } } - -// public void setDepth(int depth) { -// if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1."); -// this.bes.setDepth(depth); -// } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - this.bes.setKnowledge(knowledge); - } - - public void setNumStarts(int numStarts) { - this.numStarts = numStarts; - } - - @Override - public List getVariables() { - return variables; - } - - @Override - public Map> getParents() { - return parents; - } - - @Override - public Score getScore() { - return score; - } } From 293bcca88f529b6609b13683a0a1c8a9252ca623 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 18:25:37 -0400 Subject: [PATCH 117/464] Fixing documentation etc. --- .../algorithm/oracle/pag/Bfci.java | 6 - .../algorithm/oracle/pag/BfciTr.java | 177 -------- .../calibration/DataForCalibrationRfci.java | 3 +- .../main/java/edu/cmu/tetrad/search/BFci.java | 129 +++--- .../java/edu/cmu/tetrad/search/BfciFoo.java | 392 ------------------ .../java/edu/cmu/tetrad/search/BfciTr.java | 286 ------------- .../java/edu/cmu/tetrad/test/TestFges.java | 2 - 7 files changed, 50 insertions(+), 945 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BfciTr.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciTr.java 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 a27dc0d2f9..c1e1c59211 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 @@ -90,12 +90,6 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setNumStarts(parameters.getInt(Params.NUM_STARTS)); - Object obj = parameters.get(Params.PRINT_STREAM); - - if (obj instanceof PrintStream) { - search.setOut((PrintStream) obj); - } - return search.search(); } else { Bfci algorithm = new Bfci(this.test, this.score); 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 deleted file mode 100644 index ac5e2469eb..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BfciTr.java +++ /dev/null @@ -1,177 +0,0 @@ -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; -import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; -import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; -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.Graph; -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.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; - - -/** - * Adjusts GFCI to use a permutation algorithm (such as BOSS-Tuck) to do the initial - * steps of finding adjacencies and unshielded colliders. - *

- * GFCI reference is this: - *

- * J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm - * for Latent Variable Models," JMLR 2016. - * - * @author jdramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "BFCI-TR", -// command = "bfci-tr", -// algoType = AlgType.allow_latent_common_causes -//) -//@Bootstrapping -//@Experimental -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. - } - - public BfciTr(IndependenceWrapper test, ScoreWrapper score) { - this.test = test; - this.score = score; - } - - @Override - public Graph search(DataModel dataModel, Parameters parameters) { - 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(); - } - - edu.cmu.tetrad.search.BfciTr search = new edu.cmu.tetrad.search.BfciTr(this.test.getTest(dataModel, parameters), this.score.getScore(dataModel, parameters)); - - search.setMaxPathLength(parameters.getInt(Params.MAX_PATH_LENGTH)); - search.setCompleteRuleSetUsed(parameters.getBoolean(Params.COMPLETE_RULE_SET_USED)); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - dataModel.setKnowledge(this.knowledge); - - Object obj = parameters.get(Params.PRINT_STREAM); - - if (obj instanceof PrintStream) { - search.setOut((PrintStream) obj); - } - - return search.search(); - } else { - 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(this.knowledge); - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - Graph graph = search.search(); - this.bootstrapGraphs = search.getGraphs(); - return graph; - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return dagToPag(graph); - } - - @Override - public String getDescription() { - return "BFCI-TR (Best-order FCI with triangle reduce rule using " + this.test.getDescription() - + " and " + this.score.getDescription(); - } - - @Override - public DataType getDataType() { - return this.test.getDataType(); - } - - @Override - public List getParameters() { - List params = new ArrayList<>(); - - params.add(Params.BOSS_ALG); - params.add(Params.MAX_PATH_LENGTH); - params.add(Params.COMPLETE_RULE_SET_USED); - params.add(Params.DO_DISCRIMINATING_PATH_RULE); - params.add(Params.GRASP_USE_SCORE); - params.add(Params.GRASP_USE_RASKUTTI_UHLER); - params.add(Params.GRASP_USE_DATA_ORDER); - params.add(Params.POSSIBLE_DSEP_DONE); - params.add(Params.DEPTH); - params.add(Params.TIME_LAG); - params.add(Params.VERBOSE); - - // Parameters - params.add(Params.NUM_STARTS); - - return params; - } - - - @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; - } - - @Override - public ScoreWrapper getScoreWrapper() { - return this.score; - } - - @Override - 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/calibration/DataForCalibrationRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java index e0e582d77e..ab9422d0ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java @@ -1,5 +1,6 @@ package edu.cmu.tetrad.calibration; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Bfci; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataUtils; @@ -136,7 +137,7 @@ public static void main(String[] args) throws IOException { System.out.println("Starting search with all data"); - BfciFoo fci = new BfciFoo(test, score); + BFci fci = new BFci(test, score); fci.setVerbose(false); fci.setCompleteRuleSetUsed(true); fci.setDepth(DFC.depth); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index b8a9b42919..1f6d9d260c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -20,14 +20,12 @@ /////////////////////////////////////////////////////////////////////////////// package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; -import java.io.PrintStream; import java.util.Iterator; import java.util.List; @@ -49,6 +47,7 @@ * @author bryan andrews * @see PermutationSearch * @see Boss + * @see GFci */ public final class BFci implements GraphSearch { @@ -59,32 +58,23 @@ public final class BFci implements GraphSearch { private Knowledge knowledge = new Knowledge(); // The conditional independence test. - private IndependenceTest independenceTest; + private final IndependenceTest independenceTest; - // Flag for complete rule set, true if should use complete rule set, false otherwise. + // Flag for complete rule set, true if it should use complete rule set, false otherwise. private boolean completeRuleSetUsed = true; // The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. private int maxPathLength = -1; - // The maxDegree for the fast adjacency search. - private int maxDegree = -1; - // The logger to use. private final TetradLogger logger = TetradLogger.getInstance(); // True iff verbose output should be printed. private boolean verbose; - // The covariance matrix being searched over. Assumes continuous data. - ICovarianceMatrix covarianceMatrix; - // The sample size. int sampleSize; - // The print stream that output is directed to. - private PrintStream out = System.out; - // The score. private final Score score; private int numStarts = 1; @@ -104,7 +94,9 @@ public BFci(IndependenceTest test, Score score) { //========================PUBLIC METHODS==========================// /** - * @return the discovered CPDAG. + * Does the search and returns a PAG. + * + * @return The discovered graph. */ public Graph search() { List nodes = getIndependenceTest().getVariables(); @@ -116,7 +108,6 @@ public Graph search() { // BOSS CPDAG learning step Boss subAlg = new Boss(this.score); -// subAlg.setDepth(this.depth); subAlg.setNumStarts(this.numStarts); PermutationSearch alg = new PermutationSearch(subAlg); alg.setKnowledge(this.knowledge); @@ -148,58 +139,16 @@ public Graph search() { } /** - * @param maxDegree The maximum indegree of the output graph. + * Sets the maximum indegree of the output graph, to guide search. + * + * @param maxDegree This maximum. */ public void setMaxDegree(int maxDegree) { if (maxDegree < -1) { throw new IllegalArgumentException("Depth must be -1 (unlimited) or >= 0: " + maxDegree); } - this.maxDegree = maxDegree; - } - - /** - * Returns The maximum indegree of the output graph. - */ - public int getMaxDegree() { - return this.maxDegree; - } - - // Due to Spirtes. - public void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { - this.graph = new EdgeListGraph(graph); - this.graph.reorientAllWith(Endpoint.CIRCLE); - fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); - - List nodes = this.graph.getNodes(); - - for (Node b : nodes) { - List adjacentNodes = this.graph.getAdjacentNodes(b); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node a = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - if (fgesGraph.isDefCollider(a, b, c)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { - List sepset = sepsets.getSepset(a, c); - - if (sepset != null && !sepset.contains(b)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - } - } - } - } + // The maxDegree for the fast adjacency search. } public Knowledge getKnowledge() { @@ -255,42 +204,60 @@ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * + * @param verbose True iff the case + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * The independence test. + * The independence test being used for some steps in final orientation. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } - public ICovarianceMatrix getCovMatrix() { - return this.covarianceMatrix; - } + //===========================================PRIVATE METHODS=======================================// - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } + // Due to Spirtes. + private void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { + this.graph = new EdgeListGraph(graph); + this.graph.reorientAllWith(Endpoint.CIRCLE); + fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } + List nodes = this.graph.getNodes(); - public PrintStream getOut() { - return this.out; - } + for (Node b : nodes) { + List adjacentNodes = this.graph.getAdjacentNodes(b); - public void setOut(PrintStream out) { - this.out = out; - } + if (adjacentNodes.size() < 2) { + continue; + } - public void setIndependenceTest(IndependenceTest independenceTest) { - this.independenceTest = independenceTest; - } + ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); + int[] combination; - //===========================================PRIVATE METHODS=======================================// + while ((combination = cg.next()) != null) { + Node a = adjacentNodes.get(combination[0]); + Node c = adjacentNodes.get(combination[1]); + + if (fgesGraph.isDefCollider(a, b, c)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { + List sepset = sepsets.getSepset(a, c); + + if (sepset != null && !sepset.contains(b)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } + } + } + } + } /** * Orients according to background knowledge 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 deleted file mode 100644 index 579c91a384..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java +++ /dev/null @@ -1,392 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.SublistGenerator; -import edu.cmu.tetrad.util.TetradLogger; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Does BOSS + retain unshielded colliders + final FCI orientation rules - * - * @author jdramsey - */ -public final class BfciFoo implements GraphSearch { - - // The score used, if GS is used to build DAGs. - private final Score score; - - // The logger to use. - private final TetradLogger logger = TetradLogger.getInstance(); - - // The covariance matrix being searched over, if continuous data is supplied. This is - // no used by the algorithm beut can be retrieved by another method if desired - ICovarianceMatrix covarianceMatrix; - - // The test used if Pearl's method is used ot build DAGs - private IndependenceTest test; - - // Flag for complete rule set, true if you should use complete rule set, false otherwise. - private boolean completeRuleSetUsed = true; - - // The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. - private int maxPathLength = -1; - - // True iff verbose output should be printed. - private boolean verbose; - - // The print stream that output is directed to. - private PrintStream out = System.out; - - // GRaSP parameters - private int depth = -1; - private boolean doDiscriminatingPathRule = true; - private Knowledge knowledge = new Knowledge(); - - //============================CONSTRUCTORS============================// - public BfciFoo(IndependenceTest test, Score score) { - this.test = test; - this.score = score; - } - - //========================PUBLIC METHODS==========================// - public Graph search() { - this.logger.log("info", "Starting FCI algorithm."); - this.logger.log("info", "Independence test = " + getTest() + "."); - - // Run BOSS-tuck to get a CPDAG (like GFCI with FGES)... - PermutationSearch bossOrig = new PermutationSearch(new Boss(score)); - bossOrig.setVerbose(false); - - List variables = this.score.getVariables(); - assert variables != null; - - Graph graph = bossOrig.search(); - - if (score instanceof edu.cmu.tetrad.search.MagSemBicScore) { - ((edu.cmu.tetrad.search.MagSemBicScore) score).setMag(graph); - } - - Knowledge knowledge = new Knowledge(this.knowledge); - - for (Edge edge : graph.getEdges()) { - if (edge.getEndpoint1() == Endpoint.TAIL) edge.setEndpoint1(Endpoint.CIRCLE); - if (edge.getEndpoint2() == Endpoint.TAIL) edge.setEndpoint2(Endpoint.CIRCLE); - } - - // Do final FCI orientation rules app - SepsetProducer sepsets = new SepsetsGreedy(graph, test, null, depth); - FciOrient fciOrient = new FciOrient(sepsets); - fciOrient.setCompleteRuleSetUsed(this.completeRuleSetUsed); - fciOrient.setDoDiscriminatingPathColliderRule(this.doDiscriminatingPathRule); - fciOrient.setDoDiscriminatingPathTailRule(this.doDiscriminatingPathRule); - fciOrient.setMaxPathLength(this.maxPathLength); - fciOrient.setKnowledge(knowledge); - fciOrient.doFinalOrientation(graph); - - return graph; - } - - private static void triangleReduce1(Graph graph, TeyssierScorer scorer, Knowledge knowledge) { - boolean changed = true; - - while (changed) { - changed = false; - - for (Edge edge : graph.getEdges()) { - Node a = edge.getNode1(); - Node b = edge.getNode2(); - - if (graph.isAdjacentTo(a, b)) { - List inTriangle = graph.getAdjacentNodes(a); - inTriangle.retainAll(graph.getAdjacentNodes(b)); - - Set _all = new HashSet<>(inTriangle); - _all.addAll(graph.getAdjacentNodes(a)); - _all.addAll(graph.getAdjacentNodes(b)); - - List all = new ArrayList<>(_all); - - SublistGenerator gen = new SublistGenerator(all.size(), all.size()); - int[] choice; - - double maxScore = Float.NEGATIVE_INFINITY; - List maxAfter = null; - boolean remove = false; - - while ((choice = gen.next()) != null) { - List before = GraphUtils.asList(choice, all); - List after = new ArrayList<>(inTriangle); - after.removeAll(before); - - List perm = new ArrayList<>(before); - perm.add(a); - perm.add(b); - perm.addAll(after); - - double score = scorer.score(perm); - - if (score >= maxScore && !scorer.adjacent(a, b)) { - maxScore = score; - maxAfter = after; - remove = !scorer.adjacent(a, b); - } - } - - if (remove) { - - for (Node x : maxAfter) { - changed = true; - - // Only remove an edge and orient a new collider if it will create a bidirected edge. -// if (graph.getEndpoint(x, a) == Endpoint.ARROW || graph.getEndpoint(x, b) == Endpoint.ARROW) { - graph.removeEdge(a, b); - graph.setEndpoint(a, x, Endpoint.ARROW); - graph.setEndpoint(b, x, Endpoint.ARROW); - - if (graph.getEndpoint(x, a) == Endpoint.CIRCLE && knowledge.isForbidden(a.getName(), x.getName())) { - graph.setEndpoint(x, a, Endpoint.ARROW); - } - - if (graph.getEndpoint(x, b) == Endpoint.CIRCLE && knowledge.isForbidden(b.getName(), x.getName())) { - graph.setEndpoint(x, b, Endpoint.ARROW); - } - - } -// } - -// break; - } - } - } - } - } - -// 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) { - if (!graph.isAdjacentTo(a, b)) return false; - boolean changed = false; - List _inTriangle = origGraph.getAdjacentNodes(a); - _inTriangle.retainAll(origGraph.getAdjacentNodes(b)); - List parents = origGraph.getParents(a); - parents.remove(b); - for (Node n : _inTriangle) { - parents.remove(n); - } - - List inTriangle = new ArrayList<>(); - List all = new ArrayList<>(); - for (Node n : scorer0.getPi()) { - if (_inTriangle.contains(n)) inTriangle.add(n); - if (_inTriangle.contains(n) || n == a || n == b) all.add(n); - } - - if (_inTriangle.isEmpty()) return false; - - SublistGenerator gen = new SublistGenerator(all.size(), all.size()); - int[] choice; - - double maxScore = Float.NEGATIVE_INFINITY; - List maxAfter = null; - boolean remove = false; - - while ((choice = gen.next()) != null) { - List before = GraphUtils.asList(choice, all); - List after = new ArrayList<>(inTriangle); - after.removeAll(before); - - SublistGenerator gen2 = new SublistGenerator(parents.size(), -1); - int[] choice2; - - while ((choice2 = gen2.next()) != null) { - List p = GraphUtils.asList(choice2, parents); - - List perm = new ArrayList<>(p); - - for (Node n : all) { - perm.remove(n); - perm.add(n); - } - - for (Node n : after) { - perm.remove(n); - perm.add(n); - } - - double score = scorer.score(perm); - - if (score >= maxScore && !scorer.adjacent(a, b)) { - maxScore = score; - maxAfter = after; - remove = !scorer.adjacent(a, b); - } - } - } - - if (remove) { - for (Node x : maxAfter) { - changed = true; - - // Only remove an edge and orient a new collider if it will create a bidirected edge. - graph.removeEdge(a, b); - - if (graph.isAdjacentTo(a, x)) { - graph.setEndpoint(a, x, Endpoint.ARROW); - -// if (graph.getEndpoint(x, a) == Endpoint.CIRCLE && knowledge.isForbidden(a.getName(), x.getName())) { -// graph.setEndpoint(x, a, Endpoint.ARROW); -// } - } - - if (graph.isAdjacentTo(b, x)) { - graph.setEndpoint(b, x, Endpoint.ARROW); - -// if (graph.getEndpoint(x, b) == Endpoint.CIRCLE && knowledge.isForbidden(b.getName(), x.getName())) { -// graph.setEndpoint(x, b, Endpoint.ARROW); -// } - } - } - } - - return changed; - } - - /** - * @return true if Zhang's complete rule set should be used, false if only - * R1-R4 (the rule set of the original FCI) should be used. False by - * default. - */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; - } - - /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set - * should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. - */ - public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { - this.completeRuleSetUsed = completeRuleSetUsed; - } - - /** - * @return the maximum length of any discriminating path, or -1 of - * unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength; - } - - /** - * @param maxPathLength the maximum length of any discriminating path, or -1 - * if unlimited. - */ - public void setMaxPathLength(int maxPathLength) { - if (maxPathLength < -1) { - throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); - } - - this.maxPathLength = maxPathLength; - } - - /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - /** - * The independence test. - */ - public IndependenceTest getTest() { - return this.test; - } - - public void setTest(IndependenceTest test) { - this.test = test; - } - - public ICovarianceMatrix getCovMatrix() { - return this.covarianceMatrix; - } - - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } - - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } - - public PrintStream getOut() { - return this.out; - } - - public void setOut(PrintStream out) { - this.out = out; - } - - public void setDepth(int depth) { - this.depth = depth; - } - - public void setUseRaskuttiUhler(boolean useRaskuttiUhler) { - } - - public void setUseScore(boolean useScore) { - } - - public void setUseDataOrder(boolean useDataOrder) { - } - - public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { - this.doDiscriminatingPathRule = doDiscriminatingPathRule; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciTr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciTr.java deleted file mode 100644 index 66f8ee88de..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciTr.java +++ /dev/null @@ -1,286 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.SublistGenerator; -import edu.cmu.tetrad.util.TetradLogger; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -import static edu.cmu.tetrad.graph.GraphUtils.retainUnshieldedColliders; - -/** - * Does an FCI-style latent variable search using permutation-based reasoning. Follows GFCI to - * an extent; the GFCI reference is this: - *

- * J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm - * for Latent Variable Models," JMLR 2016. - * - * @author jdramsey - */ -public final class BfciTr implements GraphSearch { - - // The score used, if GS is used to build DAGs. - private final Score score; - - // The logger to use. - private final TetradLogger logger = TetradLogger.getInstance(); - - // The covariance matrix being searched over, if continuous data is supplied. This is - // not used by the algorithm but can be retrieved by another method if desired - ICovarianceMatrix covarianceMatrix; - - // The test used if Pearl's method is used ot build DAGs - private IndependenceTest test; - - // Flag for complete rule set, true if you should use complete rule set, false otherwise. - private boolean completeRuleSetUsed = true; - - // The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. - private int maxPathLength = -1; - - // True iff verbose output should be printed. - private boolean verbose; - - // The print stream that output is directed to. - private PrintStream out = System.out; - - private Knowledge knowledge = new Knowledge(); - - //============================CONSTRUCTORS============================// - public BfciTr(IndependenceTest test, Score score) { - this.test = test; - this.score = score; - } - - //========================PUBLIC METHODS==========================// - public Graph search() { - this.logger.log("info", "Starting FCI algorithm."); - this.logger.log("info", "Independence test = " + getTest() + "."); - - TeyssierScorer scorer = new TeyssierScorer(test, score); - - // Run BOSS-tuck to get a CPDAG (like GFCI with FGES)... - PermutationSearch bossOrig = new PermutationSearch(new Boss(score)); - bossOrig.setVerbose(false); // Get the DAG - - List variables = this.score.getVariables(); - assert variables != null; - - Graph graph = bossOrig.search(); - - test = new IndTestScore(score); - - knowledge = new Knowledge(knowledge); - - // Remove edges by conditioning on subsets of variables in triangles, orienting more colliders - retainUnshieldedColliders(graph, knowledge); - triangleReduce(graph, scorer, knowledge); // Adds <-> edges to the DAG - - // Retain only the unshielded colliders. - retainUnshieldedColliders(graph, knowledge); - - // Do final FCI orientation rules app - SepsetProducer sepsets = new SepsetsGreedy(graph, test, null, -1); - FciOrient fciOrient = new FciOrient(sepsets); - fciOrient.setCompleteRuleSetUsed(this.completeRuleSetUsed); - fciOrient.setDoDiscriminatingPathColliderRule(true);//this.doDiscriminatingPathRule); - fciOrient.setDoDiscriminatingPathTailRule(true);//this.doDiscriminatingPathRule); - fciOrient.setMaxPathLength(this.maxPathLength); - fciOrient.doFinalOrientation(graph); - - return graph; - } - - private static void triangleReduce(Graph graph, TeyssierScorer scorer, Knowledge knowledge) { - boolean changed = true; - - while (changed) { - changed = false; - - for (Edge edge : graph.getEdges()) { - Node a = edge.getNode1(); - Node b = edge.getNode2(); - - changed = changed || triangleReduceVisit(graph, scorer, knowledge, a, b); - changed = changed || triangleReduceVisit(graph, scorer, knowledge, b, a); - } - } - - } - - private static boolean triangleReduceVisit(Graph graph, TeyssierScorer scorer, Knowledge knowledge, Node a, Node b) { - List inTriangle = graph.getAdjacentNodes(a); - inTriangle.retainAll(graph.getAdjacentNodes(b)); - - if (graph.isAdjacentTo(a, b)) { - SublistGenerator gen = new SublistGenerator(inTriangle.size(), inTriangle.size()); - int[] choice; - - double maxScore = Float.NEGATIVE_INFINITY; - List maxAfter = null; - boolean remove = false; - - W: - while ((choice = gen.next()) != null) { - List before = GraphUtils.asList(choice, inTriangle); - List after = new ArrayList<>(inTriangle); - - for (Node x : after) { - if (knowledge.isForbidden(a.getName(), x.getName())) { - continue W; - } - - if (knowledge.isForbidden(b.getName(), x.getName())) { - continue W; - } - } - - after.removeAll(before); - - List perm = new ArrayList<>(graph.getParents(a)); - - for (Node n : before) { - perm.remove(n); - perm.add(n); - } - - perm.add(a); - perm.add(b); - - for (Node n : after) { - perm.remove(n); - perm.add(n); - } - - double score = scorer.score(perm); - - if (score > maxScore && !scorer.adjacent(a, b)) { - maxScore = score; - maxAfter = after; - remove = !scorer.adjacent(a, b); - } - } - - if (remove) { - for (Node x : maxAfter) { - // Only remove an edge and orient a new collider if it will create a bidirected edge. - graph.removeEdge(a, b); - graph.setEndpoint(a, x, Endpoint.ARROW); - graph.setEndpoint(b, x, Endpoint.ARROW); - - return true; - } - } - } - - return false; - } - - /** - * @return true if Zhang's complete rule set should be used, false if only - * R1-R4 (the rule set of the original FCI) should be used. False by - * default. - */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; - } - - /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set - * should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. - */ - public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { - this.completeRuleSetUsed = completeRuleSetUsed; - } - - /** - * @return the maximum length of any discriminating path, or -1 of - * unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength; - } - - /** - * @param maxPathLength the maximum length of any discriminating path, or -1 - * if unlimited. - */ - public void setMaxPathLength(int maxPathLength) { - if (maxPathLength < -1) { - throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); - } - - this.maxPathLength = maxPathLength; - } - - /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - /** - * The independence test. - */ - public IndependenceTest getTest() { - return this.test; - } - - public void setTest(IndependenceTest test) { - this.test = test; - } - - public ICovarianceMatrix getCovMatrix() { - return this.covarianceMatrix; - } - - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } - - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } - - public PrintStream getOut() { - return this.out; - } - - public void setOut(PrintStream out) { - this.out = out; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge(knowledge); - } -} diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index 9c2118b3e5..28effa5acb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java @@ -167,8 +167,6 @@ public void explore2() { // out.println("Finishing simulation"); BdeScore score = new BdeScore(data); - score.setSamplePrior(samplePrior); - score.setStructurePrior(structurePrior); edu.cmu.tetrad.search.Fges ges = new edu.cmu.tetrad.search.Fges(score); ges.setVerbose(false); From 3f912b6eae24239b58b37f4169a5702335fe5bc0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 18:35:31 -0400 Subject: [PATCH 118/464] Fixing documentation etc. --- .../algcomparison/algorithm/multi/Images.java | 5 - .../algorithm/oracle/cpdag/Bridges.java | 161 -- .../algorithm/oracle/cpdag/Bridges2.java | 154 -- .../java/edu/cmu/tetrad/search/Bridges.java | 1734 ----------------- .../java/edu/cmu/tetrad/search/Bridges2.java | 305 --- .../edu/cmu/tetrad/search/BridgesOld.java | 172 -- .../java/edu/cmu/tetrad/test/TestGrasp.java | 64 +- 7 files changed, 1 insertion(+), 2594 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Bridges.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Bridges2.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bridges.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bridges2.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/BridgesOld.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java index 5ebdcb1a82..ab4a3a590e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java @@ -88,11 +88,6 @@ public Graph search(List dataSets, Parameters parameters) { PermutationSearch search = new PermutationSearch(new Boss(score)); search.setKnowledge(this.knowledge); return search.search(); - } else if (meta == 3) { - BridgesOld search = new edu.cmu.tetrad.search.BridgesOld(score); - search.setKnowledge(this.knowledge); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); } else { throw new IllegalArgumentException("Unrecognized meta option: " + meta); } 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 deleted file mode 100644 index 0c3ce3559c..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Bridges.java +++ /dev/null @@ -1,161 +0,0 @@ -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; -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.Score; -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.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -/** - * FGES (the heuristic version). - * - * @author jdramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "BRIDGES", -// command = "bridges", -// algoType = AlgType.forbid_latent_common_causes -//) -//@Bootstrapping -//@Experimental -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() { - - } - - public Bridges(ScoreWrapper score) { - this.score = score; - } - - @Override - public Graph search(DataModel dataModel, Parameters parameters) { - 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); - Graph graph; - - edu.cmu.tetrad.search.Bridges search - = new edu.cmu.tetrad.search.Bridges(score); - search.setKnowledge(this.knowledge); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setMeekVerbose(parameters.getBoolean(Params.MEEK_VERBOSE)); - search.setMaxDegree(parameters.getInt(Params.MAX_DEGREE)); - search.setSymmetricFirstStep(parameters.getBoolean(Params.SYMMETRIC_FIRST_STEP)); - search.setFaithfulnessAssumed(parameters.getBoolean(Params.FAITHFULNESS_ASSUMED)); - search.setParallelized(parameters.getBoolean(Params.PARALLELIZED)); - search.setDepth(parameters.getInt(Params.DEPTH)); - - Object obj = parameters.get(Params.PRINT_STREAM); - if (obj instanceof PrintStream) { - search.setOut((PrintStream) obj); - } - - graph = search.search(); - - return graph; - } else { - Bridges fges = new Bridges(this.score); - - DataSet data = (DataSet) dataModel; - GeneralResamplingTest search = new GeneralResamplingTest( - data, fges, 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 - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "BRIDGES using " + this.score.getDescription(); - } - - @Override - public DataType getDataType() { - return this.score.getDataType(); - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.SYMMETRIC_FIRST_STEP); - parameters.add(Params.MAX_DEGREE); - parameters.add(Params.PARALLELIZED); - parameters.add(Params.FAITHFULNESS_ASSUMED); - parameters.add(Params.TIME_LAG); - parameters.add(Params.DEPTH); - - parameters.add(Params.VERBOSE); - parameters.add(Params.MEEK_VERBOSE); - - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - @Override - public ScoreWrapper getScoreWrapper() { - return this.score; - } - - @Override - 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 deleted file mode 100644 index e5313e5aa1..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Bridges2.java +++ /dev/null @@ -1,154 +0,0 @@ -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; -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.Score; -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.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -/** - * FGES (the heuristic version). - * - * @author jdramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "BRIDGES2", -// command = "bridges2", -// algoType = AlgType.forbid_latent_common_causes -//) -//@Bootstrapping -//@Experimental -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() { - - } - - public Bridges2(ScoreWrapper score) { - this.score = score; - } - - @Override - public Graph search(DataModel dataModel, Parameters parameters) { - 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); - Graph graph; - - edu.cmu.tetrad.search.Bridges2 search = new edu.cmu.tetrad.search.Bridges2(score); - search.setKnowledge(this.knowledge); - search.setMaxDegree(parameters.getInt(Params.MAX_DEGREE)); - - Object obj = parameters.get(Params.PRINT_STREAM); - if (obj instanceof PrintStream) { - search.setOut((PrintStream) obj); - } - - graph = search.search(); - - return graph; - } else { - Bridges2 fges = new Bridges2(this.score); - - DataSet data = (DataSet) dataModel; - GeneralResamplingTest search = new GeneralResamplingTest( - data, fges, 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 - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "BRIDGES using " + this.score.getDescription(); - } - - @Override - public DataType getDataType() { - return this.score.getDataType(); - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.SYMMETRIC_FIRST_STEP); - parameters.add(Params.MAX_DEGREE); - parameters.add(Params.PARALLELIZED); - parameters.add(Params.FAITHFULNESS_ASSUMED); - parameters.add(Params.TIME_LAG); - parameters.add(Params.DEPTH); - - parameters.add(Params.VERBOSE); - parameters.add(Params.MEEK_VERBOSE); - - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - @Override - public ScoreWrapper getScoreWrapper() { - return this.score; - } - - @Override - 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/search/Bridges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bridges.java deleted file mode 100644 index 6aaee087aa..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bridges.java +++ /dev/null @@ -1,1734 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.data.KnowledgeEdge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.SublistGenerator; -import edu.cmu.tetrad.util.TetradLogger; -import org.jetbrains.annotations.NotNull; - -import java.io.PrintStream; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.*; -import java.util.concurrent.*; - -import static edu.cmu.tetrad.graph.Edges.directedEdge; -import static edu.cmu.tetrad.util.RandomUtil.shuffle; -import static org.apache.commons.math3.util.FastMath.max; -import static org.apache.commons.math3.util.FastMath.min; - -/** - * GesSearch is an implementation of the GES algorithm, as specified in - * Chickering (2002) "Optimal structure identification with greedy search" - * Journal of Machine Learning Research. It works for both BayesNets and SEMs. - *

- * Some code optimization could be done for the scoring part of the graph for - * discrete models (method scoreGraphChange). Some of Andrew Moore's approaches - * for caching sufficient statistics, for instance. - *

- * To speed things up, it has been assumed that variables X and Y with zero - * correlation do not correspond to edges in the graph. This is a restricted - * form of the heuristicSpeedup assumption, something GES does not assume. This - * the graph. This is a restricted form of the heuristicSpeedup assumption, - * something GES does not assume. This heuristicSpeedup assumption needs to be - * explicitly turned on using setHeuristicSpeedup(true). - *

- * A number of other optimizations were added 5/2015. See code for details. - * - * @author Ricardo Silva, Summer 2003 - * @author Joseph Ramsey, Revisions 5/2015 - */ -public final class Bridges implements GraphSearch, GraphScorer { - - final Set emptySet = new HashSet<>(); - final int[] count = new int[1]; - private int depth = 10000; - /** - * The logger for this class. The config needs to be set. - */ - private final TetradLogger logger = TetradLogger.getInstance(); - /** - * The top n graphs found by the algorithm, where n is numPatternsToStore. - */ - private final LinkedList topGraphs = new LinkedList<>(); - // Potential arrows sorted by bump high to low. The first one is a candidate for adding to the graph. - private final SortedSet sortedArrows = new ConcurrentSkipListSet<>(); - private final SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>(); - private final Map arrowsMap = new ConcurrentHashMap<>(); - private final Map arrowsMapBackward = new ConcurrentHashMap<>(); - private boolean faithfulnessAssumed = true; - /** - * Specification of forbidden and required edges. - */ - private Knowledge knowledge = new Knowledge(); - /** - * List of variables in the data set, in order. - */ - private List variables; - /** - * An initial graph to start from. - */ - private Graph externalGraph; - /** - * If non-null, edges not adjacent in this graph will not be added. - */ - private Graph boundGraph = null; - /** - * Elapsed time of the most recent search. - */ - private long elapsedTime; - /** - * The totalScore for discrete searches. - */ - private Score score; - /** - * True if verbose output should be printed. - */ - private boolean verbose = false; - private boolean meekVerbose = false; - // Map from variables to their column indices in the data set. - private ConcurrentMap hashIndices; - // A graph where X--Y means that X and Y have non-zero total effect on one another. - private Graph effectEdgesGraph; - - // Where printed output is sent. - private PrintStream out = System.out; - - // A initial adjacencies graph. - private Graph adjacencies = null; - - // The graph being constructed. - private Graph graph; - - // Arrows with the same totalScore are stored in this list to distinguish their order in sortedArrows. - // The ordering doesn't matter; it just have to be transitive. - private int arrowIndex = 0; - - // The BIC score of the model. - private double modelScore = 0; - - // Internal. - private Mode mode = Mode.heuristicSpeedup; - - // Bounds the degree of the graph. - private int maxDegree = -1; - - // True if the first step of adding an edge to an empty graph should be scored in both directions - // for each edge with the maximum score chosen. - private boolean symmetricFirstStep = false; - - // True if FGES should run in a single thread, no if parallelized. - private boolean parallelized = false; - - /** - * Construct a Score and pass it in here. The totalScore should return a - * positive value in case of conditional dependence and a negative values in - * case of conditional independence. See Chickering (2002), locally - * consistent scoring criterion. This by default uses all of the processors on - * the machine. - */ - public Bridges(Score score) { - if (score == null) { - throw new NullPointerException(); - } - - setScore(score); - this.graph = new EdgeListGraph(getVariables()); - } - - // Used to find semidirected paths for cycle checking. - private static Node traverseSemiDirected(Node node, Edge edge) { - if (node == edge.getNode1()) { - if (edge.getEndpoint1() == Endpoint.TAIL) { - return edge.getNode2(); - } - } else if (node == edge.getNode2()) { - if (edge.getEndpoint2() == Endpoint.TAIL) { - return edge.getNode1(); - } - } - - return null; - } - - //==========================PUBLIC METHODS==========================// - - public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { - this.faithfulnessAssumed = faithfulnessAssumed; - } - - public void setDepth(int depth) { - this.depth = depth; - } - - public Bridges(int depth) { - this.depth = depth; - } - - public Graph search() { - - setVerbose(false); - - initializeEffectEdges(variables); - - if (adjacencies != null) { - adjacencies = GraphUtils.replaceNodes(adjacencies, getVariables()); - } - - addRequiredEdges(this.graph); - - List variables = this.variables; - - Set change = search2(new EdgeListGraph(variables), variables); - - Graph g0 = new EdgeListGraph((EdgeListGraph) graph); - - double s0 = getModelScore(); - - boolean flag = true; - - while (flag) { - if (Thread.interrupted()) break; - - flag = false; - List edges = new ArrayList<>(g0.getEdges()); - shuffle(edges); - Iterator edgeItr = edges.iterator(); - - while (!flag && edgeItr.hasNext()) { - Edge edge = edgeItr.next(); - if (edge.isDirected()) { - Graph g = new EdgeListGraph((EdgeListGraph) g0); - Node a = Edges.getDirectedEdgeHead(edge); - Node b = Edges.getDirectedEdgeTail(edge); - - // This code performs "pre-tuck" operation - // that makes anterior nodes of the distal - // node into parents of the proximal node - - for (Node c : g.getAdjacentNodes(b)) { - if (g.paths().existsSemidirectedPath(c, a)) { - g.removeEdge(g.getEdge(b, c)); - g.addDirectedEdge(c, b); - change.add(b); - change.add(c); - } - } - - Edge reversed = edge.reverse(); - - g.removeEdge(edge); - g.addEdge(reversed); - - Set change2 = new MeekRules().orientImplied(g); - change.addAll(change2); - - change = search2(g, new ArrayList<>(change)); - double s1 = getModelScore(); - - if (s1 > s0) { - flag = true; - g0 = g; - s0 = s1; - getOut().println(g0.getNumEdges()); - } - } - } - } - - return g0; - } - - /** - * Greedy equivalence search: Start from the empty graph, add edges till - * model is significant. Then start deleting edges till a minimum is - * achieved. - * - * @return the resulting Pattern. - */ - public Set search2(Graph graph, List variables) { - long start = MillisecondTimes.timeMillis(); - topGraphs.clear(); - - this.graph = graph; - - if (verbose) { - out.println("External graph variables: " + graph.getNodes()); - out.println("Data set variables: " + this.variables); - } - - addRequiredEdges(this.graph); - - this.mode = Mode.heuristicSpeedup; - Set change = fes(variables); - change = bes(new ArrayList<>(change)); - - this.mode = Mode.coverNoncolliders; - change = fes(new ArrayList<>(change)); - change = bes(new ArrayList<>(change)); - -// if (!faithfulnessAssumed) { -// this.mode = Mode.allowUnfaithfulness; -// change = fes(new ArrayList<>(change)); -// change = bes(new ArrayList<>(change)); - - long endTime = MillisecondTimes.timeMillis(); - this.elapsedTime = endTime - start; - - if (verbose) { - this.logger.forceLogMessage("Elapsed time = " + (elapsedTime) / 1000. + " s"); - } - - this.modelScore = scoreDag(SearchGraphUtils.dagFromCPDAG(this.graph), true); - - return change; - } - - /** - * @return the background knowledge. - */ - public Knowledge getKnowledge() { - return knowledge; - } - - /** - * Sets the background knowledge. - * - * @param knowledge the knowledge object, specifying forbidden and required - * edges. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - public long getElapsedTime() { - return elapsedTime; - } - - /** - * @return the totalScore of the given DAG, up to a constant. - */ - public double scoreDag(Graph dag) { - return scoreDag(dag, false); - } - - /** - * @return the list of top scoring graphs. - */ - public LinkedList getTopGraphs() { - return topGraphs; - } - - /** - * Sets whether verbose output should be produced. - */ - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - /** - * Sets whether verbose output should be produced. - */ - public void setMeekVerbose(boolean meekVerbose) { - this.meekVerbose = meekVerbose; - } - - /** - * @return the output stream that output (except for log output) should be - * sent to. - */ - public PrintStream getOut() { - return out; - } - - /** - * Sets the output stream that output (except for log output) should be sent - * to. By detault System.out. - */ - public void setOut(PrintStream out) { - this.out = out; - } - - /** - * @return the set of preset adjacenies for the algorithm; edges not in this - * adjacencies graph will not be added. - */ - public Graph getAdjacencies() { - return adjacencies; - } - - /** - * Sets the set of preset adjacenies for the algorithm; edges not in this - * adjacencies graph will not be added. - */ - public void setAdjacencies(Graph adjacencies) { - this.adjacencies = adjacencies; - } - - /** - * If non-null, edges not adjacent in this graph will not be added. - */ - public void setBoundGraph(Graph boundGraph) { - this.boundGraph = GraphUtils.replaceNodes(boundGraph, getVariables()); - } - -// /** -// * For BIC totalScore, a multiplier on the penalty term. For continuous -// * searches. -// * -// * @deprecated Use the getters on the individual scores instead. -// */ -// public double getPenaltyDiscount() { -// if (score instanceof ISemBicScore) { -// return ((ISemBicScore) score).getPenaltyDiscount(); -// } else { -// return 2.0; -// } -// } - -// /** -// * For BIC totalScore, a multiplier on the penalty term. For continuous -// * searches. -// * -// * @deprecated Use the setters on the individual scores instead. -// */ -// public void setPenaltyDiscount(double penaltyDiscount) { -// if (score instanceof ISemBicScore) { -// ((ISemBicScore) score).setPenaltyDiscount(penaltyDiscount); -// } -// } - -// /** -// * @deprecated Use the setters on the individual scores instead. -// */ -// public void setSamplePrior(double samplePrior) { -// if (score instanceof LocalDiscreteScore) { -// ((LocalDiscreteScore) score).setSamplePrior(samplePrior); -// } -// } - -// /** -// * @deprecated Use the setters on the individual scores instead. -// */ -// public void setStructurePrior(double expectedNumParents) { -// if (score instanceof LocalDiscreteScore) { -// ((LocalDiscreteScore) score).setStructurePrior(expectedNumParents); -// } -// } - - /** - * The maximum of parents any nodes can have in output pattern. - * - * @return -1 for unlimited. - */ - public int getMaxDegree() { - return maxDegree; - } - - /** - * The maximum of parents any nodes can have in output pattern. - * - * @param maxDegree -1 for unlimited. - */ - public void setMaxDegree(int maxDegree) { - if (maxDegree < -1) { - throw new IllegalArgumentException(); - } - this.maxDegree = maxDegree; - } - - public void setSymmetricFirstStep(boolean symmetricFirstStep) { - this.symmetricFirstStep = symmetricFirstStep; - } - - public String logEdgeBayesFactorsString(Graph dag) { - Map factors = logEdgeBayesFactors(dag); - return logBayesPosteriorFactorsString(factors); - } - - //===========================PRIVATE METHODS========================// - - double getModelScore() { - return modelScore; - } - - //Sets the discrete scoring function to use. - private void setScore(Score score) { - this.score = score; - - this.variables = new ArrayList<>(); - - for (Node node : score.getVariables()) { - if (node.getNodeType() == NodeType.MEASURED) { - this.variables.add(node); - } - } - - buildIndexing(score.getVariables()); - - this.maxDegree = this.score.getMaxDegree(); - } - - private int getChunkSize(int n) { - int chunk = n / Runtime.getRuntime().availableProcessors(); - if (chunk < 100) chunk = 100; - return chunk; - } - - private void initializeEffectEdges(final List nodes) { - long start = MillisecondTimes.timeMillis(); - this.effectEdgesGraph = new EdgeListGraph(nodes); - - List> tasks = new ArrayList<>(); - - int chunkSize = getChunkSize(nodes.size()); - - for (int i = 0; i < nodes.size() && !Thread.currentThread().isInterrupted(); i += chunkSize) { - NodeTaskEmptyGraph task = new NodeTaskEmptyGraph(i, min(nodes.size(), i + chunkSize), - nodes, emptySet); - - if (!parallelized) { - task.call(); - } else { - tasks.add(task); - } - } - - if (parallelized) { - ForkJoinPool.commonPool().invokeAll(tasks); - } - - long stop = MillisecondTimes.timeMillis(); - - if (verbose) { - out.println("Elapsed initializeForwardEdgesFromEmptyGraph = " + (stop - start) + " ms"); - } - } - - private Set fes(List variables) { - int maxDegree = this.maxDegree == -1 ? 1000 : this.maxDegree; - - Set _process = new HashSet<>(); - - reevaluateForward(new HashSet<>(variables)); - - while (!sortedArrows.isEmpty()) { - Arrow arrow = sortedArrows.first(); - sortedArrows.remove(arrow); - - Node x = arrow.getA(); - Node y = arrow.getB(); - - if (graph.isAdjacentTo(x, y)) { - continue; - } - - if (graph.getDegree(x) > maxDegree - 1) { - continue; - } - - if (graph.getDegree(y) > maxDegree - 1) { - continue; - } - - if (!getNaYX(x, y).equals(arrow.getNaYX())) { - continue; - } - - if (!new HashSet<>(getTNeighbors(x, y)).equals(arrow.getTNeighbors())) { - continue; - } - - if (!new HashSet<>(graph.getParents(y)).equals(new HashSet<>(arrow.getParents()))) { - continue; - } - - if (!validInsert(x, y, arrow.getHOrT(), getNaYX(x, y))) { - continue; - } - - insert(x, y, arrow.getHOrT(), arrow.getBump()); - - Set orientedByMeek = revertToCPDAG(); - Set process = new HashSet<>(orientedByMeek); - - process.add(x); - process.add(y); - process.addAll(getCommonAdjacents(x, y)); - - _process.addAll(orientedByMeek); - _process.addAll(graph.getAdjacentNodes(x)); - _process.addAll(graph.getAdjacentNodes(y)); - - for (Node n : orientedByMeek) { - _process.addAll(graph.getAdjacentNodes(n)); - } - - reevaluateForward(new HashSet<>(process)); - } - - return new HashSet<>(_process); - } - - - private Set bes(List variables) { - reevaluateBackward(new HashSet<>(variables)); - - Set _process = new HashSet<>(); - - 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).equals(arrow.getNaYX())) { - continue; - } - - if (!new HashSet<>(graph.getParents(y)).equals(new HashSet<>(arrow.getParents()))) { - continue; - } - - if (!validDelete(x, y, arrow.getHOrT(), arrow.getNaYX())) { - 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()); - - Set orientedByMeek = revertToCPDAG(); - Set process = new HashSet<>(orientedByMeek); - process.add(x); - process.add(y); - process.addAll(graph.getAdjacentNodes(x)); - process.addAll(graph.getAdjacentNodes(y)); - process.addAll(getCommonAdjacents(x, y)); - - _process.add(x); - _process.add(y); -// _process.addAll(graph.getAdjacentNodes(x)); -// _process.addAll(graph.getAdjacentNodes(y)); - -// for (Node n : orientedByMeek) { -// _process.addAll(graph.getAdjacentNodes(n)); -// } - - reevaluateBackward(new HashSet<>(process)); - } - - return new HashSet<>(_process); - } - - public List getNeighbors(Graph graph, Node node) { - List edges = graph.getEdges(node); - List neighbors = new ArrayList<>(); - - for (Edge edge : edges) { - if (edge == null) { - continue; - } - - if (!Edges.isUndirectedEdge(edge)) { - continue; - } - - neighbors.add(edge.getDistalNode(node)); - } - - return neighbors; - } - - - // Returns true if knowledge is not empty. - private boolean existsKnowledge() { - return !knowledge.isEmpty(); - } - - // Calcuates new arrows based on changes in the graph for the forward search. - private void reevaluateForward(final Set nodes) { - class AdjTask implements Callable { - - private final List nodes; - private final int from; - private final int to; - - private AdjTask(List nodes, int from, int to) { - this.nodes = nodes; - this.from = from; - this.to = to; - } - - @Override - public Boolean call() { - for (int _y = from; _y < to; _y++) { - if (Thread.interrupted()) break; - - Node y = nodes.get(_y); - - List adj; - - if (mode == Mode.heuristicSpeedup) { - adj = effectEdgesGraph.getAdjacentNodes(y); - } else if (mode == Mode.coverNoncolliders) { - Set g = new HashSet<>(); - - for (Node n : graph.getAdjacentNodes(y)) { - for (Node m : graph.getAdjacentNodes(n)) { - if (graph.isAdjacentTo(y, m)) { - continue; - } - - if (graph.isDefCollider(m, n, y)) { - continue; - } - - g.add(m); - } - } - - adj = new ArrayList<>(g); - } else if (mode == Mode.allowUnfaithfulness) { - adj = new ArrayList<>(variables); - } else { - throw new IllegalStateException(); - } - - for (Node x : adj) { - if (adjacencies != null && !(adjacencies.isAdjacentTo(x, y))) { - continue; - } - - calculateArrowsForward(x, y); - } - } - - return true; - } - } - - List> tasks = new ArrayList<>(); - - int chunkSize = getChunkSize(nodes.size()); - -// AdjTask task = new AdjTask(new ArrayList<>(nodes), 0, nodes.size()); -// task.call(); - - - for (int i = 0; i < nodes.size() && !Thread.currentThread().isInterrupted(); i += chunkSize) { - AdjTask task = new AdjTask(new ArrayList<>(nodes), i, min(nodes.size(), i + chunkSize)); - - if (!this.parallelized) { - task.call(); - } else { - tasks.add(task); - } - } - - if (this.parallelized) { - ForkJoinPool.commonPool().invokeAll(tasks); - } - } - - // Calculates the new arrows for an a->b edge. - private void calculateArrowsForward(Node a, Node b) { - if (adjacencies != null && !adjacencies.isAdjacentTo(a, b)) { - return; - } - - if (a == b) return; - - if (graph.isAdjacentTo(a, b)) return; - - if (existsKnowledge()) { - if (getKnowledge().isForbidden(a.getName(), b.getName())) { - return; - } - } - - Set naYX = getNaYX(a, b); - List TNeighbors = getTNeighbors(a, b); - Set parents = new HashSet<>(graph.getParents(b)); - - HashSet TNeighborsSet = new HashSet<>(TNeighbors); - ArrowConfig config = new ArrowConfig(TNeighborsSet, naYX, parents); - ArrowConfig storedConfig = arrowsMap.get(directedEdge(a, b)); - if (storedConfig != null && storedConfig.equals(config)) return; - arrowsMap.put(directedEdge(a, b), new ArrowConfig(TNeighborsSet, naYX, parents)); - - int _depth = min(depth, TNeighbors.size()); - - final SublistGenerator gen = new SublistGenerator(TNeighbors.size(), _depth);// TNeighbors.size()); - int[] choice; - - Set maxT = null; - double maxBump = Double.NEGATIVE_INFINITY; - List> TT = new ArrayList<>(); - - while ((choice = gen.next()) != null) { - Set _T = GraphUtils.asSet(choice, TNeighbors); - TT.add(_T); - } - - class EvalTask implements Callable { - private final List> Ts; - private final ConcurrentMap hashIndices; - private final int from; - private final int to; - private Set maxT = null; - private double maxBump = Double.NEGATIVE_INFINITY; - - public EvalTask(List> Ts, int from, int to, ConcurrentMap hashIndices) { - this.Ts = Ts; - this.hashIndices = hashIndices; - this.from = from; - this.to = to; - } - - @Override - public EvalPair call() { - for (int k = from; k < to; k++) { - if (Thread.interrupted()) break; - double _bump = insertEval(a, b, Ts.get(k), naYX, parents, this.hashIndices); - - if (_bump > maxBump) { - maxT = Ts.get(k); - maxBump = _bump; - } - } - - EvalPair pair = new EvalPair(); - pair.T = maxT; - pair.bump = maxBump; - - return pair; - } - } - - int chunkSize = getChunkSize(TT.size()); - List tasks = new ArrayList<>(); - - for (int i = 0; i < TT.size() && !Thread.currentThread().isInterrupted(); i += chunkSize) { - EvalTask task = new EvalTask(TT, i, min(TT.size(), i + chunkSize), hashIndices); - - if (!this.parallelized) { - EvalPair pair = task.call(); - - if (pair.bump > maxBump) { - maxT = pair.T; - maxBump = pair.bump; - } - } else { - tasks.add(task); - } - } - - if (this.parallelized) { - List> futures = ForkJoinPool.commonPool().invokeAll(tasks); - - for (Future future : futures) { - try { - EvalPair pair = future.get(); - if (pair.bump > maxBump) { - maxT = pair.T; - maxBump = pair.bump; - } - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - } - } - - if (maxBump > 0) { - addArrowForward(a, b, maxT, TNeighborsSet, naYX, parents, maxBump); - } - } - - private void addArrowForward(Node a, Node b, Set hOrT, Set TNeighbors, Set naYX, - Set parents, double bump) { - Arrow arrow = new Arrow(bump, a, b, hOrT, TNeighbors, naYX, parents, arrowIndex++); - sortedArrows.add(arrow); -// System.out.println(arrow); - } - - private void addArrowBackward(Node a, Node b, Set hOrT, Set naYX, - Set parents, double bump) { - Arrow arrow = new Arrow(bump, a, b, hOrT, null, naYX, parents, arrowIndex++); - sortedArrowsBack.add(arrow); - } - - // Reevaluates arrows after removing an edge from the graph. - private void reevaluateBackward(Set toProcess) { - 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 BackwardTask(Node r, List adj, int chunk, int from, int to, - Map hashIndices) { - this.adj = adj; - this.hashIndices = hashIndices; - this.chunk = chunk; - this.from = from; - this.to = to; - this.r = r; - } - - @Override - protected Boolean compute() { - if (to - from <= chunk) { - for (int _w = from; _w < to; _w++) { - final Node w = adj.get(_w); - Edge e = graph.getEdge(w, r); - - if (e != null) { - if (e.pointsTowards(r)) { - calculateArrowsBackward(w, r); - } else if (e.pointsTowards(w)) { - calculateArrowsBackward(r, w); - } else { - calculateArrowsBackward(w, r); - calculateArrowsBackward(r, w); - } - } - } - - } else { - int mid = (to - from) / 2; - - List tasks = new ArrayList<>(); - - tasks.add(new BackwardTask(r, adj, chunk, from, from + mid, hashIndices)); - tasks.add(new BackwardTask(r, adj, chunk, from + mid, to, hashIndices)); - - invokeAll(tasks); - } - - return true; - } - } - - for (Node r : toProcess) { - List adjacentNodes = new ArrayList<>(toProcess); - ForkJoinPool.commonPool().invoke(new BackwardTask(r, adjacentNodes, getChunkSize(adjacentNodes.size()), 0, - adjacentNodes.size(), hashIndices)); - } - } - - // Calculates the arrows for the removal in the backward direction. - private void calculateArrowsBackward(Node a, Node b) { - if (existsKnowledge()) { - if (!getKnowledge().noEdgeRequired(a.getName(), b.getName())) { - return; - } - } - - Set naYX = getNaYX(a, b); - Set parents = new HashSet<>(graph.getParents(b)); - - List _naYX = new ArrayList<>(naYX); - - ArrowConfigBackward config = new ArrowConfigBackward(naYX, parents); - ArrowConfigBackward storedConfig = arrowsMapBackward.get(directedEdge(a, b)); - if (storedConfig != null && storedConfig.equals(config)) return; - arrowsMapBackward.put(directedEdge(a, b), new ArrowConfigBackward(naYX, parents)); - - int _depth = min(depth, _naYX.size()); - - final SublistGenerator gen = new SublistGenerator(_naYX.size(), _depth);//_naYX.size()); - int[] choice; - Set maxComplement = null; - double maxBump = Double.NEGATIVE_INFINITY; - - while ((choice = gen.next()) != null) { - Set complement = GraphUtils.asSet(choice, _naYX); - double _bump = deleteEval(a, b, complement, parents, hashIndices); - - if (_bump > maxBump) { - maxBump = _bump; - maxComplement = complement; - } - } - - if (maxBump > 0) { - Set _H = new HashSet<>(naYX); - _H.removeAll(maxComplement); - addArrowBackward(a, b, _H, naYX, parents, maxBump); - } - } - - private Set getCommonAdjacents(Node x, Node y) { - Set adj = new HashSet<>(graph.getAdjacentNodes(x)); - adj.retainAll(graph.getAdjacentNodes(y)); - return adj; - } - - // Get all adj that are connected to Y by an undirected edge and not adjacent to X. - private List getTNeighbors(Node x, Node y) { - List yEdges = graph.getEdges(y); - List tNeighbors = new ArrayList<>(); - - for (Edge edge : yEdges) { - if (!Edges.isUndirectedEdge(edge)) { - continue; - } - - Node z = edge.getDistalNode(y); - - if (graph.isAdjacentTo(z, x)) { - continue; - } - - tNeighbors.add(z); - } - - return tNeighbors; - } - - // Evaluate the Insert(X, Y, TNeighbors) operator (Definition 12 from Chickering, 2002). - private double insertEval(Node x, Node y, Set T, Set naYX, Set parents, - Map hashIndices) { - Set set = new HashSet<>(naYX); - set.addAll(T); - set.addAll(parents); - - return scoreGraphChange(x, y, set, hashIndices); - } - - // Evaluate the Delete(X, Y, TNeighbors) operator (Definition 12 from Chickering, 2002). - 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); - } - - // Do an actual insertion. (Definition 12 from Chickering, 2002). - private void insert(Node x, Node y, Set T, double bump) { - graph.addDirectedEdge(x, y); - modelScore += bump; - - int numEdges = graph.getNumEdges(); - - if (numEdges % 1000 == 0) { - out.println("Num edges added: " + numEdges); - } - - if (verbose) { - int cond = T.size() + getNaYX(x, y).size() + graph.getParents(y).size(); - - final String message = graph.getNumEdges() + ". INSERT " + graph.getEdge(x, y) - + " " + T + " " + bump - + " degree = " + GraphUtils.getDegree(graph) - + " indegree = " + GraphUtils.getIndegree(graph) + " cond = " + cond; - TetradLogger.getInstance().forceLogMessage(message); - } - - for (Node _t : T) { - graph.removeEdge(_t, y); - graph.addDirectedEdge(_t, y); - - if (verbose) { - String message = "--- Directing " + graph.getEdge(_t, y); - TetradLogger.getInstance().forceLogMessage(message); - } - } - } - - // Do an actual deletion (Definition 13 from Chickering, 2002). - private void delete(Node x, Node y, Set H, double bump, Set naYX) { - Edge oldxy = graph.getEdge(x, y); - - Set diff = new HashSet<>(naYX); - diff.removeAll(H); - - graph.removeEdge(oldxy); - modelScore += bump; - - int numEdges = graph.getNumEdges(); - if (numEdges % 1000 == 0) { - 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)); - } - } - } - } - - // Test if the candidate insertion is a valid operation - // (Theorem 15 from Chickering, 2002). - private boolean validInsert(Node x, Node y, Set T, Set naYX) { - boolean violatesKnowledge = false; - - if (existsKnowledge()) { - if (knowledge.isForbidden(x.getName(), y.getName())) { - violatesKnowledge = true; - } - - for (Node t : T) { - if (knowledge.isForbidden(t.getName(), y.getName())) { - violatesKnowledge = true; - } - } - } - - Set union = new HashSet<>(T); - union.addAll(naYX); - - return isClique(union) && semidirectedPathCondition(y, x, union) - && !violatesKnowledge; - } - - private boolean validDelete(Node x, Node y, Set H, Set naYX) { - boolean violatesKnowledge = false; - - if (existsKnowledge()) { - for (Node h : H) { - if (knowledge.isForbidden(x.getName(), h.getName())) { - violatesKnowledge = true; - } - - if (knowledge.isForbidden(y.getName(), h.getName())) { - violatesKnowledge = true; - } - } - } - - Set diff = new HashSet<>(naYX); - diff.removeAll(H); - return isClique(diff) && !violatesKnowledge; - } - - // Adds edges required by knowledge. - private void addRequiredEdges(Graph graph) { - if (!existsKnowledge()) { - return; - } - - for (Iterator it = getKnowledge().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) && getKnowledge().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) && getKnowledge().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)); - } - } - } - } - } - } - - // Use background knowledge to decide if an insert or delete operation does not orient edges in a forbidden - // direction according to prior knowledge. If some orientation is forbidden in the subset, the whole subset is - // forbidden. - private boolean invalidSetByKnowledge(Node y, Set subset) { - for (Node node : subset) { - if (getKnowledge().isForbidden(node.getName(), y.getName())) { - return true; - } - } - return false; - } - - // Find all adj that are connected to Y by an undirected edge that are adjacent to X (that is, by undirected or - // directed edge). - private Set getNaYX(Node x, Node y) { - 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; - } - - // Returns true iif the given set forms a clique in the given graph. - private boolean isClique(Set nodes) { - 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; - } - - // Returns true iff every semidirected path from from to to contains an element of cond. - private boolean semidirectedPathCondition(Node from, Node to, Set cond) { - if (from == to) throw new IllegalArgumentException(); - - Queue Q = new LinkedList<>(); - Set V = new HashSet<>(); - - Q.add(from); - V.add(from); - - while (!Q.isEmpty()) { - Node t = Q.remove(); - - if (cond.contains(t)) { - continue; - } - - if (t == to) { - return false; - } - - for (Node u : graph.getAdjacentNodes(t)) { - Edge edge = graph.getEdge(t, u); - Node c = traverseSemiDirected(t, edge); - - if (c == null) { - continue; - } - - if (!V.contains(c)) { - V.add(c); - Q.offer(c); - } - } - } - - return true; - } - - // Runs Meek rules on just the changed adj. - private Set revertToCPDAG() { - MeekRules rules = new MeekRules(); - rules.setKnowledge(getKnowledge()); - rules.setAggressivelyPreventCycles(true); - rules.setVerbose(meekVerbose); - return rules.orientImplied(graph); - } - - // Maps adj to their indices for quick lookup. - private void buildIndexing(List nodes) { - this.hashIndices = new ConcurrentHashMap<>(); - - int i = -1; - - for (Node n : nodes) { - this.hashIndices.put(n, ++i); - } - } - - private double scoreDag(Graph dag, boolean recordScores) { - if (score instanceof GraphScore) return 0.0; - dag = GraphUtils.replaceNodes(dag, getVariables()); - -// Score score = this.score.defaultScore(); - - double _score = 0; - - for (Node node : getVariables()) { - -// if (score instanceof SemBicScore) { - List x = dag.getParents(node); - - int[] parentIndices = new int[x.size()]; - - int count = 0; - for (Node parent : x) { - parentIndices[count++] = hashIndices.get(parent); - } - - final double nodeScore = score.localScore(hashIndices.get(node), parentIndices); - - if (recordScores) { - node.addAttribute("Score", nodeScore); - } - - _score += nodeScore; -// } - } - - if (recordScores) { - graph.addAttribute("Score", _score); - } - - return _score; - } - - 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); - } - - private List getVariables() { - return variables; - } - - private Map logEdgeBayesFactors(Graph dag) { - Map logBayesFactors = new HashMap<>(); - double withEdge = scoreDag(dag); - - for (Edge edge : dag.getEdges()) { - dag.removeEdge(edge); - double withoutEdge = scoreDag(dag); - double difference = withEdge - withoutEdge; - logBayesFactors.put(edge, difference); - dag.addEdge(edge); - } - - return logBayesFactors; - } - - private String logBayesPosteriorFactorsString(final Map factors) { - NumberFormat nf = new DecimalFormat("0.00"); - StringBuilder builder = new StringBuilder(); - - List edges = new ArrayList<>(factors.keySet()); - - edges.sort((o1, o2) -> -Double.compare(factors.get(o1), factors.get(o2))); - - builder.append("Edge Posterior Log Bayes Factors:\n\n"); - - builder.append("For a DAG in the IMaGES pattern with model totalScore m, for each edge e in the " - + "DAG, the model totalScore that would result from removing each edge, calculating " - + "the resulting model totalScore m(e), and then reporting m - m(e). The totalScore used is " - + "the IMScore, L - SUM_i{kc ln n(i)}, L is the maximum likelihood of the model, " - + "k isthe number of parameters of the model, n(i) is the sample size of the ith " - + "data set, and c is the penalty penaltyDiscount. Note that the more negative the totalScore, " - + "the more important the edge is to the posterior probability of the IMaGES model. " - + "Edges are given in order of their importance so measured.\n\n"); - - int i = 0; - - for (Edge edge : edges) { - builder.append(++i).append(". ").append(edge).append(" ").append(nf.format(factors.get(edge))).append("\n"); - } - - return builder.toString(); - } - - public void setParallelized(boolean parallelized) { - this.parallelized = parallelized; - } - - //===========================SCORING METHODS===================// - - /** - * Internal. - */ - private enum Mode { - allowUnfaithfulness, heuristicSpeedup, coverNoncolliders - } - - private static class ArrowConfig { - private Set T; - private Set nayx; - private Set parents; - - public ArrowConfig(Set T, Set nayx, Set parents) { - this.setT(T); - this.setNayx(nayx); - this.setParents(parents); - } - - public Set getT() { - return T; - } - - public void setT(Set t) { - T = t; - } - - public void setNayx(Set nayx) { - this.nayx = nayx; - } - - public Set getParents() { - return parents; - } - - public void setParents(Set parents) { - this.parents = parents; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ArrowConfig that = (ArrowConfig) o; - return T.equals(that.T) && nayx.equals(that.nayx) && parents.equals(that.parents); - } - - @Override - public int hashCode() { - return Objects.hash(T, nayx, parents); - } - } - - private static class ArrowConfigBackward { - private Set nayx; - private Set parents; - - public ArrowConfigBackward(Set nayx, Set parents) { - this.setNayx(nayx); - this.setParents(parents); - } - - public void setNayx(Set nayx) { - this.nayx = nayx; - } - - public Set getParents() { - return parents; - } - - public void setParents(Set parents) { - this.parents = parents; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ArrowConfigBackward that = (ArrowConfigBackward) o; - return nayx.equals(that.nayx) && parents.equals(that.parents); - } - - @Override - public int hashCode() { - return Objects.hash(nayx, parents); - } - } - - // Basic data structure for an arrow a->b considered for addition or removal from the graph, together with - // associated sets needed to make this determination. For both forward and backward direction, NaYX is needed. - // For the forward direction, TNeighbors neighbors are needed; for the backward direction, H neighbors are needed. - // See Chickering (2002). The totalScore difference resulting from added in the edge (hypothetically) is recorded - // as the "bump". - private static class Arrow implements Comparable { - - private final double bump; - private final Node a; - private final Node b; - private final Set hOrT; - private final Set naYX; - private final Set parents; - private final int index; - private Set TNeighbors; - - Arrow(double bump, Node a, Node b, Set hOrT, Set capTorH, Set naYX, - Set parents, int index) { - this.bump = bump; - this.a = a; - this.b = b; - this.setTNeighbors(capTorH); - this.hOrT = hOrT; - this.naYX = naYX; - this.index = index; - this.parents = parents; - } - - public double getBump() { - return bump; - } - - public Node getA() { - return a; - } - - public Node getB() { - return b; - } - - Set getHOrT() { - return hOrT; - } - - Set getNaYX() { - return naYX; - } - - // Sorting by bump, high to low. The problem is the SortedSet contains won't add a new element if it compares - // to zero with an existing element, so for the cases where the comparison is to zero (i.e. have the same - // bump, we need to determine as quickly as possible a determinate ordering (fixed) ordering for two variables. - // The fastest way to do this is using a hash code, though it's still possible for two Arrows to have the - // same hash code but not be equal. If we're paranoid, in this case we calculate a determinate comparison - // not equal to zero by keeping a list. This last part is commened out by default. - public int compareTo(@NotNull Arrow arrow) { - - final int compare = Double.compare(arrow.getBump(), getBump()); - - if (compare == 0) { - return Integer.compare(getIndex(), arrow.getIndex()); - } - - return compare; - } - - public String toString() { - return "Arrow<" + a + "->" + b + " bump = " + bump - + " t/h = " + hOrT - + " TNeighbors = " + getTNeighbors() - + " parents = " + parents - + " naYX = " + naYX + ">"; - } - - public int getIndex() { - return index; - } - - public Set getTNeighbors() { - return TNeighbors; - } - - public void setTNeighbors(Set TNeighbors) { - this.TNeighbors = TNeighbors; - } - - public Set getParents() { - return parents; - } - } - - private static class EvalPair { - Set T; - double bump; - } - - class NodeTaskEmptyGraph implements Callable { - - private final int from; - private final int to; - private final List nodes; - private final Set emptySet; - - NodeTaskEmptyGraph(int from, int to, List nodes, Set emptySet) { - this.from = from; - this.to = to; - this.nodes = nodes; - this.emptySet = emptySet; - } - - @Override - public Boolean call() { - for (int i = from; i < to; i++) { - if (Thread.interrupted()) break; - if ((i + 1) % 1000 == 0) { - count[0] += 1000; - out.println("Initializing effect edges: " + (count[0])); - } - - Node y = nodes.get(i); - - for (int j = i + 1; j < nodes.size() && !Thread.currentThread().isInterrupted(); j++) { - Node x = nodes.get(j); - - if (existsKnowledge()) { - if (getKnowledge().isForbidden(x.getName(), y.getName()) && getKnowledge().isForbidden(y.getName(), x.getName())) { - continue; - } - - if (invalidSetByKnowledge(y, emptySet)) { - continue; - } - } - - if (adjacencies != null && !adjacencies.isAdjacentTo(x, y)) { - continue; - } - - int child = hashIndices.get(y); - int parent = hashIndices.get(x); - double bump = score.localScoreDiff(parent, child); - - if (symmetricFirstStep) { - double bump2 = score.localScoreDiff(child, parent); - bump = max(bump, bump2); - } - - if (boundGraph != null && !boundGraph.isAdjacentTo(x, y)) { - continue; - } - - if (bump > 0) { - effectEdgesGraph.addEdge(Edges.undirectedEdge(x, y)); - addArrowForward(x, y, emptySet, emptySet, emptySet, emptySet, bump); - addArrowForward(y, x, emptySet, emptySet, emptySet, emptySet, bump); - } - } - } - - return true; - } - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bridges2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bridges2.java deleted file mode 100644 index caf1f2922f..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bridges2.java +++ /dev/null @@ -1,305 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; - -import java.io.PrintStream; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -/** - * GesSearch is an implementation of the GES algorithm, as specified in - * Chickering (2002) "Optimal structure identification with greedy search" - * Journal of Machine Learning Research. It works for both BayesNets and SEMs. - *

- * Some code optimization could be done for the scoring part of the graph for - * discrete models (method scoreGraphChange). Some of Andrew Moore's approaches - * for caching sufficient statistics, for instance. - *

- * To speed things up, it has been assumed that variables X and Y with zero - * correlation do not correspond to edges in the graph. This is a restricted - * form of the heuristicSpeedup assumption, something GES does not assume. This - * the graph. This is a restricted form of the heuristicSpeedup assumption, - * something GES does not assume. This heuristicSpeedup assumption needs to be - * explicitly turned on using setHeuristicSpeedup(true). - *

- * A number of other optimizations were added 5/2015. See code for details. - * - * @author Ricardo Silva, Summer 2003 - * @author Joseph Ramsey, Revisions 5/2015 - */ -public final class Bridges2 implements GraphSearch, GraphScorer { - - /** - * Specification of forbidden and required edges. - */ - private Knowledge knowledge = new Knowledge(); - /** - * List of variables in the data set, in order. - */ - private final List variables; - - /** - * The totalScore for discrete searches. - */ - private final Score score; - // Map from variables to their column indices in the data set. - private final HashMap hashIndices; - - // Where printed output is sent. - private PrintStream out = System.out; - - // A initial adjacencies graph. - private Graph adjacencies = null; - - // Bounds the degree of the graph. - private int maxDegree = -1; - - /** - * Construct a Score and pass it in here. The totalScore should return a - * positive value in case of conditional dependence and a negative values in - * case of conditional independence. See Chickering (2002), locally - * consistent scoring criterion. This by default uses all of the processors on - * the machine. - */ - public Bridges2(Score score) { - if (score == null) { - throw new NullPointerException(); - } - - this.score = score; - this.variables = score.getVariables(); - - this.hashIndices = new HashMap<>(); - - for (int i = 0; i < variables.size(); i++) { - hashIndices.put(variables.get(i), i); - } - } - - //==========================PUBLIC METHODS==========================// - - public Graph search() { - - Fges fges = new Fges(score); - Graph g0 = fges.search(); - double s0 = fges.getModelScore(); - - boolean flag = true; - - while (flag) { - if (Thread.interrupted()) break; - - flag = false; - Iterator edges = g0.getEdges().iterator(); - - while (!flag && edges.hasNext()) { - Edge edge = edges.next(); - - if (edge.isDirected()) { - Graph g = new EdgeListGraph(g0); - Node a = Edges.getDirectedEdgeHead(edge); - Node b = Edges.getDirectedEdgeTail(edge); - - // This code performs "pre-tuck" operation - // that makes anterior nodes of the distal - // node into parents of the proximal node - - for (Node c : g.getAdjacentNodes(b)) { - if (g.paths().existsSemidirectedPath(c, a)) { - g.removeEdge(g.getEdge(b, c)); - g.addDirectedEdge(c, b); - } - } - - Edge reversed = edge.reverse(); - - g.removeEdge(edge); - g.addEdge(reversed); - - fges.setInitialGraph(g); - Graph g1 = fges.search(); - double s1 = fges.getModelScore(); - - if (s1 > s0) { - flag = true; - g0 = g1; - s0 = s1; - getOut().println(g0.getNumEdges()); - } - } - } - } - - return g0; - } - - /** - * @return the background knowledge. - */ - public Knowledge getKnowledge() { - return knowledge; - } - - /** - * Sets the background knowledge. - * - * @param knowledge the knowledge object, specifying forbidden and required - * edges. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - /** - * @return the output stream that output (except for log output) should be - * sent to. - */ - public PrintStream getOut() { - return out; - } - - /** - * Sets the output stream that output (except for log output) should be sent - * to. By detault System.out. - */ - public void setOut(PrintStream out) { - this.out = out; - } - - /** - * @return the set of preset adjacenies for the algorithm; edges not in this - * adjacencies graph will not be added. - */ - public Graph getAdjacencies() { - return adjacencies; - } - - /** - * Sets the set of preset adjacenies for the algorithm; edges not in this - * adjacencies graph will not be added. - */ - public void setAdjacencies(Graph adjacencies) { - this.adjacencies = adjacencies; - } - - /** - * For BIC totalScore, a multiplier on the penalty term. For continuous - * searches. - * - * @deprecated Use the getters on the individual scores instead. - */ - public double getPenaltyDiscount() { - if (score instanceof ISemBicScore) { - return ((ISemBicScore) score).getPenaltyDiscount(); - } else { - return 2.0; - } - } - - /** - * For BIC totalScore, a multiplier on the penalty term. For continuous - * searches. - * - * @deprecated Use the setters on the individual scores instead. - */ - public void setPenaltyDiscount(double penaltyDiscount) { - if (score instanceof ISemBicScore) { - ((ISemBicScore) score).setPenaltyDiscount(penaltyDiscount); - } - } - - /** - * @deprecated Use the setters on the individual scores instead. - */ - public void setSamplePrior(double samplePrior) { - if (score instanceof LocalDiscreteScore) { - ((LocalDiscreteScore) score).setSamplePrior(samplePrior); - } - } - - /** - * @deprecated Use the setters on the individual scores instead. - */ - public void setStructurePrior(double expectedNumParents) { - if (score instanceof LocalDiscreteScore) { - ((LocalDiscreteScore) score).setStructurePrior(expectedNumParents); - } - } - - /** - * The maximum of parents any nodes can have in output pattern. - * - * @return -1 for unlimited. - */ - public int getMaxDegree() { - return maxDegree; - } - - /** - * The maximum of parents any nodes can have in output pattern. - * - * @param maxDegree -1 for unlimited. - */ - public void setMaxDegree(int maxDegree) { - if (maxDegree < -1) { - throw new IllegalArgumentException(); - } - this.maxDegree = maxDegree; - } - - public double scoreDag(Graph dag) { - if (score instanceof GraphScore) return 0.0; - dag = GraphUtils.replaceNodes(dag, getVariables()); - - Score score = this.score.defaultScore(); - - double _score = 0; - - for (Node node : getVariables()) { - List x = dag.getParents(node); - - int[] parentIndices = new int[x.size()]; - - int count = 0; - for (Node parent : x) { - parentIndices[count++] = hashIndices.get(parent); - } - - final double nodeScore = score.localScore(hashIndices.get(node), parentIndices); - - node.addAttribute("Score", nodeScore); - - _score += nodeScore; - } - - dag.addAttribute("Score", _score); - - return _score; - } - - private List getVariables() { - return variables; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BridgesOld.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BridgesOld.java deleted file mode 100644 index 7c57109b09..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BridgesOld.java +++ /dev/null @@ -1,172 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import org.jetbrains.annotations.NotNull; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import static edu.cmu.tetrad.util.RandomUtil.shuffle; - -/** - * Implementation of the experimental BRIDGES algorithm - * - * @author bryanandrews - */ - -public class BridgesOld { - - private final List variables; - - private final Fges ges; - - private final MeekRules meeks; - private Knowledge knowledge = new Knowledge(); - - public BridgesOld(@NotNull Score score) { - this.variables = new ArrayList<>(score.getVariables()); - this.ges = new Fges(score); -// this.ges.setKnowledge(knowledge); - this.meeks = new MeekRules(); - } - - public Graph search() { - - Graph g0 = ges.search(); - double s0 = ges.getModelScore(); - - boolean flag = true; - - while (flag) { - if (Thread.interrupted()) break; - - flag = false; - List edges = new ArrayList<>(g0.getEdges()); - shuffle(edges); - Iterator edgeItr = edges.iterator(); - - while (!flag && edgeItr.hasNext()) { - - Edge edge = edgeItr.next(); - if (edge.isDirected()) { - - Graph g = new EdgeListGraph((EdgeListGraph) g0); - Node a = Edges.getDirectedEdgeHead(edge); - Node b = Edges.getDirectedEdgeTail(edge); - - for (Node c : g.getAdjacentNodes(b)) { - if (c == a || g.paths().existsSemidirectedPath(c, a)) { - g.removeEdge(g.getEdge(b, c)); - g.addDirectedEdge(c, b); - } - } - - meeks.orientImplied(g); - - ges.setInitialGraph(g); - Graph g1 = ges.search(); - double s1 = ges.getModelScore(); - - if (s1 > s0) { - flag = true; - g0 = g1; - s0 = s1; - getOut().println(g0.getNumEdges()); - } - } - } - } - - return g0; - } - -// public Graph search() { -// -// Graph g1 = ges.search(); -// Graph g0 = g1; -// double s1 = ges.getModelScore(); -// double s0 = s1 - 1; -// -// while (s1 > s0) { -// if (Thread.interrupted()) break; -// g0 = new EdgeListGraph((EdgeListGraph) g1); -// s0 = s1; -// -// Set edges = g0.getEdges(); -// getOut().println(edges.size()); -// -// for (Edge edge : edges) { -// -// if (edge.isDirected()) { -// -// Graph g = new EdgeListGraph((EdgeListGraph) g0); -// Node a = Edges.getDirectedEdgeHead(edge); -// Node b = Edges.getDirectedEdgeTail(edge); -// -// for (Node c : g.getAdjacentNodes(b)) { -// if (c == a || existsSemidirectedPath(c, a, g)) { -// g.removeEdge(g.getEdge(b, c)); -// g.addDirectedEdge(c, b); -// } -// } -// -// meeks.orientImplied(g); -// ges.setExternalGraph(g); -// g = ges.search(); -// -// double s = ges.getModelScore(); -// if (s > s1) { -// g1 = g; -// s1 = s; -// } -// } -// } -// } -// -// return g0; -// } - - - public List getVariables() { - return this.variables; - } - - public int getMaxDegree() { - return ges.getMaxDegree(); - } - - public void setMaxDegree(int maxDegree) { - ges.setMaxDegree(maxDegree); - } - - public void setSymmetricFirstStep(boolean symmetricFirstStep) { - ges.setSymmetricFirstStep(symmetricFirstStep); - } - - public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { - ges.setFaithfulnessAssumed(faithfulnessAssumed); - } - - public void setParallelized(boolean parallelized) { - ges.setParallelized(parallelized); - } - - public void setVerbose(boolean verbose) { - ges.setVerbose(verbose); - } - - public PrintStream getOut() { - return ges.getOut(); - } - - public void setOut(PrintStream out) { - ges.setOut(out); - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } -} diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index e9cb73aef3..f031a0745a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Boss; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Bridges; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Cpc; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Grasp; @@ -69,6 +68,7 @@ import java.text.NumberFormat; import java.util.*; +import static edu.cmu.tetrad.search.Cstar.PatternAlgorithm.GRaSP; import static edu.cmu.tetrad.search.OtherPermAlgs.Method.SP; import static edu.cmu.tetrad.util.RandomUtil.shuffle; @@ -228,68 +228,6 @@ public static void afterClass() throws Exception { } - public void testGrasp1() { - Parameters params = new Parameters(); - params.set(Params.NUM_MEASURES, 200); - params.set(Params.AVG_DEGREE, 6); - params.set(Params.SAMPLE_SIZE, 1000); - params.set(Params.NUM_RUNS, 1); - params.set(Params.COEF_LOW, 0); - params.set(Params.COEF_HIGH, 1); - params.set(Params.NUM_STARTS, 1); - - params.set(Params.PENALTY_DISCOUNT, 2); - params.set(Params.ZS_RISK_BOUND, 0.001); //, 0.01, 0.1); - params.set(Params.EBIC_GAMMA, 0.2, 0.6, 0.8); - params.set(Params.ALPHA, 0.001); - - params.set(Params.GRASP_DEPTH, 3); - params.set(Params.GRASP_SINGULAR_DEPTH, 1); - params.set(Params.GRASP_NONSINGULAR_DEPTH, 1); - - params.set(Params.GRASP_ORDERED_ALG, false); - params.set(Params.GRASP_USE_SCORE, true); - params.set(Params.GRASP_USE_RASKUTTI_UHLER, false); - params.set(Params.GRASP_USE_DATA_ORDER, false); - params.set(Params.CACHE_SCORES, false); -// params.set(Params.GRASP_ALG, false); - - params.set(Params.PARALLELIZED, true); - - Algorithms algorithms = new Algorithms(); -// algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); -// algorithms.add(new BOSS(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); -// algorithms.add(new BOSSTuck(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); - algorithms.add(new Bridges(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); - - Simulations simulations = new Simulations(); - simulations.add(new SemSimulation(new RandomForward())); - - Statistics statistics = new Statistics(); -// statistics.add(new ParameterColumn(Params.GRASP_DEPTH)); -// statistics.add(new ParameterColumn(Params.GRASP_UNCOVERED_DEPTH)); -// statistics.add(new ParameterColumn(Params.GRASP_NONSINGULAR_DEPTH)); -// statistics.add(new ParameterColumn(Params.GRASP_ORDERED_ALG)); -// statistics.add(new ParameterColumn(Params.EBIC_GAMMA)); - statistics.add(new ParameterColumn(Params.NUM_MEASURES)); - statistics.add(new ParameterColumn(Params.AVG_DEGREE)); - statistics.add(new ParameterColumn(Params.SAMPLE_SIZE)); - statistics.add(new NumberOfEdgesTrue()); - statistics.add(new NumberOfEdgesEst()); - statistics.add(new AdjacencyPrecision()); - statistics.add(new AdjacencyRecall()); - statistics.add(new ArrowheadPrecision()); - statistics.add(new ArrowheadRecall()); - statistics.add(new ElapsedCpuTime()); - - Comparison comparison = new Comparison(); - comparison.setShowAlgorithmIndices(true); - comparison.setComparisonGraph(Comparison.ComparisonGraph.true_DAG); - - comparison.compareFromSimulations("/Users/bryanandrews/Downloads/grasp/testGrasp1", - simulations, algorithms, statistics, params); - } - // @Test public void allPaperRuns() { Parameters params = new Parameters(); From 0e2948f064ab5e0264a44d76297568799c84d9ad Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 18:38:34 -0400 Subject: [PATCH 119/464] Fixing documentation etc. --- .../algorithm/oracle/cpdag/BossMb.java | 155 ----- .../algorithm/oracle/cpdag/BossMb2.java | 129 ---- .../java/edu/cmu/tetrad/search/BossMb.java | 277 -------- .../java/edu/cmu/tetrad/search/BossMb2.java | 319 ---------- .../java/edu/cmu/tetrad/search/BossOrig.java | 600 ------------------ .../java/edu/cmu/tetrad/test/TestGrasp.java | 81 --- 6 files changed, 1561 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BossMb.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BossMb2.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossMb.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossMb2.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BossMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BossMb.java deleted file mode 100644 index 47061a0954..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BossMb.java +++ /dev/null @@ -1,155 +0,0 @@ -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; -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.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; -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; - -/** - * BOSS-MB. - * - * @author jdramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "BOSS-MB", -// command = "boss-mb", -// algoType = AlgType.search_for_Markov_blankets -//) -@Bootstrapping -@Experimental -public class BossMb 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 BossMb() { - } - - public BossMb(ScoreWrapper score) { - this.score = score; - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - this.targets = parameters.getString(Params.TARGETS); - - String[] tokens = this.targets.split(","); - List targets = new ArrayList<>(); - - Score score = this.score.getScore(dataSet, parameters); - - for (String t : tokens) { - String name = t.trim(); - targets.add(score.getVariable(name)); - } - - - edu.cmu.tetrad.search.BossMb boss = new edu.cmu.tetrad.search.BossMb(score); - - boss.setDepth(parameters.getInt(Params.GRASP_DEPTH)); - boss.setUseDataOrder(parameters.getBoolean(Params.GRASP_USE_DATA_ORDER)); - boss.setVerbose(parameters.getBoolean(Params.VERBOSE)); - boss.setFindMb(parameters.getBoolean(Params.MB)); - - boss.setNumStarts(parameters.getInt(Params.NUM_STARTS)); - boss.setKnowledge(this.knowledge); - - boss.bestOrder(score.getVariables(), targets); - return boss.getGraph(); - } else { - BossMb fgesMb = new BossMb(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)); - Graph graph = search.search(); - this.bootstrapGraphs = search.getGraphs(); - return graph; - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - Node target = graph.getNode(this.targets); - return GraphUtils.markovBlanketDag(target, new EdgeListGraph(graph)); - } - - @Override - public String getDescription() { - return "BOSS-MB using " + this.score.getDescription(); - } - - @Override - public DataType getDataType() { - return this.score.getDataType(); - } - - @Override - public List getParameters() { - List params = new ArrayList<>(); - params.add(Params.TARGETS); - params.add(Params.MB); - - // Flags - params.add(Params.GRASP_DEPTH); - params.add(Params.GRASP_USE_DATA_ORDER); - params.add(Params.CACHE_SCORES); - params.add(Params.VERBOSE); - - // Parameters - params.add(Params.NUM_STARTS); - - return params; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - @Override - public ScoreWrapper getScoreWrapper() { - return this.score; - } - - @Override - 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/BossMb2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BossMb2.java deleted file mode 100644 index 02e133fe11..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BossMb2.java +++ /dev/null @@ -1,129 +0,0 @@ -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; -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.Score; -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; - -///** -// * BOSS-MB. -// * -// * @author jdramsey -// */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "BOSS-MB2", -// command = "boss-mb2", -// algoType = AlgType.search_for_Markov_blankets -//) -//@Bootstrapping -//@Experimental -public class BossMb2 implements Algorithm, HasKnowledge, UsesScoreWrapper, - ReturnsBootstrapGraphs { - - static final long serialVersionUID = 23L; - private ScoreWrapper score; - private Knowledge knowledge = new Knowledge(); - private List bootstrapGraphs = new ArrayList<>(); - - - public BossMb2() { - } - - public BossMb2(ScoreWrapper score) { - this.score = score; - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - Score score = this.score.getScore(dataSet, parameters); - - edu.cmu.tetrad.search.BossMb2 boss = new edu.cmu.tetrad.search.BossMb2(score); - - boss.setDepth(parameters.getInt(Params.DEPTH)); - boss.setVerbose(parameters.getBoolean(Params.VERBOSE)); - boss.setFindMb(parameters.getBoolean(Params.MB)); - boss.setKnowledge(this.knowledge); - - return boss.search(score.getVariables()); - } else { - BossMb2 fgesMb = new BossMb2(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)); - Graph graph = search.search(); - this.bootstrapGraphs = search.getGraphs(); - return graph; - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "BOSS-MB2 using " + this.score.getDescription(); - } - - @Override - public DataType getDataType() { - return this.score.getDataType(); - } - - @Override - public List getParameters() { - List params = new ArrayList<>(); - params.add(Params.MB); - - // Flags - params.add(Params.DEPTH); - params.add(Params.CACHE_SCORES); - params.add(Params.VERBOSE); - - return params; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - @Override - public ScoreWrapper getScoreWrapper() { - return this.score; - } - - @Override - 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/search/BossMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossMb.java deleted file mode 100644 index 7a68669bd7..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossMb.java +++ /dev/null @@ -1,277 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.RandomUtil; -import edu.cmu.tetrad.util.TetradLogger; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Implements the GRASP algorithms, with various execution flags. - * - * @author bryanandrews - * @author josephramsey - */ -public class BossMb { - private final List variables; - private final Score score; - private Knowledge knowledge = new Knowledge(); - private TeyssierScorer2 scorer; - private long start; - private boolean useDataOrder = true; - private boolean verbose = true; - private int depth = 4; - private int numStarts = 1; - private boolean findMb = false; - private Graph graph; - - public BossMb(@NotNull Score score) { - this.score = score; - this.variables = new ArrayList<>(score.getVariables()); - } - - public List bestOrder(@NotNull List order, List targets) { - long start = MillisecondTimes.timeMillis(); - order = new ArrayList<>(order); - - this.scorer = new TeyssierScorer2(this.score); - - this.scorer.setKnowledge(this.knowledge); - this.scorer.clearBookmarks(); - - List bestPerm = null; - int bestSize = scorer.size(); - - this.scorer.score(order); - - System.out.println("Initial score = " + scorer.score()); - - for (int r = 0; r < this.numStarts; r++) { - if ((r == 0 && !this.useDataOrder) || r > 0) { - RandomUtil.shuffle(order); - } - - this.start = MillisecondTimes.timeMillis(); - - makeValidKnowledgeOrder(order); - - List pi2; - List pi1; - - do { - pi1 = scorer.getPi(); - betterMutationBoss(scorer, targets); - pi2 = besOrder(scorer); - } while (!pi2.equals(pi1)); - - if (this.scorer.size() <= bestSize) { - bestSize = this.scorer.size(); - bestPerm = scorer.getPi(); - } - } - - this.scorer.score(bestPerm); - this.graph = scorer.getGraph(false); - - if (findMb) { - Set mb = new HashSet<>(); - - for (Node n : graph.getNodes()) { - for (Node t : targets) { - if (graph.isAdjacentTo(t, n)) { - mb.add(n); - } else { - for (Node m : graph.getChildren(t)) { - if (graph.isParentOf(n, m)) { - mb.add(n); - } - } - } - } - } - - N: - for (Node n : graph.getNodes()) { - for (Node t : targets) { - if (t == n) continue N; - } - - if (!mb.contains(n)) graph.removeNode(n); - } - } else { - for (Edge e : graph.getEdges()) { - if (!(targets.contains(e.getNode1()) || targets.contains(e.getNode2()))) { - graph.removeEdge(e); - } - } - } - - this.graph = SearchGraphUtils.cpdagForDag(this.graph); - - long stop = MillisecondTimes.timeMillis(); - - if (this.verbose) { - TetradLogger.getInstance().forceLogMessage("Final order = " + this.scorer.getPi()); - TetradLogger.getInstance().forceLogMessage("Elapsed time = " + (stop - start) / 1000.0 + " s"); - } - - return bestPerm; - } - - public void setFindMb(boolean findMb) { - this.findMb = findMb; - } - - public void betterMutationBoss(@NotNull TeyssierScorer2 scorer, List targets) { - double sp; - - List p1, p2; - - do { - p1 = scorer.getPi(); - - Graph g = scorer.getGraph(false); - Set keep = new HashSet<>(targets); - for (Node n : targets) { - keep.addAll(g.getAdjacentNodes(n)); - } - - if (findMb) { - for (Node k : new HashSet<>(keep)) { - keep.addAll(g.getAdjacentNodes(k)); - } - } - - List _pi = new ArrayList<>(); - - for (Node n : scorer.getPi()) { - if (keep.contains(n)) _pi.add(n); - } - - sp = scorer.score(_pi); - - scorer.bookmark(); - - System.out.println("After snips: # vars = " + scorer.getPi().size() + " # Edges = " + scorer.getNumEdges() + " Score = " + scorer.score() + " (betterMutation)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s") + " order = " + scorer.getPi()); - - - for (Node x : scorer.getPi()) { - int i = scorer.index(x); - - for (int j = i - 1; j >= 0; j--) { - if (scorer.tuck(x, j)) { - if (scorer.score() > sp && !violatesKnowledge(scorer.getPi())) { - sp = scorer.score(); - scorer.bookmark(); - - if (verbose) { - System.out.println("# vars = " + scorer.getPi().size() + " # Edges = " + scorer.getNumEdges() + " Score = " + scorer.score() + " (betterMutation)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); - } - } else { - scorer.goToBookmark(); - } - } - } - } - - p2 = scorer.getPi(); - } while (!p1.equals(p2)); - } - - public List besOrder(TeyssierScorer2 scorer) { - Graph graph = scorer.getGraph(true); - Bes bes = new Bes(score); - bes.setDepth(depth); - bes.setVerbose(verbose); - bes.setKnowledge(knowledge); - bes.bes(graph, scorer.getPi()); - return graph.paths().getValidOrder(scorer.getPi(), true); - } - - 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(o2.getName(), o1.getName())) { - return -1; - } else if (this.knowledge.isForbidden(o1.getName(), o2.getName())) { - return 1; - } else { - return 1; - } - }); - } - } - - @NotNull - public Graph getGraph() { - return graph; - } - - public void setNumStarts(int numStarts) { - this.numStarts = numStarts; - } - - public List getVariables() { - return this.variables; - } - - public boolean isVerbose() { - return this.verbose; - } - - 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 boolean violatesKnowledge(List order) { - if (!this.knowledge.isEmpty()) { - 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())) { - return true; - } - } - } - } - - return false; - } - - public void setUseDataOrder(boolean useDataOrder) { - this.useDataOrder = useDataOrder; - } - - - public Knowledge getKnowledge() { - return knowledge; - } - - public enum AlgType {BOSS_OLD, BOSS} -} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossMb2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossMb2.java deleted file mode 100644 index 79768e007d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossMb2.java +++ /dev/null @@ -1,319 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.MillisecondTimes; -import org.jetbrains.annotations.NotNull; - -import java.util.*; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.Future; - -import static java.util.Collections.sort; - - -/** - * Implements the GRASP algorithms, with various execution flags. - * - * @author bryanandrews - * @author josephramsey - */ -public class BossMb2 { - private final List variables; - private final Score score; - private Knowledge knowledge = new Knowledge(); - private long start; - private boolean verbose = true; - private int depth = 4; - private boolean findMb = false; - - public BossMb2(@NotNull Score score) { - this.score = score; - this.variables = new ArrayList<>(score.getVariables()); - } - - class MyTask2 implements Callable { - final TeyssierScorer2 scorer0; - final Node target; - - MyTask2(TeyssierScorer2 scorer0, Node target) { - this.scorer0 = scorer0; - this.target = target; - } - - @Override - public Graph call() throws InterruptedException { - return targetVisit(scorer0, target); - } - } - - /** - * Prints local graphs for all variables and returns the one of them. - */ - public Graph search(@NotNull List order) { - long start = MillisecondTimes.timeMillis(); - order = new ArrayList<>(order); - - TeyssierScorer2 scorer0 = new TeyssierScorer2(this.score); - scorer0.setKnowledge(this.knowledge); - scorer0.score(order); - - this.start = MillisecondTimes.timeMillis(); - - makeValidKnowledgeOrder(order); - - System.out.println("Initial score = " + scorer0.score() + " Elapsed = " + (MillisecondTimes.timeMillis() - start) / 1000.0 + " s"); - - List _targets = new ArrayList<>(scorer0.getPi()); - sort(_targets); - - Graph combinedGraph = new EdgeListGraph(_targets); - - List tasks = new ArrayList<>(); - - try { - for (Node node : _targets) { - tasks.add(new MyTask2(scorer0, node)); - } - - List> futures = ForkJoinPool.commonPool().invokeAll(tasks); - - for (Future future : futures) { - Graph g = future.get(); - this.graphs.add(g); - } - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - - for (Graph graph : graphs) { - for (Edge e : graph.getEdges()) { - combinedGraph.addEdge(e); - } - } - - for (Edge e : combinedGraph.getEdges()) { - if (e.isDirected()) { - if (combinedGraph.containsEdge(e) && combinedGraph.containsEdge(e.reverse())) { - combinedGraph.removeEdge(e); - combinedGraph.removeEdge(e.reverse()); - } - } else if (Edges.isUndirectedEdge(e)) { - Node n1 = e.getNode1(); - Node n2 = e.getNode2(); - - List edges = combinedGraph.getEdges(n1, n2); - - for (Edge _e : edges) { - if (e != _e) combinedGraph.removeEdge(e); - } - } - } - - long stop = MillisecondTimes.timeMillis(); - - System.out.println("Elapsed time = " + (stop - start) / 1000.0 + " s"); - - return combinedGraph; - } - - private Graph targetVisit(TeyssierScorer2 scorer0, Node target) throws InterruptedException { - TeyssierScorer2 scorer = new TeyssierScorer2(scorer0); - - List pi2 = scorer.getPi(); - List pi1; - - do { - if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); - pi1 = pi2; - betterMutationBossTuck(scorer, Collections.singletonList(target)); - pi2 = besOrder(scorer); - } while (!pi1.equals(pi2)); - - scorer.score(pi2); - Graph graph = scorer.getGraph(true); - - if (findMb) { - Set mb = new HashSet<>(); - - for (Node n : graph.getNodes()) { - if (graph.isAdjacentTo(target, n)) { - mb.add(n); - } else { - for (Node m : graph.getChildren(target)) { - if (graph.isParentOf(n, m)) { - mb.add(n); - } - } - } - } - - for (Node n : graph.getNodes()) { - if (target == n) continue; - if (!mb.contains(n)) graph.removeNode(n); - } - } else { - for (Edge e : graph.getEdges()) { - Node n1 = e.getNode1(); - Node n2 = e.getNode2(); - - if (graph.isAdjacentTo(target, n1) && graph.isAdjacentTo(target, n2)) { - graph.removeEdge(e); - } - } - } - - System.out.println("Graph for " + target + " = " + graph); - - System.out.println(); - - return graph; - } - - - public void setFindMb(boolean findMb) { - this.findMb = findMb; - } - - public void betterMutationBossTuck(@NotNull TeyssierScorer2 scorer, List targets) throws - InterruptedException { - double sp; - - List p1, p2; - - do { - if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); - p1 = scorer.getPi(); - - Graph g = scorer.getGraph(false); - Set keep = new HashSet<>(targets); - for (Node n : targets) { - keep.addAll(g.getAdjacentNodes(n)); - } - - if (findMb) { - for (Node k : new HashSet<>(keep)) { - keep.addAll(g.getAdjacentNodes(k)); - } - } - - List _pi = new ArrayList<>(); - - for (Node n : scorer.getPi()) { - if (keep.contains(n)) _pi.add(n); - } - - sp = scorer.score(_pi); - - scorer.bookmark(); - - if (verbose) { - System.out.println("After snips: # vars = " + scorer.getPi().size() + " # Edges = " + scorer.getNumEdges() + " Score = " + scorer.score() + " (betterMutation)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s") + " order = " + scorer.getPi()); - } - - - for (Node x : scorer.getPi()) { - if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); - int i = scorer.index(x); - - for (int j = i - 1; j >= 0; j--) { - if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); - if (scorer.tuck(x, j)) { - if (scorer.score() > sp && !violatesKnowledge(scorer.getPi())) { - sp = scorer.score(); - scorer.bookmark(); - - if (verbose) { - System.out.println("# vars = " + scorer.getPi().size() + " # Edges = " + scorer.getNumEdges() + " Score = " + scorer.score() + " (betterMutation)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); - } - } else { - scorer.goToBookmark(); - } - } - } - } - - p2 = scorer.getPi(); - } while (!p1.equals(p2)); - } - - public List besOrder(TeyssierScorer2 scorer) { - Graph graph = scorer.getGraph(true); - Bes bes = new Bes(score); - bes.setDepth(depth); - bes.setVerbose(verbose); - bes.setKnowledge(knowledge); - bes.bes(graph, scorer.getPi()); - return graph.paths().getValidOrder(scorer.getPi(), true); - } - - 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(o2.getName(), o1.getName())) { - return -1; - } else if (this.knowledge.isForbidden(o1.getName(), o2.getName())) { - return 1; - } else { - return 1; - } - }); - } - } - - @NotNull - public List getGraphs() { - return graphs; - } - - public List getVariables() { - return this.variables; - } - - public boolean isVerbose() { - return this.verbose; - } - - 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 boolean violatesKnowledge(List order) { - if (!this.knowledge.isEmpty()) { - 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())) { - return true; - } - } - } - } - - return false; - } - - private final List graphs = new ArrayList<>(); - - public Knowledge getKnowledge() { - return knowledge; - } - - public enum AlgType {BOSS_OLD, BOSS} -} \ No newline at end of file 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 deleted file mode 100644 index 98abe1c5cc..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java +++ /dev/null @@ -1,600 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.data.KnowledgeEdge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.JOptionUtils; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.NumberFormatUtil; -import edu.cmu.tetrad.util.TetradLogger; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.text.NumberFormat; -import java.util.*; - -import static edu.cmu.tetrad.util.RandomUtil.shuffle; -import static java.lang.Double.NEGATIVE_INFINITY; - -/** - * Implements the BOSS algorithm. - * - * @author bryanandrews - * @author josephramsey - */ -public class BossOrig { - private final List variables; - private final Score score; - private IndependenceTest test; - private Knowledge knowledge = new Knowledge(); - private final TeyssierScorer scorer; - private long start; - long stop; - private boolean useScore = true; - private boolean useRaskuttiUhler; - private boolean useDataOrder = true; - private boolean verbose = true; - private int depth = -1; - private int numStarts = 1; - private AlgType algType = AlgType.BOSS1; - private double epsilon = 1e-10; - - public BossOrig(@NotNull IndependenceTest test, Score score) { - this.test = test; - this.score = score; - this.variables = new ArrayList<>(score.getVariables()); - this.useScore = true; - this.scorer = new TeyssierScorer(this.test, this.score); - } - - public BossOrig(Score score) { - this.test = null; - this.score = score; - this.variables = new ArrayList<>(score.getVariables()); - this.useScore = true; - this.scorer = new TeyssierScorer(null, this.score); - } - - public BossOrig(TeyssierScorer scorer) { - this.scorer = scorer; - this.score = scorer.getScoreObject(); - this.variables = new ArrayList<>(scorer.getPi()); - } - - public List bestOrder(@NotNull List order) { - - scorer.setKnowledge(knowledge); - - List bestPerm; - long start = MillisecondTimes.timeMillis(); - order = new ArrayList<>(order); - - this.scorer.setUseRaskuttiUhler(this.useRaskuttiUhler); - - if (this.useRaskuttiUhler) { - this.scorer.setUseScore(false); - } else { - this.scorer.setUseScore(this.useScore && !(this.score instanceof GraphScore)); - } - - this.scorer.setKnowledge(this.knowledge); - this.scorer.clearBookmarks(); - - bestPerm = null; - double best = NEGATIVE_INFINITY; - - this.scorer.score(order); - - for (int r = 0; r < this.numStarts; r++) { - if ((r == 0 && !this.useDataOrder) || r > 0) { - shuffle(order); - } - - this.start = MillisecondTimes.timeMillis(); - - makeValidKnowledgeOrder(order); - - double s1, s2; - - int count = 0; -// boolean ensureMinimumCount = score instanceof ZhangShenBoundScore; - - if (algType == AlgType.BOSS1) { - betterMutation1(scorer); - } else if (algType == AlgType.BOSS2) { - betterMutation2(scorer); - } else if (algType == AlgType.BOSS3) { - betterMutationBryan(scorer); - } - - do { - s1 = scorer.score(); - - if (algType == AlgType.BOSS1) { - besMutation(scorer); - betterMutation1(scorer); - } else if (algType == AlgType.BOSS2) { - besMutation(scorer); - betterMutation2(scorer); - } else if (algType == AlgType.BOSS3) { - besMutation(scorer); - betterMutationBryan(scorer); - } - - s2 = scorer.score(); - } while (s2 > s1); - - if (this.scorer.score() > best) { - best = this.scorer.score(); - bestPerm = scorer.getPi(); - } - } - - this.scorer.score(bestPerm); - - this.stop = MillisecondTimes.timeMillis(); - - if (this.verbose) { - TetradLogger.getInstance().forceLogMessage("\nFinal " + algType + " order = " + this.scorer.getPi()); - TetradLogger.getInstance().forceLogMessage("Final score = " + this.scorer.score()); - TetradLogger.getInstance().forceLogMessage("Elapsed time = " + (stop - start) / 1000.0 + " s"); - } - - return bestPerm; - } - -// public void betterMutation1(@NotNull TeyssierScorer scorer) { -// double bestScore = scorer.score(); -// scorer.bookmark(); -// double s1, s2; -// -// Set introns1; -// Set introns2; -// -// introns2 = new HashSet<>(scorer.getPi()); -// -// int[] range = new int[2]; -// -// do { -// s1 = scorer.score(); -// -// introns1 = introns2; -// introns2 = new HashSet<>(); -// -// for (int i = 1; i < scorer.size(); i++) { -// Node x = scorer.get(i); -// if (!introns1.contains(x)) continue; -// -// scorer.bookmark(1); -// -// for (int j = i - 1; j >= 0; j--) { -// if (!scorer.adjacent(scorer.get(j), x)) continue; -// -// tuck(x, j, scorer, range); -// -// if (scorer.score() < bestScore || violatesKnowledge(scorer.getPi())) { -// scorer.goToBookmark(); -// } else { -// bestScore = scorer.score(); -// -// for (int l = range[0]; l <= range[1]; l++) { -// introns2.add(scorer.get(l)); -// } -// } -// -// scorer.bookmark(); -// -// if (verbose) { -// System.out.print("\rIndex = " + (i + 1) + " Score = " + scorer.score() + " (betterMutation1)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); -// } -// } -// } -// -// if (verbose) { -// System.out.println(); -// } -// -// s2 = scorer.score(); -// } while (s2 > s1); -// -// scorer.goToBookmark(1); -// } - - public void betterMutation1(@NotNull TeyssierScorer scorer) { - double bestScore = scorer.score(); - double originalScore; - scorer.bookmark(); - - Set introns1; - Set introns2; - - introns2 = new HashSet<>(scorer.getPi()); - int[] range = new int[2]; - - do { - originalScore = bestScore; - - introns1 = introns2; - introns2 = new HashSet<>(); - - for (int i = 1; i < scorer.size(); i++) { - Node x = scorer.get(i); - if (!introns1.contains(x)) continue; - - for (int j = i - 1; j >= 0; j--) { - if (!scorer.adjacent(scorer.get(j), x)) continue; - - tuck(x, j, scorer, range); - - if (scorer.score() > bestScore + epsilon || violatesKnowledge(scorer.getPi())) { - for (int l = range[0]; l <= range[1]; l++) { - introns2.add(scorer.get(l)); - } - bestScore = scorer.score(); - scorer.bookmark(); - } else { - scorer.goToBookmark(); - } - - if (verbose) { - System.out.print("\rIndex = " + (i + 1) + " Score = " + scorer.score() + " (betterMutationTuck)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); - System.out.print("\r# Edges = " + scorer.getNumEdges() + " Index = " + (i + 1) + " Score = " + scorer.score() + " (betterMutationTuck)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); - } - } - } - if (verbose) { - System.out.println(); - } - } while (bestScore > originalScore + epsilon); - } - - - public void betterMutation2(@NotNull TeyssierScorer scorer) { - scorer.bookmark(); - double s1, s2; - - do { - s1 = scorer.score(); - scorer.bookmark(1); - - for (Node k : scorer.getPi()) { - double _sp = NEGATIVE_INFINITY; - scorer.bookmark(); - - for (int j = 0; j < scorer.size(); j++) { - scorer.moveTo(k, j); - - if (scorer.score() >= _sp + epsilon) { - if (!violatesKnowledge(scorer.getPi())) { - _sp = scorer.score(); - scorer.bookmark(); - - if (verbose) { - System.out.print("\rIndex = " + (scorer.index(k) + 1) + " Score = " + scorer.score() + " (betterMutation2)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); - } - } - } - - } - - scorer.goToBookmark(); - } - - if (verbose) { - System.out.println(); - } - - s2 = scorer.score(); - } while (s2 > s1 + epsilon); - - scorer.goToBookmark(1); - } - - public void betterMutationBryan(@NotNull TeyssierScorer scorer) { - double bestScore = scorer.score(); - scorer.bookmark(); - double s1, s2; - - Set introns1; - Set introns2; - - introns2 = new HashSet<>(scorer.getPi()); - - int[] range = new int[2]; - - do { - s1 = scorer.score(); - - introns1 = introns2; - introns2 = new HashSet<>(); - - List> edges = scorer.getEdges(); - int m = 0; - int all = edges.size(); - - for (OrderedPair edge : edges) { - m++; - Node x = edge.getFirst(); - Node y = edge.getSecond(); - if (scorer.index(x) > scorer.index(y)) continue; - if (!scorer.adjacent(y, x)) continue; - if (!introns1.contains(y) && !introns1.contains(x)) continue; - - tuck(y, scorer.index(x), scorer, range); - - if (scorer.score() < bestScore || violatesKnowledge(scorer.getPi())) { - scorer.goToBookmark(); - } else { - bestScore = scorer.score(); - - for (int l = range[0]; l <= range[1]; l++) { - introns2.add(scorer.get(l)); - } - - if (verbose) { - System.out.print("\r Score " + m + " / " + all + " = " + scorer.score() + " (boss)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); - } - } - - scorer.bookmark(); - - if (verbose) { - System.out.print("\r Score " + m + " / " + all + " = " + scorer.score() + " (boss)" + " Elapsed " + ((MillisecondTimes.timeMillis() - start) / 1000.0 + " s")); - } - } - - if (verbose) { - System.out.println(); - } - - s2 = scorer.score(); - } while (s2 > s1); - } - - - public void tubes(@NotNull TeyssierScorer scorer) { - double s; - - do { - s = scorer.score(); - - for (NodePair edge : scorer.getAdjacencies()) { - Node x = edge.getFirst(); - Node y = edge.getSecond(); - if (!scorer.adjacent(x, y)) continue; - - scorer.bookmark(); - - tuck(y, scorer.index(x), scorer, new int[2]); - - if (scorer.score() >= s) { - besMutation(scorer); - } else { - scorer.goToBookmark(); - } - } - - } while (scorer.score() > s); - } - - - private void tuck(Node k, int j, TeyssierScorer scorer, int[] range) { - if (scorer.index(k) < j) return; - Set ancestors = scorer.getAncestors(k); - - int minIndex = j; - - for (int i = j + 1; i <= scorer.index(k); i++) { - if (ancestors.contains(scorer.get(i))) { - scorer.moveTo(scorer.get(i), j++); - } - } - - range[0] = minIndex; - range[1] = scorer.index(k); - } - - public void besMutation(TeyssierScorer scorer) { - Graph graph = scorer.getGraph(true); - Bes bes = new Bes(score); - bes.setDepth(depth); - bes.setVerbose(false); - bes.setKnowledge(knowledge); - bes.bes(graph, scorer.getPi()); - List pi = graph.paths().getValidOrder(scorer.getPi(), true); - scorer.score(pi); - } - - 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; - } - }); - } - - 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."); - } - } - - System.out.println("Initial knowledge sort order = " + order); - - if (violatesKnowledge(order)) { - throw new IllegalArgumentException("The initial sorting procedure could not find a permutation " + - "consistent with that knowledge."); - } - } - - public Graph getGraph(boolean cpDag) { - if (this.scorer == null) throw new IllegalArgumentException("Please run algorithm first."); - Graph graph = this.scorer.getGraph(cpDag); - - NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); - graph.addAttribute("score ", nf.format(this.scorer.score())); - return graph; - } - - public void orientbk(Knowledge bk, Graph graph, List variables) { - for (Iterator it = bk.forbiddenEdgesIterator(); it.hasNext(); ) { - 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); - } - - for (Iterator it = bk.requiredEdgesIterator(); it.hasNext(); ) { - 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); - } - } - - public void setNumStarts(int numStarts) { - this.numStarts = numStarts; - } - - public List getVariables() { - return this.variables; - } - - public boolean isVerbose() { - return this.verbose; - } - - 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; - } - - public void setUseScore(boolean useScore) { - this.useScore = useScore; - } - - private boolean violatesKnowledge(List order) { - if (!this.knowledge.isEmpty()) { - 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())) { - return true; - } - - if (this.knowledge.isRequired(order.get(j).getName(), order.get(i).getName())) { - return true; - } - } - } - } - - 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; - } - - public void setUseRaskuttiUhler(boolean useRaskuttiUhler) { - this.useRaskuttiUhler = useRaskuttiUhler; - } - - public void setUseDataOrder(boolean useDataOrder) { - this.useDataOrder = useDataOrder; - } - - public void setAlgType(AlgType algType) { - this.algType = algType; - } - - public enum AlgType {BOSS1, BOSS2, BOSS3} -} \ No newline at end of file diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index f031a0745a..4bb552fee9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -1140,87 +1140,6 @@ public void wayneCheckDensityClaim1() { System.out.println(count1); } - // @Test - public void wayneCheckDensityClaim2() { - List allFacts = new ArrayList<>(); - - // Only oracle unfaithful examples. - allFacts.add(getFactsSimpleCanceling()); - allFacts.add(wayneTriangleFaithfulnessFailExample()); - allFacts.add(wayneTriMutationFailsForFaithfulGraphExample()); - allFacts.add(getFigure7()); - allFacts.add(getFigure8()); - allFacts.add(getFigure11()); - allFacts.add(wayneExample2()); - - int count = 0; - - boolean verbose = false; - int numRounds = 50; - int depth = 5; - int maxPermSize = 6; - - boolean printCpdag = false; - - for (int i = 0; i < allFacts.size(); i++) { - Ret facts = allFacts.get(i); - count++; - - System.out.println(); - System.out.println("Test #" + (i + 1)); - System.out.println(facts.getLabel()); - System.out.println(facts.getFacts()); - } - - for (int i = 0; i < allFacts.size(); i++) { - boolean passed = true; - - Ret facts = allFacts.get(i); - count++; - - TeyssierScorer scorer = new TeyssierScorer(new IndTestDSep(facts.getFacts()), - new GraphScore(facts.getFacts())); - - OrderedMap> graphs = new ListOrderedMap<>(); - OrderedMap> labels = new ListOrderedMap<>(); - - List variables = facts.facts.getVariables(); - Collections.sort(variables); - - System.out.println("Variables = " + variables); - - PermutationGenerator gen = new PermutationGenerator(variables.size()); - int[] perm; - int count1 = 0; - int total = 0; - - while ((perm = gen.next()) != null) { - List pi = GraphUtils.asList(perm, variables); - - BossOrig boss = new BossOrig(new GraphScore(facts.getFacts())); - - boss.setUseRaskuttiUhler(true); - boss.setDepth(100); -// boss.setOrdered(true); - boss.setVerbose(false); - - boss.bestOrder(pi); - Graph estCpdagGrasp = boss.getGraph(true); - - if (estCpdagGrasp.getNumEdges() == facts.truth) { - count1++; - } else { -// System.out.println("Counterexample: Test #" + (i + 1) + " Permutation = " + pi + " #Edges = " -// + estCpdagGrasp.getNumEdges() + " #Frugal = " + facts.truth); - } - - total++; - } - - System.out.println("Test #" + (i + 1) + " #Frugal = " + count1 + " Total #Permutations = " + total); - } - } - // @Test public void bryanCheckDensityClaims() { NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.NAME); From d789550c8adba40fc256c83053c16c3ed69fd38f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:11:29 -0400 Subject: [PATCH 120/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/LvBesJoe.java | 398 ------------------ 1 file changed, 398 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/LvBesJoe.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LvBesJoe.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LvBesJoe.java deleted file mode 100644 index 0cb46324ff..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LvBesJoe.java +++ /dev/null @@ -1,398 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.SublistGenerator; -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 org.apache.commons.math3.util.FastMath.min; - - -/** - * Implements the backward equivalence search of FGES. - * - * @author bryanandrews - * @author josephramsey - */ -public class LvBesJoe { - private final List variables; - private final Score score; - private Knowledge knowledge = new Knowledge(); - private int depth = -1; - private EdgeListGraph origGraph = null; - - public LvBesJoe(@NotNull Score score) { - this.score = score; - this.variables = score.getVariables(); - } - - @NotNull - public List getVariables() { - return this.variables; - } - - 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 variables) { - origGraph = new EdgeListGraph(graph); - - Map hashIndices = new HashMap<>(); - SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>(); - Map arrowsMapBackward = new ConcurrentHashMap<>(); - int[] arrowIndex = new int[1]; - - buildIndexing(variables, hashIndices); - - reevaluateBackward(new HashSet<>(variables), 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; - } - - Set complement = new HashSet<>(arrow.getCommonAdjacents()); - complement.removeAll(arrow.getHOrT()); - - double _bump = deleteEval(x, y, complement, arrow.parents, hashIndices); - - delete(x, y, arrow.getHOrT(), _bump, arrow.getCommonAdjacents(), graph); - } - } - - private void delete(Node x, Node y, Set H, double bump, Set ca, Graph graph) { - Edge oldxy = graph.getEdge(x, y); - - Set diff = new HashSet<>(ca); - 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 = " + ca + " degree = " + GraphUtils.getDegree(graph) + " indegree = " + GraphUtils.getIndegree(graph) + " diff = " + diff + " (" + bump + ") " + " cond = " + cond; -// TetradLogger.getInstance().forceLogMessage(message); -// } - - for (Node h : H) { - if (graph.isAdjacentTo(x, h)) { - graph.setEndpoint(x, h, Endpoint.ARROW); - } - if (graph.isAdjacentTo(y, h)) { - graph.setEndpoint(y, h, Endpoint.ARROW); - } - } - } - - 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 getCommonAdjacents(Node x, Node y) { - List ca = origGraph.getAdjacentNodes(x); - ca.retainAll(origGraph.getAdjacentNodes(y)); - return new HashSet<>(ca); - } - - 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 adj, int chunk, int from, int to, Map hashIndices, SortedSet sortedArrowsBack, Map arrowsMapBackward) { - this.adj = adj; - this.hashIndices = hashIndices; - this.chunk = chunk; - this.from = from; - this.to = to; - this.r = r; - this.sortedArrowsBack = sortedArrowsBack; - this.arrowsMapBackward = arrowsMapBackward; - } - - @Override - protected Boolean compute() { - if (to - from <= chunk) { - for (int _w = from; _w < to; _w++) { - final Node w = adj.get(_w); - Edge e = graph.getEdge(w, r); - - if (e != null) { - calculateArrowsBackward(w, r, graph, hashIndices, arrowIndex, sortedArrowsBack); - calculateArrowsBackward(r, w, graph, hashIndices, arrowIndex, sortedArrowsBack); - } - } - - } else { - int mid = (to - from) / 2; - - List tasks = new ArrayList<>(); - - tasks.add(new BackwardTask(r, adj, chunk, from, from + mid, hashIndices, sortedArrowsBack, arrowsMapBackward)); - tasks.add(new BackwardTask(r, adj, chunk, from + mid, to, hashIndices, sortedArrowsBack, arrowsMapBackward)); - - invokeAll(tasks); - } - - return true; - } - } - - for (Node r : toProcess) { - List adjacentNodes = new ArrayList<>(toProcess); - ForkJoinPool.commonPool().invoke(new BackwardTask(r, adjacentNodes, getChunkSize(adjacentNodes.size()), - 0, adjacentNodes.size(), hashIndices, sortedArrowsBack, arrowsMapBackward)); - } - } - - private int getChunkSize(int n) { - return 5; -// int chunk = n / Runtime.getRuntime().availableProcessors(); -// if (chunk < 100) chunk = 100; -// return chunk; - } - - private void calculateArrowsBackward(Node a, Node b, Graph graph, - Map hashIndices, - int[] arrowIndex, SortedSet sortedArrowsBack) { - Set ca = getCommonAdjacents(a, b); - - List parents = origGraph.getAdjacentNodes(b); - for (Node n : ca) parents.remove(n); -// parents.remove(a); - - for (Node n : ca) { - parents.remove(n); - } - - List _ca = new ArrayList<>(ca); - - int _depth = min(depth == -1 ? 100000 : depth, _ca.size()); - - final SublistGenerator gen = new SublistGenerator(_ca.size(), _depth); - int[] choice; - Set maxComplement = null; - double maxBump = Double.NEGATIVE_INFINITY; - Set maxParents = new HashSet<>(); - - while ((choice = gen.next()) != null) { - Set complement = GraphUtils.asSet(choice, _ca); - - SublistGenerator gen2 = new SublistGenerator(parents.size(), -1); - int[] choice2; - - while ((choice2 = gen2.next()) != null) { - Set p = GraphUtils.asSet(choice2, parents); - - double _bump = deleteEval(a, b, complement, p, hashIndices); - - if (_bump > maxBump) { - maxBump = _bump; - maxComplement = complement; - maxParents = p; - } - } - } - - if (maxBump > 0) { - Set _H = new HashSet<>(ca); - _H.removeAll(maxComplement); - addArrowBackward(a, b, _H, ca, maxParents, maxBump, arrowIndex, sortedArrowsBack); - } - } - - private void addArrowBackward(Node a, Node b, Set hOrT, Set naYX, Set parents, - double bump, int[] arrowIndex, SortedSet sortedArrowsBack) { - Arrow arrow = new Arrow(bump, a, b, hOrT, null, naYX, parents, arrowIndex[0]++); - sortedArrowsBack.add(arrow); - } - - private static class ArrowConfigBackward { - private Set ca; - private Set parents; - - public ArrowConfigBackward(Set nayx, Set parents) { - this.setCa(nayx); - this.setParents(parents); - } - - public void setCa(Set ca) { - this.ca = ca; - } - - public Set getParents() { - return parents; - } - - public void setParents(Set parents) { - this.parents = parents; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ArrowConfigBackward that = (ArrowConfigBackward) o; - return ca.equals(that.ca) && parents.equals(that.parents); - } - - @Override - public int hashCode() { - return Objects.hash(ca, parents); - } - } - - - private static class Arrow implements Comparable { - - private final double bump; - private final Node a; - private final Node b; - private final Set hOrT; - private final Set naYX; - private final Set parents; - private final int index; - private Set TNeighbors; - - Arrow(double bump, Node a, Node b, Set hOrT, Set capTorH, Set naYX, Set parents, int index) { - this.bump = bump; - this.a = a; - this.b = b; - this.setTNeighbors(capTorH); - this.hOrT = hOrT; - this.naYX = naYX; - this.index = index; - this.parents = parents; - } - - public double getBump() { - return bump; - } - - public Node getA() { - return a; - } - - public Node getB() { - return b; - } - - Set getHOrT() { - return hOrT; - } - - Set getCommonAdjacents() { - return naYX; - } - - // Sorting by bump, high to low. The problem is the SortedSet contains won't add a new element if it compares - // to zero with an existing element, so for the cases where the comparison is to zero (i.e. have the same - // bump), we need to determine as quickly as possible a determinate ordering (fixed) ordering for two variables. - // The fastest way to do this is using a hash code, though it's still possible for two Arrows to have the - // same hash code but not be equal. If we're paranoid, in this case we calculate a determinate comparison - // not equal to zero by keeping a list. This last part is commened out by default. - public int compareTo(@NotNull Arrow arrow) { - - final int compare = Double.compare(arrow.getBump(), getBump()); - - if (compare == 0) { - return Integer.compare(getIndex(), arrow.getIndex()); - } - - return compare; - } - - public String toString() { - return "Arrow<" + a + "->" + b + " bump = " + bump + " t/h = " + hOrT + " TNeighbors = " + getTNeighbors() + " parents = " + parents + " naYX = " + naYX + ">"; - } - - public int getIndex() { - return index; - } - - public Set getTNeighbors() { - return TNeighbors; - } - - public void setTNeighbors(Set TNeighbors) { - this.TNeighbors = TNeighbors; - } - - public Set getParents() { - return parents; - } - } -} \ No newline at end of file From 15aba391832dd5d4957aac05c99751082f78fab2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:21:19 -0400 Subject: [PATCH 121/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/GrowShrink.java | 4 +- .../java/edu/cmu/tetrad/search/GwpResult.java | 157 ---------- .../java/edu/cmu/tetrad/search/HbsmsGes.java | 5 +- .../edu/cmu/tetrad/search/LingamPattern2.java | 293 ------------------ .../main/java/edu/cmu/tetrad/search/PcMb.java | 4 +- .../java/edu/cmu/tetrad/search/SvarGfci.java | 2 +- .../search/{TsFges2.java => TsFges.java} | 80 ++--- .../tetrad/search/ZhangShenBoundScore.java | 2 - 8 files changed, 47 insertions(+), 500 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/GwpResult.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern2.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{TsFges2.java => TsFges.java} (95%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index 33fbf5193c..48aae946e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -27,8 +27,8 @@ import java.util.List; /** - * Implements the Grow-Shrink algorithm of Margaritis and Thrun. Reference: "Bayesian Network Induction via Local - * Neighborhoods." + *

Implements the Grow-Shrink algorithm of Margaritis and Thrun. Reference: "Bayesian Network + * Induction via LocalmNeighborhoods."

* * @author Joseph Ramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GwpResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GwpResult.java deleted file mode 100644 index d5906c6af5..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GwpResult.java +++ /dev/null @@ -1,157 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -/** - * The purpose of this class is to store evaluation results. - * - * @author Gustavo - */ -public class GwpResult { - - public interface PartialEvaluationResult { - double[] values(); - } - - public static class AdjacencyEvaluationResult implements PartialEvaluationResult { - public Integer errorsOfOmission; - public Integer errorsOfCommission; - - public AdjacencyEvaluationResult(Integer errorsOfOmission, Integer errorsOfCommission) { - this.errorsOfOmission = errorsOfOmission; - this.errorsOfCommission = errorsOfCommission; - } - - public double loss() { - return this.errorsOfOmission + this.errorsOfCommission; - } - - public double[] values() { - return new double[]{this.errorsOfOmission, this.errorsOfCommission, loss()}; - } - } - - public static class OrientationEvaluationResult implements PartialEvaluationResult { - public Integer nCorrect; - public Integer directedWrongWay; - public Integer undirectedWhenShouldBeDirected; - public Integer directedWhenShouldBeUndirected; - - - public OrientationEvaluationResult(Integer correct, Integer directedWrongWay, - Integer undirectedWhenShouldBeDirected, Integer directedWhenShouldBeUndirected) { - this.nCorrect = correct; - this.directedWrongWay = directedWrongWay; - this.undirectedWhenShouldBeDirected = undirectedWhenShouldBeDirected; - this.directedWhenShouldBeUndirected = directedWhenShouldBeUndirected; - } - - public double[] values() { - return new double[]{this.nCorrect, this.directedWrongWay, this.undirectedWhenShouldBeDirected, this.directedWhenShouldBeUndirected}; - } - - } - - public static class CoefficientEvaluationResult implements PartialEvaluationResult { - public Double totalCoeffErrorSq; - public Integer nEdgesEvaluated; - - public CoefficientEvaluationResult(Double totalCoeffErrorSq, Integer edgesEvaluated) { - this.totalCoeffErrorSq = totalCoeffErrorSq; - this.nEdgesEvaluated = edgesEvaluated; - } - - public double loss() { - return this.totalCoeffErrorSq; - } - - public double[] values() { - return new double[]{this.totalCoeffErrorSq, this.nEdgesEvaluated, loss()}; - } - - } - - - public AdjacencyEvaluationResult adj; - public OrientationEvaluationResult ori; - public CoefficientEvaluationResult coeffAll; - public CoefficientEvaluationResult coeffSome; - - public CPDAGEvaluationResult pat; - - public String name; - - /** - * Loss function for PC: * for adjacency errors, 1 pt (i.e. 1 for omission, 1 for commission) for orientation errors: * - * undirected when it should be directed: 0.5 * directed when it should be undirected: 0.5 * directed the wrong way: - * 1.0 (in other words, 0.5 for each arrow-head difference, for orientation errors) - */ - public static class CPDAGEvaluationResult { - - public AdjacencyEvaluationResult adj; - public OrientationEvaluationResult ori; - - public CPDAGEvaluationResult(AdjacencyEvaluationResult adj, OrientationEvaluationResult ori) { - this.adj = adj; - this.ori = ori; - } - - public double loss() { - double oriLoss = this.ori.directedWrongWay + 0.5 * this.ori.undirectedWhenShouldBeDirected + - 0.5 * this.ori.directedWhenShouldBeUndirected; - - double adjLoss = 1.5 * this.adj.errorsOfOmission + 1.0 * this.adj.errorsOfCommission; - return adjLoss + oriLoss; - } - - } - - - /** - * constructor for evaluations where the method evaluated purports to give us the entire structure. - */ - public GwpResult(String methodName, AdjacencyEvaluationResult adj, OrientationEvaluationResult ori, - CoefficientEvaluationResult coeffAll, CoefficientEvaluationResult coeffSome) { - this.name = methodName; - this.adj = adj; - this.ori = ori; - this.coeffAll = coeffAll; - this.coeffSome = coeffSome; - - } - - /** - * constructor for evaluations where the method evaluated purports to give us the Markov-equivalence class, represented - * by a CPDAG. - *

- * * @param methodName - */ - public GwpResult(String methodName, CPDAGEvaluationResult pat) { - this.name = methodName; - this.pat = pat; - } - - -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java index 6f58a73755..a22f01c796 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java @@ -36,9 +36,8 @@ import java.util.*; /** - * Best Fit Finder using the GES algorithm. - *

- * Improves the P value of a SEM IM by adding, removing, or reversing single edges. + *

HBSMS using the GES algorithm.

+ *

Improves the P value of a SEM IM by adding, removing, or reversing single edges.

* * @author Joseph Ramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern2.java deleted file mode 100644 index f93f3bccca..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern2.java +++ /dev/null @@ -1,293 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import cern.colt.list.DoubleArrayList; -import cern.jet.stat.Descriptive; -import edu.cmu.tetrad.data.AndersonDarlingTest; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.regression.Regression; -import edu.cmu.tetrad.regression.RegressionDataset; -import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.util.Matrix; -import edu.cmu.tetrad.util.TetradLogger; -import edu.cmu.tetrad.util.Vector; -import org.apache.commons.math3.util.FastMath; - -import java.util.ArrayList; -import java.util.List; - -/** - * Implements the Lingam CPDAG algorithm as specified in Hoyer et al., "Causal discovery of linear acyclic models with - * arbitrary distributions," UAI 2008. The test for normality used for residuals is Anderson-Darling, following ad.test - * in the nortest package of R. The default alpha level is 0.05--that is, p values from AD below 0.05 are taken to - * indicate nongaussianity. - *

- * It is assumed that the CPDAG is the result of a CPDAG search such as PC or GES. In any case, it is important that - * the residuals be independent for ICA to work. - * - * @author Joseph Ramsey - */ -public class LingamPattern2 { - private final Graph cpdag; - private final List dataSets; - private double[] pValues; - private double alpha = 0.05; - private final List regressions; - - private final List variables; - private final ArrayList data; - - //===============================CONSTRUCTOR============================// - - public LingamPattern2(Graph cpdag, List dataSets) - throws IllegalArgumentException { - - if (dataSets == null) { - throw new IllegalArgumentException("Data set must be specified."); - } - - if (cpdag == null) { - throw new IllegalArgumentException("CPDAG must be specified."); - } - - this.cpdag = cpdag; - this.dataSets = dataSets; - - this.variables = dataSets.get(0).getVariables(); - - this.data = new ArrayList<>(); - - for (DataSet dataSet : getDataSets()) { - Matrix _data = dataSet.getDoubleData(); - this.data.add(_data); - } - - this.regressions = new ArrayList<>(); - - for (Matrix _data : this.data) { - this.regressions.add(new RegressionDataset(_data, this.variables)); - } - } - - //===============================PUBLIC METHODS========================// - - public Graph search() { - Graph _cpdag = GraphUtils.bidirectedToUndirected(getCpdag()); - - TetradLogger.getInstance().log("info", "Making list of all dags in CPDAG..."); - - List dags = SearchGraphUtils.getAllGraphsByDirectingUndirectedEdges(_cpdag); - - TetradLogger.getInstance().log("normalityTests", "Anderson Darling P value for Variables\n"); - - if (dags.isEmpty()) { - return null; - } - - List scores = new ArrayList<>(); - - for (Graph dag : dags) { - scores.add(getScore(dag, this.data, this.variables)); - } - - double maxScore = 0.0; - int maxj = -1; - - for (int j = 0; j < dags.size(); j++) { - double _score = scores.get(j).score; - - if (_score > maxScore) { - maxScore = _score; - maxj = j; - } - } - - Graph dag = dags.get(maxj); - this.pValues = scores.get(maxj).pvals; - - Graph ngDagCPDAG = SearchGraphUtils.cpdagFromDag(dag); - - List nodes = ngDagCPDAG.getNodes(); - - for (Edge edge : ngDagCPDAG.getEdges()) { - Node node1 = edge.getNode1(); - Node node2 = edge.getNode2(); - - double p1 = getPValues()[nodes.indexOf(node1)]; - double p2 = getPValues()[nodes.indexOf(node2)]; - - boolean node1Nongaussian = p1 < getAlpha(); - boolean node2Nongaussian = p2 < getAlpha(); - - if (node1Nongaussian || node2Nongaussian) { - if (!Edges.isUndirectedEdge(edge)) { - continue; - } - - ngDagCPDAG.removeEdge(edge); - ngDagCPDAG.addEdge(dag.getEdge(node1, node2)); - - if (node1Nongaussian) { - TetradLogger.getInstance().log("edgeOrientations", node1 + " nongaussian "); - } - - if (node2Nongaussian) { - TetradLogger.getInstance().log("edgeOrientations", node2 + " nongaussian "); - } - - TetradLogger.getInstance().log("nongaussianOrientations", "Nongaussian orientation: " + dag.getEdge(node1, node2)); - } - } - - System.out.println(); - - MeekRules meekRules = new MeekRules(); - meekRules.setAggressivelyPreventCycles(true); - meekRules.orientImplied(ngDagCPDAG); - - TetradLogger.getInstance().log("graph", "Returning: " + ngDagCPDAG); - return ngDagCPDAG; - } - - //=============================PRIVATE METHODS=========================// - - // Return the average score. - - private Score getScore(Graph dag, List data, List variables) { - int totalSampleSize = 0; - - for (Matrix _data : data) { - totalSampleSize += _data.rows(); - } - - int numCols = data.get(0).columns(); - - List nodes = dag.getNodes(); - double score = 0.0; - double[] pValues = new double[nodes.size()]; - Matrix residuals = new Matrix(totalSampleSize, numCols); - - for (int j = 0; j < nodes.size(); j++) { - List _residuals = new ArrayList<>(); - - Node _target = nodes.get(j); - List _regressors = dag.getParents(_target); - Node target = getVariable(variables, _target.getName()); - List regressors = new ArrayList<>(); - - for (Node _regressor : _regressors) { - Node variable = getVariable(variables, _regressor.getName()); - regressors.add(variable); - } - - for (int m = 0; m < data.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); - - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); - - double mean = Descriptive.mean(_residualsSingleDataset); - double std = Descriptive.standardDeviation(Descriptive.variance(_residualsSingleDataset.size(), - Descriptive.sum(_residualsSingleDataset), Descriptive.sumOfSquares(_residualsSingleDataset))); - - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean) / std); - } - - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); - } - - DoubleArrayList f = new DoubleArrayList(_residualsSingleDataset.elements()); - - for (int k = 0; k < f.size(); k++) { - f.set(k, FastMath.abs(f.get(k))); - } - - double _mean = Descriptive.mean(f); - double diff = _mean - FastMath.sqrt(2.0 / FastMath.PI); - score += diff * diff; - } - - for (int k = 0; k < _residuals.size(); k++) { - residuals.set(k, j, _residuals.get(k)); - } - } - - for (int j = 0; j < residuals.columns(); j++) { - double[] x = residuals.getColumn(j).toArray(); - double p = new AndersonDarlingTest(x).getP(); - pValues[j] = p; - } - - return new Score(score, pValues); - } - - - public double[] getPValues() { - return this.pValues; - } - - public double getAlpha() { - return this.alpha; - } - - public void setAlpha(double alpha) { - if (alpha < 0.0 || alpha > 1.0) { - throw new IllegalArgumentException("Alpha is in range [0, 1]"); - } - - this.alpha = alpha; - } - - private Graph getCpdag() { - return this.cpdag; - } - - private List getDataSets() { - return this.dataSets; - } - - private static class Score { - public Score(double score, double[] pvals) { - this.score = score; - this.pvals = pvals; - } - - double score; - double[] pvals; - } - - private Node getVariable(List variables, String name) { - for (Node node : variables) { - if (name.equals(node.getName())) { - return node; - } - } - - return null; - } -} - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index ae6460845a..98533c4fae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -30,9 +30,9 @@ import java.util.*; /** - * Searches for a CPDAG representing all the Markov blankets for a given target T consistent with the given + *

Searches for a CPDAG representing all the Markov blankets for a given target T consistent with the given * independence information. This CPDAG may be used to generate the actual list of DAG's that might be Markov - * blankets. Note that this code has been converted to be consistent with the CPC algorithm. + * blankets. Note that this code has been converted to be consistent with the CPC algorithm.

* * @author Joseph Ramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 4fee160877..f1f4fca058 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -139,7 +139,7 @@ public Graph search() { setScore(); } - TsFges2 fges = new TsFges2(this.score); + TsFges fges = new TsFges(this.score); fges.setKnowledge(getKnowledge()); fges.setVerbose(this.verbose); fges.setNumCPDAGsToStore(0); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges2.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 2af6520b31..77f9ff2698 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -52,7 +52,7 @@ * @author Joseph Ramsey, Revisions 5/2015 * @author Daniel Malinsky */ -public final class TsFges2 implements GraphSearch, GraphScorer { +public final class TsFges implements GraphSearch, GraphScorer { /** @@ -181,7 +181,7 @@ private enum Mode { * values in case of conditional independence. See Chickering (2002), * locally consistent scoring criterion. */ - public TsFges2(Score score) { + public TsFges(Score score) { if (score == null) throw new NullPointerException(); setScore(score); this.graph = new EdgeListGraph(getVariables()); @@ -529,12 +529,12 @@ public NodeTaskEmptyGraph(int from, int to, List nodes, Set emptySet protected Boolean compute() { for (int i = this.from; i < this.to; i++) { if ((i + 1) % 1000 == 0) { - TsFges2.this.count[0] += 1000; - TsFges2.this.out.println("Initializing effect edges: " + (TsFges2.this.count[0])); + TsFges.this.count[0] += 1000; + TsFges.this.out.println("Initializing effect edges: " + (TsFges.this.count[0])); } Node y = this.nodes.get(i); - TsFges2.this.neighbors.put(y, this.emptySet); + TsFges.this.neighbors.put(y, this.emptySet); for (int j = i + 1; j < this.nodes.size(); j++) { if (Thread.currentThread().isInterrupted()) { @@ -553,19 +553,19 @@ protected Boolean compute() { } } - if (TsFges2.this.adjacencies != null && !TsFges2.this.adjacencies.isAdjacentTo(x, y)) { + if (TsFges.this.adjacencies != null && !TsFges.this.adjacencies.isAdjacentTo(x, y)) { continue; } - int child = TsFges2.this.hashIndices.get(y); - int parent = TsFges2.this.hashIndices.get(x); - double bump = TsFges2.this.score.localScoreDiff(parent, child); + int child = TsFges.this.hashIndices.get(y); + int parent = TsFges.this.hashIndices.get(x); + double bump = TsFges.this.score.localScoreDiff(parent, child); - if (TsFges2.this.boundGraph != null && !TsFges2.this.boundGraph.isAdjacentTo(x, y)) continue; + if (TsFges.this.boundGraph != null && !TsFges.this.boundGraph.isAdjacentTo(x, y)) continue; if (bump > 0) { Edge edge = Edges.undirectedEdge(x, y); - TsFges2.this.effectEdgesGraph.addEdge(edge); + TsFges.this.effectEdgesGraph.addEdge(edge); } if (bump > 0.0) { @@ -598,7 +598,7 @@ public InitializeFromEmptyGraphTask() { protected Boolean compute() { Queue tasks = new ArrayDeque<>(); - int numNodesPerTask = FastMath.max(100, nodes.size() / TsFges2.this.maxThreads); + int numNodesPerTask = FastMath.max(100, nodes.size() / TsFges.this.maxThreads); for (int i = 0; i < nodes.size(); i += numNodesPerTask) { NodeTaskEmptyGraph task = new NodeTaskEmptyGraph(i, FastMath.min(nodes.size(), i + numNodesPerTask), @@ -613,7 +613,7 @@ protected Boolean compute() { } } - while (tasks.size() > TsFges2.this.maxThreads) { + while (tasks.size() > TsFges.this.maxThreads) { NodeTaskEmptyGraph _task = tasks.poll(); _task.join(); } @@ -676,21 +676,21 @@ protected Boolean compute() { if (this.to - this.from <= this.chunk) { for (int i = this.from; i < this.to; i++) { if ((i + 1) % 1000 == 0) { - TsFges2.this.count[0] += 1000; - TsFges2.this.out.println("Initializing effect edges: " + (TsFges2.this.count[0])); + TsFges.this.count[0] += 1000; + TsFges.this.out.println("Initializing effect edges: " + (TsFges.this.count[0])); } Node y = nodes.get(i); Set g = new HashSet<>(); - for (Node n : TsFges2.this.graph.getAdjacentNodes(y)) { - for (Node m : TsFges2.this.graph.getAdjacentNodes(n)) { - if (TsFges2.this.graph.isAdjacentTo(y, m)) { + for (Node n : TsFges.this.graph.getAdjacentNodes(y)) { + for (Node m : TsFges.this.graph.getAdjacentNodes(n)) { + if (TsFges.this.graph.isAdjacentTo(y, m)) { continue; } - if (TsFges2.this.graph.isDefCollider(m, n, y)) { + if (TsFges.this.graph.isDefCollider(m, n, y)) { continue; } @@ -709,11 +709,11 @@ protected Boolean compute() { } } - if (TsFges2.this.adjacencies != null && !TsFges2.this.adjacencies.isAdjacentTo(x, y)) { + if (TsFges.this.adjacencies != null && !TsFges.this.adjacencies.isAdjacentTo(x, y)) { continue; } - if (TsFges2.this.removedEdges.contains(Edges.undirectedEdge(x, y))) { + if (TsFges.this.removedEdges.contains(Edges.undirectedEdge(x, y))) { continue; } @@ -783,15 +783,15 @@ protected Boolean compute() { } if ((i + 1) % 1000 == 0) { - TsFges2.this.count[0] += 1000; - TsFges2.this.out.println("Initializing effect edges: " + (TsFges2.this.count[0])); + TsFges.this.count[0] += 1000; + TsFges.this.out.println("Initializing effect edges: " + (TsFges.this.count[0])); } Node y = nodes.get(i); List cond = new ArrayList<>(); - Set D = new HashSet<>(TsFges2.this.graph.paths().getDconnectedVars(y, cond)); + Set D = new HashSet<>(TsFges.this.graph.paths().getDconnectedVars(y, cond)); D.remove(y); - TsFges2.this.effectEdgesGraph.getAdjacentNodes(y).forEach(D::remove); + TsFges.this.effectEdgesGraph.getAdjacentNodes(y).forEach(D::remove); for (Node x : D) { if (existsKnowledge()) { @@ -804,7 +804,7 @@ protected Boolean compute() { } } - if (TsFges2.this.adjacencies != null && !TsFges2.this.adjacencies.isAdjacentTo(x, y)) { + if (TsFges.this.adjacencies != null && !TsFges.this.adjacencies.isAdjacentTo(x, y)) { continue; } @@ -1044,18 +1044,18 @@ protected Boolean compute() { List adj; - if (TsFges2.this.mode == Mode.heuristicSpeedup) { - adj = TsFges2.this.effectEdgesGraph.getAdjacentNodes(x); - } else if (TsFges2.this.mode == Mode.coverNoncolliders) { + if (TsFges.this.mode == Mode.heuristicSpeedup) { + adj = TsFges.this.effectEdgesGraph.getAdjacentNodes(x); + } else if (TsFges.this.mode == Mode.coverNoncolliders) { Set g = new HashSet<>(); - for (Node n : TsFges2.this.graph.getAdjacentNodes(x)) { - for (Node m : TsFges2.this.graph.getAdjacentNodes(n)) { - if (TsFges2.this.graph.isAdjacentTo(x, m)) { + for (Node n : TsFges.this.graph.getAdjacentNodes(x)) { + for (Node m : TsFges.this.graph.getAdjacentNodes(n)) { + if (TsFges.this.graph.isAdjacentTo(x, m)) { continue; } - if (TsFges2.this.graph.isDefCollider(m, n, x)) { + if (TsFges.this.graph.isDefCollider(m, n, x)) { continue; } @@ -1064,8 +1064,8 @@ protected Boolean compute() { } adj = new ArrayList<>(g); - } else if (TsFges2.this.mode == Mode.allowUnfaithfulness) { - HashSet D = new HashSet<>(TsFges2.this.graph.paths().getDconnectedVars(x, new ArrayList<>())); + } else if (TsFges.this.mode == Mode.allowUnfaithfulness) { + HashSet D = new HashSet<>(TsFges.this.graph.paths().getDconnectedVars(x, new ArrayList<>())); D.remove(x); adj = new ArrayList<>(D); } else { @@ -1073,13 +1073,13 @@ protected Boolean compute() { } for (Node w : adj) { - if (TsFges2.this.adjacencies != null && !(TsFges2.this.adjacencies.isAdjacentTo(w, x))) { + if (TsFges.this.adjacencies != null && !(TsFges.this.adjacencies.isAdjacentTo(w, x))) { continue; } if (w == x) continue; - if (!TsFges2.this.graph.isAdjacentTo(w, x)) { + if (!TsFges.this.graph.isAdjacentTo(w, x)) { clearArrow(w, x); calculateArrowsForward(w, x); } @@ -1204,7 +1204,7 @@ protected Boolean compute() { if (this.to - this.from <= this.chunk) { for (int _w = this.from; _w < this.to; _w++) { Node w = this.adj.get(_w); - Edge e = TsFges2.this.graph.getEdge(w, this.r); + Edge e = TsFges.this.graph.getEdge(w, this.r); if (e != null) { if (e.pointsTowards(this.r)) { @@ -1212,7 +1212,7 @@ protected Boolean compute() { clearArrow(this.r, w); calculateArrowsBackward(w, this.r); - } else if (Edges.isUndirectedEdge(TsFges2.this.graph.getEdge(w, this.r))) { + } else if (Edges.isUndirectedEdge(TsFges.this.graph.getEdge(w, this.r))) { clearArrow(w, this.r); clearArrow(this.r, w); @@ -1736,7 +1736,7 @@ private boolean existsUnblockedSemiDirectedPath(Node from, Node to, Set co } Edge edge = this.graph.getEdge(t, u); - Node c = TsFges2.traverseSemiDirected(t, edge); + Node c = TsFges.traverseSemiDirected(t, edge); if (c == null) continue; if (cond.contains(c)) continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java index 95c9663c17..a443a464ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java @@ -173,8 +173,6 @@ private double getLambda(int m0, int pn) { /** * Specialized scoring method for a single parent. Used to speed up the effect edges search. */ - - public ICovarianceMatrix getCovariances() { return covariances; } From 1647615ba2557a0bb978bafc3094537d92f05c5a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:21:49 -0400 Subject: [PATCH 122/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/SimpleDemoGA.java | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/SimpleDemoGA.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SimpleDemoGA.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SimpleDemoGA.java deleted file mode 100644 index 02e0668f0a..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SimpleDemoGA.java +++ /dev/null @@ -1,93 +0,0 @@ -package edu.cmu.tetrad.search; - - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import org.apache.commons.math3.util.FastMath; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.ForkJoinPool; - -import static edu.cmu.tetrad.util.RandomUtil.shuffle; - -class Individual implements Comparable { - - private final double fitness; - private final List genes; - private final TeyssierScorer scorer; - - public Individual(Score score, List genes) { - scorer = new TeyssierScorer(null, score); - - //Set genes randomly for each individual - this.genes = genes; - fitness = scorer.score(this.genes); - } - - //Calculate fitness - public double getFitness() { - return fitness; - } - - public int getLength() { - return genes.size(); - } - - public List getGenes() { - return new ArrayList<>(genes); - } - - @Override - public int compareTo(@NotNull Individual o) { - return Double.compare(o.getFitness(), getFitness()); - } - - public Graph getGraph(boolean cpdag) { - return scorer.getGraph(cpdag); - } -} - -//Population class -class Population { - - private final List vars; - private final Score score; - private final int numIndividuals; - private final ConcurrentSkipListSet individuals = new ConcurrentSkipListSet<>(); - - public Population(Score score, List vars, int numIndividuals) { - this.score = score; - this.vars = vars; - this.numIndividuals = numIndividuals; - } - - public void initializePopulation() { - for (int i = 0; i < numIndividuals; i++) { - List order = new ArrayList<>(vars); - shuffle(order); - individuals.add(new Individual(score, order)); - } - } - - public Individual getFittestIndividual() { - if (!individuals.isEmpty()) return individuals.first(); - else return null; - } - - //Calculate fitness of each individual - - public void add(Individual individual) { - individuals.add(individual); -// if (individuals.size() > numIndividuals) { -// individuals.remove(individuals.descendingIterator().next()); -// } - } - - public int getNumGenes() { - return vars.size(); - } -} \ No newline at end of file From 3f11a83f41841cb00966bd9b1c8f55a08b8c21c4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:22:51 -0400 Subject: [PATCH 123/464] Fixing documentation etc. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index cd0f5ea034..d414334745 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -204,7 +204,7 @@ public static Graph makeGraph(Matrix B, List variables) { * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair */ - public static PermutationMatrixPair strongestDiagonalByCols(Matrix W, double spineThrehold) { + public static PermutationMatrixPair strongestDiagonal(Matrix W, double spineThrehold) { List pairs = nRooks(W.transpose(), spineThrehold); if (pairs.isEmpty()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index a71fe3104f..15fa832ce0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -68,7 +68,7 @@ public Matrix fit(DataSet D) { * @return The estimated B Hat matrix. */ public Matrix fitW(Matrix W) { - PermutationMatrixPair bestPair = LingD.strongestDiagonalByCols(W, spineThreshold); + PermutationMatrixPair bestPair = LingD.strongestDiagonal(W, spineThreshold); return LingD.getScaledBHat(bestPair, bThreshold); } From 0685ea4bd9b363fa5bb20388345f6130ed839f4d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:28:39 -0400 Subject: [PATCH 124/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/CpcOrienter.java | 370 ------------------ .../edu/cmu/tetrad/search/FgesOrienter.java | 3 +- .../edu/cmu/tetrad/search/Reorienter.java | 46 --- 3 files changed, 1 insertion(+), 418 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcOrienter.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Reorienter.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcOrienter.java deleted file mode 100644 index 7a822690c4..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcOrienter.java +++ /dev/null @@ -1,370 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.TetradLogger; -import org.apache.commons.math3.util.FastMath; - -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * Reorients edges in the getModel graph as CPC would orient them. Basically, does a CPDAG search using CPC over the - * given (undirected) edges in the given graph. - * - * @author Joseph Ramsey (this version). - */ -public final class CpcOrienter implements Reorienter { - - /** - * The independence test used for the PC search. - */ - private final IndependenceTest independenceTest; - - /** - * Forbidden and required edges for the search. - */ - private Knowledge knowledge; - - /** - * The maximum number of nodes conditioned on in the search. - */ - private int depth = Integer.MAX_VALUE; - - /** - * The graph that's constructed during the search. - */ - private Graph graph; - - /** - * Elapsed time of last search. - */ - private long elapsedTime; - - /** - * Set of unshielded colliders from the triple orientation step. - */ - private Set colliderTriples; - - /** - * Set of unshielded noncolliders from the triple orientation step. - */ - private Set noncolliderTriples; - - /** - * Set of ambiguous unshielded triples. - */ - private Set ambiguousTriples; - - //=============================CONSTRUCTORS==========================// - - public CpcOrienter(IndependenceTest independenceTest, Knowledge knowledge) { - if (independenceTest == null) { - throw new NullPointerException(); - } - - if (knowledge == null) { - throw new NullPointerException(); - } - - this.independenceTest = independenceTest; - this.knowledge = knowledge; - } - - //==============================PUBLIC METHODS========================// - - private IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - public void setDepth(int depth) { - this.depth = depth; - } - - public long getElapsedTime() { - return this.elapsedTime; - } - - public Set getAmbiguousTriples() { - return new HashSet<>(this.ambiguousTriples); - } - - public Set getColliderTriples() { - return this.colliderTriples; - } - - public Set getNoncolliderTriples() { - return this.noncolliderTriples; - } - - /** - * Runs PC on just the given variable, all of which must be in the domain of the independence test. - */ - public void orient(Graph graph) { - TetradLogger.getInstance().log("info", "Starting CPC Orienter algorithm."); - TetradLogger.getInstance().log("info", "Independence test = " + this.independenceTest + "."); - long startTime = MillisecondTimes.timeMillis(); - this.ambiguousTriples = new HashSet<>(); - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); - - this.graph = graph; - Set edges = graph.getEdges(); - - for (Edge edge : edges) { - graph.removeEdge(edge); - graph.addEdge(Edges.undirectedEdge(edge.getNode1(), edge.getNode2())); - } - - SearchGraphUtils.pcOrientbk(this.knowledge, graph, graph.getNodes()); - orientUnshieldedTriples(this.knowledge, getIndependenceTest(), this.depth); - MeekRules meekRules = new MeekRules(); - meekRules.setKnowledge(this.knowledge); - meekRules.orientImplied(graph); - - TetradLogger.getInstance().log("graph", "\nReturning this graph: " + graph); - long endTime = MillisecondTimes.timeMillis(); - this.elapsedTime = endTime - startTime; - TetradLogger.getInstance().log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); - TetradLogger.getInstance().log("info", "Finishing CPC algorithm."); - logTriples(); - TetradLogger.getInstance().flush(); - - } - - private void logTriples() { - TetradLogger.getInstance().log("info", "\nCollider triples judged from sepsets:"); - - for (Triple triple : getColliderTriples()) { - TetradLogger.getInstance().log("collider", "Collider: " + triple); - } - - TetradLogger.getInstance().log("info", "\nNoncollider triples judged from sepsets:"); - - for (Triple triple : getNoncolliderTriples()) { - TetradLogger.getInstance().log("noncollider", "Noncollider: " + triple); - } - - TetradLogger.getInstance().log("info", "\nAmbiguous triples judged from sepsets (i.e. list of triples for which " + - "\nthere is ambiguous data about whether they are colliders or not):"); - - for (Triple triple : getAmbiguousTriples()) { - TetradLogger.getInstance().log("ambiguous", "Ambiguous: " + triple); - } - } - - -// public final Graph orientationForGraph(Dag trueGraph) { -// Graph graph = new EdgeListGraph(independenceTest.getVariable()); -// -// for (Edge edge : trueGraph.getEdges()) { -// Node nodeA = edge.getNode1(); -// Node nodeB = edge.getNode2(); -// -// Node _nodeA = independenceTest.getVariable(nodeA.getNode()); -// Node _nodeB = independenceTest.getVariable(nodeB.getNode()); -// -// graph.addUndirectedEdge(_nodeA, _nodeB); -// } -// -// SearchGraphUtils.pcOrientbk(knowledge, graph, graph.getNodes()); -// orientUnshieldedTriples(knowledge, getIndependenceTest(), depth); -// MeekRules meekRules = new MeekRules(); -// meekRules.setKnowledge(knowledge); -// meekRules.orientImplied(graph); -// -// return graph; -// } - - //==========================PRIVATE METHODS===========================// - - @SuppressWarnings("SameParameterValue") - private void orientUnshieldedTriples(Knowledge knowledge, - IndependenceTest test, int depth) { - TetradLogger.getInstance().log("info", "Starting Collider Orientation:"); - - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); - this.ambiguousTriples = new HashSet<>(); - - for (Node y : this.graph.getNodes()) { - List adjacentNodes = this.graph.getAdjacentNodes(y); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node x = adjacentNodes.get(combination[0]); - Node z = adjacentNodes.get(combination[1]); - - if (this.graph.isAdjacentTo(x, z)) { - continue; - } - - TripleType type = getTripleType(x, y, z, test, depth); - - System.out.println(new Triple(x, y, z) + " " + type); - - if (type == TripleType.COLLIDER) { - if (colliderAllowed(x, y, z, knowledge)) { - this.graph.setEndpoint(x, y, Endpoint.ARROW); - this.graph.setEndpoint(z, y, Endpoint.ARROW); - TetradLogger.getInstance().log("colliderOrientations", - SearchLogUtils.colliderOrientedMsg(x, y, z)); - } - - this.colliderTriples.add(new Triple(x, y, z)); - } else if (type == TripleType.AMBIGUOUS) { - Triple triple = new Triple(x, y, z); - this.ambiguousTriples.add(triple); - this.graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); - } else { - this.noncolliderTriples.add(new Triple(x, y, z)); - } - } - } - - TetradLogger.getInstance().log("info", "Finishing Collider Orientation."); - } - - private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return CpcOrienter.isArrowpointAllowed1(x, y, knowledge) && - CpcOrienter.isArrowpointAllowed1(z, y, knowledge); - } - - private TripleType getTripleType(Node x, Node y, Node z, - IndependenceTest test, int depth) { - boolean existsSepsetContainingY = false; - boolean existsSepsetNotContainingY = false; - - Set __nodes = new HashSet<>(this.graph.getAdjacentNodes(x)); - __nodes.remove(z); - - List _nodes = new LinkedList<>(__nodes); - TetradLogger.getInstance().log("adjacencies", - "Adjacents for " + x + "--" + y + "--" + z + " = " + _nodes); - - int _depth = depth; - if (_depth == -1) { - _depth = Integer.MAX_VALUE; - } - _depth = FastMath.min(_depth, _nodes.size()); - - for (int d = 0; d <= _depth; d++) { - ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d); - int[] choice; - - while ((choice = cg.next()) != null) { - List condSet = CpcOrienter.asList(choice, _nodes); - - if (test.checkIndependence(x, z, condSet).independent()) { - if (condSet.contains(y)) { - existsSepsetContainingY = true; - } else { - existsSepsetNotContainingY = true; - } - } - } - } - - __nodes = new HashSet<>(this.graph.getAdjacentNodes(z)); - __nodes.remove(x); - - _nodes = new LinkedList<>(__nodes); - TetradLogger.getInstance().log("adjacencies", - "Adjacents for " + x + "--" + y + "--" + z + " = " + _nodes); - - _depth = depth; - if (_depth == -1) { - _depth = Integer.MAX_VALUE; - } - _depth = FastMath.min(_depth, _nodes.size()); - - for (int d = 0; d <= _depth; d++) { - ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d); - int[] choice; - - while ((choice = cg.next()) != null) { - List condSet = CpcOrienter.asList(choice, _nodes); - - if (test.checkIndependence(x, z, condSet).independent()) { - if (condSet.contains(y)) { - existsSepsetContainingY = true; - } else { - existsSepsetNotContainingY = true; - } - } - } - } - - if (existsSepsetContainingY == existsSepsetNotContainingY) { - return TripleType.AMBIGUOUS; - } else if (!existsSepsetNotContainingY) { - return TripleType.NONCOLLIDER; - } else { - return TripleType.COLLIDER; - } - } - - private static List asList(int[] indices, List nodes) { - List list = new LinkedList<>(); - - for (int i : indices) { - list.add(nodes.get(i)); - } - - return list; - } - - private static boolean isArrowpointAllowed1(Node from, Node to, - Knowledge knowledge) { - if (knowledge == null) { - return true; - } - - return !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - - //==============================CLASSES==============================// - - private enum TripleType { - COLLIDER, NONCOLLIDER, AMBIGUOUS - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java index a52891963f..a93f3b3a75 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java @@ -52,7 +52,7 @@ * of the edges in the oriented graph * @author AJ Sedgewick, 5/2015 */ -public final class FgesOrienter implements GraphSearch, GraphScorer, Reorienter { +public final class FgesOrienter implements GraphSearch, GraphScorer { /** * The covariance matrix for continuous data. @@ -205,7 +205,6 @@ public FgesOrienter(DataSet dataSet) { } // This will "orient" graph - @Override public void orient(Graph graph) { this.graphToOrient = new EdgeListGraph(graph); this.graphToOrient = GraphUtils.undirectedGraph(this.graphToOrient); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Reorienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Reorienter.java deleted file mode 100644 index 9983d792bd..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Reorienter.java +++ /dev/null @@ -1,46 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.Graph; - -/** - * Reorients all or part of the given graph. - * - * @author Joseph Ramsey - */ -public interface Reorienter { - - /** - * Sets the knowledge. - */ - void setKnowledge(Knowledge knowledge); - - /** - * Globally reorients the graph. - */ - void orient(Graph graph); -} - - - From 17d29ffe8a7f703f221379f279a971d5ffe3af4f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:38:28 -0400 Subject: [PATCH 125/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Ccd.java | 65 ++++++++----------- 1 file changed, 27 insertions(+), 38 deletions(-) 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 3fe43781bb..3a96feba15 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 @@ -21,7 +21,6 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.SublistGenerator; @@ -30,22 +29,25 @@ import java.util.*; /** - * This class provides the data structures and methods for carrying out the Cyclic Causal Discovery algorithm (CCD) + *

This class provides the data structures and methods for carrying out the Cyclic Causal Discovery algorithm (CCD) * described by Thomas Richardson and Peter Spirtes in Chapter 7 of Computation, Causation, and Discovery by Glymour and * Cooper eds. The comments that appear below are keyed to the algorithm specification on pp. 269-271. The search * method returns an instance of a Graph but it also constructs two lists of node triples which represent the underlines - * and dotted underlines that the algorithm discovers. + * and dotted underlines that the algorithm discovers.

* * @author Frank C. Wimberly * @author Joseph Ramsey */ public final class Ccd implements GraphSearch { private final IndependenceTest independenceTest; - private int depth = -1; - private Knowledge knowledge; private final List nodes; private boolean applyR1; + /** + * Construct a CCD algorithm with the given independence test. + * @param test The test to be used. + * @see IndependenceTest + */ public Ccd(IndependenceTest test) { if (test == null) throw new NullPointerException("Test is not provided"); this.independenceTest = test; @@ -83,6 +85,26 @@ public Graph search() { return psi; } + /** + * Returns true iff the R1 rule should be applied. + * + * @return True if the case. + */ + public boolean isApplyR1() { + return this.applyR1; + } + + /** + * Sets whether the R1 rule should be applied. + * + * @param applyR1 True if the case. + */ + public void setApplyR1(boolean applyR1) { + this.applyR1 = applyR1; + } + + //======================================== PRIVATE METHODS ====================================// + private void orientAwayFromArrow(Graph graph) { for (Edge edge : graph.getEdges()) { Node n1 = edge.getNode1(); @@ -98,31 +120,6 @@ private void orientAwayFromArrow(Graph graph) { } } - public Knowledge getKnowledge() { - return this.knowledge; - } - - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - this.depth = depth; - } - - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException(); - } - this.knowledge = knowledge; - } - - public long getElapsedTime() { - return 0; - } - - //======================================== PRIVATE METHODS ====================================// - private void stepB(Graph graph) { Map colliders = new HashMap<>(); Map noncolliders = new HashMap<>(); @@ -489,14 +486,6 @@ private boolean orientAwayFromArrowVisit(Node a, Node b, Node c, Graph graph) { return true; } - - public boolean isApplyR1() { - return this.applyR1; - } - - public void setApplyR1(boolean applyR1) { - this.applyR1 = applyR1; - } } From d60268fe069ff28e6113335a81318fddd09c92ec Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:40:15 -0400 Subject: [PATCH 126/464] Fixing documentation etc. --- .../algorithm/multi/CcdMaxConcatenated.java | 151 ----- .../algorithm/oracle/pag/Ccd.java | 1 - .../algorithm/oracle/pag/CcdMax.java | 121 ---- .../java/edu/cmu/tetrad/search/CcdMax.java | 624 ------------------ 4 files changed, 897 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/CcdMaxConcatenated.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/CcdMaxConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/CcdMaxConcatenated.java deleted file mode 100644 index 09a7513dba..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/CcdMaxConcatenated.java +++ /dev/null @@ -1,151 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.multi; - -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.IndependenceTest; -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; - -/** - * 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 CcdMaxConcatenated implements MultiDataSetAlgorithm, HasKnowledge { - static final long serialVersionUID = 23L; - private Knowledge knowledge = new Knowledge(); - private final IndependenceWrapper test; - - public CcdMaxConcatenated(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); - - IndependenceTest test = this.test.getTest(dataSet, parameters); - edu.cmu.tetrad.search.CcdMax search = new edu.cmu.tetrad.search.CcdMax(test); - search.setDoColliderOrientations(parameters.getBoolean(Params.DO_COLLIDER_ORIENTATION)); - 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.setApplyOrientAwayFromCollider(parameters.getBoolean(Params.APPLY_R1)); - search.setUseOrientTowardDConnections(parameters.getBoolean(Params.ORIENT_TOWARD_DCONNECTIONS)); - return search.search(); - } else { - CcdMaxConcatenated algorithm = new CcdMaxConcatenated(this.test); - - List dataSets = new ArrayList<>(); - - for (DataModel dataModel : dataModels) { - dataSets.add((DataSet) dataModel); - } - GeneralResamplingTest search = new GeneralResamplingTest( - dataSets, - 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.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 { - CcdMaxConcatenated algorithm = new CcdMaxConcatenated(this.test); - - List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); - GeneralResamplingTest search = new GeneralResamplingTest(dataSets, - 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.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 "CCD-Max (Cyclic Discovery Search Max), concatenting datasets, using " + this.test.getDescription(); - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - List parameters = this.test.getParameters(); - parameters.add(Params.DEPTH); - parameters.add(Params.ORIENT_VISIBLE_FEEDBACK_LOOPS); - parameters.add(Params.DO_COLLIDER_ORIENTATION); - 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/oracle/pag/Ccd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Ccd.java index f4884808f3..cd1e34408f 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 @@ -49,7 +49,6 @@ public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { edu.cmu.tetrad.search.Ccd search = new edu.cmu.tetrad.search.Ccd( test.getTest(dataSet, parameters)); - search.setDepth(parameters.getInt(Params.DEPTH)); search.setApplyR1(parameters.getBoolean(Params.APPLY_R1)); return search.search(); 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/CcdMax.java deleted file mode 100644 index ac6a2712db..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java +++ /dev/null @@ -1,121 +0,0 @@ -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; -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.IndependenceTest; -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.LinkedList; -import java.util.List; - -/** - * FGES (the heuristic version). - * - * @author jdramsey - */ -/*@AlgorithmDescription( - name = "CCD_MAX", - algType = AlgType.forbid_latent_common_causes, - oracleType = OracleType.Test -)*/ -@Bootstrapping -public class CcdMax 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) { - this.test = test; - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - IndependenceTest test = this.test.getTest(dataSet, parameters); - edu.cmu.tetrad.search.CcdMax search = new edu.cmu.tetrad.search.CcdMax(test); - search.setDoColliderOrientations(parameters.getBoolean(Params.DO_COLLIDER_ORIENTATION)); - 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.setApplyOrientAwayFromCollider(parameters.getBoolean(Params.APPLY_R1)); - search.setUseOrientTowardDConnections(parameters.getBoolean(Params.ORIENT_TOWARD_DCONNECTIONS)); - return search.search(); - } else { - CcdMax algorithm = new CcdMax(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)); - search.setKnowledge(this.knowledge); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - Graph graph = search.search(); - this.bootstrapGraphs = search.getGraphs(); - return graph; - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "CCD-Max (Cyclic Discovery Search Max) using " + this.test.getDescription(); - } - - @Override - public DataType getDataType() { - return this.test.getDataType(); - } - - @Override - public List getParameters() { - List parameters = new LinkedList<>(); - if (this.test != null) { - parameters.addAll(this.test.getParameters()); - } - parameters.add(Params.DEPTH); - parameters.add(Params.ORIENT_VISIBLE_FEEDBACK_LOOPS); - parameters.add(Params.DO_COLLIDER_ORIENTATION); - 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.VERBOSE); - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - 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/search/CcdMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java deleted file mode 100644 index ea73280c5b..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java +++ /dev/null @@ -1,624 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.TetradLogger; -import org.apache.commons.math3.util.FastMath; - -import java.util.*; - -/** - * This is an optimization of the CCD (Cyclic Causal Discovery) algorithm by Thomas Richardson. - * - * @author Joseph Ramsey - */ -public final class CcdMax implements GraphSearch { - private final IndependenceTest independenceTest; - private int depth = -1; - private boolean applyOrientAwayFromCollider; - private long elapsed; - private Knowledge knowledge = new Knowledge(); - private boolean useHeuristic = true; - private int maxPathLength = 3; - private boolean useOrientTowardDConnections = true; - private boolean orientConcurrentFeedbackLoops = true; - private boolean doColliderOrientations = true; - private boolean collapseTiers; - private SepsetMap sepsetMap; - - public CcdMax(IndependenceTest test) { - if (test == null) throw new NullPointerException(); - this.independenceTest = test; - } - - //======================================== PUBLIC METHODS ====================================// - - public Graph search() { - - System.out.println("FAS"); - Graph graph = fastAdjacencySearch(); - - System.out.println("Orienting from background knowledge"); - - for (Edge edge : graph.getEdges()) { - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - if (this.knowledge.isForbidden(y.getName(), x.getName()) || this.knowledge.isRequired(x.getName(), y.getName())) { - graph.removeEdge(x, y); - graph.addDirectedEdge(x, y); - } else if (this.knowledge.isForbidden(x.getName(), y.getName()) || this.knowledge.isRequired(y.getName(), x.getName())) { - graph.removeEdge(y, x); - graph.addDirectedEdge(y, x); - } - } - - System.out.println("Bishop's hat"); - - if (this.orientConcurrentFeedbackLoops) { - orientTwoShieldConstructs(graph); - } - - System.out.println("Max P collider orientation"); - - if (this.doColliderOrientations) { - OrientCollidersMaxP orientCollidersMaxP = new OrientCollidersMaxP(this.independenceTest); - orientCollidersMaxP.setUseHeuristic(this.useHeuristic); - orientCollidersMaxP.setMaxPathLength(this.maxPathLength); - orientCollidersMaxP.setKnowledge(this.knowledge); - orientCollidersMaxP.orient(graph); - } - - System.out.println("Orient away from collider"); - - if (this.applyOrientAwayFromCollider) { - orientAwayFromArrow(graph); - } - - System.out.println("Toward D-connection"); - - if (this.useOrientTowardDConnections) { - orientTowardDConnection(graph); - } - - System.out.println("Done"); - - if (this.collapseTiers) { - return collapseGraph(graph); - } else { - return graph; - } - } - - private Graph collapseGraph(Graph graph) { - List nodes = new ArrayList<>(); - - for (String n : this.independenceTest.getVariableNames()) { - String[] s = n.split(":"); - - if (s.length == 1) { - Node x = this.independenceTest.getVariable(s[0]); - nodes.add(x); - } - } - - Graph _graph = new EdgeListGraph(nodes); - - for (Edge edge : graph.getEdges()) { - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - String[] sx = x.getName().split(":"); - String[] sy = y.getName().split(":"); - - int lagx = sx.length == 1 ? 0 : Integer.parseInt(sx[1]); - int lagy = sy.length == 1 ? 0 : Integer.parseInt(sy[1]); - - int maxInto = this.knowledge.getNumTiers() - 1; - - if (!((!edge.pointsTowards(x) && lagy < maxInto) - || (!edge.pointsTowards(y) && lagx < maxInto))) continue; - - String xName = sx[0]; - String yName = sy[0]; - - Node xx = this.independenceTest.getVariable(xName); - Node yy = this.independenceTest.getVariable(yName); - - if (xx == yy) continue; - - Edge _edge = new Edge(xx, yy, edge.getEndpoint1(), edge.getEndpoint2()); - - if (!_graph.containsEdge(_edge)) { - _graph.addEdge(_edge); - } - - Edge undir = Edges.undirectedEdge(xx, yy); - - if (_graph.getEdges(xx, yy).size() > 1 && _graph.containsEdge(undir)) { - _graph.removeEdge(undir); - } - } - - return _graph; - } - - /** - * @return The depth of search for the Fast Adjacency Search. - */ - public int getDepth() { - return this.depth; - } - - /** - * @param depth The depth of search for the Fast Adjacency Search. - */ - public void setDepth(int depth) { - this.depth = depth; - } - - /** - * @return The elapsed time in milliseconds. - */ - public long getElapsedTime() { - return this.elapsed; - } - - /** - * @param applyOrientAwayFromCollider True if the orient away from collider rule should be - * applied. - */ - public void setApplyOrientAwayFromCollider(boolean applyOrientAwayFromCollider) { - this.applyOrientAwayFromCollider = applyOrientAwayFromCollider; - } - - //======================================== PRIVATE METHODS ====================================// - - private Graph fastAdjacencySearch() { - long start = MillisecondTimes.timeMillis(); - - Fas fas = new Fas(this.independenceTest); - fas.setStable(true); - fas.setDepth(getDepth()); - fas.setKnowledge(this.knowledge); - fas.setVerbose(false); - - Graph graph = fas.search(); - - if (this.useOrientTowardDConnections) { - this.sepsetMap = fas.getSepsets(); - } - - long stop = MillisecondTimes.timeMillis(); - this.elapsed = stop - start; - - return new EdgeListGraph(graph); - } - - // Orient feedback loops and a few extra directed edges. - private void orientTwoShieldConstructs(Graph graph) { - TetradLogger.getInstance().log("info", "\nStep E"); - - for (Node c : graph.getNodes()) { - List adj = graph.getAdjacentNodes(c); - - for (int i = 0; i < adj.size(); i++) { - Node a = adj.get(i); - - for (int j = i + 1; j < adj.size(); j++) { - Node b = adj.get(j); - if (a == b) continue; - if (graph.isAdjacentTo(a, b)) continue; - - for (Node d : adj) { - if (d == a || d == b) continue; - - if (graph.isAdjacentTo(d, a) && graph.isAdjacentTo(d, b)) { - if (sepset(graph, a, b, set(), set(c, d)) != null) { - if ((graph.getEdges().size() == 2 || Edges.isDirectedEdge(graph.getEdge(c, d)))) { - continue; - } - - if ( - graph.getEdge(a, c).pointsTowards(a) - || graph.getEdge(a, d).pointsTowards(a) - || graph.getEdge(b, c).pointsTowards(b) - || graph.getEdge(b, d).pointsTowards(b) - ) { - continue; - } - - if (sepset(graph, a, b, set(c, d), set()) != null) { - orientCollider(graph, a, c, b); - orientCollider(graph, a, d, b); - addFeedback(graph, c, d); - } - } - } - } - } - } - } - } - - private void orientTowardDConnection(Graph graph) { - - EDGE: - for (Edge edge : graph.getEdges()) { - if (!Edges.isUndirectedEdge(edge)) continue; - - Set surround = new HashSet<>(); - Node b = edge.getNode1(); - Node c = edge.getNode2(); - surround.add(b); - - for (int i = 1; i < 3; i++) { - for (Node z : new HashSet<>(surround)) { - surround.addAll(graph.getAdjacentNodes(z)); - } - } - - surround.remove(b); - surround.remove(c); - graph.getAdjacentNodes(b).forEach(surround::remove); - graph.getAdjacentNodes(c).forEach(surround::remove); - boolean orient = false; - boolean agree = true; - - for (Node a : surround) { - - List sepsetax = maxPSepset(a, b, graph).getCond(); - List sepsetay = maxPSepset(a, c, graph).getCond(); - - if (sepsetax == null) continue; - if (sepsetay == null) continue; - - if (!sepsetax.equals(sepsetay)) { - if (sepsetax.containsAll(sepsetay)) { - orient = true; - } else { - agree = false; - } - } - } - - if (orient && agree) { - addDirectedEdge(graph, c, b); - } - - for (Node a : surround) { - if (b == a) continue; - if (c == a) continue; - if (graph.getAdjacentNodes(b).contains(a)) continue; - if (graph.getAdjacentNodes(c).contains(a)) continue; - - List sepsetax = this.sepsetMap.get(a, b); - List sepsetay = this.sepsetMap.get(a, c); - - if (sepsetax == null) continue; - if (sepsetay == null) continue; - if (sepsetay.contains(b)) continue; - - if (!sepsetay.containsAll(sepsetax)) { - if (!this.independenceTest.checkIndependence(a, b, sepsetay).independent()) { - addDirectedEdge(graph, c, b); - continue EDGE; - } - } - } - } - } - - private void addDirectedEdge(Graph graph, Node a, Node b) { - graph.removeEdges(a, b); - graph.addDirectedEdge(a, b); - orientAwayFromArrow(graph, a, b); - } - - private void addFeedback(Graph graph, Node a, Node b) { - graph.removeEdges(a, b); - graph.addEdge(Edges.directedEdge(a, b)); - graph.addEdge(Edges.directedEdge(b, a)); - } - - private void orientCollider(Graph graph, Node a, Node b, Node c) { - if (wouldCreateBadCollider(graph, a, b)) return; - if (wouldCreateBadCollider(graph, c, b)) return; - if (graph.getEdges(a, b).size() > 1) return; - if (graph.getEdges(b, c).size() > 1) return; - - if (this.knowledge.isForbidden(a.getName(), b.getName())) return; - if (this.knowledge.isForbidden(c.getName(), b.getName())) return; - - graph.removeEdge(a, b); - graph.removeEdge(c, b); - graph.addDirectedEdge(a, b); - graph.addDirectedEdge(c, b); - } - - private void orientAwayFromArrow(Graph graph, Node a, Node b) { - if (!this.applyOrientAwayFromCollider) return; - - for (Node c : graph.getAdjacentNodes(b)) { - if (c == a) continue; - orientAwayFromArrowVisit(a, b, c, graph); - } - } - - private boolean wouldCreateBadCollider(Graph graph, Node x, Node y) { - for (Node z : graph.getAdjacentNodes(y)) { - if (x == z) continue; - - if (graph.isDefCollider(x, y, z)) { - return true; - } - - } - - return false; - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - public void setUseHeuristic(boolean useHeuristic) { - this.useHeuristic = useHeuristic; - } - - public int getMaxPathLength() { - return this.maxPathLength; - } - - public void setMaxPathLength(int maxPathLength) { - this.maxPathLength = maxPathLength; - } - - public void setUseOrientTowardDConnections(boolean useOrientTowardDConnections) { - this.useOrientTowardDConnections = useOrientTowardDConnections; - } - - public void setOrientConcurrentFeedbackLoops(boolean orientConcurrentFeedbackLoops) { - this.orientConcurrentFeedbackLoops = orientConcurrentFeedbackLoops; - } - - public void setDoColliderOrientations(boolean doColliderOrientations) { - this.doColliderOrientations = doColliderOrientations; - } - - public void setCollapseTiers(boolean collapseTiers) { - this.collapseTiers = collapseTiers; - } - - private static class Pair { - private final List cond; - private final double score; - - Pair(List cond, double score) { - this.cond = cond; - this.score = score; - } - - public List getCond() { - return this.cond; - } - - public double getScore() { - return this.score; - } - - } - - private Pair maxPSepset(Node i, Node k, Graph graph) { - double _p = Double.POSITIVE_INFINITY; - List _v = null; - - List adji = graph.getAdjacentNodes(i); - List adjk = graph.getAdjacentNodes(k); - adji.remove(k); - adjk.remove(i); - - for (int d = 0; d <= FastMath.min((this.depth == -1 ? 1000 : this.depth), FastMath.max(adji.size(), adjk.size())); d++) { - if (d <= adji.size()) { - ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d); - int[] choice; - - while ((choice = gen.next()) != null) { - List v2 = GraphUtils.asList(choice, adji); - - if (isForbidden(i, k, v2)) continue; - - try { - getIndependenceTest().checkIndependence(i, k, v2); - double p2 = getIndependenceTest().getScore(); - - if (p2 < _p) { - _p = p2; - _v = v2; - } - } catch (Exception e) { - e.printStackTrace(); - return new Pair(null, Double.POSITIVE_INFINITY); - } - } - } - - if (d <= adjk.size()) { - ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d); - int[] choice; - - while ((choice = gen.next()) != null) { - List v2 = GraphUtils.asList(choice, adjk); - - try { - getIndependenceTest().checkIndependence(i, k, v2); - double p2 = getIndependenceTest().getScore(); - - if (p2 < _p) { - _p = p2; - _v = v2; - } - } catch (Exception e) { - e.printStackTrace(); - return new Pair(null, Double.POSITIVE_INFINITY); - } - } - } - } - - return new Pair(_v, _p); - } - - private boolean isForbidden(Node i, Node k, List v) { - for (Node w : v) { - if (this.knowledge.isForbidden(w.getName(), i.getName())) { - return true; - } - - if (this.knowledge.isForbidden(w.getName(), k.getName())) { - return true; - } - } - - return false; - } - - // Returns a sepset containing the nodes in 'containing' but not the nodes in 'notContaining', or - // null if there is no such sepset. - private List sepset(Graph graph, Node a, Node c, Set containing, Set notContaining) { - List adj = graph.getAdjacentNodes(a); - adj.addAll(graph.getAdjacentNodes(c)); - adj.remove(c); - adj.remove(a); - - for (int d = 0; d <= FastMath.min((this.depth == -1 ? 1000 : this.depth), adj.size()); d++) { - ChoiceGenerator gen = new ChoiceGenerator(adj.size(), d); - int[] choice; - - while ((choice = gen.next()) != null) { - Set v2 = GraphUtils.asSet(choice, adj); - v2.addAll(containing); - v2.removeAll(notContaining); - v2.remove(a); - v2.remove(c); - - if (!isForbidden(a, c, new ArrayList<>(v2))) { - getIndependenceTest().checkIndependence(a, c, new ArrayList<>(v2)); - double p2 = getIndependenceTest().getScore(); - - if (p2 < 0) { - return new ArrayList<>(v2); - } - } - } - } - - return null; - } - - private Set set(Node... n) { - Set S = new HashSet<>(); - Collections.addAll(S, n); - return S; - } - - private IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - private void orientAwayFromArrow(Graph graph) { - for (Edge edge : graph.getEdges()) { - Node n1 = edge.getNode1(); - Node n2 = edge.getNode2(); - - edge = graph.getEdge(n1, n2); - - if (edge.pointsTowards(n1)) { - orientAwayFromArrow(graph, n2, n1); - } else if (edge.pointsTowards(n2)) { - orientAwayFromArrow(graph, n1, n2); - } - } - } - - private void orientAwayFromArrowVisit(Node a, Node b, Node c, Graph graph) { - - // This shouldn't happen--a--b--c should be shielded. Checking just in case... - if (graph.getEdges(b, c).size() > 1) { - return; - } - - if (!Edges.isUndirectedEdge(graph.getEdge(b, c))) { - return; - } - - if (graph.isAdjacentTo(a, c)) { - return; - } - - if (this.knowledge.isForbidden(b.getName(), c.getName())) { - return; - } - - if (wouldCreateBadCollider(graph, b, c)) { - return; - } - - addDirectedEdge(graph, b, c); - - List undirectedEdges = new ArrayList<>(); - - for (Node d : graph.getAdjacentNodes(c)) { - if (d == b) continue; - Edge e = graph.getEdge(c, d); - if (Edges.isUndirectedEdge(e)) undirectedEdges.add(e); - } - - for (Node d : graph.getAdjacentNodes(c)) { - if (d == b) continue; - orientAwayFromArrowVisit(b, c, d, graph); - } - - for (Edge e : undirectedEdges) { - Node d = Edges.traverse(c, e); - Edge f = graph.getEdge(c, d); - - if (!f.pointsTowards(d)) { - break; - } - } - - } -} - - - - - From 54b92ee5df92e666298b842dffbf5f0a44b1ee03 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:48:57 -0400 Subject: [PATCH 127/464] Fixing documentation etc. --- .../algcomparison/algorithm/cluster/Bpc.java | 1 - .../cmu/tetrad/search/BuildPureClusters.java | 154 ++++++++---------- 2 files changed, 71 insertions(+), 84 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index 9bd5531b06..08d117ea48 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -53,7 +53,6 @@ public Graph search(DataModel dataSet, Parameters parameters) { } BuildPureClusters bpc = new BuildPureClusters(cov, alpha, testType); - bpc.setVerbose(parameters.getBoolean(Params.VERBOSE)); if (parameters.getInt(Params.CHECK_TYPE) == 1) { bpc.setCheckType(ClusterSignificance.CheckType.Significance); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index 70642705d5..dbf067adf7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -83,10 +83,8 @@ public final class BuildPureClusters { private IndependenceTest independenceTest; private DataSet dataSet; private double alpha; - private boolean verbose; private ClusterSignificance.CheckType checkType = ClusterSignificance.CheckType.Clique; - //**************************** INITIALIZATION ***********************************/ /** @@ -102,16 +100,6 @@ public BuildPureClusters(ICovarianceMatrix covarianceMatrix, double alpha, initAlgorithm(alpha, sigTestType); } - public BuildPureClusters(CovarianceMatrix covarianceMatrix, double alpha, - TestType sigTestType) { - if (covarianceMatrix == null) { - throw new IllegalArgumentException("Covariance matrix cannot be null."); - } - - this.covarianceMatrix = covarianceMatrix; - initAlgorithm(alpha, sigTestType); - } - public BuildPureClusters(DataSet dataSet, double alpha, TestType sigTestType) { if (dataSet.isContinuous()) { this.dataSet = dataSet; @@ -123,50 +111,6 @@ public BuildPureClusters(DataSet dataSet, double alpha, TestType sigTestType) { } } - private void initAlgorithm(double alpha, TestType sigTestType) { - - // Check for missing values. - if (getCovarianceMatrix() != null && DataUtils.containsMissingValue(getCovarianceMatrix().getMatrix())) { - throw new IllegalArgumentException( - "Please remove or impute missing values first."); - } - - this.alpha = alpha; - - this.outputMessage = true; - this.sigTestType = sigTestType; - this.scoreTestMode = (this.sigTestType == TestType.DISCRETE || - this.sigTestType == TestType.GAUSSIAN_FACTOR); - - if (sigTestType == TestType.DISCRETE) { - this.numVariables = this.dataSet.getNumColumns(); - this.independenceTest = new IndTestGSquare(this.dataSet, alpha); - this.tetradTest = new DiscreteTetradTest(this.dataSet, alpha); - } else { - assert getCovarianceMatrix() != null; - this.numVariables = getCovarianceMatrix().getSize(); - this.independenceTest = new IndTestFisherZ(getCovarianceMatrix(), .1); - TestType type; - - if (sigTestType == TestType.TETRAD_WISHART || sigTestType == TestType.TETRAD_DELTA - || sigTestType == TestType.GAUSSIAN_FACTOR) { - type = sigTestType; - } else { - throw new IllegalArgumentException("Expecting TETRAD_WISHART, TETRAD_DELTA, or GAUSSIAN FACTOR " + - sigTestType); - } - - if (this.dataSet != null) { - this.tetradTest = new ContinuousTetradTest(this.dataSet, type, alpha); - } else { - this.tetradTest = new ContinuousTetradTest(getCovarianceMatrix(), type, alpha); - } - } - this.labels = new int[numVariables()]; - for (int i = 0; i < numVariables(); i++) { - this.labels[i] = i + 1; - } - } /** * @return the result search graph, or null if there is no model. @@ -219,6 +163,77 @@ public Graph search() { return graph; } + /** + * Returns the wrapped covariance matrix. + */ + public ICovarianceMatrix getCovarianceMatrix() { + return this.covarianceMatrix; + } + + /** + * Sets the cluster significance type. + * @param checkType This type + * @see ClusterSignificance + */ + public void setCheckType(ClusterSignificance.CheckType checkType) { + this.checkType = checkType; + } + + // PRIVATE METHODS + + private IndependenceTest getIndependenceTest() { + return this.independenceTest; + } + + private int numVariables() { + return this.numVariables; + } + + private void initAlgorithm(double alpha, TestType sigTestType) { + + // Check for missing values. + if (getCovarianceMatrix() != null && DataUtils.containsMissingValue(getCovarianceMatrix().getMatrix())) { + throw new IllegalArgumentException( + "Please remove or impute missing values first."); + } + + this.alpha = alpha; + + this.outputMessage = true; + this.sigTestType = sigTestType; + this.scoreTestMode = (this.sigTestType == TestType.DISCRETE || + this.sigTestType == TestType.GAUSSIAN_FACTOR); + + if (sigTestType == TestType.DISCRETE) { + this.numVariables = this.dataSet.getNumColumns(); + this.independenceTest = new IndTestGSquare(this.dataSet, alpha); + this.tetradTest = new DiscreteTetradTest(this.dataSet, alpha); + } else { + assert getCovarianceMatrix() != null; + this.numVariables = getCovarianceMatrix().getSize(); + this.independenceTest = new IndTestFisherZ(getCovarianceMatrix(), .1); + TestType type; + + if (sigTestType == TestType.TETRAD_WISHART || sigTestType == TestType.TETRAD_DELTA + || sigTestType == TestType.GAUSSIAN_FACTOR) { + type = sigTestType; + } else { + throw new IllegalArgumentException("Expecting TETRAD_WISHART, TETRAD_DELTA, or GAUSSIAN FACTOR " + + sigTestType); + } + + if (this.dataSet != null) { + this.tetradTest = new ContinuousTetradTest(this.dataSet, type, alpha); + } else { + this.tetradTest = new ContinuousTetradTest(getCovarianceMatrix(), type, alpha); + } + } + this.labels = new int[numVariables()]; + for (int i = 0; i < numVariables(); i++) { + this.labels[i] = i + 1; + } + } + /** * @return the converted search graph, or null if there is no model. */ @@ -1847,33 +1862,6 @@ private List purify(List> actualClusterings, List clus return new ArrayList<>(); } - - /** - * Data storage - */ - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } - - public int numVariables() { - return this.numVariables; - } - - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setCheckType(ClusterSignificance.CheckType checkType) { - this.checkType = checkType; - } } From 21d01010c60b7877ca3d201599bb9ebf62231664 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:50:59 -0400 Subject: [PATCH 128/464] Fixing documentation etc. --- .../algcomparison/algorithm/cluster/Bpc.java | 14 +------------- .../edu/cmu/tetrad/search/BuildPureClusters.java | 2 -- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index 08d117ea48..b94f104b8c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -29,10 +29,9 @@ algoType = AlgType.search_for_structure_over_latents ) @Bootstrapping -public class Bpc implements Algorithm, HasKnowledge, ClusterAlgorithm { +public class Bpc implements Algorithm, ClusterAlgorithm { static final long serialVersionUID = 23L; - private Knowledge knowledge = new Knowledge(); public Bpc() { } @@ -111,7 +110,6 @@ public Graph search(DataModel dataSet, Parameters parameters) { 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(); @@ -145,14 +143,4 @@ public List getParameters() { 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/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index dbf067adf7..4bb5b01dc0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -37,8 +37,6 @@ * The output is only the purified model. Future versions may include options to visualize the * measurement pattern in the GUI (it shows up in the console window, though.) *

- * No background knowledge is allowed yet. Future versions of this algorithm will include it. - *

* References: *

* Silva, R.; Scheines, R.; Spirtes, P.; Glymour, C. (2003). "Learning measurement models". From 629a6bd6d91c6ac333238955e235397e2859f896 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 19:56:02 -0400 Subject: [PATCH 129/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Cefs.java | 723 ------------------ 1 file changed, 723 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cefs.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cefs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cefs.java deleted file mode 100644 index 27b696b079..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cefs.java +++ /dev/null @@ -1,723 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.NumberFormatUtil; -import edu.cmu.tetrad.util.TetradLogger; -import org.apache.commons.math3.util.FastMath; - -import java.text.NumberFormat; -import java.util.*; - -/** - * Searches for a CPDAG representing all of the Markov blankets for a given target T consistent with the given - * independence information. This CPDAG may be used to generate the actual list of DAG's that might be Markov - * blankets. Note that this code has been converted to be consistent with the CPC algorithm. - * - * @author Joseph Ramsey - */ -public final class Cefs { - - /** - * The independence test used to perform the search. - */ - private final IndependenceTest test; - - /** - * The list of variables being searched over. Must contain the target. - */ - private final List variables; - - /** - * The target variable. - */ - private Node target; - - /** - * The depth to which independence tests should be performed--i.e. the maximum number of conditioning variables for - * any independence test. - */ - private final int depth; - - /** - * The CPDAG output by the most recent search. This is saved in case the user wants to generate the list of MB - * DAGs. - */ - private Graph resultGraph; - - /** - * A count of the number of independence tests performed in the course of the most recent search. - */ - private long numIndependenceTests; - - /** - * Information to help understand what part of the search is taking the most time. - */ - private int[] maxRemainingAtDepth; - - /** - * The set of nodes that edges should not be drawn to in the addDepthZeroAssociates method. - */ - private Set visited; - - /** - * Elapsed time for the last run of the algorithm. - */ - private long elapsedTime; - - /** - * The true graph, if known. If this is provided, notes will be printed out for edges removed that are in the true - * Markov blanket. - */ - private final Dag trueMb = null; - - /** - * Knowledge. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * Set of unshielded colliders from the triple orientation step. - */ - private Set colliderTriples; - - /** - * Set of unshielded noncolliders from the triple orientation step. - */ - private Set noncolliderTriples; - - /** - * Set of ambiguous unshielded triples. - */ - private Set ambiguousTriples; - - /** - * The most recently returned graph. - */ - private Graph graph; - - - /** - * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large - * graphs). - */ - private boolean aggressivelyPreventCycles; - - /** - * The logger for this class. The config needs to be set. - */ - private final TetradLogger logger = TetradLogger.getInstance(); - - - //==============================CONSTRUCTORS==========================// - - /** - * Constructs a new search. - * - * @param test The source of conditional independence information for the search. - * @param depth The maximum number of variables conditioned on for any independence test in the search. - */ - public Cefs(IndependenceTest test, int depth) { - if (test == null) { - throw new NullPointerException(); - } - - if (depth == -1) { - depth = Integer.MAX_VALUE; - } - - if (depth < 0) { - throw new IllegalArgumentException("Depth must be >= -1: " + depth); - } - - this.test = test; - this.depth = depth; - this.variables = test.getVariables(); - } - - //===============================PUBLIC METHODS=======================// - - - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - - public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { - this.aggressivelyPreventCycles = aggressivelyPreventCycles; - } - - - /** - * Searches for the MB CPDAG for the given target. - * - * @param targetName The name of the target variable. - */ - public Graph search(String targetName) { - long start = MillisecondTimes.timeMillis(); - this.numIndependenceTests = 0; - this.ambiguousTriples = new HashSet<>(); - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); - - if (targetName == null) { - throw new IllegalArgumentException( - "Null target name not permitted"); - } - - this.target = getVariableForName(targetName); - - // Some statistics. - this.maxRemainingAtDepth = new int[20]; - Arrays.fill(this.maxRemainingAtDepth, -1); - - TetradLogger.getInstance().log("info", "target = " + getTarget()); - - Graph graph = new EdgeListGraph(); - - // Each time the addDepthZeroAssociates method is called for a node - // v, v is added to this set, and edges to elements in this set are - // not added to the graph subsequently. This is to handle the situation - // of adding v1---v2 to the graph, removing it by conditioning on - // nodes adjacent to v1, then re-adding it and not being able to - // remove it by conditioning on nodes adjacent to v2. Once an edge - // is removed, it should not be re-added to the graph. - // jdramsey 8/6/04 - this.visited = new HashSet<>(); - - // Step 1. Get associates for the target. - TetradLogger.getInstance().log("info", "BEGINNING step 1 (prune target)."); - - graph.addNode(getTarget()); - constructFan(getTarget(), graph); - - TetradLogger.getInstance().log("graph", "After step 1 (prune target)" + graph); - - // Step 2. Get associates for each variable adjacent to the target, - // removing edges based on those associates where possible. After this - // step, adjacencies to the target are parents or children of the target. - // Call this set PC. - TetradLogger.getInstance().log("info", "BEGINNING step 2 (prune PC)."); - - for (Node v : graph.getAdjacentNodes(getTarget())) { - constructFan(v, graph); - } - - TetradLogger.getInstance().log("graph", "After step 2 (prune PC)" + graph); - - TetradLogger.getInstance().log("info", "BEGINNING step 4 (PC Orient)."); - - SearchGraphUtils.pcOrientbk(this.knowledge, graph, graph.getNodes()); - - List _visited = new LinkedList<>(getVisited()); - orientUnshieldedTriples(this.knowledge, graph, getTest(), getDepth(), _visited); - - MeekRules meekRules = new MeekRules(); - meekRules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles); - meekRules.setKnowledge(this.knowledge); - meekRules.orientImplied(graph); - - TetradLogger.getInstance().log("graph", "After step 4 (PC Orient)" + graph); - - MbUtils.trimToAdjacents(graph, this.target); - - TetradLogger.getInstance().log("graph", "After step 6 (Remove edges among P and P of C)" + graph); - - finishUp(start, graph); - - this.logger.log("graph", "\nReturning this graph: " + graph); - - this.graph = graph; - return graph; - } - - /** - * @return the set of triples identified as ambiguous by the CPC algorithm during the most recent search. - */ - public Set getAmbiguousTriples() { - return new HashSet<>(this.ambiguousTriples); - } - - /** - * @return the set of triples identified as colliders by the CPC algorithm during the most recent search. - */ - public Set getColliderTriples() { - return this.colliderTriples; - } - - /** - * @return the set of triples identified as noncolliders by the CPC algorithm during the most recent search. - */ - public Set getNoncolliderTriples() { - return this.noncolliderTriples; - } - - /** - * @return the number of independence tests performed during the most recent search. - */ - public long getNumIndependenceTests() { - return this.numIndependenceTests; - } - - /** - * @return the target of the most recent search. - */ - public Node getTarget() { - return this.target; - } - - /** - * @return the elapsed time of the most recent search. - */ - public double getElapsedTime() { - return this.elapsedTime; - } - - /** - * If a true MB was set before running the search, this returns it. - */ - public Dag getTrueMb() { - return this.trueMb; - } - - /** - * @return the depth of the most recent search. - */ - public int getDepth() { - return this.depth; - } - - /** - * @return the result graph of the most recent search. - */ - public Graph resultGraph() { - return this.resultGraph; - } - - /** - * @return just the Markov blanket (not the Markov blanket DAG). - */ - public List findMb(String targetName) { - Graph graph = search(targetName); - List nodes = graph.getNodes(); - nodes.remove(this.target); - return nodes; - } - - /** - * @return the independence test set in the constructor. - */ - public IndependenceTest getTest() { - return this.test; - } - - /** - * @return the most recently set Knowledge object. - */ - public Knowledge getKnowledge() { - return this.knowledge; - } - - /** - * Sets knowledge, to which the algorithm is in fact sensitive. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - - public Graph getGraph() { - return this.graph; - } - - //================================PRIVATE METHODS====================// - - private Set getVisited() { - return this.visited; - } - - /** - * Adds associates of the target and prunes edges using subsets of adjacencies to the target. - */ - private void constructFan(Node target, Graph graph) { - addAllowableAssociates(target, graph); - prune(target, graph); - } - - private void addAllowableAssociates(Node v, Graph graph) { - this.getVisited().add(v); - int numAssociated = 0; - - for (Node w : this.variables) { - if (getVisited().contains(w)) { - continue; - } - - if (graph.containsNode(w) && graph.isAdjacentTo(v, w)) { - continue; - } - - if (!independent(v, w, new LinkedList<>()) && !edgeForbidden(v, w)) { - addEdge(graph, w, v); - numAssociated++; - } - } - - noteMaxAtDepth(0, numAssociated); - } - - private void prune(Node node, Graph graph) { - for (int depth = 1; depth <= getDepth(); depth++) { - if (graph.getAdjacentNodes(node).size() < depth) { - return; - } - - prune(node, graph, depth); - } - } - - /** - * Tries node remove the edge node---from using adjacent nodes of node 'from', then tries node remove each other - * edge adjacent node 'from' using remaining edges adjacent node 'from.' If the edge 'node' is removed, the method - * immediately returns. - */ - private void prune(Node node, Graph graph, int depth) { - TetradLogger.getInstance().log("pruning", "Trying to remove edges adjacent to node " + node + - ", depth = " + depth + "."); - - // Otherwise, try removing all other edges adjacent node node. Return - // true if more edges could be removed at the next depth. - List a = new LinkedList<>(graph.getAdjacentNodes(node)); - - NEXT_EDGE: - for (Node y : a) { - List adjNode = - new LinkedList<>(graph.getAdjacentNodes(node)); - adjNode.remove(y); - adjNode = possibleParents(node, adjNode); - - if (adjNode.size() < depth) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjNode.size(), depth); - int[] choice; - - while ((choice = cg.next()) != null) { - List condSet = GraphUtils.asList(choice, adjNode); - - if (independent(node, y, condSet) && !edgeRequired(node, y)) { - graph.removeEdge(node, y); - - // The target itself must not be removed. - if (graph.getEdges(y).isEmpty() && y != getTarget()) { - graph.removeNode(y); - } - - continue NEXT_EDGE; - } - } - } - - int numAdjacents = graph.getAdjacentNodes(node).size(); - noteMaxAtDepth(depth, numAdjacents); - } - - private void finishUp(long start, Graph graph) { - long stop = MillisecondTimes.timeMillis(); - this.elapsedTime = stop - start; - double seconds = this.elapsedTime / 1000d; - - NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); - TetradLogger.getInstance().log("info", "PC-MB took " + nf.format(seconds) + " seconds."); - TetradLogger.getInstance().log("info", "Number of independence tests performed = " + - getNumIndependenceTests()); - - this.resultGraph = graph; - } - - private boolean independent(Node v, Node w, List z) { - boolean independent = getTest().checkIndependence(v, w, z).independent(); - - if (independent) { - if (getTrueMb() != null) { - Node node1 = getTrueMb().getNode(v.getName()); - Node node2 = getTrueMb().getNode(w.getName()); - - if (node1 != null && node2 != null) { - Edge edge = getTrueMb().getEdge(node1, node2); - - if (edge != null) { - IndependenceResult result = getTest().checkIndependence(v, w, z); - - NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); - System.out.println( - "Edge removed that was in the true MB:"); - System.out.println("\tTrue edge = " + edge); - System.out.println("\t" + - SearchLogUtils.independenceFact(v, w, z) + - "\tp = " + - nf.format(result.getPValue())); - } - } - } - } - - this.numIndependenceTests++; - return independent; - } - - private void addEdge(Graph graph, Node w, Node v) { - if (!graph.containsNode(w)) { - graph.addNode(w); - } - - graph.addUndirectedEdge(v, w); - } - - private Node getVariableForName(String targetVariableName) { - Node target = null; - - for (Node V : this.variables) { - if (V.getName().equals(targetVariableName)) { - target = V; - break; - } - } - - if (target == null) { - throw new IllegalArgumentException( - "Target variable not in dataset: " + targetVariableName); - } - - return target; - } - - private void noteMaxAtDepth(int depth, int numAdjacents) { - if (depth < this.maxRemainingAtDepth.length && - numAdjacents > this.maxRemainingAtDepth[depth]) { - this.maxRemainingAtDepth[depth] = numAdjacents; - } - } - - private void orientUnshieldedTriples(Knowledge knowledge, Graph graph, - IndependenceTest test, int depth, List nodes) { - TetradLogger.getInstance().log("info", "Starting Collider Orientation:"); - - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); - this.ambiguousTriples = new HashSet<>(); - - if (nodes == null) { - nodes = graph.getNodes(); - } - - for (Node y : nodes) { - List adjacentNodes = graph.getAdjacentNodes(y); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node x = adjacentNodes.get(combination[0]); - Node z = adjacentNodes.get(combination[1]); - - if (graph.isAdjacentTo(x, z)) { - continue; - } - - TripleType type = getTripleType(graph, x, y, z, test, depth); - - if (type == TripleType.COLLIDER) { - if (colliderAllowed(x, y, z, knowledge)) { - graph.setEndpoint(x, y, Endpoint.ARROW); - graph.setEndpoint(z, y, Endpoint.ARROW); - this.logger.log("tripleClassifications", "Collider oriented: " + Triple.pathString(graph, x, y, z)); - } - - this.colliderTriples.add(new Triple(x, y, z)); - } else if (type == TripleType.AMBIGUOUS) { - Triple triple = new Triple(x, y, z); - this.ambiguousTriples.add(triple); - graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); - this.logger.log("tripleClassifications", "Ambiguous triple oriented: " + Triple.pathString(graph, x, y, z)); - } else { - this.noncolliderTriples.add(new Triple(x, y, z)); - this.logger.log("tripleClassifications", "Noncollider oriented: " + Triple.pathString(graph, x, y, z)); - } - } - } - - TetradLogger.getInstance().log("info", "Finishing Collider Orientation."); - } - - private TripleType getTripleType(Graph graph, Node x, Node y, Node z, - IndependenceTest test, int depth) { - boolean existsSepsetContainingY = false; - boolean existsSepsetNotContainingY = false; - - Set __nodes = new HashSet<>(graph.getAdjacentNodes(x)); - __nodes.remove(z); - - List _nodes = new LinkedList<>(__nodes); -// TetradLogger.getInstance().log("details", "Adjacents for " + x + "--" + y + "--" + z + " = " + _nodes); - - int _depth = depth; - if (_depth == -1) { - _depth = Integer.MAX_VALUE; - } - _depth = FastMath.min(_depth, _nodes.size()); - - for (int d = 0; d <= _depth; d++) { - ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d); - int[] choice; - - while ((choice = cg.next()) != null) { - List condSet = Cefs.asList(choice, _nodes); - - if (test.checkIndependence(x, z, condSet).independent()) { - if (condSet.contains(y)) { - existsSepsetContainingY = true; - } else { - existsSepsetNotContainingY = true; - } - } - } - } - - __nodes = new HashSet<>(graph.getAdjacentNodes(z)); - __nodes.remove(x); - - _nodes = new LinkedList<>(__nodes); -// TetradLogger.getInstance().log("details", "Adjacents for " + x + "--" + y + "--" + z + " = " + _nodes); - - _depth = depth; - if (_depth == -1) { - _depth = Integer.MAX_VALUE; - } - _depth = FastMath.min(_depth, _nodes.size()); - - for (int d = 0; d <= _depth; d++) { - ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d); - int[] choice; - - while ((choice = cg.next()) != null) { - List condSet = Cefs.asList(choice, _nodes); - - if (test.checkIndependence(x, z, condSet).independent()) { - if (condSet.contains(y)) { - existsSepsetContainingY = true; - } else { - existsSepsetNotContainingY = true; - } - } - } - } - - if (existsSepsetContainingY == existsSepsetNotContainingY) { - return TripleType.AMBIGUOUS; - } else if (!existsSepsetNotContainingY) { - return TripleType.NONCOLLIDER; - } else { - return TripleType.COLLIDER; - } - } - - private boolean edgeForbidden(Node x1, Node x2) { - return getKnowledge().isForbidden(x1.toString(), x2.toString()) && - getKnowledge().isForbidden(x2.toString(), x1.toString()); - } - - private boolean edgeRequired(Node x1, Node x2) { - return getKnowledge().isRequired(x1.toString(), x2.toString()) || - getKnowledge().isRequired(x2.toString(), x1.toString()); - } - - /** - * Removes from adjx any that cannot be parents of x given the background knowledge. - */ - private List possibleParents(Node node, List adjNode) { - List possibleParents = new LinkedList<>(); - String _x = node.getName(); - - for (Node z : adjNode) { - String _z = z.getName(); - - if (possibleParentOf(_z, _x, this.knowledge)) { - possibleParents.add(z); - } - } - - return possibleParents; - } - - /** - * @return true just in case z is a possible parent of x, in the sense that edges are not forbidden from z to x, and - * edges are not required from either x to z, according to background knowledge. - */ - private boolean possibleParentOf(String z, String x, Knowledge knowledge) { - return !knowledge.isForbidden(z, x) && !knowledge.isRequired(x, z); - } - - private static List asList(int[] indices, List nodes) { - List list = new LinkedList<>(); - - for (int i : indices) { - list.add(nodes.get(i)); - } - - return list; - } - - private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return Cefs.isArrowpointAllowed1(x, y, knowledge) && - Cefs.isArrowpointAllowed1(z, y, knowledge); - } - - private static boolean isArrowpointAllowed1(Node from, Node to, - Knowledge knowledge) { - if (knowledge == null) { - return true; - } - - return !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - - //==============================CLASSES==============================// - - private enum TripleType { - COLLIDER, NONCOLLIDER, AMBIGUOUS - } -} - - - - - - From ccb25c0db7eb2f1afbf213022454c704e0d0e081 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 23:33:40 -0400 Subject: [PATCH 130/464] Fixing documentation etc. --- .../search/BpcTetradPurifyWashdown.java | 21 +++- .../main/java/edu/cmu/tetrad/search/Cfci.java | 103 ++++++++---------- .../tetrad/search/ClusterSignificance.java | 2 +- 3 files changed, 68 insertions(+), 58 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java index dc0a6dfd76..6146651bab 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java @@ -39,16 +39,35 @@ public class BpcTetradPurifyWashdown { private final List variables; private final TetradTest test; + /** + * Construct the algorithm using a covariance matrix. + * @param cov A covariance matrix. + * @param testType A Test type. + * @param alpha An alpha cutoff + * @see edu.cmu.tetrad.data.CovarianceMatrix + * @see TestType + */ public BpcTetradPurifyWashdown(ICovarianceMatrix cov, TestType testType, double alpha) { this.variables = cov.getVariables(); this.test = new ContinuousTetradTest(cov, testType, alpha); } - public BpcTetradPurifyWashdown(DataSet dataSet, TestType testType, double alpha) { + /** + * Construct the algorithm using a data set. + * @param dataSet A DataSet. + * @param testType A Test type. + * @param alpha An alpha cutoff + * @see DataSet + * @see TestType + */ public BpcTetradPurifyWashdown(DataSet dataSet, TestType testType, double alpha) { this.variables = dataSet.getVariables(); this.test = new ContinuousTetradTest(dataSet, testType, alpha); } + /** + * Runs the search and returns a graph. + * @return The discovered graph. + */ public Graph search() { IPurify purify = new PurifyTetradBased2(this.test); List variables = new ArrayList<>(this.variables); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index cff7628e11..4f114abbf9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -21,7 +21,6 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; @@ -73,7 +72,7 @@ public final class Cfci implements GraphSearch { private final IndependenceTest independenceTest; /** - * flag for complete rule set, true if should use complete rule set, false otherwise. + * Flag for complete rule set, true if you should use complete rule set, false otherwise. */ private boolean completeRuleSetUsed = true; @@ -87,16 +86,6 @@ public final class Cfci implements GraphSearch { */ private int maxReachablePathLength = -1; - /** - * Set of unshielded colliders from the triple orientation step. - */ - private Set colliderTriples; - - /** - * Set of unshielded noncolliders from the triple orientation step. - */ - private Set noncolliderTriples; - /** * Set of ambiguous unshielded triples. */ @@ -132,29 +121,10 @@ public Cfci(IndependenceTest independenceTest) { this.independenceTest = independenceTest; this.variables.addAll(independenceTest.getVariables()); - - CorrelationMatrix corr = new CorrelationMatrix(independenceTest.getCov()); } //========================PUBLIC METHODS==========================// - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + depth); - } - - this.depth = depth; - } - - public long getElapsedTime() { - return this.elapsedTime; - } - public Graph search() { long beginTime = MillisecondTimes.timeMillis(); if (this.verbose) { @@ -173,7 +143,7 @@ public Graph search() { // // Step FCI B. (Zhang's step F2.) Fas adj = new Fas(this.independenceTest); - adj.setKnowledge(getKnowledge()); + adj.setKnowledge(this.knowledge); adj.setDepth(this.depth); adj.setVerbose(this.verbose); this.graph = adj.search(); @@ -196,8 +166,8 @@ public Graph search() { long time3 = MillisecondTimes.timeMillis(); PossibleDsepFci possibleDSep = new PossibleDsepFci(this.graph, this.independenceTest); - possibleDSep.setDepth(getDepth()); - possibleDSep.setKnowledge(getKnowledge()); + possibleDSep.setDepth(this.depth); + possibleDSep.setKnowledge(this.knowledge); possibleDSep.setMaxPathLength(getMaxReachablePathLength()); // We use these sepsets though. @@ -214,7 +184,7 @@ public Graph search() { // Step CI C (Zhang's step F3.) long time5 = MillisecondTimes.timeMillis(); - fciOrientbk(getKnowledge(), this.graph, this.variables); + fciOrientbk(this.knowledge, this.graph, this.variables); ruleR0(this.independenceTest, this.depth, this.sepsets); long time6 = MillisecondTimes.timeMillis(); @@ -246,16 +216,47 @@ public Graph search() { return this.graph; } - public SepsetMap getSepsets() { - return this.sepsets; + /** + * Sets the depth--i.e., the maximum number of variables conditioned on in any test. + * + * @param depth This maximum. + */ + public void setDepth(int depth) { + if (depth < -1) { + throw new IllegalArgumentException( + "Depth must be -1 (unlimited) or >= 0: " + depth); + } + + this.depth = depth; } - public Knowledge getKnowledge() { - return this.knowledge; + /** + * Returns the elapsed time ot the search. + * + * @return This time. + */ + public long getElapsedTime() { + return this.elapsedTime; } + /** + * Returns the map from nodes to their sepsets. For x _||_ y | z1,...,zn, this + * would map {x, y} to {z1,..,zn}. + * + * @return This map. + */ + public SepsetMap getSepsets() { + return this.sepsets; + } + + /** + * Set the knowledge used in the search. + * + * @param knowledge This knowledge. + * @see Knowledge + */ public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } /** @@ -274,14 +275,12 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { this.completeRuleSetUsed = completeRuleSetUsed; } - public Set getColliderTriples() { - return new HashSet<>(this.colliderTriples); - } - - public Set getNoncolliderTriples() { - return new HashSet<>(this.noncolliderTriples); - } - + /** + * Returns the ambiguous triples found in the search. + * + * @return This set. + * @see Cpc + */ public Set getAmbiguousTriples() { return new HashSet<>(this.ambiguousTriples); } @@ -297,8 +296,6 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { TetradLogger.getInstance().log("info", "Starting Collider Orientation:"); } - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); this.ambiguousTriples = new HashSet<>(); for (Node y : getGraph().getNodes()) { @@ -333,12 +330,6 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { } } - this.colliderTriples.add(new Triple(x, y, z)); - } else if (type == TripleType.NONCOLLIDER || (sepset != null && sepset.contains(y))) { - this.noncolliderTriples.add(new Triple(x, y, z)); - if (this.verbose) { - TetradLogger.getInstance().log("tripleClassifications", "Noncollider: " + Triple.pathString(this.graph, x, y, z)); - } } else { Triple triple = new Triple(x, y, z); this.ambiguousTriples.add(triple); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java index b3535e7cbb..cb36f223fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java @@ -17,7 +17,7 @@ /** * Some methods to check significance of clusters for clustering algroithms. It is assumed - * that for each cluster there is a single latent that is a parent of all of the nodes + * that for each cluster there is a single latent that is a parent of all the nodes * in the cluster. Significance of these models is returned. * * @author josephramsey From e26cacd5952a73d8199e9655239db8f0997d8e9c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 23:41:09 -0400 Subject: [PATCH 131/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/ChiSquareTest.java | 8 +-- .../tetrad/search/ClusterSignificance.java | 53 +++++++++---------- 2 files changed, 28 insertions(+), 33 deletions(-) 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 e0292b5f78..f5e2915943 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 @@ -272,7 +272,7 @@ public void setAlpha(double alpha) { //================================PRIVATE==============================// - public int[] selectFromArray(int[] arr, int[] indices) { + private int[] selectFromArray(int[] arr, int[] indices) { int[] retArr = new int[indices.length]; for (int i = 0; i < indices.length; i++) { @@ -282,15 +282,15 @@ public int[] selectFromArray(int[] arr, int[] indices) { return retArr; } - public DataSet getDataSet() { + private DataSet getDataSet() { return this.dataSet; } - public int[] getDims() { + private int[] getDims() { return this.dims; } - public CellTable getCellTable() { + private CellTable getCellTable() { return this.cellTable; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java index cb36f223fa..06afd601c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java @@ -16,18 +16,29 @@ import java.util.Set; /** - * Some methods to check significance of clusters for clustering algroithms. It is assumed + *

Some methods to check significance of clusters for clustering algroithms. It is assumed * that for each cluster there is a single latent that is a parent of all the nodes - * in the cluster. Significance of these models is returned. + * in the cluster. Significance of these models is returned.

+ *

The methods in this class are used only internally and so have package scope only.

* * @author josephramsey */ public class ClusterSignificance { + public enum CheckType {Significance, Clique, None} private final List variables; private final DataModel dataModel; - public void printClusterPValues(Set> out) { + private CheckType checkType = CheckType.Clique; + + ClusterSignificance(List variables, DataModel dataModel) { + if (variables == null) throw new NullPointerException("Variable null."); + if (dataModel == null) throw new NullPointerException("Data model null."); + this.variables = variables; + this.dataModel = dataModel; + } + + void printClusterPValues(Set> out) { NumberFormat nf = new DecimalFormat("0.000"); for (List _out : out) { @@ -44,7 +55,7 @@ public void printClusterPValues(Set> out) { } } - public static List variablesForIndices(List cluster, List variables) { + static List variablesForIndices(List cluster, List variables) { List _cluster = new ArrayList<>(); for (int c : cluster) { @@ -64,17 +75,6 @@ static List> variablesForIndices2(Set> clusters, List variables, DataModel dataModel) { - if (variables == null) throw new NullPointerException("Variable null."); - if (dataModel == null) throw new NullPointerException("Data model null."); - this.variables = variables; - this.dataModel = dataModel; - } - /** * Converts a list of indices into a list of Integers representing a cluster. * @@ -87,8 +87,11 @@ static List getInts(int[] indices) { return cluster; } + void setCheckType(CheckType checkType) { + this.checkType = checkType; + } - public boolean significant(List cluster, double alpha) { + boolean significant(List cluster, double alpha) { if (checkType == CheckType.None) { return true; } else if (checkType == CheckType.Significance) { @@ -100,6 +103,11 @@ public boolean significant(List cluster, double alpha) { } } + double getModelPValue(List> clusters) { + SemIm im = estimateModel(clusters); + return im.getPValue(); + } + private double significance(List cluster) { double chisq = getClusterChiSquare(cluster); @@ -167,15 +175,6 @@ private SemIm estimateClusterModel(List quartet) { return est.estimate(); } - private double modelSignificance(List> clusters) { - return getModelPValue(clusters); - } - - public double getModelPValue(List> clusters) { - SemIm im = estimateModel(clusters); - return im.getPValue(); - } - private SemIm estimateModel(List> clusters) { Graph g = new EdgeListGraph(); @@ -247,9 +246,5 @@ private SemIm estimateModel(List> clusters) { return est.estimate(); } - public void setCheckType(CheckType checkType) { - this.checkType = checkType; - } - } From 123bbdaeae67b326743871ab833ee648e5ff0c72 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 2 May 2023 23:50:55 -0400 Subject: [PATCH 132/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/ClusterUtils.java | 9 +- ...GIterator.java => DagInCpcagIterator.java} | 36 +- .../search/DegenerateGaussianScoreOld.java | 330 ------------------ .../java/edu/cmu/tetrad/search/HbsmsGes.java | 2 +- .../cmu/tetrad/search/SearchGraphUtils.java | 2 +- .../tetrad/test/TestDagInPatternIterator.java | 16 +- 6 files changed, 38 insertions(+), 357 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{DagInCPDAGIterator.java => DagInCpcagIterator.java} (90%) delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScoreOld.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterUtils.java index 246d857cdb..312e8e2c98 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterUtils.java @@ -31,14 +31,15 @@ import java.util.Set; /** - * Some general utilities for dealing with clustering input and output. + *

Some general utilities for dealing with clustering input and output.

+ *

The method of this class are used only internally and so are not documented + * for public use.

* * @author Joseph Ramsey */ public class ClusterUtils { public static final String LATENT_PREFIX = "_L"; - public static List convertListToInt(List> partition, List nodes) { List _partition = new ArrayList<>(); @@ -59,7 +60,7 @@ public static List convertListToInt(List> partition, List> convertIntToList(List partition, List nodes) { + static List> convertIntToList(List partition, List nodes) { List> _partition = new ArrayList<>(); for (int[] cluster : partition) { @@ -179,7 +180,7 @@ public static Clusters mimClusters(Graph mim) { } - public static void logClusters(Set> clusters, List variables) { + static void logClusters(Set> clusters, List variables) { int num = 1; StringBuilder buf = new StringBuilder(); buf.append("\nClusters:\n"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCPDAGIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java similarity index 90% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCPDAGIterator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java index a7417df27c..6c811a5623 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCPDAGIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java @@ -32,7 +32,7 @@ * * @author Joseph Ramsey */ -public class DagInCPDAGIterator { +public class DagInCpcagIterator { /** * The stack of graphs, with annotations as to the arbitrary undirected edges chosen in them and whether or not @@ -41,15 +41,27 @@ public class DagInCPDAGIterator { private final LinkedList decoratedGraphs = new LinkedList<>(); private Graph storedGraph; private boolean returnedOne; - private final Knowledge knowledge; private final LinkedList colliders; private final boolean allowNewColliders; - public DagInCPDAGIterator(Graph CPDAG) { + /** + * The given CPDAG must be a CPDAG. If it does not consist entirely of directed and undirected edges and if it + * is not acyclic, it is rejected. + * + * @param CPDAG The CPDAG for which DAGS are wanted. May result in cyclic outputs. + * @throws IllegalArgumentException if the CPDAG is not a CPDAG. + */ public DagInCpcagIterator(Graph CPDAG) { this(CPDAG, new Knowledge(), false, true); } - public DagInCPDAGIterator(Graph CPDAG, Knowledge knowledge) { + /** + * The given CPDAG must be a CPDAG. If it does not consist entirely of directed and undirected edges and if it + * is not acyclic, it is rejected. + * + * @param CPDAG The CPDAG for which DAGS are wanted. May result in cyclic outputs. + * @param knowledge The knowledge to be used to constrain the DAGs. + * @throws IllegalArgumentException if the CPDAG is not a CPDAG. + */ public DagInCpcagIterator(Graph CPDAG, Knowledge knowledge) { this(CPDAG, knowledge, false, true); } @@ -58,16 +70,19 @@ public DagInCPDAGIterator(Graph CPDAG, Knowledge knowledge) { * is not acyclic, it is rejected. * * @param CPDAG The CPDAG for which DAGS are wanted. + * @param knowledge The knowledge to be used to constrain the DAGs. * @param allowArbitraryOrientations True if arbitrary orientations are allowable when reasonable ones cannot be * made. May result in cyclic outputs. + * @param allowNewColliders True if new colliders are allowed in teh graphs. * @throws IllegalArgumentException if the CPDAG is not a CPDAG. */ - public DagInCPDAGIterator(Graph CPDAG, Knowledge knowledge, boolean allowArbitraryOrientations, + public DagInCpcagIterator(Graph CPDAG, Knowledge knowledge, boolean allowArbitraryOrientations, boolean allowNewColliders) { + Knowledge knowledge1; if (knowledge == null) { - this.knowledge = new Knowledge(); + knowledge1 = new Knowledge(); } else { - this.knowledge = knowledge; + knowledge1 = knowledge; } this.allowNewColliders = allowNewColliders; @@ -81,7 +96,7 @@ public DagInCPDAGIterator(Graph CPDAG, Knowledge knowledge, boolean allowArbitra HashMap> changedEdges = new HashMap<>(); changedEdges.put(CPDAG, new HashSet<>()); - this.decoratedGraphs.add(new DecoratedGraph(CPDAG, getKnowledge(), changedEdges, + this.decoratedGraphs.add(new DecoratedGraph(CPDAG, knowledge1, changedEdges, allowArbitraryOrientations)); this.colliders = GraphUtils.listColliderTriples(CPDAG); } @@ -147,10 +162,6 @@ public boolean hasNext() { return this.storedGraph != null; } - public Knowledge getKnowledge() { - return this.knowledge; - } - //==============================CLASSES==============================// private static class DecoratedGraph { @@ -239,7 +250,6 @@ public DecoratedGraph orient() { for (Edge edge : edges) { edge.setHighlighted(true); -// graph.setHighlighted(edge, true); } this.triedLeft = true; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScoreOld.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScoreOld.java deleted file mode 100755 index 5e0625f975..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScoreOld.java +++ /dev/null @@ -1,330 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.Matrix; -import org.apache.commons.collections4.map.HashedMap; -import org.apache.commons.math3.linear.BlockRealMatrix; -import org.apache.commons.math3.linear.RealMatrix; -import org.apache.commons.math3.util.FastMath; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.apache.commons.math3.util.FastMath.log; - -/** - * Implements a degenerate Gaussian BIC score for FGES. - *

- * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf - * - * @author Bryan Andrews - * @deprecated Use DegenerateGaussianScore - */ -public class DegenerateGaussianScoreOld implements Score { - - private final BoxDataSet ddata; - private final DataSet dataSet; - - // The mixed variables of the original dataset. - private final List variables; - - // The penalty discount. - private double penaltyDiscount = 1.0; - - // The structure prior. - private double structurePrior; - - // The embedding map. - private final Map> embedding; - - // A constant. - private static final double L2PE = log(2.0 * FastMath.PI * FastMath.E); - - private final Map nodesHash; - - - /** - * Constructs the score using a covariance matrix. - */ - public DegenerateGaussianScoreOld(DataSet dataSet) { - if (dataSet == null) { - throw new NullPointerException(); - } - - this.dataSet = dataSet; - this.variables = dataSet.getVariables(); - // The number of instances. - int n = dataSet.getNumRows(); - this.embedding = new HashMap<>(); - - List A = new ArrayList<>(); - List B = new ArrayList<>(); - - int index = 0; - - int i = 0; - int i_ = 0; - while (i_ < this.variables.size()) { - - Node v = this.variables.get(i_); - - if (v instanceof DiscreteVariable) { - - Map, Integer> keys = new HashMap<>(); - Map> keysReverse = new HashMap<>(); - for (int j = 0; j < n; j++) { - List key = new ArrayList<>(); - key.add(this.dataSet.getInt(j, i_)); - if (!keys.containsKey(key)) { - keys.put(key, i); - keysReverse.put(i, key); - Node v_ = new ContinuousVariable("V__" + ++index); - A.add(v_); - B.add(new double[n]); - i++; - } - B.get(keys.get(key))[j] = 1; - } - - /* - * Remove a degenerate dimension. - */ - i--; - keys.remove(keysReverse.get(i)); - A.remove(i); - B.remove(i); - - this.embedding.put(i_, new ArrayList<>(keys.values())); - - } else { - - A.add(v); - double[] b = new double[n]; - for (int j = 0; j < n; j++) { - b[j] = this.dataSet.getDouble(j, i_); - } - - B.add(b); - List index2 = new ArrayList<>(); - index2.add(i); - this.embedding.put(i_, index2); - i++; - - } - i_++; - } - double[][] B_ = new double[n][B.size()]; - for (int j = 0; j < B.size(); j++) { - for (int k = 0; k < n; k++) { - B_[k][j] = B.get(j)[k]; - } - } - - // The continuous variables of the post-embedding dataset. - RealMatrix D = new BlockRealMatrix(B_); - this.ddata = new BoxDataSet(new DoubleDataBox(D.getData()), A); - this.nodesHash = new HashedMap<>(); - - List variables = dataSet.getVariables(); - - for (int j = 0; j < variables.size(); j++) { - this.nodesHash.put(variables.get(j), j); - } - - } - - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model - */ - public double localScore(int i, int... parents) { - - List rows = getRows(i, parents); - int N = dataSet.getNumRows();// rows.size(); - - List B = new ArrayList<>(); - List A = new ArrayList<>(this.embedding.get(i)); - for (int i_ : parents) { - B.addAll(this.embedding.get(i_)); - } - - int[] A_ = new int[A.size() + B.size()]; - int[] B_ = new int[B.size()]; - for (int i_ = 0; i_ < A.size(); i_++) { - A_[i_] = A.get(i_); - } - for (int i_ = 0; i_ < B.size(); i_++) { - A_[A.size() + i_] = B.get(i_); - B_[i_] = B.get(i_); - } - - int dof = (A_.length * (A_.length + 1) - B_.length * (B_.length + 1)) / 2; - double ldetA = log(getCov(rows, A_).det()); - double ldetB = log(getCov(rows, B_).det()); - - double lik = N * (ldetB - ldetA + DegenerateGaussianScoreOld.L2PE * (B_.length - A_.length)); - double score = 2 * lik + 2 * calculateStructurePrior(parents.length) - dof * getPenaltyDiscount() * log(N); - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; - } - } - - private double calculateStructurePrior(int k) { - if (this.structurePrior <= 0) { - return 0; - } else { - double n = this.variables.size() - 1; - double p = this.structurePrior / n; - return k * log(p) + (n - k) * log(1.0 - p); - } - } - - - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - - - public int getSampleSize() { - return this.dataSet.getNumRows(); - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > 0; - } - - @Override - public List getVariables() { - return this.variables; - } - - @Override - public int getMaxDegree() { - return (int) FastMath.ceil(log(this.dataSet.getNumRows())); - } - - @Override - public boolean determines(List z, Node y) { - return false; - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public double getStructurePrior() { - return this.structurePrior; - } - - public void setStructurePrior(double structurePrior) { - this.structurePrior = structurePrior; - } - - @Override - public String toString() { - NumberFormat nf = new DecimalFormat("0.00"); - return "Degenerate Gaussian Score Penalty " + nf.format(this.penaltyDiscount); - } - - // Subsample of the continuous mixedVariables conditioning on the given cols. - private Matrix getCov(List rows, int[] cols) { - if (rows.isEmpty()) return new Matrix(0, 0); - Matrix cov = new Matrix(cols.length, cols.length); - - for (int i = 0; i < cols.length; i++) { - for (int j = 0; j < cols.length; j++) { - double mui = 0.0; - double muj = 0.0; - - for (int k : rows) { - mui += this.ddata.getDouble(k, cols[i]); - muj += this.ddata.getDouble(k, cols[j]); - } - - mui /= rows.size() - 1; - muj /= rows.size() - 1; - - double _cov = 0.0; - - for (int k : rows) { - _cov += (this.ddata.getDouble(k, cols[i]) - mui) * (this.ddata.getDouble(k, cols[j]) - muj); - } - - double mean = _cov / (rows.size()); - cov.set(i, j, mean); - } - } - - return cov; - } - - private List getRows(int i, int[] parents) { - List rows = new ArrayList<>(); - - K: - for (int k = 0; k < this.dataSet.getNumRows(); k++) { - Node ii = this.variables.get(i); - - List A = new ArrayList<>(this.embedding.get(this.nodesHash.get(ii))); - - for (int j : A) { - if (Double.isNaN(this.ddata.getDouble(k, j))) continue K; - } - - for (int ignored : parents) { - Node pp = this.variables.get(i); - - List AA = new ArrayList<>(this.embedding.get(this.nodesHash.get(pp))); - - for (int j : AA) { - if (Double.isNaN(this.ddata.getDouble(k, j))) continue K; - } - } - - rows.add(k); - } - - return rows; - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java index a22f01c796..e857db6c57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java @@ -57,7 +57,7 @@ public HbsmsGes(Graph graph, DataSet data) { final boolean allowArbitraryOrientations = true; final boolean allowNewColliders = true; - DagInCPDAGIterator iterator = new DagInCPDAGIterator(graph, getKnowledge(), allowArbitraryOrientations, + DagInCpcagIterator iterator = new DagInCpcagIterator(graph, getKnowledge(), allowArbitraryOrientations, allowNewColliders); graph = iterator.next(); graph = SearchGraphUtils.cpdagForDag(graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java index 69a1ebff68..d32d93668e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java @@ -1207,7 +1207,7 @@ public static List generateCpdagDags(Graph cpdag, boolean orientBidirecte } public static List getDagsInCpdagMeek(Graph cpdag, Knowledge knowledge) { - DagInCPDAGIterator iterator = new DagInCPDAGIterator(cpdag, knowledge); + DagInCpcagIterator iterator = new DagInCpcagIterator(cpdag, knowledge); List dags = new ArrayList<>(); while (iterator.hasNext()) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java index d6d3159bc3..bb424b956a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DagInCPDAGIterator; +import edu.cmu.tetrad.search.DagInCpcagIterator; import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.util.RandomUtil; @@ -60,7 +60,7 @@ public void test1() { System.out.println(CPDAG); - DagInCPDAGIterator iterator = new DagInCPDAGIterator(CPDAG); + DagInCpcagIterator iterator = new DagInCpcagIterator(CPDAG); int count = 0; while (iterator.hasNext()) { @@ -80,7 +80,7 @@ public void test2() { CPDAG.addNode(y); CPDAG.addDirectedEdge(x, y); - DagInCPDAGIterator iterator = new DagInCPDAGIterator(CPDAG); + DagInCpcagIterator iterator = new DagInCpcagIterator(CPDAG); int count = 0; while (iterator.hasNext()) { @@ -116,7 +116,7 @@ public void test3() { CPDAG.addUndirectedEdge(x1, x6); CPDAG.addUndirectedEdge(x4, x6); - DagInCPDAGIterator iterator = new DagInCPDAGIterator(CPDAG); + DagInCpcagIterator iterator = new DagInCpcagIterator(CPDAG); int count = 0; while (iterator.hasNext()) { @@ -152,7 +152,7 @@ public void test4() { CPDAG.addUndirectedEdge(x1, x6); CPDAG.addUndirectedEdge(x4, x6); - DagInCPDAGIterator iterator = new DagInCPDAGIterator(CPDAG); + DagInCpcagIterator iterator = new DagInCpcagIterator(CPDAG); int count = 0; while (iterator.hasNext()) { @@ -190,7 +190,7 @@ public void test5() { } if (!knowledge.isViolatedBy(CPDAG)) { - DagInCPDAGIterator iterator1 = new DagInCPDAGIterator(CPDAG); + DagInCpcagIterator iterator1 = new DagInCpcagIterator(CPDAG); Graph dag0 = null; while (iterator1.hasNext()) { @@ -207,7 +207,7 @@ public void test5() { } if (!knowledge.isViolatedBy(CPDAG)) { - DagInCPDAGIterator iterator2 = new DagInCPDAGIterator(CPDAG, knowledge); + DagInCpcagIterator iterator2 = new DagInCpcagIterator(CPDAG, knowledge); while (iterator2.hasNext()) { Graph dag = iterator2.next(); @@ -218,7 +218,7 @@ public void test5() { } } - DagInCPDAGIterator iterator3 = new DagInCPDAGIterator(CPDAG); + DagInCpcagIterator iterator3 = new DagInCpcagIterator(CPDAG); int count = 0; while (iterator3.hasNext()) { From 3d4e1150dbbc86af97e4e5ca62c6f00cbe681ecf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 00:15:58 -0400 Subject: [PATCH 133/464] Fixing documentation etc. --- .../independence/CciLingamTest.java | 70 --- .../ConditionalCorrelationIndependence.java | 69 +-- ...ditionalCorrelationIndependenceLingam.java | 441 ------------------ .../edu/cmu/tetrad/search/DagSepsets.java | 61 ++- .../java/edu/cmu/tetrad/search/DagToPag.java | 204 ++++---- .../search/IndTestConditionalCorrelation.java | 2 +- .../IndTestConditionalCorrelationLingam.java | 212 --------- 7 files changed, 179 insertions(+), 880 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciLingamTest.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependenceLingam.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelationLingam.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciLingamTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciLingamTest.java deleted file mode 100644 index 50c73622c6..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciLingamTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package edu.cmu.tetrad.algcomparison.independence; - -import edu.cmu.tetrad.annotation.General; -import edu.cmu.tetrad.annotation.TestOfIndependence; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.ConditionalCorrelationIndependenceLingam; -import edu.cmu.tetrad.search.IndTestConditionalCorrelationLingam; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; - -import java.util.ArrayList; -import java.util.List; - -// Can't change the name of this yet. - -/** - * Wrapper for Daudin Conditional Independence test. - * - * @author jdramsey - */ -@TestOfIndependence( - name = "CCI-Lingam-Test (Conditional Correlation Independence Lingam Test)", - command = "cci-lingam-test", - dataType = DataType.Continuous -) -@General -public class CciLingamTest implements IndependenceWrapper { - - static final long serialVersionUID = 23L; - - @Override - public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - IndTestConditionalCorrelationLingam cci = new IndTestConditionalCorrelationLingam(SimpleDataLoader.getContinuousDataSet(dataSet), - parameters.getDouble(Params.ALPHA)); - - if (parameters.getInt(Params.BASIS_TYPE) == 1) { - cci.setBasis(ConditionalCorrelationIndependenceLingam.Basis.Polynomial); - } else if (parameters.getInt(Params.BASIS_TYPE) == 2) { - cci.setBasis(ConditionalCorrelationIndependenceLingam.Basis.Cosine); - } else { - throw new IllegalStateException("Basis not configured."); - } - - cci.setNumFunctions(parameters.getInt(Params.NUM_BASIS_FUNCTIONS)); - - return cci; - } - - @Override - public String getDescription() { - return "CCI Test"; - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - List params = new ArrayList<>(); - params.add(Params.ALPHA); - params.add(Params.NUM_BASIS_FUNCTIONS); - params.add(Params.BASIS_TYPE); - return params; - } -} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java index 08958e23b1..425195655e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java @@ -71,11 +71,6 @@ public enum Basis {Polynomial, Cosine} */ private final HashMap nodesHash; - /** - * Alpha cutoff for this class. - */ - private double alpha; - /** * The q value of the most recent test. */ @@ -119,11 +114,9 @@ public enum Basis {Polynomial, Cosine} * significance level is used. * * @param dataSet A data set containing only continuous columns. - * @param alpha The alpha level of the test. */ - public ConditionalCorrelationIndependence(DataSet dataSet, double alpha) { + public ConditionalCorrelationIndependence(DataSet dataSet) { if (dataSet == null) throw new NullPointerException(); - this.alpha = alpha; this.dataSet = dataSet; this.variables = dataSet.getVariables(); @@ -137,7 +130,7 @@ public ConditionalCorrelationIndependence(DataSet dataSet, double alpha) { //=================PUBLIC METHODS====================// /** - * @return true iff x is independent of y conditional on z. + * @return the p-value of the test. Can be compared to alpha. */ public double isIndependent(Node x, Node y, List z) { try { @@ -256,12 +249,12 @@ public double[] residuals(Node x, List z, List rows) { double k; - if (getKernelMultiplier() == Kernel.Epinechnikov) { + if (this.kernelMultiplier == Kernel.Epinechnikov) { k = kernelEpinechnikov(d, h); - } else if (getKernelMultiplier() == Kernel.Gaussian) { + } else if (this.kernelMultiplier == Kernel.Gaussian) { k = kernelGaussian(d, h); } else { - throw new IllegalStateException("Unsupported kernel type: " + getKernelMultiplier()); + throw new IllegalStateException("Unsupported kernel type: " + this.kernelMultiplier); } _sumx[i] += k * xj; @@ -284,39 +277,58 @@ public double[] residuals(Node x, List z, List rows) { /** * Number of functions to use in (truncated) basis + * @param numFunctions This number. */ - public int getNumFunctions() { - return this.numFunctions; - } - public void setNumFunctions(int numFunctions) { this.numFunctions = numFunctions; } - public Kernel getKernelMultiplier() { - return this.kernelMultiplier; - } - + /** + * Sets the kernel multiplier. + * @param kernelMultiplier This multiplier. + */ public void setKernelMultiplier(Kernel kernelMultiplier) { this.kernelMultiplier = kernelMultiplier; } + /** + * Sets the basis. + * @param basis This basis. + * @see Basis + */ public void setBasis(Basis basis) { this.basis = basis; } + /** + * Returns the kernel width. + * @return This width. + */ public double getWidth() { return this.width; } + /** + * Sets the kernel width. + * @param width This width. + */ public void setWidth(double width) { this.width = width; } + /** + * Returns the p-value of the score. + * @return This p-value. + */ public double getPValue() { return getPValue(this.score); } + /** + * Returns the p-value of the score. + * @param score The score. + * @return This p-value. + */ public double getPValue(double score) { return 2.0 * (1.0 - new NormalDistribution(0, 1).cumulativeProbability(abs(score))); } @@ -329,15 +341,18 @@ public double getScore() { return abs(this.score) - this.cutoff;// alpha - getPValue(); } + /** + * Sets the alpha cutoff. + * @param alpha This cutoff. + */ public void setAlpha(double alpha) { - this.alpha = alpha; this.cutoff = getZForAlpha(alpha); } - public double getAlpha() { - return this.alpha; - } - + /** + * Sets the kernel regression sample size. + * @param kernelRegressionSapleSize This sample size + */ public void setKernelRegressionSampleSize(int kernelRegressionSapleSize) { this.kernelRegressionSampleSize = kernelRegressionSapleSize; } @@ -355,8 +370,8 @@ private double independent(double[] x, double[] y) { double maxScore = Double.NEGATIVE_INFINITY; - for (int m = 1; m <= getNumFunctions(); m++) { - for (int n = 1; n <= getNumFunctions(); n++) { + for (int m = 1; m <= this.numFunctions; m++) { + for (int n = 1; n <= this.numFunctions; n++) { for (int i = 0; i < x.length; i++) { _x[i] = function(m, x[i]); _y[i] = function(n, y[i]); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependenceLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependenceLingam.java deleted file mode 100644 index aec79e4817..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependenceLingam.java +++ /dev/null @@ -1,441 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.regression.RegressionDataset; -import edu.cmu.tetrad.regression.RegressionResult; -import org.apache.commons.math3.distribution.NormalDistribution; - -import java.util.*; - -import static edu.cmu.tetrad.util.StatUtils.*; -import static org.apache.commons.math3.util.FastMath.pow; -import static org.apache.commons.math3.util.FastMath.*; - -/** - * Checks conditional independence of variable in a continuous data set using Daudin's method. See - *

- * Ramsey, J. D. (2014). A scalable conditional independence test for nonlinear, non-Gaussian data. arXiv - * preprint arXiv:1401.5031. - *

- * This is corrected using Lemma 2, condition 4 of - *

- * Zhang, K., Peters, J., Janzing, D., and Schölkopf, B. (2012). Kernel-based conditional independence test and - * application in causal discovery. arXiv preprint arXiv:1202.3775. - *

- * This all follows the original Daudin paper, which is this: - *

- * Daudin, J. J. (1980). Partial association measures and a application to qualitative regression. - * Biometrika, 67(3), 581-590. - *

- * We use Nadaraya-Watson kernel regression, though we further restrict the sample size to nearby points. - * - * @author Joseph Ramsey - */ -public final class ConditionalCorrelationIndependenceLingam { - private final RegressionDataset regressionDataset; - - public enum Kernel {Epinechnikov, Gaussian} - - public enum Basis {Polynomial, Cosine} - - /** - * The dataset supplied in the constructor. - */ - private final DataSet dataSet; - - /** - * The variables in datasSet. - */ - private final List variables; - - /** - * Map from nodes to their indices. - */ - private final HashMap nodesHash; - - /** - * Alpha cutoff for this class. - */ - private double alpha; - - /** - * The q value of the most recent test. - */ - private double score; - - /** - * Number of functions to use in the (truncated) basis. - */ - private int numFunctions = 10; - - /** - * Z cutoff for testing; depends on alpha. - */ - private double cutoff; - - /** - * Azzalini kernel widths are multiplied by this. - */ - private double width = 1.0; - - /** - * Basis - */ - private Basis basis = Basis.Polynomial; - - //==================CONSTRUCTORS====================// - - /** - * Constructs a new Independence test which checks independence facts based on the - * correlation data implied by the given data set (must be continuous). The given - * significance level is used. - * - * @param dataSet A data set containing only continuous columns. - * @param alpha The alpha level of the test. - */ - public ConditionalCorrelationIndependenceLingam(DataSet dataSet, double alpha) { - if (dataSet == null) throw new NullPointerException(); - this.alpha = alpha; - - this.variables = dataSet.getVariables(); - - this.nodesHash = new HashMap<>(); - for (int i = 0; i < this.variables.size(); i++) { - this.nodesHash.put(this.variables.get(i), i); - } - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - scale(dataSet, j); - } - - this.dataSet = dataSet; - regressionDataset = new RegressionDataset(dataSet); - } - - //=================PUBLIC METHODS====================// - - /** - * @return true iff x is independent of y conditional on z. - */ - public double isIndependent(Node x, Node y, List z) { - try { - double[] rx = residuals(x, z); - double[] ry = residuals(y, z); - - // rx _||_ ry ? - double score = independent(rx, ry); - this.score = score; - - return score; - } catch (Exception e) { - e.printStackTrace(); - return 0; - } - } - - /** - * Calculates the residuals of x regressed nonparametrically onto z. Left public - * so it can be accessed separately. - * - * @return a double[2][] array. The first double[] array contains the residuals for x - * and the second double[] array contains the resituls for y. - */ - public double[] residuals(Node x, List z) { - RegressionResult result = regressionDataset.regress(x, z); - edu.cmu.tetrad.util.Vector residuals = result.getResiduals(); - - int numRows = dataSet.getNumRows(); - - double[] _residualsx = new double[numRows]; - - for (int i = 0; i < numRows; i++) _residualsx[i] = residuals.get(i); - - return _residualsx; - } - - /** - * Number of functions to use in (truncated) basis - */ - public int getNumFunctions() { - return this.numFunctions; - } - - public void setNumFunctions(int numFunctions) { -// this.numFunctions = numFunctions; - } - - public void setBasis(Basis basis) { -// this.basis = basis; - } - - public double getWidth() { - return this.width; - } - - public void setWidth(double width) { - this.width = width; - } - - public double getPValue() { - return getPValue(this.score); - } - - public double getPValue(double score) { - return 2.0 * (new NormalDistribution(0, 1).cumulativeProbability(-abs(score))); - } - - /** - * @return the minimal scores value calculated by the method for the most - * recent independence check. - */ - public double getScore() { - return abs(this.score) - this.cutoff;// alpha - getPValue(); - } - - public void setAlpha(double alpha) { - this.alpha = alpha; - this.cutoff = getZForAlpha(alpha); - } - - public double getAlpha() { - return this.alpha; - } - - //=====================PRIVATE METHODS====================// - - /** - * @return true just in the case the x and y vectors are independent, - * once undefined values have been removed. Left public so it can be - * accessed separately. - */ - private double independent(double[] x, double[] y) { - double[] _x = new double[x.length]; - double[] _y = new double[y.length]; - - double maxScore = Double.NEGATIVE_INFINITY; - - for (int m = 1; m <= getNumFunctions(); m++) { - for (int n = 1; n <= getNumFunctions(); n++) { - for (int i = 0; i < x.length; i++) { - _x[i] = function(m, x[i]); - _y[i] = function(n, y[i]); - } - - double score = abs(nonparametricFisherZ(_x, _y)); - if (Double.isInfinite(score) || Double.isNaN(score)) continue; - - if (score > maxScore) { - maxScore = score; - } - } - } - - return maxScore; - } - - private void scale(DataSet dataSet, int col) { - double max = Double.MIN_VALUE; - double min = Double.MAX_VALUE; - - for (int i = 0; i < dataSet.getNumRows(); i++) { - double d = dataSet.getDouble(i, col); - if (Double.isNaN(d)) continue; - if (d > max) max = d; - if (d < min) min = d; - } - - for (int i = 0; i < dataSet.getNumRows(); i++) { - double d = dataSet.getDouble(i, col); - if (Double.isNaN(d)) continue; - dataSet.setDouble(i, col, min + (d - min) / (max - min)); - } - } - - private double nonparametricFisherZ(double[] _x, double[] _y) { - - // Testing the hypothesis that _x and _y are uncorrelated and assuming that 4th moments of _x and _y - // are finite and that the sample is large. - double[] __x = standardize(_x); - double[] __y = standardize(_y); - - double r = covariance(__x, __y); // correlation - int N = __x.length; - - // Non-parametric Fisher Z test. - double z = 0.5 * sqrt(N) * (log(1.0 + r) - log(1.0 - r)); - - return z / (sqrt((moment22(__x, __y)))); - } - - private double moment22(double[] x, double[] y) { - int N = x.length; - double sum = 0.0; - - for (int j = 0; j < x.length; j++) { - sum += x[j] * x[j] * y[j] * y[j]; - } - - return sum / N; - } - - private double function(int index, double x) { - if (this.basis == Basis.Polynomial) { - double g = 1.0; - - for (int i = 1; i <= index; i++) { - g *= x; - } - - if (abs(g) == Double.POSITIVE_INFINITY) g = Double.NaN; - - return g; - } else if (this.basis == Basis.Cosine) { - int i = (index + 1) / 2; - - if (index % 2 == 1) { - return sin(i * x); - } else { - return cos(i * x); - } - } else { - throw new IllegalStateException("That basis is not configured: " + this.basis); - } - } - - // Optimal bandwidth qsuggested by Bowman and Bowman and Azzalini (1997) q.31, - // using MAD. - private double h(double[] xCol) { - double[] g = new double[xCol.length]; - double median = median(xCol); - for (int j = 0; j < xCol.length; j++) g[j] = abs(xCol[j] - median); - double mad = median(g); - return (1.4826 * mad) * pow((4.0 / 3.0) / xCol.length, 0.2); - } - - private double kernelEpinechnikov(double z, double h) { - z /= getWidth() * h; - if (abs(z) > 1) return 0.0; - else return (/*0.75 **/ (1.0 - z * z)); - } - - private double kernelGaussian(double z, double h) { - z /= getWidth() * h; - return exp(-z * z); - } - - // Euclidean distance. - private double distance(double[][] data, int[] z, int i, int j) { - double sum = 0.0; - - for (int _z : z) { - double d = (data[_z][i] - data[_z][j]) / 2.0; - - if (!Double.isNaN(d)) { - sum += d * d; - } - } - - return sqrt(sum); - } - - // Standardizes the given data array. No need to make a copy here. - private double[] standardize(double[] data) { - double sum = 0.0; - - for (double d : data) { - sum += d; - } - - double mean = sum / data.length; - - for (int i = 0; i < data.length; i++) { - data[i] = data[i] - mean; - } - - double var = 0.0; - - for (double d : data) { - var += d * d; - } - - var /= (data.length); - double sd = sqrt(var); - - for (int i = 0; i < data.length; i++) { - data[i] /= sd; - } - - return data; - } - - private Set getCloseZs(double[][] _data, int[] _z, int i, int sampleSize, - List> reverseLookup, - List> sortedIndices) { - Set js = new HashSet<>(); - - if (sampleSize > _data[0].length) sampleSize = (int) ceil(0.8 * _data.length); - if (_z.length == 0) return new HashSet<>(); - - int radius = 0; - - while (true) { - for (int z1 : _z) { - int q = reverseLookup.get(z1).get(i); - - if (q - radius >= 0 && q - radius < _data[z1 + 1].length) { - int r2 = sortedIndices.get(z1).get(q - radius); - js.add(r2); - } - - if (q + radius >= 0 && q + radius < _data[z1 + 1].length) { - int r2 = sortedIndices.get(z1).get(q + radius); - js.add(r2); - } - } - - if (js.size() >= sampleSize) return js; - - radius++; - } - } - - private List getRows(DataSet dataSet, List allVars, Map nodesHash) { - List rows = new ArrayList<>(); - - K: - for (int k = 0; k < dataSet.getNumRows(); k++) { - for (Node node : allVars) { - if (Double.isNaN(dataSet.getDouble(k, nodesHash.get(node)))) continue K; - } - - rows.add(k); - } - - return rows; - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java index a59cc9bad6..fa136d74de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import javax.help.UnsupportedOperationException; import java.util.List; /** @@ -35,54 +36,100 @@ */ public class DagSepsets implements SepsetProducer { private final EdgeListGraph dag; - private boolean verbose; + /** + * Constructs a new DagSepsets object for the given DAG. + * @param dag the DAG. + */ public DagSepsets(Graph dag) { this.dag = new EdgeListGraph(dag); } + /** + * Returns the list of sepset for {a, b}. + * @param a One node. + * @param b The other node. + * @return The list of sepsets for {a, b}. + */ @Override public List getSepset(Node a, Node b) { return this.dag.getSepset(a, b); } + /** + * True iff i*-*j*-*k is an unshielded collider. + * @param i Node 1 + * @param j Node 2 + * @param k Node 3 + * @return True if the condition holds. + */ @Override public boolean isUnshieldedCollider(Node i, Node j, Node k) { List sepset = this.dag.getSepset(i, k); return sepset != null && !sepset.contains(j); } - @Override + + /** + * True iff i*-*j*-*k is an unshielded noncollider. + * @param i Node 1 + * @param j Node 2 + * @param k Node 3 + * @return True if the condition holds. + */ @Override public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { // return true; List sepset = this.dag.getSepset(i, k); return sepset != null && sepset.contains(j); } + /** + * Not implemented; required for an interface. + * @throws UnsupportedOperationException Since this is not implemented. + */ @Override public double getScore() { throw new UnsupportedOperationException(); } + /** + * Returns true just in case dsep(a, b | c) in the DAG. Don't let + * the name isIndependent fool you; this is a d-separation method. We + * only use the name isIndependent so that this can be used in place + * of an independence check. + * @param a Node 1 + * @param b NOde 2 + * @param c A set of conditoning nodes. + * @return True if the condition holds. + */ @Override public boolean isIndependent(Node a, Node b, List c) { return this.dag.paths().isDSeparatedFrom(a, b, c); } + /** + * Returns the nodes in the DAG. + * @return This list. + */ @Override public List getVariables() { return this.dag.getNodes(); } - public boolean isVerbose() { - return this.verbose; - } - + /** + * Thsi method is not used. + * @throws UnsupportedOperationException Since this method is not used (but is + * required by an interface). + */ @Override public void setVerbose(boolean verbose) { - this.verbose = verbose; + throw new UnsupportedOperationException("This method is not used for this class."); } + /** + * Returns the DAG being analyzed. + * @return This DAG. + */ public Graph getDag() { return this.dag; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagToPag.java index 22b37eafae..16c5405c7d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagToPag.java @@ -32,23 +32,15 @@ /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

- * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + * Converts a DAG (Directed acyclic graph) into the PAG (partial ancestral graph) + * which it is in the equivalence class of. * - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 - * @author Joseph Ramsey - * @author Choh-Man Teng + * @author josephramsey + * @author peterspirtes */ public final class DagToPag { private final Graph dag; -// private final IndTestDSep dsep; /* * The background knowledge. @@ -70,7 +62,6 @@ public final class DagToPag { */ private boolean verbose; private int maxPathLength = -1; - private Graph truePag; private boolean doDiscriminatingPathRule = true; private static final WeakHashMap history = new WeakHashMap<>(); @@ -85,6 +76,11 @@ public DagToPag(Graph dag) { //========================PUBLIC METHODS==========================// + /** + * This method does the convertion of DAG to PAG. + * + * @return Returns the converted PAG. + */ public Graph convert() { this.logger.log("info", "Starting DAG to PAG_of_the_true_DAG."); @@ -125,18 +121,83 @@ public Graph convert() { return graph; } + public static boolean existsInducingPathInto(Node x, Node y, Graph graph) { + if (x.getNodeType() != NodeType.MEASURED) throw new IllegalArgumentException(); + if (y.getNodeType() != NodeType.MEASURED) throw new IllegalArgumentException(); + + LinkedList path = new LinkedList<>(); + path.add(x); + + for (Node b : graph.getAdjacentNodes(x)) { + Edge edge = graph.getEdge(x, b); + if (edge.getProximalEndpoint(x) != Endpoint.ARROW) continue; +// if (!edge.pointsTowards(x)) continue; + + if (graph.paths().existsInducingPathVisit(x, b, x, y, path)) { + return true; + } + } + + return false; + } + + + public Knowledge getKnowledge() { + return this.knowledge; + } + + public void setKnowledge(Knowledge knowledge) { + if (knowledge == null) { + throw new NullPointerException(); + } + + this.knowledge = knowledge; + } + + /** + * @return true if Zhang's complete rule set should be used, false if only R1-R4 (the rule set of the original FCI) + * should be used. False by default. + */ + public boolean isCompleteRuleSetUsed() { + return this.completeRuleSetUsed; + } + + /** + * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule + * set of the original FCI) should be used. False by default. + */ + public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { + this.completeRuleSetUsed = completeRuleSetUsed; + } + + /** + * Setws whether verbose output should be printed. + * + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * Sets the maximum path length for some rules in the conversion. + * + * @param maxPathLength This length. + * @see FciOrient + */ + public void setMaxPathLength(int maxPathLength) { + this.maxPathLength = maxPathLength; + } + + public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { + this.doDiscriminatingPathRule = doDiscriminatingPathRule; + } + private Graph calcAdjacencyGraph() { List allNodes = this.dag.getNodes(); List measured = new ArrayList<>(allNodes); measured.removeIf(node -> node.getNodeType() == NodeType.LATENT); - -// for (Node node : allNodes) { -// if (node.getNodeType() == NodeType.MEASURED) { -// measured.add(node); -// } -// } - Graph graph = new EdgeListGraph(measured); for (int i = 0; i < measured.size(); i++) { @@ -209,108 +270,7 @@ private boolean foundCollider(Graph dag, Node a, Node b, Node c) { boolean ipba = DagToPag.existsInducingPathInto(b, a, dag); boolean ipbc = DagToPag.existsInducingPathInto(b, c, dag); - if (!(ipba && ipbc)) { - printTrueDefCollider(a, b, c, false); - return false; - } - - printTrueDefCollider(a, b, c, true); - - return true; - } - - private void printTrueDefCollider(Node a, Node b, Node c, boolean found) { - if (this.truePag != null) { - boolean defCollider = this.truePag.isDefCollider(a, b, c); - - if (this.verbose) { - if (!found && defCollider) { - System.out.println("FOUND COLLIDER FCI"); - } else if (found && !defCollider) { - System.out.println("DIDN'T FIND COLLIDER FCI"); - } - } - } - } - - public static boolean existsInducingPathInto(Node x, Node y, Graph graph) { - if (x.getNodeType() != NodeType.MEASURED) throw new IllegalArgumentException(); - if (y.getNodeType() != NodeType.MEASURED) throw new IllegalArgumentException(); - - LinkedList path = new LinkedList<>(); - path.add(x); - - for (Node b : graph.getAdjacentNodes(x)) { - Edge edge = graph.getEdge(x, b); - if (edge.getProximalEndpoint(x) != Endpoint.ARROW) continue; -// if (!edge.pointsTowards(x)) continue; - - if (graph.paths().existsInducingPathVisit(x, b, x, y, path)) { - return true; - } - } - - return false; - } - - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException(); - } - - this.knowledge = knowledge; - } - - /** - * @return true if Zhang's complete rule set should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. - */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; - } - - /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule - * set of the original FCI) should be used. False by default. - */ - public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { - this.completeRuleSetUsed = completeRuleSetUsed; - } - - /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public int getMaxPathLength() { - return this.maxPathLength; - } - - public void setMaxPathLength(int maxPathLength) { - this.maxPathLength = maxPathLength; - } - - public Graph getTruePag() { - return this.truePag; - } - - public void setTruePag(Graph truePag) { - this.truePag = truePag; - } - - public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { - this.doDiscriminatingPathRule = doDiscriminatingPathRule; + return ipba && ipbc; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java index 8764e68b1b..3cd04cfdfa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java @@ -92,7 +92,7 @@ public IndTestConditionalCorrelation(DataSet dataSet, double alpha) { this.variables = Collections.unmodifiableList(nodes); - this.cci = new ConditionalCorrelationIndependence(dataSet, alpha); + this.cci = new ConditionalCorrelationIndependence(dataSet); this.alpha = alpha; this.dataSet = dataSet; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelationLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelationLingam.java deleted file mode 100644 index 022c195de1..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelationLingam.java +++ /dev/null @@ -1,212 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.IndependenceFact; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.NumberFormatUtil; -import edu.cmu.tetrad.util.TetradLogger; - -import java.text.NumberFormat; -import java.util.Collections; -import java.util.List; - -/** - * Checks conditional independence of variable in a continuous data set using a conditional correlation test - * for the nonlinear nonGaussian case. - * - * @author Joseph Ramsey - */ -public final class IndTestConditionalCorrelationLingam implements IndependenceTest { - - /** - * The instance of CCI that is wrapped. - */ - private final ConditionalCorrelationIndependenceLingam cci; - - /** - * The variables of the covariance data, in order. (Unmodifiable list.) - */ - private final List variables; - - /** - * The significance level of the independence tests. - */ - private double alpha; - - /** - * Formats as 0.0000. - */ - private static final NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); - - /** - * Stores a reference to the data set passed in through the constructor. - */ - private final DataSet dataSet; - - /** - * True if verbose output should be printed. - */ - private boolean verbose; - private double score = Double.NaN; - - //==========================CONSTRUCTORS=============================// - - /** - * Constructs a new Independence test which checks independence facts based on the correlation data implied by the - * given data set (must be continuous). The given significance level is used. - * - * @param dataSet A data set containing only continuous columns. - * @param alpha The q level of the test. - */ - public IndTestConditionalCorrelationLingam(DataSet dataSet, double alpha) { - if (!(dataSet.isContinuous())) { - throw new IllegalArgumentException("Data set must be continuous."); - } - - if (!(alpha >= 0 && alpha <= 1)) { - throw new IllegalArgumentException("Q mut be in [0, 1]"); - } - - List nodes = dataSet.getVariables(); - - this.variables = Collections.unmodifiableList(nodes); - - this.cci = new ConditionalCorrelationIndependenceLingam(dataSet, alpha); - this.alpha = alpha; - this.dataSet = dataSet; - } - - //==========================PUBLIC METHODS=============================// - - /** - * Creates a new IndTestCramerT instance for a subset of the variables. - */ - public IndependenceTest indTestSubset(List vars) { - throw new UnsupportedOperationException(); - } - - public IndependenceResult checkIndependence(Node x, Node y, List z) { - - double score = this.cci.isIndependent(x, y, z); - this.score = score; - double p = this.cci.getPValue(score); - - System.out.println("p " + p); - - boolean independent = p > this.alpha; - -// if (this.verbose) { - if (independent) { - TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, p)); - } -// } - - return new IndependenceResult(new IndependenceFact(x, y, z), independent, p); - } - - public double getPValue() { - return this.cci.getPValue(); - } - - /** - * Sets the significance level at which independence judgments should be made. Affects the cutoff for partial - * correlations to be considered statistically equal to zero. - */ - public void setAlpha(double alpha) { - if (alpha < 0.0 || alpha > 1.0) { - throw new IllegalArgumentException("Significance out of range."); - } - - this.alpha = alpha; - this.cci.setAlpha(alpha); - } - - /** - * Gets the getModel significance level. - */ - public double getAlpha() { - return this.alpha; - } - - /** - * @return the list of variables over which this independence checker is capable of determinine independence - * relations-- that is, all the variables in the given graph or the given data set. - */ - public List getVariables() { - return this.variables; - } - - - /** - * If isDeterminismAllowed(), deters to IndTestFisherZD; otherwise throws - * UnsupportedOperationException. - */ - public boolean determines(List z, Node x) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - /** - * @return the data set being analyzed. - */ - public DataSet getData() { - return this.dataSet; - } - - - @Override - public double getScore() { - return this.score; - } - - /** - * @return a string representation of this test. - */ - public String toString() { - return "Conditional Correlation, q = " + IndTestConditionalCorrelationLingam.nf.format(getAlpha()); - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setNumFunctions(int numFunctions) { - this.cci.setNumFunctions(numFunctions); - } - - public double getWeight() { - return this.cci.getWidth(); - } - - public void setBasis(ConditionalCorrelationIndependenceLingam.Basis basis) { - this.cci.setBasis(basis); - } -} - - - From c2d454e791dc0374d5abbf49b8384eacf853dcc0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 00:17:28 -0400 Subject: [PATCH 134/464] Fixing documentation etc. --- .../search/ConditionalGaussianLikelihood.java | 87 ++++++++++--------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java index 3dbbecda45..230a8aa296 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java @@ -39,8 +39,8 @@ import static org.apache.commons.math3.util.FastMath.log; /** - * Implements a conditional Gaussian likelihood. Please note that this this likelihood will be maximal only if the - * the continuous mixedVariables are jointly Gaussian conditional on the discrete mixedVariables; in all other cases, it will + * Implements a conditional Gaussian likelihood. Please note that this likelihood will be maximal only if the + * continuous mixedVariables are jointly Gaussian conditional on the discrete mixedVariables; in all other cases, it will * be less than maximal. For an algorithm like FGS this is fine. * * @author Joseph Ramsey @@ -147,47 +147,6 @@ public ConditionalGaussianLikelihood(DataSet dataSet) { for (int i = 0; i < dataSet.getNumRows(); i++) this.rows.add(i); } - private DataSet useErsatzVariables() { - List nodes = new ArrayList<>(); - int numCategories = this.numCategoriesToDiscretize; - - for (Node x : this.mixedVariables) { - if (x instanceof ContinuousVariable) { - nodes.add(new DiscreteVariable(x.getName(), numCategories)); - } else { - nodes.add(x); - } - } - - DataSet replaced = new BoxDataSet(new VerticalIntDataBox(this.mixedDataSet.getNumRows(), this.mixedDataSet.getNumColumns()), nodes); - - for (int j = 0; j < this.mixedVariables.size(); j++) { - if (this.mixedVariables.get(j) instanceof DiscreteVariable) { - for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { - replaced.setInt(i, j, this.mixedDataSet.getInt(i, j)); - } - } else { - double[] column = this.continuousData[j]; - - double[] breakpoints = getEqualFrequencyBreakPoints(column, numCategories); - - List categoryNames = new ArrayList<>(); - - for (int i = 0; i < numCategories; i++) { - categoryNames.add("" + i); - } - - Discretization d = discretize(column, breakpoints, this.mixedVariables.get(j).getName(), categoryNames); - - for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { - replaced.setInt(i, j, d.getData()[i]); - } - } - } - - return replaced; - } - /** * Returns the likelihood of variable i conditional on the given parents, assuming the continuous mixedVariables * index by i or by the parents are jointly Gaussian conditional on the discrete comparison. @@ -243,6 +202,48 @@ public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { this.numCategoriesToDiscretize = numCategoriesToDiscretize; } + private DataSet useErsatzVariables() { + List nodes = new ArrayList<>(); + int numCategories = this.numCategoriesToDiscretize; + + for (Node x : this.mixedVariables) { + if (x instanceof ContinuousVariable) { + nodes.add(new DiscreteVariable(x.getName(), numCategories)); + } else { + nodes.add(x); + } + } + + DataSet replaced = new BoxDataSet(new VerticalIntDataBox(this.mixedDataSet.getNumRows(), this.mixedDataSet.getNumColumns()), nodes); + + for (int j = 0; j < this.mixedVariables.size(); j++) { + if (this.mixedVariables.get(j) instanceof DiscreteVariable) { + for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { + replaced.setInt(i, j, this.mixedDataSet.getInt(i, j)); + } + } else { + double[] column = this.continuousData[j]; + + double[] breakpoints = getEqualFrequencyBreakPoints(column, numCategories); + + List categoryNames = new ArrayList<>(); + + for (int i = 0; i < numCategories; i++) { + categoryNames.add("" + i); + } + + Discretization d = discretize(column, breakpoints, this.mixedVariables.get(j).getName(), categoryNames); + + for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { + replaced.setInt(i, j, d.getData()[i]); + } + } + } + + return replaced; + } + + // The likelihood of the joint over all of these mixedVariables, assuming conditional Gaussian, // continuous and discrete. private Ret likelihoodJoint(List X, List A, Node target, List rows) { From 694a6681d70113e7e2bc5cfdb9cc1348cbe0c62d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 00:22:32 -0400 Subject: [PATCH 135/464] Fixing documentation etc. --- .../tetrad/performance/PerformanceTests.java | 4 +- .../main/java/edu/cmu/tetrad/search/Cpc.java | 8 +- .../java/edu/cmu/tetrad/search/CpcStable.java | 377 ------------------ 3 files changed, 9 insertions(+), 380 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTests.java index 29b752821e..5997f11158 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTests.java @@ -509,10 +509,10 @@ public void testCpcStable(int numVars, double edgeFactor, int numCases, double a IndTestFisherZ test = new IndTestFisherZ(cov, alpha); - CpcStable cpcStable = new CpcStable(test); + Cpc cpcStable = new Cpc(test); + cpcStable.setStable(true); cpcStable.setVerbose(false); cpcStable.setDepth(depth); - cpcStable.setOut(this.out); Graph outGraph = cpcStable.search(); 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 2a2d7b13e0..e5871f03fe 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 @@ -98,7 +98,7 @@ public final class Cpc implements GraphSearch { private boolean stable; private boolean useHeuristic = false; private int maxPPathLength = -1; - private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; + private final PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; //=============================CONSTRUCTORS==========================// @@ -125,6 +125,7 @@ public boolean isAggressivelyPreventCycles() { /** * Sets to true just in case edges will not be added if they would create cycles. + * @param aggressivelyPreventCycles True if so. */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { this.aggressivelyPreventCycles = aggressivelyPreventCycles; @@ -133,6 +134,7 @@ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { /** * Sets the maximum number of variables conditioned on in any conditional independence test. If set to -1, the value * of 1000 will be used. May not be set to Integer.MAX_VALUE, due to a Java bug on multi-core systems. + * @param depth This maximum. */ public void setDepth(int depth) { if (depth < -1) { @@ -283,6 +285,10 @@ public Graph search() { TetradLogger.getInstance().log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); TetradLogger.getInstance().log("info", "Finishing CPC algorithm."); + this.colliderTriples = search.getColliderTriples(); + this.noncolliderTriples = search.getNoncolliderTriples(); + this.ambiguousTriples = search.getAmbiguousTriples(); + logTriples(); TetradLogger.getInstance().flush(); 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 deleted file mode 100644 index 3de5fe6b38..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java +++ /dev/null @@ -1,377 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.TetradLogger; -import org.apache.commons.math3.util.FastMath; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested - * locally. Uses the PC-Stable adjacency search. - * - * @author Joseph Ramsey (this version). - */ -public final class CpcStable implements GraphSearch { - - /** - * The independence test used for the PC search. - */ - private final IndependenceTest independenceTest; - - /** - * Forbidden and required edges for the search. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * The maximum number of nodes conditioned on in the search. - */ - private int depth = 1000; - - private Graph graph; - - /** - * Elapsed time of last search. - */ - private long elapsedTime; - - /** - * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large - * graphs). - */ - private boolean aggressivelyPreventCycles; - - /** - * The logger for this class. The config needs to be set. - */ - private final TetradLogger logger = TetradLogger.getInstance(); - - /** - * The sepsets. - */ - private SepsetMap sepsets; - - /** - * Whether verbose output about independencies is output. - */ - private boolean verbose; - private PrintStream out = System.out; - - //=============================CONSTRUCTORS==========================// - - /** - * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the - * independence test, for fear of duplicating the data set! - */ - public CpcStable(IndependenceTest independenceTest) { - if (independenceTest == null) { - throw new NullPointerException(); - } - - this.independenceTest = independenceTest; - } - - //==============================PUBLIC METHODS========================// - - /** - * @return true just in case edges will not be added if they would create cycles. - */ - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - - /** - * Sets to true just in case edges will not be added if they would create cycles. - */ - public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { - this.aggressivelyPreventCycles = aggressivelyPreventCycles; - } - - /** - * Sets the maximum number of variables conditioned on in any conditional independence test. If set to -1, the value - * of 1000 will be used. May not be set to Integer.MAX_VALUE, due to a Java bug on multi-core systems. - */ - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException("Depth must be -1 or >= 0: " + depth); - } - - if (depth == Integer.MAX_VALUE) { - throw new IllegalArgumentException("Depth must not be Integer.MAX_VALUE, " + - "due to a known bug."); - } - - this.depth = depth; - } - - /** - * @return the elapsed time of search in milliseconds, after search() has been run. - */ - public long getElapsedTime() { - return this.elapsedTime; - } - - /** - * @return the knowledge specification used in the search. Non-null. - */ - public Knowledge getKnowledge() { - return this.knowledge; - } - - /** - * Sets the knowledge specification used in the search. Non-null. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - /** - * @return the independence test used in the search, set in the constructor. This is not returning a copy, for fear - * of duplicating the data set! - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - /** - * @return the depth of the search--that is, the maximum number of variables conditioned on in any conditional - * independence test. - */ - public int getDepth() { - return this.depth; - } - - public Set getAdjacencies() { - return new HashSet<>(this.graph.getEdges()); - } - - public Set getNonadjacencies() { - Graph complete = GraphUtils.completeGraph(this.graph); - Set nonAdjacencies = complete.getEdges(); - Graph undirected = GraphUtils.undirectedGraph(this.graph); - nonAdjacencies.removeAll(undirected.getEdges()); - return new HashSet<>(nonAdjacencies); - } - - /** - * Runs PC starting with a fully connected graph over all of the variables in the domain of the independence test. - * See PC for caveats. The number of possible cycles and bidirected edges is far less with CPC than with PC. - */ - public Graph search() { - return search(this.independenceTest.getVariables()); - } - - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - this.graph = new EdgeListGraph(nodes); - - - Fas fas = new Fas(getIndependenceTest()); - fas.setStable(true); - fas.setOut(this.out); - return search(fas, nodes); - } - - public Graph search(IFas fas, List nodes) { - this.logger.log("info", "Starting CPC Stable algorithm"); - this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); - -// this.logger.log("info", "Variables " + independenceTest.getVariable()); - - long startTime = MillisecondTimes.timeMillis(); - - List allNodes = getIndependenceTest().getVariables(); - if (!allNodes.containsAll(nodes)) { - throw new IllegalArgumentException("All of the given nodes must " + - "be in the domain of the independence test provided."); - } - - - fas.setKnowledge(getKnowledge()); - fas.setDepth(getDepth()); - fas.setVerbose(this.verbose); - fas.setOut(this.out); - - // Note that we are ignoring the sepset map returned by this method - // on purpose; it is not used in this search. - this.graph = fas.search(); - this.sepsets = fas.getSepsets(); - - if (this.verbose) { - this.out.println("CPC orientation..."); - } - - SearchGraphUtils.pcOrientbk(this.knowledge, getGraph(), nodes); - -// orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); - orientUnshieldedTriples(this.knowledge); - - MeekRules meekRules = new MeekRules(); - meekRules.setOut(this.out); - - meekRules.orientImplied(getGraph()); - - long endTime = MillisecondTimes.timeMillis(); - this.elapsedTime = endTime - startTime; - - TetradLogger.getInstance().log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); - TetradLogger.getInstance().log("info", "Finishing CPC algorithm."); - - TetradLogger.getInstance().flush(); - return getGraph(); - } - - //==========================PRIVATE METHODS===========================// - - private void orientUnshieldedTriples(Knowledge knowledge) { - TetradLogger.getInstance().log("info", "Starting Collider Orientation:"); - - List nodes = this.graph.getNodes(); - - for (Node y : nodes) { - List adjacentNodes = this.graph.getAdjacentNodes(y); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node x = adjacentNodes.get(combination[0]); - Node z = adjacentNodes.get(combination[1]); - - if (this.graph.isAdjacentTo(x, z)) { - continue; - } - - List> sepsetsxz = getSepsets(x, z, this.graph); - - if (isColliderSepset(y, sepsetsxz)) { - if (colliderAllowed(x, y, z, knowledge)) { - this.graph.setEndpoint(x, y, Endpoint.ARROW); - this.graph.setEndpoint(z, y, Endpoint.ARROW); - - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); - } - } else { - Triple triple = new Triple(x, y, z); - this.graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); - } - } - } - - TetradLogger.getInstance().log("info", "Finishing Collider Orientation."); - } - - private List> getSepsets(Node i, Node k, Graph g) { - List adji = g.getAdjacentNodes(i); - List adjk = g.getAdjacentNodes(k); - List> sepsets = new ArrayList<>(); - - for (int d = 0; d <= FastMath.max(adji.size(), adjk.size()); d++) { - if (adji.size() >= 2 && d <= adji.size()) { - ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d); - int[] choice; - - while ((choice = gen.next()) != null) { - List v = GraphUtils.asList(choice, adji); - if (getIndependenceTest().checkIndependence(i, k, v).independent()) sepsets.add(v); - } - } - - if (adjk.size() >= 2 && d <= adjk.size()) { - ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d); - int[] choice; - - while ((choice = gen.next()) != null) { - List v = GraphUtils.asList(choice, adjk); - if (getIndependenceTest().checkIndependence(i, k, v).independent()) sepsets.add(v); - } - } - } - - return sepsets; - } - - - private boolean isColliderSepset(Node j, List> sepsets) { - if (sepsets.isEmpty()) return false; - - for (List sepset : sepsets) { - if (sepset.contains(j)) return false; - } - - return true; - } - - private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return CpcStable.isArrowpointAllowed1(x, y, knowledge) && - CpcStable.isArrowpointAllowed1(z, y, knowledge); - } - - public static boolean isArrowpointAllowed1(Node from, Node to, - Knowledge knowledge) { - return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - - public SepsetMap getSepsets() { - return this.sepsets; - } - - /** - * The graph that's constructed during the search. - */ - public Graph getGraph() { - return this.graph; - } - - public void setGraph(Graph graph) { - this.graph = graph; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setOut(PrintStream out) { - this.out = out; - } - - public PrintStream getOut() { - return this.out; - } -} - - From 21095366816cae7522764479552ba10df58fff16 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 00:32:23 -0400 Subject: [PATCH 136/464] Fixing documentation etc. --- .../algorithm/oracle/pattern/Cstar.java | 4 +- .../java/edu/cmu/tetrad/search/Cstar.java | 294 ++++++++++-------- .../java/edu/cmu/tetrad/test/TestGrasp.java | 1 - 3 files changed, 160 insertions(+), 139 deletions(-) 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 index 4a7b0bbc15..0328100d9d 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 @@ -10,7 +10,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Cstar.PatternAlgorithm; +import edu.cmu.tetrad.search.Cstar.CpdagAlgorithm; import edu.cmu.tetrad.search.Cstar.SampleStyle; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -46,7 +46,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { cStaR.setqTo(parameters.getInt(Params.CSTAR_Q)); cStaR.setSelectionAlpha(parameters.getDouble(Params.SELECTION_MIN_EFFECT)); cStaR.setqIncrement(1); - cStaR.setPatternAlgorithm(PatternAlgorithm.PC_STABLE); + cStaR.setCpdagAlgorithm(CpdagAlgorithm.PC_STABLE); cStaR.setSampleStyle(SampleStyle.SPLIT); cStaR.setVerbose(parameters.getBoolean(Params.VERBOSE)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index 8807ba8133..744f63df17 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -34,13 +34,21 @@ public class Cstar { private int qIncrement = 1; private double selectionAlpha = 0.0; private IndependenceTest test; - private PatternAlgorithm patternAlgorithm = PatternAlgorithm.PC_STABLE; + private CpdagAlgorithm cpdagAlgorithm = CpdagAlgorithm.PC_STABLE; private SampleStyle sampleStyle = SampleStyle.BOOTSTRAP; private boolean verbose; + /** + * Constructs a new object. + */ public Cstar() { } + /** + * Returns a list of of records for making a CSTaR table. + * @param allRecords the list of all records. + * @return The list for the CSTaR table. + */ public static LinkedList cStar(LinkedList> allRecords) { Map> map = new HashMap<>(); @@ -83,16 +91,6 @@ public static LinkedList cStar(LinkedList> allRecords return cstar; } - // Meinhausen and Buhlmann E(|V|) bound - private static double er(double pi, double q, double p) { - return p * Cstar.pcer(pi, q, p); - } - - // Meinhausen and Buhlmann per comparison error rate (PCER) - private static double pcer(double pi, double q, double p) { - return (q * q) / (p * p * (2 * pi - 1)); - } - public void setParallelized(boolean parallelized) { this.parallelized = parallelized; } @@ -187,7 +185,7 @@ public LinkedList> getRecords(DataSet dataSet, List pos for (int t = 0; t < possibleEffects.size(); t++) { minimalEffects.add(new ConcurrentHashMap<>()); - for (int b = 0; b < getNumSubsamples(); b++) { + for (int b = 0; b < this.numSubsamples; b++) { Map map = new ConcurrentHashMap<>(); for (Node node : possibleCauses) map.put(node, 0.0); minimalEffects.get(t).put(b, map); @@ -238,14 +236,14 @@ public double[][] call() { } if (pattern == null || effects == null) { - if (Cstar.this.patternAlgorithm == PatternAlgorithm.FGES) { + if (Cstar.this.cpdagAlgorithm == CpdagAlgorithm.FGES) { pattern = getPatternFges(sample); - } else if (Cstar.this.patternAlgorithm == PatternAlgorithm.PC_STABLE) { + } else if (Cstar.this.cpdagAlgorithm == CpdagAlgorithm.PC_STABLE) { pattern = getPatternPcStable(sample); - } else if (Cstar.this.patternAlgorithm == PatternAlgorithm.GRaSP) { + } else if (Cstar.this.cpdagAlgorithm == CpdagAlgorithm.GRaSP) { pattern = getPatternPcStable(sample); } else { - throw new IllegalArgumentException("That type of of pattern algorithm is not configured: " + Cstar.this.patternAlgorithm); + throw new IllegalArgumentException("That type of of pattern algorithm is not configured: " + Cstar.this.cpdagAlgorithm); } edgesTotal[0] += pattern.getNumEdges(); @@ -283,7 +281,7 @@ public double[][] call() { List> tasks = new ArrayList<>(); - for (int k = 0; k < getNumSubsamples(); k++) { + for (int k = 0; k < this.numSubsamples; k++) { tasks.add(new Task(k, possibleCauses, possibleEffects, dataSet)); } @@ -296,9 +294,8 @@ public double[][] call() { List> doubles = new ArrayList<>(); -// List allDoubles = new ArrayList<>(); - for (int k = 0; k < getNumSubsamples(); k++) { + for (int k = 0; k < this.numSubsamples; k++) { double[][] effects = allEffects.get(k); if (effects.length != possibleCauses.size() || effects[0].length != possibleEffects.size()) { @@ -340,7 +337,7 @@ public Boolean call() { for (int c = 0; c < this.possibleCauses.size(); c++) { int count = 0; - for (int k = 0; k < getNumSubsamples(); k++) { + for (int k = 0; k < Cstar.this.numSubsamples; k++) { if (this.q > doubles.get(k).size()) { continue; } @@ -352,13 +349,11 @@ public Boolean call() { } } -// if (count > 0) { - double pi = count / ((double) getNumSubsamples()); + double pi = count / ((double) Cstar.this.numSubsamples); if (pi < (this.q / (double) p)) continue; Node cause = this.possibleCauses.get(c); Node effect = this.possibleEffects.get(e); tuples.add(new Tuple(cause, effect, pi, avgMinEffect(this.possibleCauses, this.possibleEffects, allEffects, cause, effect))); -// } } } @@ -406,6 +401,144 @@ public Boolean call() { return allRecords; } + /** + * Makes a graph of the estimated predictors to the effect. + */ + public Graph makeGraph(List records) { + List outNodes = new ArrayList<>(); + + Graph graph = new EdgeListGraph(outNodes); + + for (Record record : records) { + graph.addNode(record.getCauseNode()); + graph.addNode(record.getEffectNode()); + graph.addDirectedEdge(record.getCauseNode(), record.getEffectNode()); + } + + return graph; + } + + // A single record in the returned table. + public static class Record implements TetradSerializable { + static final long serialVersionUID = 23L; + + private final Node causeNode; + private final Node target; + private final double pi; + private final double effect; + private final int q; + private final int p; + + Record(Node predictor, Node target, double pi, double minEffect, int q, int p) { + this.causeNode = predictor; + this.target = target; + this.pi = pi; + this.effect = minEffect; + this.q = q; + this.p = p; + } + + public Node getCauseNode() { + return this.causeNode; + } + + public Node getEffectNode() { + return this.target; + } + + public double getPi() { + return this.pi; + } + + double getMinBeta() { + return this.effect; + } + + public int getQ() { + return this.q; + } + + public int getP() { + return this.p; + } + } + + /** + * Sets qFrom. + * @param qFrom This integer. + */ + public void setqFrom(int qFrom) { + this.qFrom = qFrom; + } + + /** + * Sets qTo. + * @param qTo This integer. + */ + public void setqTo(int qTo) { + this.qTo = qTo; + } + + /** + * Sets q increment. + * @param qIncrement This integer. + */ + public void setqIncrement(int qIncrement) { + this.qIncrement = qIncrement; + } + + /** + * The CSTaR algorithm can use any CPDAG algorithm; here you can set it. + * @param cpdagAlglorithm The CPDAG algorithm. + * @see CpdagAlgorithm + */ + public void setCpdagAlgorithm(CpdagAlgorithm cpdagAlglorithm) { + this.cpdagAlgorithm = cpdagAlglorithm; + } + + /** + * Sets whether verbose output will be printed. + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * Sets the selection alpha. + * @param selectionAlpha This alpha. + */ + public void setSelectionAlpha(double selectionAlpha) { + this.selectionAlpha = selectionAlpha; + } + + /** + * Sets the sample style. + * @param sampleStyle This style. + * @see SampleStyle + */ + public void setSampleStyle(SampleStyle sampleStyle) { + this.sampleStyle = sampleStyle; + } + + /** + * Sets the number of subsamples. + * @param numSubsamples This number. + */ + public void setNumSubsamples(int numSubsamples) { + this.numSubsamples = numSubsamples; + } + + // Meinhausen and Buhlmann E(|V|) bound + private static double er(double pi, double q, double p) { + return p * Cstar.pcer(pi, q, p); + } + + // Meinhausen and Buhlmann per comparison error rate (PCER) + private static double pcer(double pi, double q, double p) { + return (q * q) / (p * p * (2 * pi - 1)); + } + private DataSet readData(File dir) { try { DataSet dataSet = SimpleDataLoader.loadContinuousData(new File(dir, "data.txt"), "//", '*', "*", true, Delimiter.TAB); @@ -470,7 +603,7 @@ private double avgMinEffect(List possibleCauses, List possibleEffect throw new NullPointerException("effects null"); } - for (int k = 0; k < getNumSubsamples(); k++) { + for (int k = 0; k < this.numSubsamples; k++) { int c = possibleCauses.indexOf(causeNode); int e = possibleEffects.indexOf(effectNode); f.add(allEffects.get(k)[c][e]); @@ -495,10 +628,8 @@ public String makeTable(LinkedList records, boolean printTable) { table.setToken(0, column++, "Index"); table.setToken(0, column++, "Cause"); table.setToken(0, column++, "Effect"); -// table.setToken(0, column++, "Type"); table.setToken(0, column++, "PI"); table.setToken(0, column++, "Effect"); -// table.setToken(0, column++, "SUM(Pi)"); table.setToken(0, column++, "R-SUM(Pi)"); table.setToken(0, column++, "E(V)"); table.setToken(0, column, "PCER"); @@ -524,10 +655,8 @@ public String makeTable(LinkedList records, boolean printTable) { table.setToken(i + 1, column++, "" + (i + 1)); table.setToken(i + 1, column++, cause.getName()); table.setToken(i + 1, column++, effect.getName()); -// table.setToken(i + 1, column++, cause instanceof DiscreteVariable ? "D" : "C"); table.setToken(i + 1, column++, nf.format(records.get(i).getPi())); table.setToken(i + 1, column++, nf.format(records.get(i).getMinBeta())); -// table.setToken(i + 1, column++, nf.format(sumPi)); table.setToken(i + 1, column++, nf.format(R - sumPi)); double er = Cstar.er(records.get(i).getPi(), (i + 1), p); table.setToken(i + 1, column++, records.get(i).getPi() <= 0.5 ? "*" : nf.format(er)); @@ -539,59 +668,6 @@ public String makeTable(LinkedList records, boolean printTable) { return (printTable ? "\n" + table : "" + "") + "p = " + p + " q = " + q + (printTable ? " Type: C = continuous, D = discrete\n" : ""); } - /** - * Makes a graph of the estimated predictors to the effect. - */ - public Graph makeGraph(List records) { - List outNodes = new ArrayList<>(); - - Graph graph = new EdgeListGraph(outNodes); - - for (Record record : records) { - graph.addNode(record.getCauseNode()); - graph.addNode(record.getEffectNode()); - graph.addDirectedEdge(record.getCauseNode(), record.getEffectNode()); - } - - return graph; - } - - public void setqFrom(int qFrom) { - this.qFrom = qFrom; - } - - public void setqTo(int qTo) { - this.qTo = qTo; - } - - public void setqIncrement(int qIncrement) { - this.qIncrement = qIncrement; - } - - public void setPatternAlgorithm(PatternAlgorithm patternAlgorithm) { - this.patternAlgorithm = patternAlgorithm; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setSelectionAlpha(double selectionAlpha) { - this.selectionAlpha = selectionAlpha; - } - - public void setSampleStyle(SampleStyle sampleStyle) { - this.sampleStyle = sampleStyle; - } - - private int getNumSubsamples() { - return this.numSubsamples; - } - - public void setNumSubsamples(int numSubsamples) { - this.numSubsamples = numSubsamples; - } - private Graph getPatternPcStable(DataSet sample) { IndependenceTest test = getIndependenceTest(sample, this.test); test.setVerbose(false); @@ -600,16 +676,6 @@ private Graph getPatternPcStable(DataSet sample) { return pc.search(); } - private Graph getPatternGRaSP(DataSet sample) { - test.setVerbose(false); - Grasp alg = new Grasp(new SemBicScore(sample)); - alg.setVerbose(false); - alg.bestOrder(sample.getVariables()); - return alg.getGraph(true); - } - - //=============================PRIVATE==============================// - private Graph getPatternFges(DataSet sample) { Score score = new ScoredIndTest(getIndependenceTest(sample, this.test)); Fges fges = new Fges(score); @@ -695,7 +761,7 @@ private List runCallablesDoubleArray(List> task return results; } - public enum PatternAlgorithm {FGES, PC_STABLE, GRaSP} + public enum CpdagAlgorithm {FGES, PC_STABLE, GRaSP} public enum SampleStyle {BOOTSTRAP, SPLIT} @@ -729,48 +795,4 @@ public double getMinBeta() { } } - // A single record in the returned table. - public static class Record implements TetradSerializable { - static final long serialVersionUID = 23L; - - private final Node causeNode; - private final Node target; - private final double pi; - private final double effect; - private final int q; - private final int p; - - Record(Node predictor, Node target, double pi, double minEffect, int q, int p) { - this.causeNode = predictor; - this.target = target; - this.pi = pi; - this.effect = minEffect; - this.q = q; - this.p = p; - } - - public Node getCauseNode() { - return this.causeNode; - } - - public Node getEffectNode() { - return this.target; - } - - public double getPi() { - return this.pi; - } - - double getMinBeta() { - return this.effect; - } - - public int getQ() { - return this.q; - } - - public int getP() { - return this.p; - } - } } \ No newline at end of file diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 4bb552fee9..ad9be75897 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -68,7 +68,6 @@ import java.text.NumberFormat; import java.util.*; -import static edu.cmu.tetrad.search.Cstar.PatternAlgorithm.GRaSP; import static edu.cmu.tetrad.search.OtherPermAlgs.Method.SP; import static edu.cmu.tetrad.util.RandomUtil.shuffle; From e664fe98da76770684be18099ed67432d06c054f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 01:01:34 -0400 Subject: [PATCH 137/464] Fixing documentation etc. --- .../algcomparison/algorithm/cluster/Bpc.java | 1 - .../algcomparison/algorithm/other/Glasso.java | 2 +- .../java/edu/cmu/tetrad/search/FaskVote.java | 17 ++- .../java/edu/cmu/tetrad/search/Glasso.java | 119 ++++++------------ .../main/java/edu/cmu/tetrad/util/Vector.java | 6 + 5 files changed, 57 insertions(+), 88 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index b94f104b8c..bfa4086a3b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -1,7 +1,6 @@ package edu.cmu.tetrad.algcomparison.algorithm.cluster; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.annotation.AlgType; import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.*; 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 index 5530be2377..d945fddc1a 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 @@ -49,7 +49,7 @@ public Graph search(DataModel ds, Parameters parameters) { } if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - DoubleMatrix2D cov = new DenseDoubleMatrix2D(SimpleDataLoader.getContinuousDataSet(ds) + Matrix cov = new Matrix(SimpleDataLoader.getContinuousDataSet(ds) .getCovarianceMatrix().toArray()); edu.cmu.tetrad.search.Glasso glasso = new edu.cmu.tetrad.search.Glasso(cov); 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 7935500830..f01980feb4 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 @@ -21,14 +21,17 @@ * @author Joseph Ramsey 9/5/2020 */ public class FaskVote { - private final IndependenceWrapper test; private ScoreWrapper score = new SemBicScore(); - // Knowledge the search will obey, of forbidden and required edges. private Knowledge knowledge = new Knowledge(); - private final List dataSets; + /** + * Constructor. + * @param dataSets The datasets being searched over. A composite graph will be generated. + * @param score The score to use. + * @param test The test to use. + */ public FaskVote(List dataSets, ScoreWrapper score, IndependenceWrapper test) { this.dataSets = dataSets; this.score = score; @@ -37,6 +40,12 @@ public FaskVote(List dataSets, ScoreWrapper score, IndependenceWrapper //======================================== PUBLIC METHODS ====================================// + /** + * Does the search. + * @param parameters The parameers. + * @return The composite graph. + * @see Parameters + */ public Graph search(Parameters parameters) { List _dataSets = new ArrayList<>(); @@ -126,6 +135,6 @@ public Graph search(Parameters parameters) { * @param knowledge Knowledge of forbidden and required edges. */ public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Glasso.java index 8db248ff29..cc147db4a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Glasso.java @@ -21,13 +21,8 @@ package edu.cmu.tetrad.search; -import cern.colt.matrix.DoubleMatrix1D; -import cern.colt.matrix.DoubleMatrix2D; -import cern.colt.matrix.impl.DenseDoubleMatrix1D; -import cern.colt.matrix.impl.DenseDoubleMatrix2D; -import cern.colt.matrix.linalg.Algebra; -import cern.jet.math.Mult; -import cern.jet.math.PlusMult; +import edu.cmu.tetrad.util.Matrix; +import edu.cmu.tetrad.util.Vector; import org.apache.commons.math3.util.FastMath; /** @@ -45,7 +40,7 @@ public class Glasso { /** * Data covariance matrix. */ - private DoubleMatrix2D ss; + private final Matrix ss; /** * Regularization strength parameters for each element (must be symmetric, rho(i, j) = rho(j, i). @@ -99,30 +94,18 @@ public static class Result { * solution inverse covariance matrix estimate (ia = 0) * = off-diagonal lasso coefficients (ia != 0) */ - private final DoubleMatrix2D wwi; + private final Matrix wwi; - /** - * number of iterations - */ - private final int niter; - - public Result(DoubleMatrix2D wwi, int niter) { + public Result(Matrix wwi) { this.wwi = wwi; - this.niter = niter; } - public DoubleMatrix2D getWwi() { + public Matrix getWwi() { return this.wwi; } - - public int getNiter() { - return this.niter; - } - } - public Glasso(DoubleMatrix2D cov) { - + public Glasso(Matrix cov) { this.n = cov.rows(); this.ss = cov; } @@ -131,34 +114,31 @@ public Result search() { int niter = 0; final double eps = 1.0e-7; int n = getN(); - DoubleMatrix2D ss = getSs(); + Matrix ss = getSs(); boolean approximateAlgorithm = isIa(); boolean warmStart = isIs(); boolean itr = isItr(); boolean pen = isIpen(); -// System.out.println(ss); - Rho rho = getRho(); - DoubleMatrix2D ww = new DenseDoubleMatrix2D(n, n); - DoubleMatrix2D wwi = new DenseDoubleMatrix2D(n, n); + Matrix ww = new Matrix(n, n); + Matrix wwi = new Matrix(n, n); double dlx; int nm1 = n - 1; - DoubleMatrix2D vv = new DenseDoubleMatrix2D(nm1, nm1); - DoubleMatrix2D xs = null; + Matrix vv = new Matrix(nm1, nm1); + Matrix xs = null; if (!approximateAlgorithm) { - xs = new DenseDoubleMatrix2D(nm1, n); + xs = new Matrix(nm1, n); } - DoubleMatrix1D s = new DenseDoubleMatrix1D(nm1); - DoubleMatrix1D so = new DenseDoubleMatrix1D(nm1); - DoubleMatrix1D x = new DenseDoubleMatrix1D(n - 1); - DoubleMatrix1D ws; + Vector s = new Vector(nm1); + Vector x = new Vector(n - 1); + Vector ws; int[] mm = new int[nm1]; - DoubleMatrix1D ro = new DenseDoubleMatrix1D(nm1); + Vector ro = new Vector(nm1); // shr warmStart sum(abs(offdiagonal(ss))). double shr = 0.0; @@ -170,7 +150,6 @@ public Result search() { } } - // TO TEST THE FOLLOWING CODE I NEED A DIAGONAL COVARIANCE MATRIX. // If ss is diagonal, just return the inverse of the covariance matrix diagonal @@ -188,7 +167,7 @@ public Result search() { } wwi.set(j, j, 1.0 / FastMath.max(ww.get(j, j), eps)); } - return new Result(wwi, niter); + return new Result(wwi); } @@ -232,13 +211,9 @@ public Result search() { } } - - niter = 1; - return new Result(wwi, niter); + return new Result(wwi); } -// System.out.println("wwi = " + wwi); - if (!warmStart) { ww.assign(ss); @@ -246,7 +221,6 @@ public Result search() { } else { for (int j = 0; j < n; j++) { double xjj = -wwi.get(j, j); -// System.out.println("xjj = " + xjj); int l = -1; for (int k = 0; k < n; k++) { @@ -266,7 +240,6 @@ public Result search() { ww.set(j, j, ss.get(j, j) + rho.get(j, j)); } else { ww.set(j, j, ss.get(j, j)); -// System.out.println(ww); } } @@ -279,22 +252,18 @@ public Result search() { System.out.println("Outer loop = " + m); } - x = xs.viewColumn(m); + x = xs.getColumn(m); - ws = ww.viewColumn(m); + ws = ww.getColumn(m); // This sets up vv, s, and ro--i.e., W.11, s.12, and r.12. setup(m, n, ss, rho, ww, vv, s, ro); - - so.assign(s); - -// System.out.println("ww = " + ww); + Vector so = s.copy(); // This updates s and x--the estimated correlation matrix and the reduced form of the // estimated inverse covariance. lasso(ro, nm1, vv, s, shr / sum_abs(vv), x, mm); -// lasso(ro,nm1,vv,s,thr/sum_abs(vv),x,z,mm); int l = -1; for (int j = 0; j < n; j++) { @@ -308,9 +277,8 @@ public Result search() { ww.set(m, j, ww.get(j, m)); } - dlx = FastMath.max(dlx, sum_abs_diff(ww.viewColumn(m), ws)); -// xs(:,m)=x - xs.viewColumn(m).assign(x); + dlx = FastMath.max(dlx, sum_abs_diff(ww.getColumn(m), ws)); + xs.assignColumn(m, x); } niter = niter + 1; @@ -320,10 +288,10 @@ public Result search() { inv(n, ww, xs, wwi); - return new Result(wwi, niter); + return new Result(wwi); } - private double sum_abs(DoubleMatrix2D m) { + private double sum_abs(Matrix m) { double sum = 0.0; for (int i = 0; i < m.rows(); i++) { @@ -335,7 +303,7 @@ private double sum_abs(DoubleMatrix2D m) { return sum; } - private double sum_abs_diff(DoubleMatrix1D x, DoubleMatrix1D y) { + private double sum_abs_diff(Vector x, Vector y) { double sum = 0.0; for (int i = 0; i < x.size(); i++) { @@ -345,8 +313,8 @@ private double sum_abs_diff(DoubleMatrix1D x, DoubleMatrix1D y) { return sum; } - private void setup(int m, int n, DoubleMatrix2D ss, Rho rho, DoubleMatrix2D ww, DoubleMatrix2D vv, - DoubleMatrix1D s, DoubleMatrix1D r) { + private void setup(int m, int n, Matrix ss, Rho rho, Matrix ww, Matrix vv, + Vector s, Vector r) { int l = -1; for (int j = 0; j < n; j++) { @@ -367,8 +335,8 @@ private void setup(int m, int n, DoubleMatrix2D ss, Rho rho, DoubleMatrix2D ww, } } - private void lasso(DoubleMatrix1D ro, int n, DoubleMatrix2D vv, DoubleMatrix1D s, double thr, - DoubleMatrix1D x, int[] mm) { + private void lasso(Vector ro, int n, Matrix vv, Vector s, double thr, + Vector x, int[] mm) { // vv = W.11 // s = s.12 // ro = r.12 @@ -416,8 +384,7 @@ private void lasso(DoubleMatrix1D ro, int n, DoubleMatrix2D vv, DoubleMatrix1D s } // s = vv * x, or s12 = Theta.1 * Theta.12 - private void fatmul(int n, DoubleMatrix2D vv, DoubleMatrix1D x, DoubleMatrix1D s, - int[] m) { + private void fatmul(int n, Matrix vv, Vector x, Vector s, int[] m) { final double fac = 0.2; // z consists of the nonzero entries of x. m indexes these. If there are enough zeroes in x, @@ -445,13 +412,12 @@ private void fatmul(int n, DoubleMatrix2D vv, DoubleMatrix1D x, DoubleMatrix1D s s.set(j, s.get(j) - dotProduct); } } else { - s.assign(new Algebra().mult(vv, x), PlusMult.plusMult(-1)); + s.assign(vv.times(x).minus(x)); } - } - private void inv(int n, DoubleMatrix2D ww, DoubleMatrix2D xs, DoubleMatrix2D wwi) { - xs.assign(Mult.mult(-1)); + private void inv(int n, Matrix ww, Matrix xs, Matrix wwi) { + xs = xs.scalarMult(-1); int nm1 = n - 1; double dp3 = 0.0; @@ -506,7 +472,7 @@ private void inv(int n, DoubleMatrix2D ww, DoubleMatrix2D xs, DoubleMatrix2D wwi } } - private void zero(DoubleMatrix2D wwi) { + private void zero(Matrix wwi) { for (int i = 0; i < wwi.rows(); i++) { for (int j = 0; j < wwi.columns(); j++) { wwi.set(i, j, 0.0); @@ -564,20 +530,10 @@ public void setN(int n) { this.n = n; } - public DoubleMatrix2D getSs() { + public Matrix getSs() { return this.ss; } - public void setSs(DoubleMatrix2D ss) { - if (this.n == -1) throw new IllegalArgumentException("N (dimension) not set."); - - if (!(ss.rows() == this.n && ss.columns() == this.n)) { - throw new IllegalArgumentException("ss not square of dimension n."); - } - - this.ss = ss; - } - public Rho getRho() { return this.rho; } @@ -597,7 +553,6 @@ public void setMaxit(int maxit) { this.maxit = maxit; } - public void setThr(double thr) { if (thr < 0) throw new IllegalArgumentException("Threshold must be >= 0: " + thr); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java index 0f07de3a81..26ba8b9f22 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java @@ -46,6 +46,12 @@ public void assign(double value) { } } + public void assign(Vector vector) { + for (int i = 0; i < this.data.getDimension(); i++) { + this.data.setEntry(i, vector.get(i)); + } + } + public Vector copy() { return new Vector(this.data.copy().toArray()); } From 14ee89172bf65a84db3aba680b555c1a5602187f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 01:02:52 -0400 Subject: [PATCH 138/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/FaskVote.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 f01980feb4..08090f3c28 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 @@ -3,7 +3,6 @@ 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.algcomparison.score.SemBicScore; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataUtils; @@ -22,15 +21,16 @@ */ public class FaskVote { private final IndependenceWrapper test; - private ScoreWrapper score = new SemBicScore(); + private final ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private final List dataSets; /** * Constructor. + * * @param dataSets The datasets being searched over. A composite graph will be generated. - * @param score The score to use. - * @param test The test to use. + * @param score The score to use. + * @param test The test to use. */ public FaskVote(List dataSets, ScoreWrapper score, IndependenceWrapper test) { this.dataSets = dataSets; @@ -42,6 +42,7 @@ public FaskVote(List dataSets, ScoreWrapper score, IndependenceWrapper /** * Does the search. + * * @param parameters The parameers. * @return The composite graph. * @see Parameters From 67e3726212bdbe848f7553ef6b509a7d5ca57f5d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 01:35:32 -0400 Subject: [PATCH 139/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/FastIca.java | 17 +- .../main/java/edu/cmu/tetrad/search/Fges.java | 9 +- .../cmu/tetrad/search/ZhangShenBoundTest.java | 457 ------------------ 3 files changed, 2 insertions(+), 481 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundTest.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index 26e73598fd..2f0ce364fb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -46,7 +46,7 @@ * Description: *

* This is an R and C code implementation of the FastICA algorithm of Aapo - * Hyvarinen et al. (URL: http://www.cis.hut.fi/aapo/) to perform Independent + * Hyvarinen et al. (URL: ...) to perform Independent * Component Analysis (ICA) and Projection Pursuit. *

* Usage: @@ -301,13 +301,6 @@ public void setRowNorm(boolean rowNorm) { this.rowNorm = rowNorm; } - /** - * Maximum number of iterations to perform. - */ - public int getMaxIterations() { - return this.maxIterations; - } - /** * Maximum number of iterations to perform. */ @@ -353,14 +346,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * Initial un-mixing matrix of dimension (n.comp,n.comp). If NULL (default) - * then a matrix of normal r.v.'s is used. - */ - public Matrix getWInit() { - return this.wInit; - } - /** * Initial un-mixing matrix of dimension (n.comp,n.comp). If NULL (default) * then a matrix of normal r.v.'s is used. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index af4500d0d1..28da29b7ae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -247,20 +247,13 @@ public double scoreDag(Graph dag) { return scoreDag(dag, false); } - /** - * @return the list of top scoring graphs. - */ - public LinkedList getTopGraphs() { - return topGraphs; - } - /** * Sets the initial graph. * @param initialGraph This graph. */ public void setInitialGraph(Graph initialGraph) { if (initialGraph == null) { - this.initialGraph = initialGraph; + this.initialGraph = null; return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundTest.java deleted file mode 100644 index 3d6d897c9e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundTest.java +++ /dev/null @@ -1,457 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015 by Peter Spirtes, Richard Scheines, Joseph // -// Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.Matrix; -import org.apache.commons.math3.linear.SingularMatrixException; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static java.lang.Double.NEGATIVE_INFINITY; -import static org.apache.commons.math3.util.FastMath.*; - -/** - * Implements the continuous BIC score for FGES. - * - * @author Joseph Ramsey - */ -public class ZhangShenBoundTest implements Score { - - // The covariance matrix. - private ICovarianceMatrix covariances; - - // The variables of the covariance matrix. - private final List variables; - - // The sample size of the covariance matrix. - private final int sampleSize; - - // True if verbose output should be sent to out. - private boolean verbose = false; - - // Sample size or equivalent sample size. - private double N; - - // A recpord of lambdas for each m0. - private List lambdas; - - // The data, if it is set. - private Matrix data; - - // True if sume of squares should be calculated, false if estimated. - private boolean calculateSquaredEuclideanNorms = false; - - // True if row subsets should be calculated. - private boolean calculateRowSubsets = false; - - // The running maximum score, for estimating the true minimal model. - double[] maxScores; - - // The running estimate of the number of parents in the true minimal model. - int[] estMinParents; - - // The running estimate of the residual variance of the true minimal model. - double[] estVarRys; - - private boolean changed = false; - - private double correlationThreshold = 1.0; - private double penaltyDiscount = 1.0; - private boolean takeLog = true; - private double riskBound = 0; - private double trueErrorVariance; - - /** - * Constructs the score using a covariance matrix. - */ - public ZhangShenBoundTest(ICovarianceMatrix covariances) { - if (covariances == null) { - throw new NullPointerException(); - } - - setCovariances(covariances); - this.variables = covariances.getVariables(); - this.sampleSize = covariances.getSampleSize(); - this.estMinParents = new int[variables.size()]; - this.maxScores = new double[variables.size()]; - this.estVarRys = new double[variables.size()]; - } - - /** - * Constructs the score using a covariance matrix. - */ - public ZhangShenBoundTest(DataSet dataSet) { - if (dataSet == null) { - throw new NullPointerException(); - } - - this.variables = dataSet.getVariables(); - this.sampleSize = dataSet.getNumRows(); - - DataSet _dataSet = DataUtils.center(dataSet); - this.data = _dataSet.getDoubleData(); - - if (!dataSet.existsMissingValue()) { - setCovariances(new CovarianceMatrix(dataSet)); - calculateRowSubsets = false; - } else { - calculateRowSubsets = true; - } - - } - - private int[] indices(List __adj) { - int[] indices = new int[__adj.size()]; - for (int t = 0; t < __adj.size(); t++) indices[t] = variables.indexOf(__adj.get(t)); - return indices; - } - - @Override - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - - public double localScore(int i, int... parents) throws RuntimeException { - - if (this.estMinParents == null) { - this.estMinParents = new int[variables.size()]; - this.maxScores = new double[variables.size()]; - this.estVarRys = new double[variables.size()]; - - for (int j = 0; j < variables.size(); j++) { - this.estMinParents[j] = 0; - this.maxScores[j] = localScore(j, new int[0]); - this.estVarRys[j] = getVarRy(j, new int[0], data, covariances, calculateRowSubsets, calculateSquaredEuclideanNorms); - } - } - - final int pi = parents.length + 1; - double sum; - - double varRy = getVarRy(i, parents, data, covariances, calculateRowSubsets, calculateSquaredEuclideanNorms); - - double score; - - if (takeLog) { - score = -(N * log(varRy) + getLambda(estMinParents[i]) * pi * 2); - } else { -// score = -(sum + c * getLambda(estMinParents[i]) * pi * trueErrorVariance);// estVarRys[i]); - score = -(N * varRy + getLambda(estMinParents[i]) * pi * estVarRys[i]); - } - - if (score > maxScores[i]) { - estMinParents[i] = parents.length; - estVarRys[i] = varRy; - maxScores[i] = score; - changed = true; - - System.out.println(Arrays.toString(estVarRys)); - } - - return score; - } - - public static double getVarRy(int i, int[] parents, Matrix data, ICovarianceMatrix covariances, boolean calculateRowSubsets, boolean calculateSquareEuclideanNorms) { - if (calculateSquareEuclideanNorms) { - return (1. / data.rows()) * getSquaredEucleanNorm(i, parents, data); - } - - try { - int[] all = concat(i, parents); - Matrix cov = getCov(getRows(i, parents, data, calculateRowSubsets), all, all, data, covariances); - int[] pp = indexedParents(parents); - Matrix covxx = cov.getSelection(pp, pp); - Matrix covxy = cov.getSelection(pp, new int[]{0}); - Matrix b = (covxx.inverse().times(covxy)); - Matrix bStar = bStar(b); - return (bStar.transpose().times(cov).times(bStar).get(0, 0)); - } catch (SingularMatrixException e) { - List variables = covariances.getVariables(); - List p = new ArrayList<>(); - for (int _p : parents) p.add(variables.get(_p)); - System.out.println("Singularity " + variables.get(i) + " | " + p); - return NEGATIVE_INFINITY; - } - } - - private double getLambda(int m) { - if (lambdas == null) { - lambdas = new ArrayList<>(); - } - - if (lambdas.size() - 1 < m) { - for (int t = lambdas.size(); t <= m; t++) { - double lambda = zhangShenLambda(variables.size(), t, riskBound); - lambdas.add(lambda); - } - } - - return lambdas.get(m); - } - - public static double zhangShenLambda(int pn, int m0, double riskBound) { - if (pn == m0) throw new IllegalArgumentException("m0 should not equal pn"); - - double high = 1e6; - double low = 0.0; - - while (high - low > 1e-10) { - double lambda = (high + low) / 2.0; - - double p = getP(pn, m0, lambda); - - if (p < 1.0 - riskBound) { - low = lambda; - } else { - high = lambda; - } - } - - return (high + low) / 2.0; - } - - public static double getP(int pn, int m0, double lambda) { - return 2 - pow((1 + (exp(-(lambda - 1) / 2.)) * sqrt(lambda)), pn - m0); - } - - private static double getSquaredEucleanNorm(int i, int[] parents, Matrix data) { - int[] rows = new int[data.rows()]; - for (int t = 0; t < rows.length; t++) rows[t] = t; - - Matrix y = data.getSelection(rows, new int[]{i}); - Matrix x = data.getSelection(rows, parents); - - Matrix xT = x.transpose(); - Matrix xTx = xT.times(x); - Matrix xTxInv = xTx.inverse(); - Matrix xTy = xT.times(y); - Matrix b = xTxInv.times(xTy); - - Matrix yhat = x.times(b); - - double sum = 0.0; - - for (int q = 0; q < data.rows(); q++) { - double diff = data.get(q, i) - yhat.get(q, 0); - sum += diff * diff; - } - - return sum; - } - - - @NotNull - public static Matrix bStar(Matrix b) { - Matrix byx = new Matrix(b.rows() + 1, 1); - byx.set(0, 0, 1); - for (int j = 0; j < b.rows(); j++) byx.set(j + 1, 0, -b.get(j, 0)); - return byx; - } - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - - - public ICovarianceMatrix getCovariances() { - return covariances; - } - - public int getSampleSize() { - return sampleSize; - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > 0; - } - - public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public List getVariables() { - return variables; - } - - @Override - public int getMaxDegree() { - return (int) ceil(log(sampleSize)); - } - - @Override - public boolean determines(List z, Node y) { - int i = variables.indexOf(y); - - int[] k = indices(z); - - double v = localScore(i, k); - - return Double.isNaN(v); - } - - private void setCovariances(ICovarianceMatrix covariances) { - CorrelationMatrix correlations = new CorrelationMatrix(covariances); -// this.covariances = correlations; - this.covariances = covariances; - - boolean exists = false; - - for (int i = 0; i < correlations.getSize(); i++) { - for (int j = 0; j < correlations.getSize(); j++) { - if (i == j) continue; - double r = correlations.getValue(i, j); - if (abs(r) > correlationThreshold) { - System.out.println("Absolute correlation too high: " + r); - exists = true; - } - } - } - - if (exists) { - throw new IllegalArgumentException("Some correlations are too high (> " + correlationThreshold - + ") in absolute value."); - } - - - this.N = covariances.getSampleSize(); - } - - - private static int[] indexedParents(int[] parents) { - int[] pp = new int[parents.length]; - for (int j = 0; j < pp.length; j++) pp[j] = j + 1; - return pp; - } - - private static int[] concat(int i, int[] parents) { - int[] all = new int[parents.length + 1]; - all[0] = i; - System.arraycopy(parents, 0, all, 1, parents.length); - return all; - } - - private static Matrix getCov(List rows, int[] _rows, int[] cols, Matrix data, ICovarianceMatrix covarianceMatrix) { - if (rows == null) { - return covarianceMatrix.getSelection(_rows, cols); - } - - Matrix cov = new Matrix(_rows.length, cols.length); - - for (int i = 0; i < _rows.length; i++) { - for (int j = 0; j < cols.length; j++) { - double mui = 0.0; - double muj = 0.0; - - for (int k : rows) { - mui += data.get(k, _rows[i]); - muj += data.get(k, cols[j]); - } - - mui /= rows.size() - 1; - muj /= rows.size() - 1; - - double _cov = 0.0; - - for (int k : rows) { - _cov += (data.get(k, _rows[i]) - mui) * (data.get(k, cols[j]) - muj); - } - - double mean = _cov / (rows.size()); - cov.set(i, j, mean); - } - } - - return cov; - } - - private static List getRows(int i, int[] parents, Matrix data, boolean calculateRowSubsets) { - if (!calculateRowSubsets) { - return null; - } - - List rows = new ArrayList<>(); - - K: - for (int k = 0; k < data.rows(); k++) { - if (Double.isNaN(data.get(k, i))) continue; - - for (int p : parents) { - if (Double.isNaN(data.get(k, p))) continue K; - } - - rows.add(k); - } - - return rows; - } - - - public void setCalculateSquaredEuclideanNorms(boolean calculateSquaredEuclideanNorms) { - this.calculateSquaredEuclideanNorms = calculateSquaredEuclideanNorms; - } - - public boolean isChanged() { - return changed; - } - - public void setChanged(boolean b) { - changed = b; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public double getPenaltyDiscount() { - return penaltyDiscount; - } - - public void setRiskBound(double riskBound) { - this.riskBound = riskBound; - } - - public void setCorrelationThreshold(double correlationThreshold) { - this.correlationThreshold = correlationThreshold; - } - - public void setTakeLog(boolean takeLog) { - this.takeLog = takeLog; - } - - public void setTrueErrorVariance(double trueErrorVariance) { - this.trueErrorVariance = trueErrorVariance; - } -} - - From 25982119d5dc089890600320ecd3bbca5d64c76d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 01:51:15 -0400 Subject: [PATCH 140/464] Fixing documentation etc. --- .../simulation/BooleanGlassSimulation.java | 10 ++++---- .../conditions}/BryanSensitivityStudy.java | 2 +- .../conditions}/Condition1.java | 2 +- .../conditions}/Condition2.java | 2 +- .../conditions}/ExampleCompareFromFiles.java | 2 +- .../conditions}/ExampleCompareSimulation.java | 2 +- .../ExampleCompareSimulationDiscrete.java | 2 +- .../conditions}/ExampleFirstInflection.java | 2 +- .../conditions}/ExampleSave.java | 2 +- .../conditions}/ExampleStars.java | 2 +- .../conditions}/LingamStudy.java | 2 +- .../gene/algorithm/akutsu/BoolSearch.java | 2 +- .../algorithm/akutsu/LTestBoolSearch.java | 2 +- .../gene/algorithm/akutsu/LTestQnet3.java | 2 +- .../gene/algorithm/akutsu/LTestSsys1.java | 2 +- .../algorithm/akutsu/RevealOutputGraph.java | 4 ++-- .../gene/algorithm/biolingua/Biolingua.java | 4 ++-- .../algorithm/biolingua/BiolinguaDigraph.java | 4 ++-- .../algorithm/biolingua/BiolinguaRunner.java | 4 ++-- .../gene/algorithm/biolingua/Digraph.java | 6 ++--- .../gene/algorithm/biolingua/LTester.java | 3 ++- .../tetrad/gene/algorithm/biolingua/cm.txt | 0 .../gene/algorithm/biolingua/correlMatrix.txt | 0 .../tetrad/gene/algorithm/biolingua/g.txt | 0 .../gene/algorithm/biolingua/graph_gold.txt | 0 .../algorithm/biolingua/graph_paperfig1.txt | 0 .../tetrad/gene/algorithm/biolingua/ltm.txt | 0 .../tetrad/gene/algorithm/biolingua/m.txt | 0 .../gene/algorithm/data/1c5g400tmeas.dat | 0 .../gene/algorithm/data/2rate1chisq.dat | 0 .../tetrad/gene/algorithm/data/2rate1meas.dat | 0 .../tetrad/gene/algorithm/data/2rate1test.dat | 0 .../gene/algorithm/data/2rate1thresh.dat | 0 .../gene/algorithm/data/2rate2graph.dat | 0 .../tetrad/gene/algorithm/data/2rate2meas.dat | 0 .../tetrad/gene/algorithm/data/2rate2test.dat | 0 .../gene/algorithm/data/2rate3chisq.dat | 0 .../gene/algorithm/data/2rate3graph.dat | 0 .../tetrad/gene/algorithm/data/2rate3meas.dat | 0 .../tetrad/gene/algorithm/data/2ratemeas.dat | 0 .../tetrad/gene/algorithm/data/2ratetest.dat | 0 .../tetrad/gene/algorithm/data/5g400tmeas.dat | 0 .../tetrad/gene/algorithm/data/testmutual.dat | 0 .../algorithm/ideker/ItkPredictorSearch.java | 2 +- .../ideker/LTestPredictorSearch.java | 2 +- .../gene/algorithm/ideker/ReadControl.java | 2 +- .../gene/algorithm/ideker/ReadIdeker.java | 2 +- .../gene/tetrad/gene/algorithm/package.html | 0 .../algorithm/reveal/LTestRevealSearch.java | 2 +- .../algorithm/reveal/RevealEvaluator.java | 2 +- .../algorithm/reveal/RevealOutputGraph.java | 4 ++-- .../gene/algorithm/reveal/RevealSearch.java | 2 +- .../algorithm/reveal/TestRevealEvaluator.java | 2 +- .../algorithm/urchin/AbstractNbComponent.java | 2 +- .../gene/algorithm/urchin/BoolSearch.java | 2 +- .../algorithm/urchin/LTestBoolSearch.java | 2 +- .../gene/algorithm/urchin/LTestReveal.java | 2 +- .../algorithm/urchin/LTestRevealSearch.java | 2 +- .../gene/algorithm/urchin/NbComponent.java | 2 +- .../gene/algorithm/urchin/NbFunction.java | 2 +- .../gene/algorithm/urchin/NbFunctionAnd.java | 2 +- .../gene/algorithm/urchin/NbFunctionOr.java | 2 +- .../gene/algorithm/urchin/NbFunctionSV.java | 2 +- .../gene/algorithm/urchin/NbFunctionSum.java | 2 +- .../tetrad/gene/algorithm/urchin/NbGene.java | 2 +- .../gene/algorithm/urchin/NbGeneAnd.java | 2 +- .../gene/algorithm/urchin/NbGeneOr.java | 2 +- .../algorithm/urchin/NetBuilderModel.java | 2 +- .../algorithm/urchin/RevealEvaluator.java | 2 +- .../algorithm/urchin/RevealOutputGraph.java | 4 ++-- .../gene/algorithm/urchin/RevealSearch.java | 2 +- .../algorithm/urchin/SimulateNetwork.java | 2 +- .../algorithm/urchin/SimulateNetworkMain.java | 2 +- .../gene/algorithm/urchin/matearly1011.dat | 0 .../gene/algorithm/urchin/tstbool2nb1011.dat | 0 .../gene/algorithm/urchin/tstbool2nb10115.dat | 0 .../gene/algorithm/util/BasicGraph.java | 2 +- .../gene/algorithm/util/BasicLTMatrix.java | 2 +- .../gene/algorithm/util/BasicMatrix.java | 2 +- .../tetrad/gene/algorithm/util/LTMatrix.java | 6 ++--- .../tetrad/gene/algorithm/util/LTMatrixF.java | 2 +- .../tetrad/gene/algorithm/util/Matrix.java | 6 ++--- .../tetrad/gene/algorithm/util/MatrixF.java | 6 ++--- .../gene/algorithm/util/OutputGraph.java | 2 +- .../tetrad/gene/algorithm/util/SymMatrix.java | 2 +- .../gene/algorithm/util/SymMatrixF.java | 2 +- .../tetrad/gene/graph/ActiveLagGraph.java | 10 ++++---- .../tetrad/gene/graph/DisplayNameHandler.java | 4 ++-- .../tetrad/gene/graph/LagGraphParams.java | 2 +- .../gene/graph/ManualActiveLagGraph.java | 4 ++-- .../tetrad/gene/graph/ManualLagGraph.java | 8 +++---- .../gene/graph/ManualLagGraphParams.java | 2 +- .../gene/graph/RandomActiveLagGraph.java | 4 ++-- .../gene/graph/StoredLagGraphParams.java | 2 +- .../gene/tetrad/gene/graph/package.html | 0 .../tetrad/gene/history/BasalInitializer.java | 2 +- .../tetrad/gene/history/BasicLagGraph.java | 2 +- .../tetrad/gene/history/BooleanFunction.java | 2 +- .../gene/history/BooleanGlassFunction.java | 2 +- .../gene/tetrad/gene/history/DishModel.java | 2 +- .../gene/tetrad/gene/history/GeneHistory.java | 2 +- .../tetrad/gene/history/GraphInitializer.java | 2 +- .../tetrad/gene/history/GraphRandomizer.java | 2 +- .../gene/history/IndexedConnectivity.java | 2 +- .../tetrad/gene/history/IndexedLagGraph.java | 2 +- .../tetrad/gene/history/IndexedParent.java | 2 +- .../gene/tetrad/gene/history/Initializer.java | 2 +- .../gene/tetrad/gene/history/LagGraph.java | 2 +- .../gene/tetrad/gene/history/LaggedEdge.java | 2 +- .../tetrad/gene/history/LaggedFactor.java | 2 +- .../tetrad/gene/history/LinearFunction.java | 2 +- .../gene/tetrad/gene/history/Polynomial.java | 2 +- .../gene/history/PolynomialFunction.java | 2 +- .../tetrad/gene/history/PolynomialTerm.java | 2 +- .../tetrad/gene/history/PreviousStepOnly.java | 2 +- .../gene/history/RandomDistribution.java | 2 +- .../tetrad/gene/history/SimpleRandomizer.java | 2 +- .../gene/history/TestBooleanFunction.java | 2 +- .../gene/history/TestIndexedConnectivity.java | 24 +++++++++---------- .../gene/history/TestIndexedLagGraph.java | 24 +++++++++---------- .../tetrad/gene/history/TestPolynomial.java | 4 ++-- .../gene/history/TestPolynomialTerm.java | 2 +- .../gene/history/TestSimpleRandomizer.java | 2 +- .../tetrad/gene/history/UpdateFunction.java | 2 +- .../gene/tetrad/gene/history/package.html | 0 .../gene/tetrad/gene/history/package2.html | 0 .../gene/tetrad/gene/history/package3.html | 0 .../tetrad/gene/simexp/LinearSimExp1.java | 5 ++-- .../gene/tetrad/gene/simexp/package.html | 0 .../gene/simulation/MeasurementSimulator.java | 8 +++---- .../simulation/TestMeasurementSimulator.java | 3 ++- .../gene/tetrad/gene/simulation/package.html | 0 .../gene/tetrad/gene/util/HandleyConvert.java | 8 +++---- .../gene/tetrad/gene/util/package.html | 0 .../tetradapp/model/BooleanGlassGeneIm.java | 5 ++-- .../tetradapp/model/BooleanGlassGenePm.java | 6 ++--- .../gene/tetradapp/model/GenePm.java | 4 ++-- .../model/MeasurementSimulatorParams.java | 10 ++++---- 138 files changed, 175 insertions(+), 171 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/BryanSensitivityStudy.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{Conditions => examples/conditions}/Condition1.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{Conditions => examples/conditions}/Condition2.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/ExampleCompareFromFiles.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/ExampleCompareSimulation.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/ExampleCompareSimulationDiscrete.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/ExampleFirstInflection.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/ExampleSave.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/ExampleStars.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/study/{ => examples/conditions}/LingamStudy.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/akutsu/BoolSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/akutsu/LTestBoolSearch.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/akutsu/LTestQnet3.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/akutsu/LTestSsys1.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/akutsu/RevealOutputGraph.java (94%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/Biolingua.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/Digraph.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/LTester.java (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/cm.txt (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/correlMatrix.txt (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/g.txt (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/graph_gold.txt (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/graph_paperfig1.txt (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/ltm.txt (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/biolingua/m.txt (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/1c5g400tmeas.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate1chisq.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate1meas.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate1test.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate1thresh.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate2graph.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate2meas.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate2test.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate3chisq.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate3graph.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2rate3meas.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2ratemeas.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/2ratetest.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/5g400tmeas.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/data/testmutual.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/ideker/ItkPredictorSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/ideker/LTestPredictorSearch.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/ideker/ReadControl.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/ideker/ReadIdeker.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/package.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/reveal/LTestRevealSearch.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/reveal/RevealEvaluator.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/reveal/RevealOutputGraph.java (94%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/reveal/RevealSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/BoolSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/LTestBoolSearch.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/LTestReveal.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/LTestRevealSearch.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbComponent.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbFunction.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbFunctionAnd.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbFunctionOr.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbFunctionSV.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbFunctionSum.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbGene.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbGeneAnd.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NbGeneOr.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/NetBuilderModel.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/RevealEvaluator.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/RevealOutputGraph.java (94%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/RevealSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/SimulateNetwork.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/SimulateNetworkMain.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/matearly1011.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/tstbool2nb1011.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/urchin/tstbool2nb10115.dat (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/BasicGraph.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/BasicMatrix.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/LTMatrix.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/LTMatrixF.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/Matrix.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/MatrixF.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/OutputGraph.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/SymMatrix.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/algorithm/util/SymMatrixF.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/ActiveLagGraph.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/DisplayNameHandler.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/LagGraphParams.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/ManualActiveLagGraph.java (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/ManualLagGraph.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/ManualLagGraphParams.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/RandomActiveLagGraph.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/StoredLagGraphParams.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/graph/package.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/BasalInitializer.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/BasicLagGraph.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/BooleanFunction.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/BooleanGlassFunction.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/DishModel.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/GeneHistory.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/GraphInitializer.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/GraphRandomizer.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/IndexedConnectivity.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/IndexedLagGraph.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/IndexedParent.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/Initializer.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/LagGraph.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/LaggedEdge.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/LaggedFactor.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/LinearFunction.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/Polynomial.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/PolynomialFunction.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/PolynomialTerm.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/PreviousStepOnly.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/RandomDistribution.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/SimpleRandomizer.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/TestBooleanFunction.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/TestIndexedConnectivity.java (77%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/TestIndexedLagGraph.java (78%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/TestPolynomial.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/TestPolynomialTerm.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/TestSimpleRandomizer.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/UpdateFunction.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/package.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/package2.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/history/package3.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/simexp/LinearSimExp1.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/simexp/package.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/simulation/MeasurementSimulator.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/simulation/TestMeasurementSimulator.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/simulation/package.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/util/HandleyConvert.java (94%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetrad/gene/util/package.html (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetradapp/model/BooleanGlassGeneIm.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetradapp/model/BooleanGlassGenePm.java (93%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetradapp/model/GenePm.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/gene/tetradapp/model/MeasurementSimulatorParams.java (95%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java index 90101ba7bb..396f3aa3d5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java @@ -3,11 +3,11 @@ import edu.cmu.tetrad.algcomparison.graph.RandomGraph; import edu.cmu.tetrad.annotation.Experimental; import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.gene.tetrad.gene.graph.LagGraphParams; -import edu.cmu.tetrad.gene.tetrad.gene.graph.RandomActiveLagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor; -import edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGeneIm; -import edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGenePm; +import edu.cmu.tetrad.study.gene.tetrad.gene.graph.LagGraphParams; +import edu.cmu.tetrad.study.gene.tetrad.gene.graph.RandomActiveLagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LaggedFactor; +import edu.cmu.tetrad.study.gene.tetradapp.model.BooleanGlassGeneIm; +import edu.cmu.tetrad.study.gene.tetradapp.model.BooleanGlassGenePm; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/BryanSensitivityStudy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/BryanSensitivityStudy.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/BryanSensitivityStudy.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/BryanSensitivityStudy.java index e1947c34ec..57b7c6e75e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/BryanSensitivityStudy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/BryanSensitivityStudy.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition1.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition1.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition1.java index 41318cb385..93bf6a3ad9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition1.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study.Conditions; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition2.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition2.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition2.java index 58b635e6f3..befb0e6741 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition2.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study.Conditions; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareFromFiles.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareFromFiles.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareFromFiles.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareFromFiles.java index 600bc87d56..93e5bbb2ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareFromFiles.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareFromFiles.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulation.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulation.java index 0393d63ebc..6dda705e02 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulationDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulationDiscrete.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulationDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulationDiscrete.java index d0c8748081..2fc2b434ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulationDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulationDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleFirstInflection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleFirstInflection.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleFirstInflection.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleFirstInflection.java index f10daf85a5..1a3cef52b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleFirstInflection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleFirstInflection.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleSave.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleSave.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleSave.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleSave.java index 5b097cefea..762e5edee7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleSave.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleSave.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.graph.RandomForward; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleStars.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleStars.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleStars.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleStars.java index 2c41040863..2c4de94fea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleStars.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleStars.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/LingamStudy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/study/LingamStudy.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java index 4f7779f4a3..6bca10b28b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/LingamStudy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.study; +package edu.cmu.tetrad.study.examples.conditions; import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/BoolSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/BoolSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/BoolSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/BoolSearch.java index 203ec1db56..73d88b0b61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/BoolSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/BoolSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.akutsu; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.akutsu; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestBoolSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestBoolSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestBoolSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestBoolSearch.java index 4e7f3f8b53..169c1eec2c 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestBoolSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestBoolSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.akutsu; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.akutsu; import java.io.*; import java.util.StringTokenizer; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestQnet3.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestQnet3.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestQnet3.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestQnet3.java index 042a597592..5c7b76b278 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestQnet3.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestQnet3.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.akutsu; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.akutsu; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestSsys1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestSsys1.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestSsys1.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestSsys1.java index 5e3df72a62..86ef7d0215 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/LTestSsys1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/LTestSsys1.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.akutsu; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.akutsu; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/RevealOutputGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/RevealOutputGraph.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/RevealOutputGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/RevealOutputGraph.java index b62434e240..eb2d18bacd 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/akutsu/RevealOutputGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/akutsu/RevealOutputGraph.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.akutsu; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.akutsu; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.OutputGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.OutputGraph; public class RevealOutputGraph implements OutputGraph { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/Biolingua.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Biolingua.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/Biolingua.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Biolingua.java index 4f428842df..fa554e6a6c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/Biolingua.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Biolingua.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.biolingua; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.biolingua; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.SymMatrixF; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.SymMatrixF; import org.apache.commons.math3.util.FastMath; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java index 11c7857003..730a6dda93 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java @@ -19,10 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.biolingua; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.biolingua; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.OutputGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.OutputGraph; import java.io.IOException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java index 760aaca30d..18094c34a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.biolingua; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.biolingua; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.SymMatrixF; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.SymMatrixF; /** * Client of the Biolingua class, can be used to easily diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/Digraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Digraph.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/Digraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Digraph.java index cdcbd1eaef..70dfd1d8b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/Digraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Digraph.java @@ -19,10 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.biolingua; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.biolingua; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.BasicGraph; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.MatrixF; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.BasicGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.MatrixF; import java.io.IOException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/LTester.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/LTester.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java index 1e7e5df89f..c01de0c234 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/LTester.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.biolingua; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.biolingua; import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.*; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.*; /** * Class that makes some very simple tests diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/cm.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/cm.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/cm.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/cm.txt diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/correlMatrix.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/correlMatrix.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/correlMatrix.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/correlMatrix.txt diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/g.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/g.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/g.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/g.txt diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/graph_gold.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/graph_gold.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/graph_gold.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/graph_gold.txt diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/graph_paperfig1.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/graph_paperfig1.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/graph_paperfig1.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/graph_paperfig1.txt diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/ltm.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/ltm.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/ltm.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/ltm.txt diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/m.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/m.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/biolingua/m.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/m.txt diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/1c5g400tmeas.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/1c5g400tmeas.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/1c5g400tmeas.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/1c5g400tmeas.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1chisq.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1chisq.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1chisq.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1chisq.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1meas.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1meas.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1meas.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1meas.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1test.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1test.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1test.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1test.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1thresh.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1thresh.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate1thresh.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate1thresh.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate2graph.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate2graph.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate2graph.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate2graph.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate2meas.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate2meas.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate2meas.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate2meas.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate2test.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate2test.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate2test.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate2test.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate3chisq.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate3chisq.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate3chisq.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate3chisq.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate3graph.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate3graph.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate3graph.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate3graph.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate3meas.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate3meas.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2rate3meas.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2rate3meas.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2ratemeas.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2ratemeas.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2ratemeas.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2ratemeas.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2ratetest.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2ratetest.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/2ratetest.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/2ratetest.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/5g400tmeas.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/5g400tmeas.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/5g400tmeas.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/5g400tmeas.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/testmutual.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/testmutual.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/data/testmutual.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/data/testmutual.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ItkPredictorSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ItkPredictorSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ItkPredictorSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ItkPredictorSearch.java index 832ab80a39..c56f486f53 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ItkPredictorSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ItkPredictorSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.ideker; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.ideker; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/LTestPredictorSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/LTestPredictorSearch.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/LTestPredictorSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/LTestPredictorSearch.java index 36ad5a5b3f..9f16ed381e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/LTestPredictorSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/LTestPredictorSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.ideker; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.ideker; public class LTestPredictorSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ReadControl.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ReadControl.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ReadControl.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ReadControl.java index ccd24dbfff..e6793ed8b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ReadControl.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ReadControl.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.ideker; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.ideker; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ReadIdeker.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ReadIdeker.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ReadIdeker.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ReadIdeker.java index 9d511686b7..7a1e81b22d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/ideker/ReadIdeker.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/ideker/ReadIdeker.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.ideker; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.ideker; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/package.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/package.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/package.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/package.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/LTestRevealSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/LTestRevealSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/LTestRevealSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/LTestRevealSearch.java index f95960cf3a..0334ed1cfd 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/LTestRevealSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/LTestRevealSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.reveal; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.reveal; import java.io.*; import java.util.StringTokenizer; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealEvaluator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealEvaluator.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealEvaluator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealEvaluator.java index de9699d3c1..219691ddcb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealEvaluator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealEvaluator.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.reveal; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.reveal; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealOutputGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealOutputGraph.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealOutputGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealOutputGraph.java index d560a45961..f6ea8da51b 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealOutputGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealOutputGraph.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.reveal; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.reveal; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.OutputGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.OutputGraph; public class RevealOutputGraph implements OutputGraph { private final int ngenes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealSearch.java index a29cacb048..7ec38d92b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/RevealSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/RevealSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.reveal; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.reveal; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java index af8e904dc7..4f6993798e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.reveal; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.reveal; import junit.framework.Test; import junit.framework.TestCase; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java index d154719891..adb7325616 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import edu.cmu.tetrad.util.NamingProtocol; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/BoolSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/BoolSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/BoolSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/BoolSearch.java index cfb24d3a10..ecf5f6c82a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/BoolSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/BoolSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestBoolSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestBoolSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestBoolSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestBoolSearch.java index 868c9d6f0e..1e1e3ebf5e 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestBoolSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestBoolSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import java.io.*; import java.util.StringTokenizer; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestReveal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestReveal.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestReveal.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestReveal.java index a2cfe8f549..5132f40aea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestReveal.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestReveal.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestRevealSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestRevealSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestRevealSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestRevealSearch.java index 47b3c15c60..52e1bdb326 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/LTestRevealSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/LTestRevealSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import java.io.*; import java.util.StringTokenizer; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbComponent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbComponent.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbComponent.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbComponent.java index 2fbc92e927..5288225485 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbComponent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbComponent.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; public interface NbComponent { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunction.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunction.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunction.java index 0be2edc7e4..3269808f28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunction.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; public class NbFunction extends AbstractNbComponent { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionAnd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionAnd.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionAnd.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionAnd.java index 7202b9a4f9..812573c0a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionAnd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionAnd.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; public class NbFunctionAnd extends AbstractNbComponent { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionOr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionOr.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionOr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionOr.java index 5acc80d65b..445308ad16 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionOr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionOr.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; public class NbFunctionOr extends AbstractNbComponent { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionSV.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionSV.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionSV.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionSV.java index aff7a7a196..ce926e4ace 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionSV.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionSV.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionSum.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionSum.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionSum.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionSum.java index 7cf6cb2d0d..05e6e06ebb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbFunctionSum.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbFunctionSum.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; public class NbFunctionSum extends AbstractNbComponent { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGene.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGene.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGene.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGene.java index 2fe4b47e1e..72097b1928 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGene.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGene.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; public class NbGene extends AbstractNbComponent { public NbGene(double factor, double power, NbComponent[] parents, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGeneAnd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGeneAnd.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGeneAnd.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGeneAnd.java index c0516c67de..f02f38efff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGeneAnd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGeneAnd.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGeneOr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGeneOr.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGeneOr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGeneOr.java index 97b4d5d488..c3cc5d5e8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NbGeneOr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbGeneOr.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NetBuilderModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NetBuilderModel.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NetBuilderModel.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NetBuilderModel.java index 7202c45593..beba742918 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/NetBuilderModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NetBuilderModel.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealEvaluator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealEvaluator.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealEvaluator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealEvaluator.java index b24c21a0a7..052d2f984c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealEvaluator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealEvaluator.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealOutputGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealOutputGraph.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealOutputGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealOutputGraph.java index 63c3a0c376..3bcf201136 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealOutputGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealOutputGraph.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.OutputGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.OutputGraph; public class RevealOutputGraph implements OutputGraph { private final int ngenes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealSearch.java index b049c13c1f..08fcdd0490 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/RevealSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/RevealSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/SimulateNetwork.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/SimulateNetwork.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/SimulateNetwork.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/SimulateNetwork.java index 2d00422435..df0912f0ef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/SimulateNetwork.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/SimulateNetwork.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/SimulateNetworkMain.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/SimulateNetworkMain.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/SimulateNetworkMain.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/SimulateNetworkMain.java index 99b76301d9..9d3f9ede78 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/SimulateNetworkMain.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/SimulateNetworkMain.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.urchin; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.urchin; public class SimulateNetworkMain { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/matearly1011.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/matearly1011.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/matearly1011.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/matearly1011.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/tstbool2nb1011.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/tstbool2nb1011.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/tstbool2nb1011.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/tstbool2nb1011.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/tstbool2nb10115.dat b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/tstbool2nb10115.dat similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/urchin/tstbool2nb10115.dat rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/tstbool2nb10115.dat diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicGraph.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicGraph.java index 450eca7176..11d4492b51 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicGraph.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java index ef194b79e8..9070eef3e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicMatrix.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicMatrix.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicMatrix.java index 4751f76afd..fe26be4626 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/BasicMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicMatrix.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/LTMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/LTMatrix.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/LTMatrix.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/LTMatrix.java index c37e7e1542..7e9d7ff163 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/LTMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/LTMatrix.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.IOException; @@ -60,7 +60,7 @@ protected void initMatrixStorage() { * checks that x can be converted to a short without causing overflow. */ public void setDoubleValue(int r, int c, double x) { - if ((x < BasicMatrix.MIN_SHORT) || (x > BasicMatrix.MAX_SHORT)) { + if ((x < MIN_SHORT) || (x > MAX_SHORT)) { throw new IllegalArgumentException( "Double " + x + " cannot be stored as a short"); } @@ -72,7 +72,7 @@ public void setDoubleValue(int r, int c, double x) { * can be converted to a short without causing overflow. */ public void setValue(int r, int c, int x) { - if ((x < BasicMatrix.MIN_SHORT) || (x > BasicMatrix.MAX_SHORT)) { + if ((x < MIN_SHORT) || (x > MAX_SHORT)) { throw new IllegalArgumentException( "Double " + x + " cannot be stored as a short"); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/LTMatrixF.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/LTMatrixF.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/LTMatrixF.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/LTMatrixF.java index 73823cc671..404b1bb69f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/LTMatrixF.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/LTMatrixF.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.IOException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/Matrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/Matrix.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/Matrix.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/Matrix.java index a13d170cfe..35450936e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/Matrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/Matrix.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.IOException; @@ -76,7 +76,7 @@ public void setDoubleValue(int r, int c, double x) { if ((r >= this.n) || (c >= this.n) || (r < 0) || (c < 0)) { badIndexXcp(r, c); } - if ((x < BasicMatrix.MIN_SHORT) || (x > BasicMatrix.MAX_SHORT)) { + if ((x < MIN_SHORT) || (x > MAX_SHORT)) { throw new IllegalArgumentException( "Integer " + x + " cannot be stored as a short"); } @@ -108,7 +108,7 @@ public void setValue(int r, int c, short x) { * the integer x can be converted to a short without causing overflow. */ public void setValue(int r, int c, int x) { - if ((x < BasicMatrix.MIN_SHORT) || (x > BasicMatrix.MAX_SHORT)) { + if ((x < MIN_SHORT) || (x > MAX_SHORT)) { throw new IllegalArgumentException( "Integer " + x + " cannot be stored as a short"); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/MatrixF.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/MatrixF.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/MatrixF.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/MatrixF.java index a812c47e0c..3d5bb05768 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/MatrixF.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/MatrixF.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.IOException; @@ -76,7 +76,7 @@ public void setDoubleValue(int r, int c, double x) { if ((r >= this.n) || (c >= this.n) || (r < 0) || (c < 0)) { badIndexXcp(r, c); } - if ((x < BasicMatrix.MIN_FLOAT) || (x > BasicMatrix.MAX_FLOAT)) { + if ((x < MIN_FLOAT) || (x > MAX_FLOAT)) { throw new IllegalArgumentException( "Integer " + x + " cannot be stored as a float"); } @@ -108,7 +108,7 @@ public void setValue(int r, int c, float x) { * the double x can be converted to a float without causing overflow. */ public void setValue(int r, int c, double x) { - if ((x < BasicMatrix.MIN_FLOAT) || (x > BasicMatrix.MAX_FLOAT)) { + if ((x < MIN_FLOAT) || (x > MAX_FLOAT)) { throw new IllegalArgumentException( "Integer " + x + " cannot be stored as a float"); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/OutputGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/OutputGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java index 0e7b776e0a..795ecb4cd9 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/OutputGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/SymMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/SymMatrix.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/SymMatrix.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/SymMatrix.java index c76293d712..d3fcf861a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/SymMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/SymMatrix.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.IOException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/SymMatrixF.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/SymMatrixF.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/SymMatrixF.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/SymMatrixF.java index 312a3923fc..036e0d267c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/algorithm/util/SymMatrixF.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/SymMatrixF.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.algorithm.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util; import java.io.IOException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ActiveLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ActiveLagGraph.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ActiveLagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ActiveLagGraph.java index aa15c85839..7eeabd21d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ActiveLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ActiveLagGraph.java @@ -19,12 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; -import edu.cmu.tetrad.gene.tetrad.gene.history.BasicLagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LaggedEdge; -import edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.BasicLagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LaggedEdge; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LaggedFactor; import edu.cmu.tetrad.util.NamingProtocol; import edu.cmu.tetrad.util.PointXy; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/DisplayNameHandler.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/DisplayNameHandler.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/DisplayNameHandler.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/DisplayNameHandler.java index b5e40c24e7..1c72dcbe3b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/DisplayNameHandler.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/DisplayNameHandler.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LaggedFactor; /** * Translates display names of lagged variables (e.g. "V1:L1") into model names diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/LagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/LagGraphParams.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/LagGraphParams.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/LagGraphParams.java index fda5a77a17..c3b11d928e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/LagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/LagGraphParams.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualActiveLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualActiveLagGraph.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualActiveLagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualActiveLagGraph.java index 15c1c19756..0d7e2e3ada 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualActiveLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualActiveLagGraph.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LaggedFactor; import edu.cmu.tetrad.session.SessionModel; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraph.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualLagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraph.java index bbd09e7dfa..38118c09cc 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraph.java @@ -19,11 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; -import edu.cmu.tetrad.gene.tetrad.gene.history.BasicLagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.BasicLagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LaggedFactor; import edu.cmu.tetrad.util.NamingProtocol; import edu.cmu.tetrad.util.PointXy; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualLagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualLagGraphParams.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java index b62a1389ab..2169885389 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/ManualLagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/RandomActiveLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/RandomActiveLagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java index 9629da3c09..a00ce2955f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/RandomActiveLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; -import edu.cmu.tetrad.gene.tetrad.gene.history.SimpleRandomizer; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.SimpleRandomizer; import edu.cmu.tetrad.session.SessionModel; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/StoredLagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/StoredLagGraphParams.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java index 3b3a12b15d..24ea69e281 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/StoredLagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.graph; +package edu.cmu.tetrad.study.gene.tetrad.gene.graph; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/package.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/package.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/graph/package.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/package.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BasalInitializer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BasalInitializer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java index 21706384e5..917c39d64f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BasalInitializer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.dist.Distribution; import edu.cmu.tetrad.util.dist.Normal; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BasicLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BasicLagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java index 56bef47e74..e8c5d0173f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BasicLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.NamingProtocol; import edu.cmu.tetrad.util.PointXy; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BooleanFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BooleanFunction.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java index c97df1d2ea..59b174f709 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BooleanFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BooleanGlassFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BooleanGlassFunction.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java index be53bce2ac..2537ffd773 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/BooleanGlassFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.dist.Distribution; import edu.cmu.tetrad.util.dist.Normal; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/DishModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/DishModel.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java index 9653ab19dc..2e5185f337 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/DishModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetrad.util.dist.Distribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GeneHistory.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GeneHistory.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java index f64ef794e9..972afa40ce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GeneHistory.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GraphInitializer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphInitializer.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GraphInitializer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphInitializer.java index 52f4bae756..b0b8a8a191 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GraphInitializer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphInitializer.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GraphRandomizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphRandomizer.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GraphRandomizer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphRandomizer.java index 2d16c8ab7e..3414c823bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/GraphRandomizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphRandomizer.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedConnectivity.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedConnectivity.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java index 6243db4510..8bac0b616d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedConnectivity.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedLagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java index 3ca0954de8..5dc76bf2a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedParent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedParent.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java index e6644c2644..da51e521a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/IndexedParent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/Initializer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Initializer.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/Initializer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Initializer.java index 6e3e8972f8..5ff2c68fa7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/Initializer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Initializer.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java index a6f70ecef1..38a5e8db11 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.PointXy; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LaggedEdge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedEdge.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LaggedEdge.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedEdge.java index 40e649a357..551af258f1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LaggedEdge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedEdge.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LaggedFactor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LaggedFactor.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java index 89d5e09ebf..656a1c9cc0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LaggedFactor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LinearFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LinearFunction.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java index a446e3ab5b..575a28b087 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/LinearFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.dist.Distribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/Polynomial.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/Polynomial.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java index 7b2142704d..23514fa4b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/Polynomial.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PolynomialFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PolynomialFunction.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java index 1c1aeb4391..765015bc3a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PolynomialFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.dist.Distribution; import edu.cmu.tetrad.util.dist.Normal; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PolynomialTerm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PolynomialTerm.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java index 8d8596ae4a..1554c7925f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PolynomialTerm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PreviousStepOnly.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PreviousStepOnly.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PreviousStepOnly.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PreviousStepOnly.java index ca3137c70c..0ffd818c61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/PreviousStepOnly.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PreviousStepOnly.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import java.util.ArrayList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/RandomDistribution.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/RandomDistribution.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/RandomDistribution.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/RandomDistribution.java index a8120ced34..bae6244cea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/RandomDistribution.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/RandomDistribution.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/SimpleRandomizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/SimpleRandomizer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java index cdf8e149d9..83ef6ee549 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/SimpleRandomizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestBooleanFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestBooleanFunction.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestBooleanFunction.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestBooleanFunction.java index 11b1662902..2cbbb700b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestBooleanFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestBooleanFunction.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.RandomUtil; import junit.framework.Test; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestIndexedConnectivity.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedConnectivity.java similarity index 77% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestIndexedConnectivity.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedConnectivity.java index 96cad2eda9..760f0ef553 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestIndexedConnectivity.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedConnectivity.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import junit.framework.Test; import junit.framework.TestCase; @@ -60,19 +60,19 @@ public void testConstruction() { System.out.println(indexedConnectivity); - TestCase.assertEquals("G1", indexedConnectivity.getFactor(0)); - TestCase.assertEquals("G2", indexedConnectivity.getFactor(1)); - TestCase.assertEquals("G3", indexedConnectivity.getFactor(2)); + assertEquals("G1", indexedConnectivity.getFactor(0)); + assertEquals("G2", indexedConnectivity.getFactor(1)); + assertEquals("G3", indexedConnectivity.getFactor(2)); - TestCase.assertEquals(2, indexedConnectivity.getParent(0, 0).getIndex()); - TestCase.assertEquals(0, indexedConnectivity.getParent(1, 0).getIndex()); - TestCase.assertEquals(1, indexedConnectivity.getParent(2, 0).getIndex()); - TestCase.assertEquals(2, indexedConnectivity.getParent(2, 1).getIndex()); + assertEquals(2, indexedConnectivity.getParent(0, 0).getIndex()); + assertEquals(0, indexedConnectivity.getParent(1, 0).getIndex()); + assertEquals(1, indexedConnectivity.getParent(2, 0).getIndex()); + assertEquals(2, indexedConnectivity.getParent(2, 1).getIndex()); - TestCase.assertEquals(1, indexedConnectivity.getParent(0, 0).getLag()); - TestCase.assertEquals(2, indexedConnectivity.getParent(1, 0).getLag()); - TestCase.assertEquals(3, indexedConnectivity.getParent(2, 0).getLag()); - TestCase.assertEquals(4, indexedConnectivity.getParent(2, 1).getLag()); + assertEquals(1, indexedConnectivity.getParent(0, 0).getLag()); + assertEquals(2, indexedConnectivity.getParent(1, 0).getLag()); + assertEquals(3, indexedConnectivity.getParent(2, 0).getLag()); + assertEquals(4, indexedConnectivity.getParent(2, 1).getLag()); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestIndexedLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedLagGraph.java similarity index 78% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestIndexedLagGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedLagGraph.java index 743f2aa293..55cd6d5d0d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestIndexedLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedLagGraph.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import junit.framework.Test; import junit.framework.TestCase; @@ -59,19 +59,19 @@ public void testConstruction() { System.out.println(indexedLagGraph); - TestCase.assertEquals("G1", indexedLagGraph.getFactor(0)); - TestCase.assertEquals("G2", indexedLagGraph.getFactor(1)); - TestCase.assertEquals("G3", indexedLagGraph.getFactor(2)); + assertEquals("G1", indexedLagGraph.getFactor(0)); + assertEquals("G2", indexedLagGraph.getFactor(1)); + assertEquals("G3", indexedLagGraph.getFactor(2)); - TestCase.assertEquals(2, indexedLagGraph.getParent(0, 0).getIndex()); - TestCase.assertEquals(0, indexedLagGraph.getParent(1, 0).getIndex()); - TestCase.assertEquals(1, indexedLagGraph.getParent(2, 0).getIndex()); - TestCase.assertEquals(2, indexedLagGraph.getParent(2, 1).getIndex()); + assertEquals(2, indexedLagGraph.getParent(0, 0).getIndex()); + assertEquals(0, indexedLagGraph.getParent(1, 0).getIndex()); + assertEquals(1, indexedLagGraph.getParent(2, 0).getIndex()); + assertEquals(2, indexedLagGraph.getParent(2, 1).getIndex()); - TestCase.assertEquals(1, indexedLagGraph.getParent(0, 0).getLag()); - TestCase.assertEquals(2, indexedLagGraph.getParent(1, 0).getLag()); - TestCase.assertEquals(3, indexedLagGraph.getParent(2, 0).getLag()); - TestCase.assertEquals(4, indexedLagGraph.getParent(2, 1).getLag()); + assertEquals(1, indexedLagGraph.getParent(0, 0).getLag()); + assertEquals(2, indexedLagGraph.getParent(1, 0).getLag()); + assertEquals(3, indexedLagGraph.getParent(2, 0).getLag()); + assertEquals(4, indexedLagGraph.getParent(2, 1).getLag()); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestPolynomial.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomial.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestPolynomial.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomial.java index 9f7a6309eb..33dd96f9f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestPolynomial.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomial.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import junit.framework.Test; import junit.framework.TestCase; @@ -77,7 +77,7 @@ public void testEvaluation() { double[] values = {1.0, 2.0, 3.0, 4.0}; - TestCase.assertEquals(15.0, p.evaluate(values), 0.00001); + assertEquals(15.0, p.evaluate(values), 0.00001); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestPolynomialTerm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomialTerm.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestPolynomialTerm.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomialTerm.java index a3cc840174..a52edfad93 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestPolynomialTerm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomialTerm.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import junit.framework.Test; import junit.framework.TestCase; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestSimpleRandomizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestSimpleRandomizer.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestSimpleRandomizer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestSimpleRandomizer.java index 1ebcaec330..da6279ad27 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/TestSimpleRandomizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestSimpleRandomizer.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.RandomUtil; import junit.framework.Test; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/UpdateFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/UpdateFunction.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/UpdateFunction.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/UpdateFunction.java index 05ec58cd61..29f51838fe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/UpdateFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/UpdateFunction.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.history; +package edu.cmu.tetrad.study.gene.tetrad.gene.history; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/package.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/package.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/package.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/package.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/package2.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/package2.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/package2.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/package2.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/package3.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/package3.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/history/package3.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/package3.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simexp/LinearSimExp1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simexp/LinearSimExp1.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java index 99f2842484..f60123158c 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simexp/LinearSimExp1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.simexp; +package edu.cmu.tetrad.study.gene.tetrad.gene.simexp; import edu.cmu.tetrad.gene.tetrad.gene.history.*; -import edu.cmu.tetrad.gene.tetrad.gene.simulation.MeasurementSimulator; +import edu.cmu.tetrad.study.gene.tetrad.gene.simulation.MeasurementSimulator; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.*; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simexp/package.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/package.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simexp/package.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/package.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/MeasurementSimulator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/MeasurementSimulator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java index d1e77a0fee..5c033c5ea9 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/MeasurementSimulator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java @@ -19,11 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.simulation; +package edu.cmu.tetrad.study.gene.tetrad.gene.simulation; -import edu.cmu.tetrad.gene.tetrad.gene.history.DishModel; -import edu.cmu.tetrad.gene.tetrad.gene.history.GeneHistory; -import edu.cmu.tetrad.gene.tetrad.gene.history.UpdateFunction; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.DishModel; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.GeneHistory; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.UpdateFunction; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetrad.util.dist.Distribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/TestMeasurementSimulator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/TestMeasurementSimulator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java index 6336763c75..d65374df94 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/TestMeasurementSimulator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.simulation; +package edu.cmu.tetrad.study.gene.tetrad.gene.simulation; import cern.colt.list.DoubleArrayList; import cern.jet.stat.Descriptive; import edu.cmu.tetrad.gene.tetrad.gene.history.*; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.RandomUtil; import junit.framework.Test; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/package.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/package.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/simulation/package.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/package.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/util/HandleyConvert.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/HandleyConvert.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/util/HandleyConvert.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/HandleyConvert.java index 3ef439b696..888a9c0da9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/util/HandleyConvert.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/HandleyConvert.java @@ -19,11 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetrad.gene.util; +package edu.cmu.tetrad.study.gene.tetrad.gene.util; -import edu.cmu.tetrad.gene.tetrad.gene.history.BasicLagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.BasicLagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LaggedFactor; import java.io.*; import java.util.StringTokenizer; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/util/package.html b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/package.html similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetrad/gene/util/package.html rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/package.html diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/BooleanGlassGeneIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/BooleanGlassGeneIm.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java index b98bceee39..7fc6583276 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/BooleanGlassGeneIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java @@ -19,13 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetradapp.model; +package edu.cmu.tetrad.study.gene.tetradapp.model; import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.gene.tetrad.gene.graph.DisplayNameHandler; +import edu.cmu.tetrad.study.gene.tetrad.gene.graph.DisplayNameHandler; import edu.cmu.tetrad.gene.tetrad.gene.history.*; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.session.SessionModel; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.*; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.dist.Distribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/BooleanGlassGenePm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java similarity index 93% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/BooleanGlassGenePm.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java index f7cf584484..a2be25ce02 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/BooleanGlassGenePm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java @@ -19,10 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetradapp.model; +package edu.cmu.tetrad.study.gene.tetradapp.model; -import edu.cmu.tetrad.gene.tetrad.gene.graph.ManualActiveLagGraph; -import edu.cmu.tetrad.gene.tetrad.gene.graph.RandomActiveLagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.graph.ManualActiveLagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.graph.RandomActiveLagGraph; import edu.cmu.tetrad.session.SessionModel; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/GenePm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/GenePm.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java index ca0bc930da..3a8846d4a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/GenePm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java @@ -19,9 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetradapp.model; +package edu.cmu.tetrad.study.gene.tetradapp.model; -import edu.cmu.tetrad.gene.tetrad.gene.history.LagGraph; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.LagGraph; import edu.cmu.tetrad.util.TetradSerializable; import java.io.IOException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/MeasurementSimulatorParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/MeasurementSimulatorParams.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java index c0cd5c15bf..91cb1d775a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/gene/tetradapp/model/MeasurementSimulatorParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java @@ -19,12 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.gene.tetradapp.model; +package edu.cmu.tetrad.study.gene.tetradapp.model; -import edu.cmu.tetrad.gene.tetrad.gene.history.BasalInitializer; -import edu.cmu.tetrad.gene.tetrad.gene.history.BooleanGlassFunction; -import edu.cmu.tetrad.gene.tetrad.gene.history.GeneHistory; -import edu.cmu.tetrad.gene.tetrad.gene.simulation.MeasurementSimulator; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.BasalInitializer; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.BooleanGlassFunction; +import edu.cmu.tetrad.study.gene.tetrad.gene.history.GeneHistory; +import edu.cmu.tetrad.study.gene.tetrad.gene.simulation.MeasurementSimulator; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializable; From 54ed712e3924a4234019c7a21d778a2b9d40c01f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 01:57:41 -0400 Subject: [PATCH 141/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/RBExperiments.java | 2 +- .../gene/tetrad/gene/algorithm/biolingua/LTester.java | 1 - .../study/gene/tetrad/gene/simexp/LinearSimExp1.java | 1 - .../tetrad/gene/simulation/TestMeasurementSimulator.java | 1 - .../study/gene/tetradapp/model/BooleanGlassGeneIm.java | 1 - .../edu/cmu/tetrad/{ => study}/performance/Comparison.java | 2 +- .../cmu/tetrad/{ => study}/performance/Comparison2.java | 7 +++---- .../{ => study}/performance/ComparisonParameters.java | 2 +- .../tetrad/{ => study}/performance/ComparisonResult.java | 2 +- .../tetrad/{ => study}/performance/ComparisonScript.java | 2 +- .../tetrad/{ => study}/performance/ExploreComparison.java | 2 +- .../tetrad/{ => study}/performance/PerformanceTests.java | 2 +- .../{ => study}/performance/PerformanceTestsDan.java | 2 +- .../{ => study}/performance/readme_ComparisonScript.txt | 0 14 files changed, 11 insertions(+), 16 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/Comparison.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/Comparison2.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/ComparisonParameters.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/ComparisonResult.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/ComparisonScript.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/ExploreComparison.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/PerformanceTests.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/PerformanceTestsDan.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{ => study}/performance/readme_ComparisonScript.txt (100%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java index e404440d24..ed581da719 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.bayes.DirichletEstimator; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.performance.Comparison; +import edu.cmu.tetrad.study.performance.Comparison; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TextTable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java index c01de0c234..3721abebc2 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java @@ -21,7 +21,6 @@ package edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.biolingua; -import edu.cmu.tetrad.gene.tetrad.gene.algorithm.util.*; import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.*; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java index f60123158c..4451571680 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java @@ -21,7 +21,6 @@ package edu.cmu.tetrad.study.gene.tetrad.gene.simexp; -import edu.cmu.tetrad.gene.tetrad.gene.history.*; import edu.cmu.tetrad.study.gene.tetrad.gene.simulation.MeasurementSimulator; import edu.cmu.tetrad.study.gene.tetrad.gene.history.*; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java index d65374df94..2b0dd95f63 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java @@ -23,7 +23,6 @@ import cern.colt.list.DoubleArrayList; import cern.jet.stat.Descriptive; -import edu.cmu.tetrad.gene.tetrad.gene.history.*; import edu.cmu.tetrad.study.gene.tetrad.gene.history.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java index 7fc6583276..7493841d72 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java @@ -23,7 +23,6 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.study.gene.tetrad.gene.graph.DisplayNameHandler; -import edu.cmu.tetrad.gene.tetrad.gene.history.*; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.study.gene.tetrad.gene.history.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/Comparison.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index fa8ca8d7df..67b6d9479a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.bayes.BayesPm; import edu.cmu.tetrad.bayes.MlBayesIm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/Comparison2.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index 714714f8e4..791babd249 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -1,10 +1,9 @@ -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.bayes.BayesPm; import edu.cmu.tetrad.bayes.MlBayesIm; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.performance.ComparisonParameters.IndependenceTestType; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.ScoreType; @@ -301,7 +300,7 @@ public static ComparisonResult compare(ComparisonParameters params) { } } - if (params.getIndependenceTest() == IndependenceTestType.FisherZ) { + if (params.getIndependenceTest() == ComparisonParameters.IndependenceTestType.FisherZ) { if (params.getDataType() != null && params.getDataType() != ComparisonParameters.DataType.Continuous) { throw new IllegalArgumentException("Data type previously set to something other than continuous."); } @@ -314,7 +313,7 @@ public static ComparisonResult compare(ComparisonParameters params) { test = new IndTestFisherZ(dataSet, params.getAlpha()); params.setDataType(ComparisonParameters.DataType.Continuous); - } else if (params.getIndependenceTest() == IndependenceTestType.ChiSquare) { + } else if (params.getIndependenceTest() == ComparisonParameters.IndependenceTestType.ChiSquare) { if (params.getDataType() != null && params.getDataType() != ComparisonParameters.DataType.Discrete) { throw new IllegalArgumentException("Data type previously set to something other than discrete."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonParameters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonParameters.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java index f4fcf1d21b..69a78d85c9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonParameters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.sem.ScoreType; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonResult.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonResult.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonResult.java index 2ad248fd88..fb8e66ffe8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonResult.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonScript.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonScript.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonScript.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonScript.java index db97abb3e7..dfedd1f981 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ComparisonScript.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonScript.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.sem.ScoreType; import edu.cmu.tetrad.util.TextTable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ExploreComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ExploreComparison.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ExploreComparison.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ExploreComparison.java index 1bef0dfa89..8a013b5c7b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/ExploreComparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ExploreComparison.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.sem.ScoreType; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTests.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 5997f11158..8bc209e05c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.bayes.BayesPm; import edu.cmu.tetrad.bayes.MlBayesIm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTestsDan.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTestsDan.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java index 6a568c3c9c..9499b381f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/PerformanceTestsDan.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.performance; +package edu.cmu.tetrad.study.performance; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/performance/readme_ComparisonScript.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/readme_ComparisonScript.txt similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/performance/readme_ComparisonScript.txt rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/readme_ComparisonScript.txt From d23fa2852e44b4c85ce18bf297fafd4cd56bf8ee Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 02:26:35 -0400 Subject: [PATCH 142/464] Fixing documentation etc. --- .../cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Boss.java | 1 - 1 file changed, 1 deletion(-) 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 325d5e39a9..bb8e294149 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 @@ -34,7 +34,6 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -@Experimental public class Boss implements Algorithm, UsesScoreWrapper, HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; From 413ff2b4799bc75b38af40b6f19dd50e0f7a918f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 03:59:43 -0400 Subject: [PATCH 143/464] Fixing documentation etc. --- .../search/ConditionalGaussianLikelihood.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java index 230a8aa296..4a354f9025 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java @@ -186,18 +186,28 @@ public Ret getLikelihood(int i, int[] parents) { return new Ret(ret1.getLik() - ret2.getLik(), ret1.getDof() - ret2.getDof()); } - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - + /** + * Sets the penalty discount for this score, which is a multiplier on the panalty term of BIC. + * @param penaltyDiscount The penalty discount. + */ public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } + /** + * Sets whether to discretize child variables to avoid integration. An optimization. + * @param discretize True if so. + * @see #setNumCategoriesToDiscretize(int) + */ public void setDiscretize(boolean discretize) { this.discretize = discretize; } + /** + * Sets the number of categories to use to discretize child variables to avoid integrationl + * @param numCategoriesToDiscretize This number. + * @see #setDiscretize(boolean) + */ public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { this.numCategoriesToDiscretize = numCategoriesToDiscretize; } From 3935c12da84601f2fec23d6ade00d1fc9a5f99e4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:01:34 -0400 Subject: [PATCH 144/464] Fixing documentation etc. --- .../ConditionalGaussianOtherBicScore.java | 61 --- .../ConditionalGaussianOtherLikelihood.java | 457 ------------------ .../search/ConditionalGaussianOtherScore.java | 172 ------- 3 files changed, 690 deletions(-) delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianOtherBicScore.java delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherLikelihood.java delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherScore.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianOtherBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianOtherBicScore.java deleted file mode 100755 index 24229a40c1..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianOtherBicScore.java +++ /dev/null @@ -1,61 +0,0 @@ -package edu.cmu.tetrad.algcomparison.score; - -import edu.cmu.tetrad.annotation.Experimental; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ConditionalGaussianOtherScore; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.util.Parameters; - -import java.util.ArrayList; -import java.util.List; - -/** - * Wrapper for Fisher Z test. - * - * @author jdramsey - */ -@Experimental -@edu.cmu.tetrad.annotation.Score( - name = "Conditional Gaussian Other BIC Score", - command = "cg-other-bic-score", - dataType = DataType.Mixed -) -public class ConditionalGaussianOtherBicScore implements ScoreWrapper { - - static final long serialVersionUID = 23L; - - @Override - public Score getScore(DataModel dataSet, Parameters parameters) { - ConditionalGaussianOtherScore conditionalGaussianScore - = new ConditionalGaussianOtherScore(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("structurePrior")); - conditionalGaussianScore.setNumCategoriesToDiscretize(parameters.getInt("numCategoriesToDiscretize")); - return conditionalGaussianScore; - } - - @Override - public String getDescription() { - return "Conditional Gaussian Other BIC Score"; - } - - @Override - public DataType getDataType() { - return DataType.Mixed; - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - - parameters.add("structurePrior"); - parameters.add("discretize"); - return parameters; - } - - @Override - public Node getVariable(String name) { - return null; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherLikelihood.java deleted file mode 100755 index 35e114e178..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherLikelihood.java +++ /dev/null @@ -1,457 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.data.Discretizer.Discretization; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.Matrix; -import edu.cmu.tetrad.util.Vector; -import org.apache.commons.math3.linear.BlockRealMatrix; -import org.apache.commons.math3.linear.RealMatrix; -import org.apache.commons.math3.stat.correlation.Covariance; -import org.apache.commons.math3.util.FastMath; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static edu.cmu.tetrad.data.Discretizer.discretize; -import static edu.cmu.tetrad.data.Discretizer.getEqualFrequencyBreakPoints; -import static org.apache.commons.math3.util.FastMath.log; - -/** - * Implements a conditional Gaussian likelihood. Please note that this this likelihood will be maximal only if the - * the continuous mixedVariables are jointly Gaussian conditional on the discrete mixedVariables; in all other cases, it will - * be less than maximal. For an algorithm like FGS this is fine. - * - * @author Joseph Ramsey - */ -public class ConditionalGaussianOtherLikelihood { - - // The data set. May contain continuous and/or discrete mixedVariables. - private final DataSet mixedDataSet; - - // The data set with all continuous mixedVariables discretized. - private final DataSet dataSet; - - // Number of categories to use to discretize continuous mixedVariables. - private int numCategoriesToDiscretize = 3; - - // The mixedVariables of the mixed data set. - private final List mixedVariables; - - // Indices of mixedVariables. - private final Map nodesHash; - - // Continuous data only. - private final double[][] continuousData; - - // The AD Tree used to count discrete cells. - private final AdLeafTree adTree; - - // Multiplier on degrees of freedom for the continuous portion of those degrees. - private double penaltyDiscount = 1; - - // "Cell" consisting of all rows. - private final ArrayList all; - - // A constant. - private static final double LOGMATH2PI = log(2.0 * FastMath.PI); - - /** - * A return value for a likelihood--returns a likelihood value and the degrees of freedom - * for it. - */ - public static class Ret { - private final double lik; - private final int dof; - - private Ret(double lik, int dof) { - this.lik = lik; - this.dof = dof; - } - - public double getLik() { - return this.lik; - } - - public int getDof() { - return this.dof; - } - - public String toString() { - return "lik = " + this.lik + " dof = " + this.dof; - } - } - - /** - * Constructs the score using a covariance matrix. - */ - public ConditionalGaussianOtherLikelihood(DataSet dataSet) { - if (dataSet == null) { - throw new NullPointerException(); - } - - this.mixedDataSet = dataSet; - this.mixedVariables = dataSet.getVariables(); - - this.continuousData = new double[dataSet.getNumColumns()][]; - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - Node v = dataSet.getVariable(j); - - if (v instanceof ContinuousVariable) { - double[] col = new double[dataSet.getNumRows()]; - - for (int i = 0; i < dataSet.getNumRows(); i++) { - col[i] = dataSet.getDouble(i, j); - } - - this.continuousData[j] = col; - } - } - - this.nodesHash = new HashMap<>(); - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - Node v = dataSet.getVariable(j); - this.nodesHash.put(v, j); - } - - this.dataSet = useErsatzVariables(); - this.adTree = AdTrees.getAdLeafTree(this.dataSet); - - this.all = new ArrayList<>(); - for (int i = 0; i < dataSet.getNumRows(); i++) this.all.add(i); - - } - - private DataSet useErsatzVariables() { - List nodes = new ArrayList<>(); - int numCategories = this.numCategoriesToDiscretize; - - for (Node x : this.mixedVariables) { - if (x instanceof ContinuousVariable) { - nodes.add(new DiscreteVariable(x.getName(), numCategories)); - } else { - nodes.add(x); - } - } - - DataSet replaced = new BoxDataSet(new VerticalIntDataBox(this.mixedDataSet.getNumRows(), this.mixedDataSet.getNumColumns()), nodes); - - for (int j = 0; j < this.mixedVariables.size(); j++) { - if (this.mixedVariables.get(j) instanceof DiscreteVariable) { - for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { - replaced.setInt(i, j, this.mixedDataSet.getInt(i, j)); - } - } else { - double[] column = this.continuousData[j]; - - double[] breakpoints = getEqualFrequencyBreakPoints(column, numCategories); - - List categoryNames = new ArrayList<>(); - - for (int i = 0; i < numCategories; i++) { - categoryNames.add("" + i); - } - - Discretization d = discretize(column, breakpoints, this.mixedVariables.get(j).getName(), categoryNames); - - for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { - replaced.setInt(i, j, d.getData()[i]); - } - } - } - - return replaced; - } - - /** - * Returns the likelihood of variable i conditional on the given parents, assuming the continuous mixedVariables - * index by i or by the parents are jointly Gaussian conditional on the discrete comparison. - * - * @param i The index of the conditioned variable. - * @param parents The indices of the conditioning mixedVariables. - * @return The likelihood. - */ - public Ret getLikelihood(int i, int[] parents) { - Node target = this.mixedVariables.get(i); - - List X = new ArrayList<>(); - List A = new ArrayList<>(); - - for (int p : parents) { - Node parent = this.mixedVariables.get(p); - - if (parent instanceof ContinuousVariable) { - X.add((ContinuousVariable) parent); - } else { - A.add((DiscreteVariable) parent); - } - } - - if (target instanceof DiscreteVariable && X.size() > 0) { - return likelihoodMixed(X, A, (DiscreteVariable) target); - } - - List XPlus = new ArrayList<>(X); - List APlus = new ArrayList<>(A); - - if (target instanceof ContinuousVariable) { - XPlus.add((ContinuousVariable) target); - } else if (target instanceof DiscreteVariable) { - APlus.add((DiscreteVariable) target); - } - - Ret ret1 = likelihoodJoint(XPlus, APlus, target); - Ret ret2 = likelihoodJoint(X, A, target); - - return new Ret(ret1.getLik() - ret2.getLik(), ret1.getDof() - ret2.getDof()); - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { - this.numCategoriesToDiscretize = numCategoriesToDiscretize; - } - - // The likelihood of the joint over all of these mixedVariables, assuming conditional Gaussian, - // continuous and discrete. - private Ret likelihoodJoint(List X, List A, Node target) { - A = new ArrayList<>(A); - X = new ArrayList<>(X); - - if (target instanceof DiscreteVariable) { - for (ContinuousVariable x : new ArrayList<>(X)) { - Node variable = this.dataSet.getVariable(x.getName()); - - if (variable != null) { - A.add((DiscreteVariable) variable); - X.remove(x); - } - } - } - - int k = X.size(); - - int[] continuousCols = new int[k]; - for (int j = 0; j < k; j++) continuousCols[j] = this.nodesHash.get(X.get(j)); - int N = this.mixedDataSet.getNumRows(); - - double c1 = 0, c2 = 0; - - List> cells = this.adTree.getCellLeaves(A); - - for (List cell : cells) { - int a = cell.size(); - if (a == 0) continue; - - if (A.size() > 0) { - c1 += a * multinomialLikelihood(a, N); - } - - if (X.size() > 0) { - try { - - // Determinant will be zero if data are linearly dependent. - Matrix cov; - if (a > continuousCols.length + 10) { - cov = cov(getSubsample(continuousCols, cell)); - } else { - cov = cov(getSubsample(continuousCols, this.all)); - } - c2 += a * gaussianLikelihood(k, cov); - } catch (Exception e) { - // No contribution. - } - } - } - - double lnL = c1 + c2; - int p = (int) getPenaltyDiscount(); - - // Only count dof for continuous cells that contributed to the likelihood calculation. - int dof = p * f(A) * h(X) + f(A); - return new Ret(lnL, dof); - } - - private double multinomialLikelihood(int a, int N) { - return log(a / (double) N); - } - - // One record. - private double gaussianLikelihood(int k, Matrix sigma) { - return -0.5 * logdet(sigma) - 0.5 * k - 0.5 * k * ConditionalGaussianOtherLikelihood.LOGMATH2PI; - } - - private double logdet(Matrix m) { - RealMatrix M = new BlockRealMatrix(m.toArray()); - final double tol = 1e-9; - RealMatrix LT = new org.apache.commons.math3.linear.CholeskyDecomposition(M, tol, tol).getLT(); - - double sum = 0.0; - - for (int i = 0; i < LT.getRowDimension(); i++) { - sum += FastMath.log(LT.getEntry(i, i)); - } - - return 2.0 * sum; - } - - // For cases like P(C | X). This is a ratio of joints, but if the numerator is conditional Gaussian, - // the denominator is a mixture of Gaussians. - private Ret likelihoodMixed(List X, List A, DiscreteVariable B) { - int k = X.size(); - double g = FastMath.pow(2.0 * FastMath.PI, -0.5 * k) * FastMath.exp(-0.5 * k); - - int[] continuousCols = new int[k]; - for (int j = 0; j < k; j++) continuousCols[j] = this.nodesHash.get(X.get(j)); - double lnL = 0.0; - - int N = this.dataSet.getNumRows(); - - List>> cells = this.adTree.getCellLeaves(A, B); - - Matrix defaultCov = null; - - for (List> mycells : cells) { - List x = new ArrayList<>(); - List sigmas = new ArrayList<>(); - List inv = new ArrayList<>(); - List mu = new ArrayList<>(); - - for (List cell : mycells) { - Matrix subsample = getSubsample(continuousCols, cell); - - try { - - // Determinant will be zero if data are linearly dependent. - if (mycells.size() <= continuousCols.length) throw new IllegalArgumentException(); - - Matrix cov = cov(subsample); - Matrix covinv = cov.inverse(); - - if (defaultCov == null) { - defaultCov = cov; - } - - x.add(subsample); - sigmas.add(cov); - inv.add(covinv); - mu.add(means(subsample)); - } catch (Exception e) { - // No contribution. - } - } - - double[] factors = new double[x.size()]; - - for (int u = 0; u < x.size(); u++) { - factors[u] = g * FastMath.pow(sigmas.get(u).det(), -0.5); - } - - double[] a = new double[x.size()]; - - for (int u = 0; u < x.size(); u++) { - for (int i = 0; i < x.get(u).rows(); i++) { - for (int v = 0; v < x.size(); v++) { - Vector xm = x.get(u).getRow(i).minus(mu.get(v)); - a[v] = prob(factors[v], inv.get(v), xm); - } - - double num = a[u] * p(x, u, N); - double denom = 0.0; - - for (int v = 0; v < x.size(); v++) { - denom += a[v] * (p(x, v, N)); - } - - lnL += log(num) - log(denom); - } - } - } - - int p = (int) getPenaltyDiscount(); - - // Only count dof for continuous cells that contributed to the likelihood calculation. - int dof = f(A) * B.getNumCategories() + f(A) * p * h(X); - return new Ret(lnL, dof); - } - - private double p(List x, int u, double N) { - return x.get(u).rows() / N; - } - - private Matrix cov(Matrix x) { - return new Matrix(new Covariance(x.toArray(), true).getCovarianceMatrix().getData()); - } - - private double prob(Double factor, Matrix inv, Vector x) { - return factor * FastMath.exp(-0.5 * inv.times(x).dotProduct(x)); - } - - // Calculates the means of the columns of x. - private Vector means(Matrix x) { - return x.sum(1).scalarMult(1.0 / x.rows()); - } - - // Subsample of the continuous mixedVariables conditioning on the given cell. - private Matrix getSubsample(int[] continuousCols, List cell) { - Matrix subset = new Matrix(cell.size(), continuousCols.length); - - for (int i = 0; i < cell.size(); i++) { - for (int j = 0; j < continuousCols.length; j++) { - subset.set(i, j, this.continuousData[continuousCols[j]][cell.get(i)]); - } - } - - return subset; - } - - // Degrees of freedom for a discrete distribution is the product of the number of categories for each - // variable. - private int f(List A) { - int f = 1; - - for (DiscreteVariable V : A) { - f *= V.getNumCategories(); - } - - return f; - } - - // Degrees of freedom for a multivariate Gaussian distribution is p * (p + 1) / 2, where p is the number - // of mixedVariables. This is the number of unique entries in the covariance matrix over X. - private int h(List X) { - int p = X.size(); - return p * (p + 1) / 2; - } -} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherScore.java deleted file mode 100755 index 735f22539e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianOtherScore.java +++ /dev/null @@ -1,172 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Node; -import org.apache.commons.math3.util.FastMath; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.List; - -/** - * Implements a conditional Gaussian BIC score for FGS. - * - * @author Joseph Ramsey - */ -public class ConditionalGaussianOtherScore implements Score { - - private final DataSet dataSet; - - // The variables of the continuousData set. - private final List variables; - - // Likelihood function - private final ConditionalGaussianOtherLikelihood likelihood; - - private double penaltyDiscount = 1; - private int numCategoriesToDiscretize = 3; - private final double sp; - - /** - * Constructs the score using a covariance matrix. - */ - public ConditionalGaussianOtherScore(DataSet dataSet, double sp) { - if (dataSet == null) { - throw new NullPointerException(); - } - - this.dataSet = dataSet; - this.variables = dataSet.getVariables(); - this.sp = sp; - - this.likelihood = new ConditionalGaussianOtherLikelihood(dataSet); - } - - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model - * - * @return the score, or NaN if the score can't be calculated. - */ - public double localScore(int i, int... parents) { - this.likelihood.setNumCategoriesToDiscretize(this.numCategoriesToDiscretize); - this.likelihood.setPenaltyDiscount(this.penaltyDiscount); - - ConditionalGaussianOtherLikelihood.Ret ret = this.likelihood.getLikelihood(i, parents); - - int N = this.dataSet.getNumRows(); - double lik = ret.getLik(); - int k = ret.getDof(); - - - double strucPrior = getStructurePrior(parents); - if (strucPrior > 0) { - strucPrior = -2 * k * strucPrior; - } - - double score = 2.0 * lik - getPenaltyDiscount() * k * FastMath.log(N) + strucPrior; - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; - } - } - - private double getStructurePrior(int[] parents) { - if (this.sp < 0) { - return getEBICprior(); - } else if (this.sp == 0) { - return 0; - } else { - int i = parents.length; - int c = this.dataSet.getNumColumns() - 1; - double p = this.sp / (double) c; - return i * FastMath.log(p) + (c - i) * FastMath.log(1.0 - p); - } - } - - private double getEBICprior() { - - double n = this.dataSet.getNumColumns(); - double gamma = -this.sp; - return gamma * FastMath.log(n); - - } - - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - - - public int getSampleSize() { - return this.dataSet.getNumRows(); - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > 0; - } - - @Override - public List getVariables() { - return this.variables; - } - - @Override - public int getMaxDegree() { - return (int) FastMath.ceil(FastMath.log(this.dataSet.getNumRows())); - } - - @Override - public boolean determines(List z, Node y) { - return false; - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { - this.numCategoriesToDiscretize = numCategoriesToDiscretize; - } - - @Override - public String toString() { - NumberFormat nf = new DecimalFormat("0.00"); - return "Conditional Gaussian Other Score Penalty " + nf.format(this.penaltyDiscount); - } - -} - - - From 46f6ed1d7aaf6133e4bd0d837fe4e3b7b7d19bc2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:04:20 -0400 Subject: [PATCH 145/464] Fixing documentation etc. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java | 5 +++++ 1 file changed, 5 insertions(+) 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 e5871f03fe..6e8055e672 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 @@ -295,12 +295,17 @@ public Graph search() { return this.graph; } + /** + * Returns a map for x _||_ y | z1,..,zn from {x, y} to {z1,...,zn}. + * @return This map. + */ public SepsetMap getSepsets() { return this.sepsets; } /** * The graph that's constructed during the search. + * @return This graph. */ public Graph getGraph() { return this.graph; From f3b7cf3b702329a95e6b8dd728a209a22db9ca44 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:17:45 -0400 Subject: [PATCH 146/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Cfci.java | 4 + .../search/ConditionalGaussianScore.java | 130 ++++++++++++------ 2 files changed, 92 insertions(+), 42 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 4f114abbf9..5c26942cad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -125,6 +125,10 @@ public Cfci(IndependenceTest independenceTest) { //========================PUBLIC METHODS==========================// + /** + * Performs the search and returns the PAG. + * @return The search PAG. + */ public Graph search() { long beginTime = MillisecondTimes.timeMillis(); if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java index dab3369e0d..354ef48f4e 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java @@ -71,7 +71,10 @@ public ConditionalGaussianScore(DataSet dataSet, double penaltyDiscount, boolean } /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model + * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model. + * @param i The index of the child. + * @param parents The indices of the parents. + * @return The score., */ public double localScore(int i, int... parents) { List rows = getRows(i, parents); @@ -91,84 +94,89 @@ public double localScore(int i, int... parents) { } } - private List getRows(int i, int[] parents) { - List rows = new ArrayList<>(); - - K: - for (int k = 0; k < this.dataSet.getNumRows(); k++) { - if (this.variables.get(i) instanceof DiscreteVariable) { - if (this.dataSet.getInt(k, i) == -99) continue; - } else if (this.variables.get(i) instanceof ContinuousVariable) { - this.dataSet.getInt(k, i); - } - - for (int p : parents) { - if (this.variables.get(i) instanceof DiscreteVariable) { - if (this.dataSet.getInt(k, p) == -99) continue K; - } else if (this.variables.get(i) instanceof ContinuousVariable) { - this.dataSet.getInt(k, p); - } - } - - rows.add(k); - } - - return rows; - } - - private double getStructurePrior(int[] parents) { - if (this.structurePrior <= 0) { - return 0; - } else { - int k = parents.length; - double n = this.dataSet.getNumColumns() - 1; - double p = this.structurePrior / n; - return k * FastMath.log(p) + (n - k) * FastMath.log(1.0 - p); - } - } - + /** + * Calculates localScore(y | z, x) - localScore(z). + * @param x The index of the child. + * @param z The indices of the parents. + * @return The score difference. + */ public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. + * Reurns the sample size of the data. + * @return This size. */ - - public int getSampleSize() { return this.dataSet.getNumRows(); } + /** + * A method for FGES for determining whether an edge counts as an effect edges for this + * score bump. + * @param bump The bump in score. + * @return True iff so. + * @see Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; } + /** + * Returns the variables of the data. + * @return This list. + */ @Override public List getVariables() { return this.variables; } + /** + * Returns the max degree recommended for the search form the MagSemBicScore + * and Fges. + * @return This max degree. + * @see MagSemBicScore + * @see Fges + */ @Override public int getMaxDegree() { return (int) FastMath.ceil(FastMath.log(this.dataSet.getNumRows())); } + /** + * This score does not implement a method to decide whether a given set of parents + * determines a given child, so an exception is thrown. + * @throws UnsupportedOperationException Since this method is not supported. + */ @Override public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException("The 'determines' method is not supported for this score."); } + /** + * Returns the penalty discount for this score, which is a multiplier on the penatly term of the BIC + * score. + * @return This penalty discount. + */ public double getPenaltyDiscount() { return this.penaltyDiscount; } + /** + * Sets the penalty discount for this score, which is a multiplier on the penalty discount of the + * BIC score. + * @param penaltyDiscount This penalty discount. + */ public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } + /** + * Sets tne number of categories used to discretize, when this optimization is used. + * @param numCategoriesToDiscretize This number. + */ public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { this.numCategoriesToDiscretize = numCategoriesToDiscretize; } @@ -182,6 +190,44 @@ public String toString() { public void setStructurePrior(double structurePrior) { this.structurePrior = structurePrior; } + + private List getRows(int i, int[] parents) { + List rows = new ArrayList<>(); + + K: + for (int k = 0; k < this.dataSet.getNumRows(); k++) { + if (this.variables.get(i) instanceof DiscreteVariable) { + if (this.dataSet.getInt(k, i) == -99) continue; + } else if (this.variables.get(i) instanceof ContinuousVariable) { + this.dataSet.getInt(k, i); + } + + for (int p : parents) { + if (this.variables.get(i) instanceof DiscreteVariable) { + if (this.dataSet.getInt(k, p) == -99) continue K; + } else if (this.variables.get(i) instanceof ContinuousVariable) { + this.dataSet.getInt(k, p); + } + } + + rows.add(k); + } + + return rows; + } + + private double getStructurePrior(int[] parents) { + if (this.structurePrior <= 0) { + return 0; + } else { + int k = parents.length; + double n = this.dataSet.getNumColumns() - 1; + double p = this.structurePrior / n; + return k * FastMath.log(p) + (n - k) * FastMath.log(1.0 - p); + } + } + + } From 4e7f1238fc356f645f40db73ea0f537694c4d5c6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:26:31 -0400 Subject: [PATCH 147/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/DagSepsets.java | 1 - .../main/java/edu/cmu/tetrad/search/Dci.java | 2 +- .../search/DegenerateGaussianScore.java | 89 +++++++++++++------ 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java index fa136d74de..afc09ece51 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java @@ -78,7 +78,6 @@ public boolean isUnshieldedCollider(Node i, Node j, Node k) { * @return True if the condition holds. */ @Override public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { -// return true; List sepset = this.dag.getSepset(i, k); return sepset != null && sepset.contains(j); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Dci.java index dc8e338c3e..2fd32ccf62 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Dci.java @@ -32,7 +32,7 @@ /** * Implements the DCI (Distributed Causal Inference) algorithm for learning causal structure over a set of variable from - * multiple datasets that each may only measure proper overlapping subsets subsets of that sets, or datasets with some + * multiple datasets that each may only measure proper overlapping subsets of that sets, or datasets with some * variables in common and others not. The algorithm currently takes as input a set of PAGs (presumably learned using a * local learning algorithm such as FCI) and returns a complete set of PAGs over every variable included a dataset that * are consistent with all of the PAGs (same d-separations and d-connections) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java index 859a5c5fdc..d86a3185c9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java @@ -39,9 +39,8 @@ import static org.apache.commons.math3.util.FastMath.log; /** - * Implements a degenerate Gaussian BIC score for FGES. - *

- * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf + *

Implements a degenerate Gaussian BIC score for FGES.

+ * ... * * @author Bryan Andrews */ @@ -67,7 +66,6 @@ public class DegenerateGaussianScore implements Score { private final Map nodesHash; - /** * Constructs the score using a covariance matrix. */ @@ -159,7 +157,9 @@ public DegenerateGaussianScore(DataSet dataSet) { } /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model + * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model. + * @param i The child indes. + * @param parents The indices of the parents. */ public double localScore(int i, int... parents) { @@ -187,7 +187,7 @@ public double localScore(int i, int... parents) { double ldetB = log(getCov(rows, B_).det()); double lik = N * (ldetB - ldetA + DegenerateGaussianScore.L2PE * (B_.length - A_.length)); - double score = 2 * lik + 2 * calculateStructurePrior(parents.length) - dof * getPenaltyDiscount() * log(N); + double score = 2 * lik + 2 * calculateStructurePrior(parents.length) - dof * this.penaltyDiscount * log(N); if (Double.isNaN(score) || Double.isInfinite(score)) { return Double.NaN; @@ -196,68 +196,103 @@ public double localScore(int i, int... parents) { } } - private double calculateStructurePrior(int k) { - if (this.structurePrior <= 0) { - return 0; - } else { - double n = this.variables.size() - 1; - double p = this.structurePrior / n; - return k * log(p) + (n - k) * log(1.0 - p); - } - } - - + /** + * Returns localScore(y | z, x) - localScore(y, z). + * @param x Node 1. + * @param y Node 2. + * @param z The conditioning variables + * @return This score difference. + */ public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - + /** + * Returns the sample size for the data for this score. + * @return This sample size. + */ public int getSampleSize() { return this.dataSet.getNumRows(); } + /** + * Returns a decision whether a given bump counts as an effect edge + * for this score. + * @param bump The bump. + * @return True if it counts as an effect edge. + * @see Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; } + /** + * Returns the variables for this score. + * @return This list. + */ @Override public List getVariables() { return this.variables; } + /** + * Returns an estimate of the max degree needed for certain algorithms. + * @return This estimate + * @see Fges + * @see MagSemBicScore + */ @Override public int getMaxDegree() { return (int) FastMath.ceil(log(this.dataSet.getNumRows())); } + /** + * This score does not implement a method to determing whether a given set of parents determine + * a given child, so an exception is thrown. + * @throws UnsupportedOperationException Since this method is not implemented. + */ @Override public boolean determines(List z, Node y) { - return false; - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; + throw new UnsupportedOperationException("The 'determines' methods is not implemented for this score."); } + /** + * Sets the penalty discount for this score, which is a multiplier on the BIC penalty term. + * @param penaltyDiscount This penalty. + */ public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } - public double getStructurePrior() { - return this.structurePrior; - } - + /** + * Sets the structure prior for this score. + * @param structurePrior This prior. + */ public void setStructurePrior(double structurePrior) { this.structurePrior = structurePrior; } + /** + * Returns a string representation of this score. + * @return This string. + */ @Override public String toString() { NumberFormat nf = new DecimalFormat("0.00"); return "Degenerate Gaussian Score Penalty " + nf.format(this.penaltyDiscount); } + private double calculateStructurePrior(int k) { + if (this.structurePrior <= 0) { + return 0; + } else { + double n = this.variables.size() - 1; + double p = this.structurePrior / n; + return k * log(p) + (n - k) * log(1.0 - p); + } + } + // Subsample of the continuous mixedVariables conditioning on the given cols. private Matrix getCov(List rows, int[] cols) { if (rows.isEmpty()) return new Matrix(0, 0); From 83d6a2f611598fc68c98f5c0b19ecdf1f6d2831e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:33:20 -0400 Subject: [PATCH 148/464] Fixing documentation etc. --- .../cmu/tetrad/search/DeltaSextadTest.java | 21 +- .../cmu/tetrad/search/DeltaTetradTest.java | 26 +- .../edu/cmu/tetrad/search/DirichletScore.java | 248 ------------------ .../cmu/tetrad/search/DiscreteBicScore.java | 26 +- 4 files changed, 31 insertions(+), 290 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/DirichletScore.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java index ad65ec47a0..3dc4ec44a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java @@ -57,6 +57,7 @@ public class DeltaSextadTest { /** * Constructs a test using a given data set. If a data set is provided (that is, a tabular data set), fourth moment * statistics can be calculated (p. 160); otherwise, it must be assumed that the data are multivariate Gaussian. + * @param dataSet The dataset to use. */ public DeltaSextadTest(DataSet dataSet) { if (dataSet == null) { @@ -78,6 +79,7 @@ public DeltaSextadTest(DataSet dataSet) { /** * Constructs a test using the given covariance matrix. Fourth moment statistics are not caculated; it is assumed * that the data are distributed as multivariate Gaussian. + * @param cov The covariance matrix to use. */ public DeltaSextadTest(ICovarianceMatrix cov) { if (cov == null) { @@ -91,6 +93,7 @@ public DeltaSextadTest(ICovarianceMatrix cov) { /** * Generates a simple exemplar of this class to test serialization. + * @return This instance. */ public static DeltaSextadTest serializableInstance() { return new DeltaSextadTest(BoxDataSet.serializableInstance()); @@ -102,12 +105,12 @@ public static DeltaSextadTest serializableInstance() { *

* Calculates the T statistic (Bollen and Ting, p. 161). This is significant if tests as significant using the Chi * Square distribution with degrees of freedom equal to the number of nonredundant tetrads tested. + * @param sextads The sextads for which a p-value is needed. + * @return The p-value. */ public double getPValue(IntSextad... sextads) { -// int df = sextads.length; int df = dofHarman(sextads.length); double chisq = calcChiSquare(sextads); -// double cdf = ProbUtils.chisqCdf(chisq, df); double cdf = new ChiSquaredDistribution(df).cumulativeProbability(chisq); return 1.0 - cdf; } @@ -118,6 +121,8 @@ public double getPValue(IntSextad... sextads) { *

* Calculates the T statistic (Bollen and Ting, p. 161). This is significant if tests as significant using the Chi * Square distribution with degrees of freedom equal to the number of nonredundant tetrads tested. + * @param sextads The sextads for which a chi-square is needed + * @return The chi-square. */ public double calcChiSquare(IntSextad[] sextads) { Set boldSigmaSet = new HashSet<>(); @@ -222,6 +227,14 @@ public double calcChiSquare(IntSextad[] sextads) { return chisq; } + /** + * Returns the variables of the data being used. + * @return This list. + */ + public List getVariables() { + return this.variables; + } + /** * If using a covariance matrix or a correlation matrix, just returns the lookups. Otherwise calculates the * covariance. @@ -289,10 +302,6 @@ private double derivative(int a, int b, int n1, int n2, int n3, int n4, int n5, return 0.0; } - public List getVariables() { - return this.variables; - } - // Represents a single covariance symbolically. private static class Sigma { private final int a; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java index 52d8cd0f15..22bdb9bfd7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java @@ -55,6 +55,7 @@ public class DeltaTetradTest { /** * Constructs a test using a given data set. If a data set is provided (that is, a tabular data set), fourth moment * statistics can be calculated (p. 160); otherwise, it must be assumed that the data are multivariate Gaussian. + * @param dataSet The dataset to use. */ public DeltaTetradTest(DataSet dataSet) { if (dataSet == null) { @@ -76,7 +77,6 @@ public DeltaTetradTest(DataSet dataSet) { this.data = this.dataSet.getDoubleData().transpose().toArray(); this.N = dataSet.getNumRows(); this.variables = dataSet.getVariables(); -// this.numVars = dataSet.getNumColumns(); this.variablesHash = new HashMap<>(); @@ -89,6 +89,7 @@ public DeltaTetradTest(DataSet dataSet) { /** * Constructs a test using the given covariance matrix. Fourth moment statistics are not caculated; it is assumed * that the data are distributed as multivariate Gaussian. + * @param cov The covaraince matrix to use. */ public DeltaTetradTest(ICovarianceMatrix cov) { if (cov == null) { @@ -112,6 +113,7 @@ public DeltaTetradTest(ICovarianceMatrix cov) { *

* Calculates the T statistic (Bollen and Ting, p. 161). This is significant if tests as significant using the Chi * Square distribution with degrees of freedom equal to the number of nonredundant tetrads tested. + * @param tetrads The tetrads for which a chi-square is needed. */ public double calcChiSquare(Tetrad... tetrads) { this.df = tetrads.length; @@ -226,6 +228,11 @@ public double getPValue() { return 1.0 - cdf; } + /** + * Returns a p-value for the given list of tetrad. + * @param tetrads The tetrad for which a p-vaue is needed. + * @return The p-value. + */ public double getPValue(Tetrad... tetrads) { calcChiSquare(tetrads); return getPValue(); @@ -245,22 +252,7 @@ private double sxyzw(Node e, Node f, Node g, Node h) { } private double getForthMoment(int x, int y, int z, int w) { -// if (cacheFourthMoments) { -// if (fourthMoment == null) { -// initializeForthMomentMatrix(dataSet.getVariable()); -// } -// -// double sxyzw = fourthMoment[x][y][z][w]; -// -// if (sxyzw == 0.0) { -// sxyzw = sxyzw(x, y, z, w); -//// setForthMoment(x, y, z, w, sxyzw); -// } -// -// return sxyzw; -// } else { return sxyzw(x, y, z, w); -// } } /** @@ -373,13 +365,11 @@ private double sxy(double[] array1, double[] array2, int N) { double sum = 0.0; for (i = 0; i < N; i++) { -// sum += (array1[i] - meanX) * (array2[i] - meanY); sum += array1[i] * array2[i]; } return (1.0 / N) * sum; } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DirichletScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DirichletScore.java deleted file mode 100644 index 1c913c00d4..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DirichletScore.java +++ /dev/null @@ -1,248 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.Node; -import org.apache.commons.math3.util.FastMath; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.List; - -/** - * Calculates the BDeu score. - */ -public class DirichletScore implements LocalDiscreteScore { - private final List variables; - private final int[][] data; - private final int sampleSize; - - private double samplePrior = 1; - private double structurePrior = 1; - - private final int[] numCategories; - - private double lastBumpThreshold; - - public DirichletScore(DataSet dataSet) { - if (dataSet == null) { - throw new NullPointerException(); - } - - if (dataSet instanceof BoxDataSet) { - DataBox dataBox = ((BoxDataSet) dataSet).getDataBox(); - - this.variables = dataSet.getVariables(); - - if (!(((BoxDataSet) dataSet).getDataBox() instanceof VerticalIntDataBox)) { - throw new IllegalArgumentException(); - } - - VerticalIntDataBox box = (VerticalIntDataBox) dataBox; - - this.data = box.getVariableVectors(); - } else { - this.data = new int[dataSet.getNumColumns()][]; - this.variables = dataSet.getVariables(); - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - this.data[j] = new int[dataSet.getNumRows()]; - - for (int i = 0; i < dataSet.getNumRows(); i++) { - this.data[j][i] = dataSet.getInt(i, j); - } - } - - } - this.sampleSize = dataSet.getNumRows(); - - List variables = dataSet.getVariables(); - this.numCategories = new int[variables.size()]; - for (int i = 0; i < variables.size(); i++) { - this.numCategories[i] = (getVariable(i)).getNumCategories(); - } - } - - private DiscreteVariable getVariable(int i) { - return (DiscreteVariable) this.variables.get(i); - } - - @Override - public double localScore(int node, int[] parents) { - - // Number of categories for node. - int r = this.numCategories[node]; - - // Numbers of categories of parents. - int[] dims = new int[parents.length]; - - for (int p = 0; p < parents.length; p++) { - dims[p] = this.numCategories[parents[p]]; - } - - // Number of parent states. - int q = 1; - - for (int p = 0; p < parents.length; p++) { - q *= dims[p]; - } - - // Conditional cell coefs of data for node given parents(node). - int[][] n_jk = new int[q][r]; - int[] n_j = new int[q]; - - int[] parentValues = new int[parents.length]; - - int[][] myParents = new int[parents.length][]; - for (int i = 0; i < parents.length; i++) { - myParents[i] = this.data[parents[i]]; - } - - int[] myChild = this.data[node]; - - for (int i = 0; i < this.sampleSize; i++) { - for (int p = 0; p < parents.length; p++) { - parentValues[p] = myParents[p][i]; - } - - int childValue = myChild[i]; - - if (childValue == -99) { - throw new IllegalStateException("Please remove or impute missing " + - "values (record " + i + " column " + i + ")"); - } - - int rowIndex = DirichletScore.getRowIndex(dims, parentValues); - - n_jk[rowIndex][childValue]++; - n_j[rowIndex]++; - } - - //Finally, compute the score - double score = 0.0; - - double cellPrior = getSamplePrior(); - double rowPrior = r * getSamplePrior(); - - for (int j = 0; j < q; j++) { - double rowSum = rowPrior + n_j[j]; - int cellCount = 0; - double rowScore = 0; - - for (int k = 0; k < r; k++) { - double alpha = cellPrior + n_jk[j][k]; - double pk = (alpha) / rowSum; - if (Double.isInfinite(pk)) continue; - double _score = (alpha - 1) * FastMath.log(pk); - rowScore += _score; - cellCount++; - } - - if (rowScore == 0) continue; - score += rowScore; - score -= 2 * cellCount; - } - - - this.lastBumpThreshold = 0.01;//((r - 1) * q * FastMath.log(getStructurePrior())); - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; - } - } - - @Override - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - - @Override - public List getVariables() { - return this.variables; - } - - public int getSampleSize() { - return this.sampleSize; - } - - /** - * Must be called directly after the corresponding scoring call. - */ - public boolean isEffectEdge(double bump) { - return bump > this.lastBumpThreshold; - } - - @Override - public DataSet getDataSet() { - throw new UnsupportedOperationException(); - } - - private static int getRowIndex(int[] dim, int[] values) { - int rowIndex = 0; - for (int i = 0; i < dim.length; i++) { - rowIndex *= dim[i]; - rowIndex += values[i]; - } - return rowIndex; - } - - public double getStructurePrior() { - return this.structurePrior; - } - - public double getSamplePrior() { - return this.samplePrior; - } - - public void setStructurePrior(double structurePrior) { - this.structurePrior = structurePrior; - } - - public void setSamplePrior(double samplePrior) { - this.samplePrior = samplePrior; - } - - - @Override - public int getMaxDegree() { - return 1000; - } - - @Override - public boolean determines(List z, Node y) { - return false; - } - - @Override - public String toString() { - NumberFormat nf = new DecimalFormat("0.00"); - return "Dirichlet Score StructP " + nf.format(this.structurePrior) + " SampP " + nf.format(this.samplePrior); - } - -} - - - 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 c279362b66..f3a3557fe7 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 @@ -170,27 +170,11 @@ 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 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 public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - @Override public List getVariables() { return this.variables; @@ -261,7 +245,6 @@ public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } - @Override public int getMaxDegree() { return 1000; @@ -277,7 +260,14 @@ public String toString() { return "BIC Score"; } - + 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)); + } + } } From aacbfe446b159e00e13c05c1718af56a534a9333 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:38:31 -0400 Subject: [PATCH 149/464] Fixing documentation etc. --- .../tetrad/search/ZhangShenBoundScore.java | 101 ++++++++++-------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java index a443a464ac..599c2325b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java @@ -64,64 +64,34 @@ public class ZhangShenBoundScore implements Score { /** * Constructs the score using a covariance matrix. + * @param covMatrix The covariance matrix. */ - public ZhangShenBoundScore(ICovarianceMatrix covariances) { - if (covariances == null) { + public ZhangShenBoundScore(ICovarianceMatrix covMatrix) { + if (covMatrix == null) { throw new NullPointerException(); } - setCovariances(covariances); - this.variables = covariances.getVariables(); - this.sampleSize = covariances.getSampleSize(); + setCovariances(covMatrix); + this.variables = covMatrix.getVariables(); + this.sampleSize = covMatrix.getSampleSize(); } /** * Constructs the score using a covariance matrix. + * @param dataSet The data set. */ public ZhangShenBoundScore(DataSet dataSet) { this(SimpleDataLoader.getCovarianceMatrix(dataSet)); this.data = dataSet.getDoubleData(); } - public static double zhangShenLambda(int m0, double pn, double riskBound) { - if (m0 > pn) throw new IllegalArgumentException("m0 should not be > pn; m0 = " + m0 + " pn = " + pn); - - double high = 10000.0; - double low = 0.0; - - while (high - low > 1e-13) { - double lambda = (high + low) / 2.0; - - double p = getP(pn, m0, lambda); - - if (p < 1.0 - riskBound) { - low = lambda; - } else { - high = lambda; - } - } - - return low; - } - - public static double getP(double pn, double m0, double lambda) { - return 2. - pow((1. + (exp(-(lambda - 1.) / 2.)) * sqrt(lambda)), pn - m0); - } - - - private int[] indices(List __adj) { - int[] indices = new int[__adj.size()]; - for (int t = 0; t < __adj.size(); t++) indices[t] = variables.indexOf(__adj.get(t)); - return indices; - } - - @Override - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - - public double localScore(int i, int... parents) throws RuntimeException { + /** + * Returns the score for the child given the parents. + * @param i The index of the node. + * @param parents The indices of the node's parents. + * @return The score + */ + public double localScore(int i, int... parents) { int pn = variables.size() - 1; // True if row subsets should be calculated. @@ -155,6 +125,49 @@ public double localScore(int i, int... parents) throws RuntimeException { return score; } + /** + * Returns localScore(y | z, x) - localScore(y | z). + * @param x Node 1 + * @param y Node 2 + * @param z The conditioning nodes. + * @return The score. + */ + @Override + public double localScoreDiff(int x, int y, int[] z) { + return localScore(y, append(z, x)) - localScore(y, z); + } + + private static double getP(double pn, double m0, double lambda) { + return 2. - pow((1. + (exp(-(lambda - 1.) / 2.)) * sqrt(lambda)), pn - m0); + } + + private int[] indices(List __adj) { + int[] indices = new int[__adj.size()]; + for (int t = 0; t < __adj.size(); t++) indices[t] = variables.indexOf(__adj.get(t)); + return indices; + } + + private static double zhangShenLambda(int m0, double pn, double riskBound) { + if (m0 > pn) throw new IllegalArgumentException("m0 should not be > pn; m0 = " + m0 + " pn = " + pn); + + double high = 10000.0; + double low = 0.0; + + while (high - low > 1e-13) { + double lambda = (high + low) / 2.0; + + double p = getP(pn, m0, lambda); + + if (p < 1.0 - riskBound) { + low = lambda; + } else { + high = lambda; + } + } + + return low; + } + private double getLambda(int m0, int pn) { if (lambdas == null) { lambdas = new ArrayList<>(); From 6526f3420c9447ad683f93b692544ae635115038 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:42:26 -0400 Subject: [PATCH 150/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/Tetrad.java | 9 +- .../edu/cmu/tetrad/search/TetradTest.java | 3 - .../edu/cmu/tetrad/search/TeyssierScorer.java | 5 - .../cmu/tetrad/search/TeyssierScorer2.java | 881 ------------------ .../search/TeyssierScorerExperimental.java | 262 ------ .../cmu/tetrad/search/TeyssierScorerOpt.java | 585 ------------ 6 files changed, 4 insertions(+), 1741 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer2.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerExperimental.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerOpt.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java index 862a2bb301..ff128c02a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java @@ -29,7 +29,9 @@ import java.util.Set; /** - * Represents a tetrad of variables. + * Represents a tetrad of variables, (i, j, k, l). + * + * @author josephramsey */ public class Tetrad { private final Node i; @@ -39,7 +41,6 @@ public class Tetrad { private final double pValue; public Tetrad(Node i, Node j, Node k, Node l) { -// testDistinctness(i, j, k, l); this.i = i; this.j = j; this.k = k; @@ -48,7 +49,6 @@ public Tetrad(Node i, Node j, Node k, Node l) { } public Tetrad(Node i, Node j, Node k, Node l, double pValue) { -// testDistinctness(i, j, k, l); this.i = i; this.j = j; this.k = k; @@ -73,15 +73,14 @@ public Node getL() { } public int hashCode() { - int hash = 17 * this.i.hashCode() * this.j.hashCode(); hash += 29 * this.k.hashCode() * this.l.hashCode(); - return hash; } public boolean equals(Object o) { if (o == null) return false; + if (!(o instanceof Tetrad)) return false; Tetrad tetrad = (Tetrad) o; return (this.i == tetrad.i && this.j == tetrad.j && this.k == tetrad.k && this.l == tetrad.l) || (this.i == tetrad.j && this.j == tetrad.i && this.k == tetrad.k && this.l == tetrad.l) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java index fea6a0daf9..4e4808b906 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java @@ -33,7 +33,6 @@ * * @author Ricardo Silva */ - public interface TetradTest { DataSet getDataSet(); @@ -70,8 +69,6 @@ public interface TetradTest { List getVariables(); ICovarianceMatrix getCovMatrix(); - - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java index c84557f435..7cdd20a96f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java @@ -94,7 +94,6 @@ public void setKnowledge(Knowledge knowledge) { } } - /** * @param useRaskuttiUhler True if Pearl's method for building a DAG should be used. */ @@ -103,7 +102,6 @@ public void setUseRaskuttiUhler(boolean useRaskuttiUhler) { if (useRaskuttiUhler) this.useScore = false; } - /** * Scores the given permutation. This needs to be done initially before any move or tuck * operations are performed. @@ -125,7 +123,6 @@ public double score(List order) { return score(); } - /** * @return The score of the current permutation. */ @@ -133,7 +130,6 @@ public double score() { return sum(); } - private double sum() { double score = 0; @@ -148,7 +144,6 @@ private double sum() { return score; } - /** * Performs a tuck operation. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer2.java deleted file mode 100644 index 1e00955ee4..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer2.java +++ /dev/null @@ -1,881 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import org.jetbrains.annotations.NotNull; - -import java.util.*; -import java.util.concurrent.Callable; - -import static org.apache.commons.math3.util.FastMath.floor; - - -/** - * Implements a scorer extending Teyssier, M., and Koller, D. (2012). Ordering-based search: A simple and effective - * algorithm for learning Bayesian networks. arXiv preprint arXiv:1207.1429. You give it a score function - * and a variable ordering, and it computes the score. You can move any variable left or right, and it will - * keep track of the score using the Teyssier and Kohler method. You can move a variable to a new position, - * and you can bookmark a state and come back to it. - * - * @author josephramsey - * @author bryanandrews - */ -public class TeyssierScorer2 { - private final List variables; - private final Map variablesHash; - private final Score score; - private Map> bookmarkedOrders = new HashMap<>(); - private Map> bookmarkedScores = new HashMap<>(); - private Map> bookmarkedOrderHashes = new HashMap<>(); - private Map bookmarkedRunningScores = new HashMap<>(); - private final Map orderHash; - private List pi; - private List scores; - private Knowledge knowledge = new Knowledge(); - - private boolean useScore = true; - private boolean useRaskuttiUhler; - private boolean useBackwardScoring; - private boolean cachingScores = true; - private float runningScore = 0f; - private int maxIndegree = -1; - - public TeyssierScorer2(TeyssierScorer2 scorer) { - this.variables = new ArrayList<>(scorer.variables); - this.variablesHash = new HashMap<>(); - - for (Node key : scorer.variablesHash.keySet()) { - this.variablesHash.put(key, scorer.variablesHash.get(key)); - } - - this.score = scorer.score; - - this.bookmarkedOrders = new HashMap<>(); - - for (Object key : scorer.bookmarkedOrders.keySet()) { - this.bookmarkedOrders.put(key, scorer.bookmarkedOrders.get(key)); - } - - this.bookmarkedScores = new HashMap<>(); - - for (Object key : scorer.bookmarkedScores.keySet()) { - this.bookmarkedScores.put(key, new ArrayList<>(scorer.bookmarkedScores.get(key))); - } - - this.bookmarkedOrderHashes = new HashMap<>(); - - for (Object key : scorer.bookmarkedOrderHashes.keySet()) { - this.bookmarkedOrderHashes.put(key, new HashMap<>(scorer.bookmarkedOrderHashes.get(key))); - } - - this.bookmarkedRunningScores = new HashMap<>(scorer.bookmarkedRunningScores); - - this.orderHash = new HashMap<>(scorer.orderHash); - - this.pi = new ArrayList<>(scorer.pi); - - this.scores = new ArrayList<>(scorer.scores); - this.knowledge = scorer.knowledge; - this.useScore = scorer.useScore; - this.useRaskuttiUhler = scorer.useRaskuttiUhler; - this.useBackwardScoring = scorer.useBackwardScoring; - this.cachingScores = scorer.cachingScores; - this.runningScore = scorer.runningScore; - this.maxIndegree = scorer.maxIndegree; - } - - public TeyssierScorer2(Score score) { - NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT); - - this.score = score; - - if (score != null) { - this.variables = score.getVariables(); - this.pi = new ArrayList<>(this.variables); - } else { - throw new IllegalArgumentException("Need a score"); - } - - this.orderHash = new HashMap<>(); - nodesHash(this.orderHash, this.pi); - - this.variablesHash = new HashMap<>(); - nodesHash(this.variablesHash, this.variables); - - if (score instanceof GraphScore) { - this.useScore = false; - } - } - - public boolean tuck(Node k, int j) { - if (!adjacent(k, get(j))) return false; -// if (coveredEdge(k, get(j))) return false; - if (j >= index(k)) return false; - int _j = j; - int _k = index(k); - - bookmark(-55); - - Set ancestors = getAncestors(k); - - for (int i = j + 1; i <= index(k); i++) { - if (ancestors.contains(get(i))) { - moveToNoUpdate(get(i), j++); - } - } - - updateScores(_j, _k); - - return true; - } - - /** - * @param useScore True if the score should be used; false if the test should be used. - */ - public void setUseScore(boolean useScore) { - if (!(this.score instanceof GraphScore)) { - this.useScore = useScore; - } - } - - /** - * @param knowledge Knowledge of forbidden edges. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - /** - * Scores the given permutation. This needs to be done initially before any move or tuck - * operations are performed. - * - * @param order The permutation to score. - * @return The score of it. - */ - public float score(List order) { - this.pi = new ArrayList<>(order); - this.scores = new ArrayList<>(); - - for (int i1 = 0; i1 < order.size(); i1++) { - this.scores.add(null); - } - - clearBookmarks(); - initializeScores(); - return score(); - } - - /** - * @return The score of the current permutation. - */ - public float score() { - return sum(); - } - - private float sum() { - float score = 0; - - for (int i = 0; i < this.pi.size(); i++) { - float score1 = this.scores.get(i).getScore(); - score += score1; - } - - return score; - } - - /** - * Moves v to a new index. - * - * @param v The variable to move. - * @param toIndex The index to move v to. - */ - public void moveTo(Node v, int toIndex) { - int vIndex = index(v); - if (vIndex == toIndex) return; - - this.pi.remove(v); - this.pi.add(toIndex, v); - - if (toIndex < vIndex) { - updateScores(toIndex, vIndex); - } else { - updateScores(vIndex, toIndex); - } - } - - /** - * Swaps m and n in the permutation. - * - * @param m The first variable. - * @param n The second variable. - * @return True iff the swap was done. - */ - public boolean swap(Node m, Node n) { - int i = this.orderHash.get(m); - int j = this.orderHash.get(n); - - this.pi.set(i, n); - this.pi.set(j, m); - - if (violatesKnowledge(this.pi)) { - this.pi.set(i, m); - this.pi.set(j, n); - return false; - } - - if (i < j) { - updateScores(i, j); - } else { - updateScores(j, i); - } - - return true; - } - - /** - * Returns true iff x->y or y->x is a covered edge. x->y is a covered edge if - * parents(x) = parents(y) \ {x} - * - * @param x The first variable. - * @param y The second variable. - * @return True iff x->y or y->x is a covered edge. - */ - public boolean coveredEdge(Node x, Node y) { - if (!adjacent(x, y)) return false; - Set px = getParents(x); - Set py = getParents(y); - px.remove(y); - py.remove(x); - return px.equals(py); - } - - /** - * @return A copy of the current permutation. - */ - public List getPi() { - return new ArrayList<>(this.pi); - } - - /** - * Return the index of v in the current permutation. - * - * @param v The variable. - * @return Its index. - */ - public int index(Node v) { - Integer integer = this.orderHash.get(v); - - if (integer == null) - throw new IllegalArgumentException("First 'evaluate' a permutation containing variable " - + v + "."); - - return integer; - } - - /** - * Returns the parents of the node at index p. - * - * @param p The index of the node. - * @return Its parents. - */ - public Set getParents(int p) { - return new HashSet<>(this.scores.get(p).getParents()); - } - - /** - * Returns the parents of a node v. - * - * @param v The variable. - * @return Its parents. - */ - public Set getParents(Node v) { - return getParents(index(v)); - } - - /** - * Returns the nodes adjacent to v. - * - * @param v The variable. - * @return Its adjacent nodes. - */ - public Set getAdjacentNodes(Node v) { - Set adj = new HashSet<>(); - - for (Node w : this.pi) { - if (getParents(v).contains(w) || getParents(w).contains(v)) { - adj.add(w); - } - } - - return adj; - } - - /** - * Returns the DAG build for the current permutation, or its CPDAG. - * - * @param cpDag True iff the CPDAG should be returned, False if the DAG. - * @return This graph. - */ - public Graph getGraph(boolean cpDag) { - List order = getPi(); - Graph G1 = new EdgeListGraph(getPi()); - - for (int p = 0; p < order.size(); p++) { - for (Node z : getParents(p)) { - G1.addDirectedEdge(z, order.get(p)); - } - } - - if (cpDag) { - return SearchGraphUtils.cpdagForDag(G1); - } else { - return G1; - } - } - - /** - * Returns a list of adjacent node pairs in the current graph. - * - * @return This list. - */ - public List getAdjacencies() { - List order = getPi(); - Set pairs = new HashSet<>(); - - for (int i = 0; i < order.size(); i++) { - for (int j = 0; j < i; j++) { - Node x = order.get(i); - Node y = order.get(j); - - if (adjacent(x, y)) { - pairs.add(new NodePair(x, y)); - } - } - } - - return new ArrayList<>(pairs); - } - - public Set getAncestors(Node node) { - Set ancestors = new HashSet<>(); - collectAncestorsVisit(node, ancestors); - - return ancestors; - } - - private void collectAncestorsVisit(Node node, Set ancestors) { - if (ancestors.contains(node)) { - return; - } - - ancestors.add(node); - Set parents = getParents(node); - - if (!parents.isEmpty()) { - for (Node parent : parents) { - collectAncestorsVisit(parent, ancestors); - } - } - } - - /** - * Returns a list of edges for the current graph as a list of ordered pairs. - * - * @return This list. - */ - public List> getEdges() { - List order = getPi(); - List> edges = new ArrayList<>(); - - for (Node y : order) { - for (Node x : getParents(y)) { - edges.add(new OrderedPair<>(x, y)); - } - } - - return edges; - } - - /** - * @return The number of edges in the current graph. - */ - public int getNumEdges() { - int numEdges = 0; - - for (int p = 0; p < this.pi.size(); p++) { - numEdges += getParents(p).size(); - } - - return numEdges; - } - - /** - * Returns the node at index j in pi. - * - * @param j The index. - * @return The node at that index. - */ - public Node get(int j) { - return this.pi.get(j); - } - - /** - * Bookmarks the current pi as index key. - * - * @param key This bookmark may be retrieved using the index 'key', an integer. - * This bookmark will be stored until it is retrieved and then removed. - */ - public void bookmark(Object key) { - if (!bookmarkedOrders.containsKey(key)) { - this.bookmarkedOrders.put(key, new ArrayList<>(this.pi)); - this.bookmarkedScores.put(key, new ArrayList<>(this.scores)); - this.bookmarkedOrderHashes.put(key, new HashMap<>(this.orderHash)); - this.bookmarkedRunningScores.put(key, runningScore); - } else { - List pi2 = this.bookmarkedOrders.get(key); - List scores2 = this.bookmarkedScores.get(key); - Map hashes2 = this.bookmarkedOrderHashes.get(key); - - int first = 0; - int last = size() - 1; - - for (int i = 0; i < size(); i++) { - if (this.pi.get(i) != pi2.get(i)) { - first = i; - break; - } - } - - for (int i = size() - 1; i >= 0; i--) { - if (this.pi.get(i) != pi2.get(i)) { - last = i; - break; - } - } - - for (int i = first; i <= last; i++) { - pi2.set(i, pi.get(i)); - scores2.set(i, scores.get(i)); - hashes2.put(pi2.get(i), orderHash.get(pi2.get(i))); - } - - this.bookmarkedRunningScores.put(key, runningScore); - } - } - - /** - * Bookmarks the current pi with index Integer.MIN_VALUE. - */ - public void bookmark() { - bookmark(Integer.MIN_VALUE); - } - - /** - * Retrieves the bookmarked state for index 'key' and removes that bookmark. - * - * @param key The integer key for this bookmark. - */ - public void goToBookmark(Object key) { - if (!this.bookmarkedOrders.containsKey(key)) { - throw new IllegalArgumentException("That key was not bookmarked."); - } - - List pi2 = this.bookmarkedOrders.get(key); - List scores2 = this.bookmarkedScores.get(key); - Map hashes2 = this.bookmarkedOrderHashes.get(key); - Float runningScore2 = this.bookmarkedRunningScores.get(key); - - int first = size(); - int last = -1; - - for (int i = 0; i < size(); i++) { - if (this.pi.get(i) != pi2.get(i)) { - first = i; - break; - } - } - - for (int i = size() - 1; i >= 0; i--) { - if (this.pi.get(i) != pi2.get(i)) { - last = i; - break; - } - } - - for (int i = first; i <= last; i++) { - if (this.pi.get(i) != (pi2.get(i))) { - this.pi.set(i, pi2.get(i)); - this.scores.set(i, scores2.get(i)); - this.orderHash.put(pi.get(i), hashes2.get(pi.get(i))); - } - } - - this.runningScore = runningScore2; - } - - /** - * Retries the bookmark with key = Integer.MIN_VALUE and removes the bookmark. - */ - public void goToBookmark() { - goToBookmark(Integer.MIN_VALUE); - } - - /** - * Clears all bookmarks. - */ - public void clearBookmarks() { - this.bookmarkedOrders.clear(); - this.bookmarkedScores.clear(); - this.bookmarkedOrderHashes.clear(); - this.bookmarkedRunningScores.clear(); - } - - /** - * @return The size of pi, the current permutation. - */ - public int size() { - return this.pi.size(); - } - - /** - * Returns True iff a is adjacent to b in the current graph. - * - * @param a The first node. - * @param b The second node. - * @return True iff adj(a, b). - */ - public boolean adjacent(Node a, Node b) { - if (a == b) return false; - return parent(a, b) || parent(b, a); - } - - /** - * Returns true iff [a, b, c] is a collider. - * - * @param a The first node. - * @param b The second node. - * @param c The third node. - * @return True iff a->b<-c in the current DAG. - */ - public boolean collider(Node a, Node b, Node c) { - return getParents(b).contains(a) && getParents(b).contains(c); - } - - /** - * Returns true iff [a, b, c] is a triangle. - * - * @param a The first node. - * @param b The second node. - * @param c The third node. - * @return True iff adj(a, b) and adj(b, c) and adj(a, c). - */ - public boolean triangle(Node a, Node b, Node c) { - return adjacent(a, b) && adjacent(b, c) && adjacent(a, c); - } - - /** - * True iff the nodes in W form a clique in the current DAG. - * - * @param W The nodes. - * @return True iff these nodes form a clique. - */ - public boolean clique(List W) { - for (int i = 0; i < W.size(); i++) { - for (int j = i + 1; j < W.size(); j++) { - if (!adjacent(W.get(i), W.get(j))) { - return false; - } - } - } - - return true; - } - - private boolean violatesKnowledge(List order) { - if (!knowledge.isEmpty()) { - 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())) { - return true; - } - } - } - } - - return false; - } - - private void initializeScores() { -// for (int i1 = 0; i1 < this.pi.size(); i1++) this.prefixes.set(i1, null); - updateScores(0, this.pi.size() - 1); - } - - public void updateScores(int i1, int i2) { - for (int i = i1; i <= i2; i++) { - this.orderHash.put(this.pi.get(i), i); - recalculate(i); - } - -// for (int i = i1; i <= i2; i++) { -// this.orderHash.put(this.pi.get(i), i); -// } -// -// int chunk = getChunkSize(i2 - i1 + 1); -// List tasks = new ArrayList<>(); -// -// for (int w = 0; w < size(); w += chunk) { -// tasks.add(new MyTask(pi, this, chunk, orderHash, w, w + chunk)); -// } -// -// ForkJoinPool.commonPool().invokeAll(tasks); - } - - private int getChunkSize(int n) { - int chunk = n / Runtime.getRuntime().availableProcessors(); - if (chunk < 100) chunk = 100; - return chunk; - } - - public void setMaxIndegree(int maxIndegree) { - this.maxIndegree = maxIndegree; - } - - class MyTask implements Callable { - final List pi; - final Map orderHash; - TeyssierScorer2 scorer; - int chunk; - private final int from; - private final int to; - - MyTask(List pi, TeyssierScorer2 scorer, int chunk, Map orderHash, - int from, int to) { - this.pi = pi; - this.scorer = scorer; - this.chunk = chunk; - this.orderHash = orderHash; - this.from = from; - this.to = to; - } - - @Override - public Boolean call() throws InterruptedException { - for (int i = from; i <= to; i++) { - if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); - recalculate(i); - } - - return true; - } - } - - - private float score(Node n, Set pi) { - int[] parentIndices = new int[pi.size()]; - - int k = 0; - - for (Node p : pi) { - parentIndices[k++] = this.variablesHash.get(p); - } - - return (float) this.score.localScore(this.variablesHash.get(n), parentIndices); - } - - public Set getPrefix(int i) { - Set prefix = new HashSet<>(); - - for (int j = 0; j < i; j++) { - prefix.add(this.pi.get(j)); - } - - return prefix; - } - - private void recalculate(int p) { - Pair p2 = getGrowShrinkScore(p); - - if (scores.get(p) == null) { - this.runningScore += p2.score; - } else { - this.runningScore += p2.score - scores.get(p).getScore(); - } - - this.scores.set(p, p2); - } - - private void nodesHash(Map nodesHash, List variables) { - for (int i = 0; i < variables.size(); i++) { - nodesHash.put(variables.get(i), i); - } - } - - @NotNull - private Pair getGrowShrinkScore(int p) { - Node n = this.pi.get(p); - - Set parents = new HashSet<>(); - boolean changed = true; - - float sMax = score(n, new HashSet<>()); - Set prefix1 = getPrefix(p); - List prefix = new ArrayList<>(prefix1); - - // Backward scoring only from the prefix variables - if (this.useBackwardScoring) { - parents.addAll(prefix); - sMax = score(n, parents); - changed = false; - } - - // Grow-shrink - while (changed) { - changed = false; - - // Let z be the node that maximizes the score... - Node z = null; - - for (Node z0 : prefix) { - if (parents.contains(z0)) continue; - - if (!knowledge.isEmpty() && this.knowledge.isForbidden(z0.getName(), n.getName())) continue; - parents.add(z0); - - float s2 = score(n, parents); - - if (s2 > sMax) { - sMax = s2; - z = z0; - } - - parents.remove(z0); - } - - if (z != null) { - parents.add(z); - if (maxIndegree > 0 && parents.size() > maxIndegree) break; - changed = true; - } - } - - boolean changed2 = true; - - while (changed2) { - changed2 = false; - - Node w = null; - - for (Node z0 : new HashSet<>(parents)) { - parents.remove(z0); - - float s2 = score(n, parents); - - if (s2 > sMax) { - sMax = s2; - w = z0; - } - - parents.add(z0); - } - - if (w != null) { - parents.remove(w); - changed2 = true; - } - } - -// this.prefixes.set(p, prefix1); - - if (this.useScore) { - return new Pair(parents, Float.isNaN(sMax) ? Float.NEGATIVE_INFINITY : sMax); - } else { - return new Pair(parents, -parents.size()); - } - } - - public Set> getSkeleton() { - List order = getPi(); - Set> skeleton = new HashSet<>(); - - for (Node y : order) { - for (Node x : getParents(y)) { - Set adj = new HashSet<>(); - adj.add(x); - adj.add(y); - skeleton.add(adj); - } - } - - return skeleton; - } - - public void moveToNoUpdate(Node v, int toIndex) { -// bookmark(-55); - - if (!this.pi.contains(v)) return; - int vIndex = index(v); - if (vIndex == toIndex) return; - - this.pi.remove(v); - this.pi.add(toIndex, v); - -// if (violatesKnowledge(this.pi)) { -// goToBookmark(-55); -// } - } - - public boolean parent(Node k, Node j) { - return getParents(j).contains(k); - } - - public double remove(Node x) { - Set adj = getAdjacentNodes(x); - - int index = index(x); - this.scores.remove(index); - this.pi.remove(x); - this.orderHash.remove(x); - this.variables.remove(x); - this.variablesHash.remove(x); - - for (int i = index; i < pi.size(); i++) { - if (adj.contains(get(i))) { - recalculate(i); - this.orderHash.put(this.pi.get(i), i); - } - } - - updateScores(index, pi.size() - 1); - clearBookmarks(); - return score(); - } - - public static class Pair { - private final Set parents; - private final float score; - - private Pair(Set parents, float score) { - this.parents = parents; - this.score = score; - } - - public Set getParents() { - return this.parents; - } - - public float getScore() { - return this.score; - } - - public int hashCode() { - return this.parents.hashCode() + (int) floor(10000D * this.score); - } - - public boolean equals(Object o) { - if (o == null) return false; - if (!(o instanceof Pair)) return false; - Pair thatPair = (Pair) o; - return this.parents.equals(thatPair.parents) && this.score == thatPair.score; - } - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerExperimental.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerExperimental.java deleted file mode 100644 index 3215d2e703..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerExperimental.java +++ /dev/null @@ -1,262 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.*; -import org.apache.commons.lang3.RandomUtils; - -import java.util.*; - -import static org.apache.commons.math3.util.FastMath.max; -import static org.apache.commons.math3.util.FastMath.min; - - -/** - * Implements a scorer extending Teyssier, M., and Koller, D. (2012). Ordering-based search: A simple and effective - * algorithm for learning Bayesian networks. arXiv preprint arXiv:1207.1429. You give it a score function - * and a variable ordering, and it computes the score. You can move any variable left or right, and it will - * keep track of the score using the Teyssier and Kohler method. You can move a variable to a new position, - * and you can bookmark a state and come back to it. - * - * @author josephramsey - * @author bryanandrews - */ -public class TeyssierScorerExperimental { - private final Score score; - private final List variables; - private final int n; - private final int[] order; - // private final ConcurrentMap> parents; - private final Map> parents; - private final double[] scores; - - - public TeyssierScorerExperimental(Score score) { - this.score = score; - this.variables = score.getVariables(); - this.n = this.variables.size(); - - this.order = new int[n]; -// this.parents = new ConcurrentHashMap<>(); - this.parents = new HashMap<>(); - this.scores = new double[n]; - - for (int i = 0; i < n; i++) this.order[i] = i; - reset(); - } - - - private void reset() { - for (int i = 0; i < n; i++) { - int x = this.order[i]; - Set xParents = new HashSet<>(); - this.parents.put(x, xParents); - this.scores[x] = growShrink(i, i, Collections.emptySet(), xParents); - } - } - - - public void shuffleOrder() { - for (int i = 0; i < this.n - 2; i++) { - int j = RandomUtils.nextInt(i, this.n); - int x = this.order[j]; - this.order[j] = this.order[i]; - this.order[i] = x; - } - - reset(); - } - - - public void setOrder(Graph graph) { - List order = new LinkedList<>(); - for (int i : this.order) order.add(i); - - int i, j; - i = this.n; - while (i-- > 0) { - ListIterator itr = order.listIterator(order.size()); - do j = itr.previous(); - while (!validSink(this.variables.get(j), graph)); - graph.removeNode(this.variables.get(j)); - this.order[i] = j; - itr.remove(); - } - - reset(); - } - - - private boolean validSink(Node x, Graph graph) { - LinkedList neighbors = new LinkedList<>(); - - for (Edge edge : graph.getEdges(x)) { - if (edge.getDistalEndpoint(x) == Endpoint.ARROW) return false; - 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 false; - } - - return true; - } - - - public double getScore() { - double score = 0; - for (int i = 0; i < n; i++) score += this.scores[i]; - - return score; - } - - - public boolean hasParent(int i, int j) { - return this.parents.get(this.order[i]).contains(this.order[j]); - } - - - private Set getAncestors(int i, int j) { - Set ancestors = new HashSet<>(); - ancestors.add(this.order[i]); - for (int k = i; k > j; k--) { - if (!ancestors.contains(this.order[k])) continue; - ancestors.addAll(this.parents.get(k)); - } - ancestors.remove(this.order[j]); - - return ancestors; - } - - - public boolean tuck(int i, int j) { - Set ancestors = getAncestors(i, j); - Map> parents = new HashMap<>(); - - int n = i - j + 1; - int[] order = new int[n]; - double[] scores = new double[n]; - double diff = 0; - - int ii = 0; - int jj = n; - - while (i >= j) { - int x = this.order[i]; - Set xParents = new HashSet<>(); - parents.put(x, xParents); - if (ancestors.contains(x)) { - order[--jj] = x; - scores[jj] = growShrink(i--, j, ancestors, xParents); - diff += scores[jj] - this.scores[x]; - } else { - order[ii] = x; - scores[ii] = growShrink(i--, j + n - 1, ancestors, xParents); - diff += scores[ii++] - this.scores[x]; - } - } - - if (diff <= 0) return false; - - while (ii < n) { - int x = order[ii]; - this.order[j++] = x; - this.parents.replace(x, parents.get(x)); - this.scores[x] = scores[ii++]; - } - while (jj > 0) { - int x = order[--jj]; - this.order[j++] = x; - this.parents.replace(x, parents.get(x)); - this.scores[x] = scores[jj]; - } - return true; - } - - - private int[] toArray(Set set) { - int i = 0; - int[] array = new int[set.size()]; - for (Integer j : set) array[i++] = j; - - return array; - } - - - private int[] toArray(Set set, int remove) { - int i = 0; - int[] array = new int[set.size() - 1]; - for (Integer j : set) if (j != remove) array[i++] = j; - - return array; - } - - - private double growShrink(int i, int j, Set allowWithin, Set parents) { - int x = this.order[i]; - int y, z; - - double sMax = this.score.localScore(x, toArray(parents)); - - int lb = min(i, j); - int ub = max(i, j); - - do { - z = -1; - for (int k = 0; k <= ub; k++) { - if (k == i) continue; - y = this.order[k]; - - if (parents.contains(y)) continue; - if (k >= lb && !allowWithin.contains(y)) continue; - - parents.add(y); - double s = this.score.localScore(x, toArray(parents)); - parents.remove(y); - - if (s <= sMax) continue; - - sMax = s; - z = y; - } - if (z != -1) parents.add(z); - } while (z != -1); - - do { - z = -1; - for (int remove : parents) { - double s = this.score.localScore(x, toArray(parents, remove)); - - if (s <= sMax) continue; - - sMax = s; - z = remove; - } - if (z != -1) parents.remove(z); - } while (z != -1); - - return sMax; - } - - - public Graph getGraph(boolean cpDag) { - Graph graph = new EdgeListGraph(this.variables); - - for (int a : this.order) { - for (int b : this.parents.get(a)) { - graph.addDirectedEdge(this.variables.get(b), this.variables.get(a)); - } - } - - if (cpDag) { - MeekRules rules = new MeekRules(); - rules.orientImplied(graph); - } - - return graph; - } - - - public int size() { - return this.n; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerOpt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerOpt.java deleted file mode 100644 index eb2d8d002c..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorerOpt.java +++ /dev/null @@ -1,585 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import org.jetbrains.annotations.NotNull; - -import java.util.*; - - -/** - * Implements a scorer extending Teyssier, M., and Koller, D. (2012). Ordering-based search: A simple and effective - * algorithm for learning Bayesian networks. arXiv preprint arXiv:1207.1429. You give it a score function - * and a variable ordering, and it computes the score. You can move any variable left or right, and it will - * keep track of the score using the Teyssier and Kohler method. You can move a variable to a new position, - * and you can bookmark a state and come back to it. - * - * @author josephramsey - * @author bryanandrews - */ -public class TeyssierScorerOpt { - private final List variables; - private final Map variablesHash; - private final Score score; - - private final Map, Float>> cache = new HashMap<>(); - private final Map orderHash; - private ArrayList pi; // The current permutation. - private ArrayList scores = new ArrayList<>(); - private Knowledge knowledge = new Knowledge(); - private ArrayList> prefixes; - - public TeyssierScorerOpt(@NotNull Score score) { - NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT); - - this.score = score; - - this.variables = score.getVariables(); - this.pi = new ArrayList<>(this.variables); - - this.orderHash = new HashMap<>(); - nodesHash(this.orderHash, this.pi); - - this.variablesHash = new HashMap<>(); - nodesHash(this.variablesHash, this.variables); - } - - /** - * @param knowledge Knowledge of forbidden edges. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - /** - * Scores the given permutation. This needs to be done initially before any move or tuck - * operations are performed. - * - * @param order The permutation to score. - * @return The score of it. - */ - public float score(List order) { - this.pi = new ArrayList<>(order); - this.scores = new ArrayList<>(); - - for (int i1 = 0; i1 < order.size(); i1++) { - this.scores.add(null); - } - - this.prefixes = new ArrayList<>(); - for (int i1 = 0; i1 < order.size(); i1++) this.prefixes.add(new HashSet<>()); - initializeScores(); - return score(); - } - - /** - * @return The score of the current permutation. - */ - public float score() { - return sum(); - } - - private float sum() { - float score = 0; - - for (int i = 0; i < this.pi.size(); i++) { - float score1 = this.scores.get(i).getScore(); - score += score1; - } - - return score; - } - - /** - * Moves v to a new index. - * - * @param v The variable to move. - * @param toIndex The index to move v to. - */ - public void moveTo(Node v, int toIndex) { -// if (!this.pi.contains(v)) return; - - int vIndex = index(v); - - if (vIndex == toIndex) return; - -// if (lastMoveSame(vIndex, toIndex)) return; - - this.pi.remove(v); - this.pi.add(toIndex, v); - - if (toIndex < vIndex) { - updateScores(toIndex, vIndex); - } else { - updateScores(vIndex, toIndex); - } - } - - public void demote(Node v) { - int vIndex = index(v); - int toIndex = vIndex + 1; - - if (toIndex > size() - 1) return; - - this.pi.remove(v); - this.pi.add(toIndex, v); - - updateScores(vIndex, toIndex); - } - - /** - * Swaps m and n in the permutation. - * - * @param m The first variable. - * @param n The second variable. - * @return True iff the swap was done. - */ - public boolean swap(Node m, Node n) { - int i = this.orderHash.get(m); - int j = this.orderHash.get(n); - - this.pi.set(i, n); - this.pi.set(j, m); - - if (violatesKnowledge(this.pi)) { - this.pi.set(i, m); - this.pi.set(j, n); - return false; - } - - if (i < j) { - updateScores(i, j); - } else { - updateScores(j, i); - } - - return true; - } - - /** - * @return A copy of the current permutation. - */ - public List getPi() { - return new ArrayList<>(this.pi); - } - - /** - * Return the index of v in the current permutation. - * - * @param v The variable. - * @return Its index. - */ - public int index(Node v) { - if (!this.orderHash.containsKey(v)) { - System.out.println(); - } - - Integer integer = this.orderHash.get(v); - - if (integer == null) - throw new IllegalArgumentException("First 'evaluate' a permutation containing variable " - + v + "."); - - return integer; - } - - /** - * Returns the parents of the node at index p. - * - * @param p The index of the node. - * @return Its parents. - */ - public Set getParents(int p) { - return new HashSet<>(this.scores.get(p).getParents()); - } - - /** - * Returns the parents of a node v. - * - * @param v The variable. - * @return Its parents. - */ - public Set getParents(Node v) { - return getParents(index(v)); - } - - /** - * Returns the nodes adjacent to v. - * - * @param v The variable. - * @return Its adjacent nodes. - */ - public Set getAdjacentNodes(Node v) { - Set adj = new HashSet<>(); - - for (Node w : this.pi) { - if (getParents(v).contains(w) || getParents(w).contains(v)) { - adj.add(w); - } - } - - return adj; - } - - /** - * Returns the DAG build for the current permutation, or its CPDAG. - * - * @param cpDag True iff the CPDAG should be returned, False if the DAG. - * @return This graph. - */ - public Graph getGraph(boolean cpDag) { - List order = getPi(); - Graph G1 = new EdgeListGraph(this.variables); - - for (int p = 0; p < order.size(); p++) { - for (Node z : getParents(p)) { - G1.addDirectedEdge(z, order.get(p)); - } - } - - GraphUtils.replaceNodes(G1, this.variables); - - if (cpDag) { - return SearchGraphUtils.cpdagForDag(G1); - } else { - return G1; - } - } - - /** - * Returns a list of adjacent node pairs in the current graph. - * - * @return This list. - */ - public List getAdjacencies() { - List order = getPi(); - Set pairs = new HashSet<>(); - - for (int i = 0; i < order.size(); i++) { - for (int j = 0; j < i; j++) { - Node x = order.get(i); - Node y = order.get(j); - - if (adjacent(x, y)) { - pairs.add(new NodePair(x, y)); - } - } - } - - return new ArrayList<>(pairs); - } - - public Set getAncestors(Node node) { - Set ancestors = new HashSet<>(); - collectAncestorsVisit(node, ancestors); - - return ancestors; - } - - private void collectAncestorsVisit(Node node, Set ancestors) { - if (ancestors.contains(node)) { - return; - } - - ancestors.add(node); - Set parents = getParents(node); - - if (!parents.isEmpty()) { - for (Node parent : parents) { - collectAncestorsVisit(parent, ancestors); - } - } - } - - /** - * Returns a list of edges for the current graph as a list of ordered pairs. - * - * @return This list. - */ - public List> getEdges() { - List order = getPi(); - List> edges = new ArrayList<>(); - - for (Node y : order) { - for (Node x : getParents(y)) { - edges.add(new OrderedPair<>(x, y)); - } - } - - return edges; - } - - /** - * @return The number of edges in the current graph. - */ - public int getNumEdges() { - int numEdges = 0; - - for (int p = 0; p < this.pi.size(); p++) { - numEdges += getParents(p).size(); - } - - return numEdges; - } - - /** - * Returns the node at index j in pi. - * - * @param j The index. - * @return The node at that index. - */ - public Node get(int j) { - return this.pi.get(j); - } - - /** - * @return The size of pi, the current permutation. - */ - public int size() { - return this.pi.size(); - } - - /** - * Returns True iff a is adjacent to b in the current graph. - * - * @param a The first node. - * @param b The second node. - * @return True iff adj(a, b). - */ - public boolean adjacent(Node a, Node b) { - if (a == b) return false; - return getParents(a).contains(b) || getParents(b).contains(a); - } - - /** - * Returns true iff [a, b, c] is a collider. - * - * @param a The first node. - * @param b The second node. - * @param c The third node. - * @return True iff a->b<-c in the current DAG. - */ - public boolean collider(Node a, Node b, Node c) { - return getParents(b).contains(a) && getParents(b).contains(c); - } - - /** - * Returns true iff [a, b, c] is a triangle. - * - * @param a The first node. - * @param b The second node. - * @param c The third node. - * @return True iff adj(a, b) and adj(b, c) and adj(a, c). - */ - public boolean triangle(Node a, Node b, Node c) { - return adjacent(a, b) && adjacent(b, c) && adjacent(a, c); - } - - /** - * True iff the nodes in W form a clique in the current DAG. - * - * @param W The nodes. - * @return True iff these nodes form a clique. - */ - public boolean clique(List W) { - for (int i = 0; i < W.size(); i++) { - for (int j = i + 1; j < W.size(); j++) { - if (!adjacent(W.get(i), W.get(j))) { - return false; - } - } - } - - return true; - } - - private boolean violatesKnowledge(List order) { - if (!knowledge.isEmpty()) { - 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())) { - return true; - } - } - } - } - - return false; - } - - private void initializeScores() { - for (int i1 = 0; i1 < this.pi.size(); i1++) this.prefixes.set(i1, null); - - for (int i = 0; i < this.pi.size(); i++) { - recalculate(i); - this.orderHash.put(this.pi.get(i), i); - } - } - - public void updateScores(int i1, int i2) { - for (int i = i1; i <= i2; i++) { - recalculate(i); - this.orderHash.put(this.pi.get(i), i); - } - } - - private float score(Node n, Set pi) { - pi = new HashSet<>(pi); - - this.cache.computeIfAbsent(n, w -> new HashMap<>()); - Float score = this.cache.get(n).get(pi); - - if (score != null) { - return score; - } - - int[] parentIndices = new int[pi.size()]; - - int k = 0; - - for (Node p : pi) { - parentIndices[k++] = this.variablesHash.get(p); - } - - float v = (float) this.score.localScore(this.variablesHash.get(n), parentIndices); - - this.cache.computeIfAbsent(n, w -> new HashMap<>()); - this.cache.get(n).put(pi, v); - - return v; - } - - private Set getPrefix(int i) { - Set prefix = new HashSet<>(); - - for (int j = 0; j < i; j++) { - prefix.add(this.pi.get(j)); - } - - return prefix; - } - - private void recalculate(int p) { - Set prefix = getPrefix(p); - Pair pair = getGrowShrinkScore(p, prefix); - this.scores.set(p, pair); - } - - private void nodesHash(Map nodesHash, List variables) { - for (int i = 0; i < variables.size(); i++) { - nodesHash.put(variables.get(i), i); - } - } - - private boolean lastMoveSame(int i1, int i2) { - if (i1 <= i2) { - for (int i = i1; i <= i2; i++) { - if (!getPrefix(i).equals(this.prefixes.get(i))) return false; - } - } else { - for (int i = i2; i <= i1; i++) { - if (!getPrefix(i).equals(this.prefixes.get(i))) return false; - } - } - - return true; - } - - @NotNull - private Pair getGrowShrinkScore(int p, Set prefix) { - Node n = this.pi.get(p); - - Set parents = new HashSet<>(); - float sMax = score(n, new HashSet<>()); - - boolean changed = true; - - // Grow-shrink - while (changed) { - changed = false; - - // Let z be the node that maximizes the score... - Node z = null; - - for (Node z0 : prefix) { - if (parents.contains(z0)) continue; - - if (!knowledge.isEmpty() && this.knowledge.isForbidden(z0.getName(), n.getName())) continue; - parents.add(z0); - - float s2 = score(n, parents); - - if (s2 >= sMax) { - sMax = s2; - z = z0; - } - - parents.remove(z0); - } - - if (z != null) { - parents.add(z); - changed = true; - } - - } - - boolean changed2 = true; - - while (changed2) { - changed2 = false; - - Node w = null; - - for (Node z0 : new HashSet<>(parents)) { - parents.remove(z0); - - float s2 = score(n, parents); - - if (s2 >= sMax) { - sMax = s2; - w = z0; - } - - parents.add(z0); - } - - if (w != null) { - parents.remove(w); - changed2 = true; - } - } - - return new Pair(parents, Float.isNaN(sMax) ? Float.NEGATIVE_INFINITY : sMax); - } - - private static class Pair { - private final Set parents; - private final float score; - - - private Pair(Set parents, float score) { - this.parents = parents; - this.score = score; - } - - public Set getParents() { - return this.parents; - } - - public float getScore() { - return this.score; - } - - public int hashCode() { - return this.parents.hashCode();// + (int) floor(10000 * this.score); - } - - public boolean equals(Object o) { - if (o == null) return false; - if (!(o instanceof Pair)) return false; - Pair thatPair = (Pair) o; - return this.parents.equals(thatPair.parents);// && this.score == thatPair.score; - } - } -} From 27b7707589c4dffcf022b6d45a8f947e5850302c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:45:29 -0400 Subject: [PATCH 151/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Sp.java | 123 +++++++++--------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 1189b1fa35..35445d2c35 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -156,82 +156,83 @@ public Score getScore() { return score; } -} - -class SwapIterator implements Iterator { - private int[] next; - private final int n; - private final int[] perm; - private final int[] dirs; - - public SwapIterator(int size) { - this.n = size; - if (this.n <= 0) { - this.perm = null; - this.dirs = null; - } else { - this.perm = new int[n]; - this.dirs = new int[n]; - for (int i = 0; i < n; i++) { - this.perm[i] = i; - this.dirs[i] = -1; + private static class SwapIterator implements Iterator { + private int[] next; + private final int n; + private final int[] perm; + private final int[] dirs; + + public SwapIterator(int size) { + this.n = size; + if (this.n <= 0) { + this.perm = null; + this.dirs = null; + } else { + this.perm = new int[n]; + this.dirs = new int[n]; + for (int i = 0; i < n; i++) { + this.perm[i] = i; + this.dirs[i] = -1; + } + this.dirs[0] = 0; } - this.dirs[0] = 0; } - } - @Override - public int[] next() { - int[] next = makeNext(); - this.next = null; - return next; - } + @Override + public int[] next() { + int[] next = makeNext(); + this.next = null; + return next; + } - @Override - public boolean hasNext() { - return makeNext() != null; - } + @Override + public boolean hasNext() { + return makeNext() != null; + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } - private int[] makeNext() { - if (this.next != null) return this.next; - if ((this.dirs == null) || (this.perm == null)) return null; + private int[] makeNext() { + if (this.next != null) return this.next; + if ((this.dirs == null) || (this.perm == null)) return null; - int i = -1; - int x = -1; - for (int j = 0; j < n; j++) - if ((this.dirs[j] != 0) && (this.perm[j] > x)) { - x = this.perm[j]; - i = j; - } + int i = -1; + int x = -1; + for (int j = 0; j < n; j++) + if ((this.dirs[j] != 0) && (this.perm[j] > x)) { + x = this.perm[j]; + i = j; + } - if (i == -1) return null; + if (i == -1) return null; - int k = i + this.dirs[i]; - this.next = new int[] {i, k}; + int k = i + this.dirs[i]; + this.next = new int[] {i, k}; - swap(i, k, this.dirs); - swap(i, k, this.perm); + swap(i, k, this.dirs); + swap(i, k, this.perm); - if ((k == 0) || (k == n - 1) || (this.perm[k + this.dirs[k]] > x)) - this.dirs[k] = 0; + if ((k == 0) || (k == n - 1) || (this.perm[k + this.dirs[k]] > x)) + this.dirs[k] = 0; - for (int j = 0; j < n; j++) - if (this.perm[j] > x) - this.dirs[j] = (j < k) ? +1 : -1; + for (int j = 0; j < n; j++) + if (this.perm[j] > x) + this.dirs[j] = (j < k) ? +1 : -1; - return this.next; - } + return this.next; + } - private static void swap(int i, int j, int[] arr) { - int x = arr[i]; - arr[i] = arr[j]; - arr[j] = x; + private static void swap(int i, int j, int[] arr) { + int x = arr[i]; + arr[i] = arr[j]; + arr[j] = x; + } } } + + From dbbd369ddd0999fea8d9eeabb59ff64c69f31aa1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:46:04 -0400 Subject: [PATCH 152/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/SepsetsGreedy2.java | 203 ------------------ 1 file changed, 203 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy2.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy2.java deleted file mode 100644 index c8799a7000..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy2.java +++ /dev/null @@ -1,203 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.ChoiceGenerator; -import org.apache.commons.math3.util.FastMath; - -import java.util.ArrayList; -import java.util.List; - -/** - * Selects the first sepset it comes to from among the extra sepsets or the adjacents of i or k, - * or null if none is found. - */ -public class SepsetsGreedy2 implements SepsetProducer { - private final Graph graph; - private final IndependenceTest independenceTest; - private final SepsetMap extraSepsets; - private final TeyssierScorer scorer; - private int depth; - private boolean verbose; - private IndependenceResult result; - - public SepsetsGreedy2(Graph graph, IndependenceTest independenceTest, TeyssierScorer scorer, SepsetMap extraSepsets, int depth) { - this.graph = graph; - this.independenceTest = independenceTest; - this.scorer = scorer; - this.extraSepsets = extraSepsets; - this.depth = depth; - } - - /** - * Pick out the sepset from among adj(i) or adj(k) with the highest score value. - */ - public List getSepset(Node i, Node k) { - return getSepsetGreedy(i, k); - } - - public boolean isUnshieldedCollider(Node i, Node j, Node k) { - List set = getSepsetGreedy(i, k); - return set != null && !set.contains(j); - } - - public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { - List set = getSepsetGreedy(i, k); - return set != null && set.contains(j); - } - - private List getSepsetGreedy(Node i, Node k) { - if (this.extraSepsets != null) { - List v = this.extraSepsets.get(i, k); - - if (v != null) { - return v; - } - } - - List adji = this.graph.getAdjacentNodes(i); - List adjk = this.graph.getAdjacentNodes(k); - adji.remove(k); - adjk.remove(i); - - List allCond = new ArrayList<>(adji); - allCond.addAll(adjk); - - List maxCond = null; - double maxScore = Float.NEGATIVE_INFINITY; - - for (int d = 0; d <= FastMath.min((this.depth == -1 ? 1000 : this.depth), FastMath.max(adji.size(), adjk.size())); d++) { - if (d <= adji.size()) { - ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d); - int[] choice; - - while ((choice = gen.next()) != null) { - List v = GraphUtils.asList(choice, adji); - - List after = new ArrayList<>(allCond); - after.removeAll(v); - - List perm = new ArrayList<>(v); - perm.add(i); - perm.add(k); - perm.addAll(after); - - double score = scorer.score(perm); - - if (!scorer.adjacent(i, k)) { - if (score > maxScore) { - maxScore = score; - maxCond = v; - } - -// return before; - } - -// if (getIndependenceTest().checkIndependence(i, k, v).independent()) { -// return v; -// } - } - } - - if (d <= adjk.size()) { - ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d); - int[] choice; - - while ((choice = gen.next()) != null) { - List v = GraphUtils.asList(choice, adjk); - - List after = new ArrayList<>(allCond); - after.removeAll(v); - - List perm = new ArrayList<>(v); - perm.add(i); - perm.add(k); - perm.addAll(after); - - double score = scorer.score(perm); - - if (!scorer.adjacent(i, k)) { - if (score > maxScore) { - maxScore = score; - maxCond = v; - } -// return before; - } - -// if (getIndependenceTest().checkIndependence(i, k, v).independent()) { -// return v; -// } - } - } - } - - return maxCond; - -// return null; - } - - @Override - public boolean isIndependent(Node a, Node b, List c) { - IndependenceResult result = this.independenceTest.checkIndependence(a, b, c); - this.result = result; - return result.independent(); - } - - @Override - public double getScore() { - return -(result.getPValue() - this.independenceTest.getAlpha()); - } - - @Override - public List getVariables() { - return this.independenceTest.getVariables(); - } - - private IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - public boolean isVerbose() { - return this.verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public Graph getDag() { - if (this.independenceTest instanceof IndTestDSep) { - return ((IndTestDSep) this.independenceTest).getGraph(); - } else { - return null; - } - } - - public void setDepth(int depth) { - this.depth = depth; - } -} - From 37d0df05ac3e986d289fb7379d6e4e5fa76ed135 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:47:36 -0400 Subject: [PATCH 153/464] Fixing documentation etc. --- .../edu/cmu/tetradapp/model/PurifyRunner.java | 2 +- .../search/BpcTetradPurifyWashdown.java | 2 +- .../java/edu/cmu/tetrad/search/Purify.java | 4 +- .../cmu/tetrad/search/PurifyTetradBased.java | 538 ++++++------------ .../cmu/tetrad/search/PurifyTetradBased2.java | 354 ------------ .../java/edu/cmu/tetrad/test/TestPurify.java | 6 +- 6 files changed, 169 insertions(+), 737 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased2.java diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index 57fd46e9d8..b2ac4129aa 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -95,7 +95,7 @@ public void execute() { List> inputPartition = ClusterUtils.clustersToPartition((Clusters) getParams().get("clusters", null), test.getVariables()); - IPurify purify = new PurifyTetradBased2(test); + IPurify purify = new PurifyTetradBased(test); List> partition = purify.purify(inputPartition); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java index 6146651bab..f8afec133a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java @@ -69,7 +69,7 @@ public BpcTetradPurifyWashdown(ICovarianceMatrix cov, TestType testType, double * @return The discovered graph. */ public Graph search() { - IPurify purify = new PurifyTetradBased2(this.test); + IPurify purify = new PurifyTetradBased(this.test); List variables = new ArrayList<>(this.variables); List> clustering = new ArrayList<>(); List disgards; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java index 42947f488b..a691ef7336 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java @@ -185,7 +185,7 @@ private Graph getResultGraph() { type = null; if (type == TestType.TETRAD_BASED) { - IPurify purifier = new PurifyTetradBased2(this.tetradTest); + IPurify purifier = new PurifyTetradBased(this.tetradTest); List> partition2 = purifier.purify(ClusterUtils.convertIntToList(getClusters(), getVariables())); List pureClusters = ClusterUtils.convertListToInt(partition2, getVariables()); return ClusterUtils.convertSearchGraph(pureClusters, this.tetradTest.getVarNames()); @@ -202,7 +202,7 @@ private Graph getResultGraph() { } else { List pureClusters; // if (constraintSearchVariation == 0) { - IPurify purifier = new PurifyTetradBased2(this.tetradTest); + IPurify purifier = new PurifyTetradBased(this.tetradTest); List> partition2 = purifier.purify(ClusterUtils.convertIntToList(getClusters(), this.tetradTest.getVariables())); pureClusters = ClusterUtils.convertListToInt(partition2, this.tetradTest.getVariables()); // pureClusters = tetradBasedPurify(getClusters()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java index 01c688dd7e..13365e96d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java @@ -22,13 +22,13 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.RandomUtil; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.*; /** * A clean-up of Ricardo's tetrad-based purify. @@ -38,372 +38,221 @@ public class PurifyTetradBased implements IPurify { private final boolean outputMessage = true; private final TetradTest tetradTest; - private final int numVars; - boolean doFdr; - boolean listTetrads; + + private final List nodes; public PurifyTetradBased(TetradTest tetradTest) { this.tetradTest = tetradTest; - this.numVars = tetradTest.getVarNames().length; + this.nodes = tetradTest.getVariables(); } public List> purify(List> clustering) { - System.out.println("*** " + clustering); - List _clustering = convertListToInt(clustering); - - System.out.println("&&&"); - printIntPartition(_clustering); - List _clustering2 = purify2(_clustering); + // The input nodes may not be object identical to the ones from the tetrad test, so we map them over then + // back by their names. + List originalNodes = new ArrayList<>(); - System.out.println("%%%"); - printIntPartition(_clustering2); - - return convertIntToList(_clustering2); - } - - public void setTrueGraph(Graph mim) { - throw new UnsupportedOperationException(); - } - - private void printIntPartition(List clustering) { - for (int i = 0; i < clustering.size(); i++) { - int[] cluster = clustering.get(i); - System.out.print(i + ": "); - for (int k : cluster) { - System.out.print(k + " "); - } - - System.out.println(); + for (List cluster : clustering) { + originalNodes.addAll(cluster); } - System.out.println(); - } - - private List convertListToInt(List> clustering) { - List nodes = this.tetradTest.getVariables(); - List _clustering = new ArrayList<>(); + List> _clustering = new ArrayList<>(); for (List cluster : clustering) { - int[] _cluster = new int[cluster.size()]; - - for (int j = 0; j < cluster.size(); j++) { - for (int k = 0; k < nodes.size(); k++) { - if (nodes.get(k).getName().equals(cluster.get(j).getName())) { - _cluster[j] = k; - } - } - } - - _clustering.add(_cluster); + List converted = GraphUtils.replaceNodes(cluster, this.nodes); + _clustering.add(converted); } - return _clustering; - } - - private List> convertIntToList(List clustering) { - List nodes = this.tetradTest.getVariables(); - List> _clustering = new ArrayList<>(); - - for (int[] cluster : clustering) { - List _cluster = new ArrayList<>(); + if (_clustering.isEmpty()) { + throw new NullPointerException("Clusters not specified."); + } - for (int k : cluster) { - _cluster.add(nodes.get(k)); - } + List> result = combinedSearch(_clustering); + List> convertedResult = new ArrayList<>(); - _clustering.add(_cluster); + for (List cluster : result) { + List converted = GraphUtils.replaceNodes(cluster, originalNodes); + convertedResult.add(converted); } - return _clustering; + return convertedResult; } - - private List purify2(List clustering) { - return tetradBasedPurify(clustering); + public void setTrueGraph(Graph mim) { } - private List tetradBasedPurify(List clustering) { - boolean[] eliminated = new boolean[this.numVars]; - for (int i = 0; i < this.numVars; i++) { - eliminated[i] = false; - } - - printlnMessage("TETRAD-BASED PURIFY:"); - printlnMessage("Finding Unidimensional Measurement Models"); - printlnMessage(); - printlnMessage("Initially Specified Measurement Model"); - printlnMessage(); - printClustering(clustering, eliminated); - printlnMessage(); - - printlnMessage("INTRA-CONSTRUCT PHASE."); - printlnMessage("----------------------"); - printlnMessage(); - for (Object o : clustering) { - intraConstructPhase2((int[]) o, eliminated); - } - printlnMessage(); - - printlnMessage("CROSS-CONSTRUCT PHASE."); - printlnMessage("----------------------"); - printlnMessage(); - crossConstructPhase2(clustering, eliminated); - printlnMessage(); - - printlnMessage( - - "------------------------------------------------------"); - printlnMessage("Output Measurement Model"); - List output = buildSolution(clustering, eliminated); - printClustering(output, eliminated); + private List> combinedSearch(List> clustering) { + Set eliminated = new HashSet<>(); - return output; - } - - private void intraConstructPhase2(int[] _cluster, boolean[] eliminated) { - List cluster = new ArrayList<>(); - for (int i : _cluster) cluster.add(i); + Set allImpurities = null; double cutoff = this.tetradTest.getSignificance(); + final int count = 0; - if (this.doFdr) { - List allPValues = new ArrayList<>(listPValues(cluster, eliminated, Double.MAX_VALUE)); - System.out.println("# p values for this cluster: " + allPValues.size()); - Collections.sort(allPValues); - - cutoff = 1.; + for (List cluster : clustering) { + Set impurities = listTetrads(cluster, eliminated, cutoff); - for (int c = 0; c < allPValues.size(); c++) { - if (allPValues.get(c) >= this.tetradTest.getSignificance() * (c + 1.) / allPValues.size()) { - cutoff = allPValues.get(c); - break; + if (impurities != null) { + if (allImpurities == null) { + allImpurities = new HashSet<>(); } + allImpurities.addAll(impurities); } - - System.out.println("FDR cutoff = " + cutoff); } - List pValues2 = listPValues(cluster, eliminated, cutoff); + Set impurities = listCrossConstructTetrads(clustering, eliminated, cutoff); - if (pValues2 == null) { - System.out.println("Nothing to count."); - return; + if (impurities != null) { + if (allImpurities == null) { + allImpurities = new HashSet<>(); + } + allImpurities.addAll(impurities); } - int numImpurities = pValues2.size(); - - System.out.println("Num impurities going in = " + numImpurities); - - final int minImpurities = 0; - - while (numImpurities > 0) { - System.out.println("Num impurities this round = " + numImpurities); - - int min = Integer.MAX_VALUE; - int minIndex = -1; - List minList = new ArrayList<>(); - - for (int i : cluster) { - if (eliminated[i]) continue; - - eliminated[i] = true; - List pValues = listPValues(cluster, eliminated, cutoff); - - if (pValues == null) { - eliminated[i] = false; - continue; - } + if (allImpurities == null) { + return new ArrayList<>(); + } - System.out.println("Tried dropping " + this.tetradTest.getVarNames()[i] + " (" + pValues.size() - + " impurities)"); + NumberFormat nf = new DecimalFormat("0.####E00"); - eliminated[i] = false; + while (true) { + int max = 0; + Node maxNode = null; + Map> impuritiesPerNode = getImpuritiesPerNode(allImpurities, eliminated); - if (pValues.size() < min) { - min = pValues.size(); - minIndex = i; - numImpurities = min; - minList = new ArrayList<>(); - minList.add(i); - } else if (pValues.size() == min) { - minList.add(i); + for (Node node : this.nodes) { + if (impuritiesPerNode.get(node).size() > max) { + max = impuritiesPerNode.get(node).size(); + maxNode = node; } } - if (minList.isEmpty()) { - break; - } - - if (minIndex != -1) { - if (min < minImpurities) break; + if (max == 0) break; - int index = minList.get(RandomUtil.getInstance().nextInt(minList.size())); + double minP = Double.POSITIVE_INFINITY; + double maxP = Double.NEGATIVE_INFINITY; - for (int m = 0; m < minList.size(); m++) { - eliminated[index] = true; - numImpurities = min; - System.out.println("Dropped " + this.tetradTest.getVarNames()[index]); + for (Tetrad tetrad : impuritiesPerNode.get(maxNode)) { + if (tetrad.getPValue() < minP) { + minP = tetrad.getPValue(); } - } - } - } - - private void crossConstructPhase2(List clustering, boolean[] eliminated) { - double cutoff = this.tetradTest.getSignificance(); - - if (this.doFdr) { - List allPValues = new ArrayList<>(listCrossConstructPValues(clustering, eliminated, Double.MAX_VALUE)); - System.out.println("Num p values cross clusters: " + allPValues.size()); - - if (allPValues.isEmpty()) return; - - Collections.sort(allPValues); - System.out.println("# p values = " + allPValues.size()); - cutoff = 1.; - - System.out.println("significance = " + this.tetradTest.getSignificance()); - for (int c = 0; c < allPValues.size(); c++) { - if (allPValues.get(c) >= this.tetradTest.getSignificance() * (c + 1.) / allPValues.size()) { - cutoff = allPValues.get(c); - break; + if (tetrad.getPValue() > maxP) { + maxP = tetrad.getPValue(); } } - } - - List pValues = listCrossConstructPValues(clustering, eliminated, cutoff); - if (pValues == null) { - System.out.println("Nothing to count."); - return; + impuritiesPerNode.remove(maxNode); + eliminated.add(maxNode); } - int numImpurities = pValues.size(); - final int minImpurities = 0; - - while (numImpurities > 0) { - System.out.println("Num impurities this round = " + numImpurities); - - int min = Integer.MAX_VALUE; - int minIndex = -1; - List minList = new ArrayList<>(); - - for (int i = 0; i < eliminated.length; i++) { - if (eliminated[i]) continue; + return buildSolution(clustering, eliminated); + } - eliminated[i] = true; - List pValuesCrossConstruct = listCrossConstructPValues(clustering, eliminated, cutoff); + private Map> getImpuritiesPerNode(Set allImpurities, Set _eliminated) { + Map> impuritiesPerNode = new HashMap<>(); - if (pValuesCrossConstruct == null) { - eliminated[i] = false; - continue; - } + for (Node node : this.nodes) { + impuritiesPerNode.put(node, new HashSet<>()); + } - System.out.println("Tried dropping " + this.tetradTest.getVarNames()[i] + " (" + pValuesCrossConstruct.size() - + " impurities)"); - eliminated[i] = false; - - if (pValuesCrossConstruct.size() < min) { - min = pValuesCrossConstruct.size(); - minIndex = i; - numImpurities = min; - minList = new ArrayList<>(); - minList.add(i); - } else if (pValuesCrossConstruct.size() == min) { - minList.add(i); - } + for (Tetrad tetrad : allImpurities) { + if (_eliminated.contains(tetrad.getI())) { + continue; } - if (minList.isEmpty()) { - break; + if (_eliminated.contains(tetrad.getJ())) { + continue; } - if (minIndex != -1) { - if (min < minImpurities) break; - - int index = minList.get(RandomUtil.getInstance().nextInt(minList.size())); + if (_eliminated.contains(tetrad.getK())) { + continue; + } - eliminated[index] = true; - numImpurities = min; - System.out.println("Dropped " + this.tetradTest.getVarNames()[index]); + if (_eliminated.contains(tetrad.getL())) { + continue; } - } - printClustering(clustering, eliminated); + impuritiesPerNode.get(tetrad.getI()).add(tetrad); + impuritiesPerNode.get(tetrad.getJ()).add(tetrad); + impuritiesPerNode.get(tetrad.getK()).add(tetrad); + impuritiesPerNode.get(tetrad.getL()).add(tetrad); + } + return impuritiesPerNode; } - private List listCrossConstructPValues(List clustering, boolean[] eliminated, double cutoff) { - List allPValues = new ArrayList<>(); + private Set listCrossConstructTetrads(List> clustering, Set eliminated, double cutoff) { + Set allTetrads = new HashSet<>(); boolean countable = false; for (int p1 = 0; p1 < clustering.size(); p1++) { for (int p2 = p1 + 1; p2 < clustering.size(); p2++) { - int[] cluster1 = clustering.get(p1); - int[] cluster2 = clustering.get(p2); + List cluster1 = clustering.get(p1); + List cluster2 = clustering.get(p2); - if (cluster1.length >= 3 && cluster2.length >= 1) { - ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.length, 3); + if (cluster1.size() >= 3 && cluster2.size() >= 1) { + ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 3); int[] choice1; while ((choice1 = gen1.next()) != null) { - ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.length, 1); + ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 1); int[] choice2; while ((choice2 = gen2.next()) != null) { - List crossCluster = new ArrayList<>(); - for (int i : choice1) crossCluster.add(cluster1[i]); - for (int i : choice2) crossCluster.add(cluster2[i]); - List pValues = listPValues(crossCluster, eliminated, cutoff); + List crossCluster = new ArrayList<>(); + for (int i : choice1) crossCluster.add(cluster1.get(i)); + for (int i : choice2) crossCluster.add(cluster2.get(i)); + Set tetrads = listTetrads(crossCluster, eliminated, cutoff); - if (pValues != null) { + if (tetrads != null) { countable = true; - allPValues.addAll(pValues); + allTetrads.addAll(tetrads); } } } } - if (cluster2.length >= 3 && cluster1.length >= 1) { - ChoiceGenerator gen1 = new ChoiceGenerator(cluster2.length, 3); + if (cluster2.size() >= 3 && cluster1.size() >= 1) { + ChoiceGenerator gen1 = new ChoiceGenerator(cluster2.size(), 3); int[] choice1; while ((choice1 = gen1.next()) != null) { - ChoiceGenerator gen2 = new ChoiceGenerator(cluster1.length, 1); + ChoiceGenerator gen2 = new ChoiceGenerator(cluster1.size(), 1); int[] choice2; while ((choice2 = gen2.next()) != null) { - List crossCluster = new ArrayList<>(); - for (int i : choice1) crossCluster.add(cluster2[i]); - for (int i : choice2) crossCluster.add(cluster1[i]); - List pValues = listPValues(crossCluster, eliminated, cutoff); + List crossCluster = new ArrayList<>(); + for (int i : choice1) crossCluster.add(cluster2.get(i)); + for (int i : choice2) crossCluster.add(cluster1.get(i)); + + Set tetrads = listTetrads(crossCluster, eliminated, cutoff); - if (pValues != null) { + if (tetrads != null) { countable = true; - allPValues.addAll(pValues); + allTetrads.addAll(tetrads); } } } } - if (cluster1.length >= 2 && cluster2.length >= 2) { - ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.length, 2); + if (cluster1.size() >= 2 && cluster2.size() >= 2) { + ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 2); int[] choice1; while ((choice1 = gen1.next()) != null) { - ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.length, 2); + ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 2); int[] choice2; while ((choice2 = gen2.next()) != null) { - List crossCluster = new ArrayList<>(); - for (int i : choice1) crossCluster.add(cluster1[i]); - for (int i : choice2) crossCluster.add(cluster2[i]); + List crossCluster = new ArrayList<>(); + for (int i : choice1) crossCluster.add(cluster1.get(i)); + for (int i : choice2) crossCluster.add(cluster2.get(i)); - List pValues = listPValues2by2(crossCluster, eliminated, cutoff); + Set tetrads = listTetrads2By2(crossCluster, eliminated, cutoff); - if (pValues != null) { + if (tetrads != null) { countable = true; - allPValues.addAll(pValues); + allTetrads.addAll(tetrads); } } } @@ -411,156 +260,93 @@ private List listCrossConstructPValues(List clustering, boolean[] } } - return countable ? allPValues : null; + return countable ? allTetrads : null; } - private List listPValues(List cluster, boolean[] eliminated, double cutoff) { + private Set listTetrads(List cluster, Set eliminated, double cutoff) { if (cluster.size() < 4) return null; + cluster = new ArrayList<>(cluster); boolean countable = false; - List pValues = new ArrayList<>(); + Set tetrads = new HashSet<>(); ChoiceGenerator gen = new ChoiceGenerator(cluster.size(), 4); int[] choice; while ((choice = gen.next()) != null) { - int i = choice[0]; - int j = choice[1]; - int k = choice[2]; - int l = choice[3]; + int _i = choice[0]; + int _j = choice[1]; + int _k = choice[2]; + int _l = choice[3]; - int ci = cluster.get(i); - int cj = cluster.get(j); - int ck = cluster.get(k); - int cl = cluster.get(l); + Node ci = cluster.get(_i); + Node cj = cluster.get(_j); + Node ck = cluster.get(_k); + Node cl = cluster.get(_l); - if (eliminated[ci] || eliminated[cj] || eliminated[ck] || eliminated[cl]) { + if (eliminated.contains(ci) || eliminated.contains(cj) || eliminated.contains(ck) || eliminated.contains(cl)) { continue; } countable = true; + double p1; + double p2; + double p3; - double p1 = this.tetradTest.tetradPValue(ci, cj, ck, cl); - double p2 = this.tetradTest.tetradPValue(ci, cl, cj, ck); - double p3 = this.tetradTest.tetradPValue(ci, ck, cj, cl); + p1 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(cj), this.nodes.indexOf(ck), this.nodes.indexOf(cl)); + p2 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(cj), this.nodes.indexOf(cl), this.nodes.indexOf(ck)); + p3 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(ck), this.nodes.indexOf(cl), this.nodes.indexOf(cj)); if (p1 < cutoff) { - printTetrad(ci, cj, ck, cl, p1); - pValues.add(p1); + tetrads.add(new Tetrad(ci, cj, ck, cl, p1)); } if (p2 < cutoff) { - printTetrad(ci, cl, cj, ck, p2); - pValues.add(p2); + tetrads.add(new Tetrad(ci, cj, cl, ck, p2)); } if (p3 < cutoff) { - printTetrad(ci, ck, cj, cl, p3); - pValues.add(p3); + tetrads.add(new Tetrad(ci, ck, cl, cj, p3)); } } - return countable ? pValues : null; - } - - private void printTetrad(int ci, int cj, int ck, int cl, double p1) { - if (this.listTetrads) { - String[] varNames = this.tetradTest.getVarNames(); - System.out.println("Tetrad <" + varNames[ci] + ", " + varNames[cj] + ", " + varNames[ck] + ", " + varNames[cl] + "> p = " + p1); - } + return countable ? tetrads : null; } - private List listPValues2by2(List cluster, boolean[] eliminated, double cutoff) { - if (cluster.size() < 4) return new ArrayList<>(); - - List pValues = new ArrayList<>(); + private Set listTetrads2By2(List cluster, Set eliminated, double cutoff) { + if (cluster.size() < 4) return null; + cluster = new ArrayList<>(cluster); + Set tetrads = new HashSet<>(); - int x = cluster.get(0); - int z = cluster.get(1); - int y = cluster.get(2); - int w = cluster.get(3); + Node ci = cluster.get(0); + Node cj = cluster.get(1); + Node ck = cluster.get(2); + Node cl = cluster.get(3); - if (eliminated[x] || eliminated[z] || eliminated[y] || eliminated[w]) { + if (eliminated.contains(ci) || eliminated.contains(cj) || eliminated.contains(ck) || eliminated.contains(cl)) { return null; } - double p1 = this.tetradTest.tetradPValue(x, y, w, z); - - if (p1 < cutoff) { - printTetrad(x, y, w, z, p1); - pValues.add(p1); - } - - - return pValues; - } - - - private void printMessage(String message) { - if (this.outputMessage) { - System.out.print(message); - } - } + double p3 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(ck), this.nodes.indexOf(cl), this.nodes.indexOf(cj)); +// double p3 = tetradTest.tetradPValue(nodes.indexOf(ci), nodes.indexOf(cj), nodes.indexOf(cl), nodes.indexOf(ck)); - private void printlnMessage(String message) { - if (this.outputMessage) { - System.out.println(message); + if (p3 < cutoff) { + tetrads.add(new Tetrad(ci, ck, cl, cj, p3)); +// tetrads.add(new Tetrad(ci, cj, cl, ck, p3)); } - } - private void printlnMessage() { - if (this.outputMessage) { - System.out.println(); - } + return tetrads; } - private void printClustering(List clustering, boolean[] eliminated) { - for (Object o : clustering) { - int[] c = (int[]) o; - printCluster(c, eliminated); - } - } + private List> buildSolution(List> clustering, Set eliminated) { + List> solution = new ArrayList<>(); - private void printCluster(int[] c, boolean[] eliminated) { - String[] sorted = new String[c.length]; - for (int i = 0; i < c.length; i++) { - sorted[i] = this.tetradTest.getVarNames()[c[i]]; - if (eliminated[c[i]]) sorted[i] = sorted[i] + "X"; - } - for (int i = 0; i < sorted.length - 1; i++) { - String min = sorted[i]; - int min_idx = i; - for (int j = i + 1; j < sorted.length; j++) { - if (sorted[j].compareTo(min) < 0) { - min = sorted[j]; - min_idx = j; - } - } - String temp = sorted[i]; - sorted[i] = min; - sorted[min_idx] = temp; - } - for (String s : sorted) { - printMessage(s + " "); + for (List cluster : clustering) { + List _cluster = new ArrayList<>(cluster); + _cluster.removeAll(eliminated); + solution.add(_cluster); } - printlnMessage(); - } - private List buildSolution(List clustering, boolean[] eliminated) { - List solution = new ArrayList(); - for (Object o : clustering) { - int[] next = (int[]) o; - int[] draftArea = new int[next.length]; - int draftCount = 0; - for (int j : next) { - if (!eliminated[j]) { - draftArea[draftCount++] = j; - } - } - int[] realCluster = new int[draftCount]; - System.arraycopy(draftArea, 0, realCluster, 0, draftCount); - solution.add(realCluster); - } return solution; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased2.java deleted file mode 100644 index acc0129961..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased2.java +++ /dev/null @@ -1,354 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.ChoiceGenerator; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.*; - -/** - * A clean-up of Ricardo's tetrad-based purify. - * - * @author Joe Ramsey - */ -public class PurifyTetradBased2 implements IPurify { - private final boolean outputMessage = true; - private final TetradTest tetradTest; - - private final List nodes; - - public PurifyTetradBased2(TetradTest tetradTest) { - this.tetradTest = tetradTest; - this.nodes = tetradTest.getVariables(); - } - - public List> purify(List> clustering) { - - // The input nodes may not be object identical to the ones from the tetrad test, so we map them over then - // back by their names. - List originalNodes = new ArrayList<>(); - - for (List cluster : clustering) { - originalNodes.addAll(cluster); - } - - List> _clustering = new ArrayList<>(); - - for (List cluster : clustering) { - List converted = GraphUtils.replaceNodes(cluster, this.nodes); - _clustering.add(converted); - } - - if (_clustering.isEmpty()) { - throw new NullPointerException("Clusters not specified."); - } - - List> result = combinedSearch(_clustering); - List> convertedResult = new ArrayList<>(); - - for (List cluster : result) { - List converted = GraphUtils.replaceNodes(cluster, originalNodes); - convertedResult.add(converted); - } - - return convertedResult; - } - - public void setTrueGraph(Graph mim) { - } - - - private List> combinedSearch(List> clustering) { - Set eliminated = new HashSet<>(); - - Set allImpurities = null; - double cutoff = this.tetradTest.getSignificance(); - final int count = 0; - - for (List cluster : clustering) { - Set impurities = listTetrads(cluster, eliminated, cutoff); - - if (impurities != null) { - if (allImpurities == null) { - allImpurities = new HashSet<>(); - } - allImpurities.addAll(impurities); - } - } - - Set impurities = listCrossConstructTetrads(clustering, eliminated, cutoff); - - if (impurities != null) { - if (allImpurities == null) { - allImpurities = new HashSet<>(); - } - allImpurities.addAll(impurities); - } - - if (allImpurities == null) { - return new ArrayList<>(); - } - - NumberFormat nf = new DecimalFormat("0.####E00"); - - while (true) { - int max = 0; - Node maxNode = null; - Map> impuritiesPerNode = getImpuritiesPerNode(allImpurities, eliminated); - - for (Node node : this.nodes) { - if (impuritiesPerNode.get(node).size() > max) { - max = impuritiesPerNode.get(node).size(); - maxNode = node; - } - } - - if (max == 0) break; - - double minP = Double.POSITIVE_INFINITY; - double maxP = Double.NEGATIVE_INFINITY; - - for (Tetrad tetrad : impuritiesPerNode.get(maxNode)) { - if (tetrad.getPValue() < minP) { - minP = tetrad.getPValue(); - } - - if (tetrad.getPValue() > maxP) { - maxP = tetrad.getPValue(); - } - } - - impuritiesPerNode.remove(maxNode); - eliminated.add(maxNode); - } - - return buildSolution(clustering, eliminated); - } - - private Map> getImpuritiesPerNode(Set allImpurities, Set _eliminated) { - Map> impuritiesPerNode = new HashMap<>(); - - for (Node node : this.nodes) { - impuritiesPerNode.put(node, new HashSet<>()); - } - - for (Tetrad tetrad : allImpurities) { - if (_eliminated.contains(tetrad.getI())) { - continue; - } - - if (_eliminated.contains(tetrad.getJ())) { - continue; - } - - if (_eliminated.contains(tetrad.getK())) { - continue; - } - - if (_eliminated.contains(tetrad.getL())) { - continue; - } - - impuritiesPerNode.get(tetrad.getI()).add(tetrad); - impuritiesPerNode.get(tetrad.getJ()).add(tetrad); - impuritiesPerNode.get(tetrad.getK()).add(tetrad); - impuritiesPerNode.get(tetrad.getL()).add(tetrad); - } - return impuritiesPerNode; - } - - private Set listCrossConstructTetrads(List> clustering, Set eliminated, double cutoff) { - Set allTetrads = new HashSet<>(); - boolean countable = false; - - for (int p1 = 0; p1 < clustering.size(); p1++) { - for (int p2 = p1 + 1; p2 < clustering.size(); p2++) { - List cluster1 = clustering.get(p1); - List cluster2 = clustering.get(p2); - - if (cluster1.size() >= 3 && cluster2.size() >= 1) { - ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 3); - int[] choice1; - - while ((choice1 = gen1.next()) != null) { - ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 1); - int[] choice2; - - while ((choice2 = gen2.next()) != null) { - List crossCluster = new ArrayList<>(); - for (int i : choice1) crossCluster.add(cluster1.get(i)); - for (int i : choice2) crossCluster.add(cluster2.get(i)); - Set tetrads = listTetrads(crossCluster, eliminated, cutoff); - - if (tetrads != null) { - countable = true; - allTetrads.addAll(tetrads); - } - } - } - } - - if (cluster2.size() >= 3 && cluster1.size() >= 1) { - ChoiceGenerator gen1 = new ChoiceGenerator(cluster2.size(), 3); - int[] choice1; - - while ((choice1 = gen1.next()) != null) { - ChoiceGenerator gen2 = new ChoiceGenerator(cluster1.size(), 1); - int[] choice2; - - while ((choice2 = gen2.next()) != null) { - List crossCluster = new ArrayList<>(); - for (int i : choice1) crossCluster.add(cluster2.get(i)); - for (int i : choice2) crossCluster.add(cluster1.get(i)); - - Set tetrads = listTetrads(crossCluster, eliminated, cutoff); - - if (tetrads != null) { - countable = true; - allTetrads.addAll(tetrads); - } - } - } - } - - if (cluster1.size() >= 2 && cluster2.size() >= 2) { - ChoiceGenerator gen1 = new ChoiceGenerator(cluster1.size(), 2); - int[] choice1; - - while ((choice1 = gen1.next()) != null) { - ChoiceGenerator gen2 = new ChoiceGenerator(cluster2.size(), 2); - int[] choice2; - - while ((choice2 = gen2.next()) != null) { - List crossCluster = new ArrayList<>(); - for (int i : choice1) crossCluster.add(cluster1.get(i)); - for (int i : choice2) crossCluster.add(cluster2.get(i)); - - Set tetrads = listTetrads2By2(crossCluster, eliminated, cutoff); - - if (tetrads != null) { - countable = true; - allTetrads.addAll(tetrads); - } - } - } - } - } - } - - return countable ? allTetrads : null; - } - - - private Set listTetrads(List cluster, Set eliminated, double cutoff) { - if (cluster.size() < 4) return null; - cluster = new ArrayList<>(cluster); - boolean countable = false; - - Set tetrads = new HashSet<>(); - ChoiceGenerator gen = new ChoiceGenerator(cluster.size(), 4); - int[] choice; - - while ((choice = gen.next()) != null) { - int _i = choice[0]; - int _j = choice[1]; - int _k = choice[2]; - int _l = choice[3]; - - Node ci = cluster.get(_i); - Node cj = cluster.get(_j); - Node ck = cluster.get(_k); - Node cl = cluster.get(_l); - - if (eliminated.contains(ci) || eliminated.contains(cj) || eliminated.contains(ck) || eliminated.contains(cl)) { - continue; - } - - countable = true; - double p1; - double p2; - double p3; - - p1 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(cj), this.nodes.indexOf(ck), this.nodes.indexOf(cl)); - p2 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(cj), this.nodes.indexOf(cl), this.nodes.indexOf(ck)); - p3 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(ck), this.nodes.indexOf(cl), this.nodes.indexOf(cj)); - - if (p1 < cutoff) { - tetrads.add(new Tetrad(ci, cj, ck, cl, p1)); - } - - if (p2 < cutoff) { - tetrads.add(new Tetrad(ci, cj, cl, ck, p2)); - } - - if (p3 < cutoff) { - tetrads.add(new Tetrad(ci, ck, cl, cj, p3)); - } - } - - return countable ? tetrads : null; - } - - private Set listTetrads2By2(List cluster, Set eliminated, double cutoff) { - if (cluster.size() < 4) return null; - cluster = new ArrayList<>(cluster); - Set tetrads = new HashSet<>(); - - Node ci = cluster.get(0); - Node cj = cluster.get(1); - Node ck = cluster.get(2); - Node cl = cluster.get(3); - - if (eliminated.contains(ci) || eliminated.contains(cj) || eliminated.contains(ck) || eliminated.contains(cl)) { - return null; - } - - double p3 = this.tetradTest.tetradPValue(this.nodes.indexOf(ci), this.nodes.indexOf(ck), this.nodes.indexOf(cl), this.nodes.indexOf(cj)); -// double p3 = tetradTest.tetradPValue(nodes.indexOf(ci), nodes.indexOf(cj), nodes.indexOf(cl), nodes.indexOf(ck)); - - if (p3 < cutoff) { - tetrads.add(new Tetrad(ci, ck, cl, cj, p3)); -// tetrads.add(new Tetrad(ci, cj, cl, ck, p3)); - } - - return tetrads; - } - - private List> buildSolution(List> clustering, Set eliminated) { - List> solution = new ArrayList<>(); - - for (List cluster : clustering) { - List _cluster = new ArrayList<>(cluster); - _cluster.removeAll(eliminated); - solution.add(_cluster); - } - - return solution; - } -} - - diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index 1925221503..f5110936d7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -152,7 +152,7 @@ public void test1() { partition.add(cluster3); TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.05); - IPurify purify = new PurifyTetradBased2(test); + IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); List> partition2 = purify.purify(partition); @@ -249,7 +249,7 @@ public void test1b() { partition.add(cluster2); TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.0001); - IPurify purify = new PurifyTetradBased2(test); + IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); List> clustering = purify.purify(partition); @@ -288,7 +288,7 @@ public void test2() { ContinuousTetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.001); - IPurify purify = new PurifyTetradBased2(test); + IPurify purify = new PurifyTetradBased(test); List> purifiedClustering = purify.purify(clustering); List latentsNames = new ArrayList<>(); From 194da4588f06389bdc6f01f30531e6e95aee0fbc Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:48:40 -0400 Subject: [PATCH 154/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/MultiFaskV1.java | 378 ------------------ 1 file changed, 378 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/MultiFaskV1.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MultiFaskV1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MultiFaskV1.java deleted file mode 100644 index 9da7453213..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MultiFaskV1.java +++ /dev/null @@ -1,378 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.Matrix; -import edu.cmu.tetrad.util.StatUtils; -import edu.cmu.tetrad.util.SublistGenerator; -import org.apache.commons.math3.linear.SingularMatrixException; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.apache.commons.math3.util.FastMath.*; - -/** - * Created by user on 3/29/18. - */ -public class MultiFaskV1 { - - private final SemBicScoreMultiFas score; - - // An initial graph to orient, skipping the adjacency step. - private Graph externalGraph; - - // Elapsed time of the search, in milliseconds. - - - // For the Fast Adjacency Search. - private final int depth = -1; - - // For the SEM BIC score, for the Fast Adjacency Search. - private double penaltyDiscount = 1; - - // Alpha for orienting 2-cycles. Usually needs to be low. - private double alpha = 1e-6; - - // Knowledge the the search will obey, of forbidden and required edges. - private Knowledge knowledge = new Knowledge(); - - // Cutoff for T tests for 2-cycle tests. - private double cutoff; - - // Threshold for reversing casual judgments for negative coefficients. - private double delta = -0.2; - - private List dataSets; - - private final double[][][] data; - - public MultiFaskV1(List dataSets, SemBicScoreMultiFas score) { - - this.dataSets = dataSets; - this.score = score; - - this.data = new double[dataSets.size()][][]; - - for (int i = 0; i < dataSets.size(); i++) { - this.data[i] = dataSets.get(i).getDoubleData().transpose().toArray(); - } - - } - - //======================================== PUBLIC METHODS ====================================// - - public Graph search() { - setCutoff(this.alpha); - DataSet dataSet; - ArrayList standardSets = new ArrayList<>(); - - for (DataSet set : this.dataSets) { - dataSet = DataUtils.standardizeData(set); - standardSets.add(dataSet); - } - - this.dataSets = standardSets; - List variables = this.dataSets.get(0).getVariables(); - Graph G0; - - IndependenceTest test = new IndTestScore(this.score); - System.out.println("FAS"); - - Fas fas = new Fas(test); - fas.setStable(true); - fas.setDepth(getDepth()); - fas.setVerbose(false); - fas.setKnowledge(this.knowledge); - G0 = fas.search(); - - SearchGraphUtils.pcOrientbk(this.knowledge, G0, G0.getNodes()); - G0 = GraphUtils.replaceNodes(G0, this.dataSets.get(0).getVariables()); - - System.out.println("Orientation"); - - Graph graph = new EdgeListGraph(variables); - - for (int i = 0; i < variables.size(); i++) { - for (int j = i + 1; j < variables.size(); j++) { - - Node X = variables.get(i); - Node Y = variables.get(j); - - double[] x; - double[] y; - - double[][] _x = new double[this.dataSets.size()][]; - double[][] _y = new double[this.dataSets.size()][]; - - double c1 = 0; - double c2 = 0; - - for (int k = 0; k < this.dataSets.size(); k++) { - x = this.data[k][i]; - y = this.data[k][j]; - - _x[k] = x; - _y[k] = y; - - c1 += StatUtils.cov(x, y, x, 0, +1)[1]; - c2 += StatUtils.cov(x, y, y, 0, +1)[1]; - } - - // A threshold for including extra adjacencies due to skewness. - if ((G0.isAdjacentTo(X, Y)) || ((abs(c1 - c2) / this.dataSets.size()) > 0.3)) { - if (knowledgeOrients(X, Y)) { - graph.addDirectedEdge(X, Y); - } else if (knowledgeOrients(Y, X)) { - graph.addDirectedEdge(Y, X); - } else if (bidirected(_x, _y, G0, X, Y)) { - Edge edge1 = Edges.directedEdge(X, Y); - Edge edge2 = Edges.directedEdge(Y, X); - graph.addEdge(edge1); - graph.addEdge(edge2); - } else { - if (leftright(_x, _y)) { - graph.addDirectedEdge(X, Y); - } else { - graph.addDirectedEdge(Y, X); - } - } - } - } - } - - System.out.println(); - System.out.println("Done"); - - return graph; - } - - /** - * @return Returns the penalty discount used for the adjacency search. The default is 1, - * though a higher value is recommended, say, 2, 3, or 4. - */ - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - /** - * @param penaltyDiscount Sets the penalty discount used for the adjacency search. - * The default is 1, though a higher value is recommended, say, - * 2, 3, or 4. - */ - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - /** - * @param alpha Alpha for orienting 2-cycles. Needs to be on the low side usually. Default 1e-6. - */ - public void setAlpha(double alpha) { - this.alpha = alpha; - } - - /** - * @return the current knowledge. - */ - public Knowledge getKnowledge() { - return this.knowledge; - } - - /** - * @param knowledge Knowledge of forbidden and required edges. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - - public int getDepth() { - return this.depth; - } - - //======================================== PRIVATE METHODS ===================================// - - private boolean bidirected(double[][] x, double[][] y, Graph G0, Node X, Node Y) { - Set adjSet = new HashSet<>(G0.getAdjacentNodes(X)); - adjSet.addAll(G0.getAdjacentNodes(Y)); - List adj = new ArrayList<>(adjSet); - adj.remove(X); - adj.remove(Y); - - int trueCounter = 0; - int falseCounter = 0; - - for (int i = 0; i < this.dataSets.size(); i++) { - - SublistGenerator gen = new SublistGenerator(adj.size(), this.depth); - int[] choice; - - boolean possibleTwoCycle = false; - - while ((choice = gen.next()) != null) { - - List _adj = GraphUtils.asList(choice, adj); - double[][][] _Z = new double[this.dataSets.size()][_adj.size()][]; - - if (_adj.size() > 0) { - for (int f = 0; f < _adj.size(); f++) { - - Node _z = _adj.get(f); - - for (int g = 0; g < this.dataSets.size(); g++) { - - int column = this.dataSets.get(0).getColumn(_z); - _Z[g][f] = this.data[g][column]; - } - } - - - double pc = partialCorrelation(x[i], y[i], _Z[i], x[i], Double.NEGATIVE_INFINITY); - double pc1 = partialCorrelation(x[i], y[i], _Z[i], x[i], 0); - double pc2 = partialCorrelation(x[i], y[i], _Z[i], y[i], 0); - - int nc = StatUtils.getRows(x[i], Double.NEGATIVE_INFINITY, +1).size(); - int nc1 = StatUtils.getRows(x[i], 0, +1).size(); - int nc2 = StatUtils.getRows(y[i], 0, +1).size(); - - double z = 0.5 * (log(1.0 + pc) - log(1.0 - pc)); - double z1 = 0.5 * (log(1.0 + pc1) - log(1.0 - pc1)); - double z2 = 0.5 * (log(1.0 + pc2) - log(1.0 - pc2)); - - double zv1 = (z - z1) / sqrt((1.0 / ((double) nc - 3) + 1.0 / ((double) nc1 - 3))); - double zv2 = (z - z2) / sqrt((1.0 / ((double) nc - 3) + 1.0 / ((double) nc2 - 3))); - - boolean rejected1 = abs(zv1) > this.cutoff; - boolean rejected2 = abs(zv2) > this.cutoff; - - if (zv1 < 0 && zv2 > 0 && rejected1) { - possibleTwoCycle = true; - } else if (zv1 > 0 && zv2 < 0 && rejected2) { - possibleTwoCycle = true; - } else if (rejected1 && rejected2) { - possibleTwoCycle = true; - } - - } else { - double[][] _emptyZ = new double[0][0]; - double pc = partialCorrelation(x[i], y[i], _emptyZ, x[i], Double.NEGATIVE_INFINITY); - double pc1 = partialCorrelation(x[i], y[i], _emptyZ, x[i], 0); - double pc2 = partialCorrelation(x[i], y[i], _emptyZ, y[i], 0); - - int nc = StatUtils.getRows(x[i], Double.NEGATIVE_INFINITY, +1).size(); - int nc1 = StatUtils.getRows(x[i], 0, +1).size(); - int nc2 = StatUtils.getRows(y[i], 0, +1).size(); - - double z = 0.5 * (log(1.0 + pc) - log(1.0 - pc)); - double z1 = 0.5 * (log(1.0 + pc1) - log(1.0 - pc1)); - double z2 = 0.5 * (log(1.0 + pc2) - log(1.0 - pc2)); - - double zv1 = (z - z1) / sqrt((1.0 / ((double) nc - 3) + 1.0 / ((double) nc1 - 3))); - double zv2 = (z - z2) / sqrt((1.0 / ((double) nc - 3) + 1.0 / ((double) nc2 - 3))); - - boolean rejected1 = abs(zv1) > this.cutoff; - boolean rejected2 = abs(zv2) > this.cutoff; - - if (zv1 < 0 && zv2 > 0 && rejected1) { - possibleTwoCycle = true; - } else if (zv1 > 0 && zv2 < 0 && rejected2) { - possibleTwoCycle = true; - } else if (rejected1 && rejected2) { - possibleTwoCycle = true; - } - - } - if (!possibleTwoCycle) { - break; - } - } - - if (possibleTwoCycle) { - trueCounter++; - } else { - falseCounter++; - } - } - - return trueCounter > falseCounter; - } - - private boolean leftright(double[][] x, double[][] y) { - - double lrSum = 0; - - for (int i = 0; i < this.dataSets.size(); i++) { - double left = MultiFaskV1.cu(x[i], y[i], x[i]) / (sqrt(MultiFaskV1.cu(x[i], x[i], x[i]) * MultiFaskV1.cu(y[i], y[i], x[i]))); - double right = MultiFaskV1.cu(x[i], y[i], y[i]) / (sqrt(MultiFaskV1.cu(x[i], x[i], y[i]) * MultiFaskV1.cu(y[i], y[i], y[i]))); - double lr = left - right; - - double r = StatUtils.correlation(x[i], y[i]); - double sx = StatUtils.skewness(x[i]); - double sy = StatUtils.skewness(y[i]); - - r *= signum(sx) * signum(sy); - lr *= signum(r); - if (r < getDelta()) lr *= -1; - - lrSum += lr; - } - - return lrSum > 0; - } - - private static double cu(double[] x, double[] y, double[] condition) { - double exy = 0.0; - - int n = 0; - - for (int k = 0; k < x.length; k++) { - if (condition[k] > 0) { - exy += x[k] * y[k]; - n++; - } - } - - return exy / n; - } - - private double partialCorrelation(double[] x, double[] y, double[][] z, double[] condition, double threshold) throws SingularMatrixException { - double[][] cv = StatUtils.covMatrix(x, y, z, condition, threshold, 1); - Matrix m = new Matrix(cv).transpose(); - return StatUtils.partialCorrelation(m); - } - - /** - * Sets the significance level at which independence judgments should be made. Affects the cutoff for partial - * correlations to be considered statistically equal to zero. - */ - private void setCutoff(double alpha) { - if (alpha < 0.0 || alpha > 1.0) { - throw new IllegalArgumentException("Significance out of range: " + alpha); - } - - this.cutoff = StatUtils.getZForAlpha(alpha); - } - - private boolean knowledgeOrients(Node left, Node right) { - return this.knowledge.isForbidden(right.getName(), left.getName()) || this.knowledge.isRequired(left.getName(), right.getName()); - } - - public Graph getExternalGraph() { - return this.externalGraph; - } - - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } - - public double getDelta() { - return this.delta; - } - - public void setDelta(double delta) { - this.delta = delta; - } -} From e242408f0c850a4276cb1c447454af8ce269a572 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:50:29 -0400 Subject: [PATCH 155/464] Fixing documentation etc. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 66b355507a..7c4f7cbc4c 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 @@ -92,10 +92,9 @@ public class Pc implements GraphSearch { private boolean verbose; private boolean stable; -// private boolean concurrent; private boolean useMaxP = false; private int maxPPathLength = -1; - private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; + private final PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; //=============================CONSTRUCTORS==========================// @@ -218,7 +217,7 @@ public Graph search(List nodes) { return search(fas, nodes); } - private Graph search(IFas fas, List nodes) { + public Graph search(IFas fas, List nodes) { this.logger.log("info", "Starting PC algorithm"); this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); From 99e50b0502e5f2837bc13e7fc326581bedb9ffc1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:53:16 -0400 Subject: [PATCH 156/464] Fixing documentation etc. --- .../edu/cmu/tetrad/study/performance/Comparison.java | 5 ----- .../edu/cmu/tetrad/study/performance/Comparison2.java | 11 ----------- .../study/performance/ComparisonParameters.java | 4 +--- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index 67b6d9479a..11ff902a9f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -189,11 +189,6 @@ public static ComparisonResult compare(ComparisonParameters params) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); - } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCLocal) { - if (test == null) throw new IllegalArgumentException("Test not set."); - PcLocal search = new PcLocal(test); - result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCStableMax) { if (test == null) throw new IllegalArgumentException("Test not set."); PcStableMax search = new PcStableMax(test); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index 791babd249..67de72e07e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -138,10 +138,6 @@ public static ComparisonResult compare(ComparisonParameters params) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); - } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCLocal) { - PcLocal search = new PcLocal(test); - result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCStableMax) { PcStableMax search = new PcStableMax(test); result.setResultGraph(search.search()); @@ -384,13 +380,6 @@ public static ComparisonResult compare(ComparisonParameters params) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); - } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCLocal) { - if (test == null) { - throw new IllegalArgumentException("Test not set."); - } - PcLocal search = new PcLocal(test); - result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCStableMax) { if (test == null) { throw new IllegalArgumentException("Test not set."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java index 69a78d85c9..c378ed964e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java @@ -137,8 +137,6 @@ public void setAlgorithm(Algorithm algorithm) { resultType = ResultType.CPDAG; } else if (algorithm == Algorithm.FGES2) { resultType = ResultType.CPDAG; - } else if (algorithm == Algorithm.PCLocal) { - resultType = ResultType.CPDAG; } else if (algorithm == Algorithm.PCStableMax) { resultType = ResultType.CPDAG; } else if (algorithm == Algorithm.FCI) { @@ -322,5 +320,5 @@ public enum ResultType {CPDAG, PAG} public enum IndependenceTestType {FisherZ, ChiSquare} - public enum Algorithm {PC, CPC, FGES, FGES2, PCLocal, PCStableMax, FCI, GFCI, SVARFCI} + public enum Algorithm {PC, CPC, FGES, FGES2, PCStableMax, FCI, GFCI, SVARFCI} } From 358d5aea58756a94a5cc489829fb4e0b2b408c7d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:56:58 -0400 Subject: [PATCH 157/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/LingamPattern.java | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java index f4dc3b5654..3c8f7a6248 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java @@ -58,6 +58,11 @@ public class LingamPattern { //===============================CONSTRUCTOR============================// + /** + * Constructor. + * @param cpdag The CPDAG whose unoriented edges are to be oriented. + * @param dataSet Teh dataset to use. + */ public LingamPattern(Graph cpdag, DataSet dataSet) throws IllegalArgumentException { @@ -75,6 +80,10 @@ public LingamPattern(Graph cpdag, DataSet dataSet) //===============================PUBLIC METHODS========================// + /** + * Runs the search and returns the result graph. + * @return This graph. + */ public Graph search() { Graph _cpdag = GraphUtils.bidirectedToUndirected(getCpdag()); @@ -139,8 +148,8 @@ public Graph search() { double p1 = getPValues()[nodes.indexOf(node1)]; double p2 = getPValues()[nodes.indexOf(node2)]; - boolean node1Nongaussian = p1 < getAlpha(); - boolean node2Nongaussian = p2 < getAlpha(); + boolean node1Nongaussian = p1 < this.alpha; + boolean node2Nongaussian = p2 < this.alpha; if (node1Nongaussian || node2Nongaussian) { if (!Edges.isUndirectedEdge(edge)) { @@ -168,6 +177,26 @@ public Graph search() { return ngDagCPDAG; } + /** + * Returns the p-values of the search. + * @return This list as a double[] array. + */ + public double[] getPValues() { + return this.pValues; + } + + /** + * Sets the alpha level for the search. + * @param alpha This alpha level. + */ + public void setAlpha(double alpha) { + if (alpha < 0.0 || alpha > 1.0) { + throw new IllegalArgumentException("Alpha is in range [0, 1]"); + } + + this.alpha = alpha; + } + //=============================PRIVATE METHODS=========================// private Score getScore(Graph dag, Matrix data, List variables) { @@ -218,22 +247,6 @@ private Score getScore(Graph dag, Matrix data, List variables) { return new Score(score, pValues); } - public double[] getPValues() { - return this.pValues; - } - - public double getAlpha() { - return this.alpha; - } - - public void setAlpha(double alpha) { - if (alpha < 0.0 || alpha > 1.0) { - throw new IllegalArgumentException("Alpha is in range [0, 1]"); - } - - this.alpha = alpha; - } - private Graph getCpdag() { return this.cpdag; } From 53afa00a11455f72eb2a2cda8e71e96d3f327152 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 04:59:52 -0400 Subject: [PATCH 158/464] Fixing documentation etc. --- .../edu/cmu/tetradapp/model/IonRunner.java | 4 +- .../main/java/edu/cmu/tetrad/search/Ion.java | 207 +- .../main/java/edu/cmu/tetrad/search/Ion2.java | 1802 ----------------- .../edu/cmu/tetrad/search/IonHittingSet.java | 10 +- 4 files changed, 198 insertions(+), 1825 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion2.java diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java index da41666ff7..0d316f7fbc 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.Ion2; +import edu.cmu.tetrad.search.Ion; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -197,7 +197,7 @@ public static IonRunner serializableInstance() { public void execute() { System.out.println("Executing."); - Ion2 ion = new Ion2(getGraphs()); + Ion ion = new Ion(getGraphs()); ion.setAdjacencySearch(getParams().getBoolean("pruneByAdjacencies", true)); ion.setPathLengthSearch(getParams().getBoolean("pruneByPathLength", true)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java index 77fab3d8a6..9daa84aad2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java @@ -21,6 +21,8 @@ package edu.cmu.tetrad.search; +import edu.cmu.tetrad.data.Knowledge; +import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; @@ -35,8 +37,8 @@ * form an input PAG_of_the_true_DAG that are consistent (same d-separations and d-connections) with every input PAG_of_the_true_DAG. * * @author Robert Tillman + * @author Joseph Ramsey */ - public class Ion { // prune using path length @@ -85,6 +87,9 @@ public class Ion { // maximum memory usage private double maxMemory; + // knowledge if available. + private Knowledge knowledge = new Knowledge(); + //============================= Constructor ============================// @@ -125,6 +130,14 @@ public void setAdjacencySearch(boolean b) { this.adjacencySearch = b; } + public void setKnowledge(Knowledge knowledge) { + if (knowledge == null) { + throw new NullPointerException("Knowledge must not be null."); + } + + this.knowledge = knowledge; + } + /** * Begins the ION search procedure, described at each step */ @@ -173,14 +186,15 @@ public List search() { this.separations = sepAndAssoc.get(0); Set associations = sepAndAssoc.get(1); Map, List> paths; - Queue step3Pags = new LinkedList<>(); +// Queue step3PagsSet = new LinkedList(); + HashSet step3PagsSet = new HashSet<>(); Set reject = new HashSet<>(); // if no d-separations, nothing left to search if (this.separations.isEmpty()) { // makes orientations preventing definite noncolliders from becoming colliders // do final orientations // doFinalOrientation(graph); - step3Pags.add(graph); + step3PagsSet.add(graph); } // sets length to iterate once if search over path lengths not enabled, otherwise set to 2 int numNodes = graph.getNumNodes(); @@ -203,9 +217,9 @@ public List search() { seps--; // uses two queues to keep up with which PAGs are being iterated and which have been // accepted to be iterated over in the next iteration of the above for loop - searchPags.addAll(step3Pags); + searchPags.addAll(step3PagsSet); this.recGraphs.add(searchPags.size()); - step3Pags.clear(); + step3PagsSet.clear(); while (!searchPags.isEmpty()) { System.out.println("ION Step 3 size: " + searchPags.size()); double currentUsage = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); @@ -243,8 +257,7 @@ public List search() { } // accept PAG_of_the_true_DAG go to next PAG_of_the_true_DAG if no possibly d-connecting undirectedPaths if (dConnections.isEmpty()) { -// doFinalOrientation(pag); - step3Pags.add(pag); + step3PagsSet.add(pag); continue; } // maps conditioning sets to list of possibly d-connecting undirectedPaths @@ -268,8 +281,8 @@ public List search() { if (pag.underlines().isUnderlineTriple(collider.getX(), collider.getY(), collider.getZ())) { okay = false; break; - } + } if (!okay) { continue; @@ -373,7 +386,7 @@ public List search() { continue; } // if graph change has already been accepted move on to next graph - if (step3Pags.contains(changed)) { + if (step3PagsSet.contains(changed)) { continue; } // reject if null, predicts false independencies or has cycle @@ -385,7 +398,8 @@ public List search() { // do final orientations // doFinalOrientation(changed); // now add graph to queue - step3Pags.add(changed); + + step3PagsSet.add(changed); } } // exits loop if not looping over adjacencies @@ -395,6 +409,7 @@ public List search() { } } TetradLogger.getInstance().log("info", "Step 3: " + (MillisecondTimes.timeMillis() - steps) / 1000. + "s"); + Queue step3Pags = new LinkedList<>(step3PagsSet); /* * Step 4 @@ -405,6 +420,7 @@ public List search() { steps = MillisecondTimes.timeMillis(); Map necEdges; Set outputPags = new HashSet<>(); + while (!step3Pags.isEmpty()) { Graph pag = step3Pags.poll(); necEdges = new HashMap<>(); @@ -467,6 +483,7 @@ public List search() { } } outputPags = removeMoreSpecific(outputPags); +// outputPags = applyKnowledge(outputPags); TetradLogger.getInstance().log("info", "Step 4: " + (MillisecondTimes.timeMillis() - steps) / 1000. + "s"); @@ -505,6 +522,10 @@ public List search() { } } } + +// outputSet = applyKnowledge(outputSet); + outputSet = checkPaths(outputSet); + this.output.addAll(outputSet); TetradLogger.getInstance().log("info", "Step 5: " + (MillisecondTimes.timeMillis() - steps) / 1000. + "s"); this.runtime = ((MillisecondTimes.timeMillis() - start) / 1000.); @@ -1135,16 +1156,59 @@ private void awayFromColliderAncestorCycle(Graph graph) { Node C = adj.get(combination[1]); //choice gen doesnt do diff orders, so must switch A & C around. - awayFromCollider(graph, A, B, C); - awayFromCollider(graph, C, B, A); - awayFromAncestor(graph, A, B, C); - awayFromAncestor(graph, C, B, A); - awayFromCycle(graph, A, B, C); - awayFromCycle(graph, C, B, A); + ruleR1(A, B, C, graph); + ruleR1(C, B, A, graph); + ruleR2(A, B, C, graph); + ruleR2(C, B, A, graph); + } } } + /// R1, away from collider + + private void ruleR1(Node a, Node b, Node c, Graph graph) { + if (graph.isAdjacentTo(a, c)) { + return; + } + + if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.CIRCLE) { + if (!isArrowpointAllowed(graph, b, c)) { + return; + } + + graph.setEndpoint(c, b, Endpoint.TAIL); + graph.setEndpoint(b, c, Endpoint.ARROW); + } + } + + //if Ao->c and a-->b-->c, then a-->c + // Zhang's rule R2, awy from ancestor. + + private void ruleR2(Node a, Node b, Node c, Graph graph) { + if (!graph.isAdjacentTo(a, c)) { + return; + } + + if (graph.getEndpoint(b, a) == Endpoint.TAIL && graph.getEndpoint(a, b) == Endpoint.ARROW + && graph.getEndpoint(b, c) == Endpoint.ARROW && graph.getEndpoint(a, c) == Endpoint.CIRCLE) { + if (!isArrowpointAllowed(graph, a, c)) { + return; + } + + graph.setEndpoint(a, c, Endpoint.ARROW); + } else if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.TAIL + && graph.getEndpoint(b, c) == Endpoint.ARROW && graph.getEndpoint(a, c) == Endpoint.CIRCLE + ) { + if (!isArrowpointAllowed(graph, a, c)) { + return; + } + + graph.setEndpoint(a, c, Endpoint.ARROW); + } + } + + private boolean isArrowpointAllowed(Graph graph, Node x, Node y) { if (graph.getEndpoint(x, y) == Endpoint.ARROW) { return true; @@ -1422,6 +1486,41 @@ private Set removeMoreSpecific(Set outputPags) { return outputPags; } + private Set checkPaths(Set pags) { + HashSet pagsOut = new HashSet<>(); + + for (Graph pag : pags) { + boolean allAccountFor = true; + + GRAPH: + for (Graph inGraph : this.input) { + for (Edge edge : inGraph.getEdges()) { + Node node1 = pag.getNode(edge.getNode1().getName()); + Node node2 = pag.getNode(edge.getNode2().getName()); + + if (Edges.isDirectedEdge(edge)) { + if (!pag.paths().existsSemiDirectedPathFromTo(node1, Collections.singleton(node2))) { + allAccountFor = false; + break GRAPH; + } + } + if (/*!pag.existsTrek(node1, node2) ||*/ Edges.isPartiallyOrientedEdge(edge)) { + if (pag.paths().existsSemiDirectedPathFromTo(node2, Collections.singleton(node1))) { + allAccountFor = false; + break GRAPH; + } + } + } + } + + if (allAccountFor) { + pagsOut.add(pag); + } + } + + return pagsOut; + } + /** * Exactly the same as edu.cmu.tetrad.graph.IndependenceFact excepting this class allows for multiple conditioning * sets to be associated with a single pair of nodes, which is necessary for the proper ordering of iterations in @@ -1581,7 +1680,7 @@ public static List> treks(Graph graph, Node node1, Node node2) { } /** - * Constucts the list of treks between node1 and node2. + * Constructs the list of treks between node1 and node2. */ private static void treks(Graph graph, Node node1, Node node2, LinkedList path, List> paths) { @@ -1623,6 +1722,80 @@ private static void treks(Graph graph, Node node1, Node node2, path.removeLast(); } + private Graph screenForKnowledge(Graph pag) { + for (Iterator it = this.knowledge.forbiddenEdgesIterator(); it.hasNext(); ) { + KnowledgeEdge next = it.next(); + Node y = pag.getNode(next.getFrom()); + Node x = pag.getNode(next.getTo()); + + if (x == null || y == null) { + continue; + } + + Edge edge = pag.getEdge(x, y); + + if (edge == null) { + continue; + } + + if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.TAIL) { + return null; + } else if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { + pag.removeEdge(edge); + pag.addEdge(Edges.bidirectedEdge(x, y)); + } else if (edge.getProximalEndpoint(x) == Endpoint.CIRCLE && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { + pag.removeEdge(edge); + pag.addEdge(Edges.partiallyOrientedEdge(x, y)); + } + } + + + for (Iterator it = this.knowledge.requiredEdgesIterator(); it.hasNext(); ) { + KnowledgeEdge next = it.next(); + Node x = pag.getNode(next.getFrom()); + Node y = pag.getNode(next.getTo()); + + if (x == null || y == null) { + continue; + } + + Edge edge = pag.getEdge(x, y); + + if (edge == null) { + return null; + } else if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.TAIL) { + return null; + } else if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { + return null; + } else if (edge.getProximalEndpoint(x) == Endpoint.CIRCLE && edge.getProximalEndpoint(y) == Endpoint.ARROW) { + pag.removeEdge(edge); + pag.addEdge(Edges.directedEdge(x, y)); + } else if (edge.getProximalEndpoint(x) == Endpoint.CIRCLE && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { + pag.removeEdge(edge); + pag.addEdge(Edges.directedEdge(x, y)); + } + } + + +// doFinalOrientation(pag); + return pag; + } + + private Set applyKnowledge(Set outputSet) { + Set _out = new HashSet<>(); + + for (Graph graph : outputSet) { + Graph _graph = screenForKnowledge(graph); + + if (_graph != null) { + _out.add(_graph); + } + } + + return _out; + } + + } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion2.java deleted file mode 100644 index cc14f568b6..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion2.java +++ /dev/null @@ -1,1802 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.data.KnowledgeEdge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.TetradLogger; - -import java.util.*; - -/** - * Implements the ION (Integration of Overlapping Networks) algorithm for distributed causal inference. The algorithm - * takes as input a set of PAGs (presumably learned using a local learning algorithm) over variable sets that may have - * some variables in common and others not in common. The algorithm returns a complete set of PAGs over every variable - * form an input PAG_of_the_true_DAG that are consistent (same d-separations and d-connections) with every input PAG_of_the_true_DAG. - * - * @author Robert Tillman - * @author Joseph Ramsey - */ -public class Ion2 { - - // prune using path length - private boolean pathLengthSearch = true; - - // prune using adjacencies - private boolean adjacencySearch; - - /** - * The input PAGs being to be intergrated, possibly FCI outputs. - */ - private final List input = new ArrayList<>(); - - /** - * The output PAGs over all variables consistent with the input PAGs - */ - private final List output = new ArrayList<>(); - - /** - * All the variables being integrated from the input PAGs - */ - private final List variables = new ArrayList<>(); - - /** - * Definite noncolliders - */ - private final Set definiteNoncolliders = new HashSet<>(); - - /** - * separations and associations found in the input PAGs - */ - private Set separations; - - /** - * tracks changes for final orientations orientation methods - */ - private boolean changeFlag = true; - private final Set discrimGraphs = new HashSet<>(); - private final Set finalResult = new HashSet<>(); - - // running runtime and time and size information for hitting sets - private final List recGraphs = new ArrayList<>(); - private final List recHitTimes = new ArrayList<>(); - private double runtime; - - // maximum memory usage - private double maxMemory; - - // knowledge if available. - private Knowledge knowledge = new Knowledge(); - - //============================= Constructor ============================// - - - /** - * Constructs a new instance of the ION search from the input PAGs - * - * @param pags The PAGs to be integrated - */ - public Ion2(List pags) { - this.input.addAll(pags); - for (Graph pag : this.input) { - for (Node node : pag.getNodes()) { - if (!this.variables.contains(node.getName())) { - this.variables.add(node.getName()); - } - } - for (Triple triple : getAllTriples(pag)) { - if (pag.isDefNoncollider(triple.getX(), triple.getY(), triple.getZ())) { - pag.underlines().addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); - } - } - } - } - - //============================= Public Methods ============================// - - /** - * Sets path length search on or off - */ - public void setPathLengthSearch(boolean b) { - this.pathLengthSearch = b; - } - - /** - * Sets adjacency search on or off - */ - public void setAdjacencySearch(boolean b) { - this.adjacencySearch = b; - } - - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException("Knowledge must not be null."); - } - - this.knowledge = knowledge; - } - - /** - * Begins the ION search procedure, described at each step - */ - public List search() { - - long start = MillisecondTimes.timeMillis(); - TetradLogger.getInstance().log("info", "Starting ION Search."); - logGraphs("\nInitial Pags: ", this.input); - TetradLogger.getInstance().log("info", "Transfering local information."); - long steps = MillisecondTimes.timeMillis(); - - /* - * Step 1 - Create the empty graph - */ - List varNodes = new ArrayList<>(); - for (String varName : this.variables) { - varNodes.add(new GraphNode(varName)); - } - Graph graph = new EdgeListGraph(varNodes); - - /* - * Step 2 - Transfer local information from the PAGs (adjacencies - * and edge orientations) - */ - // transfers edges from each graph and finds definite noncolliders - transferLocal(graph); - // adds edges for variables never jointly measured - for (NodePair pair : nonIntersection(graph)) { - graph.addEdge(new Edge(pair.getFirst(), pair.getSecond(), Endpoint.CIRCLE, Endpoint.CIRCLE)); - } - TetradLogger.getInstance().log("info", "Steps 1-2: " + (MillisecondTimes.timeMillis() - steps) / 1000. + "s"); - System.out.println("step2"); - System.out.println(graph); - - /* - * Step 3 - * - * Branch and prune step that blocks problematic undirectedPaths, possibly d-connecting undirectedPaths - */ - steps = MillisecondTimes.timeMillis(); - Queue searchPags = new LinkedList<>(); - // place graph constructed in step 2 into the queue - searchPags.offer(graph); - // get d-separations and d-connections - List> sepAndAssoc = findSepAndAssoc(graph); - this.separations = sepAndAssoc.get(0); - Set associations = sepAndAssoc.get(1); - Map, List> paths; -// Queue step3PagsSet = new LinkedList(); - HashSet step3PagsSet = new HashSet<>(); - Set reject = new HashSet<>(); - // if no d-separations, nothing left to search - if (this.separations.isEmpty()) { - // makes orientations preventing definite noncolliders from becoming colliders - // do final orientations -// doFinalOrientation(graph); - step3PagsSet.add(graph); - } - // sets length to iterate once if search over path lengths not enabled, otherwise set to 2 - int numNodes = graph.getNumNodes(); - int pl = numNodes - 1; - if (this.pathLengthSearch) { - pl = 2; - } - // iterates over path length, then adjacencies - for (int l = pl; l < numNodes; l++) { - if (this.pathLengthSearch) { - TetradLogger.getInstance().log("info", "Braching over path lengths: " + l + " of " + (numNodes - 1)); - } - int seps = this.separations.size(); - final int currentSep = 1; - int numAdjacencies = this.separations.size(); - for (IonIndependenceFacts fact : this.separations) { - if (this.adjacencySearch) { - TetradLogger.getInstance().log("info", "Braching over path nonadjacencies: " + currentSep + " of " + numAdjacencies); - } - seps--; - // uses two queues to keep up with which PAGs are being iterated and which have been - // accepted to be iterated over in the next iteration of the above for loop - searchPags.addAll(step3PagsSet); - this.recGraphs.add(searchPags.size()); - step3PagsSet.clear(); - while (!searchPags.isEmpty()) { - System.out.println("ION Step 3 size: " + searchPags.size()); - double currentUsage = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - if (currentUsage > this.maxMemory) this.maxMemory = currentUsage; - // deques first PAG from searchPags - Graph pag = searchPags.poll(); - // Part 3.a - finds possibly d-connecting undirectedPaths between each pair of nodes - // known to be d-separated - List dConnections = new ArrayList<>(); - // checks to see if looping over adjacencies - if (this.adjacencySearch) { - for (Collection conditions : fact.getZ()) { - // checks to see if looping over path lengths - if (this.pathLengthSearch) { - dConnections.addAll(PossibleDConnectingPath.findDConnectingPathsOfLength - (pag, fact.getX(), fact.getY(), conditions, l)); - } else { - dConnections.addAll(PossibleDConnectingPath.findDConnectingPaths - (pag, fact.getX(), fact.getY(), conditions)); - } - } - } else { - for (IonIndependenceFacts allfact : this.separations) { - for (Collection conditions : allfact.getZ()) { - // checks to see if looping over path lengths - if (this.pathLengthSearch) { - dConnections.addAll(PossibleDConnectingPath.findDConnectingPathsOfLength - (pag, allfact.getX(), allfact.getY(), conditions, l)); - } else { - dConnections.addAll(PossibleDConnectingPath.findDConnectingPaths - (pag, allfact.getX(), allfact.getY(), conditions)); - } - } - } - } - // accept PAG_of_the_true_DAG go to next PAG_of_the_true_DAG if no possibly d-connecting undirectedPaths - if (dConnections.isEmpty()) { - step3PagsSet.add(pag); - continue; - } - // maps conditioning sets to list of possibly d-connecting undirectedPaths - paths = new HashMap<>(); - for (PossibleDConnectingPath path : dConnections) { - List p = paths.get(path.getConditions()); - if (p == null) { - p = new LinkedList<>(); - } - p.add(path); - paths.put(path.getConditions(), p); - } - // Part 3.b - finds minimal graphical changes to block possibly d-connecting undirectedPaths - List> possibleChanges = new ArrayList<>(); - for (Set changes : findChanges(paths)) { - Set newChanges = new HashSet<>(); - for (GraphChange gc : changes) { - boolean okay = true; - for (Triple collider : gc.getColliders()) { - - if (pag.underlines().isUnderlineTriple(collider.getX(), collider.getY(), collider.getZ())) { - okay = false; - break; - } - - } - if (!okay) { - continue; - } - for (Triple collider : gc.getNoncolliders()) { - if (pag.isDefCollider(collider.getX(), collider.getY(), collider.getZ())) { - okay = false; - break; - } - } - if (okay) { - newChanges.add(gc); - } - } - if (!newChanges.isEmpty()) { - possibleChanges.add(newChanges); - } else { - possibleChanges.clear(); - break; - } - } - float starthitset = MillisecondTimes.timeMillis(); - Collection hittingSets = IonHittingSet.findHittingSet(possibleChanges); - this.recHitTimes.add((MillisecondTimes.timeMillis() - starthitset) / 1000.); - // Part 3.c - checks the newly constructed graphs from 3.b and rejects those that - // cycles or produce independencies known not to occur from the input PAGs or - // include undirectedPaths from definite nonancestors - for (GraphChange gc : hittingSets) { - boolean badhittingset = false; - for (Edge edge : gc.getRemoves()) { - Node node1 = edge.getNode1(); - Node node2 = edge.getNode2(); - Set triples = new HashSet<>(); - triples.addAll(gc.getColliders()); - triples.addAll(gc.getNoncolliders()); - if (triples.size() != (gc.getColliders().size() + gc.getNoncolliders().size())) { - badhittingset = true; - break; - } - for (Triple triple : triples) { - if (node1.equals(triple.getY())) { - if (node2.equals(triple.getX()) || - node2.equals(triple.getZ())) { - badhittingset = true; - break; - } - } - if (node2.equals(triple.getY())) { - if (node1.equals(triple.getX()) || - node1.equals(triple.getZ())) { - badhittingset = true; - break; - } - } - } - if (badhittingset) { - break; - } - for (NodePair pair : gc.getOrients()) { - if ((node1.equals(pair.getFirst()) && node2.equals(pair.getSecond())) || - (node2.equals(pair.getFirst()) && node1.equals(pair.getSecond()))) { - badhittingset = true; - break; - } - } - if (badhittingset) { - break; - } - } - if (!badhittingset) { - for (NodePair pair : gc.getOrients()) { - for (Triple triple : gc.getNoncolliders()) { - if (pair.getSecond().equals(triple.getY())) { - if (pair.getFirst().equals(triple.getX()) && - pag.getEndpoint(triple.getZ(), triple.getY()).equals(Endpoint.ARROW)) { - badhittingset = true; - break; - - } - if (pair.getFirst().equals(triple.getZ()) && - pag.getEndpoint(triple.getX(), triple.getY()).equals(Endpoint.ARROW)) { - badhittingset = true; - break; - } - } - if (badhittingset) { - break; - } - } - if (badhittingset) { - break; - } - } - } - if (badhittingset) { - continue; - } - Graph changed = gc.applyTo(pag); - // if graph change has already been rejected move on to next graph - if (reject.contains(changed)) { - continue; - } - // if graph change has already been accepted move on to next graph - if (step3PagsSet.contains(changed)) { - continue; - } - // reject if null, predicts false independencies or has cycle - if (predictsFalseIndependence(associations, changed) - || changed.paths().existsDirectedCycle()) { - reject.add(changed); - } - // makes orientations preventing definite noncolliders from becoming colliders - // do final orientations -// doFinalOrientation(changed); - // now add graph to queue - - step3PagsSet.add(changed); - } - } - // exits loop if not looping over adjacencies - if (!this.adjacencySearch) { - break; - } - } - } - TetradLogger.getInstance().log("info", "Step 3: " + (MillisecondTimes.timeMillis() - steps) / 1000. + "s"); - Queue step3Pags = new LinkedList<>(step3PagsSet); - - /* - * Step 4 - * - * Finds redundant undirectedPaths and uses this information to expand the list - * of possible graphs - */ - steps = MillisecondTimes.timeMillis(); - Map necEdges; - Set outputPags = new HashSet<>(); - - while (!step3Pags.isEmpty()) { - Graph pag = step3Pags.poll(); - necEdges = new HashMap<>(); - // Step 4.a - if x and y are known to be unconditionally associated and there is - // exactly one trek between them, mark each edge on that trek as necessary and - // make the tiples on the trek definite noncolliders - // initially mark each edge as not necessary - for (Edge edge : pag.getEdges()) { - necEdges.put(edge, false); - } - // look for unconditional associations - for (IonIndependenceFacts fact : associations) { - for (List nodes : fact.getZ()) { - if (nodes.isEmpty()) { - List> treks = Ion2.treks(pag, fact.x, fact.y); - if (treks.size() == 1) { - List trek = treks.get(0); - List triples = new ArrayList<>(); - for (int i = 1; i < trek.size(); i++) { - // marks each edge in trek as necessary - necEdges.put(pag.getEdge(trek.get(i - 1), trek.get(i)), true); - if (i == 1) { - continue; - } - // makes each triple a noncollider - pag.underlines().addUnderlineTriple(trek.get(i - 2), trek.get(i - 1), trek.get(i)); - } - } - // stop looping once the empty set is found - break; - } - } - } - // Part 4.b - branches by generating graphs for every combination of removing - // redundant undirectedPaths - boolean elimTreks; - // checks to see if removing redundant undirectedPaths eliminates every trek between - // two variables known to be nconditionally assoicated - List possRemovePags = possRemove(pag, necEdges); - double currentUsage = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - if (currentUsage > this.maxMemory) this.maxMemory = currentUsage; - for (Graph newPag : possRemovePags) { - elimTreks = false; - // looks for unconditional associations - for (IonIndependenceFacts fact : associations) { - for (List nodes : fact.getZ()) { - if (nodes.isEmpty()) { - if (Ion2.treks(newPag, fact.x, fact.y).isEmpty()) { - elimTreks = true; - } - // stop looping once the empty set is found - break; - } - } - } - // add new PAG to output unless a necessary trek has been eliminated - if (!elimTreks) { - outputPags.add(newPag); - } - } - } - outputPags = removeMoreSpecific(outputPags); -// outputPags = applyKnowledge(outputPags); - - TetradLogger.getInstance().log("info", "Step 4: " + (MillisecondTimes.timeMillis() - steps) / 1000. + "s"); - - /* - * Step 5 - * - * Generate the Markov equivalence classes for graphs and accept only - * those that do not predict false d-separations - */ - steps = MillisecondTimes.timeMillis(); - Set outputSet = new HashSet<>(); - for (Graph pag : outputPags) { - Set unshieldedPossibleColliders = new HashSet<>(); - for (Triple triple : getPossibleTriples(pag)) { - if (!pag.isAdjacentTo(triple.getX(), triple.getZ())) { - unshieldedPossibleColliders.add(triple); - } - } - - PowerSet pset = new PowerSet<>(unshieldedPossibleColliders); - for (Set set : pset) { - Graph newGraph = new EdgeListGraph(pag); - for (Triple triple : set) { - newGraph.setEndpoint(triple.getX(), triple.getY(), Endpoint.ARROW); - newGraph.setEndpoint(triple.getZ(), triple.getY(), Endpoint.ARROW); - } - doFinalOrientation(newGraph); - } - for (Graph outputPag : this.finalResult) { - if (!predictsFalseIndependence(associations, outputPag)) { - Set underlineTriples = new HashSet<>(outputPag.underlines().getUnderLines()); - for (Triple triple : underlineTriples) { - outputPag.underlines().removeUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); - } - outputSet.add(outputPag); - } - } - } - -// outputSet = applyKnowledge(outputSet); - outputSet = checkPaths(outputSet); - - this.output.addAll(outputSet); - TetradLogger.getInstance().log("info", "Step 5: " + (MillisecondTimes.timeMillis() - steps) / 1000. + "s"); - this.runtime = ((MillisecondTimes.timeMillis() - start) / 1000.); - logGraphs("\nReturning output (" + this.output.size() + " Graphs):", this.output); - double currentUsage = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - if (currentUsage > this.maxMemory) this.maxMemory = currentUsage; - return this.output; - } - - // returns total runtime and times for hitting set calculations - - public List getRuntime() { - double totalhit = 0; - double longesthit = 0; - double averagehit = 0; - for (Double i : this.recHitTimes) { - totalhit += i; - averagehit += i / this.recHitTimes.size(); - if (i > longesthit) { - longesthit = i; - } - } - List list = new ArrayList<>(); - list.add(Double.toString(this.runtime)); - list.add(Double.toString(totalhit)); - list.add(Double.toString(longesthit)); - list.add(Double.toString(averagehit)); - return list; - } - - // returns the maximum memory used in a run of ION - - public double getMaxMemUsage() { - return this.maxMemory; - } - - // return hitting set sizes - - public List getIterations() { - int totalit = 0; - int largestit = 0; - int averageit = 0; - for (Integer i : this.recGraphs) { - totalit += i; - averageit += i / this.recGraphs.size(); - if (i > largestit) { - largestit = i; - } - } - List list = new ArrayList<>(); - list.add(totalit); - list.add(largestit); - list.add(averageit); - return list; - } - - // summarizes time and hitting set time and size information for latex - - public String getStats() { - String stats = "Total running time: " + this.runtime + "\\\\"; - int totalit = 0; - int largestit = 0; - int averageit = 0; - for (Integer i : this.recGraphs) { - totalit += i; - averageit += i; - if (i > largestit) { - largestit = i; - } - } - averageit /= this.recGraphs.size(); - double totalhit = 0; - double longesthit = 0; - double averagehit = 0; - for (Double i : this.recHitTimes) { - totalhit += i; - averagehit += i / this.recHitTimes.size(); - if (i > longesthit) { - longesthit = i; - } - } - stats += "Total iterations in step 3: " + totalit + "\\\\"; - stats += "Largest set of iterations in step 3: " + largestit + "\\\\"; - stats += "Average iterations set in step 3: " + averageit + "\\\\"; - stats += "Total hitting sets calculation time: " + totalhit + "\\\\"; - stats += "Average hitting set calculation time: " + averagehit + "\\\\"; - stats += "Longest hitting set calculation time: " + longesthit + "\\\\"; - return stats; - } - - //============================= Private Methods ============================// - - /** - * Logs a set of graphs with a corresponding message - */ - private void logGraphs(String message, List graphs) { - if (message != null) { - TetradLogger.getInstance().log("graph", message); - } - for (Graph graph : graphs) { - TetradLogger.getInstance().log("graph", graph.toString()); - } - } - - /** - * Generates NodePairs of all possible pairs of nodes from given list of nodes. - */ - private List allNodePairs(List nodes) { - List nodePairs = new ArrayList<>(); - for (int j = 0; j < nodes.size() - 1; j++) { - for (int k = j + 1; k < nodes.size(); k++) { - nodePairs.add(new NodePair(nodes.get(j), nodes.get(k))); - } - } - return nodePairs; - } - - /** - * Finds all node pairs that are not adjacent in an input graph - */ - private Set nonadjacencies(Graph graph) { - Set nonadjacencies = new HashSet<>(); - for (Graph inputPag : this.input) { - for (NodePair pair : allNodePairs(inputPag.getNodes())) { - if (!inputPag.isAdjacentTo(pair.getFirst(), pair.getSecond())) { - nonadjacencies.add(new NodePair(graph.getNode(pair.getFirst().getName()), graph.getNode(pair.getSecond().getName()))); - } - } - } - return nonadjacencies; - } - - /* - * Transfers local information from the input PAGs by adding edges from - * local PAGs with their orientations and unorienting the edges if there - * is a conflict and recording definite noncolliders. - */ - - private void transferLocal(Graph graph) { - Set nonadjacencies = nonadjacencies(graph); - for (Graph pag : this.input) { - for (Edge edge : pag.getEdges()) { - NodePair graphNodePair = new NodePair(graph.getNode(edge.getNode1().getName()), graph.getNode(edge.getNode2().getName())); - if (nonadjacencies.contains(graphNodePair)) { - continue; - } - if (!graph.isAdjacentTo(graphNodePair.getFirst(), graphNodePair.getSecond())) { - graph.addEdge(new Edge(graphNodePair.getFirst(), graphNodePair.getSecond(), edge.getEndpoint1(), edge.getEndpoint2())); - continue; - } - Endpoint first = edge.getEndpoint1(); - Endpoint firstCurrent = graph.getEndpoint(graphNodePair.getSecond(), graphNodePair.getFirst()); - if (!first.equals(Endpoint.CIRCLE)) { - if ((first.equals(Endpoint.ARROW) && firstCurrent.equals(Endpoint.TAIL)) || - (first.equals(Endpoint.TAIL) && firstCurrent.equals(Endpoint.ARROW))) { - graph.setEndpoint(graphNodePair.getSecond(), graphNodePair.getFirst(), Endpoint.CIRCLE); - } else { - graph.setEndpoint(graphNodePair.getSecond(), graphNodePair.getFirst(), edge.getEndpoint1()); - } - } - Endpoint second = edge.getEndpoint2(); - Endpoint secondCurrent = graph.getEndpoint(graphNodePair.getFirst(), graphNodePair.getSecond()); - if (!second.equals(Endpoint.CIRCLE)) { - if ((second.equals(Endpoint.ARROW) && secondCurrent.equals(Endpoint.TAIL)) || - (second.equals(Endpoint.TAIL) && secondCurrent.equals(Endpoint.ARROW))) { - graph.setEndpoint(graphNodePair.getFirst(), graphNodePair.getSecond(), Endpoint.CIRCLE); - } else { - graph.setEndpoint(graphNodePair.getFirst(), graphNodePair.getSecond(), edge.getEndpoint2()); - } - } - } - for (Triple triple : pag.underlines().getUnderLines()) { - Triple graphTriple = new Triple(graph.getNode(triple.getX().getName()), graph.getNode(triple.getY().getName()), graph.getNode(triple.getZ().getName())); - if (graphTriple.alongPathIn(graph)) { - graph.underlines().addUnderlineTriple(graphTriple.getX(), graphTriple.getY(), graphTriple.getZ()); - this.definiteNoncolliders.add(graphTriple); - } - } - } - } - - /* - * @return all triples in a graph - */ - - private Set getAllTriples(Graph graph) { - Set triples = new HashSet<>(); - for (Node node : graph.getNodes()) { - List adjNodes = graph.getAdjacentNodes(node); - for (int i = 0; i < adjNodes.size() - 1; i++) { - for (int j = i + 1; j < adjNodes.size(); j++) { - triples.add(new Triple(adjNodes.get(i), node, adjNodes.get(j))); - } - } - } - return triples; - } - - /* - * @return variable pairs that are not in the intersection of the variable - * sets for any two input PAGs - */ - - private List nonIntersection(Graph graph) { - List> varsets = new ArrayList<>(); - for (Graph inputPag : this.input) { - Set varset = new HashSet<>(); - for (Node node : inputPag.getNodes()) { - varset.add(node.getName()); - } - varsets.add(varset); - } - List pairs = new ArrayList(); - - for (int i = 0; i < this.variables.size() - 1; i++) { - for (int j = i + 1; j < this.variables.size(); j++) { - boolean intersection = false; - for (Set varset : varsets) { - if (varset.containsAll(Arrays.asList(this.variables.get(i), this.variables.get(j)))) { - intersection = true; - break; - } - } - if (!intersection) { - pairs.add(new NodePair(graph.getNode(this.variables.get(i)), graph.getNode(this.variables.get(j)))); - } - } - } - return pairs; - } - - /** - * Finds the association or seperation sets for every pair of nodes. - */ - private List> findSepAndAssoc(Graph graph) { - Set separations = new HashSet<>(); - Set associations = new HashSet<>(); - List allNodes = allNodePairs(graph.getNodes()); - - for (NodePair pair : allNodes) { - Node x = pair.getFirst(); - Node y = pair.getSecond(); - - List variables = new ArrayList<>(graph.getNodes()); - variables.remove(x); - variables.remove(y); - - List> subsets = SearchGraphUtils.powerSet(variables); - - IonIndependenceFacts indep = new IonIndependenceFacts(x, y, new HashSet<>()); - IonIndependenceFacts assoc = new IonIndependenceFacts(x, y, new HashSet<>()); - boolean addIndep = false; - boolean addAssoc = false; - - for (Graph pag : this.input) { - for (Set subset : subsets) { - if (containsAll(pag, subset, pair)) { - Node pagX = pag.getNode(x.getName()); - Node pagY = pag.getNode(y.getName()); - ArrayList pagSubset = new ArrayList<>(); - for (Node node : subset) { - pagSubset.add(pag.getNode(node.getName())); - } - if (pag.paths().isDSeparatedFrom(pagX, pagY, new ArrayList<>(pagSubset))) { - if (!pag.isAdjacentTo(pagX, pagY)) { - addIndep = true; - indep.addMoreZ(new ArrayList<>(subset)); - } - } else { - addAssoc = true; - assoc.addMoreZ(new ArrayList<>(subset)); - } - } - } - } - if (addIndep) separations.add(indep); - if (addAssoc) associations.add(assoc); - - } - - List> facts = new ArrayList<>(2); - facts.add(0, separations); - facts.add(1, associations); - return facts; - } - - /** - * States whether the given graph contains the nodes in the given set and the node pair. - */ - private boolean containsAll(Graph g, Set nodes, NodePair pair) { - List nodeNames = g.getNodeNames(); - if (!nodeNames.contains(pair.getFirst().getName()) || !nodeNames.contains(pair.getSecond().getName())) { - return false; - } - for (Node node : nodes) { - if (!nodeNames.contains(node.getName())) { - return false; - } - } - return true; - } - - /** - * Checks given pag against a set of necessary associations to determine if the pag implies an indepedence where one - * is known to not exist. - */ - private boolean predictsFalseIndependence(Set associations, Graph pag) { - for (IonIndependenceFacts assocFact : associations) - for (List conditioningSet : assocFact.getZ()) - if (pag.paths().isDSeparatedFrom( - assocFact.getX(), assocFact.getY(), conditioningSet)) - return true; - return false; - } - - /** - * @return all the triples in the graph that can be either oriented as a collider or non-collider. - */ - private Set getPossibleTriples(Graph pag) { - Set possibleTriples = new HashSet<>(); - for (Triple triple : getAllTriples(pag)) { - if (pag.isAdjacentTo(triple.getX(), triple.getY()) && pag.isAdjacentTo(triple.getY(), triple.getZ()) - && !pag.underlines().isUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()) && - !this.definiteNoncolliders.contains(triple) && - !pag.isDefCollider(triple.getX(), triple.getY(), triple.getZ())) { - possibleTriples.add(triple); - } - } - return possibleTriples; - } - - /** - * Given a map between sets of conditioned on variables and lists of PossibleDConnectingPaths, finds all the - * possible GraphChanges which could be used to block said undirectedPaths - */ - private List> findChanges(Map, List> paths) { - List> pagChanges = new ArrayList<>(); - - Set, List>> entries = paths.entrySet(); - /* Loop through each entry, ie each conditioned set of variables. */ - for (Map.Entry, List> entry : entries) { - Collection conditions = entry.getKey(); - List dConnecting = entry.getValue(); - - /* loop through each path */ - for (PossibleDConnectingPath possible : dConnecting) { - List possPath = possible.getPath(); - /* Created with 2*# of undirectedPaths as appoximation. might have to increase size once */ - Set pathChanges = new HashSet<>(2 * possPath.size()); - - /* find those conditions which are not along the path (used in colider) */ - List outsidePath = new ArrayList<>(conditions.size()); - for (Node condition : conditions) { - if (!possPath.contains(condition)) - outsidePath.add(condition); - } - - /* Walk through path, node by node */ - for (int i = 0; i < possPath.size() - 1; i++) { - Node current = possPath.get(i); - Node next = possPath.get(i + 1); - GraphChange gc; - - /* for each pair of nodes, add the operation to remove their edge */ - gc = new GraphChange(); - gc.addRemove(possible.getPag().getEdge(current, next)); - pathChanges.add(gc); - - /* for each triple centered on a node which is an element of the conditioning - * set, add the operation to orient as a nonColider around that node */ - if (conditions.contains(current) && i > 0) { - gc = new GraphChange(); - Triple nonColider = new Triple(possPath.get(i - 1), current, next); - gc.addNonCollider(nonColider); - pathChanges.add(gc); - } - - /* for each node on the path not in the conditioning set, make a colider. It - * is necessary though to ensure that there are no undirectedPaths implying that a - * conditioned variable (even outside the path) is a decendant of a colider */ - if ((!conditions.contains(current)) && i > 0) { - Triple colider = new Triple(possPath.get(i - 1), current, next); - - if (possible.getPag().underlines().isUnderlineTriple(possPath.get(i - 1), current, next)) - continue; - - Edge edge1 = possible.getPag().getEdge(colider.getX(), colider.getY()); - Edge edge2 = possible.getPag().getEdge(colider.getZ(), colider.getY()); - - if (edge1.getNode1().equals(colider.getY())) { - if (edge1.getEndpoint1().equals(Endpoint.TAIL)) { - continue; - } - } else if (edge1.getNode2().equals(colider.getY())) { - if (edge1.getEndpoint2().equals(Endpoint.TAIL)) { - continue; - } - } - - if (edge2.getNode1().equals(colider.getY())) { - if (edge2.getEndpoint1().equals(Endpoint.TAIL)) { - continue; - } - } else if (edge2.getNode2().equals(colider.getY())) { - if (edge2.getEndpoint2().equals(Endpoint.TAIL)) { - continue; - } - } - - /* Simple case, no conditions outside the path, so just add colider */ - if (outsidePath.size() == 0) { - gc = new GraphChange(); - gc.addCollider(colider); - pathChanges.add(gc); - continue; - } - - /* ensure nondecendency in possible path between getModel and each conditioned - * variable outside the path */ - for (Node outside : outsidePath) { - - /* list of possible decendant undirectedPaths */ - - List decendantPaths = new ArrayList<>(); - decendantPaths - = PossibleDConnectingPath.findDConnectingPaths - (possible.getPag(), current, outside, new ArrayList<>()); - - if (decendantPaths.isEmpty()) { - gc = new GraphChange(); - gc.addCollider(colider); - pathChanges.add(gc); - continue; - } - - /* loop over each possible path which might indicate decendency */ - for (PossibleDConnectingPath decendantPDCPath : decendantPaths) { - List decendantPath = decendantPDCPath.getPath(); - - /* walk down path checking orientation (path may already - * imply non-decendency) and creating changes if need be*/ - boolean impliesDecendant = true; - Set colideChanges = new HashSet<>(); - for (int j = 0; j < decendantPath.size() - 1; j++) { - Node from = decendantPath.get(j); - // chaneges from +1 - Node to = decendantPath.get(j + 1); - Edge currentEdge = possible.getPag().getEdge(from, to); - - if (currentEdge.getEndpoint1().equals(Endpoint.ARROW)) { - impliesDecendant = false; - break; - } - - gc = new GraphChange(); - gc.addCollider(colider); - gc.addRemove(currentEdge); - colideChanges.add(gc); - - gc = new GraphChange(); - gc.addCollider(colider); - gc.addOrient(to, from); - colideChanges.add(gc); - } - if (impliesDecendant) - pathChanges.addAll(colideChanges); - } - } - } - } - - pagChanges.add(pathChanges); - } - } - return pagChanges; - } - - /** - * Constructs PossRemove, every combination of removing of not removing redudant undirectedPaths - */ - private List possRemove(Graph pag, Map necEdges) { - // list of edges that can be removed - List remEdges = new ArrayList<>(); - for (Edge remEdge : necEdges.keySet()) { - if (!necEdges.get(remEdge)) - remEdges.add(remEdge); - } - // powerset of edges that can be removed - PowerSet pset = new PowerSet<>(remEdges); - List possRemove = new ArrayList<>(); - // for each set of edges in the powerset remove edges from graph and add to PossRemove - for (Set set : pset) { - Graph newPag = new EdgeListGraph(pag); - for (Edge edge : set) { - newPag.removeEdge(edge); - } - possRemove.add(newPag); - } - return possRemove; - } - - /* - * Does the final set of orientations after colliders have been oriented - */ - - private void doFinalOrientation(Graph graph) { - this.discrimGraphs.clear(); - Set currentDiscrimGraphs = new HashSet<>(); - currentDiscrimGraphs.add(graph); - while (this.changeFlag) { - this.changeFlag = false; - currentDiscrimGraphs.addAll(this.discrimGraphs); - this.discrimGraphs.clear(); - for (Graph newGraph : currentDiscrimGraphs) { - doubleTriangle(newGraph); - awayFromColliderAncestorCycle(newGraph); - if (!discrimPaths(newGraph)) { - if (this.changeFlag) { - this.discrimGraphs.add(newGraph); - } else { - this.finalResult.add(newGraph); - } - } - } - currentDiscrimGraphs.clear(); - } - this.changeFlag = true; - } - - /** - * Implements the double-triangle orientation rule, which states that if D*-oB, A*->B<-*C and A*-*D*-*C is a - * noncollider, then D*->B. - */ - private void doubleTriangle(Graph graph) { - List nodes = graph.getNodes(); - - for (Node B : nodes) { - - List intoBArrows = graph.getNodesInTo(B, Endpoint.ARROW); - List intoBCircles = graph.getNodesInTo(B, Endpoint.CIRCLE); - - //possible A's and C's are those with arrows into B - List possA = new LinkedList<>(intoBArrows); - List possC = new LinkedList<>(intoBArrows); - - //possible D's are those with circles into B - for (Node D : intoBCircles) { - for (Node A : possA) { - for (Node C : possC) { - if (C == A) { - continue; - } - - //skip anything not a double triangle - if (!graph.isAdjacentTo(A, D) || - !graph.isAdjacentTo(C, D)) { - continue; - } - - //skip if A,D,C is a collider - if (graph.isDefCollider(A, D, C)) { - continue; - } - - //if all of the previous tests pass, orient D*-oB as D*->B - if (!isArrowpointAllowed(graph, D, B)) { - continue; - } - - graph.setEndpoint(D, B, Endpoint.ARROW); - this.changeFlag = true; - } - } - } - } - } - - // Does only the ancestor and cycle rules of these repeatedly until no changes - - private void awayFromAncestorCycle(Graph graph) { - while (this.changeFlag) { - this.changeFlag = false; - List nodes = graph.getNodes(); - - for (Node B : nodes) { - List adj = graph.getAdjacentNodes(B); - - if (adj.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adj.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node A = adj.get(combination[0]); - Node C = adj.get(combination[1]); - - //choice gen doesnt do diff orders, so must switch A & C around. - awayFromAncestor(graph, A, B, C); - awayFromAncestor(graph, C, B, A); - awayFromCycle(graph, A, B, C); - awayFromCycle(graph, C, B, A); - } - } - } - this.changeFlag = true; - } - - // Does all 3 of these rules at once instead of going through all - // triples multiple times per iteration of doFinalOrientation. - - private void awayFromColliderAncestorCycle(Graph graph) { - List nodes = graph.getNodes(); - - for (Node B : nodes) { - List adj = graph.getAdjacentNodes(B); - - if (adj.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adj.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node A = adj.get(combination[0]); - Node C = adj.get(combination[1]); - - //choice gen doesnt do diff orders, so must switch A & C around. - ruleR1(A, B, C, graph); - ruleR1(C, B, A, graph); - ruleR2(A, B, C, graph); - ruleR2(C, B, A, graph); - - } - } - } - - /// R1, away from collider - - private void ruleR1(Node a, Node b, Node c, Graph graph) { - if (graph.isAdjacentTo(a, c)) { - return; - } - - if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(graph, b, c)) { - return; - } - - graph.setEndpoint(c, b, Endpoint.TAIL); - graph.setEndpoint(b, c, Endpoint.ARROW); - } - } - - //if Ao->c and a-->b-->c, then a-->c - // Zhang's rule R2, awy from ancestor. - - private void ruleR2(Node a, Node b, Node c, Graph graph) { - if (!graph.isAdjacentTo(a, c)) { - return; - } - - if (graph.getEndpoint(b, a) == Endpoint.TAIL && graph.getEndpoint(a, b) == Endpoint.ARROW - && graph.getEndpoint(b, c) == Endpoint.ARROW && graph.getEndpoint(a, c) == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(graph, a, c)) { - return; - } - - graph.setEndpoint(a, c, Endpoint.ARROW); - } else if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.TAIL - && graph.getEndpoint(b, c) == Endpoint.ARROW && graph.getEndpoint(a, c) == Endpoint.CIRCLE - ) { - if (!isArrowpointAllowed(graph, a, c)) { - return; - } - - graph.setEndpoint(a, c, Endpoint.ARROW); - } - } - - - private boolean isArrowpointAllowed(Graph graph, Node x, Node y) { - if (graph.getEndpoint(x, y) == Endpoint.ARROW) { - return true; - } - - if (graph.getEndpoint(x, y) == Endpoint.TAIL) { - return false; - } - - if (graph.getEndpoint(y, x) == Endpoint.ARROW) { - graph.getEndpoint(x, y); - } - return true; - } - - // if a*->Bo-oC and not a*-*c, then a*->b-->c - // (orient either circle if present, don't need both) - - private void awayFromCollider(Graph graph, Node a, Node b, Node c) { - Endpoint BC = graph.getEndpoint(b, c); - Endpoint CB = graph.getEndpoint(c, b); - - if (!(graph.isAdjacentTo(a, c)) && - (graph.getEndpoint(a, b) == Endpoint.ARROW)) { - if (CB == Endpoint.CIRCLE || CB == Endpoint.TAIL) { - if (BC == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(graph, b, c)) { - return; - } - - graph.setEndpoint(b, c, Endpoint.ARROW); - this.changeFlag = true; - } - } - - if (BC == Endpoint.CIRCLE || BC == Endpoint.ARROW) { - if (CB == Endpoint.CIRCLE) { - graph.setEndpoint(c, b, Endpoint.TAIL); - this.changeFlag = true; - } - } - } - } - - //if a*-oC and either a-->b*->c or a*->b-->c, then a*->c - - private void awayFromAncestor(Graph graph, Node a, Node b, Node c) { - if ((graph.isAdjacentTo(a, c)) && - (graph.getEndpoint(a, c) == Endpoint.CIRCLE)) { - - if ((graph.getEndpoint(a, b) == Endpoint.ARROW) && - (graph.getEndpoint(b, c) == Endpoint.ARROW) && ( - (graph.getEndpoint(b, a) == Endpoint.TAIL) || - (graph.getEndpoint(c, b) == Endpoint.TAIL))) { - - if (!isArrowpointAllowed(graph, a, c)) { - return; - } - - graph.setEndpoint(a, c, Endpoint.ARROW); - this.changeFlag = true; - } - } - } - - //if Ao->c and a-->b-->c, then a-->c - - private void awayFromCycle(Graph graph, Node a, Node b, Node c) { - if ((graph.isAdjacentTo(a, c)) && - (graph.getEndpoint(a, c) == Endpoint.ARROW) && - (graph.getEndpoint(c, a) == Endpoint.CIRCLE)) { - if (graph.paths().isDirectedFromTo(a, b) && graph.paths().isDirectedFromTo(b, c)) { - graph.setEndpoint(c, a, Endpoint.TAIL); - this.changeFlag = true; - } - } - } - - /** - * The triangles that must be oriented this way (won't be done by another rule) all look like the ones below, where - * the dots are a collider path from L to A with each node on the path (except L) a parent of C. - *

-     *          B
-     *         xo           x is either an arrowhead or a circle
-     *        /  \
-     *       v    v
-     * L....A --> C
-     * 
- */ - private boolean discrimPaths(Graph graph) { - List nodes = graph.getNodes(); - - for (Node b : nodes) { - - //potential A and C candidate pairs are only those - // that look like this: A<-oBo->C or A<->Bo->C - List possAandC = graph.getNodesOutTo(b, Endpoint.ARROW); - - //keep arrows and circles - List possA = new LinkedList<>(possAandC); - possA.removeAll(graph.getNodesInTo(b, Endpoint.TAIL)); - - //keep only circles - List possC = new LinkedList<>(possAandC); - possC.retainAll(graph.getNodesInTo(b, Endpoint.CIRCLE)); - - for (Node a : possA) { - for (Node c : possC) { - if (!graph.isParentOf(a, c)) { - continue; - } - - LinkedList reachable = new LinkedList<>(); - reachable.add(a); - if (reachablePathFindOrient(graph, a, b, c, reachable)) { - return true; - } - } - } - } - return false; - } - - /** - * a method to search "back from a" to find a DDP. It is called with a reachability list (first consisting only of - * a). This is breadth-first, utilizing "reachability" concept from Geiger, Verma, and Pearl 1990. The body of - * a DDP consists of colliders that are parents of c. - */ - private boolean reachablePathFindOrient(Graph graph, Node a, Node b, Node c, - LinkedList reachable) { - Set cParents = new HashSet<>(graph.getParents(c)); - - // Needed to avoid cycles in failure case. - Set visited = new HashSet<>(); - visited.add(b); - visited.add(c); - - // We don't want to include a,b,or c on the path, so they are added to - // the "visited" set. b and c are added explicitly here; a will be - // added in the first while iteration. - while (reachable.size() > 0) { - Node x = reachable.removeFirst(); - visited.add(x); - - // Possible DDP path endpoints. - List pathExtensions = graph.getNodesInTo(x, Endpoint.ARROW); - pathExtensions.removeAll(visited); - - for (Node l : pathExtensions) { - - // If l is reachable and not adjacent to c, its a DDP - // endpoint, so do DDP orientation. Otherwise, if l <-> c, - // add l to the list of reachable nodes. - if (!graph.isAdjacentTo(l, c)) { - - // Check whether should be reoriented given - // that l is not adjacent to c; if so, orient and stop. - doDdpOrientation(graph, l, a, b, c); - return true; - } else if (cParents.contains(l)) { - if (graph.getEndpoint(x, l) == Endpoint.ARROW) { - reachable.add(l); - } - } - } - } - return false; - } - - /** - * Orients the edges inside the definte discriminating path triangle. Takes the left endpoint, and a,b,c as - * arguments. - */ - private void doDdpOrientation(Graph graph, Node l, Node a, Node b, Node c) { - this.changeFlag = true; - for (IonIndependenceFacts iif : this.separations) { - if ((iif.getX().equals(l) && iif.getY().equals(c)) || - iif.getY().equals(l) && iif.getX().equals(c)) { - for (List condSet : iif.getZ()) { - if (condSet.contains(b)) { - graph.setEndpoint(c, b, Endpoint.TAIL); - this.discrimGraphs.add(graph); - return; - } - } - break; - } - } - Graph newGraph1 = new EdgeListGraph(graph); - newGraph1.setEndpoint(a, b, Endpoint.ARROW); - newGraph1.setEndpoint(c, b, Endpoint.ARROW); - this.discrimGraphs.add(newGraph1); - Graph newGraph2 = new EdgeListGraph(graph); - newGraph2.setEndpoint(c, b, Endpoint.TAIL); - this.discrimGraphs.add(newGraph2); - } - - private Set removeMoreSpecific(Set outputPags) { - Set moreSpecific = new HashSet<>(); - // checks for and removes PAGs tht are more specific, same skeleton and orientations - // except for one or more arrows or tails where another graph has circles, than other - // pags in the output graphs that may be produced from the edge removes in step 4 - for (Graph pag : outputPags) { - for (Graph pag2 : outputPags) { - // if same pag - if (pag.equals(pag2)) { - continue; - } - // if different number of edges then continue - if (pag.getEdges().size() != pag2.getEdges().size()) { - continue; - } - boolean sameAdjacencies = true; - for (Edge edge1 : pag.getEdges()) { - if (!pag2.isAdjacentTo(edge1.getNode1(), edge1.getNode2())) { - sameAdjacencies = false; - } - } - if (sameAdjacencies) { - // checks to see if pag2 has same arrows and tails - boolean arrowstails = true; - boolean circles = true; - for (Edge edge2 : pag2.getEdges()) { - Edge edge1 = pag.getEdge(edge2.getNode1(), edge2.getNode2()); - if (edge1.getNode1().equals(edge2.getNode1())) { - if (!edge2.getEndpoint1().equals(Endpoint.CIRCLE)) { - if (!edge1.getEndpoint1().equals(edge2.getEndpoint1())) { - arrowstails = false; - } - } else { - if (!edge1.getEndpoint1().equals(edge2.getEndpoint1())) { - circles = false; - } - } - if (!edge2.getEndpoint2().equals(Endpoint.CIRCLE)) { - if (!edge1.getEndpoint2().equals(edge2.getEndpoint2())) { - arrowstails = false; - } - } else { - if (!edge1.getEndpoint2().equals(edge2.getEndpoint2())) { - circles = false; - } - } - } else if (edge1.getNode1().equals(edge2.getNode2())) { - if (!edge2.getEndpoint1().equals(Endpoint.CIRCLE)) { - if (!edge1.getEndpoint2().equals(edge2.getEndpoint1())) { - arrowstails = false; - } - } else { - if (!edge1.getEndpoint2().equals(edge2.getEndpoint1())) { - circles = false; - } - } - if (!edge2.getEndpoint2().equals(Endpoint.CIRCLE)) { - if (!edge1.getEndpoint1().equals(edge2.getEndpoint2())) { - arrowstails = false; - } - } else { - if (!edge1.getEndpoint1().equals(edge2.getEndpoint2())) { - circles = false; - } - } - } - } - if (arrowstails && !circles) { - moreSpecific.add(pag); - break; - } - } - } - } - for (Graph pag : moreSpecific) { - outputPags.remove(pag); - } - return outputPags; - } - - private Set checkPaths(Set pags) { - HashSet pagsOut = new HashSet<>(); - - for (Graph pag : pags) { - boolean allAccountFor = true; - - GRAPH: - for (Graph inGraph : this.input) { - for (Edge edge : inGraph.getEdges()) { - Node node1 = pag.getNode(edge.getNode1().getName()); - Node node2 = pag.getNode(edge.getNode2().getName()); - - if (Edges.isDirectedEdge(edge)) { - if (!pag.paths().existsSemiDirectedPathFromTo(node1, Collections.singleton(node2))) { - allAccountFor = false; - break GRAPH; - } - } - if (/*!pag.existsTrek(node1, node2) ||*/ Edges.isPartiallyOrientedEdge(edge)) { - if (pag.paths().existsSemiDirectedPathFromTo(node2, Collections.singleton(node1))) { - allAccountFor = false; - break GRAPH; - } - } - } - } - - if (allAccountFor) { - pagsOut.add(pag); - } - } - - return pagsOut; - } - - /** - * Exactly the same as edu.cmu.tetrad.graph.IndependenceFact excepting this class allows for multiple conditioning - * sets to be associated with a single pair of nodes, which is necessary for the proper ordering of iterations in - * the ION search. - */ - private static final class IonIndependenceFacts { - private final Node x; - private final Node y; - private final Collection> z; - - /** - * Constructs a triple of nodes. - */ - public IonIndependenceFacts(Node x, Node y, Collection> z) { - if (x == null || y == null || z == null) { - throw new NullPointerException(); - } - - this.x = x; - this.y = y; - this.z = z; - } - - public Node getX() { - return this.x; - } - - public Node getY() { - return this.y; - } - - public Collection> getZ() { - return this.z; - } - - public void addMoreZ(List moreZ) { - this.z.add(moreZ); - } - - public int hashCode() { - int hash = 17; - hash += 19 * this.x.hashCode() * this.y.hashCode(); - hash += 23 * this.z.hashCode(); - return hash; - } - - public boolean equals(Object obj) { - if (!(obj instanceof IonIndependenceFacts)) { - return false; - } - - IonIndependenceFacts fact = (IonIndependenceFacts) obj; - return (this.x.equals(fact.x) && this.y.equals(fact.y) && - this.z.equals(fact.z)) - || (this.x.equals(fact.y) & this.y.equals(fact.x) && - this.z.equals(fact.z)); - } - - public String toString() { - return "I(" + this.x + ", " + this.y + " | " + this.z + ")"; - } - } - - /** - * A PowerSet constructed with a collection with elements of type E can construct an Iterator which enumerates all - * possible subsets (of type Collection) of the collection used to construct the PowerSet. - * - * @param The type of elements in the Collection passed to the constructor. - * @author pingel - */ - - private static class PowerSet implements Iterable> { - Collection all; - - public PowerSet(Collection all) { - this.all = all; - } - - /** - * @return an iterator over elements of type Collection which enumerates the PowerSet of the collection used - * in the constructor - */ - - public Iterator> iterator() { - return new PowerSetIterator<>(this); - } - - static class PowerSetIterator implements Iterator> { - PowerSet powerSet; - List canonicalOrder = new ArrayList<>(); - List mask = new ArrayList<>(); - boolean hasNext = true; - - PowerSetIterator(PowerSet powerSet) { - - this.powerSet = powerSet; - this.canonicalOrder.addAll(powerSet.all); - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - private boolean allOnes() { - for (InE bit : this.mask) { - if (bit == null) { - return false; - } - } - return true; - } - - private void increment() { - int i = 0; - while (true) { - if (i < this.mask.size()) { - InE bit = this.mask.get(i); - if (bit == null) { - this.mask.set(i, this.canonicalOrder.get(i)); - return; - } else { - this.mask.set(i, null); - i++; - } - } else { - this.mask.add(this.canonicalOrder.get(i)); - return; - } - } - } - - public boolean hasNext() { - return this.hasNext; - } - - public Set next() { - - Set result = new HashSet<>(this.mask); - result.remove(null); - - this.hasNext = this.mask.size() < this.powerSet.all.size() || !allOnes(); - - if (this.hasNext) { - increment(); - } - - return result; - - } - } - } - - public static List> treks(Graph graph, Node node1, Node node2) { - List> paths = new LinkedList<>(); - Ion2.treks(graph, node1, node2, new LinkedList<>(), paths); - return paths; - } - - /** - * Constructs the list of treks between node1 and node2. - */ - private static void treks(Graph graph, Node node1, Node node2, - LinkedList path, List> paths) { - path.addLast(node1); - - for (Edge edge : graph.getEdges(node1)) { - Node next = Edges.traverse(node1, edge); - - if (next == null) { - continue; - } - - if (path.size() > 1) { - Node node0 = path.get(path.size() - 2); - - if (next == node0) { - continue; - } - - if (graph.isDefCollider(node0, node1, next)) { - continue; - } - } - - if (next == node2) { - LinkedList _path = new LinkedList<>(path); - _path.add(next); - paths.add(_path); - continue; - } - - if (path.contains(next)) { - continue; - } - - Ion2.treks(graph, next, node2, path, paths); - } - - path.removeLast(); - } - - private Graph screenForKnowledge(Graph pag) { - for (Iterator it = this.knowledge.forbiddenEdgesIterator(); it.hasNext(); ) { - KnowledgeEdge next = it.next(); - Node y = pag.getNode(next.getFrom()); - Node x = pag.getNode(next.getTo()); - - if (x == null || y == null) { - continue; - } - - Edge edge = pag.getEdge(x, y); - - if (edge == null) { - continue; - } - - if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.TAIL) { - return null; - } else if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { - pag.removeEdge(edge); - pag.addEdge(Edges.bidirectedEdge(x, y)); - } else if (edge.getProximalEndpoint(x) == Endpoint.CIRCLE && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { - pag.removeEdge(edge); - pag.addEdge(Edges.partiallyOrientedEdge(x, y)); - } - } - - - for (Iterator it = this.knowledge.requiredEdgesIterator(); it.hasNext(); ) { - KnowledgeEdge next = it.next(); - Node x = pag.getNode(next.getFrom()); - Node y = pag.getNode(next.getTo()); - - if (x == null || y == null) { - continue; - } - - Edge edge = pag.getEdge(x, y); - - if (edge == null) { - return null; - } else if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.TAIL) { - return null; - } else if (edge.getProximalEndpoint(x) == Endpoint.ARROW && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { - return null; - } else if (edge.getProximalEndpoint(x) == Endpoint.CIRCLE && edge.getProximalEndpoint(y) == Endpoint.ARROW) { - pag.removeEdge(edge); - pag.addEdge(Edges.directedEdge(x, y)); - } else if (edge.getProximalEndpoint(x) == Endpoint.CIRCLE && edge.getProximalEndpoint(y) == Endpoint.CIRCLE) { - pag.removeEdge(edge); - pag.addEdge(Edges.directedEdge(x, y)); - } - } - - -// doFinalOrientation(pag); - return pag; - } - - private Set applyKnowledge(Set outputSet) { - Set _out = new HashSet<>(); - - for (Graph graph : outputSet) { - Graph _graph = screenForKnowledge(graph); - - if (_graph != null) { - _out.add(_graph); - } - } - - return _out; - } - - -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonHittingSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonHittingSet.java index f1eba94188..0b1aadda71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonHittingSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonHittingSet.java @@ -27,22 +27,24 @@ import java.util.Set; /** - * ************************************************************************** - * - * @author Trevor Burns *

* Provides a static method which implements a correct version of Reiter's hitting set algorithm as described by * Greiner, Smith, and Wilkerson in "A Correction to the Algorithm in Reiter's Theory of Diagnosis" Artificial * Intellegence 41 (1989) (see for detailed specification). However, this is not a general implementation, it is * tailored for use in the ION search by dealing with GraphChange objects instead of something more general. + *

*

* Varies mainly in that no explicit DAG is constructed, it is only implied by the structure of the calls. This is * because this implementation is concerned solely with finding the hitting sets and once a node is processed its * information is never again accessed if one stores the necessary path of edge labels in newly constructed nodes. + *

*

* There is one exception to the above claim. If one follows the revised algorithm strictly, in Enhancement Step 3 one * does need information from previous levels. The author decided this step was easier to code if one precomputes - * instead of doing it on the fly, so this exception is inconsiquential. + * instead of doing it on the fly, so this exception is inconsiquential. * + *

+ * + * @author Trevor Burns */ public class IonHittingSet { From 125ae4b13a1d41178be3d6e1f35ac6c0c4837562 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:11:40 -0400 Subject: [PATCH 159/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/IndTestFisherZ.java | 252 ++++++++++-------- 1 file changed, 141 insertions(+), 111 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java index b57a56205c..3731386a3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java @@ -73,7 +73,6 @@ public final class IndTestFisherZ implements IndependenceTest { private double p = Double.NaN; private double r = Double.NaN; - //==========================CONSTRUCTORS=============================// /** @@ -133,12 +132,11 @@ public IndTestFisherZ(DataSet dataSet, double alpha) { * * @param data A 2D continuous data set with no missing values. * @param variables A list of variables, a subset of the variables of data. - * @param alpha The significance cutoff level. p values less than alpha will be reported as dependent. + * @param alpha The alpha level of the test. */ public IndTestFisherZ(Matrix data, List variables, double alpha) { this.dataSet = new BoxDataSet(new VerticalDoubleDataBox(data.transpose().toArray()), variables); this.cor = SimpleDataLoader.getCorrelationMatrix(this.dataSet); -// this.cor = new CorrelationMatrix(this.dataSet); this.variables = Collections.unmodifiableList(variables); this.indexMap = indexMap(variables); this.nameMap = nameMap(variables); @@ -156,6 +154,8 @@ public IndTestFisherZ(Matrix data, List variables, double alpha) { /** * Constructs a new independence test that will determine conditional independence facts using the given correlation * matrix and the given significance level. + * @param covMatrix The covaraince matrix. + * @param alpha The alpha level of the test. */ public IndTestFisherZ(ICovarianceMatrix covMatrix, double alpha) { this.cor = new CorrelationMatrix(covMatrix); @@ -177,6 +177,8 @@ public IndTestFisherZ(ICovarianceMatrix covMatrix, double alpha) { /** * Creates a new independence test instance for a subset of the variables. + * @return a new independence test. + * @see IndependenceTest */ public IndependenceTest indTestSubset(List vars) { if (vars.isEmpty()) { @@ -208,8 +210,9 @@ public IndependenceTest indTestSubset(List vars) { * @param x the one variable being compared. * @param y the second variable being compared. * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. + * @return Independence result for x _||_ y | z. * @throws RuntimeException if a matrix singularity is encountered. + * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, List z) { double p = 0.0; @@ -246,6 +249,14 @@ public double getPValue() { return this.p; } + /** + * Returns the p-value for x _||_ y | z. + * @param x Node 1 + * @param y Node 2 + * @param z The conditioning varialbes. + * @return The p-value. + * @throws SingularMatrixException If a singularity occurs when invering a matrix. + */ public double getPValue(Node x, Node y, List z) throws SingularMatrixException { double r; int n; @@ -272,69 +283,10 @@ public double getPValue(Node x, Node y, List z) throws SingularMatrixExcep return p; } - //======================PRIVATE==========================// - - private double partialCorrelation(Node x, Node y, List z, List rows) throws SingularMatrixException { - int[] indices = new int[z.size() + 2]; - indices[0] = this.indexMap.get(x.getName()); - indices[1] = this.indexMap.get(y.getName()); - for (int i = 0; i < z.size(); i++) indices[i + 2] = this.indexMap.get(z.get(i).getName()); -// - Matrix cor; - - if (this.cor != null) { - cor = this.cor.getSelection(indices, indices); - } else { - Matrix cov = getCov(rows, indices); - cor = MatrixUtils.convertCovToCorr(cov); - } - -// if (z.isEmpty()) return cor.get(0, 1); - - return StatUtils.partialCorrelationPrecisionMatrix(cor); - } - - private Matrix getCov(List rows, int[] cols) { - Matrix cov = new Matrix(cols.length, cols.length); - - for (int i = 0; i < cols.length; i++) { - for (int j = 0; j < cols.length; j++) { - double mui = 0.0; - double muj = 0.0; - - for (int k : rows) { - mui += this.dataSet.getDouble(k, cols[i]); - muj += this.dataSet.getDouble(k, cols[j]); - } - - mui /= rows.size() - 1; - muj /= rows.size() - 1; - - double _cov = 0.0; - - for (int k : rows) { - _cov += (this.dataSet.getDouble(k, cols[i]) - mui) * (this.dataSet.getDouble(k, cols[j]) - muj); - } - - double mean = _cov / (rows.size()); - cov.set(i, j, mean); - } - } - - return cov; - } - - private double getR(Node x, Node y, List z, List rows) { -// try { - return partialCorrelation(x, y, z, rows); -// } catch (SingularMatrixException e) { -// e.printStackTrace(); -// System.out.println(SearchLogUtils.determinismDetected(z, x)); -// return Double.NaN; -// } - } - - + /** + * Returns the BIC score for this test. + * @return The BIC score. + */ public double getBic() { return -sampleSize() * FastMath.log(1.0 - this.r * this.r) - FastMath.log(sampleSize()); } @@ -356,7 +308,6 @@ public void setAlpha(double alpha) { } this.alpha = alpha; -// double cutoff = StatUtils.getZForAlpha(alpha); } /** @@ -367,6 +318,11 @@ public List getVariables() { return this.variables; } + /** + * Sets teh variables to a new list of the same size. Useful if multiple independence tests + * are needed with object-identical sets of variables. + * @param variables The new list of variables. + */ public void setVariables(List variables) { if (variables.size() != this.variables.size()) throw new IllegalArgumentException("Wrong # of variables."); this.variables = new ArrayList<>(variables); @@ -380,10 +336,76 @@ public Node getVariable(String name) { return this.nameMap.get(name); } + /** + * @return the data set being analyzed. + */ + public DataSet getData() { + return this.dataSet; + } + + /** + * @return the correlation matrix being analyzed. + */ + public ICovarianceMatrix getCov() { + return this.cor; + } + + /** + * Returns the (singleton) list of datasets being analyzed. + * @return This list (length 1). + */ + @Override + public List getDataSets() { + List dataSets = new ArrayList<>(); + dataSets.add(this.dataSet); + return dataSets; + } + + /** + * Returns the sample size. + * @return This size. + */ + @Override + public int getSampleSize() { + return this.cor.getSampleSize(); + } + + /** + * Returns the score for this test, alpha - p. Should be dependent only for positive values. + * @return This score. + */ + @Override + public double getScore() { + return this.alpha - this.p;//FastMath.abs(fisherZ) - cutoff; + } + + /** + * Returns true iff verbose output should be printed. + * @return True if so. + */ + public boolean isVerbose() { + return this.verbose; + } + + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * @return A string representation of this test. + */ + public String toString() { + return "Fisher Z, alpha = " + new DecimalFormat("0.0###").format(getAlpha()); + } /** - * If isDeterminismAllowed(), deters to IndTestFisherZD; otherwise throws - * UnsupportedOperationException. + * Returns true in case the variable in Z jointly determine x. + * @param z The contitioning variables. + * @param x The conditioned variable. */ public boolean determines(List z, Node x) throws UnsupportedOperationException { int[] parents = new int[z.size()]; @@ -408,20 +430,58 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep return false; } - /** - * @return the data set being analyzed. - */ - public DataSet getData() { - return this.dataSet; + private double partialCorrelation(Node x, Node y, List z, List rows) throws SingularMatrixException { + int[] indices = new int[z.size() + 2]; + indices[0] = this.indexMap.get(x.getName()); + indices[1] = this.indexMap.get(y.getName()); + for (int i = 0; i < z.size(); i++) indices[i + 2] = this.indexMap.get(z.get(i).getName()); +// + Matrix cor; + + if (this.cor != null) { + cor = this.cor.getSelection(indices, indices); + } else { + Matrix cov = getCov(rows, indices); + cor = MatrixUtils.convertCovToCorr(cov); + } + +// if (z.isEmpty()) return cor.get(0, 1); + + return StatUtils.partialCorrelationPrecisionMatrix(cor); } - //==========================PRIVATE METHODS============================// + private Matrix getCov(List rows, int[] cols) { + Matrix cov = new Matrix(cols.length, cols.length); + + for (int i = 0; i < cols.length; i++) { + for (int j = 0; j < cols.length; j++) { + double mui = 0.0; + double muj = 0.0; - /** - * @return a string representation of this test. - */ - public String toString() { - return "Fisher Z, alpha = " + new DecimalFormat("0.0###").format(getAlpha()); + for (int k : rows) { + mui += this.dataSet.getDouble(k, cols[i]); + muj += this.dataSet.getDouble(k, cols[j]); + } + + mui /= rows.size() - 1; + muj /= rows.size() - 1; + + double _cov = 0.0; + + for (int k : rows) { + _cov += (this.dataSet.getDouble(k, cols[i]) - mui) * (this.dataSet.getDouble(k, cols[j]) - muj); + } + + double mean = _cov / (rows.size()); + cov.set(i, j, mean); + } + } + + return cov; + } + + private double getR(Node x, Node y, List z, List rows) { + return partialCorrelation(x, y, z, rows); } private int sampleSize() { @@ -452,36 +512,6 @@ private Map indexMap(List variables) { return indexMap; } - public ICovarianceMatrix getCov() { - return this.cor; - } - - @Override - public List getDataSets() { - List dataSets = new ArrayList<>(); - dataSets.add(this.dataSet); - return dataSets; - } - - @Override - public int getSampleSize() { - return this.cor.getSampleSize(); - } - - - @Override - public double getScore() { - return this.alpha - this.p;//FastMath.abs(fisherZ) - cutoff; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - private List getRows(List allVars, Map nodesHash) { List rows = new ArrayList<>(); From 4c3d474aae88c3189436d9299377ff4627b0b26e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:13:16 -0400 Subject: [PATCH 160/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/IndTestFisherZ.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java index 3731386a3f..069396e3c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java @@ -48,26 +48,13 @@ * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z */ public final class IndTestFisherZ implements IndependenceTest { - private final Map indexMap; private final Map nameMap; private final NormalDistribution normal = new NormalDistribution(0, 1, 1e-15); private final Map nodesHash; - /** - * The correlation matrix. - */ private final ICovarianceMatrix cor; - /** - * The variables of the covariance matrix, in order. (Unmodifiable list.) - */ private List variables; - /** - * The significance level of the independence tests. - */ private double alpha; - /** - * Stores a reference to the dataset being analyzed. - */ private DataSet dataSet; private boolean verbose = true; private double p = Double.NaN; From 776a204f288f790dcf098f0f45d945d57ad1cb2c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:29:50 -0400 Subject: [PATCH 161/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java index 069396e3c1..8062b6733c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java @@ -422,7 +422,7 @@ private double partialCorrelation(Node x, Node y, List z, List ro indices[0] = this.indexMap.get(x.getName()); indices[1] = this.indexMap.get(y.getName()); for (int i = 0; i < z.size(); i++) indices[i + 2] = this.indexMap.get(z.get(i).getName()); -// + Matrix cor; if (this.cor != null) { @@ -432,8 +432,6 @@ private double partialCorrelation(Node x, Node y, List z, List ro cor = MatrixUtils.convertCovToCorr(cov); } -// if (z.isEmpty()) return cor.get(0, 1); - return StatUtils.partialCorrelationPrecisionMatrix(cor); } From 66056cda31ebdec0eca29246661f71a11059c2a8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:31:53 -0400 Subject: [PATCH 162/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java index 8062b6733c..b4bf73995f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java @@ -45,7 +45,7 @@ * Scheines, "Causation, Prediction and Search," 2nd edition, page 94. * * @author Joseph Ramsey - * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z + * @author Frank Wimberly */ public final class IndTestFisherZ implements IndependenceTest { private final Map indexMap; From 74b924593a476b3939fcdd23ba94f399cacf2a2d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:33:18 -0400 Subject: [PATCH 163/464] Fixing documentation etc. --- .../cmu/tetrad/search/XdslXmlConstants.java | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/XdslXmlConstants.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/XdslXmlConstants.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/XdslXmlConstants.java deleted file mode 100644 index f441b3941f..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/XdslXmlConstants.java +++ /dev/null @@ -1,43 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -/** - * This class contains all the constants used in the xml representation of a Bayes - * graph. - * - * @author mattheweasterday - */ -class XdslXmlConstants { - - public static final String PARENTS = "parents"; - public static final String CPT = "cpt"; - public static final String ROW = "row"; - public static final String NAME = "name"; - public static final String LATENT = "latent"; - public static final String X = "x"; - public static final String Y = "y"; - public static final String VARIABLE = "variable"; -} - - - From ca6e126d91bd30ee5bed35dd000fd5192d915c04 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:35:03 -0400 Subject: [PATCH 164/464] Fixing documentation etc. --- .../edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java | 4 ++-- .../tetrad/search/{XdslXmlParser.java => BayesImParser.java} | 4 ++-- .../src/main/java/edu/cmu/tetrad/search/RBExperiments.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{XdslXmlParser.java => BayesImParser.java} (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java index bc4968711b..7dfdc200c2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.graph.LayoutUtil; -import edu.cmu.tetrad.search.XdslXmlParser; +import edu.cmu.tetrad.search.BayesImParser; import edu.cmu.tetradapp.model.BayesImWrapper; import nu.xom.Builder; import nu.xom.Document; @@ -72,7 +72,7 @@ public void actionPerformed(ActionEvent e) { Document document = builder.build(file); LoadBayesImXsdlXmlAction.printDocument(document); - XdslXmlParser parser = new XdslXmlParser(); + BayesImParser parser = new BayesImParser(); BayesIm bayesIm = parser.getBayesIm(document.getRootElement()); System.out.println(bayesIm); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/XdslXmlParser.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesImParser.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/XdslXmlParser.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesImParser.java index 221d8cfe16..cc691dc9a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/XdslXmlParser.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesImParser.java @@ -42,11 +42,11 @@ * * @author mattheweasterday */ -public class XdslXmlParser { +public class BayesImParser { private boolean useDisplayNames; - public XdslXmlParser() { + public BayesImParser() { } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java index ed581da719..f795973f9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java @@ -851,7 +851,7 @@ private BayesIm loadBayesIm(String filename, boolean useDisplayNames) { File dir = new File(this.directory + "/xdsl"); File file = new File(dir, filename); Document document = builder.build(file); - XdslXmlParser parser = new XdslXmlParser(); + BayesImParser parser = new BayesImParser(); parser.setUseDisplayNames(useDisplayNames); return parser.getBayesIm(document.getRootElement()); } catch (ParsingException | IOException e) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java index f2b25831fe..abda0f57e8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.IndTestProbabilistic; import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.XdslXmlParser; +import edu.cmu.tetrad.search.BayesImParser; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; import nu.xom.Builder; @@ -195,7 +195,7 @@ private static BayesIm loadBayesIm() { File file = new File("src/test/resources/" + "Alarm.xdsl"); System.out.println(file.getAbsolutePath()); Document document = builder.build(file); - XdslXmlParser parser = new XdslXmlParser(); + BayesImParser parser = new BayesImParser(); parser.setUseDisplayNames(true); return parser.getBayesIm(document.getRootElement()); } catch (ParsingException | IOException e) { From 79d4000e00391318433b5de8aba3fafc5151f283 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:36:42 -0400 Subject: [PATCH 165/464] Fixing documentation etc. --- .../tetrad/search/TimeSeriesLagSearch.java | 385 ------------------ 1 file changed, 385 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/TimeSeriesLagSearch.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TimeSeriesLagSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TimeSeriesLagSearch.java deleted file mode 100644 index c6ed217a8e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TimeSeriesLagSearch.java +++ /dev/null @@ -1,385 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.TetradLogger; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested - * locally. - * - * @author Joseph Ramsey (this version). - */ -public final class TimeSeriesLagSearch implements GraphSearch { - - /** - * The independence test used for the PC search. - */ - private final IndependenceTest independenceTest; - - /** - * Forbidden and required edges for the search. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * The maximum number of nodes conditioned on in the search. - */ - private final int depth = 0; - - /** - * The graph that's constructed during the search. - */ - private Graph graph; - - /** - * Elapsed time of last search. - */ - private long elapsedTime; - - /** - * The list of all unshielded triples. - */ - private Set allTriples; - - /** - * Set of unshielded colliders from the triple orientation step. - */ - private Set colliderTriples; - - /** - * Set of unshielded noncolliders from the triple orientation step. - */ - private Set noncolliderTriples; - - /** - * Set of ambiguous unshielded triples. - */ - private Set ambiguousTriples; - - /** - * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large - * graphs). - */ - private boolean aggressivelyPreventCycles; - - //=============================CONSTRUCTORS==========================// - - /** - * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the - * independence test, for fear of duplicating the data set! - */ - public TimeSeriesLagSearch(IndependenceTest independenceTest) { - if (independenceTest == null) { - throw new NullPointerException(); - } - - this.independenceTest = independenceTest; - } - - //==============================PUBLIC METHODS========================// - - /** - * @return true just in case edges will not be added if they would create cycles. - */ - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - - /** - * Sets to true just in case edges will not be added if they would create cycles. - */ - public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { - this.aggressivelyPreventCycles = aggressivelyPreventCycles; - } - - /** - * @return the elapsed time of search in milliseconds, after search() has been run. - */ - public long getElapsedTime() { - return this.elapsedTime; - } - - /** - * @return the knowledge specification used in the search. Non-null. - */ - public Knowledge getKnowledge() { - return this.knowledge; - } - - /** - * Sets the knowledge specification used in the search. Non-null. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - - /** - * @return the independence test used in the search, set in the constructor. This is not returning a copy, for fear - * of duplicating the data set! - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - /** - * @return the depth of the search--that is, the maximum number of variables conditioned on in any conditional - * independence test. - */ - public int getDepth() { - return this.depth; - } - - /** - * @return the set of ambiguous triples found during the most recent run of the algorithm. Non-null after a call to - * search(). - */ - public Set getAmbiguousTriples() { - return new HashSet<>(this.ambiguousTriples); - } - - /** - * @return the set of collider triples found during the most recent run of the algorithm. Non-null after a call to - * search(). - */ - public Set getColliderTriples() { - return new HashSet<>(this.colliderTriples); - } - - /** - * @return the set of noncollider triples found during the most recent run of the algorithm. Non-null after a call - * to search(). - */ - public Set getNoncolliderTriples() { - return new HashSet<>(this.noncolliderTriples); - } - - /** - * @return the set of all triples found during the most recent run of the algorithm. Non-null after a call to - * search(). - */ - public Set getAllTriples() { - return new HashSet<>(this.allTriples); - } - - /** - * Runs PC starting with a fully connected graph over all of the variables in the domain of the independence test. - * See PC for caveats. The number of possible cycles and bidirected edges is far less with CPC than with PC. - */ - public Graph search() { - return search(this.independenceTest.getVariables()); - } - - /** - * Runs PC on just the given variable, all of which must be in the domain of the independence test. See PC for - * caveats. The number of possible cycles and bidirected edges is far less with CPC than with PC. - */ - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - - TetradLogger.getInstance().log("info", "Starting TimeSeriesLagSearch."); - TetradLogger.getInstance().log("info", "Independence test = " + this.independenceTest + "."); - long startTime = MillisecondTimes.timeMillis(); - this.allTriples = new HashSet<>(); - this.ambiguousTriples = new HashSet<>(); - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); - - if (getIndependenceTest() == null) { - throw new NullPointerException(); - } - - List allNodes = getIndependenceTest().getVariables(); - if (!allNodes.containsAll(nodes)) { - throw new IllegalArgumentException("All of the given nodes must " + - "be in the domain of the independence test provided."); - } - - this.graph = new EdgeListGraph(nodes); - this.graph.fullyConnect(Endpoint.TAIL); - - Fas fas = new Fas(getIndependenceTest()); - fas.setKnowledge(getKnowledge()); - fas.setDepth(0); - - // Note that we are ignoring the sepset map returned by this method - // on purpose; it is not used in this search. - fas.search(); - -// SearchGraphUtils.pcOrientbk(knowledge, graph, nodes); - orientUnshieldedTriples(this.knowledge, getIndependenceTest(), 3); - - TetradLogger.getInstance().log("graph", "\nReturning this graph: " + this.graph); - - long endTime = MillisecondTimes.timeMillis(); - this.elapsedTime = endTime - startTime; - - TetradLogger.getInstance().log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); - TetradLogger.getInstance().log("info", "Finishing CPC algorithm."); - - logTriples(); - - TetradLogger.getInstance().flush(); -// SearchGraphUtils.verifySepsetIntegrity(sepsetMap, graph); - return this.graph; - } - - /** - * Orients the given graph using CPC orientation with the conditional independence test provided in the - * constructor. - */ - public Graph orientationForGraph(Dag trueGraph) { - Graph graph = new EdgeListGraph(this.independenceTest.getVariables()); - - for (Edge edge : trueGraph.getEdges()) { - Node nodeA = edge.getNode1(); - Node nodeB = edge.getNode2(); - - Node _nodeA = this.independenceTest.getVariable(nodeA.getName()); - Node _nodeB = this.independenceTest.getVariable(nodeB.getName()); - - graph.addUndirectedEdge(_nodeA, _nodeB); - } - - SearchGraphUtils.pcOrientbk(this.knowledge, graph, graph.getNodes()); - orientUnshieldedTriples(this.knowledge, getIndependenceTest(), this.depth); - MeekRules meekRules = new MeekRules(); - meekRules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles); - meekRules.setKnowledge(this.knowledge); - meekRules.orientImplied(graph); - - return graph; - } - - //==========================PRIVATE METHODS===========================// - - private void logTriples() { - TetradLogger.getInstance().log("info", "\nCollider triples judged from sepsets:"); - - for (Triple triple : this.colliderTriples) { - TetradLogger.getInstance().log("info", "Collider: " + triple); - } - - TetradLogger.getInstance().log("info", "\nNoncollider triples judged from sepsets:"); - - for (Triple triple : this.noncolliderTriples) { - TetradLogger.getInstance().log("info", "Noncollider: " + triple); - } - - TetradLogger.getInstance().log("info", "\nAmbiguous triples judged from sepsets (i.e. list of triples for which " + - "\nthere is ambiguous data about whether they are colliders or not):"); - - for (Triple triple : getAmbiguousTriples()) { - TetradLogger.getInstance().log("info", "Ambiguous: " + triple); - } - } - - private void orientUnshieldedTriples(Knowledge knowledge, - IndependenceTest test, int depth) { - TetradLogger.getInstance().log("info", "Starting Collider Orientation:"); - -// System.out.println("orientUnshieldedTriples 1"); - - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); - this.ambiguousTriples = new HashSet<>(); - - for (Node y : this.graph.getNodes()) { -// System.out.println("orientUnshieldedTriples 2"); - - List adjacentNodes = this.graph.getAdjacentNodes(y); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { -// System.out.println("orientUnshieldedTriples 3"); - - Node x = adjacentNodes.get(combination[0]); - Node z = adjacentNodes.get(combination[1]); - - if (this.graph.isAdjacentTo(x, z)) { - continue; - } - - getAllTriples().add(new Triple(x, y, z)); - -// System.out.println("orientUnshieldedTriples 4"); - - SearchGraphUtils.CpcTripleType type = SearchGraphUtils.getCpcTripleType(x, y, z, test, depth, graph); - -// System.out.println("orientUnshieldedTriples 5"); - - if (type == SearchGraphUtils.CpcTripleType.COLLIDER) { -// System.out.println("orientUnshieldedTriples 6"); - - if (this.colliderAllowed(x, y, z, knowledge)) { - graph.setEndpoint(x, y, Endpoint.ARROW); - graph.setEndpoint(z, y, Endpoint.ARROW); - - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); - } - - colliderTriples.add(new Triple(x, y, z)); - } else if (type == SearchGraphUtils.CpcTripleType.AMBIGUOUS) { -// System.out.println("orientUnshieldedTriples 7"); - - Triple triple = new Triple(x, y, z); - this.ambiguousTriples.add(triple); - this.graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); - } else { -// System.out.println("orientUnshieldedTriples 8"); - - this.noncolliderTriples.add(new Triple(x, y, z)); - } - } - } - - TetradLogger.getInstance().log("info", "Finishing Collider Orientation."); - } - - private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return TimeSeriesLagSearch.isArrowpointAllowed1(x, y, knowledge) && - TimeSeriesLagSearch.isArrowpointAllowed1(z, y, knowledge); - } - - private static boolean isArrowpointAllowed1(Node from, Node to, - Knowledge knowledge) { - return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } -} - - From b5242d3eba7fc2b5a541610ee277f8366aecfc08 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:39:37 -0400 Subject: [PATCH 166/464] Fixing documentation etc. --- .../edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java | 4 ++-- .../edu/cmu/tetrad/algcomparison/score/MVPBicScore.java | 4 ++-- .../main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java | 4 ++-- .../main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java | 4 ++-- .../search/{MNLRLikelihood.java => MnlrLikelihood.java} | 4 ++-- .../cmu/tetrad/search/{MNLRScore.java => MnlrScore.java} | 8 ++++---- .../search/{MVPLikelihood.java => MvpLikelihood.java} | 4 ++-- .../cmu/tetrad/search/{MVPScore.java => MvpScore.java} | 8 ++++---- 8 files changed, 20 insertions(+), 20 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{MNLRLikelihood.java => MnlrLikelihood.java} (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{MNLRScore.java => MnlrScore.java} (94%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{MVPLikelihood.java => MvpLikelihood.java} (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{MVPScore.java => MvpScore.java} (94%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java index 59999f99b3..11dfb0cd93 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.MNLRScore; +import edu.cmu.tetrad.search.MnlrScore; import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Parameters; @@ -29,7 +29,7 @@ public class MNLRBicScore implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { - return new MNLRScore(SimpleDataLoader.getMixedDataSet(dataSet), + return new MnlrScore(SimpleDataLoader.getMixedDataSet(dataSet), 1, parameters.getInt("fDegree", 1)); } 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 d6dcca4c3d..c1f7176952 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 @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.MVPScore; +import edu.cmu.tetrad.search.MvpScore; import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -30,7 +30,7 @@ public class MVPBicScore implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { - return new MVPScore(SimpleDataLoader.getMixedDataSet(dataSet), + return new MvpScore(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("structurePrior", 0), parameters.getInt("fDegree", -1), parameters.getInt("discretize", 0) > 0); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java index 0d67df0d33..db41cae15e 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java @@ -44,7 +44,7 @@ public class IndTestMNLRLRT implements IndependenceTest { private double alpha; // Likelihood function - private final MNLRLikelihood likelihood; + private final MnlrLikelihood likelihood; private boolean verbose; @@ -53,7 +53,7 @@ public class IndTestMNLRLRT implements IndependenceTest { public IndTestMNLRLRT(DataSet data, double alpha) { this.data = data; - this.likelihood = new MNLRLikelihood(data, -1, 1); + this.likelihood = new MnlrLikelihood(data, -1, 1); this.nodesHash = new HashedMap<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java index 3207684be3..0878b0f982 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java @@ -44,7 +44,7 @@ public class IndTestMVPLRT implements IndependenceTest { private double alpha; // Likelihood function - private final MVPLikelihood likelihood; + private final MvpLikelihood likelihood; private boolean verbose; @@ -53,7 +53,7 @@ public class IndTestMVPLRT implements IndependenceTest { public IndTestMVPLRT(DataSet data, double alpha, int fDegree, boolean discretize) { this.data = data; - this.likelihood = new MVPLikelihood(data, -1, fDegree, discretize); + this.likelihood = new MvpLikelihood(data, -1, fDegree, discretize); this.nodesHash = new HashedMap<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MNLRLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MNLRLikelihood.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java index 1ddf3f8754..fa917354a7 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MNLRLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java @@ -45,7 +45,7 @@ */ -public class MNLRLikelihood { +public class MnlrLikelihood { private final DataSet dataSet; @@ -78,7 +78,7 @@ public void write(int b) { } }); - public MNLRLikelihood(DataSet dataSet, double structurePrior, int fDegree) { + public MnlrLikelihood(DataSet dataSet, double structurePrior, int fDegree) { if (dataSet == null) { throw new NullPointerException(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MNLRScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrScore.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MNLRScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrScore.java index d55d3fdaa5..ccbaafd595 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MNLRScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrScore.java @@ -32,7 +32,7 @@ * * @author Bryan Andrews */ -public class MNLRScore implements Score { +public class MnlrScore implements Score { private final DataSet dataSet; @@ -40,12 +40,12 @@ public class MNLRScore implements Score { private final List variables; // Likelihood function - private final MNLRLikelihood likelihood; + private final MnlrLikelihood likelihood; // Log number of instances private final double logn; - public MNLRScore(DataSet dataSet, double structurePrior, int fDegree) { + public MnlrScore(DataSet dataSet, double structurePrior, int fDegree) { if (dataSet == null) { throw new NullPointerException(); @@ -53,7 +53,7 @@ public MNLRScore(DataSet dataSet, double structurePrior, int fDegree) { this.dataSet = dataSet; this.variables = dataSet.getVariables(); - this.likelihood = new MNLRLikelihood(dataSet, structurePrior, fDegree); + this.likelihood = new MnlrLikelihood(dataSet, structurePrior, fDegree); this.logn = FastMath.log(dataSet.getNumRows()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MVPLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MVPLikelihood.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java index 441750fc98..ee6e98bd58 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MVPLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java @@ -41,7 +41,7 @@ * * @author Bryan Andrews */ -public class MVPLikelihood { +public class MvpLikelihood { private final DataSet dataSet; @@ -72,7 +72,7 @@ public class MVPLikelihood { // Discretize private final boolean discretize; - public MVPLikelihood(DataSet dataSet, double structurePrior, int fDegree, boolean discretize) { + public MvpLikelihood(DataSet dataSet, double structurePrior, int fDegree, boolean discretize) { if (dataSet == null) { throw new NullPointerException(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MVPScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpScore.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MVPScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpScore.java index 36a1d42e8d..4dcba2fcaf 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MVPScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpScore.java @@ -32,7 +32,7 @@ * * @author Bryan Andrews */ -public class MVPScore implements Score { +public class MvpScore implements Score { private final DataSet dataSet; @@ -40,12 +40,12 @@ public class MVPScore implements Score { private final List variables; // Likelihood function - private final MVPLikelihood likelihood; + private final MvpLikelihood likelihood; // Log number of instances private final double logn; - public MVPScore(DataSet dataSet, double structurePrior, int fDegree, boolean discretize) { + public MvpScore(DataSet dataSet, double structurePrior, int fDegree, boolean discretize) { if (dataSet == null) { throw new NullPointerException(); @@ -53,7 +53,7 @@ public MVPScore(DataSet dataSet, double structurePrior, int fDegree, boolean dis this.dataSet = dataSet; this.variables = dataSet.getVariables(); - this.likelihood = new MVPLikelihood(dataSet, structurePrior, fDegree, discretize); + this.likelihood = new MvpLikelihood(dataSet, structurePrior, fDegree, discretize); this.logn = FastMath.log(dataSet.getNumRows()); } From ad1ad77275e816a822e55244607df598e779ce96 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:42:44 -0400 Subject: [PATCH 167/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Fci.java | 57 ++----------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 3b3a78bfa9..5c57346e7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -48,70 +48,18 @@ * @author Choh-Man Teng */ public final class Fci implements GraphSearch { - - /** - * The SepsetMap being constructed. - */ private SepsetMap sepsets; - - /** - * The background knowledge. - */ private Knowledge knowledge = new Knowledge(); - - /** - * The variables to search over (optional) - */ private final List variables = new ArrayList<>(); - - /** - * The test to use for the search. - */ private final IndependenceTest independenceTest; - - /** - * flag for complete rule set, true if should use complete rule set, false otherwise. - */ private boolean completeRuleSetUsed = true; - - /** - * True iff the possible dsep search is done. - */ private boolean possibleDsepSearchDone = true; - - /** - * The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. - */ private int maxPathLength = -1; - - /** - * The depth for the fast adjacency search. - */ private int depth = -1; - - /** - * Elapsed time of last search. - */ private long elapsedTime; - - /** - * The logger to use. - */ private final TetradLogger logger = TetradLogger.getInstance(); - - /** - * True iff verbose output should be printed. - */ private boolean verbose; - - /** - * FAS heuristic - */ private int heuristic; - - /** - * FAS stable option. - */ private boolean stable; private boolean doDiscriminatingPathRule = true; @@ -234,7 +182,6 @@ public Graph search() { return graph; } - /** * Retrieves the sepset map from FAS. */ @@ -343,6 +290,10 @@ public void setStable(boolean stable) { this.stable = stable; } + /** + * Sets whether the discriminating path rule should be used. + * @param doDiscriminatingPathRule True if so. + */ public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { this.doDiscriminatingPathRule = doDiscriminatingPathRule; } From 7e3f3c7f8f7cc139522fb2c14462feb6f47120be Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 05:55:23 -0400 Subject: [PATCH 168/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/FciOrient.java | 374 +++++++++--------- 1 file changed, 184 insertions(+), 190 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java index 90ec871ef9..9396cb8837 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java @@ -46,38 +46,13 @@ * @author Choh-Man Teng */ public final class FciOrient { - - /** - * The SepsetMap being constructed. - */ private final SepsetProducer sepsets; - private Knowledge knowledge = new Knowledge(); - private boolean changeFlag = true; - - /** - * flag for complete rule set, true if should use complete rule set, false - * otherwise. - */ private boolean completeRuleSetUsed = true; - - /** - * The maximum length for any discriminating path. -1 if unlimited; - * otherwise, a positive integer. - */ private int maxPathLength = -1; - - /** - * The logger to use. - */ private final TetradLogger logger = TetradLogger.getInstance(); - - /** - * True iff verbose output should be printed. - */ private boolean verbose; - private Graph truePag; private boolean doDiscriminatingPathColliderRule = true; private boolean doDiscriminatingPathTailRule = true; @@ -93,10 +68,14 @@ public FciOrient(SepsetProducer sepsets) { } //========================PUBLIC METHODS==========================// - public Graph orient(Graph graph) { + /** + * Performs final FCI orientation on the given graph. + * @param graph The graph to further orient. + * @return The oriented graph. + */ + public Graph orient(Graph graph) { this.logger.forceLogMessage("Starting FCI algorithm."); - ruleR0(graph); if (this.verbose) { @@ -106,7 +85,6 @@ public Graph orient(Graph graph) { // Step CI D. (Zhang's step F4.) doFinalOrientation(graph); -// graph.closeInducingPaths(); //to make sure it's a legal PAG if (this.verbose) { this.logger.forceLogMessage("Returning graph: " + graph); } @@ -114,17 +92,18 @@ public Graph orient(Graph graph) { return graph; } + /** + * Returns the map from {x,y} to {z1,...,zn} for x _||_ y | z1,..,zn. + * @return Thia map. + */ public SepsetProducer getSepsets() { return this.sepsets; } /** - * The background knowledge. + * Sets the knowledge to use for the final orientation. + * @param knowledge This knowledge. */ - public Knowledge getKnowledge() { - return this.knowledge; - } - public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { throw new NullPointerException(); @@ -155,6 +134,7 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { * Orients colliders in the graph. (FCI Step C) *

* Zhang's step F3, rule R0. + * @param graph The graph to orient. */ public void ruleR0(Graph graph) { graph.reorientAllWith(Endpoint.CIRCLE); @@ -214,11 +194,6 @@ public void ruleR0(Graph graph) { } } - private void printWrongColliderMessage(Node a, Node b, Node c, Graph graph) { - if (this.truePag != null && graph.isDefCollider(a, b, c) && !this.truePag.isDefCollider(a, b, c)) { - logger.forceLogMessage("R0" + ": Orienting collider by mistake: " + a + "*->;" + b + "<-*" + c); - } - } /** * Orients the graph according to rules in the graph (FCI step D). @@ -233,7 +208,7 @@ public void doFinalOrientation(Graph graph) { } } - private void spirtesFinalOrientation(Graph graph) { + public void spirtesFinalOrientation(Graph graph) { this.changeFlag = true; boolean firstTime = true; @@ -258,7 +233,7 @@ private void spirtesFinalOrientation(Graph graph) { } } - private void zhangFinalOrientation(Graph graph) { + public void zhangFinalOrientation(Graph graph) { this.changeFlag = true; boolean firstTime = true; @@ -337,7 +312,7 @@ public void rulesR1R2cycle(Graph graph) { /// R1, away from collider // If a*->bo-*c and a, c not adjacent then a*->b->c - private void ruleR1(Node a, Node b, Node c, Graph graph) { + public void ruleR1(Node a, Node b, Node c, Graph graph) { if (graph.isAdjacentTo(a, c)) { return; } @@ -359,7 +334,7 @@ private void ruleR1(Node a, Node b, Node c, Graph graph) { //if a*-oc and either a-->b*->c or a*->b-->c, and a*-oc then a*->c // This is Zhang's rule R2. - private void ruleR2(Node a, Node b, Node c, Graph graph) { + public void ruleR2(Node a, Node b, Node c, Graph graph) { if ((graph.isAdjacentTo(a, c)) && (graph.getEndpoint(a, c) == Endpoint.CIRCLE)) { if ((graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(b, c) == Endpoint.ARROW) && (graph.getEndpoint(b, a) == Endpoint.TAIL || graph.getEndpoint(c, b) == Endpoint.TAIL)) { @@ -557,61 +532,6 @@ public void ddpOrient(Node a, Node b, Node c, Graph graph) { } } - /** - * Orients the edges inside the definte discriminating path triangle. Takes - * the left endpoint, and a,b,c as arguments. - */ - private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Graph graph) { - if (graph.isAdjacentTo(d, c)) { - throw new IllegalArgumentException(); - } - - List sepset = getSepsets().getSepset(d, c); - - if (this.verbose) { - logger.forceLogMessage("Sepset for d = " + d + " and c = " + c + " = " + sepset); - } - - if (sepset == null) { - if (this.verbose) { - logger.forceLogMessage("Must be a sepset: " + d + " and " + c + "; they're non-adjacent."); - } - return false; - } - - if (!sepset.contains(b) && doDiscriminatingPathColliderRule) { - if (!isArrowpointAllowed(a, b, graph, knowledge)) { - return false; - } - - if (!isArrowpointAllowed(c, b, graph, knowledge)) { - return false; - } - - graph.setEndpoint(a, b, Endpoint.ARROW); - graph.setEndpoint(c, b, Endpoint.ARROW); - - if (this.verbose) { - this.logger.forceLogMessage( - "R4: Definite discriminating path collider rule d = " + d + " " + GraphUtils.pathString(graph, a, b, c)); - } - - this.changeFlag = true; - } else if (doDiscriminatingPathTailRule) { - graph.setEndpoint(c, b, Endpoint.TAIL); - - if (this.verbose) { - this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg( - "R4: Definite discriminating path tail rule d = " + d, graph.getEdge(b, c))); - } - - this.changeFlag = true; - return true; - } - - return false; - } - /** * Implements Zhang's rule R5, orient circle undirectedPaths: for any Ao-oB, * if there is an uncovered circle path u = @@ -779,9 +699,64 @@ public void rulesR8R9R10(Graph graph) { } } } + } + + /** + * Orients the edges inside the definte discriminating path triangle. Takes + * the left endpoint, and a,b,c as arguments. + */ + public boolean doDdpOrientation(Node d, Node a, Node b, Node c, Graph graph) { + if (graph.isAdjacentTo(d, c)) { + throw new IllegalArgumentException(); + } + + List sepset = getSepsets().getSepset(d, c); + + if (this.verbose) { + logger.forceLogMessage("Sepset for d = " + d + " and c = " + c + " = " + sepset); + } + + if (sepset == null) { + if (this.verbose) { + logger.forceLogMessage("Must be a sepset: " + d + " and " + c + "; they're non-adjacent."); + } + return false; + } + + if (!sepset.contains(b) && doDiscriminatingPathColliderRule) { + if (!isArrowpointAllowed(a, b, graph, knowledge)) { + return false; + } + + if (!isArrowpointAllowed(c, b, graph, knowledge)) { + return false; + } + + graph.setEndpoint(a, b, Endpoint.ARROW); + graph.setEndpoint(c, b, Endpoint.ARROW); + if (this.verbose) { + this.logger.forceLogMessage( + "R4: Definite discriminating path collider rule d = " + d + " " + GraphUtils.pathString(graph, a, b, c)); + } + + this.changeFlag = true; + } else if (doDiscriminatingPathTailRule) { + graph.setEndpoint(c, b, Endpoint.TAIL); + + if (this.verbose) { + this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg( + "R4: Definite discriminating path tail rule d = " + d, graph.getEdge(b, c))); + } + + this.changeFlag = true; + return true; + } + + return false; } + /** * Orients every edge on a path as undirected (i.e. A---B). *

@@ -926,9 +901,9 @@ private List> getUcCirclePaths(Node n1, Node n2, Graph graph) { * * @param a The node A. * @param c The node C. - * @return Whether or not R8 was successfully applied. + * @return Whether R8 was successfully applied. */ - private boolean ruleR8(Node a, Node c, Graph graph) { + public boolean ruleR8(Node a, Node c, Graph graph) { List intoCArrows = graph.getNodesInTo(c, Endpoint.ARROW); for (Node b : intoCArrows) { @@ -980,7 +955,7 @@ private boolean ruleR8(Node a, Node c, Graph graph) { * @param c The node C. * @return Whether R9 was succesfully applied. */ - private boolean ruleR9(Node a, Node c, Graph graph) { + public boolean ruleR9(Node a, Node c, Graph graph) { Edge e = graph.getEdge(a, c); if (e == null) return false; @@ -1012,88 +987,6 @@ private boolean ruleR9(Node a, Node c, Graph graph) { return false; } - /** - * Tries to apply Zhang's rule R10 to a pair of nodes A and C which are - * assumed to be such that Ao->C. - *

- * MAY HAVE WEIRD EFFECTS ON ARBITRARY NODE PAIRS. - *

- * R10: If Ao->C, B-->C<--D, there is an uncovered p.d. path u1= - * and an uncovered p.d. path u2= - * with M != N and M,N nonadjacent then A-->C. - * - * @param a The node A. - * @param c The node C. - */ - private void ruleR10(Node a, Node c, Graph graph) { - List intoCArrows = graph.getNodesInTo(c, Endpoint.ARROW); - - for (Node b : intoCArrows) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (b == a) { - continue; - } - - if (!(graph.getEndpoint(c, b) == Endpoint.TAIL)) { - continue; - } - // We know Ao->C and B-->C. - - for (Node d : intoCArrows) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (d == a || d == b) { - continue; - } - - if (!(graph.getEndpoint(d, c) == Endpoint.TAIL)) { - continue; - } - // We know Ao->C and B-->C<--D. - - List> ucPdPsToB = getUcPdPaths(a, b, graph); - List> ucPdPsToD = getUcPdPaths(a, d, graph); - for (List u1 : ucPdPsToB) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node m = u1.get(1); - for (List u2 : ucPdPsToD) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node n = u2.get(1); - - if (m.equals(n)) { - continue; - } - if (graph.isAdjacentTo(m, n)) { - continue; - } - // We know B,D,u1,u2 as required: R10 applies! - - graph.setEndpoint(c, a, Endpoint.TAIL); - - if (verbose) { - this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("R10: ", graph.getEdge(c, a))); - } - - this.changeFlag = true; - return; - } - } - } - } - - } - /** * Orients according to background knowledge */ @@ -1202,16 +1095,17 @@ public void setMaxPathLength(int maxPathLength) { } /** - * True iff verbose output should be printed. + * Sets whether verbose output is printed. + * @param verbose True if so. */ - public boolean isVerbose() { - return this.verbose; - } - public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Sets the true PAG for comparison. + * @param truePag This PAG. + */ public void setTruePag(Graph truePag) { this.truePag = truePag; } @@ -1223,23 +1117,123 @@ public Graph getTruePag() { return this.truePag; } + /** + * Sets the change flag--marks externally that a change has been made. + * @param changeFlag This flag. + */ public void setChangeFlag(boolean changeFlag) { this.changeFlag = changeFlag; } /** - * change flag for repeat rules + * Change flag for repeat rules + * @return True if a change has occurred. */ public boolean isChangeFlag() { return this.changeFlag; } - public void setDoDiscriminatingPathColliderRule(boolean skip) { - this.doDiscriminatingPathColliderRule = skip; + /** + * Sets whether the discriminating path collider rule should be done. + * @param doDiscriminatingPathColliderRule True is done. + */ + public void setDoDiscriminatingPathColliderRule(boolean doDiscriminatingPathColliderRule) { + this.doDiscriminatingPathColliderRule = doDiscriminatingPathColliderRule; } + /** + * Sets whether the discriminating path tail rule should be done. + * @param doDiscriminatingPathTailRule True if done. + */ public void setDoDiscriminatingPathTailRule(boolean doDiscriminatingPathTailRule) { this.doDiscriminatingPathTailRule = doDiscriminatingPathTailRule; } + /** + * Tries to apply Zhang's rule R10 to a pair of nodes A and C which are + * assumed to be such that Ao->C. + *

+ * MAY HAVE WEIRD EFFECTS ON ARBITRARY NODE PAIRS. + *

+ * R10: If Ao->C, B-->C<--D, there is an uncovered p.d. path u1= + * and an uncovered p.d. path u2= + * with M != N and M,N nonadjacent then A-->C. + * + * @param a The node A. + * @param c The node C. + */ + public void ruleR10(Node a, Node c, Graph graph) { + List intoCArrows = graph.getNodesInTo(c, Endpoint.ARROW); + + for (Node b : intoCArrows) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + if (b == a) { + continue; + } + + if (!(graph.getEndpoint(c, b) == Endpoint.TAIL)) { + continue; + } + // We know Ao->C and B-->C. + + for (Node d : intoCArrows) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + if (d == a || d == b) { + continue; + } + + if (!(graph.getEndpoint(d, c) == Endpoint.TAIL)) { + continue; + } + // We know Ao->C and B-->C<--D. + + List> ucPdPsToB = getUcPdPaths(a, b, graph); + List> ucPdPsToD = getUcPdPaths(a, d, graph); + for (List u1 : ucPdPsToB) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node m = u1.get(1); + for (List u2 : ucPdPsToD) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node n = u2.get(1); + + if (m.equals(n)) { + continue; + } + if (graph.isAdjacentTo(m, n)) { + continue; + } + // We know B,D,u1,u2 as required: R10 applies! + + graph.setEndpoint(c, a, Endpoint.TAIL); + + if (verbose) { + this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("R10: ", graph.getEdge(c, a))); + } + + this.changeFlag = true; + return; + } + } + } + } + + } + + private void printWrongColliderMessage(Node a, Node b, Node c, Graph graph) { + if (this.truePag != null && graph.isDefCollider(a, b, c) && !this.truePag.isDefCollider(a, b, c)) { + logger.forceLogMessage("R0" + ": Orienting collider by mistake: " + a + "*->;" + b + "<-*" + c); + } + } } From 9de71530ad584086b3e2e4b14323b328bc5ec5ea Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:09:09 -0400 Subject: [PATCH 169/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Fas.java | 57 +---- .../cmu/tetrad/search/FasDeterministic.java | 10 - .../java/edu/cmu/tetrad/search/FasFdr.java | 204 +++++++----------- .../java/edu/cmu/tetrad/search/Fasts.java | 10 - .../main/java/edu/cmu/tetrad/search/IFas.java | 10 - 5 files changed, 79 insertions(+), 212 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index 7d703e288d..d9cdde4132 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -65,9 +65,6 @@ public class Fas implements IFas { * be taken to be the maximum value, which is 1000. Otherwise, it should be set to a non-negative integer. */ private int depth = 1000; - /** - * The number of independence tests. - */ private int numIndependenceTests; /** @@ -245,6 +242,8 @@ public void setKnowledge(Knowledge knowledge) { } /** + * The number of independence tests. + */ /** * Returns the nubmer of independence tests that were done. * * @return This number. @@ -263,17 +262,6 @@ public SepsetMap getSepsets() { return this.sepset; } - /** - * Returns the depth of the search, which is the maximum number of conditioning variables allowed - * for any conditional independence test. - * - * @return This maximum. - */ - @Override - public int getDepth() { - return depth; - } - /** * Sets whether verbose output should be printed. * @@ -283,37 +271,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * There are no cycles in this undirected result graph. - * - * @return False. - */ - @Override - public boolean isAggressivelyPreventCycles() { - return false; - } - - /** - * Returns the independence test being used to do the search. - * - * @return This test - */ - @Override - public IndependenceTest getIndependenceTest() { - return test; - } - - /** - * Returns the knowledge used in the search. - * - * @return this knowledge. - * @see Knowledge - */ - @Override - public Knowledge getKnowledge() { - return knowledge; - } - /** * Runs the search and returns the resulting (undirected) graph. * @@ -354,16 +311,6 @@ public List getAmbiguousTriples(Node node) { return new ArrayList<>(); } - /** - * Returns whether verbose output should be printed. - * - * @return True iff the case. - */ - @Override - public boolean isVerbose() { - return verbose; - } - /** * This is not used here. * @param out This print stream. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index b4022b8661..df2c022bdc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -420,16 +420,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - @Override - public boolean isAggressivelyPreventCycles() { - return false; - } - - @Override - public IndependenceTest getIndependenceTest() { - return null; - } - @Override public Graph search(List nodes) { nodes = new ArrayList<>(nodes); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasFdr.java index 58a6ea544b..71999b5261 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasFdr.java @@ -48,77 +48,33 @@ * @author Joseph Ramsey. */ public class FasFdr implements IFas { - private final Matrix cov; - private final double alpha; - /** - * The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node - * x. It is hoped (i.e. true in the large sample limit) that true adjacencies are never removed. - */ private final Graph graph; - - /** - * The independence test. This should be appropriate to the types - */ private final IndependenceTest test; - - /** - * Specification of which edges are forbidden or required. - */ private Knowledge knowledge = new Knowledge(); - - /** - * The maximum number of variables conditioned on in any conditional independence test. If the depth is -1, it will - * be taken to be the maximum value, which is 1000. Otherwise, it should be set to a non-negative integer. - */ private int depth = 1000; - - /** - * The number of independence tests. - */ private final int numIndependenceTests; - - - /** - * The logger, by default the empty logger. - */ private final TetradLogger logger = TetradLogger.getInstance(); - - /** - * The number of dependence judgements. Temporary. - */ - private final int numDependenceJudgement; - - /** - * The sepsets found during the search. - */ private SepsetMap sepset = new SepsetMap(); - - // private List pValues = new ArrayList(); - private final NumberFormat nf = new DecimalFormat("0.00E0"); - - /** - * True iff verbose output should be printed. - */ private boolean verbose; private final List pValueList = new ArrayList<>(); - private PrintStream out = System.out; //==========================CONSTRUCTORS=============================// /** * Constructs a new FastAdjacencySearch. + * @param test The independence test to use. + * @param numIndependenceTests The number of independence tests total done. */ - public FasFdr(IndependenceTest test, int numIndependenceTests, int numDependenceJudgement) { + public FasFdr(IndependenceTest test, int numIndependenceTests) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; this.alpha = test.getAlpha(); this.cov = test.getCov().getMatrix(); this.numIndependenceTests = numIndependenceTests; - this.numDependenceJudgement = numDependenceJudgement; } //==========================PUBLIC METHODS===========================// @@ -192,6 +148,80 @@ public Graph search() { return this.graph; } + /** + * Returns the nubmer of independence tests done in the course of the search. + * @return This number. + */ + public int getNumIndependenceTests() { + return this.numIndependenceTests; + } + + /** + * Returns a map for x _||_ y | z1,...,zn of {x, y} to {z1,...,zn}, + * @return This map. + */ + public SepsetMap getSepsets() { + return this.sepset; + } + + /** + * Sets whether verbose output will be printed. + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * @throws UnsupportedOperationException This method is not used. + */ + @Override + public Graph search(List nodes) { + throw new UnsupportedOperationException("Method not used."); + } + + @Override + public long getElapsedTime() { + return 0; + } + + @Override + public List getNodes() { + return null; + } + + @Override + public List getAmbiguousTriples(Node node) { + return null; + } + + @Override + public void setOut(PrintStream out) { + this.out = out; + } + + /** + * Sets the depth of the search--i.e., the maximum number of variables conditioned on for any + * conditional independence test. + * @param depth This maximum. + */ + public void setDepth(int depth) { + if (depth < -1) { + throw new IllegalArgumentException( + "Depth must be -1 (unlimited) or >= 0."); + } + + this.depth = depth; + } + + /** + * Sets the knowledge to be used in the search. + * @param knowledge This knowledge. + */ + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge((Knowledge) knowledge); + } + private Map> emptyGraph(List nodes) { Map> adjacencies = new HashMap<>(); @@ -221,7 +251,6 @@ private void searchiCovAll(List nodes, IndependenceTest test, Map> copy(Map> adjacencies) { Map> copy = new HashMap<>(); @@ -232,29 +261,6 @@ private Map> copy(Map> adjacencies) { return copy; } - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0."); - } - - this.depth = depth; - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - //==============================PRIVATE METHODS======================/ - private boolean searchICov(List nodes, IndependenceTest test, Map> adjacencies, boolean addDependencies) { if (nodes.size() < 2) return false; @@ -436,62 +442,6 @@ private List possibleParents(Node x, List adjx, private boolean possibleParentOf(String z, String x, Knowledge knowledge) { return !knowledge.isForbidden(z, x) && !knowledge.isRequired(x, z); } - - public int getNumIndependenceTests() { - return this.numIndependenceTests; - } - - public int getNumDependenceJudgments() { - return this.numDependenceJudgement; - } - - public SepsetMap getSepsets() { - return this.sepset; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public boolean isAggressivelyPreventCycles() { - return false; - } - - @Override - public IndependenceTest getIndependenceTest() { - return null; - } - - @Override - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - return null; - } - - @Override - public long getElapsedTime() { - return 0; - } - - @Override - public List getNodes() { - return null; - } - - @Override - public List getAmbiguousTriples(Node node) { - return null; - } - - @Override - public void setOut(PrintStream out) { - this.out = out; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java index 1db4f814a5..868601a4d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java @@ -757,16 +757,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - @Override - public boolean isAggressivelyPreventCycles() { - return false; - } - - @Override - public IndependenceTest getIndependenceTest() { - return null; - } - @Override public Graph search(List nodes) { nodes = new ArrayList<>(nodes); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java index 0cb2c00369..01b02d90cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java @@ -33,18 +33,10 @@ * An interface for fast adjacency searches (i.e. PC adjacency searches). */ public interface IFas { - boolean isAggressivelyPreventCycles(); - - IndependenceTest getIndependenceTest(); - - Knowledge getKnowledge(); - void setKnowledge(Knowledge knowledge); SepsetMap getSepsets(); - int getDepth(); - void setDepth(int depth); Graph search(); @@ -59,8 +51,6 @@ public interface IFas { List getAmbiguousTriples(Node node); - boolean isVerbose(); - void setVerbose(boolean verbose); void setOut(PrintStream out); From 65780597394c363a45cb0caecde087bf11e360f1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:13:48 -0400 Subject: [PATCH 170/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/Fasts.java | 138 +++++------------- 1 file changed, 36 insertions(+), 102 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java index 868601a4d8..8e875816d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java @@ -77,7 +77,6 @@ public class Fasts implements IFas { */ private int numIndependenceTests; - /** * The logger, by default the empty logger. */ @@ -129,6 +128,9 @@ public Fasts(Graph graph, IndependenceTest test) { this.test = test; } + /** + * Constructs a new FastAdjacencySearch. + */ public Fasts(IndependenceTest test) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; @@ -149,10 +151,7 @@ public Fasts(IndependenceTest test) { public Graph search() { this.logger.log("info", "Starting Fast Adjacency Search."); this.graph.removeEdges(this.graph.getEdges()); - this.sepset = new SepsetMap(); -// sepset.setReturnEmptyIfNotSet(true); - int _depth = this.depth; if (_depth == -1) { @@ -196,43 +195,6 @@ public Graph search() { return this.graph; } - public Map> searchMapOnly() { - this.logger.log("info", "Starting Fast Adjacency Search."); - this.graph.removeEdges(this.graph.getEdges()); - - this.sepset = new SepsetMap(); - - int _depth = this.depth; - - if (_depth == -1) { - _depth = 1000; - } - - - Map> adjacencies = new HashMap<>(); - List nodes = this.graph.getNodes(); - - for (Node node : nodes) { - adjacencies.put(node, new TreeSet<>()); - } - - for (int d = 0; d <= _depth; d++) { - boolean more; - - if (d == 0) { - more = searchAtDepth0(nodes, this.test, adjacencies); - } else { - more = searchAtDepth(nodes, this.test, adjacencies, d); - } - - if (!more) { - break; - } - } - - return adjacencies; - } - public int getDepth() { return this.depth; } @@ -277,8 +239,8 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map itx1 = simListX.iterator(); + Iterator ity1 = simListY.iterator(); while (itx1.hasNext() && ity1.hasNext()) { Node x1 = (Node) itx1.next(); Node y1 = (Node) ity1.next(); @@ -335,11 +297,11 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map y1List = simList.get(1); simListX.addAll(x1List); simListY.addAll(y1List); - Iterator itx = x1List.iterator(); - Iterator ity = y1List.iterator(); + Iterator itx = x1List.iterator(); + Iterator ity = y1List.iterator(); while (itx.hasNext() && ity.hasNext()) { - Node x1 = (Node) itx.next(); - Node y1 = (Node) ity.next(); + Node x1 = itx.next(); + Node y1 = ity.next(); System.out.println("$$$$$$$$$$$ found similar pair x,y = " + x1 + ", " + y1); getSepsets().set(x1, y1, empty); } @@ -364,11 +326,11 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map y1List = simList.get(1); simListX.addAll(x1List); simListY.addAll(y1List); - Iterator itx = x1List.iterator(); - Iterator ity = y1List.iterator(); + Iterator itx = x1List.iterator(); + Iterator ity = y1List.iterator(); while (itx.hasNext() && ity.hasNext()) { - Node x1 = (Node) itx.next(); - Node y1 = (Node) ity.next(); + Node x1 = itx.next(); + Node y1 = ity.next(); System.out.println("$$$$$$$$$$$ similar pair x,y = " + x1 + ", " + y1); System.out.println("adding edge between x = " + x1 + " and y = " + y1); adjacencies.get(x1).add(y1); @@ -521,10 +483,8 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe int tier_diff = FastMath.max(indx_tier, indy_tier) - FastMath.min(indx_tier, indy_tier); int indx_comp = -1; int indy_comp = -1; - List tier_x = this.knowledge.getTier(indx_tier); -// Collections.sort(tier_x); - List tier_y = this.knowledge.getTier(indy_tier); -// Collections.sort(tier_y); + List tier_x = this.knowledge.getTier(indx_tier); + List tier_y = this.knowledge.getTier(indy_tier); int i; for (i = 0; i < tier_x.size(); ++i) { @@ -551,10 +511,8 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe String B; Node y1; if (indx_tier >= indy_tier) { - List tmp_tier1 = this.knowledge.getTier(i + tier_diff); -// Collections.sort(tmp_tier1); - List tmp_tier2 = this.knowledge.getTier(i); -// Collections.sort(tmp_tier2); + List tmp_tier1 = this.knowledge.getTier(i + tier_diff); + List tmp_tier2 = this.knowledge.getTier(i); A = (String) tmp_tier1.get(indx_comp); B = (String) tmp_tier2.get(indy_comp); if (A.equals(B)) continue; @@ -568,8 +526,7 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe List condSetAB = new ArrayList<>(); for (Node tempNode : condSet) { int ind_temptier = this.knowledge.isInWhichTier(tempNode); - List temptier = this.knowledge.getTier(ind_temptier); -// Collections.sort(temptier); + List temptier = this.knowledge.getTier(ind_temptier); int ind_temp = -1; for (int j = 0; j < temptier.size(); ++j) { if (getNameNoLag(tempNode.getName()).equals(getNameNoLag(temptier.get(j)))) { @@ -586,8 +543,7 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe + "of window, so not added to SepSet"); continue; } - List new_tier = this.knowledge.getTier(condAB_tier); -// Collections.sort(new_tier); + List new_tier = this.knowledge.getTier(condAB_tier); String tempNode1 = (String) new_tier.get(ind_temp); System.out.println("adding variable " + tempNode1 + " to SepSet"); condSetAB.add(test.getVariable(tempNode1)); @@ -595,12 +551,10 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe System.out.println("done"); getSepsets().set(x1, y1, condSetAB); } else { - List tmp_tier1 = this.knowledge.getTier(i); -// Collections.sort(tmp_tier1); - List tmp_tier2 = this.knowledge.getTier(i + tier_diff); -// Collections.sort(tmp_tier2); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + List tmp_tier1 = this.knowledge.getTier(i); + List tmp_tier2 = this.knowledge.getTier(i + tier_diff); + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp))) continue; if (B.equals(tier_x.get(indx_comp)) && A.equals(tier_y.get(indy_comp))) continue; @@ -612,8 +566,7 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe List condSetAB = new ArrayList<>(); for (Node tempNode : condSet) { int ind_temptier = this.knowledge.isInWhichTier(tempNode); - List temptier = this.knowledge.getTier(ind_temptier); -// Collections.sort(temptier); + List temptier = this.knowledge.getTier(ind_temptier); int ind_temp = -1; for (int j = 0; j < temptier.size(); ++j) { if (getNameNoLag(tempNode.getName()).equals(getNameNoLag(temptier.get(j)))) { @@ -630,9 +583,8 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe + "of window, so not added to SepSet"); continue; } - List new_tier = this.knowledge.getTier(condAB_tier); -// Collections.sort(new_tier); - String tempNode1 = (String) new_tier.get(ind_temp); + List new_tier = this.knowledge.getTier(condAB_tier); + String tempNode1 = new_tier.get(ind_temp); System.out.println("adding variable " + tempNode1 + " to SepSet"); condSetAB.add(test.getVariable(tempNode1)); } @@ -655,10 +607,8 @@ private List> returnSimilarPairs(IndependenceTest test, Node x, Node int tier_diff = FastMath.max(indx_tier, indy_tier) - FastMath.min(indx_tier, indy_tier); int indx_comp = -1; int indy_comp = -1; - List tier_x = this.knowledge.getTier(indx_tier); -// Collections.sort(tier_x); - List tier_y = this.knowledge.getTier(indy_tier); -// Collections.sort(tier_y); + List tier_x = this.knowledge.getTier(indx_tier); + List tier_y = this.knowledge.getTier(indy_tier); int i; for (i = 0; i < tier_x.size(); ++i) { @@ -691,19 +641,15 @@ private List> returnSimilarPairs(IndependenceTest test, Node x, Node String B; Node y1; if (indx_tier >= indy_tier) { - List tmp_tier1 = this.knowledge.getTier(i + tier_diff); -// Collections.sort(tmp_tier1); - List tmp_tier2 = this.knowledge.getTier(i); -// Collections.sort(tmp_tier2); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + List tmp_tier1 = this.knowledge.getTier(i + tier_diff); + List tmp_tier2 = this.knowledge.getTier(i); + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); } else { - List tmp_tier1 = this.knowledge.getTier(i); -// Collections.sort(tmp_tier1); - List tmp_tier2 = this.knowledge.getTier(i + tier_diff); -// Collections.sort(tmp_tier2); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + List tmp_tier1 = this.knowledge.getTier(i); + List tmp_tier2 = this.knowledge.getTier(i + tier_diff); + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); } if (A.equals(B)) continue; if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp))) continue; @@ -733,14 +679,6 @@ public int getNumIndependenceTests() { return this.numIndependenceTests; } - public int getNumFalseDependenceJudgments() { - return this.numFalseDependenceJudgments; - } - - public int getNumDependenceJudgments() { - return this.numDependenceJudgement; - } - public SepsetMap getSepsets() { return this.sepset; } @@ -749,10 +687,6 @@ public void setExternalGraph(Graph externalGraph) { this.externalGraph = externalGraph; } - public boolean isVerbose() { - return this.verbose; - } - public void setVerbose(boolean verbose) { this.verbose = verbose; } From 2b4ba572e7e3a01b8be6b9bad19f7d0adddf6d54 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:23:14 -0400 Subject: [PATCH 171/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/Fasts.java | 183 +++++++++--------- 1 file changed, 93 insertions(+), 90 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java index 8e875816d0..f236dd5035 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java @@ -40,13 +40,13 @@ * the maximum depth or else the first such depth at which no edges can be removed. The interpretation of this adjacency * search is different for different algorithm, depending on the assumptions of the algorithm. A mapping from {x, y} to * S({x, y}) is returned for edges x *-* y that have been removed. - * - * @author Joseph Ramsey. - *

*

* This is a copy of Fas.java for the SvarFCI algorithm. The main difference is that if an edge is removed, it will also * remove all homologous edges to preserve the time-repeating structure assumed by SvarFCI. Based on (but not identicial * to) code by Entner and Hoyer for their 2010 paper. Modified by DMalinsky 4/21/2016. + * + * @author Joseph Ramsey. + * @author DMalinsky */ public class Fasts implements IFas { @@ -82,16 +82,6 @@ public class Fasts implements IFas { */ private final TetradLogger logger = TetradLogger.getInstance(); - /** - * The number of false dependence judgements, judged from the true graph using d-separation. Temporary. - */ - private int numFalseDependenceJudgments; - - /** - * The number of dependence judgements. Temporary. - */ - private int numDependenceJudgement; - private int numIndependenceJudgements; /** @@ -99,11 +89,6 @@ public class Fasts implements IFas { */ private SepsetMap sepset = new SepsetMap(); - /** - * True if this is being run by FCI--need to skip the knowledge forbid step. - */ - private final boolean fci = false; - /** * The depth 0 graph, specified initially. */ @@ -118,8 +103,6 @@ public class Fasts implements IFas { private PrintStream out = System.out; - //==========================CONSTRUCTORS=============================// - /** * Constructs a new FastAdjacencySearch. */ @@ -136,8 +119,6 @@ public Fasts(IndependenceTest test) { this.test = test; } - //==========================PUBLIC METHODS===========================// - /** * Discovers all adjacencies in data. The procedure is to remove edges in the graph which connect pairs of * variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are @@ -195,10 +176,11 @@ public Graph search() { return this.graph; } - public int getDepth() { - return this.depth; - } - + /** + * Sets the depth--i.e., the maximum number of variables conditioned on in any + * test, -1 for unlimited. + * @param depth This depth. + */ public void setDepth(int depth) { if (depth < -1) { throw new IllegalArgumentException( @@ -208,15 +190,88 @@ public void setDepth(int depth) { this.depth = depth; } - public Knowledge getKnowledge() { - return this.knowledge; + /** + * Sets the knowledge used in the search. + * @param knowledge This knowledge. + */ + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge(knowledge); } - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + /** + * Returns the number of independence tests. + * @return This number. + */ + public int getNumIndependenceTests() { + return this.numIndependenceTests; + } + + /** + * Returns a map for x _||_ y | Z from {x, y} to Z. + * @return This map. + */ + public SepsetMap getSepsets() { + return this.sepset; + } + + /** + * Sets an external graph. + * @param externalGraph This grpah. + */ + public void setExternalGraph(Graph externalGraph) { + this.externalGraph = externalGraph; + } + + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * @throws UnsupportedOperationException This method is not used. + */ + @Override + public Graph search(List nodes) { + throw new UnsupportedOperationException("This method is not used."); + } + + /** + * @throws UnsupportedOperationException This method is not used. + */ + @Override + public long getElapsedTime() { + throw new UnsupportedOperationException("This method is not used."); + } + + /** + * Returns the nodes of the test. + * @return This list. + */ + @Override + public List getNodes() { + return this.test.getVariables(); + } + + /** + * @throws UnsupportedOperationException This method is not used. + */ + @Override + public List getAmbiguousTriples(Node node) { + throw new UnsupportedOperationException("This method is not used."); } - //==============================PRIVATE METHODS======================/ + /** + * Sets the output stream for printing, default is System.out. + * @param out The print stream. + * @see PrintStream + */ + @Override + public void setOut(PrintStream out) { + this.out = out; + } private boolean searchAtDepth0(List nodes, IndependenceTest test, Map> adjacencies) { List empty = Collections.emptyList(); @@ -242,8 +297,8 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map itx1 = simListX.iterator(); Iterator ity1 = simListY.iterator(); while (itx1.hasNext() && ity1.hasNext()) { - Node x1 = (Node) itx1.next(); - Node y1 = (Node) ity1.next(); + Node x1 = itx1.next(); + Node y1 = ity1.next(); String simX = x1.getName(); String simY = y1.getName(); if ((Objects.equals(xName, simX) && Objects.equals(yName, simY)) || @@ -279,8 +334,6 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map nodes, IndependenceTest test, Map> adjacencies, IndependenceTe int ntiers = this.knowledge.getNumTiers(); int indx_tier = this.knowledge.isInWhichTier(x); int indy_tier = this.knowledge.isInWhichTier(y); - int max_tier = FastMath.max(indx_tier, indy_tier); int tier_diff = FastMath.max(indx_tier, indy_tier) - FastMath.min(indx_tier, indy_tier); int indx_comp = -1; int indy_comp = -1; @@ -513,8 +563,8 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe if (indx_tier >= indy_tier) { List tmp_tier1 = this.knowledge.getTier(i + tier_diff); List tmp_tier2 = this.knowledge.getTier(i); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp))) continue; if (B.equals(tier_x.get(indx_comp)) && A.equals(tier_y.get(indy_comp))) continue; @@ -544,7 +594,7 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe continue; } List new_tier = this.knowledge.getTier(condAB_tier); - String tempNode1 = (String) new_tier.get(ind_temp); + String tempNode1 = new_tier.get(ind_temp); System.out.println("adding variable " + tempNode1 + " to SepSet"); condSetAB.add(test.getVariable(tempNode1)); } @@ -594,13 +644,13 @@ private void removeSimilarPairs(Map> adjacencies, IndependenceTe } } + // returnSimilarPairs based on orientSimilarPairs in SvarFciOrient.java by Entner and Hoyer private List> returnSimilarPairs(IndependenceTest test, Node x, Node y) { System.out.println("$$$$$ Entering returnSimilarPairs method with x,y = " + x + ", " + y); if (x.getName().equals("time") || y.getName().equals("time")) { return new ArrayList<>(); } -// System.out.println("Knowledge within returnSimilar : " + knowledge); int ntiers = this.knowledge.getNumTiers(); int indx_tier = this.knowledge.isInWhichTier(x); int indy_tier = this.knowledge.isInWhichTier(y); @@ -667,58 +717,11 @@ private List> returnSimilarPairs(IndependenceTest test, Node x, Node return (pairList); } - - public String getNameNoLag(Object obj) { + private String getNameNoLag(Object obj) { String tempS = obj.toString(); if (tempS.indexOf(':') == -1) { return tempS; } else return tempS.substring(0, tempS.indexOf(':')); } - - public int getNumIndependenceTests() { - return this.numIndependenceTests; - } - - public SepsetMap getSepsets() { - return this.sepset; - } - - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - return null; - } - - @Override - public long getElapsedTime() { - return 0; - } - - @Override - public List getNodes() { - return this.test.getVariables(); - } - - @Override - public List getAmbiguousTriples(Node node) { - return null; - } - - public int getNumIndependenceJudgements() { - return this.numIndependenceJudgements; - } - - @Override - public void setOut(PrintStream out) { - this.out = out; - } } From 0dc454947a36c62617145a94ff6f1200405b2b89 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:24:44 -0400 Subject: [PATCH 172/464] Fixing documentation etc. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java index 80c4b6fa30..5ba187c2d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java @@ -38,7 +38,7 @@ import java.util.*; /** - * Best Fit Finder using a beam search. + * Heuristic Best Significant Model Search using a beam search. *

* Improves the P value of a SEM IM by adding, removing, or reversing single edges. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java index c4bc100d26..6fd515823c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.sem.SemIm; /** - * Interface for Bff (Best Fit Finder) algorithm. See implementations. + * Interface for Bff (Heuristic Best Significant Model Search) algorithm. See implementations. */ public interface Hbsms { void setAlpha(double alpha); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java index e857db6c57..b89df476d4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java @@ -36,7 +36,7 @@ import java.util.*; /** - *

HBSMS using the GES algorithm.

+ *

Heuristic Best Significant Model Search using the GES algorithm.

*

Improves the P value of a SEM IM by adding, removing, or reversing single edges.

* * @author Joseph Ramsey From a1b4d81d5b6dbedcf0679284b983f8feb8ce5321 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:24:57 -0400 Subject: [PATCH 173/464] Fixing documentation etc. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java index b89df476d4..0eb28936ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java @@ -41,7 +41,6 @@ * * @author Joseph Ramsey */ - public final class HbsmsGes implements Hbsms { private Knowledge knowledge = new Knowledge(); private final Graph graph; From 1c1ac5c1279373e38b5bbfefbc6a069093f09758 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:28:42 -0400 Subject: [PATCH 174/464] Fixing documentation etc. --- .../cmu/tetrad/search/FciDsepLegalPairs.java | 85 ------ .../tetrad/search/FciDsepLegalPairsCfci.java | 91 ------- .../cmu/tetrad/search/PossibleDsepCfci.java | 250 ------------------ 3 files changed, 426 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairs.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairsCfci.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepCfci.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairs.java deleted file mode 100644 index 3582dcc24e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairs.java +++ /dev/null @@ -1,85 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; - -import java.util.List; - -/** - * Specifies what coefs as a legal pair of edges X---Y---Z for purposes of calculating possible d-separation sets for - * the FCI algorithm. In this case, legal initial edges are those adjacent to initial nodes, and legal pairs of edges - * are those for which either X-->Y<--Z or X is adjacent to Z--i.e. X, Y, and Z form a triangle. (It is assumed (and - * checked) that is adjacent to Y and Y is adjacent to Z.) - * - * @author Joseph Ramsey - */ -class FciDsepLegalPairs implements LegalPairs { - - /** - * Graph with respect to which graph properties are tested. - */ - private final Graph graph; - - /** - * Constructs a new legal pairs object. See class level doc. - * - * @param graph The graph with respect to which legal pairs will be tested. - */ - public FciDsepLegalPairs(Graph graph) { - if (graph == null) { - throw new NullPointerException(); - } - - this.graph = graph; - } - - /** - * @return true iff x is adjacent to y. - */ - public boolean isLegalFirstEdge(Node x, Node y) { - return this.graph.isAdjacentTo(x, y); - } - - /** - * @return true iff x-->y<--z or else x is adjacent to z. - * @throws IllegalArgumentException if x is not adjacent to y or y is not adjacent to z. - */ - public boolean isLegalPair(Node x, Node y, Node z, List c, - List d) { - if (!(this.graph.isAdjacentTo(x, y)) || !(this.graph.isAdjacentTo(y, z))) { - throw new IllegalArgumentException(); - } - - if (this.graph.isDefCollider(x, y, z)) { - return true; - } - - return this.graph.isAdjacentTo(x, z); - } -} - - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairsCfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairsCfci.java deleted file mode 100644 index d1fb20f886..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciDsepLegalPairsCfci.java +++ /dev/null @@ -1,91 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.graph.Triple; - -import java.util.List; -import java.util.Set; - -/** - * Specifies what coefs as a legal pair of edges X---Y---Z for purposes of calculating possible d-separation sets for - * the FCI algorithm. In this case, legal initial edges are those adjacent to initial nodes, and legal pairs of edges - * are those for which either X-->Y<--Z or X is adjacent to Z--i.e. X, Y, and Z form a triangle. (It is assumed (and - * checked) that is adjacent to Y and Y is adjacent to Z.) - * - * @author Joseph Ramsey - */ -class FciDsepLegalPairsCfci implements LegalPairs { - - /** - * Graph with respect to which graph properties are tested. - */ - private final Graph graph; - private final Set ambiguousTriples; - - /** - * Constructs a new legal pairs object. See class level doc. - * - * @param graph The graph with respect to which legal pairs will be tested. - */ - public FciDsepLegalPairsCfci(Graph graph, Set unfaithfulTriples) { - if (graph == null) { - throw new NullPointerException(); - } - - this.graph = graph; - this.ambiguousTriples = unfaithfulTriples; - } - - /** - * @return true iff x is adjacent to y. - */ - public boolean isLegalFirstEdge(Node x, Node y) { - return this.graph.isAdjacentTo(x, y); - } - - /** - * @return true iff x-->y<--z or else x is adjacent to z. - * @throws IllegalArgumentException if x is not adjacent to y or y is not adjacent to z. - */ - public boolean isLegalPair(Node x, Node y, Node z, List c, - List d) { - if (!(this.graph.isAdjacentTo(x, y)) || !(this.graph.isAdjacentTo(y, z))) { - throw new IllegalArgumentException(); - } - - if (this.graph.isDefCollider(x, y, z)) { - return true; - } - - if (this.ambiguousTriples.contains(new Triple(x, y, z))) { - return true; - } - - return this.graph.isAdjacentTo(x, z); - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepCfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepCfci.java deleted file mode 100644 index ec077f149e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepCfci.java +++ /dev/null @@ -1,250 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.graph.Triple; -import edu.cmu.tetrad.util.ChoiceGenerator; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * This class implements the Possible-D-Sep search step of Spirtes, et al's (1993) FCI algorithm (pp 144-145). - * Specifically, the methods in this class perform step D. of the algorithm. The algorithm implemented by this - * class is a bit broader, however, because it allows for the possibility that some pairs of variables have already been - * compared by a different algorithm. Specifically, if the prevCheck variable is provided in the - * constructor, then the algorithm pairwise checks every variable in the graph with every variable in v \ - * prevCheck (that is, the unchecked variables). This feature is used by the CIVI algorithm of Danks's - * "Efficient Inclusion of Novel Variables." - * - * @author David Danks - */ -final class PossibleDsepCfci { - - private final Graph graph; - private final IndependenceTest test; - private final List nodes; - - /** - * This sepset collects up only the sepsets discovered by this search. - */ - private final SepsetMap sepset; - private int depth = -1; - private final LegalPairs legalPairs; - - /** - * The background knowledge. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. - */ - private int maxReachablePathLength = -1; - - /** - * @param graph The GaSearchGraph on which to work - * @param test The IndependenceChecker to use as an oracle - */ - public PossibleDsepCfci(Graph graph, IndependenceTest test, - Set unfaithfulTriples) { - if (graph == null) { - throw new NullPointerException("null GaSearchGraph passed in " + - "PossibleDSepSearch constructor!"); - } - if (test == null) { - throw new NullPointerException("null IndependenceChecker passed " + - "in PossibleDSepSearch " + "constructor!"); - } - - this.graph = graph; - this.test = test; - this.nodes = new LinkedList<>(this.graph.getNodes()); - this.sepset = new SepsetMap(); - this.legalPairs = new FciDsepLegalPairsCfci(this.graph, unfaithfulTriples); - - setMaxReachablePathLength(this.maxReachablePathLength); - } - - /** - * Performs pairwise comparisons of each variable in the graph with the variables that have not already been - * checked. We get the Possible-D-Sep sets for the pair of variables, and we check to see if they are independent - * conditional on some subset of the union of Possible-D-Sep sets. This method returns the SepSet passed in the - * constructor (if any), possibly augmented by some edge removals in this step. The GaSearchGraph passed in the - * constructor is directly changed. - */ - public SepsetMap search() { - for (int i = 0; i < this.nodes.size(); i++) { - Node node1 = this.nodes.get(i); - - List adj = this.graph.getAdjacentNodes(node1); - - // Remove the variables that we've already looked at. - for (int j = 0; j < i; j++) { - adj.remove(this.nodes.get(j)); - } - - // now we need to iterate through adj - for (Node node2 : adj) { - - // now get the two Possible-D-Sep sets - boolean removed = tryRemovingUsingDsep(node1, node2, getMaxReachablePathLength()); - - if (!removed) { - tryRemovingUsingDsep(node2, node1, getMaxReachablePathLength()); - } - } - } - - return this.sepset; - } - - private boolean tryRemovingUsingDsep(Node node1, Node node2, int maxPathLength) { - List possDsep = new LinkedList<>(getPossibleDsep(node1, node2, maxPathLength)); - - boolean noEdgeRequired = - getKnowledge().noEdgeRequired(node1.getName(), node2.getName()); - - // Added this in accordance with the algorithm spec. - // jdramsey 1/8/04 - possDsep.remove(node1); - possDsep.remove(node2); - - List possibleParents = possibleParents(node1, possDsep, getKnowledge()); - int _depth = possibleParents.size(); - - if (getDepth() != -1 && _depth > getDepth()) { - _depth = getDepth(); - } - - for (int num = 1; num <= _depth; num++) { - ChoiceGenerator cg = - new ChoiceGenerator(possibleParents.size(), num); - int[] indSet; - - while ((indSet = cg.next()) != null) { - List condSet = GraphUtils.asList(indSet, possibleParents); - - boolean independent = - this.test.checkIndependence(node1, node2, condSet).independent(); - - if (independent && noEdgeRequired) { - System.out.println("*** DSEP removed " + this.graph.getEdge(node1, node2)); - this.graph.removeEdge(node1, node2); - List z = new LinkedList<>(condSet); - this.sepset.set(node1, node2, z); - return true; - } - } - } - - return false; - } - - /** - * Removes from the list of nodes any that cannot be parents of x given the background knowledge. - */ - private List possibleParents(Node x, List nodes, Knowledge knowledge) { - List possibleParents = new LinkedList<>(); - String _x = x.getName(); - - for (Node z : nodes) { - String _z = z.getName(); - - if (PossibleDsepCfci.possibleParentOf(_z, _x, knowledge)) { - possibleParents.add(z); - } - } - - return possibleParents; - } - - private static boolean possibleParentOf(String _z, String _x, Knowledge bk) { - return !(bk.isForbidden(_z, _x) || bk.isRequired(_x, _z)); - } - - /** - * A variable v is in Possible-D-Sep(A,B) iff - *
-     * 	(i) v != A & v != B
-     * 	(ii) there is an undirected path U between A and v such that for every
-     * 		 subpath  of U either:
-     * 		(a) Y is a collider on the subpath, or
-     * 		(b) X is adjacent to Z.
-     * 
- */ - private Set getPossibleDsep(Node node1, Node node2, int maxPathLength) { - List initialNodes = Collections.singletonList(node1); - - Set reachable = SearchGraphUtils.getReachableNodes(initialNodes, - this.legalPairs, null, null, this.graph, maxPathLength); - - reachable.remove(node1); - reachable.remove(node2); - -// TetradLogger.getInstance().log("details", "Possible-D-Sep(" + node1 + ", " + node2 + ") = " + reachable); - - return reachable; - } - - private int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + depth); - } - - this.depth = depth; - } - - private Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - - public int getMaxReachablePathLength() { - return this.maxReachablePathLength == Integer.MAX_VALUE ? -1 : this.maxReachablePathLength; - } - - public void setMaxReachablePathLength(int maxReachablePathLength) { - if (maxReachablePathLength < -1) { - throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxReachablePathLength); - } - - this.maxReachablePathLength = maxReachablePathLength == -1 ? Integer.MAX_VALUE : maxReachablePathLength; - } -} - - - From 56dd669c58b4e4c44333446feb694959f7a5206b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:32:29 -0400 Subject: [PATCH 175/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/BdeuScore.java | 5 +---- .../edu/cmu/tetrad/search/DiscreteBicScore.java | 5 +---- .../java/edu/cmu/tetrad/search/IBDeuScore.java | 14 -------------- 3 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/IBDeuScore.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java index b2ea304c06..3ad9805ed0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java @@ -33,7 +33,7 @@ /** * Calculates the BDeu score. */ -public class BdeuScore implements LocalDiscreteScore, IBDeuScore { +public class BdeuScore implements LocalDiscreteScore { private final int[][] data; private final int sampleSize; private final int[] numCategories; @@ -222,7 +222,6 @@ public DataSet getDataSet() { * Returns the structure prior. * @return This prior. */ - @Override public double getStructurePrior() { return this.structurePrior; } @@ -231,7 +230,6 @@ public double getStructurePrior() { * Sets the structure prior * @param structurePrior This prior. */ - @Override public void setStructurePrior(double structurePrior) { this.structurePrior = structurePrior; } @@ -240,7 +238,6 @@ public void setStructurePrior(double structurePrior) { * Returns the smaple prior. * @return This prior. */ - @Override public double getSamplePrior() { return this.samplePrior; } 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 f3a3557fe7..79ac4a1295 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 @@ -33,7 +33,7 @@ /** * Calculates the discrete BIC score. */ -public class DiscreteBicScore implements LocalDiscreteScore, IBDeuScore { +public class DiscreteBicScore implements LocalDiscreteScore { private List variables; private final int[][] data; private final int sampleSize; @@ -205,13 +205,10 @@ private static int getRowIndex(int[] dim, int[] values) { return rowIndex; } - @Override 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/IBDeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IBDeuScore.java deleted file mode 100644 index efb78b2247..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IBDeuScore.java +++ /dev/null @@ -1,14 +0,0 @@ -package edu.cmu.tetrad.search; - -/** - * Created by jdramsey on 2/21/16. - */ -public interface IBDeuScore extends Score { - double getStructurePrior(); - - double getSamplePrior(); - - void setStructurePrior(double structurePrior); - - void setSamplePrior(double samplePrior); -} From d703ff6036cf46f492a3fb9ec307231479f2d06f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:35:03 -0400 Subject: [PATCH 176/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/IndTestTrekSep.java | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java index fa6185984c..397b480f58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java @@ -42,46 +42,15 @@ * @author Adam Brodie */ public final class IndTestTrekSep implements IndependenceTest { - - /** - * The covariance matrix. - */ private final ICovarianceMatrix covMatrix; private final List latents; - private boolean verbose; - - - /** - * The variables of the covariance matrix, in order. (Unmodifiable list.) - */ private final List> clustering; - - /** - * The variables of the covariance matrix, in order. (Unmodifiable list.) - */ private List variables; - - /** - * The significance level of the independence tests. - */ private double alpha; - - /** - * The value of the Fisher's Z statistic associated with the las calculated partial correlation. - */ private double pValue; - - /** - * Formats as 0.0000. - */ private static final NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); - - /** - * Stores a reference to the dataset being analyzed. - */ private DataSet dataSet; - private final Map indexMap; private final Map nameMap; From b271c5171570f5c586896415a0c8dfa96233d606 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:36:27 -0400 Subject: [PATCH 177/464] Fixing documentation etc. --- .../edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java | 4 ++-- .../edu/cmu/tetrad/algcomparison/independence/Mvplrt.java | 4 ++-- .../tetrad/search/{IndTestMNLRLRT.java => IndTestMNlrlr.java} | 4 ++-- .../tetrad/search/{IndTestMVPLRT.java => IndTestMvplrt.java} | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IndTestMNLRLRT.java => IndTestMNlrlr.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IndTestMVPLRT.java => IndTestMvplrt.java} (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java index e845650614..8000e61981 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestMNLRLRT; +import edu.cmu.tetrad.search.IndTestMNlrlr; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; @@ -29,7 +29,7 @@ public class Mnlrlrt implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - return new IndTestMNLRLRT(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha")); + return new IndTestMNlrlr(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha")); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java index 9e36a5b612..d6178bde12 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestMVPLRT; +import edu.cmu.tetrad.search.IndTestMvplrt; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; @@ -29,7 +29,7 @@ public class Mvplrt implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - return new IndTestMVPLRT(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha"), parameters.getInt("fDegree"), parameters.getInt("discretize") > 0); + return new IndTestMvplrt(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha"), parameters.getInt("fDegree"), parameters.getInt("discretize") > 0); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java index db41cae15e..8273958e59 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNLRLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java @@ -38,7 +38,7 @@ * * @author Bryan Andrews */ -public class IndTestMNLRLRT implements IndependenceTest { +public class IndTestMNlrlr implements IndependenceTest { private final DataSet data; private final Map nodesHash; private double alpha; @@ -51,7 +51,7 @@ public class IndTestMNLRLRT implements IndependenceTest { // P Values private double pValue = Double.NaN; - public IndTestMNLRLRT(DataSet data, double alpha) { + public IndTestMNlrlr(DataSet data, double alpha) { this.data = data; this.likelihood = new MnlrLikelihood(data, -1, 1); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvplrt.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvplrt.java index 0878b0f982..1bd1d772a2 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMVPLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvplrt.java @@ -38,7 +38,7 @@ * * @author Bryan Andrews */ -public class IndTestMVPLRT implements IndependenceTest { +public class IndTestMvplrt implements IndependenceTest { private final DataSet data; private final Map nodesHash; private double alpha; @@ -51,7 +51,7 @@ public class IndTestMVPLRT implements IndependenceTest { // P Values private double pValue = Double.NaN; - public IndTestMVPLRT(DataSet data, double alpha, int fDegree, boolean discretize) { + public IndTestMvplrt(DataSet data, double alpha, int fDegree, boolean discretize) { this.data = data; this.likelihood = new MvpLikelihood(data, -1, fDegree, discretize); From 8b21b2bf4c50bf61284ee9b6c2e02367511762f1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:41:28 -0400 Subject: [PATCH 178/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/ImagesScore.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java index e5cbac663c..ecaf2851a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java @@ -176,9 +176,6 @@ public int getSampleSize() { return this.sampleSize; } - // Prints a smallest subset of parents that causes a singular matrix exception. - - @Override public int getMaxDegree() { return 1000; From 95e425a50ff2afb3ad813c582c988dd340b682d9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:43:07 -0400 Subject: [PATCH 179/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/GraphChange.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java index 461ba9d364..7af6f45ea2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java @@ -27,15 +27,12 @@ /** - * ************************************************************************************** - * + *

GraphChange is a data structure created mainly for use in the ION search algorithm. However, it models a general + * concept: storage for a variety of seperate changes one could possibly apply to a PAG.

+ *

By convention, the NodePairs in the orients ArrayList are ordered such that Node1 is the "from" node + * and Node2 is the "to" node (ie 1 o-> 2).

+* * @author Trevor Burns - *

- * GraphChange is a data structure created mainly for use in the ION search algorithm. However, it models a general - * concept: storage for a variety of seperate changes one could possibly apply to a PAG. - *

- * By convention, the NodePairs in the orients ArrayList are ordered such that Node1 is the "from" node and Node2 is the - * "to" node (ie 1 o-> 2) */ public class GraphChange { private final List removes; From 1d5de51bb7ee5ce6e878b4875d9e2a6edeb58e82 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:45:00 -0400 Subject: [PATCH 180/464] Fixing documentation etc. --- .../score/DiscreteMixedBicScore.java | 59 ------- .../cmu/tetrad/search/DiscreteMixedScore.java | 161 ------------------ 2 files changed, 220 deletions(-) delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteMixedBicScore.java delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedScore.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteMixedBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteMixedBicScore.java deleted file mode 100755 index 868467239b..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteMixedBicScore.java +++ /dev/null @@ -1,59 +0,0 @@ -package edu.cmu.tetrad.algcomparison.score; - -import edu.cmu.tetrad.annotation.Experimental; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.DiscreteMixedScore; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.util.Parameters; - -import java.util.ArrayList; -import java.util.List; - -/** - * Wrapper for Fisher Z test. - * - * @author jdramsey - */ -@Experimental -@edu.cmu.tetrad.annotation.Score( - name = "Discrete Mixed BIC Score", - command = "disc-mixed-bic-score", - dataType = DataType.Mixed -) -public class DiscreteMixedBicScore implements ScoreWrapper { - - static final long serialVersionUID = 23L; - - @Override - public Score getScore(DataModel dataSet, Parameters parameters) { - DiscreteMixedScore discreteMixedScore - = new DiscreteMixedScore(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("structurePrior")); - discreteMixedScore.setNumCategoriesToDiscretize(parameters.getInt("numCategoriesToDiscretize")); - return discreteMixedScore; - } - - @Override - public String getDescription() { - return "Discrete Mixed BIC Score"; - } - - @Override - public DataType getDataType() { - return DataType.Mixed; - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add("structurePrior"); - return parameters; - } - - @Override - public Node getVariable(String name) { - return null; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedScore.java deleted file mode 100755 index 8433e32ac7..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedScore.java +++ /dev/null @@ -1,161 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Node; -import org.apache.commons.math3.util.FastMath; - -import java.util.List; - -/** - * Implements a conditional Gaussian BIC score for FGS. - * - * @author Joseph Ramsey - */ -public class DiscreteMixedScore implements Score { - - private final DataSet dataSet; - - // The variables of the continuousData set. - private final List variables; - - // Likelihood function - private final DiscreteMixedLikelihood likelihood; - - private double penaltyDiscount = 1; - private int numCategoriesToDiscretize = 3; - private final double sp; - - /** - * Constructs the score using a covariance matrix. - */ - public DiscreteMixedScore(DataSet dataSet, double sp) { - if (dataSet == null) { - throw new NullPointerException(); - } - - this.dataSet = dataSet; - this.variables = dataSet.getVariables(); - this.sp = sp; - - this.likelihood = new DiscreteMixedLikelihood(dataSet); - } - - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model - */ - public double localScore(int i, int... parents) { - this.likelihood.setNumCategoriesToDiscretize(this.numCategoriesToDiscretize); - this.likelihood.setPenaltyDiscount(this.penaltyDiscount); - - DiscreteMixedLikelihood.Ret ret = this.likelihood.getLikelihood(i, parents); - - int N = this.dataSet.getNumRows(); - double lik = ret.getLik(); - int k = ret.getDof(); - - double strucPrior = getStructurePrior(parents); - if (strucPrior > 0) { - strucPrior = -2 * k * strucPrior; - } - - double score = 2.0 * lik - getPenaltyDiscount() * k * FastMath.log(N) + strucPrior; - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; - } - } - - private double getStructurePrior(int[] parents) { - if (this.sp < 0) { - return getEBICprior(); - } else if (this.sp == 0) { - return 0; - } else { - int i = parents.length; - int c = this.dataSet.getNumColumns() - 1; - double p = this.sp / (double) c; - return i * FastMath.log(p) + (c - i) * FastMath.log(1.0 - p); - } - } - - private double getEBICprior() { - - double n = this.dataSet.getNumColumns(); - double gamma = -this.sp; - return gamma * FastMath.log(n); - - } - - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - - - public int getSampleSize() { - return this.dataSet.getNumRows(); - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > 0; - } - - @Override - public List getVariables() { - return this.variables; - } - - - @Override - public int getMaxDegree() { - return (int) FastMath.ceil(FastMath.log(this.dataSet.getNumRows())); - } - - @Override - public boolean determines(List z, Node y) { - return false; - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { - this.numCategoriesToDiscretize = numCategoriesToDiscretize; - } -} - - - From ab7de24c02fe5c90fac8365ea0152618f294c360 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:45:38 -0400 Subject: [PATCH 181/464] Fixing documentation etc. --- .../tetrad/search/GraphWithParameters.java | 180 ------------------ 1 file changed, 180 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphWithParameters.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphWithParameters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphWithParameters.java deleted file mode 100644 index f9ac2c0a9a..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphWithParameters.java +++ /dev/null @@ -1,180 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.BoxDataSet; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DoubleDataBox; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.sem.SemEstimator; -import edu.cmu.tetrad.sem.SemIm; -import edu.cmu.tetrad.sem.SemPm; -import edu.cmu.tetrad.util.Matrix; - -import java.util.HashMap; -import java.util.List; - - -/** - * Dag plus edge weights. Later include distributions for the error terms - */ -public class GraphWithParameters { - //a Dag has a list of edges - //therefore, Hashmap from edges to weights - - private Graph graph; - - private final HashMap weightHash; - -// public Dag patDag = null; //only non-null when graph is a CPDAG - - /* - * estimate the weights for the nodes that have all parents determined. - */ - //it would have been more efficient to only regression on the nodes that matter - - public GraphWithParameters(SemIm semIm, Graph trueCPDAG) { - this(trueCPDAG); - - //make the SemIm - - //estimate the weights for the nodes that have all parents determined. - for (Node node : this.getGraph().getNodes()) { - if (GraphUtils.allAdjacenciesAreDirected(node, getGraph())) { //if we know the set of parents of 'node' - - //steal the coefficients from the SemIm - for (Edge edge : this.getGraph().getEdges(node)) { - double semImWeight = semIm.getEdgeCoef(edge); - this.getWeightHash().put(edge, semImWeight); - } - } - } - this.graph = getGraph(); - } - - public GraphWithParameters(Graph graph) { - this.graph = graph; - this.weightHash = new HashMap<>(); - } - - public void addEdge(Node node1, Node node2, double weight) { - Edge edge = new Edge(node1, node2, Endpoint.TAIL, Endpoint.ARROW); - getGraph().addEdge(edge); - getWeightHash().put(edge, weight); - } - - public void addEdge(String nodeName1, String nodeName2, double weight) { - Node node1 = getGraph().getNode(nodeName1); - Node node2 = getGraph().getNode(nodeName2); - addEdge(node1, node2, weight); - } - - - public GraphWithParameters(DataSet dataSet) { - - Matrix Bmatrix = dataSet.getDoubleData(); - - this.graph = new EdgeListGraph(); - this.weightHash = new HashMap<>(); - - int n = Bmatrix.rows(); - - //add nodes - for (int i = 0; i < n; i++) { - this.getGraph().addNode(new GraphNode(dataSet.getVariable(i).getName())); - } - - //add edges with weights - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - double value = Bmatrix.get(i, j); - if (value > 1E-15 || value < -1E-15) { - // Switched i and j in the below. --jdrmasey 10/23/08 - Node node1 = getGraph().getNode(dataSet.getVariableNames().get(i));//"X"+(j+1)); //read as the B matrix as: from column to row - Node node2 = getGraph().getNode(dataSet.getVariableNames().get(j)); - Edge edge = new Edge(node1, node2, Endpoint.TAIL, Endpoint.ARROW); - getGraph().addEdge(edge); - getWeightHash().put(edge, value); - } - } - } - } - - public String toString() { //iterate through the edges and print their weight too - StringBuilder str = new StringBuilder(); - for (Edge edge : getGraph().getEdges()) { - str.append(edge.toString()); - str.append(" ").append(getWeightHash().get(edge)).append("\n"); - } - return str.toString(); - } - - /** - * creates a CPDAGWithParameters by running a regression, given a graph and data - */ - public static GraphWithParameters regress(DataSet dataSet, Graph graph) { - SemPm semPmEstDag = new SemPm(graph); - SemEstimator estimatorEstDag = new SemEstimator(dataSet, semPmEstDag); - estimatorEstDag.estimate(); - SemIm semImEstDag = estimatorEstDag.getEstimatedSem(); - return new GraphWithParameters(semImEstDag, graph); - } - - - /** - * @return the B matrix corresponding to the graph we do the reverse of Shimizu2006Search.makeDagWithParms() - */ - //possible difference: makeDagWithParms() uses - // List variables = ltDataSet.getVariable(); - public DataSet getGraphMatrix() { - int n = this.getGraph().getNumNodes(); - Matrix matrix = new Matrix(n, n); - for (Edge edge : this.getGraph().getEdges()) { - Node node1 = edge.getNode1(); - Node node2 = edge.getNode2(); - int node1Index = getGraph().getNodes().indexOf(node1); - int node2Index = getGraph().getNodes().indexOf(node2); - double value = getWeightHash().get(edge); - matrix.set(node2Index, node1Index, value); //the B matrix is read: from column to row - } - return new BoxDataSet(new DoubleDataBox(matrix.toArray()), getGraph().getNodes()); - } - - List> cycles; - - public List> getCycles() { - //find cycles - return this.cycles; - } - - - public Graph getGraph() { - return this.graph; - } - - public HashMap getWeightHash() { - return this.weightHash; - } -} - - - From 6467e2e013c0ae8bfc0161f63b90b5a38e9d1d3f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:52:25 -0400 Subject: [PATCH 182/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/GFci.java | 35 +------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index 7db922972b..f657badb4b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -42,44 +42,17 @@ * @author jdramsey */ public final class GFci implements GraphSearch { - - // The PAG being constructed. private Graph graph; - - // The background knowledge. private Knowledge knowledge = new Knowledge(); - - // The conditional independence test. private IndependenceTest independenceTest; - - // Flag for complete rule set, true if should use complete rule set, false otherwise. private boolean completeRuleSetUsed = true; - - // The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. private int maxPathLength = -1; - - // The maxDegree for the fast adjacency search. private int maxDegree = -1; - - // The logger to use. private final TetradLogger logger = TetradLogger.getInstance(); - - // True iff verbose output should be printed. private boolean verbose; - - // The covariance matrix beign searched over. Assumes continuous data. - ICovarianceMatrix covarianceMatrix; - - // The sample size. - int sampleSize; - - // The print stream that output is directed to. + private ICovarianceMatrix covarianceMatrix; private PrintStream out = System.out; - - // True iff one-edge faithfulness is assumed. Speed up the algorith for very large searches. By default false. private boolean faithfulnessAssumed = true; - - // The score. private final Score score; private boolean doDiscriminatingPathRule = true; private boolean possibleDsepSearchDone = true; @@ -90,7 +63,6 @@ public GFci(IndependenceTest test, Score score) { if (score == null) { throw new NullPointerException(); } - this.sampleSize = score.getSampleSize(); this.score = score; this.independenceTest = test; } @@ -115,9 +87,6 @@ public Graph search() { Graph fgesGraph = new EdgeListGraph(this.graph); -// knowledge = new Knowledge(knowledge); -// addForbiddenReverseEdgesForDirectedEdges(SearchGraphUtils.cpdagForDag(graph), knowledge); - SepsetProducer sepsets = new SepsetsGreedy(this.graph, this.independenceTest, null, this.depth); gfciExtraEdgeRemovalStep(this.graph, fgesGraph, nodes, sepsets); @@ -127,8 +96,6 @@ public Graph search() { graph.paths().removeByPossibleDsep(independenceTest, null); } -// retainUnshieldedColliders(this.graph); - FciOrient fciOrient = new FciOrient(sepsets); fciOrient.setCompleteRuleSetUsed(this.completeRuleSetUsed); From 98f97043214ae5f8f4546eda4b8020b4328ab813 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 06:56:23 -0400 Subject: [PATCH 183/464] Fixing documentation etc. --- .../algcomparison/independence/DiscreteBicTest.java | 4 ++-- .../tetrad/algcomparison/score/DiscreteBicScore.java | 5 +++-- .../java/edu/cmu/tetrad/bayes/BayesProperties.java | 4 ++-- .../src/main/java/edu/cmu/tetrad/search/BdeScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/BdeuScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/FgesMb.java | 8 ++++---- .../main/java/edu/cmu/tetrad/search/FgesOrienter.java | 10 +++++----- .../{DiscreteBicScore.java => IDiscreteBicScore.java} | 6 +++--- .../{LocalDiscreteScore.java => IDiscreteScore.java} | 4 +--- .../src/main/java/edu/cmu/tetrad/search/TsFges.java | 8 ++++---- 10 files changed, 26 insertions(+), 27 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{DiscreteBicScore.java => IDiscreteBicScore.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{LocalDiscreteScore.java => IDiscreteScore.java} (97%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java index 031d51310b..903240b8a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.DiscreteBicScore; +import edu.cmu.tetrad.search.IDiscreteBicScore; import edu.cmu.tetrad.search.IndTestScore; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; @@ -31,7 +31,7 @@ public class DiscreteBicTest implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - DiscreteBicScore score = new DiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); + IDiscreteBicScore score = new IDiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); return new IndTestScore(score); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java index d055a56630..266dd0c902 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java @@ -4,6 +4,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IDiscreteBicScore; import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -29,8 +30,8 @@ public class DiscreteBicScore implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.DiscreteBicScore score - = new edu.cmu.tetrad.search.DiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); + IDiscreteBicScore score + = new IDiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); return score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java index 131410ee39..3e278feec5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.DiscreteBicScore; +import edu.cmu.tetrad.search.IDiscreteBicScore; import org.apache.commons.math3.distribution.ChiSquaredDistribution; import org.apache.commons.math3.util.FastMath; @@ -270,7 +270,7 @@ private int getDof2(Graph graph) { private Ret getLikelihoodNode(int node, int[] parents) { - DiscreteBicScore bic = new DiscreteBicScore(dataSet); + IDiscreteBicScore bic = new IDiscreteBicScore(dataSet); double lik = bic.localScore(node, parents); int dof = (numCategories[node] - 1) * parents.length; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java index db0334d3d3..6c241397e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java @@ -33,7 +33,7 @@ * * @author josephramsey */ -public class BdeScore implements LocalDiscreteScore { +public class BdeScore implements IDiscreteScore { private final DataSet dataSet; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java index 3ad9805ed0..5d9bb38b79 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java @@ -33,7 +33,7 @@ /** * Calculates the BDeu score. */ -public class BdeuScore implements LocalDiscreteScore { +public class BdeuScore implements IDiscreteScore { private final int[][] data; private final int sampleSize; private final int[] numCategories; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index 5c0ca707fc..7bc98d07bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -560,8 +560,8 @@ public void setPenaltyDiscount(double penaltyDiscount) { * @deprecated Use the setters on the individual scores instead. */ public void setSamplePrior(double samplePrior) { - if (this.fgesScore instanceof LocalDiscreteScore) { - ((LocalDiscreteScore) this.fgesScore).setSamplePrior(samplePrior); + if (this.fgesScore instanceof IDiscreteScore) { + ((IDiscreteScore) this.fgesScore).setSamplePrior(samplePrior); } } @@ -569,8 +569,8 @@ public void setSamplePrior(double samplePrior) { * @deprecated Use the setters on the individual scores instead. */ public void setStructurePrior(double expectedNumParents) { - if (this.fgesScore instanceof LocalDiscreteScore) { - ((LocalDiscreteScore) this.fgesScore).setStructurePrior(expectedNumParents); + if (this.fgesScore instanceof IDiscreteScore) { + ((IDiscreteScore) this.fgesScore).setStructurePrior(expectedNumParents); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java index a93f3b3a75..f12f2bfa02 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java @@ -108,7 +108,7 @@ public final class FgesOrienter implements GraphSearch, GraphScorer { /** * The score for discrete searches. */ - private LocalDiscreteScore discreteScore; + private IDiscreteScore IDiscreteScore; /** * The logger for this class. The config needs to be set. @@ -379,15 +379,15 @@ public int getnumCPDAGsToStore() { /** * @return the discrete scoring function being used. By default, BDeu. */ - public LocalDiscreteScore getDiscreteScore() { - return this.discreteScore; + public IDiscreteScore getDiscreteScore() { + return this.IDiscreteScore; } /** * Sets the discrete scoring function to use. */ - public void setDiscreteScore(LocalDiscreteScore discreteScore) { - this.discreteScore = discreteScore; + public void setDiscreteScore(IDiscreteScore IDiscreteScore) { + this.IDiscreteScore = IDiscreteScore; } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteBicScore.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteBicScore.java index 79ac4a1295..32a195cf56 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteBicScore.java @@ -33,7 +33,7 @@ /** * Calculates the discrete BIC score. */ -public class DiscreteBicScore implements LocalDiscreteScore { +public class IDiscreteBicScore implements IDiscreteScore { private List variables; private final int[][] data; private final int sampleSize; @@ -43,7 +43,7 @@ public class DiscreteBicScore implements LocalDiscreteScore { private final int[] numCategories; private double structurePrior = 1; - public DiscreteBicScore(DataSet dataSet) { + public IDiscreteBicScore(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException("Data was not provided."); } @@ -139,7 +139,7 @@ public double localScore(int node, int[] parents) { continue; } - int rowIndex = DiscreteBicScore.getRowIndex(dims, parentValues); + int rowIndex = IDiscreteBicScore.getRowIndex(dims, parentValues); n_jk[rowIndex][childValue]++; n_j[rowIndex]++; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LocalDiscreteScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteScore.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/LocalDiscreteScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteScore.java index ef441df081..bbac76ba4c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LocalDiscreteScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteScore.java @@ -27,11 +27,9 @@ * Created by IntelliJ IDEA. User: jdramsey Date: Jul 6, 2009 Time: 3:58:26 PM To change this template use File | * Settings | File Templates. */ -public interface LocalDiscreteScore extends Score { +public interface IDiscreteScore extends Score { void setStructurePrior(double structurePrior); - void setSamplePrior(double samplePrior); - DataSet getDataSet(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 77f9ff2698..4201bb41e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -441,8 +441,8 @@ public double getPenaltyDiscount() { * @deprecated Use the setters on the individual scores instead. */ public void setSamplePrior(double samplePrior) { - if (this.score instanceof LocalDiscreteScore) { - ((LocalDiscreteScore) this.score).setSamplePrior(samplePrior); + if (this.score instanceof IDiscreteScore) { + ((IDiscreteScore) this.score).setSamplePrior(samplePrior); } } @@ -450,8 +450,8 @@ public void setSamplePrior(double samplePrior) { * @deprecated Use the setters on the individual scores instead. */ public void setStructurePrior(double expectedNumParents) { - if (this.score instanceof LocalDiscreteScore) { - ((LocalDiscreteScore) this.score).setStructurePrior(expectedNumParents); + if (this.score instanceof IDiscreteScore) { + ((IDiscreteScore) this.score).setStructurePrior(expectedNumParents); } } From 62672510c8791ed6d32d274a4447e452546bdade Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 07:00:12 -0400 Subject: [PATCH 184/464] Fixing documentation etc. --- .../algcomparison/independence/DiscreteBicTest.java | 4 ++-- .../cmu/tetrad/algcomparison/score/DiscreteBicScore.java | 5 ++--- .../main/java/edu/cmu/tetrad/bayes/BayesProperties.java | 4 ++-- .../{IDiscreteBicScore.java => DiscreteBicScore.java} | 8 +++----- 4 files changed, 9 insertions(+), 12 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IDiscreteBicScore.java => DiscreteBicScore.java} (97%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java index 903240b8a0..031d51310b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IDiscreteBicScore; +import edu.cmu.tetrad.search.DiscreteBicScore; import edu.cmu.tetrad.search.IndTestScore; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; @@ -31,7 +31,7 @@ public class DiscreteBicTest implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - IDiscreteBicScore score = new IDiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); + DiscreteBicScore score = new DiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); return new IndTestScore(score); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java index 266dd0c902..d055a56630 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java @@ -4,7 +4,6 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IDiscreteBicScore; import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -30,8 +29,8 @@ public class DiscreteBicScore implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - IDiscreteBicScore score - = new IDiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); + edu.cmu.tetrad.search.DiscreteBicScore score + = new edu.cmu.tetrad.search.DiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); return score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java index 3e278feec5..131410ee39 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IDiscreteBicScore; +import edu.cmu.tetrad.search.DiscreteBicScore; import org.apache.commons.math3.distribution.ChiSquaredDistribution; import org.apache.commons.math3.util.FastMath; @@ -270,7 +270,7 @@ private int getDof2(Graph graph) { private Ret getLikelihoodNode(int node, int[] parents) { - IDiscreteBicScore bic = new IDiscreteBicScore(dataSet); + DiscreteBicScore bic = new DiscreteBicScore(dataSet); double lik = bic.localScore(node, parents); int dof = (numCategories[node] - 1) * parents.length; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteBicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java index 32a195cf56..ba9ab5f3e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java @@ -33,17 +33,15 @@ /** * Calculates the discrete BIC score. */ -public class IDiscreteBicScore implements IDiscreteScore { +public class DiscreteBicScore implements IDiscreteScore { private List variables; private final int[][] data; private final int sampleSize; - private double penaltyDiscount = 1; - private final int[] numCategories; private double structurePrior = 1; - public IDiscreteBicScore(DataSet dataSet) { + public DiscreteBicScore(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException("Data was not provided."); } @@ -139,7 +137,7 @@ public double localScore(int node, int[] parents) { continue; } - int rowIndex = IDiscreteBicScore.getRowIndex(dims, parentValues); + int rowIndex = DiscreteBicScore.getRowIndex(dims, parentValues); n_jk[rowIndex][childValue]++; n_j[rowIndex]++; From e26a3e9547e0c68a5358fcbdc0ed287cbf701a18 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 07:02:46 -0400 Subject: [PATCH 185/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java | 1 + 1 file changed, 1 insertion(+) 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 ba9ab5f3e5..942b4d4962 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 @@ -32,6 +32,7 @@ /** * Calculates the discrete BIC score. + * @author josephramsey */ public class DiscreteBicScore implements IDiscreteScore { private List variables; From 11e748ad3303fe2d02827d41628396769352a0d4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 14:14:42 -0400 Subject: [PATCH 186/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java | 4 ---- 1 file changed, 4 deletions(-) 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 942b4d4962..eaa00a8881 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 @@ -233,10 +233,6 @@ public void setVariables(List variables) { this.variables = variables; } - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } From 7c444044c55669638267b2d6895743d7039063f8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 14:27:30 -0400 Subject: [PATCH 187/464] Fixing documentation etc. --- .../cmu/tetrad/search/DiscreteBicScore.java | 107 +++++++++++++----- 1 file changed, 80 insertions(+), 27 deletions(-) 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 eaa00a8881..f0f110587e 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 @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.Node; import org.apache.commons.math3.util.FastMath; +import javax.help.UnsupportedOperationException; import java.util.List; import static org.apache.commons.math3.util.FastMath.abs; @@ -35,6 +36,7 @@ * @author josephramsey */ public class DiscreteBicScore implements IDiscreteScore { + private final DataSet dataSet; private List variables; private final int[][] data; private final int sampleSize; @@ -42,11 +44,17 @@ public class DiscreteBicScore implements IDiscreteScore { private final int[] numCategories; private double structurePrior = 1; + /** + * Constructor. + * @param dataSet The discrete dataset to analyze. + */ public DiscreteBicScore(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException("Data was not provided."); } + this.dataSet = dataSet; + if (dataSet instanceof BoxDataSet && ((BoxDataSet) dataSet).getDataBox() instanceof VerticalIntDataBox) { DataBox dataBox = ((BoxDataSet) dataSet).getDataBox(); this.variables = dataSet.getVariables(); @@ -76,10 +84,12 @@ public DiscreteBicScore(DataSet dataSet) { } } - private DiscreteVariable getVariable(int i) { - return (DiscreteVariable) this.variables.get(i); - } - + /** + * Returns the score of the given nodes given its parents. + * @param node The index of the node. + * @param parents The indices of the node's parents. + * @return The score. + */ @Override public double localScore(int node, int[] parents) { @@ -169,59 +179,72 @@ public double localScore(int node, int[] parents) { } } + /** + * Returns localScore(y | z, x) - localScore(y | z). + * @return This score. + */ @Override public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } + /** + * Returns the variables. + * @return This list. + */ @Override public List getVariables() { return this.variables; } + /** + * Returns the sample size. + * @return This size. + */ public int getSampleSize() { return this.sampleSize; } /** - * Must be called directly after the corresponding scoring call. + * Must be called directly after the corresponding scoring call. Used in FGES. + * @param bump The score bump. + * @see Fges */ public boolean isEffectEdge(double bump) { return bump > 0;//lastBumpThreshold; } + /** + * Returns the dataset being analyzed. + * @return this dataset. + */ @Override public DataSet getDataSet() { - throw new UnsupportedOperationException(); - } - - private static int getRowIndex(int[] dim, int[] values) { - int rowIndex = 0; - for (int i = 0; i < dim.length; i++) { - rowIndex *= dim[i]; - rowIndex += values[i]; - } - return rowIndex; - } - - public double getStructurePrior() { - return this.structurePrior; - } - - public double getSamplePrior() { - throw new UnsupportedOperationException(); + return this.dataSet; } + /** + * Sets the structure prior. + * @param structurePrior This prior. + */ @Override public void setStructurePrior(double structurePrior) { this.structurePrior = structurePrior; } + /** + * This method is not used for this score. + * @throws UnsupportedOperationException Since this method is not used. + */ @Override public void setSamplePrior(double samplePrior) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("This method is not used."); } + /** + * Sets the variables to a new list of the same size. + * @param variables The new list of variables. + */ public void setVariables(List variables) { for (int i = 0; i < variables.size(); i++) { if (!variables.get(i).getName().equals(this.variables.get(i).getName())) { @@ -233,33 +256,63 @@ public void setVariables(List variables) { this.variables = variables; } + /** + * Sets the penalty discount, which is a multiplier on the penalty term of BIC. + * @param penaltyDiscount This discount. + */ public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } + /** + * Returns the maximum degree for some algorithms. + * @return 1000. + */ @Override public int getMaxDegree() { return 1000; } + /** + * This method is not used; a method for calculating whether nodes Z determind node y has not + * been implemented here. + * @throws UnsupportedOperationException Since this method is not used. + */ @Override public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException("This method is not used."); } + /** + * Returns a string representation of this score. + * @return This string. + */ @Override public String toString() { return "BIC Score"; } + private static int getRowIndex(int[] dim, int[] values) { + int rowIndex = 0; + for (int i = 0; i < dim.length; i++) { + rowIndex *= dim[i]; + rowIndex += values[i]; + } + return rowIndex; + } + private double getPriorForStructure(int parents) { - if (abs(getStructurePrior()) <= 0) { + if (abs(this.structurePrior) <= 0) { return 0; } else { - double p = (getStructurePrior()) / (this.variables.size()); + double p = (this.structurePrior) / (this.variables.size()); return -((parents) * log(p) + (this.variables.size() - (parents)) * log(1.0 - p)); } } + + private DiscreteVariable getVariable(int i) { + return (DiscreteVariable) this.variables.get(i); + } } From 3e5ed091afd30dbf5707a71c0105f4a2e963fc51 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 14:29:11 -0400 Subject: [PATCH 188/464] Fixing documentation etc. --- .../search/DiscreteMixedLikelihood.java | 355 ------------------ 1 file changed, 355 deletions(-) delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedLikelihood.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedLikelihood.java deleted file mode 100755 index 463da99684..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteMixedLikelihood.java +++ /dev/null @@ -1,355 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.data.Discretizer.Discretization; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.Matrix; -import org.apache.commons.math3.linear.BlockRealMatrix; -import org.apache.commons.math3.linear.RealMatrix; -import org.apache.commons.math3.stat.correlation.Covariance; -import org.apache.commons.math3.util.FastMath; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static edu.cmu.tetrad.data.Discretizer.discretize; -import static edu.cmu.tetrad.data.Discretizer.getEqualFrequencyBreakPoints; -import static org.apache.commons.math3.util.FastMath.log; - -/** - * Implements a conditional Gaussian likelihood. Please note that this this likelihood will be maximal only if the - * the continuous mixedVariables are jointly Gaussian conditional on the discrete mixedVariables; in all other cases, it will - * be less than maximal. For an algorithm like FGS this is fine. - * - * @author Joseph Ramsey - */ -public class DiscreteMixedLikelihood { - - // The data set. May contain continuous and/or discrete mixedVariables. - private final DataSet mixedDataSet; - - // The data set with all continuous mixedVariables discretized. - private final DataSet dataSet; - - // Number of categories to use to discretize continuous mixedVariables. - private int numCategoriesToDiscretize = 3; - - // The mixedVariables of the mixed data set. - private final List mixedVariables; - - // Indices of mixedVariables. - private final Map nodesHash; - - // Continuous data only. - private final double[][] continuousData; - - // The AD Tree used to count discrete cells. - private final AdLeafTree adTree; - - // Multiplier on degrees of freedom for the continuous portion of those degrees. - private double penaltyDiscount = 1; - - // "Cell" consisting of all rows. - private final ArrayList all; - - // A constant. - private static final double LOG2PI = log(2.0 * FastMath.PI); - - /** - * A return value for a likelihood--returns a likelihood value and the degrees of freedom - * for it. - */ - public static class Ret { - private final double lik; - private final int dof; - - private Ret(double lik, int dof) { - this.lik = lik; - this.dof = dof; - } - - public double getLik() { - return this.lik; - } - - public int getDof() { - return this.dof; - } - - public String toString() { - return "lik = " + this.lik + " dof = " + this.dof; - } - } - - /** - * Constructs the score using a covariance matrix. - */ - public DiscreteMixedLikelihood(DataSet dataSet) { - if (dataSet == null) { - throw new NullPointerException(); - } - - this.mixedDataSet = dataSet; - this.mixedVariables = dataSet.getVariables(); - - this.continuousData = new double[dataSet.getNumColumns()][]; - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - Node v = dataSet.getVariable(j); - - if (v instanceof ContinuousVariable) { - double[] col = new double[dataSet.getNumRows()]; - - for (int i = 0; i < dataSet.getNumRows(); i++) { - col[i] = dataSet.getDouble(i, j); - } - - this.continuousData[j] = col; - } - } - - this.nodesHash = new HashMap<>(); - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - Node v = dataSet.getVariable(j); - this.nodesHash.put(v, j); - } - - this.dataSet = useErsatzVariables(); - this.adTree = new AdLeafTree(this.dataSet); - - this.all = new ArrayList<>(); - for (int i = 0; i < dataSet.getNumRows(); i++) this.all.add(i); - - } - - private DataSet useErsatzVariables() { - List nodes = new ArrayList<>(); - int numCategories = this.numCategoriesToDiscretize; - - for (Node x : this.mixedVariables) { - if (x instanceof ContinuousVariable) { - nodes.add(new DiscreteVariable(x.getName(), numCategories)); - } else { - nodes.add(x); - } - } - - DataSet replaced = new BoxDataSet(new VerticalIntDataBox(this.mixedDataSet.getNumRows(), this.mixedDataSet.getNumColumns()), nodes); - - for (int j = 0; j < this.mixedVariables.size(); j++) { - if (this.mixedVariables.get(j) instanceof DiscreteVariable) { - for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { - replaced.setInt(i, j, this.mixedDataSet.getInt(i, j)); - } - } else { - double[] column = this.continuousData[j]; - - double[] breakpoints = getEqualFrequencyBreakPoints(column, numCategories); - - List categoryNames = new ArrayList<>(); - - for (int i = 0; i < numCategories; i++) { - categoryNames.add("" + i); - } - - Discretization d = discretize(column, breakpoints, this.mixedVariables.get(j).getName(), categoryNames); - - for (int i = 0; i < this.mixedDataSet.getNumRows(); i++) { - replaced.setInt(i, j, d.getData()[i]); - } - } - } - - return replaced; - } - - /** - * Returns the likelihood of variable i conditional on the given parents, assuming the continuous mixedVariables - * index by i or by the parents are jointly Gaussian conditional on the discrete comparison. - * - * @param i The index of the conditioned variable. - * @param parents The indices of the conditioning mixedVariables. - * @return The likelihood. - */ - public Ret getLikelihood(int i, int[] parents) { - Node target = this.mixedVariables.get(i); - - List X = new ArrayList<>(); - List A = new ArrayList<>(); - - for (int p : parents) { - Node parent = this.mixedVariables.get(p); - - if (parent instanceof ContinuousVariable) { - X.add((ContinuousVariable) parent); - } else { - A.add((DiscreteVariable) parent); - } - } - - List XPlus = new ArrayList<>(X); - List APlus = new ArrayList<>(A); - - if (target instanceof ContinuousVariable) { - XPlus.add((ContinuousVariable) target); - } else if (target instanceof DiscreteVariable) { - APlus.add((DiscreteVariable) target); - } - - Ret ret1 = likelihoodJoint(XPlus, APlus); - Ret ret2 = likelihoodJoint(X, A); - - return new Ret(ret1.getLik() - ret2.getLik(), ret1.getDof() - ret2.getDof()); - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { - this.numCategoriesToDiscretize = numCategoriesToDiscretize; - } - - // The likelihood of the joint over all of these mixedVariables, assuming conditional Gaussian, - // continuous and discrete. - private Ret likelihoodJoint(List X, List A) { - A = new ArrayList<>(A); - X = new ArrayList<>(X); - - for (ContinuousVariable x : new ArrayList<>(X)) { - Node variable = this.dataSet.getVariable(x.getName()); - - if (variable != null) { - A.add((DiscreteVariable) variable); - X.remove(x); - } - } - - int k = X.size(); - - int[] continuousCols = new int[k]; - for (int j = 0; j < k; j++) continuousCols[j] = this.nodesHash.get(X.get(j)); - int N = this.mixedDataSet.getNumRows(); - - double c1 = 0, c2 = 0; - - List> cells = this.adTree.getCellLeaves(A); - //List> cells = partition(A); - - for (List cell : cells) { - int a = cell.size(); - if (a == 0) continue; - - if (A.size() > 0) { - c1 += a * multinomialLikelihood(a, N); - } - - if (X.size() > 0) { - try { - - // Determinant will be zero if data are linearly dependent. - Matrix cov; - if (a > continuousCols.length + 5) { - cov = cov(getSubsample(continuousCols, cell)); - } else { - cov = cov(getSubsample(continuousCols, this.all)); - } - c2 += a * gaussianLikelihood(k, cov); - } catch (Exception e) { - // No contribution. - } - } - } - - double lnL = c1 + c2; - int dof = f(A) * h(X) + f(A); - return new Ret(lnL, dof); - } - - private double multinomialLikelihood(int a, int N) { - return log(a / (double) N); - } - - // One record. - private double gaussianLikelihood(int k, Matrix sigma) { - return -0.5 * logdet(sigma) - 0.5 * k * (1 + DiscreteMixedLikelihood.LOG2PI); - } - - private double logdet(Matrix m) { - RealMatrix M = new BlockRealMatrix(m.toArray()); - final double tol = 1e-9; - RealMatrix LT = new org.apache.commons.math3.linear.CholeskyDecomposition(M, tol, tol).getLT(); - - double sum = 0.0; - - for (int i = 0; i < LT.getRowDimension(); i++) { - sum += FastMath.log(LT.getEntry(i, i)); - } - - return 2.0 * sum; - } - - private Matrix cov(Matrix x) { - return new Matrix(new Covariance(x.toArray(), true).getCovarianceMatrix().getData()); - } - - // Subsample of the continuous mixedVariables conditioning on the given cell. - private Matrix getSubsample(int[] continuousCols, List cell) { - Matrix subset = new Matrix(cell.size(), continuousCols.length); - - for (int i = 0; i < cell.size(); i++) { - for (int j = 0; j < continuousCols.length; j++) { - subset.set(i, j, this.continuousData[continuousCols[j]][cell.get(i)]); - } - } - - return subset; - } - - // Degrees of freedom for a discrete distribution is the product of the number of categories for each - // variable. - private int f(List A) { - int f = 1; - - for (DiscreteVariable V : A) { - f *= V.getNumCategories(); - } - - return f; - } - - // Degrees of freedom for a multivariate Gaussian distribution is p * (p + 1) / 2, where p is the number - // of mixedVariables. This is the number of unique entries in the covariance matrix over X. - private int h(List X) { - int p = X.size(); - return p * (p + 1) / 2; - } -} \ No newline at end of file From c4fd18972fe258104f0a60c6b128cac01d86f336 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 14:45:10 -0400 Subject: [PATCH 189/464] Fixing documentation etc. --- .../edu/cmu/tetradapp/model/PurifyRunner.java | 2 +- .../tetrad/search/BayesUpdaterClassifier.java | 2 +- .../search/BpcTetradPurifyWashdown.java | 2 +- .../cmu/tetrad/search/BuildPureClusters.java | 2 +- .../tetrad/search/ContinuousTetradTest.java | 2 +- .../cmu/tetrad/search/DeltaSextadTest.java | 24 +++-- .../cmu/tetrad/search/DiscreteTetradTest.java | 2 +- .../java/edu/cmu/tetrad/search/EbicScore.java | 90 +++++++++---------- .../edu/cmu/tetrad/search/EstimateRank.java | 36 ++------ ...assifier.java => IDiscreteClassifier.java} | 2 +- .../{TetradTest.java => ITetradTest.java} | 2 +- .../edu/cmu/tetrad/search/MbClassify.java | 2 +- .../tetrad/search/PopulationTetradTest.java | 2 +- .../java/edu/cmu/tetrad/search/Purify.java | 4 +- .../cmu/tetrad/search/PurifyScoreBased.java | 4 +- .../cmu/tetrad/search/PurifyTetradBased.java | 4 +- .../java/edu/cmu/tetrad/test/TestPurify.java | 4 +- 17 files changed, 81 insertions(+), 105 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{DiscreteClassifier.java => IDiscreteClassifier.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{TetradTest.java => ITetradTest.java} (98%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index b2ac4129aa..db05ea5042 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -70,7 +70,7 @@ public static PcRunner serializableInstance() { public void execute() { Object source = getData(); - TetradTest test; + ITetradTest test; System.out.println("Clusters " + getParams().get("clusters", null)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java index 4494a07adf..a695394a60 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java @@ -46,7 +46,7 @@ * @author Frank Wimberly based on a specification by Clark Glymour */ public final class BayesUpdaterClassifier - implements DiscreteClassifier, TetradSerializable { + implements IDiscreteClassifier, TetradSerializable { static final long serialVersionUID = 23L; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java index f8afec133a..8321e43248 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java @@ -37,7 +37,7 @@ */ public class BpcTetradPurifyWashdown { private final List variables; - private final TetradTest test; + private final ITetradTest test; /** * Construct the algorithm using a covariance matrix. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index 4bb5b01dc0..e82e1feb57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -77,7 +77,7 @@ public final class BuildPureClusters { final int EDGE_RED = 4; final int MAX_CLIQUE_TRIALS = 50; - private TetradTest tetradTest; + private ITetradTest tetradTest; private IndependenceTest independenceTest; private DataSet dataSet; private double alpha; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java index ff3b1130ca..d6974f6782 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java @@ -54,7 +54,7 @@ * @author Ricardo Silva */ -public final class ContinuousTetradTest implements TetradTest { +public final class ContinuousTetradTest implements ITetradTest { private double sig; private double[] prob; private ICovarianceMatrix covMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java index 3dc4ec44a5..78ea60a134 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java @@ -57,6 +57,7 @@ public class DeltaSextadTest { /** * Constructs a test using a given data set. If a data set is provided (that is, a tabular data set), fourth moment * statistics can be calculated (p. 160); otherwise, it must be assumed that the data are multivariate Gaussian. + * * @param dataSet The dataset to use. */ public DeltaSextadTest(DataSet dataSet) { @@ -79,6 +80,7 @@ public DeltaSextadTest(DataSet dataSet) { /** * Constructs a test using the given covariance matrix. Fourth moment statistics are not caculated; it is assumed * that the data are distributed as multivariate Gaussian. + * * @param cov The covariance matrix to use. */ public DeltaSextadTest(ICovarianceMatrix cov) { @@ -93,6 +95,7 @@ public DeltaSextadTest(ICovarianceMatrix cov) { /** * Generates a simple exemplar of this class to test serialization. + * * @return This instance. */ public static DeltaSextadTest serializableInstance() { @@ -105,6 +108,7 @@ public static DeltaSextadTest serializableInstance() { *

* Calculates the T statistic (Bollen and Ting, p. 161). This is significant if tests as significant using the Chi * Square distribution with degrees of freedom equal to the number of nonredundant tetrads tested. + * * @param sextads The sextads for which a p-value is needed. * @return The p-value. */ @@ -121,6 +125,7 @@ public double getPValue(IntSextad... sextads) { *

* Calculates the T statistic (Bollen and Ting, p. 161). This is significant if tests as significant using the Chi * Square distribution with degrees of freedom equal to the number of nonredundant tetrads tested. + * * @param sextads The sextads for which a chi-square is needed * @return The chi-square. */ @@ -163,10 +168,10 @@ public double calcChiSquare(IntSextad[] sextads) { - r(g, h) * (r(f, g) * r(e, g) + r(f, h) * r(e, h)); // General. - double rr2 = r(e, f, g, h) + 0.25 * r(e, f) * r(g, h) * - (r(e, e, g, g) * r(f, f, g, g) + r(e, e, h, h) + r(f, f, h, h)) - - 0.5 * r(e, f) * (r(e, e, g, h) + r(f, f, g, h)) - - 0.5 * r(g, h) * (r(e, f, g, g) + r(e, f, h, h)); +// double rr2 = r(e, f, g, h) + 0.25 * r(e, f) * r(g, h) * +// (r(e, e, g, g) * r(f, f, g, g) + r(e, e, h, h) + r(f, f, h, h)) +// - 0.5 * r(e, f) * (r(e, e, g, h) + r(f, f, g, h)) +// - 0.5 * r(g, h) * (r(e, f, g, g) + r(e, f, h, h)); sigma_ss.set(i, j, rr); sigma_ss.set(j, i, rr); @@ -229,6 +234,7 @@ public double calcChiSquare(IntSextad[] sextads) { /** * Returns the variables of the data being used. + * * @return This list. */ public List getVariables() { @@ -368,11 +374,11 @@ private double r(double[] array1, double[] array2, int N) { return (1.0 / N) * sum; } - private int dofDrton(int n) { - int dof = ((n - 2) * (n - 3)) / 2 - 2; - if (dof < 1) dof = 1; - return dof; - } +// private int dofDrton(int n) { +// int dof = ((n - 2) * (n - 3)) / 2 - 2; +// if (dof < 1) dof = 1; +// return dof; +// } private int dofHarman(int n) { int dof = n * (n - 5) / 2 + 1; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java index 62bbf7511a..08beb7297c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java @@ -45,7 +45,7 @@ * @author Ricardo Silva */ -public final class DiscreteTetradTest implements TetradTest { +public final class DiscreteTetradTest implements ITetradTest { DataSet dataSet; // int rawdata[][]; int[][][][] counts; //bivariate coefs only diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java index e0b4a3df86..d4bee76c8a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java @@ -32,35 +32,18 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Implements the extended BIC score (Chen and Chen).. + * Implements the extended BIC (EBIC) score (Chen and Chen).. * * @author Joseph Ramsey */ public class EbicScore implements Score { - private DataSet dataSet; - // The covariance matrix. private ICovarianceMatrix covariances; - - // The variables of the covariance matrix. private final List variables; - - // The sample size of the covariance matrix. private final int sampleSize; - - // True if verbose output should be sent to out. - private boolean verbose; - - // Sample size or equivalent sample size. private double N; - - // The data, if it is set. private Matrix data; - - // True if row subsets should be calculated. private boolean calculateRowSubsets; - - // The gamma paramter for EBIC. private double gamma = 1; /** @@ -78,6 +61,9 @@ public EbicScore(ICovarianceMatrix covariances) { /** * Constructs the score using a covariance matrix. + * @param dataSet The continuous dataset to analyze. + * @param precomputeCovariances Whether the covariances should be precomputed or computed on the fly. + * True if precomputed. */ public EbicScore(DataSet dataSet, boolean precomputeCovariances) { @@ -106,19 +92,16 @@ public EbicScore(DataSet dataSet, boolean precomputeCovariances) { } - private int[] indices(List __adj) { - int[] indices = new int[__adj.size()]; - for (int t = 0; t < __adj.size(); t++) indices[t] = this.variables.indexOf(__adj.get(t)); - return indices; - } - + /** + * @return localScore(y | z, x) - localScore(y | z). + */ @Override public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - /** + * Returns the score of the node i given its parents. * @param i The index of the node. * @param parents The indices of the node's parents. * @return The score, or NaN if the score cannot be calculated. @@ -145,47 +128,49 @@ public double localScore(int i, int... parents) throws RuntimeException { } } - public static double getP(int pn, int m0, double lambda) { - return 2 - pow(1 + (exp(-(lambda - 1) / 2.)) * sqrt(lambda), (double) pn - m0); - } - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. + * Returns the sample size. + * @return This size. */ - - - public ICovarianceMatrix getCovariances() { - return this.covariances; - } - public int getSampleSize() { return this.sampleSize; } + /** + * Returns a judgement for FGES of whether the given bump implies an effect edge. + * @param bump The bump + * @return True if so + * @see Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; } - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - + /** + * Returns the variables for this score. + * @return Thsi list. + */ @Override public List getVariables() { return this.variables; } - + /** + * Returns an estimate of max degree of the graph for some algorithms. + * @return This max degree. + * @see Fges + * @see MagSemBicScore + */ @Override public int getMaxDegree() { return (int) ceil(log(this.sampleSize)); } + /** + * Return a judgment of whether the variable in z determine y exactly. + * @return This judgment + */ @Override public boolean determines(List z, Node y) { int i = this.variables.indexOf(y); @@ -197,8 +182,12 @@ public boolean determines(List z, Node y) { return Double.isNaN(v); } - public DataModel getData() { - return this.dataSet; + /** + * Sets the gamma parameter for EBIC. + * @param gamma The gamma parameter. + */ + public void setGamma(double gamma) { + this.gamma = gamma; } private void setCovariances(ICovarianceMatrix covariances) { @@ -228,9 +217,10 @@ private void setCovariances(ICovarianceMatrix covariances) { this.N = covariances.getSampleSize(); } - - public void setGamma(double gamma) { - this.gamma = gamma; + private int[] indices(List __adj) { + int[] indices = new int[__adj.size()]; + for (int t = 0; t < __adj.size(); t++) indices[t] = this.variables.indexOf(__adj.get(t)); + return indices; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EstimateRank.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EstimateRank.java index dde9c251cd..a704118adc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EstimateRank.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EstimateRank.java @@ -31,18 +31,9 @@ * Estimates the rank of a matrix. */ public class EstimateRank { - double alpha; - double[][] A; - double[][] B; - int[] iA; - int[] iB; - double[][] cov; - int N; //Compute canonical correlations from data. - public double[] CanCor(double[][] A, double[][] B) { - this.A = A; - this.B = B; + public static double[] CanCor(double[][] A, double[][] B) { RealMatrix Ua = new SingularValueDecomposition(new BlockRealMatrix(A)).getU(); RealMatrix UTa = Ua.transpose(); RealMatrix Ub = new SingularValueDecomposition(new BlockRealMatrix(B)).getU(); @@ -50,10 +41,7 @@ public double[] CanCor(double[][] A, double[][] B) { } //Compute canonical correlations from covariance matrix. - public double[] CanCor(int[] iA, int[] iB, double[][] cov) { - this.iA = iA; - this.iB = iB; - this.cov = cov; + public static double[] CanCor(int[] iA, int[] iB, double[][] cov) { RealMatrix covA = new BlockRealMatrix(cov).getSubMatrix(iA, iA); RealMatrix covB = new BlockRealMatrix(cov).getSubMatrix(iB, iB); RealMatrix covAB = new BlockRealMatrix(cov).getSubMatrix(iA, iB); @@ -68,15 +56,8 @@ public double[] CanCor(int[] iA, int[] iB, double[][] cov) { return Cors; } - private RealMatrix getInverse(RealMatrix covA) { - return new LUDecomposition(covA).getSolver().getInverse(); - } - //Estimate rank from data. - public int Estimate(double[][] A, double[][] B, double alpha) { - this.alpha = alpha; - this.A = A; - this.B = B; + public static int Estimate(double[][] A, double[][] B, double alpha) { double[] Cors = CanCor(A, B); int rank = 0; boolean reject = true; @@ -99,12 +80,7 @@ public int Estimate(double[][] A, double[][] B, double alpha) { } //Estimate rank from covariance matrix. - public int Estimate(int[] iA, int[] iB, double[][] cov, int N, double alpha) { - this.alpha = alpha; - this.iA = iA; - this.iB = iB; - this.cov = cov; - this.N = N; + public static int Estimate(int[] iA, int[] iB, double[][] cov, int N, double alpha) { double[] Cors = CanCor(iA, iB, cov); int rank = 0; boolean reject = true; @@ -126,4 +102,8 @@ public int Estimate(int[] iA, int[] iB, double[][] cov, int N, double alpha) { return rank; } + + private static RealMatrix getInverse(RealMatrix covA) { + return new LUDecomposition(covA).getSolver().getInverse(); + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteClassifier.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteClassifier.java index 938686c9e8..576ad4721b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteClassifier.java @@ -27,7 +27,7 @@ * * @author Frank Wimberly */ -public interface DiscreteClassifier { +public interface IDiscreteClassifier { /** * @return an array with a classification (estimated value) of a target variable for each case in a DataSet. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ITetradTest.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/ITetradTest.java index 4e4808b906..c862fdd850 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ITetradTest.java @@ -33,7 +33,7 @@ * * @author Ricardo Silva */ -public interface TetradTest { +public interface ITetradTest { DataSet getDataSet(); int tetradScore(int i, int j, int k, int q); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java index cc0f5e333d..ba225ec4d3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java @@ -47,7 +47,7 @@ * @author Frank Wimberly * @author Joseph Ramsey */ -public class MbClassify implements DiscreteClassifier { +public class MbClassify implements IDiscreteClassifier { private DataSet train; private DataSet test; private Node target; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java index 192c9642df..4c9d572158 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java @@ -36,7 +36,7 @@ * @author Ricardo Silva */ -public class PopulationTetradTest implements TetradTest { +public class PopulationTetradTest implements ITetradTest { private final CorrelationMatrix CorrelationMatrix; private final boolean[] bvalues; private final double epsilon = 0.001; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java index a691ef7336..c0197390e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java @@ -67,7 +67,7 @@ public class Purify { private Clusters clusters; private List forbiddenList; private int numVars; - private TetradTest tetradTest; + private ITetradTest tetradTest; /** * The logger for this class. The config needs to be set. @@ -120,7 +120,7 @@ public Purify(DataSet dataSet, double sig, TestType testType, this.variables = dataSet.getVariables(); } - public Purify(TetradTest tetradTest, Clusters knowledge) { + public Purify(ITetradTest tetradTest, Clusters knowledge) { this.tetradTest = tetradTest; initAlgorithm(-1., TestType.NONE, knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java index 26ec1d718c..bc72b9e515 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java @@ -39,7 +39,7 @@ */ public class PurifyScoreBased implements IPurify { private final boolean outputMessage = true; - private final TetradTest tetradTest; + private final ITetradTest tetradTest; private final int numVars; private List forbiddenList; @@ -87,7 +87,7 @@ public class PurifyScoreBased implements IPurify { boolean extraDebugPrint; - public PurifyScoreBased(TetradTest tetradTest) { + public PurifyScoreBased(ITetradTest tetradTest) { this.tetradTest = tetradTest; this.numVars = tetradTest.getVarNames().length; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java index 13365e96d7..87da3cb236 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java @@ -37,11 +37,11 @@ */ public class PurifyTetradBased implements IPurify { private final boolean outputMessage = true; - private final TetradTest tetradTest; + private final ITetradTest tetradTest; private final List nodes; - public PurifyTetradBased(TetradTest tetradTest) { + public PurifyTetradBased(ITetradTest tetradTest) { this.tetradTest = tetradTest; this.nodes = tetradTest.getVariables(); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index f5110936d7..cb049ad073 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -151,7 +151,7 @@ public void test1() { partition.add(cluster2); partition.add(cluster3); - TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.05); + ITetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.05); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); @@ -248,7 +248,7 @@ public void test1b() { partition.add(cluster1); partition.add(cluster2); - TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.0001); + ITetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.0001); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); From 89eed052507f5f4bdc14eeff6c7fd1a6d35361d6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 14:49:39 -0400 Subject: [PATCH 190/464] Fixing documentation etc. --- .../edu/cmu/tetrad/search/FactorAnalysis.java | 164 +----------------- .../main/java/edu/cmu/tetrad/search/Fas.java | 1 - 2 files changed, 8 insertions(+), 157 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index e94c697b96..e30b413f21 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -51,10 +51,18 @@ public class FactorAnalysis { private int numFactors = 2; private Matrix residual; + /** + * Consructor. + * @param covarianceMatrix The covariance matrix being analyzed. + */ public FactorAnalysis(ICovarianceMatrix covarianceMatrix) { this.covariance = new CovarianceMatrix(covarianceMatrix); } + /** + * Constructor. + * @param dataSet The continuous dataset being analyzed. + */ public FactorAnalysis(DataSet dataSet) { this.covariance = new CovarianceMatrix(dataSet); } @@ -342,162 +350,6 @@ public void setNumFactors(int numFactors) { public Matrix getResidual() { return this.residual; } - - // factanal in R: - -// function (x, factors, data = NULL, covmat = NULL, n.obs = NA, -// subset, na.action, start = NULL, scores = c("none", "regression", -// "Bartlett"), rotation = "varimax", control = NULL, ...) -// { -// sortLoadings <- function(Lambda) { -// cn <- colnames(Lambda) -// Phi <- attr(Lambda, "covariance") -// ssq <- apply(Lambda, 2L, function(x) -sum(x^2)) -// Lambda <- Lambda[, order(ssq), drop = FALSE] -// colnames(Lambda) <- cn -// neg <- colSums(Lambda) < 0 -// Lambda[, neg] <- -Lambda[, neg] -// if (!is.null(Phi)) { -// unit <- ifelse(neg, -1, 1) -// attr(Lambda, "covariance") <- unit %*% Phi[order(ssq), -// order(ssq)] %*% unit -// } -// Lambda -// } -// cl <- match.call() -// na.act <- NULL -// if (is.list(covmat)) { -// if (any(is.na(match(c("cov", "n.obs"), names(covmat))))) -// stop("'covmat' is not a valid covariance list") -// cv <- covmat$cov -// n.obs <- covmat$n.obs -// have.x <- FALSE -// } -// else if (is.matrix(covmat)) { -// cv <- covmat -// have.x <- FALSE -// } -// else if (is.null(covmat)) { -// if (missing(x)) -// stop("neither 'x' nor 'covmat' supplied") -// have.x <- TRUE -// if (inherits(x, "formula")) { -// mt <- terms(x, data = data) -// if (attr(mt, "response") > 0) -// stop("response not allowed in formula") -// attr(mt, "intercept") <- 0 -// mf <- match.call(expand.dots = FALSE) -// names(mf)[names(mf) == "x"] <- "formula" -// mf$factors <- mf$covmat <- mf$scores <- mf$start <- mf$rotation <- mf$control <- mf$... <- NULL -// mf[[1L]] <- quote(stats::model.frame) -// mf <- eval.parent(mf) -// na.act <- attr(mf, "na.action") -// if (.check_vars_numeric(mf)) -// stop("factor analysis applies only to numerical variables") -// z <- model.matrix(mt, mf) -// } -// else { -// z <- as.matrix(x) -// if (!is.numeric(z)) -// stop("factor analysis applies only to numerical variables") -// if (!missing(subset)) -// z <- z[subset, , drop = FALSE] -// } -// covmat <- cov.wt(z) -// cv <- covmat$cov -// n.obs <- covmat$n.obs -// } -// else stop("'covmat' is of unknown type") -// scores <- match.arg(scores) -// if (scores != "none" && !have.x) -// stop("requested scores without an 'x' matrix") -// p <- ncol(cv) -// if (p < 3) -// stop("factor analysis requires at least three variables") -// dof <- 0.5 * ((p - factors)^2 - p - factors) -// if (dof < 0) -// stop(sprintf(ngettext(factors, "%d factor is too many for %d variables", -// "%d factors are too many for %d variables"), factors, -// p), domain = NA) -// sds <- sqrt(diag(cv)) -// cv <- cv/(sds %o% sds) -// cn <- list(nstart = 1, trace = FALSE, lower = 0.005) -// cn[names(control)] <- control -// more <- list(...)[c("nstart", "trace", "lower", "opt", "rotate")] -// if (length(more)) -// cn[names(more)] <- more -// if (is.null(start)) { -// start <- (1 - 0.5 * factors/p)/diag(solve(cv)) -// if ((ns <- cn$nstart) > 1) -// start <- cbind(start, matrix(runif(ns - 1), p, ns - -// 1, byrow = TRUE)) -// } -// start <- as.matrix(start) -// if (nrow(start) != p) -// stop(sprintf(ngettext(p, "'start' must have %d row", -// "'start' must have %d rows"), p), domain = NA) -// nc <- ncol(start) -// if (nc < 1) -// stop("no starting values supplied") -// best <- Inf -// for (i in 1L:nc) { -// nfit <- factanal.fit.mle(cv, factors, start[, i], max(cn$lower, -// 0), cn$opt) -// if (cn$trace) -// cat("start", i, "value:", format(nfit$criteria[1L]), -// "uniqs:", format(as.vector(round(nfit$uniquenesses, -// 4))), "\n") -// if (nfit$converged && nfit$criteria[1L] < best) { -// fit <- nfit -// best <- fit$criteria[1L] -// } -// } -// if (best == Inf) -// stop(ngettext(nc, "unable to optimize from this starting value", -// "unable to optimize from these starting values"), -// domain = NA) -// load <- fit$loadings -// if (rotation != "none") { -// rot <- do.call(rotation, c(list(load), cn$rotate)) -// load <- if (is.list(rot)) { -// load <- rot$loadings -// fit$rotmat <- if (inherits(rot, "GPArotation")) -// t(solve(rot$Th)) -// else rot$rotmat -// rot$loadings -// } -// else rot -// } -// fit$loadings <- sortLoadings(load) -// class(fit$loadings) <- "loadings" -// fit$na.action <- na.act -// if (have.x && scores != "none") { -// Lambda <- fit$loadings -// zz <- scale(z, TRUE, TRUE) -// switch(scores, regression = { -// sc <- zz %*% solve(cv, Lambda) -// if (!is.null(Phi <- attr(Lambda, "covariance"))) sc <- sc %*% -// Phi -// }, Bartlett = { -// d <- 1/fit$uniquenesses -// tmp <- t(Lambda * d) -// sc <- t(solve(tmp %*% Lambda, tmp %*% t(zz))) -// }) -// rownames(sc) <- rownames(z) -// colnames(sc) <- colnames(Lambda) -// if (!is.null(na.act)) -// sc <- napredict(na.act, sc) -// fit$scores <- sc -// } -// if (!is.na(n.obs) && dof > 0) { -// fit$STATISTIC <- (n.obs - 1 - (2 * p + 5)/6 - (2 * factors)/3) * -// fit$criteria["objective"] -// fit$PVAL <- pchisq(fit$STATISTIC, dof, lower.tail = FALSE) -// } -// fit$n.obs <- n.obs -// fit$call <- cl -// fit -// } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index d9cdde4132..69a51f9c52 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -453,6 +453,5 @@ private List possibleParents(Node x, List adjx, private boolean possibleParentOf(String z, String x, Knowledge knowledge) { return !knowledge.isForbidden(z, x) && !knowledge.isRequired(x, z); } - } From 23e00efc713664a443f39229901a24bfd7101be2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 15:39:03 -0400 Subject: [PATCH 191/464] Fixing documentation etc. --- .../src/main/java/edu/cmu/tetrad/search/SampleVcpc.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java | 2 +- .../java/edu/cmu/tetrad/search/{Vcfas.java => VcFas.java} | 4 ++-- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{Vcfas.java => VcFas.java} (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java index 14e354a7bd..7b84ce9f2c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java @@ -252,7 +252,7 @@ public Graph search() { this.ambiguousTriples = new HashSet<>(); this.colliderTriples = new HashSet<>(); this.noncolliderTriples = new HashSet<>(); - Vcfas fas = new Vcfas(getIndependenceTest()); + VcFas fas = new VcFas(getIndependenceTest()); this.definitelyNonadjacencies = new HashSet<>(); long startTime = MillisecondTimes.timeMillis(); List allNodes = getIndependenceTest().getVariables(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java index 8dca299ad4..beefe1d170 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java @@ -250,7 +250,7 @@ public Graph search() { this.ambiguousTriples = new HashSet<>(); this.colliderTriples = new HashSet<>(); this.noncolliderTriples = new HashSet<>(); - Vcfas fas = new Vcfas(getIndependenceTest()); + VcFas fas = new VcFas(getIndependenceTest()); this.definitelyNonadjacencies = new HashSet<>(); long startTime = MillisecondTimes.timeMillis(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcfas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcFas.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcfas.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcFas.java index e975cb36e6..30bc3d7e38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcfas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcFas.java @@ -39,7 +39,7 @@ * * @author Joseph Ramsey. */ -public class Vcfas { +public class VcFas { /** * The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node @@ -87,7 +87,7 @@ public class Vcfas { //==========================CONSTRUCTORS=============================// - public Vcfas(IndependenceTest test) { + public VcFas(IndependenceTest test) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java index 8e77c7fc7a..7165f145a4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java @@ -232,7 +232,7 @@ public Graph search() { this.ambiguousTriples = new HashSet<>(); this.colliderTriples = new HashSet<>(); this.noncolliderTriples = new HashSet<>(); - Vcfas fas = new Vcfas(independenceTest); + VcFas fas = new VcFas(independenceTest); this.definitelyNonadjacencies = new HashSet<>(); long startTime = MillisecondTimes.timeMillis(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java index 8f3cd31c39..2f827646d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java @@ -205,7 +205,7 @@ public Graph search() { this.ambiguousTriples = new HashSet<>(); this.colliderTriples = new HashSet<>(); this.noncolliderTriples = new HashSet<>(); - Vcfas fas = new Vcfas(getIndependenceTest()); + VcFas fas = new VcFas(getIndependenceTest()); this.definitelyNonadjacencies = new HashSet<>(); long startTime = MillisecondTimes.timeMillis(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java index d4346e492f..0d440084b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java @@ -231,7 +231,7 @@ public Graph search() { this.ambiguousTriples = new HashSet<>(); this.colliderTriples = new HashSet<>(); this.noncolliderTriples = new HashSet<>(); - Vcfas fas = new Vcfas(getIndependenceTest()); + VcFas fas = new VcFas(getIndependenceTest()); this.definitelyNonadjacencies = new HashSet<>(); // this.logger.log("info", "Variables " + independenceTest.getVariable()); From b301dbf5e31e5226009e4917eb847a074cfd5d18 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 15:39:58 -0400 Subject: [PATCH 192/464] Fixing documentation etc. --- .../edu/cmu/tetradapp/model/VcpcFastRunner.java | 4 ++-- .../java/edu/cmu/tetradapp/model/VcpcRunner.java | 4 ++-- .../edu/cmu/tetrad/search/{Vcpc.java => VcPc.java} | 14 +++++++------- .../tetrad/search/{VcpcAlt.java => VcPcAlt.java} | 14 +++++++------- .../tetrad/search/{VcpcFast.java => VcPcFast.java} | 14 +++++++------- 5 files changed, 25 insertions(+), 25 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{Vcpc.java => VcPc.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{VcpcAlt.java => VcPcAlt.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{VcpcFast.java => VcPcFast.java} (98%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index 8c49fb6163..79d91ce5d8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -171,7 +171,7 @@ public void execute() { Knowledge knowledge = (Knowledge) getParams().get("knowledge", new Knowledge()); - VcpcFast fvcpc = new VcpcFast(getIndependenceTest()); + VcPcFast fvcpc = new VcPcFast(getIndependenceTest()); fvcpc.setKnowledge(knowledge); fvcpc.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); fvcpc.setDepth(getParams().getInt("depth", -1)); @@ -269,7 +269,7 @@ private boolean isAggressivelyPreventCycles() { return params instanceof Parameters && params.getBoolean("aggressivelyPreventCycles", false); } - private void setVcpcFastFields(VcpcFast fvcpc) { + private void setVcpcFastFields(VcPcFast fvcpc) { this.fvcpcAdjacent = fvcpc.getAdjacencies(); this.fvcpcApparent = fvcpc.getApparentNonadjacencies(); this.fvcpcDefinite = fvcpc.getDefiniteNonadjacencies(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 216f89c628..68bd430dd3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -171,7 +171,7 @@ public void execute() { Knowledge knowledge = (Knowledge) getParams().get("knowledge", new Knowledge()); - Vcpc vcpc = new Vcpc(getIndependenceTest()); + VcPc vcpc = new VcPc(getIndependenceTest()); vcpc.setKnowledge(knowledge); vcpc.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); vcpc.setDepth(getParams().getInt("depth", -1)); @@ -272,7 +272,7 @@ private boolean isAggressivelyPreventCycles() { return false; } - private void setVcpcFields(Vcpc vcpc) { + private void setVcpcFields(VcPc vcpc) { this.vcpcAdjacent = vcpc.getAdjacencies(); this.vcpcApparent = vcpc.getApparentNonadjacencies(); this.vcpcDefinite = vcpc.getDefiniteNonadjacencies(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPc.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPc.java index 7165f145a4..00ccd989da 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Vcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPc.java @@ -38,7 +38,7 @@ * * @author Joseph Ramsey (this version). */ -public final class Vcpc implements GraphSearch { +public final class VcPc implements GraphSearch { /** * The independence test used for the PC search. @@ -109,7 +109,7 @@ public final class Vcpc implements GraphSearch { * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the * independence test, for fear of duplicating the data set! */ - public Vcpc(IndependenceTest independenceTest) { + public VcPc(IndependenceTest independenceTest) { if (independenceTest == null) { throw new NullPointerException(); } @@ -461,7 +461,7 @@ private Set boundary(Node x, Graph graph) { private Set future(Node x, Graph graph) { Set futureNodes = new HashSet<>(); LinkedList path = new LinkedList<>(); - Vcpc.futureNodeVisit(graph, x, path, futureNodes); + VcPc.futureNodeVisit(graph, x, path, futureNodes); futureNodes.remove(x); List adj = graph.getAdjacentNodes(x); for (Node y : adj) { @@ -505,7 +505,7 @@ public static void futureNodeVisit(Graph graph, Node b, LinkedList path, S } else { Node a = path.get(size - 2); Edge edge1 = graph.getEdge(a, b); - c = Vcpc.traverseFuturePath(b, edge1, edge2); + c = VcPc.traverseFuturePath(b, edge1, edge2); } if (c == null) { continue; @@ -513,7 +513,7 @@ public static void futureNodeVisit(Graph graph, Node b, LinkedList path, S if (path.contains(c)) { continue; } - Vcpc.futureNodeVisit(graph, c, path, futureNodes); + VcPc.futureNodeVisit(graph, c, path, futureNodes); } path.removeLast(); } @@ -679,8 +679,8 @@ public enum CpcTripleType { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return Vcpc.isArrowpointAllowed1(x, y, knowledge) && - Vcpc.isArrowpointAllowed1(z, y, knowledge); + return VcPc.isArrowpointAllowed1(x, y, knowledge) && + VcPc.isArrowpointAllowed1(z, y, knowledge); } public static boolean isArrowpointAllowed1(Node from, Node to, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcAlt.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcAlt.java index 2f827646d2..7b23e40593 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcAlt.java @@ -36,7 +36,7 @@ * * @author Joseph Ramsey (this version). */ -public final class VcpcAlt implements GraphSearch { +public final class VcPcAlt implements GraphSearch { /** * The independence test used for the PC search. @@ -96,7 +96,7 @@ public final class VcpcAlt implements GraphSearch { * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the * independence test, for fear of duplicating the data set! */ - public VcpcAlt(IndependenceTest independenceTest) { + public VcPcAlt(IndependenceTest independenceTest) { if (independenceTest == null) { throw new NullPointerException(); } @@ -451,7 +451,7 @@ private Set boundary(Node x, Graph graph) { private Set future(Node x, Graph graph) { Set futureNodes = new HashSet<>(); LinkedList path = new LinkedList<>(); - VcpcAlt.futureNodeVisit(graph, x, path, futureNodes); + VcPcAlt.futureNodeVisit(graph, x, path, futureNodes); futureNodes.remove(x); List adj = graph.getAdjacentNodes(x); for (Node y : adj) { @@ -495,7 +495,7 @@ public static void futureNodeVisit(Graph graph, Node b, LinkedList path, S } else { Node a = path.get(size - 2); Edge edge1 = graph.getEdge(a, b); - c = VcpcAlt.traverseFuturePath(b, edge1, edge2); + c = VcPcAlt.traverseFuturePath(b, edge1, edge2); } if (c == null) { continue; @@ -503,7 +503,7 @@ public static void futureNodeVisit(Graph graph, Node b, LinkedList path, S if (path.contains(c)) { continue; } - VcpcAlt.futureNodeVisit(graph, c, path, futureNodes); + VcPcAlt.futureNodeVisit(graph, c, path, futureNodes); } path.removeLast(); } @@ -585,8 +585,8 @@ private void orientUnshieldedTriples(Knowledge knowledge, } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return VcpcAlt.isArrowpointAllowed1(x, y, knowledge) && - VcpcAlt.isArrowpointAllowed1(z, y, knowledge); + return VcPcAlt.isArrowpointAllowed1(x, y, knowledge) && + VcPcAlt.isArrowpointAllowed1(z, y, knowledge); } public static boolean isArrowpointAllowed1(Node from, Node to, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcFast.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcFast.java index 0d440084b9..ed4ce1fa67 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcFast.java @@ -38,7 +38,7 @@ * * @author Joseph Ramsey (this version). */ -public final class VcpcFast implements GraphSearch { +public final class VcPcFast implements GraphSearch { /** * The independence test used for the PC search. @@ -109,7 +109,7 @@ public final class VcpcFast implements GraphSearch { * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the * independence test, for fear of duplicating the data set! */ - public VcpcFast(IndependenceTest independenceTest) { + public VcPcFast(IndependenceTest independenceTest) { if (independenceTest == null) { throw new NullPointerException(); } @@ -472,7 +472,7 @@ private Set boundary(Node x, Graph graph) { private Set future(Node x, Graph graph) { Set futureNodes = new HashSet<>(); LinkedList path = new LinkedList<>(); - VcpcFast.futureNodeVisit(graph, x, path, futureNodes); + VcPcFast.futureNodeVisit(graph, x, path, futureNodes); futureNodes.remove(x); List adj = graph.getAdjacentNodes(x); for (Node y : adj) { @@ -518,7 +518,7 @@ public static void futureNodeVisit(Graph graph, Node b, LinkedList path, S } else { Node a = path.get(size - 2); Edge edge1 = graph.getEdge(a, b); - c = VcpcFast.traverseFuturePath(b, edge1, edge2); + c = VcPcFast.traverseFuturePath(b, edge1, edge2); } if (c == null) { continue; @@ -526,7 +526,7 @@ public static void futureNodeVisit(Graph graph, Node b, LinkedList path, S if (path.contains(c)) { continue; } - VcpcFast.futureNodeVisit(graph, c, path, futureNodes); + VcPcFast.futureNodeVisit(graph, c, path, futureNodes); } path.removeLast(); } @@ -699,8 +699,8 @@ public enum CpcTripleType { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return VcpcFast.isArrowpointAllowed1(x, y, knowledge) && - VcpcFast.isArrowpointAllowed1(z, y, knowledge); + return VcPcFast.isArrowpointAllowed1(x, y, knowledge) && + VcPcFast.isArrowpointAllowed1(z, y, knowledge); } public static boolean isArrowpointAllowed1(Node from, Node to, From f5ac719a40990e79a79f67d51645b5db82f0e4f1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 15:56:19 -0400 Subject: [PATCH 193/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Washdown.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Washdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Washdown.java index 5ea8836c64..8dbb3497b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Washdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Washdown.java @@ -63,24 +63,37 @@ */ public class Washdown { - private ICovarianceMatrix cov; private DataSet dataSet; private final List variables; private final double alpha; + /** + * Constructor. + * @param cov The covaraince matrix. + * @param alpha The alpha cutoff level. + */ public Washdown(ICovarianceMatrix cov, double alpha) { this.cov = cov; this.variables = cov.getVariables(); this.alpha = alpha; } + /** + * Constructor. + * @param data The dataset. + * @param alpha The alpha cutoff level. + */ public Washdown(DataSet data, double alpha) { this.dataSet = data; this.variables = data.getVariables(); this.alpha = alpha; } + /** + * Runs the Washdown algorithm and return a graph. + * @return The graph. + */ public Graph search() { List> clusters = new ArrayList<>(); clusters.add(new ArrayList<>(this.variables)); From 75c247c7eb6333f7b649133af74b4044cb9f1395 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 16:00:15 -0400 Subject: [PATCH 194/464] Fixing documentation etc. --- .../java/edu/cmu/tetrad/search/SepsetMap.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java index 6028da4919..dc88f58d21 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java @@ -45,20 +45,22 @@ public final class SepsetMap implements TetradSerializable { static final long serialVersionUID = 23L; - /** - * @serial - */ private Map, List> sepsets = new ConcurrentHashMap<>(); private Map, Double> pValues = new ConcurrentHashMap<>(); private final Map> parents = new HashMap<>(); -// private Set> correlations; -// private boolean returnEmptyIfNotSet = false; //=============================CONSTRUCTORS===========================// + /** + * Constructor. + */ public SepsetMap() { } + /** + * Copy constructor. + * @param map A given sepset map. + */ public SepsetMap(SepsetMap map) { this.sepsets = new HashMap<>(map.sepsets); this.pValues = new HashMap<>(map.pValues); @@ -98,6 +100,9 @@ public List get(Node a, Node b) { return this.sepsets.get(pair); } + /** + * Looks up the p-value for {x, y} + */ public double getPValue(Node x, Node y) { Set pair = new HashSet<>(2); pair.add(x); @@ -106,6 +111,9 @@ public double getPValue(Node x, Node y) { return this.pValues.get(pair); } + /** + * Sets the parents of x to the (ordered) set z. + */ public void set(Node x, LinkedHashSet z) { if (this.parents.get(x) != null) { this.parents.get(x).addAll(z); @@ -114,10 +122,16 @@ public void set(Node x, LinkedHashSet z) { } } + /** + * Returns the parents of the node x. + */ public HashSet get(Node x) { return this.parents.get(x) == null ? new HashSet<>() : this.parents.get(x); } + /** + * Checks equality of this to another sepset map. + */ public boolean equals(Object o) { if (o == null) { return false; @@ -148,14 +162,23 @@ private void readObject(ObjectInputStream s) } } + /** + * Returns the number of {x, y} in the keyset of the map. + */ public int size() { return this.sepsets.keySet().size(); } + /** + * Returns a string representation of this sepset map. + */ public String toString() { return this.sepsets.toString(); } + /** + * Adds all entries in the given sepset map to the current one. + */ public void addAll(SepsetMap newSepsets) { this.sepsets.putAll(newSepsets.sepsets); } From d02d375353e9cf455a3c5ffae3c006e8f0f33736 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 16:03:08 -0400 Subject: [PATCH 195/464] Fixing documentation etc. --- .../main/java/edu/cmu/tetrad/search/Sp.java | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 35445d2c35..b13af3b08c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -92,9 +92,48 @@ public void searchSuborder(List prefix, List suborder, Map getVariables() { + return variables; + } + + /** + * Returns the map from nodes to their parents. + * @return This map. + */ + @Override + public Map> getParents() { + return parents; + } + + /** + * Returns the score being used for this search. + * @return This score. + * @see Score + */ + @Override + public Score getScore() { + return score; + } + private void makeValidKnowledgeOrder(List order) { if (!this.knowledge.isEmpty()) { order.sort((a, b) -> { @@ -120,11 +159,6 @@ private boolean violatesKnowledge(List suborder, Map> requ return false; } - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - private double update(List prefix, List suborder) { double score = 0; @@ -141,21 +175,6 @@ private double update(List prefix, List suborder) { return score; } - @Override - public List getVariables() { - return variables; - } - - @Override - public Map> getParents() { - return parents; - } - - @Override - public Score getScore() { - return score; - } - private static class SwapIterator implements Iterator { private int[] next; private final int n; From 4d8ffd7c87754b3ecffc849a1b713438362fa044 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 3 May 2023 16:07:01 -0400 Subject: [PATCH 196/464] Fixing documentation etc. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java index ff128c02a1..8e53e0f509 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java @@ -29,7 +29,7 @@ import java.util.Set; /** - * Represents a tetrad of variables, (i, j, k, l). + * Represents a ordered tetrad of variables, (i, j, k, l). * * @author josephramsey */ From 32a3ed5865f861732da83765e86682a8988d42f9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 10:59:21 -0400 Subject: [PATCH 197/464] Fixing documentation etc. --- .../comparegraphs/CompareTwoGraphs.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java new file mode 100644 index 0000000000..780eaaf7ac --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java @@ -0,0 +1,32 @@ +package edu.cmu.tetrad.algcomparison.comparegraphs; + +import edu.cmu.tetrad.algcomparison.statistic.Statistic; +import edu.cmu.tetrad.graph.Graph; + +import java.util.List; + +public class CompareTwoGraphs { + public enum CompareTo {DAG, CPDAG, PAG} +// public enum ComparisonType {STATS_LIST, } + + private final Graph target; + private final Graph reference; + private List statistics; + + private CompareTo compareTo = CompareTo.DAG; + + public CompareTwoGraphs(Graph target, Graph reference) { + this.target = target; + this.reference = reference; + } + + public void addStatistic(Statistic statistic) { + this.statistics.add(statistic); + } + + public void setGraphComparedTo(CompareTo compareTo) { + this.compareTo = compareTo; + } + + +} From 259b91b5740aadf44f54b886da02b1ac196c8245 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 11:33:45 -0400 Subject: [PATCH 198/464] Fixing documentation etc. --- .../comparegraphs/CompareTwoGraphs.java | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java index 780eaaf7ac..8bfbf58157 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/comparegraphs/CompareTwoGraphs.java @@ -6,27 +6,69 @@ import java.util.List; public class CompareTwoGraphs { - public enum CompareTo {DAG, CPDAG, PAG} -// public enum ComparisonType {STATS_LIST, } + + + public enum CompareToType {DAG, CPDAG, PAG} + public enum ComparisonType {STATS_LIST, EDGEWISE, MISCLASSIFICATTONS} private final Graph target; private final Graph reference; private List statistics; - private CompareTo compareTo = CompareTo.DAG; + private CompareToType compareToType = CompareToType.DAG; + private ComparisonType comparisontype = ComparisonType.STATS_LIST; public CompareTwoGraphs(Graph target, Graph reference) { this.target = target; this.reference = reference; } + public void setCompareToType(CompareToType compareTo) { + this.compareToType = compareTo; + } + + public void setComparisontype(ComparisonType comparisontype) { + this.comparisontype = comparisontype; + } + public void addStatistic(Statistic statistic) { this.statistics.add(statistic); } - public void setGraphComparedTo(CompareTo compareTo) { - this.compareTo = compareTo; + + /** + * Returns a string comparing 'target' to 'reference' using the given comparison method. + * If type comparison method is 'stats list', a list of comparison statistics will be + * printed out using the stats added via the 'addStatistic' method. These stats will not + * be used for the other comparison methods. The type of graph compared to (DAG, + * CPDAG, PAG) can be set using the 'setCompareTotype' method. + * @return This string, which can be printed. + * @see #setCompareToType(CompareToType) + * @see #setComparisontype(ComparisonType) + * @see #addStatistic(Statistic) + */ + public String getComparisonString() { + switch (comparisontype) { + case STATS_LIST: + return statsListString(); + case EDGEWISE: + return edgewiseString(); + case MISCLASSIFICATTONS: + return misclassificationsString(); + default: + throw new IllegalStateException("Unsupported comparison type: " + comparisontype); + } } + private String statsListString() { + return "foo"; + } + private String edgewiseString() { + return "foo"; + } + + private String misclassificationsString() { + return "foo"; + } } From 6566d579ecc22d1094fa79854db9277e983e9abe Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 12:23:04 -0400 Subject: [PATCH 199/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetradapp/model/IndTestChooser.java | 16 +- .../model/PValueImproverWrapper.java | 3 + .../algorithm/oracle/cpdag/Boss.java | 1 - .../tetrad/search/BayesUpdaterClassifier.java | 2 +- .../java/edu/cmu/tetrad/search/BdeScore.java | 2 +- .../java/edu/cmu/tetrad/search/BdeuScore.java | 2 +- .../cmu/tetrad/search/DiscreteBicScore.java | 2 +- ...lassifier.java => DiscreteClassifier.java} | 2 +- ...IDiscreteScore.java => DiscreteScore.java} | 2 +- .../java/edu/cmu/tetrad/search/FgesMb.java | 8 +- .../edu/cmu/tetrad/search/FgesOrienter.java | 6 +- .../java/edu/cmu/tetrad/search/Grasp.java | 3 - .../edu/cmu/tetrad/search/GrowShrinkTree.java | 3 +- .../edu/cmu/tetrad/search/ImagesScore.java | 119 +++++---- .../edu/cmu/tetrad/search/MbClassify.java | 2 +- .../java/edu/cmu/tetrad/search/Score.java | 4 - .../cmu/tetrad/search/SemBicScoreImages.java | 230 ------------------ .../edu/cmu/tetrad/search/ShiftSearch.java | 11 +- .../edu/cmu/tetrad/search/TeyssierScorer.java | 2 - .../java/edu/cmu/tetrad/search/TsFges.java | 8 +- .../{ => work_in_progress}/DMSearch.java | 6 +- .../search/{ => work_in_progress}/Dci.java | 3 +- .../search/{ => work_in_progress}/FasDci.java | 5 +- .../{ => work_in_progress}/HbmsBeam.java | 4 +- .../search/{ => work_in_progress}/Hbsms.java | 2 +- .../{ => work_in_progress}/HbsmsGes.java | 5 +- .../test/java/edu/cmu/tetrad/test/TestDM.java | 2 +- 27 files changed, 137 insertions(+), 318 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IDiscreteClassifier.java => DiscreteClassifier.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IDiscreteScore.java => DiscreteScore.java} (97%) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreImages.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/DMSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Dci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/FasDci.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/HbmsBeam.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Hbsms.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/HbsmsGes.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index 7b53811246..91cd81c968 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -147,9 +147,9 @@ private IndependenceTest getMultiContinuousTest(List dataSets, if (IndTestType.TIPPETT == testType) { List independenceTests = new ArrayList<>(); - for (DataModel dataModel : dataSets) { - DataSet dataSet = (DataSet) dataModel; - independenceTests.add(new IndTestFisherZ(dataSet, params.getDouble("alpha", 0.001))); + for (DataSet dataModel : dataSets) { + independenceTests.add(new IndTestFisherZ(dataModel, params.getDouble("alpha", + 0.001))); } return new IndTestMulti(independenceTests, ResolveSepsets.Method.tippett); @@ -160,8 +160,14 @@ private IndependenceTest getMultiContinuousTest(List dataSets, } if (IndTestType.SEM_BIC == testType) { - List dataModels = new ArrayList<>(dataSets); - return new IndTestScore(new SemBicScoreImages(dataModels)); + List scores = new ArrayList<>(); + for (DataSet dataSet : dataSets) { + SemBicScore _score = new SemBicScore(dataSet); + scores.add(_score); + } + + ImagesScore imagesScore = new ImagesScore(scores); + return new IndTestScore(imagesScore); } { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index 00a2bedc0f..1d214dc37c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.work_in_progress.HbmsBeam; +import edu.cmu.tetrad.search.work_in_progress.Hbsms; +import edu.cmu.tetrad.search.work_in_progress.HbsmsGes; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.*; 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 bb8e294149..a9d414afec 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 @@ -7,7 +7,6 @@ import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; import edu.cmu.tetrad.annotation.AlgType; 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; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java index a695394a60..4494a07adf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java @@ -46,7 +46,7 @@ * @author Frank Wimberly based on a specification by Clark Glymour */ public final class BayesUpdaterClassifier - implements IDiscreteClassifier, TetradSerializable { + implements DiscreteClassifier, TetradSerializable { static final long serialVersionUID = 23L; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java index 6c241397e0..a85c46f937 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java @@ -33,7 +33,7 @@ * * @author josephramsey */ -public class BdeScore implements IDiscreteScore { +public class BdeScore implements DiscreteScore { private final DataSet dataSet; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java index 5d9bb38b79..ee61e5bee2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java @@ -33,7 +33,7 @@ /** * Calculates the BDeu score. */ -public class BdeuScore implements IDiscreteScore { +public class BdeuScore implements DiscreteScore { private final int[][] data; private final int sampleSize; private final int[] numCategories; 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 f0f110587e..9495e3e723 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 @@ -35,7 +35,7 @@ * Calculates the discrete BIC score. * @author josephramsey */ -public class DiscreteBicScore implements IDiscreteScore { +public class DiscreteBicScore implements DiscreteScore { private final DataSet dataSet; private List variables; private final int[][] data; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteClassifier.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java index 576ad4721b..938686c9e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java @@ -27,7 +27,7 @@ * * @author Frank Wimberly */ -public interface IDiscreteClassifier { +public interface DiscreteClassifier { /** * @return an array with a classification (estimated value) of a target variable for each case in a DataSet. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java index bbac76ba4c..e13d6d5d2e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IDiscreteScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java @@ -27,7 +27,7 @@ * Created by IntelliJ IDEA. User: jdramsey Date: Jul 6, 2009 Time: 3:58:26 PM To change this template use File | * Settings | File Templates. */ -public interface IDiscreteScore extends Score { +public interface DiscreteScore extends Score { void setStructurePrior(double structurePrior); void setSamplePrior(double samplePrior); DataSet getDataSet(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index 7bc98d07bd..e933d24046 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -560,8 +560,8 @@ public void setPenaltyDiscount(double penaltyDiscount) { * @deprecated Use the setters on the individual scores instead. */ public void setSamplePrior(double samplePrior) { - if (this.fgesScore instanceof IDiscreteScore) { - ((IDiscreteScore) this.fgesScore).setSamplePrior(samplePrior); + if (this.fgesScore instanceof DiscreteScore) { + ((DiscreteScore) this.fgesScore).setSamplePrior(samplePrior); } } @@ -569,8 +569,8 @@ public void setSamplePrior(double samplePrior) { * @deprecated Use the setters on the individual scores instead. */ public void setStructurePrior(double expectedNumParents) { - if (this.fgesScore instanceof IDiscreteScore) { - ((IDiscreteScore) this.fgesScore).setStructurePrior(expectedNumParents); + if (this.fgesScore instanceof DiscreteScore) { + ((DiscreteScore) this.fgesScore).setStructurePrior(expectedNumParents); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java index f12f2bfa02..a6da0954f7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java @@ -108,7 +108,7 @@ public final class FgesOrienter implements GraphSearch, GraphScorer { /** * The score for discrete searches. */ - private IDiscreteScore IDiscreteScore; + private DiscreteScore IDiscreteScore; /** * The logger for this class. The config needs to be set. @@ -379,14 +379,14 @@ public int getnumCPDAGsToStore() { /** * @return the discrete scoring function being used. By default, BDeu. */ - public IDiscreteScore getDiscreteScore() { + public DiscreteScore getDiscreteScore() { return this.IDiscreteScore; } /** * Sets the discrete scoring function to use. */ - public void setDiscreteScore(IDiscreteScore IDiscreteScore) { + public void setDiscreteScore(DiscreteScore IDiscreteScore) { this.IDiscreteScore = IDiscreteScore; } 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 88e8eced5f..a454b3e0bf 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 @@ -1,15 +1,12 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; import org.jetbrains.annotations.NotNull; -import javax.swing.*; import java.text.NumberFormat; import java.util.*; 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 1ac1d93b64..e2222634bd 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,6 +1,5 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Node; import org.jetbrains.annotations.NotNull; @@ -15,7 +14,7 @@ public class GrowShrinkTree { private List forbidden; private GSTNode root; - public GrowShrinkTree(Score score, Map index, Node node) { + public GrowShrinkTree(Score score, Map index, Node node) { this.score = score; this.index = index; this.node = node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java index ecaf2851a7..bffc5a8ed5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java @@ -21,7 +21,6 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; import java.util.List; @@ -29,9 +28,22 @@ import static org.apache.commons.math3.util.FastMath.log; /** - * Implements a score to average results over multiple scores. + *

Implements a score to average results over multiple scores. This is + * used for the IMaGES algorithm. The idea is that one pick and algorithm + * that takes (only) a score as input, such as FGES or GRaSP or BOSS, + * and then constructs an ImagesScore (which class) with a list of + * datasets as input, feeds this ImagesScore to this algorithm through + * the contructor, and then runs the algorithm to get an estimate + * of the structure.

+ *

Importantly, only the variables from the first score will be + * returned from the getVariables method, so it is up to the user to + * ensure that all of the scores share the same (object-identical) + * variables.

* * @author Joseph Ramsey + * @see Fges + * @see Grasp + * @see Boss */ public class ImagesScore implements Score { @@ -41,16 +53,10 @@ public class ImagesScore implements Score { // The variables of the covariance matrix. private final List variables; - private final int sampleSize; - - // The penalty penaltyDiscount. - private double penaltyDiscount = 2.0; - - // True if verbose output should be sent to out. - private boolean verbose; - /** - * Constructs the score using a covariance matrix. + * Constructs an IMaGES score using the given list of individual scores. + * These scores will be be averaged to obtain the IMaGES score itself. + * @param scores The list of scores. */ public ImagesScore(List scores) { if (scores == null) { @@ -60,24 +66,39 @@ public ImagesScore(List scores) { this.scores = scores; this.variables = scores.get(0).getVariables(); - this.sampleSize = scores.get(0).getSampleSize(); } - + /** + * Returns the average of the individual scores returned from each + * component score from their localScoreDiff methods. Score differences + * that are returned as undefined (NaN) are excluded from the + * average. + * @return This average score. + */ @Override public double localScoreDiff(int x, int y, int[] z) { double sum = 0.0; + int count = 0; for (Score score : this.scores) { - sum += score.localScoreDiff(x, y, z); + double _score = score.localScoreDiff(x, y, z); + + if (Double.isNaN(_score)) { + sum += _score; + count++; + } } - return sum; + return sum / count; } - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model + * Returns the (aggregate) local score for a variable given its parents, + * which is obtained by averaging the local such scores obtained from each + * individual score provided in the constructor, excluding scores that are + * returned as undefined (which are left out of the average). + * @param i The variable whose score is needed. + * @return This score. */ public double localScore(int i, int[] parents) { double sum = 0.0; @@ -105,12 +126,13 @@ public double localScore(int i, int[] parents, int index) { return localScoreOneDataSet(i, parents, index); } - private double localScoreOneDataSet(int i, int[] parents, int index) { - return this.scores.get(index).localScore(i, parents); - } - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. + * Returns the (aggregate) local score for a variable given one of its + * parents, which is obtained by averaging the local such scores obtained + * from each individual score provided in the constructor, excluding scores + * that are returned as undefined (which are left out of the average). + * @param i The variable whose score is needed. + * @return This score. */ public double localScore(int i, int parent) { double sum = 0.0; @@ -128,7 +150,14 @@ public double localScore(int i, int parent) { return sum / count; } - + /** + * Returns the (aggregate) local node score, which is obtained by + * averaging the local scores obtained from each individual score + * provided in the constructor, excluding scores that are returned + * as undefined (which are left out of the average). + * @param i The variable whose score is needed. + * @return This score. + */ public double localScore(int i) { double sum = 0.0; int count = 0; @@ -145,45 +174,49 @@ public double localScore(int i) { return sum / count; } - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - @Override public boolean isEffectEdge(double bump) { - return bump > -0.25 * getPenaltyDiscount() * log(this.sampleSize); - } - - public DataSet getDataSet() { - throw new UnsupportedOperationException(); - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; + return scores.get(0).isEffectEdge(bump); } + /** + * Returns the variables. + * @return This list. + */ @Override public List getVariables() { return this.variables; } + /** + * Returns the sample size from the first score. + * @return This size. + */ @Override public int getSampleSize() { - return this.sampleSize; + return scores.get(0).getSampleSize(); } + /** + * Returns the max degree from teh first score. + * @return This maximum. + */ @Override public int getMaxDegree() { - return 1000; + return scores.get(0).getMaxDegree(); } + /** + * Returns the 'determines' judgment from the first score. + * @return This judgment, true if the 'determine' relations holds. + */ @Override public boolean determines(List z, Node y) { - return false; + return scores.get(0).determines(z, y); + } + + private double localScoreOneDataSet(int i, int[] parents, int index) { + return this.scores.get(index).localScore(i, parents); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java index ba225ec4d3..cc0f5e333d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java @@ -47,7 +47,7 @@ * @author Frank Wimberly * @author Joseph Ramsey */ -public class MbClassify implements IDiscreteClassifier { +public class MbClassify implements DiscreteClassifier { private DataSet train; private DataSet test; private Node target; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Score.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Score.java index a4c05cf84b..e4df41aed2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Score.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Score.java @@ -89,9 +89,5 @@ default int getMaxDegree() { default boolean determines(List z, Node y) { throw new UnsupportedOperationException("Method determines() is not implemented for this score."); } - - default Score defaultScore() { - return this; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreImages.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreImages.java deleted file mode 100644 index 1adf1bb318..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreImages.java +++ /dev/null @@ -1,230 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.graph.Node; -import org.apache.commons.math3.util.FastMath; - -import java.util.ArrayList; -import java.util.List; - -/** - * Implements the continuous BIC score for FGES. - * - * @author Joseph Ramsey - */ -public class SemBicScoreImages implements ISemBicScore { - - // The covariance matrix. - private final List semBicScores; - - // The variables of the covariance matrix. - private final List variables; - - private final int sampleSize; - - // The penalty penaltyDiscount. - private double penaltyDiscount = 2.0; - - // True if verbose output should be sent to out. - private boolean verbose; - - /** - * Constructs the score using a covariance matrix. - */ - public SemBicScoreImages(List dataModels) { - if (dataModels == null) { - throw new NullPointerException(); - } - - List semBicScores = new ArrayList<>(); - - for (DataModel model : dataModels) { - if (model instanceof DataSet) { - DataSet dataSet = (DataSet) model; - - if (!dataSet.isContinuous()) { - throw new IllegalArgumentException("Datasets must be continuous."); - } - - SemBicScore semBicScore = new SemBicScore(dataSet); - semBicScore.setPenaltyDiscount(this.penaltyDiscount); - semBicScores.add(semBicScore); - } else if (model instanceof ICovarianceMatrix) { - SemBicScore semBicScore = new SemBicScore((ICovarianceMatrix) model); - semBicScore.setPenaltyDiscount(this.penaltyDiscount); - semBicScores.add(semBicScore); - } else { - throw new IllegalArgumentException("Only continuous data sets and covariance matrices may be used as input."); - } - } - - List variables = semBicScores.get(0).getVariables(); - - for (int i = 2; i < semBicScores.size(); i++) { - semBicScores.get(i).setVariables(variables); - } - - this.semBicScores = semBicScores; - this.variables = variables; - this.sampleSize = semBicScores.get(0).getSampleSize(); - } - - - @Override - public double localScoreDiff(int x, int y, int[] z) { - double sum = 0.0; - - for (SemBicScore score : this.semBicScores) { - sum += score.localScoreDiff(x, y, z); - } - - return sum / this.semBicScores.size(); - } - - - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model - */ - public double localScore(int i, int[] parents) { - double sum = 0.0; - int count = 0; - - for (SemBicScore score : this.semBicScores) { - double _score = score.localScore(i, parents); - - if (!Double.isNaN(_score)) { - sum += _score; - count++; - } - } - - double score = sum / count; - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; - } - } - - public double localScore(int i, int[] parents, int index) { - return localScoreOneDataSet(i, parents, index); - } - - private double localScoreOneDataSet(int i, int[] parents, int index) { - return this.semBicScores.get(index).localScore(i, parents); - } - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - public double localScore(int i, int parent) { - double sum = 0.0; - int count = 0; - - for (SemBicScore score : this.semBicScores) { - double _score = score.localScore(i, parent); - - if (!Double.isNaN(_score)) { - sum += _score; - count++; - } - } - - return sum / count; - } - - - public double localScore(int i) { - double sum = 0.0; - int count = 0; - - for (SemBicScore score : this.semBicScores) { - double _score = score.localScore(i); - - if (!Double.isNaN(_score)) { - sum += _score; - count++; - } - } - - return sum / count; - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > -0.25 * getPenaltyDiscount() * FastMath.log(this.sampleSize); - } - - public DataSet getDataSet() { - throw new UnsupportedOperationException(); - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - for (SemBicScore score : this.semBicScores) { - score.setPenaltyDiscount(penaltyDiscount); - } - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public List getVariables() { - return this.variables; - } - - @Override - public int getSampleSize() { - return this.sampleSize; - } - - // Prints a smallest subset of parents that causes a singular matrix exception. - - - @Override - public int getMaxDegree() { - return 1000; - } - - @Override - public boolean determines(List z, Node y) { - return false; - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java index d45acfb1ef..f3ab84319c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java @@ -161,9 +161,14 @@ private List ensureNumRows(List dataSets, int numRows) { } private double getAvgBic(List dataSets) { - SemBicScoreImages fgesScore = new SemBicScoreImages(dataSets); - fgesScore.setPenaltyDiscount(this.c); - Fges images = new Fges(fgesScore); + List scores = new ArrayList<>(); + for (DataModel dataSet : dataSets) { + SemBicScore _score = new SemBicScore((DataSet) dataSet); + scores.add(_score); + } + + ImagesScore imagesScore = new ImagesScore(scores); + Fges images = new Fges(imagesScore); images.setKnowledge(this.knowledge); images.search(); return -images.getModelScore() / dataSets.size(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java index 7cdd20a96f..4ec9dc6f88 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java @@ -1,12 +1,10 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import org.jetbrains.annotations.NotNull; import java.util.*; -import java.util.concurrent.Callable; import static edu.cmu.tetrad.util.RandomUtil.shuffle; import static java.util.Collections.sort; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 4201bb41e3..0b3344bbba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -441,8 +441,8 @@ public double getPenaltyDiscount() { * @deprecated Use the setters on the individual scores instead. */ public void setSamplePrior(double samplePrior) { - if (this.score instanceof IDiscreteScore) { - ((IDiscreteScore) this.score).setSamplePrior(samplePrior); + if (this.score instanceof DiscreteScore) { + ((DiscreteScore) this.score).setSamplePrior(samplePrior); } } @@ -450,8 +450,8 @@ public void setSamplePrior(double samplePrior) { * @deprecated Use the setters on the individual scores instead. */ public void setStructurePrior(double expectedNumParents) { - if (this.score instanceof IDiscreteScore) { - ((IDiscreteScore) this.score).setStructurePrior(expectedNumParents); + if (this.score instanceof DiscreteScore) { + ((DiscreteScore) this.score).setStructurePrior(expectedNumParents); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DMSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DMSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java index 2910837b1d..8bdf7026c9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DMSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java @@ -1,9 +1,13 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.IndTestFisherZ; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SemBicScore; import org.apache.commons.math3.linear.SingularMatrixException; import java.io.File; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Dci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java index 2fd32ccf62..9bde31bdbd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java index f71aced11a..83661613ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java @@ -19,13 +19,16 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.ResolveSepsets; +import edu.cmu.tetrad.search.SepsetMapDci; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java index 5ba187c2d9..9e78fd2c85 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; @@ -29,6 +29,8 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionCovariance; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.MeekRules; +import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java index 6fd515823c..55f2bd655d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Hbsms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java index 0eb28936ee..cc3964480e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java @@ -19,11 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.DagInCpcagIterator; +import edu.cmu.tetrad.search.MeekRules; +import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.sem.DagScorer; import edu.cmu.tetrad.sem.Scorer; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java index 7ade354e2d..53c230d7a8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DMSearch; +import edu.cmu.tetrad.search.work_in_progress.DMSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; From fdc4b3659911295bfa27861ff00dcdbfdfa2f6a3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 12:38:43 -0400 Subject: [PATCH 200/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/FactorAnalysis.java | 32 ++-- .../cmu/tetrad/search/FasDeterministic.java | 115 +++++------- .../main/java/edu/cmu/tetrad/search/Fask.java | 176 +++++++----------- .../search/{ => work_in_progress}/FasFdr.java | 3 +- 4 files changed, 137 insertions(+), 189 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/FasFdr.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index e30b413f21..fb0f0f453e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -231,6 +231,22 @@ public void setThreshold(double threshold) { this.threshold = threshold; } + public double getThreshold() { + return this.threshold; + } + + public int getNumFactors() { + return this.numFactors; + } + + public void setNumFactors(int numFactors) { + this.numFactors = numFactors; + } + + public Matrix getResidual() { + return this.residual; + } + // ------------------Private methods-------------------// /** @@ -334,22 +350,6 @@ private static Matrix matrixExp(Matrix matrix, double exponent) { } return result; } - - public double getThreshold() { - return this.threshold; - } - - public int getNumFactors() { - return this.numFactors; - } - - public void setNumFactors(int numFactors) { - this.numFactors = numFactors; - } - - public Matrix getResidual() { - return this.residual; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index df2c022bdc..b1c5014deb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -32,17 +32,10 @@ import java.util.*; /** - * Implements the "fast adjacency search" used in several causal algorithm in this package. In the fast adjacency - * search, at a given stage of the search, an edge X*-*Y is removed from the graph if X _||_ Y | S, where S is a subset - * of size d either of adj(X) or of adj(Y), where d is the depth of the search. The fast adjacency search performs this - * procedure for each pair of adjacent edges in the graph and for each depth d = 0, 1, 2, ..., d1, where d1 is either - * the maximum depth or else the first such depth at which no edges can be removed. The interpretation of this adjacency - * search is different for different algorithm, depending on the assumptions of the algorithm. A mapping from {x, y} to - * S({x, y}) is returned for edges x *-* y that have been removed. - *

* This adjusts FAS for the deterministic case. * * @author Joseph Ramsey. + * @see Fas */ public class FasDeterministic implements IFas { @@ -120,8 +113,6 @@ public FasDeterministic(IndependenceTest test) { this.test = test; } - //==========================PUBLIC METHODS===========================// - /** * Discovers all adjacencies in data. The procedure is to remove edges in the graph which connect pairs of * variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are @@ -165,8 +156,6 @@ public Graph search() { } } -// out.println("Finished with search, constructing Graph..."); - for (int i = 0; i < nodes.size(); i++) { for (int j = i + 1; j < nodes.size(); j++) { Node x = nodes.get(i); @@ -178,8 +167,6 @@ public Graph search() { } } -// out.println("Finished constructing Graph."); - this.logger.log("info", "Finishing Fast Adjacency Search."); return this.graph; @@ -209,7 +196,55 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } - //==============================PRIVATE METHODS======================/ + public int getNumIndependenceTests() { + return this.numIndependenceTests; + } + + public int getNumDependenceJudgments() { + return this.numDependenceJudgement; + } + + public SepsetMap getSepsets() { + return this.sepset; + } + + public void setExternalGraph(Graph externalGraph) { + this.externalGraph = externalGraph; + } + + public boolean isVerbose() { + return this.verbose; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + @Override + public Graph search(List nodes) { + nodes = new ArrayList<>(nodes); + return null; + } + + @Override + public long getElapsedTime() { + return 0; + } + + @Override + public List getNodes() { + return this.test.getVariables(); + } + + @Override + public List getAmbiguousTriples(Node node) { + return null; + } + + @Override + public void setOut(PrintStream out) { + this.out = out; + } private boolean searchAtDepth0(List nodes, IndependenceTest test, Map> adjacencies) { List empty = Collections.emptyList(); @@ -395,56 +430,6 @@ private List possibleParents(Node x, List adjx, private boolean possibleParentOf(String z, String x, Knowledge knowledge) { return !knowledge.isForbidden(z, x) && !knowledge.isRequired(x, z); } - - public int getNumIndependenceTests() { - return this.numIndependenceTests; - } - - public int getNumDependenceJudgments() { - return this.numDependenceJudgement; - } - - public SepsetMap getSepsets() { - return this.sepset; - } - - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - return null; - } - - @Override - public long getElapsedTime() { - return 0; - } - - @Override - public List getNodes() { - return this.test.getVariables(); - } - - @Override - public List getAmbiguousTriples(Node node) { - return null; - } - - @Override - public void setOut(PrintStream out) { - this.out = out; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 89ee11d623..4bb8ded2ae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -125,6 +125,16 @@ */ public final class Fask implements GraphSearch { + // The method to use for finding the adjacencies. + public enum AdjacencyMethod {FAS_STABLE, FGES, EXTERNAL_GRAPH, NONE} + + // The left-right rule to use. Options include the FASK left-right rule and three left-right rules + // from the Hyvarinen and Smith pairwise orientation paper: Robust Skew, Skew, and Tanh. In that + // paper, "empirical" versions were given in which the variables are multiplied through by the + // signs of the skewnesses; we follow this advice here (with good results). These others are provided + // for comparison; in general they are quite good. + public enum LeftRight {FASK1, FASK2, RSKEW, SKEW, TANH} + // The score to be used for the FAS adjacency search. private final IndependenceTest test; private final Score score; @@ -133,7 +143,7 @@ public final class Fask implements GraphSearch { private final DataSet dataSet; // Used for calculating coefficient values. private final RegressionDataset regressionDataset; - double[][] D; + private double[][] D; // An initial graph to constrain the adjacency step. private Graph externalGraph; // Elapsed time of the search, in milliseconds. @@ -197,43 +207,8 @@ public Fask(DataSet dataSet, Score score, IndependenceTest test) { this.orientationAlpha = 0.01; } - private static double cu(double[] x, double[] y, double[] condition) { - double exy = 0.0; - - int n = 0; - - for (int k = 0; k < x.length; k++) { - if (condition[k] > 0) { - exy += x[k] * y[k]; - n++; - } - } - - return exy / n; - } - - // Returns E(XY | Z > 0) / sqrt(E(XX | Z > 0) * E(YY | Z > 0)). Z is typically either X or Y. - private static double correxp(double[] x, double[] y, double[] z) { - return Fask.E(x, y, z) / sqrt(Fask.E(x, x, z) * Fask.E(y, y, z)); - } - //======================================== PUBLIC METHODS ====================================// - // Returns E(XY | Z > 0); Z is typically either X or Y. - private static double E(double[] x, double[] y, double[] z) { - double exy = 0.0; - int n = 0; - - for (int k = 0; k < x.length; k++) { - if (z[k] > 0) { - exy += x[k] * y[k]; - n++; - } - } - - return exy / n; - } - /** * Runs the search on the concatenated data, returning a graph, possibly cyclic, possibly with * two-cycles. Runs the fast adjacency search (FAS, Spirtes et al., 2000) follows by a modification @@ -251,7 +226,6 @@ public Graph search() { List variables = dataSet.getVariables(); double[][] lrs = getLrScores(); // Sets D. -// D = dataSet.getDoubleData().transpose().toArray(); for (int i = 0; i < variables.size(); i++) { System.out.println("Skewness of " + variables.get(i) + " = " + skewness(this.D[i])); @@ -398,24 +372,7 @@ public Graph search() { graph.addDirectedEdge(Y, X); logTwoCycle(nf, variables, this.D, X, Y, "2-cycle Pre-screen"); } - } -// else if (twoCycleScreeningCutoff == 0 && orientationAlpha > 0) { -// for (Edge edge : graph.getEdges()) { -// Node X = edge.getNode1(); -// Node Y = edge.getNode2(); -// -// int i = variables.indexOf(X); -// int j = variables.indexOf(Y); -// -// if (twoCycleTest(i, j, D, graph, variables)) { -// graph.removeEdges(X, Y); -// graph.addDirectedEdge(X, Y); -// graph.addDirectedEdge(Y, X); -// logTwoCycle(nf, variables, D, X, Y, "2-cycle Tested"); -// } -// } -// } - else if (this.twoCycleScreeningCutoff > 0 && this.orientationAlpha > 0) { + } else if (this.twoCycleScreeningCutoff > 0 && this.orientationAlpha > 0) { for (NodePair edge : twoCycles) { Node X = edge.getFirst(); Node Y = edge.getSecond(); @@ -440,21 +397,6 @@ else if (this.twoCycleScreeningCutoff > 0 && this.orientationAlpha > 0) { return graph; } - private void logTwoCycle(NumberFormat nf, List variables, double[][] d, Node X, Node Y, String type) { - int i = variables.indexOf(X); - int j = variables.indexOf(Y); - - double[] x = d[i]; - double[] y = d[j]; - - double lr = leftRight(x, y); - - TetradLogger.getInstance().forceLogMessage(X + "\t" + Y + "\t" + type - + "\t" + nf.format(lr) - + "\t" + X + "<=>" + Y - ); - } - /** * Returns the coefficient matrix for the search. If the search has not yet run, runs it, * then estimates coefficients of each node given its parents using linear regression and forms @@ -535,7 +477,7 @@ public Knowledge getKnowledge() { * @param knowledge Knowledge of forbidden and required edges. */ public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } public Graph getExternalGraph() { @@ -579,32 +521,14 @@ public void setEmpirical(boolean empirical) { this.empirical = empirical; } - - //======================================== PRIVATE METHODS ====================================// - - public double leftRight(Node X, Node Y) { - List variables = this.dataSet.getVariables(); - - int i = -1; - - for (int k = 0; k < variables.size(); k++) { - if (X.getName().equals(variables.get(k).getName())) i = k; - } - - int j = -1; - - for (int k = 0; k < variables.size(); k++) { - if (Y.getName().equals(variables.get(k).getName())) j = k; - } - - double[] x = this.D[i]; - double[] y = this.D[j]; - - return leftRight(x, y); - - } - - private double leftRight(double[] x, double[] y) { + /** + * A left/right judgment for double[] arrays (data) as input. + * @param x The data for the first variable. + * @param y The data for the second variable. + * @return The left-right judgment, which is negative if X<-Y, positive if X->Y, and + * 0 if indeterminate. + */ + public double leftRight(double[] x, double[] y) { if (this.leftRight == LeftRight.FASK1) { return faskLeftRightV1(x, y); } else if (this.leftRight == LeftRight.FASK2) { @@ -630,8 +554,6 @@ private double faskLeftRightV2(double[] x, double[] y) { lr *= signum(sx) * signum(sy); } -// lr *= signum(r); - if (r < this.delta) { lr *= -1; } @@ -827,15 +749,55 @@ private double partialCorrelation(double[] x, double[] y, double[][] z, double[] return StatUtils.partialCorrelation(m); } - // The method to use for finding the adjacencies. - public enum AdjacencyMethod {FAS_STABLE, FGES, EXTERNAL_GRAPH, NONE} + private void logTwoCycle(NumberFormat nf, List variables, double[][] d, Node X, Node Y, String type) { + int i = variables.indexOf(X); + int j = variables.indexOf(Y); - // The left-right rule to use. Options include the FASK left-right rule and three left-right rules - // from the Hyvarinen and Smith pairwise orientation paper: Robust Skew, Skew, and Tanh. In that - // paper, "empirical" versions were given in which the variables are multiplied through by the - // signs of the skewnesses; we follow this advice here (with good results). These others are provided - // for comparison; in general they are quite good. - public enum LeftRight {FASK1, FASK2, RSKEW, SKEW, TANH} + double[] x = d[i]; + double[] y = d[j]; + + double lr = leftRight(x, y); + + TetradLogger.getInstance().forceLogMessage(X + "\t" + Y + "\t" + type + + "\t" + nf.format(lr) + + "\t" + X + "<=>" + Y + ); + } + + private static double cu(double[] x, double[] y, double[] condition) { + double exy = 0.0; + + int n = 0; + + for (int k = 0; k < x.length; k++) { + if (condition[k] > 0) { + exy += x[k] * y[k]; + n++; + } + } + + return exy / n; + } + + // Returns E(XY | Z > 0); Z is typically either X or Y. + private static double E(double[] x, double[] y, double[] z) { + double exy = 0.0; + int n = 0; + + for (int k = 0; k < x.length; k++) { + if (z[k] > 0) { + exy += x[k] * y[k]; + n++; + } + } + + return exy / n; + } + + // Returns E(XY | Z > 0) / sqrt(E(XX | Z > 0) * E(YY | Z > 0)). Z is typically either X or Y. + private static double correxp(double[] x, double[] y, double[] z) { + return Fask.E(x, y, z) / sqrt(Fask.E(x, x, z) * Fask.E(y, y, z)); + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasFdr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java index 71999b5261..7f5f84c516 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; From 3f94824e3135d4db199d12347c9fb1851e3efcd5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 12:39:30 -0400 Subject: [PATCH 201/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java index a6a3f7d02d..697b08890f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java @@ -39,6 +39,7 @@ public final class FasLofs implements GraphSearch { private final Lofs2.Rule rule; + // Elapsed time of the search, in milliseconds. private long elapsed; From 023394ed7196c87e975fadb1436788dd167b4387 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 12:55:30 -0400 Subject: [PATCH 202/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetradapp/model/BuildPureClustersRunner.java | 1 + .../cmu/tetrad/search/{Fasts.java => FasTs.java} | 15 ++++----------- .../main/java/edu/cmu/tetrad/search/FgesMb.java | 8 ++++---- ...{ISemBicScore.java => HasPenaltyDiscount.java} | 3 +-- .../cmu/tetrad/search/SemBicScoreMultiFas.java | 2 +- .../main/java/edu/cmu/tetrad/search/SvarFci.java | 2 +- .../main/java/edu/cmu/tetrad/search/TsFges.java | 8 ++++---- .../BpcTetradPurifyWashdown.java | 3 ++- 8 files changed, 18 insertions(+), 24 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{Fasts.java => FasTs.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ISemBicScore.java => HasPenaltyDiscount.java} (75%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/BpcTetradPurifyWashdown.java (98%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index bfb11d08b6..3e187a2364 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.work_in_progress.BpcTetradPurifyWashdown; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasTs.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasTs.java index f236dd5035..96bd05ccc8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasTs.java @@ -33,22 +33,15 @@ import java.util.*; /** - * Implements the "fast adjacency search" used in several causal algorithm in this package. In the fast adjacency - * search, at a given stage of the search, an edge X*-*Y is removed from the graph if X _||_ Y | S, where S is a subset - * of size d either of adj(X) or of adj(Y), where d is the depth of the search. The fast adjacency search performs this - * procedure for each pair of adjacent edges in the graph and for each depth d = 0, 1, 2, ..., d1, where d1 is either - * the maximum depth or else the first such depth at which no edges can be removed. The interpretation of this adjacency - * search is different for different algorithm, depending on the assumptions of the algorithm. A mapping from {x, y} to - * S({x, y}) is returned for edges x *-* y that have been removed. - *

* This is a copy of Fas.java for the SvarFCI algorithm. The main difference is that if an edge is removed, it will also * remove all homologous edges to preserve the time-repeating structure assumed by SvarFCI. Based on (but not identicial * to) code by Entner and Hoyer for their 2010 paper. Modified by DMalinsky 4/21/2016. * * @author Joseph Ramsey. * @author DMalinsky + * @see Fas */ -public class Fasts implements IFas { +public class FasTs implements IFas { /** * The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node @@ -106,7 +99,7 @@ public class Fasts implements IFas { /** * Constructs a new FastAdjacencySearch. */ - public Fasts(Graph graph, IndependenceTest test) { + public FasTs(Graph graph, IndependenceTest test) { this.graph = graph; this.test = test; } @@ -114,7 +107,7 @@ public Fasts(Graph graph, IndependenceTest test) { /** * Constructs a new FastAdjacencySearch. */ - public Fasts(IndependenceTest test) { + public FasTs(IndependenceTest test) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index e933d24046..bb9b71d47e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -537,8 +537,8 @@ public void setParallelized(boolean parallelized) { * @deprecated Use the getters on the individual scores instead. */ public double getPenaltyDiscount() { - if (this.fgesScore instanceof ISemBicScore) { - return ((ISemBicScore) this.fgesScore).getPenaltyDiscount(); + if (this.fgesScore instanceof HasPenaltyDiscount) { + return ((HasPenaltyDiscount) this.fgesScore).getPenaltyDiscount(); } else { return 2.0; } @@ -551,8 +551,8 @@ public double getPenaltyDiscount() { * @deprecated Use the setters on the individual scores instead. */ public void setPenaltyDiscount(double penaltyDiscount) { - if (this.fgesScore instanceof ISemBicScore) { - ((ISemBicScore) this.fgesScore).setPenaltyDiscount(penaltyDiscount); + if (this.fgesScore instanceof HasPenaltyDiscount) { + ((HasPenaltyDiscount) this.fgesScore).setPenaltyDiscount(penaltyDiscount); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ISemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java similarity index 75% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ISemBicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java index ec1e199995..de1152dbff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ISemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java @@ -3,8 +3,7 @@ /** * Created by jdramsey on 2/21/16. */ -public interface ISemBicScore extends Score { +public interface HasPenaltyDiscount extends Score { void setPenaltyDiscount(double penaltyDiscount); - double getPenaltyDiscount(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java index dd8aef9886..ac5865a4dc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java @@ -41,7 +41,7 @@ * * @author Joseph Ramsey */ -public class SemBicScoreMultiFas implements ISemBicScore { +public class SemBicScoreMultiFas implements HasPenaltyDiscount { // The covariance matrix. private final List semBicScores; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index ca23b446e9..b4a994147f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -124,7 +124,7 @@ public void setDepth(int depth) { public Graph search() { getIndependenceTest().getVariables(); - return search(new Fasts(getIndependenceTest())); + return search(new FasTs(getIndependenceTest())); // return search(new Fas(getIndependenceTest())); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 0b3344bbba..1906aa7ca0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -430,8 +430,8 @@ public void setBoundGraph(Graph boundGraph) { * @deprecated Use the getters on the individual scores instead. */ public double getPenaltyDiscount() { - if (this.score instanceof ISemBicScore) { - return ((ISemBicScore) this.score).getPenaltyDiscount(); + if (this.score instanceof HasPenaltyDiscount) { + return ((HasPenaltyDiscount) this.score).getPenaltyDiscount(); } else { return 2.0; } @@ -461,8 +461,8 @@ public void setStructurePrior(double expectedNumParents) { * @deprecated Use the setters on the individual scores instead. */ public void setPenaltyDiscount(double penaltyDiscount) { - if (this.score instanceof ISemBicScore) { - ((ISemBicScore) this.score).setPenaltyDiscount(penaltyDiscount); + if (this.score instanceof HasPenaltyDiscount) { + ((HasPenaltyDiscount) this.score).setPenaltyDiscount(penaltyDiscount); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java index 8321e43248..7f0a414597 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import java.util.ArrayList; import java.util.HashSet; From 729c6951f546fa0970d0846e26055ec7e35a5868 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 12:56:46 -0400 Subject: [PATCH 203/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java | 1 + .../edu/cmu/tetrad/search/{ => work_in_progress}/Washdown.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Washdown.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index 3e187a2364..0bccc6b4b3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -28,6 +28,7 @@ import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.work_in_progress.BpcTetradPurifyWashdown; +import edu.cmu.tetrad.search.work_in_progress.Washdown; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Washdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Washdown.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java index 8dbb3497b5..af7b438951 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Washdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; From f350758670fc314147f32a65c44803e77a7dd21f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 13:51:42 -0400 Subject: [PATCH 204/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetradapp/model/VcpcFastRunner.java | 1 + .../edu/cmu/tetradapp/model/VcpcRunner.java | 1 + .../edu/cmu/tetrad/search/SampleVcpc.java | 1 + .../edu/cmu/tetrad/search/SampleVcpcFast.java | 1 + .../java/edu/cmu/tetrad/search/Sextad.java | 2 +- .../main/java/edu/cmu/tetrad/search/Test.java | 61 ------------------- .../search/{ => work_in_progress}/VcFas.java | 3 +- .../search/{ => work_in_progress}/VcPc.java | 3 +- .../{ => work_in_progress}/VcPcAlt.java | 3 +- .../{ => work_in_progress}/VcPcFast.java | 3 +- 10 files changed, 13 insertions(+), 66 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Test.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/VcFas.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/VcPc.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/VcPcAlt.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/VcPcFast.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index 79d91ce5d8..4967a2b913 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.work_in_progress.VcPcFast; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 68bd430dd3..d8a4ce331d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.work_in_progress.VcPc; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java index 7b84ce9f2c..6699f1001f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java @@ -29,6 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.work_in_progress.VcFas; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java index beefe1d170..6efdfbec92 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java @@ -29,6 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.work_in_progress.VcFas; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java index 7d5554c92e..b54bf5048a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java @@ -29,7 +29,7 @@ import java.util.List; /** - * Represents a sextad of variables. + * Represents an ordered sextad of variables. */ public class Sextad implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Test.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Test.java deleted file mode 100644 index f96945bb8d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Test.java +++ /dev/null @@ -1,61 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.util.StatUtils; -import org.apache.commons.math3.util.FastMath; - -import java.util.ArrayList; -import java.util.List; - -/** - * Implements a conditional Gaussian BIC score for FGES. - * - * @author Joseph Ramsey - */ -public class Test { - - @org.junit.Test - public void test() { - double[] a = {.3, .03, .01}; - - List logs = new ArrayList<>(); - - for (double _a : a) { - logs.add(FastMath.log(_a)); - } - - double sum = 0.0; - - for (double _a : a) { - sum += _a; - } - - double logsum = StatUtils.logsum(logs); - - System.out.println(FastMath.exp(logsum) + " " + sum); - } - -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcFas.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java index 30bc3d7e38..613c4147e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java index 00ccd989da..0efb628807 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcAlt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java index 7b23e40593..b09e547075 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcFast.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java index ed4ce1fa67..66b2772e83 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.MillisecondTimes; From 9f5bf905f1c338f8aa30cb9832675cbda661778d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:07:54 -0400 Subject: [PATCH 205/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../model/YeastPcCcdSearchWrapper.java | 2 +- .../algcomparison/independence/Codec.java | 57 ---- .../edu/cmu/tetrad/search/IndTestCodec.java | 264 ------------------ .../edu/cmu/tetrad/search/SuborderSearch.java | 30 ++ .../IndTestCramerT.java | 5 +- 5 files changed, 35 insertions(+), 323 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Codec.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestCodec.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/IndTestCramerT.java (98%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java index 338417d319..fc7e6cccb1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Ccd; -import edu.cmu.tetrad.search.IndTestCramerT; +import edu.cmu.tetrad.search.work_in_progress.IndTestCramerT; import edu.cmu.tetrad.search.Pc; import edu.pitt.dbmi.data.reader.Delimiter; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Codec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Codec.java deleted file mode 100644 index 02e638853e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Codec.java +++ /dev/null @@ -1,57 +0,0 @@ -package edu.cmu.tetrad.algcomparison.independence; - -import edu.cmu.tetrad.annotation.LinearGaussian; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.search.IndTestCodec; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; - -import java.util.ArrayList; -import java.util.List; - -/** - * Wrapper for Fisher Z test. - * - * @author jdramsey - */ -//@TestOfIndependence( -// name = "CODEC Test", -// command = "codec-test", -// dataType = {DataType.Continuous, DataType.Covariance} -//) -@LinearGaussian -public class Codec implements IndependenceWrapper { - - static final long serialVersionUID = 23L; - - @Override - public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - double alpha = parameters.getDouble(Params.ALPHA); - - if (dataSet instanceof DataSet) { - return new IndTestCodec((DataSet) dataSet, alpha); - } - - throw new IllegalArgumentException("Expecting a data set."); - } - - @Override - public String getDescription() { - return "CODEC"; - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - List params = new ArrayList<>(); - params.add(Params.ALPHA); - return params; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestCodec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestCodec.java deleted file mode 100644 index 7da4b3b3bb..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestCodec.java +++ /dev/null @@ -1,264 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.IndependenceFact; -import edu.cmu.tetrad.graph.Node; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.apache.commons.math3.util.FastMath.min; -import static org.apache.commons.math3.util.FastMath.sqrt; - -/** - * Checks conditional independence of variable in a continuous data set using Fisher's Z test. See Spirtes, Glymour, and - * Scheines, "Causation, Prediction and Search," 2nd edition, page 94. - * - * @author Joseph Ramsey - * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z - */ -public final class IndTestCodec implements IndependenceTest { - - private double alpha = 0; - private final List variables; - private final DataSet dataSet; - private final double[][] data; - private final boolean verbose = true; - - - //==========================CONSTRUCTORS=============================// - - /** - * Constructs a new Independence test which checks independence facts based on the correlation matrix implied by the - * given data set (must be continuous). The given significance level is used. - * - * @param dataSet A data set containing only continuous columns. - */ - public IndTestCodec(DataSet dataSet, double alpha) { - if (!(dataSet.isContinuous())) { - throw new IllegalArgumentException("Data set must be continuous."); - } - - this.dataSet = dataSet; - this.data = dataSet.getDoubleData().transpose().toArray(); - this.alpha = alpha; - - this.variables = dataSet.getVariables(); - - Map nodesHash = new HashMap<>(); - - for (int i = 0; i < variables.size(); i++) { - nodesHash.put(variables.get(i), i); - } - } - - //==========================PUBLIC METHODS=============================// - - /** - * Creates a new independence test instance for a subset of the variables. - */ - public IndependenceTest indTestSubset(List vars) { - throw new UnsupportedOperationException(); - } - - /** - * Determines whether variable x is independent of variable y given a list of conditioning variables z. - * - * @param x the one variable being compared. - * @param y the second variable being compared. - * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. - * @throws RuntimeException if a matrix singularity is encountered. - */ - public IndependenceResult checkIndependence(Node y, Node z, List x) { - IndependenceFact fact = new IndependenceFact(y, z, x); - - int N = data[0].length; - - List X = new ArrayList<>(); - for (Node node : x) X.add(indexOf(node)); - - List XZ = new ArrayList<>(); - XZ.add(indexOf(z)); - XZ.addAll(X); - - int[] R = new int[N]; - int _y = indexOf(y); - double[] ydata = data[_y]; - - for (int j = 0; j < N; j++) { - int count = 0; - - for (int i = 0; i < N; i++) { - if (ydata[i] < ydata[j]) count++; - } - - R[j] = count; - } - - -// for (int j = 0; j < N; j++) { -// double Ndistance = Double.POSITIVE_INFINITY; -// int Nj = 0; -// -// for (int i = 0; i < N; i++) { -// if (i == j) continue; -// double d = distance(data, X, i, j); -// if (d < Ndistance) { -// Ndistance = d; -// Nj = i; -// } -// } -// } -// -// for (int j = 0; j < N; j++) { -// double Mdistance = Double.POSITIVE_INFINITY; -// int Mj = 0; -// -// for (int i = 0; i < N; i++) { -// if (i == j) continue; -// double d = distance(data, XZ, i, j); -// if (d < Mdistance) { -// Mdistance = d; -// Mj = i; -// } -// } -// } - - double num = 0; - double den = 0; - - for (int j = 0; j < N; j++) { - double Ndistance = Double.POSITIVE_INFINITY; - int Nj = 0; - - for (int i = 0; i < N; i++) { - if (i == j) continue; - double d = distance(data, X, i, j); - if (d < Ndistance) { - Ndistance = d; - Nj = i; - } - } - - double Mdistance = Double.POSITIVE_INFINITY; - int Mj = 0; - - for (int i = 0; i < N; i++) { - if (i == j) continue; - double d = distance(data, XZ, i, j); - if (d < Mdistance) { - Mdistance = d; - Mj = i; - } - } - - num += min(R[j], R[Mj]) - min(R[j], R[Nj]); - den += R[j] - min(R[j], R[Nj]); - } - - double t = num / den; -// t = abs(t); -// System.out.println(t); - - if (t < 0) return new IndependenceResult(fact, true, t); - if (t > 1) return new IndependenceResult(fact, false, t); - - - return new IndependenceResult(fact, t <= alpha, t); - } - - private int indexOf(Node node) { - for (int i = 0; i < variables.size(); i++) - if (variables.get(i).getName().equals(node.getName())) return i; - return -1; - } - - @Override - public List getVariables() { - return variables; - } - - @Override - public boolean determines(List z, Node y) { - return false; - } - - @Override - public double getAlpha() { - return 0; - } - - @Override - public void setAlpha(double alpha) { - - } - - @Override - public DataModel getData() { - return dataSet; - } - - - @Override - public double getScore() { - return 0; - } - - @Override - public void setVerbose(boolean verbose) { - - } - - @Override - public boolean isVerbose() { - return false; - } - - private double distance(double[][] data, List cols, int i, int j) { - double sum = 0.0; - - for (int col : cols) { - double d = (data[col][i] - data[col][j]) / 2; - - if (!Double.isNaN(d)) { - sum += d * d; - } - } - - return sqrt(sum); - } - - public String toString() { - return "Fisher Z, alpha = " + new DecimalFormat("0.0###").format(getAlpha()); - } -} - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index c76430f778..e170209ddd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -8,17 +8,47 @@ import java.util.Set; /** + * Interface to help implement suborder searches for various types of permutation algorithms. + * A "suborder search" is a search for permutation <x1a,...x1n, x2a,...,x2m, x3a,...,x3l>> + * that searches for a good permutation of x2a,...,x2m with x1a,...,x1n as a prefix. * @author bryanandrews */ public interface SuborderSearch { + /** + * Searches the suburder. + * @param prefix The prefix of the suborder. + * @param suborder The suborder. + * @param gsts The GrowShinkTree being used to do caching of scores. + * @see GrowShrinkTree + */ void searchSuborder(List prefix, List suborder, Map gsts); + /** + * The knowledge being used. + * @param knowledge This knowledge. + * @see Knowledge + */ void setKnowledge(Knowledge knowledge); + /** + * The list of all variables, in order. They should satisfy the suborder requirements. + * @return This list. + * @see Node + * @see edu.cmu.tetrad.data.Variable + */ List getVariables(); + /** + * The map from nodes to parents resulting from the search. + * @return This map. + */ Map> getParents(); + /** + * The score being used. + * @return This score. + * @see Score + */ Score getScore(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestCramerT.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java index 553e06ad69..b56ab4737e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; @@ -27,6 +27,9 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; From cb1e3ef0cc6ea443d3e1f50359f32b5a6a1614c9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:21:49 -0400 Subject: [PATCH 206/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/PcLocal.java | 339 ------------------ .../edu/cmu/tetrad/search/SemBicScorer.java | 9 +- .../edu/cmu/tetrad/search/SepsetProducer.java | 2 + .../tetrad/search/SepsetsConservative.java | 9 +- .../edu/cmu/tetrad/search/SepsetsGreedy.java | 8 +- .../tetrad/search/SepsetsPossibleDsep.java | 7 + .../edu/cmu/tetrad/search/SepsetsSet.java | 5 +- 7 files changed, 32 insertions(+), 347 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLocal.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLocal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLocal.java deleted file mode 100644 index 54d367b0ab..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLocal.java +++ /dev/null @@ -1,339 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.SublistGenerator; -import edu.cmu.tetrad.util.TetradLogger; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Implements the PC Local algorithm. - * - * @author Joseph Ramsey (this version). - */ -public class PcLocal implements GraphSearch { - - /** - * The independence test used for the PC search. - */ - private final IndependenceTest independenceTest; - - /** - * Forbidden and required edges for the search. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large - * graphs). - */ - private boolean aggressivelyPreventCycles; - - /** - * The logger for this class. The config needs to be set. - */ - private final TetradLogger logger = TetradLogger.getInstance(); - - /** - * Elapsed time of the most recent search. - */ - private long elapsedTime; - - private Graph graph; - private MeekRules meekRules; - private final SepsetMap sepsetMap = new SepsetMap(); - private boolean verbose; - private Graph externalGraph; - - //=============================CONSTRUCTORS==========================// - - /** - * Constructs a PC Local search with the given independence oracle. - */ - public PcLocal(IndependenceTest independenceTest) { - this(independenceTest, null); - } - - public PcLocal(IndependenceTest independenceTest, Graph graph) { - if (independenceTest == null) { - throw new NullPointerException(); - } - - this.independenceTest = independenceTest; - this.graph = graph; - } - - //==============================PUBLIC METHODS========================// - - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - - public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { - this.aggressivelyPreventCycles = aggressivelyPreventCycles; - } - - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - public long getElapsedTime() { - return this.elapsedTime; - } - - /** - * Runs PC starting with a fully connected graph over all of the variables in the domain of the independence test. - */ - public Graph search() { - long time1 = MillisecondTimes.timeMillis(); - - if (this.externalGraph != null) { - this.graph = new EdgeListGraph(this.externalGraph); - this.graph.reorientAllWith(Endpoint.TAIL); - } else if (this.graph == null) { - this.graph = new EdgeListGraph(getIndependenceTest().getVariables()); - } else { - this.graph = new EdgeListGraph(this.graph); - this.graph.reorientAllWith(Endpoint.TAIL); - } - - this.meekRules = new MeekRules(); - this.meekRules.setKnowledge(this.knowledge); - - // This is the list of all changed nodes from the last iteration - List nodes = getIndependenceTest().getVariables(); - - int numEdges = nodes.size() * (nodes.size() - 1) / 2; - int index = 0; - - for (int i = 0; i < nodes.size(); i++) { - for (int j = i + 1; j < nodes.size(); j++) { - ++index; - - if (this.verbose && index % 100 == 0) { - log(index + " of " + numEdges); - } - - Node x = nodes.get(i); - Node y = nodes.get(j); - - tryAddingEdge(x, y); - } - } - - for (Node node : nodes) { - reorientNode(node); -// applyMeek(Collections.singletonList(node)); - } - - applyMeek(); - - this.logger.log("graph", "\nReturning this graph: " + this.graph); - - long time2 = MillisecondTimes.timeMillis(); - this.elapsedTime = time2 - time1; - - return this.graph; - } - - private void log(String message) { - TetradLogger.getInstance().log("info", message); - } - - private void tryAddingEdge(Node x, Node y) { - if (this.graph.isAdjacentTo(x, y)) { - return; - } - - if (sepset(x, y) == null) { - if (getKnowledge().isForbidden(x.getName(), y.getName()) && getKnowledge().isForbidden(y.getName(), x.getName())) { - return; - } - - this.graph.addUndirectedEdge(x, y); - reorient(x, y); - - for (Node w : this.graph.getAdjacentNodes(x)) { - tryRemovingEdge(w, x); - } - - for (Node w : this.graph.getAdjacentNodes(y)) { - tryRemovingEdge(w, y); - } - } - } - - private void tryRemovingEdge(Node x, Node y) { - if (!this.graph.isAdjacentTo(x, y)) return; - - if (sepset(x, y) != null) { - if (!getKnowledge().noEdgeRequired(x.getName(), y.getName())) { - return; - } - - this.graph.removeEdge(x, y); - reorient(x, y); - } - } - - //================================PRIVATE METHODS=======================// - - private List sepset(Node x, Node y) { - if (x == y) throw new IllegalArgumentException("Can't have x == y."); - - { - List adj = this.graph.getAdjacentNodes(x); - adj.remove(y); - - SublistGenerator gen = new SublistGenerator(adj.size(), adj.size()); - int[] choice; - - while ((choice = gen.next()) != null) { - List cond = GraphUtils.asList(choice, adj); - - if (getIndependenceTest().checkIndependence(x, y, cond).independent()) { - this.sepsetMap.set(x, y, cond); - return cond; - } - } - } - - { - List adj = this.graph.getAdjacentNodes(y); - adj.remove(x); - - SublistGenerator gen = new SublistGenerator(adj.size(), adj.size()); - int[] choice; - - while ((choice = gen.next()) != null) { - List cond = GraphUtils.asList(choice, adj); - - if (getIndependenceTest().checkIndependence(x, y, cond).independent()) { - this.sepsetMap.set(x, y, cond); - return cond; - } - } - } - - return null; - } - - private void reorient(Node x, Node y) { - reorientNode(y); - reorientNode(x); - - for (Node c : getCommonAdjacents(x, y)) { - reorientNode(c); - } - } - - private Set getCommonAdjacents(Node x, Node y) { - Set commonChildren = new HashSet<>(this.graph.getAdjacentNodes(x)); - commonChildren.retainAll(this.graph.getAdjacentNodes(y)); - return commonChildren; - } - - private void reorientNode(Node y) { - unorientAdjacents(y); - orientLocalColliders(y); - } - - private void applyMeek() { - this.meekRules.orientImplied(this.graph); - } - - private void unorientAdjacents(Node y) { - for (Node z : this.graph.getAdjacentNodes(y)) { - if (this.graph.isParentOf(y, z)) continue; - this.graph.removeEdge(z, y); - this.graph.addUndirectedEdge(z, y); - } - } - - private void orientLocalColliders(Node y) { - List adjy = this.graph.getAdjacentNodes(y); - - for (int i = 0; i < adjy.size(); i++) { - for (int j = i + 1; j < adjy.size(); j++) { - Node z = adjy.get(i); - Node w = adjy.get(j); - - if (this.graph.paths().isAncestorOf(y, z)) continue; - if (this.graph.paths().isAncestorOf(y, w)) continue; - -// if (z == w) continue; - if (this.graph.isAdjacentTo(z, w)) continue; - List cond = sepset(z, w); - - if (cond != null && !cond.contains(y) && !this.knowledge.isForbidden(z.getName(), y.getName()) - && !this.knowledge.isForbidden(w.getName(), y.getName())) { - this.graph.setEndpoint(z, y, Endpoint.ARROW); - this.graph.setEndpoint(w, y, Endpoint.ARROW); - } - } - } - } - - /** - * Checks if an arrowpoint is allowed by background knowledge. - */ - public static boolean isArrowpointAllowed(Object from, Object to, - Knowledge knowledge) { - if (knowledge == null) { - return true; - } - return !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - - public SepsetMap getSepsets() { - return this.sepsetMap; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } -} - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java index c23b92a1f1..a7890bb47f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java @@ -11,12 +11,13 @@ import java.util.List; import java.util.Map; +/** + * Scores a DAG using the SemBicScore. + * @author josephramsey + * @see SemBicScore + */ public class SemBicScorer { public static double scoreDag(Graph dag, DataModel data) { - return scoreDag(dag, data, true); - } - - public static double scoreDag(Graph dag, DataModel data, boolean precomputeCovariances) { if (dag == null) throw new NullPointerException("DAG not specified."); Score score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java index 473aee66f8..73af7a6de2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java @@ -26,6 +26,8 @@ import java.util.List; /** + *

A covenience structure that can generate and keep track of sepsets

+ * @see SepsetMap * @author Joseph Ramsey */ public interface SepsetProducer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java index 3793849e1a..cbd498d2a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java @@ -31,7 +31,14 @@ import java.util.List; /** - * Created by josephramsey on 3/24/15. + *

A SepsetProcuder that selects the first sepset it comes to from among the extra + * sepsets or the adjacents of i or k, or null if none is found. This version uses + * conservative reasoning (see the CPC algorithm).

+ * + * @author josephramsey + * @see SepsetProducer + * @see SepsetMap + * @see Cpc */ public class SepsetsConservative implements SepsetProducer { private final Graph graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java index 1bf398a9c7..3641e6822b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java @@ -30,8 +30,12 @@ import java.util.List; /** - * Selects the first sepset it comes to from among the extra sepsets or the adjacents of i or k, - * or null if none is found. + *

A SepsetProcuder that selects the first sepset it comes to from among the extra + * sepsets or the adjacents of i or k, or null if none is found.

+ * + * @author josephramsey + * @see SepsetProducer + * @see SepsetMap */ public class SepsetsGreedy implements SepsetProducer { private final Graph graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java index 911c2ae724..3e699e49dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java @@ -31,6 +31,13 @@ import java.util.ArrayList; import java.util.List; +/** + *

A sepset producer using conditional independence tests to generate the Sepset map, + * for the case where possible dsep sets are required.

+ * @author josephramsey + * @see SepsetProducer + * @see SepsetMap + */ public class SepsetsPossibleDsep implements SepsetProducer { private final Graph graph; private final int maxPathLength; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java index ca9c9f5766..12c5d0530b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java @@ -26,7 +26,10 @@ import java.util.List; /** - * Created by josephramsey on 3/24/15. + *

A sepset producer using conditional independence tests to generate the Sepset map.

+ * @author josephramsey + * @see SepsetProducer + * @see SepsetMap */ public class SepsetsSet implements SepsetProducer { private final SepsetMap sepsets; From 88024a5f64f1ed3b9793ed2d161b4cfea6a9094b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:26:44 -0400 Subject: [PATCH 207/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/algcomparison/algorithm/cluster/Fofc.java | 10 +++++----- .../tetrad/algcomparison/algorithm/cluster/Ftfc.java | 11 +++++------ .../algcomparison/score/ZhangShenBoundScore.java | 7 ++++--- .../search/{FindOneFactorClusters.java => Fofc.java} | 6 +++--- .../search/{FindTwoFactorClusters.java => Ftfc.java} | 6 +++--- .../java/edu/cmu/tetrad/search/IndTestSepset.java | 1 + .../java/edu/cmu/tetrad/search/ResolveSepsets.java | 1 + .../{ZhangShenBoundScore.java => ZsbScore.java} | 6 +++--- .../cmu/tetrad/search/work_in_progress/FasDci.java | 1 - .../search/{ => work_in_progress}/SepsetMapDci.java | 3 ++- .../test/java/edu/cmu/tetrad/test/TestMimbuild.java | 4 ++-- 11 files changed, 29 insertions(+), 27 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{FindOneFactorClusters.java => Fofc.java} (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{FindTwoFactorClusters.java => Ftfc.java} (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ZhangShenBoundScore.java => ZsbScore.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/SepsetMapDci.java (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index b714b4f4cb..f9182bf278 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -52,16 +52,16 @@ public Graph search(DataModel dataSet, Parameters parameters) { } boolean gap = parameters.getBoolean(Params.USE_GAP, true); - FindOneFactorClusters.Algorithm algorithm; + edu.cmu.tetrad.search.Fofc.Algorithm algorithm; if (gap) { - algorithm = FindOneFactorClusters.Algorithm.GAP; + algorithm = edu.cmu.tetrad.search.Fofc.Algorithm.GAP; } else { - algorithm = FindOneFactorClusters.Algorithm.SAG; + algorithm = edu.cmu.tetrad.search.Fofc.Algorithm.SAG; } - edu.cmu.tetrad.search.FindOneFactorClusters search - = new edu.cmu.tetrad.search.FindOneFactorClusters(cov, testType, algorithm, alpha); + edu.cmu.tetrad.search.Fofc search + = new edu.cmu.tetrad.search.Fofc(cov, testType, algorithm, alpha); search.setSignificanceChecked(parameters.getBoolean(Params.SIGNIFICANCE_CHECKED)); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java index 3e90c0d6c3..9b76631f19 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java @@ -7,7 +7,6 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.FindTwoFactorClusters; import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -51,16 +50,16 @@ public Graph search(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble(Params.ALPHA); boolean gap = parameters.getBoolean(Params.USE_GAP, true); - FindTwoFactorClusters.Algorithm algorithm; + edu.cmu.tetrad.search.Ftfc.Algorithm algorithm; if (gap) { - algorithm = FindTwoFactorClusters.Algorithm.GAP; + algorithm = edu.cmu.tetrad.search.Ftfc.Algorithm.GAP; } else { - algorithm = FindTwoFactorClusters.Algorithm.SAG; + algorithm = edu.cmu.tetrad.search.Ftfc.Algorithm.SAG; } - FindTwoFactorClusters search - = new FindTwoFactorClusters(cov, algorithm, alpha); + edu.cmu.tetrad.search.Ftfc search + = new edu.cmu.tetrad.search.Ftfc(cov, algorithm, alpha); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); return search.search(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java index 08db0a2bdc..c46912dbe9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java @@ -7,6 +7,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.ZsbScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -34,12 +35,12 @@ public class ZhangShenBoundScore implements ScoreWrapper { public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.ZhangShenBoundScore score; + ZsbScore score; if (dataSet instanceof DataSet) { - score = new edu.cmu.tetrad.search.ZhangShenBoundScore((DataSet) this.dataSet); + score = new ZsbScore((DataSet) this.dataSet); } else if (dataSet instanceof ICovarianceMatrix) { - score = new edu.cmu.tetrad.search.ZhangShenBoundScore((ICovarianceMatrix) this.dataSet); + score = new ZsbScore((ICovarianceMatrix) this.dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FindOneFactorClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FindOneFactorClusters.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index d26e512327..8ef3c05a48 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FindOneFactorClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -41,7 +41,7 @@ * * @author Joseph Ramsey */ -public class FindOneFactorClusters { +public class Fofc { private final CorrelationMatrix corr; // The list of all variables. @@ -62,7 +62,7 @@ public class FindOneFactorClusters { private ClusterSignificance.CheckType checkType = ClusterSignificance.CheckType.Clique; - public FindOneFactorClusters(ICovarianceMatrix cov, TestType testType, Algorithm algorithm, double alpha) { + public Fofc(ICovarianceMatrix cov, TestType testType, Algorithm algorithm, double alpha) { if (testType == null) throw new NullPointerException("Null indepTest type."); cov = new CovarianceMatrix(cov); this.variables = cov.getVariables(); @@ -78,7 +78,7 @@ public FindOneFactorClusters(ICovarianceMatrix cov, TestType testType, Algorithm } - public FindOneFactorClusters(DataSet dataSet, TestType testType, Algorithm algorithm, double alpha) { + public Fofc(DataSet dataSet, TestType testType, Algorithm algorithm, double alpha) { if (testType == null) throw new NullPointerException("Null test type."); this.variables = dataSet.getVariables(); this.alpha = alpha; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FindTwoFactorClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FindTwoFactorClusters.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 7b3df06c87..8e916cebb9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FindTwoFactorClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -39,7 +39,7 @@ * * @author Joseph Ramsey */ -public class FindTwoFactorClusters { +public class Ftfc { public Algorithm getAlgorithm() { return this.algorithm; @@ -71,7 +71,7 @@ public enum Algorithm {SAG, GAP} //========================================PUBLIC METHODS====================================// - public FindTwoFactorClusters(ICovarianceMatrix cov, Algorithm algorithm, double alpha) { + public Ftfc(ICovarianceMatrix cov, Algorithm algorithm, double alpha) { cov = new CovarianceMatrix(cov); this.variables = cov.getVariables(); this.alpha = alpha; @@ -84,7 +84,7 @@ public FindTwoFactorClusters(ICovarianceMatrix cov, Algorithm algorithm, double } - public FindTwoFactorClusters(DataSet dataSet, Algorithm algorithm, double alpha) { + public Ftfc(DataSet dataSet, Algorithm algorithm, double alpha) { this.variables = dataSet.getVariables(); this.alpha = alpha; this.test = new DeltaSextadTest(dataSet); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java index d98b7791a3..e1b4781685 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; +import edu.cmu.tetrad.search.work_in_progress.SepsetMapDci; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index d35e750cab..a1187da146 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodePair; +import edu.cmu.tetrad.search.work_in_progress.SepsetMapDci; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java index 599c2325b7..b10f976980 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java @@ -38,7 +38,7 @@ * * @author Joseph Ramsey */ -public class ZhangShenBoundScore implements Score { +public class ZsbScore implements Score { // The variables of the covariance matrix. private final List variables; @@ -66,7 +66,7 @@ public class ZhangShenBoundScore implements Score { * Constructs the score using a covariance matrix. * @param covMatrix The covariance matrix. */ - public ZhangShenBoundScore(ICovarianceMatrix covMatrix) { + public ZsbScore(ICovarianceMatrix covMatrix) { if (covMatrix == null) { throw new NullPointerException(); } @@ -80,7 +80,7 @@ public ZhangShenBoundScore(ICovarianceMatrix covMatrix) { * Constructs the score using a covariance matrix. * @param dataSet The data set. */ - public ZhangShenBoundScore(DataSet dataSet) { + public ZsbScore(DataSet dataSet) { this(SimpleDataLoader.getCovarianceMatrix(dataSet)); this.data = dataSet.getDoubleData(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java index 83661613ad..dff62816b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java @@ -28,7 +28,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.ResolveSepsets; -import edu.cmu.tetrad.search.SepsetMapDci; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMapDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMapDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java index d28aa18876..5be41e09a9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMapDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.SepsetMap; import java.io.IOException; import java.io.ObjectInputStream; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index c2ffb7692d..030de7a0e9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -74,8 +74,8 @@ public void test1() { List> partition; if (algorithm.equals("FOFC")) { - FindOneFactorClusters fofc = new FindOneFactorClusters(data, TestType.TETRAD_WISHART, - FindOneFactorClusters.Algorithm.GAP, 0.001); + Fofc fofc = new Fofc(data, TestType.TETRAD_WISHART, + Fofc.Algorithm.GAP, 0.001); searchGraph = fofc.search(); partition = fofc.getClusters(); } else if (algorithm.equals("BPC")) { From 78470c49be70379ec6de2d258fcd4b7bf8e9e477 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:27:38 -0400 Subject: [PATCH 208/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/RecursivePartialCorrelation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java index 5fa50213f1..647f8ef36a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java @@ -35,7 +35,8 @@ import static org.apache.commons.math3.util.FastMath.sqrt; /** - * Created by josephramsey on 4/13/14. + * Calculates partial correlation using the recursive method. + * @author josephramsey */ public class RecursivePartialCorrelation { From bebfae36d877541da66acfe648c7ae4073e7d9c4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:29:52 -0400 Subject: [PATCH 209/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../search/RecursivePartialCorrelation.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java index 647f8ef36a..f1549516c0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java @@ -43,17 +43,32 @@ public class RecursivePartialCorrelation { private final ICovarianceMatrix corr; private final Map nodesMap = new HashMap<>(); + /** + * Constructor. + * @param nodes The lsit of nodes. + * @param cov The covariance matrix, as a Matrix. + * @param sampleSize The sample size. + */ public RecursivePartialCorrelation(List nodes, Matrix cov, int sampleSize) { this.corr = new CorrelationMatrixOnTheFly(new CovarianceMatrix(nodes, cov, sampleSize)); for (int i = 0; i < nodes.size(); i++) this.nodesMap.put(nodes.get(i), i); } + /** + * Constructor + * @param cov The covariance matrix, as an ICovariance object. + */ public RecursivePartialCorrelation(ICovarianceMatrix cov) { this.corr = new CorrelationMatrixOnTheFly(cov); List nodes = this.corr.getVariables(); for (int i = 0; i < nodes.size(); i++) this.nodesMap.put(nodes.get(i), i); } + /** + * Calculates the partial correlation of x and y conditional on the nodes in z + * recursively. + * @return this partial correlation. + */ public double corr(Node x, Node y, List z) { if (z.isEmpty()) return this.corr.getValue(this.nodesMap.get(x), this.nodesMap.get(y)); Node z0 = z.get(0); From 0f45d44223904527f06482b88f9893ecea43ddc1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:30:49 -0400 Subject: [PATCH 210/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/search/IndTestFisherZPercentIndependent.java | 4 ++-- .../edu/cmu/tetrad/search/IndTestFisherZRecursive.java | 8 ++++---- ...ivePartialCorrelation.java => PartialCorrelation.java} | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{RecursivePartialCorrelation.java => PartialCorrelation.java} (94%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZPercentIndependent.java index 03fb4b4099..0f012c0be3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZPercentIndependent.java @@ -52,7 +52,7 @@ public final class IndTestFisherZPercentIndependent implements IndependenceTest private final Map variablesMap; private double percent = .75; private boolean fdr = true; - private final ArrayList recursivePartialCorrelation; + private final ArrayList recursivePartialCorrelation; private boolean verbose; //==========================CONSTRUCTORS=============================// @@ -87,7 +87,7 @@ public IndTestFisherZPercentIndependent(List dataSets, double alpha) { this.recursivePartialCorrelation = new ArrayList<>(); for (Matrix covMatrix : this.ncov) { - this.recursivePartialCorrelation.add(new RecursivePartialCorrelation(getVariables(), covMatrix, dataSets.get(0).getNumRows())); + this.recursivePartialCorrelation.add(new PartialCorrelation(getVariables(), covMatrix, dataSets.get(0).getNumRows())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZRecursive.java index 8199f3bf0e..9ea3f49c23 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZRecursive.java @@ -77,7 +77,7 @@ public final class IndTestFisherZRecursive implements IndependenceTest { private double fisherZ = Double.NaN; private double cutoff = Double.NaN; private final NormalDistribution normal = new NormalDistribution(0, 1); - private final RecursivePartialCorrelation recursivePartialCorrelation; + private final PartialCorrelation recursivePartialCorrelation; //==========================CONSTRUCTORS=============================// @@ -108,7 +108,7 @@ public IndTestFisherZRecursive(DataSet dataSet, double alpha) { this.dataSet = dataSet; - this.recursivePartialCorrelation = new RecursivePartialCorrelation(this.covMatrix); + this.recursivePartialCorrelation = new PartialCorrelation(this.covMatrix); } /** @@ -126,7 +126,7 @@ public IndTestFisherZRecursive(Matrix data, List variables, double alpha) this.nameMap = nameMap(variables); setAlpha(alpha); - this.recursivePartialCorrelation = new RecursivePartialCorrelation(this.covMatrix); + this.recursivePartialCorrelation = new PartialCorrelation(this.covMatrix); } @@ -141,7 +141,7 @@ public IndTestFisherZRecursive(ICovarianceMatrix covMatrix, double alpha) { this.nameMap = nameMap(this.variables); setAlpha(alpha); - this.recursivePartialCorrelation = new RecursivePartialCorrelation(this.covMatrix); + this.recursivePartialCorrelation = new PartialCorrelation(this.covMatrix); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java index f1549516c0..4a39912d20 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RecursivePartialCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java @@ -38,7 +38,7 @@ * Calculates partial correlation using the recursive method. * @author josephramsey */ -public class RecursivePartialCorrelation { +public class PartialCorrelation { private final ICovarianceMatrix corr; private final Map nodesMap = new HashMap<>(); @@ -49,7 +49,7 @@ public class RecursivePartialCorrelation { * @param cov The covariance matrix, as a Matrix. * @param sampleSize The sample size. */ - public RecursivePartialCorrelation(List nodes, Matrix cov, int sampleSize) { + public PartialCorrelation(List nodes, Matrix cov, int sampleSize) { this.corr = new CorrelationMatrixOnTheFly(new CovarianceMatrix(nodes, cov, sampleSize)); for (int i = 0; i < nodes.size(); i++) this.nodesMap.put(nodes.get(i), i); } @@ -58,7 +58,7 @@ public RecursivePartialCorrelation(List nodes, Matrix cov, int sampleSize) * Constructor * @param cov The covariance matrix, as an ICovariance object. */ - public RecursivePartialCorrelation(ICovarianceMatrix cov) { + public PartialCorrelation(ICovarianceMatrix cov) { this.corr = new CorrelationMatrixOnTheFly(cov); List nodes = this.corr.getVariables(); for (int i = 0; i < nodes.size(); i++) this.nodesMap.put(nodes.get(i), i); From b9ba25e085d0d77d82e61dcc16dd45bbff4f5a26 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:33:20 -0400 Subject: [PATCH 211/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- ...CollidersMaxP.java => MaxPColliderOrientation.java} | 10 +++++----- .../src/main/java/edu/cmu/tetrad/search/PcAll.java | 2 +- .../main/java/edu/cmu/tetrad/search/PcStableMax.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{OrientCollidersMaxP.java => MaxPColliderOrientation.java} (97%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OrientCollidersMaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/OrientCollidersMaxP.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java index 50e576ed36..7093a123c5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OrientCollidersMaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java @@ -32,11 +32,11 @@ import java.util.concurrent.ConcurrentHashMap; /** - * This is an optimization of the CCD (Cyclic Causal Discovery) algorithm by Thomas Richardson. - * + *

Performs a Max-P orientation of unshielded triples in a graph.

* @author Joseph Ramsey + * @see PcMax */ -public final class OrientCollidersMaxP { +public final class MaxPColliderOrientation { private final IndependenceTest independenceTest; private int depth = -1; private Knowledge knowledge = new Knowledge(); @@ -44,7 +44,7 @@ public final class OrientCollidersMaxP { private int maxPathLength = 3; private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; - public OrientCollidersMaxP(IndependenceTest test) { + public MaxPColliderOrientation(IndependenceTest test) { if (test == null) throw new NullPointerException(); this.independenceTest = test; } @@ -227,7 +227,7 @@ private void testColliderHeuristic(Graph graph, Map colliders, N private void orientCollider(Graph graph, Node a, Node b, Node c, PcAll.ConflictRule conflictRule) { if (this.knowledge.isForbidden(a.getName(), b.getName())) return; if (this.knowledge.isForbidden(c.getName(), b.getName())) return; - OrientCollidersMaxP.orientCollider(a, b, c, conflictRule, graph); + MaxPColliderOrientation.orientCollider(a, b, c, conflictRule, graph); } public Knowledge getKnowledge() { 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 e57fb1fd06..a6fd2dd4a5 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 @@ -376,7 +376,7 @@ public Graph search(List nodes) { System.out.println("MaxP orientation..."); } - OrientCollidersMaxP orientCollidersMaxP = new OrientCollidersMaxP(this.independenceTest); + MaxPColliderOrientation orientCollidersMaxP = new MaxPColliderOrientation(this.independenceTest); orientCollidersMaxP.setConflictRule(this.conflictRule); orientCollidersMaxP.setUseHeuristic(this.useHeuristic); orientCollidersMaxP.setMaxPathLength(this.maxPathLength); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java index 86920bf61a..e74d2a5d27 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java @@ -189,7 +189,7 @@ public Graph search(List nodes) { SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - OrientCollidersMaxP orientCollidersMaxP = new OrientCollidersMaxP(this.independenceTest); + MaxPColliderOrientation orientCollidersMaxP = new MaxPColliderOrientation(this.independenceTest); orientCollidersMaxP.setKnowledge(this.knowledge); orientCollidersMaxP.setUseHeuristic(this.useHeuristic); orientCollidersMaxP.setMaxPathLength(this.maxPathLength); From 7dfc037016dd489817cc4c47ebc0d27b46994672 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:50:52 -0400 Subject: [PATCH 212/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algorithm/oracle/cpdag/Pcd.java | 2 +- .../independence/SemBicDTest.java | 2 +- .../score/SemBicScoreDeterministic.java | 4 +- .../tetrad/search/SemBicScoreMultiFas.java | 307 ------------------ .../{ => work_in_progress}/OtherPermAlgs.java | 6 +- .../SemBicScoreDeterministic.java | 3 +- .../java/edu/cmu/tetrad/test/TestGrasp.java | 92 ------ 7 files changed, 11 insertions(+), 405 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/OtherPermAlgs.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/SemBicScoreDeterministic.java (98%) 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 index 9a22afd46f..2a428dcf79 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 @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndTestScore; import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.SemBicScoreDeterministic; +import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java index 658924f3ad..f1d3a2928a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.search.IndTestScore; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SemBicScoreDeterministic; +import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java index 42613788c3..6ffad5af8a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java @@ -28,8 +28,8 @@ public class SemBicScoreDeterministic implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.SemBicScoreDeterministic semBicScore - = new edu.cmu.tetrad.search.SemBicScoreDeterministic(SimpleDataLoader.getCovarianceMatrix(dataSet)); + edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic semBicScore + = new edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic(SimpleDataLoader.getCovarianceMatrix(dataSet)); semBicScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount")); semBicScore.setDeterminismThreshold(parameters.getDouble("determinismThreshold")); return semBicScore; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java deleted file mode 100644 index ac5865a4dc..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreMultiFas.java +++ /dev/null @@ -1,307 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.CovarianceMatrix; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.Matrix; -import edu.cmu.tetrad.util.StatUtils; -import org.apache.commons.math3.linear.SingularMatrixException; -import org.apache.commons.math3.util.FastMath; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Implements the continuous BIC score for FGES. - * - * @author Joseph Ramsey - */ -public class SemBicScoreMultiFas implements HasPenaltyDiscount { - - // The covariance matrix. - private final List semBicScores; - - // The variables of the covariance matrix. - private final List variables; - - private final int sampleSize; - - // The penalty penaltyDiscount. - private double penaltyDiscount = 2.0; - - // True if linear dependencies should return NaN for the score, and hence be - // ignored by FGES - - // True if verbose output should be sent to out. - private boolean verbose; - - private final Map indexMap; - - private final Map covMap; - - /** - * Constructs the score using a covariance matrix. - */ - public SemBicScoreMultiFas(List dataModels) { - if (dataModels == null) { - throw new NullPointerException(); - } - - List semBicScores = new ArrayList<>(); - - for (DataModel model : dataModels) { - if (model instanceof DataSet) { - DataSet dataSet = (DataSet) model; - - if (!dataSet.isContinuous()) { - throw new IllegalArgumentException("Datasets must be continuous."); - } - - SemBicScore semBicScore = new SemBicScore(new CovarianceMatrix(dataSet)); - semBicScore.setPenaltyDiscount(this.penaltyDiscount); - semBicScores.add(semBicScore); - } else if (model instanceof ICovarianceMatrix) { - SemBicScore semBicScore = new SemBicScore((ICovarianceMatrix) model); - semBicScore.setPenaltyDiscount(this.penaltyDiscount); - semBicScores.add(semBicScore); - } else { - throw new IllegalArgumentException("Only continuous data sets and covariance matrices may be used as input."); - } - } - - List variables = semBicScores.get(0).getVariables(); - - for (int i = 2; i < semBicScores.size(); i++) { - semBicScores.get(i).setVariables(variables); - } - - this.semBicScores = semBicScores; - this.variables = variables; - this.sampleSize = semBicScores.get(0).getSampleSize(); - - this.indexMap = indexMap(this.variables); - this.covMap = covMap(this.semBicScores); - } - - - @Override - public double localScoreDiff(int x, int y, int[] z) { - double sum = 0.0; - - Node _x = this.variables.get(x); - Node _y = this.variables.get(y); - List _z = getVariableList(z); - - - double r; - int p; - int N; - - for (SemBicScore score : this.semBicScores) { - try { - r = partialCorrelation(_x, _y, _z, score); - } catch (SingularMatrixException e) { -// System.out.println(SearchLogUtils.determinismDetected(_z, _x)); - return Double.NaN; - } - - p = 2 + z.length; - - N = this.covMap.get(score).getSampleSize(); - - sum += -N * FastMath.log(1.0 - r * r) - p * getPenaltyDiscount() * FastMath.log(N); - } - - return sum; - } - - - /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model - */ - public double localScore(int i, int[] parents) { - double sum = 0.0; - int count = 0; - - for (SemBicScore score : this.semBicScores) { - double _score = score.localScore(i, parents); - - if (!Double.isNaN(_score)) { - sum += _score; - count++; - } - } - - double score = sum / count; - - if (Double.isNaN(score) || Double.isInfinite(score)) { - return Double.NaN; - } else { - return score; - } - } - - public double localScore(int i, int[] parents, int index) { - return localScoreOneDataSet(i, parents, index); - } - - private double localScoreOneDataSet(int i, int[] parents, int index) { - return this.semBicScores.get(index).localScore(i, parents); - } - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - public double localScore(int i, int parent) { - double sum = 0.0; - int count = 0; - - for (SemBicScore score : this.semBicScores) { - double _score = score.localScore(i, parent); - - if (!Double.isNaN(_score)) { - sum += _score; - count++; - } - } - - return sum / count; - } - - - public double localScore(int i) { - double sum = 0.0; - int count = 0; - - for (SemBicScore score : this.semBicScores) { - double _score = score.localScore(i); - - if (!Double.isNaN(_score)) { - sum += _score; - count++; - } - } - - return sum / count; - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > -0.25 * getPenaltyDiscount() * FastMath.log(this.sampleSize); - } - - public DataSet getDataSet() { - throw new UnsupportedOperationException(); - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - for (SemBicScore score : this.semBicScores) { - score.setPenaltyDiscount(penaltyDiscount); - } - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public List getVariables() { - return this.variables; - } - - public boolean getAlternativePenalty() { - return false; - } - - @Override - public int getSampleSize() { - return this.sampleSize; - } - - private List getVariableList(int[] indices) { - List variables = new ArrayList<>(); - for (int i : indices) { - variables.add(this.variables.get(i)); - } - return variables; - } - - private double partialCorrelation(Node x, Node y, List z, SemBicScore score) throws SingularMatrixException { - int[] indices = new int[z.size() + 2]; - indices[0] = this.indexMap.get(x.getName()); - indices[1] = this.indexMap.get(y.getName()); - for (int i = 0; i < z.size(); i++) indices[i + 2] = this.indexMap.get(z.get(i).getName()); - Matrix submatrix = this.covMap.get(score).getSubmatrix(indices).getMatrix(); - return StatUtils.partialCorrelation(submatrix); - } - - private Map indexMap(List variables) { - Map indexMap = new HashMap<>(); - - for (int i = 0; i < variables.size(); i++) { - indexMap.put(variables.get(i).getName(), i); - } - - return indexMap; - } - - private Map covMap(List scores) { - Map covMap = new HashMap<>(); - SemBicScore score; - - for (SemBicScore semBicScore : scores) { - score = semBicScore; - covMap.put(score, score.getCovariances()); - } - - return covMap; - } - - - @Override - public int getMaxDegree() { - return 1000; - } - - @Override - public boolean determines(List z, Node y) { - return false; - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java index 7e403d8f8d..fdc933f485 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java @@ -1,10 +1,14 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.OrderedPair; +import edu.cmu.tetrad.search.GraphScore; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.PermutationGenerator; import org.jetbrains.annotations.NotNull; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreDeterministic.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java index 7ffd88d577..231dad556b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Vector; import org.apache.commons.math3.linear.SingularMatrixException; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index ad9be75897..3843b39db2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -68,7 +68,6 @@ import java.text.NumberFormat; import java.util.*; -import static edu.cmu.tetrad.search.OtherPermAlgs.Method.SP; import static edu.cmu.tetrad.util.RandomUtil.shuffle; @@ -1946,30 +1945,6 @@ public List getPrefix(List order, int i) { return prefix; } - // @Test - public void testRaskutti() { - Ret facts = getFactsRaskutti(); - - IndTestDSep test = new IndTestDSep(facts.getFacts()); - - OtherPermAlgs otherPermAlgs = new OtherPermAlgs(test); - otherPermAlgs.setMethod(SP); - otherPermAlgs.setNumStarts(1); - - List variables = test.getVariables(); - PermutationGenerator gen = new PermutationGenerator(variables.size()); - int[] perm; - - while ((perm = gen.next()) != null) { - List p = GraphUtils.asList(perm, variables); - - List p2 = otherPermAlgs.bestOrder(test.getVariables()); - Graph cpdag = otherPermAlgs.getGraph(true); - - System.out.println(p + " " + cpdag.getNumEdges()); - } - } - // @Test public void testManyVarManyDegreeTest() { Parameters params = new Parameters(); @@ -3006,73 +2981,6 @@ public void test7Examples() { } } - // @Test - public void testWorstCaseExamples() { - List allFacts = new ArrayList<>(); - - allFacts.add(getBryanWorseCaseMParentsNChildren(3, 2)); - - int count = 0; - - boolean printCpdag = false; - - for (int i = 0; i < allFacts.size(); i++) { - Ret facts = allFacts.get(i); - count++; - - System.out.println(); - System.out.println("Test #" + (i + 1)); - System.out.println(facts.getLabel()); - System.out.println(facts.getFacts()); - } - - for (int i = 0; i < allFacts.size(); i++) { - boolean passed = true; - - Ret facts = allFacts.get(i); - count++; - - TeyssierScorer scorer = new TeyssierScorer(new IndTestDSep(facts.getFacts()), - new GraphScore(facts.getFacts())); - - OrderedMap> graphs = new ListOrderedMap<>(); - OrderedMap> labels = new ListOrderedMap<>(); - - List variables = facts.facts.getVariables(); - Collections.sort(variables); - - PermutationGenerator gen = new PermutationGenerator(variables.size()); - int[] perm; - - while ((perm = gen.next()) != null) { - List p = GraphUtils.asList(perm, variables); - - OtherPermAlgs search = new OtherPermAlgs(new IndTestDSep(facts.getFacts())); -// search.setMaxPermSize(6); - search.setDepth(Integer.MAX_VALUE); -// search.setDepth((method == BOSS1 || method == BOSS2 || method == GRASP || method == RCG) ? 20 : 5); - search.setNumRounds(20); -// search.setVerbose(true); - List order = search.bestOrder(p); - System.out.println(p + " " + order + " " + search.getNumEdges());// + " " + search.getGraph(false)); - - if (search.getNumEdges() != facts.getTruth()) { - passed = false; -// break; - } - -// Pc search = new Pc(new IndTestDSep(facts.getFacts())); -// System.out.println(p + " " + search.search().getNumEdges()); - -// Fges search = new Fges(new GraphScore(facts.getFacts())); -// System.out.println(p + " " + search.search().getNumEdges()); - - } - - System.out.println((i + 1) + " " + (passed ? "P " : "F")); - } - } - // @Test public void testWayne2() { // int[] numNodes = new int[]{30};//4, 5, 6, 7}; From 461be10a56605a688d93f460178d15fd656d69a1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:55:24 -0400 Subject: [PATCH 213/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/FastIca.java | 8 +- .../edu/cmu/tetrad/search/IonLegalPairs.java | 83 ------------------- 2 files changed, 1 insertion(+), 90 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonLegalPairs.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index 2f0ce364fb..5620b0d337 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -35,13 +35,9 @@ * difference (I believe) is that the R package can handle complex numbers, * whereas this implementation cannot. *

- * Performance. The R version scales up much better than this one does, the main - * reason for which is that the calculation of the initial covariance matrix - * (1/n) X'X is so much faster. - *

* The documention of the R version is as follows, all of which is true of this * translation (so far as I know) except for its being in R and its allowing - * complex values: + * complex values. *

* Description: *

@@ -137,8 +133,6 @@ *

* A. Hyvarinen and E. Oja (2000) Independent Component Analysis: Algorithms and * Applications, _Neural Networks_, *13(4-5)*:411-430 - *

- *

Note: This code is currently broken; please do not use it until it's fixed. 11/24/2015> 0 * * @author Joseph Ramsey (of the translation, that is) */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonLegalPairs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonLegalPairs.java deleted file mode 100644 index 8bc2dbbaa3..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonLegalPairs.java +++ /dev/null @@ -1,83 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; - -import java.util.List; - -/** - * Specifies what coefs as a legal pair of edges X---Y---Z for purposes of calculating possible d-separation sets for - * the FCI algorithm. In this case, legal initial edges are those adjacent to initial nodes, and legal pairs of edges - * are those for which either X-->Y<--Z or X is adjacent to Z--i.e. X, Y, and Z form a triangle. (It is assumed (and - * checked) that is adjacent to Y and Y is adjacent to Z.) - * - * @author Tyler Gibson - */ -class IonLegalPairs implements LegalPairs { - - /** - * Graph with respect to which graph properties are tested. - */ - private final Graph graph; - - /** - * Constructs a new legal pairs object. See class level doc. - * - * @param graph The graph with respect to which legal pairs will be tested. - */ - public IonLegalPairs(Graph graph) { - if (graph == null) { - throw new NullPointerException(); - } - - this.graph = graph; - } - - /** - * @return true iff x is adjacent to y. - */ - public boolean isLegalFirstEdge(Node x, Node y) { - return this.graph.isAdjacentTo(x, y); - } - - /** - * @throws IllegalArgumentException if x is not adjacent to y or y is not adjacent to z. - */ - public boolean isLegalPair(Node x, Node y, Node z, List c, List d) { - if (!(this.graph.isAdjacentTo(x, y)) || !(this.graph.isAdjacentTo(y, z))) { - throw new IllegalArgumentException(); - } - //noinspection SimplifiableIfStatement - if (this.graph.isDefCollider(x, y, x) || this.graph.isAdjacentTo(x, z)) { - return true; - } - - return this.graph.underlines().isUnderlineTriple(x, y, z); - } -} - - - - - From 7682f741187491ad5858b50c3aa0f5ff311c79bb Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 14:57:04 -0400 Subject: [PATCH 214/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index 5620b0d337..a1cd04e4da 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -133,8 +133,10 @@ *

* A. Hyvarinen and E. Oja (2000) Independent Component Analysis: Algorithms and * Applications, _Neural Networks_, *13(4-5)*:411-430 + *

+ * This code has been well-tested. * - * @author Joseph Ramsey (of the translation, that is) + * @author Joseph Ramsey (of the translation, that is, not the original.) */ public class FastIca { From 20e93a9df81bb196991ada27076e320c083fcd78 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 15:35:00 -0400 Subject: [PATCH 215/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../independence/KimEtAlScoreTests.java | 21 ++-- .../algcomparison/score/KimEtAlScores.java | 21 ++-- .../java/edu/cmu/tetrad/search/FciMax.java | 7 +- .../java/edu/cmu/tetrad/search/FciOrient.java | 30 ++++-- .../java/edu/cmu/tetrad/search/FgesMb.java | 23 +--- .../main/java/edu/cmu/tetrad/search/Fofc.java | 100 +++++++++++------- .../main/java/edu/cmu/tetrad/search/Ftfc.java | 1 + .../{KimEtAlScores.java => GicScores.java} | 12 ++- .../java/edu/cmu/tetrad/search/SvarFci.java | 2 +- .../tetrad/search/{FasTs.java => TsFas.java} | 6 +- 10 files changed, 123 insertions(+), 100 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{KimEtAlScores.java => GicScores.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{FasTs.java => TsFas.java} (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java index 56a4ae7cb1..8cc7d44e9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java @@ -6,6 +6,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; +import edu.cmu.tetrad.search.GicScores; import edu.cmu.tetrad.search.IndTestScore; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; @@ -31,37 +32,37 @@ public class KimEtAlScoreTests implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - edu.cmu.tetrad.search.KimEtAlScores score; + GicScores score; if (dataSet instanceof DataSet) { - score = new edu.cmu.tetrad.search.KimEtAlScores((DataSet) dataSet); + score = new GicScores((DataSet) dataSet); } else if (dataSet instanceof ICovarianceMatrix) { - score = new edu.cmu.tetrad.search.KimEtAlScores((ICovarianceMatrix) dataSet); + score = new GicScores((ICovarianceMatrix) dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } int anInt = parameters.getInt((Params.SEM_GIC_RULE)); - edu.cmu.tetrad.search.KimEtAlScores.RuleType ruleType; + GicScores.RuleType ruleType; switch (anInt) { case 1: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.BIC; + ruleType = GicScores.RuleType.BIC; break; case 2: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.GIC2; + ruleType = GicScores.RuleType.GIC2; break; case 3: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.RIC; + ruleType = GicScores.RuleType.RIC; break; case 4: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.RICc; + ruleType = GicScores.RuleType.RICc; break; case 5: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.GIC5; + ruleType = GicScores.RuleType.GIC5; break; case 6: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.GIC6; + ruleType = GicScores.RuleType.GIC6; break; default: throw new IllegalArgumentException("Unrecognized rule type: " + anInt); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java index 984283d58f..bf470c89ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java @@ -6,6 +6,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.GicScores; import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -33,37 +34,37 @@ public class KimEtAlScores implements ScoreWrapper { public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.KimEtAlScores score; + GicScores score; if (dataSet instanceof DataSet) { - score = new edu.cmu.tetrad.search.KimEtAlScores((DataSet) this.dataSet); + score = new GicScores((DataSet) this.dataSet); } else if (dataSet instanceof ICovarianceMatrix) { - score = new edu.cmu.tetrad.search.KimEtAlScores((ICovarianceMatrix) this.dataSet); + score = new GicScores((ICovarianceMatrix) this.dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } int anInt = parameters.getInt((Params.SEM_GIC_RULE)); - edu.cmu.tetrad.search.KimEtAlScores.RuleType ruleType; + GicScores.RuleType ruleType; switch (anInt) { case 1: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.BIC; + ruleType = GicScores.RuleType.BIC; break; case 2: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.GIC2; + ruleType = GicScores.RuleType.GIC2; break; case 3: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.RIC; + ruleType = GicScores.RuleType.RIC; break; case 4: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.RICc; + ruleType = GicScores.RuleType.RICc; break; case 5: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.GIC5; + ruleType = GicScores.RuleType.GIC5; break; case 6: - ruleType = edu.cmu.tetrad.search.KimEtAlScores.RuleType.GIC6; + ruleType = GicScores.RuleType.GIC6; break; default: throw new IllegalArgumentException("Unrecognized rule type: " + anInt); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index 4b996e18de..af17e3760f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -30,12 +30,6 @@ import java.util.concurrent.RecursiveTask; /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

- * This versions uses the max-P collider orientation step. - *

* This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. * (By a remark of Zhang's, the rule applications can be staged in this way.) @@ -44,6 +38,7 @@ * @author Alex Smith, December 2008 * @author Joseph Ramsey * @author Choh-Man Teng + * @see Fci */ public final class FciMax implements GraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java index 9396cb8837..c5bb18a56e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java @@ -29,21 +29,31 @@ import java.util.*; /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm - * (found in FCI.java) with Jiji Zhang's Augmented FCI rules (found in sec. 4.1 - * of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

- * This class is based off a copy of FCI.java taken from the repository on - * 2008/12/16, revision 7306. The extension is done by extending - * doFinalOrientation() with methods for Zhang's rules R5-R10 which implements - * the augmented search. (By a remark of Zhang's, the rule applications can be - * staged in this way.) + *

This class performs the final orientation steps of the FCI algorithms. + * There are two versions of these final orientation steps, one due to + * Peter Spirtes (the original, in Causation, Prediction and Search), + * which is arrow complete, and the other which Jiji Zhang worked out + * in his Ph.D. dissertation, which is both arrow and tail complete. The + * references for these are as follows.

+ *

Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). + * Causation, prediction, and search. MIT press.

+ *

Zhang, J. (2008). On the completeness of orientation rules for causal + * discovery in the presence of latent confounders and selection bias. + * Artificial Intelligence, 172(16-17), 1873-1896.

+ *

These final rules are used in all algorithms in Tetrad that + * follow and refine the FCI algorithm--for example, the GFCI and RFCI + * algorihtms.

+ *

We've made the methods for each of the separate rules publicly + * accessible in case someone wants to use the individual rules in the + * context of their own algorithms.

* * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 * @author Joseph Ramsey * @author Choh-Man Teng + * @see Fci + * @see GFci + * @see Rfci */ public final class FciOrient { private final SepsetProducer sepsets; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index bb9b71d47e..314512c057 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -34,25 +34,12 @@ import java.util.concurrent.*; /** - * GesSearch is an implementation of the GES algorithm, as specified in - * Chickering (2002) "Optimal structure identification with greedy search" - * Journal of Machine Learning Research. It works for both BayesNets and SEMs. - *

- * Some code optimization could be done for the scoring part of the graph for - * discrete models (method scoreGraphChange). Some of Andrew Moore's approaches - * for caching sufficient statistics, for instance. - *

- * To speed things up, it has been assumed that variables X and Y with zero - * correlation do not correspond to edges in the graph. This is a restricted - * form of the heuristicSpeedup assumption, something GES does not assume. This - * the graph. This is a restricted form of the heuristicSpeedup assumption, - * something GES does not assume. This heuristicSpeedup assumption needs to be - * explicitly turned on using setHeuristicSpeedup(true). - *

- * A number of other optimizations were added 5/2015. See code for details. + * This code restricts the FGES algorithm to the operations needed just + * to find the graph over the Markov blanket of a variable X (or a graph + * over the Markov blankets of a list of variables X1,..,Xn), together + * with the target X (or, respectively, the targets X1,...,Xn). * - * @author Ricardo Silva, Summer 2003 - * @author Joseph Ramsey, Revisions 5/2015 + * @author josephramsey */ public final class FgesMb { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index 8ef3c05a48..da59fc21d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -40,8 +40,10 @@ * quartet algorithm to a one factor tetrad algorithm). * * @author Joseph Ramsey + * @author erichkummerfeld */ public class Fofc { + public enum Algorithm {SAG, GAP} private final CorrelationMatrix corr; // The list of all variables. @@ -61,7 +63,15 @@ public class Fofc { private final Algorithm algorithm; private ClusterSignificance.CheckType checkType = ClusterSignificance.CheckType.Clique; - + /** + * Conctructor. + * @param cov The covariance matrix searched over. + * @param testType The type of test used. + * @param algorithm The type of FOFC algorithm used. + * @param alpha The alpha significance cutoff. + * @see TestType + * @see Algorithm + */ public Fofc(ICovarianceMatrix cov, TestType testType, Algorithm algorithm, double alpha) { if (testType == null) throw new NullPointerException("Null indepTest type."); cov = new CovarianceMatrix(cov); @@ -78,6 +88,15 @@ public Fofc(ICovarianceMatrix cov, TestType testType, Algorithm algorithm, doubl } + /** + * Conctructor. + * @param dataSet The continuous dataset searched over. + * @param testType The type of test used. + * @param algorithm The type of FOFC algorithm used. + * @param alpha The alpha significance cutoff. + * @see TestType + * @see Algorithm + */ public Fofc(DataSet dataSet, TestType testType, Algorithm algorithm, double alpha) { if (testType == null) throw new NullPointerException("Null test type."); this.variables = dataSet.getVariables(); @@ -91,6 +110,48 @@ public Fofc(DataSet dataSet, TestType testType, Algorithm algorithm, double alph this.corr = new CorrelationMatrix(dataSet); } + public Graph search() { + Set> allClusters; + + if (this.algorithm == Algorithm.SAG) { + allClusters = estimateClustersTetradsFirst(); + } else if (this.algorithm == Algorithm.GAP) { + allClusters = estimateClustersTriplesFirst(); + } else { + throw new IllegalStateException("Expected SAG or GAP: " + this.testType); + } + + this.clusters = ClusterSignificance.variablesForIndices2(allClusters, variables); + + System.out.println("allClusters = " + allClusters); + System.out.println("this.clusters = " + this.clusters); + +// if (allClusters.isEmpty()) return new EdgeListGraph(); + + ClusterSignificance clusterSignificance = new ClusterSignificance(variables, dataModel); + clusterSignificance.printClusterPValues(allClusters); + + return convertToGraph(allClusters); + } + + /** + * Sets whether the significant of cluster should be checked for each cluster. + * @param significanceChecked True if so. + */ + public void setSignificanceChecked(boolean significanceChecked) { + this.significanceChecked = significanceChecked; + } + + /** + * Sets which type of cluster check should be performed. + * @param checkType The type to be performed. + * @see ClusterSignificance.CheckType + */ + public void setCheckType(ClusterSignificance.CheckType checkType) { + this.checkType = checkType; + } + + // renjiey private int findFrequentestIndex(Integer[] outliers) { Map map = new HashMap<>(); @@ -189,33 +250,6 @@ private Integer[] removeZeroIndex(Integer[] outlier) { return list.toArray(new Integer[1]); } - - public Graph search() { - Set> allClusters; - - if (this.algorithm == Algorithm.SAG) { - allClusters = estimateClustersTetradsFirst(); - } else if (this.algorithm == Algorithm.GAP) { - allClusters = estimateClustersTriplesFirst(); - } else { - throw new IllegalStateException("Expected SAG or GAP: " + this.testType); - } - - this.clusters = ClusterSignificance.variablesForIndices2(allClusters, variables); - - System.out.println("allClusters = " + allClusters); - System.out.println("this.clusters = " + this.clusters); - -// if (allClusters.isEmpty()) return new EdgeListGraph(); - - ClusterSignificance clusterSignificance = new ClusterSignificance(variables, dataModel); - clusterSignificance.printClusterPValues(allClusters); - - return convertToGraph(allClusters); - } - - //========================================PRIVATE METHODS====================================// - // This is the main algorithm. private Set> estimateClustersTriplesFirst() { List _variables = allVariables(); @@ -965,16 +999,6 @@ private void log(String s) { TetradLogger.getInstance().forceLogMessage(s); } } - - public void setSignificanceChecked(boolean significanceChecked) { - this.significanceChecked = significanceChecked; - } - - public void setCheckType(ClusterSignificance.CheckType checkType) { - this.checkType = checkType; - } - - public enum Algorithm {SAG, GAP} } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 8e916cebb9..e4e1887b86 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -38,6 +38,7 @@ * sextet algorithm to a one factor IntSextad algorithm). * * @author Joseph Ramsey + * @author erichkummerfeld */ public class Ftfc { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/KimEtAlScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/KimEtAlScores.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java index 1d51494a82..22f274cc63 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/KimEtAlScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java @@ -33,11 +33,15 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Implements the continuous BIC score for FGES. + *

Implements scores motivated by the Generalized Information Criterion (GIC) + * approach as given in Kim et al. (2012).

+ *

Kim, Y., Kwon, S., & Choi, H. (2012). Consistent model selection criteria on + * high dimensions. The Journal of Machine Learning Research, 13(1), 1037-1057. + * Foster and George.

* * @author Joseph Ramsey */ -public class KimEtAlScores implements Score { +public class GicScores implements Score { // The dataset. private DataSet dataSet; @@ -70,7 +74,7 @@ public class KimEtAlScores implements Score { /** * Constructs the score using a covariance matrix. */ - public KimEtAlScores(ICovarianceMatrix covariances/*, double correlationThreshold*/) { + public GicScores(ICovarianceMatrix covariances/*, double correlationThreshold*/) { if (covariances == null) { throw new NullPointerException(); } @@ -86,7 +90,7 @@ public KimEtAlScores(ICovarianceMatrix covariances/*, double correlationThreshol /** * Constructs the score using a covariance matrix. */ - public KimEtAlScores(DataSet dataSet/*, double correlationThreshold*/) { + public GicScores(DataSet dataSet/*, double correlationThreshold*/) { if (dataSet == null) { throw new NullPointerException(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index b4a994147f..71d96f2cce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -124,7 +124,7 @@ public void setDepth(int depth) { public Graph search() { getIndependenceTest().getVariables(); - return search(new FasTs(getIndependenceTest())); + return search(new TsFas(getIndependenceTest())); // return search(new Fas(getIndependenceTest())); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasTs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasTs.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index 96bd05ccc8..48c52713ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasTs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -41,7 +41,7 @@ * @author DMalinsky * @see Fas */ -public class FasTs implements IFas { +public class TsFas implements IFas { /** * The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node @@ -99,7 +99,7 @@ public class FasTs implements IFas { /** * Constructs a new FastAdjacencySearch. */ - public FasTs(Graph graph, IndependenceTest test) { + public TsFas(Graph graph, IndependenceTest test) { this.graph = graph; this.test = test; } @@ -107,7 +107,7 @@ public FasTs(Graph graph, IndependenceTest test) { /** * Constructs a new FastAdjacencySearch. */ - public FasTs(IndependenceTest test) { + public TsFas(IndependenceTest test) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; } From af33801a7b9d5bae7aa78e6b2817da881bd10323 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 15:53:55 -0400 Subject: [PATCH 216/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Ftfc.java | 153 ++++++++++-------- .../java/edu/cmu/tetrad/search/GicScores.java | 58 +++---- 2 files changed, 115 insertions(+), 96 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index e4e1887b86..9b4bc0e28c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -70,8 +70,15 @@ public enum Algorithm {SAG, GAP} private boolean verbose; private Algorithm algorithm = Algorithm.GAP; - //========================================PUBLIC METHODS====================================// - + /** + * Conctructor. + * + * @param cov The covariance matrix searched over. + * @param algorithm The type of FOFC algorithm used. + * @param alpha The alpha significance cutoff. + * @see TestType + * @see Fofc.Algorithm + */ public Ftfc(ICovarianceMatrix cov, Algorithm algorithm, double alpha) { cov = new CovarianceMatrix(cov); this.variables = cov.getVariables(); @@ -81,10 +88,17 @@ public Ftfc(ICovarianceMatrix cov, Algorithm algorithm, double alpha) { this.algorithm = algorithm; this.corr = new CorrelationMatrix(cov); - - } + /** + * Conctructor. + * + * @param dataSet The continuous dataset searched over. + * @param algorithm The type of FOFC algorithm used. + * @param alpha The alpha significance cutoff. + * @see TestType + * @see Fofc.Algorithm + */ public Ftfc(DataSet dataSet, Algorithm algorithm, double alpha) { this.variables = dataSet.getVariables(); this.alpha = alpha; @@ -95,6 +109,73 @@ public Ftfc(DataSet dataSet, Algorithm algorithm, double alpha) { this.corr = new CorrelationMatrix(dataSet); } + public Graph search() { + Set> allClusters; + + if (this.algorithm == Algorithm.SAG) { + allClusters = estimateClustersSAG(); + } else if (this.algorithm == Algorithm.GAP) { + allClusters = estimateClustersGAP(); + } else { + throw new IllegalStateException("Expected SAG or GAP: " + this.algorithm); + } + this.clusters = variablesForIndices(allClusters); + return convertToGraph(allClusters); + } + + /** + * Returns clusters output by the algorithm from the last call to search(). + * @return These clusters. + */ + public List> getClusters() { + return this.clusters; + } + + /** + * Sets whether verbose output should be printed. + * @param verbose True if the case. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + // This is the main algorithm. + private Set> estimateClustersGAP() { + List _variables = allVariables(); + + Set> pentads = findPurepentads(_variables); + Set> combined = combinePurePentads(pentads, _variables); + + Set> _combined = new HashSet<>(); + + for (List c : combined) { + List a = new ArrayList<>(c); + Collections.sort(a); + _combined.add(a); + } + + return _combined; + + } + + private List allVariables() { + List _variables = new ArrayList<>(); + for (int i = 0; i < this.variables.size(); i++) _variables.add(i); + return _variables; + } + + private Set> estimateClustersSAG() { + List _variables = allVariables(); + + Set> pureClusters = findPureClusters(_variables); + Set> mixedClusters = findMixedClusters(pureClusters, _variables, unionPure(pureClusters)); + Set> allClusters = new HashSet<>(pureClusters); + allClusters.addAll(mixedClusters); + return allClusters; + + } + + // renjiey private int findFrequentestIndex(Integer[] outliers) { Map map = new HashMap<>(); @@ -192,59 +273,6 @@ private Integer[] removeZeroIndex(Integer[] outlier) { return list.toArray(new Integer[1]); } - - public Graph search() { - Set> allClusters; - - if (this.algorithm == Algorithm.SAG) { - allClusters = estimateClustersSAG(); - } else if (this.algorithm == Algorithm.GAP) { - allClusters = estimateClustersGAP(); - } else { - throw new IllegalStateException("Expected SAG or GAP: " + this.algorithm); - } - this.clusters = variablesForIndices(allClusters); - return convertToGraph(allClusters); - } - - //========================================PRIVATE METHODS====================================// - - // This is the main algorithm. - private Set> estimateClustersGAP() { - List _variables = allVariables(); - - Set> pentads = findPurepentads(_variables); - Set> combined = combinePurePentads(pentads, _variables); - - Set> _combined = new HashSet<>(); - - for (List c : combined) { - List a = new ArrayList<>(c); - Collections.sort(a); - _combined.add(a); - } - - return _combined; - - } - - private List allVariables() { - List _variables = new ArrayList<>(); - for (int i = 0; i < this.variables.size(); i++) _variables.add(i); - return _variables; - } - - private Set> estimateClustersSAG() { - List _variables = allVariables(); - - Set> pureClusters = findPureClusters(_variables); - Set> mixedClusters = findMixedClusters(pureClusters, _variables, unionPure(pureClusters)); - Set> allClusters = new HashSet<>(pureClusters); - allClusters.addAll(mixedClusters); - return allClusters; - - } - private Set> findPurepentads(List variables) { if (variables.size() < 6) { return new HashSet<>(); @@ -990,17 +1018,6 @@ private boolean zeroCorr(List cluster, int n) { return count >= n; } - /** - * The clusters output by the algorithm from the last call to search(). - */ - public List> getClusters() { - return this.clusters; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - private boolean vanishes(int n1, int n2, int n3, int n4, int n5, int n6) { IntSextad t1 = new IntSextad(n1, n2, n3, n4, n5, n6); IntSextad t2 = new IntSextad(n1, n5, n6, n2, n3, n4); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java index 22f274cc63..b27231b208 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java @@ -272,34 +272,6 @@ public boolean determines(List z, Node y) { return Double.isNaN(v); } - private void setCovariances(ICovarianceMatrix covariances) { -// CorrelationMatrix correlations = new CorrelationMatrix(covariances); - this.covariances = covariances; -// this.covariances = covariances; - -// boolean exists = false; - -// for (int i = 0; i < correlations.getSize(); i++) { -// for (int j = 0; j < correlations.getSize(); j++) { -// if (i == j) continue; -// double r = correlations.getValue(i, j); -// if (abs(r) > correlationThreshold) { -// System.out.println("Absolute correlation too high: " + r); -// exists = true; -// } -// } -// } - -// if (exists) { -// throw new IllegalArgumentException("Some correlations are too high (> " + correlationThreshold -// + ") in absolute value."); -// } - - - this.N = covariances.getSampleSize(); - } - - public void setRuleType(RuleType ruleType) { this.ruleType = ruleType; } @@ -337,6 +309,36 @@ public void setPenaltyDiscount(double penaltyDiscount) { } public enum RuleType {MANUAL, BIC, NANDY, GIC2, RIC, RICc, GIC5, GIC6} + + + private void setCovariances(ICovarianceMatrix covariances) { +// CorrelationMatrix correlations = new CorrelationMatrix(covariances); + this.covariances = covariances; +// this.covariances = covariances; + +// boolean exists = false; + +// for (int i = 0; i < correlations.getSize(); i++) { +// for (int j = 0; j < correlations.getSize(); j++) { +// if (i == j) continue; +// double r = correlations.getValue(i, j); +// if (abs(r) > correlationThreshold) { +// System.out.println("Absolute correlation too high: " + r); +// exists = true; +// } +// } +// } + +// if (exists) { +// throw new IllegalArgumentException("Some correlations are too high (> " + correlationThreshold +// + ") in absolute value."); +// } + + + this.N = covariances.getSampleSize(); + } + + } From 8bcf2f351878ec7a9c8dd0db3ed72089c9367f5a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 15:58:04 -0400 Subject: [PATCH 217/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index f657badb4b..876def5f58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -34,12 +34,14 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - * J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm - * for Latent Variable Models," JMLR 2016. + *

Implements a version of FCI that started by running the FGES algorithm and + * then correct the result to be correct for latent variables models.

+ *

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm + * for Latent Variable Models," JMLR 2016.

* * @author Juan Miguel Ogarrio * @author ps7z - * @author jdramsey + * @author josephramsey */ public final class GFci implements GraphSearch { private Graph graph; From e003227334999586ef0c6db07b58e9cb8d77657b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 16:23:29 -0400 Subject: [PATCH 218/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algcomparison/algorithm/other/Glasso.java | 6 +- .../edu/cmu/tetrad/search/GraphChange.java | 9 +-- .../edu/cmu/tetrad/search/GraphoidAxioms.java | 68 ++++++++++++++----- .../search/{ => work_in_progress}/Glasso.java | 2 +- .../java/edu/cmu/tetrad/test/TestGrasp.java | 4 +- 5 files changed, 62 insertions(+), 27 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Glasso.java (99%) 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 index d945fddc1a..1b8374abcb 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 @@ -1,7 +1,5 @@ package edu.cmu.tetrad.algcomparison.algorithm.other; -import cern.colt.matrix.DoubleMatrix2D; -import cern.colt.matrix.impl.DenseDoubleMatrix2D; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.annotation.AlgType; import edu.cmu.tetrad.annotation.Bootstrapping; @@ -52,7 +50,7 @@ public Graph search(DataModel ds, Parameters parameters) { Matrix cov = new Matrix(SimpleDataLoader.getContinuousDataSet(ds) .getCovarianceMatrix().toArray()); - edu.cmu.tetrad.search.Glasso glasso = new edu.cmu.tetrad.search.Glasso(cov); + edu.cmu.tetrad.search.work_in_progress.Glasso glasso = new edu.cmu.tetrad.search.work_in_progress.Glasso(cov); glasso.setMaxit(parameters.getInt(Params.MAXIT)); glasso.setIa(parameters.getBoolean(Params.IA)); glasso.setIs(parameters.getBoolean(Params.IS)); @@ -61,7 +59,7 @@ public Graph search(DataModel ds, Parameters parameters) { glasso.setThr(parameters.getDouble(Params.THR)); glasso.setRhoAllEqual(1.0); - edu.cmu.tetrad.search.Glasso.Result result = glasso.search(); + edu.cmu.tetrad.search.work_in_progress.Glasso.Result result = glasso.search(); Matrix wwi = new Matrix(result.getWwi().toArray()); List variables = ds.getVariables(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java index 7af6f45ea2..73d925e90d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java @@ -27,10 +27,11 @@ /** - *

GraphChange is a data structure created mainly for use in the ION search algorithm. However, it models a general - * concept: storage for a variety of seperate changes one could possibly apply to a PAG.

- *

By convention, the NodePairs in the orients ArrayList are ordered such that Node1 is the "from" node - * and Node2 is the "to" node (ie 1 o-> 2).

+ *

GraphChange is a data structure created mainly for use in the ION search algorithm. + * However, it models a general concept: storage for a variety of seperate changes one could + * possibly apply to a PAG.

+ *

By convention, the NodePairs in the orients ArrayList are ordered such that Node1 is the + * "from" node and Node2 is the "to" node (ie 1 o-> 2).

* * @author Trevor Burns */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java index ae967d3009..0582de59f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java @@ -48,14 +48,24 @@ public class GraphoidAxioms { /** * Constructor. - * - * @param facts A set of GraphoidIdFacts. + * @param facts A set of GraphoidIndFacts. + * @param nodes The list of nodes. + * @see GraphoidIndFact k */ public GraphoidAxioms(Set facts, List nodes) { this.facts = new LinkedHashSet<>(facts); this.nodes = new ArrayList<>(nodes); } + /** + * Constructor. + * @param facts A list of GraphoidIndFacts. + * @param nodes The list of nodes. + * @param textSpecs A map from GraphoidIndFacts to String text specs. The + * text specs are used for printing information to the user + * about which facts are found or are missing. + * @see GraphoidIndFact + */ public GraphoidAxioms(Set facts, List nodes, Map textSpecs) { @@ -64,6 +74,14 @@ public GraphoidAxioms(Set facts, this.textSpecs = new HashMap<>(textSpecs); } + /** + * The main methods. + * @param args E.g., "java -cp tetrad-gui-7.1.3-SNAPSHOT-launch.jar edu.cmu.tetrad.search.GraphoidAxioms udags5.txt 5" + * Here, udgas5.txt is a file containing independence models, one per line, where each independence + * fast is specified by, e.g., "1:23|56", indicating that 1 is independence of 2 and 3 conditional + * on 5 and 6. No more than 9 variables can be handled this way. If you need more, let us know and + * we'll change the format. + */ public static void main(String... args) { try { File file = new File(args[0]); @@ -87,8 +105,8 @@ public static void main(String... args) { } GraphoidAxioms axioms = getGraphoidAxioms(line, variables); - axioms.setTrivialtyAssumed(); - axioms.setSymmetryAssumed(); + axioms.ensureTriviality(); + axioms.ensureSymmetry(); System.out.println(axioms.getIndependenceFacts().getVariableNames()); @@ -141,20 +159,33 @@ private static GraphoidAxioms getGraphoidAxioms(String line, List nodes) t return new GraphoidAxioms(facts, nodes, textSpecs); } + /** + * Checked whether the IM is a semigraphoid. + * @return True if so. + */ public boolean semigraphoid() { return symmetry() && decomposition() && weakUnion() && contraction(); } + /** + * Checks whether teh IM is a semigraphoid. + * @return True if so. + */ public boolean graphoid() { return semigraphoid() && intersection(); } + /** + * Checks whether the IM is a compositional graphoid. + * @return True if so. + */ public boolean compositionalGraphoid() { return graphoid() && composition(); } /** - * Assumes decompositiona nd composition. + * Returns the independence facts in the form 1:2|3 for use in various Tetrad algorithms. Assumes + * decomposition and compositios, so that there are no complex independence facts. */ public IndependenceFacts getIndependenceFacts() { IndependenceFacts ifFacts = new IndependenceFacts(); @@ -173,7 +204,7 @@ public IndependenceFacts getIndependenceFacts() { } /** - * X ⊥⊥ Y | Z ==> Y ⊥⊥ X | Z + * Checks is symmetry holds--i.e., X ⊥⊥ Y | Z ==> Y ⊥⊥ X | Z */ public boolean symmetry() { @@ -196,7 +227,7 @@ public boolean symmetry() { } /** - * X ⊥⊥ (Y ∪ W) |Z ==> (X ⊥⊥ Y |Z) ∧ (X ⊥⊥ W |Z) + * Checks if decomposition holds, e.g., X ⊥⊥ (Y ∪ W) |Z ==> (X ⊥⊥ Y |Z) ∧ (X ⊥⊥ W |Z) */ public boolean decomposition() { boolean found0 = false; @@ -272,7 +303,7 @@ public boolean decomposition() { } /** - * X _||_ Y U W | Z ==> X _||_ Y | Z U W + * Checks is weak union holds, e.g., X _||_ Y U W | Z ==> X _||_ Y | Z U W */ public boolean weakUnion() { boolean found0 = false; @@ -327,7 +358,7 @@ public boolean weakUnion() { } /** - * (X ⊥⊥ Y |Z) ∧ (X ⊥⊥ W |Z ∪ Y) ==> X ⊥⊥ (Y ∪ W) |Z + * Checks if contraction holds--e.g., (X ⊥⊥ Y |Z) ∧ (X ⊥⊥ W |Z ∪ Y) ==> X ⊥⊥ (Y ∪ W) |Z */ public boolean contraction() { boolean found0 = false; @@ -384,7 +415,7 @@ public boolean contraction() { } /** - * (X ⊥⊥ Y | (Z ∪ W)) ∧ (X ⊥⊥ W | (Z ∪ Y)) ==> X ⊥⊥ (Y ∪ W) |Z + * Checks if intersection holds--e.g., (X ⊥⊥ Y | (Z ∪ W)) ∧ (X ⊥⊥ W | (Z ∪ Y)) ==> X ⊥⊥ (Y ∪ W) |Z */ public boolean intersection() { boolean found0 = false; @@ -422,8 +453,6 @@ public boolean intersection() { Set YW = new HashSet<>(Y); YW.addAll(W); - if (YW.isEmpty()) continue; - boolean found2 = false; for (GraphoidIndFact _fact : facts) { @@ -456,7 +485,7 @@ public boolean intersection() { } /** - * (X ⊥⊥ Y | Z) ∧ (X ⊥⊥ W |Z) ==> X ⊥⊥ (Y ∪ W) |Z + * Checks if composition holds--e.g., (X ⊥⊥ Y | Z) ∧ (X ⊥⊥ W |Z) ==> X ⊥⊥ (Y ∪ W) |Z */ public boolean composition() { boolean found0 = false; @@ -505,14 +534,17 @@ public boolean composition() { return !found0; } - public void setTrivialtyAssumed() { + /** + * Sets whether triviality as assumed. + */ + public void ensureTriviality() { this.trivialtyAssumed = true; } /** - * X ⊥⊥ Y | Z ==> Y ⊥⊥ X | Z + * Sets symmetry as assumed--i.e., ensures that X ⊥⊥ Y | Z ==> Y ⊥⊥ X | Z. */ - public void setSymmetryAssumed() { + public void ensureSymmetry() { for (GraphoidIndFact fact : new HashSet<>(facts)) { Set X = fact.getX(); Set Y = fact.getY(); @@ -525,6 +557,10 @@ public void setSymmetryAssumed() { } } + /** + * Represents a graphoid independence fact--i.e., a fact in a general independence model (IM) + * X _||_Y | Z. + */ public static class GraphoidIndFact { private final Set X; private final Set Y; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Glasso.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java index cc147db4a8..92b0881135 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 3843b39db2..cdc35f6224 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -1344,8 +1344,8 @@ public void bryanCheckDensityClaims() { line = line.trim(); GraphoidAxioms axioms = getGraphoidAxioms(line, variables); - axioms.setTrivialtyAssumed(); - axioms.setSymmetryAssumed(); + axioms.ensureTriviality(); + axioms.ensureSymmetry(); System.out.println(axioms.getIndependenceFacts().getVariableNames()); From fa259e16cf0b3ea2a095055fc192b8161044a834 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 16:36:38 -0400 Subject: [PATCH 219/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/GraphScore.java | 154 ++++++++++-------- 1 file changed, 84 insertions(+), 70 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java index c4c9d8323c..3b2678b837 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java @@ -29,13 +29,16 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; +import javax.help.UnsupportedOperationException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** - * Implements Chickering and Meek's (2002) locally consistent score criterion. + * A "score" that implmenets implements Chickering and Meek's (2002) locally + * consistent score criterion. This is not a true score; rather, a 0 is returned + * in case dseparation holds and a 1 in case dseparation does not hold. * * @author Joseph Ramsey */ @@ -51,36 +54,30 @@ public class GraphScore implements Score { private boolean verbose = false; /** - * Constructs the score using a covariance matrix. + * Constructor + * @param dag A directed acyclic graph. */ public GraphScore(Graph dag) { this.dag = dag; - this.variables = new ArrayList<>(dag.getNodes()); this.variables.removeIf(node -> node.getNodeType() == NodeType.LATENT); - -// for (Node node : dag.getNodes()) { -// if (node.getNodeType() == NodeType.MEASURED) { -// this.variables.add(node); -// } -// } } + /** + * Constructor. + * @param facts A list known independence facts; a lookup will be donw + * from these facts. + * @see IndependenceFacts + */ public GraphScore(IndependenceFacts facts) { this.facts = facts; - this.variables = new ArrayList<>(facts.getVariables()); this.variables.removeIf(node -> node.getNodeType() == NodeType.LATENT); - -// for (Node node : facts.getVariables()) { -// if (node.getNodeType() == NodeType.MEASURED) { -// this.variables.add(node); -// } -// } } /** - * Calculates the sample likelihood and BIC score for y given its z in a simple SEM model + * Calculates the sample likelihood and BIC score for y given its z in a simple SEM model. + * @return this score. */ public double localScore(int y, int[] z) { return getPearlParentsTest().size(); @@ -104,108 +101,125 @@ private Set getPearlParentsTest() { return mb; } - private List getVariableList(int[] indices) { - List variables = new ArrayList<>(); - for (int i : indices) { - variables.add(this.variables.get(i)); - } - return variables; - } - + /** + * Returns a "score difference", which amounts to a conditional + * local scoring criterion results + * @return The "difference". + */ @Override public double localScoreDiff(int x, int y, int[] z) { return locallyConsistentScoringCriterion(x, y, z); } + /** + * The "unconditional difference." + * @return This. + */ @Override public double localScoreDiff(int x, int y) { return localScoreDiff(x, y, new int[0]); -// return localScore(y, x) - localScore(y); - } - - private double locallyConsistentScoringCriterion(int x, int y, int[] z) { - Node _y = variables.get(y); - Node _x = variables.get(x); - List _z = getVariableList(z); - - boolean dSeparatedFrom; - - if (dag != null) { - dSeparatedFrom = dag.paths().isDSeparatedFrom(_x, _y, _z); - } else if (facts != null) { - dSeparatedFrom = facts.isIndependent(_x, _y, _z); - } else { - throw new IllegalStateException("Expecting either a graph or a IndependenceFacts object."); - } - - return dSeparatedFrom ? -1.0 : 1.0; } /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. + * @throws UnsupportedOperationException Since the method doesn't make sense here. */ - public double localScore(int i, int parent) { throw new UnsupportedOperationException(); } /** - * Specialized scoring method for no parents. Used to speed up the effect edges search. + * @throws UnsupportedOperationException Since the method doesn't make sense here. */ public double localScore(int i) { throw new UnsupportedOperationException(); } + /** + * Returns a judgment for FGES as to whether a score with the bump is for an effect edge. + * @param bump The bump + * @return True if so. + * @see Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; } + /** + * @throws UnsupportedOperationException Since the method doesn't make sense here. + */ public DataSet getDataSet() { throw new UnsupportedOperationException(); } - public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - + /** + * Returns the list of variables. + * @return This list. + */ @Override public List getVariables() { return variables; } + /** + * Returns the maximum degree, which is set to 1000. + * @return 1000. + */ @Override public int getMaxDegree() { return 1000; } + /** + * @throws UnsupportedOperationException Since this method doesn't make sense here. + */ @Override public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException("The 'determines' method is not implemented for this score."); } + /** + * @throws UnsupportedOperationException Since this "score" does not use data. + */ public DataModel getData() { - return null; + throw new UnsupportedOperationException("This score does not use data."); } + /** + * @throws UnsupportedOperationException Since this score does not use data. + */ public int getSampleSize() { - return 0; - } - - public boolean getAlternativePenalty() { - return false; + throw new UnsupportedOperationException("This score does not use data, so no sample size is available."); } + /** + * Returns a copy of the DAG being searched over. + * @return This DAG. + */ public Graph getDag() { return new EdgeListGraph(dag); } - public boolean isDSeparatedFrom(Node x, Node y, List z) { + private double locallyConsistentScoringCriterion(int x, int y, int[] z) { + Node _y = variables.get(y); + Node _x = variables.get(x); + List _z = getVariableList(z); + + boolean dSeparatedFrom; + + if (dag != null) { + dSeparatedFrom = dag.paths().isDSeparatedFrom(_x, _y, _z); + } else if (facts != null) { + dSeparatedFrom = facts.isIndependent(_x, _y, _z); + } else { + throw new IllegalStateException("Expecting either a graph or a IndependenceFacts object."); + } + + return dSeparatedFrom ? -1.0 : 1.0; + } + + private boolean isDSeparatedFrom(Node x, Node y, List z) { if (dag != null) { return dag.paths().isDSeparatedFrom(x, y, z); } else if (facts != null) { @@ -215,16 +229,16 @@ public boolean isDSeparatedFrom(Node x, Node y, List z) { throw new IllegalArgumentException("Expecting either a DAG or an IndependenceFacts object."); } - public boolean isDConnectedTo(Node x, Node y, List z) { + private boolean isDConnectedTo(Node x, Node y, List z) { return !isDSeparatedFrom(x, y, z); } - public void setPrefix(List prefix) { - this.prefix = prefix; - } - - public void setN(Node n) { - this.n = n; + private List getVariableList(int[] indices) { + List variables = new ArrayList<>(); + for (int i : indices) { + variables.add(this.variables.get(i)); + } + return variables; } } From 909eaa9d3c784b00f2dc37dbe94c946a75a77a1d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 16:37:40 -0400 Subject: [PATCH 220/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java | 4 ++-- .../java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java | 8 ++++---- .../tetrad/search/{GraphScorer.java => DagScorer.java} | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/FgesOrienter.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/TsFges.java | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{GraphScorer.java => DagScorer.java} (98%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java index e90ebe2fee..17dafd2ae2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphScorer; +import edu.cmu.tetrad.search.DagScorer; import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradSerializable; @@ -71,7 +71,7 @@ public ScoredGraphsDisplay(ScoredGraphsWrapper scoredGraphsWrapper) { setup(); } - public ScoredGraphsDisplay(Graph graph, GraphScorer scorer) { + public ScoredGraphsDisplay(Graph graph, DagScorer scorer) { List _dags = SearchGraphUtils.generateCpdagDags(graph, true); for (Graph _graph : _dags) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java index 50b1a1fb4c..375908134f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphScorer; +import edu.cmu.tetrad.search.DagScorer; import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; @@ -63,7 +63,7 @@ public class ScoredGraphsWrapper implements SessionModel, GraphSource, Unmarshal /** * Transient graph scorer, null if non exists (or needs to be refreshed). */ - private final transient GraphScorer graphScorer; + private final transient DagScorer graphScorer; //=============================CONSTRUCTORS==========================// @@ -72,7 +72,7 @@ private ScoredGraphsWrapper() { this.graphScorer = null; } - public ScoredGraphsWrapper(Graph graph, GraphScorer scorer) { + public ScoredGraphsWrapper(Graph graph, DagScorer scorer) { List dags = SearchGraphUtils.generateCpdagDags(graph, true); this.graphsToScores = new HashMap<>(); this.graphScorer = scorer; @@ -201,7 +201,7 @@ public void setSelectedGraph(Graph graph) { this.selectedGraph = graph; } - public GraphScorer getGraphScorer() { + public DagScorer getGraphScorer() { return this.graphScorer; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagScorer.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScorer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagScorer.java index f1738854a4..80e8cbd3c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagScorer.java @@ -28,7 +28,7 @@ * * @author Joseph Ramsey */ -public interface GraphScorer { +public interface DagScorer { double scoreDag(Graph dag); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 28da29b7ae..5fc56fa380 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -55,7 +55,7 @@ * @author Ricardo Silva, Summer 2003 * @author Joseph Ramsey, Revisions 5/2015 */ -public final class Fges implements GraphSearch, GraphScorer { +public final class Fges implements GraphSearch, DagScorer { private final Set emptySet = new HashSet<>(); private final int[] count = new int[1]; private final int depth = 10000; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java index a6da0954f7..a6fa3f8418 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java @@ -52,7 +52,7 @@ * of the edges in the oriented graph * @author AJ Sedgewick, 5/2015 */ -public final class FgesOrienter implements GraphSearch, GraphScorer { +public final class FgesOrienter implements GraphSearch, DagScorer { /** * The covariance matrix for continuous data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 1906aa7ca0..0471cc3b17 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -52,7 +52,7 @@ * @author Joseph Ramsey, Revisions 5/2015 * @author Daniel Malinsky */ -public final class TsFges implements GraphSearch, GraphScorer { +public final class TsFges implements GraphSearch, DagScorer { /** From b293079a4683a6280237199bf7fca8af7a17ec77 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 16:38:12 -0400 Subject: [PATCH 221/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java index 15a2761754..d7959f3c7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Graph; /** - * Interface for a search method that returns a graph. + * Interface for a search method that searches and returns a graph. */ public interface GraphSearch { Graph search(); From c94bf3e027f78eb489dbf51b8773c992257402ae Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 17:04:33 -0400 Subject: [PATCH 222/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/Grasp.java | 352 +++++++++--------- 1 file changed, 181 insertions(+), 171 deletions(-) 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 a454b3e0bf..23a61beb7d 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 @@ -15,7 +15,15 @@ /** - * Implements the GRASP algorithms, with various execution flags. + *

Implements the GRaSP algorithms, with various execution flags. GRaSP can use + * either a score or an independence test; you can provide both, though if you do + * you need to use the paremeters to choose which one will be used. The score + * options is more scalable and accurate, though the independence option is + * perhaps a little easier ot deal with theoretically.

+ *

Reference:

+ *

Lam, W. Y., Andrews, B., & Ramsey, J. (2022, August). Greedy relaxations of + * the sparsest permutation algorithm. In Uncertainty in Artificial Intelligence + * (pp. 1052-1062). PMLR.

* * @author bryanandrews * @author josephramsey @@ -27,7 +35,6 @@ public class Grasp { private Knowledge knowledge = new Knowledge(); private TeyssierScorer scorer; private long start; - // flags private boolean useScore = true; private boolean useRaskuttiUhler; private boolean ordered; @@ -35,29 +42,48 @@ public class Grasp { private int uncoveredDepth = 1; private int nonSingularDepth = 1; private boolean useDataOrder = true; - - // other params private int depth = 3; private int numStarts = 1; + /** + * Constructor for a score. + * @param score The score to use. + */ public Grasp(@NotNull Score score) { this.score = score; this.variables = new ArrayList<>(score.getVariables()); this.useScore = true; } + /** + * Constructor for a test. + * @param test The test to use. + */ public Grasp(@NotNull IndependenceTest test) { this.test = test; this.variables = new ArrayList<>(test.getVariables()); this.useScore = false; } + /** + * Constructor that takes both a test and a score; only one is used-- + * the parameter setting will decide which. + * @param test The test to use. + * @param score The score to use. + */ public Grasp(@NotNull IndependenceTest test, Score score) { this.test = test; this.score = score; this.variables = new ArrayList<>(test.getVariables()); } + /** + * Given an initial permutation, 'order', of the variables, searches + * for a best permutation of the variables by rearranging the varialbes + * in 'order'. + * @param order The initial permutation. + * @return The discovered permutation at the end of the procedure. + */ public List bestOrder(@NotNull List order) { long start = MillisecondTimes.timeMillis(); order = new ArrayList<>(order); @@ -115,67 +141,154 @@ public List bestOrder(@NotNull List order) { return bestPerm; } + /** + * Returns the number of edges in the DAG implied by the discovered permuttion. + * @return This number. + */ public int getNumEdges() { return this.scorer.getNumEdges(); } + /** + * Returns the graph implied by the discovered permutation. + * @param cpDag True if a CPDAG should be returned, false if a DAG should be returned. + * @return This graph. + */ + @NotNull + public Graph getGraph(boolean cpDag) { + if (this.scorer == null) throw new IllegalArgumentException("Please run algorithm first."); + Graph graph = this.scorer.getGraph(cpDag); - private void makeValidKnowledgeOrder(List order) { - if (!this.knowledge.isEmpty()) { - 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; - }); + NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); + graph.addAttribute("score ", nf.format(this.scorer.score())); + return graph; + } + + /** + * Sets the number of times the best order algorithm should be rerun with different + * starting permtutions in search of a best BIC scoring permutation. + * @param numStarts This number; if 1, it is run just once with the given + * starting permutation; if 2 or higher, it is rerun subsequently + * with random initial permutations and the best scoring + * discovered final permutation is reported. + * @see #setUseDataOrder(boolean) + */ + public void setNumStarts(int numStarts) { + this.numStarts = numStarts; + } + + /** + * True if the order of the variables in the data should be used for an initial + * best-order search, false if a random permutation should be used. (Subsequence + * automatic best order runs will use random permutations.) This is included + * so that the algorithm will be capable of outputting the same results with the + * same data without any randomness. + * @param useDataOrder True if so + */ + public void setUseDataOrder(boolean useDataOrder) { + this.useDataOrder = useDataOrder; + } + + /** + * Returns the variables. + * @return This list. + */ + public List getVariables() { + return this.variables; + } + + /** + * Sets whether verbose output is printed. + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + if (test != null) { + this.test.setVerbose(verbose); + } + } + + /** + * Sets the knowledge used in the search. The search is set up to honor all + * knowledge of forbidden or required directed edges, and tiered knowledge. + * @param knowledge This knowledge. + */ + public void setKnowledge(Knowledge knowledge) { + this.knowledge = knowledge; + } + + /** + * Sets the depth of ??? (Bryan cnan you document this?) + * @param depth This depth. + */ + public void setDepth(int depth) { + if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1."); + this.depth = depth; + } + + /** + * Sets the depth of ??? (Bryan cnan you document this?) + * @param uncoveredDepth This depth. + */ public void setSingularDepth(int uncoveredDepth) { + if (uncoveredDepth < -1) throw new IllegalArgumentException("Uncovered depth should be >= -1."); + this.uncoveredDepth = uncoveredDepth; + } + + /** + * Sets the depth of ??? (Bryan cnan you document this?) + * @param nonSingularDepth This depth. + */ public void setNonSingularDepth(int nonSingularDepth) { + if (nonSingularDepth < -1) throw new IllegalArgumentException("Non-singular depth should be >= -1."); + this.nonSingularDepth = nonSingularDepth; + } + + /** + * True if the score should be used (if both a score and a test are provided), + * false if not. + * @param useScore True if so. + */ + public void setUseScore(boolean useScore) { + this.useScore = useScore; + } + + /** + * True if GRasP0 should be performed before GRaSP1 and GRaSP1 before GRaSP2. + * False if this ordering should not be imposed. + * @param ordered True if the ordering should be imposed. + */ + public void setOrdered(boolean ordered) { + this.ordered = ordered; + } + + /** + * True if the Raskutti-Uhler method should be used, false if the Verma-Pearl + * method should be used. + * @param useRaskuttiUhler True if RU, false if VP. + * @see #setNumStarts(int) + */ + public void setUseRaskuttiUhler(boolean useRaskuttiUhler) { + this.useRaskuttiUhler = useRaskuttiUhler; + + if (this.useRaskuttiUhler) { + this.useScore = false; } } + private boolean violatesKnowledge(List order) { + if (this.knowledge.isEmpty()) return false; -// 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."); -// } -// } -// } - - - public List grasp(@NotNull TeyssierScorer scorer) { + 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; + } + } + } + + return false; + } + + private List grasp(@NotNull TeyssierScorer scorer) { scorer.clearBookmarks(); List depths = new ArrayList<>(); @@ -216,6 +329,18 @@ public List grasp(@NotNull TeyssierScorer scorer) { return scorer.getPi(); } + private void makeValidKnowledgeOrder(List order) { + if (!this.knowledge.isEmpty()) { + 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; + }); + } + } + + private void graspDfs(@NotNull TeyssierScorer scorer, double sOld, int[] depth, int currentDepth, Set> tucks, Set>> dfsHistory) { for (Node y : scorer.getShuffledVariables()) { @@ -295,119 +420,4 @@ private void graspDfs(@NotNull TeyssierScorer scorer, double sOld, int[] depth, } } } - - @NotNull - public Graph getGraph(boolean cpDag) { - if (this.scorer == null) throw new IllegalArgumentException("Please run algorithm first."); - Graph graph = this.scorer.getGraph(cpDag); - - NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); - graph.addAttribute("score ", nf.format(this.scorer.score())); - return graph; - } - - public void setNumStarts(int numStarts) { - this.numStarts = numStarts; - } - - public List getVariables() { - return this.variables; - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - if (test != null) { - this.test.setVerbose(verbose); - } - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - - public void setDepth(int depth) { - if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1."); - this.depth = depth; - } - - public void setSingularDepth(int uncoveredDepth) { - if (uncoveredDepth < -1) throw new IllegalArgumentException("Uncovered depth should be >= -1."); - this.uncoveredDepth = uncoveredDepth; - } - - public void setNonSingularDepth(int nonSingularDepth) { - if (nonSingularDepth < -1) throw new IllegalArgumentException("Non-singular depth should be >= -1."); - this.nonSingularDepth = nonSingularDepth; - } - - public void setUseScore(boolean useScore) { - this.useScore = useScore; - } - - private boolean violatesKnowledge(List order) { - if (this.knowledge.isEmpty()) return false; - - 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; - } - } - } - - 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; -// } - - public void setOrdered(boolean ordered) { - this.ordered = ordered; - } - - public void setUseRaskuttiUhler(boolean usePearl) { - this.useRaskuttiUhler = usePearl; - - if (this.useRaskuttiUhler) { - this.useScore = false; - } - } - - public void setUseDataOrder(boolean useDataOrder) { - this.useDataOrder = useDataOrder; - } - } \ No newline at end of file From 06fbe61628005b238d3ac8aa6004c29ab53de949 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 17:06:23 -0400 Subject: [PATCH 223/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/Grasp.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) 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 23a61beb7d..c1a85d1357 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 @@ -1,7 +1,8 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; @@ -47,6 +48,7 @@ public class Grasp { /** * Constructor for a score. + * * @param score The score to use. */ public Grasp(@NotNull Score score) { @@ -57,6 +59,7 @@ public Grasp(@NotNull Score score) { /** * Constructor for a test. + * * @param test The test to use. */ public Grasp(@NotNull IndependenceTest test) { @@ -68,7 +71,8 @@ public Grasp(@NotNull IndependenceTest test) { /** * Constructor that takes both a test and a score; only one is used-- * the parameter setting will decide which. - * @param test The test to use. + * + * @param test The test to use. * @param score The score to use. */ public Grasp(@NotNull IndependenceTest test, Score score) { @@ -81,6 +85,7 @@ public Grasp(@NotNull IndependenceTest test, Score score) { * Given an initial permutation, 'order', of the variables, searches * for a best permutation of the variables by rearranging the varialbes * in 'order'. + * * @param order The initial permutation. * @return The discovered permutation at the end of the procedure. */ @@ -143,6 +148,7 @@ public List bestOrder(@NotNull List order) { /** * Returns the number of edges in the DAG implied by the discovered permuttion. + * * @return This number. */ public int getNumEdges() { @@ -151,6 +157,7 @@ public int getNumEdges() { /** * Returns the graph implied by the discovered permutation. + * * @param cpDag True if a CPDAG should be returned, false if a DAG should be returned. * @return This graph. */ @@ -167,6 +174,7 @@ public Graph getGraph(boolean cpDag) { /** * Sets the number of times the best order algorithm should be rerun with different * starting permtutions in search of a best BIC scoring permutation. + * * @param numStarts This number; if 1, it is run just once with the given * starting permutation; if 2 or higher, it is rerun subsequently * with random initial permutations and the best scoring @@ -183,6 +191,7 @@ public void setNumStarts(int numStarts) { * automatic best order runs will use random permutations.) This is included * so that the algorithm will be capable of outputting the same results with the * same data without any randomness. + * * @param useDataOrder True if so */ public void setUseDataOrder(boolean useDataOrder) { @@ -191,6 +200,7 @@ public void setUseDataOrder(boolean useDataOrder) { /** * Returns the variables. + * * @return This list. */ public List getVariables() { @@ -199,6 +209,7 @@ public List getVariables() { /** * Sets whether verbose output is printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -211,6 +222,7 @@ public void setVerbose(boolean verbose) { /** * Sets the knowledge used in the search. The search is set up to honor all * knowledge of forbidden or required directed edges, and tiered knowledge. + * * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { @@ -219,6 +231,7 @@ public void setKnowledge(Knowledge knowledge) { /** * Sets the depth of ??? (Bryan cnan you document this?) + * * @param depth This depth. */ public void setDepth(int depth) { @@ -228,16 +241,20 @@ public void setDepth(int depth) { /** * Sets the depth of ??? (Bryan cnan you document this?) + * * @param uncoveredDepth This depth. - */ public void setSingularDepth(int uncoveredDepth) { + */ + public void setSingularDepth(int uncoveredDepth) { if (uncoveredDepth < -1) throw new IllegalArgumentException("Uncovered depth should be >= -1."); this.uncoveredDepth = uncoveredDepth; } /** * Sets the depth of ??? (Bryan cnan you document this?) + * * @param nonSingularDepth This depth. - */ public void setNonSingularDepth(int nonSingularDepth) { + */ + public void setNonSingularDepth(int nonSingularDepth) { if (nonSingularDepth < -1) throw new IllegalArgumentException("Non-singular depth should be >= -1."); this.nonSingularDepth = nonSingularDepth; } @@ -245,6 +262,7 @@ public void setDepth(int depth) { /** * True if the score should be used (if both a score and a test are provided), * false if not. + * * @param useScore True if so. */ public void setUseScore(boolean useScore) { @@ -254,6 +272,7 @@ public void setUseScore(boolean useScore) { /** * True if GRasP0 should be performed before GRaSP1 and GRaSP1 before GRaSP2. * False if this ordering should not be imposed. + * * @param ordered True if the ordering should be imposed. */ public void setOrdered(boolean ordered) { @@ -263,6 +282,7 @@ public void setOrdered(boolean ordered) { /** * True if the Raskutti-Uhler method should be used, false if the Verma-Pearl * method should be used. + * * @param useRaskuttiUhler True if RU, false if VP. * @see #setNumStarts(int) */ From 03aa7cff7a1e23d6e6fea499d557f95d248c4899 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 17:17:40 -0400 Subject: [PATCH 224/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algorithm/oracle/cpdag/GraspTol.java | 184 ------------------ .../algorithm/oracle/pag/GraspFci.java | 1 - .../java/edu/cmu/tetrad/search/GraspFci.java | 22 +-- .../{ => work_in_progress}/GraspTol.java | 6 +- 4 files changed, 14 insertions(+), 199 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GraspTol.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/GraspTol.java (98%) 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/GraspTol.java deleted file mode 100644 index c8d8cbd295..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GraspTol.java +++ /dev/null @@ -1,184 +0,0 @@ -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; -import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; -import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; -import edu.cmu.tetrad.annotation.AlgType; -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.IndependenceTest; -import edu.cmu.tetrad.search.Score; -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.List; - -/** - * GRaSP (Greedy Relaxations of Sparsest Permutation) - * - * @author bryanandrews - * @author josephramsey - */ -@edu.cmu.tetrad.annotation.Algorithm( - name = "GRaSP-Tol", - command = "grasptol", - algoType = AlgType.forbid_latent_common_causes -) -@Bootstrapping -@Experimental -public class GraspTol 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() { - // Used in reflection; do not delete. - } - - public GraspTol(ScoreWrapper score, IndependenceWrapper test) { - this.score = score; - this.test = test; - } - - @Override - public Graph search(DataModel dataModel, Parameters parameters) { - 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); - IndependenceTest test = this.test.getTest(dataModel, parameters); - - test.setVerbose(parameters.getBoolean(Params.VERBOSE)); - edu.cmu.tetrad.search.GraspTol grasp = new edu.cmu.tetrad.search.GraspTol(test, score); - - grasp.setDepth(parameters.getInt(Params.GRASP_DEPTH)); - grasp.setUncoveredDepth(parameters.getInt(Params.GRASP_SINGULAR_DEPTH)); - grasp.setNonSingularDepth(parameters.getInt(Params.GRASP_NONSINGULAR_DEPTH)); - grasp.setOrdered(parameters.getBoolean(Params.GRASP_ORDERED_ALG)); - grasp.setUseScore(parameters.getBoolean(Params.GRASP_USE_SCORE)); - grasp.setUseRaskuttiUhler(parameters.getBoolean(Params.GRASP_USE_RASKUTTI_UHLER)); - grasp.setUseDataOrder(parameters.getBoolean(Params.GRASP_USE_DATA_ORDER)); - 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.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); - - 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 - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "GRaSPTol (Greedy Relaxed Sparsest Permutation Tolerance) using " + this.test.getDescription() - + " or " + this.score.getDescription(); - } - - @Override - public DataType getDataType() { - return this.score.getDataType(); - } - - @Override - public List getParameters() { - ArrayList params = new ArrayList<>(); - - // Flags - params.add(Params.GRASP_DEPTH); - params.add(Params.GRASP_SINGULAR_DEPTH); - params.add(Params.GRASP_NONSINGULAR_DEPTH); - params.add(Params.GRASP_TOLERANCE_DEPTH); - params.add(Params.GRASP_ORDERED_ALG); -// params.add(Params.GRASP_USE_SCORE); - params.add(Params.GRASP_USE_RASKUTTI_UHLER); - params.add(Params.GRASP_USE_DATA_ORDER); - params.add(Params.GRASP_ALLOW_RANDOMNESS_INSIDE_ALGORITHM); - params.add(Params.CACHE_SCORES); - params.add(Params.TIME_LAG); - params.add(Params.VERBOSE); - - // Parameters - params.add(Params.NUM_STARTS); - - return params; - } - - @Override - public ScoreWrapper getScoreWrapper() { - return this.score; - } - - @Override - public void setScoreWrapper(ScoreWrapper score) { - this.score = score; - } - - @Override - public IndependenceWrapper getIndependenceWrapper() { - return this.test; - } - - @Override - public void setIndependenceWrapper(IndependenceWrapper independenceWrapper) { - this.test = independenceWrapper; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge.copy(); - } - - @Override - 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/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index 2920d383f2..5295cd7410 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -98,7 +98,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.setDoDiscriminatingPathRule(parameters.getBoolean(Params.DO_DISCRIMINATING_PATH_RULE)); - search.setPossibleDsepSearchDone(parameters.getBoolean((Params.POSSIBLE_DSEP_DONE))); // General search.setVerbose(parameters.getBoolean(Params.VERBOSE)); 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 ccca654a03..4ffa516a41 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 @@ -35,14 +35,16 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - * J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm + *

Replaces FGES in GFCI by GRaSP using a score, which is another score-based + * (but more accurate) algorithm.

+ *

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for - * FGES. - * - * @author Juan Miguel Ogarrio - * @author ps7z - * @author jdramsey - * @author bryan andrews + * FGES.

+ * @author peterspirtes + * @author josephramsey + * @author bryanandrews + * @see GFci + * @see Grasp */ public final class GraspFci implements GraphSearch { @@ -84,8 +86,6 @@ public final class GraspFci implements GraphSearch { private boolean useDataOrder = true; private boolean useScore = true; private boolean doDiscriminatingPathRule = true; - private boolean possibleDsepSearchDone = true; - private boolean ordered = false; private int graspDepth = 3; private int uncoveredDepth = 1; @@ -397,10 +397,6 @@ public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { this.doDiscriminatingPathRule = doDiscriminatingPathRule; } - public void setPossibleDsepSearchDone(boolean possibleDsepSearchDone) { - this.possibleDsepSearchDone = possibleDsepSearchDone; - } - public void setGraspDepth(int graspDepth) { if (graspDepth < -1) throw new IllegalArgumentException("GRaSP depth should be >= -1."); this.graspDepth = graspDepth; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java index 15d1ca4ce9..afc6a67455 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java @@ -1,8 +1,12 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.GraphScore; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; From ba483e64d03a85ba2f5df58f7bf6a5bbbfde316c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 17:26:11 -0400 Subject: [PATCH 225/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/GrowShrinkTree.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 e2222634bd..a095a13d06 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 @@ -5,6 +5,13 @@ import java.util.*; +/** + *

A tree-based score-caching data structure useful for permutation searches. + * The use of this caching data structure speeds these algorithms up + * significantly.

+ * + * @author bryanandrews + */ public class GrowShrinkTree { private final Score score; private final Map index; From 6d5ade317eecb5ad56cedf449a89627351466a08 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 17:30:47 -0400 Subject: [PATCH 226/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/GrowShrink.java | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index 48aae946e1..a4675e0149 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -27,9 +27,10 @@ import java.util.List; /** - *

Implements the Grow-Shrink algorithm of Margaritis and Thrun. Reference: "Bayesian Network - * Induction via LocalmNeighborhoods."

- * + *

Implements the Grow-Shrink algorithm of Margaritis and Thrun, a simple yet correct + * and useful Markov blanket search.

+ *

Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. + * Advances in neural information processing systems, 12.

* @author Joseph Ramsey */ public class GrowShrink implements MbSearch { @@ -42,12 +43,11 @@ public class GrowShrink implements MbSearch { /** * The list of variables being searched over. Must contain the target. */ - private List variables; + private final List variables; /** * Constructs a new search. - * - * @param test The source of conditional independence information for the search. + * @param test The test used for this search. */ public GrowShrink(IndependenceTest test) { if (test == null) { @@ -104,34 +104,19 @@ public List findMb(Node target) { return blanket; } + /** + * Returns "Grow Shrink". + * @return This string. + */ public String getAlgorithmName() { return "Grow Shrink"; } + /** + * @throws UnsupportedOperationException Since independence tests are not counted. + */ public int getNumIndependenceTests() { - return 0; - } - - private Node getVariableForName(String targetName) { - Node target = null; - - for (Node V : this.variables) { - if (V.getName().equals(targetName)) { - target = V; - break; - } - } - - if (target == null) { - throw new IllegalArgumentException( - "Target variable not in dataset: " + targetName); - } - - return target; - } - - public void setVariables(List variables) { - this.variables = variables; + throw new UnsupportedOperationException("Independence tests are not counted in the algorithm."); } } From eff2e2ce5ecb7e98e08f4a2b092fb2de64e9368b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 17:37:17 -0400 Subject: [PATCH 227/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/GSquareTest.java | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) 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 c75923a27d..2847e9b641 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 @@ -63,7 +63,11 @@ public final class GSquareTest { */ private double alpha; - + /** + * Constructor + * @param dataSet The discrete dataset for which test results are requested. + * @param alpha The alpha sigificance level cutoff. + */ public GSquareTest(DataSet dataSet, double alpha) { if (alpha < 0.0 || alpha > 1.0) { throw new IllegalArgumentException("Significance level must be in " + @@ -84,14 +88,13 @@ public GSquareTest(DataSet dataSet, double alpha) { 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. + * @param testIndices The indices of the test result needed, in order. So for the above, [0 1 2 3...max]. + * @return the test result. + * @see Result */ public Result calcGSquare(int[] testIndices) { @@ -214,8 +217,7 @@ public Result calcGSquare(int[] testIndices) { } /** - * Simple class to store the parameters of the result returned by the G Square test. - * + * Stores the parameters of the result returned by the G Square test and its p-value. * @author Frank Wimberly */ public static final class Result { @@ -267,11 +269,20 @@ public boolean isIndep() { } } - + /** + * Returns the dimensions of the variables, in order. + * @return These dimensions, as an int[] array. For instance, if the array is [2 3], + * then the first variable has 2 categories and second variable has 3 categories. + */ public int[] getDims() { return this.dims; } + /** + * Returns the cell table for this test. + * @return This table. + * @see CellTable + */ public CellTable getCellTable() { return this.cellTable; } @@ -285,6 +296,7 @@ public double getAlpha() { /** * Sets the significance level to be used for tests. + * @param alpha The alpha significance level of the test. */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { @@ -295,20 +307,21 @@ public void setAlpha(double 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; - } - + /** + * Returns the dataset used for this test. + * @return This dataset. + */ public DataSet getDataSet() { return this.dataSet; } + /** + * Returns a judgement of whether the variables index by 'testIndices' + * determine the variable index by 'p'. + * @param testIndices The indices of the conditioning variables. + * @param p The index of the child variable. + * @return True if the conditioning variables determine the child variable. + */ public boolean isDetermined(int[] testIndices, double p) { // Reset the cell table for the columns referred to in @@ -360,6 +373,16 @@ public boolean isDetermined(int[] testIndices, double p) { return true; } + + private 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; + } } From 5fd16bf9049fef43f5f1c1cd09d3c0da7fffa4cd Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 18:17:01 -0400 Subject: [PATCH 228/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java index de1152dbff..5956c5ce29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java @@ -1,7 +1,8 @@ package edu.cmu.tetrad.search; /** - * Created by jdramsey on 2/21/16. + * Interface for an algorithm can can get/set a value for penalty disoucnt. + * @author josephramsey */ public interface HasPenaltyDiscount extends Score { void setPenaltyDiscount(double penaltyDiscount); From 33762599003f0532a356145e27894a6413606266 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 18:18:18 -0400 Subject: [PATCH 229/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java index fc2d2b4cf0..0f969985fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java @@ -8,6 +8,8 @@ *

An implemetation of the Kuhn–Munkres assignment algorithm of the year 1957. * https://en.wikipedia.org/wiki/Hungarian_algorithm.

*

From: https://github.com/aalmi/HungarianAlgorithm

+ *

This is not our code code; please see the references given. We've just + * made a few tweaks to make it work better in Tetrad. Thanks aalmi.

* * @author https://github.com/aalmi | march 2014 * @version 1.0 From 711069abf6e7359081095af223ade7cfe3c4a55f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 18:23:29 -0400 Subject: [PATCH 230/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Ida.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index f6d0817235..aff982603b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -19,11 +19,11 @@ import static org.apache.commons.math3.util.FastMath.min; /** - * Implements the IDA algorithm, Maathuis, Marloes H., Markus Kalisch, and Peter Bühlmann. + *

Implements the IDA algorithm

+ *

Maathuis, Marloes H., Markus Kalisch, and Peter Bühlmann. * "Estimating high-dimensional intervention effects from observational data." - * The Annals of Statistics 37.6A (2009): 3133-3164. - * - * @author jdramsey@andrew.cmu.edu + * The Annals of Statistics 37.6A (2009): 3133-3164.

+ * @author josephramsey */ public class Ida { private final DataSet dataSet; @@ -32,9 +32,16 @@ public class Ida { private final Map nodeIndices; private final ICovarianceMatrix allCovariances; - public Ida(DataSet dataSet, Graph pattern, List possibleCauses) { + /** + * Constructor. + * @param dataSet The dataset being searched over. + * @param cpdag The CPDAG (found, e.g., by running PC, or some other CPDAG- + * producing algorithm. + * @param possibleCauses The possible causes to be considered. + */ + public Ida(DataSet dataSet, Graph cpdag, List possibleCauses) { this.dataSet = DataUtils.convertNumericalDiscreteToContinuous(dataSet); - this.pattern = pattern; + this.pattern = cpdag; possibleCauses = GraphUtils.replaceNodes(possibleCauses, dataSet.getVariables()); this.possibleCauses = possibleCauses; @@ -42,14 +49,13 @@ public Ida(DataSet dataSet, Graph pattern, List possibleCauses) { this.nodeIndices = new HashMap<>(); - for (int i = 0; i < pattern.getNodes().size(); i++) { - this.nodeIndices.put(pattern.getNodes().get(i).getName(), i); + for (int i = 0; i < cpdag.getNodes().size(); i++) { + this.nodeIndices.put(cpdag.getNodes().get(i).getName(), i); } } /** * Returns the minimum effects of X on Y for X in V \ {Y}, sorted downward by minimum effect - * * @param y The child variable. * @return Two sorted lists, one of nodes, the other of corresponding minimum effects, sorted downward by * minimum effect size. @@ -73,8 +79,7 @@ public NodeEffects getSortedMinEffects(Node y) { /** * A list of nodes and corresponding minimum effects. - * - * @author jdramsey@andrew.cmu.edu + * @author josephramsey */ public static class NodeEffects { private List nodes; @@ -112,6 +117,12 @@ public String toString() { } } + /** + * Calculates the true effect of (x, y) given the true DAG (which + * must be provided. + * @param trueDag The true DAG. + * @return The true effect of (x, y). + */ public double trueEffect(Node x, Node y, Graph trueDag) { if (x == y) throw new IllegalArgumentException("x == y"); @@ -223,7 +234,6 @@ private LinkedList getEffects(Node x, Node y) { /** * Returns a map from nodes in V \ {Y} to their minimum effects. - * * @param y The child variable * @return Thia map. */ From 4358e26a0d034aaf458b1e86ef5e1db25860470b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 18:23:59 -0400 Subject: [PATCH 231/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/IFas.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java index 01b02d90cb..0449531f17 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java @@ -31,28 +31,19 @@ /** * An interface for fast adjacency searches (i.e. PC adjacency searches). + * @author josephramsey */ public interface IFas { void setKnowledge(Knowledge knowledge); - SepsetMap getSepsets(); - void setDepth(int depth); - Graph search(); - Graph search(List nodes); - long getElapsedTime(); - int getNumIndependenceTests(); - List getNodes(); - List getAmbiguousTriples(Node node); - void setVerbose(boolean verbose); - void setOut(PrintStream out); } From df8de7f54ecfa729d4797d4eee75d477b044a551 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 18:24:48 -0400 Subject: [PATCH 232/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java index bffc5a8ed5..9a15294ad7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java @@ -38,7 +38,7 @@ *

Importantly, only the variables from the first score will be * returned from the getVariables method, so it is up to the user to * ensure that all of the scores share the same (object-identical) - * variables.

+ * variables.

* * @author Joseph Ramsey * @see Fges From 8f437bae5b78556ae83af9d976a740264fc0b148 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 18:37:22 -0400 Subject: [PATCH 233/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../editor/IndependenceFactsEditor.java | 2 +- .../tetradapp/editor/MarkovCheckEditor.java | 16 +++--- .../cmu/tetrad/data/IndependenceFacts.java | 2 +- .../main/java/edu/cmu/tetrad/graph/Paths.java | 4 +- .../cmu/tetrad/search/BuildPureClusters.java | 4 +- .../main/java/edu/cmu/tetrad/search/Cfci.java | 4 +- .../main/java/edu/cmu/tetrad/search/Fas.java | 2 +- .../cmu/tetrad/search/FasDeterministic.java | 6 +- .../edu/cmu/tetrad/search/GrowShrink.java | 4 +- .../cmu/tetrad/search/IndependenceResult.java | 55 ++++++++++++++++--- .../main/java/edu/cmu/tetrad/search/Kci.java | 10 ++-- .../java/edu/cmu/tetrad/search/PcAll.java | 4 +- .../main/java/edu/cmu/tetrad/search/PcMb.java | 2 +- .../cmu/tetrad/search/PossibleDsepFci.java | 2 +- .../edu/cmu/tetrad/search/RBExperiments.java | 2 +- .../edu/cmu/tetrad/search/ResolveSepsets.java | 4 +- .../main/java/edu/cmu/tetrad/search/Rfci.java | 8 +-- .../edu/cmu/tetrad/search/SampleVcpc.java | 4 +- .../edu/cmu/tetrad/search/SampleVcpcFast.java | 4 +- .../cmu/tetrad/search/SearchGraphUtils.java | 6 +- .../tetrad/search/SepsetsConservative.java | 10 ++-- .../edu/cmu/tetrad/search/SepsetsGreedy.java | 6 +- .../tetrad/search/SepsetsPossibleDsep.java | 4 +- .../edu/cmu/tetrad/search/SepsetsSet.java | 2 +- .../edu/cmu/tetrad/search/TeyssierScorer.java | 6 +- .../java/edu/cmu/tetrad/search/TsFas.java | 4 +- .../java/edu/cmu/tetrad/search/mb/Iamb.java | 4 +- .../edu/cmu/tetrad/search/mb/IambnPc.java | 2 +- .../edu/cmu/tetrad/search/mb/InterIamb.java | 4 +- .../java/edu/cmu/tetrad/search/mb/Mmmb.java | 8 +-- .../search/work_in_progress/DMSearch.java | 4 +- .../search/work_in_progress/FasDci.java | 4 +- .../search/work_in_progress/FasFdr.java | 2 +- .../tetrad/search/work_in_progress/VcFas.java | 4 +- .../tetrad/search/work_in_progress/VcPc.java | 6 +- .../search/work_in_progress/VcPcAlt.java | 4 +- .../search/work_in_progress/VcPcFast.java | 6 +- .../bayesian/constraint/search/RfciBsc.java | 2 +- .../edu/cmu/tetrad/test/TestCheckMarkov.java | 4 +- .../java/edu/cmu/tetrad/test/TestFges.java | 4 +- .../tetrad/test/TestFisherZCalibration.java | 6 +- .../java/edu/cmu/tetrad/test/TestGrasp.java | 10 ++-- .../cmu/tetrad/test/TestIndTestGSquare.java | 2 +- 43 files changed, 147 insertions(+), 106 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java index 7853bcebb1..1ccfb635d3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java @@ -638,7 +638,7 @@ private void generateResults() { try { IndependenceResult result = independenceTest.checkIndependence(x, y, z); - indep = result.independent() + indep = result.isIndependent() ? IndependenceResultIndFacts.Type.INDEPENDENT : IndependenceResultIndFacts.Type.DEPENDENT; pValue = result.getPValue(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java index c9cae20317..6b44ff1d2d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java @@ -210,13 +210,13 @@ public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 2) { if (getIndependenceTest() instanceof IndTestDSep) { - if (result.independent()) { + if (result.isIndependent()) { return "D-SEPARATED"; } else { return "d-connected"; } } else { - if (result.independent()) { + if (result.isIndependent()) { return "INDEPENDENT"; } else { return "dependent"; @@ -306,7 +306,7 @@ public void mouseClicked(MouseEvent e) { int dependent = 0; for (IndependenceResult result : model.getResults(false)) { - if (result.dependent() && !Double.isNaN(result.getPValue())) dependent++; + if (result.isDependent() && !Double.isNaN(result.getPValue())) dependent++; } fractionDependentDep = dependent / (double) model.getResults(false).size(); @@ -392,13 +392,13 @@ public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 2) { if (getIndependenceTest() instanceof IndTestDSep) { - if (result.independent()) { + if (result.isIndependent()) { return "D-SEPARATED"; } else { return "d-connected"; } } else { - if (result.independent()) { + if (result.isIndependent()) { return "INDEPENDENT"; } else { return "dependent"; @@ -488,7 +488,7 @@ public void mouseClicked(MouseEvent e) { int dependent = 0; for (IndependenceResult result : model.getResults(true)) { - if (result.dependent() && !Double.isNaN(result.getPValue())) dependent++; + if (result.isDependent() && !Double.isNaN(result.getPValue())) dependent++; } fractionDependentIndep = dependent / (double) model.getResults(true).size(); @@ -621,7 +621,7 @@ public List call() { boolean verbose = test.isVerbose(); test.setVerbose(verbose); IndependenceResult result = test.checkIndependence(x, y, z); - boolean indep = result.independent(); + boolean indep = result.isIndependent(); double pValue = result.getPValue(); test.setVerbose(verbose); @@ -669,7 +669,7 @@ public List call() { int dependent = 0; for (IndependenceResult result : model.getResults(indep)) { - if (result.dependent() && !Double.isNaN(result.getPValue())) dependent++; + if (result.isDependent() && !Double.isNaN(result.getPValue())) dependent++; } if (indep) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java index 012598dbfe..bf946a9a77 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java @@ -73,7 +73,7 @@ public IndependenceFacts(Graph graph) { Z.add(nodes.get(choice[perm[i]])); } - if (dsep.checkIndependence(x, y, Z).independent()) { + if (dsep.checkIndependence(x, y, Z).isIndependent()) { facts.add(new IndependenceFact(x, y, Z)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java index 2a5cb11803..6a44aa9f02 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java @@ -907,7 +907,7 @@ public void removeByPossibleDsep(IndependenceTest test, SepsetMap sepsets) { List sepset = GraphUtils.asList(choice, possibleDsep); if (new HashSet<>(graph.getAdjacentNodes(a)).containsAll(sepset)) continue; if (new HashSet<>(graph.getAdjacentNodes(b)).containsAll(sepset)) continue; - if (test.checkIndependence(a, b, sepset).independent()) { + if (test.checkIndependence(a, b, sepset).isIndependent()) { graph.removeEdge(edge); if (sepsets != null) { @@ -931,7 +931,7 @@ public void removeByPossibleDsep(IndependenceTest test, SepsetMap sepsets) { List sepset = GraphUtils.asList(choice, possibleDsep); if (new HashSet<>(graph.getAdjacentNodes(a)).containsAll(sepset)) continue; if (new HashSet<>(graph.getAdjacentNodes(b)).containsAll(sepset)) continue; - if (test.checkIndependence(a, b, sepset).independent()) { + if (test.checkIndependence(a, b, sepset).isIndependent()) { graph.removeEdge(edge); if (sepsets != null) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index e82e1feb57..cfd163c7de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -462,11 +462,11 @@ private boolean uncorrelated(int v1, int v2) { if (getCovarianceMatrix() != null) { List variables = getCovarianceMatrix().getVariables(); return getIndependenceTest().checkIndependence(variables.get(v1), - variables.get(v2)).independent(); + variables.get(v2)).isIndependent(); } else { return getIndependenceTest().checkIndependence(this.dataSet.getVariable(v1), - this.dataSet.getVariable(v2)).independent(); + this.dataSet.getVariable(v2)).isIndependent(); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 5c26942cad..1732187d47 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -400,7 +400,7 @@ private TripleType getTripleType(Node x, Node y, Node z, while ((choice = cg.next()) != null) { List condSet = Cfci.asList(choice, _nodes); - if (test.checkIndependence(x, z, condSet).independent()) { + if (test.checkIndependence(x, z, condSet).isIndependent()) { if (condSet.contains(y)) { existsSepsetContainingY = true; } else { @@ -428,7 +428,7 @@ private TripleType getTripleType(Node x, Node y, Node z, while ((choice = cg.next()) != null) { List condSet = Cfci.asList(choice, _nodes); - if (test.checkIndependence(x, z, condSet).independent()) { + if (test.checkIndependence(x, z, condSet).isIndependent()) { if (condSet.contains(y)) { existsSepsetContainingY = true; } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index 69a51f9c52..b9266b9e5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -412,7 +412,7 @@ private boolean checkSide(Map scores, IndependenceTest test, Map Z = GraphUtils.asList(choice, ppx); this.numIndependenceTests++; - boolean independent = test.checkIndependence(x, y, Z).independent(); + boolean independent = test.checkIndependence(x, y, Z).isIndependent(); boolean noEdgeRequired = this.knowledge.noEdgeRequired(x.getName(), y.getName()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index b1c5014deb..57d3de3f76 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -279,7 +279,7 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map nodes, IndependenceTest test, Map z) { if (verbose) { double p = result.getPValue(); - if (result.independent()) { + if (result.isIndependent()) { TetradLogger.getInstance().forceLogMessage(fact + " INDEPENDENT p = " + p); } else { TetradLogger.getInstance().forceLogMessage(fact + " dependent p = " + p); } } - return new IndependenceResult(fact, result.independent(), result.getPValue()); + return new IndependenceResult(fact, result.isIndependent(), result.getPValue()); } else { List rows = getRows(this.data); @@ -230,7 +230,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { IndependenceResult result = facts.get(fact); if (this.facts.get(fact) != null) { - return new IndependenceResult(fact, result.independent(), result.getPValue()); + return new IndependenceResult(fact, result.isIndependent(), result.getPValue()); } else { if (z.isEmpty()) { result = isIndependentUnconditional(x, y, fact, _data, h, N, hash); @@ -242,7 +242,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (verbose) { double p = result.getPValue(); - if (result.independent()) { + if (result.isIndependent()) { TetradLogger.getInstance().forceLogMessage(fact + " INDEPENDENT p = " + p); } else { @@ -250,7 +250,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } } - return new IndependenceResult(fact, result.independent(), result.getPValue()); + return new IndependenceResult(fact, result.isIndependent(), result.getPValue()); } } 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 a6fd2dd4a5..511e7fb958 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 @@ -526,7 +526,7 @@ private List> getSepsets(Node i, Node k, Graph g) { } List v = GraphUtils.asList(choice, adji); - if (getIndependenceTest().checkIndependence(i, k, v).independent()) sepsets.add(v); + if (getIndependenceTest().checkIndependence(i, k, v).isIndependent()) sepsets.add(v); } } @@ -540,7 +540,7 @@ private List> getSepsets(Node i, Node k, Graph g) { } List v = GraphUtils.asList(choice, adjk); - if (getIndependenceTest().checkIndependence(i, k, v).independent()) sepsets.add(v); + if (getIndependenceTest().checkIndependence(i, k, v).isIndependent()) sepsets.add(v); } } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index 98533c4fae..cad9e78b13 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -639,7 +639,7 @@ private void finishUp(long start, Graph graph) { } private boolean independent(Node v, Node w, List z) { - boolean independent = getTest().checkIndependence(v, w, z).independent(); + boolean independent = getTest().checkIndependence(v, w, z).isIndependent(); this.numIndependenceTests++; return independent; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java index e0ba944d92..84ca63793f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java @@ -141,7 +141,7 @@ private List getCondSet(IndependenceTest test, Node node1, Node node2, int while ((choice = cg.next()) != null) { List condSet = GraphUtils.asList(choice, possParents); - boolean independent = test.checkIndependence(node1, node2, condSet).independent(); + boolean independent = test.checkIndependence(node1, node2, condSet).isIndependent(); if (independent && noEdgeRequired) { return condSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java index f795973f9a..a7a43cd2f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java @@ -629,7 +629,7 @@ private DataSet createDepDataFiltering(Map H, DataSet IndTestProbabilistic bsTest = new IndTestProbabilistic(bsData); bsTest.setThreshold(threshold); for (IndependenceFact f : HCopy.keySet()) { - boolean ind = bsTest.checkIndependence(f.getX(), f.getY(), f.getZ()).independent(); + boolean ind = bsTest.checkIndependence(f.getX(), f.getY(), f.getZ()).isIndependent(); int value = ind ? 1 : 0; depData.setInt(b, depData.getColumn(depData.getVariable(f.toString())), value); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index a1187da146..ccf6df4756 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -111,11 +111,11 @@ public static SepsetMapDci resolveSepsets(List sepsets, List rTuples) { if (this.knowledge.noEdgeRequired(i.getName(), j.getName())) // if BK allows { try { - independent1 = this.independenceTest.checkIndependence(i, j, sepSet).independent(); + independent1 = this.independenceTest.checkIndependence(i, j, sepSet).isIndependent(); } catch (Exception e) { independent1 = true; } @@ -274,7 +274,7 @@ private void ruleR0_RFCI(List rTuples) { if (this.knowledge.noEdgeRequired(j.getName(), k.getName())) // if BK allows { try { - independent2 = this.independenceTest.checkIndependence(j, k, sepSet).independent(); + independent2 = this.independenceTest.checkIndependence(j, k, sepSet).isIndependent(); } catch (Exception e) { independent2 = true; } @@ -427,7 +427,7 @@ private void setMinSepSet(List sepSet, Node x, Node y) { boolean indep; try { - indep = this.independenceTest.checkIndependence(x, y, empty).independent(); + indep = this.independenceTest.checkIndependence(x, y, empty).isIndependent(); } catch (Exception e) { indep = false; } @@ -445,7 +445,7 @@ private void setMinSepSet(List sepSet, Node x, Node y) { while ((combination = cg.next()) != null) { List condSet = GraphUtils.asList(combination, sepSet); - indep = this.independenceTest.checkIndependence(x, y, condSet).independent(); + indep = this.independenceTest.checkIndependence(x, y, condSet).isIndependent(); if (indep) { getSepsets().set(x, y, condSet); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java index 6699f1001f..5f8c4d6611 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java @@ -487,14 +487,14 @@ public Graph search() { IndependenceTest test = this.independenceTest; if (!futureX.contains(y)) { - if (!test.checkIndependence(x, y, boundaryX).independent()) { + if (!test.checkIndependence(x, y, boundaryX).isIndependent()) { continue MARKOV; } } if (!futureY.contains(x)) { - if (!test.checkIndependence(y, x, boundaryY).independent()) { + if (!test.checkIndependence(y, x, boundaryY).isIndependent()) { continue MARKOV; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java index 6efdfbec92..2dcb96be0b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java @@ -417,14 +417,14 @@ public Graph search() { IndependenceTest test = this.independenceTest; if (!futureX.contains(y)) { - if (!test.checkIndependence(x, y, boundaryX).independent()) { + if (!test.checkIndependence(x, y, boundaryX).isIndependent()) { continue MARKOV; } } if (!futureY.contains(x)) { - if (!test.checkIndependence(y, x, boundaryY).independent()) { + if (!test.checkIndependence(y, x, boundaryY).isIndependent()) { continue MARKOV; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java index d32d93668e..b249f3377d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java @@ -318,7 +318,7 @@ public static boolean existsLocalSepsetWithout(Node x, Node y, Node z, } // LogUtils.getInstance().finest("Trying " + condSet); - if (test.checkIndependence(x, z, condSet).independent()) { + if (test.checkIndependence(x, z, condSet).isIndependent()) { return true; } } @@ -1299,7 +1299,7 @@ public static CpcTripleType getCpcTripleType(Node x, Node y, Node z, while ((choice = cg.next()) != null) { List cond = GraphUtils.asList(choice, _nodes); - if (test.checkIndependence(x, z, cond).independent()) { + if (test.checkIndependence(x, z, cond).isIndependent()) { if (cond.contains(y)) { numSepsetsContainingY++; } else { @@ -1326,7 +1326,7 @@ public static CpcTripleType getCpcTripleType(Node x, Node y, Node z, while ((choice = cg.next()) != null) { List cond = GraphUtils.asList(choice, _nodes); - if (test.checkIndependence(x, z, cond).independent()) { + if (test.checkIndependence(x, z, cond).isIndependent()) { if (cond.contains(y)) { numSepsetsContainingY++; } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java index cbd498d2a1..3c5a102017 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java @@ -85,7 +85,7 @@ public List getSepset(Node i, Node k) { IndependenceResult result = getIndependenceTest().checkIndependence(i, k, v); - if (result.independent()) { + if (result.isIndependent()) { double pValue = result.getPValue(); if (pValue > _p) { _p = pValue; @@ -103,7 +103,7 @@ public List getSepset(Node i, Node k) { List v = GraphUtils.asList(choice, adjk); IndependenceResult result = getIndependenceTest().checkIndependence(i, k, v); - if (result.independent()) { + if (result.isIndependent()) { double pValue = result.getPValue(); if (pValue > _p) { _p = pValue; @@ -151,7 +151,7 @@ public List>> getSepsetsLists(Node x, Node y, Node z, while ((choice = cg.next()) != null) { List cond = GraphUtils.asList(choice, _nodes); - if (test.checkIndependence(x, z, cond).independent()) { + if (test.checkIndependence(x, z, cond).isIndependent()) { if (verbose) { System.out.println("Indep: " + x + " _||_ " + z + " | " + cond); } @@ -181,7 +181,7 @@ public List>> getSepsetsLists(Node x, Node y, Node z, while ((choice = cg.next()) != null) { List cond = GraphUtils.asList(choice, _nodes); - if (test.checkIndependence(x, z, cond).independent()) { + if (test.checkIndependence(x, z, cond).isIndependent()) { if (cond.contains(y)) { sepsetsContainingY.add(cond); } else { @@ -203,7 +203,7 @@ public List>> getSepsetsLists(Node x, Node y, Node z, public boolean isIndependent(Node a, Node b, List c) { IndependenceResult result = this.independenceTest.checkIndependence(a, b, c); this.lastResult = result; - return result.independent(); + return result.isIndependent(); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java index 3641e6822b..a51f689323 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java @@ -91,7 +91,7 @@ private List getSepsetGreedy(Node i, Node k) { while ((choice = gen.next()) != null) { List v = GraphUtils.asList(choice, adji); - if (getIndependenceTest().checkIndependence(i, k, v).independent()) { + if (getIndependenceTest().checkIndependence(i, k, v).isIndependent()) { return v; } } @@ -104,7 +104,7 @@ private List getSepsetGreedy(Node i, Node k) { while ((choice = gen.next()) != null) { List v = GraphUtils.asList(choice, adjk); - if (getIndependenceTest().checkIndependence(i, k, v).independent()) { + if (getIndependenceTest().checkIndependence(i, k, v).isIndependent()) { return v; } } @@ -118,7 +118,7 @@ private List getSepsetGreedy(Node i, Node k) { public boolean isIndependent(Node a, Node b, List c) { IndependenceResult result = this.independenceTest.checkIndependence(a, b, c); this.result = result; - return result.independent(); + return result.isIndependent(); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java index 3e699e49dd..6b4be73967 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java @@ -114,7 +114,7 @@ private List getCondSet(Node node1, Node node2, int maxPathLength) { IndependenceResult result = this.test.checkIndependence(node1, node2, condSet); this.result = result; - if (result.independent() && noEdgeRequired) { + if (result.isIndependent() && noEdgeRequired) { return condSet; } } @@ -153,7 +153,7 @@ public void setVerbose(boolean verbose) { @Override public boolean isIndependent(Node d, Node c, List path) { IndependenceResult result = this.test.checkIndependence(d, c, path); - return result.independent(); + return result.isIndependent(); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java index 12c5d0530b..6acd93390b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java @@ -67,7 +67,7 @@ public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { public boolean isIndependent(Node a, Node b, List c) { IndependenceResult result = this.test.checkIndependence(a, b, c); this.result = result; - return result.independent(); + return result.isIndependent(); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java index 4ec9dc6f88..babe1395ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java @@ -755,7 +755,7 @@ private Pair getGrowShrinkIndependent(int p) { parents.add(z0); continue; } - if (this.test.checkIndependence(n, z0, new ArrayList<>(parents)).dependent()) { + if (this.test.checkIndependence(n, z0, new ArrayList<>(parents)).isDependent()) { parents.add(z0); changed1 = true; } @@ -766,7 +766,7 @@ private Pair getGrowShrinkIndependent(int p) { continue; } parents.remove(z1); - if (this.test.checkIndependence(n, z1, new ArrayList<>(parents)).dependent()) { + if (this.test.checkIndependence(n, z1, new ArrayList<>(parents)).isDependent()) { parents.add(z1); } else { changed1 = true; @@ -808,7 +808,7 @@ private Pair getRaskuttiUhlerParents(int p) { ArrayList z = new ArrayList<>(minus); sort(z); - if (this.test.checkIndependence(x, y, z).dependent()) { + if (this.test.checkIndependence(x, y, z).isDependent()) { parents.add(y); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index 48c52713ad..d0a6bbbd2a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -317,7 +317,7 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map testsWithVars = new ArrayList<>(); for (int k = 0; k < this.marginalVars.size(); k++) { @@ -325,7 +325,7 @@ private boolean searchAtDepth(Graph graph, IndependenceTest independenceTest, } boolean inconsistency = false; for (IndependenceTest testWithVars : testsWithVars) { - if (testWithVars.checkIndependence(x, y, condSet).independent() != independent) { + if (testWithVars.checkIndependence(x, y, condSet).isIndependent() != independent) { inconsistency = true; break; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java index 7f5f84c516..2879196ff0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java @@ -404,7 +404,7 @@ private boolean searchAtDepth(List nodes, IndependenceTest test, Map nodes, IndependenceTest test, Map nodes, IndependenceTest test, Map cond = GraphUtils.asList(choice, _nodes); - if (test.checkIndependence(x, z, cond).independent()) { + if (test.checkIndependence(x, z, cond).isIndependent()) { // System.out.println("Indep: " + x + " _||_ " + z + " | " + cond); if (cond.contains(y)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java index b09e547075..e322f767e4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java @@ -371,9 +371,9 @@ public Graph search() { IndependenceTest test = this.independenceTest; if (!futureX.contains(y)) { - if (test.checkIndependence(x, y, boundaryX).independent()) { + if (test.checkIndependence(x, y, boundaryX).isIndependent()) { if (!futureY.contains(x)) { - if (test.checkIndependence(y, x, boundaryY).independent()) { + if (test.checkIndependence(y, x, boundaryY).isIndependent()) { this.definitelyNonadjacencies.add(edge); continue MARKOV; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java index 66b2772e83..03386469e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java @@ -402,14 +402,14 @@ public Graph search() { IndependenceTest test = this.independenceTest; if (!futureX.contains(y)) { - if (!test.checkIndependence(x, y, boundaryX).independent()) { + if (!test.checkIndependence(x, y, boundaryX).isIndependent()) { continue MARKOV; } } if (!futureY.contains(x)) { - if (!test.checkIndependence(y, x, boundaryY).independent()) { + if (!test.checkIndependence(y, x, boundaryY).isIndependent()) { continue MARKOV; } } @@ -666,7 +666,7 @@ public CpcTripleType getPopulationTripleType(Node x, Node y, Node z, while ((choice = cg.next()) != null) { List cond = GraphUtils.asList(choice, _nodes); - if (test.checkIndependence(x, z, cond).independent()) { + if (test.checkIndependence(x, z, cond).isIndependent()) { // System.out.println("Indep: " + x + " _||_ " + z + " | " + cond); if (cond.contains(y)) { diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java index 5eedd4a832..bff8982131 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java @@ -204,7 +204,7 @@ public BootstrapDepDataTask(int row_index, int rows) { @Override public Boolean call() throws Exception { for (IndependenceFact f : hCopy.keySet()) { - boolean ind = this.bsTest.checkIndependence(f.getX(), f.getY(), f.getZ()).independent(); + boolean ind = this.bsTest.checkIndependence(f.getX(), f.getY(), f.getZ()).isIndependent(); int value = ind ? 1 : 0; String indFact = f.toString(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java index 006cd8fa93..486e38b6f8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java @@ -63,13 +63,13 @@ public void test1() { IndependenceResult result = test.checkIndependence(x, y, cond); - if (result.independent()) { + if (result.isIndependent()) { numIndep++; } total++; - System.out.print(" " + (result.independent() ? "Independent" : "Dependent")); + System.out.print(" " + (result.isIndependent() ? "Independent" : "Dependent")); System.out.print(" p = " + result.getPValue()); System.out.println(); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index 28effa5acb..a78708ab79 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java @@ -452,7 +452,7 @@ private void clarkTestForAlpha(double alpha, Parameters parameters, DataSet data fp1++; } - boolean dependent = !_test.checkIndependence(x, y).independent(); + boolean dependent = !_test.checkIndependence(x, y).isIndependent(); if (trueAncestral && dependent) { tp2++; @@ -1592,7 +1592,7 @@ public void testSemBicDiffs() { z.add(nodes.get(c)); } - boolean _dsep = dsep.checkIndependence(x, y, new ArrayList<>(z)).independent(); + boolean _dsep = dsep.checkIndependence(x, y, new ArrayList<>(z)).isIndependent(); double diff = scoreGraphChange(x, y, z, this.hashIndices, score); boolean diffNegative = diff < 0; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java index c0d168a96b..508a2e648f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java @@ -84,9 +84,9 @@ private void testOneDepth(Parameters parameters, IndependenceTest test1, Indepen z.add(variables.get(j + 2)); } - boolean fzInd = test1.checkIndependence(x, y, z).independent(); - boolean sembInd = test2.checkIndependence(x, y, z).independent(); - boolean _dsep = dsep.checkIndependence(x, y, z).independent(); + boolean fzInd = test1.checkIndependence(x, y, z).isIndependent(); + boolean sembInd = test2.checkIndependence(x, y, z).isIndependent(); + boolean _dsep = dsep.checkIndependence(x, y, z).isIndependent(); if (fzInd == sembInd) countSame++; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index cdc35f6224..919ad083c2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -1671,10 +1671,10 @@ private void testForWayne3() { } private static void extractedWayne(Node x1, Node x2, Node x3, Node x4, IndependenceTest chiSq) { - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList()) + " " + chiSq.checkIndependence(x1, x2).independent()); - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x3)) + " " + chiSq.checkIndependence(x1, x2, x3).independent()); - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x4)) + " " + chiSq.checkIndependence(x1, x2, x4).independent()); - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x3, x4)) + " " + chiSq.checkIndependence(x1, x2, x3, x4).independent()); + System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList()) + " " + chiSq.checkIndependence(x1, x2).isIndependent()); + System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x3)) + " " + chiSq.checkIndependence(x1, x2, x3).isIndependent()); + System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x4)) + " " + chiSq.checkIndependence(x1, x2, x4).isIndependent()); + System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x3, x4)) + " " + chiSq.checkIndependence(x1, x2, x3, x4).isIndependent()); } @NotNull @@ -3242,7 +3242,7 @@ public void testAddUnfaithfulIndependencies() { } } - if (dsep.checkIndependence(x, y, new ArrayList<>(pathColliders)).independent()) { + if (dsep.checkIndependence(x, y, new ArrayList<>(pathColliders)).isIndependent()) { IndependenceFact fact = new IndependenceFact(x, y, new ArrayList<>(pathColliders)); facts.add(fact); System.out.println("Added " + fact); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java index 0c8fe98f85..09c147a4bc 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java @@ -58,7 +58,7 @@ public void testIsIndependent() { Node y = v.get(1); ArrayList z = new ArrayList<>(); z.add(v.get(2)); - assertTrue(test.checkIndependence(x, y, z).independent()); + assertTrue(test.checkIndependence(x, y, z).isIndependent()); test.setDeterminationP(0.99); assertFalse(test.determines(z, x)); From bfd916c91e22b346086bfa87c0f3bb8853e34303 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:08:51 -0400 Subject: [PATCH 234/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/IndependenceTest.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java index 81c2980858..5af96f3e8a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java @@ -32,8 +32,9 @@ import java.util.List; /** - * Interface implemented by classes that do conditional independence testing. These classes are capable of serving as - * conditional independence "oracles" for constraint-based searches. + *

Interface implemented by classes that do conditional independence testing. + * These classes are capable of serving as conditional independence "oracles" + * for constraint-based searches.

* * @author Joseph Ramsey */ @@ -46,25 +47,42 @@ public interface IndependenceTest { IndependenceResult checkIndependence(Node x, Node y, List z); /** - * @return the list of variables over which this independence checker is capable of determinining independence + * @return the list of variables over which this independence checker is + * capable of determinining independence * relations. */ List getVariables(); /** - * @return The data model for the independence test. + * @return The data model for the independence test, either a DataSet or a + * CovarianceMatrix. + * @see DataSet + * @see ICovarianceMatrix + * @see DataModel */ DataModel getData(); /** - * A score that is higher with more likely models. + * @return A score that is higher with more likely models. */ double getScore(); + /** + * Sets whether this test will print verbose output. + * @param verbose True if so. + */ void setVerbose(boolean verbose); + /** + * Returns true if the test prints verbose output. + * @return True if the case. + */ boolean isVerbose(); + /** + * Returns a string representation of this test. + * @return This string. + */ String toString(); //==============================DEFAULT METHODS=========================// From 32d65c99cc9cbe7c4f40ce853c1c39be5631b5a6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:17:08 -0400 Subject: [PATCH 235/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/IndTestChiSquare.java | 78 +++++++++++-------- .../edu/cmu/tetrad/search/ResolveSepsets.java | 2 +- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java index be73659436..02220ed081 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java @@ -30,22 +30,22 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; /** - * Checks the conditional independence X _||_ Y | S, where S is a set of discrete variable, and X and Y are discrete - * variable not in S, by applying a conditional Chi Square test. A description of such a test is given in Fienberg, "The - * Analysis of Cross-Classified Categorical Data," 2nd edition. The formula for degrees of freedom used in this test are + * Checks the conditional independence X _||_ Y | S, where S is a set of discrete variable, + * and X and Y are discrete variable not in S, by applying a conditional Chi Square test. + * A description of such a test is given in Fienberg, "The Analysis of Cross-Classified + * Categorical Data," 2nd edition. The formula for degrees of freedom used in this test are * equivalent to the formulation on page 142 of Fienberg. * - * @author Joseph Ramsey + * @author josephramsey * @see ChiSquareTest */ public final class IndTestChiSquare implements IndependenceTest { /** - * The X Square tester. + * The Chi Square tester. */ private final ChiSquareTest chiSquareTest; @@ -71,13 +71,8 @@ public final class IndTestChiSquare implements IndependenceTest { */ private int df; - /** - * - */ private double pValue; - private final HashSet facts = new HashSet<>(); - private boolean verbose; /** @@ -108,6 +103,7 @@ public IndTestChiSquare(DataSet dataSet, double alpha) { /** * Creates a new IndTestChiSquare for a subset of the nodes. + * @param nodes This list of nodes. */ public IndependenceTest indTestSubset(List nodes) { if (nodes.isEmpty()) { @@ -138,9 +134,9 @@ public IndependenceTest indTestSubset(List nodes) { } /** - * @return the G Square value. + * @return the chi Square value. */ - public double getXSquare() { + public double getChiSquare() { return this.xSquare; } @@ -164,11 +160,9 @@ public double getPValue() { * @param x the one variable being compared. * @param y the second variable being compared. * @param z the list of conditioning varNames. - * @return true iff x _||_ y | z. + * @return True iff x _||_ y | z. */ public IndependenceResult checkIndependence(Node x, Node y, List z) { - NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); - if (z == null) { throw new NullPointerException(); } @@ -211,8 +205,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } IndependenceFact fact = new IndependenceFact(x, y, z); - this.facts.add(fact); - return new IndependenceResult(fact, result.isIndep(), result.getPValue()); } @@ -275,6 +267,10 @@ public boolean determines(List z, Node x1) { return countDetermined; } + /** + * Returns the alpha significance level of the test. + * @return This level. + */ public double getAlpha() { return this.chiSquareTest.getAlpha(); } @@ -290,50 +286,64 @@ public void setAlpha(double alpha) { } /** - * @return the list of variables over which this independence checker is capable of determinine independence - * relations-- that is, all the variables in the given graph or the given data set. + * @return the list of variables over which this independence checker is capable of determinine + * independence relations-- that is, all the variables in the given graph or the given data set. */ public List getVariables() { return Collections.unmodifiableList(this.variables); } - + /** + * Returns a string representation of this test. + * @return This string. + */ public String toString() { NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); return "Chi Square, alpha = " + nf.format(getAlpha()); } - private double getDeterminationP() { - /* - * The lower bound of percentages of observation of some category in the data, given some particular combination of - * values of conditioning variables, that coefs as 'determining." - */ - return 0.99; - } - + /** + * Returns the data being analyzed. + * @return This data. + */ public DataSet getData() { return this.dataSet; } - + /** + * Returns a number which is more positive for more dependent test tesults. + * @return This number. + */ @Override public double getScore() { return -(getPValue() - getAlpha()); } - public HashSet getFacts() { - return this.facts; - } - + /** + * Returns true if verbose output should be printed. + * @return This. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; } + + private double getDeterminationP() { + /* + * The lower bound of percentages of observation of some category in the data, given some particular combination of + * values of conditioning variables, that coefs as 'determining." + */ + return 0.99; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index ccf6df4756..8d00d9a1af 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -509,7 +509,7 @@ public static boolean isIndependentPooledAverageTest(List inde localCondSet.add(independenceTest.getVariable(node.getName())); } independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); - ts += ((IndTestChiSquare) independenceTest).getXSquare() / independenceTests.size(); + ts += ((IndTestChiSquare) independenceTest).getChiSquare() / independenceTests.size(); df += ((IndTestChiSquare) independenceTest).getDf(); } df = df / independenceTests.size(); From bc029aa0380da4423a40948fae0bbb8f2afa473b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:31:12 -0400 Subject: [PATCH 236/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../independence/ConditionalGaussianLRT.java | 6 +- .../independence/DegenerateGaussianLRT.java | 4 +- .../search/IndTestConditionalCorrelation.java | 77 +++++++++++++++---- ...ava => IndTestConditionalGaussianLrt.java} | 4 +- ...java => IndTestDegenerateGaussianLrt.java} | 6 +- .../java/edu/cmu/tetrad/test/TestGrasp.java | 2 +- 6 files changed, 75 insertions(+), 24 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IndTestConditionalGaussianLRT.java => IndTestConditionalGaussianLrt.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IndTestDegenerateGaussianLRT.java => IndTestDegenerateGaussianLrt.java} (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java index d774aec925..9d5083b9fa 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestConditionalGaussianLRT; +import edu.cmu.tetrad.search.IndTestConditionalGaussianLrt; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -30,8 +30,8 @@ public class ConditionalGaussianLRT implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - IndTestConditionalGaussianLRT test - = new IndTestConditionalGaussianLRT(SimpleDataLoader.getMixedDataSet(dataSet), + IndTestConditionalGaussianLrt test + = new IndTestConditionalGaussianLrt(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble(Params.ALPHA), parameters.getBoolean(Params.DISCRETIZE)); test.setNumCategoriesToDiscretize(parameters.getInt(Params.NUM_CATEGORIES_TO_DISCRETIZE)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java index b4766fd4b5..e4ef355271 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestDegenerateGaussianLRT; +import edu.cmu.tetrad.search.IndTestDegenerateGaussianLrt; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -30,7 +30,7 @@ public class DegenerateGaussianLRT implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - IndTestDegenerateGaussianLRT test = new IndTestDegenerateGaussianLRT(SimpleDataLoader.getMixedDataSet(dataSet)); + IndTestDegenerateGaussianLrt test = new IndTestDegenerateGaussianLrt(SimpleDataLoader.getMixedDataSet(dataSet)); test.setAlpha(parameters.getDouble(Params.ALPHA)); return test; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java index 3cd04cfdfa..51ba766fbc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java @@ -32,10 +32,11 @@ import java.util.List; /** - * Checks conditional independence of variable in a continuous data set using a conditional correlation test - * for the nonlinear nonGaussian case. + * Checks conditional independence of variable in a continuous data set using a + * conditional correlation test for the nonlinear nonGaussian with additive error + * case. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IndTestConditionalCorrelation implements IndependenceTest { @@ -106,6 +107,12 @@ public IndependenceTest indTestSubset(List vars) { throw new UnsupportedOperationException(); } + /** + * Checks the independence of x _||_ y | z + * + * @return the result. + * @see IndependenceResult + */ public IndependenceResult checkIndependence(Node x, Node y, List z) { double score = this.cci.isIndependent(x, y, z); @@ -123,13 +130,20 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { return new IndependenceResult(new IndependenceFact(x, y, z), independent, p); } + /** + * Returns the p-value of the test, + * + * @return The p-value. + */ public double getPValue() { return this.cci.getPValue(); } /** - * Sets the significance level at which independence judgments should be made. Affects the cutoff for partial - * correlations to be considered statistically equal to zero. + * Sets the significance level at which independence judgments should be made. + * Affects the cutoff for partial correlations to be considered statistically equal to zero. + * + * @param alpha The alpha level. */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { @@ -141,27 +155,26 @@ public void setAlpha(double alpha) { } /** - * Gets the getModel significance level. + * @return The getModel significance level. */ public double getAlpha() { return this.alpha; } /** - * @return the list of variables over which this independence checker is capable of determinine independence - * relations-- that is, all the variables in the given graph or the given data set. + * @return the list of variables over which this independence checker is capable + * of determinine independence relations-- that is, all the variables in the given + * graph or the given data set. */ public List getVariables() { return this.variables; } - /** - * If isDeterminismAllowed(), deters to IndTestFisherZD; otherwise throws - * UnsupportedOperationException. + * @throws UnsupportedOperationException Since such code is not avialable. */ public boolean determines(List z, Node x) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("The 'determine' method is not implemented"); } /** @@ -172,6 +185,10 @@ public DataSet getData() { } + /** + * Returns a number is more positive for stronger judgments of dependence. + * @return This number. + */ @Override public double getScore() { return this.score; @@ -184,34 +201,68 @@ public String toString() { return "Conditional Correlation, q = " + IndTestConditionalCorrelation.nf.format(getAlpha()); } + /** + * Returns true if verbose output should be printed. + * @return True if the case. + */ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Sets the number of orthogal functions to use to do the calculations. + * @param numFunctions This number. + */ public void setNumFunctions(int numFunctions) { this.cci.setNumFunctions(numFunctions); } - public double getWeight() { + /** + * Returns the kernel width. + * @return This width. + */ + public double getWidth() { return this.cci.getWidth(); } + /** + * Returns the kernel multiplier. + * @param multiplier This multiplier. + */ public void setKernelMultiplier(double multiplier) { this.cci.setWidth(multiplier); } + /** + * Sets the kernel to be used. + * @param kernel This kernel. + * @see edu.cmu.tetrad.search.ConditionalCorrelationIndependence.Kernel + */ public void setKernel(ConditionalCorrelationIndependence.Kernel kernel) { this.cci.setKernelMultiplier(kernel); } + /** + * Sets the basis used for the calculation. + * @param basis This basis. + * @see edu.cmu.tetrad.search.ConditionalCorrelationIndependence.Basis + */ public void setBasis(ConditionalCorrelationIndependence.Basis basis) { this.cci.setBasis(basis); } + /** + * Sets the kernal regression sample size. + * @param i This size. + */ public void setKernelRegressionSampleSize(int i) { this.cci.setKernelRegressionSampleSize(i); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLRT.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java index 0028c4daa1..7ab22e72e5 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java @@ -44,7 +44,7 @@ * * @author Joseph Ramsey */ -public class IndTestConditionalGaussianLRT implements IndependenceTest { +public class IndTestConditionalGaussianLrt implements IndependenceTest { private final DataSet data; private final Map nodesHash; private double alpha; @@ -56,7 +56,7 @@ public class IndTestConditionalGaussianLRT implements IndependenceTest { private boolean verbose; private int numCategoriesToDiscretize = 3; - public IndTestConditionalGaussianLRT(DataSet data, double alpha, boolean discretize) { + public IndTestConditionalGaussianLrt(DataSet data, double alpha, boolean discretize) { this.data = data; this.likelihood = new ConditionalGaussianLikelihood(data); this.likelihood.setDiscretize(discretize); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLRT.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java index 7b69f6b47f..b5dc6f0505 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java @@ -47,7 +47,7 @@ * * @author Bryan Andrews */ -public class IndTestDegenerateGaussianLRT implements IndependenceTest { +public class IndTestDegenerateGaussianLrt implements IndependenceTest { private final BoxDataSet ddata; private final double[][] _ddata; @@ -100,7 +100,7 @@ public String toString() { /** * Constructs the score using a covariance matrix. */ - public IndTestDegenerateGaussianLRT(DataSet dataSet) { + public IndTestDegenerateGaussianLrt(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException(); } @@ -215,7 +215,7 @@ private Ret getlldof(List rows, int i, int... parents) { double ldetA = log(getCov(rows, A_).det()); double ldetB = log(getCov(rows, B_).det()); - double lik = N * (ldetB - ldetA) + IndTestDegenerateGaussianLRT.L2PE * (B_.length - A_.length); + double lik = N * (ldetB - ldetA) + IndTestDegenerateGaussianLrt.L2PE * (B_.length - A_.length); return new Ret(lik, dof); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 919ad083c2..28418b27f1 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -147,7 +147,7 @@ private void testCgScore() { DegenerateGaussianScore score = new DegenerateGaussianScore((DataSet) data); score.setStructurePrior(structurePrior); - IndTestDegenerateGaussianLRT test = new IndTestDegenerateGaussianLRT((DataSet) data); + IndTestDegenerateGaussianLrt test = new IndTestDegenerateGaussianLrt((DataSet) data); test.setAlpha(0.01); From 8557b79599defff52a5a41ea7f69ddaa1232783c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:37:11 -0400 Subject: [PATCH 237/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../search/IndTestConditionalGaussianLrt.java | 64 ++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java index 7ab22e72e5..d864f70716 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java @@ -79,9 +79,9 @@ public IndependenceTest indTestSubset(List vars) { } /** - * @return true if the given independence question is judged true, false if not. The independence question is of the - * form x _||_ y | z, z = z1,...,zn, where x, y, z1,...,zn are searchVariables in the list returned by - * getVariableNames(). + * @return True if the given independence question is judged true, False if not. + * The independence question is of the form x _||_ y | z, z = z1,...,zn, where + * x, y, z1,...,zn are searchVariables in the list returned by getVariableNames(). */ public IndependenceResult checkIndependence(Node x, Node y, List z) { this.likelihood.setNumCategoriesToDiscretize(this.numCategoriesToDiscretize); @@ -140,24 +140,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { return new IndependenceResult(new IndependenceFact(x, y, z), independent, pValue); } - private List getRows(List allVars, Map nodesHash) { - List rows = new ArrayList<>(); - - K: - for (int k = 0; k < this.data.getNumRows(); k++) { - for (Node node : allVars) { - if (node instanceof ContinuousVariable) { - if (Double.isNaN(this.data.getDouble(k, nodesHash.get(node)))) continue K; - } else if (node instanceof DiscreteVariable) { - if (this.data.getInt(k, nodesHash.get(node)) == -99) continue K; - } - } - - rows.add(k); - } - return rows; - } - /** * @return the probability associated with the most recently executed independence test, of Double.NaN if p value is * not meaningful for tis test. @@ -197,13 +179,21 @@ public void setAlpha(double alpha) { this.alpha = alpha; } + /** + * Returns the data. + * @return This. + */ public DataSet getData() { return this.data; } + /** + * Returns a number that is higher for stronger judgments of dependence + * and negative for judgments of independence. + * @return This number. + */ @Override - public double getScore() { return getAlpha() - getPValue(); } @@ -216,17 +206,47 @@ public String toString() { return "Conditional Gaussian LRT, alpha = " + nf.format(getAlpha()); } + /** + * Returns true iff verbose output should be printed. + * @return This. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Sets the nubmer of categories used to discretize variables. + * @param numCategoriesToDiscretize This number, by default 3. + */ public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { this.numCategoriesToDiscretize = numCategoriesToDiscretize; } + + private List getRows(List allVars, Map nodesHash) { + List rows = new ArrayList<>(); + + K: + for (int k = 0; k < this.data.getNumRows(); k++) { + for (Node node : allVars) { + if (node instanceof ContinuousVariable) { + if (Double.isNaN(this.data.getDouble(k, nodesHash.get(node)))) continue K; + } else if (node instanceof DiscreteVariable) { + if (this.data.getInt(k, nodesHash.get(node)) == -99) continue K; + } + } + + rows.add(k); + } + return rows; + } } \ No newline at end of file From 93d11b2919df7d3b4cedfb00842dccfe88bf6318 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:40:09 -0400 Subject: [PATCH 238/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../search/IndTestConditionalGaussianLrt.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java index d864f70716..ec530910d4 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java @@ -37,12 +37,13 @@ import java.util.concurrent.ConcurrentSkipListMap; /** - * Performs a test of conditional independence X _||_ Y | Z1...Zn where all searchVariables are either continuous or discrete. - * This test is valid for both ordinal and non-ordinal discrete searchVariables. + * Performs a test of conditional independence X _||_ Y | Z1...Zn where all searchVariables + * are either continuous or discrete. This test is valid for both ordinal and non-ordinal + * discrete searchVariables. *

- * Assumed a conditional Gaussain model and uses a likelihood rat test. + * Assumes a conditional Gaussain model and uses a likelihood ratio test. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndTestConditionalGaussianLrt implements IndependenceTest { private final DataSet data; @@ -181,6 +182,7 @@ public void setAlpha(double alpha) { /** * Returns the data. + * * @return This. */ public DataSet getData() { @@ -191,6 +193,7 @@ public DataSet getData() { /** * Returns a number that is higher for stronger judgments of dependence * and negative for judgments of independence. + * * @return This number. */ @Override @@ -208,6 +211,7 @@ public String toString() { /** * Returns true iff verbose output should be printed. + * * @return This. */ @Override @@ -217,6 +221,7 @@ public boolean isVerbose() { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ @Override @@ -226,6 +231,7 @@ public void setVerbose(boolean verbose) { /** * Sets the nubmer of categories used to discretize variables. + * * @param numCategoriesToDiscretize This number, by default 3. */ public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { From b0a164d7a7b1d186a3cf321eb623ac083bf401a7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:40:55 -0400 Subject: [PATCH 239/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/AdLeafTree.java | 1 + .../java/edu/cmu/tetrad/search/AdTrees.java | 1 + .../tetrad/search/BayesUpdaterClassifier.java | 9 +++++++++ .../java/edu/cmu/tetrad/search/BdeScore.java | 17 ++++++++++++++--- .../java/edu/cmu/tetrad/search/BdeuScore.java | 17 ++++++++++++++++- .../main/java/edu/cmu/tetrad/search/Bes.java | 7 ++++++- .../main/java/edu/cmu/tetrad/search/Boss.java | 10 ++++++++-- .../cmu/tetrad/search/BuildPureClusters.java | 1 + .../main/java/edu/cmu/tetrad/search/Ccd.java | 1 + .../main/java/edu/cmu/tetrad/search/Cfci.java | 1 + .../ConditionalCorrelationIndependence.java | 9 +++++++++ .../search/ConditionalGaussianLikelihood.java | 3 +++ .../tetrad/search/ConditionalGaussianScore.java | 12 +++++++++++- .../main/java/edu/cmu/tetrad/search/Cpc.java | 12 +++++++++++- .../main/java/edu/cmu/tetrad/search/Cstar.java | 9 +++++++++ .../cmu/tetrad/search/DagInCpcagIterator.java | 14 ++++++++------ .../java/edu/cmu/tetrad/search/DagSepsets.java | 14 ++++++++++++-- .../tetrad/search/DegenerateGaussianScore.java | 12 +++++++++++- .../edu/cmu/tetrad/search/DeltaTetradTest.java | 4 ++++ .../edu/cmu/tetrad/search/DiscreteBicScore.java | 15 +++++++++++++++ .../edu/cmu/tetrad/search/DiscreteScore.java | 2 ++ .../java/edu/cmu/tetrad/search/EbicScore.java | 10 +++++++++- .../edu/cmu/tetrad/search/FactorAnalysis.java | 2 ++ .../main/java/edu/cmu/tetrad/search/Fas.java | 4 +++- .../main/java/edu/cmu/tetrad/search/Fask.java | 1 + .../main/java/edu/cmu/tetrad/search/Fci.java | 1 + .../java/edu/cmu/tetrad/search/FciOrient.java | 10 ++++++++++ .../main/java/edu/cmu/tetrad/search/Fges.java | 10 ++++++++++ .../main/java/edu/cmu/tetrad/search/Fofc.java | 16 ++++++++++------ .../main/java/edu/cmu/tetrad/search/Ftfc.java | 2 ++ .../java/edu/cmu/tetrad/search/GSquareTest.java | 16 +++++++++++----- .../java/edu/cmu/tetrad/search/GraphChange.java | 2 +- .../java/edu/cmu/tetrad/search/GraphScore.java | 9 +++++++++ .../edu/cmu/tetrad/search/GraphoidAxioms.java | 10 ++++++++-- .../java/edu/cmu/tetrad/search/GraspFci.java | 1 + .../java/edu/cmu/tetrad/search/GrowShrink.java | 3 +++ .../edu/cmu/tetrad/search/GrowShrinkTree.java | 10 +++++++--- .../cmu/tetrad/search/HasPenaltyDiscount.java | 2 ++ .../cmu/tetrad/search/HungarianAlgorithm.java | 8 ++++---- .../main/java/edu/cmu/tetrad/search/IFas.java | 11 +++++++++++ .../main/java/edu/cmu/tetrad/search/Ida.java | 12 +++++++++--- .../java/edu/cmu/tetrad/search/ImagesScore.java | 11 +++++++++-- .../edu/cmu/tetrad/search/IndTestChiSquare.java | 7 +++++++ .../search/IndTestConditionalCorrelation.java | 9 +++++++++ .../edu/cmu/tetrad/search/IndTestFisherZ.java | 15 +++++++++++++-- .../cmu/tetrad/search/IndependenceResult.java | 14 +++++++++++--- .../edu/cmu/tetrad/search/IndependenceTest.java | 3 +++ .../edu/cmu/tetrad/search/LingamPattern.java | 6 +++++- .../tetrad/search/MaxPColliderOrientation.java | 1 + .../main/java/edu/cmu/tetrad/search/NRooks.java | 6 ++++-- .../cmu/tetrad/search/PartialCorrelation.java | 8 ++++++-- .../src/main/java/edu/cmu/tetrad/search/Pc.java | 8 ++++++-- .../main/java/edu/cmu/tetrad/search/PcAll.java | 9 +++++++-- .../tetrad/search/PermutationMatrixPair.java | 5 ++++- .../cmu/tetrad/search/PermutationSearch.java | 8 +++++--- .../edu/cmu/tetrad/search/SemBicScorer.java | 1 + .../java/edu/cmu/tetrad/search/SepsetMap.java | 1 + .../edu/cmu/tetrad/search/SepsetProducer.java | 3 ++- .../cmu/tetrad/search/SepsetsPossibleDsep.java | 1 + .../java/edu/cmu/tetrad/search/SepsetsSet.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Sp.java | 14 ++++++++++---- .../edu/cmu/tetrad/search/SuborderSearch.java | 10 ++++++++-- .../java/edu/cmu/tetrad/search/SvarGfci.java | 4 +++- .../edu/cmu/tetrad/search/TeyssierScorer.java | 2 +- .../main/java/edu/cmu/tetrad/search/TsFas.java | 8 ++++++++ .../java/edu/cmu/tetrad/search/ZsbScore.java | 6 +++++- .../BpcTetradPurifyWashdown.java | 14 +++++++++----- .../tetrad/search/work_in_progress/FasFdr.java | 8 +++++++- .../search/work_in_progress/Washdown.java | 7 +++++-- 69 files changed, 419 insertions(+), 82 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java index 0cdcf039d7..38bda9584e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java @@ -35,6 +35,7 @@ public class AdLeafTree { /** * Constructs an AD Leaf Tree for the given dataset. + * * @param dataSet A discrete dataset. */ public AdLeafTree(DataSet dataSet) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java index cee992dd57..08c1eab2f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java @@ -15,6 +15,7 @@ public class AdTrees { /** * Returns an ADLeafTree for the given dataset. + * * @param dataSet A discrete dataset. * @return The AdLeafTree * @see AdLeafTree diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java index 4494a07adf..4fcf361299 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java @@ -141,6 +141,7 @@ public static BayesUpdaterClassifier serializableInstance() { /** * Sets the target variable. + * * @param target This variable. */ public void setTarget(String target) { @@ -168,6 +169,7 @@ public void setTarget(String target) { /** * Computes and returns the cross-tabulation of observed versus estimated * values of the target variable as described above. + * * @return this cross-tabulation. */ public int[] classify() { @@ -381,6 +383,7 @@ public DiscreteVariable getTargetVariable() { /** * Returns the Bayes IM being used. + * * @return This IM * @see BayesIm */ @@ -390,6 +393,7 @@ public BayesIm getBayesIm() { /** * Returns the test data being used. + * * @return This data. */ public DataSet getTestData() { @@ -398,6 +402,7 @@ public DataSet getTestData() { /** * Returns the classification for the target variable. + * * @return Thsi classification. */ public int[] getClassifications() { @@ -406,6 +411,7 @@ public int[] getClassifications() { /** * Returns the marginals. + * * @return This. */ public double[][] getMarginals() { @@ -414,6 +420,7 @@ public double[][] getMarginals() { /** * Returns the number of cases for the data. + * * @return This number. */ public int getNumCases() { @@ -422,6 +429,7 @@ public int getNumCases() { /** * Returns the number of usable cases for the data. + * * @return Thsi number. */ public int getTotalUsableCases() { @@ -430,6 +438,7 @@ public int getTotalUsableCases() { /** * Returns the variables of the BayesIM. + * * @return These variables as a list. * @see BayesIm */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java index a85c46f937..0d58a14fb0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java @@ -38,6 +38,7 @@ public class BdeScore implements DiscreteScore { /** * Constructs a BDe score for the given dataset. + * * @param dataSet A discrete dataset. */ public BdeScore(DataSet dataSet) { @@ -55,9 +56,10 @@ public BdeScore(DataSet dataSet) { /** * Returns the score for the given parent given its parents, where these are * specified as column indices into the dataset. - * @return the score, or NaN if the score can't be calculated. - * @param i The index of the variable. + * + * @param i The index of the variable. * @param parents The indices of the parents of the variables. + * @return the score, or NaN if the score can't be calculated. */ public double localScore(int i, int[] parents) { @@ -142,6 +144,7 @@ public double localScore(int i, int[] parents) { /** * Returns the different between localScore(y | z, x) and localScore(y | z) + * * @param x The index of the x variable * @param y The index of the y variable. * @param z The indices of the z variables @@ -155,6 +158,7 @@ public double localScoreDiff(int x, int y, int[] z) { /** * Returns the dataset being analyzed. + * * @return This dataset. */ @Override @@ -173,6 +177,7 @@ private int getRowIndex(int[] dim, int[] values) { /** * BDe does not use a structure prior. + * * @param structurePrior The structure prior (not used). * @throws UnsupportedOperationException Since this method is not implemented for this score. */ @@ -182,6 +187,7 @@ public void setStructurePrior(double structurePrior) { /** * BDe does not use a sample prior. + * * @param samplePrior The structure prior (not used). * @throws UnsupportedOperationException Since this method is not implemented for this score. */ @@ -191,6 +197,7 @@ public void setSamplePrior(double samplePrior) { /** * Returns the variables of the dataset. + * * @return These variables as list. */ @Override @@ -200,6 +207,7 @@ public List getVariables() { /** * Returns the sample size of the data. + * * @return This size. */ public int getSampleSize() { @@ -209,6 +217,7 @@ public int getSampleSize() { /** * Returns a judgment of whether the given bump in score allows one to conclude * that the edge is an "effect edge" for FGES. + * * @param bump The bump. * @return True iff so. * @see Fges @@ -220,6 +229,7 @@ public boolean isEffectEdge(double bump) { /** * Returns the maximum degree of the graphs as they're searched. + * * @return This maximum degree. */ @Override @@ -230,6 +240,7 @@ public int getMaxDegree() { /** * A judgment of whether a node given its parents is determined is not available for this * score. + * * @param z The parents. * @param y The node. * @return The judgment @@ -243,6 +254,7 @@ public boolean determines(List z, Node y) { /** * Returns "BDe Score". + * * @return This string. */ @Override @@ -263,7 +275,6 @@ private DataSet dataSet() { } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java index ee61e5bee2..ceb6b9e982 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java @@ -44,6 +44,7 @@ public class BdeuScore implements DiscreteScore { /** * Constructs a BDe score for the given dataset. + * * @param dataSet A discrete dataset. */ public BdeuScore(DataSet dataSet) { @@ -84,6 +85,7 @@ public BdeuScore(DataSet dataSet) { /** * Calculates the BDeu score of a node given its parents. + * * @param node The index of the node. * @param parents The indices of the node's parents. * @return The score. @@ -171,6 +173,7 @@ public double localScore(int node, int[] parents) { /** * Calculates localScore(y | z, x) - localScore(y | z). + * * @param x The index of x. * @param y The index of y. * @param z The indeces of the z variables. @@ -184,6 +187,7 @@ public double localScoreDiff(int x, int y, int[] z) { /** * Returns the variables of the data. + * * @return These variables as a list. */ @Override @@ -193,6 +197,7 @@ public List getVariables() { /** * Returns the sample size of the data. + * * @return This size. */ public int getSampleSize() { @@ -201,7 +206,8 @@ public int getSampleSize() { /** * For FGES, this determines whether an edge counts as an effect edge. - * @param bump The bump for the edge. + * + * @param bump The bump for the edge. * @return True if so. * @see Fges */ @@ -211,6 +217,7 @@ public boolean isEffectEdge(double bump) { /** * Returns the dataset being analyzed. + * * @return This dataset */ @Override @@ -220,6 +227,7 @@ public DataSet getDataSet() { /** * Returns the structure prior. + * * @return This prior. */ public double getStructurePrior() { @@ -228,6 +236,7 @@ public double getStructurePrior() { /** * Sets the structure prior + * * @param structurePrior This prior. */ public void setStructurePrior(double structurePrior) { @@ -236,6 +245,7 @@ public void setStructurePrior(double structurePrior) { /** * Returns the smaple prior. + * * @return This prior. */ public double getSamplePrior() { @@ -244,6 +254,7 @@ public double getSamplePrior() { /** * Set the sample prior + * * @param samplePrior This prior. */ @Override @@ -253,6 +264,7 @@ public void setSamplePrior(double samplePrior) { /** * Returns a string representation of this score. + * * @return This string. */ @Override @@ -263,6 +275,7 @@ public String toString() { /** * Sets the variables to another of the same names, in the same order. + * * @param variables The new varialbe list. * @see edu.cmu.tetrad.algcomparison.algorithm.multi.Images */ @@ -279,6 +292,7 @@ void setVariables(List variables) { /** * Returns the needed max degree for some searches. + * * @return This max degree. */ @Override @@ -289,6 +303,7 @@ public int getMaxDegree() { /** * This score does not implement a method to decide whehter a node is determined * by its parents. + * * @param z The parents. * @param y The node. * @return This determination diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java index 549536ec10..280417899f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java @@ -37,6 +37,7 @@ public Bes(@NotNull Score score) { /** * Returns the variables being searched over. + * * @return These variables as a list. */ @NotNull @@ -46,6 +47,7 @@ public List getVariables() { /** * Sets whether verbose output should be printed. + * * @param verbose True iff so. */ public void setVerbose(boolean verbose) { @@ -54,6 +56,7 @@ public void setVerbose(boolean verbose) { /** * Sets the knowledge for the search. + * * @param knowledge This knowledge. * @see Knowledge */ @@ -63,6 +66,7 @@ public void setKnowledge(Knowledge knowledge) { /** * Sets the depth for the search, which is the maximum number of variables conditioned on. + * * @param depth This maximum; for unlimited depth use -1; otherwise, give a nonzero integer. */ public void setDepth(int depth) { @@ -72,7 +76,8 @@ public void setDepth(int depth) { /** * Runs BES for a graph over the given list of variables - * @param graph The graph. + * + * @param graph The graph. * @param variables The variables the search should be restricted to. */ public void bes(Graph graph, List variables) { 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 0545dbca6c..a0c5c074e1 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 @@ -39,6 +39,7 @@ public class Boss implements SuborderSearch { /** * This algorithm will work with an arbitrary score. + * * @param score The Score to use. */ public Boss(Score score) { @@ -58,9 +59,10 @@ public Boss(Score score) { /** * Searches over the given suborder using the given prefix. Useful if tiered knowledge is available. - * @param prefix The prefix--variables alwasys allowed for conditioning. + * + * @param prefix The prefix--variables alwasys allowed for conditioning. * @param suborder The suborder--these are the variables being searched over. - * @param gsts The grow-shrink tree used for caching. + * @param gsts The grow-shrink tree used for caching. * @see GrowShrinkTree */ @Override @@ -127,6 +129,7 @@ public void setKnowledge(Knowledge knowledge) { /** * Sets the number of times the procedure should be restarted in search of a better * score. + * * @param numStarts This number. */ public void setNumStarts(int numStarts) { @@ -135,6 +138,7 @@ public void setNumStarts(int numStarts) { /** * Returns the variables. + * * @return A list of these. */ @Override @@ -144,6 +148,7 @@ public List getVariables() { /** * Returns a map from nodes to their parents. + * * @return This map. */ @Override @@ -153,6 +158,7 @@ public Map> getParents() { /** * Returns the score being used for the search. + * * @return This score. * @see Score */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index cfd163c7de..b9ad36b03a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -170,6 +170,7 @@ public ICovarianceMatrix getCovarianceMatrix() { /** * Sets the cluster significance type. + * * @param checkType This type * @see ClusterSignificance */ 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 3a96feba15..ede0d1b77f 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 @@ -45,6 +45,7 @@ public final class Ccd implements GraphSearch { /** * Construct a CCD algorithm with the given independence test. + * * @param test The test to be used. * @see IndependenceTest */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 1732187d47..d6fb73db7c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -127,6 +127,7 @@ public Cfci(IndependenceTest independenceTest) { /** * Performs the search and returns the PAG. + * * @return The search PAG. */ public Graph search() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java index 425195655e..f76838c7e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java @@ -277,6 +277,7 @@ public double[] residuals(Node x, List z, List rows) { /** * Number of functions to use in (truncated) basis + * * @param numFunctions This number. */ public void setNumFunctions(int numFunctions) { @@ -285,6 +286,7 @@ public void setNumFunctions(int numFunctions) { /** * Sets the kernel multiplier. + * * @param kernelMultiplier This multiplier. */ public void setKernelMultiplier(Kernel kernelMultiplier) { @@ -293,6 +295,7 @@ public void setKernelMultiplier(Kernel kernelMultiplier) { /** * Sets the basis. + * * @param basis This basis. * @see Basis */ @@ -302,6 +305,7 @@ public void setBasis(Basis basis) { /** * Returns the kernel width. + * * @return This width. */ public double getWidth() { @@ -310,6 +314,7 @@ public double getWidth() { /** * Sets the kernel width. + * * @param width This width. */ public void setWidth(double width) { @@ -318,6 +323,7 @@ public void setWidth(double width) { /** * Returns the p-value of the score. + * * @return This p-value. */ public double getPValue() { @@ -326,6 +332,7 @@ public double getPValue() { /** * Returns the p-value of the score. + * * @param score The score. * @return This p-value. */ @@ -343,6 +350,7 @@ public double getScore() { /** * Sets the alpha cutoff. + * * @param alpha This cutoff. */ public void setAlpha(double alpha) { @@ -351,6 +359,7 @@ public void setAlpha(double alpha) { /** * Sets the kernel regression sample size. + * * @param kernelRegressionSapleSize This sample size */ public void setKernelRegressionSampleSize(int kernelRegressionSapleSize) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java index 4a354f9025..0282e73368 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java @@ -188,6 +188,7 @@ public Ret getLikelihood(int i, int[] parents) { /** * Sets the penalty discount for this score, which is a multiplier on the panalty term of BIC. + * * @param penaltyDiscount The penalty discount. */ public void setPenaltyDiscount(double penaltyDiscount) { @@ -196,6 +197,7 @@ public void setPenaltyDiscount(double penaltyDiscount) { /** * Sets whether to discretize child variables to avoid integration. An optimization. + * * @param discretize True if so. * @see #setNumCategoriesToDiscretize(int) */ @@ -205,6 +207,7 @@ public void setDiscretize(boolean discretize) { /** * Sets the number of categories to use to discretize child variables to avoid integrationl + * * @param numCategoriesToDiscretize This number. * @see #setDiscretize(boolean) */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java index 354ef48f4e..58b2db0143 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java @@ -72,7 +72,8 @@ public ConditionalGaussianScore(DataSet dataSet, double penaltyDiscount, boolean /** * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model. - * @param i The index of the child. + * + * @param i The index of the child. * @param parents The indices of the parents. * @return The score., */ @@ -96,6 +97,7 @@ public double localScore(int i, int... parents) { /** * Calculates localScore(y | z, x) - localScore(z). + * * @param x The index of the child. * @param z The indices of the parents. * @return The score difference. @@ -106,6 +108,7 @@ public double localScoreDiff(int x, int y, int[] z) { /** * Reurns the sample size of the data. + * * @return This size. */ public int getSampleSize() { @@ -115,6 +118,7 @@ public int getSampleSize() { /** * A method for FGES for determining whether an edge counts as an effect edges for this * score bump. + * * @param bump The bump in score. * @return True iff so. * @see Fges @@ -126,6 +130,7 @@ public boolean isEffectEdge(double bump) { /** * Returns the variables of the data. + * * @return This list. */ @Override @@ -136,6 +141,7 @@ public List getVariables() { /** * Returns the max degree recommended for the search form the MagSemBicScore * and Fges. + * * @return This max degree. * @see MagSemBicScore * @see Fges @@ -148,6 +154,7 @@ public int getMaxDegree() { /** * This score does not implement a method to decide whether a given set of parents * determines a given child, so an exception is thrown. + * * @throws UnsupportedOperationException Since this method is not supported. */ @Override @@ -158,6 +165,7 @@ public boolean determines(List z, Node y) { /** * Returns the penalty discount for this score, which is a multiplier on the penatly term of the BIC * score. + * * @return This penalty discount. */ public double getPenaltyDiscount() { @@ -167,6 +175,7 @@ public double getPenaltyDiscount() { /** * Sets the penalty discount for this score, which is a multiplier on the penalty discount of the * BIC score. + * * @param penaltyDiscount This penalty discount. */ public void setPenaltyDiscount(double penaltyDiscount) { @@ -175,6 +184,7 @@ public void setPenaltyDiscount(double penaltyDiscount) { /** * Sets tne number of categories used to discretize, when this optimization is used. + * * @param numCategoriesToDiscretize This number. */ public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) { 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 6e8055e672..d1fc00aac3 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 @@ -22,7 +22,10 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.graph.Edge; +import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphUtils; +import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; @@ -125,6 +128,7 @@ public boolean isAggressivelyPreventCycles() { /** * Sets to true just in case edges will not be added if they would create cycles. + * * @param aggressivelyPreventCycles True if so. */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { @@ -134,6 +138,7 @@ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { /** * Sets the maximum number of variables conditioned on in any conditional independence test. If set to -1, the value * of 1000 will be used. May not be set to Integer.MAX_VALUE, due to a Java bug on multi-core systems. + * * @param depth This maximum. */ public void setDepth(int depth) { @@ -212,6 +217,7 @@ public Set getNoncolliderTriples() { /** * Returns the edges in the search graph. + * * @return These edges. */ public Set getAdjacencies() { @@ -220,6 +226,7 @@ public Set getAdjacencies() { /** * Returns the non-adjacencies in the seaarch graph. + * * @return These non-adjacencies. */ public Set getNonadjacencies() { @@ -297,6 +304,7 @@ public Graph search() { /** * Returns a map for x _||_ y | z1,..,zn from {x, y} to {z1,...,zn}. + * * @return This map. */ public SepsetMap getSepsets() { @@ -305,6 +313,7 @@ public SepsetMap getSepsets() { /** * The graph that's constructed during the search. + * * @return This graph. */ public Graph getGraph() { @@ -334,6 +343,7 @@ public void setUseHeuristic(boolean useHeuristic) { /** * Sets the max path length for the max p heuristic. + * * @param maxPPathLength This length. */ public void setMaxPPathLength(int maxPPathLength) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index 744f63df17..95c1005a07 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -46,6 +46,7 @@ public Cstar() { /** * Returns a list of of records for making a CSTaR table. + * * @param allRecords the list of all records. * @return The list for the CSTaR table. */ @@ -465,6 +466,7 @@ public int getP() { /** * Sets qFrom. + * * @param qFrom This integer. */ public void setqFrom(int qFrom) { @@ -473,6 +475,7 @@ public void setqFrom(int qFrom) { /** * Sets qTo. + * * @param qTo This integer. */ public void setqTo(int qTo) { @@ -481,6 +484,7 @@ public void setqTo(int qTo) { /** * Sets q increment. + * * @param qIncrement This integer. */ public void setqIncrement(int qIncrement) { @@ -489,6 +493,7 @@ public void setqIncrement(int qIncrement) { /** * The CSTaR algorithm can use any CPDAG algorithm; here you can set it. + * * @param cpdagAlglorithm The CPDAG algorithm. * @see CpdagAlgorithm */ @@ -498,6 +503,7 @@ public void setCpdagAlgorithm(CpdagAlgorithm cpdagAlglorithm) { /** * Sets whether verbose output will be printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -506,6 +512,7 @@ public void setVerbose(boolean verbose) { /** * Sets the selection alpha. + * * @param selectionAlpha This alpha. */ public void setSelectionAlpha(double selectionAlpha) { @@ -514,6 +521,7 @@ public void setSelectionAlpha(double selectionAlpha) { /** * Sets the sample style. + * * @param sampleStyle This style. * @see SampleStyle */ @@ -523,6 +531,7 @@ public void setSampleStyle(SampleStyle sampleStyle) { /** * Sets the number of subsamples. + * * @param numSubsamples This number. */ public void setNumSubsamples(int numSubsamples) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java index 6c811a5623..c864063a28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java @@ -50,7 +50,8 @@ public class DagInCpcagIterator { * * @param CPDAG The CPDAG for which DAGS are wanted. May result in cyclic outputs. * @throws IllegalArgumentException if the CPDAG is not a CPDAG. - */ public DagInCpcagIterator(Graph CPDAG) { + */ + public DagInCpcagIterator(Graph CPDAG) { this(CPDAG, new Knowledge(), false, true); } @@ -58,10 +59,11 @@ public class DagInCpcagIterator { * The given CPDAG must be a CPDAG. If it does not consist entirely of directed and undirected edges and if it * is not acyclic, it is rejected. * - * @param CPDAG The CPDAG for which DAGS are wanted. May result in cyclic outputs. - * @param knowledge The knowledge to be used to constrain the DAGs. + * @param CPDAG The CPDAG for which DAGS are wanted. May result in cyclic outputs. + * @param knowledge The knowledge to be used to constrain the DAGs. * @throws IllegalArgumentException if the CPDAG is not a CPDAG. - */ public DagInCpcagIterator(Graph CPDAG, Knowledge knowledge) { + */ + public DagInCpcagIterator(Graph CPDAG, Knowledge knowledge) { this(CPDAG, knowledge, false, true); } @@ -70,10 +72,10 @@ public class DagInCpcagIterator { * is not acyclic, it is rejected. * * @param CPDAG The CPDAG for which DAGS are wanted. - * @param knowledge The knowledge to be used to constrain the DAGs. + * @param knowledge The knowledge to be used to constrain the DAGs. * @param allowArbitraryOrientations True if arbitrary orientations are allowable when reasonable ones cannot be * made. May result in cyclic outputs. - * @param allowNewColliders True if new colliders are allowed in teh graphs. + * @param allowNewColliders True if new colliders are allowed in teh graphs. * @throws IllegalArgumentException if the CPDAG is not a CPDAG. */ public DagInCpcagIterator(Graph CPDAG, Knowledge knowledge, boolean allowArbitraryOrientations, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java index afc09ece51..d78b009e3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java @@ -39,6 +39,7 @@ public class DagSepsets implements SepsetProducer { /** * Constructs a new DagSepsets object for the given DAG. + * * @param dag the DAG. */ public DagSepsets(Graph dag) { @@ -47,6 +48,7 @@ public DagSepsets(Graph dag) { /** * Returns the list of sepset for {a, b}. + * * @param a One node. * @param b The other node. * @return The list of sepsets for {a, b}. @@ -58,6 +60,7 @@ public List getSepset(Node a, Node b) { /** * True iff i*-*j*-*k is an unshielded collider. + * * @param i Node 1 * @param j Node 2 * @param k Node 3 @@ -72,11 +75,13 @@ public boolean isUnshieldedCollider(Node i, Node j, Node k) { /** * True iff i*-*j*-*k is an unshielded noncollider. + * * @param i Node 1 * @param j Node 2 * @param k Node 3 * @return True if the condition holds. - */ @Override + */ + @Override public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { List sepset = this.dag.getSepset(i, k); return sepset != null && sepset.contains(j); @@ -84,6 +89,7 @@ public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { /** * Not implemented; required for an interface. + * * @throws UnsupportedOperationException Since this is not implemented. */ @Override @@ -96,6 +102,7 @@ public double getScore() { * the name isIndependent fool you; this is a d-separation method. We * only use the name isIndependent so that this can be used in place * of an independence check. + * * @param a Node 1 * @param b NOde 2 * @param c A set of conditoning nodes. @@ -108,6 +115,7 @@ public boolean isIndependent(Node a, Node b, List c) { /** * Returns the nodes in the DAG. + * * @return This list. */ @Override @@ -117,8 +125,9 @@ public List getVariables() { /** * Thsi method is not used. + * * @throws UnsupportedOperationException Since this method is not used (but is - * required by an interface). + * required by an interface). */ @Override public void setVerbose(boolean verbose) { @@ -127,6 +136,7 @@ public void setVerbose(boolean verbose) { /** * Returns the DAG being analyzed. + * * @return This DAG. */ public Graph getDag() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java index d86a3185c9..2cfaba3aaa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java @@ -158,7 +158,8 @@ public DegenerateGaussianScore(DataSet dataSet) { /** * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model. - * @param i The child indes. + * + * @param i The child indes. * @param parents The indices of the parents. */ public double localScore(int i, int... parents) { @@ -198,6 +199,7 @@ public double localScore(int i, int... parents) { /** * Returns localScore(y | z, x) - localScore(y, z). + * * @param x Node 1. * @param y Node 2. * @param z The conditioning variables @@ -209,6 +211,7 @@ public double localScoreDiff(int x, int y, int[] z) { /** * Returns the sample size for the data for this score. + * * @return This sample size. */ public int getSampleSize() { @@ -218,6 +221,7 @@ public int getSampleSize() { /** * Returns a decision whether a given bump counts as an effect edge * for this score. + * * @param bump The bump. * @return True if it counts as an effect edge. * @see Fges @@ -229,6 +233,7 @@ public boolean isEffectEdge(double bump) { /** * Returns the variables for this score. + * * @return This list. */ @Override @@ -238,6 +243,7 @@ public List getVariables() { /** * Returns an estimate of the max degree needed for certain algorithms. + * * @return This estimate * @see Fges * @see MagSemBicScore @@ -250,6 +256,7 @@ public int getMaxDegree() { /** * This score does not implement a method to determing whether a given set of parents determine * a given child, so an exception is thrown. + * * @throws UnsupportedOperationException Since this method is not implemented. */ @Override @@ -259,6 +266,7 @@ public boolean determines(List z, Node y) { /** * Sets the penalty discount for this score, which is a multiplier on the BIC penalty term. + * * @param penaltyDiscount This penalty. */ public void setPenaltyDiscount(double penaltyDiscount) { @@ -267,6 +275,7 @@ public void setPenaltyDiscount(double penaltyDiscount) { /** * Sets the structure prior for this score. + * * @param structurePrior This prior. */ public void setStructurePrior(double structurePrior) { @@ -275,6 +284,7 @@ public void setStructurePrior(double structurePrior) { /** * Returns a string representation of this score. + * * @return This string. */ @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java index 22bdb9bfd7..4343e69a13 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java @@ -55,6 +55,7 @@ public class DeltaTetradTest { /** * Constructs a test using a given data set. If a data set is provided (that is, a tabular data set), fourth moment * statistics can be calculated (p. 160); otherwise, it must be assumed that the data are multivariate Gaussian. + * * @param dataSet The dataset to use. */ public DeltaTetradTest(DataSet dataSet) { @@ -89,6 +90,7 @@ public DeltaTetradTest(DataSet dataSet) { /** * Constructs a test using the given covariance matrix. Fourth moment statistics are not caculated; it is assumed * that the data are distributed as multivariate Gaussian. + * * @param cov The covaraince matrix to use. */ public DeltaTetradTest(ICovarianceMatrix cov) { @@ -113,6 +115,7 @@ public DeltaTetradTest(ICovarianceMatrix cov) { *

* Calculates the T statistic (Bollen and Ting, p. 161). This is significant if tests as significant using the Chi * Square distribution with degrees of freedom equal to the number of nonredundant tetrads tested. + * * @param tetrads The tetrads for which a chi-square is needed. */ public double calcChiSquare(Tetrad... tetrads) { @@ -230,6 +233,7 @@ public double getPValue() { /** * Returns a p-value for the given list of tetrad. + * * @param tetrads The tetrad for which a p-vaue is needed. * @return The p-value. */ 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 9495e3e723..4c218a130f 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 @@ -33,6 +33,7 @@ /** * Calculates the discrete BIC score. + * * @author josephramsey */ public class DiscreteBicScore implements DiscreteScore { @@ -46,6 +47,7 @@ public class DiscreteBicScore implements DiscreteScore { /** * Constructor. + * * @param dataSet The discrete dataset to analyze. */ public DiscreteBicScore(DataSet dataSet) { @@ -86,6 +88,7 @@ public DiscreteBicScore(DataSet dataSet) { /** * Returns the score of the given nodes given its parents. + * * @param node The index of the node. * @param parents The indices of the node's parents. * @return The score. @@ -181,6 +184,7 @@ public double localScore(int node, int[] parents) { /** * Returns localScore(y | z, x) - localScore(y | z). + * * @return This score. */ @Override @@ -190,6 +194,7 @@ public double localScoreDiff(int x, int y, int[] z) { /** * Returns the variables. + * * @return This list. */ @Override @@ -199,6 +204,7 @@ public List getVariables() { /** * Returns the sample size. + * * @return This size. */ public int getSampleSize() { @@ -207,6 +213,7 @@ public int getSampleSize() { /** * Must be called directly after the corresponding scoring call. Used in FGES. + * * @param bump The score bump. * @see Fges */ @@ -216,6 +223,7 @@ public boolean isEffectEdge(double bump) { /** * Returns the dataset being analyzed. + * * @return this dataset. */ @Override @@ -225,6 +233,7 @@ public DataSet getDataSet() { /** * Sets the structure prior. + * * @param structurePrior This prior. */ @Override @@ -234,6 +243,7 @@ public void setStructurePrior(double structurePrior) { /** * This method is not used for this score. + * * @throws UnsupportedOperationException Since this method is not used. */ @Override @@ -243,6 +253,7 @@ public void setSamplePrior(double samplePrior) { /** * Sets the variables to a new list of the same size. + * * @param variables The new list of variables. */ public void setVariables(List variables) { @@ -258,6 +269,7 @@ public void setVariables(List variables) { /** * Sets the penalty discount, which is a multiplier on the penalty term of BIC. + * * @param penaltyDiscount This discount. */ public void setPenaltyDiscount(double penaltyDiscount) { @@ -266,6 +278,7 @@ public void setPenaltyDiscount(double penaltyDiscount) { /** * Returns the maximum degree for some algorithms. + * * @return 1000. */ @Override @@ -276,6 +289,7 @@ public int getMaxDegree() { /** * This method is not used; a method for calculating whether nodes Z determind node y has not * been implemented here. + * * @throws UnsupportedOperationException Since this method is not used. */ @Override @@ -285,6 +299,7 @@ public boolean determines(List z, Node y) { /** * Returns a string representation of this score. + * * @return This string. */ @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java index e13d6d5d2e..0444091bcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java @@ -29,7 +29,9 @@ */ public interface DiscreteScore extends Score { void setStructurePrior(double structurePrior); + void setSamplePrior(double samplePrior); + DataSet getDataSet(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java index d4bee76c8a..3c00e4a802 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java @@ -61,7 +61,8 @@ public EbicScore(ICovarianceMatrix covariances) { /** * Constructs the score using a covariance matrix. - * @param dataSet The continuous dataset to analyze. + * + * @param dataSet The continuous dataset to analyze. * @param precomputeCovariances Whether the covariances should be precomputed or computed on the fly. * True if precomputed. */ @@ -102,6 +103,7 @@ public double localScoreDiff(int x, int y, int[] z) { /** * Returns the score of the node i given its parents. + * * @param i The index of the node. * @param parents The indices of the node's parents. * @return The score, or NaN if the score cannot be calculated. @@ -130,6 +132,7 @@ public double localScore(int i, int... parents) throws RuntimeException { /** * Returns the sample size. + * * @return This size. */ public int getSampleSize() { @@ -138,6 +141,7 @@ public int getSampleSize() { /** * Returns a judgement for FGES of whether the given bump implies an effect edge. + * * @param bump The bump * @return True if so * @see Fges @@ -149,6 +153,7 @@ public boolean isEffectEdge(double bump) { /** * Returns the variables for this score. + * * @return Thsi list. */ @Override @@ -158,6 +163,7 @@ public List getVariables() { /** * Returns an estimate of max degree of the graph for some algorithms. + * * @return This max degree. * @see Fges * @see MagSemBicScore @@ -169,6 +175,7 @@ public int getMaxDegree() { /** * Return a judgment of whether the variable in z determine y exactly. + * * @return This judgment */ @Override @@ -184,6 +191,7 @@ public boolean determines(List z, Node y) { /** * Sets the gamma parameter for EBIC. + * * @param gamma The gamma parameter. */ public void setGamma(double gamma) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index fb0f0f453e..469463bbd0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -53,6 +53,7 @@ public class FactorAnalysis { /** * Consructor. + * * @param covarianceMatrix The covariance matrix being analyzed. */ public FactorAnalysis(ICovarianceMatrix covarianceMatrix) { @@ -61,6 +62,7 @@ public FactorAnalysis(ICovarianceMatrix covarianceMatrix) { /** * Constructor. + * * @param dataSet The continuous dataset being analyzed. */ public FactorAnalysis(DataSet dataSet) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index b9266b9e5f..4cd3603600 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -243,7 +243,8 @@ public void setKnowledge(Knowledge knowledge) { /** * The number of independence tests. - */ /** + */ + /** * Returns the nubmer of independence tests that were done. * * @return This number. @@ -313,6 +314,7 @@ public List getAmbiguousTriples(Node node) { /** * This is not used here. + * * @param out This print stream. */ @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 4bb8ded2ae..da11e0c12b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -523,6 +523,7 @@ public void setEmpirical(boolean empirical) { /** * A left/right judgment for double[] arrays (data) as input. + * * @param x The data for the first variable. * @param y The data for the second variable. * @return The left-right judgment, which is negative if X<-Y, positive if X->Y, and diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 5c57346e7a..37fce5f882 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -292,6 +292,7 @@ public void setStable(boolean stable) { /** * Sets whether the discriminating path rule should be used. + * * @param doDiscriminatingPathRule True if so. */ public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java index c5bb18a56e..767f233ea2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java @@ -81,6 +81,7 @@ public FciOrient(SepsetProducer sepsets) { /** * Performs final FCI orientation on the given graph. + * * @param graph The graph to further orient. * @return The oriented graph. */ @@ -104,6 +105,7 @@ public Graph orient(Graph graph) { /** * Returns the map from {x,y} to {z1,...,zn} for x _||_ y | z1,..,zn. + * * @return Thia map. */ public SepsetProducer getSepsets() { @@ -112,6 +114,7 @@ public SepsetProducer getSepsets() { /** * Sets the knowledge to use for the final orientation. + * * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { @@ -144,6 +147,7 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { * Orients colliders in the graph. (FCI Step C) *

* Zhang's step F3, rule R0. + * * @param graph The graph to orient. */ public void ruleR0(Graph graph) { @@ -1106,6 +1110,7 @@ public void setMaxPathLength(int maxPathLength) { /** * Sets whether verbose output is printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -1114,6 +1119,7 @@ public void setVerbose(boolean verbose) { /** * Sets the true PAG for comparison. + * * @param truePag This PAG. */ public void setTruePag(Graph truePag) { @@ -1129,6 +1135,7 @@ public Graph getTruePag() { /** * Sets the change flag--marks externally that a change has been made. + * * @param changeFlag This flag. */ public void setChangeFlag(boolean changeFlag) { @@ -1137,6 +1144,7 @@ public void setChangeFlag(boolean changeFlag) { /** * Change flag for repeat rules + * * @return True if a change has occurred. */ public boolean isChangeFlag() { @@ -1145,6 +1153,7 @@ public boolean isChangeFlag() { /** * Sets whether the discriminating path collider rule should be done. + * * @param doDiscriminatingPathColliderRule True is done. */ public void setDoDiscriminatingPathColliderRule(boolean doDiscriminatingPathColliderRule) { @@ -1153,6 +1162,7 @@ public void setDoDiscriminatingPathColliderRule(boolean doDiscriminatingPathColl /** * Sets whether the discriminating path tail rule should be done. + * * @param doDiscriminatingPathTailRule True if done. */ public void setDoDiscriminatingPathTailRule(boolean doDiscriminatingPathTailRule) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 5fc56fa380..0c4624a365 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -140,6 +140,7 @@ public final class Fges implements GraphSearch, DagScorer { * case of conditional independence. See Chickering (2002), locally * consistent scoring criterion. This by default uses all the processors on * the machine. + * * @param score The score to use. The score should yield better scores for * more correct local models. The algorithm as given by * Chickering assumes the score will be a BIC score of some @@ -234,6 +235,7 @@ public void setKnowledge(Knowledge knowledge) { /** * Returns the elapsed time of the search. + * * @return This elapsed time. */ public long getElapsedTime() { @@ -249,6 +251,7 @@ public double scoreDag(Graph dag) { /** * Sets the initial graph. + * * @param initialGraph This graph. */ public void setInitialGraph(Graph initialGraph) { @@ -274,6 +277,7 @@ public void setInitialGraph(Graph initialGraph) { /** * Sets whether verbose output should be produced. Verbose output generated * by the Meek rules is treated separately. + * * @param verbose True iff the case. * @see #setMeekVerbose(boolean) */ @@ -283,6 +287,7 @@ public void setVerbose(boolean verbose) { /** * Sets whether verbose output should be produced for the Meek rules. + * * @param meekVerbose True iff the case. */ public void setMeekVerbose(boolean meekVerbose) { @@ -300,6 +305,7 @@ public PrintStream getOut() { /** * Sets the output stream that output (except for log output) should be sent * to. By detault System.out. + * * @param out This print stream. */ public void setOut(PrintStream out) { @@ -308,6 +314,7 @@ public void setOut(PrintStream out) { /** * If non-null, edges not adjacent in this graph will not be added. + * * @param boundGraph This bound graph. */ public void setBoundGraph(Graph boundGraph) { @@ -342,6 +349,7 @@ public void setMaxDegree(int maxDegree) { /** * Sets whether the first step of the procedure will score both X->Y and Y->X and prefer the * higher score (for adding X--Y to the graph). + * * @param symmetricFirstStep True iff the case. */ public void setSymmetricFirstStep(boolean symmetricFirstStep) { @@ -350,6 +358,7 @@ public void setSymmetricFirstStep(boolean symmetricFirstStep) { /** * Makes a string for the edge Bayes factors to log. + * * @param dag The DAG to logs the factors for. * @return The string to log. */ @@ -360,6 +369,7 @@ public String logEdgeBayesFactorsString(Graph dag) { /** * Returns the score of the final search model. + * * @return This score. */ public double getModelScore() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index da59fc21d1..b71fe7e496 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -65,10 +65,11 @@ public enum Algorithm {SAG, GAP} /** * Conctructor. - * @param cov The covariance matrix searched over. - * @param testType The type of test used. + * + * @param cov The covariance matrix searched over. + * @param testType The type of test used. * @param algorithm The type of FOFC algorithm used. - * @param alpha The alpha significance cutoff. + * @param alpha The alpha significance cutoff. * @see TestType * @see Algorithm */ @@ -90,10 +91,11 @@ public Fofc(ICovarianceMatrix cov, TestType testType, Algorithm algorithm, doubl /** * Conctructor. - * @param dataSet The continuous dataset searched over. - * @param testType The type of test used. + * + * @param dataSet The continuous dataset searched over. + * @param testType The type of test used. * @param algorithm The type of FOFC algorithm used. - * @param alpha The alpha significance cutoff. + * @param alpha The alpha significance cutoff. * @see TestType * @see Algorithm */ @@ -136,6 +138,7 @@ public Graph search() { /** * Sets whether the significant of cluster should be checked for each cluster. + * * @param significanceChecked True if so. */ public void setSignificanceChecked(boolean significanceChecked) { @@ -144,6 +147,7 @@ public void setSignificanceChecked(boolean significanceChecked) { /** * Sets which type of cluster check should be performed. + * * @param checkType The type to be performed. * @see ClusterSignificance.CheckType */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 9b4bc0e28c..896e4b4ad4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -125,6 +125,7 @@ public Graph search() { /** * Returns clusters output by the algorithm from the last call to search(). + * * @return These clusters. */ public List> getClusters() { @@ -133,6 +134,7 @@ public List> getClusters() { /** * Sets whether verbose output should be printed. + * * @param verbose True if the case. */ public void setVerbose(boolean verbose) { 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 2847e9b641..b013ac0d7e 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 @@ -32,8 +32,6 @@ import java.util.Arrays; import java.util.List; -import static org.apache.commons.math3.util.FastMath.log; - /** * Performs conditional independence tests of discrete data using the G Square method. Degrees of freedom are calculated * as in Fienberg, The Analysis of Cross-Classified Categorical Data, 2nd Edition, 142. @@ -65,8 +63,9 @@ public final class GSquareTest { /** * Constructor + * * @param dataSet The discrete dataset for which test results are requested. - * @param alpha The alpha sigificance level cutoff. + * @param alpha The alpha sigificance level cutoff. */ public GSquareTest(DataSet dataSet, double alpha) { if (alpha < 0.0 || alpha > 1.0) { @@ -92,6 +91,7 @@ public GSquareTest(DataSet dataSet, double 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. + * * @param testIndices The indices of the test result needed, in order. So for the above, [0 1 2 3...max]. * @return the test result. * @see Result @@ -218,6 +218,7 @@ public Result calcGSquare(int[] testIndices) { /** * Stores the parameters of the result returned by the G Square test and its p-value. + * * @author Frank Wimberly */ public static final class Result { @@ -271,7 +272,8 @@ public boolean isIndep() { /** * Returns the dimensions of the variables, in order. - * @return These dimensions, as an int[] array. For instance, if the array is [2 3], + * + * @return These dimensions, as an int[] array. For instance, if the array is [2 3], * then the first variable has 2 categories and second variable has 3 categories. */ public int[] getDims() { @@ -280,6 +282,7 @@ public int[] getDims() { /** * Returns the cell table for this test. + * * @return This table. * @see CellTable */ @@ -296,6 +299,7 @@ public double getAlpha() { /** * Sets the significance level to be used for tests. + * * @param alpha The alpha significance level of the test. */ public void setAlpha(double alpha) { @@ -309,6 +313,7 @@ public void setAlpha(double alpha) { /** * Returns the dataset used for this test. + * * @return This dataset. */ public DataSet getDataSet() { @@ -318,8 +323,9 @@ public DataSet getDataSet() { /** * Returns a judgement of whether the variables index by 'testIndices' * determine the variable index by 'p'. + * * @param testIndices The indices of the conditioning variables. - * @param p The index of the child variable. + * @param p The index of the child variable. * @return True if the conditioning variables determine the child variable. */ public boolean isDetermined(int[] testIndices, double p) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java index 73d925e90d..86b4493dad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java @@ -32,7 +32,7 @@ * possibly apply to a PAG.

*

By convention, the NodePairs in the orients ArrayList are ordered such that Node1 is the * "from" node and Node2 is the "to" node (ie 1 o-> 2).

-* + * * @author Trevor Burns */ public class GraphChange { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java index 3b2678b837..b709a96c43 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java @@ -55,6 +55,7 @@ public class GraphScore implements Score { /** * Constructor + * * @param dag A directed acyclic graph. */ public GraphScore(Graph dag) { @@ -65,6 +66,7 @@ public GraphScore(Graph dag) { /** * Constructor. + * * @param facts A list known independence facts; a lookup will be donw * from these facts. * @see IndependenceFacts @@ -77,6 +79,7 @@ public GraphScore(IndependenceFacts facts) { /** * Calculates the sample likelihood and BIC score for y given its z in a simple SEM model. + * * @return this score. */ public double localScore(int y, int[] z) { @@ -105,6 +108,7 @@ private Set getPearlParentsTest() { /** * Returns a "score difference", which amounts to a conditional * local scoring criterion results + * * @return The "difference". */ @Override @@ -114,6 +118,7 @@ public double localScoreDiff(int x, int y, int[] z) { /** * The "unconditional difference." + * * @return This. */ @Override @@ -137,6 +142,7 @@ public double localScore(int i) { /** * Returns a judgment for FGES as to whether a score with the bump is for an effect edge. + * * @param bump The bump * @return True if so. * @see Fges @@ -155,6 +161,7 @@ public DataSet getDataSet() { /** * Returns the list of variables. + * * @return This list. */ @Override @@ -164,6 +171,7 @@ public List getVariables() { /** * Returns the maximum degree, which is set to 1000. + * * @return 1000. */ @Override @@ -195,6 +203,7 @@ public int getSampleSize() { /** * Returns a copy of the DAG being searched over. + * * @return This DAG. */ public Graph getDag() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java index 0582de59f9..8c1a2e6c4c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java @@ -48,6 +48,7 @@ public class GraphoidAxioms { /** * Constructor. + * * @param facts A set of GraphoidIndFacts. * @param nodes The list of nodes. * @see GraphoidIndFact k @@ -59,8 +60,9 @@ public GraphoidAxioms(Set facts, List nodes) { /** * Constructor. - * @param facts A list of GraphoidIndFacts. - * @param nodes The list of nodes. + * + * @param facts A list of GraphoidIndFacts. + * @param nodes The list of nodes. * @param textSpecs A map from GraphoidIndFacts to String text specs. The * text specs are used for printing information to the user * about which facts are found or are missing. @@ -76,6 +78,7 @@ public GraphoidAxioms(Set facts, /** * The main methods. + * * @param args E.g., "java -cp tetrad-gui-7.1.3-SNAPSHOT-launch.jar edu.cmu.tetrad.search.GraphoidAxioms udags5.txt 5" * Here, udgas5.txt is a file containing independence models, one per line, where each independence * fast is specified by, e.g., "1:23|56", indicating that 1 is independence of 2 and 3 conditional @@ -161,6 +164,7 @@ private static GraphoidAxioms getGraphoidAxioms(String line, List nodes) t /** * Checked whether the IM is a semigraphoid. + * * @return True if so. */ public boolean semigraphoid() { @@ -169,6 +173,7 @@ public boolean semigraphoid() { /** * Checks whether teh IM is a semigraphoid. + * * @return True if so. */ public boolean graphoid() { @@ -177,6 +182,7 @@ public boolean graphoid() { /** * Checks whether the IM is a compositional graphoid. + * * @return True if so. */ public boolean compositionalGraphoid() { 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 4ffa516a41..745460d5b7 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 @@ -40,6 +40,7 @@ *

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

+ * * @author peterspirtes * @author josephramsey * @author bryanandrews diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index ef8a73f492..dbe270fe76 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -31,6 +31,7 @@ * and useful Markov blanket search.

*

Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. * Advances in neural information processing systems, 12.

+ * * @author Joseph Ramsey */ public class GrowShrink implements MbSearch { @@ -47,6 +48,7 @@ public class GrowShrink implements MbSearch { /** * Constructs a new search. + * * @param test The test used for this search. */ public GrowShrink(IndependenceTest test) { @@ -106,6 +108,7 @@ public List findMb(Node target) { /** * Returns "Grow Shrink". + * * @return This string. */ public String getAlgorithmName() { 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 a095a13d06..7796276992 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 @@ -63,9 +63,13 @@ public List getVariables() { return this.score.getVariables(); } - public List getRequired() { return this.required; } + public List getRequired() { + return this.required; + } - public List getForbidden() { return this.forbidden; } + public List getForbidden() { + return this.forbidden; + } public void setKnowledge(List required, List forbidden) { this.root = new GSTNode(this); @@ -163,7 +167,7 @@ public double trace(Set prefix, Set parents) { parents.remove(best); this.remove.add(best); } - } while(best != null); + } while (best != null); } parents.removeAll(this.remove); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java index 5956c5ce29..28710c104f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java @@ -2,9 +2,11 @@ /** * Interface for an algorithm can can get/set a value for penalty disoucnt. + * * @author josephramsey */ public interface HasPenaltyDiscount extends Score { void setPenaltyDiscount(double penaltyDiscount); + double getPenaltyDiscount(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java index 0f969985fa..a0388e7501 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java @@ -293,10 +293,10 @@ public static void main(String[] args) { // the problem is written in the form of a matrix double[][] dataMatrix = { //col0 col1 col2 col3 - {70, 40, 20, 55}, //row0 - {65, 60, 45, 90}, //row1 - {30, 45, 50, 75}, //row2 - {25, 30, 55, 40} //row3 + {70, 40, 20, 55}, //row0 + {65, 60, 45, 90}, //row1 + {30, 45, 50, 75}, //row2 + {25, 30, 55, 40} //row3 }; //find optimal assignment diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java index 0449531f17..61ded6deb4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java @@ -31,19 +31,30 @@ /** * An interface for fast adjacency searches (i.e. PC adjacency searches). + * * @author josephramsey */ public interface IFas { void setKnowledge(Knowledge knowledge); + SepsetMap getSepsets(); + void setDepth(int depth); + Graph search(); + Graph search(List nodes); + long getElapsedTime(); + int getNumIndependenceTests(); + List getNodes(); + List getAmbiguousTriples(Node node); + void setVerbose(boolean verbose); + void setOut(PrintStream out); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index aff982603b..528266e84b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -23,6 +23,7 @@ *

Maathuis, Marloes H., Markus Kalisch, and Peter Bühlmann. * "Estimating high-dimensional intervention effects from observational data." * The Annals of Statistics 37.6A (2009): 3133-3164.

+ * * @author josephramsey */ public class Ida { @@ -34,9 +35,10 @@ public class Ida { /** * Constructor. - * @param dataSet The dataset being searched over. - * @param cpdag The CPDAG (found, e.g., by running PC, or some other CPDAG- - * producing algorithm. + * + * @param dataSet The dataset being searched over. + * @param cpdag The CPDAG (found, e.g., by running PC, or some other CPDAG- + * producing algorithm. * @param possibleCauses The possible causes to be considered. */ public Ida(DataSet dataSet, Graph cpdag, List possibleCauses) { @@ -56,6 +58,7 @@ public Ida(DataSet dataSet, Graph cpdag, List possibleCauses) { /** * Returns the minimum effects of X on Y for X in V \ {Y}, sorted downward by minimum effect + * * @param y The child variable. * @return Two sorted lists, one of nodes, the other of corresponding minimum effects, sorted downward by * minimum effect size. @@ -79,6 +82,7 @@ public NodeEffects getSortedMinEffects(Node y) { /** * A list of nodes and corresponding minimum effects. + * * @author josephramsey */ public static class NodeEffects { @@ -120,6 +124,7 @@ public String toString() { /** * Calculates the true effect of (x, y) given the true DAG (which * must be provided. + * * @param trueDag The true DAG. * @return The true effect of (x, y). */ @@ -234,6 +239,7 @@ private LinkedList getEffects(Node x, Node y) { /** * Returns a map from nodes in V \ {Y} to their minimum effects. + * * @param y The child variable * @return Thia map. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java index 9a15294ad7..d512efbe7d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java @@ -25,8 +25,6 @@ import java.util.List; -import static org.apache.commons.math3.util.FastMath.log; - /** *

Implements a score to average results over multiple scores. This is * used for the IMaGES algorithm. The idea is that one pick and algorithm @@ -56,6 +54,7 @@ public class ImagesScore implements Score { /** * Constructs an IMaGES score using the given list of individual scores. * These scores will be be averaged to obtain the IMaGES score itself. + * * @param scores The list of scores. */ public ImagesScore(List scores) { @@ -73,6 +72,7 @@ public ImagesScore(List scores) { * component score from their localScoreDiff methods. Score differences * that are returned as undefined (NaN) are excluded from the * average. + * * @return This average score. */ @Override @@ -97,6 +97,7 @@ public double localScoreDiff(int x, int y, int[] z) { * which is obtained by averaging the local such scores obtained from each * individual score provided in the constructor, excluding scores that are * returned as undefined (which are left out of the average). + * * @param i The variable whose score is needed. * @return This score. */ @@ -131,6 +132,7 @@ public double localScore(int i, int[] parents, int index) { * parents, which is obtained by averaging the local such scores obtained * from each individual score provided in the constructor, excluding scores * that are returned as undefined (which are left out of the average). + * * @param i The variable whose score is needed. * @return This score. */ @@ -155,6 +157,7 @@ public double localScore(int i, int parent) { * averaging the local scores obtained from each individual score * provided in the constructor, excluding scores that are returned * as undefined (which are left out of the average). + * * @param i The variable whose score is needed. * @return This score. */ @@ -181,6 +184,7 @@ public boolean isEffectEdge(double bump) { /** * Returns the variables. + * * @return This list. */ @Override @@ -190,6 +194,7 @@ public List getVariables() { /** * Returns the sample size from the first score. + * * @return This size. */ @Override @@ -199,6 +204,7 @@ public int getSampleSize() { /** * Returns the max degree from teh first score. + * * @return This maximum. */ @Override @@ -208,6 +214,7 @@ public int getMaxDegree() { /** * Returns the 'determines' judgment from the first score. + * * @return This judgment, true if the 'determine' relations holds. */ @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java index 02220ed081..18dfce70df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java @@ -103,6 +103,7 @@ public IndTestChiSquare(DataSet dataSet, double alpha) { /** * Creates a new IndTestChiSquare for a subset of the nodes. + * * @param nodes This list of nodes. */ public IndependenceTest indTestSubset(List nodes) { @@ -269,6 +270,7 @@ public boolean determines(List z, Node x1) { /** * Returns the alpha significance level of the test. + * * @return This level. */ public double getAlpha() { @@ -295,6 +297,7 @@ public List getVariables() { /** * Returns a string representation of this test. + * * @return This string. */ public String toString() { @@ -304,6 +307,7 @@ public String toString() { /** * Returns the data being analyzed. + * * @return This data. */ public DataSet getData() { @@ -312,6 +316,7 @@ public DataSet getData() { /** * Returns a number which is more positive for more dependent test tesults. + * * @return This number. */ @Override @@ -321,6 +326,7 @@ public double getScore() { /** * Returns true if verbose output should be printed. + * * @return This. */ @Override @@ -330,6 +336,7 @@ public boolean isVerbose() { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java index 51ba766fbc..626c64e2fe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java @@ -187,6 +187,7 @@ public DataSet getData() { /** * Returns a number is more positive for stronger judgments of dependence. + * * @return This number. */ @Override @@ -203,6 +204,7 @@ public String toString() { /** * Returns true if verbose output should be printed. + * * @return True if the case. */ public boolean isVerbose() { @@ -211,6 +213,7 @@ public boolean isVerbose() { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -219,6 +222,7 @@ public void setVerbose(boolean verbose) { /** * Sets the number of orthogal functions to use to do the calculations. + * * @param numFunctions This number. */ public void setNumFunctions(int numFunctions) { @@ -227,6 +231,7 @@ public void setNumFunctions(int numFunctions) { /** * Returns the kernel width. + * * @return This width. */ public double getWidth() { @@ -235,6 +240,7 @@ public double getWidth() { /** * Returns the kernel multiplier. + * * @param multiplier This multiplier. */ public void setKernelMultiplier(double multiplier) { @@ -243,6 +249,7 @@ public void setKernelMultiplier(double multiplier) { /** * Sets the kernel to be used. + * * @param kernel This kernel. * @see edu.cmu.tetrad.search.ConditionalCorrelationIndependence.Kernel */ @@ -252,6 +259,7 @@ public void setKernel(ConditionalCorrelationIndependence.Kernel kernel) { /** * Sets the basis used for the calculation. + * * @param basis This basis. * @see edu.cmu.tetrad.search.ConditionalCorrelationIndependence.Basis */ @@ -261,6 +269,7 @@ public void setBasis(ConditionalCorrelationIndependence.Basis basis) { /** * Sets the kernal regression sample size. + * * @param i This size. */ public void setKernelRegressionSampleSize(int i) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java index b4bf73995f..7101682bdc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java @@ -119,7 +119,7 @@ public IndTestFisherZ(DataSet dataSet, double alpha) { * * @param data A 2D continuous data set with no missing values. * @param variables A list of variables, a subset of the variables of data. - * @param alpha The alpha level of the test. + * @param alpha The alpha level of the test. */ public IndTestFisherZ(Matrix data, List variables, double alpha) { this.dataSet = new BoxDataSet(new VerticalDoubleDataBox(data.transpose().toArray()), variables); @@ -141,8 +141,9 @@ public IndTestFisherZ(Matrix data, List variables, double alpha) { /** * Constructs a new independence test that will determine conditional independence facts using the given correlation * matrix and the given significance level. + * * @param covMatrix The covaraince matrix. - * @param alpha The alpha level of the test. + * @param alpha The alpha level of the test. */ public IndTestFisherZ(ICovarianceMatrix covMatrix, double alpha) { this.cor = new CorrelationMatrix(covMatrix); @@ -164,6 +165,7 @@ public IndTestFisherZ(ICovarianceMatrix covMatrix, double alpha) { /** * Creates a new independence test instance for a subset of the variables. + * * @return a new independence test. * @see IndependenceTest */ @@ -238,6 +240,7 @@ public double getPValue() { /** * Returns the p-value for x _||_ y | z. + * * @param x Node 1 * @param y Node 2 * @param z The conditioning varialbes. @@ -272,6 +275,7 @@ public double getPValue(Node x, Node y, List z) throws SingularMatrixExcep /** * Returns the BIC score for this test. + * * @return The BIC score. */ public double getBic() { @@ -308,6 +312,7 @@ public List getVariables() { /** * Sets teh variables to a new list of the same size. Useful if multiple independence tests * are needed with object-identical sets of variables. + * * @param variables The new list of variables. */ public void setVariables(List variables) { @@ -339,6 +344,7 @@ public ICovarianceMatrix getCov() { /** * Returns the (singleton) list of datasets being analyzed. + * * @return This list (length 1). */ @Override @@ -350,6 +356,7 @@ public List getDataSets() { /** * Returns the sample size. + * * @return This size. */ @Override @@ -359,6 +366,7 @@ public int getSampleSize() { /** * Returns the score for this test, alpha - p. Should be dependent only for positive values. + * * @return This score. */ @Override @@ -368,6 +376,7 @@ public double getScore() { /** * Returns true iff verbose output should be printed. + * * @return True if so. */ public boolean isVerbose() { @@ -376,6 +385,7 @@ public boolean isVerbose() { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -391,6 +401,7 @@ public String toString() { /** * Returns true in case the variable in Z jointly determine x. + * * @param z The contitioning variables. * @param x The conditioned variable. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceResult.java index 903ad3967c..afaa4ed76e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceResult.java @@ -9,6 +9,7 @@ /** * Stores a single conditional independence result, e.g., whether * X _||_ Y | Z1,..,Zn holds or does not. + * * @author josephramsey */ public final class IndependenceResult implements TetradSerializable { @@ -20,9 +21,10 @@ public final class IndependenceResult implements TetradSerializable { /** * Construtor. - * @param fact The fact itself. - * @param indep The conditional independence result, true if the fact - * holds, false if not. + * + * @param fact The fact itself. + * @param indep The conditional independence result, true if the fact + * holds, false if not. * @param pValue The p-values of the independence result, under the null * (independence) hypothesis. * @see IndependenceFact @@ -35,6 +37,7 @@ public IndependenceResult(IndependenceFact fact, boolean indep, double pValue) { /** * Generates a simple exemplar of this class to test serialization. + * * @see TetradSerializableUtils */ public static IndependenceResult serializableInstance() { @@ -45,6 +48,7 @@ public static IndependenceResult serializableInstance() { /** * Returns the independence fact being stored. + * * @return This fact * @see IndependenceFact */ @@ -55,6 +59,7 @@ public IndependenceFact getFact() { /** * Returns whether the fact holds--i.e., if the judgment is for * independence. + * * @return True if the fact holds, false if ot. * @see #isDependent() */ @@ -65,6 +70,7 @@ public boolean isIndependent() { /** * Returns whether the fact fails to hold--i.e., if the judgment is for * dependence. This is the negation of isIndependent. + * * @return True if the fact does not, false if it does. * @see #isIndependent() */ @@ -77,6 +83,7 @@ public boolean isDependent() { * A special case obtains is this fact is being used to store a d-separation * fact, in which case the "p-value" is deemed to be 0 if the fact holds and * 1 if it does not. + * * @return The p-value of result under the null hypothesis. */ public double getPValue() { @@ -85,6 +92,7 @@ public double getPValue() { /** * Returns a string represnetation of this independence fact. + * * @return This string. */ public String toString() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java index 5af96f3e8a..6b53555ea6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java @@ -69,18 +69,21 @@ public interface IndependenceTest { /** * Sets whether this test will print verbose output. + * * @param verbose True if so. */ void setVerbose(boolean verbose); /** * Returns true if the test prints verbose output. + * * @return True if the case. */ boolean isVerbose(); /** * Returns a string representation of this test. + * * @return This string. */ String toString(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java index 3c8f7a6248..f98538843a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java @@ -60,7 +60,8 @@ public class LingamPattern { /** * Constructor. - * @param cpdag The CPDAG whose unoriented edges are to be oriented. + * + * @param cpdag The CPDAG whose unoriented edges are to be oriented. * @param dataSet Teh dataset to use. */ public LingamPattern(Graph cpdag, DataSet dataSet) @@ -82,6 +83,7 @@ public LingamPattern(Graph cpdag, DataSet dataSet) /** * Runs the search and returns the result graph. + * * @return This graph. */ public Graph search() { @@ -179,6 +181,7 @@ public Graph search() { /** * Returns the p-values of the search. + * * @return This list as a double[] array. */ public double[] getPValues() { @@ -187,6 +190,7 @@ public double[] getPValues() { /** * Sets the alpha level for the search. + * * @param alpha This alpha level. */ public void setAlpha(double alpha) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java index 7093a123c5..2d92ac7bce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java @@ -33,6 +33,7 @@ /** *

Performs a Max-P orientation of unshielded triples in a graph.

+ * * @author Joseph Ramsey * @see PcMax */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java index 79f9d9a773..cce9448c92 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.search; -import java.util.*; +import java.util.ArrayList; +import java.util.Stack; /** *

Returns row positions for placing rooks for an n x n matrix so the rooks @@ -16,8 +17,9 @@ public class NRooks { /** * Solves the N-Rooks problem for the given board or allowable positions. + * * @param allowablePositions A matrix of allowable rook positions, should be - * true iff the position is allowable. + * true iff the position is allowable. * @return A list of row indices for where to place the rooks for each solution. */ public static ArrayList nRooks(boolean[][] allowablePositions) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java index 4a39912d20..b5544afd70 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java @@ -36,6 +36,7 @@ /** * Calculates partial correlation using the recursive method. + * * @author josephramsey */ public class PartialCorrelation { @@ -45,8 +46,9 @@ public class PartialCorrelation { /** * Constructor. - * @param nodes The lsit of nodes. - * @param cov The covariance matrix, as a Matrix. + * + * @param nodes The lsit of nodes. + * @param cov The covariance matrix, as a Matrix. * @param sampleSize The sample size. */ public PartialCorrelation(List nodes, Matrix cov, int sampleSize) { @@ -56,6 +58,7 @@ public PartialCorrelation(List nodes, Matrix cov, int sampleSize) { /** * Constructor + * * @param cov The covariance matrix, as an ICovariance object. */ public PartialCorrelation(ICovarianceMatrix cov) { @@ -67,6 +70,7 @@ public PartialCorrelation(ICovarianceMatrix cov) { /** * Calculates the partial correlation of x and y conditional on the nodes in z * recursively. + * * @return this partial correlation. */ public double corr(Node x, Node y, List z) { 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 7c4f7cbc4c..9933c2dab3 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 @@ -284,7 +284,7 @@ public Set getAdjacencies() { } /** - * @return the non-adjacencies of the searched graph. + * @return the non-adjacencies of the searched graph. */ public Set getNonadjacencies() { Graph complete = GraphUtils.completeGraph(this.graph); @@ -295,7 +295,7 @@ public Set getNonadjacencies() { } /** - * @return the number of independence tests performed in the search. + * @return the number of independence tests performed in the search. */ public int getNumIndependenceTests() { return this.numIndependenceTests; @@ -310,6 +310,7 @@ public List getNodes() { /** * Sets whether verbose output should be given. + * * @param verbose True iff the case. */ public void setVerbose(boolean verbose) { @@ -318,6 +319,7 @@ public void setVerbose(boolean verbose) { /** * Sets whether the stable adjacency search should be used. + * * @param stable True iff the case. */ public void setStable(boolean stable) { @@ -326,6 +328,7 @@ public void setStable(boolean stable) { /** * Sets whether the max p method should be used in the adjacency searc h. + * * @param useMaxP iff the case. */ public void setUseMaxP(boolean useMaxP) { @@ -334,6 +337,7 @@ public void setUseMaxP(boolean useMaxP) { /** * Sets the maximum path length for the PC heuristic. + * * @param maxPPathLength this length. */ public void setMaxPPathLength(int maxPPathLength) { 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 511e7fb958..e5595c80d0 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 @@ -41,7 +41,9 @@ */ public final class PcAll implements GraphSearch { public enum FasType {REGULAR, STABLE} + public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P} + public enum ConflictRule {PRIORITY, BIDIRECTED, OVERWRITE} /** @@ -187,6 +189,7 @@ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { /** * Sets the type of collider discovery to do. + * * @param colliderDiscovery This type. */ public void setColliderDiscovery(ColliderDiscovery colliderDiscovery) { @@ -195,6 +198,7 @@ public void setColliderDiscovery(ColliderDiscovery colliderDiscovery) { /** * Sets the conflict rule to use. + * * @param conflictRule This rule. */ public void setConflictRule(ConflictRule conflictRule) { @@ -261,6 +265,7 @@ public SepsetMap getSepsets() { /** * Sets whether verbose output should be printed. + * * @param verbose True iff the case. */ public void setVerbose(boolean verbose) { @@ -459,7 +464,7 @@ private void logTriples() { } } - private void orientUnshieldedTriplesConservative(Knowledge knowledge) { + private void orientUnshieldedTriplesConservative(Knowledge knowledge) { TetradLogger.getInstance().log("info", "Starting Collider Orientation:"); this.colliderTriples = new HashSet<>(); @@ -627,5 +632,5 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra } } } - } +} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index a808034127..6f31c86ee9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -40,7 +40,8 @@ public class PermutationMatrixPair { /** * Constructs with a given matrix M and a row and column permutation (which * may be null). - * @param M The matrix to be permuted. + * + * @param M The matrix to be permuted. * @param rowPerm The row permutation for M; if null the identity permutation * ([0 1 2...#rows]) will be used. * @param colPerm The row permutation for M; if null the identity permutation @@ -64,6 +65,7 @@ public PermutationMatrixPair(Matrix M, int[] rowPerm, int[] colPerm) { /** * Returns W, permuted rowwise by the permutation passed in through the constructor. + * * @return The matrix, permuted columnwise and rowwise, by the specified column and * row permutations. */ @@ -87,6 +89,7 @@ public int[] getColPerm() { /** * Prints a string representation of this. + * * @return The row and columns permutations, followed by the permuted matrix. */ public String toString() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index c1f5071e76..4eba50a5e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -49,12 +49,12 @@ public Graph search() { end++; } if (!this.knowledge.isTierForbiddenWithin(i)) { - tasks.add(new int[] {start, end}); + tasks.add(new int[]{start, end}); } } } else { this.order.addAll(this.variables); - tasks.add(new int[] {0, this.variables.size()}); + tasks.add(new int[]{0, this.variables.size()}); } for (int[] task : tasks) { @@ -102,7 +102,9 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - public Knowledge getKnowledge() { return this.knowledge; } + public Knowledge getKnowledge() { + return this.knowledge; + } public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java index a7890bb47f..2611153bcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java @@ -13,6 +13,7 @@ /** * Scores a DAG using the SemBicScore. + * * @author josephramsey * @see SemBicScore */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java index dc88f58d21..2100d5191c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java @@ -59,6 +59,7 @@ public SepsetMap() { /** * Copy constructor. + * * @param map A given sepset map. */ public SepsetMap(SepsetMap map) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java index 73af7a6de2..0aa3d89905 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java @@ -27,8 +27,9 @@ /** *

A covenience structure that can generate and keep track of sepsets

- * @see SepsetMap + * * @author Joseph Ramsey + * @see SepsetMap */ public interface SepsetProducer { List getSepset(Node a, Node b); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java index 6b4be73967..bbe6e015c9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java @@ -34,6 +34,7 @@ /** *

A sepset producer using conditional independence tests to generate the Sepset map, * for the case where possible dsep sets are required.

+ * * @author josephramsey * @see SepsetProducer * @see SepsetMap diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java index 6acd93390b..8da12d358c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java @@ -27,6 +27,7 @@ /** *

A sepset producer using conditional independence tests to generate the Sepset map.

+ * * @author josephramsey * @see SepsetProducer * @see SepsetMap diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index b13af3b08c..636109d47f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -36,6 +36,7 @@ public class Sp implements SuborderSearch { /** * This algorithm will work with an arbitrary score. + * * @param score The Score to use. */ public Sp(Score score) { @@ -51,11 +52,12 @@ public Sp(Score score) { /** * This is the method called by PermutationSearch per tier. - * @param prefix The variable preceding the suborder variables in the permutation, including - * all variables from previous tiers. + * + * @param prefix The variable preceding the suborder variables in the permutation, including + * all variables from previous tiers. * @param suborder The suborder of the variables list beign searched over. Only the order of the * variables in this suborder will be modified. - * @param gsts The GrowShrinkTree used for the search. This is an optimized score-caching class. + * @param gsts The GrowShrinkTree used for the search. This is an optimized score-caching class. */ @Override public void searchSuborder(List prefix, List suborder, Map gsts) { @@ -98,6 +100,7 @@ public void searchSuborder(List prefix, List suborder, Map getVariables() { /** * Returns the map from nodes to their parents. + * * @return This map. */ @Override @@ -126,6 +131,7 @@ public Map> getParents() { /** * Returns the score being used for this search. + * * @return This score. * @see Score */ @@ -229,7 +235,7 @@ private int[] makeNext() { if (i == -1) return null; int k = i + this.dirs[i]; - this.next = new int[] {i, k}; + this.next = new int[]{i, k}; swap(i, k, this.dirs); swap(i, k, this.perm); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index e170209ddd..5876eb0aa2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -11,21 +11,24 @@ * Interface to help implement suborder searches for various types of permutation algorithms. * A "suborder search" is a search for permutation <x1a,...x1n, x2a,...,x2m, x3a,...,x3l>> * that searches for a good permutation of x2a,...,x2m with x1a,...,x1n as a prefix. + * * @author bryanandrews */ public interface SuborderSearch { /** * Searches the suburder. - * @param prefix The prefix of the suborder. + * + * @param prefix The prefix of the suborder. * @param suborder The suborder. - * @param gsts The GrowShinkTree being used to do caching of scores. + * @param gsts The GrowShinkTree being used to do caching of scores. * @see GrowShrinkTree */ void searchSuborder(List prefix, List suborder, Map gsts); /** * The knowledge being used. + * * @param knowledge This knowledge. * @see Knowledge */ @@ -33,6 +36,7 @@ public interface SuborderSearch { /** * The list of all variables, in order. They should satisfy the suborder requirements. + * * @return This list. * @see Node * @see edu.cmu.tetrad.data.Variable @@ -41,12 +45,14 @@ public interface SuborderSearch { /** * The map from nodes to parents resulting from the search. + * * @return This map. */ Map> getParents(); /** * The score being used. + * * @return This score. * @see Score */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index f1f4fca058..c2a462b43c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -28,7 +28,9 @@ import org.apache.commons.math3.util.FastMath; import java.io.PrintStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java index babe1395ac..a722730935 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java @@ -45,7 +45,7 @@ public class TeyssierScorer { public TeyssierScorer(IndependenceTest test, Score score) { - if (test == null && score == null) throw new IllegalArgumentException("Required: test or score"); + if (test == null && score == null) throw new IllegalArgumentException("Required: test or score"); NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT); this.variables = score.getVariables(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index d0a6bbbd2a..f2f69373bb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -172,6 +172,7 @@ public Graph search() { /** * Sets the depth--i.e., the maximum number of variables conditioned on in any * test, -1 for unlimited. + * * @param depth This depth. */ public void setDepth(int depth) { @@ -185,6 +186,7 @@ public void setDepth(int depth) { /** * Sets the knowledge used in the search. + * * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { @@ -193,6 +195,7 @@ public void setKnowledge(Knowledge knowledge) { /** * Returns the number of independence tests. + * * @return This number. */ public int getNumIndependenceTests() { @@ -201,6 +204,7 @@ public int getNumIndependenceTests() { /** * Returns a map for x _||_ y | Z from {x, y} to Z. + * * @return This map. */ public SepsetMap getSepsets() { @@ -209,6 +213,7 @@ public SepsetMap getSepsets() { /** * Sets an external graph. + * * @param externalGraph This grpah. */ public void setExternalGraph(Graph externalGraph) { @@ -217,6 +222,7 @@ public void setExternalGraph(Graph externalGraph) { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -241,6 +247,7 @@ public long getElapsedTime() { /** * Returns the nodes of the test. + * * @return This list. */ @Override @@ -258,6 +265,7 @@ public List getAmbiguousTriples(Node node) { /** * Sets the output stream for printing, default is System.out. + * * @param out The print stream. * @see PrintStream */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java index b10f976980..2b4a26edf3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java @@ -64,6 +64,7 @@ public class ZsbScore implements Score { /** * Constructs the score using a covariance matrix. + * * @param covMatrix The covariance matrix. */ public ZsbScore(ICovarianceMatrix covMatrix) { @@ -78,6 +79,7 @@ public ZsbScore(ICovarianceMatrix covMatrix) { /** * Constructs the score using a covariance matrix. + * * @param dataSet The data set. */ public ZsbScore(DataSet dataSet) { @@ -87,7 +89,8 @@ public ZsbScore(DataSet dataSet) { /** * Returns the score for the child given the parents. - * @param i The index of the node. + * + * @param i The index of the node. * @param parents The indices of the node's parents. * @return The score */ @@ -127,6 +130,7 @@ public double localScore(int i, int... parents) { /** * Returns localScore(y | z, x) - localScore(y | z). + * * @param x Node 1 * @param y Node 2 * @param z The conditioning nodes. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java index 7f0a414597..e3230b8d61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java @@ -42,9 +42,10 @@ public class BpcTetradPurifyWashdown { /** * Construct the algorithm using a covariance matrix. - * @param cov A covariance matrix. + * + * @param cov A covariance matrix. * @param testType A Test type. - * @param alpha An alpha cutoff + * @param alpha An alpha cutoff * @see edu.cmu.tetrad.data.CovarianceMatrix * @see TestType */ @@ -55,18 +56,21 @@ public BpcTetradPurifyWashdown(ICovarianceMatrix cov, TestType testType, double /** * Construct the algorithm using a data set. - * @param dataSet A DataSet. + * + * @param dataSet A DataSet. * @param testType A Test type. - * @param alpha An alpha cutoff + * @param alpha An alpha cutoff * @see DataSet * @see TestType - */ public BpcTetradPurifyWashdown(DataSet dataSet, TestType testType, double alpha) { + */ + public BpcTetradPurifyWashdown(DataSet dataSet, TestType testType, double alpha) { this.variables = dataSet.getVariables(); this.test = new ContinuousTetradTest(dataSet, testType, alpha); } /** * Runs the search and returns a graph. + * * @return The discovered graph. */ public Graph search() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java index 2879196ff0..2c1866905d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java @@ -67,7 +67,8 @@ public class FasFdr implements IFas { /** * Constructs a new FastAdjacencySearch. - * @param test The independence test to use. + * + * @param test The independence test to use. * @param numIndependenceTests The number of independence tests total done. */ public FasFdr(IndependenceTest test, int numIndependenceTests) { @@ -151,6 +152,7 @@ public Graph search() { /** * Returns the nubmer of independence tests done in the course of the search. + * * @return This number. */ public int getNumIndependenceTests() { @@ -159,6 +161,7 @@ public int getNumIndependenceTests() { /** * Returns a map for x _||_ y | z1,...,zn of {x, y} to {z1,...,zn}, + * * @return This map. */ public SepsetMap getSepsets() { @@ -167,6 +170,7 @@ public SepsetMap getSepsets() { /** * Sets whether verbose output will be printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -204,6 +208,7 @@ public void setOut(PrintStream out) { /** * Sets the depth of the search--i.e., the maximum number of variables conditioned on for any * conditional independence test. + * * @param depth This maximum. */ public void setDepth(int depth) { @@ -217,6 +222,7 @@ public void setDepth(int depth) { /** * Sets the knowledge to be used in the search. + * * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java index af7b438951..12472dbbf1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java @@ -70,7 +70,8 @@ public class Washdown { /** * Constructor. - * @param cov The covaraince matrix. + * + * @param cov The covaraince matrix. * @param alpha The alpha cutoff level. */ public Washdown(ICovarianceMatrix cov, double alpha) { @@ -81,7 +82,8 @@ public Washdown(ICovarianceMatrix cov, double alpha) { /** * Constructor. - * @param data The dataset. + * + * @param data The dataset. * @param alpha The alpha cutoff level. */ public Washdown(DataSet data, double alpha) { @@ -92,6 +94,7 @@ public Washdown(DataSet data, double alpha) { /** * Runs the Washdown algorithm and return a graph. + * * @return The graph. */ public Graph search() { From 58273d2a625b5496bda9a596adb3fd149ef95c0a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:57:52 -0400 Subject: [PATCH 240/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/IndTestDSep.java | 119 ++++++++++++++---- .../edu/cmu/tetrad/search/IndTestFisherZ.java | 4 +- 2 files changed, 96 insertions(+), 27 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java index fbe0d123d9..dcf59ac8e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java @@ -34,8 +34,8 @@ import java.util.List; /** - * Checks independence facts for variables associated with the nodes in a given graph by checking d-separation facts on - * the underlying nodes. + * Checks independence facts for variables associated with the nodes in a given graph by + * checking d-separation facts on the underlying nodes. * * @author Joseph Ramsey */ @@ -57,21 +57,52 @@ public class IndTestDSep implements IndependenceTest { private boolean verbose = false; private double pvalue = 0; + /** + * Constructor. + * + * @param graph The graph for which d-separation facts should be checked. + * This may be a DAG, CPDAG, or PAG. In the latter case, + * m-separation results will be returned (same algorithm). + */ public IndTestDSep(Graph graph) { this(graph, false); } + /** + * Constructor. + * + * @param facts Independence facts to be used for direct calculations of + * d-separation. + * @param variables The variables for the facts, if different from those + * that independenceFacts would return. + * @see IndependenceFacts + */ public IndTestDSep(IndependenceFacts facts, List variables) { this(facts, false); facts.setNodes(variables); } + + /** + * Constructor. + * + * @param facts Independence facts to be used for direct calculations of + * d-separation. + * @see IndependenceFacts + */ public IndTestDSep(IndependenceFacts facts) { this(facts, false); } /** - * Constructs a new independence test that returns d-separation facts for the given graph as independence results. + * Constructor. + * + * @param graph The graph for which d-separation facts should be checked. + * This may be a DAG, CPDAG, or PAG. In the latter case, + * m-separation results will be returned (same algorithm). + * @param keepLatents Whether latent in the graph should be used in conditional + * independence facts. If the graph is being marginalized, + * this should be false. */ public IndTestDSep(Graph graph, boolean keepLatents) { if (graph == null) { @@ -84,6 +115,16 @@ public IndTestDSep(Graph graph, boolean keepLatents) { this.observedVars = new ArrayList<>(_observedVars); } + /** + * Constructor. + * + * @param facts Independence facts to be used for direct calculations of + * d-separation. + * @param keepLatents Whether latent in the graph should be used in conditional + * independence facts. If the graph is being marginalized, + * this should be false. + * @see IndependenceFacts + */ public IndTestDSep(IndependenceFacts facts, boolean keepLatents) { if (facts == null) { throw new NullPointerException(); @@ -96,7 +137,7 @@ public IndTestDSep(IndependenceFacts facts, boolean keepLatents) { } /** - * Required by IndependenceTest. + * Returns a test over a buset of the variables. */ public IndependenceTest indTestSubset(List vars) { if (vars.isEmpty()) { @@ -125,7 +166,7 @@ public IndependenceTest indTestSubset(List vars) { } /** - * @return the list of observed nodes in the given graph. + * @return the list of observed varialbes in the given graph. */ private List calcVars(List nodes, boolean keepLatents) { if (keepLatents) { @@ -145,8 +186,6 @@ private List calcVars(List nodes, boolean keepLatents) { return _nodes; } - - } /** @@ -155,7 +194,7 @@ private List calcVars(List nodes, boolean keepLatents) { * @param x one node. * @param y a second node. * @param z a List of nodes (conditioning variables) - * @return true iff x _||_ y | z + * @return True iff x _||_ y | z */ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (z == null) { @@ -215,7 +254,8 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * Auxiliary method to calculate dseparation facts directly from nodes instead of from variables. + * Auxiliary method to calculate dseparation facts directly from nodes instead + * of from variables. */ public boolean isDSeparated(Node x, Node y, List z) { if (z == null) { @@ -239,26 +279,48 @@ public double getPValue() { } /** - * @return the list of TetradNodes over which this independence checker is capable of determinine independence - * relations-- that is, all the variables in the given graph or the given data set. + * @return the list of TetradNodes over which this independence checker is capable + * of determinine independence relations-- that is, all the variables in the given + * graph or the given data set. */ public List getVariables() { return Collections.unmodifiableList(_observedVars); } - + /** + * We're assuming faithfuless (i.e., calculating d-separation facts), so is markes + * no sense to give judgments of determination of a varialbe by a set of variables. + * + * @throws UnsupportedOperationException Since this method is not feasible. + */ public boolean determines(List z, Node x1) { - return false; + throw new UnsupportedOperationException("The 'determines' method is not implemented") } + /** + * Returns an alpha level, 0.5. + * + * @return 0.5. + */ public double getAlpha() { return 0.5; } + /** + * @throws UnsupportedOperationException it makes no sense to set an alpha level + * for a d-separation test. + */ public void setAlpha(double alpha) { - // + throw new UnsupportedOperationException("Method mot implemented. What were you thinking?" + + "This is a d-separation method."); } + /** + * Returns the variable with the given name. + * + * @param name The name. + * @return The variable. + */ public Node getVariable(String name) { for (Node variable : observedVars) { if (variable.getName().equals(name)) { @@ -276,37 +338,44 @@ public Graph getGraph() { return this.graph; } - public void setGraph(Graph graph) { - this.graph = graph; - } - + /** + * Returns a string representation of this test. + * + * @return "D-separation". + */ public String toString() { return "D-separation"; } + /** + * @throws UnsupportedOperationException Method doesn't make sense here. + */ public DataSet getData() { throw new UnsupportedOperationException("This is a d-separation test, no data available."); } - + /** + * @return 1 for d-connections, -1 for d-separations + */ @Override public double getScore() { return getPValue() == 1 ? -1 : 1; } - public List getFacts() { - return facts; - } - + /** + * @return True just in case verbose output should be printed. + */ public boolean isVerbose() { return verbose; } + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } - - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java index 7101682bdc..e4fb09e1d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java @@ -41,8 +41,8 @@ import static org.apache.commons.math3.util.FastMath.sqrt; /** - * Checks conditional independence of variable in a continuous data set using Fisher's Z test. See Spirtes, Glymour, and - * Scheines, "Causation, Prediction and Search," 2nd edition, page 94. + * Checks conditional independence of variable in a continuous data set using Fisher's Z test. + * See Spirtes, Glymour, and Scheines, "Causation, Prediction and Search," 2nd edition, page 94. * * @author Joseph Ramsey * @author Frank Wimberly From 7c54c29e93d427100e662040ef2532a2be12f9dc Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 19:58:53 -0400 Subject: [PATCH 241/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java index dcf59ac8e7..321754dfd6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java @@ -294,7 +294,7 @@ public List getVariables() { * @throws UnsupportedOperationException Since this method is not feasible. */ public boolean determines(List z, Node x1) { - throw new UnsupportedOperationException("The 'determines' method is not implemented") + throw new UnsupportedOperationException("The 'determines' method is not implemented"); } /** From a7e04ef32f0fb35388ad3ed466637bafea6addc7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 20:26:12 -0400 Subject: [PATCH 242/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/IndTestDSep.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java index 321754dfd6..d27947889f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java @@ -311,8 +311,7 @@ public double getAlpha() { * for a d-separation test. */ public void setAlpha(double alpha) { - throw new UnsupportedOperationException("Method mot implemented. What were you thinking?" + - "This is a d-separation method."); + throw new UnsupportedOperationException("Method mot implemented."); } /** From 45e16589da6af22010ecd34a87933da4a7507cd6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 20:44:32 -0400 Subject: [PATCH 243/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/IndTestDSep.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java index d27947889f..b9cdd44753 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java @@ -53,7 +53,6 @@ public class IndTestDSep implements IndependenceTest { */ private List observedVars; private List _observedVars; - private List facts; private boolean verbose = false; private double pvalue = 0; @@ -160,8 +159,6 @@ public IndependenceTest indTestSubset(List vars) { this._observedVars = _vars; this.observedVars = new ArrayList<>(_observedVars); - facts = new ArrayList<>(); - return this; } @@ -174,16 +171,6 @@ private List calcVars(List nodes, boolean keepLatents) { } else { List _nodes = new ArrayList<>(nodes); _nodes.removeIf(node -> node.getNodeType() == NodeType.LATENT); - - -// List observedVars = new ArrayList<>(); -// -// for (Node node : nodes) { -// if (node.getNodeType() == NodeType.MEASURED) { -// observedVars.add(node); -// } -// } - return _nodes; } } @@ -239,10 +226,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { double pValue; if (dSeparated) { - if (this.facts != null) { - this.facts.add(new IndependenceFact(x, y, z)); - } - pValue = 1.0; } else { pValue = 0.0; From 1908ed3ceddabe2924d6a19b520ddecdabeb594a Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Thu, 4 May 2023 20:45:08 -0500 Subject: [PATCH 244/464] added descriptions for the grasps depth setters --- .../src/main/java/edu/cmu/tetrad/search/Grasp.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 c1a85d1357..94ffb1a81c 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 @@ -230,7 +230,8 @@ public void setKnowledge(Knowledge knowledge) { } /** - * Sets the depth of ??? (Bryan cnan you document this?) + * Sets the maximum depth of the depth first search that GRaSP perform while + * searching for a weakly increasing tuck sequence that improves the score. * * @param depth This depth. */ @@ -240,7 +241,8 @@ public void setDepth(int depth) { } /** - * Sets the depth of ??? (Bryan cnan you document this?) + * Sets the maximum depth at which uncovered tucks can be performed within + * the depth first search of GRaSP. * * @param uncoveredDepth This depth. */ @@ -250,7 +252,8 @@ public void setSingularDepth(int uncoveredDepth) { } /** - * Sets the depth of ??? (Bryan cnan you document this?) + * Sets the maximum depth at which singular tucks can be performed within + * the depth first search of GRaSP. * * @param nonSingularDepth This depth. */ From 8262b28207219d199f95e47049921b53388985e7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 21:52:04 -0400 Subject: [PATCH 245/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/algcomparison/algorithm/oracle/cpdag/Grasp.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/GraspFci.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) 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 index 41da455c77..b809b422d3 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 @@ -75,7 +75,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { edu.cmu.tetrad.search.Grasp grasp = new edu.cmu.tetrad.search.Grasp(test, score); grasp.setDepth(parameters.getInt(Params.GRASP_DEPTH)); - grasp.setSingularDepth(parameters.getInt(Params.GRASP_SINGULAR_DEPTH)); + grasp.setUncoveredDepth(parameters.getInt(Params.GRASP_SINGULAR_DEPTH)); grasp.setNonSingularDepth(parameters.getInt(Params.GRASP_NONSINGULAR_DEPTH)); grasp.setOrdered(parameters.getBoolean(Params.GRASP_ORDERED_ALG)); grasp.setUseScore(parameters.getBoolean(Params.GRASP_USE_SCORE)); 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 94ffb1a81c..2e260193c8 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 @@ -246,7 +246,7 @@ public void setDepth(int depth) { * * @param uncoveredDepth This depth. */ - public void setSingularDepth(int uncoveredDepth) { + public void setUncoveredDepth(int uncoveredDepth) { if (uncoveredDepth < -1) throw new IllegalArgumentException("Uncovered depth should be >= -1."); this.uncoveredDepth = uncoveredDepth; } 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 745460d5b7..187edd1fee 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 @@ -124,7 +124,7 @@ public Graph search() { alg.setUseRaskuttiUhler(useRaskuttiUhler); alg.setUseDataOrder(useDataOrder); alg.setDepth(graspDepth); - alg.setSingularDepth(uncoveredDepth); + alg.setUncoveredDepth(uncoveredDepth); alg.setNonSingularDepth(nonSingularDepth); alg.setNumStarts(numStarts); alg.setVerbose(verbose); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 28418b27f1..433b8dc132 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -1371,7 +1371,7 @@ public void bryanCheckDensityClaims() { edu.cmu.tetrad.search.Grasp boss = new edu.cmu.tetrad.search.Grasp(test, new GraphScore(facts)); boss.setNonSingularDepth(1); - boss.setSingularDepth(1); + boss.setUncoveredDepth(1); // OtherPermAlgs spAlg = new OtherPermAlgs(test); // spAlg.setUsePearl(true); @@ -1395,7 +1395,7 @@ public void bryanCheckDensityClaims() { edu.cmu.tetrad.search.Grasp grasp = new edu.cmu.tetrad.search.Grasp(test); grasp.setDepth(3); - grasp.setSingularDepth(1); + grasp.setUncoveredDepth(1); grasp.setNonSingularDepth(1); grasp.setUseRaskuttiUhler(usePearl); grasp.setOrdered(true); @@ -2964,7 +2964,7 @@ public void test7Examples() { edu.cmu.tetrad.search.Grasp search = new edu.cmu.tetrad.search.Grasp(new IndTestDSep(facts.getFacts())); search.setDepth(depth); - search.setSingularDepth(depth); + search.setUncoveredDepth(depth); search.setNonSingularDepth(depth); search.setUseRaskuttiUhler(false); List order = search.bestOrder(p); From 2220be274b98fa67b45c532755fbcaee165fede5 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Thu, 4 May 2023 21:51:32 -0500 Subject: [PATCH 246/464] added descriptions for gst methods --- .../edu/cmu/tetrad/search/GrowShrinkTree.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) 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 7796276992..5115eef57a 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 @@ -21,6 +21,13 @@ public class GrowShrinkTree { private List forbidden; private GSTNode root; + /** + * Constructor for a grow-shrink tree. + * + * @param score A score. + * @param index A node-index map. + * @param node The root node. + */ public GrowShrinkTree(Score score, Map index, Node node) { this.score = score; this.index = index; @@ -31,46 +38,108 @@ public GrowShrinkTree(Score score, Map index, Node node) { this.forbidden = new ArrayList<>(); } + /** + * Trace down the tree and updates parents. + * + * @param prefix The prefix (mutated during call). + * @param parents The parents (modified in place). + * @return The grow-shrink score. + */ public double trace(Set prefix, Set parents) { return this.root.trace(prefix, parents); } + /** + * Gets the root node. + * + * @return The root node. + */ public Node getNode() { return this.node; } + /** + * Gets the index of a node. + * + * @param node The node. + * @return The index. + */ public Integer getIndex(Node node) { return this.index.get(node); } + /** + * Wraps the localScore call of the score. + * + * @return The value return by the score. + */ public Double localScore() { return this.score.localScore(this.nodeIndex); } + /** + * Wraps the localScore call of the score. + * + * @param X The parents. + * @return The value return by the score. + */ public Double localScore(int[] X) { return this.score.localScore(this.nodeIndex, X); } + /** + * True if node is a required parent. + * + * @param node The node. + * @return The boolean. + */ public boolean isRequired(Node node) { return this.required.contains(node); } + /** + * True if node is a forbidden parent. + * + * @param node The node. + * @return The boolean. + */ public boolean isForbidden(Node node) { return this.forbidden.contains(node); } + /** + * Gets the list of variables. + * + * @return The list of variables. + */ public List getVariables() { return this.score.getVariables(); } + /** + * Gets the list of required parents. + * + * @return The list of required parents. + */ public List getRequired() { return this.required; } + /** + * Gets the list of forbidden parents. + * + * @return The list of forbidden parents. + */ public List getForbidden() { return this.forbidden; } + /** + * Sets the background knowledge. + * + * @param required A list of required parents. + * @param forbidden A list of forbidden parents. + */ public void setKnowledge(List required, List forbidden) { this.root = new GSTNode(this); this.required = required; From 0a25bd93377c0ba09523d4db5d20a4caafc21f75 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 23:29:48 -0400 Subject: [PATCH 247/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/GSquareTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 b013ac0d7e..07fda86a38 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 @@ -33,8 +33,9 @@ import java.util.List; /** - * Performs conditional independence tests of discrete data using the G Square method. Degrees of freedom are calculated - * as in Fienberg, The Analysis of Cross-Classified Categorical Data, 2nd Edition, 142. + * Performs conditional independence tests of discrete data using the G Square method. + * Degrees of freedom are calculated as in Fienberg, The Analysis of Cross-Classified + * Categorical Data, 2nd Edition, 142. * * @author Frank Wimberly original version * @author Joseph Ramsey revision 10/01 From 71c941f8da732705409df82d190f659f33c2d4c9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 23:30:45 -0400 Subject: [PATCH 248/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java index a0388e7501..0f606c462a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java @@ -8,7 +8,7 @@ *

An implemetation of the Kuhn–Munkres assignment algorithm of the year 1957. * https://en.wikipedia.org/wiki/Hungarian_algorithm.

*

From: https://github.com/aalmi/HungarianAlgorithm

- *

This is not our code code; please see the references given. We've just + *

This is not our code; please see the references given. We've just * made a few tweaks to make it work better in Tetrad. Thanks aalmi.

* * @author https://github.com/aalmi | march 2014 From 08ef7441a99b38472df2db227a2ed421875fe178 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 4 May 2023 23:31:27 -0400 Subject: [PATCH 249/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java index 0f606c462a..3923e81f22 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java @@ -6,12 +6,12 @@ /** *

An implemetation of the Kuhn–Munkres assignment algorithm of the year 1957. - * https://en.wikipedia.org/wiki/Hungarian_algorithm.

+ * ....

*

From: https://github.com/aalmi/HungarianAlgorithm

*

This is not our code; please see the references given. We've just * made a few tweaks to make it work better in Tetrad. Thanks aalmi.

* - * @author https://github.com/aalmi | march 2014 + * @author ... | march 2014 * @version 1.0 */ public class HungarianAlgorithm { From 005b635902ccd3baa91070e7e6b841451bf99205 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 00:47:25 -0400 Subject: [PATCH 250/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../search/IndTestConditionalGaussianLrt.java | 9 +- .../search/IndTestDegenerateGaussianLrt.java | 85 ++++++++++++------- .../main/java/edu/cmu/tetrad/search/Lofs.java | 14 +-- 3 files changed, 67 insertions(+), 41 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java index ec530910d4..dffa828c3d 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java @@ -57,6 +57,13 @@ public class IndTestConditionalGaussianLrt implements IndependenceTest { private boolean verbose; private int numCategoriesToDiscretize = 3; + /** + * Consstructor. + * + * @param data The data to analyze. + * @param alpha The signifcance level. + * @param discretize Whether discrete children of continuous parents should be discretized. + */ public IndTestConditionalGaussianLrt(DataSet data, double alpha, boolean discretize) { this.data = data; this.likelihood = new ConditionalGaussianLikelihood(data); @@ -157,7 +164,6 @@ public List getVariables() { return new ArrayList<>(this.data.getVariables()); } - /** * @return true if y is determined the variable in z. */ @@ -189,7 +195,6 @@ public DataSet getData() { return this.data; } - /** * Returns a number that is higher for stronger judgments of dependence * and negative for judgments of independence. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java index b5dc6f0505..0d0e5a5fc3 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java @@ -99,6 +99,8 @@ public String toString() { /** * Constructs the score using a covariance matrix. + * + * @param dataSet The data being analyzed. */ public IndTestDegenerateGaussianLrt(DataSet dataSet) { if (dataSet == null) { @@ -189,38 +191,9 @@ public IndTestDegenerateGaussianLrt(DataSet dataSet) { this._ddata = this.ddata.getDoubleData().toArray(); } - /** - * Calculates the sample log likelihood - */ - private Ret getlldof(List rows, int i, int... parents) { - int N = rows.size(); - - List B = new ArrayList<>(); - List A = new ArrayList<>(this.embedding.get(i)); - for (int i_ : parents) { - B.addAll(this.embedding.get(i_)); - } - - int[] A_ = new int[A.size() + B.size()]; - int[] B_ = new int[B.size()]; - for (int i_ = 0; i_ < A.size(); i_++) { - A_[i_] = A.get(i_); - } - for (int i_ = 0; i_ < B.size(); i_++) { - A_[A.size() + i_] = B.get(i_); - B_[i_] = B.get(i_); - } - - double dof = (A_.length * (A_.length + 1) - B_.length * (B_.length + 1)) / 2.0; - double ldetA = log(getCov(rows, A_).det()); - double ldetB = log(getCov(rows, B_).det()); - - double lik = N * (ldetB - ldetA) + IndTestDegenerateGaussianLrt.L2PE * (B_.length - A_.length); - - return new Ret(lik, dof); - } /** + * @param vars A sublist of the dataset variables. * @return an Independence test for a subset of the searchVariables. */ public IndependenceTest indTestSubset(List vars) { @@ -228,7 +201,7 @@ public IndependenceTest indTestSubset(List vars) { } /** - * @return true if the given independence question is judged true, false if not. The independence question is of the + * @return True if the given independence question is judged true, False if not. The independence question is of the * form x _||_ y | z, z = [z1,...,zn], where x, y, z1,...,zn are searchVariables in the list returned by * getVariableNames(). */ @@ -312,7 +285,6 @@ public List getVariables() { return new ArrayList<>(this.variables); } - /** * @return true if y is determined the variable in z. */ @@ -335,11 +307,20 @@ public void setAlpha(double alpha) { this.alpha = alpha; } + /** + * @return The dataset being analyzed. + */ public DataSet getData() { return this.dataSet; } + /** + * Returns a value that more positive for stronger dependence and positive + * only if dependence holds. + * @return This value. + * @see Fges + */ @Override public double getScore() { return getAlpha() - getPValue(); @@ -353,16 +334,56 @@ public String toString() { return "Degenerate Gaussian, alpha = " + nf.format(getAlpha()); } + /** + * Returns true iff verbose output should be printed. + * @return True if so. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; } + + /** + * Calculates the sample log likelihood + */ + private Ret getlldof(List rows, int i, int... parents) { + int N = rows.size(); + + List B = new ArrayList<>(); + List A = new ArrayList<>(this.embedding.get(i)); + for (int i_ : parents) { + B.addAll(this.embedding.get(i_)); + } + + int[] A_ = new int[A.size() + B.size()]; + int[] B_ = new int[B.size()]; + for (int i_ = 0; i_ < A.size(); i_++) { + A_[i_] = A.get(i_); + } + for (int i_ = 0; i_ < B.size(); i_++) { + A_[A.size() + i_] = B.get(i_); + B_[i_] = B.get(i_); + } + + double dof = (A_.length * (A_.length + 1) - B_.length * (B_.length + 1)) / 2.0; + double ldetA = log(getCov(rows, A_).det()); + double ldetB = log(getCov(rows, B_).det()); + + double lik = N * (ldetB - ldetA) + IndTestDegenerateGaussianLrt.L2PE * (B_.length - A_.length); + + return new Ret(lik, dof); + } + private List getRows(List allVars, Map nodesHash) { List rows = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index e39c0711fd..6b29bf1474 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -41,7 +41,7 @@ * @author Joseph Ramsey */ public class Lofs { - private final Graph CPDAG; + private final Graph cpdag; private final List dataSets; private double alpha = 0.05; private final ArrayList regressions; @@ -59,13 +59,13 @@ public enum Score { //===============================CONSTRUCTOR============================// - public Lofs(Graph CPDAG, List dataSets, boolean strongR2, boolean meekDone, boolean meanCenterResiduals) + public Lofs(Graph cpdag, List dataSets, boolean strongR2, boolean meekDone, boolean meanCenterResiduals) throws IllegalArgumentException { this.strongR2 = strongR2; this.meekDone = meekDone; this.meanCenterResiduals = meanCenterResiduals; - if (CPDAG == null) { + if (cpdag == null) { throw new IllegalArgumentException("CPDAG must be specified."); } @@ -73,7 +73,7 @@ public Lofs(Graph CPDAG, List dataSets, boolean strongR2, boolean meekD throw new IllegalArgumentException("Data set must be specified."); } - this.CPDAG = CPDAG; + this.cpdag = cpdag; this.dataSets = dataSets; this.regressions = new ArrayList<>(); @@ -85,7 +85,7 @@ public Lofs(Graph CPDAG, List dataSets, boolean strongR2, boolean meekD } public Graph orient() { - Graph skeleton = GraphUtils.undirectedGraph(getCPDAG()); + Graph skeleton = GraphUtils.undirectedGraph(getCpdag()); Graph graph = new EdgeListGraph(skeleton.getNodes()); List nodes = skeleton.getNodes(); @@ -617,8 +617,8 @@ public void setAlpha(double alpha) { this.alpha = alpha; } - private Graph getCPDAG() { - return this.CPDAG; + private Graph getCpdag() { + return this.cpdag; } private Node getVariable(List variables, String name) { From d90a4bacd3dce8a487ca7d73e365346935e87fae Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 00:49:19 -0400 Subject: [PATCH 251/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java | 1 - .../java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java index b9cdd44753..561d359304 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java @@ -81,7 +81,6 @@ public IndTestDSep(IndependenceFacts facts, List variables) { facts.setNodes(variables); } - /** * Constructor. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java index 4fe4cecdc8..58d2bf8988 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java @@ -48,7 +48,6 @@ public final class IndTestFisherZFisherPValue implements IndependenceTest { private double alpha; private double pValue = Double.NaN; private final int[] rows; - // private List data; private final List ncov; private final Map variablesMap; private double percent = .5; @@ -104,7 +103,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { Matrix _ncov = iCovarianceMatrix.getSelection(all, all); Matrix inv = _ncov.inverse(); double r = -inv.get(0, 1) / sqrt(inv.get(0, 0) * inv.get(1, 1)); -// r *= 0.6; double _z = sqrt(this.sampleSize - z.size() - 3.0) * 0.5 * (log(1.0 + r) - log(1.0 - r)); double pvalue = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(_z))); pValues.add(pvalue); From 55f04c72359bfbcd386faccfa4d3c196b5a25ade Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 00:52:58 -0400 Subject: [PATCH 252/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/DeltaSextadTest.java | 12 +- .../main/java/edu/cmu/tetrad/search/Ftfc.java | 26 +-- .../edu/cmu/tetrad/search/IndTestSepset.java | 3 +- .../edu/cmu/tetrad/search/IndTestTrekSep.java | 72 ++++---- .../java/edu/cmu/tetrad/search/IntSextad.java | 123 ------------- .../cmu/tetrad/search/PurifySextadBased.java | 74 ++++---- .../java/edu/cmu/tetrad/search/Sextad.java | 90 +++------ .../InverseCorrelation.java | 2 +- .../search/work_in_progress/Sextad.java | 171 ++++++++++++++++++ .../cmu/tetrad/test/TestDeltaSextadTest.java | 54 +++--- 10 files changed, 312 insertions(+), 315 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/IntSextad.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/InverseCorrelation.java (98%) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java index 78ea60a134..2f24fca059 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java @@ -112,7 +112,7 @@ public static DeltaSextadTest serializableInstance() { * @param sextads The sextads for which a p-value is needed. * @return The p-value. */ - public double getPValue(IntSextad... sextads) { + public double getPValue(Sextad... sextads) { int df = dofHarman(sextads.length); double chisq = calcChiSquare(sextads); double cdf = new ChiSquaredDistribution(df).cumulativeProbability(chisq); @@ -129,10 +129,10 @@ public double getPValue(IntSextad... sextads) { * @param sextads The sextads for which a chi-square is needed * @return The chi-square. */ - public double calcChiSquare(IntSextad[] sextads) { + public double calcChiSquare(Sextad[] sextads) { Set boldSigmaSet = new HashSet<>(); - for (IntSextad sextad : sextads) { + for (Sextad sextad : sextads) { List _nodes = sextad.getNodes(); for (int k1 = 0; k1 < 3; k1++) { @@ -195,7 +195,7 @@ public double calcChiSquare(IntSextad[] sextads) { Matrix del = new Matrix(boldSigma.size(), sextads.length); for (int j = 0; j < sextads.length; j++) { - IntSextad sextad = sextads[j]; + Sextad sextad = sextads[j]; for (int i = 0; i < boldSigma.size(); i++) { Sigma sigma = boldSigma.get(i); @@ -208,7 +208,7 @@ public double calcChiSquare(IntSextad[] sextads) { Matrix t = new Matrix(sextads.length, 1); for (int i = 0; i < sextads.length; i++) { - IntSextad sextad = sextads[i]; + Sextad sextad = sextads[i]; List nodes = sextad.getNodes(); Matrix m = new Matrix(3, 3); @@ -255,7 +255,7 @@ private double r(int i, int j) { } } - private double getDerivative(IntSextad sextad, Sigma sigma) { + private double getDerivative(Sextad sextad, Sigma sigma) { int a = sigma.getA(); int b = sigma.getB(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 896e4b4ad4..f376f809a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -1021,21 +1021,21 @@ private boolean zeroCorr(List cluster, int n) { } private boolean vanishes(int n1, int n2, int n3, int n4, int n5, int n6) { - IntSextad t1 = new IntSextad(n1, n2, n3, n4, n5, n6); - IntSextad t2 = new IntSextad(n1, n5, n6, n2, n3, n4); - IntSextad t3 = new IntSextad(n1, n4, n6, n2, n3, n5); - IntSextad t4 = new IntSextad(n1, n4, n5, n2, n3, n6); - IntSextad t5 = new IntSextad(n1, n3, n4, n2, n5, n6); - IntSextad t6 = new IntSextad(n1, n3, n5, n2, n4, n6); - IntSextad t7 = new IntSextad(n1, n3, n6, n2, n4, n5); - IntSextad t8 = new IntSextad(n1, n2, n4, n3, n5, n6); - IntSextad t9 = new IntSextad(n1, n2, n5, n3, n4, n6); - IntSextad t10 = new IntSextad(n1, n2, n6, n3, n4, n5); + Sextad t1 = new Sextad(n1, n2, n3, n4, n5, n6); + Sextad t2 = new Sextad(n1, n5, n6, n2, n3, n4); + Sextad t3 = new Sextad(n1, n4, n6, n2, n3, n5); + Sextad t4 = new Sextad(n1, n4, n5, n2, n3, n6); + Sextad t5 = new Sextad(n1, n3, n4, n2, n5, n6); + Sextad t6 = new Sextad(n1, n3, n5, n2, n4, n6); + Sextad t7 = new Sextad(n1, n3, n6, n2, n4, n5); + Sextad t8 = new Sextad(n1, n2, n4, n3, n5, n6); + Sextad t9 = new Sextad(n1, n2, n5, n3, n4, n6); + Sextad t10 = new Sextad(n1, n2, n6, n3, n4, n5); // IntSextad[] independents = {t2, t5, t10, t3, t6}; - List independents = new ArrayList<>(); - independents.add(new IntSextad[]{t1, t2, t3, t5, t6}); + List independents = new ArrayList<>(); + independents.add(new Sextad[]{t1, t2, t3, t5, t6}); // independents.add(new IntSextad[]{t1, t2, t3, t9, t10}); // independents.add(new IntSextad[]{t6, t7, t8, t9, t10}); // independents.add(new IntSextad[]{t1, t2, t4, t5, t9}); @@ -1046,7 +1046,7 @@ private boolean vanishes(int n1, int n2, int n3, int n4, int n5, int n6) { // The four sextads implied by equation 5.17 in Harmann. // independents.add(new IntSextad[]{t3, t7, t8, t9}); - for (IntSextad[] sextads : independents) { + for (Sextad[] sextads : independents) { double p = this.test.getPValue(sextads); if (Double.isNaN(p)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java index e1b4781685..957b3c57f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java @@ -34,7 +34,8 @@ /** - * Checks independence facts for variables associated associated with a sepset by simply querying the sepset + * Checks independence facts for variables associated with a sepset by simply + * querying the sepset * * @author Robert Tillman */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java index 397b480f58..a8e4d87647 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java @@ -197,7 +197,6 @@ public Node getVariable(String name) { return this.nameMap.get(name); } - /** * If isDeterminismAllowed(), deters to IndTestFisherZD; otherwise throws * UnsupportedOperationException. @@ -250,42 +249,6 @@ public String toString() { return "t-Separation test, alpha = " + IndTestTrekSep.nf.format(getAlpha()); } - //==========================PRIVATE METHODS============================// - - private int sampleSize() { - return covMatrix().getSampleSize(); - } - - private ICovarianceMatrix covMatrix() { - return this.covMatrix; - } - - private Map nameMap(List variables) { - Map nameMap = new ConcurrentHashMap<>(); - - for (Node node : variables) { - nameMap.put(node.getName(), node); - } - - return nameMap; - } - - private Map indexMap(List variables, List latents) { - Map indexMap = new ConcurrentHashMap<>(); - - int index = 0; - - for (Node variable : variables) { - indexMap.put(variable, index++); - } - - for (Node latent : latents) { - indexMap.put(latent, index++); - } - - return indexMap; - } - public void setVariables(List variables) { if (variables.size() != this.variables.size()) throw new IllegalArgumentException("Wrong # of variables."); this.variables = new ArrayList<>(variables); @@ -311,7 +274,6 @@ public int getSampleSize() { return this.covMatrix.getSampleSize(); } - @Override public double getScore() { return getPValue(); @@ -326,6 +288,40 @@ public boolean isVerbose() { public void setVerbose(boolean verbose) { this.verbose = verbose; } + + private int sampleSize() { + return covMatrix().getSampleSize(); + } + + private ICovarianceMatrix covMatrix() { + return this.covMatrix; + } + + private Map nameMap(List variables) { + Map nameMap = new ConcurrentHashMap<>(); + + for (Node node : variables) { + nameMap.put(node.getName(), node); + } + + return nameMap; + } + + private Map indexMap(List variables, List latents) { + Map indexMap = new ConcurrentHashMap<>(); + + int index = 0; + + for (Node variable : variables) { + indexMap.put(variable, index++); + } + + for (Node latent : latents) { + indexMap.put(latent, index++); + } + + return indexMap; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IntSextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IntSextad.java deleted file mode 100644 index e490feb393..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IntSextad.java +++ /dev/null @@ -1,123 +0,0 @@ -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.util.TetradSerializable; - -import java.util.ArrayList; -import java.util.List; - -public class IntSextad implements TetradSerializable { - static final long serialVersionUID = 23L; - - private final int i; - private final int j; - private final int k; - private final int l; - private final int m; - private final int n; - - public IntSextad(int i, int j, int k, int l, int m, int n) { - testDistinctness(i, j, k, l, m, n); - this.i = i; - this.j = j; - this.k = k; - this.l = l; - this.m = m; - this.n = n; - } - - /** - * Generates a simple exemplar of this class to test serialization. - */ - public static IntSextad serializableInstance() { - return new IntSextad(0, 1, 2, 3, 4, 5); - } - - - private void testDistinctness(int i, int j, int k, int l, int m, int n) { - if (i == j || i == k || i == l || i == m || i == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (j == k || j == l || j == m || j == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (k == l || k == m || k == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (l == m || l == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (m == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - } - - public int getI() { - return this.i; - } - - public int getJ() { - return this.j; - } - - public int getK() { - return this.k; - } - - public int getL() { - return this.l; - } - - public int getM() { - return this.m; - } - - public int getN() { - return this.n; - } - - public int hashCode() { - int hash = this.i * this.j * this.k; - hash += this.l * this.m * this.n; - return hash; - } - - public boolean equals(Object o) { - if (!(o instanceof IntSextad)) return false; - IntSextad sextad = (IntSextad) o; - - boolean leftEquals = this.i == sextad.i && this.j == sextad.j && this.k == sextad.k || - this.i == sextad.i && this.j == sextad.k && this.k == sextad.j || - this.i == sextad.j && this.j == sextad.i && this.k == sextad.k || - this.i == sextad.j && this.j == sextad.k && this.k == sextad.i || - this.i == sextad.k && this.j == sextad.i && this.k == sextad.j || - this.i == sextad.k && this.j == sextad.j && this.k == sextad.i; - - boolean rightEquals = this.l == sextad.l && this.m == sextad.m && this.n == sextad.n || - this.l == sextad.l && this.m == sextad.n && this.n == sextad.m || - this.l == sextad.m && this.m == sextad.l && this.n == sextad.n || - this.l == sextad.m && this.m == sextad.n && this.n == sextad.l || - this.l == sextad.n && this.m == sextad.l && this.n == sextad.m || - this.l == sextad.n && this.m == sextad.m && this.n == sextad.l; - - return leftEquals && rightEquals; - } - - public String toString() { - return "<" + this.i + ", " + this.j + ", " + this.k + "; " + this.l + ", " + this.m + ", " + this.n + ">"; - } - - public List getNodes() { - List nodes = new ArrayList<>(); - nodes.add(this.i); - nodes.add(this.j); - nodes.add(this.k); - nodes.add(this.l); - nodes.add(this.m); - nodes.add(this.n); - return nodes; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java index 182aee0fd4..105b475ad0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java @@ -74,13 +74,13 @@ public List> purify(List> clustering) { private List> combinedSearch(List> clustering) { Set eliminated = new HashSet<>(); - Set allImpurities = null; + Set allImpurities = null; double cutoff = this.alpha; int count = 0; for (List cluster : clustering) { System.out.println("Within cluster: " + ++count); - Set impurities = listSextads(cluster, eliminated, cutoff); + Set impurities = listSextads(cluster, eliminated, cutoff); if (impurities != null) { if (allImpurities == null) { @@ -90,7 +90,7 @@ private List> combinedSearch(List> clustering) { } } - Set impurities = listCrossConstructSextads(clustering, eliminated, cutoff); + Set impurities = listCrossConstructSextads(clustering, eliminated, cutoff); if (impurities != null) { if (allImpurities == null) { @@ -108,7 +108,7 @@ private List> combinedSearch(List> clustering) { while (true) { int max = 0; Integer maxNode = null; - Map> impuritiesPerNode = getImpuritiesPerNode(allImpurities, eliminated); + Map> impuritiesPerNode = getImpuritiesPerNode(allImpurities, eliminated); for (Integer node : this.nodes) { if (impuritiesPerNode.get(node).size() > max) { @@ -122,8 +122,8 @@ private List> combinedSearch(List> clustering) { double minP = Double.POSITIVE_INFINITY; double maxP = Double.NEGATIVE_INFINITY; - for (IntSextad IntSextad : impuritiesPerNode.get(maxNode)) { - double pValue = this.sextadTest.getPValue(IntSextad); + for (Sextad Sextad : impuritiesPerNode.get(maxNode)) { + double pValue = this.sextadTest.getPValue(Sextad); if (pValue < minP) { minP = pValue; @@ -143,50 +143,50 @@ private List> combinedSearch(List> clustering) { return buildSolution(clustering, eliminated); } - private Map> getImpuritiesPerNode(Set allImpurities, Set _eliminated) { - Map> impuritiesPerNode = new HashMap<>(); + private Map> getImpuritiesPerNode(Set allImpurities, Set _eliminated) { + Map> impuritiesPerNode = new HashMap<>(); for (Integer node : this.nodes) { impuritiesPerNode.put(node, new HashSet<>()); } - for (IntSextad IntSextad : allImpurities) { - if (_eliminated.contains(IntSextad.getI())) { + for (Sextad Sextad : allImpurities) { + if (_eliminated.contains(Sextad.getI())) { continue; } - if (_eliminated.contains(IntSextad.getJ())) { + if (_eliminated.contains(Sextad.getJ())) { continue; } - if (_eliminated.contains(IntSextad.getK())) { + if (_eliminated.contains(Sextad.getK())) { continue; } - if (_eliminated.contains(IntSextad.getL())) { + if (_eliminated.contains(Sextad.getL())) { continue; } - if (_eliminated.contains(IntSextad.getM())) { + if (_eliminated.contains(Sextad.getM())) { continue; } - if (_eliminated.contains(IntSextad.getN())) { + if (_eliminated.contains(Sextad.getN())) { continue; } - impuritiesPerNode.get(IntSextad.getI()).add(IntSextad); - impuritiesPerNode.get(IntSextad.getJ()).add(IntSextad); - impuritiesPerNode.get(IntSextad.getK()).add(IntSextad); - impuritiesPerNode.get(IntSextad.getL()).add(IntSextad); - impuritiesPerNode.get(IntSextad.getM()).add(IntSextad); - impuritiesPerNode.get(IntSextad.getN()).add(IntSextad); + impuritiesPerNode.get(Sextad.getI()).add(Sextad); + impuritiesPerNode.get(Sextad.getJ()).add(Sextad); + impuritiesPerNode.get(Sextad.getK()).add(Sextad); + impuritiesPerNode.get(Sextad.getL()).add(Sextad); + impuritiesPerNode.get(Sextad.getM()).add(Sextad); + impuritiesPerNode.get(Sextad.getN()).add(Sextad); } return impuritiesPerNode; } - private Set listCrossConstructSextads(List> clustering, Set eliminated, double cutoff) { - Set allSextads = new HashSet<>(); + private Set listCrossConstructSextads(List> clustering, Set eliminated, double cutoff) { + Set allSextads = new HashSet<>(); boolean countable = false; for (int p1 = 0; p1 < clustering.size(); p1++) { @@ -206,7 +206,7 @@ private Set listCrossConstructSextads(List> clustering, List crossCluster = new ArrayList<>(); for (int i : choice1) crossCluster.add(cluster1.get(i)); for (int i : choice2) crossCluster.add(cluster2.get(i)); - Set Sextads = listSextads(crossCluster, eliminated, cutoff); + Set Sextads = listSextads(crossCluster, eliminated, cutoff); if (Sextads != null) { countable = true; @@ -229,7 +229,7 @@ private Set listCrossConstructSextads(List> clustering, for (int i : choice1) crossCluster.add(cluster2.get(i)); for (int i : choice2) crossCluster.add(cluster1.get(i)); - Set Sextads = listSextads(crossCluster, eliminated, cutoff); + Set Sextads = listSextads(crossCluster, eliminated, cutoff); if (Sextads != null) { countable = true; @@ -246,12 +246,12 @@ private Set listCrossConstructSextads(List> clustering, } - private Set listSextads(List cluster, Set eliminated, double cutoff) { + private Set listSextads(List cluster, Set eliminated, double cutoff) { if (cluster.size() < 6) return null; cluster = new ArrayList<>(cluster); boolean countable = false; - Set Sextads = new HashSet<>(); + Set Sextads = new HashSet<>(); ChoiceGenerator gen = new ChoiceGenerator(cluster.size(), 6); int[] choice; @@ -287,16 +287,16 @@ private Set listSextads(List cluster, Set eliminate double p9; double p10; - IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6); - IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6); - IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6); - IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5); - IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6); - IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6); - IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5); - IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6); - IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5); - IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4); + Sextad t1 = new Sextad(m1, m2, m3, m4, m5, m6); + Sextad t2 = new Sextad(m1, m2, m4, m3, m5, m6); + Sextad t3 = new Sextad(m1, m2, m5, m3, m4, m6); + Sextad t4 = new Sextad(m1, m2, m6, m3, m4, m5); + Sextad t5 = new Sextad(m1, m3, m4, m2, m5, m6); + Sextad t6 = new Sextad(m1, m3, m5, m2, m4, m6); + Sextad t7 = new Sextad(m1, m3, m6, m2, m4, m5); + Sextad t8 = new Sextad(m1, m4, m5, m2, m3, m6); + Sextad t9 = new Sextad(m1, m4, m6, m2, m3, m5); + Sextad t10 = new Sextad(m1, m5, m6, m2, m3, m4); p1 = this.sextadTest.getPValue(t1); p2 = this.sextadTest.getPValue(t2); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java index b54bf5048a..2e793d85d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java @@ -1,47 +1,21 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - package edu.cmu.tetrad.search; -import edu.cmu.tetrad.graph.GraphNode; -import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.TetradSerializable; import java.util.ArrayList; import java.util.List; -/** - * Represents an ordered sextad of variables. - */ public class Sextad implements TetradSerializable { static final long serialVersionUID = 23L; - private final Node i; - private final Node j; - private final Node k; - private final Node l; - private final Node m; - private final Node n; + private final int i; + private final int j; + private final int k; + private final int l; + private final int m; + private final int n; - public Sextad(Node i, Node j, Node k, Node l, Node m, Node n) { + public Sextad(int i, int j, int k, int l, int m, int n) { testDistinctness(i, j, k, l, m, n); this.i = i; this.j = j; @@ -51,34 +25,15 @@ public Sextad(Node i, Node j, Node k, Node l, Node m, Node n) { this.n = n; } - public Sextad(Node[] nodes) { - if (nodes.length != 6) throw new IllegalArgumentException("Must provide exactly 6 nodes."); - - this.i = nodes[0]; - this.j = nodes[1]; - this.k = nodes[2]; - this.l = nodes[3]; - this.m = nodes[4]; - this.n = nodes[5]; - - testDistinctness(this.i, this.j, this.k, this.l, this.m, this.n); - - } - /** * Generates a simple exemplar of this class to test serialization. */ public static Sextad serializableInstance() { - Node i = new GraphNode("i"); - Node j = new GraphNode("j"); - Node k = new GraphNode("k"); - Node l = new GraphNode("l"); - Node m = new GraphNode("m"); - Node n = new GraphNode("n"); - return new Sextad(i, j, k, l, m, n); + return new Sextad(0, 1, 2, 3, 4, 5); } - private void testDistinctness(Node i, Node j, Node k, Node l, Node m, Node n) { + + private void testDistinctness(int i, int j, int k, int l, int m, int n) { if (i == j || i == k || i == l || i == m || i == n) { throw new IllegalArgumentException("Nodes not distinct."); } @@ -100,39 +55,38 @@ private void testDistinctness(Node i, Node j, Node k, Node l, Node m, Node n) { } } - public Node getI() { + public int getI() { return this.i; } - public Node getJ() { + public int getJ() { return this.j; } - public Node getK() { + public int getK() { return this.k; } - public Node getL() { + public int getL() { return this.l; } - public Node getM() { + public int getM() { return this.m; } - public Node getN() { + public int getN() { return this.n; } public int hashCode() { - int hash = 17 * this.i.hashCode() * this.j.hashCode() * this.k.hashCode(); - hash += 29 * this.l.hashCode() * this.m.hashCode() * this.n.hashCode(); - + int hash = this.i * this.j * this.k; + hash += this.l * this.m * this.n; return hash; } public boolean equals(Object o) { - if (!(o instanceof Sextad)) throw new IllegalArgumentException(); + if (!(o instanceof Sextad)) return false; Sextad sextad = (Sextad) o; boolean leftEquals = this.i == sextad.i && this.j == sextad.j && this.k == sextad.k || @@ -156,8 +110,8 @@ public String toString() { return "<" + this.i + ", " + this.j + ", " + this.k + "; " + this.l + ", " + this.m + ", " + this.n + ">"; } - public List getNodes() { - List nodes = new ArrayList<>(); + public List getNodes() { + List nodes = new ArrayList<>(); nodes.add(this.i); nodes.add(this.j); nodes.add(this.k); @@ -167,5 +121,3 @@ public List getNodes() { return nodes; } } - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InverseCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/InverseCorrelation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java index 72823e7ceb..ed9cc40ae2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InverseCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java new file mode 100644 index 0000000000..876fa07f28 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java @@ -0,0 +1,171 @@ +/////////////////////////////////////////////////////////////////////////////// +// For information as to what this class does, see the Javadoc, below. // +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // +// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // +// Scheines, Joseph Ramsey, and Clark Glymour. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +/////////////////////////////////////////////////////////////////////////////// + +package edu.cmu.tetrad.search.work_in_progress; + +import edu.cmu.tetrad.graph.GraphNode; +import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.util.TetradSerializable; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents an ordered sextad of variables. + */ +public class Sextad implements TetradSerializable { + static final long serialVersionUID = 23L; + + private final Node i; + private final Node j; + private final Node k; + private final Node l; + private final Node m; + private final Node n; + + public Sextad(Node i, Node j, Node k, Node l, Node m, Node n) { + testDistinctness(i, j, k, l, m, n); + this.i = i; + this.j = j; + this.k = k; + this.l = l; + this.m = m; + this.n = n; + } + + public Sextad(Node[] nodes) { + if (nodes.length != 6) throw new IllegalArgumentException("Must provide exactly 6 nodes."); + + this.i = nodes[0]; + this.j = nodes[1]; + this.k = nodes[2]; + this.l = nodes[3]; + this.m = nodes[4]; + this.n = nodes[5]; + + testDistinctness(this.i, this.j, this.k, this.l, this.m, this.n); + + } + + /** + * Generates a simple exemplar of this class to test serialization. + */ + public static Sextad serializableInstance() { + Node i = new GraphNode("i"); + Node j = new GraphNode("j"); + Node k = new GraphNode("k"); + Node l = new GraphNode("l"); + Node m = new GraphNode("m"); + Node n = new GraphNode("n"); + return new Sextad(i, j, k, l, m, n); + } + + private void testDistinctness(Node i, Node j, Node k, Node l, Node m, Node n) { + if (i == j || i == k || i == l || i == m || i == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (j == k || j == l || j == m || j == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (k == l || k == m || k == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (l == m || l == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (m == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + } + + public Node getI() { + return this.i; + } + + public Node getJ() { + return this.j; + } + + public Node getK() { + return this.k; + } + + public Node getL() { + return this.l; + } + + public Node getM() { + return this.m; + } + + public Node getN() { + return this.n; + } + + public int hashCode() { + int hash = 17 * this.i.hashCode() * this.j.hashCode() * this.k.hashCode(); + hash += 29 * this.l.hashCode() * this.m.hashCode() * this.n.hashCode(); + + return hash; + } + + public boolean equals(Object o) { + if (!(o instanceof Sextad)) throw new IllegalArgumentException(); + Sextad sextad = (Sextad) o; + + boolean leftEquals = this.i == sextad.i && this.j == sextad.j && this.k == sextad.k || + this.i == sextad.i && this.j == sextad.k && this.k == sextad.j || + this.i == sextad.j && this.j == sextad.i && this.k == sextad.k || + this.i == sextad.j && this.j == sextad.k && this.k == sextad.i || + this.i == sextad.k && this.j == sextad.i && this.k == sextad.j || + this.i == sextad.k && this.j == sextad.j && this.k == sextad.i; + + boolean rightEquals = this.l == sextad.l && this.m == sextad.m && this.n == sextad.n || + this.l == sextad.l && this.m == sextad.n && this.n == sextad.m || + this.l == sextad.m && this.m == sextad.l && this.n == sextad.n || + this.l == sextad.m && this.m == sextad.n && this.n == sextad.l || + this.l == sextad.n && this.m == sextad.l && this.n == sextad.m || + this.l == sextad.n && this.m == sextad.m && this.n == sextad.l; + + return leftEquals && rightEquals; + } + + public String toString() { + return "<" + this.i + ", " + this.j + ", " + this.k + "; " + this.l + ", " + this.m + ", " + this.n + ">"; + } + + public List getNodes() { + List nodes = new ArrayList<>(); + nodes.add(this.i); + nodes.add(this.j); + nodes.add(this.k); + nodes.add(this.l); + nodes.add(this.m); + nodes.add(this.n); + return nodes; + } +} + + diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java index 01b53594bd..b379c0a075 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.DeltaSextadTest; -import edu.cmu.tetrad.search.IntSextad; +import edu.cmu.tetrad.search.Sextad; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -66,18 +66,18 @@ public void testBollenExample1() { final int m5 = 4; final int m6 = 5; - IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6); - IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6); - IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6); - IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5); - IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6); - IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6); - IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5); - IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6); - IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5); - IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4); + Sextad t1 = new Sextad(m1, m2, m3, m4, m5, m6); + Sextad t2 = new Sextad(m1, m2, m4, m3, m5, m6); + Sextad t3 = new Sextad(m1, m2, m5, m3, m4, m6); + Sextad t4 = new Sextad(m1, m2, m6, m3, m4, m5); + Sextad t5 = new Sextad(m1, m3, m4, m2, m5, m6); + Sextad t6 = new Sextad(m1, m3, m5, m2, m4, m6); + Sextad t7 = new Sextad(m1, m3, m6, m2, m4, m5); + Sextad t8 = new Sextad(m1, m4, m5, m2, m3, m6); + Sextad t9 = new Sextad(m1, m4, m6, m2, m3, m5); + Sextad t10 = new Sextad(m1, m5, m6, m2, m3, m4); - List sextads = new ArrayList<>(); + List sextads = new ArrayList<>(); sextads.add(t1); sextads.add(t2); @@ -100,7 +100,7 @@ public void testBollenExample1() { int[] choice; while ((choice = gen.next()) != null) { - IntSextad[] _sextads = new IntSextad[numSextads]; + Sextad[] _sextads = new Sextad[numSextads]; for (int i = 0; i < numSextads; i++) { _sextads[i] = sextads.get(choice[i]); @@ -130,24 +130,24 @@ public void testBollenExampleb() { final int m5 = 4; final int m6 = 5; - IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6); - IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6); - IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6); - IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5); - IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6); - IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6); - IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5); - IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6); - IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5); - IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4); + Sextad t1 = new Sextad(m1, m2, m3, m4, m5, m6); + Sextad t2 = new Sextad(m1, m2, m4, m3, m5, m6); + Sextad t3 = new Sextad(m1, m2, m5, m3, m4, m6); + Sextad t4 = new Sextad(m1, m2, m6, m3, m4, m5); + Sextad t5 = new Sextad(m1, m3, m4, m2, m5, m6); + Sextad t6 = new Sextad(m1, m3, m5, m2, m4, m6); + Sextad t7 = new Sextad(m1, m3, m6, m2, m4, m5); + Sextad t8 = new Sextad(m1, m4, m5, m2, m3, m6); + Sextad t9 = new Sextad(m1, m4, m6, m2, m3, m5); + Sextad t10 = new Sextad(m1, m5, m6, m2, m3, m4); DeltaSextadTest test = new DeltaSextadTest(data); - IntSextad[] _sextads = {t2, t5, t10, t3, t6}; + Sextad[] _sextads = {t2, t5, t10, t3, t6}; double p = test.getPValue(_sextads); assertEquals(0.21, p, 0.01); - _sextads = new IntSextad[]{t10}; + _sextads = new Sextad[]{t10}; p = test.getPValue(_sextads); assertEquals(0.30, p, 0.01); @@ -236,8 +236,8 @@ public void test2() { DeltaSextadTest test = new DeltaSextadTest(data); // Should be invariant to changes or order of the first three or of the last three variables. - double a = test.getPValue(new IntSextad(x1, x2, x3, x4, x5, x6)); - double b = test.getPValue(new IntSextad(x2, x3, x1, x5, x4, x6)); + double a = test.getPValue(new Sextad(x1, x2, x3, x4, x5, x6)); + double b = test.getPValue(new Sextad(x2, x3, x1, x5, x4, x6)); assertEquals(a, b, 1e-7); } From 26f53b9090196aa41c4044b8954a3f3b22062c6b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 00:53:35 -0400 Subject: [PATCH 253/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/algcomparison/independence/Mvplrt.java | 4 ++-- .../tetrad/search/{IndTestMvplrt.java => IndTestMvpLrt.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IndTestMvplrt.java => IndTestMvpLrt.java} (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java index d6178bde12..3152f3ea03 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestMvplrt; +import edu.cmu.tetrad.search.IndTestMvpLrt; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; @@ -29,7 +29,7 @@ public class Mvplrt implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - return new IndTestMvplrt(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha"), parameters.getInt("fDegree"), parameters.getInt("discretize") > 0); + return new IndTestMvpLrt(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha"), parameters.getInt("fDegree"), parameters.getInt("discretize") > 0); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvplrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvplrt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java index 1bd1d772a2..b758ea9b37 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvplrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java @@ -38,7 +38,7 @@ * * @author Bryan Andrews */ -public class IndTestMvplrt implements IndependenceTest { +public class IndTestMvpLrt implements IndependenceTest { private final DataSet data; private final Map nodesHash; private double alpha; @@ -51,7 +51,7 @@ public class IndTestMvplrt implements IndependenceTest { // P Values private double pValue = Double.NaN; - public IndTestMvplrt(DataSet data, double alpha, int fDegree, boolean discretize) { + public IndTestMvpLrt(DataSet data, double alpha, int fDegree, boolean discretize) { this.data = data; this.likelihood = new MvpLikelihood(data, -1, fDegree, discretize); From 27e19731d8441b2cb23fa9535d21b40c12c65c0a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 00:55:04 -0400 Subject: [PATCH 254/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Kci.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java index d789d5f077..4d499f4b3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java @@ -370,7 +370,15 @@ public void setEpsilon(double epsilon) { this.epsilon = epsilon; } - //====================================PRIVATE METHODS==================================// + @Override + public boolean isVerbose() { + return this.verbose; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } /** * KCI independence for the unconditional case. Uses Theorem 4 from the paper. @@ -658,16 +666,6 @@ private double distance(double[][] data, List cols, int i, int j) { return sum; } - @Override - public boolean isVerbose() { - return this.verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - private class Eigendecomposition { private final Matrix k; private Matrix D; From 120393e85ae7ee8493268758c3af3f1220560706 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 01:01:36 -0400 Subject: [PATCH 255/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java index 2b4a26edf3..8beaed2a9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java @@ -187,9 +187,6 @@ private double getLambda(int m0, int pn) { return lambdas.get(m0); } - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ public ICovarianceMatrix getCovariances() { return covariances; } From fd925be4c84d4c4967917cb668a2f146e9626da9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 01:03:16 -0400 Subject: [PATCH 256/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 e5595c80d0..8df5a773b5 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 @@ -34,10 +34,10 @@ import java.util.Set; /** - * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested - * locally. + * Common implementation of variaous PC-like algorithms, with options for + * collider discovery type, FAS type, and conflict rule. * - * @author Joseph Ramsey (this version). + * @author josephramsey */ public final class PcAll implements GraphSearch { public enum FasType {REGULAR, STABLE} From 3723905050f5c37545e9fd99d9c7537a3a48673d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 14:43:15 -0400 Subject: [PATCH 257/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../IndTestFisherZConcatenateResiduals.java | 123 ++++++++++-------- 1 file changed, 71 insertions(+), 52 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java index 4589cbc8cc..6fa4b445f8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java @@ -65,10 +65,11 @@ public final class IndTestFisherZConcatenateResiduals implements IndependenceTes private double pValue = Double.NaN; private boolean verbose; -// private DataSet concatenatedData; - - //==========================CONSTRUCTORS=============================// - + /** + * Constructor. + * @param dataSets The continuous datasets to analyze. + * @param alpha The alpha significance cutoff value. + */ public IndTestFisherZConcatenateResiduals(List dataSets, double alpha) { System.out.println("# data sets = " + dataSets.size()); this.dataSets = dataSets; @@ -84,8 +85,6 @@ public IndTestFisherZConcatenateResiduals(List dataSets, double alpha) setAlpha(alpha); -// this.concatenatedData = DataUtils.concatenate(dataSets); - this.variables = dataSets.get(0).getVariables(); List dataSets2 = new ArrayList<>(); @@ -100,6 +99,9 @@ public IndTestFisherZConcatenateResiduals(List dataSets, double alpha) //==========================PUBLIC METHODS=============================// + /** + * @throws UnsupportedOperationException Not implemented. + */ public IndependenceTest indTestSubset(List vars) { throw new UnsupportedOperationException(); } @@ -110,7 +112,7 @@ public IndependenceTest indTestSubset(List vars) { * @param x the one variable being compared. * @param y the second variable being compared. * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. + * @return True iff x _||_ y | z. * @throws RuntimeException if a matrix singularity is encountered. */ public IndependenceResult checkIndependence(Node x, Node y, List z) { @@ -175,44 +177,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } - - private double[] residuals(Node node, List parents) { - List _residuals = new ArrayList<>(); - - Node target = this.dataSets.get(0).getVariable(node.getName()); - - List regressors = new ArrayList<>(); - - for (Node _regressor : parents) { - Node variable = this.dataSets.get(0).getVariable(_regressor.getName()); - regressors.add(variable); - } - - - for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - double[] residualsSingleDataset = result.getResiduals().toArray(); - - double mean = StatUtils.mean(residualsSingleDataset); - for (int i2 = 0; i2 < residualsSingleDataset.length; i2++) { - residualsSingleDataset[i2] = residualsSingleDataset[i2] - mean; - } - - for (double d : residualsSingleDataset) { - _residuals.add(d); - } - } - - double[] _f = new double[_residuals.size()]; - - - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); - } - - return _f; - } - private Node getVariable(List variables, String name) { for (Node node : variables) { if (name.equals(node.getName())) { @@ -260,18 +224,24 @@ public List getVariables() { } /** - * @return the variable with the given name. + * @throws UnsupportedOperationException Not implemented. */ - - - public boolean determines(List z, Node x) throws UnsupportedOperationException { + public boolean determines(List z, Node x) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * Returns the concatenated data. + * @return This data + */ public DataSet getData() { return DataUtils.concatenate(this.dataSets); } + /** + * Returns teh covaraince matrix of the concatenated data. + * @return This covariance matrix. + */ @Override public ICovarianceMatrix getCov() { List _dataSets = new ArrayList<>(); @@ -283,13 +253,16 @@ public ICovarianceMatrix getCov() { return new CovarianceMatrix(DataUtils.concatenate(_dataSets)); } - + /** + * Return a number that is positive when dependence holds and more positive + * for greater dependence. + * @return This number + * @see Fges + */ @Override public double getScore() { return -(getPValue() - getAlpha()); } - - /** * @return a string representation of this test. */ @@ -297,13 +270,59 @@ public String toString() { return "Fisher Z, Concatenating Residuals"; } + /** + * Return True if verbose output should be printed. + * @return True if so. + */ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output is printed. + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + + private double[] residuals(Node node, List parents) { + List _residuals = new ArrayList<>(); + + Node target = this.dataSets.get(0).getVariable(node.getName()); + + List regressors = new ArrayList<>(); + + for (Node _regressor : parents) { + Node variable = this.dataSets.get(0).getVariable(_regressor.getName()); + regressors.add(variable); + } + + + for (int m = 0; m < this.dataSets.size(); m++) { + RegressionResult result = this.regressions.get(m).regress(target, regressors); + double[] residualsSingleDataset = result.getResiduals().toArray(); + + double mean = StatUtils.mean(residualsSingleDataset); + for (int i2 = 0; i2 < residualsSingleDataset.length; i2++) { + residualsSingleDataset[i2] = residualsSingleDataset[i2] - mean; + } + + for (double d : residualsSingleDataset) { + _residuals.add(d); + } + } + + double[] _f = new double[_residuals.size()]; + + + for (int k = 0; k < _residuals.size(); k++) { + _f[k] = _residuals.get(k); + } + + return _f; + } + } From 3167d67f8aa48926e5bd101bc1a19dc48dc26e79 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 14:52:04 -0400 Subject: [PATCH 258/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../IndTestFisherZConcatenateResiduals.java | 3 +- .../search/IndTestFisherZFisherPValue.java | 72 +++++++++++-------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java index 6fa4b445f8..5887e862e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java @@ -97,8 +97,6 @@ public IndTestFisherZConcatenateResiduals(List dataSets, double alpha) this.dataSets = dataSets2; } - //==========================PUBLIC METHODS=============================// - /** * @throws UnsupportedOperationException Not implemented. */ @@ -263,6 +261,7 @@ public ICovarianceMatrix getCov() { public double getScore() { return -(getPValue() - getAlpha()); } + /** * @return a string representation of this test. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java index 58d2bf8988..948cb018dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java @@ -47,16 +47,17 @@ public final class IndTestFisherZFisherPValue implements IndependenceTest { private final List dataSets; private double alpha; private double pValue = Double.NaN; - private final int[] rows; private final List ncov; private final Map variablesMap; - private double percent = .5; - - private final List tests = new ArrayList<>(); private boolean verbose; //==========================CONSTRUCTORS=============================// + /** + * Constructor. + * @param dataSets The continuous datasets to analyze. + * @param alpha The alpha significance cutoff value. + */ public IndTestFisherZFisherPValue(List dataSets, double alpha) { this.sampleSize = dataSets.get(0).getNumRows(); @@ -67,9 +68,6 @@ public IndTestFisherZFisherPValue(List dataSets, double alpha) { this.ncov.add(new CovarianceMatrix(dataSet)); } - this.rows = new int[dataSets.get(0).getNumRows()]; - for (int i = 0; i < getRows().length; i++) getRows()[i] = i; - this.variables = dataSets.get(0).getVariables(); this.variablesMap = new HashMap<>(); for (int i = 0; i < this.variables.size(); i++) { @@ -77,18 +75,28 @@ public IndTestFisherZFisherPValue(List dataSets, double alpha) { } for (DataSet dataSet : dataSets) { - this.tests.add(new IndTestFisherZ(dataSet, alpha)); + ((List) new ArrayList()).add(new IndTestFisherZ(dataSet, alpha)); } this.dataSets = dataSets; } - //==========================PUBLIC METHODS=============================// - + /** + * @throws UnsupportedOperationException Not implemented. + */ public IndependenceTest indTestSubset(List vars) { throw new UnsupportedOperationException(); } + /** + * Determines whether variable x is independent of variable y given a list of conditioning variables z. + * + * @param x the one variable being compared. + * @param y the second variable being compared. + * @param z the list of conditioning variables. + * @return True iff x _||_ y | z. + * @throws RuntimeException if a matrix singularity is encountered. + */ public IndependenceResult checkIndependence(Node x, Node y, List z) { int[] all = new int[z.size() + 2]; all[0] = this.variablesMap.get(x); @@ -180,18 +188,24 @@ public List getVariables() { } /** - * @return the variable with the given name. + * @throws UnsupportedOperationException Not implemented. */ - - public boolean determines(List z, Node x) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * Returns the concatenated data. + * @return This data + */ public DataSet getData() { - return (DataSet) this.tests.get(0).getData(); + return DataUtils.concatenate(this.dataSets); } + /** + * Returns teh covaraince matrix of the concatenated data. + * @return This covariance matrix. + */ public ICovarianceMatrix getCov() { List _dataSets = new ArrayList<>(); @@ -202,7 +216,12 @@ public ICovarianceMatrix getCov() { return new CovarianceMatrix(DataUtils.concatenate(_dataSets)); } - + /** + * Return a number that is positive when dependence holds and more positive + * for greater dependence. + * @return This number + * @see Fges + */ @Override public double getScore() { return getPValue(); @@ -212,26 +231,21 @@ public double getScore() { * @return a string representation of this test. */ public String toString() { - return "Fisher Z, Fisher P Value Percent = " + round(this.percent * 100); - } - - public int[] getRows() { - return this.rows; - } - - public double getPercent() { - return this.percent; - } - - public void setPercent(double percent) { - if (percent < 0.0 || percent > 1.0) throw new IllegalArgumentException(); - this.percent = percent; + return "Fisher Z, Fisher P Value Percent = " + round(.5 * 100); } + /** + * Return True if verbose output should be printed. + * @return True if so. + */ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output is printed. + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } From 13f5c745a58fa43e7e0f50458fe648cc5b83ef41 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 16:11:17 -0400 Subject: [PATCH 259/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java index 17b04d78f4..852433b77f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java @@ -27,9 +27,11 @@ import cern.colt.matrix.linalg.Algebra; import cern.jet.math.Functions; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.*; +import edu.pitt.dbmi.data.reader.Data; import org.apache.commons.math3.util.FastMath; import java.text.NumberFormat; @@ -92,7 +94,7 @@ public IndTestFisherZGeneralizedInverse(DataSet dataSet, double alpha) { throw new IllegalArgumentException("Alpha mut be in [0, 1]"); } - this.dataSet = dataSet; + this.dataSet = DataUtils.center(dataSet); this.data = new DenseDoubleMatrix2D(dataSet.getDoubleData().toArray()); this.variables = Collections.unmodifiableList(dataSet.getVariables()); setAlpha(alpha); From 8d31cd49a9a81902320f24c833f3f4e20d5d5275 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 16:14:33 -0400 Subject: [PATCH 260/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../IndTestFisherZGeneralizedInverse.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java index 852433b77f..e4964a8d9c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java @@ -94,9 +94,10 @@ public IndTestFisherZGeneralizedInverse(DataSet dataSet, double alpha) { throw new IllegalArgumentException("Alpha mut be in [0, 1]"); } - this.dataSet = DataUtils.center(dataSet); - this.data = new DenseDoubleMatrix2D(dataSet.getDoubleData().toArray()); - this.variables = Collections.unmodifiableList(dataSet.getVariables()); + this.dataSet = dataSet; + + this.data = new DenseDoubleMatrix2D(DataUtils.center(this.dataSet).getDoubleData().toArray()); + this.variables = Collections.unmodifiableList(this.dataSet.getVariables()); setAlpha(alpha); } @@ -291,6 +292,27 @@ private int sampleSize() { return this.data.rows(); } + /** + * Returns the data being analyzed (centered). + * @return This data. + */ + public DataSet getData() { + return this.dataSet; + } + + @Override + public double getScore() { + return getPValue(); + } + + public boolean isVerbose() { + return this.verbose; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + public boolean determines(List zList, Node xVar) { if (zList == null) { throw new NullPointerException(); @@ -365,24 +387,6 @@ public boolean determines(List zList, Node xVar) { return determined; } - - public DataSet getData() { - return this.dataSet; - } - - - @Override - public double getScore() { - return getPValue(); - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } } From 5074d372f2eae77cb195e3f154239bbaf1a46381 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 16:17:59 -0400 Subject: [PATCH 261/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../IndTestFisherZGeneralizedInverse.java | 99 +++++++++++-------- 1 file changed, 59 insertions(+), 40 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java index e4964a8d9c..8edeaece5e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java @@ -31,7 +31,6 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.*; -import edu.pitt.dbmi.data.reader.Data; import org.apache.commons.math3.util.FastMath; import java.text.NumberFormat; @@ -116,7 +115,7 @@ public IndependenceTest indTestSubset(List vars) { * @param xVar the one variable being compared. * @param yVar the second variable being compared. * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. + * @return True iff x _||_ y | z. * @throws RuntimeException if a matrix singularity is encountered. */ public IndependenceResult checkIndependence(Node xVar, Node yVar, List z) { @@ -256,63 +255,49 @@ public String toString() { return "Fisher's Z - Generalized Inverse, alpha = " + IndTestFisherZGeneralizedInverse.nf.format(getAlpha()); } - //==========================PRIVATE METHODS============================// - /** - * Computes that value x such that P(abs(N(0,1) > x) < alpha. Note that this is a two sided test of the null - * hypothesis that the Fisher's Z value, which is distributed as N(0,1) is not equal to 0.0. - */ - private double cutoffGaussian() { - double upperTail = 1.0 - getAlpha() / 2.0; - final double epsilon = 1e-14; - - // Find an upper bound. - double lowerBound = -1.0; - double upperBound = 0.0; - - while (RandomUtil.getInstance().normalCdf(0, 1, upperBound) < upperTail) { - lowerBound += 1.0; - upperBound += 1.0; - } - - while (upperBound >= lowerBound + epsilon) { - double midPoint = lowerBound + (upperBound - lowerBound) / 2.0; - - if (RandomUtil.getInstance().normalCdf(0, 1, midPoint) <= upperTail) { - lowerBound = midPoint; - } else { - upperBound = midPoint; - } - } - - return lowerBound; - } - - private int sampleSize() { - return this.data.rows(); - } - - /** - * Returns the data being analyzed (centered). + * Returns the data being analyzed. + * * @return This data. */ public DataSet getData() { return this.dataSet; } + /** + * Returns the score of the data. + * + * @return A number that's great than zero iff dependent. + * @see Fges + */ @Override public double getScore() { - return getPValue(); + return alpha - getPValue(); } + /** + * Returns True just in case verbose output should be printed. + * + * @return This. + */ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Returns true just in case the varialbe in zList determine xVar. + * + * @return True if so. + */ public boolean determines(List zList, Node xVar) { if (zList == null) { throw new NullPointerException(); @@ -387,6 +372,40 @@ public boolean determines(List zList, Node xVar) { return determined; } + + /** + * Computes that value x such that P(abs(N(0,1) > x) < alpha. Note that this is a two sided test of the null + * hypothesis that the Fisher's Z value, which is distributed as N(0,1) is not equal to 0.0. + */ + private double cutoffGaussian() { + double upperTail = 1.0 - getAlpha() / 2.0; + final double epsilon = 1e-14; + + // Find an upper bound. + double lowerBound = -1.0; + double upperBound = 0.0; + + while (RandomUtil.getInstance().normalCdf(0, 1, upperBound) < upperTail) { + lowerBound += 1.0; + upperBound += 1.0; + } + + while (upperBound >= lowerBound + epsilon) { + double midPoint = lowerBound + (upperBound - lowerBound) / 2.0; + + if (RandomUtil.getInstance().normalCdf(0, 1, midPoint) <= upperTail) { + lowerBound = midPoint; + } else { + upperBound = midPoint; + } + } + + return lowerBound; + } + + private int sampleSize() { + return this.data.rows(); + } } From 96516b6ec7d4477d3a93d74bfdca58316411733c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 16:32:25 -0400 Subject: [PATCH 262/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetradapp/model/IndTestChooser.java | 1 + .../search/IndTestIndependenceFacts.java | 68 +++++++++++++++++-- .../IndTestFisherZPercentIndependent.java | 19 ++---- .../IndTestFisherZRecursive.java | 3 +- 4 files changed, 73 insertions(+), 18 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/IndTestFisherZPercentIndependent.java (92%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/IndTestFisherZRecursive.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index 91cd81c968..148e32209a 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZPercentIndependent; import edu.cmu.tetrad.util.Parameters; import edu.pitt.csb.mgm.IndTestMultinomialLogisticRegressionWald; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java index 270b884cd1..3d3f02b549 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.TetradLogger; +import javax.help.UnsupportedOperationException; import java.util.List; /** @@ -40,15 +41,30 @@ public final class IndTestIndependenceFacts implements IndependenceTest { private final IndependenceFacts facts; private boolean verbose; + /** + * Constructor. + * + * @param facts The facts to check. + * @see IndependenceFacts + */ public IndTestIndependenceFacts(IndependenceFacts facts) { this.facts = facts; } - + /** + * @throws UnsupportedOperationException Not implemented. + */ public IndependenceTest indTestSubset(List vars) { throw new UnsupportedOperationException(); } + /** + * Checks independence by looking up facts in the list of facts supplied in the + * constructor. + * + * @return the independence result. + * @see IndependenceResult + */ public IndependenceResult checkIndependence(Node x, Node y, List z) { Node[] _z = new Node[z.size()]; @@ -68,14 +84,30 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { return new IndependenceResult(new IndependenceFact(x, y, z), independent, getPValue()); } + /** + * No p-values are available. + * + * @return Double.NaN. + */ public double getPValue() { return Double.NaN; } + /** + * Returns the list of variables for the facts. + * + * @return This list. + */ public List getVariables() { return this.facts.getVariables(); } + /** + * Returns the node with the given name. + * + * @param name The name of the node, + * @return The node. + */ public Node getVariable(String name) { if (name == null) throw new NullPointerException(); @@ -90,32 +122,60 @@ public Node getVariable(String name) { return null; } + /** + * @throws UnsupportedOperationException Method not implemented. + */ public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException("Method not implmeented."); } + /** + * @throws java.lang.UnsupportedOperationException Method not implemented. + */ public double getAlpha() { - return Double.NaN; + throw new java.lang.UnsupportedOperationException("Method not implemented"); } + /** + * @throws java.lang.UnsupportedOperationException Method not implemented. + */ public void setAlpha(double alpha) { throw new UnsupportedOperationException(); } + /** + * Returns the facts supplied in the constructor, which constutite a data model. + * + * @return These facts. + */ public DataModel getData() { return this.facts; } - + /** + * Returns NaN. + * + * @return This. + */ @Override public double getScore() { return getPValue(); } + /** + * Returns whether verbose output is to be printed. + * + * @return True if so. + */ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output is to be printed. + * + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java similarity index 92% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZPercentIndependent.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java index 0f012c0be3..a93ce94b32 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; @@ -27,6 +27,9 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.StatUtils; @@ -52,7 +55,6 @@ public final class IndTestFisherZPercentIndependent implements IndependenceTest private final Map variablesMap; private double percent = .75; private boolean fdr = true; - private final ArrayList recursivePartialCorrelation; private boolean verbose; //==========================CONSTRUCTORS=============================// @@ -84,11 +86,6 @@ public IndTestFisherZPercentIndependent(List dataSets, double alpha) { for (int i = 0; i < this.variables.size(); i++) { this.variablesMap.put(this.variables.get(i), i); } - - this.recursivePartialCorrelation = new ArrayList<>(); - for (Matrix covMatrix : this.ncov) { - this.recursivePartialCorrelation.add(new PartialCorrelation(getVariables(), covMatrix, dataSets.get(0).getNumRows())); - } } //==========================PUBLIC METHODS=============================// @@ -108,8 +105,8 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { int sampleSize = this.data.get(0).rows(); List pValues = new ArrayList<>(); - for (int m = 0; m < this.ncov.size(); m++) { - Matrix _ncov = this.ncov.get(m).getSelection(all, all); + for (Matrix matrix : this.ncov) { + Matrix _ncov = matrix.getSelection(all, all); Matrix inv = _ncov.inverse(); double r = -inv.get(0, 1) / sqrt(inv.get(0, 0) * inv.get(1, 1)); @@ -135,10 +132,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { int index = (int) round((1.0 - this.percent) * pValues.size()); this.pValue = pValues.get(index); -// if (this.pValue == 0) { -// System.out.println("Zero pvalue "+ SearchLogUtils.independenceFactMsg(x, y, z, getScore())); -// } - boolean independent = this.pValue > _cutoff; if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZRecursive.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java index 9ea3f49c23..1f2138e613 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.StatUtils; import edu.cmu.tetrad.util.TetradLogger; From ec6b433cb9aa0241f5dfeb12d730b3ccfcc0f41a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 16:37:51 -0400 Subject: [PATCH 263/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../search/IndTestMixedMultipleTTest.java | 150 ++++++++++-------- 1 file changed, 84 insertions(+), 66 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMixedMultipleTTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMixedMultipleTTest.java index 018b884471..addf5609b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMixedMultipleTTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMixedMultipleTTest.java @@ -90,7 +90,7 @@ public IndependenceTest indTestSubset(List vars) { } /** - * @return true if the given independence question is judged true, false if not. The independence question is of the + * @return True if the given independence question is judged true, False if not. The independence question is of the * form x _||_ y | z, z = [z1,...,zn], where x, y, z1,...,zn are searchVariables in the list returned by * getVariableNames(). */ @@ -112,6 +112,89 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } } + + /** + * @return the probability associated with the most recently executed independence test, of Double.NaN if p value is + * not meaningful for tis test. + */ + public double getPValue() { + return this.lastP; //STUB + } + + /** + * @return the list of searchVariables over which this independence checker is capable of determinining independence + * relations. + */ + public List getVariables() { + return this.searchVariables; // Make sure the variables from the ORIGINAL data set are returned, not the modified dataset! + } + + /** + * @throws javax.help.UnsupportedOperationException Method not implemented. + */ + public boolean determines(List z, Node y) { + throw new UnsupportedOperationException("Method not implemented."); + } + + /** + * @throws UnsupportedOperationException if there is no significance level. + */ + public double getAlpha() { + throw new UnsupportedOperationException("Method not implemented."); + } + + /** + * Sets the significance level. + */ + public void setAlpha(double alpha) { + this.alpha = alpha; + } + + /** + * Returne the original data for the method. + * + * @return This data. + */ + public DataSet getData() { + return this.originalData; + } + + /** + * Returns alpha minus the last p-value calculated. + * + * @return Thsi. + */ + @Override + public double getScore() { + return alpha - getPValue(); + } + + /** + * @return a string representation of this test. + */ + public String toString() { + NumberFormat nf = new DecimalFormat("0.0000"); + return "Multinomial Logistic Regression, alpha = " + nf.format(getAlpha()); + } + + /** + * Returns whether verbose output should be printed. + * + * @return This. + */ + public boolean isVerbose() { + return this.verbose; + } + + /** + * Sets whether verbose output should be printed. + * + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + private List expandVariable(DataSet dataSet, Node node) { if (node instanceof ContinuousVariable) { return Collections.singletonList(node); @@ -340,69 +423,4 @@ private IndependenceResult isIndependentRegression(Node x, Node y, List z) return new IndependenceResult(new IndependenceFact(x, y, z), independent, p); } - - /** - * @return the probability associated with the most recently executed independence test, of Double.NaN if p value is - * not meaningful for tis test. - */ - public double getPValue() { - return this.lastP; //STUB - } - - /** - * @return the list of searchVariables over which this independence checker is capable of determinining independence - * relations. - */ - public List getVariables() { - return this.searchVariables; // Make sure the variables from the ORIGINAL data set are returned, not the modified dataset! - } - - - /** - * @return true if y is determined the variable in z. - */ - public boolean determines(List z, Node y) { - return false; //stub - } - - /** - * @return the significance level of the independence test. - * @throws UnsupportedOperationException if there is no significance level. - */ - public double getAlpha() { - return this.alpha; //STUB - } - - /** - * Sets the significance level. - */ - public void setAlpha(double alpha) { - this.alpha = alpha; - } - - public DataSet getData() { - return this.originalData; - } - - - @Override - public double getScore() { - return getPValue(); - } - - /** - * @return a string representation of this test. - */ - public String toString() { - NumberFormat nf = new DecimalFormat("0.0000"); - return "Multinomial Logistic Regression, alpha = " + nf.format(getAlpha()); - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } } From abf4448da7f7dc2fd0ea2a421dd172f19889a6f9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 16:40:01 -0400 Subject: [PATCH 264/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/IndTestMNlrlr.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java index 8273958e59..4864f51a28 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java @@ -36,7 +36,7 @@ * Performs a test of conditional independence X _||_ Y | Z1...Zn where all searchVariables are either continuous or discrete. * This test is valid for both ordinal and non-ordinal discrete searchVariables. * - * @author Bryan Andrews + * @author bryanandrews */ public class IndTestMNlrlr implements IndependenceTest { private final DataSet data; @@ -47,7 +47,6 @@ public class IndTestMNlrlr implements IndependenceTest { private final MnlrLikelihood likelihood; private boolean verbose; - // P Values private double pValue = Double.NaN; @@ -178,22 +177,33 @@ public void setAlpha(double alpha) { this.alpha = alpha; } + /** + * Returns the data. + * @return This. + */ public DataSet getData() { return this.data; } - @Override - public double getScore() { return getAlpha() - getPValue(); } + /** + * Returns whether verbose output should be printed. + * @return True is so. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether this test will print verbose output. + * + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; From c9507c38c160d7d0c9089f3e8628100d6c6e4503 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 17:01:02 -0400 Subject: [PATCH 265/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../model/AbstractMBSearchRunner.java | 1 + .../model/BuildPureClustersRunner.java | 4 +-- .../cmu/tetradapp/model/IndTestChooser.java | 4 ++- .../model/PValueImproverWrapper.java | 6 ++-- .../cmu/tetradapp/model/VcpcFastRunner.java | 2 +- .../edu/cmu/tetradapp/model/VcpcRunner.java | 2 +- .../model/YeastPcCcdSearchWrapper.java | 2 +- .../algorithm/oracle/cpdag/Pcd.java | 2 +- .../algcomparison/algorithm/other/Glasso.java | 4 +-- .../algcomparison/independence/Mnlrlrt.java | 4 +-- .../independence/SemBicDTest.java | 2 +- .../score/SemBicScoreDeterministic.java | 4 +-- ...{IndTestMNlrlr.java => IndTestMnlrLr.java} | 4 +-- .../edu/cmu/tetrad/search/IndTestMulti.java | 28 +++++++++++++++---- .../edu/cmu/tetrad/search/IndTestSepset.java | 2 +- .../edu/cmu/tetrad/search/ResolveSepsets.java | 2 +- .../edu/cmu/tetrad/search/SampleVcpc.java | 2 +- .../edu/cmu/tetrad/search/SampleVcpcFast.java | 2 +- .../BpcTetradPurifyWashdown.java | 2 +- .../{work_in_progress => WIP}/DMSearch.java | 2 +- .../search/{work_in_progress => WIP}/Dci.java | 2 +- .../{work_in_progress => WIP}/FasDci.java | 2 +- .../{work_in_progress => WIP}/FasFdr.java | 2 +- .../{work_in_progress => WIP}/Glasso.java | 2 +- .../{work_in_progress => WIP}/GraspTol.java | 2 +- .../{work_in_progress => WIP}/HbmsBeam.java | 2 +- .../{work_in_progress => WIP}/Hbsms.java | 2 +- .../{work_in_progress => WIP}/HbsmsGes.java | 2 +- .../IndTestCramerT.java | 2 +- .../IndTestFisherZGeneralizedInverse.java | 6 +++- .../IndTestFisherZPercentIndependent.java | 2 +- .../IndTestFisherZRecursive.java | 2 +- .../{ => WIP}/IndTestMixedMultipleTTest.java | 5 +++- .../IndTestMultinomialLogisticRegression.java | 5 +++- .../InverseCorrelation.java | 2 +- .../OtherPermAlgs.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/README.txt | 2 ++ .../SemBicScoreDeterministic.java | 2 +- .../SepsetMapDci.java | 2 +- .../{work_in_progress => WIP}/Sextad.java | 2 +- .../{work_in_progress => WIP}/VcFas.java | 2 +- .../{work_in_progress => WIP}/VcPc.java | 2 +- .../{work_in_progress => WIP}/VcPcAlt.java | 2 +- .../{work_in_progress => WIP}/VcPcFast.java | 2 +- .../{work_in_progress => WIP}/Washdown.java | 2 +- .../edu/pitt/csb/mgm/ExploreIndepTests.java | 2 +- .../java/edu/pitt/csb/mgm/MixedUtils.java | 2 +- .../pitt/csb/stability/SearchWrappers.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestDM.java | 2 +- .../TestIndTestFisherGeneralizedInverse.java | 2 +- 50 files changed, 91 insertions(+), 60 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IndTestMNlrlr.java => IndTestMnlrLr.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/BpcTetradPurifyWashdown.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/DMSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/Dci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/FasDci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/FasFdr.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/Glasso.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/GraspTol.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/HbmsBeam.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/Hbsms.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/HbsmsGes.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/IndTestCramerT.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/IndTestFisherZGeneralizedInverse.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/IndTestFisherZPercentIndependent.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/IndTestFisherZRecursive.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/IndTestMixedMultipleTTest.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/IndTestMultinomialLogisticRegression.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/InverseCorrelation.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/OtherPermAlgs.java (99%) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/SemBicScoreDeterministic.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/SepsetMapDci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/Sextad.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/VcFas.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/VcPc.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/VcPcAlt.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/VcPcFast.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => WIP}/Washdown.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java index 924b0660f9..3f00f8890f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.data.DoubleDataBox; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; import edu.cmu.tetrad.util.Parameters; import java.io.IOException; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index 0bccc6b4b3..e2e3379b2b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -27,8 +27,8 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.work_in_progress.BpcTetradPurifyWashdown; -import edu.cmu.tetrad.search.work_in_progress.Washdown; +import edu.cmu.tetrad.search.WIP.BpcTetradPurifyWashdown; +import edu.cmu.tetrad.search.WIP.Washdown; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index 148e32209a..bdca937cce 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -24,7 +24,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZPercentIndependent; +import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; +import edu.cmu.tetrad.search.WIP.IndTestFisherZPercentIndependent; +import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.util.Parameters; import edu.pitt.csb.mgm.IndTestMultinomialLogisticRegressionWald; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index 1d214dc37c..477f5feed4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -24,9 +24,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.work_in_progress.HbmsBeam; -import edu.cmu.tetrad.search.work_in_progress.Hbsms; -import edu.cmu.tetrad.search.work_in_progress.HbsmsGes; +import edu.cmu.tetrad.search.WIP.HbmsBeam; +import edu.cmu.tetrad.search.WIP.Hbsms; +import edu.cmu.tetrad.search.WIP.HbsmsGes; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.*; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index 4967a2b913..a4f4ea1f65 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.work_in_progress.VcPcFast; +import edu.cmu.tetrad.search.WIP.VcPcFast; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index d8a4ce331d..148fb635af 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.work_in_progress.VcPc; +import edu.cmu.tetrad.search.WIP.VcPc; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java index fc7e6cccb1..4adb4c950d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Ccd; -import edu.cmu.tetrad.search.work_in_progress.IndTestCramerT; +import edu.cmu.tetrad.search.WIP.IndTestCramerT; import edu.cmu.tetrad.search.Pc; import edu.pitt.dbmi.data.reader.Delimiter; 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 index 2a428dcf79..e00bf1701b 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 @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndTestScore; import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; +import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 index 1b8374abcb..5ada536be8 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 @@ -50,7 +50,7 @@ public Graph search(DataModel ds, Parameters parameters) { Matrix cov = new Matrix(SimpleDataLoader.getContinuousDataSet(ds) .getCovarianceMatrix().toArray()); - edu.cmu.tetrad.search.work_in_progress.Glasso glasso = new edu.cmu.tetrad.search.work_in_progress.Glasso(cov); + edu.cmu.tetrad.search.WIP.Glasso glasso = new edu.cmu.tetrad.search.WIP.Glasso(cov); glasso.setMaxit(parameters.getInt(Params.MAXIT)); glasso.setIa(parameters.getBoolean(Params.IA)); glasso.setIs(parameters.getBoolean(Params.IS)); @@ -59,7 +59,7 @@ public Graph search(DataModel ds, Parameters parameters) { glasso.setThr(parameters.getDouble(Params.THR)); glasso.setRhoAllEqual(1.0); - edu.cmu.tetrad.search.work_in_progress.Glasso.Result result = glasso.search(); + edu.cmu.tetrad.search.WIP.Glasso.Result result = glasso.search(); Matrix wwi = new Matrix(result.getWwi().toArray()); List variables = ds.getVariables(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java index 8000e61981..fd5cabb8bf 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestMNlrlr; +import edu.cmu.tetrad.search.IndTestMnlrLr; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.Parameters; @@ -29,7 +29,7 @@ public class Mnlrlrt implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - return new IndTestMNlrlr(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha")); + return new IndTestMnlrLr(SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha")); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java index f1d3a2928a..d2a80d8d0a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.search.IndTestScore; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; +import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java index 6ffad5af8a..25fd795fcd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java @@ -28,8 +28,8 @@ public class SemBicScoreDeterministic implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic semBicScore - = new edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic(SimpleDataLoader.getCovarianceMatrix(dataSet)); + edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic semBicScore + = new edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic(SimpleDataLoader.getCovarianceMatrix(dataSet)); semBicScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount")); semBicScore.setDeterminismThreshold(parameters.getDouble("determinismThreshold")); return semBicScore; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java index 4864f51a28..f82bd52b49 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMNlrlr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java @@ -38,7 +38,7 @@ * * @author bryanandrews */ -public class IndTestMNlrlr implements IndependenceTest { +public class IndTestMnlrLr implements IndependenceTest { private final DataSet data; private final Map nodesHash; private double alpha; @@ -50,7 +50,7 @@ public class IndTestMNlrlr implements IndependenceTest { // P Values private double pValue = Double.NaN; - public IndTestMNlrlr(DataSet data, double alpha) { + public IndTestMnlrLr(DataSet data, double alpha) { this.data = data; this.likelihood = new MnlrLikelihood(data, -1, 1); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java index b645ec7b3a..252fae64aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java @@ -31,7 +31,7 @@ import java.util.Set; /** - * Pools together a set of independence tests using a specified methods + * Pools together a set of independence tests using a specified method. * * @author Robert Tillman */ @@ -83,7 +83,7 @@ public IndependenceTest indTestSubset(List vars) { * @param x the one variable being compared. * @param y the second variable being compared. * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. + * @return True iff x _||_ y | z. * @throws RuntimeException if a matrix singularity is encountered. */ public IndependenceResult checkIndependence(Node x, Node y, List z) { @@ -122,22 +122,28 @@ public List getVariables() { } /** - * @return the variable with the given name. + * @throws UnsupportedOperationException Method not implemented. */ - - public boolean determines(List z, Node x) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * @throws javax.help.UnsupportedOperationException Method not implemented. + */ public DataSet getData() { throw new UnsupportedOperationException(); } + /** + * Returns alpha - pvalue. + * + * @return This. + */ @Override public double getScore() { - return getPValue(); + return getAlpha() - getPValue(); } /** @@ -147,11 +153,21 @@ public String toString() { return "Pooled Independence Test: alpha = " + this.independenceTests.get(0).getAlpha(); } + /** + * Returns true if the test prints verbose output. + * + * @return True if the case. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether this test will print verbose output. + * + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java index 957b3c57f4..f02580070f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.work_in_progress.SepsetMapDci; +import edu.cmu.tetrad.search.WIP.SepsetMapDci; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index 8d00d9a1af..fb1aaa07ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodePair; -import edu.cmu.tetrad.search.work_in_progress.SepsetMapDci; +import edu.cmu.tetrad.search.WIP.SepsetMapDci; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java index 5f8c4d6611..794a777eff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.work_in_progress.VcFas; +import edu.cmu.tetrad.search.WIP.VcFas; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java index 2dcb96be0b..6e334a4f15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.work_in_progress.VcFas; +import edu.cmu.tetrad.search.WIP.VcFas; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java index e3230b8d61..f27e0b73af 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java index e1e597016e..f269fe5111 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java index 9bde31bdbd..ce395c884a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java index a2f0110b32..f7b525e5ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java index 2c1866905d..cd6161c8a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Glasso.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Glasso.java index 92b0881135..f7876f91a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Glasso.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java index afc6a67455..36cd872bcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java index 9e78fd2c85..0997ce722a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Hbsms.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Hbsms.java index 55f2bd655d..da6c9152d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Hbsms.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java index cc3964480e..6d3cb0de8d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java index b56ab4737e..d796c7c814 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java index 8edeaece5e..f3c67b295c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import cern.colt.matrix.DoubleMatrix1D; import cern.colt.matrix.DoubleMatrix2D; @@ -30,6 +30,10 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java index a93ce94b32..f30a6e7284 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java index 1f2138e613..dd72c04e90 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMixedMultipleTTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMixedMultipleTTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java index addf5609b5..e514b2336e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMixedMultipleTTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; @@ -29,6 +29,9 @@ import edu.cmu.tetrad.regression.LogisticRegression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMultinomialLogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMultinomialLogisticRegression.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java index 033e94f746..a1023d0a8c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMultinomialLogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; @@ -29,6 +29,9 @@ import edu.cmu.tetrad.regression.LogisticRegression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/InverseCorrelation.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/InverseCorrelation.java index ed9cc40ae2..db31ec28da 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/InverseCorrelation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java index fdc933f485..8040b24ede 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt new file mode 100644 index 0000000000..c1367a6d3e --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt @@ -0,0 +1,2 @@ +These classes are put here in the "Work In Progress" (WIP) directory because +they're either old (but not disposable) or not in finished form. \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java index 231dad556b..d2e6bcc10b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java index 5be41e09a9..e4f9a28c7c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.SepsetMap; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Sextad.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Sextad.java index 876fa07f28..7faae81903 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Sextad.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java index bc596d595d..1e20be1fab 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java index 5a4238247a..aca03fa817 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.data.Knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java index e322f767e4..1e627ae472 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java index 03386469e1..823689c181 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.data.Knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Washdown.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Washdown.java index 12472dbbf1..46b92d44e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Washdown.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java index 2dbe039ce2..8f793d91ce 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphPersistence; -import edu.cmu.tetrad.search.IndTestMultinomialLogisticRegression; +import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.search.PcStable; import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java index 820dd8af46..9b9a64ae28 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java @@ -26,7 +26,7 @@ import cern.colt.matrix.DoubleMatrix2D; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestMixedMultipleTTest; +import edu.cmu.tetrad.search.WIP.IndTestMixedMultipleTTest; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java index ca1cfb2d35..ba6e183b8b 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.IndTestMultinomialLogisticRegression; +import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.search.PcStable; import edu.cmu.tetrad.search.SemBicScore; import edu.pitt.csb.mgm.Mgm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java index 53c230d7a8..a599924618 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.work_in_progress.DMSearch; +import edu.cmu.tetrad.search.WIP.DMSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java index 9600b66c21..f1fb5ad2b9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestFisherZGeneralizedInverse; +import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; From f3952ee834c09ee5250bb07511aac5eb48d58e5e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 17:13:36 -0400 Subject: [PATCH 266/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetradapp/model/PurifyRunner.java | 2 +- .../cmu/tetrad/search/BuildPureClusters.java | 2 +- .../tetrad/search/ContinuousTetradTest.java | 2 +- .../cmu/tetrad/search/DiscreteTetradTest.java | 2 +- .../java/edu/cmu/tetrad/search/IPurify.java | 3 --- .../edu/cmu/tetrad/search/IndTestType.java | 3 ++- .../main/java/edu/cmu/tetrad/search/Ion.java | 2 -- .../main/java/edu/cmu/tetrad/search/Kpc.java | 26 +++++++------------ .../tetrad/search/PopulationTetradTest.java | 2 +- .../java/edu/cmu/tetrad/search/Purify.java | 4 +-- .../cmu/tetrad/search/PurifyScoreBased.java | 4 +-- .../cmu/tetrad/search/PurifyTetradBased.java | 4 +-- .../{ITetradTest.java => TetradTest.java} | 19 +------------- .../search/WIP/BpcTetradPurifyWashdown.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/README.txt | 2 +- .../java/edu/cmu/tetrad/test/TestPurify.java | 4 +-- 16 files changed, 28 insertions(+), 55 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ITetradTest.java => TetradTest.java} (98%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index db05ea5042..b2ac4129aa 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -70,7 +70,7 @@ public static PcRunner serializableInstance() { public void execute() { Object source = getData(); - ITetradTest test; + TetradTest test; System.out.println("Clusters " + getParams().get("clusters", null)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index b9ad36b03a..ae8b33e814 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -77,7 +77,7 @@ public final class BuildPureClusters { final int EDGE_RED = 4; final int MAX_CLIQUE_TRIALS = 50; - private ITetradTest tetradTest; + private TetradTest tetradTest; private IndependenceTest independenceTest; private DataSet dataSet; private double alpha; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java index d6974f6782..ff3b1130ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java @@ -54,7 +54,7 @@ * @author Ricardo Silva */ -public final class ContinuousTetradTest implements ITetradTest { +public final class ContinuousTetradTest implements TetradTest { private double sig; private double[] prob; private ICovarianceMatrix covMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java index 08beb7297c..62bbf7511a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java @@ -45,7 +45,7 @@ * @author Ricardo Silva */ -public final class DiscreteTetradTest implements ITetradTest { +public final class DiscreteTetradTest implements TetradTest { DataSet dataSet; // int rawdata[][]; int[][][][] counts; //bivariate coefs only diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java index 325e408462..656444e446 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java @@ -31,10 +31,7 @@ */ public interface IPurify { List> purify(List> partition); - void setTrueGraph(Graph mim); - - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestType.java index 26900928fa..9f8a68134d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestType.java @@ -27,7 +27,8 @@ import java.io.ObjectStreamException; /** - * A typesafe enumeration of the types of independence tests that are used for basic search algorithm in this package. + * A typesafe enumeration of the types of independence tests that are used for basic + * search algorithm in this package. * * @author Joseph Ramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java index 9daa84aad2..7cdf754404 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java @@ -1794,8 +1794,6 @@ private Set applyKnowledge(Set outputSet) { return _out; } - - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java index febf374fd1..3ca8b5a9eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java @@ -92,11 +92,6 @@ public class Kpc implements GraphSearch { */ private Set unshieldedNoncolliders; - /** - * The number of indepdendence tests in the last search. - */ - private int numIndependenceTests; - /** * The threshold for rejecting the null */ @@ -236,7 +231,7 @@ public Graph search(List nodes) { } List allNodes = getIndependenceTest().getVariables(); - if (!allNodes.containsAll(nodes)) { + if (!new HashSet<>(allNodes).containsAll(nodes)) { throw new IllegalArgumentException("All of the given nodes must " + "be in the domain of the independence test provided."); } @@ -249,7 +244,6 @@ public Graph search(List nodes) { fas.setDepth(getDepth()); this.graph = fas.search(); this.sepset = fas.getSepsets(); - this.numIndependenceTests = fas.getNumIndependenceTests(); enumerateTriples(); @@ -294,6 +288,15 @@ public Set getUnshieldedNoncolliders() { return this.unshieldedNoncolliders; } + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + //===============================ADDED FOR KPC=========================// /** @@ -373,16 +376,7 @@ private void enumerateTriples() { } } } - - public int getNumIndependenceTests() { - return this.numIndependenceTests; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } } - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java index 4c9d572158..192c9642df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java @@ -36,7 +36,7 @@ * @author Ricardo Silva */ -public class PopulationTetradTest implements ITetradTest { +public class PopulationTetradTest implements TetradTest { private final CorrelationMatrix CorrelationMatrix; private final boolean[] bvalues; private final double epsilon = 0.001; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java index c0197390e2..a691ef7336 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java @@ -67,7 +67,7 @@ public class Purify { private Clusters clusters; private List forbiddenList; private int numVars; - private ITetradTest tetradTest; + private TetradTest tetradTest; /** * The logger for this class. The config needs to be set. @@ -120,7 +120,7 @@ public Purify(DataSet dataSet, double sig, TestType testType, this.variables = dataSet.getVariables(); } - public Purify(ITetradTest tetradTest, Clusters knowledge) { + public Purify(TetradTest tetradTest, Clusters knowledge) { this.tetradTest = tetradTest; initAlgorithm(-1., TestType.NONE, knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java index bc72b9e515..26ec1d718c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java @@ -39,7 +39,7 @@ */ public class PurifyScoreBased implements IPurify { private final boolean outputMessage = true; - private final ITetradTest tetradTest; + private final TetradTest tetradTest; private final int numVars; private List forbiddenList; @@ -87,7 +87,7 @@ public class PurifyScoreBased implements IPurify { boolean extraDebugPrint; - public PurifyScoreBased(ITetradTest tetradTest) { + public PurifyScoreBased(TetradTest tetradTest) { this.tetradTest = tetradTest; this.numVars = tetradTest.getVarNames().length; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java index 87da3cb236..13365e96d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java @@ -37,11 +37,11 @@ */ public class PurifyTetradBased implements IPurify { private final boolean outputMessage = true; - private final ITetradTest tetradTest; + private final TetradTest tetradTest; private final List nodes; - public PurifyTetradBased(ITetradTest tetradTest) { + public PurifyTetradBased(TetradTest tetradTest) { this.tetradTest = tetradTest; this.nodes = tetradTest.getVariables(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ITetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ITetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java index c862fdd850..7deebdeec6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ITetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java @@ -33,41 +33,24 @@ * * @author Ricardo Silva */ -public interface ITetradTest { +public interface TetradTest { DataSet getDataSet(); - int tetradScore(int i, int j, int k, int q); - boolean tetradScore3(int i, int j, int k, int q); - boolean tetradScore1(int i, int j, int k, int q); - boolean tetradHolds(int i, int j, int k, int q); - double tetradPValue(int i, int j, int k, int q); - double tetradPValue(int i1, int j1, int k1, int l1, int i2, int j2, int k2, int l2); - boolean oneFactorTest(int a, int b, int c, int d); - boolean oneFactorTest(int a, int b, int c, int d, int e); - boolean oneFactorTest(int a, int b, int c, int d, int e, int f); - boolean twoFactorTest(int a, int b, int c, int d); - boolean twoFactorTest(int a, int b, int c, int d, int e); - boolean twoFactorTest(int a, int b, int c, int d, int e, int f); - double getSignificance(); - void setSignificance(double sig); - String[] getVarNames(); - List getVariables(); - ICovarianceMatrix getCovMatrix(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java index f27e0b73af..890f8eadb7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java @@ -38,7 +38,7 @@ */ public class BpcTetradPurifyWashdown { private final List variables; - private final ITetradTest test; + private final TetradTest test; /** * Construct the algorithm using a covariance matrix. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt index c1367a6d3e..e7e873c6aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt @@ -1,2 +1,2 @@ These classes are put here in the "Work In Progress" (WIP) directory because -they're either old (but not disposable) or not in finished form. \ No newline at end of file +they're either old (but not disposable) or require more work. \ No newline at end of file diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index cb049ad073..f5110936d7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -151,7 +151,7 @@ public void test1() { partition.add(cluster2); partition.add(cluster3); - ITetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.05); + TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.05); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); @@ -248,7 +248,7 @@ public void test1b() { partition.add(cluster1); partition.add(cluster2); - ITetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.0001); + TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.0001); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); From 50de625043650c114ca05539e048fa9505ed1cb0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 18:31:34 -0400 Subject: [PATCH 267/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetradapp/model/SampleVcpcFastRunner.java | 1 + .../cmu/tetradapp/model/SampleVcpcRunner.java | 1 + .../edu/cmu/tetrad/search/MagSemBicScore.java | 78 ++++++++++--------- .../main/java/edu/cmu/tetrad/search/Sp.java | 3 + .../ProbabilisticMapIndependence.java} | 9 ++- .../tetrad/search/{ => WIP}/SampleVcpc.java | 4 +- .../search/{ => WIP}/SampleVcpcFast.java | 4 +- 7 files changed, 55 insertions(+), 45 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ProbabilisticMAPIndependence.java => WIP/ProbabilisticMapIndependence.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/SampleVcpc.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/SampleVcpcFast.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 8f3ebd166e..7dc77a2556 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.WIP.SampleVcpcFast; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index c1fe39c520..65c5600b29 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.WIP.SampleVcpc; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java index d20b52fe33..6e245ecbc5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java @@ -149,6 +149,46 @@ public double localScore(int i, int... js) { return score; } + + public double getPenaltyDiscount() { + return this.score.getPenaltyDiscount(); + } + + public void setPenaltyDiscount(double penaltyDiscount) { + this.score.setPenaltyDiscount(penaltyDiscount); + } + + + @Override + public double localScoreDiff(int x, int y, int[] z) { + return localScore(y, append(z, x)) - localScore(y, z); + } + + @Override + public int getSampleSize() { + return this.score.getSampleSize(); + } + + @Override + public List getVariables() { + return this.score.getVariables(); + } + + @Override + public boolean isEffectEdge(double bump) { + return bump > 0; + } + + @Override + public int getMaxDegree() { + return this.score.getMaxDegree(); + } + + @Override + public boolean determines(List z, Node y) { + return false; + } + private void constructHeadsTails(List> heads, List> tails, List mbo, List head, List in, Set an, Node v1) { /* Calculates the head and tails of a MAG for vertex v1 and ordered Markov blanket mbo. @@ -201,43 +241,5 @@ private void updateIntrinsics(List in, List sib, Set an, Node } } - public double getPenaltyDiscount() { - return this.score.getPenaltyDiscount(); - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.score.setPenaltyDiscount(penaltyDiscount); - } - - - @Override - public double localScoreDiff(int x, int y, int[] z) { - return localScore(y, append(z, x)) - localScore(y, z); - } - - @Override - public int getSampleSize() { - return this.score.getSampleSize(); - } - - @Override - public List getVariables() { - return this.score.getVariables(); - } - - @Override - public boolean isEffectEdge(double bump) { - return bump > 0; - } - - @Override - public int getMaxDegree() { - return this.score.getMaxDegree(); - } - - @Override - public boolean determines(List z, Node y) { - return false; - } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 636109d47f..29dc0b0ba4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -21,6 +21,9 @@ *

This class is meant to be used in the context of the PermutationSearch class (see). * the proper use is PermutationSearch search = new PermutationSearch(new Sp(score));

* + *

Raskutti, G., & Uhler, C. (2018). Learning directed acyclic graph models based on + * sparsest permutations. Stat, 7(1), e183.

+ * * @author bryanandrews * @author josephramsey * @see PermutationSearch diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ProbabilisticMAPIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ProbabilisticMAPIndependence.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java index 997ae712c5..d49075b42b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ProbabilisticMAPIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java @@ -19,13 +19,16 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; @@ -39,7 +42,7 @@ * * @author Joseph Ramsey 3/2014 */ -public class ProbabilisticMAPIndependence implements IndependenceTest { +public class ProbabilisticMapIndependence implements IndependenceTest { /** * Calculates probabilities of independence for conditional independence facts. @@ -72,7 +75,7 @@ public class ProbabilisticMAPIndependence implements IndependenceTest { /** * Initializes the test using a discrete data sets. */ - public ProbabilisticMAPIndependence(DataSet dataSet) { + public ProbabilisticMapIndependence(DataSet dataSet) { this.data = dataSet; int[] counts = new int[dataSet.getNumColumns() + 2]; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java index 794a777eff..c32f937e2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.WIP.VcFas; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java index 6e334a4f15..6f6ff25e59 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.WIP.VcFas; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; From 0aeed2ec62a015a5c67d3439f6c8ad613bc57760 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 5 May 2023 18:33:37 -0400 Subject: [PATCH 268/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java index a722730935..60079b42c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java @@ -12,12 +12,14 @@ /** - * Implements a scorer extending Teyssier, M., and Koller, D. (2012). Ordering-based search: A simple and effective - * algorithm for learning Bayesian networks. arXiv preprint arXiv:1207.1429. You give it a score function + * Implements and extends a scorer extending Teyssier, M., and Koller, D. (2012). You give it a score function * and a variable ordering, and it computes the score. You can move any variable left or right, and it will * keep track of the score using the Teyssier and Kohler method. You can move a variable to a new position, * and you can bookmark a state and come back to it. * + *

Teyssier, M., & Koller, D. (2012). Ordering-based search: A simple and effective algorithm for + * learning Bayesian networks. arXiv preprint arXiv:1207.1429.

+ * * @author josephramsey * @author bryanandrews */ From 1d9b97f68851a988a1a09da047e948d4f3fea2be Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 07:20:12 -0400 Subject: [PATCH 269/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/search/IndTestPositiveCorr.java | 5 -- .../edu/cmu/tetrad/search/TeyssierScorer.java | 58 +------------------ .../java/edu/cmu/tetrad/search/WIP/Dci.java | 10 ++-- .../IndTestSepsetDci.java} | 45 +++++++------- 4 files changed, 32 insertions(+), 86 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{IndTestSepset.java => WIP/IndTestSepsetDci.java} (94%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java index 066c48654d..60ec927555 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java @@ -245,19 +245,14 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep // TetradMatrix inverse; try { -// inverse = Czz.inverse(); } catch (SingularMatrixException e) { -// System.out.println(SearchLogUtils.determinismDetected(z, x)); - return true; } } return false; - -// return variance < 1e-20; } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java index 60079b42c7..92580c3aeb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java @@ -26,7 +26,6 @@ public class TeyssierScorer { private final List variables; private ArrayList pi; // The current permutation. - private final Map variablesHash = new HashMap<>(); private Map orderHash = new HashMap<>(); private final IndependenceTest test; @@ -52,7 +51,8 @@ public TeyssierScorer(IndependenceTest test, Score score) { this.variables = score.getVariables(); this.pi = new ArrayList<>(this.variables); - nodesHash(this.variablesHash, this.variables); + Map variablesHash = new HashMap<>(); + nodesHash(variablesHash, this.variables); nodesHash(this.orderHash, this.pi); this.test = test; @@ -61,7 +61,7 @@ public TeyssierScorer(IndependenceTest test, Score score) { setUseScore(true); if (this.useScore) { for (Node node : this.variables) { - this.trees.put(node, new GrowShrinkTree(score, this.variablesHash, node)); + this.trees.put(node, new GrowShrinkTree(score, variablesHash, node)); } } } @@ -158,12 +158,10 @@ public boolean swaptuck(Node x, Node y) { return false; } - public boolean tuck(Node k, Node j) { return tuck(k, index(j)); } - public boolean tuck(Node k, int j) { if (adjacent(k, get(j))) return false; if (j >= index(k)) return false; @@ -648,47 +646,6 @@ public Set getPrefix(int i) { return prefix; } - - public Score getScoreObject() { - return this.score; - } - - - public IndependenceTest getTestObject() { - return this.test; - } - - -// class MyTask implements Callable { -// final List pi; -// final Map orderHash; -// TeyssierScorer scorer; -// int chunk; -// private final int from; -// private final int to; -// -// MyTask(List pi, TeyssierScorer scorer, int chunk, Map orderHash, -// int from, int to) { -// this.pi = pi; -// this.scorer = scorer; -// this.chunk = chunk; -// this.orderHash = orderHash; -// this.from = from; -// this.to = to; -// } -// -// @Override -// public Boolean call() throws InterruptedException { -// for (int i = from; i <= to; i++) { -// if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); -// recalculate(i); -// } -// -// return true; -// } -// } - - private void recalculate(int p) { if (this.prefixes.get(p) == null || !this.prefixes.get(p).containsAll(getPrefix(p))) { Pair p2 = getParentsInternal(p); @@ -701,14 +658,12 @@ private void recalculate(int p) { } } - private void nodesHash(Map nodesHash, List variables) { for (int i = 0; i < variables.size(); i++) { nodesHash.put(variables.get(i), i); } } - private boolean lastMoveSame(int i1, int i2) { if (i1 <= i2) { Set prefix0 = getPrefix(i1); @@ -729,7 +684,6 @@ private boolean lastMoveSame(int i1, int i2) { return true; } - @NotNull private Pair getGrowShrinkScore(int p) { Node n = this.pi.get(p); @@ -740,7 +694,6 @@ private Pair getGrowShrinkScore(int p) { return new Pair(parents, Double.isNaN(sMax) ? Double.NEGATIVE_INFINITY : sMax); } - private Pair getGrowShrinkIndependent(int p) { Node n = this.pi.get(p); Set parents = new HashSet<>(); @@ -779,7 +732,6 @@ private Pair getGrowShrinkIndependent(int p) { return new Pair(parents, -parents.size()); } - private Pair getParentsInternal(int p) { if (this.useRaskuttiUhler) { return getRaskuttiUhlerParents(p); @@ -792,7 +744,6 @@ private Pair getParentsInternal(int p) { } } - /** * Returns the parents of the node at index p, calculated using Pearl's method. * @@ -818,7 +769,6 @@ private Pair getRaskuttiUhlerParents(int p) { return new Pair(parents, -parents.size()); } - public Set> getSkeleton() { List order = getPi(); Set> skeleton = new HashSet<>(); @@ -835,12 +785,10 @@ public Set> getSkeleton() { return skeleton; } - public boolean parent(Node k, Node j) { return getParents(j).contains(k); } - private static class Pair { private final Set parents; private final double score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java index ce395c884a..b7b819fead 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java @@ -1809,7 +1809,7 @@ private boolean predictsFalseDependence(Graph graph) { */ private void resolveResultingIndependencies() { List allSepsets = new ArrayList<>(); - Pc fci = new Pc(new IndTestSepset(combineSepsets(this.sepsetMaps), this.variables)); + Pc fci = new Pc(new IndTestSepsetDci(combineSepsets(this.sepsetMaps), this.variables)); System.out.println("Starting pc..."); SepsetMapDci consSepset = new SepsetMapDci(); doSepsetClosure(consSepset, fci.search()); @@ -1840,7 +1840,7 @@ private void resolveResultingIndependencies() { List variables = new ArrayList<>(this.marginalVars.get(k)); Graph newGraph = new EdgeListGraph(variables); newGraph.fullyConnect(Endpoint.CIRCLE); - FasDci fas = new FasDci(newGraph, new IndTestSepset(allSepsets.get(k), new ArrayList<>(this.marginalVars.get(k)))); + FasDci fas = new FasDci(newGraph, new IndTestSepsetDci(allSepsets.get(k), new ArrayList<>(this.marginalVars.get(k)))); this.minimalSepsetMaps.add(fas.search()); } this.sepsetMaps = allSepsets; @@ -1853,7 +1853,7 @@ private void resolveResultingIndependencies() { */ private void resolveResultingIndependenciesB() { SepsetMapDci combinedSepset = combineSepsets(this.sepsetMaps); - Pc pc = new Pc(new IndTestSepset(combinedSepset, this.variables)); + Pc pc = new Pc(new IndTestSepsetDci(combinedSepset, this.variables)); Graph allInd = pc.search(); System.out.println("PC finished..."); List overlap = new ArrayList<>(this.marginalVars.get(0)); @@ -1943,7 +1943,7 @@ private void resolveResultingIndependenciesB() { List variables = new ArrayList<>(marginalVar); Graph newGraph = new EdgeListGraph(variables); newGraph.fullyConnect(Endpoint.CIRCLE); - FasDci fas = new FasDci(newGraph, new IndTestSepset(newSepset, variables)); + FasDci fas = new FasDci(newGraph, new IndTestSepsetDci(newSepset, variables)); this.minimalSepsetMaps.add(fas.search()); } } @@ -1954,7 +1954,7 @@ private void resolveResultingIndependenciesB() { */ private void resolveResultingIndependenciesC() { List allSepsets = new ArrayList<>(); - Pc fci = new Pc(new IndTestSepset(combineSepsets(this.sepsetMaps), this.variables)); + Pc fci = new Pc(new IndTestSepsetDci(combineSepsets(this.sepsetMaps), this.variables)); System.out.println("Starting pc..."); SepsetMapDci consSepset = new SepsetMapDci(); Graph fciResult = fci.search(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java index f02580070f..f48381403b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestSepset.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java @@ -19,12 +19,15 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; import edu.cmu.tetrad.search.WIP.SepsetMapDci; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; @@ -39,7 +42,7 @@ * * @author Robert Tillman */ -public class IndTestSepset implements IndependenceTest { +public class IndTestSepsetDci implements IndependenceTest { /** * The sepset being queried @@ -63,9 +66,10 @@ public class IndTestSepset implements IndependenceTest { private boolean verbose; /** - * Constructs a new independence test that returns d-separation facts for the given graph as independence results. + * Constructs a new independence test that returns d-separation facts for the given + * graph as independence results. */ - public IndTestSepset(SepsetMapDci sepset, List nodes) { + public IndTestSepsetDci(SepsetMapDci sepset, List nodes) { if (sepset == null) { throw new NullPointerException(); } @@ -100,28 +104,13 @@ public IndependenceTest indTestSubset(List vars) { return this; } - /** - * @return the list of observed nodes in the given graph. - */ - private List calcObservedVars(List nodes) { - List observedVars = new ArrayList<>(); - - for (Node node : nodes) { - if (node.getNodeType() == NodeType.MEASURED) { - observedVars.add(getVariable(node)); - } - } - - return observedVars; - } - /** * Checks the indicated independence fact. * * @param x one node. * @param y a second node. * @param z a List of nodes (conditioning variables) - * @return true iff x _||_ y | z + * @return True iff x _||_ y | z */ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (z == null) { @@ -223,7 +212,6 @@ public DataSet getData() { return null; //To change body of implemented methods use File | Settings | File Templates. } - @Override public double getScore() { return getPValue(); @@ -236,6 +224,21 @@ public boolean isVerbose() { public void setVerbose(boolean verbose) { this.verbose = verbose; } + + /** + * @return the list of observed nodes in the given graph. + */ + private List calcObservedVars(List nodes) { + List observedVars = new ArrayList<>(); + + for (Node node : nodes) { + if (node.getNodeType() == NodeType.MEASURED) { + observedVars.add(getVariable(node)); + } + } + + return observedVars; + } } From 516d2fcfeb6e2e77601a01bf280ceb36b9b89913 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 07:26:19 -0400 Subject: [PATCH 270/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java | 2 +- .../edu/cmu/tetradapp/editor/MarkovBlanketSearchEditor.java | 2 +- .../java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java | 1 + tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java | 1 + tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java | 1 + .../src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java | 1 + tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java | 1 + .../main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java | 1 + .../src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java | 1 + .../src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java | 1 + .../src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java | 1 + .../src/main/java/edu/cmu/tetradapp/util}/IndTestType.java | 2 +- 14 files changed, 14 insertions(+), 5 deletions(-) rename {tetrad-lib/src/main/java/edu/cmu/tetrad/search => tetrad-gui/src/main/java/edu/cmu/tetradapp/util}/IndTestType.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java index faa74bd45c..a10890e514 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; -import edu.cmu.tetrad.search.IndTestType; +import edu.cmu.tetradapp.util.IndTestType; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java index 4266a53557..91036b845d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataModelList; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.IndTestType; +import edu.cmu.tetradapp.util.IndTestType; import edu.cmu.tetrad.util.JOptionUtils; import javax.swing.*; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java index 591498e81c..62b90ee344 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.search.IndTestType; +import edu.cmu.tetradapp.util.IndTestType; /** * Helps to set independence test types. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovBlanketSearchEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovBlanketSearchEditor.java index 7464216418..2589e26417 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovBlanketSearchEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovBlanketSearchEditor.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndTestType; +import edu.cmu.tetradapp.util.IndTestType; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java index 3f00f8890f..51450513b3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java @@ -29,6 +29,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetradapp.util.IndTestType; import java.io.IOException; import java.io.ObjectInputStream; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index 5b60dae2d4..63e49378c8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; +import edu.cmu.tetradapp.util.IndTestType; import java.util.ArrayList; import java.util.List; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java index 4e491c80bf..84f17bfae4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; +import edu.cmu.tetradapp.util.IndTestType; import edu.cmu.tetradapp.util.IonInput; import java.util.ArrayList; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index bdca937cce..f40f8bfbf8 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -28,6 +28,7 @@ import edu.cmu.tetrad.search.WIP.IndTestFisherZPercentIndependent; import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetradapp.util.IndTestType; import edu.pitt.csb.mgm.IndTestMultinomialLogisticRegressionWald; import java.util.ArrayList; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index 4b942cf22b..67313bd93c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; +import edu.cmu.tetradapp.util.IndTestType; import java.util.*; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 7dc77a2556..4e60d60a10 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.search.WIP.SampleVcpcFast; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetradapp.util.IndTestType; import java.util.ArrayList; import java.util.HashSet; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index 65c5600b29..0904eb54e1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -29,6 +29,7 @@ import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; +import edu.cmu.tetradapp.util.IndTestType; import java.util.ArrayList; import java.util.HashSet; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index a4f4ea1f65..a9e82eb166 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.search.WIP.VcPcFast; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; +import edu.cmu.tetradapp.util.IndTestType; import java.util.ArrayList; import java.util.HashSet; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 148fb635af..97e7e56306 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.search.WIP.VcPc; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; +import edu.cmu.tetradapp.util.IndTestType; import java.util.ArrayList; import java.util.HashSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestType.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestType.java rename to tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java index 9f8a68134d..a356309bb6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestType.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetradapp.util; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.util.TetradSerializable; From fb248189ab43e8bcff10794434790cda7ff43ece Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 07:32:09 -0400 Subject: [PATCH 271/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/IndTestScore.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java index 4e06e5f064..62aa749dd6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java @@ -39,7 +39,7 @@ * conditional independence "oracles" for constraint-based searches. * * @author Don Crimbchin (djc2@andrew.cmu.edu) - * @author Joseph Ramsey + * @author josephramsey */ public class IndTestScore implements IndependenceTest { @@ -156,6 +156,7 @@ public double getAlpha() { /** * Sets the significance level. + * @param alpha This level. */ public void setAlpha(double alpha) { } @@ -167,43 +168,67 @@ public DataModel getData() { return this.data; } + /** + * Returns the covariance matrix. + * @return This matrix. + */ public ICovarianceMatrix getCov() { return ((SemBicScore) this.score).getCovariances(); } + /** + * @throws UnsupportedOperationException Not implemented. + */ public List getDataSets() { throw new UnsupportedOperationException(); } + /** + * Returns the sample size. + * @return This size. + */ public int getSampleSize() { return this.score.getSampleSize(); } - public List getCovMatrices() { - throw new UnsupportedOperationException(); - } - /** - * A score that is higher with more likely models. + * @return A score that is higher with more likely models. */ public double getScore() { return this.bump; } + /** + * Returns the score that this test wraps. + * @return This score + * @see Score + */ public Score getWrappedScore() { return this.score; } + /** + * Returns true if verbose ouput should be printed. + * @return True if so. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Returns a String representation of this test. + * @return This string. + */ @Override public String toString() { return this.score.toString() + " Interpreted as a Test"; From 2139faede5d001e584d0945f3e2cf18488088fe5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 07:42:56 -0400 Subject: [PATCH 272/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetradapp/model/IonRunner.java | 6 +- .../java/edu/cmu/tetrad/search/IPurify.java | 1 + .../main/java/edu/cmu/tetrad/search/Kci.java | 27 +------- .../edu/cmu/tetrad/search/{ => WIP}/Ion.java | 61 +++++++++++-------- .../search/{ => WIP}/IonHittingSet.java | 4 +- 5 files changed, 42 insertions(+), 57 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/Ion.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/IonHittingSet.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java index 0d316f7fbc..187b52fcbb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.Ion; +import edu.cmu.tetrad.search.WIP.Ion; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -199,8 +199,8 @@ public void execute() { Ion ion = new Ion(getGraphs()); - ion.setAdjacencySearch(getParams().getBoolean("pruneByAdjacencies", true)); - ion.setPathLengthSearch(getParams().getBoolean("pruneByPathLength", true)); + ion.setDoAdjacencySearch(getParams().getBoolean("pruneByAdjacencies", true)); + ion.setDoPathLengthSearch(getParams().getBoolean("pruneByPathLength", true)); ion.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); List graphs = ion.search(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java index 656444e446..cf84c7e367 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java @@ -28,6 +28,7 @@ /** * An interface for Purify algorithm. + * @author josephramsey */ public interface IPurify { List> purify(List> partition); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java index 4d499f4b3f..30edba945d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java @@ -50,7 +50,6 @@ public class Kci implements IndependenceTest { // Variables in data private final List variables; private final double[] h; -// private final double[][] _data; // The alpha level of the test. private double alpha; @@ -113,7 +112,6 @@ public Kci(DataSet data, double alpha) { for (int j = 0; j < n; j++) Ones.set(j, 0, 1); this.alpha = alpha; - } //====================================PUBLIC METHODS==================================// @@ -126,7 +124,7 @@ public IndependenceTest indTestSubset(List vars) { } /** - * Returns true if the given independence question is judged true, false if not. The independence question is of the + * Returns True if the given independence question is judged true, false if not. The independence question is of the * form x _||_ y | z, z = [z1,...,zn], where x, y, z1,...,zn are variables in the list returned by * getVariableNames(). */ @@ -136,29 +134,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { true, Double.NaN); } -// Node _x = data.getVariable(x.getName()); -// -// if (_x == null) { -// throw new NullPointerException("The x variable, " + x + " was not in the data."); -// } -// -// Node _y = data.getVariable(y.getName()); -// -// if (_y == null) { -// throw new NullPointerException("The y variable, " + y + " was not in the data."); -// } -// -// List _z = new ArrayList<>(); -// for (Node v : z) { -// Node variable = data.getVariable(v.getName()); -// -// if (variable == null) { -// throw new NullPointerException("A conditioning variable, " + v + " was not in the data."); -// } -// -// _z.add(variable); -// } - List allVars = new ArrayList<>(); allVars.add(x); allVars.add(y); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java index 7cdf754404..ffd9390376 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java @@ -19,11 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.GraphChange; +import edu.cmu.tetrad.search.PossibleDConnectingPath; +import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; @@ -45,7 +48,7 @@ public class Ion { private boolean pathLengthSearch = true; // prune using adjacencies - private boolean adjacencySearch; + private boolean doAdjacencySearch; /** * The input PAGs being to be intergrated, possibly FCI outputs. @@ -117,19 +120,25 @@ public Ion(List pags) { //============================= Public Methods ============================// /** - * Sets path length search on or off + * Sets path length search on or off. + * @param doPathLengthSearch True if on. */ - public void setPathLengthSearch(boolean b) { - this.pathLengthSearch = b; + public void setDoPathLengthSearch(boolean doPathLengthSearch) { + this.pathLengthSearch = doPathLengthSearch; } /** * Sets adjacency search on or off + * @param doAdjacencySearch True if on. */ - public void setAdjacencySearch(boolean b) { - this.adjacencySearch = b; + public void setDoAdjacencySearch(boolean doAdjacencySearch) { + this.doAdjacencySearch = doAdjacencySearch; } + /** + * Sets the knowledge to be used for this search. + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { throw new NullPointerException("Knowledge must not be null."); @@ -139,7 +148,8 @@ public void setKnowledge(Knowledge knowledge) { } /** - * Begins the ION search procedure, described at each step + * Runs the ION search and returns a list of compatible graphs. + * @return These graphs. */ public List search() { @@ -211,7 +221,7 @@ public List search() { final int currentSep = 1; int numAdjacencies = this.separations.size(); for (IonIndependenceFacts fact : this.separations) { - if (this.adjacencySearch) { + if (this.doAdjacencySearch) { TetradLogger.getInstance().log("info", "Braching over path nonadjacencies: " + currentSep + " of " + numAdjacencies); } seps--; @@ -230,7 +240,7 @@ public List search() { // known to be d-separated List dConnections = new ArrayList<>(); // checks to see if looping over adjacencies - if (this.adjacencySearch) { + if (this.doAdjacencySearch) { for (Collection conditions : fact.getZ()) { // checks to see if looping over path lengths if (this.pathLengthSearch) { @@ -403,7 +413,7 @@ public List search() { } } // exits loop if not looping over adjacencies - if (!this.adjacencySearch) { + if (!this.doAdjacencySearch) { break; } } @@ -510,6 +520,7 @@ public List search() { newGraph.setEndpoint(triple.getX(), triple.getY(), Endpoint.ARROW); newGraph.setEndpoint(triple.getZ(), triple.getY(), Endpoint.ARROW); } + doFinalOrientation(newGraph); } for (Graph outputPag : this.finalResult) { @@ -535,8 +546,9 @@ public List search() { return this.output; } - // returns total runtime and times for hitting set calculations - + /** + * @return The total runtime and times for hitting set calculations. + */ public List getRuntime() { double totalhit = 0; double longesthit = 0; @@ -556,8 +568,9 @@ public List getRuntime() { return list; } - // returns the maximum memory used in a run of ION - + /** + * @return The maximum memory used in a run of ION + */ public double getMaxMemUsage() { return this.maxMemory; } @@ -584,6 +597,10 @@ public List getIterations() { // summarizes time and hitting set time and size information for latex + /** + * Summarizes time and hitting set time and size information for latex + * @return A string summarizing this information. + */ public String getStats() { String stats = "Total running time: " + this.runtime + "\\\\"; int totalit = 0; @@ -658,12 +675,11 @@ private Set nonadjacencies(Graph graph) { return nonadjacencies; } - /* + /** * Transfers local information from the input PAGs by adding edges from * local PAGs with their orientations and unorienting the edges if there * is a conflict and recording definite noncolliders. */ - private void transferLocal(Graph graph) { Set nonadjacencies = nonadjacencies(graph); for (Graph pag : this.input) { @@ -724,11 +740,10 @@ private Set getAllTriples(Graph graph) { return triples; } - /* + /** * @return variable pairs that are not in the intersection of the variable * sets for any two input PAGs */ - private List nonIntersection(Graph graph) { List> varsets = new ArrayList<>(); for (Graph inputPag : this.input) { @@ -1030,7 +1045,6 @@ private List possRemove(Graph pag, Map necEdges) { /* * Does the final set of orientations after colliders have been oriented */ - private void doFinalOrientation(Graph graph) { this.discrimGraphs.clear(); Set currentDiscrimGraphs = new HashSet<>(); @@ -1104,7 +1118,6 @@ private void doubleTriangle(Graph graph) { } // Does only the ancestor and cycle rules of these repeatedly until no changes - private void awayFromAncestorCycle(Graph graph) { while (this.changeFlag) { this.changeFlag = false; @@ -1137,7 +1150,6 @@ private void awayFromAncestorCycle(Graph graph) { // Does all 3 of these rules at once instead of going through all // triples multiple times per iteration of doFinalOrientation. - private void awayFromColliderAncestorCycle(Graph graph) { List nodes = graph.getNodes(); @@ -1166,7 +1178,6 @@ private void awayFromColliderAncestorCycle(Graph graph) { } /// R1, away from collider - private void ruleR1(Node a, Node b, Node c, Graph graph) { if (graph.isAdjacentTo(a, c)) { return; @@ -1184,7 +1195,6 @@ private void ruleR1(Node a, Node b, Node c, Graph graph) { //if Ao->c and a-->b-->c, then a-->c // Zhang's rule R2, awy from ancestor. - private void ruleR2(Node a, Node b, Node c, Graph graph) { if (!graph.isAdjacentTo(a, c)) { return; @@ -1208,7 +1218,6 @@ private void ruleR2(Node a, Node b, Node c, Graph graph) { } } - private boolean isArrowpointAllowed(Graph graph, Node x, Node y) { if (graph.getEndpoint(x, y) == Endpoint.ARROW) { return true; @@ -1275,7 +1284,6 @@ private void awayFromAncestor(Graph graph, Node a, Node b, Node c) { } //if Ao->c and a-->b-->c, then a-->c - private void awayFromCycle(Graph graph, Node a, Node b, Node c) { if ((graph.isAdjacentTo(a, c)) && (graph.getEndpoint(a, c) == Endpoint.ARROW) && @@ -1591,7 +1599,6 @@ public String toString() { * @param The type of elements in the Collection passed to the constructor. * @author pingel */ - private static class PowerSet implements Iterable> { Collection all; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonHittingSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonHittingSet.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java index 0b1aadda71..b01077bcff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IonHittingSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java @@ -19,7 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; + +import edu.cmu.tetrad.search.GraphChange; import java.util.ArrayList; import java.util.LinkedList; From 1a39c9dd5b10fa96d23243369f4c92d6034f8573 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 07:47:15 -0400 Subject: [PATCH 273/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algorithm/multi/FasLofs.java | 6 +- .../algorithm/multi/FaskLofsConcatenated.java | 6 +- .../algcomparison/algorithm/pairwise/Eb.java | 6 +- .../algcomparison/algorithm/pairwise/R1.java | 6 +- .../algcomparison/algorithm/pairwise/R2.java | 6 +- .../algcomparison/algorithm/pairwise/R3.java | 6 +- .../algorithm/pairwise/Rskew.java | 6 +- .../algorithm/pairwise/RskewE.java | 6 +- .../algorithm/pairwise/Skew.java | 6 +- .../algorithm/pairwise/SkewE.java | 6 +- .../algorithm/pairwise/Tanh.java | 6 +- .../java/edu/cmu/tetrad/search/FasLofs.java | 6 +- .../main/java/edu/cmu/tetrad/search/Lofs.java | 1686 +++++++++++++-- .../java/edu/cmu/tetrad/search/Lofs2.java | 1904 ----------------- .../edu/cmu/tetrad/search/WIP/LofsOld.java | 673 ++++++ 15 files changed, 2168 insertions(+), 2167 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs2.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java index 09de8ce56a..bdda1f3c3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -26,10 +26,10 @@ */ public class FasLofs implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; - private final Lofs2.Rule rule; + private final Lofs.Rule rule; private Knowledge knowledge = new Knowledge(); - public FasLofs(Lofs2.Rule rule) { + public FasLofs(Lofs.Rule rule) { this.rule = rule; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java index 9240aec56a..ded02c1fd5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.FasLofs; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -29,10 +29,10 @@ @Bootstrapping public class FaskLofsConcatenated implements MultiDataSetAlgorithm, HasKnowledge { static final long serialVersionUID = 23L; - private final Lofs2.Rule rule; + private final Lofs.Rule rule; private Knowledge knowledge = new Knowledge(); - public FaskLofsConcatenated(Lofs2.Rule rule) { + public FaskLofsConcatenated(Lofs.Rule rule) { this.rule = rule; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java index a02b9df69d..5ed8f33ff2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -59,8 +59,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.EB); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.EB); return lofs.orient(); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java index afa98650d4..4f34e1edbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -58,8 +58,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.R1); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.R1); return lofs.orient(); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java index fa9eeac66c..13389b2a0b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -58,8 +58,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.R2); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.R2); return lofs.orient(); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java index 411fe5e0e8..a159901bd6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java @@ -10,7 +10,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -59,8 +59,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.R3); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.R3); return lofs.orient(); } else { 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 index 291d517d5c..014a6b2eb4 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 @@ -10,7 +10,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -58,8 +58,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.RSkew); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.RSkew); return lofs.orient(); } else { 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/RskewE.java index ed684aa7ca..96843f8493 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/RskewE.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -60,8 +60,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.RSkewE); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.RSkewE); return lofs.orient(); } else { 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 index 2c9871e465..885fa8a15c 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 @@ -10,7 +10,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -59,8 +59,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.Skew); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.Skew); return lofs.orient(); } else { 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/SkewE.java index f3642b96da..9f3c487fbc 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/SkewE.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -58,8 +58,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.SkewE); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.SkewE); return lofs.orient(); } else { 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/Tanh.java index 6e84ae7447..b69e81a75d 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/Tanh.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Lofs2; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -50,8 +50,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { List dataSets = new ArrayList<>(); dataSets.add(SimpleDataLoader.getContinuousDataSet(dataSet)); - Lofs2 lofs = new Lofs2(this.externalGraph, dataSets); - lofs.setRule(Lofs2.Rule.Tanh); + Lofs lofs = new Lofs(this.externalGraph, dataSets); + lofs.setRule(Lofs.Rule.Tanh); return lofs.orient(); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java index 697b08890f..b3ab159a3c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java @@ -38,7 +38,7 @@ */ public final class FasLofs implements GraphSearch { - private final Lofs2.Rule rule; + private final Lofs.Rule rule; // Elapsed time of the search, in milliseconds. private long elapsed; @@ -59,7 +59,7 @@ public final class FasLofs implements GraphSearch { /** * @param dataSet These datasets to analyze. */ - public FasLofs(DataSet dataSet, Lofs2.Rule rule) { + public FasLofs(DataSet dataSet, Lofs.Rule rule) { this.dataSet = dataSet; this.rule = rule; } @@ -93,7 +93,7 @@ public Graph search() { System.out.println("LOFS orientation, rule " + this.rule); - Lofs2 lofs2 = new Lofs2(G0, Collections.singletonList(this.dataSet)); + Lofs lofs2 = new Lofs(G0, Collections.singletonList(this.dataSet)); lofs2.setRule(this.rule); lofs2.setKnowledge(this.knowledge); Graph graph = lofs2.orient(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 6b29bf1474..fe8a1bdfe6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -21,102 +21,345 @@ package edu.cmu.tetrad.search; -import cern.colt.list.DoubleArrayList; -import cern.jet.stat.Descriptive; -import edu.cmu.tetrad.data.AndersonDarlingTest; -import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.util.Vector; import edu.cmu.tetrad.util.*; +import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression; import org.apache.commons.math3.util.FastMath; import java.util.*; +import static edu.cmu.tetrad.util.MatrixUtils.transpose; +import static edu.cmu.tetrad.util.StatUtils.*; +import static java.lang.Double.isNaN; +import static org.apache.commons.math3.util.FastMath.pow; +import static org.apache.commons.math3.util.FastMath.*; + /** - * LOFS = Ling Orientation Fixed Structure. + * LOFS = Ling Orientation Fixed Structure. Some additional algorithm. + *

+ * Expands the set of algorithm from Lofs. * * @author Joseph Ramsey */ public class Lofs { - private final Graph cpdag; - private final List dataSets; - private double alpha = 0.05; - private final ArrayList regressions; - private final List variables; - private final boolean strongR2; - private final boolean meekDone; - private final boolean meanCenterResiduals; public enum Score { andersonDarling, skew, kurtosis, fifthMoment, absoluteValue, exp, expUnstandardized, expUnstandardizedInverted, other, logcosh, entropy } - private Score score = Score.andersonDarling; + private final Graph CPDAG; + private List dataSets; + private List matrices; + private double alpha = 1.1; + private List regressions; + private List variables; + private boolean orientStrongerDirection; + private boolean r2Orient2Cycles = true; + + private Lofs.Score score = Lofs.Score.andersonDarling; + private double epsilon = 1.0; + private Knowledge knowledge = new Knowledge(); + private Rule rule = Rule.R1; + private double selfLoopStrength; //===============================CONSTRUCTOR============================// - public Lofs(Graph cpdag, List dataSets, boolean strongR2, boolean meekDone, boolean meanCenterResiduals) + public Lofs(Graph CPDAG, List dataSets) throws IllegalArgumentException { - this.strongR2 = strongR2; - this.meekDone = meekDone; - this.meanCenterResiduals = meanCenterResiduals; - - if (cpdag == null) { - throw new IllegalArgumentException("CPDAG must be specified."); - } if (dataSets == null) { throw new IllegalArgumentException("Data set must be specified."); } - this.cpdag = cpdag; - this.dataSets = dataSets; + if (CPDAG == null) { + throw new IllegalArgumentException("CPDAG must be specified."); + } - this.regressions = new ArrayList<>(); + this.CPDAG = CPDAG; this.variables = dataSets.get(0).getVariables(); - for (DataSet dataSet : dataSets) { - this.regressions.add(new RegressionDataset(dataSet)); + List dataSets2 = new ArrayList<>(); + + for (DataSet set : dataSets) { + DataSet dataSet = new BoxDataSet(new DoubleDataBox(set.getDoubleData().toArray()), this.variables); + dataSets2.add(dataSet); } + + this.dataSets = dataSets2; + } + + //==========================PUBLIC=========================================// + + public void setRule(Rule rule) { + this.rule = rule; + } + + public double getSelfLoopStrength() { + return this.selfLoopStrength; + } + + public void setSelfLoopStrength(double selfLoopStrength) { + this.selfLoopStrength = selfLoopStrength; + } + + // orientStrongerDirection list of past and present rules. + public enum Rule { + IGCI, R1TimeLag, R1, R2, R3, Tanh, EB, Skew, SkewE, RSkew, RSkewE, + Patel, Patel25, Patel50, Patel75, Patel90, FastICA, RC } public Graph orient() { - Graph skeleton = GraphUtils.undirectedGraph(getCpdag()); + + Graph skeleton = GraphUtils.undirectedGraph(getCPDAG()); Graph graph = new EdgeListGraph(skeleton.getNodes()); List nodes = skeleton.getNodes(); -// RandomUtil.shuffle(nodes); - if (isR1Done()) { + if (this.rule == Rule.R1TimeLag) { + ruleR1TimeLag(skeleton, graph); + } else if (this.rule == Rule.R1) { ruleR1(skeleton, graph, nodes); + } else if (this.rule == Rule.R2) { + graph = GraphUtils.undirectedGraph(skeleton); + ruleR2(graph, graph); + } else if (this.rule == Rule.R3) { + graph = GraphUtils.undirectedGraph(skeleton); + ruleR3(graph); + } else if (this.rule == Rule.EB) { + graph = GraphUtils.undirectedGraph(skeleton); + return entropyBased(graph); + } else if (this.rule == Rule.Tanh) { + graph = GraphUtils.undirectedGraph(skeleton); + return tanhGraph(graph); + } else if (this.rule == Rule.Skew) { + graph = GraphUtils.undirectedGraph(skeleton); + return skewGraph(graph, false); + } else if (this.rule == Rule.SkewE) { + graph = GraphUtils.undirectedGraph(skeleton); + return skewGraph(graph, true); + } else if (this.rule == Rule.RSkew) { + graph = GraphUtils.undirectedGraph(skeleton); + return robustSkewGraph(graph, false); + } else if (this.rule == Rule.RSkewE) { + graph = GraphUtils.undirectedGraph(skeleton); + return robustSkewGraph(graph, true); + } else if (this.rule == Rule.IGCI) { + graph = GraphUtils.undirectedGraph(skeleton); + return igci(graph); + } else if (this.rule == Rule.RC) { + graph = GraphUtils.undirectedGraph(skeleton); + return resolveEdgeConditional(graph); + } else if (this.rule == Rule.Patel) { + graph = GraphUtils.undirectedGraph(skeleton); + return patelTauOrientation(graph, Double.NaN); + } else if (this.rule == Rule.Patel25) { + graph = GraphUtils.undirectedGraph(skeleton); + return patelTauOrientation(graph, 0.25); + } else if (this.rule == Rule.Patel50) { + graph = GraphUtils.undirectedGraph(skeleton); + return patelTauOrientation(graph, 0.50); + } else if (this.rule == Rule.Patel75) { + graph = GraphUtils.undirectedGraph(skeleton); + return patelTauOrientation(graph, 0.75); + } else if (this.rule == Rule.Patel90) { + graph = GraphUtils.undirectedGraph(skeleton); + return patelTauOrientation(graph, 0.90); + } else if (this.rule == Rule.FastICA) { + FastIca fastIca = new FastIca(this.dataSets.get(0).getDoubleData(), + this.dataSets.get(0).getNumColumns()); + FastIca.IcaResult result = fastIca.findComponents(); + System.out.println(result.getW()); + return new EdgeListGraph(); } - for (Edge edge : skeleton.getEdges()) { - if (!graph.isAdjacentTo(edge.getNode1(), edge.getNode2())) { - graph.addUndirectedEdge(edge.getNode1(), edge.getNode2()); + return graph; + } + + public double getAlpha() { + return this.alpha; + } + + public void setAlpha(double alpha) { + if (alpha < 0.0 || alpha > 1.0) { + throw new IllegalArgumentException("Alpha is in range [0, 1]"); + } + + this.alpha = alpha; + } + + public boolean isOrientStrongerDirection() { + return this.orientStrongerDirection; + } + + public void setOrientStrongerDirection(boolean orientStrongerDirection) { + this.orientStrongerDirection = orientStrongerDirection; + } + + public void setR2Orient2Cycles(boolean r2Orient2Cycles) { + this.r2Orient2Cycles = r2Orient2Cycles; + } + + public boolean isR2Orient2Cycles() { + return this.r2Orient2Cycles; + } + + public Lofs.Score getScore() { + return this.score; + } + + public void setScore(Lofs.Score score) { + if (score == null) { + throw new NullPointerException(); + } + + this.score = score; + } + + //==========================PRIVATE=======================================// + + private List getRegressions() { + if (this.regressions == null) { + List regressions = new ArrayList<>(); + this.variables = this.dataSets.get(0).getVariables(); + + for (DataSet dataSet : this.dataSets) { + regressions.add(new RegressionDataset(dataSet)); + } + + this.regressions = regressions; + } + + return this.regressions; + } + + private void setDataSets(List dataSets) { + this.dataSets = dataSets; + + this.matrices = new ArrayList<>(); + + for (DataSet dataSet : dataSets) { + this.matrices.add(dataSet.getDoubleData()); + } + } + + private void ruleR1TimeLag(Graph skeleton, Graph graph) { + List timeSeriesDataSets = new ArrayList<>(); + Knowledge knowledge = null; + List dataNodes = null; + + for (DataSet dataModel : this.dataSets) { + if (dataModel == null) { + throw new IllegalArgumentException("Dataset is not supplied."); + } + + DataSet lags = TimeSeriesUtils.createLagData(dataModel, 1); + if (dataModel.getName() != null) { + lags.setName(dataModel.getName()); + } + timeSeriesDataSets.add(lags); + + if (knowledge == null) { + knowledge = lags.getKnowledge(); + } + + if (dataNodes == null) { + dataNodes = lags.getVariables(); } } - if (isR2Done()) { - ruleR2(skeleton, graph); + Graph laggedSkeleton = new EdgeListGraph(dataNodes); + + for (Edge edge : skeleton.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + String node1 = edge.getNode1().getName(); + String node2 = edge.getNode2().getName(); + + Node node10 = laggedSkeleton.getNode(node1 + ":0"); + Node node20 = laggedSkeleton.getNode(node2 + ":0"); + + laggedSkeleton.addUndirectedEdge(node10, node20); + + Node node11 = laggedSkeleton.getNode(node1 + ":1"); + Node node21 = laggedSkeleton.getNode(node2 + ":1"); + + laggedSkeleton.addUndirectedEdge(node11, node21); } - if (isMeekDone()) { - new MeekRules().orientImplied(graph); + for (Node node : skeleton.getNodes()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + String _node = node.getName(); + + Node node0 = laggedSkeleton.getNode(_node + ":0"); + Node node1 = laggedSkeleton.getNode(_node + ":1"); + + laggedSkeleton.addUndirectedEdge(node0, node1); } - return graph; + Lofs lofs = new Lofs(laggedSkeleton, timeSeriesDataSets); + lofs.setKnowledge(knowledge); + lofs.setRule(Rule.R1); + Graph _graph = lofs.orient(); + + graph.removeEdges(new ArrayList<>(graph.getEdges())); + + for (Edge edge : _graph.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node node1 = edge.getNode1(); + Node node2 = edge.getNode2(); + Endpoint end1 = edge.getEndpoint1(); + Endpoint end2 = edge.getEndpoint2(); + + String index1 = node1.getName().split(":")[1]; + String index2 = node2.getName().split(":")[1]; + + if ("1".equals(index1) || "1".equals(index2)) continue; + + String name1 = node1.getName().split(":")[0]; + String name2 = node2.getName().split(":")[0]; + + Node _node1 = graph.getNode(name1); + Node _node2 = graph.getNode(name2); + + Edge _edge = new Edge(_node1, _node2, end1, end2); + graph.addEdge(_edge); + } } private void ruleR1(Graph skeleton, Graph graph, List nodes) { + List centeredData = DataUtils.center(this.dataSets); + setDataSets(centeredData); + for (Node node : nodes) { + if (Thread.currentThread().isInterrupted()) { + break; + } + SortedMap scoreReports = new TreeMap<>(); - List adj = skeleton.getAdjacentNodes(node); + List adj = new ArrayList<>(); + + for (Node _node : skeleton.getAdjacentNodes(node)) { + if (this.knowledge.isForbidden(_node.getName(), node.getName())) { + continue; + } + + adj.add(_node); + } SublistGenerator gen = new SublistGenerator(adj.size(), adj.size()); int[] choice; @@ -124,6 +367,10 @@ private void ruleR1(Graph skeleton, Graph graph, List nodes) { List parents = null; while ((choice = gen.next()) != null) { + if (Thread.currentThread().isInterrupted()) { + break; + } + List _parents = GraphUtils.asList(choice, adj); double score = score(node, _parents); @@ -145,9 +392,11 @@ private void ruleR1(Graph skeleton, Graph graph, List nodes) { continue; } - if (normal(node, parents)) continue; - for (Node _node : adj) { + if (Thread.currentThread().isInterrupted()) { + break; + } + if (parents.contains(_node)) { Edge parentEdge = Edges.directedEdge(_node, node); @@ -157,13 +406,29 @@ private void ruleR1(Graph skeleton, Graph graph, List nodes) { } } } + + for (Edge edge : skeleton.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + if (!graph.isAdjacentTo(edge.getNode1(), edge.getNode2())) { + graph.addUndirectedEdge(edge.getNode1(), edge.getNode2()); + } + } } private void ruleR2(Graph skeleton, Graph graph) { + List standardized = DataUtils.standardizeData(this.dataSets); + setDataSets(standardized); + Set edgeList1 = skeleton.getEdges(); -// RandomUtil.shuffle(edgeList1); for (Edge adj : edgeList1) { + if (Thread.currentThread().isInterrupted()) { + break; + } + Node x = adj.getNode1(); Node y = adj.getNode2(); @@ -175,46 +440,29 @@ private void ruleR2(Graph skeleton, Graph graph) { continue; } - resolveOneEdgeMax(graph, x, y, isStrongR2()); + resolveOneEdgeMax2(graph, x, y, !isOrientStrongerDirection()); } } - private boolean isTwoCycle(Graph graph, Node x, Node y) { - List edges = graph.getEdges(x, y); - return edges.size() == 2; - } - - private boolean isUndirected(Graph graph, Node x, Node y) { - List edges = graph.getEdges(x, y); - if (edges.size() == 1) { - Edge edge = graph.getEdge(x, y); - return Edges.isUndirectedEdge(edge); - } + private void resolveOneEdgeMax2(Graph graph, Node x, Node y, boolean strong) { + TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y); - return false; - } + SortedMap scoreReports = new TreeMap<>(); - private boolean normal(Node node, List parents) { - if (getAlpha() > .999) { - return false; - } + List neighborsx = new ArrayList<>(); - return pValue(node, parents) > getAlpha(); - } + for (Node _node : graph.getAdjacentNodes(x)) { + if (Thread.currentThread().isInterrupted()) { + break; + } - private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { - if (RandomUtil.getInstance().nextDouble() > 0.5) { - Node temp = x; - x = y; - y = temp; + if (!this.knowledge.isForbidden(_node.getName(), x.getName())) { +// if (!knowledge.edgeForbidden(x.getNode(), _node.getNode())) { + neighborsx.add(_node); + } } - TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y); - - SortedMap scoreReports = new TreeMap<>(); - - List neighborsx = graph.getAdjacentNodes(x); - neighborsx.remove(y); +// neighborsx.remove(y); double max = Double.NEGATIVE_INFINITY; boolean left = false; @@ -224,33 +472,65 @@ private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { int[] choicex; while ((choicex = genx.next()) != null) { + if (Thread.currentThread().isInterrupted()) { + break; + } + List condxMinus = GraphUtils.asList(choicex, neighborsx); + if (condxMinus.contains(y)) continue; + List condxPlus = new ArrayList<>(condxMinus); + condxPlus.add(y); double xPlus = score(x, condxPlus); double xMinus = score(x, condxMinus); - List neighborsy = graph.getAdjacentNodes(y); - neighborsy.remove(x); + double p = pValue(x, condxPlus); + + if (p > this.alpha) { + continue; + } + + double p2 = pValue(x, condxMinus); + + if (p2 > this.alpha) { + continue; + } + + List neighborsy = new ArrayList<>(); + + for (Node _node : graph.getAdjacentNodes(y)) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + if (!this.knowledge.isForbidden(_node.getName(), y.getName())) { + neighborsy.add(_node); + } + } SublistGenerator geny = new SublistGenerator(neighborsy.size(), neighborsy.size()); int[] choicey; while ((choicey = geny.next()) != null) { + if (Thread.currentThread().isInterrupted()) { + break; + } + List condyMinus = GraphUtils.asList(choicey, neighborsy); + if (condyMinus.contains(x)) continue; + List condyPlus = new ArrayList<>(condyMinus); condyPlus.add(x); double yPlus = score(y, condyPlus); double yMinus = score(y, condyMinus); - // Checking them all at once is expensive but avoids lexical ordering problems in the algorithm. - if (normal(y, condyPlus) || normal(x, condxMinus) || normal(x, condxPlus) || normal(y, condyMinus)) { - continue; - } + boolean forbiddenLeft = this.knowledge.isForbidden(y.getName(), x.getName()); + boolean forbiddenRight = this.knowledge.isForbidden(x.getName(), y.getName()); final double delta = 0.0; @@ -258,7 +538,8 @@ private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { if (yPlus <= xPlus + delta && xMinus <= yMinus + delta) { double score = combinedScore(xPlus, yMinus); - if (yPlus <= yMinus + delta && xMinus <= xPlus + delta) { + if ((yPlus <= yMinus + delta && xMinus <= xPlus + delta) || forbiddenRight) { + String s = "\nStrong " + y + "->" + x + " " + score + "\n Parents(" + x + ") = " + condxMinus + "\n Parents(" + y + ") = " + condyMinus; @@ -271,16 +552,18 @@ private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { right = false; } } else { + String s = "\nNo directed edge " + x + "--" + y + " " + score + "\n Parents(" + x + ") = " + condxMinus + "\n Parents(" + y + ") = " + condyMinus; scoreReports.put(-score, s); } - } else if (xPlus <= yPlus + delta && yMinus <= xMinus + delta) { + } else if ((xPlus <= yPlus + delta && yMinus <= xMinus + delta) || forbiddenLeft) { double score = combinedScore(yPlus, xMinus); if (yMinus <= yPlus + delta && xPlus <= xMinus + delta) { + String s = "\nStrong " + x + "->" + y + " " + score + "\n Parents(" + x + ") = " + condxMinus + "\n Parents(" + y + ") = " + condyMinus; @@ -293,6 +576,7 @@ private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { right = true; } } else { + String s = "\nNo directed edge " + x + "--" + y + " " + score + "\n Parents(" + x + ") = " + condxMinus + "\n Parents(" + y + ") = " + condyMinus; @@ -317,7 +601,7 @@ private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { scoreReports.put(-score, s); } } else { - if (yPlus <= xPlus + delta && xMinus <= yMinus + delta) { + if ((yPlus <= xPlus + delta && xMinus <= yMinus + delta) || forbiddenRight) { double score = combinedScore(xPlus, yMinus); String s = "\nWeak " + y + "->" + x + " " + score + @@ -331,7 +615,7 @@ private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { left = true; right = false; } - } else if (xPlus <= yPlus + delta && yMinus <= xMinus + delta) { + } else if ((xPlus <= yPlus + delta && yMinus <= xMinus + delta) || forbiddenLeft) { double score = combinedScore(yPlus, xMinus); String s = "\nWeak " + x + "->" + y + " " + score + @@ -385,138 +669,832 @@ private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { } } - private double combinedScore(double score1, double score2) { - return score1 + score2; - } - private double score(Node y, List parents) { - if (this.score == Score.andersonDarling) { - return andersonDarlingPASquareStar(y, parents); - } else if (this.score == Score.kurtosis) { - return FastMath.abs(StatUtils.kurtosis(residual(y, parents))); - } else if (this.score == Score.skew) { - return FastMath.abs(StatUtils.skewness(residual(y, parents))); - } else if (this.score == Score.fifthMoment) { - return FastMath.abs(StatUtils.standardizedFifthMoment(residual(y, parents))); - } else if (this.score == Score.absoluteValue) { - return localScoreA(y, parents); - } + private void ruleR3(Graph graph) { + List standardized = DataUtils.standardizeData(this.dataSets); + setDataSets(standardized); - throw new IllegalStateException(); - } + Set edgeList1 = graph.getEdges(); - //=============================PRIVATE METHODS=========================// + for (Edge adj : edgeList1) { + if (Thread.currentThread().isInterrupted()) { + break; + } - private double localScoreA(Node node, List parents) { - double score = 0.0; + Node x = adj.getNode1(); + Node y = adj.getNode2(); - List _residuals = new ArrayList<>(); + resolveOneEdgeMaxR3(graph, x, y); + } - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); + } - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); - } + private void resolveOneEdgeMaxR3(Graph graph, Node x, Node y) { + String xname = x.getName(); + String yname = y.getName(); - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); + if (this.knowledge.isForbidden(yname, xname) || this.knowledge.isRequired(xname, yname)) { + graph.removeEdge(x, y); + graph.addDirectedEdge(x, y); + return; + } else if (this.knowledge.isForbidden(xname, yname) || this.knowledge.isRequired(yname, xname)) { + graph.removeEdge(y, x); + graph.addDirectedEdge(y, x); + return; + } - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { - continue DATASET; - } - } +// TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y); - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + List condxMinus = Collections.emptyList(); + List condxPlus = Collections.singletonList(y); + List condyMinus = Collections.emptyList(); + List condyPlus = Collections.singletonList(x); - double mean = Descriptive.mean(_residualsSingleDataset); - double std = Descriptive.standardDeviation(Descriptive.variance(_residualsSingleDataset.size(), - Descriptive.sum(_residualsSingleDataset), Descriptive.sumOfSquares(_residualsSingleDataset))); + double xPlus = score(x, condxPlus); + double xMinus = score(x, condxMinus); - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean) / std); - } + double yPlus = score(y, condyPlus); + double yMinus = score(y, condyMinus); - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); - } - } +// if (!(xPlus > 0.8 && xMinus > 0.8 && yPlus > 0.8 && yMinus > 0.8)) return; - double[] _f = new double[_residuals.size()]; + double deltaX = xPlus - xMinus; + double deltaY = yPlus - yMinus; + graph.removeEdges(x, y); +// double epsilon = 0; - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); + if (deltaY > deltaX) { + graph.addDirectedEdge(x, y); + } else { + graph.addDirectedEdge(y, x); } + } - DoubleArrayList f = new DoubleArrayList(_f); + private double[] col; - for (int k = 0; k < _residuals.size(); k++) { - f.set(k, FastMath.abs(f.get(k))); + // rowIndex is for the W matrix, not for the data. + public double scoreRow(int rowIndex, Matrix data, List> rows, List> parameters) { + if (this.col == null) { + this.col = new double[data.rows()]; } - double _mean = Descriptive.mean(f); - double diff = _mean - FastMath.sqrt(2.0 / FastMath.PI); - score += diff * diff; + List cols = rows.get(rowIndex); - return score; - } + for (int i = 0; i < data.rows(); i++) { + if (Thread.currentThread().isInterrupted()) { + break; + } - private double andersonDarlingPASquareStar(Node node, List parents) { - List _residuals = new ArrayList<>(); + double d = 0.0; - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); + for (int j = 0; j < cols.size(); j++) { + if (Thread.currentThread().isInterrupted()) { + break; + } - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); + int _j = cols.get(j); + double coef = parameters.get(rowIndex).get(j); + double value = data.get(i, _j); + d += coef * value; + } + + // Add in the diagonal, assumed to consist entirely of 1's, indicating no self loop. + d += (1.0 - getSelfLoopStrength()) * data.get(i, rowIndex); + + this.col[i] = d; } - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); + return score(this.col); + } - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { - continue DATASET; - } + private Graph entropyBased(Graph graph) { + DataSet dataSet = DataUtils.concatenate(this.dataSets); + dataSet = DataUtils.standardizeData(dataSet); + Graph _graph = new EdgeListGraph(graph.getNodes()); + + for (Edge edge : graph.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; } - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + Node x = edge.getNode1(); + Node y = edge.getNode2(); - double mean = Descriptive.mean(_residualsSingleDataset); + Node _x = dataSet.getVariable(x.getName()); + Node _y = dataSet.getVariable(y.getName()); - // By centering the individual residual columns, all moments of the mixture become weighted - // averages of the momentsof the individual columns. http://en.wikipedia.org/wiki/Mixture_ - // distribution#Finite_and_countable_mixtures - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - if (isMeanCenterResiduals()) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); - } - } + List ret = extractData(dataSet, _x, _y); - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); + double[] xData = ret.get(0); + double[] yData = ret.get(1); + + double[] d = new double[xData.length]; + double[] e = new double[xData.length]; + + double cov = covariance(xData, yData); + + for (int i = 0; i < xData.length; i++) { + d[i] = yData[i] - cov * xData[i]; // y regressed on x + e[i] = xData[i] - cov * yData[i]; // x regressed on y } - } - double[] _f = new double[_residuals.size()]; + double R = -maxEntApprox(xData) - maxEntApprox(d) + + maxEntApprox(yData) + maxEntApprox(e); - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); + if (R > 0) { + _graph.addDirectedEdge(x, y); + } else { + _graph.addDirectedEdge(y, x); + } } - return new AndersonDarlingTest(_f).getASquaredStar(); + return _graph; } - private double pValue(Node node, List parents) { - List _residuals = new ArrayList<>(); + private Graph tanhGraph(Graph graph) { + DataSet dataSet = DataUtils.concatenate(this.dataSets); + graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); + dataSet = DataUtils.standardizeData(dataSet); + double[][] data = dataSet.getDoubleData().transpose().toArray(); + Graph _graph = new EdgeListGraph(graph.getNodes()); + List nodes = dataSet.getVariables(); + Map nodesHash = new HashMap<>(); + + for (int i = 0; i < nodes.size(); i++) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + nodesHash.put(nodes.get(i), i); + } + + for (Edge edge : graph.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node x = edge.getNode1(); + Node y = edge.getNode2(); + + double sumX = 0.0; + int countX = 0; + + double[] xData = data[nodesHash.get(edge.getNode1())]; + double[] yData = data[nodesHash.get(edge.getNode2())]; + + for (int i = 0; i < xData.length; i++) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + double x0 = xData[i]; + double y0 = yData[i]; + + double termX = (x0 * tanh(y0) - tanh(x0) * y0); + + sumX += termX; + countX++; + } + + double R = sumX / countX; + + double rhoX = regressionCoef(xData, yData); + R *= rhoX; + + if (R > 0) { + _graph.addDirectedEdge(x, y); + } else { + _graph.addDirectedEdge(y, x); + } + } + + return _graph; + } + + + // @param empirical True if the skew signs are estimated empirically. + private Graph skewGraph(Graph graph, boolean empirical) { + DataSet dataSet = DataUtils.concatenate(this.dataSets); + graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); + dataSet = DataUtils.standardizeData(dataSet); + double[][] data = dataSet.getDoubleData().transpose().toArray(); + Graph _graph = new EdgeListGraph(graph.getNodes()); + List nodes = dataSet.getVariables(); + Map nodesHash = new HashMap<>(); + + for (int i = 0; i < nodes.size(); i++) { + nodesHash.put(nodes.get(i), i); + } + + for (Edge edge : graph.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node x = edge.getNode1(); + Node y = edge.getNode2(); + + double sumX = 0.0; + int countX = 0; + + int _i = nodesHash.get(edge.getNode1()); + int _j = nodesHash.get(edge.getNode2()); + + double[] xData = data[_i]; + double[] yData = data[_j]; + + if (empirical) { + xData = correctSkewnesses(xData); + yData = correctSkewnesses(yData); + } + + for (int i = 0; i < xData.length; i++) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + double x0 = xData[i]; + double y0 = yData[i]; + + double termX = x0 * x0 * y0 - x0 * y0 * y0; + + sumX += termX; + countX++; + } + + double R = sumX / countX; + + double rhoX = regressionCoef(xData, yData); + + R *= rhoX; + + if (R > 0) { + _graph.addDirectedEdge(x, y); + } else { + _graph.addDirectedEdge(y, x); + } + } + + return _graph; + + } + + // @param empirical True if the skew signs are estimated empirically. + private Graph robustSkewGraph(Graph graph, boolean empirical) { + // DataUtils.standardizeData(dataSet)); + List _dataSets = new ArrayList<>(this.dataSets); + DataSet dataSet = DataUtils.concatenate(_dataSets); + graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); + dataSet = DataUtils.standardizeData(dataSet); + double[][] data = dataSet.getDoubleData().transpose().toArray(); + List nodes = dataSet.getVariables(); + Map nodesHash = new HashMap<>(); + + for (int i = 0; i < nodes.size(); i++) { + nodesHash.put(nodes.get(i), i); + } + + for (Edge edge : graph.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node x = edge.getNode1(); + Node y = edge.getNode2(); + + double[] xData = data[nodesHash.get(edge.getNode1())]; + double[] yData = data[nodesHash.get(edge.getNode2())]; + + if (empirical) { + xData = correctSkewnesses(xData); + yData = correctSkewnesses(yData); + } + + double[] xx = new double[xData.length]; + double[] yy = new double[yData.length]; + + for (int i = 0; i < xData.length; i++) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + double xi = xData[i]; + double yi = yData[i]; + + double s1 = g(xi) * yi; + double s2 = xi * g(yi); + + xx[i] = s1; + yy[i] = s2; + } + + double mxx = mean(xx); + double myy = mean(yy); + + graph.removeEdge(edge); + + if (mxx > myy) { + graph.addDirectedEdge(x, y); + } else if (myy > mxx) { + graph.addDirectedEdge(y, x); + } else { + graph.addUndirectedEdge(x, y); + } + } + + return graph; + } + + private double g(double x) { + return log(cosh(FastMath.max(x, 0))); + } + + // cutoff is NaN if no thresholding is to be done, otherwise a threshold between 0 and 1. + private Graph patelTauOrientation(Graph graph, double cutoff) { + List centered = DataUtils.center(this.dataSets); + DataSet concat = DataUtils.concatenate(centered); + DataSet dataSet = DataUtils.standardizeData(concat); + + Graph _graph = new EdgeListGraph(graph.getNodes()); + + for (Edge edge : graph.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node x = edge.getNode1(); + Node y = edge.getNode2(); + + Node _x = dataSet.getVariable(x.getName()); + Node _y = dataSet.getVariable(y.getName()); + + List ret = prepareData(dataSet, _x, _y); + double[] xData = ret.get(0); + double[] yData = ret.get(1); + + double R = patelTau(xData, yData, cutoff); + + if (R > 0) { + _graph.addDirectedEdge(x, y); + } else { + _graph.addDirectedEdge(y, x); + } + } + + System.out.println(_graph); + + return _graph; + } + + // cutoff is NaN if no thresholding is to be done, otherwise a threshold between 0 and 1. + private double patelTau(double[] d1in, double[] d2in, double cutoff) { + double grotMIN = percentile(d1in, 10); + double grotMAX = percentile(d1in, 90); + + final double XT = .25; // Cancels out, don't know why this is here. + + double[] d1b = new double[d1in.length]; + + for (int i = 0; i < d1b.length; i++) { + double y1 = (d1in[i] - grotMIN) / (grotMAX - grotMIN); + double y2 = FastMath.min(y1, 1.0); + double y3 = FastMath.max(y2, 0.0); + d1b[i] = y3; + } + + if (!isNaN(cutoff)) { + for (int i = 0; i < d1b.length; i++) { + if (d1b[i] > cutoff) d1b[i] = 1.0; + else d1b[i] = 0.0; + } + } + + grotMIN = percentile(d2in, 10); + grotMAX = percentile(d2in, 90); + + double[] d2b = new double[d2in.length]; + + for (int i = 0; i < d2b.length; i++) { + double y1 = (d2in[i] - grotMIN) / (grotMAX - grotMIN); + double y2 = FastMath.min(y1, 1.0); + double y3 = FastMath.max(y2, 0.0); + d2b[i] = y3; + } + + if (!isNaN(cutoff)) { + for (int i = 0; i < d2b.length; i++) { + if (d2b[i] > cutoff) d2b[i] = 1.0; + else d2b[i] = 0.0; + } + } + + double theta1 = dotProduct(d1b, d2b) / XT; + double theta2 = dotProduct(d1b, minus(d2b)) / XT; + double theta3 = dotProduct(d2b, minus(d1b)) / XT; +// double theta4= dotProduct(minus(1, d1b), minus(1, d2b))/XT; + + double tau_12; + + if (theta2 > theta3) tau_12 = 1 - (theta1 + theta3) / (theta1 + theta2); + else tau_12 = (theta1 + theta2) / (theta1 + theta3) - 1; + + return -tau_12; + } + + private double dotProduct(double[] x, double[] y) { + double p = 0.0; + + for (int i = 0; i < x.length; i++) { + p += x[i] * y[i]; + } + + return p; + } + + private double[] minus(double[] x) { + double[] y = new double[x.length]; + + for (int i = 0; i < x.length; i++) { + y[i] = 1 - x[i]; + } + + return y; + } + + private double percentile(double[] x, double percent) { + double[] _x = Arrays.copyOf(x, x.length); + Arrays.sort(_x); + return _x[(int) (x.length * (percent / 100.0))]; + } + + private List extractData(DataSet data, Node _x, Node _y) { + int xIndex = data.getColumn(_x); + int yIndex = data.getColumn(_y); + + double[][] _data = data.getDoubleData().transpose().toArray(); + + double[] xData = _data[xIndex]; + double[] yData = _data[yIndex]; + + List xValues = new ArrayList<>(); + List yValues = new ArrayList<>(); + + for (int i = 0; i < data.getNumRows(); i++) { + if (!isNaN(xData[i]) && !isNaN(yData[i])) { + xValues.add(xData[i]); + yValues.add(yData[i]); + } + } + + xData = new double[xValues.size()]; + yData = new double[yValues.size()]; + + for (int i = 0; i < xValues.size(); i++) { + xData[i] = xValues.get(i); + yData[i] = yValues.get(i); + } + + List ret = new ArrayList<>(); + ret.add(xData); + ret.add(yData); + + return ret; + } + + private double[] correctSkewnesses(double[] data) { + double skewness = skewness(data); + double[] data2 = new double[data.length]; + for (int i = 0; i < data.length; i++) data2[i] = data[i] * signum(skewness); + return data2; + } + + private List prepareData(DataSet concatData, Node _x, Node _y) { + int xIndex = concatData.getColumn(_x); + int yIndex = concatData.getColumn(_y); + + double[] xData = concatData.getDoubleData().getColumn(xIndex).toArray(); + double[] yData = concatData.getDoubleData().getColumn(yIndex).toArray(); + + List xValues = new ArrayList<>(); + List yValues = new ArrayList<>(); + + for (int i = 0; i < concatData.getNumRows(); i++) { + if (!isNaN(xData[i]) && !isNaN(yData[i])) { + xValues.add(xData[i]); + yValues.add(yData[i]); + } + } + + xData = new double[xValues.size()]; + yData = new double[yValues.size()]; + + for (int i = 0; i < xValues.size(); i++) { + xData[i] = xValues.get(i); + yData[i] = yValues.get(i); + } + + List ret = new ArrayList<>(); + ret.add(xData); + ret.add(yData); + + return ret; + } + + private double regressionCoef(double[] xValues, double[] yValues) { + List v = new ArrayList<>(); + v.add(new GraphNode("x")); + v.add(new GraphNode("y")); + + Matrix bothData = new Matrix(xValues.length, 2); + + for (int i = 0; i < xValues.length; i++) { + bothData.set(i, 0, xValues[i]); + bothData.set(i, 1, yValues[i]); + } + + Regression regression2 = new RegressionDataset(bothData, v); + RegressionResult result; + + try { + result = regression2.regress(v.get(0), v.get(1)); + } catch (Exception e) { + return Double.NaN; + } + + return result.getCoef()[1]; + } + + private boolean isTwoCycle(Graph graph, Node x, Node y) { + List edges = graph.getEdges(x, y); + return edges.size() == 2; + } + + private boolean isUndirected(Graph graph, Node x, Node y) { + List edges = graph.getEdges(x, y); + if (edges.size() == 1) { + Edge edge = graph.getEdge(x, y); + return Edges.isUndirectedEdge(edge); + } + + return false; + } + + public void setEpsilon(double epsilon) { + this.epsilon = epsilon; + } + + public void setKnowledge(Knowledge knowledge) { + if (knowledge == null) { + throw new NullPointerException(); + } + + this.knowledge = knowledge; + } + + /** + * @return the probability associated with the most recently computed independence test. + */ + public double getPValue(double fisherZ) { + return 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(fisherZ))); + } + + private Graph igci(Graph graph) { + if (this.dataSets.size() > 1) throw new IllegalArgumentException("Expecting exactly one data set for IGCI."); + + DataSet dataSet = this.dataSets.get(0); + Matrix matrix = dataSet.getDoubleData(); + + Graph _graph = new EdgeListGraph(graph.getNodes()); + + for (Edge edge : graph.getEdges()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + Node x = edge.getNode1(); + Node y = edge.getNode2(); + + Node _x = dataSet.getVariable(x.getName()); + Node _y = dataSet.getVariable(y.getName()); + + int xIndex = dataSet.getVariables().indexOf(_x); + int yIndex = dataSet.getVariables().indexOf(_y); + + double[] xCol = matrix.getColumn(xIndex).toArray(); + double[] yCol = matrix.getColumn(yIndex).toArray(); + + double f = igci(xCol, yCol); + + graph.removeEdges(x, y); + + if (f < -this.epsilon) { + _graph.addDirectedEdge(x, y); + } else if (f > this.epsilon) { + _graph.addDirectedEdge(y, x); + } else { + if (resolveOneEdgeMaxR3(xCol, yCol) < 0) { + _graph.addDirectedEdge(x, y); + } else { + _graph.addDirectedEdge(y, x); + } + } + + } + + return _graph; + } + + private double igci(double[] x, double[] y) { + int m = x.length; + + if (m != y.length) { + throw new IllegalArgumentException("Vectors must be the same length."); + } + + // uniform reference measure + + double meanx = mean(x); + double stdx = sd(x); + double meany = mean(y); + double stdy = sd(y); + + // Gaussian reference measure + for (int i = 0; i < x.length; i++) { + x[i] = (x[i] - meanx) / stdx; + y[i] = (y[i] - meany) / stdy; + } + + + double f; + + // difference of entropies + + double[] x1 = Arrays.copyOf(x, x.length); + Arrays.sort(x1); + + x1 = removeNaN(x1); + + double[] y1 = Arrays.copyOf(y, y.length); + Arrays.sort(y1); + + y1 = removeNaN(y1); + + int n1 = x1.length; + double hx = 0.0; + for (int i = 0; i < n1 - 1; i++) { + double delta = x1[i + 1] - x1[i]; + if (delta != 0) { + hx = hx + log(abs(delta)); + } + } + + hx = hx / (n1 - 1) + psi(n1) - psi(1); + + int n2 = y1.length; + double hy = 0.0; + for (int i = 0; i < n2 - 1; i++) { + double delta = y1[i + 1] - y1[i]; + + if (delta != 0) { + if (isNaN(delta)) { + throw new IllegalArgumentException(); + } + + hy = hy + log(abs(delta)); + } + } + + hy = hy / (n2 - 1) + psi(n2) - psi(1); + + f = hy - hx; + + return f; + + } + + private double[] removeNaN(double[] data) { + List _leaveOutMissing = new ArrayList<>(); + + for (double datum : data) { + if (!isNaN(datum)) { + _leaveOutMissing.add(datum); + } + } + + double[] _data = new double[_leaveOutMissing.size()]; + + for (int i = 0; i < _leaveOutMissing.size(); i++) _data[i] = _leaveOutMissing.get(i); + + return _data; + } + + + // digamma + + double psi(double x) { + double result = 0; + double xx; + double xx2; + double xx4; + assert (x > 0); + for (; x < 7; ++x) + result -= 1 / x; + x -= 1.0 / 2.0; + xx = 1.0 / x; + xx2 = xx * xx; + xx4 = xx2 * xx2; + result += log(x) + (1. / 24.) * xx2 - (7.0 / 960.0) * xx4 + (31.0 / 8064.0) * xx4 * xx2 - (127.0 / 30720.0) * xx4 * xx4; + return result; + } + + + private double combinedScore(double score1, double score2) { + return score1 + score2; + } + + private double score(Node y, List parents) { + if (this.score == Lofs.Score.andersonDarling) { + return andersonDarlingPASquare(y, parents); + } else if (this.score == Lofs.Score.kurtosis) { + return abs(kurtosis(residuals(y, parents, true))); + } else if (this.score == Lofs.Score.entropy) { + return entropy(y, parents); + } else if (this.score == Lofs.Score.skew) { + return abs(skewness(residuals(y, parents, true))); + } else if (this.score == Lofs.Score.fifthMoment) { + return abs(standardizedFifthMoment(residuals(y, parents, true))); + } else if (this.score == Lofs.Score.absoluteValue) { + return meanAbsolute(y, parents); + } else if (this.score == Lofs.Score.exp) { + return expScoreUnstandardized(y, parents); + } else if (this.score == Lofs.Score.other) { + double[] _f = residuals(y, parents, true); + return score(_f); + } else if (this.score == Lofs.Score.logcosh) { + return logCoshScore(y, parents); + } + + throw new IllegalStateException(); + } + + private double score(double[] col) { + if (this.score == Lofs.Score.andersonDarling) { + return new AndersonDarlingTest(col).getASquaredStar(); + } else if (this.score == Lofs.Score.entropy) { + return maxEntApprox(col); + } else if (this.score == Lofs.Score.kurtosis) { + col = DataUtils.standardizeData(col); + return -abs(kurtosis(col)); + } else if (this.score == Lofs.Score.skew) { + return abs(skewness(col)); + } else if (this.score == Lofs.Score.fifthMoment) { + return abs(standardizedFifthMoment(col)); + } else if (this.score == Lofs.Score.absoluteValue) { + return StatUtils.meanAbsolute(col); + } else if (this.score == Lofs.Score.exp) { + return expScoreUnstandardized(col); + } else if (this.score == Lofs.Score.other) { + return abs(kurtosis(col)); + } else if (this.score == Lofs.Score.logcosh) { + return StatUtils.logCoshScore(col); + } + + throw new IllegalStateException("Unrecognized score: " + this.score); + } + + //=============================PRIVATE METHODS=========================// + + private double meanAbsolute(Node node, List parents) { + double[] _f = residuals(node, parents, false); + + return StatUtils.meanAbsolute(_f); + } + + private double expScoreUnstandardized(Node node, List parents) { + double[] _f = residuals(node, parents, false); + + return expScoreUnstandardized(_f); + } + + private double expScoreUnstandardized(double[] _f) { + double sum = 0.0; + + for (double v : _f) { + sum += exp(v); + } + + double expected = sum / _f.length; + return -abs(log(expected)); + } + + private double logCoshScore(Node node, List parents) { + double[] _f = residuals(node, parents, true); + return StatUtils.logCoshScore(_f); + } + + private double[] residuals(Node node, List parents, boolean standardize) { + List _residuals = new ArrayList<>(); Node target = getVariable(this.variables, node.getName()); List regressors = new ArrayList<>(); @@ -528,27 +1506,48 @@ private double pValue(Node node, List parents) { DATASET: for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); + if (Thread.currentThread().isInterrupted()) { + break; + } - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { + DataSet dataSet = this.dataSets.get(m); + + int targetCol = dataSet.getColumn(target); + + for (int i = 0; i < dataSet.getNumRows(); i++) { + if (isNaN(dataSet.getDouble(i, targetCol))) { continue DATASET; } } - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + for (Node regressor : regressors) { + if (Thread.currentThread().isInterrupted()) { + break; + } - double mean = Descriptive.mean(_residualsSingleDataset); + int regressorCol = dataSet.getColumn(regressor); - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - if (isMeanCenterResiduals()) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); + for (int i = 0; i < dataSet.getNumRows(); i++) { + if (isNaN(dataSet.getDouble(i, regressorCol))) { + continue DATASET; + } } } - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); + RegressionResult result = getRegressions().get(m).regress(target, regressors); + double[] residualsSingleDataset = result.getResiduals().toArray(); + + if (result.getCoef().length > 0) { + double intercept = result.getCoef()[0]; + + for (int i2 = 0; i2 < residualsSingleDataset.length; i2++) { + residualsSingleDataset[i2] = residualsSingleDataset[i2] + intercept; + } + } + + for (double _x : residualsSingleDataset) { + if (isNaN(_x)) continue; + _residuals.add(_x); } } @@ -558,10 +1557,25 @@ private double pValue(Node node, List parents) { _f[k] = _residuals.get(k); } - return new AndersonDarlingTest(_f).getP(); + if (standardize) { + _f = DataUtils.standardizeData(_f); + } + + return _f; + } + + private double andersonDarlingPASquare(Node node, List parents) { + double[] _f = residuals(node, parents, true); +// return new AndersonDarlingTest(_f).getASquaredStar(); + return new AndersonDarlingTest(_f).getASquared(); } - private double[] residual(Node node, List parents) { + private double entropy(Node node, List parents) { + double[] _f = residuals(node, parents, true); + return maxEntApprox(_f); + } + + private double pValue(Node node, List parents) { List _residuals = new ArrayList<>(); Node target = getVariable(this.variables, node.getName()); @@ -574,23 +1588,45 @@ private double[] residual(Node node, List parents) { DATASET: for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); + if (Thread.currentThread().isInterrupted()) { + break; + } - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { + DataSet dataSet = this.dataSets.get(m); + + int targetCol = dataSet.getColumn(target); + + for (int i = 0; i < dataSet.getNumRows(); i++) { + if (isNaN(dataSet.getDouble(i, targetCol))) { continue DATASET; } } - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + for (Node regressor : regressors) { + if (Thread.currentThread().isInterrupted()) { + break; + } - double mean = Descriptive.mean(_residualsSingleDataset); + int regressorCol = dataSet.getColumn(regressor); - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); + for (int i = 0; i < dataSet.getNumRows(); i++) { + if (isNaN(dataSet.getDouble(i, regressorCol))) { + continue DATASET; + } + } } + RegressionResult result = getRegressions().get(m).regress(target, regressors); + Vector residualsSingleDataset = result.getResiduals(); + + for (int h = 0; h < residualsSingleDataset.size(); h++) { + if (isNaN(residualsSingleDataset.get(h))) { + continue DATASET; + } + } + + Vector _residualsSingleDataset = new Vector(residualsSingleDataset.toArray()); + for (int k = 0; k < _residualsSingleDataset.size(); k++) { _residuals.add(_residualsSingleDataset.get(k)); } @@ -602,23 +1638,15 @@ private double[] residual(Node node, List parents) { _f[k] = _residuals.get(k); } - return _f; - } + double p = new AndersonDarlingTest(_f).getP(); - public double getAlpha() { - return this.alpha; - } - - public void setAlpha(double alpha) { - if (alpha < 0.0 || alpha > 1.0) { - throw new IllegalArgumentException("Alpha is in range [0, 1]"); - } + if (p > 1.0 || isNaN(p)) p = 1.0; - this.alpha = alpha; + return p; } - private Graph getCpdag() { - return this.cpdag; + private Graph getCPDAG() { + return this.CPDAG; } private Node getVariable(List variables, String name) { @@ -631,42 +1659,246 @@ private Node getVariable(List variables, String name) { return null; } - public boolean isR1Done() { - return true; + private Graph resolveEdgeConditional(Graph graph) { + setDataSets(this.dataSets); + + Set edgeList1 = graph.getEdges(); +// RandomUtil.shuffle(edgeList1); + + for (Edge adj : edgeList1) { + Node x = adj.getNode1(); + Node y = adj.getNode2(); + + resolveEdgeConditional(graph, x, y); + } + + return graph; + } + + Matrix _data; + + private void resolveEdgeConditional(Graph graph, Node x, Node y) { + if (this._data == null) { + this._data = DataUtils.centerData(this.matrices.get(0)); + } + int xIndex = this.dataSets.get(0).getColumn(this.dataSets.get(0).getVariable(x.getName())); + int yIndex = this.dataSets.get(0).getColumn(this.dataSets.get(0).getVariable(y.getName())); + double[] xCol = this._data.getColumn(xIndex).toArray(); + double[] yCol = this._data.getColumn(yIndex).toArray(); + int N = xCol.length; + + double[][] yCols = new double[1][N]; + yCols[0] = yCol; + + double[][] xCols = new double[1][N]; + xCols[0] = xCol; + + double[][] empty = new double[0][N]; + + double[] resX = conditionalResiduals(xCol, empty); + double[] resY = conditionalResiduals(yCol, empty); + double[] resXY = conditionalResiduals(xCol, yCols); + double[] resYX = conditionalResiduals(yCol, xCols); + + double ngX = new AndersonDarlingTest(xCol).getASquared(); + double ngY = new AndersonDarlingTest(yCol).getASquared(); + + graph.removeEdges(x, y); + + double sdX = sd(resX); + double sdXY = sd(resXY); + double sdY = sd(resY); + double sdYX = sd(resYX); + + double abs1 = abs(sdX - sdXY); + double abs2 = abs(sdY - sdYX); + + if (abs(abs1 - abs2) < this.epsilon) { + System.out.println("Orienting by non-Gaussianity " + abs(abs1 - abs2) + " epsilon = " + this.epsilon); + System.out.println(x + "===" + y); + double v = resolveOneEdgeMaxR3b(xCol, yCol); + + if (v < 0) { + graph.addDirectedEdge(x, y); + } else if (v > 0) { + graph.addDirectedEdge(y, x); + } else { + graph.addUndirectedEdge(x, y); + } + + return; + } + + System.out.println("Orienting by variances " + abs(abs1 - abs2)); + System.out.println(x + "===" + y); + + if (sdXY + ngY < sdYX + ngX) { + graph.addDirectedEdge(x, y); + } else { + graph.addDirectedEdge(y, x); + } + } + + private double[] conditionalResiduals(double[] x, double[][] y) { + int N = x.length; + double[] residuals = new double[N]; + + double _h = 1.0; + + for (double[] doubles : y) { + _h *= h(doubles); + } + + _h = (y.length == 0) ? 1.0 : pow(_h, 1.0 / (y.length)); + + for (int i = 0; i < N; i++) { + double xi = x[i]; + + double sum = 0.0; + double kTot = 0.0; + + for (int j = 0; j < N; j++) { + double d = distance(y, i, j); + double k = kernel(d / _h) / _h; + if (k < 1e-5) continue; + double xj = x[j]; + sum += k * xj; + kTot += k; + } + + residuals[i] = xi - (sum / kTot); + } + + return residuals; } - public boolean isR2Done() { - return true; + private double h(double[] xCol) { +// % optimal bandwidth suggested by Bowman and Azzalini (1997) p.31 (rks code Matlab) +// h *= median(abs(x-median(x)))/0.6745*(4/3/r.h)^0.2, geometric mean across variables. + + double[] g = new double[xCol.length]; + double median = median(xCol); + for (int j = 0; j < xCol.length; j++) g[j] = abs(xCol[j] - median); + return median(g) / 0.6745 * pow((4.0 / 3.0) / xCol.length, 0.2); } - public boolean isMeekDone() { - return this.meekDone; + public double kernel(double z) { + return kernel1(z); } - public boolean isStrongR2() { - return this.strongR2; + private final double SQRT = sqrt(2. * PI); + + // Gaussian + public double kernel1(double z) { + return exp(-(z * z) / 2.) / this.SQRT; //(sqrt(2. * PI)); } - public boolean isR2Orient2Cycles() { - return true; + // Uniform + public double kernel2(double z) { + if (abs(z) > 1) return 0; + else return .5; } - public Score getScore() { - return this.score; + // Triangular + public double kernel3(double z) { + if (abs(z) > 1) return 0; + else return 1 - abs(z); } - public void setScore(Score score) { - if (score == null) { - throw new NullPointerException(); + // Epanechnikov + public double kernel4(double z) { + if (abs(z) > 1) return 0; + else return (3. / 4.) * (1. - z * z); + } + + // Quartic + public double kernel5(double z) { + if (abs(z) > 1) return 0; + else return 15. / 16. * pow(1. - z * z, 2.); + } + + // Triweight + public double kernel6(double z) { + if (abs(z) > 1) return 0; + else return 35. / 32. * pow(1. - z * z, 3.); + } + + // Tricube + public double kernel7(double z) { + if (abs(z) > 1) return 0; + else return 70. / 81. * pow(1. - z * z * z, 3.); + } + + // Cosine + public double kernel8(double z) { + if (abs(z) > 1) return 0; + else return (PI / 4.) * cos((PI / 2.) * z); + } + + private double distance(double[][] yCols, int i, int j) { + double sum = 0.0; + + for (double[] yCol : yCols) { + double d = yCol[i] - yCol[j]; + sum += d * d; } - this.score = score; + return sqrt(sum); + } + + + private double resolveOneEdgeMaxR3(double[] x, double[] y) { + OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression(); + double[][] _x = new double[1][]; + _x[0] = x; + double[][] _y = new double[1][]; + _y[0] = y; + + regression.newSampleData(x, transpose(_y)); + double[] rXY = regression.estimateResiduals(); + + regression.newSampleData(y, transpose(_x)); + double[] rYX = regression.estimateResiduals(); + + double xPlus = new AndersonDarlingTest(rXY).getASquared(); + double xMinus = new AndersonDarlingTest(x).getASquared(); + double yPlus = new AndersonDarlingTest(rYX).getASquared(); + double yMinus = new AndersonDarlingTest(y).getASquared(); + + double deltaX = xPlus - xMinus; + double deltaY = yPlus - yMinus; + + return deltaX - deltaY; } - public boolean isMeanCenterResiduals() { - return this.meanCenterResiduals; + private double resolveOneEdgeMaxR3b(double[] x, double[] y) { + int N = x.length; + + double[][] yCols = new double[1][N]; + yCols[0] = y; + + double[][] xCols = new double[1][N]; + xCols[0] = x; + + double[][] empty = new double[0][N]; + + double[] rX = conditionalResiduals(x, empty); + double[] rY = conditionalResiduals(y, empty); + double[] rXY = conditionalResiduals(x, yCols); + double[] rYX = conditionalResiduals(y, xCols); + + double xPlus = new AndersonDarlingTest(rXY).getASquared(); + double xMinus = new AndersonDarlingTest(rX).getASquared(); + double yPlus = new AndersonDarlingTest(rYX).getASquared(); + double yMinus = new AndersonDarlingTest(rY).getASquared(); + + double deltaX = xPlus - xMinus; + double deltaY = yPlus - yMinus; + + return deltaX - deltaY; } } + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs2.java deleted file mode 100644 index 3d36bc3047..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs2.java +++ /dev/null @@ -1,1904 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.regression.Regression; -import edu.cmu.tetrad.regression.RegressionDataset; -import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.util.Vector; -import edu.cmu.tetrad.util.*; -import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression; -import org.apache.commons.math3.util.FastMath; - -import java.util.*; - -import static edu.cmu.tetrad.util.MatrixUtils.transpose; -import static edu.cmu.tetrad.util.StatUtils.*; -import static java.lang.Double.isNaN; -import static org.apache.commons.math3.util.FastMath.pow; -import static org.apache.commons.math3.util.FastMath.*; - -/** - * LOFS = Ling Orientation Fixed Structure. Some additional algorithm. - *

- * Expands the set of algorithm from Lofs. - * - * @author Joseph Ramsey - */ -public class Lofs2 { - - public enum Score { - andersonDarling, skew, kurtosis, fifthMoment, absoluteValue, - exp, expUnstandardized, expUnstandardizedInverted, other, logcosh, entropy - } - - private final Graph CPDAG; - private List dataSets; - private List matrices; - private double alpha = 1.1; - private List regressions; - private List variables; - private boolean orientStrongerDirection; - private boolean r2Orient2Cycles = true; - - private Lofs.Score score = Lofs.Score.andersonDarling; - private double epsilon = 1.0; - private Knowledge knowledge = new Knowledge(); - private Rule rule = Rule.R1; - private double selfLoopStrength; - - //===============================CONSTRUCTOR============================// - - public Lofs2(Graph CPDAG, List dataSets) - throws IllegalArgumentException { - - if (dataSets == null) { - throw new IllegalArgumentException("Data set must be specified."); - } - - if (CPDAG == null) { - throw new IllegalArgumentException("CPDAG must be specified."); - } - - this.CPDAG = CPDAG; - this.variables = dataSets.get(0).getVariables(); - - List dataSets2 = new ArrayList<>(); - - for (DataSet set : dataSets) { - DataSet dataSet = new BoxDataSet(new DoubleDataBox(set.getDoubleData().toArray()), this.variables); - dataSets2.add(dataSet); - } - - this.dataSets = dataSets2; - } - - //==========================PUBLIC=========================================// - - public void setRule(Rule rule) { - this.rule = rule; - } - - public double getSelfLoopStrength() { - return this.selfLoopStrength; - } - - public void setSelfLoopStrength(double selfLoopStrength) { - this.selfLoopStrength = selfLoopStrength; - } - - // orientStrongerDirection list of past and present rules. - public enum Rule { - IGCI, R1TimeLag, R1, R2, R3, Tanh, EB, Skew, SkewE, RSkew, RSkewE, - Patel, Patel25, Patel50, Patel75, Patel90, FastICA, RC - } - - public Graph orient() { - - Graph skeleton = GraphUtils.undirectedGraph(getCPDAG()); - Graph graph = new EdgeListGraph(skeleton.getNodes()); - - List nodes = skeleton.getNodes(); - - if (this.rule == Rule.R1TimeLag) { - ruleR1TimeLag(skeleton, graph); - } else if (this.rule == Rule.R1) { - ruleR1(skeleton, graph, nodes); - } else if (this.rule == Rule.R2) { - graph = GraphUtils.undirectedGraph(skeleton); - ruleR2(graph, graph); - } else if (this.rule == Rule.R3) { - graph = GraphUtils.undirectedGraph(skeleton); - ruleR3(graph); - } else if (this.rule == Rule.EB) { - graph = GraphUtils.undirectedGraph(skeleton); - return entropyBased(graph); - } else if (this.rule == Rule.Tanh) { - graph = GraphUtils.undirectedGraph(skeleton); - return tanhGraph(graph); - } else if (this.rule == Rule.Skew) { - graph = GraphUtils.undirectedGraph(skeleton); - return skewGraph(graph, false); - } else if (this.rule == Rule.SkewE) { - graph = GraphUtils.undirectedGraph(skeleton); - return skewGraph(graph, true); - } else if (this.rule == Rule.RSkew) { - graph = GraphUtils.undirectedGraph(skeleton); - return robustSkewGraph(graph, false); - } else if (this.rule == Rule.RSkewE) { - graph = GraphUtils.undirectedGraph(skeleton); - return robustSkewGraph(graph, true); - } else if (this.rule == Rule.IGCI) { - graph = GraphUtils.undirectedGraph(skeleton); - return igci(graph); - } else if (this.rule == Rule.RC) { - graph = GraphUtils.undirectedGraph(skeleton); - return resolveEdgeConditional(graph); - } else if (this.rule == Rule.Patel) { - graph = GraphUtils.undirectedGraph(skeleton); - return patelTauOrientation(graph, Double.NaN); - } else if (this.rule == Rule.Patel25) { - graph = GraphUtils.undirectedGraph(skeleton); - return patelTauOrientation(graph, 0.25); - } else if (this.rule == Rule.Patel50) { - graph = GraphUtils.undirectedGraph(skeleton); - return patelTauOrientation(graph, 0.50); - } else if (this.rule == Rule.Patel75) { - graph = GraphUtils.undirectedGraph(skeleton); - return patelTauOrientation(graph, 0.75); - } else if (this.rule == Rule.Patel90) { - graph = GraphUtils.undirectedGraph(skeleton); - return patelTauOrientation(graph, 0.90); - } else if (this.rule == Rule.FastICA) { - FastIca fastIca = new FastIca(this.dataSets.get(0).getDoubleData(), - this.dataSets.get(0).getNumColumns()); - FastIca.IcaResult result = fastIca.findComponents(); - System.out.println(result.getW()); - return new EdgeListGraph(); - } - - return graph; - } - - public double getAlpha() { - return this.alpha; - } - - public void setAlpha(double alpha) { - if (alpha < 0.0 || alpha > 1.0) { - throw new IllegalArgumentException("Alpha is in range [0, 1]"); - } - - this.alpha = alpha; - } - - public boolean isOrientStrongerDirection() { - return this.orientStrongerDirection; - } - - public void setOrientStrongerDirection(boolean orientStrongerDirection) { - this.orientStrongerDirection = orientStrongerDirection; - } - - public void setR2Orient2Cycles(boolean r2Orient2Cycles) { - this.r2Orient2Cycles = r2Orient2Cycles; - } - - public boolean isR2Orient2Cycles() { - return this.r2Orient2Cycles; - } - - public Lofs.Score getScore() { - return this.score; - } - - public void setScore(Lofs.Score score) { - if (score == null) { - throw new NullPointerException(); - } - - this.score = score; - } - - //==========================PRIVATE=======================================// - - private List getRegressions() { - if (this.regressions == null) { - List regressions = new ArrayList<>(); - this.variables = this.dataSets.get(0).getVariables(); - - for (DataSet dataSet : this.dataSets) { - regressions.add(new RegressionDataset(dataSet)); - } - - this.regressions = regressions; - } - - return this.regressions; - } - - private void setDataSets(List dataSets) { - this.dataSets = dataSets; - - this.matrices = new ArrayList<>(); - - for (DataSet dataSet : dataSets) { - this.matrices.add(dataSet.getDoubleData()); - } - } - - private void ruleR1TimeLag(Graph skeleton, Graph graph) { - List timeSeriesDataSets = new ArrayList<>(); - Knowledge knowledge = null; - List dataNodes = null; - - for (DataSet dataModel : this.dataSets) { - if (dataModel == null) { - throw new IllegalArgumentException("Dataset is not supplied."); - } - - DataSet lags = TimeSeriesUtils.createLagData(dataModel, 1); - if (dataModel.getName() != null) { - lags.setName(dataModel.getName()); - } - timeSeriesDataSets.add(lags); - - if (knowledge == null) { - knowledge = lags.getKnowledge(); - } - - if (dataNodes == null) { - dataNodes = lags.getVariables(); - } - } - - Graph laggedSkeleton = new EdgeListGraph(dataNodes); - - for (Edge edge : skeleton.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - String node1 = edge.getNode1().getName(); - String node2 = edge.getNode2().getName(); - - Node node10 = laggedSkeleton.getNode(node1 + ":0"); - Node node20 = laggedSkeleton.getNode(node2 + ":0"); - - laggedSkeleton.addUndirectedEdge(node10, node20); - - Node node11 = laggedSkeleton.getNode(node1 + ":1"); - Node node21 = laggedSkeleton.getNode(node2 + ":1"); - - laggedSkeleton.addUndirectedEdge(node11, node21); - } - - for (Node node : skeleton.getNodes()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - String _node = node.getName(); - - Node node0 = laggedSkeleton.getNode(_node + ":0"); - Node node1 = laggedSkeleton.getNode(_node + ":1"); - - laggedSkeleton.addUndirectedEdge(node0, node1); - } - - Lofs2 lofs = new Lofs2(laggedSkeleton, timeSeriesDataSets); - lofs.setKnowledge(knowledge); - lofs.setRule(Rule.R1); - Graph _graph = lofs.orient(); - - graph.removeEdges(new ArrayList<>(graph.getEdges())); - - for (Edge edge : _graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node node1 = edge.getNode1(); - Node node2 = edge.getNode2(); - Endpoint end1 = edge.getEndpoint1(); - Endpoint end2 = edge.getEndpoint2(); - - String index1 = node1.getName().split(":")[1]; - String index2 = node2.getName().split(":")[1]; - - if ("1".equals(index1) || "1".equals(index2)) continue; - - String name1 = node1.getName().split(":")[0]; - String name2 = node2.getName().split(":")[0]; - - Node _node1 = graph.getNode(name1); - Node _node2 = graph.getNode(name2); - - Edge _edge = new Edge(_node1, _node2, end1, end2); - graph.addEdge(_edge); - } - } - - private void ruleR1(Graph skeleton, Graph graph, List nodes) { - List centeredData = DataUtils.center(this.dataSets); - setDataSets(centeredData); - - for (Node node : nodes) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - SortedMap scoreReports = new TreeMap<>(); - - List adj = new ArrayList<>(); - - for (Node _node : skeleton.getAdjacentNodes(node)) { - if (this.knowledge.isForbidden(_node.getName(), node.getName())) { - continue; - } - - adj.add(_node); - } - - SublistGenerator gen = new SublistGenerator(adj.size(), adj.size()); - int[] choice; - double maxScore = Double.NEGATIVE_INFINITY; - List parents = null; - - while ((choice = gen.next()) != null) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - List _parents = GraphUtils.asList(choice, adj); - - double score = score(node, _parents); - scoreReports.put(-score, _parents.toString()); - - if (score > maxScore) { - maxScore = score; - parents = _parents; - } - } - - for (double score : scoreReports.keySet()) { - TetradLogger.getInstance().log("score", "For " + node + " parents = " + scoreReports.get(score) + " score = " + -score); - } - - TetradLogger.getInstance().log("score", ""); - - if (parents == null) { - continue; - } - - for (Node _node : adj) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (parents.contains(_node)) { - Edge parentEdge = Edges.directedEdge(_node, node); - - if (!graph.containsEdge(parentEdge)) { - graph.addEdge(parentEdge); - } - } - } - } - - for (Edge edge : skeleton.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (!graph.isAdjacentTo(edge.getNode1(), edge.getNode2())) { - graph.addUndirectedEdge(edge.getNode1(), edge.getNode2()); - } - } - } - - private void ruleR2(Graph skeleton, Graph graph) { - List standardized = DataUtils.standardizeData(this.dataSets); - setDataSets(standardized); - - Set edgeList1 = skeleton.getEdges(); - - for (Edge adj : edgeList1) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = adj.getNode1(); - Node y = adj.getNode2(); - - if (!isR2Orient2Cycles() && isTwoCycle(graph, x, y)) { - continue; - } - - if (!isTwoCycle(graph, x, y) && !isUndirected(graph, x, y)) { - continue; - } - - resolveOneEdgeMax2(graph, x, y, !isOrientStrongerDirection()); - } - } - - private void resolveOneEdgeMax2(Graph graph, Node x, Node y, boolean strong) { - TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y); - - SortedMap scoreReports = new TreeMap<>(); - - List neighborsx = new ArrayList<>(); - - for (Node _node : graph.getAdjacentNodes(x)) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (!this.knowledge.isForbidden(_node.getName(), x.getName())) { -// if (!knowledge.edgeForbidden(x.getNode(), _node.getNode())) { - neighborsx.add(_node); - } - } - -// neighborsx.remove(y); - - double max = Double.NEGATIVE_INFINITY; - boolean left = false; - boolean right = false; - - SublistGenerator genx = new SublistGenerator(neighborsx.size(), neighborsx.size()); - int[] choicex; - - while ((choicex = genx.next()) != null) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - List condxMinus = GraphUtils.asList(choicex, neighborsx); - - if (condxMinus.contains(y)) continue; - - List condxPlus = new ArrayList<>(condxMinus); - - condxPlus.add(y); - - double xPlus = score(x, condxPlus); - double xMinus = score(x, condxMinus); - - double p = pValue(x, condxPlus); - - if (p > this.alpha) { - continue; - } - - double p2 = pValue(x, condxMinus); - - if (p2 > this.alpha) { - continue; - } - - List neighborsy = new ArrayList<>(); - - for (Node _node : graph.getAdjacentNodes(y)) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (!this.knowledge.isForbidden(_node.getName(), y.getName())) { - neighborsy.add(_node); - } - } - - SublistGenerator geny = new SublistGenerator(neighborsy.size(), neighborsy.size()); - int[] choicey; - - while ((choicey = geny.next()) != null) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - List condyMinus = GraphUtils.asList(choicey, neighborsy); - - if (condyMinus.contains(x)) continue; - - List condyPlus = new ArrayList<>(condyMinus); - condyPlus.add(x); - - double yPlus = score(y, condyPlus); - double yMinus = score(y, condyMinus); - - boolean forbiddenLeft = this.knowledge.isForbidden(y.getName(), x.getName()); - boolean forbiddenRight = this.knowledge.isForbidden(x.getName(), y.getName()); - - final double delta = 0.0; - - if (strong) { - if (yPlus <= xPlus + delta && xMinus <= yMinus + delta) { - double score = combinedScore(xPlus, yMinus); - - if ((yPlus <= yMinus + delta && xMinus <= xPlus + delta) || forbiddenRight) { - - String s = "\nStrong " + y + "->" + x + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = true; - right = false; - } - } else { - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } else if ((xPlus <= yPlus + delta && yMinus <= xMinus + delta) || forbiddenLeft) { - double score = combinedScore(yPlus, xMinus); - - if (yMinus <= yPlus + delta && xPlus <= xMinus + delta) { - - String s = "\nStrong " + x + "->" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = false; - right = true; - } - } else { - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } else if (yPlus <= xPlus + delta && yMinus <= xMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } else if (xPlus <= yPlus + delta && xMinus <= yMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } else { - if ((yPlus <= xPlus + delta && xMinus <= yMinus + delta) || forbiddenRight) { - double score = combinedScore(xPlus, yMinus); - - String s = "\nWeak " + y + "->" + x + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = true; - right = false; - } - } else if ((xPlus <= yPlus + delta && yMinus <= xMinus + delta) || forbiddenLeft) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nWeak " + x + "->" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = false; - right = true; - } - } else if (yPlus <= xPlus + delta && yMinus <= xMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } else if (xPlus <= yPlus + delta && xMinus <= yMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } - } - } - - for (double score : scoreReports.keySet()) { - TetradLogger.getInstance().log("info", scoreReports.get(score)); - } - - graph.removeEdges(x, y); - - if (left) { - graph.addDirectedEdge(y, x); - } - - if (right) { - graph.addDirectedEdge(x, y); - } - - if (!graph.isAdjacentTo(x, y)) { - graph.addUndirectedEdge(x, y); - } - } - - - private void ruleR3(Graph graph) { - List standardized = DataUtils.standardizeData(this.dataSets); - setDataSets(standardized); - - Set edgeList1 = graph.getEdges(); - - for (Edge adj : edgeList1) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = adj.getNode1(); - Node y = adj.getNode2(); - - resolveOneEdgeMaxR3(graph, x, y); - } - - } - - private void resolveOneEdgeMaxR3(Graph graph, Node x, Node y) { - String xname = x.getName(); - String yname = y.getName(); - - if (this.knowledge.isForbidden(yname, xname) || this.knowledge.isRequired(xname, yname)) { - graph.removeEdge(x, y); - graph.addDirectedEdge(x, y); - return; - } else if (this.knowledge.isForbidden(xname, yname) || this.knowledge.isRequired(yname, xname)) { - graph.removeEdge(y, x); - graph.addDirectedEdge(y, x); - return; - } - -// TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y); - - List condxMinus = Collections.emptyList(); - List condxPlus = Collections.singletonList(y); - List condyMinus = Collections.emptyList(); - List condyPlus = Collections.singletonList(x); - - double xPlus = score(x, condxPlus); - double xMinus = score(x, condxMinus); - - double yPlus = score(y, condyPlus); - double yMinus = score(y, condyMinus); - -// if (!(xPlus > 0.8 && xMinus > 0.8 && yPlus > 0.8 && yMinus > 0.8)) return; - - double deltaX = xPlus - xMinus; - double deltaY = yPlus - yMinus; - - graph.removeEdges(x, y); -// double epsilon = 0; - - if (deltaY > deltaX) { - graph.addDirectedEdge(x, y); - } else { - graph.addDirectedEdge(y, x); - } - } - - private double[] col; - - // rowIndex is for the W matrix, not for the data. - public double scoreRow(int rowIndex, Matrix data, List> rows, List> parameters) { - if (this.col == null) { - this.col = new double[data.rows()]; - } - - List cols = rows.get(rowIndex); - - for (int i = 0; i < data.rows(); i++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - double d = 0.0; - - for (int j = 0; j < cols.size(); j++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - int _j = cols.get(j); - double coef = parameters.get(rowIndex).get(j); - double value = data.get(i, _j); - d += coef * value; - } - - // Add in the diagonal, assumed to consist entirely of 1's, indicating no self loop. - d += (1.0 - getSelfLoopStrength()) * data.get(i, rowIndex); - - this.col[i] = d; - } - - return score(this.col); - } - - private Graph entropyBased(Graph graph) { - DataSet dataSet = DataUtils.concatenate(this.dataSets); - dataSet = DataUtils.standardizeData(dataSet); - Graph _graph = new EdgeListGraph(graph.getNodes()); - - for (Edge edge : graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - Node _x = dataSet.getVariable(x.getName()); - Node _y = dataSet.getVariable(y.getName()); - - List ret = extractData(dataSet, _x, _y); - - double[] xData = ret.get(0); - double[] yData = ret.get(1); - - double[] d = new double[xData.length]; - double[] e = new double[xData.length]; - - double cov = covariance(xData, yData); - - for (int i = 0; i < xData.length; i++) { - d[i] = yData[i] - cov * xData[i]; // y regressed on x - e[i] = xData[i] - cov * yData[i]; // x regressed on y - } - - double R = -maxEntApprox(xData) - maxEntApprox(d) - + maxEntApprox(yData) + maxEntApprox(e); - - if (R > 0) { - _graph.addDirectedEdge(x, y); - } else { - _graph.addDirectedEdge(y, x); - } - } - - return _graph; - } - - private Graph tanhGraph(Graph graph) { - DataSet dataSet = DataUtils.concatenate(this.dataSets); - graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); - dataSet = DataUtils.standardizeData(dataSet); - double[][] data = dataSet.getDoubleData().transpose().toArray(); - Graph _graph = new EdgeListGraph(graph.getNodes()); - List nodes = dataSet.getVariables(); - Map nodesHash = new HashMap<>(); - - for (int i = 0; i < nodes.size(); i++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - nodesHash.put(nodes.get(i), i); - } - - for (Edge edge : graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - double sumX = 0.0; - int countX = 0; - - double[] xData = data[nodesHash.get(edge.getNode1())]; - double[] yData = data[nodesHash.get(edge.getNode2())]; - - for (int i = 0; i < xData.length; i++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - double x0 = xData[i]; - double y0 = yData[i]; - - double termX = (x0 * tanh(y0) - tanh(x0) * y0); - - sumX += termX; - countX++; - } - - double R = sumX / countX; - - double rhoX = regressionCoef(xData, yData); - R *= rhoX; - - if (R > 0) { - _graph.addDirectedEdge(x, y); - } else { - _graph.addDirectedEdge(y, x); - } - } - - return _graph; - } - - - // @param empirical True if the skew signs are estimated empirically. - private Graph skewGraph(Graph graph, boolean empirical) { - DataSet dataSet = DataUtils.concatenate(this.dataSets); - graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); - dataSet = DataUtils.standardizeData(dataSet); - double[][] data = dataSet.getDoubleData().transpose().toArray(); - Graph _graph = new EdgeListGraph(graph.getNodes()); - List nodes = dataSet.getVariables(); - Map nodesHash = new HashMap<>(); - - for (int i = 0; i < nodes.size(); i++) { - nodesHash.put(nodes.get(i), i); - } - - for (Edge edge : graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - double sumX = 0.0; - int countX = 0; - - int _i = nodesHash.get(edge.getNode1()); - int _j = nodesHash.get(edge.getNode2()); - - double[] xData = data[_i]; - double[] yData = data[_j]; - - if (empirical) { - xData = correctSkewnesses(xData); - yData = correctSkewnesses(yData); - } - - for (int i = 0; i < xData.length; i++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - double x0 = xData[i]; - double y0 = yData[i]; - - double termX = x0 * x0 * y0 - x0 * y0 * y0; - - sumX += termX; - countX++; - } - - double R = sumX / countX; - - double rhoX = regressionCoef(xData, yData); - - R *= rhoX; - - if (R > 0) { - _graph.addDirectedEdge(x, y); - } else { - _graph.addDirectedEdge(y, x); - } - } - - return _graph; - - } - - // @param empirical True if the skew signs are estimated empirically. - private Graph robustSkewGraph(Graph graph, boolean empirical) { - // DataUtils.standardizeData(dataSet)); - List _dataSets = new ArrayList<>(this.dataSets); - DataSet dataSet = DataUtils.concatenate(_dataSets); - graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); - dataSet = DataUtils.standardizeData(dataSet); - double[][] data = dataSet.getDoubleData().transpose().toArray(); - List nodes = dataSet.getVariables(); - Map nodesHash = new HashMap<>(); - - for (int i = 0; i < nodes.size(); i++) { - nodesHash.put(nodes.get(i), i); - } - - for (Edge edge : graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - double[] xData = data[nodesHash.get(edge.getNode1())]; - double[] yData = data[nodesHash.get(edge.getNode2())]; - - if (empirical) { - xData = correctSkewnesses(xData); - yData = correctSkewnesses(yData); - } - - double[] xx = new double[xData.length]; - double[] yy = new double[yData.length]; - - for (int i = 0; i < xData.length; i++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - double xi = xData[i]; - double yi = yData[i]; - - double s1 = g(xi) * yi; - double s2 = xi * g(yi); - - xx[i] = s1; - yy[i] = s2; - } - - double mxx = mean(xx); - double myy = mean(yy); - - graph.removeEdge(edge); - - if (mxx > myy) { - graph.addDirectedEdge(x, y); - } else if (myy > mxx) { - graph.addDirectedEdge(y, x); - } else { - graph.addUndirectedEdge(x, y); - } - } - - return graph; - } - - private double g(double x) { - return log(cosh(FastMath.max(x, 0))); - } - - // cutoff is NaN if no thresholding is to be done, otherwise a threshold between 0 and 1. - private Graph patelTauOrientation(Graph graph, double cutoff) { - List centered = DataUtils.center(this.dataSets); - DataSet concat = DataUtils.concatenate(centered); - DataSet dataSet = DataUtils.standardizeData(concat); - - Graph _graph = new EdgeListGraph(graph.getNodes()); - - for (Edge edge : graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - Node _x = dataSet.getVariable(x.getName()); - Node _y = dataSet.getVariable(y.getName()); - - List ret = prepareData(dataSet, _x, _y); - double[] xData = ret.get(0); - double[] yData = ret.get(1); - - double R = patelTau(xData, yData, cutoff); - - if (R > 0) { - _graph.addDirectedEdge(x, y); - } else { - _graph.addDirectedEdge(y, x); - } - } - - System.out.println(_graph); - - return _graph; - } - - // cutoff is NaN if no thresholding is to be done, otherwise a threshold between 0 and 1. - private double patelTau(double[] d1in, double[] d2in, double cutoff) { - double grotMIN = percentile(d1in, 10); - double grotMAX = percentile(d1in, 90); - - final double XT = .25; // Cancels out, don't know why this is here. - - double[] d1b = new double[d1in.length]; - - for (int i = 0; i < d1b.length; i++) { - double y1 = (d1in[i] - grotMIN) / (grotMAX - grotMIN); - double y2 = FastMath.min(y1, 1.0); - double y3 = FastMath.max(y2, 0.0); - d1b[i] = y3; - } - - if (!isNaN(cutoff)) { - for (int i = 0; i < d1b.length; i++) { - if (d1b[i] > cutoff) d1b[i] = 1.0; - else d1b[i] = 0.0; - } - } - - grotMIN = percentile(d2in, 10); - grotMAX = percentile(d2in, 90); - - double[] d2b = new double[d2in.length]; - - for (int i = 0; i < d2b.length; i++) { - double y1 = (d2in[i] - grotMIN) / (grotMAX - grotMIN); - double y2 = FastMath.min(y1, 1.0); - double y3 = FastMath.max(y2, 0.0); - d2b[i] = y3; - } - - if (!isNaN(cutoff)) { - for (int i = 0; i < d2b.length; i++) { - if (d2b[i] > cutoff) d2b[i] = 1.0; - else d2b[i] = 0.0; - } - } - - double theta1 = dotProduct(d1b, d2b) / XT; - double theta2 = dotProduct(d1b, minus(d2b)) / XT; - double theta3 = dotProduct(d2b, minus(d1b)) / XT; -// double theta4= dotProduct(minus(1, d1b), minus(1, d2b))/XT; - - double tau_12; - - if (theta2 > theta3) tau_12 = 1 - (theta1 + theta3) / (theta1 + theta2); - else tau_12 = (theta1 + theta2) / (theta1 + theta3) - 1; - - return -tau_12; - } - - private double dotProduct(double[] x, double[] y) { - double p = 0.0; - - for (int i = 0; i < x.length; i++) { - p += x[i] * y[i]; - } - - return p; - } - - private double[] minus(double[] x) { - double[] y = new double[x.length]; - - for (int i = 0; i < x.length; i++) { - y[i] = 1 - x[i]; - } - - return y; - } - - private double percentile(double[] x, double percent) { - double[] _x = Arrays.copyOf(x, x.length); - Arrays.sort(_x); - return _x[(int) (x.length * (percent / 100.0))]; - } - - private List extractData(DataSet data, Node _x, Node _y) { - int xIndex = data.getColumn(_x); - int yIndex = data.getColumn(_y); - - double[][] _data = data.getDoubleData().transpose().toArray(); - - double[] xData = _data[xIndex]; - double[] yData = _data[yIndex]; - - List xValues = new ArrayList<>(); - List yValues = new ArrayList<>(); - - for (int i = 0; i < data.getNumRows(); i++) { - if (!isNaN(xData[i]) && !isNaN(yData[i])) { - xValues.add(xData[i]); - yValues.add(yData[i]); - } - } - - xData = new double[xValues.size()]; - yData = new double[yValues.size()]; - - for (int i = 0; i < xValues.size(); i++) { - xData[i] = xValues.get(i); - yData[i] = yValues.get(i); - } - - List ret = new ArrayList<>(); - ret.add(xData); - ret.add(yData); - - return ret; - } - - private double[] correctSkewnesses(double[] data) { - double skewness = skewness(data); - double[] data2 = new double[data.length]; - for (int i = 0; i < data.length; i++) data2[i] = data[i] * signum(skewness); - return data2; - } - - private List prepareData(DataSet concatData, Node _x, Node _y) { - int xIndex = concatData.getColumn(_x); - int yIndex = concatData.getColumn(_y); - - double[] xData = concatData.getDoubleData().getColumn(xIndex).toArray(); - double[] yData = concatData.getDoubleData().getColumn(yIndex).toArray(); - - List xValues = new ArrayList<>(); - List yValues = new ArrayList<>(); - - for (int i = 0; i < concatData.getNumRows(); i++) { - if (!isNaN(xData[i]) && !isNaN(yData[i])) { - xValues.add(xData[i]); - yValues.add(yData[i]); - } - } - - xData = new double[xValues.size()]; - yData = new double[yValues.size()]; - - for (int i = 0; i < xValues.size(); i++) { - xData[i] = xValues.get(i); - yData[i] = yValues.get(i); - } - - List ret = new ArrayList<>(); - ret.add(xData); - ret.add(yData); - - return ret; - } - - private double regressionCoef(double[] xValues, double[] yValues) { - List v = new ArrayList<>(); - v.add(new GraphNode("x")); - v.add(new GraphNode("y")); - - Matrix bothData = new Matrix(xValues.length, 2); - - for (int i = 0; i < xValues.length; i++) { - bothData.set(i, 0, xValues[i]); - bothData.set(i, 1, yValues[i]); - } - - Regression regression2 = new RegressionDataset(bothData, v); - RegressionResult result; - - try { - result = regression2.regress(v.get(0), v.get(1)); - } catch (Exception e) { - return Double.NaN; - } - - return result.getCoef()[1]; - } - - private boolean isTwoCycle(Graph graph, Node x, Node y) { - List edges = graph.getEdges(x, y); - return edges.size() == 2; - } - - private boolean isUndirected(Graph graph, Node x, Node y) { - List edges = graph.getEdges(x, y); - if (edges.size() == 1) { - Edge edge = graph.getEdge(x, y); - return Edges.isUndirectedEdge(edge); - } - - return false; - } - - public void setEpsilon(double epsilon) { - this.epsilon = epsilon; - } - - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException(); - } - - this.knowledge = knowledge; - } - - /** - * @return the probability associated with the most recently computed independence test. - */ - public double getPValue(double fisherZ) { - return 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(fisherZ))); - } - - private Graph igci(Graph graph) { - if (this.dataSets.size() > 1) throw new IllegalArgumentException("Expecting exactly one data set for IGCI."); - - DataSet dataSet = this.dataSets.get(0); - Matrix matrix = dataSet.getDoubleData(); - - Graph _graph = new EdgeListGraph(graph.getNodes()); - - for (Edge edge : graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - Node _x = dataSet.getVariable(x.getName()); - Node _y = dataSet.getVariable(y.getName()); - - int xIndex = dataSet.getVariables().indexOf(_x); - int yIndex = dataSet.getVariables().indexOf(_y); - - double[] xCol = matrix.getColumn(xIndex).toArray(); - double[] yCol = matrix.getColumn(yIndex).toArray(); - - double f = igci(xCol, yCol); - - graph.removeEdges(x, y); - - if (f < -this.epsilon) { - _graph.addDirectedEdge(x, y); - } else if (f > this.epsilon) { - _graph.addDirectedEdge(y, x); - } else { - if (resolveOneEdgeMaxR3(xCol, yCol) < 0) { - _graph.addDirectedEdge(x, y); - } else { - _graph.addDirectedEdge(y, x); - } - } - - } - - return _graph; - } - - private double igci(double[] x, double[] y) { - int m = x.length; - - if (m != y.length) { - throw new IllegalArgumentException("Vectors must be the same length."); - } - - // uniform reference measure - - double meanx = mean(x); - double stdx = sd(x); - double meany = mean(y); - double stdy = sd(y); - - // Gaussian reference measure - for (int i = 0; i < x.length; i++) { - x[i] = (x[i] - meanx) / stdx; - y[i] = (y[i] - meany) / stdy; - } - - - double f; - - // difference of entropies - - double[] x1 = Arrays.copyOf(x, x.length); - Arrays.sort(x1); - - x1 = removeNaN(x1); - - double[] y1 = Arrays.copyOf(y, y.length); - Arrays.sort(y1); - - y1 = removeNaN(y1); - - int n1 = x1.length; - double hx = 0.0; - for (int i = 0; i < n1 - 1; i++) { - double delta = x1[i + 1] - x1[i]; - if (delta != 0) { - hx = hx + log(abs(delta)); - } - } - - hx = hx / (n1 - 1) + psi(n1) - psi(1); - - int n2 = y1.length; - double hy = 0.0; - for (int i = 0; i < n2 - 1; i++) { - double delta = y1[i + 1] - y1[i]; - - if (delta != 0) { - if (isNaN(delta)) { - throw new IllegalArgumentException(); - } - - hy = hy + log(abs(delta)); - } - } - - hy = hy / (n2 - 1) + psi(n2) - psi(1); - - f = hy - hx; - - return f; - - } - - private double[] removeNaN(double[] data) { - List _leaveOutMissing = new ArrayList<>(); - - for (double datum : data) { - if (!isNaN(datum)) { - _leaveOutMissing.add(datum); - } - } - - double[] _data = new double[_leaveOutMissing.size()]; - - for (int i = 0; i < _leaveOutMissing.size(); i++) _data[i] = _leaveOutMissing.get(i); - - return _data; - } - - - // digamma - - double psi(double x) { - double result = 0; - double xx; - double xx2; - double xx4; - assert (x > 0); - for (; x < 7; ++x) - result -= 1 / x; - x -= 1.0 / 2.0; - xx = 1.0 / x; - xx2 = xx * xx; - xx4 = xx2 * xx2; - result += log(x) + (1. / 24.) * xx2 - (7.0 / 960.0) * xx4 + (31.0 / 8064.0) * xx4 * xx2 - (127.0 / 30720.0) * xx4 * xx4; - return result; - } - - - private double combinedScore(double score1, double score2) { - return score1 + score2; - } - - private double score(Node y, List parents) { - if (this.score == Lofs.Score.andersonDarling) { - return andersonDarlingPASquare(y, parents); - } else if (this.score == Lofs.Score.kurtosis) { - return abs(kurtosis(residuals(y, parents, true))); - } else if (this.score == Lofs.Score.entropy) { - return entropy(y, parents); - } else if (this.score == Lofs.Score.skew) { - return abs(skewness(residuals(y, parents, true))); - } else if (this.score == Lofs.Score.fifthMoment) { - return abs(standardizedFifthMoment(residuals(y, parents, true))); - } else if (this.score == Lofs.Score.absoluteValue) { - return meanAbsolute(y, parents); - } else if (this.score == Lofs.Score.exp) { - return expScoreUnstandardized(y, parents); - } else if (this.score == Lofs.Score.other) { - double[] _f = residuals(y, parents, true); - return score(_f); - } else if (this.score == Lofs.Score.logcosh) { - return logCoshScore(y, parents); - } - - throw new IllegalStateException(); - } - - private double score(double[] col) { - if (this.score == Lofs.Score.andersonDarling) { - return new AndersonDarlingTest(col).getASquaredStar(); - } else if (this.score == Lofs.Score.entropy) { - return maxEntApprox(col); - } else if (this.score == Lofs.Score.kurtosis) { - col = DataUtils.standardizeData(col); - return -abs(kurtosis(col)); - } else if (this.score == Lofs.Score.skew) { - return abs(skewness(col)); - } else if (this.score == Lofs.Score.fifthMoment) { - return abs(standardizedFifthMoment(col)); - } else if (this.score == Lofs.Score.absoluteValue) { - return StatUtils.meanAbsolute(col); - } else if (this.score == Lofs.Score.exp) { - return expScoreUnstandardized(col); - } else if (this.score == Lofs.Score.other) { - return abs(kurtosis(col)); - } else if (this.score == Lofs.Score.logcosh) { - return StatUtils.logCoshScore(col); - } - - throw new IllegalStateException("Unrecognized score: " + this.score); - } - - //=============================PRIVATE METHODS=========================// - - private double meanAbsolute(Node node, List parents) { - double[] _f = residuals(node, parents, false); - - return StatUtils.meanAbsolute(_f); - } - - private double expScoreUnstandardized(Node node, List parents) { - double[] _f = residuals(node, parents, false); - - return expScoreUnstandardized(_f); - } - - private double expScoreUnstandardized(double[] _f) { - double sum = 0.0; - - for (double v : _f) { - sum += exp(v); - } - - double expected = sum / _f.length; - return -abs(log(expected)); - } - - private double logCoshScore(Node node, List parents) { - double[] _f = residuals(node, parents, true); - return StatUtils.logCoshScore(_f); - } - - private double[] residuals(Node node, List parents, boolean standardize) { - List _residuals = new ArrayList<>(); - - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); - - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); - } - - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - DataSet dataSet = this.dataSets.get(m); - - int targetCol = dataSet.getColumn(target); - - for (int i = 0; i < dataSet.getNumRows(); i++) { - if (isNaN(dataSet.getDouble(i, targetCol))) { - continue DATASET; - } - } - - for (Node regressor : regressors) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - int regressorCol = dataSet.getColumn(regressor); - - for (int i = 0; i < dataSet.getNumRows(); i++) { - if (isNaN(dataSet.getDouble(i, regressorCol))) { - continue DATASET; - } - } - } - - RegressionResult result = getRegressions().get(m).regress(target, regressors); - double[] residualsSingleDataset = result.getResiduals().toArray(); - - if (result.getCoef().length > 0) { - double intercept = result.getCoef()[0]; - - for (int i2 = 0; i2 < residualsSingleDataset.length; i2++) { - residualsSingleDataset[i2] = residualsSingleDataset[i2] + intercept; - } - } - - for (double _x : residualsSingleDataset) { - if (isNaN(_x)) continue; - _residuals.add(_x); - } - } - - double[] _f = new double[_residuals.size()]; - - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); - } - - if (standardize) { - _f = DataUtils.standardizeData(_f); - } - - return _f; - } - - private double andersonDarlingPASquare(Node node, List parents) { - double[] _f = residuals(node, parents, true); -// return new AndersonDarlingTest(_f).getASquaredStar(); - return new AndersonDarlingTest(_f).getASquared(); - } - - private double entropy(Node node, List parents) { - double[] _f = residuals(node, parents, true); - return maxEntApprox(_f); - } - - private double pValue(Node node, List parents) { - List _residuals = new ArrayList<>(); - - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); - - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); - } - - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - DataSet dataSet = this.dataSets.get(m); - - int targetCol = dataSet.getColumn(target); - - for (int i = 0; i < dataSet.getNumRows(); i++) { - if (isNaN(dataSet.getDouble(i, targetCol))) { - continue DATASET; - } - } - - for (Node regressor : regressors) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - int regressorCol = dataSet.getColumn(regressor); - - for (int i = 0; i < dataSet.getNumRows(); i++) { - if (isNaN(dataSet.getDouble(i, regressorCol))) { - continue DATASET; - } - } - } - - RegressionResult result = getRegressions().get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); - - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (isNaN(residualsSingleDataset.get(h))) { - continue DATASET; - } - } - - Vector _residualsSingleDataset = new Vector(residualsSingleDataset.toArray()); - - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); - } - } - - double[] _f = new double[_residuals.size()]; - - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); - } - - double p = new AndersonDarlingTest(_f).getP(); - - if (p > 1.0 || isNaN(p)) p = 1.0; - - return p; - } - - private Graph getCPDAG() { - return this.CPDAG; - } - - private Node getVariable(List variables, String name) { - for (Node node : variables) { - if (name.equals(node.getName())) { - return node; - } - } - - return null; - } - - private Graph resolveEdgeConditional(Graph graph) { - setDataSets(this.dataSets); - - Set edgeList1 = graph.getEdges(); -// RandomUtil.shuffle(edgeList1); - - for (Edge adj : edgeList1) { - Node x = adj.getNode1(); - Node y = adj.getNode2(); - - resolveEdgeConditional(graph, x, y); - } - - return graph; - } - - Matrix _data; - - private void resolveEdgeConditional(Graph graph, Node x, Node y) { - if (this._data == null) { - this._data = DataUtils.centerData(this.matrices.get(0)); - } - int xIndex = this.dataSets.get(0).getColumn(this.dataSets.get(0).getVariable(x.getName())); - int yIndex = this.dataSets.get(0).getColumn(this.dataSets.get(0).getVariable(y.getName())); - double[] xCol = this._data.getColumn(xIndex).toArray(); - double[] yCol = this._data.getColumn(yIndex).toArray(); - int N = xCol.length; - - double[][] yCols = new double[1][N]; - yCols[0] = yCol; - - double[][] xCols = new double[1][N]; - xCols[0] = xCol; - - double[][] empty = new double[0][N]; - - double[] resX = conditionalResiduals(xCol, empty); - double[] resY = conditionalResiduals(yCol, empty); - double[] resXY = conditionalResiduals(xCol, yCols); - double[] resYX = conditionalResiduals(yCol, xCols); - - double ngX = new AndersonDarlingTest(xCol).getASquared(); - double ngY = new AndersonDarlingTest(yCol).getASquared(); - - graph.removeEdges(x, y); - - double sdX = sd(resX); - double sdXY = sd(resXY); - double sdY = sd(resY); - double sdYX = sd(resYX); - - double abs1 = abs(sdX - sdXY); - double abs2 = abs(sdY - sdYX); - - if (abs(abs1 - abs2) < this.epsilon) { - System.out.println("Orienting by non-Gaussianity " + abs(abs1 - abs2) + " epsilon = " + this.epsilon); - System.out.println(x + "===" + y); - double v = resolveOneEdgeMaxR3b(xCol, yCol); - - if (v < 0) { - graph.addDirectedEdge(x, y); - } else if (v > 0) { - graph.addDirectedEdge(y, x); - } else { - graph.addUndirectedEdge(x, y); - } - - return; - } - - System.out.println("Orienting by variances " + abs(abs1 - abs2)); - System.out.println(x + "===" + y); - - if (sdXY + ngY < sdYX + ngX) { - graph.addDirectedEdge(x, y); - } else { - graph.addDirectedEdge(y, x); - } - } - - private double[] conditionalResiduals(double[] x, double[][] y) { - int N = x.length; - double[] residuals = new double[N]; - - double _h = 1.0; - - for (double[] doubles : y) { - _h *= h(doubles); - } - - _h = (y.length == 0) ? 1.0 : pow(_h, 1.0 / (y.length)); - - for (int i = 0; i < N; i++) { - double xi = x[i]; - - double sum = 0.0; - double kTot = 0.0; - - for (int j = 0; j < N; j++) { - double d = distance(y, i, j); - double k = kernel(d / _h) / _h; - if (k < 1e-5) continue; - double xj = x[j]; - sum += k * xj; - kTot += k; - } - - residuals[i] = xi - (sum / kTot); - } - - return residuals; - } - - private double h(double[] xCol) { -// % optimal bandwidth suggested by Bowman and Azzalini (1997) p.31 (rks code Matlab) -// h *= median(abs(x-median(x)))/0.6745*(4/3/r.h)^0.2, geometric mean across variables. - - double[] g = new double[xCol.length]; - double median = median(xCol); - for (int j = 0; j < xCol.length; j++) g[j] = abs(xCol[j] - median); - return median(g) / 0.6745 * pow((4.0 / 3.0) / xCol.length, 0.2); - } - - public double kernel(double z) { - return kernel1(z); - } - - private final double SQRT = sqrt(2. * PI); - - // Gaussian - public double kernel1(double z) { - return exp(-(z * z) / 2.) / this.SQRT; //(sqrt(2. * PI)); - } - - // Uniform - public double kernel2(double z) { - if (abs(z) > 1) return 0; - else return .5; - } - - // Triangular - public double kernel3(double z) { - if (abs(z) > 1) return 0; - else return 1 - abs(z); - } - - // Epanechnikov - public double kernel4(double z) { - if (abs(z) > 1) return 0; - else return (3. / 4.) * (1. - z * z); - } - - // Quartic - public double kernel5(double z) { - if (abs(z) > 1) return 0; - else return 15. / 16. * pow(1. - z * z, 2.); - } - - // Triweight - public double kernel6(double z) { - if (abs(z) > 1) return 0; - else return 35. / 32. * pow(1. - z * z, 3.); - } - - // Tricube - public double kernel7(double z) { - if (abs(z) > 1) return 0; - else return 70. / 81. * pow(1. - z * z * z, 3.); - } - - // Cosine - public double kernel8(double z) { - if (abs(z) > 1) return 0; - else return (PI / 4.) * cos((PI / 2.) * z); - } - - private double distance(double[][] yCols, int i, int j) { - double sum = 0.0; - - for (double[] yCol : yCols) { - double d = yCol[i] - yCol[j]; - sum += d * d; - } - - return sqrt(sum); - } - - - private double resolveOneEdgeMaxR3(double[] x, double[] y) { - OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression(); - double[][] _x = new double[1][]; - _x[0] = x; - double[][] _y = new double[1][]; - _y[0] = y; - - regression.newSampleData(x, transpose(_y)); - double[] rXY = regression.estimateResiduals(); - - regression.newSampleData(y, transpose(_x)); - double[] rYX = regression.estimateResiduals(); - - double xPlus = new AndersonDarlingTest(rXY).getASquared(); - double xMinus = new AndersonDarlingTest(x).getASquared(); - double yPlus = new AndersonDarlingTest(rYX).getASquared(); - double yMinus = new AndersonDarlingTest(y).getASquared(); - - double deltaX = xPlus - xMinus; - double deltaY = yPlus - yMinus; - - return deltaX - deltaY; - } - - private double resolveOneEdgeMaxR3b(double[] x, double[] y) { - int N = x.length; - - double[][] yCols = new double[1][N]; - yCols[0] = y; - - double[][] xCols = new double[1][N]; - xCols[0] = x; - - double[][] empty = new double[0][N]; - - double[] rX = conditionalResiduals(x, empty); - double[] rY = conditionalResiduals(y, empty); - double[] rXY = conditionalResiduals(x, yCols); - double[] rYX = conditionalResiduals(y, xCols); - - double xPlus = new AndersonDarlingTest(rXY).getASquared(); - double xMinus = new AndersonDarlingTest(rX).getASquared(); - double yPlus = new AndersonDarlingTest(rYX).getASquared(); - double yMinus = new AndersonDarlingTest(rY).getASquared(); - - double deltaX = xPlus - xMinus; - double deltaY = yPlus - yMinus; - - return deltaX - deltaY; - } - -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java new file mode 100644 index 0000000000..5fe60781d4 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java @@ -0,0 +1,673 @@ +/////////////////////////////////////////////////////////////////////////////// +// For information as to what this class does, see the Javadoc, below. // +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // +// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // +// Scheines, Joseph Ramsey, and Clark Glymour. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +/////////////////////////////////////////////////////////////////////////////// + +package edu.cmu.tetrad.search.WIP; + +import cern.colt.list.DoubleArrayList; +import cern.jet.stat.Descriptive; +import edu.cmu.tetrad.data.AndersonDarlingTest; +import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.regression.Regression; +import edu.cmu.tetrad.regression.RegressionDataset; +import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.MeekRules; +import edu.cmu.tetrad.util.Vector; +import edu.cmu.tetrad.util.*; +import org.apache.commons.math3.util.FastMath; + +import java.util.*; + +/** + * LOFS = Ling Orientation Fixed Structure. + * + * @author Joseph Ramsey + */ +public class LofsOld { + private final Graph cpdag; + private final List dataSets; + private double alpha = 0.05; + private final ArrayList regressions; + private final List variables; + private final boolean strongR2; + private final boolean meekDone; + private final boolean meanCenterResiduals; + + public enum Score { + andersonDarling, skew, kurtosis, fifthMoment, absoluteValue, + exp, expUnstandardized, expUnstandardizedInverted, other, logcosh, entropy + } + + private Score score = Score.andersonDarling; + + //===============================CONSTRUCTOR============================// + + public LofsOld(Graph cpdag, List dataSets, boolean strongR2, boolean meekDone, boolean meanCenterResiduals) + throws IllegalArgumentException { + this.strongR2 = strongR2; + this.meekDone = meekDone; + this.meanCenterResiduals = meanCenterResiduals; + + if (cpdag == null) { + throw new IllegalArgumentException("CPDAG must be specified."); + } + + if (dataSets == null) { + throw new IllegalArgumentException("Data set must be specified."); + } + + this.cpdag = cpdag; + this.dataSets = dataSets; + + this.regressions = new ArrayList<>(); + this.variables = dataSets.get(0).getVariables(); + + for (DataSet dataSet : dataSets) { + this.regressions.add(new RegressionDataset(dataSet)); + } + } + + public Graph orient() { + Graph skeleton = GraphUtils.undirectedGraph(getCpdag()); + Graph graph = new EdgeListGraph(skeleton.getNodes()); + + List nodes = skeleton.getNodes(); +// RandomUtil.shuffle(nodes); + + if (isR1Done()) { + ruleR1(skeleton, graph, nodes); + } + + for (Edge edge : skeleton.getEdges()) { + if (!graph.isAdjacentTo(edge.getNode1(), edge.getNode2())) { + graph.addUndirectedEdge(edge.getNode1(), edge.getNode2()); + } + } + + if (isR2Done()) { + ruleR2(skeleton, graph); + } + + if (isMeekDone()) { + new MeekRules().orientImplied(graph); + } + + return graph; + } + + private void ruleR1(Graph skeleton, Graph graph, List nodes) { + for (Node node : nodes) { + SortedMap scoreReports = new TreeMap<>(); + + List adj = skeleton.getAdjacentNodes(node); + + SublistGenerator gen = new SublistGenerator(adj.size(), adj.size()); + int[] choice; + double maxScore = Double.NEGATIVE_INFINITY; + List parents = null; + + while ((choice = gen.next()) != null) { + List _parents = GraphUtils.asList(choice, adj); + + double score = score(node, _parents); + scoreReports.put(-score, _parents.toString()); + + if (score > maxScore) { + maxScore = score; + parents = _parents; + } + } + + for (double score : scoreReports.keySet()) { + TetradLogger.getInstance().log("score", "For " + node + " parents = " + scoreReports.get(score) + " score = " + -score); + } + + TetradLogger.getInstance().log("score", ""); + + if (parents == null) { + continue; + } + + if (normal(node, parents)) continue; + + for (Node _node : adj) { + if (parents.contains(_node)) { + Edge parentEdge = Edges.directedEdge(_node, node); + + if (!graph.containsEdge(parentEdge)) { + graph.addEdge(parentEdge); + } + } + } + } + } + + private void ruleR2(Graph skeleton, Graph graph) { + Set edgeList1 = skeleton.getEdges(); +// RandomUtil.shuffle(edgeList1); + + for (Edge adj : edgeList1) { + Node x = adj.getNode1(); + Node y = adj.getNode2(); + + if (!isR2Orient2Cycles() && isTwoCycle(graph, x, y)) { + continue; + } + + if (!isTwoCycle(graph, x, y) && !isUndirected(graph, x, y)) { + continue; + } + + resolveOneEdgeMax(graph, x, y, isStrongR2()); + } + } + + private boolean isTwoCycle(Graph graph, Node x, Node y) { + List edges = graph.getEdges(x, y); + return edges.size() == 2; + } + + private boolean isUndirected(Graph graph, Node x, Node y) { + List edges = graph.getEdges(x, y); + if (edges.size() == 1) { + Edge edge = graph.getEdge(x, y); + return Edges.isUndirectedEdge(edge); + } + + return false; + } + + private boolean normal(Node node, List parents) { + if (getAlpha() > .999) { + return false; + } + + return pValue(node, parents) > getAlpha(); + } + + private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { + if (RandomUtil.getInstance().nextDouble() > 0.5) { + Node temp = x; + x = y; + y = temp; + } + + TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y); + + SortedMap scoreReports = new TreeMap<>(); + + List neighborsx = graph.getAdjacentNodes(x); + neighborsx.remove(y); + + double max = Double.NEGATIVE_INFINITY; + boolean left = false; + boolean right = false; + + SublistGenerator genx = new SublistGenerator(neighborsx.size(), neighborsx.size()); + int[] choicex; + + while ((choicex = genx.next()) != null) { + List condxMinus = GraphUtils.asList(choicex, neighborsx); + + List condxPlus = new ArrayList<>(condxMinus); + condxPlus.add(y); + + double xPlus = score(x, condxPlus); + double xMinus = score(x, condxMinus); + + List neighborsy = graph.getAdjacentNodes(y); + neighborsy.remove(x); + + SublistGenerator geny = new SublistGenerator(neighborsy.size(), neighborsy.size()); + int[] choicey; + + while ((choicey = geny.next()) != null) { + List condyMinus = GraphUtils.asList(choicey, neighborsy); + + List condyPlus = new ArrayList<>(condyMinus); + condyPlus.add(x); + + double yPlus = score(y, condyPlus); + double yMinus = score(y, condyMinus); + + // Checking them all at once is expensive but avoids lexical ordering problems in the algorithm. + if (normal(y, condyPlus) || normal(x, condxMinus) || normal(x, condxPlus) || normal(y, condyMinus)) { + continue; + } + + final double delta = 0.0; + + if (strong) { + if (yPlus <= xPlus + delta && xMinus <= yMinus + delta) { + double score = combinedScore(xPlus, yMinus); + + if (yPlus <= yMinus + delta && xMinus <= xPlus + delta) { + String s = "\nStrong " + y + "->" + x + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + + if (score > max) { + max = score; + left = true; + right = false; + } + } else { + String s = "\nNo directed edge " + x + "--" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + } + } else if (xPlus <= yPlus + delta && yMinus <= xMinus + delta) { + double score = combinedScore(yPlus, xMinus); + + if (yMinus <= yPlus + delta && xPlus <= xMinus + delta) { + String s = "\nStrong " + x + "->" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + + if (score > max) { + max = score; + left = false; + right = true; + } + } else { + String s = "\nNo directed edge " + x + "--" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + } + } else if (yPlus <= xPlus + delta && yMinus <= xMinus + delta) { + double score = combinedScore(yPlus, xMinus); + + String s = "\nNo directed edge " + x + "--" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + } else if (xPlus <= yPlus + delta && xMinus <= yMinus + delta) { + double score = combinedScore(yPlus, xMinus); + + String s = "\nNo directed edge " + x + "--" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + } + } else { + if (yPlus <= xPlus + delta && xMinus <= yMinus + delta) { + double score = combinedScore(xPlus, yMinus); + + String s = "\nWeak " + y + "->" + x + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + + if (score > max) { + max = score; + left = true; + right = false; + } + } else if (xPlus <= yPlus + delta && yMinus <= xMinus + delta) { + double score = combinedScore(yPlus, xMinus); + + String s = "\nWeak " + x + "->" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + + if (score > max) { + max = score; + left = false; + right = true; + } + } else if (yPlus <= xPlus + delta && yMinus <= xMinus + delta) { + double score = combinedScore(yPlus, xMinus); + + String s = "\nNo directed edge " + x + "--" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + } else if (xPlus <= yPlus + delta && xMinus <= yMinus + delta) { + double score = combinedScore(yPlus, xMinus); + + String s = "\nNo directed edge " + x + "--" + y + " " + score + + "\n Parents(" + x + ") = " + condxMinus + + "\n Parents(" + y + ") = " + condyMinus; + + scoreReports.put(-score, s); + } + } + } + } + + for (double score : scoreReports.keySet()) { + TetradLogger.getInstance().log("info", scoreReports.get(score)); + } + + graph.removeEdges(x, y); + + if (left) { + graph.addDirectedEdge(y, x); + } + + if (right) { + graph.addDirectedEdge(x, y); + } + + if (!graph.isAdjacentTo(x, y)) { + graph.addUndirectedEdge(x, y); + } + } + + private double combinedScore(double score1, double score2) { + return score1 + score2; + } + + private double score(Node y, List parents) { + if (this.score == Score.andersonDarling) { + return andersonDarlingPASquareStar(y, parents); + } else if (this.score == Score.kurtosis) { + return FastMath.abs(StatUtils.kurtosis(residual(y, parents))); + } else if (this.score == Score.skew) { + return FastMath.abs(StatUtils.skewness(residual(y, parents))); + } else if (this.score == Score.fifthMoment) { + return FastMath.abs(StatUtils.standardizedFifthMoment(residual(y, parents))); + } else if (this.score == Score.absoluteValue) { + return localScoreA(y, parents); + } + + throw new IllegalStateException(); + } + + //=============================PRIVATE METHODS=========================// + + private double localScoreA(Node node, List parents) { + double score = 0.0; + + List _residuals = new ArrayList<>(); + + Node target = getVariable(this.variables, node.getName()); + List regressors = new ArrayList<>(); + + for (Node _regressor : parents) { + Node variable = getVariable(this.variables, _regressor.getName()); + regressors.add(variable); + } + + DATASET: + for (int m = 0; m < this.dataSets.size(); m++) { + RegressionResult result = this.regressions.get(m).regress(target, regressors); + Vector residualsSingleDataset = result.getResiduals(); + + for (int h = 0; h < residualsSingleDataset.size(); h++) { + if (Double.isNaN(residualsSingleDataset.get(h))) { + continue DATASET; + } + } + + DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + + double mean = Descriptive.mean(_residualsSingleDataset); + double std = Descriptive.standardDeviation(Descriptive.variance(_residualsSingleDataset.size(), + Descriptive.sum(_residualsSingleDataset), Descriptive.sumOfSquares(_residualsSingleDataset))); + + for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { + _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean) / std); + } + + for (int k = 0; k < _residualsSingleDataset.size(); k++) { + _residuals.add(_residualsSingleDataset.get(k)); + } + } + + double[] _f = new double[_residuals.size()]; + + + for (int k = 0; k < _residuals.size(); k++) { + _f[k] = _residuals.get(k); + } + + DoubleArrayList f = new DoubleArrayList(_f); + + for (int k = 0; k < _residuals.size(); k++) { + f.set(k, FastMath.abs(f.get(k))); + } + + double _mean = Descriptive.mean(f); + double diff = _mean - FastMath.sqrt(2.0 / FastMath.PI); + score += diff * diff; + + return score; + } + + private double andersonDarlingPASquareStar(Node node, List parents) { + List _residuals = new ArrayList<>(); + + Node target = getVariable(this.variables, node.getName()); + List regressors = new ArrayList<>(); + + for (Node _regressor : parents) { + Node variable = getVariable(this.variables, _regressor.getName()); + regressors.add(variable); + } + + DATASET: + for (int m = 0; m < this.dataSets.size(); m++) { + RegressionResult result = this.regressions.get(m).regress(target, regressors); + Vector residualsSingleDataset = result.getResiduals(); + + for (int h = 0; h < residualsSingleDataset.size(); h++) { + if (Double.isNaN(residualsSingleDataset.get(h))) { + continue DATASET; + } + } + + DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + + double mean = Descriptive.mean(_residualsSingleDataset); + + // By centering the individual residual columns, all moments of the mixture become weighted + // averages of the momentsof the individual columns. http://en.wikipedia.org/wiki/Mixture_ + // distribution#Finite_and_countable_mixtures + for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { + if (isMeanCenterResiduals()) { + _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); + } + } + + for (int k = 0; k < _residualsSingleDataset.size(); k++) { + _residuals.add(_residualsSingleDataset.get(k)); + } + } + + double[] _f = new double[_residuals.size()]; + + for (int k = 0; k < _residuals.size(); k++) { + _f[k] = _residuals.get(k); + } + + return new AndersonDarlingTest(_f).getASquaredStar(); + } + + private double pValue(Node node, List parents) { + List _residuals = new ArrayList<>(); + + Node target = getVariable(this.variables, node.getName()); + List regressors = new ArrayList<>(); + + for (Node _regressor : parents) { + Node variable = getVariable(this.variables, _regressor.getName()); + regressors.add(variable); + } + + DATASET: + for (int m = 0; m < this.dataSets.size(); m++) { + RegressionResult result = this.regressions.get(m).regress(target, regressors); + Vector residualsSingleDataset = result.getResiduals(); + + for (int h = 0; h < residualsSingleDataset.size(); h++) { + if (Double.isNaN(residualsSingleDataset.get(h))) { + continue DATASET; + } + } + + DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + + double mean = Descriptive.mean(_residualsSingleDataset); + + for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { + if (isMeanCenterResiduals()) { + _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); + } + } + + for (int k = 0; k < _residualsSingleDataset.size(); k++) { + _residuals.add(_residualsSingleDataset.get(k)); + } + } + + double[] _f = new double[_residuals.size()]; + + for (int k = 0; k < _residuals.size(); k++) { + _f[k] = _residuals.get(k); + } + + return new AndersonDarlingTest(_f).getP(); + } + + private double[] residual(Node node, List parents) { + List _residuals = new ArrayList<>(); + + Node target = getVariable(this.variables, node.getName()); + List regressors = new ArrayList<>(); + + for (Node _regressor : parents) { + Node variable = getVariable(this.variables, _regressor.getName()); + regressors.add(variable); + } + + DATASET: + for (int m = 0; m < this.dataSets.size(); m++) { + RegressionResult result = this.regressions.get(m).regress(target, regressors); + Vector residualsSingleDataset = result.getResiduals(); + + for (int h = 0; h < residualsSingleDataset.size(); h++) { + if (Double.isNaN(residualsSingleDataset.get(h))) { + continue DATASET; + } + } + + DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); + + double mean = Descriptive.mean(_residualsSingleDataset); + + for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { + _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); + } + + for (int k = 0; k < _residualsSingleDataset.size(); k++) { + _residuals.add(_residualsSingleDataset.get(k)); + } + } + + double[] _f = new double[_residuals.size()]; + + for (int k = 0; k < _residuals.size(); k++) { + _f[k] = _residuals.get(k); + } + + return _f; + } + + public double getAlpha() { + return this.alpha; + } + + public void setAlpha(double alpha) { + if (alpha < 0.0 || alpha > 1.0) { + throw new IllegalArgumentException("Alpha is in range [0, 1]"); + } + + this.alpha = alpha; + } + + private Graph getCpdag() { + return this.cpdag; + } + + private Node getVariable(List variables, String name) { + for (Node node : variables) { + if (name.equals(node.getName())) { + return node; + } + } + + return null; + } + + public boolean isR1Done() { + return true; + } + + public boolean isR2Done() { + return true; + } + + public boolean isMeekDone() { + return this.meekDone; + } + + public boolean isStrongR2() { + return this.strongR2; + } + + public boolean isR2Orient2Cycles() { + return true; + } + + public Score getScore() { + return this.score; + } + + public void setScore(Score score) { + if (score == null) { + throw new NullPointerException(); + } + + this.score = score; + } + + public boolean isMeanCenterResiduals() { + return this.meanCenterResiduals; + } + +} + + From ee0701326362b9c5d9452857c25077186ba13444 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:03:17 -0400 Subject: [PATCH 274/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Lofs.java | 146 ++++++++++-------- 1 file changed, 84 insertions(+), 62 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index fe8a1bdfe6..94ae23f527 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -40,20 +40,28 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * LOFS = Ling Orientation Fixed Structure. Some additional algorithm. - *

- * Expands the set of algorithm from Lofs. + *

These are methods for linear, non-Gaussian Orientation with a Fixed graph + * Structure (LOFS). The options for different types of scores are given in the enum + * Lofs.Score. The options for rules to use to do the orientations are given in the + * enum, Lofs.Rule. Most of these are taken from the literature and ca be googled.

* * @author Joseph Ramsey + * @see Score + * @see Rule */ public class Lofs { - public enum Score { andersonDarling, skew, kurtosis, fifthMoment, absoluteValue, exp, expUnstandardized, expUnstandardizedInverted, other, logcosh, entropy } - private final Graph CPDAG; + // orientStrongerDirection list of past and present rules. + public enum Rule { + IGCI, R1TimeLag, R1, R2, R3, Tanh, EB, Skew, SkewE, RSkew, RSkewE, + Patel, Patel25, Patel50, Patel75, Patel90, FastICA, RC + } + + private final Graph cpdag; private List dataSets; private List matrices; private double alpha = 1.1; @@ -61,27 +69,32 @@ public enum Score { private List variables; private boolean orientStrongerDirection; private boolean r2Orient2Cycles = true; - private Lofs.Score score = Lofs.Score.andersonDarling; private double epsilon = 1.0; private Knowledge knowledge = new Knowledge(); private Rule rule = Rule.R1; private double selfLoopStrength; - //===============================CONSTRUCTOR============================// - - public Lofs(Graph CPDAG, List dataSets) + /** + * Constructor. + * + * @param graph The graph to be oriented. Orientations for the graph will be overwritten. + * @param dataSets A list of datasets to use to do the orientation. This may be just one + * dataset. If more than one dataset are given, the data will be concatenated + * (pooled). + */ + public Lofs(Graph graph, List dataSets) throws IllegalArgumentException { - if (dataSets == null) { - throw new IllegalArgumentException("Data set must be specified."); + if (graph == null) { + throw new IllegalArgumentException("graph must be specified."); } - if (CPDAG == null) { - throw new IllegalArgumentException("CPDAG must be specified."); + if (dataSets == null) { + throw new IllegalArgumentException("Data set must be specified."); } - this.CPDAG = CPDAG; + this.cpdag = graph; this.variables = dataSets.get(0).getVariables(); List dataSets2 = new ArrayList<>(); @@ -94,29 +107,14 @@ public Lofs(Graph CPDAG, List dataSets) this.dataSets = dataSets2; } - //==========================PUBLIC=========================================// - - public void setRule(Rule rule) { - this.rule = rule; - } - - public double getSelfLoopStrength() { - return this.selfLoopStrength; - } - - public void setSelfLoopStrength(double selfLoopStrength) { - this.selfLoopStrength = selfLoopStrength; - } - - // orientStrongerDirection list of past and present rules. - public enum Rule { - IGCI, R1TimeLag, R1, R2, R3, Tanh, EB, Skew, SkewE, RSkew, RSkewE, - Patel, Patel25, Patel50, Patel75, Patel90, FastICA, RC - } - + /** + * Orients the graph and returns the oriented graph. + * + * @return The oriented graph. + */ public Graph orient() { - Graph skeleton = GraphUtils.undirectedGraph(getCPDAG()); + Graph skeleton = GraphUtils.undirectedGraph(getCpdag()); Graph graph = new EdgeListGraph(skeleton.getNodes()); List nodes = skeleton.getNodes(); @@ -181,10 +179,43 @@ public Graph orient() { return graph; } - public double getAlpha() { - return this.alpha; + /** + * Sets the rule to use to do the orientation. + * + * @param rule This rule. + * @see Rule + */ + public void setRule(Rule rule) { + this.rule = rule; + } + + /** + * Sets the (LoFS) score to use. + * @param score This score. + * @see Score + */ + public void setScore(Lofs.Score score) { + if (score == null) { + throw new NullPointerException(); + } + + this.score = score; } + /** + * Sets the self-loop strength, if applicable. + * + * @param selfLoopStrength This strength. + */ + public void setSelfLoopStrength(double selfLoopStrength) { + this.selfLoopStrength = selfLoopStrength; + } + + /** + * Sets the alpha to use, where applicable. + * + * @param alpha This alpha. + */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { throw new IllegalArgumentException("Alpha is in range [0, 1]"); @@ -193,34 +224,25 @@ public void setAlpha(double alpha) { this.alpha = alpha; } - public boolean isOrientStrongerDirection() { - return this.orientStrongerDirection; - } - + /** + * Sets whether orientation should be done in the stronger direction, where + * applicable. + * + * @param orientStrongerDirection True if so. + */ public void setOrientStrongerDirection(boolean orientStrongerDirection) { this.orientStrongerDirection = orientStrongerDirection; } + /** + * Sets for R2 whether cycles shoudld be oriented. + * + * @param r2Orient2Cycles True if so. + */ public void setR2Orient2Cycles(boolean r2Orient2Cycles) { this.r2Orient2Cycles = r2Orient2Cycles; } - public boolean isR2Orient2Cycles() { - return this.r2Orient2Cycles; - } - - public Lofs.Score getScore() { - return this.score; - } - - public void setScore(Lofs.Score score) { - if (score == null) { - throw new NullPointerException(); - } - - this.score = score; - } - //==========================PRIVATE=======================================// private List getRegressions() { @@ -432,7 +454,7 @@ private void ruleR2(Graph skeleton, Graph graph) { Node x = adj.getNode1(); Node y = adj.getNode2(); - if (!isR2Orient2Cycles() && isTwoCycle(graph, x, y)) { + if (!this.r2Orient2Cycles && isTwoCycle(graph, x, y)) { continue; } @@ -440,7 +462,7 @@ private void ruleR2(Graph skeleton, Graph graph) { continue; } - resolveOneEdgeMax2(graph, x, y, !isOrientStrongerDirection()); + resolveOneEdgeMax2(graph, x, y, !this.orientStrongerDirection); } } @@ -760,7 +782,7 @@ public double scoreRow(int rowIndex, Matrix data, List> rows, List } // Add in the diagonal, assumed to consist entirely of 1's, indicating no self loop. - d += (1.0 - getSelfLoopStrength()) * data.get(i, rowIndex); + d += (1.0 - this.selfLoopStrength) * data.get(i, rowIndex); this.col[i] = d; } @@ -1645,8 +1667,8 @@ private double pValue(Node node, List parents) { return p; } - private Graph getCPDAG() { - return this.CPDAG; + private Graph getCpdag() { + return this.cpdag; } private Node getVariable(List variables, String name) { From df1fc27d5427fdc1f1b4b7697af1c166fa15857e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:15:15 -0400 Subject: [PATCH 275/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/MagSemBicScore.java | 89 ++++++++++++++++++- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java index 6e245ecbc5..a430b83507 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java @@ -28,9 +28,13 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import javax.help.UnsupportedOperationException; import java.util.*; /** + * This ia BIC score for a linear, Gaussian MAG (Mixed Ancestral Graph). It + * will perform the same as SemBicScore for DAGs. + * * @author Bryan Andrews */ public class MagSemBicScore implements Score { @@ -41,6 +45,11 @@ public class MagSemBicScore implements Score { private List order; + /** + * Constructor. + * + * @param covariances The covarainces to analyze. + */ public MagSemBicScore(ICovarianceMatrix covariances) { if (covariances == null) { throw new NullPointerException(); @@ -51,6 +60,11 @@ public MagSemBicScore(ICovarianceMatrix covariances) { this.order = null; } + /** + * Constructor. + * + * @param dataSet The continuous dataset to analyze. + */ public MagSemBicScore(DataSet dataSet) { if (dataSet == null) { throw new NullPointerException(); @@ -61,30 +75,63 @@ public MagSemBicScore(DataSet dataSet) { this.order = null; } + /** + * Returns the wrapped MAG. + * + * @return This MAG. + */ public Graph getMag() { return this.mag; } + /** + * Sets the MAG to wrap. + * + * @param mag This MAG. + */ public void setMag(Graph mag) { this.mag = mag; } + /** + * Sets the MAG to null. + */ public void resetMag() { this.mag = null; } + /** + * Returns the order. + * + * @return The order of variables, a list. + */ public List getOrder() { return this.order; } + /** + * Sets the order. + * + * @param order The order of variables, a list. + */ public void setOrder(List order) { this.order = order; } + /** + * Sets the order ot null. + */ public void resetOrder() { this.order = null; } + /** + * Return the BIC score for a node given its parents. + * + * @param i The index of the node. + * @param js The indices of the node's parents. + * @return The BIC score. + */ @Override public double localScore(int i, int... js) { if (this.mag == null || this.order == null) { @@ -149,44 +196,80 @@ public double localScore(int i, int... js) { return score; } - + /** + * @return The penalty discount, a multiplier on the penalty term of BIC. + */ public double getPenaltyDiscount() { return this.score.getPenaltyDiscount(); } + /** + * Seets the penalty discount. + * + * @param penaltyDiscount This number, a multiplier on the penalty term of BIC. + */ public void setPenaltyDiscount(double penaltyDiscount) { this.score.setPenaltyDiscount(penaltyDiscount); } - + /** + * @return localScore(y | z, x) - localScore(y | z). + */ @Override public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } + /** + * Returns the sample size. + * + * @return This size. + */ @Override public int getSampleSize() { return this.score.getSampleSize(); } + /** + * Returns the list of variables. + * + * @return This list. + */ @Override public List getVariables() { return this.score.getVariables(); } + /** + * Returns a judgment for FGES as to whether an edges with this bump + * (for this score) counts as an effect edge. + * + * @param bump Ths bump. + * @return The judgment. + * @see Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; } + /** + * Returns a judgment of the max degree needed for this score. + * + * @return This max. + * @see Fges + */ @Override public int getMaxDegree() { return this.score.getMaxDegree(); } + /** + * @throws UnsupportedOperationException Not implemented. + */ @Override public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException(); } private void constructHeadsTails(List> heads, List> tails, List mbo, List head, List in, Set an, Node v1) { From 08d7f011b71a5b5763a90186746eda753f796364 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:31:55 -0400 Subject: [PATCH 276/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../search/MaxPColliderOrientation.java | 130 +++--- .../edu/cmu/tetrad/search/MeekRulesCpdag.java | 376 ------------------ 2 files changed, 73 insertions(+), 433 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesCpdag.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java index 2d92ac7bce..033a21206c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java @@ -32,7 +32,9 @@ import java.util.concurrent.ConcurrentHashMap; /** - *

Performs a Max-P orientation of unshielded triples in a graph.

+ *

Performs a Max-P orientation of unshielded triples in a graph.

+ *

Ramsey, J. (2016). Improving accuracy and scalability of the pc + * algorithm by maximizing p-value. arXiv preprint arXiv:1610.00378.

* * @author Joseph Ramsey * @see PcMax @@ -45,6 +47,11 @@ public final class MaxPColliderOrientation { private int maxPathLength = 3; private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; + /** + * Constructor. + * + * @param test The test to use for orienting colliders using the Max-P rule. + */ public MaxPColliderOrientation(IndependenceTest test) { if (test == null) throw new NullPointerException(); this.independenceTest = test; @@ -53,18 +60,41 @@ public MaxPColliderOrientation(IndependenceTest test) { //======================================== PUBLIC METHODS ====================================// /** - * Searches for a PAG satisfying the description in Thomas Richardson (1997), dissertation, - * Carnegie Mellon University. Uses a simplification of that algorithm. + * Adds colliders to the given graph using the max P rule. + * + * @param graph The graph to orient. + * @see PcMax */ public synchronized void orient(Graph graph) { addColliders(graph); } /** - * @return The depth of search for the Fast Adjacency Search. + * Orient a single unshielded triple, x*-*y*-*z, in a graph. + * + * @param conflictRule The conflict rule to use. + * @param graph The graph to orient. + * @see edu.cmu.tetrad.search.PcAll.ConflictRule */ - public int getDepth() { - return this.depth; + public static void orientCollider(Node x, Node y, Node z, PcAll.ConflictRule conflictRule, Graph graph) { + if (conflictRule == PcAll.ConflictRule.PRIORITY) { + if (!(graph.getEndpoint(y, x) == Endpoint.ARROW || graph.getEndpoint(y, z) == Endpoint.ARROW)) { + graph.removeEdge(x, y); + graph.removeEdge(z, y); + graph.addDirectedEdge(x, y); + graph.addDirectedEdge(z, y); + } + } else if (conflictRule == PcAll.ConflictRule.BIDIRECTED) { + graph.setEndpoint(x, y, Endpoint.ARROW); + graph.setEndpoint(z, y, Endpoint.ARROW); + } else if (conflictRule == PcAll.ConflictRule.OVERWRITE) { + graph.removeEdge(x, y); + graph.removeEdge(z, y); + graph.addDirectedEdge(x, y); + graph.addDirectedEdge(z, y); + } + + TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); } /** @@ -74,7 +104,42 @@ public void setDepth(int depth) { this.depth = depth; } - //======================================== PRIVATE METHODS ====================================// + /** + * Sets whether the max P heuristic should be used. + * + * @param useHeuristic True if so. + */ + public void setUseHeuristic(boolean useHeuristic) { + this.useHeuristic = useHeuristic; + } + + /** + * Sets the max path length to use for the max P heuristic. + * + * @param maxPathLength This maximum. + */ + public void setMaxPathLength(int maxPathLength) { + this.maxPathLength = maxPathLength; + } + + /** + * Sets the PC conflict rule to use for orientation. + * + * @param conflictRule This rule. + * @see edu.cmu.tetrad.search.PcAll.ConflictRule + */ + public void setConflictRule(PcAll.ConflictRule conflictRule) { + this.conflictRule = conflictRule; + } + + /** + * Sets the knowledge to use for orientation. + * + * @param knowledge This knowledge. + */ + public void setKnowledge(Knowledge knowledge) { + this.knowledge = knowledge; + } private void addColliders(Graph graph) { Map scores = new ConcurrentHashMap<>(); @@ -99,7 +164,7 @@ private void addColliders(Graph graph) { Node b = triple.getY(); Node c = triple.getZ(); - orientCollider(graph, a, b, c, getConflictRule()); + orientCollider(graph, a, b, c, this.conflictRule); } } @@ -231,14 +296,6 @@ private void orientCollider(Graph graph, Node a, Node b, Node c, PcAll.ConflictR MaxPColliderOrientation.orientCollider(a, b, c, conflictRule, graph); } - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - // Returns true if there is an undirected path from x to either y or z within the given number of steps. private boolean existsShortPath(Node x, Node z, int bound, Graph graph) { Queue Q = new LinkedList<>(); @@ -280,47 +337,6 @@ private boolean existsShortPath(Node x, Node z, int bound, Graph graph) { return false; } - - public void setUseHeuristic(boolean useHeuristic) { - this.useHeuristic = useHeuristic; - } - - public int getMaxPathLength() { - return this.maxPathLength; - } - - public void setMaxPathLength(int maxPathLength) { - this.maxPathLength = maxPathLength; - } - - public static void orientCollider(Node x, Node y, Node z, PcAll.ConflictRule conflictRule, Graph graph) { - if (conflictRule == PcAll.ConflictRule.PRIORITY) { - if (!(graph.getEndpoint(y, x) == Endpoint.ARROW || graph.getEndpoint(y, z) == Endpoint.ARROW)) { - graph.removeEdge(x, y); - graph.removeEdge(z, y); - graph.addDirectedEdge(x, y); - graph.addDirectedEdge(z, y); - } - } else if (conflictRule == PcAll.ConflictRule.BIDIRECTED) { - graph.setEndpoint(x, y, Endpoint.ARROW); - graph.setEndpoint(z, y, Endpoint.ARROW); - } else if (conflictRule == PcAll.ConflictRule.OVERWRITE) { - graph.removeEdge(x, y); - graph.removeEdge(z, y); - graph.addDirectedEdge(x, y); - graph.addDirectedEdge(z, y); - } - - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); - } - - public PcAll.ConflictRule getConflictRule() { - return this.conflictRule; - } - - public void setConflictRule(PcAll.ConflictRule conflictRule) { - this.conflictRule = conflictRule; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesCpdag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesCpdag.java deleted file mode 100644 index c66ed12600..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesCpdag.java +++ /dev/null @@ -1,376 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.Endpoint; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.TetradLogger; - -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * Implements Meek's complete orientation rule set for PC (Chris Meek (1995), "Causal inference and causal explanation - * with background Knowledge"), modified for Conservative PC to check noncolliders against recorded noncolliders before - * orienting. - *

- * For now, the fourth rule is always performed. - * - * @author Joseph Ramsey - */ -public class MeekRulesCpdag implements ImpliedOrientation { - - private edu.cmu.tetrad.data.Knowledge Knowledge; - - /** - * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large - * graphs). - */ - private boolean aggressivelyPreventCycles; - - - /** - * The logger to use. - */ - private final TetradLogger logger = TetradLogger.getInstance(); - - - /** - * Constructs the MeekRules with no logging. - */ - public MeekRulesCpdag() { - - } - - //======================== Public Methods ========================// - - - public Set orientImplied(Graph graph) { - orientUsingMeekRulesLocally(this.Knowledge, graph); - return null; - } - - public void setKnowledge(Knowledge Knowledge) { - this.Knowledge = Knowledge; - } - - //============================== Private Methods ===================================// - - public void orientUsingMeekRulesLocally(Knowledge Knowledge, Graph graph) { - - this.logger.log("info", "Starting Orientation Step D."); - - boolean changed; - - do { - changed = meekR2(graph, Knowledge) || - meekR1Locally(graph, Knowledge) || meekR3(graph, Knowledge) || - meekR4(graph, Knowledge); - } while (changed); - - - this.logger.log("info", "Finishing Orientation Step D."); - } - - public boolean meekR1Locally(Graph graph, Knowledge Knowledge) { - List nodes = graph.getNodes(); - boolean changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = - new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - // Skip triples that are shielded. - if (graph.isAdjacentTo(b, c)) { - continue; - } - - if (graph.getEndpoint(b, a) == Endpoint.ARROW && - graph.paths().isUndirectedFromTo(a, c)) { - if (MeekRulesCpdag.isShieldedNoncollider(b, a, c, graph)) { - continue; - } - - if (MeekRulesCpdag.isArrowpointAllowed(a, c, Knowledge) && !graph.paths().isAncestorOf(c, a)) { - graph.setEndpoint(a, c, Endpoint.ARROW); - - this.logger.log("impliedOrientation", SearchLogUtils.edgeOrientedMsg( - "Meek R1 triangle (" + b + "-->" + a + "---" + c + ")", graph.getEdge(a, c))); - changed = true; - - meekR2(graph, Knowledge); - } - } else if (graph.getEndpoint(c, a) == Endpoint.ARROW && - graph.paths().isUndirectedFromTo(a, b)) { - if (MeekRulesCpdag.isShieldedNoncollider(b, a, c, graph)) { - continue; - } - - if (MeekRulesCpdag.isArrowpointAllowed(a, b, Knowledge) && !graph.paths().isAncestorOf(b, a)) { - graph.setEndpoint(a, b, Endpoint.ARROW); - - this.logger.log("impliedOrientation", SearchLogUtils.edgeOrientedMsg( - "Meek R1 triangle (" + c + "-->" + a + "---" + b + ")", graph.getEdge(a, b))); - changed = true; - - meekR2(graph, Knowledge); - } - } - } - } - - return changed; - } - - public boolean meekR2(Graph graph, Knowledge Knowledge) { - List nodes = graph.getNodes(); - final boolean changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - if (graph.paths().isDirectedFromTo(b, a) && - graph.paths().isDirectedFromTo(a, c) && - graph.paths().isUndirectedFromTo(b, c)) { - if (MeekRulesCpdag.isArrowpointAllowed(b, c, Knowledge) && !graph.paths().isAncestorOf(c, b)) { - graph.setEndpoint(b, c, Endpoint.ARROW); - this.logger.log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R2", graph.getEdge(b, c))); - meekR2(graph, Knowledge); - } - } else if (graph.paths().isDirectedFromTo(c, a) && - graph.paths().isDirectedFromTo(a, b) && - graph.paths().isUndirectedFromTo(c, b)) { - if (MeekRulesCpdag.isArrowpointAllowed(c, b, Knowledge) && !graph.paths().isAncestorOf(b, c)) { - graph.setEndpoint(c, b, Endpoint.ARROW); - this.logger.log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R2", graph.getEdge(c, b))); - meekR2(graph, Knowledge); - } - } - } - } - - return changed; - } - - /** - * Meek's rule R3. If a--b, a--c, a--d, c-->b, d-->b, then orient a-->b. - */ - public boolean meekR3(Graph graph, Knowledge Knowledge) { - - List nodes = graph.getNodes(); - boolean changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 3) { - continue; - } - - for (Node b : adjacentNodes) { - List otherAdjacents = new LinkedList<>(adjacentNodes); - otherAdjacents.remove(b); - - if (!graph.paths().isUndirectedFromTo(a, b)) { - continue; - } - - ChoiceGenerator cg = - new ChoiceGenerator(otherAdjacents.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node c = otherAdjacents.get(combination[0]); - Node d = otherAdjacents.get(combination[1]); - - if (graph.isAdjacentTo(c, d)) { - continue; - } - - if (!graph.paths().isUndirectedFromTo(a, c)) { - continue; - } - - if (!graph.paths().isUndirectedFromTo(a, d)) { - continue; - } - - if (MeekRulesCpdag.isShieldedNoncollider(c, a, d, graph)) { - continue; - } - - if (graph.paths().isDirectedFromTo(c, b) && - graph.paths().isDirectedFromTo(d, b)) { - if (MeekRulesCpdag.isArrowpointAllowed(a, b, Knowledge) && !graph.paths().isAncestorOf(b, a)) { - graph.setEndpoint(a, b, Endpoint.ARROW); - - this.logger.log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R3", graph.getEdge(a, b))); - changed = true; - meekR2(graph, Knowledge); - break; - } - } - } - } - } - - return changed; - } - - public boolean meekR4(Graph graph, Knowledge Knowledge) { - if (Knowledge == null) { - return false; - } - - List nodes = graph.getNodes(); - boolean changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 3) { - continue; - } - - for (Node d : adjacentNodes) { - if (!graph.isAdjacentTo(a, d)) { - continue; - } - - List otherAdjacents = new LinkedList<>(adjacentNodes); - otherAdjacents.remove(d); - - ChoiceGenerator cg = - new ChoiceGenerator(otherAdjacents.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = otherAdjacents.get(combination[0]); - Node c = otherAdjacents.get(combination[1]); - - if (!graph.paths().isUndirectedFromTo(a, b)) { - continue; - } - - if (!graph.paths().isUndirectedFromTo(a, c)) { - continue; - } - - if (MeekRulesCpdag.isShieldedNoncollider(c, a, b, graph)) { - continue; - } - - if (graph.paths().isDirectedFromTo(b, d) && - graph.paths().isDirectedFromTo(d, c)) { - if (MeekRulesCpdag.isArrowpointAllowed(a, c, Knowledge) && !graph.paths().isAncestorOf(c, a)) { - graph.setEndpoint(a, c, Endpoint.ARROW); - - this.logger.log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek T1", graph.getEdge(a, c))); - changed = true; - meekR2(graph, Knowledge); - break; - } - } else if (graph.paths().isDirectedFromTo(c, d) && - graph.paths().isDirectedFromTo(d, b)) { - if (MeekRulesCpdag.isArrowpointAllowed(a, b, Knowledge) && !graph.paths().isAncestorOf(b, a)) { - graph.setEndpoint(a, b, Endpoint.ARROW); - - this.logger.log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek T1", graph.getEdge(a, b))); - changed = true; - meekR2(graph, Knowledge); - break; - } - } - } - } - } - - return changed; - } - - private static boolean isShieldedNoncollider(Node a, Node b, Node c, - Graph graph) { - if (graph.underlines().isAmbiguousTriple(a, b, c)) { - return true; - } - - if (!graph.isAdjacentTo(a, b)) { - return true; - } - - if (!graph.isAdjacentTo(c, b)) { - return true; - } - - if (graph.isAdjacentTo(a, c)) { - return true; - } - - return graph.getEndpoint(a, b) == Endpoint.ARROW && - graph.getEndpoint(c, b) == Endpoint.ARROW; - - } - - private static boolean isArrowpointAllowed(Object from, Object to, - Knowledge Knowledge) { - if (Knowledge == null) return true; - return !Knowledge.isRequired(to.toString(), from.toString()) && - !Knowledge.isForbidden(from.toString(), to.toString()); - } - - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - - public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { - this.aggressivelyPreventCycles = aggressivelyPreventCycles; - } -} - - - From ebc64eeb7d71466f4fbfa55db61994ac8296db5a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:33:10 -0400 Subject: [PATCH 277/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../search/{MaxPColliderOrientation.java => MaxP.java} | 6 +++--- tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/PcStableMax.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{MaxPColliderOrientation.java => MaxP.java} (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java index 033a21206c..5146b89b97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxPColliderOrientation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java @@ -39,7 +39,7 @@ * @author Joseph Ramsey * @see PcMax */ -public final class MaxPColliderOrientation { +public final class MaxP { private final IndependenceTest independenceTest; private int depth = -1; private Knowledge knowledge = new Knowledge(); @@ -52,7 +52,7 @@ public final class MaxPColliderOrientation { * * @param test The test to use for orienting colliders using the Max-P rule. */ - public MaxPColliderOrientation(IndependenceTest test) { + public MaxP(IndependenceTest test) { if (test == null) throw new NullPointerException(); this.independenceTest = test; } @@ -293,7 +293,7 @@ private void testColliderHeuristic(Graph graph, Map colliders, N private void orientCollider(Graph graph, Node a, Node b, Node c, PcAll.ConflictRule conflictRule) { if (this.knowledge.isForbidden(a.getName(), b.getName())) return; if (this.knowledge.isForbidden(c.getName(), b.getName())) return; - MaxPColliderOrientation.orientCollider(a, b, c, conflictRule, graph); + MaxP.orientCollider(a, b, c, conflictRule, graph); } // Returns true if there is an undirected path from x to either y or z within the given number of steps. 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 8df5a773b5..46fa0e9cd5 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 @@ -381,7 +381,7 @@ public Graph search(List nodes) { System.out.println("MaxP orientation..."); } - MaxPColliderOrientation orientCollidersMaxP = new MaxPColliderOrientation(this.independenceTest); + MaxP orientCollidersMaxP = new MaxP(this.independenceTest); orientCollidersMaxP.setConflictRule(this.conflictRule); orientCollidersMaxP.setUseHeuristic(this.useHeuristic); orientCollidersMaxP.setMaxPathLength(this.maxPathLength); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java index e74d2a5d27..5681af7983 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java @@ -189,7 +189,7 @@ public Graph search(List nodes) { SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - MaxPColliderOrientation orientCollidersMaxP = new MaxPColliderOrientation(this.independenceTest); + MaxP orientCollidersMaxP = new MaxP(this.independenceTest); orientCollidersMaxP.setKnowledge(this.knowledge); orientCollidersMaxP.setUseHeuristic(this.useHeuristic); orientCollidersMaxP.setMaxPathLength(this.maxPathLength); From 14c27ddd24dcfdd7376236a01675015df6e571d1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:34:28 -0400 Subject: [PATCH 278/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java index cc0f5e333d..1b11e61086 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java @@ -55,7 +55,6 @@ public class MbClassify implements DiscreteClassifier { private int depth; private double prior; private int maxMissing; - private DiscreteVariable targetVariable; private double percentCorrect; private int[][] crossTabulation; From 6a520b397d744b3b6c6eb91bb01e895e849f84ca Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:37:47 -0400 Subject: [PATCH 279/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java index 0ffbf71ddb..a0e7103e4b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java @@ -29,7 +29,7 @@ /** * An interface for Markov blanket searches. * - * @author Joseph Ramsey + * @author josephramsey */ public interface MbSearch { From 58b1d4a942120dfa50d9753f616e272f1e49ac24 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:41:47 -0400 Subject: [PATCH 280/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/MbUtils.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java index 23b341ee5f..b7110193bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java @@ -30,7 +30,7 @@ /** * Some useful utilities for dealing with Markov blankets and Markov blanket DAGs. * - * @author Joseph Ramsey + * @author josephramsey */ public class MbUtils { @@ -38,6 +38,8 @@ public class MbUtils { * Trims the graph to the target, the parents and children of the target, and the parents of the children of the * target. Bidirected edges are interpreted as if they could be oriented in either direction. * + * @param graph The graph. + * @param target The target. * @param includeBidirected true if bidirected edges should be included. */ public static void trimToMbNodes(Graph graph, Node target, @@ -136,6 +138,9 @@ public static void trimToMbNodes(Graph graph, Node target, /** * Removes edges among the parents of the target. + * + * @param graph The graph. + * @param target The target. */ public static void trimEdgesAmongParents(Graph graph, Node target) { List parents = graph.getParents(target); @@ -151,7 +156,6 @@ public static void trimEdgesAmongParents(Graph graph, Node target) { Edge edge = graph.getEdge(v, w); if (edge != null) { -// LogUtils.getInstance().finest("Removing edge among parents: " + edge); graph.removeEdges(v, w); } } @@ -160,6 +164,9 @@ public static void trimEdgesAmongParents(Graph graph, Node target) { /** * Removes edges among the parents of children of the target. + * + * @param graph The graph. + * @param target The target. */ public static void trimEdgesAmongParentsOfChildren(Graph graph, Node target) { @@ -186,13 +193,18 @@ public static void trimEdgesAmongParentsOfChildren(Graph graph, Edge edge = graph.getEdge(v, w); if (edge != null) { -// LogUtils.getInstance().finest("Removing edge among parents: " + edge); graph.removeEdge(v, w); } } } } + /** + * Trims the graph to just the adjacents of the target. + * + * @param graph The graph. + * @param target The target. + */ public static void trimToAdjacents(Graph graph, Node target) { for (Node node : graph.getNodes()) { if (node == target) { @@ -263,8 +275,13 @@ private static Set listMbDags(Graph mbCPDAG, return dags; } - public static Graph getOneMbDag(Graph mbCPDAG) { - return SearchGraphUtils.dagFromCPDAG(mbCPDAG); + /** + * Returns an example DAG from the given MB CPDAG. + * @param mbCpdag The MB CPDAG. + * @return An example DAG in this CPDAG. + */ + public static Graph getOneMbDag(Graph mbCpdag) { + return SearchGraphUtils.dagFromCPDAG(mbCpdag); } /** From 744e00d3053feea5b536a8f2705219b244b20f50 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:52:01 -0400 Subject: [PATCH 281/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/MeekRules.java | 101 +++++++++++------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java index ea3d241096..c05c88f358 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java @@ -28,7 +28,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.TetradLogger; -import java.io.PrintStream; import java.util.*; /** @@ -56,9 +55,6 @@ public class MeekRules implements ImpliedOrientation { // Whether verbose output should be generated. - // Where verbose output should be sent. - private PrintStream out; - // True if verbose output should be printed. private boolean verbose; @@ -74,6 +70,12 @@ public MeekRules() { //======================== Public Methods ========================// + /** + * Uses the Meek rules to do as many orientations in the given graph as possible. + * + * @param graph The graph. + * @return The set of nodes that were visited in this orientation. + */ public Set orientImplied(Graph graph) { // The initial list of nodes to visit. Set visited = new HashSet<>(); @@ -111,46 +113,76 @@ public Set orientImplied(Graph graph) { return visited; } - public void revertToUnshieldedColliders(List nodes, Graph graph, Set visited) { - boolean reverted = true; - - while (reverted) { - reverted = false; - - for (Node node : nodes) { - if (revertToUnshieldedColliders(node, graph, visited)) { - reverted = true; - } - } - } - } - + /** + * Sets the knowledge to be used in the orientation. + * + * @param knowledge The knowledge. + * @see Knowledge + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } - - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - + /** + * Sets whether cycles should be aggressively prevented by cycle checking. + * + * @param aggressivelyPreventCycles True if so. + */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { this.aggressivelyPreventCycles = aggressivelyPreventCycles; } + /** + * Returns a complete set of all the edges that were changed in the course of + * orientation, as a map from the previous edges in the graph to the new, changed + * edges for the same node pair. For example, if X->Y was changed to X<-Y, thie + * map will send X->Y to X<-Y. + * + * @return This map. + */ public Map getChangedEdges() { return this.changedEdges; } - public void setOut(PrintStream out) { - this.out = out; + /** + * Sets whether verbose output should be printed. + * + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; } - public PrintStream getOut() { - return this.out; + /** + * Sets whether orientations in the graph should be reverted to its + * unshielded colliders before performing any Meek rule orintations. + * + * @param revertToUnshieldedColliders True if so. + */ + public void setRevertToUnshieldedColliders(boolean revertToUnshieldedColliders) { + this.revertToUnshieldedColliders = revertToUnshieldedColliders; } - //============================== Private Methods ===================================// + /** + * Reverts the subgraph of the given graph over the given nodes to just its unshielded colliders. + * + * @param nodes The nodes of the subgraph. + * @param graph The graph. + * @param visited The set of nodes visited. + */ + private void revertToUnshieldedColliders(List nodes, Graph graph, Set visited) { + boolean reverted = true; + + while (reverted) { + reverted = false; + + for (Node node : nodes) { + if (revertToUnshieldedColliders(node, graph, visited)) { + reverted = true; + } + } + } + } /** * Meek's rule R1: if a-->b, b---c, and a not adj to c, then b-->c @@ -276,11 +308,6 @@ private boolean direct(Node a, Node c, Graph graph, Set visited) { Edge before = graph.getEdge(a, c); graph.removeEdge(before); -// if (aggressivelyPreventCycles && GraphUtils.existsSemidirectedPath(c, a, graph)) { -// graph.addEdge(before); -// return false; -// } - if (aggressivelyPreventCycles && graph.paths().existsDirectedPathFromTo(c, a)) { graph.addEdge(before); return false; @@ -337,19 +364,11 @@ private void log(String message) { } } - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - private Set getCommonAdjacents(Node x, Node y, Graph graph) { Set adj = new HashSet<>(graph.getAdjacentNodes(x)); adj.retainAll(graph.getAdjacentNodes(y)); return adj; } - - public void setRevertToUnshieldedColliders(boolean revertToUnshieldedColliders) { - this.revertToUnshieldedColliders = revertToUnshieldedColliders; - } } From a7c0fe0caa435583fdc9044ff1771b0c0b73e7fb Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 08:58:08 -0400 Subject: [PATCH 282/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/FgesOrienter.java | 62 +-- .../tetrad/search/MeekRulesRestricted.java | 498 ------------------ .../java/edu/cmu/tetrad/search/Mimbuild.java | 2 +- 3 files changed, 5 insertions(+), 557 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesRestricted.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java index a6fa3f8418..bc474bfbe4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java @@ -115,16 +115,6 @@ public final class FgesOrienter implements GraphSearch, DagScorer { */ private final TetradLogger logger = TetradLogger.getInstance(); - /** - * The top n graphs found by the algorithm, where n is numCPDAGsToStore. - */ - private final SortedSet topGraphs = new TreeSet<>(); - - /** - * The number of top CPDAGs to store. - */ - private int numCPDAGsToStore; - /** * True if logs should be output. */ @@ -147,9 +137,6 @@ public final class FgesOrienter implements GraphSearch, DagScorer { // The static ForkJoinPool instance. private final ForkJoinPool pool = ForkJoinPoolInstance.getInstance().getPool(); - // A running tally of the total BIC score. - private double score; - // A graph where X--Y means that X and Y have non-zero total effect on one another. private Graph effectEdgesGraph; @@ -266,12 +253,7 @@ public Graph search() { addRequiredEdges(graph); - this.topGraphs.clear(); - - storeGraph(graph); - long start = MillisecondTimes.timeMillis(); - this.score = 0.0; // Do forward search. fes(graph); @@ -362,20 +344,6 @@ public double getScore(Graph dag) { return scoreDag(dag); } - /** - * @return the list of top scoring graphs. - */ - public SortedSet getTopGraphs() { - return this.topGraphs; - } - - /** - * @return the number of CPDAGs to store. - */ - public int getnumCPDAGsToStore() { - return this.numCPDAGsToStore; - } - /** * @return the discrete scoring function being used. By default, BDeu. */ @@ -621,7 +589,6 @@ private void fes(Graph graph) { double bump = arrow.getBump(); insert(x, y, t, graph, bump); - this.score += bump; Set visited = rebuildCPDAGRestricted(graph, x, y); Set toProcess = new HashSet<>(); @@ -645,8 +612,6 @@ private void fes(Graph graph) { } reevaluateForward(graph, toProcess); - - storeGraph(graph); } } @@ -687,12 +652,9 @@ private void bes(Graph graph) { double bump = arrow.getBump(); delete(x, y, h, graph, bump); - this.score += bump; rebuildCPDAGRestricted(graph, x, y); - storeGraph(graph); - reevaluateBackward(graph, x, y); } } @@ -1402,7 +1364,7 @@ private Set reorientNode(Graph graph, Node a) { List edges = graph.getEdges(a); SearchGraphUtils.basicCpdagRestricted2(graph, a); addRequiredEdges(graph); - Set visited = meekOrientRestricted(graph, nodes, getKnowledge()); + Set visited = meekOrientRestricted(graph, getKnowledge()); List newEdges = graph.getEdges(a); newEdges.removeAll(edges); // The newly oriented edges. @@ -1418,11 +1380,10 @@ private Set reorientNode(Graph graph, Node a) { } // Runs Meek rules on just the changed nodes. - private Set meekOrientRestricted(Graph graph, List nodes, Knowledge knowledge) { - MeekRulesRestricted rules = new MeekRulesRestricted(); + private Set meekOrientRestricted(Graph graph, Knowledge knowledge) { + MeekRules rules = new MeekRules(); rules.setKnowledge(knowledge); - rules.orientImplied(graph, new HashSet<>(nodes)); - return rules.getVisitedNodes(); + return rules.orientImplied(graph); } // Sets the data set, possibly calculating a covariane matrix. @@ -1714,21 +1675,6 @@ private ICovarianceMatrix getCovMatrix() { private boolean isDiscrete() { return this.discrete; } - - // Stores the graph, if its score knocks out one of the top ones. - private void storeGraph(Graph graph) { - if (this.numCPDAGsToStore < 1) return; - - if (this.topGraphs.isEmpty() || this.score > this.topGraphs.first().getScore()) { - Graph graphCopy = new EdgeListGraph(graph); - - this.topGraphs.add(new ScoredGraph(graphCopy, this.score)); - - if (this.topGraphs.size() > getnumCPDAGsToStore()) { - this.topGraphs.remove(this.topGraphs.first()); - } - } - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesRestricted.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesRestricted.java deleted file mode 100644 index c613794c67..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRulesRestricted.java +++ /dev/null @@ -1,498 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.TetradLogger; - -import java.util.*; - -/** - * Implements Meek's complete orientation rule set for PC (Chris Meek (1995), "Causal inference and causal explanation - * with background knowledge"), modified for Conservative PC to check noncolliders against recorded noncolliders before - * orienting. - *

- * For now, the fourth rule is always performed. - * - * @author Joseph Ramsey - */ -public class MeekRulesRestricted implements ImpliedOrientation { - - private Knowledge knowledge; - - /** - * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large - * graphs). - */ - private boolean aggressivelyPreventCycles; - - /** - * If knowledge is available. - */ - boolean useRule4; - - - /** - * The logger to use. - */ - private ArrayList> changedEdges = new ArrayList<>(); - private final Set visitedNodes = new HashSet<>(); - - private final Queue rule1Queue = new LinkedList<>(); - private final Queue rule2Queue = new LinkedList<>(); - private final Queue rule3Queue = new LinkedList<>(); - private final Queue rule4Queue = new LinkedList<>(); - - // Restricted to these nodes. - private Set nodes; - -// private Set colliderNodes = null; - - /** - * Constructs the MeekRules with no logging. - */ - public MeekRulesRestricted() { - } - - //======================== Public Methods ========================// - - public Set orientImplied(Graph graph) { - this.nodes = new HashSet<>(graph.getNodes()); - this.visitedNodes.addAll(this.nodes); - - TetradLogger.getInstance().log("impliedOrientations", "Starting Orientation Step D."); - this.changedEdges = new ArrayList<>(); - orientUsingMeekRulesLocally(this.knowledge, graph); - TetradLogger.getInstance().log("impliedOrientations", "Finishing Orientation Step D."); - - graph.underlines().removeTriplesNotInGraph(); - - return this.visitedNodes; - } - - public void orientImplied(Graph graph, Set nodes) { - this.nodes = nodes; - this.visitedNodes.addAll(nodes); - - TetradLogger.getInstance().log("impliedOrientations", "Starting Orientation Step D."); - this.changedEdges = new ArrayList<>(); - orientUsingMeekRulesLocally(this.knowledge, graph); - TetradLogger.getInstance().log("impliedOrientations", "Finishing Orientation Step D."); - - graph.underlines().removeTriplesNotInGraph(); - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - } - - //============================== Private Methods ===================================// - - private void orientUsingMeekRulesLocally(Knowledge knowledge, Graph graph) { -// List colliderNodes = getColliderNodes(graph); - - // Previously oriented, probably by knowledge. - for (Node node : getNodes()) { - if (!graph.getParents(node).isEmpty()) { - meekR1Locally(node, graph, knowledge); - meekR2(node, graph, knowledge); - meekR3(node, graph, knowledge); - - if (this.useRule4) { - meekR4(node, graph, knowledge); - } - } - } - - while (!this.rule1Queue.isEmpty() || !this.rule2Queue.isEmpty() || !this.rule3Queue.isEmpty() || !this.rule4Queue.isEmpty()) { - while (!this.rule1Queue.isEmpty()) { - Node node = this.rule1Queue.remove(); - meekR1Locally(node, graph, knowledge); - } - - while (!this.rule2Queue.isEmpty()) { - Node node = this.rule2Queue.remove(); - meekR2(node, graph, knowledge); - } - - while (!this.rule3Queue.isEmpty()) { - Node node = this.rule3Queue.remove(); - meekR3(node, graph, knowledge); - } - - while (!this.rule4Queue.isEmpty()) { - Node node = this.rule4Queue.remove(); - meekR4(node, graph, knowledge); - } - } - } - - /** - * Meek's rule R1: if b-->a, a---c, and a not adj to c, then a-->c - */ - private void meekR1Locally(Node a, Graph graph, Knowledge knowledge) { - List adjacentNodes = graph.getAdjacentNodes(a); - this.visitedNodes.add(a); - - if (adjacentNodes.size() < 2) { - return; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - // Skip triples that are shielded. - if (graph.isAdjacentTo(b, c)) { - continue; - } - - if (graph.paths().isDirectedFromTo(b, a) && graph.paths().isUndirectedFromTo(a, c)) { - if (MeekRulesRestricted.isShieldedNoncollider(b, a, c, graph)) { - continue; - } - - if (MeekRulesRestricted.isArrowpointAllowed(a, c, knowledge) && doesNotCreateCycle(a, c, graph)) { - Edge after = direct(a, c, graph); - Node x = after.getNode1(); - Node y = after.getNode2(); - - this.rule1Queue.add(y); - this.rule2Queue.add(y); - this.rule3Queue.add(x); - - if (this.useRule4) { - this.rule4Queue.add(x); - } - - TetradLogger.getInstance().log("impliedOrientations", SearchLogUtils.edgeOrientedMsg( - "Meek R1 triangle (" + b + "-->" + a + "---" + c + ")", graph.getEdge(a, c))); - } - } else if (graph.paths().isDirectedFromTo(c, a) && graph.paths().isUndirectedFromTo(a, b)) { - if (MeekRulesRestricted.isShieldedNoncollider(b, a, c, graph)) { - continue; - } - - if (MeekRulesRestricted.isArrowpointAllowed(a, b, knowledge) && doesNotCreateCycle(a, b, graph)) { - Edge after = direct(a, b, graph); - Node x = after.getNode1(); - Node y = after.getNode2(); - - this.rule1Queue.add(y); - this.rule2Queue.add(y); - this.rule3Queue.add(x); - - if (this.useRule4) { - this.rule4Queue.add(x); - } - - TetradLogger.getInstance().log("impliedOrientations", SearchLogUtils.edgeOrientedMsg( - "Meek R1 (" + c + "-->" + a + "---" + b + ")", graph.getEdge(a, b))); - } - } - } - } - - /** - * If b-->a-->c, b--c, then b-->c. - */ - private void meekR2(Node a, Graph graph, Knowledge knowledge) { - List adjacentNodes = graph.getAdjacentNodes(a); - this.visitedNodes.add(a); - - if (adjacentNodes.size() < 2) { - return; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - if (graph.paths().isDirectedFromTo(b, a) && - graph.paths().isDirectedFromTo(a, c) && - graph.paths().isUndirectedFromTo(b, c)) { - if (MeekRulesRestricted.isArrowpointAllowed(b, c, knowledge) && doesNotCreateCycle(b, c, graph)) { - Edge after = direct(b, c, graph); - Node x = after.getNode1(); - Node y = after.getNode2(); - - this.rule1Queue.add(y); - this.rule2Queue.add(y); - this.rule3Queue.add(x); - - if (this.useRule4) { - this.rule4Queue.add(x); - } - - TetradLogger.getInstance().log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Meek R2", graph.getEdge(b, c))); - } - } else if (graph.paths().isDirectedFromTo(c, a) && - graph.paths().isDirectedFromTo(a, b) && - graph.paths().isUndirectedFromTo(c, b)) { - if (MeekRulesRestricted.isArrowpointAllowed(c, b, knowledge) && doesNotCreateCycle(c, b, graph)) { - Edge after = direct(c, b, graph); - Node x = after.getNode1(); - Node y = after.getNode2(); - - this.rule1Queue.add(y); - this.rule2Queue.add(y); - this.rule3Queue.add(x); - - if (this.useRule4) { - this.rule4Queue.add(x); - } - - TetradLogger.getInstance().log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Meek R2", graph.getEdge(c, b))); - } - } - } - } - - /** - * Meek's rule R3. If a--b, a--c, a--d, c-->b, d-->b, then orient a-->b. - */ - private void meekR3(Node a, Graph graph, Knowledge knowledge) { - List adjacentNodes = graph.getAdjacentNodes(a); - this.visitedNodes.add(a); - - if (adjacentNodes.size() < 3) { - return; - } - - for (Node b : adjacentNodes) { - List otherAdjacents = new LinkedList<>(adjacentNodes); - otherAdjacents.remove(b); - - if (!graph.paths().isUndirectedFromTo(a, b)) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(otherAdjacents.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node c = otherAdjacents.get(combination[0]); - Node d = otherAdjacents.get(combination[1]); - - if (graph.isAdjacentTo(c, d)) { - continue; - } - - if (!graph.paths().isDirectedFromTo(c, a)) { - continue; - } - - if (!graph.paths().isDirectedFromTo(d, a)) { - continue; - } - - if (graph.paths().isUndirectedFromTo(b, c) && - graph.paths().isUndirectedFromTo(b, d)) { - if (MeekRulesRestricted.isArrowpointAllowed(b, a, knowledge) && doesNotCreateCycle(b, a, graph)) { - if (MeekRulesRestricted.isShieldedNoncollider(c, b, d, graph)) { - continue; - } - - Edge after = direct(b, a, graph); - - Node x = after.getNode1(); - Node y = after.getNode2(); - - this.rule1Queue.add(y); - this.rule2Queue.add(y); - this.rule3Queue.add(x); - - if (this.useRule4) { - this.rule4Queue.add(x); - } - - TetradLogger.getInstance().log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Meek R3", graph.getEdge(a, b))); -// continue; - } - } - } - } - } - - private void meekR4(Node a, Graph graph, Knowledge knowledge) { - if (!this.useRule4) { - return; - } - - List adjacentNodes = graph.getAdjacentNodes(a); - this.visitedNodes.add(a); - - if (adjacentNodes.size() < 3) { - return; - } - - for (Node d : adjacentNodes) { - if (!graph.isAdjacentTo(d, a)) { - continue; - } - - List otherAdjacents = new LinkedList<>(adjacentNodes); - otherAdjacents.remove(d); - - ChoiceGenerator cg = new ChoiceGenerator(otherAdjacents.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = otherAdjacents.get(combination[0]); - Node c = otherAdjacents.get(combination[1]); - - if (graph.paths().isDirectedFromTo(b, a) && graph.paths().isDirectedFromTo(a, c)) { - if (graph.paths().isUndirectedFromTo(d, b) && - graph.paths().isUndirectedFromTo(d, c)) { - if (MeekRulesRestricted.isShieldedNoncollider(c, d, b, graph)) { - continue; - } - - if (MeekRulesRestricted.isArrowpointAllowed(d, c, knowledge) && doesNotCreateCycle(d, c, graph)) { - Edge after = direct(d, c, graph); - Node x = after.getNode1(); - Node y = after.getNode2(); - - this.rule1Queue.add(y); - this.rule2Queue.add(y); - this.rule3Queue.add(x); - - if (this.useRule4) { - this.rule4Queue.add(x); - } - - TetradLogger.getInstance().log("impliedOientations", SearchLogUtils.edgeOrientedMsg("Meek T1", graph.getEdge(a, c))); -// continue; - } - } - } else if (graph.paths().isDirectedFromTo(c, a) && graph.paths().isDirectedFromTo(a, b)) { - if (graph.paths().isUndirectedFromTo(d, b) && graph.paths().isUndirectedFromTo(d, c)) { - if (MeekRulesRestricted.isShieldedNoncollider(c, d, b, graph)) { - continue; - } - - if (MeekRulesRestricted.isArrowpointAllowed(d, c, knowledge) && doesNotCreateCycle(d, c, graph)) { - Edge after = direct(d, c, graph); - Node x = after.getNode1(); - Node y = after.getNode2(); - - this.rule1Queue.add(y); - this.rule2Queue.add(y); - this.rule3Queue.add(x); - - if (this.useRule4) { - this.rule4Queue.add(x); - } - - TetradLogger.getInstance().log("impliedOientations", SearchLogUtils.edgeOrientedMsg("Meek T1", graph.getEdge(a, c))); -// continue; - } - } - } - } - } - } - - private Edge direct(Node a, Node c, Graph graph) { - Edge before = graph.getEdge(a, c); - Edge after = Edges.directedEdge(a, c); - - graph.removeEdge(before); - graph.addEdge(after); - - this.changedEdges.add(new OrderedPair<>(before, after)); - - return after; - } - - private static boolean isShieldedNoncollider(Node a, Node b, Node c, - Graph graph) { - if (!graph.isAdjacentTo(a, b)) { - return true; - } - - if (!graph.isAdjacentTo(c, b)) { - return true; - } - - if (graph.isAdjacentTo(a, c)) { - return true; - } - - if (graph.underlines().isAmbiguousTriple(a, b, c)) { - return true; - } - - return graph.getEndpoint(a, b) == Endpoint.ARROW && - graph.getEndpoint(c, b) == Endpoint.ARROW; - - } - - - private static boolean isArrowpointAllowed(Node from, Node to, Knowledge knowledge) { - if (knowledge == null) return true; - return !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - - /** - * @return true if orienting x-->y would create a cycle. - */ - private boolean doesNotCreateCycle(Node x, Node y, Graph graph) { - if (this.aggressivelyPreventCycles) { - return !graph.paths().isAncestorOf(y, x); - } else { - return true; - } - } - - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - - public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { - this.aggressivelyPreventCycles = aggressivelyPreventCycles; - } - - public List> getChangedEdges() { - return this.changedEdges; - } - - public Set getVisitedNodes() { - return this.visitedNodes; - } - - public Set getNodes() { - return this.nodes; - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 49c91f344c..7e5dfd5bdc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -48,7 +48,7 @@ *

* Uses a different (better) algorithm from Mimbuild. Preferable. * - * @author Joseph Ramsey + * @author josephramsey */ public class Mimbuild { From 1e97427ca47e679ea85fb50fc5ce30a218022239 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:09:31 -0400 Subject: [PATCH 283/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/Mimbuild.java | 85 ++++++++++--------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 7e5dfd5bdc..26c2d64098 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -41,12 +41,11 @@ import java.util.List; /** - * An implemetation of Mimbuild based on the Fgsl score. The search will attempt a GES search first and if that - * throws and exception then a CPC search. The penalty penaltyDiscount parameter is for the GES search; the alpha - * value is for the CPC search. Or you can just grab the latent covariance matrix and run whatever search you - * want to. (I don't know why GES sometimes fails, it is a mystery.) - *

- * Uses a different (better) algorithm from Mimbuild. Preferable. + *

>An implemetation of Mimbuild. The search will first infer the covariance matrix + * over the latents and then will use GRaSP to infer the structure grpah over the + * latents, using the SemBicScore with the given penalty discount (default 2).

The covariance matrix over the latents may be retried if one desires to use + * a different method to infer the structure graph over the latents.

* * @author josephramsey */ @@ -81,9 +80,7 @@ public class Mimbuild { * The p value of the optimization. */ private double pValue; - private int numParams; private List latents; - private double epsilon = 1e-4; private double penaltyDiscount = 1; private int minClusterSize = 3; @@ -92,6 +89,16 @@ public Mimbuild() { //=================================== PUBLIC METHODS =========================================// + /** + * Does a Mimbuild search. + * + * @param clustering The clustering to use--this clusters the measured variables in such a way + * that each cluster is explained by a single latent variables. + * @param latentNames The names of the latent variables corresponding in order ot each cluster + * in the clustering. + * @param measuresCov The covariance matrix over the measured variables. + * @return The inferred graph over the latent variables. + */ public Graph search(List> clustering, List latentNames, ICovarianceMatrix measuresCov) { List _latentNames = new ArrayList<>(latentNames); @@ -150,42 +157,53 @@ public Graph search(List> clustering, List latentNames, ICova return this.structureGraph; } + /** + * Returns the clustering of measured variables, each of which is explained + * by a single latent. + * + * @return This clustering. + */ public List> getClustering() { return this.clustering; } - public Knowledge getKnowledge() { - return this.knowledge; - } - + /** + * Sets the knowledge to be used in the search. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } + /** + * Returns the inferred covariance matrix over the late4nt variables. + * + * @return Thsi covariance matrix. + */ public ICovarianceMatrix getLatentsCov() { return this.latentsCov; } - public List getLatentNames(List latents) { - List latentNames = new ArrayList<>(); - - for (Node node : latents) { - latentNames.add(node.getName()); - } - - return latentNames; - } - + /** + * @return The minimum function (Fgsl) value achieved. + */ public double getMinimum() { return this.minimum; } + /** + * @return The p value of the optimization. + */ public double getpValue() { return this.pValue; } /** - * @return the allowUnfaithfulness discovered graph, with latents and indicators. + * The full graph inferred, including the edges from latents to measures and + * all fo the edges inferred among latents. + * + * @return This full graph. */ public Graph getFullGraph() { Graph graph = new EdgeListGraph(this.structureGraph); @@ -206,18 +224,11 @@ public Graph getFullGraph() { return graph; } - public double getEpsilon() { - return this.epsilon; - } - /** - * Parameter convergence threshold. Default = 1e-4. + * Sets the penalty discount of the score used to infer the structure graph. + * + * @param penaltyDiscount The penalty discount. */ - public void setEpsilon(double epsilon) { - if (epsilon < 0) throw new IllegalArgumentException("Epsilon mut be >= 0: " + epsilon); - this.epsilon = epsilon; - } - public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } @@ -298,14 +309,14 @@ private Matrix getCov(ICovarianceMatrix _measurescov, List latents, Node[] optimizeNonMeasureVariancesQuick(indicators, measurescov, latentscov, loadings, indicatorIndices); - this.numParams = allParams1.length; + int numParams = allParams1.length; optimizeAllParamsSimultaneously(indicators, measurescov, latentscov, loadings, indicatorIndices, delta); double N = _measurescov.getSampleSize(); int p = _measurescov.getDimension(); - int df = (p) * (p + 1) / 2 - (this.numParams); + int df = (p) * (p + 1) / 2 - (numParams); double x = (N - 1) * this.minimum; System.out.println("p = " + p); @@ -363,10 +374,6 @@ private void optimizeNonMeasureVariancesQuick(Node[][] indicators, Matrix measur this.minimum = pair.getValue(); } - public int getNumParams() { - return this.numParams; - } - private void optimizeAllParamsSimultaneously(Node[][] indicators, Matrix measurescov, Matrix latentscov, double[][] loadings, int[][] indicatorIndices, double[] delta) { From ec8d630fe8ee5bf8d1d717232afae2f46280c55d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:14:48 -0400 Subject: [PATCH 284/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algorithm/oracle/cpdag/CpcStable.java | 129 ------------------ .../algorithm/oracle/cpdag/PcStable.java | 122 ----------------- .../examples/TestDegenerateGaussian.java | 3 - .../main/java/edu/cmu/tetrad/search/Cpc.java | 10 +- .../main/java/edu/cmu/tetrad/search/MaxP.java | 22 +-- .../edu/cmu/tetrad/search/MimbuildTrek.java | 24 +--- .../main/java/edu/cmu/tetrad/search/Pc.java | 10 +- .../search/{PcAll.java => PcCommon.java} | 14 +- .../java/edu/cmu/tetrad/search/PcMax.java | 12 +- .../tetrad/algcomparison/TestKnowledge.java | 2 - 10 files changed, 38 insertions(+), 310 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{PcAll.java => PcCommon.java} (97%) 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/CpcStable.java deleted file mode 100644 index e06cff69b5..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java +++ /dev/null @@ -1,129 +0,0 @@ -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; -import edu.cmu.tetrad.annotation.Bootstrapping; -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.PcAll; -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; - -/** - * PC. - * - * @author jdramsey - */ -@Bootstrapping -public class CpcStable 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 CpcStable(IndependenceWrapper test) { - this.test = test; - } - - public CpcStable(IndependenceWrapper test, Algorithm algorithm) { - this.test = test; - this.algorithm = algorithm; - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - // init = algorithm.search(dataSet, parameters); - PcAll search = new PcAll(this.test.getTest(dataSet, parameters)); - search.setDepth(parameters.getInt(Params.DEPTH)); - search.setKnowledge(this.knowledge); - search.setFasType(PcAll.FasType.STABLE); - 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); - - 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)); - search.setKnowledge(this.knowledge); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - Graph graph = search.search(); - this.bootstrapGraphs = search.getGraphs(); - return graph; - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); - } - - @Override - public String getDescription() { - return "CPC-Stable (Conservative \"Peter and Clark\" Stable), Priority Rule, using " + this.test.getDescription(); - } - - @Override - public DataType getDataType() { - return this.test.getDataType(); - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.DEPTH); - - 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 void setIndependenceWrapper(IndependenceWrapper independenceWrapper) { - this.test = independenceWrapper; - } - - @Override - 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/PcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java deleted file mode 100644 index e2d116c181..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java +++ /dev/null @@ -1,122 +0,0 @@ -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; -import edu.cmu.tetrad.annotation.Bootstrapping; -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.PcAll; -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; - -/** - * PC-Stable. - * - * @author jdramsey - */ -@Bootstrapping -public class PcStable 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 PcStable(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 search = new edu.cmu.tetrad.search.PcAll(this.test.getTest(dataSet, parameters)); - search.setDepth(parameters.getInt(Params.DEPTH)); - search.setKnowledge(this.knowledge); - search.setFasType(PcAll.FasType.STABLE); -// 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); - - 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)); - search.setKnowledge(this.knowledge); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - Graph graph = search.search(); - this.bootstrapGraphs = search.getGraphs(); - return graph; - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); - } - - @Override - public String getDescription() { - return "PC-Stable (\"Peter and Clark\" Stable), Priority Rule, using " + this.test.getDescription(); - } - - @Override - public DataType getDataType() { - return this.test.getDataType(); - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.DEPTH); - - 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 void setIndependenceWrapper(IndependenceWrapper independenceWrapper) { - this.test = independenceWrapper; - } - - @Override - 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/examples/TestDegenerateGaussian.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java index 4bc86b99e1..f3b9aebfbc 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 @@ -24,9 +24,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.PcStable; import edu.cmu.tetrad.algcomparison.graph.RandomForward; -import edu.cmu.tetrad.algcomparison.independence.DegenerateGaussianLRT; import edu.cmu.tetrad.algcomparison.score.ConditionalGaussianBicScore; import edu.cmu.tetrad.algcomparison.score.DegenerateGaussianBicScore; import edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation; @@ -79,7 +77,6 @@ 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())); Simulations simulations = new Simulations(); simulations.add(new ConditionalGaussianSimulation(new RandomForward())); 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 d1fc00aac3..d4bae11f0a 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 stable; private boolean useHeuristic = false; private int maxPPathLength = -1; - private final PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; + private final PcCommon.ConflictRule conflictRule = PcCommon.ConflictRule.OVERWRITE; //=============================CONSTRUCTORS==========================// @@ -261,18 +261,18 @@ public Graph search() { this.graph = fas.search(); this.sepsets = fas.getSepsets(); - edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(independenceTest); + PcCommon search = new PcCommon(independenceTest); search.setDepth(depth); search.setHeuristic(1); search.setKnowledge(this.knowledge); if (stable) { - search.setFasType(PcAll.FasType.STABLE); + search.setFasType(PcCommon.FasType.STABLE); } else { - search.setFasType(PcAll.FasType.REGULAR); + search.setFasType(PcCommon.FasType.REGULAR); } - search.setColliderDiscovery(PcAll.ColliderDiscovery.CONSERVATIVE); + search.setColliderDiscovery(PcCommon.ColliderDiscovery.CONSERVATIVE); search.setConflictRule(conflictRule); search.setUseHeuristic(useHeuristic); search.setMaxPathLength(maxPPathLength); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java index 5146b89b97..49aeaac318 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java @@ -45,7 +45,7 @@ public final class MaxP { private Knowledge knowledge = new Knowledge(); private boolean useHeuristic; private int maxPathLength = 3; - private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; + private PcCommon.ConflictRule conflictRule = PcCommon.ConflictRule.OVERWRITE; /** * Constructor. @@ -74,20 +74,20 @@ public synchronized void orient(Graph graph) { * * @param conflictRule The conflict rule to use. * @param graph The graph to orient. - * @see edu.cmu.tetrad.search.PcAll.ConflictRule + * @see PcCommon.ConflictRule */ - public static void orientCollider(Node x, Node y, Node z, PcAll.ConflictRule conflictRule, Graph graph) { - if (conflictRule == PcAll.ConflictRule.PRIORITY) { + public static void orientCollider(Node x, Node y, Node z, PcCommon.ConflictRule conflictRule, Graph graph) { + if (conflictRule == PcCommon.ConflictRule.PRIORITY) { if (!(graph.getEndpoint(y, x) == Endpoint.ARROW || graph.getEndpoint(y, z) == Endpoint.ARROW)) { graph.removeEdge(x, y); graph.removeEdge(z, y); graph.addDirectedEdge(x, y); graph.addDirectedEdge(z, y); } - } else if (conflictRule == PcAll.ConflictRule.BIDIRECTED) { + } else if (conflictRule == PcCommon.ConflictRule.BIDIRECTED) { graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); - } else if (conflictRule == PcAll.ConflictRule.OVERWRITE) { + } else if (conflictRule == PcCommon.ConflictRule.OVERWRITE) { graph.removeEdge(x, y); graph.removeEdge(z, y); graph.addDirectedEdge(x, y); @@ -126,9 +126,9 @@ public void setMaxPathLength(int maxPathLength) { * Sets the PC conflict rule to use for orientation. * * @param conflictRule This rule. - * @see edu.cmu.tetrad.search.PcAll.ConflictRule + * @see PcCommon.ConflictRule */ - public void setConflictRule(PcAll.ConflictRule conflictRule) { + public void setConflictRule(PcCommon.ConflictRule conflictRule) { this.conflictRule = conflictRule; } @@ -209,8 +209,8 @@ private void testColliderMaxP(Graph graph, Map scores, Node a, N adja.remove(c); adjc.remove(a); - if (!(PcAll.isArrowpointAllowed(a, b, knowledge) - && (PcAll.isArrowpointAllowed(c, b, knowledge)))) { + if (!(PcCommon.isArrowpointAllowed(a, b, knowledge) + && (PcCommon.isArrowpointAllowed(c, b, knowledge)))) { return; } @@ -290,7 +290,7 @@ private void testColliderHeuristic(Graph graph, Map colliders, N } } - private void orientCollider(Graph graph, Node a, Node b, Node c, PcAll.ConflictRule conflictRule) { + private void orientCollider(Graph graph, Node a, Node b, Node c, PcCommon.ConflictRule conflictRule) { if (this.knowledge.isForbidden(a.getName(), b.getName())) return; if (this.knowledge.isForbidden(c.getName(), b.getName())) return; MaxP.orientCollider(a, b, c, conflictRule, graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index 2422c28d59..1e60941ebd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -43,7 +43,7 @@ /** * An implemetation of Mimbuild based on the treks and ranks. * - * @author Adam + * @author adambrodie */ public class MimbuildTrek { @@ -81,7 +81,6 @@ public class MimbuildTrek { * The p value of the optimization. */ private double pValue; - private int numParams; private List latents; private double epsilon = 1e-4; private int minClusterSize = 3; @@ -162,23 +161,13 @@ public Knowledge getKnowledge() { } public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } public ICovarianceMatrix getLatentsCov() { return this.latentsCov; } - public List getLatentNames(List latents) { - List latentNames = new ArrayList<>(); - - for (Node node : latents) { - latentNames.add(node.getName()); - } - - return latentNames; - } - public double getMinimum() { return this.minimum; } @@ -297,14 +286,14 @@ private Matrix getCov(ICovarianceMatrix _measurescov, List latents, Node[] optimizeNonMeasureVariancesQuick(indicators, measurescov, latentscov, loadings, indicatorIndices); - this.numParams = allParams1.length; + int numParams = allParams1.length; optimizeAllParamsSimultaneously(indicators, measurescov, latentscov, loadings, indicatorIndices, delta); double N = _measurescov.getSampleSize(); int p = _measurescov.getDimension(); - int df = (p) * (p + 1) / 2 - (this.numParams); + int df = (p) * (p + 1) / 2 - (numParams); double x = (N - 1) * this.minimum; this.pValue = 1.0 - new ChiSquaredDistribution(df).cumulativeProbability(x); @@ -354,10 +343,6 @@ private void optimizeNonMeasureVariancesQuick(Node[][] indicators, Matrix measur this.minimum = pair.getValue(); } - public int getNumParams() { - return this.numParams; - } - private void optimizeAllParamsSimultaneously(Node[][] indicators, Matrix measurescov, Matrix latentscov, double[][] loadings, int[][] indicatorIndices, double[] delta) { @@ -573,7 +558,6 @@ private double sumOfDifferences(int[][] indicatorIndices, Matrix cov, double[][] return sum; } - } 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 9933c2dab3..5d2e612117 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 @@ -94,7 +94,7 @@ public class Pc implements GraphSearch { private boolean stable; private boolean useMaxP = false; private int maxPPathLength = -1; - private final PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; + private final PcCommon.ConflictRule conflictRule = PcCommon.ConflictRule.OVERWRITE; //=============================CONSTRUCTORS==========================// @@ -233,18 +233,18 @@ public Graph search(IFas fas, List nodes) { "be in the domain of the independence test provided."); } - edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(independenceTest); + PcCommon search = new PcCommon(independenceTest); search.setDepth(depth); search.setHeuristic(1); search.setKnowledge(this.knowledge); if (stable) { - search.setFasType(PcAll.FasType.STABLE); + search.setFasType(PcCommon.FasType.STABLE); } else { - search.setFasType(PcAll.FasType.REGULAR); + search.setFasType(PcCommon.FasType.REGULAR); } - search.setColliderDiscovery(PcAll.ColliderDiscovery.FAS_SEPSETS); + search.setColliderDiscovery(PcCommon.ColliderDiscovery.FAS_SEPSETS); search.setConflictRule(conflictRule); search.setUseHeuristic(useMaxP); search.setMaxPathLength(maxPPathLength); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java index 46fa0e9cd5..cb7ce89e88 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java @@ -39,7 +39,7 @@ * * @author josephramsey */ -public final class PcAll implements GraphSearch { +public final class PcCommon implements GraphSearch { public enum FasType {REGULAR, STABLE} public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P} @@ -104,7 +104,7 @@ public enum ConflictRule {PRIORITY, BIDIRECTED, OVERWRITE} * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the * independence test, for fear of duplicating the data set! */ - public PcAll(IndependenceTest independenceTest) { + public PcCommon(IndependenceTest independenceTest) { if (independenceTest == null) { throw new NullPointerException(); } @@ -498,7 +498,7 @@ private void orientUnshieldedTriplesConservative(Knowledge knowledge) { if (isColliderSepset(y, sepsetsxz)) { if (colliderAllowed(x, y, z, knowledge)) { - PcAll.orientCollider(x, y, z, this.conflictRule, this.graph); + PcCommon.orientCollider(x, y, z, this.conflictRule, this.graph); } this.colliderTriples.add(new Triple(x, y, z)); @@ -574,8 +574,8 @@ private boolean isNoncolliderSepset(Node j, List> sepsets) { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return PcAll.isArrowpointAllowed1(x, y, knowledge) && - PcAll.isArrowpointAllowed1(z, y, knowledge); + return PcCommon.isArrowpointAllowed1(x, y, knowledge) && + PcCommon.isArrowpointAllowed1(z, y, knowledge); } /** @@ -620,8 +620,8 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra List s2 = new ArrayList<>(sepset); if (!s2.contains(b)) s2.add(b); - if (!sepset.contains(b) && PcAll.isArrowpointAllowed(a, b, knowledge) && PcAll.isArrowpointAllowed(c, b, knowledge)) { - PcAll.orientCollider(a, b, c, conflictRule, graph); + if (!sepset.contains(b) && PcCommon.isArrowpointAllowed(a, b, knowledge) && PcCommon.isArrowpointAllowed(c, b, knowledge)) { + PcCommon.orientCollider(a, b, c, conflictRule, graph); if (verbose) { System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); 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 d7e7e9b5d9..eff901aa51 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 @@ -94,7 +94,7 @@ public class PcMax implements GraphSearch { // private boolean concurrent; private boolean useMaxP = false; private int maxPPathLength = -1; - private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; + private PcCommon.ConflictRule conflictRule = PcCommon.ConflictRule.OVERWRITE; //=============================CONSTRUCTORS==========================// @@ -233,15 +233,15 @@ public Graph search(IFas fas, List nodes) { "be in the domain of the independence test provided."); } - edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(independenceTest); + PcCommon search = new PcCommon(independenceTest); search.setDepth(depth); search.setHeuristic(1); search.setKnowledge(this.knowledge); if (stable) { - search.setFasType(PcAll.FasType.STABLE); + search.setFasType(PcCommon.FasType.STABLE); } else { - search.setFasType(PcAll.FasType.REGULAR); + search.setFasType(PcCommon.FasType.REGULAR); } // if (concurrent) { @@ -250,7 +250,7 @@ public Graph search(IFas fas, List nodes) { // search.setConcurrent(PcAll.Concurrent.NO); // } - search.setColliderDiscovery(PcAll.ColliderDiscovery.MAX_P); + search.setColliderDiscovery(PcCommon.ColliderDiscovery.MAX_P); search.setConflictRule(conflictRule); search.setUseHeuristic(useMaxP); search.setMaxPathLength(maxPPathLength); @@ -327,7 +327,7 @@ public void setMaxPPathLength(int maxPPathLength) { this.maxPPathLength = maxPPathLength; } - public void setConflictRule(PcAll.ConflictRule conflictRule) { + public void setConflictRule(PcCommon.ConflictRule conflictRule) { this.conflictRule = conflictRule; } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/algcomparison/TestKnowledge.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/algcomparison/TestKnowledge.java index b8fed09400..d4ad7f9d60 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/algcomparison/TestKnowledge.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/algcomparison/TestKnowledge.java @@ -49,10 +49,8 @@ public void test1() { testKnowledge(dataSet, knowledge, parameters, new Boss(score)); testKnowledge(dataSet, knowledge, parameters, new Cpc(test)); - testKnowledge(dataSet, knowledge, parameters, new CpcStable(test)); testKnowledge(dataSet, knowledge, parameters, new Fges(score)); testKnowledge(dataSet, knowledge, parameters, new Grasp(test, score)); - testKnowledge(dataSet, knowledge, parameters, new PcStable(test)); testKnowledge(dataSet, knowledge, parameters, new Pc(test)); testKnowledge(dataSet, knowledge, parameters, new PcMax(test)); testKnowledge(dataSet, knowledge, parameters, new Sp(score)); From b4383cefcb8cb5ceebc594e570a03057513988b6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:16:35 -0400 Subject: [PATCH 285/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java index b7110193bd..665aea02b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java @@ -35,8 +35,9 @@ public class MbUtils { /** - * Trims the graph to the target, the parents and children of the target, and the parents of the children of the - * target. Bidirected edges are interpreted as if they could be oriented in either direction. + * Trims the graph to the target, the parents and children of the target, and + * the parents of the children of the target. Bidirected edges are interpreted + * as if they could be oriented in either direction. * * @param graph The graph. * @param target The target. From 7b6a1d44d8a7523f4f882dd9ea82ed3cc840e822 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:23:16 -0400 Subject: [PATCH 286/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/MimUtils.java | 2 +- .../edu/cmu/tetrad/search/MnlrLikelihood.java | 2 - .../edu/cmu/tetrad/search/PcStableMax.java | 258 ------------------ .../tetrad/study/performance/Comparison.java | 5 - .../tetrad/study/performance/Comparison2.java | 11 - .../performance/ComparisonParameters.java | 6 +- .../study/performance/PerformanceTests.java | 73 ----- .../edu/cmu/tetrad/test/TestPcStableMax.java | 8 +- 8 files changed, 8 insertions(+), 357 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimUtils.java index ecdfa4053e..2ec82b6fe0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimUtils.java @@ -31,7 +31,7 @@ /** * Holds some utility methods for Purify, Build Clusters, and Mimbuild. * - * @author Joseph Ramsey + * @author josephramsey */ public final class MimUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java index fa917354a7..487e090c50 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java @@ -43,8 +43,6 @@ * * @author Bryan Andrews */ - - public class MnlrLikelihood { private final DataSet dataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java deleted file mode 100644 index 5681af7983..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStableMax.java +++ /dev/null @@ -1,258 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.TetradLogger; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Implements a modification of the the PC ("Peter/Clark") algorithm, as specified in Chapter 6 of - * Spirtes, Glymour, and Scheines, Causation, Prediction, and Search, 2nd edition, using the rule set - * in step D due to Chris Meek. For the modified rule set, see Chris Meek (1995), "Causal inference and - * causal explanation with background knowledge." The modification is to replace the collider orientation - * step by a scoring step. - * - * @author Joseph Ramsey. - */ -public class PcStableMax implements GraphSearch { - - /** - * The independence test used for the PC search. This can be a test based on a score. - */ - private final IndependenceTest independenceTest; - - /** - * Forbidden and required edges for the search. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * The maximum number of nodes conditioned on in the search. The default unlimited (1000). - */ - private int depth = -1; - - /** - * The graph that's constructed during the search. - */ - private Graph graph; - - /** - * Elapsed time of the most recent search. - */ - private long elapsedTime; - - /** - * The logger for this class. The config needs to be set. - */ - private final TetradLogger logger = TetradLogger.getInstance(); - - /** - * True if verbose output should be printed. - */ - private boolean verbose; - private boolean useHeuristic; - private int maxPathLength; - - //=============================CONSTRUCTORS==========================// - - /** - * Constructs a new PC search using the given independence test as oracle. - * - * @param independenceTest The oracle for conditional independence facts. This does not make a copy of the - * independence test, for fear of duplicating the data set! - */ - public PcStableMax(IndependenceTest independenceTest) { - if (independenceTest == null) { - throw new NullPointerException(); - } - - this.independenceTest = independenceTest; - } - - //==============================PUBLIC METHODS========================// - - /** - * @return the independence test being used in the search. - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - /** - * @return the knowledge specification used in the search. Non-null. - */ - public Knowledge getKnowledge() { - return this.knowledge; - } - - /** - * Sets the knowledge specification to be used in the search. May not be null. - */ - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException(); - } - - this.knowledge = knowledge; - } - - /** - * @return the current depth of search--that is, the maximum number of conditioning nodes for any conditional - * independence checked. - */ - public int getDepth() { - return this.depth; - } - - /** - * Sets the depth of the search--that is, the maximum number of conditioning nodes for any conditional independence - * checked. - * - * @param depth The depth of the search. The default is 1000. A value of -1 may be used to indicate that the depth - * should be high (1000). A value of Integer.MAX_VALUE may not be used, due to a bug on multi-core - * machines. - */ - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException("Depth must be -1 or >= 0: " + depth); - } - - if (depth > 1000) { - throw new IllegalArgumentException("Depth must be <= 1000."); - } - - this.depth = depth; - } - - /** - * Runs PC search, returning the output CPDAG. - */ - public Graph search() { - return search(this.independenceTest.getVariables()); - } - - /** - * Runs PC search, returning the output CPDAG, over the given nodes. - */ - public Graph search(List nodes) { - this.logger.log("info", "Starting PC algorithm"); - this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); - - long startTime = MillisecondTimes.timeMillis(); - - if (getIndependenceTest() == null) { - throw new NullPointerException(); - } - - List allNodes = getIndependenceTest().getVariables(); - - if (!allNodes.containsAll(nodes)) { - throw new IllegalArgumentException("All of the given nodes must " + - "be in the domain of the independence test provided."); - } - - Fas fas = new Fas(getIndependenceTest()); - fas.setStable(true); - fas.setKnowledge(getKnowledge()); - fas.setDepth(getDepth()); - fas.setVerbose(this.verbose); -// fas.setRecordSepsets(false); - this.graph = fas.search(); - - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - - MaxP orientCollidersMaxP = new MaxP(this.independenceTest); - orientCollidersMaxP.setKnowledge(this.knowledge); - orientCollidersMaxP.setUseHeuristic(this.useHeuristic); - orientCollidersMaxP.setMaxPathLength(this.maxPathLength); - orientCollidersMaxP.orient(this.graph); - - MeekRules rules = new MeekRules(); - rules.setKnowledge(this.knowledge); - rules.orientImplied(this.graph); - - this.logger.log("graph", "\nReturning this graph: " + this.graph); - - this.elapsedTime = MillisecondTimes.timeMillis() - startTime; - - this.logger.log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); - this.logger.log("info", "Finishing PC Algorithm."); - this.logger.flush(); - - return this.graph; - } - - /** - * @return the elapsed time of the search, in milliseconds. - */ - public long getElapsedTime() { - return this.elapsedTime; - } - - public Set getAdjacencies() { - return new HashSet<>(this.graph.getEdges()); - } - - public Set getNonadjacencies() { - Graph complete = GraphUtils.completeGraph(this.graph); - Set nonAdjacencies = complete.getEdges(); - Graph undirected = GraphUtils.undirectedGraph(this.graph); - nonAdjacencies.removeAll(undirected.getEdges()); - return new HashSet<>(nonAdjacencies); - } - - public List getNodes() { - return this.graph.getNodes(); - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setUseHeuristic(boolean useHeuristic) { - this.useHeuristic = useHeuristic; - } - - public void setMaxPathLength(int maxPathLength) { - this.maxPathLength = maxPathLength; - } - - public int getMaxPathLength() { - return this.maxPathLength; - } -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index 11ff902a9f..b9710ef829 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -189,11 +189,6 @@ public static ComparisonResult compare(ComparisonParameters params) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); - } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCStableMax) { - if (test == null) throw new IllegalArgumentException("Test not set."); - PcStableMax search = new PcStableMax(test); - result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) throw new IllegalArgumentException("Score not set."); Fges search = new Fges(score); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index 67de72e07e..a98095f8ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -138,10 +138,6 @@ public static ComparisonResult compare(ComparisonParameters params) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); - } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCStableMax) { - PcStableMax search = new PcStableMax(test); - result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { Fges search = new Fges(score); //search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); @@ -380,13 +376,6 @@ public static ComparisonResult compare(ComparisonParameters params) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); - } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.PCStableMax) { - if (test == null) { - throw new IllegalArgumentException("Test not set."); - } - PcStableMax search = new PcStableMax(test); - result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) { throw new IllegalArgumentException("Score not set."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java index c378ed964e..62a707b4df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonParameters.java @@ -135,10 +135,6 @@ public void setAlgorithm(Algorithm algorithm) { resultType = ResultType.CPDAG; } else if (algorithm == Algorithm.FGES) { resultType = ResultType.CPDAG; - } else if (algorithm == Algorithm.FGES2) { - resultType = ResultType.CPDAG; - } else if (algorithm == Algorithm.PCStableMax) { - resultType = ResultType.CPDAG; } else if (algorithm == Algorithm.FCI) { resultType = ResultType.PAG; } else if (algorithm == Algorithm.GFCI) { @@ -320,5 +316,5 @@ public enum ResultType {CPDAG, PAG} public enum IndependenceTestType {FisherZ, ChiSquare} - public enum Algorithm {PC, CPC, FGES, FGES2, PCStableMax, FCI, GFCI, SVARFCI} + public enum Algorithm {PC, CPC, FGES, FGES2, FCI, GFCI, SVARFCI} } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 8bc209e05c..5d5a4e2a07 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -247,74 +247,6 @@ public void testPcStable(int numVars, double edgeFactor, int numCases, double al this.out.close(); } - public void testPcStableMax(int numVars, double edgeFactor, int numCases, double alpha) { - final int depth = -1; - - init(new File("long.pcstablemax." + numVars + "." + edgeFactor + "." + alpha + ".txt"), "Tests performance of the PC Max algorithm"); - - long time1 = MillisecondTimes.timeMillis(); - - Graph dag = makeDag(numVars, edgeFactor); - - System.out.println("Graph done"); - - this.out.println("Graph done"); - - System.out.println("Starting simulation"); - LargeScaleSimulation simulator = new LargeScaleSimulation(dag); - simulator.setOut(this.out); - - DataSet data = simulator.simulateDataFisher(numCases); - - System.out.println("Finishing simulation"); - - long time2 = MillisecondTimes.timeMillis(); - - this.out.println("Elapsed (simulating the data): " + (time2 - time1) + " ms"); - - System.out.println("Making covariance matrix"); - -// ICovarianceMatrix cov = new CovarianceMatrix(data); - ICovarianceMatrix cov = new CovarianceMatrix(data); - - System.out.println("Covariance matrix done"); - - long time3 = MillisecondTimes.timeMillis(); - - this.out.println("Elapsed (calculating cov): " + (time3 - time2) + " ms"); - -// out.println(cov); - - IndTestFisherZ test = new IndTestFisherZ(cov, alpha); - - PcStableMax pcStable = new PcStableMax(test); - - Graph estCPDAG = pcStable.search(); - -// out.println(estCPDAG); - - long time4 = MillisecondTimes.timeMillis(); - - this.out.println("# Cases = " + numCases); - this.out.println("alpha = " + alpha); - this.out.println("depth = " + depth); - - this.out.println("Elapsed (simulating the data): " + (time2 - time1) + " ms"); - this.out.println("Elapsed (calculating cov): " + (time3 - time2) + " ms"); - this.out.println("Elapsed (running PC-Max) " + (time4 - time3) + " ms"); - - this.out.println("Total elapsed (cov + PC-Max) " + (time4 - time2) + " ms"); - - Graph trueCPDAG = SearchGraphUtils.cpdagForDag(dag); - - System.out.println("# edges in true CPDAG = " + trueCPDAG.getNumEdges()); - System.out.println("# edges in est CPDAG = " + estCPDAG.getNumEdges()); - - SearchGraphUtils.graphComparison(trueCPDAG, estCPDAG, this.out); - - this.out.close(); - } - public void testFges(int numVars, double edgeFactor, int numCases, double penaltyDiscount) { init(new File("long.fges." + numVars + "." + edgeFactor + "." + penaltyDiscount + ".txt"), "Tests performance of the FGES algorithm"); @@ -2103,11 +2035,6 @@ else if (args.length == 5) { System.out.println("Finish"); performanceTests.testPc(5000, 1, 1000, .0001); - - -// performanceTests.testPcStable(20000, 1, 1000, .00001); - performanceTests.testPcStableMax(5000, 1, 1000, .0001); - } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java index 2c62571ae6..8feb59cbf7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java @@ -111,7 +111,9 @@ public void testCites() { knowledge.addToTier(5, "PUBS"); knowledge.addToTier(6, "CITES"); - PcStableMax pc = new PcStableMax(new IndTestFisherZ(dataSet, 0.11)); + Pc pc = new Pc(new IndTestFisherZ(dataSet, 0.11)); + pc.setStable(true); + pc.setUseMaxP(true); pc.setKnowledge(knowledge); Graph CPDAG = pc.search(); @@ -170,7 +172,9 @@ private void checkWithKnowledge(String input, Knowledge knowledge) { // Set up search. IndependenceTest independence = new IndTestDSep(graph); - PcStableMax pc = new PcStableMax(independence); + Pc pc = new Pc(independence); + pc.setStable(true); + pc.setUseMaxP(true); // Set up search. pc.setKnowledge(knowledge); From 7addda8d0b6629882c777d49829c65ec324c7f84 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:27:09 -0400 Subject: [PATCH 287/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/Cstar.java | 3 +- .../java/edu/cmu/tetrad/search/PcStable.java | 284 ------------------ .../study/performance/PerformanceTests.java | 8 +- .../edu/pitt/csb/mgm/ExploreIndepTests.java | 12 +- .../pitt/csb/stability/SearchWrappers.java | 5 +- 5 files changed, 18 insertions(+), 294 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStable.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index 95c1005a07..eeaf488cc5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -680,7 +680,8 @@ public String makeTable(LinkedList records, boolean printTable) { private Graph getPatternPcStable(DataSet sample) { IndependenceTest test = getIndependenceTest(sample, this.test); test.setVerbose(false); - PcStable pc = new PcStable(test); + Pc pc = new Pc(test); + pc.setStable(true); pc.setVerbose(false); return pc.search(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStable.java deleted file mode 100644 index be65cc2b8d..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcStable.java +++ /dev/null @@ -1,284 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.TetradLogger; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -/** - * Implements the PC ("Peter/Clark") algorithm, as specified in Chapter 6 of Spirtes, Glymour, and Scheines, "Causation, - * Prediction, and Search," 2nd edition, with a modified rule set in step D due to Chris Meek. For the modified rule - * set, see Chris Meek (1995), "Causal inference and causal explanation with background knowledge." - *

- * In addition, the PC Stable modification to PC has been included (Colombo and Maathuis). - * - * @author Joseph Ramsey. - */ -public class PcStable implements GraphSearch { - - /** - * The independence test used for the PC search. - */ - private final IndependenceTest independenceTest; - - /** - * Forbidden and required edges for the search. - */ - private Knowledge knowledge = new Knowledge(); - - /** - * Sepset information accumulated in the search. - */ - private SepsetMap sepsets; - - /** - * The maximum number of nodes conditioned on in the search. The default it 1000. - */ - private int depth = 1000; - - /** - * The graph that's constructed during the search. - */ - private Graph graph; - - /** - * Elapsed time of the most recent search. - */ - private long elapsedTime; - - /** - * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large - * graphs). - */ - private boolean aggressivelyPreventCycles; - - /** - * The logger for this class. The config needs to be set. - */ - private final TetradLogger logger = TetradLogger.getInstance(); - - /** - * Prints independencies info to out. - */ - private boolean verbose; - private PrintStream out = System.out; - - //=============================CONSTRUCTORS==========================// - - /** - * Constructs a new PC search using the given independence test as oracle. - * - * @param independenceTest The oracle for conditional independence facts. This does not make a copy of the - * independence test, for fear of duplicating the data set! - */ - public PcStable(IndependenceTest independenceTest) { - if (independenceTest == null) { - throw new NullPointerException(); - } - - this.independenceTest = independenceTest; - } - - //==============================PUBLIC METHODS========================// - - /** - * @return true iff edges will not be added if they would create cycles. - */ - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - - /** - * @param aggressivelyPreventCycles Set to true just in case edges will not be addeds if they would create cycles. - */ - public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { - this.aggressivelyPreventCycles = aggressivelyPreventCycles; - } - - /** - * @return the independence test being used in the search. - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - /** - * @return the knowledge specification used in the search. Non-null. - */ - public Knowledge getKnowledge() { - return this.knowledge; - } - - /** - * Sets the knowledge specification to be used in the search. May not be null. - */ - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - /** - * @return the sepset map from the most recent search. Non-null after the first call to search(). - */ - public SepsetMap getSepsets() { - return this.sepsets; - } - - /** - * @return the current depth of search--that is, the maximum number of conditioning nodes for any conditional - * independence checked. - */ - public int getDepth() { - return this.depth; - } - - /** - * Sets the depth of the search--that is, the maximum number of conditioning nodes for any conditional independence - * checked. - * - * @param depth The depth of the search. The default is 1000. A value of -1 may be used to indicate that the depth - * should be high (1000). A value of Integer.MAX_VALUE may not be used, due to a bug on multi-core - * machines. - */ - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException("Depth must be -1 or >= 0: " + depth); - } - - if (depth > 1000) { - throw new IllegalArgumentException("Depth must be <= 1000."); - } - - this.depth = depth; - } - - /** - * Runs PC starting with a complete graph over all nodes of the given conditional independence test, using the given - * independence test and knowledge and returns the resultant graph. The returned graph will be a CPDAG if the - * independence information is consistent with the hypothesis that there are no latent common causes. It may, - * however, contain cycles or bidirected edges if this assumption is not born out, either due to the actual presence - * of latent common causes, or due to statistical errors in conditional independence judgments. - */ - public Graph search() { - return search(this.independenceTest.getVariables()); - } - - /** - * Runs PC starting with a commplete graph over the given list of nodes, using the given independence test and - * knowledge and returns the resultant graph. The returned graph will be a CPDAG if the independence information - * is consistent with the hypothesis that there are no latent common causes. It may, however, contain cycles or - * bidirected edges if this assumption is not born out, either due to the actual presence of latent common causes, - * or due to statistical errors in conditional independence judgments. - *

- * All of the given nodes must be in the domain of the given conditional independence test. - */ - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - - if (verbose) { - this.logger.log("info", "Starting PC algorithm"); - this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); - } - - long startTime = MillisecondTimes.timeMillis(); - - if (getIndependenceTest() == null) { - throw new NullPointerException(); - } - - List allNodes = getIndependenceTest().getVariables(); - - if (!allNodes.containsAll(nodes)) { - throw new IllegalArgumentException("All of the given nodes must " + - "be in the domain of the independence test provided."); - } - - this.graph = new EdgeListGraph(nodes); - - Fas fas = new Fas(getIndependenceTest()); - fas.setStable(true); - fas.setKnowledge(getKnowledge()); - fas.setDepth(getDepth()); - fas.setVerbose(this.verbose); - - this.graph = fas.search(); - this.sepsets = fas.getSepsets(); - - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - SearchGraphUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); - - MeekRules rules = new MeekRules(); - rules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles); - rules.setKnowledge(this.knowledge); - rules.orientImplied(this.graph); - - if (verbose) { - this.logger.log("graph", "\nReturning this graph: " + this.graph); - } - - this.elapsedTime = MillisecondTimes.timeMillis() - startTime; - - if (verbose) { - this.logger.log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); - this.logger.log("info", "Finishing PC Algorithm."); - this.logger.flush(); - } - - return this.graph; - } - - /** - * @return the elapsed time of the search, in milliseconds. - */ - public long getElapsedTime() { - return this.elapsedTime; - } - - //===============================PRIVATE METHODS=======================// - - public List getNodes() { - return this.graph.getNodes(); - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setOut(PrintStream out) { - this.out = out; - } - - public PrintStream getOut() { - return this.out; - } -} - - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 5d5a4e2a07..dd2ab67f96 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -219,9 +219,10 @@ public void testPcStable(int numVars, double edgeFactor, int numCases, double al IndTestFisherZ test = new IndTestFisherZ(cov, alpha); - PcStable pcStable = new PcStable(test); + Pc pc = new Pc(test); + pc.setStable(true); - Graph estCPDAG = pcStable.search(); + Graph estCPDAG = pc.search(); // out.println(estCPDAG); @@ -1379,7 +1380,8 @@ public void testComparePcVersions(int numVars, double edgeFactor, int numLatents System.out.println("First FAS graph = " + left); - PcStable pc2 = new PcStable(new IndTestDSep(dag)); + Pc pc2 = new Pc(new IndTestDSep(dag)); + pc2.setStable(true); Graph top = pc2.search(); System.out.println("Second FAS graph = " + top); diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java index 8f793d91ce..414b9438cf 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java @@ -24,8 +24,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphPersistence; +import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; -import edu.cmu.tetrad.search.PcStable; import edu.cmu.tetrad.search.SearchGraphUtils; import edu.cmu.tetrad.util.MillisecondTimes; @@ -45,9 +45,13 @@ public static void main(String[] args) { IndTestMultinomialLogisticRegressionWald indWalLin = new IndTestMultinomialLogisticRegressionWald(ds, .05, true); IndTestMultinomialLogisticRegressionWald indWalLog = new IndTestMultinomialLogisticRegressionWald(ds, .05, false); - PcStable s1 = new PcStable(indMix); - PcStable s2 = new PcStable(indWalLin); - PcStable s3 = new PcStable(indWalLog); + Pc s1 = new Pc(indMix); + Pc s2 = new Pc(indWalLin); + Pc s3 = new Pc(indWalLog); + + s1.setStable(true); + s2.setStable(true); + s3.setStable(true); long time = MillisecondTimes.timeMillis(); Graph g1 = SearchGraphUtils.cpdagFromDag(s1.search()); diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java index ba6e183b8b..8521b39ecf 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java @@ -25,8 +25,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; -import edu.cmu.tetrad.search.PcStable; import edu.cmu.tetrad.search.SemBicScore; import edu.pitt.csb.mgm.Mgm; import edu.pitt.csb.mgm.MixedUtils; @@ -47,7 +47,8 @@ public PcStableWrapper copy() { public Graph search(DataSet ds) { IndTestMultinomialLogisticRegression indTest = new IndTestMultinomialLogisticRegression(ds, this.searchParams[0]); - PcStable pcs = new PcStable(indTest); + Pc pcs = new Pc(indTest); + pcs.setStable(true); return pcs.search(); } } From cf0e16d921ac87f84d33d40f61d629456df70392 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:30:33 -0400 Subject: [PATCH 288/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/PermutationMatrixPair.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index 6f31c86ee9..244f42a7cf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -26,9 +26,9 @@ import java.util.Arrays; /** - * Stores a matrix together with a row and column permutation. (if either - * of these is null, the identity permtuation will be used.) Returns - * the permuted matrix. + * Stores a matrix together with a row and column permutation. if either + * of these is null in the constructor, the identity permtuation will be used. + * Returns the matrix permuted by these row and column permutations. * * @author josephramsey */ From a861e3caec9796878b01d28e9b71ab02e22c854a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:38:41 -0400 Subject: [PATCH 289/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/PermutationSearch.java | 10 +++++++++- .../cmu/tetrad/search/PoissonPriorScore.java | 18 ++++-------------- .../edu/cmu/tetrad/search/SuborderSearch.java | 4 ++++ .../search/{ => WIP}/PopulationTetradTest.java | 3 ++- 4 files changed, 19 insertions(+), 16 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => WIP}/PopulationTetradTest.java (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index 4eba50a5e7..12ab7684c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -8,9 +8,17 @@ import java.util.*; /** - * Implements permutation search. + *

Implements common elements of a permutation search. The specific parts + * for each permutation search are implemented as a SuborderSearch.

+ *

This class specificaly handls an optimization for tiered knowledge, whereby + * tiers in the knowledge can be searched one at a time in order form lowest + * to highest, taking all variables from previous tiesrs as a fixed previs + * for an later tier. This allos these permutation searches to search over + * many more varaibles than otherwise, so long as tiered knowledge is available + * to organize the search.

* * @author bryanandrews + * @see SuborderSearch */ public class PermutationSearch { private final SuborderSearch suborderSearch; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java index ded58d4f22..76f4bc20d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java @@ -145,15 +145,6 @@ public double localScore(int i, int... parents) throws RuntimeException { } } - public static double getP(int pn, int m0, double lambda) { - return 2 - pow(1 + (exp(-(lambda - 1) / 2.)) * sqrt(lambda), (double) pn - m0); - } - - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. - */ - - public ICovarianceMatrix getCovariances() { return this.covariances; } @@ -180,7 +171,6 @@ public List getVariables() { return this.variables; } - @Override public int getMaxDegree() { return (int) ceil(log(this.sampleSize)); @@ -189,11 +179,8 @@ public int getMaxDegree() { @Override public boolean determines(List z, Node y) { int i = this.variables.indexOf(y); - int[] k = indices(z); - double v = localScore(i, k); - return Double.isNaN(v); } @@ -228,11 +215,14 @@ private void setCovariances(ICovarianceMatrix covariances) { this.N = covariances.getSampleSize(); } - public void setLambda(double lambda) { if (lambda < 1.0) throw new IllegalArgumentException("Structure prior can't be < 1: " + lambda); this.lambda = lambda; } + + private static double getP(int pn, int m0, double lambda) { + return 2 - pow(1 + (exp(-(lambda - 1) / 2.)) * sqrt(lambda), (double) pn - m0); + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index 5876eb0aa2..72fb545e46 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -11,8 +11,12 @@ * Interface to help implement suborder searches for various types of permutation algorithms. * A "suborder search" is a search for permutation <x1a,...x1n, x2a,...,x2m, x3a,...,x3l>> * that searches for a good permutation of x2a,...,x2m with x1a,...,x1n as a prefix. + * This is used by PermutationSearch to form a complete permutation search algorithm, + * where PermutationSearch handles an optimization for tiered knowledge where each + * tier can be search separately in order. (See the documentation for that class.) * * @author bryanandrews + * @see PermutationSearch */ public interface SuborderSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/PopulationTetradTest.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/PopulationTetradTest.java index 192c9642df..46346f3944 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PopulationTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/PopulationTetradTest.java @@ -19,12 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.TetradTest; import org.apache.commons.math3.util.FastMath; import java.util.List; From 555d2950b174601aa5060620722d2d031c1a50b8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:39:17 -0400 Subject: [PATCH 290/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index fb1aaa07ea..ca9489e205 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -39,7 +39,6 @@ * @author Robert Tillman */ public final class ResolveSepsets { - public enum Method { fisher, fisher2, tippett, worsleyfriston, stouffer, mudholkergeorge, mudholkergeorge2, average, averagetest, random, fdr, majority From b200aa5d425c766a255cb5f39acdbd751cd8a247 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:56:10 -0400 Subject: [PATCH 291/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/ResolveSepsets.java | 238 +------ .../tetrad/search/WIP/ResolveSepsetsDci.java | 633 ++++++++++++++++++ 2 files changed, 664 insertions(+), 207 deletions(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index ca9489e205..4fd4f3cf00 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -23,14 +23,14 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.graph.NodePair; -import edu.cmu.tetrad.search.WIP.SepsetMapDci; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * Utilities for resolving inconsistencies that arise between sepsets learned for overlapping datasets. This occurs @@ -44,184 +44,11 @@ public enum Method { mudholkergeorge2, average, averagetest, random, fdr, majority } - /** - * Resolves all inconsistencies between sepsets using a paricular method. Returns a sepsetMapDci with the resolved - * separations and associations. resolvedIndependent and resolvedDependent keep up with the number resolved to check - * later against the truth - */ - public static SepsetMapDci resolveSepsets(List sepsets, List independenceTests, - Method method, SepsetMapDci resolvedIndependent, SepsetMapDci resolvedDependent) { - SepsetMapDci resolvedSepset = new SepsetMapDci(); - // get all variables - Set allVars = new HashSet<>(); - for (IndependenceTest independenceTest : independenceTests) { - allVars.addAll(independenceTest.getVariables()); - } - // checks each pair of nodes for inconsistencies across independenceTests - for (NodePair pair : ResolveSepsets.allNodePairs(new ArrayList<>(allVars))) { - // gets independenceTests and sepsets for every dataset with the pair - List>> pairSepsets = new ArrayList<>(); - List testsWithPair = new ArrayList<>(); - for (int k = 0; k < independenceTests.size(); k++) { - IndependenceTest independenceTest = independenceTests.get(k); - if (independenceTest.getVariables().containsAll(Arrays.asList(pair.getFirst(), pair.getSecond()))) { - pairSepsets.add(sepsets.get(k).getSet(pair.getFirst(), pair.getSecond())); - testsWithPair.add(independenceTest); - } - } - // only check if pair is included in more than one dataset - if (testsWithPair.size() < 2) { - // if pair only in one dataset then add all to resolvedSepset - if (testsWithPair.size() == 1) { - if (pairSepsets.get(0) == null) { - continue; - } - for (List sepset : pairSepsets.get(0)) { - resolvedSepset.set(pair.getFirst(), pair.getSecond(), sepset); - } - } - continue; - } - // check each conditioning set from a dataset - List> allConditioningSets = new ArrayList<>(); - for (List> conditioningSet : pairSepsets) { - if (conditioningSet == null) { - continue; - } - allConditioningSets.addAll(conditioningSet); - } - for (List conditioningSet : allConditioningSets) { - List testsWithSet = new ArrayList<>(); - for (IndependenceTest independenceTest : testsWithPair) { - if (independenceTest.getVariables().containsAll(conditioningSet) || conditioningSet.isEmpty()) { - testsWithSet.add(independenceTest); - } - } - // only check if more than one dataset have test - if (testsWithSet.size() < 2) { - // if conditioning set only in one dataset then add to resolvedSepset - if (testsWithPair.size() == 1) { - resolvedSepset.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - continue; - } - boolean separated = false; - boolean inconsistent = false; - for (int k = 0; k < testsWithSet.size(); k++) { - IndependenceTest testWithSet = testsWithSet.get(k); - if (k == 0) { - separated = testWithSet.checkIndependence(pair.getFirst(), pair.getSecond(), conditioningSet).isIndependent(); - continue; - } - // checks to see if inconsistent - if (separated != testWithSet.checkIndependence(pair.getFirst(), pair.getSecond(), conditioningSet).isIndependent()) { - inconsistent = true; - break; - } - } - // if inconsistent then use pooling method - if (inconsistent) { - // if using Fisher pooling - if (method == Method.fisher) { - if (ResolveSepsets.isIndependentPooledFisher(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.fisher2) { - if (ResolveSepsets.isIndependentPooledFisher2(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.tippett) { - if (ResolveSepsets.isIndependentPooledTippett(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.worsleyfriston) { - if (ResolveSepsets.isIndependentPooledWorsleyFriston(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.stouffer) { - if (ResolveSepsets.isIndependentPooledStouffer(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.mudholkergeorge) { - if (ResolveSepsets.isIndependentPooledMudholkerGeorge(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.mudholkergeorge2) { - if (ResolveSepsets.isIndependentPooledMudholkerGeorge2(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.averagetest) { - if (ResolveSepsets.isIndependentPooledAverageTest(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.average) { - if (ResolveSepsets.isIndependentPooledAverage(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.random) { - if (ResolveSepsets.isIndependentPooledRandom(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.fdr) { - if (ResolveSepsets.isIndependentMajorityFdr(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else if (method == Method.majority) { - if (ResolveSepsets.isIndependentMajorityIndep(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { - resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); - resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } else { - resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } else { - throw new RuntimeException("Invalid Test"); - } - - } else { - resolvedSepset.set(pair.getFirst(), pair.getSecond(), conditioningSet); - } - } - } - return resolvedSepset; - } - /** * Tests for independence using one of the pooled methods */ - public static boolean isIndependentPooled(Method method, List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooled(Method method, List independenceTests, + Node x, Node y, List condSet) { if (method == Method.fisher) { return ResolveSepsets.isIndependentPooledFisher(independenceTests, x, y, condSet); } else if (method == Method.fisher2) { @@ -256,7 +83,8 @@ public static boolean isIndependentPooled(Method method, List *

* See R. A. Fisher. Statistical Methods for Research Workers. Oliver and Boyd, 11th edition, 1950. */ - public static boolean isIndependentPooledFisher(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledFisher(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); double tf = 0.0; for (IndependenceTest independenceTest : independenceTests) { @@ -275,7 +103,8 @@ public static boolean isIndependentPooledFisher(List independe /** * Eliminates from considerations independence tests that cannot be evaluated (due to missing variables mainly). */ - public static boolean isIndependentPooledFisher2(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledFisher2(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); List pValues = ResolveSepsets.getAvailablePValues(independenceTests, x, y, condSet); @@ -299,7 +128,8 @@ public static boolean isIndependentPooledFisher2(List independ *

* See L. H. C. Tippett. The Method of Statistics. Williams and Norgate, 1st edition, 1950. */ - public static boolean isIndependentPooledTippett(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledTippett(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); double p = -1.0; for (IndependenceTest independenceTest : independenceTests) { @@ -327,7 +157,8 @@ public static boolean isIndependentPooledTippett(List independ *

* I don't have a reference for this but its basically in between Tippett and Worsley and Friston. */ - public static boolean isIndependentPooledWilkinson(List independenceTests, Node x, Node y, List condSet, int r) { + public static boolean isIndependentPooledWilkinson(List independenceTests, Node x, Node y, + List condSet, int r) { double alpha = independenceTests.get(0).getAlpha(); double[] p = new double[independenceTests.size()]; int k = 0; @@ -346,7 +177,8 @@ public static boolean isIndependentPooledWilkinson(List indepe * See K. J. Worsely and K. J. Friston. A test for conjunction. Statistics and Probability Letters * 2000. */ - public static boolean isIndependentPooledWorsleyFriston(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledWorsleyFriston(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); double p = -1.0; for (IndependenceTest independenceTest : independenceTests) { @@ -374,7 +206,8 @@ public static boolean isIndependentPooledWorsleyFriston(List i * See S. A. Stouffer, E. A. Suchman, L. C. Devinney, S. A. Star, and R. M. Williams. The American Soldier: Vol. 1. * Adjustment During Army Life. Princeton University Press, 1949. */ - public static boolean isIndependentPooledStouffer(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledStouffer(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); double ts = 0.0; for (IndependenceTest independenceTest : independenceTests) { @@ -382,7 +215,8 @@ public static boolean isIndependentPooledStouffer(List indepen for (Node node : condSet) { localCondSet.add(independenceTest.getVariable(node.getName())); } - IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), + independenceTest.getVariable(y.getName()), localCondSet); ts += ProbUtils.normalQuantile(result.getPValue()) / FastMath.sqrt(independenceTests.size()); } double p = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, FastMath.abs(ts))); @@ -417,7 +251,8 @@ public static boolean isIndependentPooledMudholkerGeorge(List /** * The same as isIndepenentPooledMudholkerGeoerge, except that only available independence tests are used. */ - public static boolean isIndependentPooledMudholkerGeorge2(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledMudholkerGeorge2(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); List pValues = ResolveSepsets.getAvailablePValues(independenceTests, x, y, condSet); double c = FastMath.sqrt(3 * (5 * pValues.size() + 4) / (pValues.size() * FastMath.pow(FastMath.PI, 2) * (5 * pValues.size() + 2))); @@ -432,7 +267,8 @@ public static boolean isIndependentPooledMudholkerGeorge2(List /** * Checks independence from pooled samples by taking the average p value */ - public static boolean isIndependentPooledAverage(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledAverage(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); double sum = 0.0; int numTests = 0; @@ -495,7 +331,8 @@ private static boolean isMissing(Node node, DataSet dataSet) { * Checks independence from pooled samples by taking the average test statistic CURRENTLY ONLY WORKS FOR CHISQUARE * TEST */ - public static boolean isIndependentPooledAverageTest(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledAverageTest(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); double ts = 0.0; int df = 0; @@ -519,7 +356,8 @@ public static boolean isIndependentPooledAverageTest(List inde /** * Checks independence from pooled samples by randomly selecting a p value */ - public static boolean isIndependentPooledRandom(List independenceTests, Node x, Node y, List condSet) { + public static boolean isIndependentPooledRandom(List independenceTests, Node x, Node y, + List condSet) { double alpha = independenceTests.get(0).getAlpha(); int r = RandomUtil.getInstance().nextInt(independenceTests.size()); IndependenceTest independenceTest = independenceTests.get(r); @@ -532,25 +370,13 @@ public static boolean isIndependentPooledRandom(List independe return (p > alpha); } - /** - * Generates NodePairs of all possible pairs of nodes from given list of nodes. - */ - public static List allNodePairs(List nodes) { - List nodePairs = new ArrayList<>(); - for (int j = 0; j < nodes.size() - 1; j++) { - for (int k = j + 1; k < nodes.size(); k++) { - nodePairs.add(new NodePair(nodes.get(j), nodes.get(k))); - } - } - return nodePairs; - } - /** * Judges x to be independent of y conditional on condSet if the false discovery rate of the p values for the * separate judgements for their collective alpha level identifies no more than # p values / 2 values below * threshold. */ - private static boolean isIndependentMajorityFdr(List independenceTests, Node x, Node y, List condSet) { + private static boolean isIndependentMajorityFdr(List independenceTests, Node x, Node y, + List condSet) { List allPValues = ResolveSepsets.getAvailablePValues(independenceTests, x, y, condSet); Collections.sort(allPValues); @@ -563,7 +389,6 @@ private static boolean isIndependentMajorityFdr(List independe // At least half of the judgments are for independence. boolean independent = c < allPValues.size() / 2; -// boolean independent = c < allPValues.size() - 2; if (independent) { TetradLogger.getInstance().log("independence", "***FDR judges " + SearchLogUtils.independenceFact(x, y, condSet) + " independent"); @@ -575,7 +400,8 @@ private static boolean isIndependentMajorityFdr(List independe return independent; } - private static List getAvailablePValues(List independenceTests, Node x, Node y, List condSet) { + private static List getAvailablePValues(List independenceTests, Node x, Node y, + List condSet) { List allPValues = new ArrayList<>(); for (IndependenceTest test : independenceTests) { @@ -610,9 +436,7 @@ private static boolean isIndependentMajorityIndep(List indepen c++; } - // At least half of the judgments are for independence. -// boolean independent = c < 40; boolean independent = c < allPValues.size() / 2; if (independent) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java new file mode 100644 index 0000000000..22967e0bdc --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java @@ -0,0 +1,633 @@ +/////////////////////////////////////////////////////////////////////////////// +// For information as to what this class does, see the Javadoc, below. // +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // +// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // +// Scheines, Joseph Ramsey, and Clark Glymour. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation; either version 2 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program; if not, write to the Free Software // +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +/////////////////////////////////////////////////////////////////////////////// + +package edu.cmu.tetrad.search.WIP; + +import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.graph.NodePair; +import edu.cmu.tetrad.search.IndTestChiSquare; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.util.ProbUtils; +import edu.cmu.tetrad.util.RandomUtil; +import edu.cmu.tetrad.util.TetradLogger; +import org.apache.commons.math3.util.FastMath; + +import java.util.*; + +/** + * Utilities for resolving inconsistencies that arise between sepsets learned for overlapping datasets. This occurs + * frequently when using the DCI and ION algorithm. f + * + * @author Robert Tillman + */ +public final class ResolveSepsetsDci { + public enum Method { + fisher, fisher2, tippett, worsleyfriston, stouffer, mudholkergeorge, + mudholkergeorge2, average, averagetest, random, fdr, majority + } + + /** + * Resolves all inconsistencies between sepsets using a paricular method. Returns a sepsetMapDci with the resolved + * separations and associations. resolvedIndependent and resolvedDependent keep up with the number resolved to check + * later against the truth + */ + public static SepsetMapDci resolveSepsets(List sepsets, List independenceTests, + Method method, SepsetMapDci resolvedIndependent, SepsetMapDci resolvedDependent) { + SepsetMapDci resolvedSepset = new SepsetMapDci(); + // get all variables + Set allVars = new HashSet<>(); + for (IndependenceTest independenceTest : independenceTests) { + allVars.addAll(independenceTest.getVariables()); + } + // checks each pair of nodes for inconsistencies across independenceTests + for (NodePair pair : ResolveSepsetsDci.allNodePairs(new ArrayList<>(allVars))) { + // gets independenceTests and sepsets for every dataset with the pair + List>> pairSepsets = new ArrayList<>(); + List testsWithPair = new ArrayList<>(); + for (int k = 0; k < independenceTests.size(); k++) { + IndependenceTest independenceTest = independenceTests.get(k); + if (independenceTest.getVariables().containsAll(Arrays.asList(pair.getFirst(), pair.getSecond()))) { + pairSepsets.add(sepsets.get(k).getSet(pair.getFirst(), pair.getSecond())); + testsWithPair.add(independenceTest); + } + } + // only check if pair is included in more than one dataset + if (testsWithPair.size() < 2) { + // if pair only in one dataset then add all to resolvedSepset + if (testsWithPair.size() == 1) { + if (pairSepsets.get(0) == null) { + continue; + } + for (List sepset : pairSepsets.get(0)) { + resolvedSepset.set(pair.getFirst(), pair.getSecond(), sepset); + } + } + continue; + } + // check each conditioning set from a dataset + List> allConditioningSets = new ArrayList<>(); + for (List> conditioningSet : pairSepsets) { + if (conditioningSet == null) { + continue; + } + allConditioningSets.addAll(conditioningSet); + } + for (List conditioningSet : allConditioningSets) { + List testsWithSet = new ArrayList<>(); + for (IndependenceTest independenceTest : testsWithPair) { + if (independenceTest.getVariables().containsAll(conditioningSet) || conditioningSet.isEmpty()) { + testsWithSet.add(independenceTest); + } + } + // only check if more than one dataset have test + if (testsWithSet.size() < 2) { + // if conditioning set only in one dataset then add to resolvedSepset + if (testsWithPair.size() == 1) { + resolvedSepset.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + continue; + } + boolean separated = false; + boolean inconsistent = false; + for (int k = 0; k < testsWithSet.size(); k++) { + IndependenceTest testWithSet = testsWithSet.get(k); + if (k == 0) { + separated = testWithSet.checkIndependence(pair.getFirst(), pair.getSecond(), conditioningSet).isIndependent(); + continue; + } + // checks to see if inconsistent + if (separated != testWithSet.checkIndependence(pair.getFirst(), pair.getSecond(), conditioningSet).isIndependent()) { + inconsistent = true; + break; + } + } + // if inconsistent then use pooling method + if (inconsistent) { + // if using Fisher pooling + if (method == Method.fisher) { + if (ResolveSepsetsDci.isIndependentPooledFisher(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.fisher2) { + if (ResolveSepsetsDci.isIndependentPooledFisher2(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.tippett) { + if (ResolveSepsetsDci.isIndependentPooledTippett(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.worsleyfriston) { + if (ResolveSepsetsDci.isIndependentPooledWorsleyFriston(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.stouffer) { + if (ResolveSepsetsDci.isIndependentPooledStouffer(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.mudholkergeorge) { + if (ResolveSepsetsDci.isIndependentPooledMudholkerGeorge(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.mudholkergeorge2) { + if (ResolveSepsetsDci.isIndependentPooledMudholkerGeorge2(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.averagetest) { + if (ResolveSepsetsDci.isIndependentPooledAverageTest(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.average) { + if (ResolveSepsetsDci.isIndependentPooledAverage(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.random) { + if (ResolveSepsetsDci.isIndependentPooledRandom(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.fdr) { + if (ResolveSepsetsDci.isIndependentMajorityFdr(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else if (method == Method.majority) { + if (ResolveSepsetsDci.isIndependentMajorityIndep(testsWithSet, pair.getFirst(), pair.getSecond(), conditioningSet)) { + resolvedSepset.set(pair.getFirst(), pair.getFirst(), conditioningSet); + resolvedIndependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } else { + resolvedDependent.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } else { + throw new RuntimeException("Invalid Test"); + } + + } else { + resolvedSepset.set(pair.getFirst(), pair.getSecond(), conditioningSet); + } + } + } + return resolvedSepset; + } + + /** + * Tests for independence using one of the pooled methods + */ + public static boolean isIndependentPooled(Method method, List independenceTests, Node x, Node y, List condSet) { + if (method == Method.fisher) { + return ResolveSepsetsDci.isIndependentPooledFisher(independenceTests, x, y, condSet); + } else if (method == Method.fisher2) { + return ResolveSepsetsDci.isIndependentPooledFisher2(independenceTests, x, y, condSet); + } else if (method == Method.tippett) { + return ResolveSepsetsDci.isIndependentPooledTippett(independenceTests, x, y, condSet); + } else if (method == Method.worsleyfriston) { + return ResolveSepsetsDci.isIndependentPooledWorsleyFriston(independenceTests, x, y, condSet); + } else if (method == Method.stouffer) { + return ResolveSepsetsDci.isIndependentPooledStouffer(independenceTests, x, y, condSet); + } else if (method == Method.mudholkergeorge) { + return ResolveSepsetsDci.isIndependentPooledMudholkerGeorge(independenceTests, x, y, condSet); + } else if (method == Method.mudholkergeorge2) { + return ResolveSepsetsDci.isIndependentPooledMudholkerGeorge2(independenceTests, x, y, condSet); + } else if (method == Method.averagetest) { + return ResolveSepsetsDci.isIndependentPooledAverageTest(independenceTests, x, y, condSet); + } else if (method == Method.average) { + return ResolveSepsetsDci.isIndependentPooledAverage(independenceTests, x, y, condSet); + } else if (method == Method.random) { + return ResolveSepsetsDci.isIndependentPooledRandom(independenceTests, x, y, condSet); + } else if (method == Method.fdr) { + return ResolveSepsetsDci.isIndependentMajorityFdr(independenceTests, x, y, condSet); + } else if (method == Method.majority) { + return ResolveSepsetsDci.isIndependentMajorityIndep(independenceTests, x, y, condSet); + } else { + throw new RuntimeException("Invalid Test"); + } + } + + /** + * Checks independence from pooled samples using Fisher's method. + *

+ * See R. A. Fisher. Statistical Methods for Research Workers. Oliver and Boyd, 11th edition, 1950. + */ + public static boolean isIndependentPooledFisher(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + double tf = 0.0; + for (IndependenceTest independenceTest : independenceTests) { + if (ResolveSepsetsDci.missingVariable(x, y, condSet, independenceTest)) continue; + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + tf += -2.0 * FastMath.log(result.getPValue()); + } + double p = 1.0 - ProbUtils.chisqCdf(tf, 2 * independenceTests.size()); + return (p > alpha); + } + + /** + * Eliminates from considerations independence tests that cannot be evaluated (due to missing variables mainly). + */ + public static boolean isIndependentPooledFisher2(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + List pValues = ResolveSepsetsDci.getAvailablePValues(independenceTests, x, y, condSet); + + double tf = 0.0; + int numPValues = 0; + + for (double p : pValues) { +// if (p > 0) { + tf += -2.0 * FastMath.log(p); + numPValues++; +// } + } + + double p = 1.0 - ProbUtils.chisqCdf(tf, 2 * numPValues); + + return (p > alpha); + } + + /** + * Checks independence from pooled samples using Tippett's method + *

+ * See L. H. C. Tippett. The Method of Statistics. Williams and Norgate, 1st edition, 1950. + */ + public static boolean isIndependentPooledTippett(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + double p = -1.0; + for (IndependenceTest independenceTest : independenceTests) { + if (ResolveSepsetsDci.missingVariable(x, y, condSet, independenceTest)) continue; + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + IndependenceResult result = independenceTest.checkIndependence( + independenceTest.getVariable(x.getName()), + independenceTest.getVariable(y.getName()), localCondSet); + if (Double.isNaN(result.getPValue())) { + continue; + } + double newp = result.getPValue(); + if (newp < p) { + p = newp; + } + } + return (p > (1 - FastMath.pow(1 - alpha, (1 / (double) independenceTests.size())))); + } + + /** + * Checks independence from pooled samples using Wilkinson's method + *

+ * I don't have a reference for this but its basically in between Tippett and Worsley and Friston. + */ + public static boolean isIndependentPooledWilkinson(List independenceTests, Node x, Node y, List condSet, int r) { + double alpha = independenceTests.get(0).getAlpha(); + double[] p = new double[independenceTests.size()]; + int k = 0; + for (IndependenceTest independenceTest : independenceTests) { + IndependenceResult result = independenceTest.checkIndependence(x, y, condSet); + p[k] = result.getPValue(); + k++; + } + Arrays.sort(p); + return (p[r] > (1 - FastMath.pow(1 - FastMath.pow(alpha, 1.0 / (double) r), (r / (double) independenceTests.size())))); + } + + /** + * Checks independence from pooled samples using Worsley and Friston's method + *

+ * See K. J. Worsely and K. J. Friston. A test for conjunction. Statistics and Probability Letters + * 2000. + */ + public static boolean isIndependentPooledWorsleyFriston(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + double p = -1.0; + for (IndependenceTest independenceTest : independenceTests) { + List localCondSet = new ArrayList<>(); + if (ResolveSepsetsDci.missingVariable(x, y, condSet, independenceTest)) continue; + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + if (Double.isNaN(result.getPValue())) { +// p = result.getPValue(); + continue; + } + double newp = result.getPValue(); + if (newp > p) { + p = newp; + } + } + return (p > FastMath.pow(alpha, (1 / (double) independenceTests.size()))); + } + + /** + * Checks independence from pooled samples using Stouffer et al.'s method + *

+ * See S. A. Stouffer, E. A. Suchman, L. C. Devinney, S. A. Star, and R. M. Williams. The American Soldier: Vol. 1. + * Adjustment During Army Life. Princeton University Press, 1949. + */ + public static boolean isIndependentPooledStouffer(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + double ts = 0.0; + for (IndependenceTest independenceTest : independenceTests) { + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + ts += ProbUtils.normalQuantile(result.getPValue()) / FastMath.sqrt(independenceTests.size()); + } + double p = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, FastMath.abs(ts))); + return (p > alpha); + } + + /** + * Checks independence from pooled samples using Mudholker and George's method + *

+ * See G. S. Mudholkar and E. O. George. The logit method for combining probabilities. In J. Rustagi, editor, + * Symposium on Optimizing Method in Statistics, pages 345-366. Academic Press, 1979. + */ + public static boolean isIndependentPooledMudholkerGeorge(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + double c = FastMath.sqrt(3 * (5 * independenceTests.size() + 4) / (independenceTests.size() * FastMath.pow(FastMath.PI, 2) * (5 * independenceTests.size() + 2))); + double tm = 0.0; + for (IndependenceTest independenceTest : independenceTests) { + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + double pk = result.getPValue(); + if (pk != 0 && pk != 1) { + tm += -c * FastMath.log(pk / (1 - pk)); + } + } + double p = 2.0 * (1.0 - ProbUtils.tCdf(FastMath.abs(tm), 5 * independenceTests.size() + 4)); + return (p > alpha); + } + + /** + * The same as isIndepenentPooledMudholkerGeoerge, except that only available independence tests are used. + */ + public static boolean isIndependentPooledMudholkerGeorge2(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + List pValues = ResolveSepsetsDci.getAvailablePValues(independenceTests, x, y, condSet); + double c = FastMath.sqrt(3 * (5 * pValues.size() + 4) / (pValues.size() * FastMath.pow(FastMath.PI, 2) * (5 * pValues.size() + 2))); + double tm = 0.0; + for (double pk : pValues) { + tm += -c * FastMath.log(pk / (1 - pk)); + } + double p = 2.0 * (1.0 - ProbUtils.tCdf(FastMath.abs(tm), 5 * pValues.size() + 4)); + return (p > alpha); + } + + /** + * Checks independence from pooled samples by taking the average p value + */ + public static boolean isIndependentPooledAverage(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + double sum = 0.0; + int numTests = 0; + + for (IndependenceTest independenceTest : independenceTests) { + if (ResolveSepsetsDci.missingVariable(x, y, condSet, independenceTest)) continue; + + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + + IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + double p = result.getPValue(); + + if (Double.isNaN(p)) continue; + + sum += p; + numTests++; + } + + + return (sum / numTests > alpha); + } + + private static boolean missingVariable(Node x, Node y, List condSet, IndependenceTest independenceTest) { + DataSet dataSet = (DataSet) independenceTest.getData(); + + if (ResolveSepsetsDci.isMissing(x, dataSet)) { + return true; + } + + if (ResolveSepsetsDci.isMissing(y, dataSet)) { + return true; + } + + for (Node z : condSet) { + if (ResolveSepsetsDci.isMissing(z, dataSet)) { + return true; + } + } + return false; + } + + private static boolean isMissing(Node node, DataSet dataSet) { + Node _node = dataSet.getVariable(node.getName()); + + int col = dataSet.getColumn(_node); + + for (int i = 0; i < dataSet.getNumRows(); i++) { + if (Double.isNaN(dataSet.getDouble(i, col))) { + return true; + } + } + + return false; + } + + /** + * Checks independence from pooled samples by taking the average test statistic CURRENTLY ONLY WORKS FOR CHISQUARE + * TEST + */ + public static boolean isIndependentPooledAverageTest(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + double ts = 0.0; + int df = 0; + for (IndependenceTest independenceTest : independenceTests) { + if (!(independenceTest instanceof IndTestChiSquare)) { + throw new RuntimeException("Must be ChiSquare Test"); + } + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + ts += ((IndTestChiSquare) independenceTest).getChiSquare() / independenceTests.size(); + df += ((IndTestChiSquare) independenceTest).getDf(); + } + df = df / independenceTests.size(); + double p = 1.0 - ProbUtils.chisqCdf(ts, df); + return (p > alpha); + } + + /** + * Checks independence from pooled samples by randomly selecting a p value + */ + public static boolean isIndependentPooledRandom(List independenceTests, Node x, Node y, List condSet) { + double alpha = independenceTests.get(0).getAlpha(); + int r = RandomUtil.getInstance().nextInt(independenceTests.size()); + IndependenceTest independenceTest = independenceTests.get(r); + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(independenceTest.getVariable(node.getName())); + } + IndependenceResult result = independenceTest.checkIndependence(independenceTest.getVariable(x.getName()), independenceTest.getVariable(y.getName()), localCondSet); + double p = result.getPValue(); + return (p > alpha); + } + + /** + * Generates NodePairs of all possible pairs of nodes from given list of nodes. + */ + public static List allNodePairs(List nodes) { + List nodePairs = new ArrayList<>(); + for (int j = 0; j < nodes.size() - 1; j++) { + for (int k = j + 1; k < nodes.size(); k++) { + nodePairs.add(new NodePair(nodes.get(j), nodes.get(k))); + } + } + return nodePairs; + } + + /** + * Judges x to be independent of y conditional on condSet if the false discovery rate of the p values for the + * separate judgements for their collective alpha level identifies no more than # p values / 2 values below + * threshold. + */ + private static boolean isIndependentMajorityFdr(List independenceTests, Node x, Node y, List condSet) { + List allPValues = ResolveSepsetsDci.getAvailablePValues(independenceTests, x, y, condSet); + + Collections.sort(allPValues); + int c = 0; + while (c < allPValues.size() && + allPValues.get(c) < independenceTests.get(0).getAlpha() * (c + 1.) / allPValues.size()) { + c++; + } + + + // At least half of the judgments are for independence. + boolean independent = c < allPValues.size() / 2; +// boolean independent = c < allPValues.size() - 2; + + if (independent) { + TetradLogger.getInstance().log("independence", "***FDR judges " + SearchLogUtils.independenceFact(x, y, condSet) + " independent"); + } else { + TetradLogger.getInstance().log("independence", "###FDR judges " + SearchLogUtils.independenceFact(x, y, condSet) + " dependent"); + } + TetradLogger.getInstance().log("independence", "c = " + c); + + return independent; + } + + private static List getAvailablePValues(List independenceTests, Node x, Node y, List condSet) { + List allPValues = new ArrayList<>(); + + for (IndependenceTest test : independenceTests) { + if (ResolveSepsetsDci.missingVariable(x, y, condSet, test)) continue; + List localCondSet = new ArrayList<>(); + for (Node node : condSet) { + localCondSet.add(test.getVariable(node.getName())); + } + + try { + IndependenceResult result = test.checkIndependence(test.getVariable(x.getName()), test.getVariable(y.getName()), localCondSet); + allPValues.add(result.getPValue()); + } catch (Exception e) { + // Skip that test. + } + } + + return allPValues; + } + + /** + * Judges x to be independent of y conditional on condSet if the false discovery rate of the p values for the + * separate judgements for their collective alpha level identifies no more than # p values / 2 values below + * threshold. + */ + private static boolean isIndependentMajorityIndep(List independenceTests, Node x, Node y, List condSet) { + List allPValues = ResolveSepsetsDci.getAvailablePValues(independenceTests, x, y, condSet); + + Collections.sort(allPValues); + int c = 0; + while (c < allPValues.size() && allPValues.get(c) < independenceTests.get(0).getAlpha()) { + c++; + } + + + // At least half of the judgments are for independence. +// boolean independent = c < 40; + boolean independent = c < allPValues.size() / 2; + + if (independent) { + TetradLogger.getInstance().log("independence", "***Majority = " + SearchLogUtils.independenceFact(x, y, condSet) + " independent"); + } else { + TetradLogger.getInstance().log("independence", "###Majority = " + SearchLogUtils.independenceFact(x, y, condSet) + " dependent"); + } + TetradLogger.getInstance().log("independence", "c = " + c); + + return independent; + } +} + + + From b5da3c64f02bedbb2c55abb3024300059458a259 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:58:49 -0400 Subject: [PATCH 292/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/Sextad.java | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java index 2e793d85d0..0e6812b03f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java @@ -5,6 +5,11 @@ import java.util.ArrayList; import java.util.List; +/** + * Represents an ordered sextad of nodes. + * + * @author josephramsey + */ public class Sextad implements TetradSerializable { static final long serialVersionUID = 23L; @@ -15,6 +20,9 @@ public class Sextad implements TetradSerializable { private final int m; private final int n; + /** + * Constructor. + */ public Sextad(int i, int j, int k, int l, int m, int n) { testDistinctness(i, j, k, l, m, n); this.i = i; @@ -32,29 +40,6 @@ public static Sextad serializableInstance() { return new Sextad(0, 1, 2, 3, 4, 5); } - - private void testDistinctness(int i, int j, int k, int l, int m, int n) { - if (i == j || i == k || i == l || i == m || i == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (j == k || j == l || j == m || j == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (k == l || k == m || k == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (l == m || l == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - - if (m == n) { - throw new IllegalArgumentException("Nodes not distinct."); - } - } - public int getI() { return this.i; } @@ -85,6 +70,11 @@ public int hashCode() { return hash; } + /** + * Returns a judgment of equality with another Sextad instance. + * @param o The other Sextad instance. + * @return True if equal. + */ public boolean equals(Object o) { if (!(o instanceof Sextad)) return false; Sextad sextad = (Sextad) o; @@ -110,6 +100,10 @@ public String toString() { return "<" + this.i + ", " + this.j + ", " + this.k + "; " + this.l + ", " + this.m + ", " + this.n + ">"; } + /** + * Returns the list of nodes. + * @return This list. + */ public List getNodes() { List nodes = new ArrayList<>(); nodes.add(this.i); @@ -120,4 +114,26 @@ public List getNodes() { nodes.add(this.n); return nodes; } + + private void testDistinctness(int i, int j, int k, int l, int m, int n) { + if (i == j || i == k || i == l || i == m || i == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (j == k || j == l || j == m || j == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (k == l || k == m || k == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (l == m || l == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + + if (m == n) { + throw new IllegalArgumentException("Nodes not distinct."); + } + } } From a683695c32be32eb66c39f8b45e312f161e5668f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 09:59:57 -0400 Subject: [PATCH 293/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/SpFci.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index cbba9a609b..1210be574f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -35,21 +35,17 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** + *

Replaces FGES in GFCI by SP using a score, which is another score-based + * (but more accurate) algorithm.

*

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

* - *

This uses PermutationSearch (see), calling the Sp algorithm (see).

- * - *

An independence test must be provided for the definite discriminating path step - * of FCI. Otherwise, the provided score is used throughout.

- * - * @author Juan Miguel Ogarrio - * @author ps7z - * @author jdramsey - * @author bryan andrews - * @see PermutationSearch - * @see Sp + * @author peterspirtes + * @author josephramsey + * @author bryanandrews + * @see GFci + * @see Grasp */ public final class SpFci implements GraphSearch { From 1841a54e3f820d1d6ee605c4eab30d62bf3b264c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 10:01:29 -0400 Subject: [PATCH 294/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/SemBicScorer.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java index 2611153bcf..cc6d2a503c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java @@ -18,6 +18,13 @@ * @see SemBicScore */ public class SemBicScorer { + + /** + * Scores the given DAG using the given data model, usimg a BIC score. + * @param dag The DAG. + * @param data a continuous dataset or a covariance matrix. + * @return The BIC score of the DAG. + */ public static double scoreDag(Graph dag, DataModel data) { if (dag == null) throw new NullPointerException("DAG not specified."); From ebdd20ee6ae5a947ebd973749033c4a059792adf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 11:10:51 -0400 Subject: [PATCH 295/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/TeyssierScorer.java | 208 +++++++----------- 1 file changed, 80 insertions(+), 128 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java index 92580c3aeb..331fe55aa8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java @@ -27,10 +27,8 @@ public class TeyssierScorer { private final List variables; private ArrayList pi; // The current permutation. private Map orderHash = new HashMap<>(); - private final IndependenceTest test; private final Score score; - private ArrayList> prefixes; private ArrayList scores; private final Map> bookmarkedOrders = new HashMap<>(); @@ -39,12 +37,18 @@ public class TeyssierScorer { private final Map bookmarkedRunningScores = new HashMap<>(); private final Map trees = new HashMap<>(); private Knowledge knowledge = new Knowledge(); - private boolean useScore; private boolean useRaskuttiUhler = false; private double runningScore = 0f; - + /** + * Constructor that takes both a test or a score. Only one of these is used, dependeint + * on how the parameters are set. + * @param test The test. + * @param score The score + * @see IndependenceTest + * @see Score + */ public TeyssierScorer(IndependenceTest test, Score score) { if (test == null && score == null) throw new IllegalArgumentException("Required: test or score"); NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT); @@ -66,7 +70,6 @@ public TeyssierScorer(IndependenceTest test, Score score) { } } - /** * @param useScore True if the score should be used; false if the test should be used. */ @@ -75,7 +78,6 @@ public void setUseScore(boolean useScore) { if (this.useScore) this.useRaskuttiUhler = false; } - /** * @param knowledge Knowledge of forbidden edges. */ @@ -130,36 +132,13 @@ public double score() { return sum(); } - private double sum() { - double score = 0; - - for (int i = 0; i < this.pi.size(); i++) { - if (this.scores.get(i) == null) { - recalculate(i); - } - double score1 = this.scores.get(i).getScore(); - score += score1; - } - - return score; - } - /** * Performs a tuck operation. */ - public boolean swaptuck(Node x, Node y) { - if (index(x) < index(y)) { - return false; - } else if (index(y) < index(x)) { + public void swaptuck(Node x, Node y) { + if (index(y) < index(x)) { moveTo(x, index(y)); - return true; } - - return false; - } - - public boolean tuck(Node k, Node j) { - return tuck(k, index(j)); } public boolean tuck(Node k, int j) { @@ -176,7 +155,6 @@ public boolean tuck(Node k, int j) { return true; } - /** * Moves v to a new index. * @@ -198,7 +176,6 @@ public void moveTo(Node v, int toIndex) { } } - /** * Swaps m and n in the permutation. * @@ -228,7 +205,6 @@ public boolean swap(Node m, Node n) { return true; } - /** * Returns true iff x->y or y->x is a covered edge. x->y is a covered edge if * parents(x) = parents(y) \ {x} @@ -246,7 +222,6 @@ public boolean coveredEdge(Node x, Node y) { return px.equals(py); } - /** * @return A copy of the current permutation. */ @@ -254,7 +229,6 @@ public List getPi() { return new ArrayList<>(this.pi); } - /** * Returns the current permutation without making a copy. Could be dangerous! * @@ -264,7 +238,6 @@ public List getOrderShallow() { return this.pi; } - /** * Return the index of v in the current permutation. * @@ -281,7 +254,6 @@ public int index(Node v) { return integer; } - /** * Returns the parents of the node at index p. * @@ -293,14 +265,18 @@ public Set getParents(int p) { return new HashSet<>(this.scores.get(p).getParents()); } - + /** + * Returns the children of a node v. + * + * @param p The index of the variable. + * @return Its parents. + */ public Set getChildren(int p) { Set adj = getAdjacentNodes(get(p)); adj.removeAll(getParents(p)); return adj; } - /** * Returns the parents of a node v. * @@ -311,12 +287,16 @@ public Set getParents(Node v) { return getParents(index(v)); } - + /** + * Returns the children of a node v. + * + * @param v The variable. + * @return Its parents. + */ public Set getChildren(Node v) { return getChildren(index(v)); } - /** * Returns the nodes adjacent to v. * @@ -335,7 +315,6 @@ public Set getAdjacentNodes(Node v) { return adj; } - /** * Returns the DAG build for the current permutation, or its CPDAG. * @@ -359,7 +338,6 @@ public Graph getGraph(boolean cpDag) { return graph; } - /** * Returns a list of adjacent node pairs in the current graph. * @@ -383,7 +361,6 @@ public List getAdjacencies() { return new ArrayList<>(pairs); } - public Set getAncestors(Node node) { Set ancestors = new HashSet<>(); collectAncestorsVisit(node, ancestors); @@ -391,23 +368,6 @@ public Set getAncestors(Node node) { return ancestors; } - - private void collectAncestorsVisit(Node node, Set ancestors) { - if (ancestors.contains(node)) { - return; - } - - ancestors.add(node); - Set parents = getParents(node); - - if (!parents.isEmpty()) { - for (Node parent : parents) { - collectAncestorsVisit(parent, ancestors); - } - } - } - - /** * Returns a list of edges for the current graph as a list of ordered pairs. * @@ -426,7 +386,6 @@ public List> getEdges() { return edges; } - /** * @return The number of edges in the current graph. */ @@ -440,7 +399,6 @@ public int getNumEdges() { return numEdges; } - /** * Returns the node at index j in pi. * @@ -451,7 +409,6 @@ public Node get(int j) { return this.pi.get(j); } - /** * Bookmarks the current pi as index key. * @@ -469,7 +426,6 @@ public void bookmark(int key) { } } - /** * Bookmarks the current pi with index Integer.MIN_VALUE. */ @@ -477,7 +433,6 @@ public void bookmark() { bookmark(Integer.MIN_VALUE); } - /** * Retrieves the bookmarked state for index 'key' and removes that bookmark. * @@ -494,7 +449,6 @@ public void goToBookmark(int key) { this.runningScore = this.bookmarkedRunningScores.get(key); } - /** * Retries the bookmark with key = Integer.MIN_VALUE and removes the bookmark. */ @@ -502,7 +456,6 @@ public void goToBookmark() { goToBookmark(Integer.MIN_VALUE); } - /** * Clears all bookmarks. */ @@ -513,7 +466,6 @@ public void clearBookmarks() { this.bookmarkedRunningScores.clear(); } - /** * @return The size of pi, the current permutation. */ @@ -521,14 +473,12 @@ public int size() { return this.pi.size(); } - public List getShuffledVariables() { List variables = getPi(); shuffle(variables); return variables; } - /** * Returns True iff a is adjacent to b in the current graph. * @@ -541,7 +491,6 @@ public boolean adjacent(Node a, Node b) { return getParents(a).contains(b) || getParents(b).contains(a); } - /** * Returns true iff [a, b, c] is a collider. * @@ -554,7 +503,6 @@ public boolean collider(Node a, Node b, Node c) { return getParents(b).contains(a) && getParents(b).contains(c); } - /** * Returns true iff [a, b, c] is a triangle. * @@ -567,7 +515,6 @@ public boolean triangle(Node a, Node b, Node c) { return adjacent(a, b) && adjacent(b, c) && adjacent(a, c); } - /** * True iff the nodes in W form a clique in the current DAG. * @@ -586,6 +533,50 @@ public boolean clique(List W) { return true; } + public Set getPrefix(int i) { + Set prefix = new HashSet<>(); + + for (int j = 0; j < i; j++) { + prefix.add(this.pi.get(j)); + } + + return prefix; + } + + public Set> getSkeleton() { + List order = getPi(); + Set> skeleton = new HashSet<>(); + + for (Node y : order) { + for (Node x : getParents(y)) { + Set adj = new HashSet<>(); + adj.add(x); + adj.add(y); + skeleton.add(adj); + } + } + + return skeleton; + } + + public boolean parent(Node k, Node j) { + return getParents(j).contains(k); + } + + private void collectAncestorsVisit(Node node, Set ancestors) { + if (ancestors.contains(node)) { + return; + } + + ancestors.add(node); + Set parents = getParents(node); + + if (!parents.isEmpty()) { + for (Node parent : parents) { + collectAncestorsVisit(parent, ancestors); + } + } + } private boolean violatesKnowledge(List order) { if (this.knowledge.isEmpty()) return false; @@ -601,49 +592,16 @@ private boolean violatesKnowledge(List order) { return false; } - private void initializeScores() { for (int i1 = 0; i1 < this.pi.size(); i1++) this.prefixes.set(i1, null); updateScores(0, this.pi.size() - 1); } - private void updateScores(int i1, int i2) { for (int i = i1; i <= i2; i++) { this.orderHash.put(this.pi.get(i), i); this.scores.set(i, null); -// recalculate(i); - } - -// for (int i = i1; i <= i2; i++) { -// this.orderHash.put(this.pi.get(i), i); -// } -// -// int chunk = getChunkSize(i2 - i1 + 1); -// List tasks = new ArrayList<>(); -// -// for (int w = 0; w < size(); w += chunk) { -// tasks.add(new MyTask(pi, this, chunk, orderHash, w, w + chunk)); -// } -// -// ForkJoinPool.commonPool().invokeAll(tasks); - } - -// private int getChunkSize(int n) { -// int chunk = n / Runtime.getRuntime().availableProcessors(); -// if (chunk < 100) chunk = 100; -// return chunk; -// } - - - public Set getPrefix(int i) { - Set prefix = new HashSet<>(); - - for (int j = 0; j < i; j++) { - prefix.add(this.pi.get(j)); } - - return prefix; } private void recalculate(int p) { @@ -658,6 +616,20 @@ private void recalculate(int p) { } } + private double sum() { + double score = 0; + + for (int i = 0; i < this.pi.size(); i++) { + if (this.scores.get(i) == null) { + recalculate(i); + } + double score1 = this.scores.get(i).getScore(); + score += score1; + } + + return score; + } + private void nodesHash(Map nodesHash, List variables) { for (int i = 0; i < variables.size(); i++) { nodesHash.put(variables.get(i), i); @@ -769,26 +741,6 @@ private Pair getRaskuttiUhlerParents(int p) { return new Pair(parents, -parents.size()); } - public Set> getSkeleton() { - List order = getPi(); - Set> skeleton = new HashSet<>(); - - for (Node y : order) { - for (Node x : getParents(y)) { - Set adj = new HashSet<>(); - adj.add(x); - adj.add(y); - skeleton.add(adj); - } - } - - return skeleton; - } - - public boolean parent(Node k, Node j) { - return getParents(j).contains(k); - } - private static class Pair { private final Set parents; private final double score; From 0e4dbf21a6c204b877717ae0eecc27229d6c8b13 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 11:16:18 -0400 Subject: [PATCH 296/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/ZsbScore.java | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java index 8beaed2a9a..96028971ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java @@ -141,52 +141,6 @@ public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - private static double getP(double pn, double m0, double lambda) { - return 2. - pow((1. + (exp(-(lambda - 1.) / 2.)) * sqrt(lambda)), pn - m0); - } - - private int[] indices(List __adj) { - int[] indices = new int[__adj.size()]; - for (int t = 0; t < __adj.size(); t++) indices[t] = variables.indexOf(__adj.get(t)); - return indices; - } - - private static double zhangShenLambda(int m0, double pn, double riskBound) { - if (m0 > pn) throw new IllegalArgumentException("m0 should not be > pn; m0 = " + m0 + " pn = " + pn); - - double high = 10000.0; - double low = 0.0; - - while (high - low > 1e-13) { - double lambda = (high + low) / 2.0; - - double p = getP(pn, m0, lambda); - - if (p < 1.0 - riskBound) { - low = lambda; - } else { - high = lambda; - } - } - - return low; - } - - private double getLambda(int m0, int pn) { - if (lambdas == null) { - lambdas = new ArrayList<>(); - } - - if (lambdas.size() - 1 < m0) { - for (int t = lambdas.size(); t <= m0; t++) { - double lambda = zhangShenLambda(t, pn, riskBound); - lambdas.add(lambda); - } - } - - return lambdas.get(m0); - } - public ICovarianceMatrix getCovariances() { return covariances; } @@ -266,6 +220,52 @@ public void setChanged(boolean b) { public void setRiskBound(double riskBound) { this.riskBound = riskBound; } + + private static double zhangShenLambda(int m0, double pn, double riskBound) { + if (m0 > pn) throw new IllegalArgumentException("m0 should not be > pn; m0 = " + m0 + " pn = " + pn); + + double high = 10000.0; + double low = 0.0; + + while (high - low > 1e-13) { + double lambda = (high + low) / 2.0; + + double p = getP(pn, m0, lambda); + + if (p < 1.0 - riskBound) { + low = lambda; + } else { + high = lambda; + } + } + + return low; + } + + private double getLambda(int m0, int pn) { + if (lambdas == null) { + lambdas = new ArrayList<>(); + } + + if (lambdas.size() - 1 < m0) { + for (int t = lambdas.size(); t <= m0; t++) { + double lambda = zhangShenLambda(t, pn, riskBound); + lambdas.add(lambda); + } + } + + return lambdas.get(m0); + } + + private static double getP(double pn, double m0, double lambda) { + return 2. - pow((1. + (exp(-(lambda - 1.) / 2.)) * sqrt(lambda)), pn - m0); + } + + private int[] indices(List __adj) { + int[] indices = new int[__adj.size()]; + for (int t = 0; t < __adj.size(); t++) indices[t] = variables.indexOf(__adj.get(t)); + return indices; + } } From 6584ba3646dbeab6e06f21d833fd4779d09ca692 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 11:49:22 -0400 Subject: [PATCH 297/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/PermutationBes.java | 45 +++++++++------- .../java/edu/cmu/tetrad/search/ZsbScore.java | 51 ++++++++++++------- 2 files changed, 61 insertions(+), 35 deletions(-) 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 index 5cbfc9b610..4c94219d74 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java @@ -17,7 +17,8 @@ /** - * Implements the backward equivalence search of FGES. + *

Implements the backward equivalence search of FGES, taking permutations + * as input and returning updated permutations as output.

* * @author bryanandrews * @author josephramsey @@ -27,31 +28,45 @@ public class PermutationBes { private final Score score; private Knowledge knowledge = new Knowledge(); private boolean verbose = true; - private int depth = -1; + /** + * Constructor. + * + * @param score The score that BES (from FGES) will use. + */ public PermutationBes(@NotNull Score score) { this.score = score; this.variables = score.getVariables(); } + /** + * Returns the variables. + * + * @return This list. + */ @NotNull public List getVariables() { return this.variables; } + /** + * Sets whether verbose output should be printed. + * + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Sets the knowledge that BES will use. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new 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; @@ -197,13 +212,9 @@ private double scoreGraphChange(Node x, Node y, Set parents, Map revertToCPDAG(Graph graph) { MeekRules rules = new MeekRules(); - rules.setKnowledge(getKnowledge()); + rules.setKnowledge(knowledge); rules.setAggressivelyPreventCycles(true); boolean meekVerbose = false; rules.setVerbose(meekVerbose); @@ -384,10 +395,10 @@ private int getChunkSize(int n) { } private void calculateArrowsBackward(Node a, Node b, Graph - graph, Map arrowsMapBackward, Map hashIndices, - int[] arrowIndex, SortedSet sortedArrowsBack) { + graph, Map arrowsMapBackward, Map hashIndices, int[] arrowIndex, SortedSet sortedArrowsBack) { if (existsKnowledge()) { - if (!getKnowledge().noEdgeRequired(a.getName(), b.getName())) { + if (!knowledge.noEdgeRequired(a.getName(), b.getName())) { return; } } @@ -402,6 +413,7 @@ private void calculateArrowsBackward(Node a, Node b, Graph if (storedConfig != null && storedConfig.equals(config)) return; arrowsMapBackward.put(directedEdge(a, b), new ArrowConfigBackward(naYX, parents)); + int depth = -1; int _depth = min(depth, _naYX.size()); final SublistGenerator gen = new SublistGenerator(_naYX.size(), _depth);//_naYX.size()); @@ -467,7 +479,6 @@ public int hashCode() { } } - private static class Arrow implements Comparable { private final double bump; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java index 96028971ba..abba6ba321 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java @@ -34,7 +34,11 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Implements the Zhang-Shen bound score. + *

Implements the Zhang-Shen bound score. This is an adaptation of + * Theorem 1 in the following:

+ *

Zhang, Y., & Shen, X. (2010). Model selection procedure for + * high‐dimensional data. Statistical Analysis and Data Mining: The + * ASA Data Science Journal, 3(5), 350-358

* * @author Joseph Ramsey */ @@ -54,7 +58,6 @@ public class ZsbScore implements Score { // The sample size of the covariance matrix. private int sampleSize; // True if verbose output should be sent to out. - private boolean verbose = false; // A record of lambdas for each m0. private List lambdas; // The data, if it is set. @@ -171,33 +174,49 @@ private void setCovariances(ICovarianceMatrix covariances) { this.sampleSize = covariances.getSampleSize(); } + /** + * Returns the sample size. + * @return This size. + */ public int getSampleSize() { return sampleSize; } + /** + * Returns a judgement for FGES for whether a certain bump in score gives + * efidence of an effect edges. + * @param bump The bump. + * @return True if so. + * @see Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; } - public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - + /** + * Returns the variables. + * @return This list. + */ @Override public List getVariables() { return new ArrayList<>(variables); } + /** + * Returns a judgment of max degree for some algorithms. + * @return This maximum. + * @see Fges + */ @Override public int getMaxDegree() { return (int) ceil(log(sampleSize)); } + /** + * Returns true if the variable in Z determine y. + * @return True if so. + */ @Override public boolean determines(List z, Node y) { int i = variables.indexOf(y); @@ -209,14 +228,10 @@ public boolean determines(List z, Node y) { return Double.isNaN(v); } - public boolean isChanged() { - return changed; - } - - public void setChanged(boolean b) { - changed = b; - } - + /** + * Sets the risk bound for the Zhang Shen Bound score. + * @param riskBound The risk bound. + */ public void setRiskBound(double riskBound) { this.riskBound = riskBound; } From d119d5e438d1043c6530ca9e369cd155ee2c52e8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 11:53:10 -0400 Subject: [PATCH 298/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/PcMb.java | 35 +------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index cad9e78b13..395922de47 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -90,16 +90,6 @@ public final class PcMb implements MbSearch, GraphSearch { */ private Knowledge knowledge = new Knowledge(); - /** - * Set of unshielded colliders from the triple orientation step. - */ - private Set colliderTriples; - - /** - * Set of unshielded noncolliders from the triple orientation step. - */ - private Set noncolliderTriples; - /** * Set of ambiguous unshielded triples. */ @@ -170,8 +160,6 @@ public Graph search(List targets) { long start = MillisecondTimes.timeMillis(); this.numIndependenceTests = 0; this.ambiguousTriples = new HashSet<>(); - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); if (targets == null) { throw new IllegalArgumentException( @@ -358,8 +346,6 @@ public Graph search(List targets) { public Graph search() { this.numIndependenceTests = 0; this.ambiguousTriples = new HashSet<>(); - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); // Some statistics. this.maxRemainingAtDepth = new int[20]; @@ -416,20 +402,6 @@ public Set getAmbiguousTriples() { return new HashSet<>(this.ambiguousTriples); } - /** - * @return the set of triples identified as colliders by the CPC algorithm during the most recent search. - */ - public Set getColliderTriples() { - return this.colliderTriples; - } - - /** - * @return the set of triples identified as noncolliders by the CPC algorithm during the most recent search. - */ - public Set getNoncolliderTriples() { - return this.noncolliderTriples; - } - /** * @return the number of independence tests performed during the most recent search. */ @@ -516,7 +488,7 @@ public Knowledge getKnowledge() { * @param knowledge See the Knowledge class. */ public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } public Graph getGraph() { @@ -663,8 +635,6 @@ private void noteMaxAtDepth(int depth, int numAdjacents) { private void orientUnshieldedTriples(Knowledge knowledge, Graph graph, int depth, List nodes) { this.logger.log("info", "Starting Collider Orientation:"); - this.colliderTriples = new HashSet<>(); - this.noncolliderTriples = new HashSet<>(); this.ambiguousTriples = new HashSet<>(); if (nodes == null) { @@ -701,15 +671,12 @@ private void orientUnshieldedTriples(Knowledge knowledge, Graph graph, int depth graph.setEndpoint(z, y, Endpoint.ARROW); this.logger.log("tripleClassifications", "Collider oriented: " + Triple.pathString(graph, x, y, z)); } - - this.colliderTriples.add(new Triple(x, y, z)); } else if (type == TripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); this.ambiguousTriples.add(triple); graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); this.logger.log("tripleClassifications", "tripleClassifications: " + Triple.pathString(graph, x, y, z)); } else { - this.noncolliderTriples.add(new Triple(x, y, z)); this.logger.log("tripleClassifications", "tripleClassifications: " + Triple.pathString(graph, x, y, z)); } } From d4b3ca2f6c25465722e196f7988d08af97836446 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 11:54:10 -0400 Subject: [PATCH 299/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java index 244f42a7cf..825f5a3641 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java @@ -31,6 +31,8 @@ * Returns the matrix permuted by these row and column permutations. * * @author josephramsey + * @see Lingam + * @see LingD */ public class PermutationMatrixPair { private final int[] rowPerm; From 30d7ad53610b431e74aacb7c34cdb220b18e0719 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 11:56:06 -0400 Subject: [PATCH 300/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../manual/common_tasks/loading_covariance_matrices.html | 1 - .../resources/javahelp/manual/common_tasks/loading_data.html | 1 - .../javahelp/manual/common_tasks/loading_tabular_data.html | 1 - .../javahelp/manual/common_tasks/manipulating_data.html | 1 - .../common_tasks/transferring_data_from_other_programs.html | 1 - .../javahelp/manual/common_tasks/transferring_from_excel.html | 1 - .../manual/common_tasks/transferring_from_minitab.html | 1 - tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java | 2 +- .../main/java/edu/cmu/tetrad/search/PermutationSearch.java | 4 +++- 9 files changed, 4 insertions(+), 9 deletions(-) diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_covariance_matrices.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_covariance_matrices.html index 76ed7d4ea9..2c0a071a4d 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_covariance_matrices.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_covariance_matrices.html @@ -122,6 +122,5 @@


-

diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_data.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_data.html index 1ed94adcbf..d113ef0fb6 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_data.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_data.html @@ -99,6 +99,5 @@

Loading Data

-

diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_tabular_data.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_tabular_data.html index 76ed7d4ea9..2c0a071a4d 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_tabular_data.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/loading_tabular_data.html @@ -122,6 +122,5 @@


-

diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/manipulating_data.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/manipulating_data.html index 84d0310cc9..d85de8fbbb 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/manipulating_data.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/manipulating_data.html @@ -69,6 +69,5 @@

Loading Data

-

diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_data_from_other_programs.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_data_from_other_programs.html index 84d0310cc9..d85de8fbbb 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_data_from_other_programs.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_data_from_other_programs.html @@ -69,6 +69,5 @@

Loading Data

-

diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_excel.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_excel.html index 84d0310cc9..d85de8fbbb 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_excel.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_excel.html @@ -69,6 +69,5 @@

Loading Data

-

diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_minitab.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_minitab.html index 84d0310cc9..d85de8fbbb 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_minitab.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/common_tasks/transferring_from_minitab.html @@ -69,6 +69,5 @@

Loading Data

-

diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 94ae23f527..eab0b1b0ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -40,7 +40,7 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

These are methods for linear, non-Gaussian Orientation with a Fixed graph + *

These are methods for linear, non-Gaussian Orientation with a Fixed graph * Structure (LOFS). The options for different types of scores are given in the enum * Lofs.Score. The options for rules to use to do the orientations are given in the * enum, Lofs.Rule. Most of these are taken from the literature and ca be googled.

diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index 12ab7684c1..d870e367ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -8,7 +8,7 @@ import java.util.*; /** - *

Implements common elements of a permutation search. The specific parts + *

Implements common elements of a permutation search. The specific parts * for each permutation search are implemented as a SuborderSearch.

*

This class specificaly handls an optimization for tiered knowledge, whereby * tiers in the knowledge can be searched one at a time in order form lowest @@ -19,6 +19,8 @@ * * @author bryanandrews * @see SuborderSearch + * @see Boss + * @see Sp */ public class PermutationSearch { private final SuborderSearch suborderSearch; From ea431d49dc91e0a8976b1281a59f27581621971f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 12:01:13 -0400 Subject: [PATCH 301/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/PoissonPriorScore.java | 23 ++++--- .../search/PossibleDConnectingPath.java | 8 --- .../cmu/tetrad/search/PossibleDsepFci.java | 66 ++++++++----------- .../search/PossibleGraphicalChangeFinder.java | 58 ---------------- 4 files changed, 40 insertions(+), 115 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleGraphicalChangeFinder.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java index 76f4bc20d2..eda00eb07d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java @@ -105,18 +105,11 @@ public PoissonPriorScore(DataSet dataSet, boolean precomputeCovariances) { } - private int[] indices(List __adj) { - int[] indices = new int[__adj.size()]; - for (int t = 0; t < __adj.size(); t++) indices[t] = this.variables.indexOf(__adj.get(t)); - return indices; - } - @Override public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - /** * @param i The index of the node. * @param parents The indices of the node's parents. @@ -188,6 +181,11 @@ public DataModel getData() { return this.dataSet; } + public void setLambda(double lambda) { + if (lambda < 1.0) throw new IllegalArgumentException("Structure prior can't be < 1: " + lambda); + this.lambda = lambda; + } + private void setCovariances(ICovarianceMatrix covariances) { CorrelationMatrixOnTheFly correlations = new CorrelationMatrixOnTheFly(covariances); this.covariances = covariances; @@ -215,14 +213,15 @@ private void setCovariances(ICovarianceMatrix covariances) { this.N = covariances.getSampleSize(); } - public void setLambda(double lambda) { - if (lambda < 1.0) throw new IllegalArgumentException("Structure prior can't be < 1: " + lambda); - this.lambda = lambda; - } - private static double getP(int pn, int m0, double lambda) { return 2 - pow(1 + (exp(-(lambda - 1) / 2.)) * sqrt(lambda), (double) pn - m0); } + + private int[] indices(List __adj) { + int[] indices = new int[__adj.size()]; + for (int t = 0; t < __adj.size(); t++) indices[t] = this.variables.indexOf(__adj.get(t)); + return indices; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDConnectingPath.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDConnectingPath.java index c5cb9d6e5d..7d3a351308 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDConnectingPath.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDConnectingPath.java @@ -34,25 +34,21 @@ */ public class PossibleDConnectingPath { - /** * The pag we are searching in. */ private final Graph pag; - /** * The conditions. */ private final Set conditions; - /** * The path. */ private final List path; - private PossibleDConnectingPath(Graph p, Set conditions, List path) { if (p == null || conditions == null || path == null) { throw new NullPointerException(); @@ -62,10 +58,8 @@ private PossibleDConnectingPath(Graph p, Set conditions, List path) this.pag = p; } - //========================= Public methods ======================// - public Graph getPag() { return this.pag; } @@ -270,7 +264,6 @@ private static void findPathsOfLength(Graph pag, Set> paths, Node pre } - private static boolean isOpen(Graph pag, Node x, Node y, Node z) { Edge edge = pag.getEdge(x, y); if (edge.getEndpoint1() != Endpoint.CIRCLE || edge.getEndpoint2() != Endpoint.CIRCLE) { @@ -279,7 +272,6 @@ private static boolean isOpen(Graph pag, Node x, Node y, Node z) { edge = pag.getEdge(y, z); return edge.getEndpoint1() == Endpoint.CIRCLE && edge.getEndpoint2() == Endpoint.CIRCLE; } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java index 84ca63793f..efdb1e0822 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java @@ -45,16 +45,10 @@ * @author David Danks */ public class PossibleDsepFci { - private final Graph graph; private final IndependenceTest test; - private final SepsetMap sepset; private int depth = -1; - - /** - * The background knowledge. - */ private Knowledge knowledge = new Knowledge(); private int maxReachablePathLength = -1; @@ -81,9 +75,6 @@ public PossibleDsepFci(Graph graph, IndependenceTest test) { setMaxPathLength(this.maxReachablePathLength); } - //============================== Public Methods =========================// - - /** * Performs pairwise comparisons of each variable in the graph with the variables that have not already been * checked. We get the Possible-D-Sep sets for the pair of variables, and we check to see if they are independent @@ -126,6 +117,35 @@ public List getSepset(IndependenceTest test, Node node1, Node node2) { return condSet; } + public int getDepth() { + return this.depth; + } + + public void setDepth(int depth) { + if (depth < -1) { + throw new IllegalArgumentException( + "Depth must be -1 (unlimited) or >= 0: " + depth); + } + + this.depth = depth; + } + + public Knowledge getKnowledge() { + return this.knowledge; + } + + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge((Knowledge) knowledge); + } + + public void setMaxPathLength(int maxReachablePathLength) { + if (maxReachablePathLength < -1) { + throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxReachablePathLength); + } + + this.maxReachablePathLength = maxReachablePathLength == -1 ? Integer.MAX_VALUE : maxReachablePathLength; + } + private List getCondSet(IndependenceTest test, Node node1, Node node2, int maxPathLength) { List possibleDsepSet = getPossibleDsep(node1, node2, maxPathLength); List possibleDsep = new ArrayList<>(possibleDsepSet); @@ -196,34 +216,6 @@ private List getPossibleDsep(Node node1, Node node2, int maxPathLength) { return dsep; } - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + depth); - } - - this.depth = depth; - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - public void setMaxPathLength(int maxReachablePathLength) { - if (maxReachablePathLength < -1) { - throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxReachablePathLength); - } - - this.maxReachablePathLength = maxReachablePathLength == -1 ? Integer.MAX_VALUE : maxReachablePathLength; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleGraphicalChangeFinder.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleGraphicalChangeFinder.java deleted file mode 100644 index 0431afa942..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleGraphicalChangeFinder.java +++ /dev/null @@ -1,58 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * Finds the minimal graphical changes that block a collection of d-connecting undirectedPaths. - * - * @author Tyler Gibson - */ -class PossibleGraphicalChangeFinder { - - - /** - * Constructs the finder given the undirectedPaths that must be blocked. - */ - public PossibleGraphicalChangeFinder(Graph pag, Collection> separations) { - if (pag == null) { - throw new NullPointerException("The given pag must not be null."); - } - if (separations == null) { - throw new NullPointerException("The given separation sets must not be null."); - } - - List> separations1 = new ArrayList<>(); - for (Collection sep : separations) { - separations1.add(new ArrayList<>(sep)); - } - } -} - - - From 4c4453846acc9582b2f48582390ddf984b3d45f4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 12:02:46 -0400 Subject: [PATCH 302/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java index a0e7103e4b..08389c72a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java @@ -25,7 +25,6 @@ import java.util.List; - /** * An interface for Markov blanket searches. * @@ -33,19 +32,16 @@ */ public interface MbSearch { - /** * Given the target this returns all the nodes in the Markov Blanket. */ List findMb(Node target); - /** * The name of the algorithm. */ String getAlgorithmName(); - /** * Number of independent tests. */ From 65d67b43b7c66b82990c94ae4386ee76b92a2e84 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 12:29:25 -0400 Subject: [PATCH 303/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/MbUtils.java | 18 +- .../edu/cmu/tetrad/search/MnlrLikelihood.java | 66 +++---- .../edu/cmu/tetrad/search/MvpLikelihood.java | 176 +++++++++--------- 3 files changed, 131 insertions(+), 129 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java index 665aea02b6..5d0f4f0ea5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java @@ -232,6 +232,15 @@ public static List generateMbDags(Graph mbCPDAG, orientBidirectedEdges, test, depth, target)); } + /** + * Returns an example DAG from the given MB CPDAG. + * @param mbCpdag The MB CPDAG. + * @return An example DAG in this CPDAG. + */ + public static Graph getOneMbDag(Graph mbCpdag) { + return SearchGraphUtils.dagFromCPDAG(mbCpdag); + } + /** * The recursive method used to list the MB DAGS consistent with an MB CPDAG (i.e. with the independence * information available to the search). @@ -276,15 +285,6 @@ private static Set listMbDags(Graph mbCPDAG, return dags; } - /** - * Returns an example DAG from the given MB CPDAG. - * @param mbCpdag The MB CPDAG. - * @return An example DAG in this CPDAG. - */ - public static Graph getOneMbDag(Graph mbCpdag) { - return SearchGraphUtils.dagFromCPDAG(mbCpdag); - } - /** * A reiteration of orientation steps 5-7 of the search for use in generating the list of MB DAGs. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java index 487e090c50..7c29662c21 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java @@ -116,39 +116,6 @@ public MnlrLikelihood(DataSet dataSet, double structurePrior, int fDegree) { } - private double multipleRegression(Vector Y, Matrix X) { - - int n = X.rows(); - Vector r; - - try { - Matrix Xt = X.transpose(); - Matrix XtX = Xt.times(X); - r = X.times(XtX.inverse().times(Xt.times(Y))).minus(Y); - } catch (Exception e) { - Vector ones = new Vector(n); - for (int i = 0; i < n; i++) ones.set(i, 1); - r = ones.scalarMult(ones.dotProduct(Y) / (double) n).minus(Y); - } - - double sigma2 = r.dotProduct(r) / n; - - if (sigma2 <= 0) { - Vector ones = new Vector(n); - for (int i = 0; i < n; i++) ones.set(i, 1); - r = ones.scalarMult(ones.dotProduct(Y) / (double) FastMath.max(n, 2)).minus(Y); - sigma2 = r.dotProduct(r) / n; - } - - double lik = -(n / 2.) * (FastMath.log(2 * FastMath.PI) + FastMath.log(sigma2) + 1); - - if (Double.isInfinite(lik) || Double.isNaN(lik)) { - System.out.println(lik); - } - - return lik; - } - public double getLik(int child_index, int[] parents) { double lik = 0; @@ -289,6 +256,39 @@ public double getEBICprior() { } + private double multipleRegression(Vector Y, Matrix X) { + + int n = X.rows(); + Vector r; + + try { + Matrix Xt = X.transpose(); + Matrix XtX = Xt.times(X); + r = X.times(XtX.inverse().times(Xt.times(Y))).minus(Y); + } catch (Exception e) { + Vector ones = new Vector(n); + for (int i = 0; i < n; i++) ones.set(i, 1); + r = ones.scalarMult(ones.dotProduct(Y) / (double) n).minus(Y); + } + + double sigma2 = r.dotProduct(r) / n; + + if (sigma2 <= 0) { + Vector ones = new Vector(n); + for (int i = 0; i < n; i++) ones.set(i, 1); + r = ones.scalarMult(ones.dotProduct(Y) / (double) FastMath.max(n, 2)).minus(Y); + sigma2 = r.dotProduct(r) / n; + } + + double lik = -(n / 2.) * (FastMath.log(2 * FastMath.PI) + FastMath.log(sigma2) + 1); + + if (Double.isInfinite(lik) || Double.isNaN(lik)) { + System.out.println(lik); + } + + return lik; + } + private double MultinomialLogisticRegression(Matrix targets, Matrix subset) { Problem problem = new Problem(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java index ee6e98bd58..152cb05e78 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java @@ -127,6 +127,95 @@ public MvpLikelihood(DataSet dataSet, double structurePrior, int fDegree, boolea } + public double getLik(int child_index, int[] parents) { + + double lik = 0; + Node c = this.variables.get(child_index); + List continuous_parents = new ArrayList<>(); + List discrete_parents = new ArrayList<>(); + + if (c instanceof DiscreteVariable && this.discretize) { + for (int p : parents) { + Node parent = this.discreteVariables.get(p); + discrete_parents.add((DiscreteVariable) parent); + } + } else { + for (int p : parents) { + Node parent = this.variables.get(p); + if (parent instanceof ContinuousVariable) { + continuous_parents.add((ContinuousVariable) parent); + } else { + discrete_parents.add((DiscreteVariable) parent); + } + } + } + + int p = continuous_parents.size(); + + List> cells = this.adTree.getCellLeaves(discrete_parents); + + int[] continuousCols = new int[p]; + for (int j = 0; j < p; j++) continuousCols[j] = this.nodesHash.get(continuous_parents.get(j)); + + for (List cell : cells) { +// for (int[] cell : cells) { + int r = cell.size(); +// int r = cell.length; + if (r > 1) { + + double[] mean = new double[p]; + double[] var = new double[p]; + for (int i = 0; i < p; i++) { + for (Integer integer : cell) { + mean[i] += this.continuousData[continuousCols[i]][integer]; + var[i] += FastMath.pow(this.continuousData[continuousCols[i]][integer], 2); + } + mean[i] /= r; + var[i] /= r; + var[i] -= FastMath.pow(mean[i], 2); + var[i] = FastMath.sqrt(var[i]); + + if (Double.isNaN(var[i])) { + System.out.println(var[i]); + } + } + + int degree = this.fDegree; + if (this.fDegree < 1) { + degree = (int) FastMath.floor(FastMath.log(r)); + } + Matrix subset = new Matrix(r, p * degree + 1); + for (int i = 0; i < r; i++) { + subset.set(i, p * degree, 1); + for (int j = 0; j < p; j++) { + for (int d = 0; d < degree; d++) { + subset.set(i, p * d + j, FastMath.pow((this.continuousData[continuousCols[j]][cell.get(i)] - mean[j]) / var[j], d + 1)); + } + } + } + + if (c instanceof ContinuousVariable) { + Vector target = new Vector(r); + for (int i = 0; i < r; i++) { + target.set(i, this.continuousData[child_index][cell.get(i)]); +// target.set(i, continuousData[child_index][cell[i]]); + } + lik += multipleRegression(target, subset); + } else { + assert c instanceof DiscreteVariable; + Matrix target = new Matrix(r, ((DiscreteVariable) c).getNumCategories()); + for (int i = 0; i < r; i++) { + target.set(i, this.discreteData[child_index][cell.get(i)], 1); + } + lik += approxMultinomialRegression(target, subset); + } + } + } + + return lik; + } + + private double multipleRegression(Vector Y, Matrix X) { int n = X.rows(); @@ -221,93 +310,6 @@ private double approxMultinomialRegression(Matrix Y, Matrix X) { } - public double getLik(int child_index, int[] parents) { - - double lik = 0; - Node c = this.variables.get(child_index); - List continuous_parents = new ArrayList<>(); - List discrete_parents = new ArrayList<>(); - - if (c instanceof DiscreteVariable && this.discretize) { - for (int p : parents) { - Node parent = this.discreteVariables.get(p); - discrete_parents.add((DiscreteVariable) parent); - } - } else { - for (int p : parents) { - Node parent = this.variables.get(p); - if (parent instanceof ContinuousVariable) { - continuous_parents.add((ContinuousVariable) parent); - } else { - discrete_parents.add((DiscreteVariable) parent); - } - } - } - - int p = continuous_parents.size(); - - List> cells = this.adTree.getCellLeaves(discrete_parents); - - int[] continuousCols = new int[p]; - for (int j = 0; j < p; j++) continuousCols[j] = this.nodesHash.get(continuous_parents.get(j)); - - for (List cell : cells) { -// for (int[] cell : cells) { - int r = cell.size(); -// int r = cell.length; - if (r > 1) { - - double[] mean = new double[p]; - double[] var = new double[p]; - for (int i = 0; i < p; i++) { - for (Integer integer : cell) { - mean[i] += this.continuousData[continuousCols[i]][integer]; - var[i] += FastMath.pow(this.continuousData[continuousCols[i]][integer], 2); - } - mean[i] /= r; - var[i] /= r; - var[i] -= FastMath.pow(mean[i], 2); - var[i] = FastMath.sqrt(var[i]); - - if (Double.isNaN(var[i])) { - System.out.println(var[i]); - } - } - - int degree = this.fDegree; - if (this.fDegree < 1) { - degree = (int) FastMath.floor(FastMath.log(r)); - } - Matrix subset = new Matrix(r, p * degree + 1); - for (int i = 0; i < r; i++) { - subset.set(i, p * degree, 1); - for (int j = 0; j < p; j++) { - for (int d = 0; d < degree; d++) { - subset.set(i, p * d + j, FastMath.pow((this.continuousData[continuousCols[j]][cell.get(i)] - mean[j]) / var[j], d + 1)); - } - } - } - - if (c instanceof ContinuousVariable) { - Vector target = new Vector(r); - for (int i = 0; i < r; i++) { - target.set(i, this.continuousData[child_index][cell.get(i)]); -// target.set(i, continuousData[child_index][cell[i]]); - } - lik += multipleRegression(target, subset); - } else { - assert c instanceof DiscreteVariable; - Matrix target = new Matrix(r, ((DiscreteVariable) c).getNumCategories()); - for (int i = 0; i < r; i++) { - target.set(i, this.discreteData[child_index][cell.get(i)], 1); - } - lik += approxMultinomialRegression(target, subset); - } - } - } - - return lik; - } public double getDoF(int child_index, int[] parents) { From 91692369df9e2c49c37ba73c627ef714478dd495 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 12:46:17 -0400 Subject: [PATCH 304/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/TsFges.java | 305 +++++------------- 1 file changed, 79 insertions(+), 226 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 0471cc3b17..b237a90929 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -26,10 +26,9 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; +import org.jetbrains.annotations.NotNull; import java.io.PrintStream; -import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.*; import java.util.concurrent.*; @@ -54,7 +53,6 @@ */ public final class TsFges implements GraphSearch, DagScorer { - /** * Internal. */ @@ -83,21 +81,11 @@ private enum Mode { */ private Graph externalGraph; - /** - * If non-null, edges not adjacent in this graph will not be added. - */ - private Graph boundGraph; - /** * Elapsed time of the most recent search. */ private long elapsedTime; - /** - * A bound on cycle length. - */ - private int cycleBound = -1; - /** * The totalScore for discrete searches. */ @@ -136,7 +124,7 @@ private enum Mode { private ConcurrentMap hashIndices; // The static ForkJoinPool instance. - private ForkJoinPool pool = ForkJoinPoolInstance.getInstance().getPool(); + private final ForkJoinPool pool = ForkJoinPoolInstance.getInstance().getPool(); // A running tally of the total BIC totalScore. private double totalScore; @@ -147,19 +135,16 @@ private enum Mode { // Where printed output is sent. private PrintStream out = System.out; - // A initial adjacencies graph. + // An initial adjacencies graph. private Graph adjacencies; // The graph being constructed. private Graph graph; // Arrows with the same totalScore are stored in this list to distinguish their order in sortedArrows. - // The ordering doesn't matter; it just have to be transitive. + // The ordering doesn't matter; it just has to be transitive. int arrowIndex; - // The final totalScore after search. - private double modelScore; - // Internal. private Mode mode = Mode.heuristicSpeedup; @@ -173,6 +158,9 @@ private enum Mode { final int maxThreads = ForkJoinPoolInstance.getInstance().getPool().getParallelism(); + private final int[] count = new int[1]; + + //===========================CONSTRUCTORS=============================// /** @@ -189,20 +177,6 @@ public TsFges(Score score) { //==========================PUBLIC METHODS==========================// - /** - * Set to true if it is assumed that all path pairs with one length 1 path do not cancel. - */ - public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { - this.faithfulnessAssumed = faithfulnessAssumed; - } - - /** - * @return true if it is assumed that all path pairs with one length 1 path do not cancel. - */ - public boolean isFaithfulnessAssumed() { - return this.faithfulnessAssumed; - } - /** * Greedy equivalence search: Start from the empty graph, add edges till model is significant. Then start deleting * edges till a minimum is achieved. @@ -261,15 +235,21 @@ public Graph search() { this.logger.log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); this.logger.flush(); - this.modelScore = this.totalScore; + // The final totalScore after search. return this.graph; } /** - * @return the background knowledge. + * Set to true if it is assumed that all path pairs with one length 1 path do not cancel. */ + public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { + this.faithfulnessAssumed = faithfulnessAssumed; + } + /** + * @return the background knowledge. + */ public Knowledge getKnowledge() { return this.knowledge; } @@ -280,15 +260,20 @@ public Knowledge getKnowledge() { * @param knowledge the knowledge object, specifying forbidden and required edges. */ public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } + /** + * Returns the elapsed time o the search. + * + * @return This time. + */ public long getElapsedTime() { return this.elapsedTime; } /** - * If the true graph is set, askterisks will be printed in log output for the true edges. + * If the true graph is set, asterisks will be printed in log output for the true edges. */ public void setTrueGraph(Graph trueGraph) { this.trueGraph = trueGraph; @@ -301,13 +286,6 @@ public double getScore(Graph dag) { return scoreDag(dag); } - /** - * @return the list of top scoring graphs. - */ - public LinkedList getTopGraphs() { - return this.topGraphs; - } - /** * @return the number of patterns to store. */ @@ -377,7 +355,7 @@ public PrintStream getOut() { } /** - * @return the set of preset adjacenies for the algorithm; edges not in this adjacencies graph + * @return the set of preset adjacencies for the algorithm; edges not in this adjacencies graph * will not be added. */ public Graph getAdjacencies() { @@ -385,45 +363,13 @@ public Graph getAdjacencies() { } /** - * Sets the set of preset adjacenies for the algorithm; edges not in this adjacencies graph + * Sets the set of preset adjacencies for the algorithm; edges not in this adjacencies graph * will not be added. */ public void setAdjacencies(Graph adjacencies) { this.adjacencies = adjacencies; } - /** - * A bound on cycle length. - */ - public int getCycleBound() { - return this.cycleBound; - } - - /** - * A bound on cycle length. - * - * @param cycleBound The bound, >= 1, or -1 for unlimited. - */ - public void setCycleBound(int cycleBound) { - if (!(cycleBound == -1 || cycleBound >= 1)) - throw new IllegalArgumentException("Cycle bound needs to be -1 or >= 1: " + cycleBound); - this.cycleBound = cycleBound; - } - - /** - * Creates a new processors pool with the specified number of threads. - */ - public void setParallelism(int numProcessors) { - this.pool = new ForkJoinPool(numProcessors); - } - - /** - * If non-null, edges not adjacent in this graph will not be added. - */ - public void setBoundGraph(Graph boundGraph) { - this.boundGraph = GraphUtils.replaceNodes(boundGraph, getVariables()); - } - /** * For BIC totalScore, a multiplier on the penalty term. For continuous searches. * @@ -485,6 +431,12 @@ public void setMaxIndegree(int maxIndegree) { this.maxIndegree = maxIndegree; } + public int getMinChunk(int n) { + // The minimum number of operations to do before parallelizing. + int minChunk = 100; + return FastMath.max(n / this.maxThreads, minChunk); + } + //===========================PRIVATE METHODS========================// //Sets the discrete scoring function to use. @@ -504,15 +456,7 @@ private void setScore(Score totalScore) { this.maxIndegree = this.score.getMaxDegree(); } - final int[] count = new int[1]; - - public int getMinChunk(int n) { - // The minimum number of operations to do before parallelizing. - int minChunk = 100; - return FastMath.max(n / this.maxThreads, minChunk); - } - - class NodeTaskEmptyGraph extends RecursiveTask { + private class NodeTaskEmptyGraph extends RecursiveTask { private final int from; private final int to; private final List nodes; @@ -548,7 +492,7 @@ protected Boolean compute() { continue; } - if (!validSetByKnowledge(y, this.emptySet)) { + if (invalidSetByKnowledge(y, this.emptySet)) { continue; } } @@ -561,8 +505,6 @@ protected Boolean compute() { int parent = TsFges.this.hashIndices.get(x); double bump = TsFges.this.score.localScoreDiff(parent, child); - if (TsFges.this.boundGraph != null && !TsFges.this.boundGraph.isAdjacentTo(x, y)) continue; - if (bump > 0) { Edge edge = Edges.undirectedEdge(x, y); TsFges.this.effectEdgesGraph.addEdge(edge); @@ -615,7 +557,10 @@ protected Boolean compute() { while (tasks.size() > TsFges.this.maxThreads) { NodeTaskEmptyGraph _task = tasks.poll(); - _task.join(); + + if (_task != null) { + _task.join(); + } } } @@ -704,7 +649,7 @@ protected Boolean compute() { continue; } - if (!validSetByKnowledge(y, emptySet)) { + if (invalidSetByKnowledge(y, emptySet)) { continue; } } @@ -799,7 +744,7 @@ protected Boolean compute() { continue; } - if (!validSetByKnowledge(y, emptySet)) { + if (invalidSetByKnowledge(y, emptySet)) { continue; } } @@ -852,7 +797,7 @@ private void fes() { continue; } - if (!getTNeighbors(x, y).containsAll(arrow.getHOrT())) { + if (!new HashSet<>(getTNeighbors(x, y)).containsAll(arrow.getHOrT())) { continue; } @@ -868,7 +813,7 @@ private void fes() { this.totalScore += bump; - Set visited = reapplyOrientation(x, y, null); + Set visited = reapplyOrientation(); Set toProcess = new HashSet<>(); for (Node node : visited) { @@ -888,7 +833,7 @@ private void fes() { toProcess.add(y); storeGraph(); - reevaluateForward(toProcess, arrow); + reevaluateForward(toProcess); } } @@ -921,9 +866,6 @@ private void bes() { Edge edge = this.graph.getEdge(x, y); if (edge.pointsTowards(x)) continue; - HashSet diff = new HashSet<>(arrow.getNaYX()); - diff.removeAll(arrow.getHOrT()); - if (!validDelete(x, y, arrow.getHOrT(), arrow.getNaYX())) continue; Set H = arrow.getHOrT(); @@ -936,7 +878,7 @@ private void bes() { clearArrow(x, y); - Set visited = reapplyOrientation(x, y, H); + Set visited = reapplyOrientation(); Set toProcess = new HashSet<>(); @@ -957,7 +899,7 @@ private void bes() { reevaluateBackward(toProcess); } - meekOrientRestricted(getVariables(), getKnowledge()); + meekOrientRestricted(getKnowledge()); } private Set getCommonAdjacents(Node x, Node y) { @@ -966,16 +908,8 @@ private Set getCommonAdjacents(Node x, Node y) { return commonChildren; } - private Set reapplyOrientation(Node x, Node y, Set newArrows) { - Set toProcess = new HashSet<>(); - toProcess.add(x); - toProcess.add(y); - - if (newArrows != null) { - toProcess.addAll(newArrows); - } - - return meekOrientRestricted(new ArrayList<>(toProcess), getKnowledge()); + private Set reapplyOrientation() { + return meekOrientRestricted(getKnowledge()); } // Returns true if knowledge is not empty. @@ -1017,8 +951,8 @@ private void initializeArrowsBackward() { } } - // Calcuates new arrows based on changes in the graph for the forward search. - private void reevaluateForward(Set nodes, Arrow arrow) { + // Calculates new arrows based on changes in the graph for the forward search. + private void reevaluateForward(Set nodes) { class AdjTask extends RecursiveTask { private final List nodes; private final int from; @@ -1274,12 +1208,12 @@ private void calculateArrowsBackward(Node a, Node b) { h.removeAll(diff); if (existsKnowledge()) { - if (!validSetByKnowledge(b, h)) { + if (invalidSetByKnowledge(b, h)) { continue; } } - double bump = deleteEval(a, b, diff, naYX, this.hashIndices); + double bump = deleteEval(a, b, diff, this.hashIndices); if (bump > 0.0) { addArrow(a, b, naYX, h, bump); @@ -1288,11 +1222,7 @@ private void calculateArrowsBackward(Node a, Node b) { } } - public double getModelScore() { - return this.modelScore; - } - - // Basic data structure for an arrow a->b considered for additiom or removal from the graph, together with + // Basic data structure for an arrow a->b considered for addition or removal from the graph, together with // associated sets needed to make this determination. For both forward and backward direction, NaYX is needed. // For the forward direction, T neighbors are needed; for the backward direction, H neighbors are needed. // See Chickering (2002). The totalScore difference resulting from added in the edge (hypothetically) is recorded @@ -1335,14 +1265,12 @@ public Set getNaYX() { } // Sorting by bump, high to low. The problem is the SortedSet contains won't add a new element if it compares - // to zero with an existing element, so for the cases where the comparison is to zero (i.e. have the same + // to zero with an existing element, so for the cases where the comparison is to zero, i.e. have the same // bump, we need to determine as quickly as possible a determinate ordering (fixed) ordering for two variables. // The fastest way to do this is using a hash code, though it's still possible for two Arrows to have the // same hash code but not be equal. If we're paranoid, in this case we calculate a determinate comparison - // not equal to zero by keeping a list. This last part is commened out by default. - public int compareTo(Arrow arrow) { - if (arrow == null) throw new NullPointerException(); - + // not equal to zero by keeping a list. This last part is commented out by default. + public int compareTo(@NotNull Arrow arrow) { int compare = Double.compare(arrow.getBump(), getBump()); if (compare == 0) { @@ -1411,7 +1339,7 @@ private double insertEval(Node x, Node y, Set t, Set naYX, } // Evaluate the Delete(X, Y, T) operator (Definition 12 from Chickering, 2002). - private double deleteEval(Node x, Node y, Set diff, Set naYX, + private double deleteEval(Node x, Node y, Set diff, Map hashIndices) { Set set = new HashSet<>(diff); set.addAll(this.graph.getParents(y)); @@ -1433,8 +1361,6 @@ private boolean insert(Node x, Node y, Set T, double bump) { trueEdge = this.trueGraph.getEdge(_x, _y); } - if (this.boundGraph != null && !this.boundGraph.isAdjacentTo(x, y)) return false; - this.graph.addDirectedEdge(x, y); // Adding similar edges to enforce repeating structure **/ addSimilarEdges(x, y); @@ -1448,9 +1374,7 @@ private boolean insert(Node x, Node y, Set T, double bump) { int numEdges = this.graph.getNumEdges(); -// if (verbose) { if (numEdges % 1000 == 0) this.out.println("Num edges added: " + numEdges); -// } if (this.verbose) { String label = this.trueGraph != null && trueEdge != null ? "*" : ""; @@ -1468,8 +1392,6 @@ private boolean insert(Node x, Node y, Set T, double bump) { this.graph.removeEdge(_t, y); // removing similar edges to enforce repeating structure **/ removeSimilarEdges(_t, y); - // **/ - if (this.boundGraph != null && !this.boundGraph.isAdjacentTo(_t, y)) continue; this.graph.addDirectedEdge(_t, y); // Adding similar edges to enforce repeating structure **/ @@ -1507,12 +1429,9 @@ private boolean delete(Node x, Node y, Set H, double bump, Set naYX) this.removedEdges.add(Edges.undirectedEdge(x, y)); // removing similar edges to enforce repeating structure **/ removeSimilarEdges(x, y); - // **/ -// if (verbose) { int numEdges = this.graph.getNumEdges(); if (numEdges % 1000 == 0) this.out.println("Num edges (backwards) = " + numEdges); -// } if (this.verbose) { String label = this.trueGraph != null && trueEdge != null ? "*" : ""; @@ -1584,7 +1503,8 @@ private boolean validInsert(Node x, Node y, Set T, Set naYX) { Set union = new HashSet<>(T); union.addAll(naYX); boolean clique = GraphUtils.isClique(union, this.graph); - boolean noCycle = !existsUnblockedSemiDirectedPath(y, x, union, this.cycleBound); + int cycleBound = -1; + boolean noCycle = !existsUnblockedSemiDirectedPath(y, x, union, cycleBound); return clique && noCycle && !violatesKnowledge; } @@ -1639,7 +1559,6 @@ private void addRequiredEdges(Graph graph) { if (this.knowledge.isForbidden(A, B)) { Node nodeA = edge.getNode1(); Node nodeB = edge.getNode2(); - if (nodeA == null || nodeB == null) throw new NullPointerException(); if (graph.isAdjacentTo(nodeA, nodeB) && !graph.isChildOf(nodeA, nodeB)) { if (!graph.paths().isAncestorOf(nodeA, nodeB)) { @@ -1659,7 +1578,6 @@ private void addRequiredEdges(Graph graph) { } else if (this.knowledge.isForbidden(B, A)) { Node nodeA = edge.getNode2(); Node nodeB = edge.getNode1(); - if (nodeA == null || nodeB == null) throw new NullPointerException(); if (graph.isAdjacentTo(nodeA, nodeB) && !graph.isChildOf(nodeA, nodeB)) { if (!graph.paths().isAncestorOf(nodeA, nodeB)) { @@ -1682,13 +1600,13 @@ private void addRequiredEdges(Graph graph) { // Use background knowledge to decide if an insert or delete operation does not orient edges in a forbidden // direction according to prior knowledge. If some orientation is forbidden in the subset, the whole subset is // forbidden. - private boolean validSetByKnowledge(Node y, Set subset) { + private boolean invalidSetByKnowledge(Node y, Set subset) { for (Node node : subset) { if (getKnowledge().isForbidden(node.getName(), y.getName())) { - return false; + return true; } } - return true; + return false; } // Find all adj that are connected to Y by an undirected edge that are adjacent to X (that is, by undirected or @@ -1773,13 +1691,7 @@ private static Node traverseSemiDirected(Node node, Edge edge) { } // Runs Meek rules on just the changed adj. - private Set reorientNode(List nodes) { - addRequiredEdges(this.graph); - return meekOrientRestricted(nodes, getKnowledge()); - } - - // Runs Meek rules on just the changed adj. - private Set meekOrientRestricted(List nodes, Knowledge knowledge) { + private Set meekOrientRestricted(Knowledge knowledge) { MeekRules rules = new MeekRules(); rules.setKnowledge(knowledge); return rules.orientImplied(this.graph); @@ -1882,76 +1794,21 @@ private void storeGraph() { } } - public String logEdgeBayesFactorsString(Graph dag) { - Map factors = logEdgeBayesFactors(dag); - return logBayesPosteriorFactorsString(factors, scoreDag(dag)); - } - - public Map logEdgeBayesFactors(Graph dag) { - Map logBayesFactors = new HashMap<>(); - double withEdge = scoreDag(dag); - - for (Edge edge : dag.getEdges()) { - dag.removeEdge(edge); - double withoutEdge = scoreDag(dag); - double difference = withEdge - withoutEdge; - logBayesFactors.put(edge, difference); - dag.addEdge(edge); - } - - return logBayesFactors; - } - - private String logBayesPosteriorFactorsString(Map factors, double modelScore) { - NumberFormat nf = new DecimalFormat("0.00"); - StringBuilder builder = new StringBuilder(); - - List edges = new ArrayList<>(factors.keySet()); - - Collections.sort(edges, new Comparator() { - @Override - public int compare(Edge o1, Edge o2) { - return -Double.compare(factors.get(o1), factors.get(o2)); - } - }); - - builder.append("Edge Posterior Log Bayes Factors:\n\n"); - - builder.append("For a DAG in the IMaGES pattern with model totalScore m, for each edge e in the " + - "DAG, the model totalScore that would result from removing each edge, calculating " + - "the resulting model totalScore m(e), and then reporting m - m(e). The totalScore used is " + - "the IMScore, L - SUM_i{kc ln n(i)}, L is the maximum likelihood of the model, " + - "k isthe number of parameters of the model, n(i) is the sample size of the ith " + - "data set, and c is the penalty penaltyDiscount. Note that the more negative the totalScore, " + - "the more important the edge is to the posterior probability of the IMaGES model. " + - "Edges are given in order of their importance so measured.\n\n"); - - int i = 0; - - for (Edge edge : edges) { - builder.append(++i).append(". ").append(edge).append(" ").append(nf.format(factors.get(edge))).append("\n"); - } - - return builder.toString(); - } - // returnSimilarPairs based on orientSimilarPairs in SvarFciOrient.java by Entner and Hoyer private List> returnSimilarPairs(Node x, Node y) { System.out.println("$$$$$ Entering returnSimilarPairs method with x,y = " + x + ", " + y); if (x.getName().equals("time") || y.getName().equals("time")) { return new ArrayList<>(); } -// System.out.println("Knowledge within returnSimilar : " + knowledge); + int ntiers = this.knowledge.getNumTiers(); int indx_tier = this.knowledge.isInWhichTier(x); int indy_tier = this.knowledge.isInWhichTier(y); int tier_diff = FastMath.max(indx_tier, indy_tier) - FastMath.min(indx_tier, indy_tier); int indx_comp = -1; int indy_comp = -1; - List tier_x = this.knowledge.getTier(indx_tier); -// Collections.sort(tier_x); - List tier_y = this.knowledge.getTier(indy_tier); -// Collections.sort(tier_y); + List tier_x = this.knowledge.getTier(indx_tier); + List tier_y = this.knowledge.getTier(indy_tier); int i; for (i = 0; i < tier_x.size(); ++i) { @@ -1983,21 +1840,17 @@ private List> returnSimilarPairs(Node x, Node y) { Node x1; String B; Node y1; + List tmp_tier1; + List tmp_tier2; if (indx_tier >= indy_tier) { - List tmp_tier1 = this.knowledge.getTier(i + tier_diff); -// Collections.sort(tmp_tier1); - List tmp_tier2 = this.knowledge.getTier(i); -// Collections.sort(tmp_tier2); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + tmp_tier1 = this.knowledge.getTier(i + tier_diff); + tmp_tier2 = this.knowledge.getTier(i); } else { - List tmp_tier1 = this.knowledge.getTier(i); -// Collections.sort(tmp_tier1); - List tmp_tier2 = this.knowledge.getTier(i + tier_diff); -// Collections.sort(tmp_tier2); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + tmp_tier1 = this.knowledge.getTier(i); + tmp_tier2 = this.knowledge.getTier(i + tier_diff); } + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp))) continue; if (B.equals(tier_x.get(indx_comp)) && A.equals(tier_y.get(indy_comp))) continue; @@ -2026,11 +1879,11 @@ public void addSimilarEdges(Node x, Node y) { if (simList.isEmpty()) return; List x1List = simList.get(0); List y1List = simList.get(1); - Iterator itx = x1List.iterator(); - Iterator ity = y1List.iterator(); + Iterator itx = x1List.iterator(); + Iterator ity = y1List.iterator(); while (itx.hasNext() && ity.hasNext()) { - Node x1 = (Node) itx.next(); - Node y1 = (Node) ity.next(); + Node x1 = itx.next(); + Node y1 = ity.next(); System.out.println("$$$$$$$$$$$ similar pair x,y = " + x1 + ", " + y1); System.out.println("adding edge between x = " + x1 + " and y = " + y1); this.graph.addDirectedEdge(x1, y1); @@ -2042,11 +1895,11 @@ public void removeSimilarEdges(Node x, Node y) { if (simList.isEmpty()) return; List x1List = simList.get(0); List y1List = simList.get(1); - Iterator itx = x1List.iterator(); - Iterator ity = y1List.iterator(); + Iterator itx = x1List.iterator(); + Iterator ity = y1List.iterator(); while (itx.hasNext() && ity.hasNext()) { - Node x1 = (Node) itx.next(); - Node y1 = (Node) ity.next(); + Node x1 = itx.next(); + Node y1 = ity.next(); System.out.println("$$$$$$$$$$$ similar pair x,y = " + x1 + ", " + y1); System.out.println("removing edge between x = " + x1 + " and y = " + y1); Edge oldxy = this.graph.getEdge(x1, y1); From 4138aa2524fd8d0973826bcc5d2c7e85946be44c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 12:49:43 -0400 Subject: [PATCH 305/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../BuildPureClustersIndTestParamsEditor.java | 24 ++++---- ...BuildPureClustersIndTestParamsEditor2.java | 58 +++++++++---------- .../editor/BuildPureClustersParamsEditor.java | 18 +++--- .../model/BuildPureClustersRunner.java | 4 +- .../edu/cmu/tetradapp/model/PurifyRunner.java | 4 +- .../algcomparison/algorithm/cluster/Bpc.java | 6 +- .../algcomparison/algorithm/cluster/Fofc.java | 6 +- .../{TestType.java => BpcTestType.java} | 29 +++++----- .../cmu/tetrad/search/BuildPureClusters.java | 20 +++---- .../tetrad/search/ContinuousTetradTest.java | 36 ++++++------ .../main/java/edu/cmu/tetrad/search/Fofc.java | 14 ++--- .../main/java/edu/cmu/tetrad/search/Ftfc.java | 4 +- .../search/{PagUtils.java => GraphInPag.java} | 7 ++- .../java/edu/cmu/tetrad/search/Purify.java | 28 ++++----- .../cmu/tetrad/search/PurifyScoreBased.java | 4 +- .../search/WIP/BpcTetradPurifyWashdown.java | 8 +-- .../edu/cmu/tetrad/test/TestMimbuild.java | 6 +- .../java/edu/cmu/tetrad/test/TestPurify.java | 6 +- 18 files changed, 141 insertions(+), 141 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{TestType.java => BpcTestType.java} (84%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{PagUtils.java => GraphInPag.java} (97%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java index 55cc4028f3..68ff29bcfd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.search.BpcAlgorithmType; -import edu.cmu.tetrad.search.TestType; +import edu.cmu.tetrad.search.BpcTestType; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.DoubleTextField; @@ -60,17 +60,17 @@ public BuildPureClustersIndTestParamsEditor( JComboBox testSelector = new JComboBox(); if (!discreteData) { - TestType[] descriptions = TestType.getTestDescriptions(); + BpcTestType[] descriptions = BpcTestType.getTestDescriptions(); testSelector.removeAllItems(); - for (TestType description : descriptions) { + for (BpcTestType description : descriptions) { testSelector.addItem(description); } - testSelector.setSelectedItem(getParams().get("tetradTestType", TestType.TETRAD_WISHART)); + testSelector.setSelectedItem(getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART)); testSelector.addActionListener(e -> { JComboBox combo = (JComboBox) e.getSource(); - TestType index = (TestType) combo.getSelectedItem(); + BpcTestType index = (BpcTestType) combo.getSelectedItem(); getParams().set("tetradTestType", index); }); } @@ -89,21 +89,21 @@ public BuildPureClustersIndTestParamsEditor( if (type == BpcAlgorithmType.FIND_TWO_FACTOR_CLUSTERS) { testSelector.removeAllItems(); - testSelector.addItem(TestType.SAG); - testSelector.addItem(TestType.GAP); + testSelector.addItem(BpcTestType.SAG); + testSelector.addItem(BpcTestType.GAP); } else { testSelector.removeAllItems(); - testSelector.addItem(TestType.TETRAD_WISHART); - testSelector.addItem(TestType.TETRAD_DELTA); + testSelector.addItem(BpcTestType.TETRAD_WISHART); + testSelector.addItem(BpcTestType.TETRAD_DELTA); } testSelector.revalidate(); - if (paramsPureClusters.get("tetradTestType", TestType.TETRAD_WISHART) == TestType.TETRAD_WISHART) { - testSelector.setSelectedItem(TestType.TETRAD_WISHART); + if (paramsPureClusters.get("tetradTestType", BpcTestType.TETRAD_WISHART) == BpcTestType.TETRAD_WISHART) { + testSelector.setSelectedItem(BpcTestType.TETRAD_WISHART); } else { - testSelector.setSelectedItem(TestType.TETRAD_DELTA); + testSelector.setSelectedItem(BpcTestType.TETRAD_DELTA); } }); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java index 41559c6ddc..93267cc97b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.search.BpcAlgorithmType; -import edu.cmu.tetrad.search.TestType; +import edu.cmu.tetrad.search.BpcTestType; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.DoubleTextField; @@ -60,18 +60,18 @@ public BuildPureClustersIndTestParamsEditor2( JComboBox testSelector = new JComboBox(); if (!discreteData) { - TestType[] descriptions = TestType.getTestDescriptions(); + BpcTestType[] descriptions = BpcTestType.getTestDescriptions(); testSelector.removeAllItems(); - for (TestType description : descriptions) { + for (BpcTestType description : descriptions) { testSelector.addItem(description); } - TestType tetradTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART); + BpcTestType tetradTestType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); testSelector.setSelectedItem(tetradTestType); testSelector.addActionListener(e -> { JComboBox combo = (JComboBox) e.getSource(); - TestType index = (TestType) combo.getSelectedItem(); + BpcTestType index = (BpcTestType) combo.getSelectedItem(); if (index != null) { getParams().set("tetradTestType", index); } @@ -86,29 +86,29 @@ public BuildPureClustersIndTestParamsEditor2( if (getParams().get("bpcAlgorithmthmType", BpcAlgorithmType.FIND_ONE_FACTOR_CLUSTERS) == BpcAlgorithmType.FIND_TWO_FACTOR_CLUSTERS) { testSelector.removeAllItems(); - testSelector.addItem(TestType.SAG); - testSelector.addItem(TestType.GAP); - testSelector.setSelectedItem(TestType.GAP); + testSelector.addItem(BpcTestType.SAG); + testSelector.addItem(BpcTestType.GAP); + testSelector.setSelectedItem(BpcTestType.GAP); } else { - TestType type1 = (TestType) testSelector.getItemAt(0); - TestType type2 = (TestType) testSelector.getItemAt(1); + BpcTestType type1 = (BpcTestType) testSelector.getItemAt(0); + BpcTestType type2 = (BpcTestType) testSelector.getItemAt(1); - if (!(type1 == TestType.TETRAD_WISHART && type2 == TestType.TETRAD_DELTA)) { + if (!(type1 == BpcTestType.TETRAD_WISHART && type2 == BpcTestType.TETRAD_DELTA)) { testSelector.removeAllItems(); - testSelector.addItem(TestType.TETRAD_WISHART); - testSelector.addItem(TestType.TETRAD_DELTA); + testSelector.addItem(BpcTestType.TETRAD_WISHART); + testSelector.addItem(BpcTestType.TETRAD_DELTA); } } - TestType tetradTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART); + BpcTestType tetradTestType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); testSelector.setSelectedItem(tetradTestType); - if (paramsPureClusters.get("tetradTestType", TestType.TETRAD_WISHART) == TestType.TETRAD_WISHART) { - testSelector.setSelectedItem(TestType.TETRAD_WISHART); - getParams().set("tetradTestType", TestType.TETRAD_WISHART); + if (paramsPureClusters.get("tetradTestType", BpcTestType.TETRAD_WISHART) == BpcTestType.TETRAD_WISHART) { + testSelector.setSelectedItem(BpcTestType.TETRAD_WISHART); + getParams().set("tetradTestType", BpcTestType.TETRAD_WISHART); } else { - testSelector.setSelectedItem(TestType.TETRAD_DELTA); - getParams().set("tetradTestType", TestType.TETRAD_DELTA); + testSelector.setSelectedItem(BpcTestType.TETRAD_DELTA); + getParams().set("tetradTestType", BpcTestType.TETRAD_DELTA); } algorithmSelector.addActionListener(e -> { @@ -118,20 +118,20 @@ public BuildPureClustersIndTestParamsEditor2( if (type == BpcAlgorithmType.FIND_TWO_FACTOR_CLUSTERS) { testSelector.removeAllItems(); - testSelector.addItem(TestType.SAG); - testSelector.addItem(TestType.GAP); - testSelector.setSelectedItem(TestType.GAP); + testSelector.addItem(BpcTestType.SAG); + testSelector.addItem(BpcTestType.GAP); + testSelector.setSelectedItem(BpcTestType.GAP); } else { testSelector.removeAllItems(); - testSelector.addItem(TestType.TETRAD_WISHART); - testSelector.addItem(TestType.TETRAD_DELTA); + testSelector.addItem(BpcTestType.TETRAD_WISHART); + testSelector.addItem(BpcTestType.TETRAD_DELTA); - if (getParams().get("tetradTestType", TestType.TETRAD_WISHART) == TestType.TETRAD_WISHART) { - testSelector.setSelectedItem(TestType.TETRAD_WISHART); - getParams().set("tetradTestType", TestType.TETRAD_WISHART); + if (getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART) == BpcTestType.TETRAD_WISHART) { + testSelector.setSelectedItem(BpcTestType.TETRAD_WISHART); + getParams().set("tetradTestType", BpcTestType.TETRAD_WISHART); } else { - testSelector.setSelectedItem(TestType.TETRAD_DELTA); - getParams().set("tetradTestType", TestType.TETRAD_DELTA); + testSelector.setSelectedItem(BpcTestType.TETRAD_DELTA); + getParams().set("tetradTestType", BpcTestType.TETRAD_DELTA); } } }); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java index 770f79b47a..dcbd03c7ba 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.TestType; +import edu.cmu.tetrad.search.BpcTestType; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.model.DataWrapper; @@ -86,23 +86,23 @@ public void setup() { } }); - TestType[] descriptions = TestType.getTestDescriptions(); + BpcTestType[] descriptions = BpcTestType.getTestDescriptions(); JComboBox testSelector = new JComboBox(descriptions); - testSelector.setSelectedItem(getParams().get("tetradTestType", TestType.TETRAD_WISHART)); + testSelector.setSelectedItem(getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART)); testSelector.addActionListener(e -> { JComboBox combo = (JComboBox) e.getSource(); - TestType testType = (TestType) combo.getSelectedItem(); + BpcTestType testType = (BpcTestType) combo.getSelectedItem(); getParams().set("tetradTestType", testType); }); - TestType[] purifyDescriptions = TestType.getPurifyTestDescriptions(); + BpcTestType[] purifyDescriptions = BpcTestType.getPurifyTestDescriptions(); JComboBox purifySelector = new JComboBox(purifyDescriptions); - purifySelector.setSelectedItem(getParams().get("purifyTestType", TestType.NONE)); + purifySelector.setSelectedItem(getParams().get("purifyTestType", BpcTestType.NONE)); purifySelector.addActionListener(e -> { JComboBox combo = (JComboBox) e.getSource(); - TestType testType = (TestType) combo.getSelectedItem(); + BpcTestType testType = (BpcTestType) combo.getSelectedItem(); getParams().set("purifyTestType", testType); }); @@ -156,8 +156,8 @@ public void setup() { b3.add(purifySelector); b.add(b3); } else { - this.params.set("purifyTestType", TestType.DISCRETE_LRT); - this.params.set("tetradTestType", TestType.DISCRETE); + this.params.set("purifyTestType", BpcTestType.DISCRETE_LRT); + this.params.set("tetradTestType", BpcTestType.DISCRETE); } setLayout(new BorderLayout()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index e2e3379b2b..a331a9509a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -115,7 +115,7 @@ public void execute() { searchGraph = washdown.search(); } else { - TestType tetradTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART); + BpcTestType tetradTestType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); if (algorithm == BpcAlgorithmType.TETRAD_PURIFY_WASHDOWN) { BpcTetradPurifyWashdown bpc; @@ -138,7 +138,7 @@ public void execute() { BuildPureClusters bpc; DataModel source = getData(); - TestType testType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART); + BpcTestType testType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); if (source instanceof ICovarianceMatrix) { bpc = new BuildPureClusters((ICovarianceMatrix) source, diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index b2ac4129aa..2a6b248dfd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -79,13 +79,13 @@ public void execute() { ICovarianceMatrix covMatrix = (ICovarianceMatrix) source; CorrelationMatrix corrMatrix = new CorrelationMatrix(covMatrix); double alpha = getParams().getDouble("alpha", 0.001); - TestType sigTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART); + BpcTestType sigTestType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); test = new ContinuousTetradTest(covMatrix, sigTestType, alpha); // sextadTest = new DeltaSextadTest(covMatrix); } else if (source instanceof DataSet) { DataSet data = (DataSet) source; double alpha = getParams().getDouble("alpha", 0.001); - TestType sigTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART); + BpcTestType sigTestType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); test = new ContinuousTetradTest(data, sigTestType, alpha); // sextadTest = new DeltaSextadTest(data); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index bfa4086a3b..3ec375d101 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -42,12 +42,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble(Params.ALPHA); boolean wishart = parameters.getBoolean(Params.USE_WISHART, true); - TestType testType; + BpcTestType testType; if (wishart) { - testType = TestType.TETRAD_WISHART; + testType = BpcTestType.TETRAD_WISHART; } else { - testType = TestType.TETRAD_DELTA; + testType = BpcTestType.TETRAD_DELTA; } BuildPureClusters bpc = new BuildPureClusters(cov, alpha, testType); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index f9182bf278..788c7492bf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -43,12 +43,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble(Params.ALPHA); boolean wishart = parameters.getBoolean(Params.USE_WISHART, true); - TestType testType; + BpcTestType testType; if (wishart) { - testType = TestType.TETRAD_WISHART; + testType = BpcTestType.TETRAD_WISHART; } else { - testType = TestType.TETRAD_DELTA; + testType = BpcTestType.TETRAD_DELTA; } boolean gap = parameters.getBoolean(Params.USE_GAP, true); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TestType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTestType.java similarity index 84% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TestType.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTestType.java index da2f9444a4..e66a1e7f73 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TestType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTestType.java @@ -26,8 +26,7 @@ /** * An enumeration of the test types for BuildPureClusters, and Purify. */ -public enum TestType implements TetradSerializable { - /*POPULATION,*/ +public enum BpcTestType implements TetradSerializable { // This one will work and does a good job for medium sized models. GAUSSIAN_PVALUE, @@ -41,7 +40,7 @@ public enum TestType implements TetradSerializable { // Even slower. GAUSSIAN_SCORE_ITERATE, - // This option does't do any purify. + // This option doesn't do any purify. NONE, DISCRETE_LRT, DISCRETE_VARIATIONAL, @@ -57,28 +56,28 @@ public enum TestType implements TetradSerializable { static final long serialVersionUID = 23L; - public static TestType serializableInstance() { - return TestType.GAUSSIAN_PVALUE; + public static BpcTestType serializableInstance() { + return BpcTestType.GAUSSIAN_PVALUE; } - public static TestType[] getPurifyTestDescriptions() { + public static BpcTestType[] getPurifyTestDescriptions() { - return new TestType[]{ - TestType.NONE, - TestType.TETRAD_BASED, - TestType.GAUSSIAN_PVALUE, - TestType.GAUSSIAN_SCORE_MARKS, + return new BpcTestType[]{ + BpcTestType.NONE, + BpcTestType.TETRAD_BASED, + BpcTestType.GAUSSIAN_PVALUE, + BpcTestType.GAUSSIAN_SCORE_MARKS, // TestType.GAUSSIAN_SCORE, // TestType.POPULATION, }; } - public static TestType[] getTestDescriptions() { - return new TestType[]{ - TestType.TETRAD_WISHART, + public static BpcTestType[] getTestDescriptions() { + return new BpcTestType[]{ + BpcTestType.TETRAD_WISHART, // TestType.TETRAD_BOLLEN, - TestType.TETRAD_DELTA + BpcTestType.TETRAD_DELTA // TestType.GAUSSIAN_FACTOR }; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index ae8b33e814..25bdf11af4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -62,7 +62,7 @@ public final class BuildPureClusters { private ICovarianceMatrix covarianceMatrix; private int numVariables; - private TestType sigTestType; + private BpcTestType sigTestType; private int[] labels; private boolean scoreTestMode; @@ -89,7 +89,7 @@ public final class BuildPureClusters { * Constructor BuildPureClusters */ public BuildPureClusters(ICovarianceMatrix covarianceMatrix, double alpha, - TestType sigTestType) { + BpcTestType sigTestType) { if (covarianceMatrix == null) { throw new IllegalArgumentException("Covariance matrix cannot be null."); } @@ -98,7 +98,7 @@ public BuildPureClusters(ICovarianceMatrix covarianceMatrix, double alpha, initAlgorithm(alpha, sigTestType); } - public BuildPureClusters(DataSet dataSet, double alpha, TestType sigTestType) { + public BuildPureClusters(DataSet dataSet, double alpha, BpcTestType sigTestType) { if (dataSet.isContinuous()) { this.dataSet = dataSet; this.covarianceMatrix = new CovarianceMatrix(dataSet); @@ -188,7 +188,7 @@ private int numVariables() { return this.numVariables; } - private void initAlgorithm(double alpha, TestType sigTestType) { + private void initAlgorithm(double alpha, BpcTestType sigTestType) { // Check for missing values. if (getCovarianceMatrix() != null && DataUtils.containsMissingValue(getCovarianceMatrix().getMatrix())) { @@ -200,10 +200,10 @@ private void initAlgorithm(double alpha, TestType sigTestType) { this.outputMessage = true; this.sigTestType = sigTestType; - this.scoreTestMode = (this.sigTestType == TestType.DISCRETE || - this.sigTestType == TestType.GAUSSIAN_FACTOR); + this.scoreTestMode = (this.sigTestType == BpcTestType.DISCRETE || + this.sigTestType == BpcTestType.GAUSSIAN_FACTOR); - if (sigTestType == TestType.DISCRETE) { + if (sigTestType == BpcTestType.DISCRETE) { this.numVariables = this.dataSet.getNumColumns(); this.independenceTest = new IndTestGSquare(this.dataSet, alpha); this.tetradTest = new DiscreteTetradTest(this.dataSet, alpha); @@ -211,10 +211,10 @@ private void initAlgorithm(double alpha, TestType sigTestType) { assert getCovarianceMatrix() != null; this.numVariables = getCovarianceMatrix().getSize(); this.independenceTest = new IndTestFisherZ(getCovarianceMatrix(), .1); - TestType type; + BpcTestType type; - if (sigTestType == TestType.TETRAD_WISHART || sigTestType == TestType.TETRAD_DELTA - || sigTestType == TestType.GAUSSIAN_FACTOR) { + if (sigTestType == BpcTestType.TETRAD_WISHART || sigTestType == BpcTestType.TETRAD_DELTA + || sigTestType == BpcTestType.GAUSSIAN_FACTOR) { type = sigTestType; } else { throw new IllegalArgumentException("Expecting TETRAD_WISHART, TETRAD_DELTA, or GAUSSIAN FACTOR " + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java index ff3b1130ca..3eb82007c8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java @@ -60,7 +60,7 @@ public final class ContinuousTetradTest implements TetradTest { private ICovarianceMatrix covMatrix; // private CorrelationMatrix corrMatrix; private Matrix rho; - private TestType sigTestType; + private BpcTestType sigTestType; private int sampleSize; private final DataSet dataSet; private OneFactorEstimator oneFactorEst4, oneFactorEst5, oneFactorEst6; @@ -70,15 +70,15 @@ public final class ContinuousTetradTest implements TetradTest { private List variables; DeltaTetradTest deltaTest; - public ContinuousTetradTest(DataSet dataSet, TestType sigTestType, + public ContinuousTetradTest(DataSet dataSet, BpcTestType sigTestType, double sig) { - if (sigTestType == TestType.TETRAD_BOLLEN || sigTestType == null) { - sigTestType = TestType.TETRAD_DELTA; + if (sigTestType == BpcTestType.TETRAD_BOLLEN || sigTestType == null) { + sigTestType = BpcTestType.TETRAD_DELTA; } - if (!(sigTestType == TestType.TETRAD_WISHART || - sigTestType == TestType.TETRAD_DELTA || - sigTestType == TestType.GAUSSIAN_FACTOR)) { + if (!(sigTestType == BpcTestType.TETRAD_WISHART || + sigTestType == BpcTestType.TETRAD_DELTA || + sigTestType == BpcTestType.GAUSSIAN_FACTOR)) { throw new IllegalArgumentException("Unexpected type: " + sigTestType); } @@ -99,10 +99,10 @@ public ContinuousTetradTest(DataSet dataSet, TestType sigTestType, } public ContinuousTetradTest(ICovarianceMatrix covMatrix, - TestType sigTestType, double sig) { - if (!(sigTestType == TestType.TETRAD_WISHART || - sigTestType == TestType.TETRAD_DELTA || - sigTestType == TestType.GAUSSIAN_FACTOR)) { + BpcTestType sigTestType, double sig) { + if (!(sigTestType == BpcTestType.TETRAD_WISHART || + sigTestType == BpcTestType.TETRAD_DELTA || + sigTestType == BpcTestType.GAUSSIAN_FACTOR)) { throw new IllegalArgumentException("Unexpected type: " + sigTestType); } this.dataSet = null; @@ -120,10 +120,10 @@ public ContinuousTetradTest(ICovarianceMatrix covMatrix, } public ContinuousTetradTest(CorrelationMatrix correlationMatrix, - TestType sigTestType, double sig) { - if (!(sigTestType == TestType.TETRAD_WISHART || - sigTestType == TestType.TETRAD_DELTA || - sigTestType == TestType.GAUSSIAN_FACTOR)) { + BpcTestType sigTestType, double sig) { + if (!(sigTestType == BpcTestType.TETRAD_WISHART || + sigTestType == BpcTestType.TETRAD_DELTA || + sigTestType == BpcTestType.GAUSSIAN_FACTOR)) { throw new IllegalArgumentException("Unexpected type: " + sigTestType); } @@ -183,11 +183,11 @@ public List getVariables() { return this.variables; } - public TestType getTestType() { + public BpcTestType getTestType() { return this.sigTestType; } - public void setTestType(TestType sigTestType) { + public void setTestType(BpcTestType sigTestType) { this.sigTestType = sigTestType; } @@ -225,7 +225,7 @@ public boolean tetradScore1(int v1, int v2, int v3, int v4) { */ public boolean tetradScore3(int v1, int v2, int v3, int v4) { - if (this.sigTestType != TestType.GAUSSIAN_FACTOR) { + if (this.sigTestType != BpcTestType.GAUSSIAN_FACTOR) { return tetradScore(v1, v2, v3, v4) == 3; } else { return oneFactorTest(v1, v2, v3, v4); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index b71fe7e496..d48a19fc89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -56,7 +56,7 @@ public enum Algorithm {SAG, GAP} private final ContinuousTetradTest test2; // The data. private final transient DataModel dataModel; - private final TestType testType; + private final BpcTestType testType; private List> clusters; private boolean verbose; private boolean significanceChecked; @@ -70,10 +70,10 @@ public enum Algorithm {SAG, GAP} * @param testType The type of test used. * @param algorithm The type of FOFC algorithm used. * @param alpha The alpha significance cutoff. - * @see TestType + * @see BpcTestType * @see Algorithm */ - public Fofc(ICovarianceMatrix cov, TestType testType, Algorithm algorithm, double alpha) { + public Fofc(ICovarianceMatrix cov, BpcTestType testType, Algorithm algorithm, double alpha) { if (testType == null) throw new NullPointerException("Null indepTest type."); cov = new CovarianceMatrix(cov); this.variables = cov.getVariables(); @@ -96,10 +96,10 @@ public Fofc(ICovarianceMatrix cov, TestType testType, Algorithm algorithm, doubl * @param testType The type of test used. * @param algorithm The type of FOFC algorithm used. * @param alpha The alpha significance cutoff. - * @see TestType + * @see BpcTestType * @see Algorithm */ - public Fofc(DataSet dataSet, TestType testType, Algorithm algorithm, double alpha) { + public Fofc(DataSet dataSet, BpcTestType testType, Algorithm algorithm, double alpha) { if (testType == null) throw new NullPointerException("Null test type."); this.variables = dataSet.getVariables(); this.alpha = alpha; @@ -939,12 +939,12 @@ public void setVerbose(boolean verbose) { } private boolean vanishes(int x, int y, int z, int w) { - if (this.testType == TestType.TETRAD_DELTA) { + if (this.testType == BpcTestType.TETRAD_DELTA) { Tetrad t1 = new Tetrad(this.variables.get(x), this.variables.get(y), this.variables.get(z), this.variables.get(w)); Tetrad t2 = new Tetrad(this.variables.get(x), this.variables.get(y), this.variables.get(w), this.variables.get(z)); return this.test.getPValue(t1, t2) > this.alpha; - } else if (this.testType == TestType.TETRAD_WISHART) { + } else if (this.testType == BpcTestType.TETRAD_WISHART) { return this.test2.tetradPValue(x, y, z, w) > this.alpha && this.test2.tetradPValue(x, y, w, z) > this.alpha; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index f376f809a3..b29a90c12c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -76,7 +76,7 @@ public enum Algorithm {SAG, GAP} * @param cov The covariance matrix searched over. * @param algorithm The type of FOFC algorithm used. * @param alpha The alpha significance cutoff. - * @see TestType + * @see BpcTestType * @see Fofc.Algorithm */ public Ftfc(ICovarianceMatrix cov, Algorithm algorithm, double alpha) { @@ -96,7 +96,7 @@ public Ftfc(ICovarianceMatrix cov, Algorithm algorithm, double alpha) { * @param dataSet The continuous dataset searched over. * @param algorithm The type of FOFC algorithm used. * @param alpha The alpha significance cutoff. - * @see TestType + * @see BpcTestType * @see Fofc.Algorithm */ public Ftfc(DataSet dataSet, Algorithm algorithm, double alpha) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PagUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphInPag.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PagUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphInPag.java index 2fce717d73..02ed14c344 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PagUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphInPag.java @@ -29,12 +29,13 @@ import java.util.Set; /** - * This class contains methods which can be used to determine whether a directed graph is in the equivalence class - * determined by the given PAG. See p. 300 Def. 12.1.1 of CPS for a specification. + * This class contains methods which can be used to determine whether a directed graph + * is in the equivalence class determined by the given PAG. See p. 300 Def. 12.1.1 of + * CPS for a specification. * * @author Frank Wimberly */ -public final class PagUtils { +public final class GraphInPag { /** * This method implements step (1) of the definition. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java index a691ef7336..e4e6512200 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java @@ -83,7 +83,7 @@ public class Purify { /* * Constructor Purify */ - public Purify(CorrelationMatrix correlationMatrix, double sig, TestType testType, + public Purify(CorrelationMatrix correlationMatrix, double sig, BpcTestType testType, Clusters clusters) { if (DataUtils.containsMissingValue(correlationMatrix.getMatrix())) { throw new IllegalArgumentException( @@ -92,7 +92,7 @@ public Purify(CorrelationMatrix correlationMatrix, double sig, TestType testType this.correlationMatrix = correlationMatrix; initAlgorithm(sig, testType, clusters); - if (testType == TestType.TETRAD_DELTA) { + if (testType == BpcTestType.TETRAD_DELTA) { throw new RuntimeException( "Covariance/correlation matrix is not enough to " + "run Bollen's tetrad test."); @@ -101,7 +101,7 @@ public Purify(CorrelationMatrix correlationMatrix, double sig, TestType testType this.variables = correlationMatrix.getVariables(); } - public Purify(DataSet dataSet, double sig, TestType testType, + public Purify(DataSet dataSet, double sig, BpcTestType testType, Clusters clusters) { if (DataUtils.containsMissingValue(dataSet)) { throw new IllegalArgumentException( @@ -122,7 +122,7 @@ public Purify(DataSet dataSet, double sig, TestType testType, public Purify(TetradTest tetradTest, Clusters knowledge) { this.tetradTest = tetradTest; - initAlgorithm(-1., TestType.NONE, knowledge); + initAlgorithm(-1., BpcTestType.NONE, knowledge); this.variables = tetradTest.getVariables(); } @@ -131,7 +131,7 @@ public void setForbiddenList(List forbiddenList) { this.forbiddenList = forbiddenList; } - private void initAlgorithm(double sig, TestType testType, Clusters clusters) { + private void initAlgorithm(double sig, BpcTestType testType, Clusters clusters) { this.clusters = clusters; this.forbiddenList = null; if (this.tetradTest == null) { @@ -139,8 +139,8 @@ private void initAlgorithm(double sig, TestType testType, Clusters clusters) { // Should type these ones. - if (testType == TestType.TETRAD_DELTA) { - this.tetradTest = new ContinuousTetradTest(this.dataSet, TestType.TETRAD_DELTA, sig); + if (testType == BpcTestType.TETRAD_DELTA) { + this.tetradTest = new ContinuousTetradTest(this.dataSet, BpcTestType.TETRAD_DELTA, sig); } else { this.tetradTest = new ContinuousTetradTest(this.correlationMatrix, testType, sig); @@ -180,23 +180,23 @@ private Graph getResultGraph() { // return convertSearchGraph(pureClusters); // } else { - TestType type = ((ContinuousTetradTest) this.tetradTest).getTestType(); + BpcTestType type = ((ContinuousTetradTest) this.tetradTest).getTestType(); // type = TestType.TETRAD_BASED; type = null; - if (type == TestType.TETRAD_BASED) { + if (type == BpcTestType.TETRAD_BASED) { IPurify purifier = new PurifyTetradBased(this.tetradTest); List> partition2 = purifier.purify(ClusterUtils.convertIntToList(getClusters(), getVariables())); List pureClusters = ClusterUtils.convertListToInt(partition2, getVariables()); return ClusterUtils.convertSearchGraph(pureClusters, this.tetradTest.getVarNames()); } - if (type == TestType.GAUSSIAN_SCORE || type == TestType.GAUSSIAN_SCORE_MARKS) { + if (type == BpcTestType.GAUSSIAN_SCORE || type == BpcTestType.GAUSSIAN_SCORE_MARKS) { SemGraph semGraph = scoreBasedPurify(getClusters()); return Purify.convertSearchGraph(semGraph); - } else if (type == TestType.GAUSSIAN_SCORE_ITERATE) { + } else if (type == BpcTestType.GAUSSIAN_SCORE_ITERATE) { SemGraph semGraphI = scoreBasedPurifyIterate(getClusters()); return Purify.convertSearchGraph(semGraphI); - } else if (type == TestType.NONE) { + } else if (type == BpcTestType.NONE) { SemGraph semGraph3 = dummyPurification(getClusters()); return Purify.convertSearchGraph(semGraph3); } else { @@ -1343,7 +1343,7 @@ private SemGraph scoreBasedPurify(List partition) { } } if (((ContinuousTetradTest) this.tetradTest).getTestType() == - TestType.GAUSSIAN_SCORE) { + BpcTestType.GAUSSIAN_SCORE) { bestGraph = removeMarkedImpurities(bestGraph, impurities); } return bestGraph; @@ -1503,7 +1503,7 @@ private void structuralEmInitialization(List partition) { this.purePartitionGraph = new SemGraph(this.basicGraph); if (((ContinuousTetradTest) this.tetradTest).getTestType() == - TestType.NONE) { + BpcTestType.NONE) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java index 26ec1d718c..f9b8d04a20 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java @@ -306,7 +306,7 @@ private SemGraph scoreBasedPurify(List partition) { } } if (((ContinuousTetradTest) this.tetradTest).getTestType() == - TestType.GAUSSIAN_SCORE) { + BpcTestType.GAUSSIAN_SCORE) { bestGraph = removeMarkedImpurities(bestGraph, impurities); } return bestGraph; @@ -360,7 +360,7 @@ private void structuralEmInitialization(List partition) { this.purePartitionGraph.setShowErrorTerms(true); if (((ContinuousTetradTest) this.tetradTest).getTestType() == - TestType.NONE) { + BpcTestType.NONE) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java index 890f8eadb7..22ab99dbe7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java @@ -47,9 +47,9 @@ public class BpcTetradPurifyWashdown { * @param testType A Test type. * @param alpha An alpha cutoff * @see edu.cmu.tetrad.data.CovarianceMatrix - * @see TestType + * @see BpcTestType */ - public BpcTetradPurifyWashdown(ICovarianceMatrix cov, TestType testType, double alpha) { + public BpcTetradPurifyWashdown(ICovarianceMatrix cov, BpcTestType testType, double alpha) { this.variables = cov.getVariables(); this.test = new ContinuousTetradTest(cov, testType, alpha); } @@ -61,9 +61,9 @@ public BpcTetradPurifyWashdown(ICovarianceMatrix cov, TestType testType, double * @param testType A Test type. * @param alpha An alpha cutoff * @see DataSet - * @see TestType + * @see BpcTestType */ - public BpcTetradPurifyWashdown(DataSet dataSet, TestType testType, double alpha) { + public BpcTetradPurifyWashdown(DataSet dataSet, BpcTestType testType, double alpha) { this.variables = dataSet.getVariables(); this.test = new ContinuousTetradTest(dataSet, testType, alpha); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index 030de7a0e9..c1cf54c1ae 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -74,13 +74,13 @@ public void test1() { List> partition; if (algorithm.equals("FOFC")) { - Fofc fofc = new Fofc(data, TestType.TETRAD_WISHART, + Fofc fofc = new Fofc(data, BpcTestType.TETRAD_WISHART, Fofc.Algorithm.GAP, 0.001); searchGraph = fofc.search(); partition = fofc.getClusters(); } else if (algorithm.equals("BPC")) { - final TestType testType = TestType.TETRAD_WISHART; - final TestType purifyType = TestType.TETRAD_BASED; + final BpcTestType testType = BpcTestType.TETRAD_WISHART; + final BpcTestType purifyType = BpcTestType.TETRAD_BASED; BuildPureClusters bpc = new BuildPureClusters( data, 0.001, diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index f5110936d7..704248a225 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -151,7 +151,7 @@ public void test1() { partition.add(cluster2); partition.add(cluster3); - TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.05); + TetradTest test = new ContinuousTetradTest(data, BpcTestType.TETRAD_WISHART, 0.05); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); @@ -248,7 +248,7 @@ public void test1b() { partition.add(cluster1); partition.add(cluster2); - TetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.0001); + TetradTest test = new ContinuousTetradTest(data, BpcTestType.TETRAD_WISHART, 0.0001); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); @@ -286,7 +286,7 @@ public void test2() { clustering.add(adj); } - ContinuousTetradTest test = new ContinuousTetradTest(data, TestType.TETRAD_WISHART, 0.001); + ContinuousTetradTest test = new ContinuousTetradTest(data, BpcTestType.TETRAD_WISHART, 0.001); IPurify purify = new PurifyTetradBased(test); From cd935214c0ef935b83e66427a9cce769f62e9a2d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 12:56:08 -0400 Subject: [PATCH 306/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../model/GeneralAlgorithmRunner.java | 2 +- .../model/datamanip/ArResidualsWrapper.java | 4 +- .../model/datamanip/ShiftDataWrapper.java | 4 +- .../model/datamanip/TimeSeriesWrapper.java | 4 +- .../model/datamanip/TimeSeriesWrapper2.java | 4 +- .../algcomparison/algorithm/multi/Images.java | 4 +- .../algorithm/oracle/cpdag/Boss.java | 2 +- .../algorithm/oracle/cpdag/Cpc.java | 4 +- .../algorithm/oracle/cpdag/Fges.java | 4 +- .../algorithm/oracle/cpdag/Grasp.java | 4 +- .../algorithm/oracle/cpdag/Pc.java | 4 +- .../algorithm/oracle/cpdag/PcMax.java | 4 +- .../algorithm/oracle/cpdag/Sp.java | 2 +- .../algorithm/oracle/pag/Bfci.java | 5 +- .../algorithm/oracle/pag/Fci.java | 4 +- .../algorithm/oracle/pag/FciMax.java | 4 +- .../algorithm/oracle/pag/Gfci.java | 4 +- .../algorithm/oracle/pag/GraspFci.java | 4 +- .../algorithm/oracle/pag/Rfci.java | 4 +- .../algorithm/oracle/pag/SvarFci.java | 4 +- .../algorithm/oracle/pag/SvarGfci.java | 4 +- .../simulation/TimeSeriesSemSimulation.java | 10 +- .../main/java/edu/cmu/tetrad/search/Lofs.java | 2 +- .../edu/cmu/tetrad/search/ShiftSearch.java | 2 +- .../java/edu/cmu/tetrad/search/SvarGfci.java | 25 +- .../edu/cmu/tetrad/search/TsDagToPag.java | 234 +++++++++--------- .../{TimeSeriesUtils.java => TsUtils.java} | 28 +-- .../tetrad/study/performance/Comparison2.java | 6 +- 28 files changed, 188 insertions(+), 198 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{TimeSeriesUtils.java => TsUtils.java} (95%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index c88e56044a..58021f195a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -271,7 +271,7 @@ public void execute() { } if (this.algorithm instanceof HasKnowledge) { - Knowledge knowledge1 = TimeSeriesUtils.getKnowledge(getSourceGraph()); + Knowledge knowledge1 = TsUtils.getKnowledge(getSourceGraph()); if (this.knowledge.isEmpty() && !knowledge1.isEmpty()) { ((HasKnowledge) algo).setKnowledge(knowledge1); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java index 298992d291..1619bb6157 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataModelList; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.LogDataUtils; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.model.DataWrapper; @@ -55,7 +55,7 @@ public ArResidualsWrapper(DataWrapper data, Parameters params) { continue; } - DataModel model = TimeSeriesUtils.ar2((DataSet) selectedModel, params.getInt("numTimeLags", 1)); + DataModel model = TsUtils.ar2((DataSet) selectedModel, params.getInt("numTimeLags", 1)); model.setKnowledge(selectedModel.getKnowledge()); convertedList.add(model); setSourceGraph(data.getSourceGraph()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java index ab977fae8a..53f6ba79d0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataModelList; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.LogDataUtils; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -97,7 +97,7 @@ private List shiftDataSets(List dataSets, int[] shifts) { List shiftedDataSets = new ArrayList<>(); for (DataSet dataSet : dataSets) { - shiftedDataSets.add(TimeSeriesUtils.createShiftedData(dataSet, shifts)); + shiftedDataSets.add(TsUtils.createShiftedData(dataSet, shifts)); } return shiftedDataSets; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java index d355fc56ed..d9f3cd0e3c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model.datamanip; import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.model.DataWrapper; @@ -53,7 +53,7 @@ public TimeSeriesWrapper(DataWrapper data, Parameters params) { } DataSet dataSet = (DataSet) dataModel; - DataSet timeSeries = TimeSeriesUtils.createLagData(dataSet, params.getInt("numTimeLags", 1)); + DataSet timeSeries = TsUtils.createLagData(dataSet, params.getInt("numTimeLags", 1)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java index 80714766a8..b6d5f89f02 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model.datamanip; import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.model.DataWrapper; @@ -50,7 +50,7 @@ public TimeSeriesWrapper2(DataWrapper data, Parameters params) { } DataSet dataSet = (DataSet) dataModel; - DataSet timeSeries = TimeSeriesUtils.addIndex(dataSet); + DataSet timeSeries = TsUtils.addIndex(dataSet); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java index ab4a3a590e..027be0c29b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java @@ -60,7 +60,7 @@ public Graph search(List dataSets, Parameters parameters) { if (parameters.getInt(Params.TIME_LAG) > 0) { for (DataModel dataSet : dataSets) { - DataSet timeSeries = TimeSeriesUtils.createLagData((DataSet) dataSet, parameters.getInt(Params.TIME_LAG)); + DataSet timeSeries = TsUtils.createLagData((DataSet) dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } @@ -104,7 +104,7 @@ public Graph search(List dataSets, Parameters parameters) { if (parameters.getInt(Params.TIME_LAG) > 0) { for (DataSet dataSet : dataSets2) { - DataSet timeSeries = TimeSeriesUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 a9d414afec..20c843f8e3 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 @@ -55,7 +55,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 115dd6dcfa..691da02b8c 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 @@ -14,7 +14,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -54,7 +54,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 index 59963e13f5..9d429454c7 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 @@ -15,7 +15,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -60,7 +60,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 index b809b422d3..a726be4ad2 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 @@ -17,7 +17,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -60,7 +60,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 eb5a43a62d..d74b052e92 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 @@ -14,7 +14,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -56,7 +56,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 c4940d29d5..0de7df54b4 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 @@ -14,7 +14,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -56,7 +56,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 25dd67d92e..a926692650 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 @@ -56,7 +56,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 c1e1c59211..f6fa0c07f5 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 @@ -16,12 +16,11 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.BFci; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; -import java.io.PrintStream; import java.util.ArrayList; import java.util.List; @@ -70,7 +69,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 index 6f2be7e35c..95d2d17a6e 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -55,7 +55,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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/FciMax.java index 371d9b71f4..81e3808669 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/FciMax.java @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -55,7 +55,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 f7f50e8735..a53717685e 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 @@ -15,7 +15,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.GFci; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -60,7 +60,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index 5295cd7410..44c39f9942 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -16,7 +16,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -69,7 +69,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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 index 8294f610ad..5458042f08 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -54,7 +54,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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/SvarFci.java index bd0e5a3f4c..e9be420ab6 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/SvarFci.java @@ -14,7 +14,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.search.TsDagToPag; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -57,7 +57,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } 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/SvarGfci.java index 15fe75c537..b868f3baba 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/SvarGfci.java @@ -16,7 +16,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.search.TsDagToPag; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -62,7 +62,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { 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)); + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); if (dataSet.getName() != null) { timeSeries.setName(dataSet.getName()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java index 947441cb8b..fd2db3b134 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java @@ -10,7 +10,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.TimeLagGraph; -import edu.cmu.tetrad.search.TimeSeriesUtils; +import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Parameters; @@ -49,14 +49,14 @@ public void createData(Parameters parameters, boolean newModel) { this.graphs = new ArrayList<>(); Graph graph = this.randomGraph.createGraph(parameters); - graph = TimeSeriesUtils.graphToLagGraph(graph, parameters.getInt(Params.NUM_LAGS)); + graph = TsUtils.graphToLagGraph(graph, parameters.getInt(Params.NUM_LAGS)); TimeSeriesSemSimulation.topToBottomLayout((TimeLagGraph) graph); - this.knowledge = TimeSeriesUtils.getKnowledge(graph); + this.knowledge = TsUtils.getKnowledge(graph); for (int i = 0; i < parameters.getInt(Params.NUM_RUNS); i++) { if (parameters.getBoolean(Params.DIFFERENT_GRAPHS) && i > 0) { graph = this.randomGraph.createGraph(parameters); - graph = TimeSeriesUtils.graphToLagGraph(graph, 2); + graph = TsUtils.graphToLagGraph(graph, 2); TimeSeriesSemSimulation.topToBottomLayout((TimeLagGraph) graph); } @@ -72,7 +72,7 @@ public void createData(Parameters parameters, boolean newModel) { int numLags = ((TimeLagGraph) graph).getMaxLag(); - dataSet = TimeSeriesUtils.createLagData(dataSet, numLags); + dataSet = TsUtils.createLagData(dataSet, numLags); dataSet.setName("" + (i + 1)); dataSet.setKnowledge(this.knowledge.copy()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index eab0b1b0ea..e0c7e99749 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -280,7 +280,7 @@ private void ruleR1TimeLag(Graph skeleton, Graph graph) { throw new IllegalArgumentException("Dataset is not supplied."); } - DataSet lags = TimeSeriesUtils.createLagData(dataModel, 1); + DataSet lags = TsUtils.createLagData(dataModel, 1); if (dataModel.getName() != null) { lags.setName(dataModel.getName()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java index f3ab84319c..d470fc4057 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java @@ -140,7 +140,7 @@ private List getShiftedDataSets(int[] shifts, int maxNumRows) { List shiftedDataSets2 = new ArrayList<>(); for (DataModel dataSet : this.dataSets) { - DataSet shiftedData = TimeSeriesUtils.createShiftedData((DataSet) dataSet, shifts); + DataSet shiftedData = TsUtils.createShiftedData((DataSet) dataSet, shifts); shiftedDataSets2.add(shiftedData); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index c2a462b43c..58205be889 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -68,7 +68,7 @@ public final class SvarGfci implements GraphSearch { // The conditional independence test. private IndependenceTest independenceTest; - // Flag for complete rule set, true if should use complete rule set, false otherwise. + // Flag for complete rule set, true if one should use complete rule set, false otherwise. private boolean completeRuleSetUsed; // True iff the possible dsep search is done. @@ -86,13 +86,13 @@ public final class SvarGfci implements GraphSearch { // True iff verbose output should be printed. private boolean verbose; - // The covariance matrix beign searched over. Assumes continuous data. + // The covariance matrix being searched over. Assumes continuous data. ICovarianceMatrix covarianceMatrix; // The sample size. int sampleSize; - // The penalty discount for the GES search. By default 2. + // The penalty discount for the GES search. By default, 2. private double penaltyDiscount = 2; // The sample prior for the BDeu score (discrete data). @@ -104,7 +104,8 @@ public final class SvarGfci implements GraphSearch { // The print stream that output is directed to. private PrintStream out = System.out; - // True iff one-edge faithfulness is assumed. Speed up the algorith for very large searches. By default false. + // True iff one-edge faithfulness is assumed. Speed up the algorith for very large searches. + // By default, false. private boolean faithfulnessAssumed = true; // The score. @@ -556,17 +557,17 @@ private List> returnSimilarPairs(Node x, Node y) { Node x1; String B; Node y1; + List tmp_tier1; + List tmp_tier2; if (indx_tier >= indy_tier) { - List tmp_tier1 = this.knowledge.getTier(i + tier_diff); - List tmp_tier2 = this.knowledge.getTier(i); - A = tmp_tier1.get(indx_comp); - B = tmp_tier2.get(indy_comp); + tmp_tier1 = this.knowledge.getTier(i + tier_diff); + tmp_tier2 = this.knowledge.getTier(i); } else { - List tmp_tier1 = this.knowledge.getTier(i); - List tmp_tier2 = this.knowledge.getTier(i + tier_diff); - A = tmp_tier1.get(indx_comp); - B = tmp_tier2.get(indy_comp); + tmp_tier1 = this.knowledge.getTier(i); + tmp_tier2 = this.knowledge.getTier(i + tier_diff); } + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp))) continue; if (B.equals(tier_x.get(indx_comp)) && A.equals(tier_y.get(indy_comp))) continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java index 8d4e4a6602..08117e7868 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java @@ -32,24 +32,15 @@ /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

- * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + * This class finds the PAG to which a DAG belongs, for a time series model. * - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 - * @author Joseph Ramsey - * @author Choh-Man Teng * @author Daniel Malinsky + * @see Fci + * @see DagToPag */ public final class TsDagToPag { private final Graph dag; -// private final IndTestDSep dsep; /* * The background knowledge. @@ -115,8 +106,6 @@ public TsDagToPag(Graph dag) { } - //========================PUBLIC METHODS==========================// - public Graph convert() { this.logger.log("info", "Starting DAG to PAG_of_the_true_DAG."); // System.out.println("Knowledge is = " + knowledge); @@ -154,110 +143,6 @@ public Graph convert() { return graph; } - private Graph calcAdjacencyGraph() { - List allNodes = this.dag.getNodes(); - List measured = new ArrayList<>(); - - for (Node node : allNodes) { - if (node.getNodeType() == NodeType.MEASURED) { - measured.add(node); - } - } - - Graph graph = new EdgeListGraph(measured); - - for (int i = 0; i < measured.size(); i++) { - for (int j = i + 1; j < measured.size(); j++) { - Node n1 = measured.get(i); - Node n2 = measured.get(j); - - List inducingPath = this.dag.paths().getInducingPath(n1, n2); - - boolean exists = inducingPath != null; - - if (exists) { - graph.addEdge(Edges.nondirectedEdge(n1, n2)); - } - } - } - - return graph; - } - - private void orientUnshieldedColliders(Graph graph, Graph dag) { - graph.reorientAllWith(Endpoint.CIRCLE); - - List allNodes = dag.getNodes(); - List measured = new ArrayList<>(); - - for (Node node : allNodes) { - if (node.getNodeType() == NodeType.MEASURED) { - measured.add(node); - } - } - - for (Node b : measured) { - List adjb = graph.getAdjacentNodes(b); - - if (adjb.size() < 2) continue; - - for (int i = 0; i < adjb.size(); i++) { - for (int j = i + 1; j < adjb.size(); j++) { - Node a = adjb.get(i); - Node c = adjb.get(j); - - if (graph.isDefCollider(a, b, c)) { - continue; - } - - if (graph.isAdjacentTo(a, c)) { - continue; - } - - boolean found = foundCollider(dag, a, b, c); - - if (found) { - - if (this.verbose) { - System.out.println("Orienting collider " + a + "*->" + b + "<-*" + c); - } - - graph.setEndpoint(a, b, Endpoint.ARROW); - graph.setEndpoint(c, b, Endpoint.ARROW); - } - } - } - } - } - - private boolean foundCollider(Graph dag, Node a, Node b, Node c) { - boolean ipba = TsDagToPag.existsInducingPathInto(b, a, dag, this.knowledge); - boolean ipbc = TsDagToPag.existsInducingPathInto(b, c, dag, this.knowledge); - - if (!(ipba && ipbc)) { - printTrueDefCollider(a, b, c, false); - return false; - } - - printTrueDefCollider(a, b, c, true); - - return true; - } - - private void printTrueDefCollider(Node a, Node b, Node c, boolean found) { - if (this.truePag != null) { - boolean defCollider = this.truePag.isDefCollider(a, b, c); - - if (this.verbose) { - if (!found && defCollider) { - System.out.println("FOUND COLLIDER FCI"); - } else if (found && !defCollider) { - System.out.println("DIDN'T FIND COLLIDER FCI"); - } - } - } - } - public static boolean existsInducingPathInto(Node x, Node y, Graph graph, Knowledge knowledge) { if (x.getNodeType() != NodeType.MEASURED) throw new IllegalArgumentException(); if (y.getNodeType() != NodeType.MEASURED) throw new IllegalArgumentException(); @@ -299,8 +184,9 @@ public boolean isCompleteRuleSetUsed() { } /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule - * set of the original FCI) should be used. False by default. + * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, + * false if only R1-R4 (the rule set of the original FCI) should + * be used. False by default. */ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { this.completeRuleSetUsed = completeRuleSetUsed; @@ -333,7 +219,6 @@ public void setTruePag(Graph truePag) { this.truePag = truePag; } - public static boolean existsInducingPathVisitts(Graph graph, Node a, Node b, Node x, Node y, LinkedList path, Knowledge knowledge) { if (path.contains(b)) { @@ -368,10 +253,115 @@ public static boolean existsInducingPathVisitts(Graph graph, Node a, Node b, Nod return false; } - public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { this.doDiscriminatingPathRule = doDiscriminatingPathRule; } + + + private Graph calcAdjacencyGraph() { + List allNodes = this.dag.getNodes(); + List measured = new ArrayList<>(); + + for (Node node : allNodes) { + if (node.getNodeType() == NodeType.MEASURED) { + measured.add(node); + } + } + + Graph graph = new EdgeListGraph(measured); + + for (int i = 0; i < measured.size(); i++) { + for (int j = i + 1; j < measured.size(); j++) { + Node n1 = measured.get(i); + Node n2 = measured.get(j); + + List inducingPath = this.dag.paths().getInducingPath(n1, n2); + + boolean exists = inducingPath != null; + + if (exists) { + graph.addEdge(Edges.nondirectedEdge(n1, n2)); + } + } + } + + return graph; + } + + private void orientUnshieldedColliders(Graph graph, Graph dag) { + graph.reorientAllWith(Endpoint.CIRCLE); + + List allNodes = dag.getNodes(); + List measured = new ArrayList<>(); + + for (Node node : allNodes) { + if (node.getNodeType() == NodeType.MEASURED) { + measured.add(node); + } + } + + for (Node b : measured) { + List adjb = graph.getAdjacentNodes(b); + + if (adjb.size() < 2) continue; + + for (int i = 0; i < adjb.size(); i++) { + for (int j = i + 1; j < adjb.size(); j++) { + Node a = adjb.get(i); + Node c = adjb.get(j); + + if (graph.isDefCollider(a, b, c)) { + continue; + } + + if (graph.isAdjacentTo(a, c)) { + continue; + } + + boolean found = foundCollider(dag, a, b, c); + + if (found) { + + if (this.verbose) { + System.out.println("Orienting collider " + a + "*->" + b + "<-*" + c); + } + + graph.setEndpoint(a, b, Endpoint.ARROW); + graph.setEndpoint(c, b, Endpoint.ARROW); + } + } + } + } + } + + private boolean foundCollider(Graph dag, Node a, Node b, Node c) { + boolean ipba = TsDagToPag.existsInducingPathInto(b, a, dag, this.knowledge); + boolean ipbc = TsDagToPag.existsInducingPathInto(b, c, dag, this.knowledge); + + if (!(ipba && ipbc)) { + printTrueDefCollider(a, b, c, false); + return false; + } + + printTrueDefCollider(a, b, c, true); + + return true; + } + + private void printTrueDefCollider(Node a, Node b, Node c, boolean found) { + if (this.truePag != null) { + boolean defCollider = this.truePag.isDefCollider(a, b, c); + + if (this.verbose) { + if (!found && defCollider) { + System.out.println("FOUND COLLIDER FCI"); + } else if (found && !defCollider) { + System.out.println("DIDN'T FIND COLLIDER FCI"); + } + } + } + } + } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TimeSeriesUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsUtils.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TimeSeriesUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsUtils.java index 9479e72644..2ee56aceed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TimeSeriesUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsUtils.java @@ -45,7 +45,7 @@ * @author Joseph Ramsey * @author Daniel Malinsky (some improvements) */ -public class TimeSeriesUtils { +public class TsUtils { /** * @return the VAR residuals of the given time series with the given number @@ -54,7 +54,7 @@ public class TimeSeriesUtils { * residuals of these regressions for each variable are returned. */ public static DataSet ar(DataSet timeSeries, int numLags) { - DataSet timeLags = TimeSeriesUtils.createLagData(timeSeries, numLags); + DataSet timeLags = TsUtils.createLagData(timeSeries, numLags); List regressors = new ArrayList<>(); for (int i = timeSeries.getNumColumns(); i < timeLags.getNumColumns(); i++) { @@ -96,7 +96,7 @@ public static DataSet ar2(DataSet timeSeries, int numLags) { } } - DataSet timeLags = TimeSeriesUtils.createLagData(timeSeries, numLags); + DataSet timeLags = TsUtils.createLagData(timeSeries, numLags); Regression regression = new RegressionDataset(timeLags); @@ -154,7 +154,7 @@ private int[] eliminateMissing(int[] parents, int dataIndex, DataSet dataSet, Li } public static VarResult structuralVar(DataSet timeSeries, int numLags) { - DataSet timeLags = TimeSeriesUtils.createLagData(timeSeries, numLags); + DataSet timeLags = TsUtils.createLagData(timeSeries, numLags); Knowledge knowledge = timeLags.getKnowledge().copy(); for (int i = 0; i <= numLags; i++) { @@ -281,7 +281,7 @@ public Graph getCollapsedVarGraph() { } public static double[] getSelfLoopCoefs(DataSet timeSeries) { - DataSet timeLags = TimeSeriesUtils.createLagData(timeSeries, 1); + DataSet timeLags = TsUtils.createLagData(timeSeries, 1); double[] coefs = new double[timeSeries.getNumColumns()]; @@ -299,7 +299,7 @@ public static double[] getSelfLoopCoefs(DataSet timeSeries) { } public static double sumOfArCoefficients(DataSet timeSeries, int numLags) { - DataSet timeLags = TimeSeriesUtils.createLagData(timeSeries, numLags); + DataSet timeLags = TsUtils.createLagData(timeSeries, numLags); List regressors = new ArrayList<>(); for (int i = timeSeries.getNumColumns(); i < timeLags.getNumColumns(); i++) { @@ -575,23 +575,23 @@ public static Knowledge getKnowledge(Graph graph) { Collections.sort(variables, new Comparator() { @Override public int compare(Node o1, Node o2) { - String name1 = TimeSeriesUtils.getNameNoLag(o1); - String name2 = TimeSeriesUtils.getNameNoLag(o2); + String name1 = TsUtils.getNameNoLag(o1); + String name2 = TsUtils.getNameNoLag(o2); - String prefix1 = TimeSeriesUtils.getPrefix(name1); - String prefix2 = TimeSeriesUtils.getPrefix(name2); + String prefix1 = TsUtils.getPrefix(name1); + String prefix2 = TsUtils.getPrefix(name2); - int index1 = TimeSeriesUtils.getIndex(name1); - int index2 = TimeSeriesUtils.getIndex(name2); + int index1 = TsUtils.getIndex(name1); + int index2 = TsUtils.getIndex(name2); - if (TimeSeriesUtils.getLag(o1.getName()) == TimeSeriesUtils.getLag(o2.getName())) { + if (TsUtils.getLag(o1.getName()) == TsUtils.getLag(o2.getName())) { if (prefix1.compareTo(prefix2) == 0) { return Integer.compare(index1, index2); } else { return prefix1.compareTo(prefix2); } } else { - return TimeSeriesUtils.getLag(o1.getName()) - TimeSeriesUtils.getLag(o2.getName()); + return TsUtils.getLag(o1.getName()) - TsUtils.getLag(o2.getName()); } } }); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index a98095f8ac..a733728d5d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -117,7 +117,7 @@ public static ComparisonResult compare(ComparisonParameters params) { if (params.getAlgorithm() == ComparisonParameters.Algorithm.SVARFCI) { trueDag = RandomGraph.randomGraphRandomForwardEdges( nodes, 0, params.getNumEdges(), 10, 10, 10, false, true); - trueDag = TimeSeriesUtils.graphToLagGraph(trueDag, 2); + trueDag = TsUtils.graphToLagGraph(trueDag, 2); System.out.println("Creating Time Lag Graph : " + trueDag); } @@ -205,7 +205,7 @@ public static ComparisonResult compare(ComparisonParameters params) { if (params.getAlgorithm() == ComparisonParameters.Algorithm.SVARFCI) { trueDag = RandomGraph.randomGraphRandomForwardEdges( nodes, 0, params.getNumEdges(), 10, 10, 10, false, true); - trueDag = TimeSeriesUtils.graphToLagGraph(trueDag, 2); + trueDag = TsUtils.graphToLagGraph(trueDag, 2); System.out.println("Creating Time Lag Graph : " + trueDag); } @@ -243,7 +243,7 @@ public static ComparisonResult compare(ComparisonParameters params) { Matrix Gamma0 = Matrix.identity(tierSize).minus(B); Matrix A1 = Gamma0.inverse().times(Gamma1); - isStableTetradMatrix = TimeSeriesUtils.allEigenvaluesAreSmallerThanOneInModulus(A1); + isStableTetradMatrix = TsUtils.allEigenvaluesAreSmallerThanOneInModulus(A1); System.out.println("isStableTetradMatrix? : " + isStableTetradMatrix); attempt++; } while ((!isStableTetradMatrix) && attempt <= 5); From 6a88a3dd67cfbdbb053fd49b9ec69d7494da4b5c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 12:58:23 -0400 Subject: [PATCH 307/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/TsFas.java | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index f2f69373bb..d639e92cc4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -44,7 +44,7 @@ public class TsFas implements IFas { /** - * The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node + * The search graph. It is assumed going in that all the true adjacencies of x are in this graph for every node * x. It is hoped (i.e. true in the large sample limit) that true adjacencies are never removed. */ private final Graph graph; @@ -75,8 +75,6 @@ public class TsFas implements IFas { */ private final TetradLogger logger = TetradLogger.getInstance(); - private int numIndependenceJudgements; - /** * The sepsets found during the search. */ @@ -96,14 +94,6 @@ public class TsFas implements IFas { private PrintStream out = System.out; - /** - * Constructs a new FastAdjacencySearch. - */ - public TsFas(Graph graph, IndependenceTest test) { - this.graph = graph; - this.test = test; - } - /** * Constructs a new FastAdjacencySearch. */ @@ -333,10 +323,6 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map nodes, IndependenceTest test, Map> returnSimilarPairs(IndependenceTest test, Node x, Node Node x1; String B; Node y1; + List tmp_tier1; + List tmp_tier2; if (indx_tier >= indy_tier) { - List tmp_tier1 = this.knowledge.getTier(i + tier_diff); - List tmp_tier2 = this.knowledge.getTier(i); - A = tmp_tier1.get(indx_comp); - B = tmp_tier2.get(indy_comp); + tmp_tier1 = this.knowledge.getTier(i + tier_diff); + tmp_tier2 = this.knowledge.getTier(i); } else { - List tmp_tier1 = this.knowledge.getTier(i); - List tmp_tier2 = this.knowledge.getTier(i + tier_diff); - A = tmp_tier1.get(indx_comp); - B = tmp_tier2.get(indy_comp); + tmp_tier1 = this.knowledge.getTier(i); + tmp_tier2 = this.knowledge.getTier(i + tier_diff); } + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp))) continue; if (B.equals(tier_x.get(indx_comp)) && A.equals(tier_y.get(indy_comp))) continue; From c6327e5a0e83d0d2f348b03b290717e64b3f0237 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:07:01 -0400 Subject: [PATCH 308/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetradapp/model/PurifyRunner.java | 4 ++-- .../cmu/tetrad/search/BuildPureClusters.java | 6 +++--- .../main/java/edu/cmu/tetrad/search/Fofc.java | 6 +++--- .../java/edu/cmu/tetrad/search/Purify.java | 12 +++++------ .../cmu/tetrad/search/PurifyScoreBased.java | 4 ++-- ...radTest.java => TetradTestContinuous.java} | 8 ++++---- ...etradTest.java => TetradTestDiscrete.java} | 20 +++++++++---------- ...radTest.java => TetradTestPopulation.java} | 6 +++--- .../java/edu/cmu/tetrad/search/TsFas.java | 2 +- .../search/WIP/BpcTetradPurifyWashdown.java | 4 ++-- .../java/edu/cmu/tetrad/test/TestPurify.java | 6 +++--- 11 files changed, 39 insertions(+), 39 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ContinuousTetradTest.java => TetradTestContinuous.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{DiscreteTetradTest.java => TetradTestDiscrete.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP/PopulationTetradTest.java => TetradTestPopulation.java} (97%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index 2a6b248dfd..8f2e0a6431 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -80,13 +80,13 @@ public void execute() { CorrelationMatrix corrMatrix = new CorrelationMatrix(covMatrix); double alpha = getParams().getDouble("alpha", 0.001); BpcTestType sigTestType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); - test = new ContinuousTetradTest(covMatrix, sigTestType, alpha); + test = new TetradTestContinuous(covMatrix, sigTestType, alpha); // sextadTest = new DeltaSextadTest(covMatrix); } else if (source instanceof DataSet) { DataSet data = (DataSet) source; double alpha = getParams().getDouble("alpha", 0.001); BpcTestType sigTestType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); - test = new ContinuousTetradTest(data, sigTestType, alpha); + test = new TetradTestContinuous(data, sigTestType, alpha); // sextadTest = new DeltaSextadTest(data); } else { throw new RuntimeException( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java index 25bdf11af4..8774c34c5e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java @@ -206,7 +206,7 @@ private void initAlgorithm(double alpha, BpcTestType sigTestType) { if (sigTestType == BpcTestType.DISCRETE) { this.numVariables = this.dataSet.getNumColumns(); this.independenceTest = new IndTestGSquare(this.dataSet, alpha); - this.tetradTest = new DiscreteTetradTest(this.dataSet, alpha); + this.tetradTest = new TetradTestDiscrete(this.dataSet, alpha); } else { assert getCovarianceMatrix() != null; this.numVariables = getCovarianceMatrix().getSize(); @@ -222,9 +222,9 @@ private void initAlgorithm(double alpha, BpcTestType sigTestType) { } if (this.dataSet != null) { - this.tetradTest = new ContinuousTetradTest(this.dataSet, type, alpha); + this.tetradTest = new TetradTestContinuous(this.dataSet, type, alpha); } else { - this.tetradTest = new ContinuousTetradTest(getCovarianceMatrix(), type, alpha); + this.tetradTest = new TetradTestContinuous(getCovarianceMatrix(), type, alpha); } } this.labels = new int[numVariables()]; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index d48a19fc89..94619aac6d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -53,7 +53,7 @@ public enum Algorithm {SAG, GAP} // The Delta test. Testing two tetrads simultaneously. private final DeltaTetradTest test; // The tetrad test--using Ricardo's. Used only for Wishart. - private final ContinuousTetradTest test2; + private final TetradTestContinuous test2; // The data. private final transient DataModel dataModel; private final BpcTestType testType; @@ -80,7 +80,7 @@ public Fofc(ICovarianceMatrix cov, BpcTestType testType, Algorithm algorithm, do this.alpha = alpha; this.testType = testType; this.test = new DeltaTetradTest(cov); - this.test2 = new ContinuousTetradTest(cov, testType, alpha); + this.test2 = new TetradTestContinuous(cov, testType, alpha); this.dataModel = cov; this.algorithm = algorithm; @@ -105,7 +105,7 @@ public Fofc(DataSet dataSet, BpcTestType testType, Algorithm algorithm, double a this.alpha = alpha; this.testType = testType; this.test = new DeltaTetradTest(dataSet); - this.test2 = new ContinuousTetradTest(dataSet, testType, alpha); + this.test2 = new TetradTestContinuous(dataSet, testType, alpha); this.dataModel = dataSet; this.algorithm = algorithm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java index e4e6512200..d83438f1d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java @@ -140,13 +140,13 @@ private void initAlgorithm(double sig, BpcTestType testType, Clusters clusters) // Should type these ones. if (testType == BpcTestType.TETRAD_DELTA) { - this.tetradTest = new ContinuousTetradTest(this.dataSet, BpcTestType.TETRAD_DELTA, sig); + this.tetradTest = new TetradTestContinuous(this.dataSet, BpcTestType.TETRAD_DELTA, sig); } else { - this.tetradTest = new ContinuousTetradTest(this.correlationMatrix, + this.tetradTest = new TetradTestContinuous(this.correlationMatrix, testType, sig); } } else { - this.tetradTest = new DiscreteTetradTest(this.dataSet, sig); + this.tetradTest = new TetradTestDiscrete(this.dataSet, sig); } } this.numVars = this.tetradTest.getVarNames().length; @@ -180,7 +180,7 @@ private Graph getResultGraph() { // return convertSearchGraph(pureClusters); // } else { - BpcTestType type = ((ContinuousTetradTest) this.tetradTest).getTestType(); + BpcTestType type = ((TetradTestContinuous) this.tetradTest).getTestType(); // type = TestType.TETRAD_BASED; type = null; @@ -1342,7 +1342,7 @@ private SemGraph scoreBasedPurify(List partition) { impurities[j][i] = impurities[i][j]; } } - if (((ContinuousTetradTest) this.tetradTest).getTestType() == + if (((TetradTestContinuous) this.tetradTest).getTestType() == BpcTestType.GAUSSIAN_SCORE) { bestGraph = removeMarkedImpurities(bestGraph, impurities); } @@ -1502,7 +1502,7 @@ private void structuralEmInitialization(List partition) { } this.purePartitionGraph = new SemGraph(this.basicGraph); - if (((ContinuousTetradTest) this.tetradTest).getTestType() == + if (((TetradTestContinuous) this.tetradTest).getTestType() == BpcTestType.NONE) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java index f9b8d04a20..b6753f6255 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java @@ -305,7 +305,7 @@ private SemGraph scoreBasedPurify(List partition) { impurities[j][i] = impurities[i][j]; } } - if (((ContinuousTetradTest) this.tetradTest).getTestType() == + if (((TetradTestContinuous) this.tetradTest).getTestType() == BpcTestType.GAUSSIAN_SCORE) { bestGraph = removeMarkedImpurities(bestGraph, impurities); } @@ -359,7 +359,7 @@ private void structuralEmInitialization(List partition) { this.purePartitionGraph = new SemGraph(this.basicGraph); this.purePartitionGraph.setShowErrorTerms(true); - if (((ContinuousTetradTest) this.tetradTest).getTestType() == + if (((TetradTestContinuous) this.tetradTest).getTestType() == BpcTestType.NONE) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java index 3eb82007c8..5809e67a40 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ContinuousTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java @@ -54,7 +54,7 @@ * @author Ricardo Silva */ -public final class ContinuousTetradTest implements TetradTest { +public final class TetradTestContinuous implements TetradTest { private double sig; private double[] prob; private ICovarianceMatrix covMatrix; @@ -70,7 +70,7 @@ public final class ContinuousTetradTest implements TetradTest { private List variables; DeltaTetradTest deltaTest; - public ContinuousTetradTest(DataSet dataSet, BpcTestType sigTestType, + public TetradTestContinuous(DataSet dataSet, BpcTestType sigTestType, double sig) { if (sigTestType == BpcTestType.TETRAD_BOLLEN || sigTestType == null) { sigTestType = BpcTestType.TETRAD_DELTA; @@ -98,7 +98,7 @@ public ContinuousTetradTest(DataSet dataSet, BpcTestType sigTestType, initialization(); } - public ContinuousTetradTest(ICovarianceMatrix covMatrix, + public TetradTestContinuous(ICovarianceMatrix covMatrix, BpcTestType sigTestType, double sig) { if (!(sigTestType == BpcTestType.TETRAD_WISHART || sigTestType == BpcTestType.TETRAD_DELTA || @@ -119,7 +119,7 @@ public ContinuousTetradTest(ICovarianceMatrix covMatrix, this.variables = covMatrix.getVariables(); } - public ContinuousTetradTest(CorrelationMatrix correlationMatrix, + public TetradTestContinuous(CorrelationMatrix correlationMatrix, BpcTestType sigTestType, double sig) { if (!(sigTestType == BpcTestType.TETRAD_WISHART || sigTestType == BpcTestType.TETRAD_DELTA || diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java index 62bbf7511a..4e9c48fdff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java @@ -45,7 +45,7 @@ * @author Ricardo Silva */ -public final class DiscreteTetradTest implements TetradTest { +public final class TetradTestDiscrete implements TetradTest { DataSet dataSet; // int rawdata[][]; int[][][][] counts; //bivariate coefs only @@ -96,7 +96,7 @@ public final class DiscreteTetradTest implements TetradTest { */ int[][][][] twoFactor4Tests; - public DiscreteTetradTest(DataSet dataSet, double sig) { + public TetradTestDiscrete(DataSet dataSet, double sig) { this.dataSet = dataSet; this.sig = sig; initialization(); @@ -115,8 +115,8 @@ public DataSet getDataSet() { } private void initialization() { - for (int i = 0; i < DiscreteTetradTest.GHY.length; i++) { - DiscreteTetradTest.GHY[i] *= FastMath.sqrt(2); + for (int i = 0; i < TetradTestDiscrete.GHY.length; i++) { + TetradTestDiscrete.GHY[i] *= FastMath.sqrt(2); } int numRows = this.dataSet.getNumRows(); int numColumns = this.dataSet.getNumColumns(); @@ -127,9 +127,9 @@ private void initialization() { this.sig2 = 2. * this.sig / 3.; this.sig3 = this.sig; - this.rhoGrid = new double[DiscreteTetradTest.RHO_GRID_SIZE]; - for (int i = 1; i < DiscreteTetradTest.RHO_GRID_SIZE; i++) { - this.rhoGrid[i - 1] = -1. + (2. / DiscreteTetradTest.RHO_GRID_SIZE) * i; + this.rhoGrid = new double[TetradTestDiscrete.RHO_GRID_SIZE]; + for (int i = 1; i < TetradTestDiscrete.RHO_GRID_SIZE; i++) { + this.rhoGrid[i - 1] = -1. + (2. / TetradTestDiscrete.RHO_GRID_SIZE) * i; } // this.rawdata = this.dataSet.getIntMatrixTransposed(); @@ -137,8 +137,8 @@ private void initialization() { // Store and order possible values this.values = new int[numColumns][]; this.valueIndices = new int[numColumns]; - int[] tempValues = new int[DiscreteTetradTest.MAX_VALUES]; - boolean[] marked = new boolean[DiscreteTetradTest.MAX_VALUES]; + int[] tempValues = new int[TetradTestDiscrete.MAX_VALUES]; + boolean[] marked = new boolean[TetradTestDiscrete.MAX_VALUES]; for (int i = 0; i < numColumns; i++) { int vSize = 0; rowloop: @@ -149,7 +149,7 @@ private void initialization() { continue rowloop; } } - if (vSize < DiscreteTetradTest.MAX_VALUES - 1) { + if (vSize < TetradTestDiscrete.MAX_VALUES - 1) { tempValues[vSize++] = value; } else { throw new RuntimeException( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/PopulationTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/PopulationTetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java index 46346f3944..e8b71ced7d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/PopulationTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; @@ -37,12 +37,12 @@ * @author Ricardo Silva */ -public class PopulationTetradTest implements TetradTest { +public class TetradTestPopulation implements TetradTest { private final CorrelationMatrix CorrelationMatrix; private final boolean[] bvalues; private final double epsilon = 0.001; - public PopulationTetradTest(CorrelationMatrix CorrelationMatrix) { + public TetradTestPopulation(CorrelationMatrix CorrelationMatrix) { this.CorrelationMatrix = CorrelationMatrix; this.bvalues = new boolean[3]; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index d639e92cc4..3d9d2f5021 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -37,7 +37,7 @@ * remove all homologous edges to preserve the time-repeating structure assumed by SvarFCI. Based on (but not identicial * to) code by Entner and Hoyer for their 2010 paper. Modified by DMalinsky 4/21/2016. * - * @author Joseph Ramsey. + * @author josephramsey * @author DMalinsky * @see Fas */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java index 22ab99dbe7..f8c66d4ba4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java @@ -51,7 +51,7 @@ public class BpcTetradPurifyWashdown { */ public BpcTetradPurifyWashdown(ICovarianceMatrix cov, BpcTestType testType, double alpha) { this.variables = cov.getVariables(); - this.test = new ContinuousTetradTest(cov, testType, alpha); + this.test = new TetradTestContinuous(cov, testType, alpha); } /** @@ -65,7 +65,7 @@ public BpcTetradPurifyWashdown(ICovarianceMatrix cov, BpcTestType testType, doub */ public BpcTetradPurifyWashdown(DataSet dataSet, BpcTestType testType, double alpha) { this.variables = dataSet.getVariables(); - this.test = new ContinuousTetradTest(dataSet, testType, alpha); + this.test = new TetradTestContinuous(dataSet, testType, alpha); } /** diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index 704248a225..e9b5f8fec0 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -151,7 +151,7 @@ public void test1() { partition.add(cluster2); partition.add(cluster3); - TetradTest test = new ContinuousTetradTest(data, BpcTestType.TETRAD_WISHART, 0.05); + TetradTest test = new TetradTestContinuous(data, BpcTestType.TETRAD_WISHART, 0.05); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); @@ -248,7 +248,7 @@ public void test1b() { partition.add(cluster1); partition.add(cluster2); - TetradTest test = new ContinuousTetradTest(data, BpcTestType.TETRAD_WISHART, 0.0001); + TetradTest test = new TetradTestContinuous(data, BpcTestType.TETRAD_WISHART, 0.0001); IPurify purify = new PurifyTetradBased(test); purify.setTrueGraph(graph); @@ -286,7 +286,7 @@ public void test2() { clustering.add(adj); } - ContinuousTetradTest test = new ContinuousTetradTest(data, BpcTestType.TETRAD_WISHART, 0.001); + TetradTestContinuous test = new TetradTestContinuous(data, BpcTestType.TETRAD_WISHART, 0.001); IPurify purify = new PurifyTetradBased(test); From 7d316bc16e02e511fc8f6e155a16db0230a00030 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:13:11 -0400 Subject: [PATCH 309/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/TetradTest.java | 5 +++-- .../main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java | 4 ---- .../java/edu/cmu/tetrad/search/TetradTestPopulation.java | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java index 7deebdeec6..536422fa33 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java @@ -28,8 +28,9 @@ import java.util.List; /** - * Interface implemented by classes that test tetrad constraints. For the continuous case, we have a variety of tests, - * including a distribution-free one (which may not be currently practical when the number of variables is too large). + * Interface implemented by classes that test tetrad constraints. For the continuous case, + * we have a variety of tests, including a distribution-free one (which may not be + * currently practical when the number of variables is too large). * * @author Ricardo Silva */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java index 4e9c48fdff..57b973eaf4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java @@ -132,8 +132,6 @@ private void initialization() { this.rhoGrid[i - 1] = -1. + (2. / TetradTestDiscrete.RHO_GRID_SIZE) * i; } -// this.rawdata = this.dataSet.getIntMatrixTransposed(); - // Store and order possible values this.values = new int[numColumns][]; this.valueIndices = new int[numColumns]; @@ -272,7 +270,6 @@ public int tetradScore(int i, int j, int k, int l) { /** * Tests the tetrad (v1, v3) x (v2, v4) = (v1, v4) x (v2, v3), and only that. */ - public boolean tetradScore1(int v1, int v2, int v3, int v4) { if (oneFactorTest(v1, v2, v3, v4)) { return false; @@ -283,7 +280,6 @@ public boolean tetradScore1(int v1, int v2, int v3, int v4) { /** * Tests if all tetrad constraints hold */ - public boolean tetradScore3(int v1, int v2, int v3, int v4) { return oneFactorTest(v1, v2, v3, v4); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java index e8b71ced7d..8430df398c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java @@ -36,7 +36,6 @@ * * @author Ricardo Silva */ - public class TetradTestPopulation implements TetradTest { private final CorrelationMatrix CorrelationMatrix; private final boolean[] bvalues; From fae21d47fc1d705236e39d2af7b007c335713c61 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:30:09 -0400 Subject: [PATCH 310/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/SvarFciOrient.java | 249 ++-------------- .../java/edu/cmu/tetrad/search/SvarGfci.java | 281 ++++++------------ 2 files changed, 121 insertions(+), 409 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index a3a9eac7af..56fdd3cf19 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -64,15 +64,10 @@ public final class SvarFciOrient { private boolean changeFlag = true; /** - * flag for complete rule set, true if should use complete rule set, false otherwise. + * flag for complete rule set, true if one should use complete rule set, false otherwise. */ private boolean completeRuleSetUsed; - /** - * True iff the possible dsep search is done. - */ - private boolean possibleDsepSearchDone = true; - /** * The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. */ @@ -102,8 +97,6 @@ public SvarFciOrient(SepsetProducer sepsets, IndependenceTest independenceTest) this.independenceTest = independenceTest; } - //========================PUBLIC METHODS==========================// - public Graph orient(Graph graph) { this.logger.log("info", "Starting FCI algorithm."); @@ -163,10 +156,6 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { //===========================PRIVATE METHODS=========================// - private List getSepset(Node i, Node k) { - return this.sepsets.getSepset(i, k); - } - /** * Orients colliders in the graph. (FCI Step C) *

@@ -205,11 +194,11 @@ public void ruleR0(Graph graph) { } if (this.sepsets.isUnshieldedCollider(a, b, c)) { - if (!isArrowpointAllowed(a, b, graph)) { + if (isArrowheadDisallowed(a, b, graph)) { continue; } - if (!isArrowpointAllowed(c, b, graph)) { + if (isArrowheadDisallowed(c, b, graph)) { continue; } @@ -218,8 +207,6 @@ public void ruleR0(Graph graph) { if (this.verbose) { this.logger.log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(a, b, c)); System.out.println(SearchLogUtils.colliderOrientedMsg(a, b, c)); - final String location = "R0"; - printWrongColliderMessage(a, b, c, graph); } this.orientSimilarPairs(graph, this.knowledge, a, b, Endpoint.ARROW); @@ -335,7 +322,7 @@ public void rulesR1R2cycle(Graph graph) { Node A = adj.get(combination[0]); Node C = adj.get(combination[1]); - //choice gen doesnt do diff orders, so must switch A & C around. + //choice gen doesn't do diff orders, so must switch A & C around. ruleR1(A, B, C, graph); ruleR1(C, B, A, graph); ruleR2(A, B, C, graph); @@ -352,7 +339,7 @@ private void ruleR1(Node a, Node b, Node c, Graph graph) { } if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(b, c, graph)) { + if (isArrowheadDisallowed(b, c, graph)) { return; } @@ -369,10 +356,6 @@ private void ruleR1(Node a, Node b, Node c, Graph graph) { } } - private boolean isNoncollider(Node a, Node b, Node c) { - return this.sepsets.isUnshieldedNoncollider(a, b, c); - } - //if a*-oc and either a-->b*->c or a*->b-->c, then a*->c // This is Zhang's rule R2. private void ruleR2(Node a, Node b, Node c, Graph graph) { @@ -384,7 +367,7 @@ private void ruleR2(Node a, Node b, Node c, Graph graph) { (graph.getEndpoint(b, a) == Endpoint.TAIL) || (graph.getEndpoint(c, b) == Endpoint.TAIL))) { - if (!isArrowpointAllowed(a, c, graph)) { + if (isArrowheadDisallowed(a, c, graph)) { return; } @@ -443,7 +426,7 @@ public void ruleR3(Graph graph) { continue; } - if (!isArrowpointAllowed(D, B, graph)) { + if (isArrowheadDisallowed(D, B, graph)) { continue; } @@ -461,146 +444,6 @@ public void ruleR3(Graph graph) { } - /** - * The triangles that must be oriented this way (won't be done by another rule) all look like the ones below, where - * the dots are a collider path from L to A with each node on the path (except L) a parent of C. - *

-     *          B
-     *         xo           x is either an arrowhead or a circle
-     *        /  \
-     *       v    v
-     * L....A --> C
-     * 
- *

- * This is Zhang's rule R4, discriminating undirectedPaths. - */ - private void ruleR4A(Graph graph) { - List nodes = graph.getNodes(); - - for (Node b : nodes) { - - //potential A and C candidate pairs are only those - // that look like this: A<-*Bo-*C - List possA = graph.getNodesOutTo(b, Endpoint.ARROW); - List possC = graph.getNodesInTo(b, Endpoint.CIRCLE); - - for (Node a : possA) { - for (Node c : possC) { - if (!graph.isParentOf(a, c)) { - continue; - } - - if (graph.getEndpoint(b, c) != Endpoint.ARROW) { - continue; - } - - LinkedList reachable = new LinkedList<>(); - reachable.add(a); - - if (this.verbose) { - System.out.println("Found CPDAG " + a + " " + b + " " + c); - reachablePathFind(a, b, c, reachable, graph); - } - } - } - } - } - - /** - * a method to search "back from a" to find a DDP. It is called with a reachability list (first consisting only of - * a). This is breadth-first, utilizing "reachability" concept from Geiger, Verma, and Pearl 1990. The body of - * a DDP consists of colliders that are parents of c. - */ - private void reachablePathFind(Node a, Node b, Node c, - LinkedList reachable, Graph graph) { - - Set cParents = new HashSet<>(graph.getParents(c)); - - // Needed to avoid cycles in failure case. - Set visited = new HashSet<>(); - visited.add(b); - visited.add(c); - - Node e = reachable.getFirst(); - int distance = 0; - - // We don't want to include a,b,or c on the path, so they are added to - // the "visited" set. b and c are added explicitly here; a will be - // added in the first while iteration. - while (reachable.size() > 0) { - Node x = reachable.removeFirst(); - visited.add(x); - - if (e == x) { - e = x; - distance++; - - int _maxPathLength = this.maxPathLength == -1 ? 1000 : this.maxPathLength; - - if (distance > 0 && distance > _maxPathLength) { - continue; - } - } - - // Possible DDP path endpoints. - List pathExtensions = graph.getNodesInTo(x, Endpoint.ARROW); - pathExtensions.removeAll(visited); - - for (Node d : pathExtensions) { - // If d is reachable and not adjacent to c, its a DDP - // endpoint, so do DDP orientation. Otherwise, if d <-> c, - // add d to the list of reachable nodes. - if (!graph.isAdjacentTo(d, c)) { - // Check whether should be reoriented given - // that d is not adjacent to c; if so, orient and stop. - doDdpOrientation(d, a, b, c, graph); - return; - } else if (cParents.contains(d)) { - if (graph.getEndpoint(x, d) == Endpoint.ARROW) { - reachable.add(d); - - // RFCI: only record the next node of the first (shortest) occurrence - } - } - } - } - } - - /** - * Orients the edges inside the definte discriminating path triangle. Takes the left endpoint, and a,b,c as - * arguments. - */ - private void doDdpOrientation(Node d, Node a, Node b, Node c, Graph graph) { - List sepset = getSepset(d, c); - - if (sepset == null) return; - - if (sepset.contains(b)) { - graph.setEndpoint(c, b, Endpoint.TAIL); - this.orientSimilarPairs(graph, this.getKnowledge(), c, b, Endpoint.TAIL); - if (this.verbose) { - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Definite discriminating path d = " + d, graph.getEdge(b, c))); - System.out.println(SearchLogUtils.edgeOrientedMsg("Definite discriminating path d = " + d, graph.getEdge(b, c))); - } - - } else { - if (!isArrowpointAllowed(a, b, graph)) { - return; - } - - if (!isArrowpointAllowed(c, b, graph)) { - return; - } - - graph.setEndpoint(a, b, Endpoint.ARROW); - graph.setEndpoint(c, b, Endpoint.ARROW); - this.orientSimilarPairs(graph, this.getKnowledge(), a, b, Endpoint.ARROW); - this.orientSimilarPairs(graph, this.getKnowledge(), c, b, Endpoint.ARROW); - this.logger.log("colliderOrientations", SearchLogUtils.colliderOrientedMsg("Definite discriminating path.. d = " + d, a, b, c)); - } - this.changeFlag = true; - } - /** * The triangles that must be oriented this way (won't be done by another rule) all look like * the ones below, where the dots are a collider path from L to A with each node on the path @@ -700,7 +543,7 @@ public void ddpOrient(Node a, Node b, Node c, Graph graph) { } /** - * Orients the edges inside the definte discriminating path triangle. Takes the left endpoint, and a,b,c as + * Orients the edges inside the definite discriminating path triangle. Takes the left endpoint, and a,b,c as * arguments. */ private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Map previous, Graph graph) { @@ -747,11 +590,11 @@ private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Map } } else { - if (!isArrowpointAllowed(a, b, graph)) { + if (isArrowheadDisallowed(a, b, graph)) { return false; } - if (!isArrowpointAllowed(c, b, graph)) { + if (isArrowheadDisallowed(c, b, graph)) { return false; } @@ -769,19 +612,6 @@ private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Map return true; } - private void printDdp(Node d, List path, Node a, Node b, Node c, Graph graph) { - List nodes = new ArrayList<>(); - nodes.add(d); - nodes.addAll(path); - nodes.add(a); - nodes.add(b); - nodes.add(c); - - if (this.verbose) { - System.out.println("DDP subgraph = " + graph.subgraph(nodes)); - } - } - private List getPath(Node c, Map previous) { List l = new ArrayList<>(); @@ -1045,7 +875,7 @@ private List> getUcCirclePaths(Node n1, Node n2, Graph graph) { * * @param a The node A. * @param c The node C. - * @return Whether or not R8 was successfully applied. + * @return Whether R8 was successfully applied. */ private boolean ruleR8(Node a, Node c, Graph graph) { List intoCArrows = graph.getNodesInTo(c, Endpoint.ARROW); @@ -1083,7 +913,7 @@ private boolean ruleR8(Node a, Node c, Graph graph) { * * @param a The node A. * @param c The node C. - * @return Whether or not R9 was succesfully applied. + * @return Whether R9 was successfully applied. */ private boolean ruleR9(Node a, Node c, Graph graph) { List> ucPdPsToC = getUcPdPaths(a, c, graph); @@ -1115,9 +945,8 @@ private boolean ruleR9(Node a, Node c, Graph graph) { * * @param a The node A. * @param c The node C. - * @return Whether or not R10 was successfully applied. */ - private boolean ruleR10(Node a, Node c, Graph graph) { + private void ruleR10(Node a, Node c, Graph graph) { List intoCArrows = graph.getNodesInTo(c, Endpoint.ARROW); for (Node b : intoCArrows) { @@ -1148,13 +977,12 @@ private boolean ruleR10(Node a, Node c, Graph graph) { graph.setEndpoint(c, a, Endpoint.TAIL); this.changeFlag = true; this.orientSimilarPairs(graph, this.getKnowledge(), c, a, Endpoint.TAIL); - return true; + return; } } } } - return false; } /** @@ -1214,39 +1042,31 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { /** - * Helper method. Appears to check if an arrowpoint is permitted by background knowledge. + * Helper method. Appears to check if an arrowhead is permitted by background knowledge. * * @param x The possible other node. * @param y The possible point node. - * @return Whether the arrowpoint is allowed. + * @return Whether the arrowhead is allowed. */ - private boolean isArrowpointAllowed(Node x, Node y, Graph graph) { + private boolean isArrowheadDisallowed(Node x, Node y, Graph graph) { if (graph.getEndpoint(x, y) == Endpoint.ARROW) { - return true; + return false; } if (graph.getEndpoint(x, y) == Endpoint.TAIL) { - return false; + return true; } if (graph.getEndpoint(y, x) == Endpoint.ARROW) { - return true; // changed by DMalinsky 02/11/2019, if already an arrowhead at x, arrowpoint is allowed at y + return false; // changed by DMalinsky 02/11/2019, if already an arrowhead at x, arrowhead is allowed at y // if (!knowledge.isForbidden(x.getName(), y.getName())) return true; } if (graph.getEndpoint(y, x) == Endpoint.TAIL) { - if (!this.knowledge.isForbidden(x.getName(), y.getName())) return true; + if (!this.knowledge.isForbidden(x.getName(), y.getName())) return false; } - return graph.getEndpoint(y, x) == Endpoint.CIRCLE; - } - - public boolean isPossibleDsepSearchDone() { - return this.possibleDsepSearchDone; - } - - public void setPossibleDsepSearchDone(boolean possibleDsepSearchDone) { - this.possibleDsepSearchDone = possibleDsepSearchDone; + return graph.getEndpoint(y, x) != Endpoint.CIRCLE; } /** @@ -1289,17 +1109,6 @@ public Graph getTruePag() { return this.truePag; } - public void setChangeFlag(boolean changeFlag) { - this.changeFlag = changeFlag; - } - - /** - * change flag for repeat rules - */ - public boolean isChangeFlag() { - return this.changeFlag; - } - private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y, Endpoint mark) { if (x.getName().equals("time") || y.getName().equals("time")) { return; @@ -1311,9 +1120,9 @@ private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y int tier_diff = FastMath.max(indx_tier, indy_tier) - FastMath.min(indx_tier, indy_tier); int indx_comp = -1; int indy_comp = -1; - List tier_x = knowledge.getTier(indx_tier); + List tier_x = knowledge.getTier(indx_tier); // Collections.sort(tier_x); - List tier_y = knowledge.getTier(indy_tier); + List tier_y = knowledge.getTier(indy_tier); // Collections.sort(tier_y); int i; @@ -1341,12 +1150,12 @@ private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y String B; Node y1; if (indx_tier >= indy_tier) { - List tmp_tier1 = knowledge.getTier(i + tier_diff); + List tmp_tier1 = knowledge.getTier(i + tier_diff); // Collections.sort(tmp_tier1); - List tmp_tier2 = knowledge.getTier(i); + List tmp_tier2 = knowledge.getTier(i); // Collections.sort(tmp_tier2); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + A = tmp_tier1.get(indx_comp); + B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp))) continue; if (B.equals(tier_x.get(indx_comp)) && A.equals(tier_y.get(indy_comp))) continue; @@ -1358,8 +1167,6 @@ private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y graph.setEndpoint(x1, y1, mark); System.out.println(" by structure knowledge as: " + graph.getEdge(x1, y1).toString()); } - } else { -// System.out.println("############## WARNING (orientSimilarPairs): did not catch x,y pair " + x + ", " + y); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 58205be889..5b0a219303 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -27,33 +27,16 @@ import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; -import java.io.PrintStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** - * Replaces the FAS search in the previous version with GES followed by PC adjacency removals for more accuracy. - * Uses conservative collider orientation. Gets sepsets for X---Y from among adjacents of X or of Y. -jdramsey 3/10/2015 - *

- * Following an idea of Spirtes, now it uses more of the information in GES, to calculating possible dsep paths and to - * utilize unshielded colliders found by GES. 5/31/2015 - *

- * Previous: - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in Fci.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

- * This class is based off a copy of Fci.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + * Adapts GFCI to the SVAR case. * - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 - * @author Joseph Ramsey - * @author Choh-Man Teng * @author Daniel Malinsky + * @see GFci */ public final class SvarGfci implements GraphSearch { @@ -63,17 +46,12 @@ public final class SvarGfci implements GraphSearch { // The background knowledge. private Knowledge knowledge = new Knowledge(); - // The variables to search over (optional) - // The conditional independence test. private IndependenceTest independenceTest; // Flag for complete rule set, true if one should use complete rule set, false otherwise. private boolean completeRuleSetUsed; - // True iff the possible dsep search is done. -// private boolean possibleDsepSearchDone = true; - // The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. private int maxPathLength = -1; @@ -89,9 +67,6 @@ public final class SvarGfci implements GraphSearch { // The covariance matrix being searched over. Assumes continuous data. ICovarianceMatrix covarianceMatrix; - // The sample size. - int sampleSize; - // The penalty discount for the GES search. By default, 2. private double penaltyDiscount = 2; @@ -101,9 +76,6 @@ public final class SvarGfci implements GraphSearch { // The structure prior for the Bdeu score (discrete data). private double structurePrior = 1; - // The print stream that output is directed to. - private PrintStream out = System.out; - // True iff one-edge faithfulness is assumed. Speed up the algorith for very large searches. // By default, false. private boolean faithfulnessAssumed = true; @@ -122,28 +94,22 @@ public SvarGfci(IndependenceTest test, Score score) { if (score == null) { throw new NullPointerException(); } - this.sampleSize = score.getSampleSize(); this.score = score; this.independenceTest = test; } - //========================PUBLIC METHODS==========================// - - public Graph search() { - - this.logger.log("info", "Starting svarGFCI algorithm."); - this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); + this.logger.log("info", "Independence test = " + this.independenceTest + "."); this.graph = new EdgeListGraph(independenceTest.getVariables()); if (this.score == null) { - setScore(); + chooseScore(); } TsFges fges = new TsFges(this.score); - fges.setKnowledge(getKnowledge()); + fges.setKnowledge(this.knowledge); fges.setVerbose(this.verbose); fges.setNumCPDAGsToStore(0); fges.setFaithfulnessAssumed(this.faithfulnessAssumed); @@ -184,7 +150,7 @@ public Graph search() { modifiedR0(fgesGraph); SvarFciOrient fciOrient = new SvarFciOrient(this.sepsets, this.independenceTest); - fciOrient.setKnowledge(getKnowledge()); + fciOrient.setKnowledge(this.knowledge); fciOrient.setCompleteRuleSetUsed(this.completeRuleSetUsed); fciOrient.setMaxPathLength(this.maxPathLength); fciOrient.doFinalOrientation(this.graph); @@ -194,9 +160,72 @@ public Graph search() { return this.graph; } - private void setScore() { - this.sampleSize = this.independenceTest.getSampleSize(); - double penaltyDiscount = getPenaltyDiscount(); + public void setMaxIndegree(int maxIndegree) { + if (maxIndegree < -1) { + throw new IllegalArgumentException( + "Depth must be -1 (unlimited) or >= 0: " + maxIndegree); + } + + this.maxIndegree = maxIndegree; + } + + public void setKnowledge(Knowledge knowledge) { + if (knowledge == null) { + throw new NullPointerException(); + } + + this.knowledge = knowledge; + } + + /** + * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule + * set of the original FCI) should be used. False by default. + */ + public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { + this.completeRuleSetUsed = completeRuleSetUsed; + } + + /** + * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. + */ + public void setMaxPathLength(int maxPathLength) { + if (maxPathLength < -1) { + throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); + } + + this.maxPathLength = maxPathLength; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public void setPenaltyDiscount(double penaltyDiscount) { + this.penaltyDiscount = penaltyDiscount; + } + + public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { + this.covarianceMatrix = covarianceMatrix; + } + + public void setIndependenceTest(IndependenceTest independenceTest) { + this.independenceTest = independenceTest; + } + + public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { + this.faithfulnessAssumed = faithfulnessAssumed; + } + + public void setSamplePrior(double samplePrior) { + this.samplePrior = samplePrior; + } + + public void setStructurePrior(double structurePrior) { + this.structurePrior = structurePrior; + } + + private void chooseScore() { + double penaltyDiscount = this.penaltyDiscount; DataSet dataSet = (DataSet) this.independenceTest.getData(); ICovarianceMatrix cov = this.independenceTest.getCov(); @@ -226,21 +255,8 @@ private void setScore() { this.score = score; } - public int getMaxIndegree() { - return this.maxIndegree; - } - - public void setMaxIndegree(int maxIndegree) { - if (maxIndegree < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + maxIndegree); - } - - this.maxIndegree = maxIndegree; - } - // Due to Spirtes. - public void modifiedR0(Graph fgesGraph) { + private void modifiedR0(Graph fgesGraph) { this.graph.reorientAllWith(Endpoint.CIRCLE); fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); @@ -284,108 +300,6 @@ public void modifiedR0(Graph fgesGraph) { } } - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException(); - } - - this.knowledge = knowledge; - } - - /** - * @return true if Zhang's complete rule set should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. - */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; - } - - /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule - * set of the original FCI) should be used. False by default. - */ - public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { - this.completeRuleSetUsed = completeRuleSetUsed; - } - - /** - * @return the maximum length of any discriminating path, or -1 of unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength; - } - - /** - * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. - */ - public void setMaxPathLength(int maxPathLength) { - if (maxPathLength < -1) { - throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); - } - - this.maxPathLength = maxPathLength; - } - - /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - /** - * The independence test. - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public ICovarianceMatrix getCovMatrix() { - return this.covarianceMatrix; - } - - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } - - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } - - public PrintStream getOut() { - return this.out; - } - - public void setOut(PrintStream out) { - this.out = out; - } - - public void setIndependenceTest(IndependenceTest independenceTest) { - this.independenceTest = independenceTest; - } - - public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { - this.faithfulnessAssumed = faithfulnessAssumed; - } - - //===========================================PRIVATE METHODS=======================================// - /** * Orients according to background knowledge */ @@ -437,12 +351,28 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) this.logger.log("info", "Finishing BK Orientation."); } - public void setSamplePrior(double samplePrior) { - this.samplePrior = samplePrior; + private String getNameNoLag(Object obj) { + String tempS = obj.toString(); + if (tempS.indexOf(':') == -1) { + return tempS; + } else return tempS.substring(0, tempS.indexOf(':')); } - public void setStructurePrior(double structurePrior) { - this.structurePrior = structurePrior; + private void removeSimilarEdges(Node x, Node y) { + List> simList = returnSimilarPairs(x, y); + if (simList.isEmpty()) return; + List x1List = simList.get(0); + List y1List = simList.get(1); + Iterator itx = x1List.iterator(); + Iterator ity = y1List.iterator(); + while (itx.hasNext() && ity.hasNext()) { + Node x1 = itx.next(); + Node y1 = ity.next(); + System.out.println("$$$$$$$$$$$ similar pair x,y = " + x1 + ", " + y1); + System.out.println("removing edge between x = " + x1 + " and y = " + y1); + Edge oldxy = this.graph.getEdge(x1, y1); + this.graph.removeEdge(oldxy); + } } private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y) { @@ -504,13 +434,6 @@ private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y } - public String getNameNoLag(Object obj) { - String tempS = obj.toString(); - if (tempS.indexOf(':') == -1) { - return tempS; - } else return tempS.substring(0, tempS.indexOf(':')); - } - // returnSimilarPairs based on orientSimilarPairs in SvarFciOrient.java by Entner and Hoyer private List> returnSimilarPairs(Node x, Node y) { System.out.println("$$$$$ Entering returnSimilarPairs method with x,y = " + x + ", " + y); @@ -583,24 +506,6 @@ private List> returnSimilarPairs(Node x, Node y) { pairList.add(simListY); return (pairList); } - - public void removeSimilarEdges(Node x, Node y) { - List> simList = returnSimilarPairs(x, y); - if (simList.isEmpty()) return; - List x1List = simList.get(0); - List y1List = simList.get(1); - Iterator itx = x1List.iterator(); - Iterator ity = y1List.iterator(); - while (itx.hasNext() && ity.hasNext()) { - Node x1 = itx.next(); - Node y1 = ity.next(); - System.out.println("$$$$$$$$$$$ similar pair x,y = " + x1 + ", " + y1); - System.out.println("removing edge between x = " + x1 + " and y = " + y1); - Edge oldxy = this.graph.getEdge(x1, y1); - this.graph.removeEdge(oldxy); - } - } - } From bce62f4659dbecf9d52e607eaf1ed300b8fce48b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:31:41 -0400 Subject: [PATCH 311/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/TetradTest.java | 2 -- .../edu/cmu/tetrad/search/TetradTestContinuous.java | 12 ------------ .../edu/cmu/tetrad/search/TetradTestDiscrete.java | 8 -------- .../edu/cmu/tetrad/search/TetradTestPopulation.java | 10 ---------- 4 files changed, 32 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java index 536422fa33..c990c94097 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java @@ -41,10 +41,8 @@ public interface TetradTest { boolean tetradScore1(int i, int j, int k, int q); boolean tetradHolds(int i, int j, int k, int q); double tetradPValue(int i, int j, int k, int q); - double tetradPValue(int i1, int j1, int k1, int l1, int i2, int j2, int k2, int l2); boolean oneFactorTest(int a, int b, int c, int d); boolean oneFactorTest(int a, int b, int c, int d, int e); - boolean oneFactorTest(int a, int b, int c, int d, int e, int f); boolean twoFactorTest(int a, int b, int c, int d); boolean twoFactorTest(int a, int b, int c, int d, int e); boolean twoFactorTest(int a, int b, int c, int d, int e, int f); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java index 5809e67a40..9107426811 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java @@ -242,11 +242,6 @@ public double tetradPValue(int v1, int v2, int v3, int v4) { return this.prob[0]; } - public double tetradPValue(int i1, int j1, int k1, int l1, int i2, int j2, int k2, int l2) { - evalTetradDifference(i1, j1, k1, l1, i2, j2, k2, l2); - return this.prob[0]; - } - /** * -------------------------------------------------------------------------- @@ -650,13 +645,6 @@ public boolean oneFactorTest(int v1, int v2, int v3, int v4, int v5) { return this.oneFactorEst5.isSignificant(); } - public boolean oneFactorTest(int v1, int v2, int v3, int v4, int v5, - int v6) { - int[] indices = {v1, v2, v3, v4, v5, v6}; - this.oneFactorEst6.init(indices); - return this.oneFactorEst6.isSignificant(); - } - public boolean twoFactorTest(int v1, int v2, int v3, int v4) { int[] indices = {v1, v2, v3, v4}; this.twoFactorsEst4.init(indices, 2); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java index 57b973eaf4..73f2b6fe94 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java @@ -289,10 +289,6 @@ public double tetradPValue(int v1, int v2, int v3, int v4) { return this.tempProb; } - public double tetradPValue(int i1, int j1, int k1, int l1, int i2, int j2, int k2, int l2) { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - public boolean tetradHolds(int i, int j, int k, int l) { twoFactorTest(i, l, j, k); this.prob[0] = this.tempProb; @@ -513,10 +509,6 @@ public boolean oneFactorTest(int i, int j, int k, int l, int x) { throw new UnsupportedOperationException(); } - public boolean oneFactorTest(int i, int j, int k, int l, int x, int y) { - throw new UnsupportedOperationException(); // Need to remove dependence on PAL. - } - public boolean twoFactorTest(int i, int j, int k, int l) { throw new UnsupportedOperationException(); // Need to remove dependence on PAL. } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java index 8430df398c..e2f406648c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.TetradTest; import org.apache.commons.math3.util.FastMath; import java.util.List; @@ -122,11 +121,6 @@ public boolean oneFactorTest(int a, int b, int c, int d, int e) { tetradScore3(b, c, d, e); } - public boolean oneFactorTest(int a, int b, int c, int d, int e, int f) { - return tetradScore3(a, b, c, d) && tetradScore3(b, c, d, e) && - tetradScore3(c, d, e, f); - } - public boolean twoFactorTest(int a, int b, int c, int d) { tetradScore(a, b, c, d); return this.bvalues[2]; @@ -165,10 +159,6 @@ public double tetradPValue(int v1, int v2, int v3, int v4) { return -1; } - public double tetradPValue(int i1, int j1, int k1, int l1, int i2, int j2, int k2, int l2) { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - public double getSignificance() { return 0; } From 7c868a6c03f9e7465bb94f036b459ba6a0adadd1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:33:35 -0400 Subject: [PATCH 312/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/ShiftSearch.java | 90 +++++++++---------- .../main/java/edu/cmu/tetrad/search/Sp.java | 1 - .../java/edu/cmu/tetrad/search/SpFci.java | 16 ++-- 3 files changed, 52 insertions(+), 55 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java index d470fc4057..d2a3ea91b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java @@ -38,9 +38,7 @@ * @author Joseph Ramsey */ public class ShiftSearch { - private final List dataSets; - private int maxShift = 2; private Knowledge knowledge = new Knowledge(); private int c = 4; @@ -116,6 +114,50 @@ public int[] search() { return bestshifts; } + public int getMaxShift() { + return this.maxShift; + } + + public void setMaxShift(int maxShift) { + this.maxShift = maxShift; + } + + public Knowledge getKnowledge() { + return this.knowledge; + } + + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge((Knowledge) knowledge); + } + + public int getC() { + return this.c; + } + + public void setC(int c) { + this.c = c; + } + + public int getMaxNumShifts() { + return this.maxNumShifts; + } + + public void setMaxNumShifts(int maxNumShifts) { + this.maxNumShifts = maxNumShifts; + } + + public void setOut(OutputStream out) { + this.out = new PrintStream(out); + } + + public void stop() { + this.scheduleStop = true; + } + + public void setForwardSearch(boolean forwardSearch) { + this.forwardSearch = forwardSearch; + } + private void printShifts(int[] shifts, double b, List nodes) { StringBuilder buf = new StringBuilder(); @@ -173,50 +215,6 @@ private double getAvgBic(List dataSets) { images.search(); return -images.getModelScore() / dataSets.size(); } - - public int getMaxShift() { - return this.maxShift; - } - - public void setMaxShift(int maxShift) { - this.maxShift = maxShift; - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - public int getC() { - return this.c; - } - - public void setC(int c) { - this.c = c; - } - - public int getMaxNumShifts() { - return this.maxNumShifts; - } - - public void setMaxNumShifts(int maxNumShifts) { - this.maxNumShifts = maxNumShifts; - } - - public void setOut(OutputStream out) { - this.out = new PrintStream(out); - } - - public void stop() { - this.scheduleStop = true; - } - - public void setForwardSearch(boolean forwardSearch) { - this.forwardSearch = forwardSearch; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 29dc0b0ba4..d7f14e076a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -36,7 +36,6 @@ public class Sp implements SuborderSearch { private Map gsts; private Knowledge knowledge = new Knowledge(); - /** * This algorithm will work with an arbitrary score. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 1210be574f..dffa5054dc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -289,6 +289,14 @@ public void setIndependenceTest(IndependenceTest independenceTest) { this.independenceTest = independenceTest; } + public void setDepth(int depth) { + this.depth = depth; + } + + public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { + this.doDiscriminatingPathRule = doDiscriminatingPathRule; + } + //===========================================PRIVATE METHODS=======================================// /** @@ -340,12 +348,4 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) this.logger.log("info", "Finishing BK Orientation."); } - public void setDepth(int depth) { - this.depth = depth; - } - - - public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { - this.doDiscriminatingPathRule = doDiscriminatingPathRule; - } } From 2e6a90c0517b8bbf0c84c4d5363ad0cd6e9f7d34 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:34:23 -0400 Subject: [PATCH 313/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/search/SepsetsPossibleDsep.java | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java index bbe6e015c9..464e07e8df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java @@ -80,6 +80,30 @@ public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { return sepset != null && sepset.contains(j); } + @Override + public double getScore() { + return -(this.result.getPValue() - this.test.getAlpha()); + } + + @Override + public List getVariables() { + return this.test.getVariables(); + } + + public boolean isVerbose() { + return this.verbose; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + @Override + public boolean isIndependent(Node d, Node c, List path) { + IndependenceResult result = this.test.checkIndependence(d, c, path); + return result.isIndependent(); + } + private List getCondSet(Node node1, Node node2, int maxPathLength) { List possibleDsepSet = getPossibleDsep(node1, node2, maxPathLength); List possibleDsep = new ArrayList<>(possibleDsepSet); @@ -132,30 +156,5 @@ private List getPossibleDsep(Node x, Node y, int maxPathLength) { return dsep; } - - @Override - public double getScore() { - return -(this.result.getPValue() - this.test.getAlpha()); - } - - @Override - public List getVariables() { - return this.test.getVariables(); - } - - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public boolean isIndependent(Node d, Node c, List path) { - IndependenceResult result = this.test.checkIndependence(d, c, path); - return result.isIndependent(); - } - } From b8f8a4f37c0f8f9624fa0dd168ab7f4e89207cdf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:41:57 -0400 Subject: [PATCH 314/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetradapp/editor/CPDAGDisplay.java | 8 +- .../edu/cmu/tetradapp/editor/PagColorer.java | 4 +- .../tetradapp/editor/ScoredGraphsDisplay.java | 4 +- .../KnowledgeEditorToolbar.java | 4 +- .../cmu/tetradapp/model/CPDAGFitModel.java | 8 +- .../model/CPDAGFromDagGraphWrapper.java | 4 +- .../tetradapp/model/DagInCPDAGWrapper.java | 4 +- .../model/EdgewiseComparisonModel.java | 8 +- .../model/ExtractStructureModelWrapper.java | 4 +- .../edu/cmu/tetradapp/model/FasRunner.java | 2 +- .../edu/cmu/tetradapp/model/FciRunner.java | 2 +- .../model/GeneralAlgorithmRunner.java | 2 +- .../cmu/tetradapp/model/MagInPagWrapper.java | 4 +- .../tetradapp/model/Misclassifications.java | 6 +- .../model/PValueImproverWrapper.java | 4 +- .../model/PagFromDagGraphWrapper.java | 4 +- .../edu/cmu/tetradapp/model/PcRunner.java | 2 +- .../tetradapp/model/SampleVcpcFastRunner.java | 2 +- .../cmu/tetradapp/model/SampleVcpcRunner.java | 2 +- .../tetradapp/model/ScoredGraphsWrapper.java | 4 +- .../cmu/tetradapp/model/VcpcFastRunner.java | 2 +- .../edu/cmu/tetradapp/model/VcpcRunner.java | 2 +- .../cmu/tetradapp/workbench/LayoutUtils.java | 4 +- .../cmu/tetrad/algcomparison/Comparison.java | 14 +- .../algcomparison/TimeoutComparison.java | 8 +- .../algcomparison/algorithm/cluster/Bpc.java | 2 +- .../algcomparison/algorithm/cluster/Fofc.java | 2 +- .../algcomparison/algorithm/cluster/Ftfc.java | 4 +- .../algorithm/multi/FgesConcatenated.java | 4 +- .../algorithm/oracle/cpdag/Cpc.java | 4 +- .../algorithm/oracle/cpdag/Fas.java | 4 +- .../oracle/cpdag/FgesMeasurement.java | 4 +- .../algorithm/oracle/cpdag/GesMe.java | 4 +- .../algorithm/oracle/cpdag/Pc.java | 4 +- .../algorithm/oracle/cpdag/PcMax.java | 4 +- .../algorithm/oracle/cpdag/Pcd.java | 4 +- .../algorithm/oracle/pag/Bfci.java | 2 +- .../algorithm/oracle/pag/Cfci.java | 2 +- .../algorithm/oracle/pag/Fci.java | 2 +- .../algorithm/oracle/pag/FciMax.java | 2 +- .../algorithm/oracle/pag/Gfci.java | 2 +- .../algorithm/oracle/pag/GraspFci.java | 2 +- .../algorithm/oracle/pag/PagSampleRfci.java | 2 +- .../algorithm/oracle/pag/Rfci.java | 2 +- .../algorithm/oracle/pag/RfciBsc.java | 2 +- .../algorithm/oracle/pag/SpFci.java | 2 +- .../algcomparison/statistic/BicDiff.java | 6 +- .../statistic/BicDiffPerRecord.java | 6 +- .../algcomparison/statistic/BicEst.java | 4 +- .../algcomparison/statistic/BicTrue.java | 4 +- .../algcomparison/statistic/BidirectedFP.java | 2 +- .../statistic/BidirectedPrecision.java | 2 +- .../statistic/BidirectedRecall.java | 2 +- .../algcomparison/statistic/BidirectedTP.java | 2 +- .../statistic/BidirectedTrue.java | 2 +- ...CommonAncestorFalseNegativeBidirected.java | 2 +- .../DefiniteDirectedPathPrecision.java | 4 +- .../statistic/DefiniteDirectedPathRecall.java | 4 +- ...CommonAncestorFalseNegativeBidirected.java | 2 +- .../algcomparison/statistic/LegalPag.java | 4 +- .../statistic/MaximalityCondition.java | 4 +- .../NoAlmostCyclicPathsInMagCondition.java | 4 +- .../NoCyclicPathsInMagCondition.java | 4 +- .../statistic/NoSemidirectedPrecision.java | 4 +- .../statistic/NoSemidirectedRecall.java | 4 +- ...mpatibleDefiniteDirectedEdgeAncestors.java | 4 +- .../NumCompatibleDirectedEdgeConfounded.java | 4 +- .../statistic/NumCompatibleEdges.java | 4 +- ...mpatiblePossiblyDirectedEdgeAncestors.java | 4 +- ...tiblePossiblyDirectedEdgeNonAncestors.java | 4 +- .../NumCompatibleVisibleAncestors.java | 4 +- .../NumCompatibleVisibleNonancestors.java | 4 +- .../statistic/NumDefinitelyDirected.java | 4 +- .../NumDefinitelyNotDirectedPaths.java | 4 +- .../statistic/NumDirectedEdgeVisible.java | 4 +- .../statistic/NumPossiblyDirected.java | 4 +- .../statistic/PagAdjacencyPrecision.java | 2 +- .../statistic/PagAdjacencyRecall.java | 2 +- .../tetrad/algcomparison/statistic/Shd.java | 4 +- .../calibration/DataForCalibrationRfci.java | 3 +- .../java/edu/cmu/tetrad/graph/GraphUtils.java | 6 +- .../main/java/edu/cmu/tetrad/search/BFci.java | 12 +- .../main/java/edu/cmu/tetrad/search/Cfci.java | 12 +- .../main/java/edu/cmu/tetrad/search/Cpc.java | 4 +- .../cmu/tetrad/search/FasDeterministic.java | 6 +- .../main/java/edu/cmu/tetrad/search/Fask.java | 2 +- .../java/edu/cmu/tetrad/search/FciOrient.java | 34 ++-- .../main/java/edu/cmu/tetrad/search/Fges.java | 2 +- .../edu/cmu/tetrad/search/FgesOrienter.java | 2 +- .../main/java/edu/cmu/tetrad/search/GFci.java | 12 +- ...hGraphUtils.java => GraphUtilsSearch.java} | 170 +++++------------- .../java/edu/cmu/tetrad/search/GraspFci.java | 12 +- .../cmu/tetrad/search/IndTestChiSquare.java | 2 +- .../search/IndTestConditionalCorrelation.java | 2 +- .../search/IndTestConditionalGaussianLrt.java | 2 +- .../edu/cmu/tetrad/search/IndTestDSep.java | 2 +- .../search/IndTestDegenerateGaussianLrt.java | 2 +- .../edu/cmu/tetrad/search/IndTestFisherZ.java | 4 +- .../IndTestFisherZConcatenateResiduals.java | 2 +- .../search/IndTestFisherZFisherPValue.java | 2 +- .../edu/cmu/tetrad/search/IndTestGSquare.java | 2 +- .../edu/cmu/tetrad/search/IndTestHsic.java | 2 +- .../search/IndTestIndependenceFacts.java | 2 +- .../edu/cmu/tetrad/search/IndTestMnlrLr.java | 2 +- .../edu/cmu/tetrad/search/IndTestMulti.java | 4 +- .../edu/cmu/tetrad/search/IndTestMvpLrt.java | 2 +- .../tetrad/search/IndTestPositiveCorr.java | 2 +- .../tetrad/search/IndTestProbabilistic.java | 2 +- .../cmu/tetrad/search/IndTestRegression.java | 6 +- .../edu/cmu/tetrad/search/IndTestScore.java | 3 +- .../main/java/edu/cmu/tetrad/search/Kpc.java | 4 +- .../edu/cmu/tetrad/search/LingamPattern.java | 4 +- ...earchLogUtils.java => LogUtilsSearch.java} | 7 +- .../main/java/edu/cmu/tetrad/search/MaxP.java | 2 +- .../java/edu/cmu/tetrad/search/MbUtils.java | 4 +- .../java/edu/cmu/tetrad/search/MeekRules.java | 8 +- .../main/java/edu/cmu/tetrad/search/Pc.java | 4 +- .../java/edu/cmu/tetrad/search/PcCommon.java | 6 +- .../java/edu/cmu/tetrad/search/PcMax.java | 4 +- .../main/java/edu/cmu/tetrad/search/PcMb.java | 2 +- .../main/java/edu/cmu/tetrad/search/Pcd.java | 4 +- .../edu/cmu/tetrad/search/RBExperiments.java | 6 +- .../edu/cmu/tetrad/search/ResolveSepsets.java | 8 +- .../main/java/edu/cmu/tetrad/search/Rfci.java | 12 +- .../edu/cmu/tetrad/search/SepsetProducer.java | 6 - .../edu/cmu/tetrad/search/SepsetsGreedy.java | 83 +++++---- .../java/edu/cmu/tetrad/search/SpFci.java | 14 +- .../edu/cmu/tetrad/search/SvarFciOrient.java | 50 +++--- .../java/edu/cmu/tetrad/search/SvarGfci.java | 12 +- .../java/edu/cmu/tetrad/search/TsFas.java | 6 +- .../edu/cmu/tetrad/search/WIP/FasFdr.java | 2 +- .../edu/cmu/tetrad/search/WIP/HbmsBeam.java | 6 +- .../edu/cmu/tetrad/search/WIP/HbsmsGes.java | 8 +- .../cmu/tetrad/search/WIP/IndTestCramerT.java | 6 +- .../WIP/IndTestFisherZGeneralizedInverse.java | 8 +- .../WIP/IndTestFisherZPercentIndependent.java | 4 +- .../search/WIP/IndTestFisherZRecursive.java | 6 +- .../search/WIP/IndTestMixedMultipleTTest.java | 6 +- .../IndTestMultinomialLogisticRegression.java | 8 +- .../tetrad/search/WIP/IndTestSepsetDci.java | 7 +- .../java/edu/cmu/tetrad/search/WIP/Ion.java | 4 +- .../WIP/ProbabilisticMapIndependence.java | 4 +- .../tetrad/search/WIP/ResolveSepsetsDci.java | 10 +- .../edu/cmu/tetrad/search/WIP/SampleVcpc.java | 10 +- .../cmu/tetrad/search/WIP/SampleVcpcFast.java | 10 +- .../java/edu/cmu/tetrad/search/WIP/VcPc.java | 4 +- .../edu/cmu/tetrad/search/WIP/VcPcAlt.java | 10 +- .../edu/cmu/tetrad/search/WIP/VcPcFast.java | 4 +- .../tetrad/simulation/GdistanceRandom.java | 6 +- .../edu/cmu/tetrad/simulation/HsimAutoC.java | 4 +- .../cmu/tetrad/simulation/HsimAutoRun.java | 4 +- .../tetrad/simulation/HsimEvalFromData.java | 4 +- .../tetrad/simulation/HsimRobustCompare.java | 4 +- .../edu/cmu/tetrad/simulation/HsimRun.java | 6 +- .../edu/cmu/tetrad/simulation/HsimUtils.java | 4 +- .../tetrad/study/performance/Comparison.java | 12 +- .../tetrad/study/performance/Comparison2.java | 16 +- .../study/performance/PerformanceTests.java | 30 ++-- .../performance/PerformanceTestsDan.java | 2 +- .../edu/pitt/csb/mgm/ExploreIndepTests.java | 10 +- ...TestMultinomialLogisticRegressionWald.java | 10 +- .../constraint/search/PagSamplingRfci.java | 5 +- .../bayesian/constraint/search/RfciBsc.java | 2 +- .../edu/cmu/tetrad/test/TestCheckMarkov.java | 4 +- .../tetrad/test/TestDagInPatternIterator.java | 6 +- .../cmu/tetrad/test/TestEdgeListGraph.java | 4 +- .../java/edu/cmu/tetrad/test/TestFci.java | 2 +- .../java/edu/cmu/tetrad/test/TestFges.java | 14 +- .../java/edu/cmu/tetrad/test/TestGFci.java | 6 +- .../test/TestGeneralResamplingTest.java | 10 +- .../java/edu/cmu/tetrad/test/TestGrasp.java | 20 +-- .../edu/cmu/tetrad/test/TestMimbuild.java | 4 +- .../test/java/edu/cmu/tetrad/test/TestPc.java | 4 +- .../java/edu/cmu/tetrad/test/TestRfciBsc.java | 6 +- .../edu/cmu/tetrad/test/TestSearchGraph.java | 4 +- 175 files changed, 542 insertions(+), 636 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{SearchGraphUtils.java => GraphUtilsSearch.java} (90%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{SearchLogUtils.java => LogUtilsSearch.java} (96%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java index d37eb0ebde..9975f3a14e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.workbench.DisplayEdge; @@ -49,7 +49,7 @@ public class CPDAGDisplay extends JPanel implements GraphEditable { private GraphWorkbench workbench; public CPDAGDisplay(Graph graph) { - List dags = SearchGraphUtils.generateCpdagDags(graph, false); + List dags = GraphUtilsSearch.generateCpdagDags(graph, false); if (dags.size() == 0) { JOptionPane.showMessageDialog( @@ -81,7 +81,7 @@ public CPDAGDisplay(Graph graph) { String option = (String) box.getSelectedItem(); if ("Orient --- only".equals(option)) { - List _dags = SearchGraphUtils.generateCpdagDags(graph, false); + List _dags = GraphUtilsSearch.generateCpdagDags(graph, false); dags.clear(); dags.addAll(_dags); SpinnerNumberModel model1 = @@ -97,7 +97,7 @@ public CPDAGDisplay(Graph graph) { totalLabel.setText(" of " + dags.size()); CPDAGDisplay.this.workbench.setGraph(dags.get(0)); } else if ("Orient ---, <->".equals(option)) { - List _dags = SearchGraphUtils.generateCpdagDags(graph, true); + List _dags = GraphUtilsSearch.generateCpdagDags(graph, true); dags.clear(); dags.addAll(_dags); SpinnerNumberModel model1 = diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java index a3f120020a..44c484ba25 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetradapp.workbench.GraphWorkbench; import javax.swing.*; @@ -60,7 +60,7 @@ public PagColorer(GraphWorkbench workbench) { breakDown("Would you like to verify that this is a legal PAG?", 60), "Legal PAG check", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (ret == JOptionPane.YES_NO_OPTION) { - SearchGraphUtils.LegalPagRet legalPag = SearchGraphUtils.isLegalPag(graph); + GraphUtilsSearch.LegalPagRet legalPag = GraphUtilsSearch.isLegalPag(graph); String reason = breakDown(legalPag.getReason(), 60); if (!legalPag.isLegalPag()) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java index 17dafd2ae2..34c4944be7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.DagScorer; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.model.ScoredGraphsWrapper; @@ -72,7 +72,7 @@ public ScoredGraphsDisplay(ScoredGraphsWrapper scoredGraphsWrapper) { } public ScoredGraphsDisplay(Graph graph, DagScorer scorer) { - List _dags = SearchGraphUtils.generateCpdagDags(graph, true); + List _dags = GraphUtilsSearch.generateCpdagDags(graph, true); for (Graph _graph : _dags) { double score = Double.NaN; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java index 2719dd914f..98af33e6e1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetradapp.util.ImageUtils; import edu.cmu.tetradapp.workbench.AbstractWorkbench; @@ -234,7 +234,7 @@ private void setWorkbenchMode(JToggleButton button) { KnowledgeGraph graph = (KnowledgeGraph) this.workbench.getGraph(); Knowledge knowledge = graph.getKnowledge(); try { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); this.workbench.setGraph(graph); } catch (IllegalArgumentException ex) { System.out.print(ex.getMessage()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java index 5866078c01..72bea687c1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.graph.SemGraph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -89,7 +89,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn for (int i = 0; i < dataModels.size(); i++) { DataSet dataSet = (DataSet) dataModels.get(0); - Graph dag = SearchGraphUtils.dagFromCPDAG(graphs.get(0)); + Graph dag = GraphUtilsSearch.dagFromCPDAG(graphs.get(0)); BayesPm pm = new BayesPmWrapper(dag, new DataWrapper(dataSet)).getBayesPm(); this.bayesPms.add(pm); this.bayesIms.add(estimate(dataSet, pm)); @@ -100,7 +100,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn for (int i = 0; i < dataModels.size(); i++) { DataSet dataSet = (DataSet) dataModels.get(0); - Graph dag = SearchGraphUtils.dagFromCPDAG(graphs.get(0)); + Graph dag = GraphUtilsSearch.dagFromCPDAG(graphs.get(0)); try { SemPm pm = new SemPm(dag); @@ -109,7 +109,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn } catch (Exception e) { e.printStackTrace(); - Graph mag = SearchGraphUtils.pagToMag(graphs.get(0)); + Graph mag = GraphUtilsSearch.pagToMag(graphs.get(0)); // Ricf.RicfResult result = estimatePag(dataSet, mag); SemGraph graph = new SemGraph(mag); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java index a6378b941c..620e8e1af2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Dag; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -66,7 +66,7 @@ public static CPDAGFromDagGraphWrapper serializableInstance() { private static Graph getCPDAG(Graph graph) { - return SearchGraphUtils.cpdagFromDag(graph); + return GraphUtilsSearch.cpdagFromDag(graph); } @Override diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java index cb1e2e1d39..beb3eea6a2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -47,7 +47,7 @@ public DagInCPDAGWrapper(Graph graph) { } private static Graph getGraph(Graph graph) { - return SearchGraphUtils.dagFromCPDAG(graph); + return GraphUtilsSearch.dagFromCPDAG(graph); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java index 64ea9f5ecf..6c6d94eb42 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -33,7 +33,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** @@ -112,7 +112,7 @@ public String getComparisonString() { Graph comparisonGraph = getComparisonGraph(referenceGraph, params); - return SearchGraphUtils.graphComparisonString(refName, comparisonGraph, + return GraphUtilsSearch.graphComparisonString(refName, comparisonGraph, targetName, this.targetGraph, false); } @@ -143,7 +143,7 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return SearchGraphUtils.cpdagForDag(graph); + return GraphUtilsSearch.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); return dagToPag(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java index 9d59ff000b..5f202aef09 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -80,7 +80,7 @@ public static ExtractStructureModelWrapper serializableInstance() { private static Graph getCPDAG(Dag dag) { - return SearchGraphUtils.cpdagFromDag(dag); + return GraphUtilsSearch.cpdagFromDag(dag); } @Override diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index 63e49378c8..094c2aecde 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -146,7 +146,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java index 84f17bfae4..419c68c3eb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java @@ -128,7 +128,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index 58021f195a..3aa6f88b19 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -406,7 +406,7 @@ public void execute() { if (_knowledge.getVariablesNotInTiers().size() < _knowledge.getVariables().size()) { for (Graph graph : graphList) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, _knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, _knowledge); } } } else { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java index 61133a4df9..8c04db5159 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -47,7 +47,7 @@ public MagInPagWrapper(Graph graph) { } private static Graph getGraph(Graph graph) { - return SearchGraphUtils.pagToMag(graph); + return GraphUtilsSearch.pagToMag(graph); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java index 03b20e605c..7ca91f17c5 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.MisclassificationUtils; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -34,7 +34,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** @@ -150,7 +150,7 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return SearchGraphUtils.cpdagForDag(graph); + return GraphUtilsSearch.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); return dagToPag(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index 477f5feed4..6791dbc338 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -257,12 +257,12 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(this.graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(this.graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(this.graph, knowledge); } else { LayoutUtil.circleLayout(this.graph, 200, 200, 150); } - setResultGraph(SearchGraphUtils.cpdagForDag(this.graph)); + setResultGraph(GraphUtilsSearch.cpdagForDag(this.graph)); } public boolean supportsKnowledge() { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java index d204d807d7..7a3c82724d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -47,7 +47,7 @@ public PagFromDagGraphWrapper(Graph graph) { throw new IllegalArgumentException("The source graph is not a DAG."); } - Graph pag = SearchGraphUtils.dagToPag(graph); + Graph pag = GraphUtilsSearch.dagToPag(graph); setGraph(pag); TetradLogger.getInstance().log("info", "\nGenerating allow_latent_common_causes from DAG."); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index 67313bd93c..0f66696f1e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -143,7 +143,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 4e60d60a10..60323bcbac 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -159,7 +159,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index 0904eb54e1..972fd5da78 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -193,7 +193,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java index 375908134f..d97a512cc3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.DagScorer; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -73,7 +73,7 @@ private ScoredGraphsWrapper() { } public ScoredGraphsWrapper(Graph graph, DagScorer scorer) { - List dags = SearchGraphUtils.generateCpdagDags(graph, true); + List dags = GraphUtilsSearch.generateCpdagDags(graph, true); this.graphsToScores = new HashMap<>(); this.graphScorer = scorer; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index a9e82eb166..4413323fd9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -185,7 +185,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 97e7e56306..e86919e961 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -185,7 +185,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java index cb18b9e554..ece6b1e2a1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetradapp.util.GraphEditorUtils; import edu.cmu.tetradapp.util.LayoutEditable; @@ -487,7 +487,7 @@ public static void knowledgeLayout(LayoutEditable layoutEditable) { } Knowledge knowledge = layoutEditable.getKnowledge(); - SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge); + GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); layoutEditable.layoutByGraph(graph); } catch (Exception e1) { JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java index 9c837ebceb..80af45b7c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java @@ -41,7 +41,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; @@ -563,12 +563,12 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param if (isSaveCPDAGs()) { File file3 = new File(dir3, "cpdag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(SearchGraphUtils.cpdagForDag(graph), file3, false); + GraphPersistence.saveGraph(GraphUtilsSearch.cpdagForDag(graph), file3, false); } if (isSavePags()) { File file4 = new File(dir4, "pag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(SearchGraphUtils.dagToPag(graph), file4, false); + GraphPersistence.saveGraph(GraphUtilsSearch.dagToPag(graph), file4, false); } } @@ -650,12 +650,12 @@ public void saveToFilesSingleSimulation(String dataPath, Simulation simulation, if (isSaveCPDAGs()) { File file3 = new File(dir3, "cpdag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(SearchGraphUtils.cpdagForDag(graph), file3, false); + GraphPersistence.saveGraph(GraphUtilsSearch.cpdagForDag(graph), file3, false); } if (isSavePags()) { File file4 = new File(dir4, "pag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(SearchGraphUtils.dagToPag(graph), file4, false); + GraphPersistence.saveGraph(GraphUtilsSearch.dagToPag(graph), file4, false); } } } catch (IOException e) { @@ -1236,9 +1236,9 @@ private void doRun(List algorithmSimulationWrappers, if (this.comparisonGraph == ComparisonGraph.true_DAG) { comparisonGraph = new EdgeListGraph(trueGraph); } else if (this.comparisonGraph == ComparisonGraph.CPDAG_of_the_true_DAG) { - comparisonGraph = SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueGraph)); + comparisonGraph = GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueGraph)); } else if (this.comparisonGraph == ComparisonGraph.PAG_of_the_true_DAG) { - comparisonGraph = SearchGraphUtils.dagToPag(trueGraph); + comparisonGraph = GraphUtilsSearch.dagToPag(trueGraph); } else { throw new IllegalArgumentException("Unrecognized graph type."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java index 6d1b851d1e..8d8a58f76c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java @@ -39,7 +39,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; @@ -53,7 +53,7 @@ import java.util.*; import java.util.concurrent.*; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Nov 14, 2017 12:00:31 PM @@ -508,7 +508,7 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param if (isSaveCPDAGs()) { File file3 = new File(dir3, "pattern." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(SearchGraphUtils.cpdagForDag(graph), file3, false); + GraphPersistence.saveGraph(GraphUtilsSearch.cpdagForDag(graph), file3, false); } if (isSavePags()) { @@ -1148,7 +1148,7 @@ private void doRun(List algorithmSimulationWrappers, if (this.comparisonGraph == ComparisonGraph.true_DAG) { comparisonGraph = new EdgeListGraph(trueGraph); } else if (this.comparisonGraph == ComparisonGraph.CPDAG_of_the_true_DAG) { - comparisonGraph = SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueGraph)); + comparisonGraph = GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueGraph)); } else if (this.comparisonGraph == ComparisonGraph.PAG_of_the_true_DAG) { comparisonGraph = dagToPag(new EdgeListGraph(trueGraph)); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index 3ec375d101..eff1398535 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -117,7 +117,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index 788c7492bf..9cfe543840 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -131,7 +131,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(graph); + return GraphUtilsSearch.cpdagForDag(graph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java index 9b76631f19..7f4b0ee9ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -78,7 +78,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java index d67ccb29de..db70b013bf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -135,7 +135,7 @@ public Graph getComparisonGraph(Graph graph) { if (this.compareToTrue) { return new EdgeListGraph(graph); } else { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } } 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 691da02b8c..ef9cbb329f 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 @@ -13,7 +13,7 @@ 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.search.GraphUtilsSearch; import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -88,7 +88,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } @Override 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 a6aaca268d..3500dde048 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 @@ -13,7 +13,7 @@ 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.search.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -82,7 +82,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } @Override 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/FgesMeasurement.java index 70f85431f7..f4d0dcc5bd 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/FgesMeasurement.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.RandomUtil; @@ -85,7 +85,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } @Override 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/GesMe.java index 84c0ffcaf3..c90415d5e2 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/GesMe.java @@ -11,7 +11,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import org.apache.commons.math3.util.FastMath; @@ -191,7 +191,7 @@ public Graph getComparisonGraph(Graph graph) { if (this.compareToTrue) { return new EdgeListGraph(graph); } else { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } } 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 d74b052e92..e4c0b57361 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 @@ -13,7 +13,7 @@ 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.search.GraphUtilsSearch; import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -90,7 +90,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } @Override 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 0de7df54b4..2d572618ea 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 @@ -13,7 +13,7 @@ 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.search.GraphUtilsSearch; import edu.cmu.tetrad.search.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -90,7 +90,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); + return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); } @Override 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 index e00bf1701b..f73ee815ca 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 @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -71,7 +71,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(graph); + return GraphUtilsSearch.cpdagForDag(graph); } @Override 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 f6fa0c07f5..1d35427b5a 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 @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** 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 index 77746d530c..b1f11b716e 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 @@ -19,7 +19,7 @@ import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Conserative FCI. 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 index 95d2d17a6e..9e606cbd9b 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 @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * FCI. 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/FciMax.java index 81e3808669..94a4f47fd0 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/FciMax.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * FCI. 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 a53717685e..971552d36d 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 @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index 44c39f9942..3be6cafc29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java index 75aea0f857..f0c3a74d0d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java @@ -18,7 +18,7 @@ import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Jan 29, 2023 3:45:09 PM 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 index 5458042f08..4d97e9e2e4 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 @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * RFCI. 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/RfciBsc.java index 8ddb6f4374..5b8011ff11 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/RfciBsc.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Jan 4, 2019 4:32:05 PM 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/SpFci.java index df6c77a477..89a774d692 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/SpFci.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java index 8aa81889dc..076fe19ccb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; @@ -27,8 +27,8 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - double _true = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(trueGraph), dataModel); - double est = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(estGraph), dataModel); + double _true = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(trueGraph), dataModel); + double est = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(estGraph), dataModel); return (_true - est); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java index 2bb4286413..51707d2efe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.abs; @@ -30,8 +30,8 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - double _true = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(trueGraph), dataModel); - double est = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(estGraph), dataModel); + double _true = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(trueGraph), dataModel); + double est = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(estGraph), dataModel); if (abs(_true) < 0.0001) _true = 0.0; if (abs(est) < 0.0001) est = 0.0; return (_true - est) / ((DataSet) dataModel).getNumRows(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java index 02cba0d8e4..985495d77f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; @@ -28,7 +28,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { // double _true = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(trueGraph), dataModel); - return SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(estGraph), dataModel); + return SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(estGraph), dataModel); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java index 3f75f51a12..e874dd6aef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; @@ -28,7 +28,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { // double est = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(estGraph), dataModel); - return SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(trueGraph), dataModel); + return SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(trueGraph), dataModel); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java index 635a6bd0e4..a1f86c6b24 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The bidirected false negatives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java index cd124147aa..422a18b241 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The bidirected edge precision. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java index 2ded1140c5..ec377259de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The bidirected edge precision. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java index a8fed31f98..147d36f88f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java index 42b717c3ce..4cba0b3671 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java index 3e0ddc9123..bedc5a2ed2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,7 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.CommonAncestorTruePositiveBidirected.existsCommonAncestor; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java index ef9fdc6bbc..99a4c9c19d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import java.util.List; @@ -32,7 +32,7 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fp = 0; List nodes = trueGraph.getNodes(); - Graph cpdag = SearchGraphUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); GraphUtils.addPagColoring(estGraph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java index eb147683ce..2db0964171 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import java.util.List; @@ -30,7 +30,7 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fn = 0; List nodes = trueGraph.getNodes(); - Graph cpdag = SearchGraphUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); for (Node x : nodes) { for (Node y : nodes) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java index 048adf663d..5851a0f693 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,7 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java index 57f1e05df6..033597271a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; /** * Legal PAG @@ -24,7 +24,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - SearchGraphUtils.LegalPagRet legalPag = SearchGraphUtils.isLegalPag(estGraph); + GraphUtilsSearch.LegalPagRet legalPag = GraphUtilsSearch.isLegalPag(estGraph); System.out.println(legalPag.getReason()); if (legalPag.isLegalPag()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java index c5aa44ba30..c210002e47 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import java.util.List; @@ -27,7 +27,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { Graph pag = estGraph; - Graph mag = SearchGraphUtils.pagToMag(estGraph); + Graph mag = GraphUtilsSearch.pagToMag(estGraph); List nodes = pag.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java index 845b1c4838..7da9ff76db 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; /** * @author jdramsey @@ -25,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph mag = SearchGraphUtils.pagToMag(estGraph); + Graph mag = GraphUtilsSearch.pagToMag(estGraph); for (Edge e : mag.getEdges()) { Node x = e.getNode1(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java index 341497f8e0..14f17f744e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; /** * @author jdramsey @@ -23,7 +23,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph mag = SearchGraphUtils.pagToMag(estGraph); + Graph mag = GraphUtilsSearch.pagToMag(estGraph); for (Node n : mag.getNodes()) { if (mag.paths().existsDirectedPathFromTo(n, n)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java index d3b03a239e..40ed117429 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import java.util.List; @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fp = 0; - Graph cpdag = SearchGraphUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); List nodes = estGraph.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java index 60bb038fe1..d1d894d1ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import java.util.List; @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fn = 0; - Graph cpdag = SearchGraphUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); List nodes = trueGraph.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java index 5c2ce5bcd9..c724f833ff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java index 98fc9ca409..87c398e5e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java index 0c7e904f3a..e99cff0d46 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -30,7 +30,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java index 4c4f7bd90d..a995c074dc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java index cc297a4674..4c99942c4e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java index 957465bf5a..0dc0dff6d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java index ba1f067999..a7a16cff0a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -29,7 +29,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java index 82bdc88fd6..06bec2427a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; /** * The bidirected true positives. @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = SearchGraphUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java index 89449aacac..d909a5ec2f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; /** * The bidirected true positives. @@ -26,7 +26,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = SearchGraphUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java index b12f204197..c59c614d3e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; /** * @author jdramsey @@ -25,7 +25,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0; - Graph pag = SearchGraphUtils.dagToPag(trueGraph); + Graph pag = GraphUtilsSearch.dagToPag(trueGraph); for (Edge edge : pag.getEdges()) { if (pag.paths().defVisible(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java index 4d3a832eca..d08d5fd033 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; /** * The bidirected true positives. @@ -26,7 +26,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = SearchGraphUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java index 1da11dfa38..725d422274 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The adjacency precision. The true positives are the number of adjacencies in both diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java index 60b683c12d..51ff800135 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * The adjacency recall. The true positives are the number of adjacencies in both diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java index aa11109d35..13519abb86 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import org.apache.commons.math3.util.FastMath; /** @@ -27,7 +27,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - GraphUtils.GraphComparison comparison = SearchGraphUtils.getGraphComparison(trueGraph, estGraph); + GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison(trueGraph, estGraph); return comparison.getShd(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java index ab9422d0ea..d781cf3a57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java @@ -1,6 +1,5 @@ package edu.cmu.tetrad.calibration; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Bfci; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataUtils; @@ -108,7 +107,7 @@ public static void main(String[] args) throws IOException { // // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(dag); + Graph truePag = GraphUtilsSearch.dagToPag(dag); System.out.println("true PAG construction Done!"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index 9c90538244..8ffb68b5e9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge.Property; import edu.cmu.tetrad.search.FciOrient; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.ForkJoinPoolInstance; @@ -35,7 +35,7 @@ import java.util.*; import java.util.concurrent.RecursiveTask; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Basic graph utilities. @@ -1766,7 +1766,7 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return SearchGraphUtils.cpdagForDag(graph); + return GraphUtilsSearch.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); return dagToPag(graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 1f6d9d260c..01cff711a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -269,8 +269,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -282,15 +282,15 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) // Orient to*->from graph.setEndpoint(to, from, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it = knowledge.requiredEdgesIterator(); it.hasNext(); ) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -302,7 +302,7 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index d6fb73db7c..6715ce78cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -520,8 +520,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -535,7 +535,7 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { graph.setEndpoint(to, from, Endpoint.ARROW); if (this.verbose) { - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } } @@ -544,8 +544,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -566,7 +566,7 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { graph.setEndpoint(from, to, Endpoint.ARROW); if (this.verbose) { - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } } 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 d4bae11f0a..22a6cedfb5 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 @@ -281,8 +281,8 @@ public Graph search() { this.graph = search.search(); this.sepsets = fas.getSepsets(); - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, independenceTest.getVariables()); - SearchGraphUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, independenceTest.getVariables()); + GraphUtilsSearch.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); TetradLogger.getInstance().log("graph", "\nReturning this graph: " + this.graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index 57d3de3f76..905ad6d610 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -290,11 +290,11 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map variables) { 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -1030,7 +1030,7 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { // Orient to*->from graph.setEndpoint(to, from, Endpoint.ARROW); this.changeFlag = true; - this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.forceLogMessage(LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it @@ -1042,8 +1042,8 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -1056,7 +1056,7 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); this.changeFlag = true; - this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.forceLogMessage(LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.forceLogMessage("Finishing BK Orientation."); @@ -1239,7 +1239,7 @@ public void ruleR10(Node a, Node c, Graph graph) { graph.setEndpoint(c, a, Endpoint.TAIL); if (verbose) { - this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("R10: ", graph.getEdge(c, a))); + this.logger.forceLogMessage(LogUtilsSearch.edgeOrientedMsg("R10: ", graph.getEdge(c, a))); } this.changeFlag = true; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 0c4624a365..b5a180dda2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -208,7 +208,7 @@ public Graph search() { this.logger.forceLogMessage("Elapsed time = " + (elapsedTime) / 1000. + " s"); } - this.modelScore = scoreDag(SearchGraphUtils.dagFromCPDAG(graph), true); + this.modelScore = scoreDag(GraphUtilsSearch.dagFromCPDAG(graph), true); return graph; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java index bc474bfbe4..95d3fc4840 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java @@ -1362,7 +1362,7 @@ private Set reorientNode(Graph graph, Node a) { nodes.add(a); List edges = graph.getEdges(a); - SearchGraphUtils.basicCpdagRestricted2(graph, a); + GraphUtilsSearch.basicCpdagRestricted2(graph, a); addRequiredEdges(graph); Set visited = meekOrientRestricted(graph, getKnowledge()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index 876def5f58..f7f3c374a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -278,8 +278,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -291,15 +291,15 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) // Orient to*->from graph.setEndpoint(to, from, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it = knowledge.requiredEdgesIterator(); it.hasNext(); ) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -311,7 +311,7 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java similarity index 90% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java index b249f3377d..e3f4ca701a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchGraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java @@ -45,7 +45,7 @@ * * @author Joseph Ramsey */ -public final class SearchGraphUtils { +public final class GraphUtilsSearch { /** * Orients according to background knowledge. @@ -56,8 +56,8 @@ public static void pcOrientbk(Knowledge bk, Graph graph, List nodes) { KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = SearchGraphUtils.translate(edge.getFrom(), nodes); - Node to = SearchGraphUtils.translate(edge.getTo(), nodes); + Node from = GraphUtilsSearch.translate(edge.getFrom(), nodes); + Node to = GraphUtilsSearch.translate(edge.getTo(), nodes); if (from == null || to == null) { continue; @@ -71,15 +71,15 @@ public static void pcOrientbk(Knowledge bk, Graph graph, List nodes) { graph.removeEdge(from, to); graph.addDirectedEdge(to, from); - TetradLogger.getInstance().log("knowledgeOrientations", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(to, from))); + TetradLogger.getInstance().log("knowledgeOrientations", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(to, from))); } for (Iterator it = bk.requiredEdgesIterator(); it.hasNext(); ) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), nodes); - Node to = SearchGraphUtils.translate(edge.getTo(), nodes); + Node from = GraphUtilsSearch.translate(edge.getFrom(), nodes); + Node to = GraphUtilsSearch.translate(edge.getTo(), nodes); if (from == null || to == null) { continue; @@ -93,7 +93,7 @@ public static void pcOrientbk(Knowledge bk, Graph graph, List nodes) { graph.removeEdges(from, to); graph.addDirectedEdge(from, to); - TetradLogger.getInstance().log("knowledgeOrientations", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + TetradLogger.getInstance().log("knowledgeOrientations", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } TetradLogger.getInstance().log("details", "Finishing BK Orientation."); @@ -129,7 +129,7 @@ public static void pcdOrientC(IndependenceTest test, Knowledge knowledge, Graph continue; } - List sepset = SearchGraphUtils.sepset(graph, x, z, new HashSet<>(), new HashSet<>(), + List sepset = GraphUtilsSearch.sepset(graph, x, z, new HashSet<>(), new HashSet<>(), test); if (sepset == null) { @@ -166,16 +166,16 @@ public static void pcdOrientC(IndependenceTest test, Knowledge knowledge, Graph continue; } - if (!SearchGraphUtils.isArrowpointAllowed(x, y, knowledge) - || !SearchGraphUtils.isArrowpointAllowed(z, y, knowledge)) { + if (!GraphUtilsSearch.isArrowpointAllowed(x, y, knowledge) + || !GraphUtilsSearch.isArrowpointAllowed(z, y, knowledge)) { continue; } graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); - System.out.println(SearchLogUtils.colliderOrientedMsg(x, y, z) + " sepset = " + sepset); - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + System.out.println(LogUtilsSearch.colliderOrientedMsg(x, y, z) + " sepset = " + sepset); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } } @@ -222,9 +222,9 @@ public static void orientUsingMeekRulesLocally(Knowledge knowledge, boolean changed; do { - changed = SearchGraphUtils.meekR1Locally(graph, knowledge, test, depth) - || SearchGraphUtils.meekR2(graph, knowledge) || SearchGraphUtils.meekR3(graph, knowledge) - || SearchGraphUtils.meekR4(graph, knowledge); + changed = GraphUtilsSearch.meekR1Locally(graph, knowledge, test, depth) + || GraphUtilsSearch.meekR2(graph, knowledge) || GraphUtilsSearch.meekR3(graph, knowledge) + || GraphUtilsSearch.meekR4(graph, knowledge); } while (changed); TetradLogger.getInstance().log("info", "Finishing Orientation Step D."); @@ -262,8 +262,8 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg //I think the null check needs to be here --AJ if (sepset != null && !sepset.contains(b) - && SearchGraphUtils.isArrowpointAllowed(a, b, knowledge) - && SearchGraphUtils.isArrowpointAllowed(c, b, knowledge)) { + && GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge) + && GraphUtilsSearch.isArrowpointAllowed(c, b, knowledge)) { if (verbose) { System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); } @@ -280,7 +280,7 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg graph.addDirectedEdge(a, b); graph.addDirectedEdge(c, b); - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(a, b, c, sepset)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(a, b, c, sepset)); } } } @@ -361,26 +361,26 @@ public static boolean meekR1Locally(Graph graph, Knowledge knowledge, if (graph.getEndpoint(b, a) == Endpoint.ARROW && graph.paths().isUndirectedFromTo(a, c)) { - if (SearchGraphUtils.existsLocalSepsetWithout(b, a, c, test, graph, + if (GraphUtilsSearch.existsLocalSepsetWithout(b, a, c, test, graph, depth)) { continue; } - if (SearchGraphUtils.isArrowpointAllowed(a, c, knowledge)) { + if (GraphUtilsSearch.isArrowpointAllowed(a, c, knowledge)) { graph.setEndpoint(a, c, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R1", graph.getEdge(a, c))); + TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R1", graph.getEdge(a, c))); changed = true; } } else if (graph.getEndpoint(c, a) == Endpoint.ARROW && graph.paths().isUndirectedFromTo(a, b)) { - if (SearchGraphUtils.existsLocalSepsetWithout(b, a, c, test, graph, + if (GraphUtilsSearch.existsLocalSepsetWithout(b, a, c, test, graph, depth)) { continue; } - if (SearchGraphUtils.isArrowpointAllowed(a, b, knowledge)) { + if (GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge)) { graph.setEndpoint(a, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R1", graph.getEdge(a, b))); + TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R1", graph.getEdge(a, b))); changed = true; } } @@ -415,16 +415,16 @@ public static boolean meekR2(Graph graph, Knowledge knowledge) { if (graph.paths().isDirectedFromTo(b, a) && graph.paths().isDirectedFromTo(a, c) && graph.paths().isUndirectedFromTo(b, c)) { - if (SearchGraphUtils.isArrowpointAllowed(b, c, knowledge)) { + if (GraphUtilsSearch.isArrowpointAllowed(b, c, knowledge)) { graph.setEndpoint(b, c, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R2", graph.getEdge(b, c))); + TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R2", graph.getEdge(b, c))); } } else if (graph.paths().isDirectedFromTo(c, a) && graph.paths().isDirectedFromTo(a, b) && graph.paths().isUndirectedFromTo(c, b)) { - if (SearchGraphUtils.isArrowpointAllowed(c, b, knowledge)) { + if (GraphUtilsSearch.isArrowpointAllowed(c, b, knowledge)) { graph.setEndpoint(c, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R2", graph.getEdge(c, b))); + TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R2", graph.getEdge(c, b))); } } } @@ -478,9 +478,9 @@ public static boolean meekR3(Graph graph, Knowledge knowledge) { if (graph.paths().isDirectedFromTo(c, b) && graph.paths().isDirectedFromTo(d, b)) { - if (SearchGraphUtils.isArrowpointAllowed(a, b, knowledge)) { + if (GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge)) { graph.setEndpoint(a, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek R3", graph.getEdge(a, b))); + TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R3", graph.getEdge(a, b))); changed = true; break; } @@ -533,17 +533,17 @@ public static boolean meekR4(Graph graph, Knowledge knowledge) { if (graph.paths().isDirectedFromTo(b, c) && graph.paths().isDirectedFromTo(d, c)) { - if (SearchGraphUtils.isArrowpointAllowed(a, c, knowledge)) { + if (GraphUtilsSearch.isArrowpointAllowed(a, c, knowledge)) { graph.setEndpoint(a, c, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek T1", graph.getEdge(a, c))); + TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek T1", graph.getEdge(a, c))); changed = true; break; } } else if (graph.paths().isDirectedFromTo(c, d) && graph.paths().isDirectedFromTo(d, b)) { - if (SearchGraphUtils.isArrowpointAllowed(a, b, knowledge)) { + if (GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge)) { graph.setEndpoint(a, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", SearchLogUtils.edgeOrientedMsg("Meek T1", graph.getEdge(a, b))); + TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek T1", graph.getEdge(a, b))); changed = true; break; } @@ -639,14 +639,14 @@ public static void basicCpdagRestricted2(Graph graph, Node node) { */ public static Graph cpdagFromDag(Graph dag) { Graph graph = new EdgeListGraph(dag); - SearchGraphUtils.basicCPDAG(graph); + GraphUtilsSearch.basicCPDAG(graph); MeekRules rules = new MeekRules(); rules.orientImplied(graph); return graph; } public static Graph dagFromCPDAG(Graph graph) { - return SearchGraphUtils.dagFromCPDAG(graph, null); + return GraphUtilsSearch.dagFromCPDAG(graph, null); } public static Graph dagFromCPDAG(Graph graph, Knowledge knowledge) { @@ -678,7 +678,7 @@ public static Graph dagFromCPDAG(Graph graph, Knowledge knowledge) { Node y = edge.getNode2(); if (Edges.isUndirectedEdge(edge) && !graph.paths().isAncestorOf(y, x)) { - SearchGraphUtils.direct(x, y, dag); + GraphUtilsSearch.direct(x, y, dag); rules.orientImplied(dag); continue NEXT; } @@ -792,45 +792,15 @@ public static LegalPagRet isLegalPag(Graph pag) { } } -// for (Node n : pag.getNodes()) { -// if (pag.paths().existsDirectedPathFromTo(n, n)) -// return new LegalPagRet(false, -// "Acyclicity violated: There is a directed cyclic path from from " + n + " to itself"); -// } - -// for (Edge e : pag.getEdges()) { -// Node x = e.getNode1(); -// Node y = e.getNode2(); -// -// if (Edges.isBidirectedEdge(e)) { -// if (pag.existsDirectedPathFromTo(x, y)) { -// List path = GraphUtils.directedPathsFromTo( -// pag, x, y, 100).get(0); -// return new LegalPagRet(false, -// "Bidirected edge semantics violated: there is a directed path for " + e + " from " + x + " to " + y -// + ". This is \"almost cyclic\"; for <-> edges there should not be a path from either endpoint to the other. " -// + "An example path is " + GraphUtils.pathString(pag, path)); -// } else if (pag.existsDirectedPathFromTo(y, x)) { -// List path = GraphUtils.directedPathsFromTo( -// pag, y, x, 100).get(0); -// return new LegalPagRet(false, -// "Bidirected edge semantics violated: There is an a directed path for " + e + " from " + y + " to " + x + -// ". This is \"almost cyclic\"; for <-> edges there should not be a path from either endpoint to the other. " -// + "An example path is " + GraphUtils.pathString(pag, path)); -// } -// } -// } - Graph mag = pagToMag(pag); - LegalMagRet legalMag = isLegalMag(mag); if (!legalMag.isLegalMag()) { return new LegalPagRet(false, legalMag.getReason() + " in a MAG implied by this graph"); } - Graph pag2 = SearchGraphUtils.dagToPag(mag); + Graph pag2 = GraphUtilsSearch.dagToPag(mag); if (!pag.equals(pag2)) { String edgeMismatch = ""; @@ -1203,7 +1173,7 @@ public static List generateCpdagDags(Graph cpdag, boolean orientBidirecte cpdag = GraphUtils.removeBidirectedOrientations(cpdag); } - return SearchGraphUtils.getDagsInCpdagMeek(cpdag, new Knowledge()); + return GraphUtilsSearch.getDagsInCpdagMeek(cpdag, new Knowledge()); } public static List getDagsInCpdagMeek(Graph cpdag, Knowledge knowledge) { @@ -1366,8 +1336,8 @@ public static int structuralHammingDistance(Graph trueGraph, Graph estGraph) { try { estGraph = GraphUtils.replaceNodes(estGraph, trueGraph.getNodes()); - trueGraph = SearchGraphUtils.cpdagForDag(trueGraph); - estGraph = SearchGraphUtils.cpdagForDag(estGraph); + trueGraph = GraphUtilsSearch.cpdagForDag(trueGraph); + estGraph = GraphUtilsSearch.cpdagForDag(estGraph); // Will check mixedness later. if (trueGraph.paths().existsDirectedCycle()) { @@ -1399,7 +1369,7 @@ public static int structuralHammingDistance(Graph trueGraph, Graph estGraph) { return -99; } - int error = SearchGraphUtils.structuralHammingDistanceOneEdge(e1, e2); + int error = GraphUtilsSearch.structuralHammingDistanceOneEdge(e1, e2); shd += error; } } @@ -1809,8 +1779,6 @@ public static String graphComparisonString(String trueGraphName, Graph trueGraph } List incorrect = new ArrayList<>(); - List compatible = new ArrayList<>(); - List incompatible = new ArrayList<>(); for (Edge adj : allSingleEdges) { Edge edge1 = trueGraph.getEdge(adj.getNode1(), adj.getNode2()); @@ -1818,57 +1786,9 @@ public static String graphComparisonString(String trueGraphName, Graph trueGraph if (!edge1.equals(edge2)) { incorrect.add(adj); + } + } -// if (SearchGraphUtils.isLegalPag(trueGraph).isLegalPag() && SearchGraphUtils.isLegalPag(targetGraph).isLegalPag()) { -// GraphUtils.addPagColoring(trueGraph); -// GraphUtils.addPagColoring(targetGraph); -// -// if (edge2 == null) continue; -// -// if (GraphUtils.compatible(edge1, edge2)) { -// compatible.add(edge1); -// } else { -// incompatible.add(edge1); -// } -// } - } - } - -// if (SearchGraphUtils.isLegalPag(trueGraph).isLegalPag() && SearchGraphUtils.isLegalPag(targetGraph).isLegalPag()) { -// builder.append("\n\n" + "Edges incorrectly oriented (incompatible)"); -// -// if (incompatible.isEmpty()) { -// builder.append("\n --NONE--"); -// } else { -// sort(incompatible); -// -// int j1 = 0; -// -// for (Edge adj : incompatible) { -// Edge edge1 = trueGraph.getEdge(adj.getNode1(), adj.getNode2()); -// Edge edge2 = targetGraph.getEdge(adj.getNode1(), adj.getNode2()); -// if (edge1 == null || edge2 == null) continue; -// builder.append("\n").append(++j1).append(". ").append(edge1).append(" ====> ").append(edge2); -// } -// } -// -// builder.append("\n\n" + "Edges incorrectly oriented (compatible)"); -// -// sort(compatible); -// -// if (compatible.isEmpty()) { -// builder.append("\n --NONE--"); -// } else { -// int j1 = 0; -// -// for (Edge adj : compatible) { -// Edge edge1 = trueGraph.getEdge(adj.getNode1(), adj.getNode2()); -// Edge edge2 = targetGraph.getEdge(adj.getNode1(), adj.getNode2()); -// if (edge1 == null || edge2 == null) continue; -// builder.append("\n").append(++j1).append(". ").append(edge1).append(" ====> ").append(edge2); -// } -// } -// } else { builder.append("\n\n" + "Edges incorrectly oriented"); @@ -1917,7 +1837,7 @@ public static String graphComparisonString(String trueGraphName, Graph trueGraph } public static int[][] graphComparison(Graph trueCpdag, Graph estCpdag, PrintStream out) { - GraphUtils.GraphComparison comparison = SearchGraphUtils.getGraphComparison2(estCpdag, trueCpdag); + GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison2(estCpdag, trueCpdag); if (out != null) { out.println("Adjacencies:"); 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 187edd1fee..669de6d213 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 @@ -335,8 +335,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -348,15 +348,15 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) // Orient to*->from graph.setEndpoint(to, from, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it = knowledge.requiredEdgesIterator(); it.hasNext(); ) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -368,7 +368,7 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java index 18dfce70df..90a3b2b03b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java @@ -201,7 +201,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (verbose) { if (result.isIndep()) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, this.pValue)); + LogUtilsSearch.independenceFactMsg(x, y, z, this.pValue)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java index 626c64e2fe..cc7b35cacc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java @@ -123,7 +123,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, p)); + LogUtilsSearch.independenceFactMsg(x, y, z, p)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java index dffa828c3d..5a9d3085a7 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java @@ -141,7 +141,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, this.pValue)); + LogUtilsSearch.independenceFactMsg(x, y, z, this.pValue)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java index 561d359304..1ab93903b8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java @@ -218,7 +218,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (dSeparated) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, 1.0)); + LogUtilsSearch.independenceFactMsg(x, y, z, 1.0)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java index 0d0e5a5fc3..e1712ea73f 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java @@ -261,7 +261,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, pValue)); + LogUtilsSearch.independenceFactMsg(x, y, z, pValue)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java index e4fb09e1d6..c4bc95e68a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java @@ -218,7 +218,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, p)); + LogUtilsSearch.independenceFactMsg(x, y, z, p)); } } @@ -420,7 +420,7 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep try { Czz.inverse(); } catch (SingularMatrixException e) { - System.out.println(SearchLogUtils.determinismDetected(z, x)); + System.out.println(LogUtilsSearch.determinismDetected(z, x)); return true; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java index 5887e862e5..1e93ce14f8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java @@ -167,7 +167,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, this.pValue)); + LogUtilsSearch.independenceFactMsg(x, y, z, this.pValue)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java index 948cb018dd..7412bce297 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java @@ -145,7 +145,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, this.pValue)); + LogUtilsSearch.independenceFactMsg(x, y, z, this.pValue)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestGSquare.java index a94c0e4fb4..f89750b33c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestGSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestGSquare.java @@ -193,7 +193,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (result.isIndep()) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestHsic.java index 0864cca9ef..f644de0097 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestHsic.java @@ -320,7 +320,7 @@ public IndependenceResult checkIndependence(Node y, Node x, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java index 3d3f02b549..7888f3eb5a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java @@ -77,7 +77,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java index f82bd52b49..b64d7a7530 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java @@ -130,7 +130,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java index 252fae64aa..e713012f6a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java @@ -90,9 +90,9 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { boolean independent = ResolveSepsets.isIndependentPooled(this.method, this.independenceTests, x, y, z); if (independent) { - TetradLogger.getInstance().log("independencies", "In aggregate independent: " + SearchLogUtils.independenceFact(x, y, z)); + TetradLogger.getInstance().log("independencies", "In aggregate independent: " + LogUtilsSearch.independenceFact(x, y, z)); } else { - TetradLogger.getInstance().log("dependencies", "In aggregate dependent: " + SearchLogUtils.independenceFact(x, y, z)); + TetradLogger.getInstance().log("dependencies", "In aggregate dependent: " + LogUtilsSearch.independenceFact(x, y, z)); } return new IndependenceResult(new IndependenceFact(x, y, z), independent, getPValue()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java index b758ea9b37..a330d75c6a 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java @@ -131,7 +131,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java index 60ec927555..5fdd1b4416 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java @@ -132,7 +132,7 @@ public IndependenceTest indTestSubset(List vars) { */ public IndependenceResult checkIndependence(Node x0, Node y0, List z0) { - System.out.println(SearchLogUtils.independenceFact(x0, y0, z0)); + System.out.println(LogUtilsSearch.independenceFact(x0, y0, z0)); double[] x = this.data[this.dataSet.getColumn(x0)]; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestProbabilistic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestProbabilistic.java index a7909cbf2f..466e8facc0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestProbabilistic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestProbabilistic.java @@ -208,7 +208,7 @@ public IndependenceResult checkIndependence(Node x, Node y, Node... z) { if (this.verbose) { if (ind) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, Arrays.asList(z), p)); + LogUtilsSearch.independenceFactMsg(x, y, Arrays.asList(z), p)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestRegression.java index 1f87c27b1a..4c33c3b230 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestRegression.java @@ -152,16 +152,16 @@ public IndependenceResult checkIndependence(Node xVar, Node yVar, List zLi if (this.verbose) { if (independent) { - TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(xVar, yVar, zList, p)); + TetradLogger.getInstance().log("independencies", LogUtilsSearch.independenceFactMsg(xVar, yVar, zList, p)); } else { - TetradLogger.getInstance().log("dependencies", SearchLogUtils.dependenceFactMsg(xVar, yVar, zList, p)); + TetradLogger.getInstance().log("dependencies", LogUtilsSearch.dependenceFactMsg(xVar, yVar, zList, p)); } } if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(xVar, yVar, zList, p)); + LogUtilsSearch.independenceFactMsg(xVar, yVar, zList, p)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java index 62aa749dd6..10db5fb470 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java @@ -26,7 +26,6 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; @@ -93,7 +92,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (independent) { NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFact(x, y, z) + " score = " + nf.format(bump)); + LogUtilsSearch.independenceFact(x, y, z) + " score = " + nf.format(bump)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java index 3ca8b5a9eb..dcaee20aaf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java @@ -247,8 +247,8 @@ public Graph search(List nodes) { enumerateTriples(); - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - SearchGraphUtils.orientCollidersUsingSepsets(this.sepset, this.knowledge, this.graph, this.verbose, true); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); + GraphUtilsSearch.orientCollidersUsingSepsets(this.sepset, this.knowledge, this.graph, this.verbose, true); MeekRules rules = new MeekRules(); rules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles); rules.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java index f98538843a..f9d8420520 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java @@ -92,7 +92,7 @@ public Graph search() { TetradLogger.getInstance().log("info", "Making list of all dags in CPDAG..."); - List dags = SearchGraphUtils.getAllGraphsByDirectingUndirectedEdges(_cpdag); + List dags = GraphUtilsSearch.getAllGraphsByDirectingUndirectedEdges(_cpdag); TetradLogger.getInstance().log("normalityTests", "Anderson Darling P value for Variables\n"); NumberFormat nf = new DecimalFormat("0.0000"); @@ -139,7 +139,7 @@ public Graph search() { TetradLogger.getInstance().log("normalityTests", getDataSet().getVariable(j) + ": " + nf.format(scores.get(maxj).pvals[j])); } - Graph ngDagCPDAG = SearchGraphUtils.cpdagFromDag(dag); + Graph ngDagCPDAG = GraphUtilsSearch.cpdagFromDag(dag); List nodes = ngDagCPDAG.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchLogUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LogUtilsSearch.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchLogUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/LogUtilsSearch.java index 8823cec878..5e21b89d9a 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SearchLogUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LogUtilsSearch.java @@ -34,7 +34,7 @@ * * @author Joseph Ramsey */ -public class SearchLogUtils { +public class LogUtilsSearch { public static String edgeOrientedMsg(String reason, Edge edge) { return "Orienting edge (" + reason + "): " + edge; } @@ -64,7 +64,7 @@ public static String independenceFactMsg(Node x, Node y, List condSet, dou NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); sb.append("Independence accepted: "); - sb.append(SearchLogUtils.independenceFact(x, y, condSet)); + sb.append(LogUtilsSearch.independenceFact(x, y, condSet)); if (!Double.isNaN(pValue)) { sb.append("\tp = ").append(nf.format(pValue)); @@ -78,7 +78,7 @@ public static String dependenceFactMsg(Node x, Node y, List condSet, doubl NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); sb.append("Dependent: "); - sb.append(SearchLogUtils.independenceFact(x, y, condSet)); + sb.append(LogUtilsSearch.independenceFact(x, y, condSet)); if (!Double.isNaN(pValue)) { sb.append("\tp = ").append(nf.format(pValue)); @@ -109,7 +109,6 @@ public static String independenceFact(Node x, Node y, List condSet) { return sb.toString(); } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java index 49aeaac318..d6650cc548 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java @@ -94,7 +94,7 @@ public static void orientCollider(Node x, Node y, Node z, PcCommon.ConflictRule graph.addDirectedEdge(z, y); } - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java index 5d0f4f0ea5..d3af42a50a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java @@ -238,7 +238,7 @@ public static List generateMbDags(Graph mbCPDAG, * @return An example DAG in this CPDAG. */ public static Graph getOneMbDag(Graph mbCpdag) { - return SearchGraphUtils.dagFromCPDAG(mbCpdag); + return GraphUtilsSearch.dagFromCPDAG(mbCpdag); } /** @@ -291,7 +291,7 @@ private static Set listMbDags(Graph mbCPDAG, private static void doAbbreviatedMbOrientation(Graph graph, IndependenceTest test, int depth, Node target) { - SearchGraphUtils.orientUsingMeekRulesLocally(new Knowledge(), graph, + GraphUtilsSearch.orientUsingMeekRulesLocally(new Knowledge(), graph, test, depth); MbUtils.trimToMbNodes(graph, target, false); MbUtils.trimEdgesAmongParents(graph, target); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java index c05c88f358..f985c19e5b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java @@ -191,7 +191,7 @@ private boolean meekR1(Node b, Node c, Graph graph, Set visited) { for (Node a : graph.getParents(b)) { if (graph.isAdjacentTo(c, a)) continue; if (direct(b, c, graph, visited)) { - log(SearchLogUtils.edgeOrientedMsg( + log(LogUtilsSearch.edgeOrientedMsg( "Meek R1 triangle (" + a + "-->" + b + "---" + c + ")", graph.getEdge(b, c))); return true; } @@ -228,7 +228,7 @@ private boolean meekR2(Node a, Node c, Graph graph, Set visited) { private boolean r2Helper(Node a, Node b, Node c, Graph graph, Set visited) { boolean directed = direct(a, c, graph, visited); - log(SearchLogUtils.edgeOrientedMsg( + log(LogUtilsSearch.edgeOrientedMsg( "Meek R2 triangle (" + a + "-->" + b + "-->" + c + ", " + a + "---" + c + ")", graph.getEdge(a, c))); return directed; } @@ -270,7 +270,7 @@ private boolean r3Helper(Node a, Node d, Node b, Node c, Graph graph, Set if (b4 && b5 && b6 && b7 && b8) { oriented = direct(d, a, graph, visited); - log(SearchLogUtils.edgeOrientedMsg("Meek R3 " + d + "--" + a + ", " + b + ", " + log(LogUtilsSearch.edgeOrientedMsg("Meek R3 " + d + "--" + a + ", " + b + ", " + c, graph.getEdge(d, a))); } @@ -292,7 +292,7 @@ private boolean meekR4(Node a, Node b, Graph graph, Set visited) { if (!dc.pointsTowards(c)) continue; if (graph.getEdge(a, d).isDirected()) continue; if (direct(a, b, graph, visited)) { - log(SearchLogUtils.edgeOrientedMsg("Meek R4 using " + c + ", " + d, graph.getEdge(a, b))); + log(LogUtilsSearch.edgeOrientedMsg("Meek R4 using " + c + ", " + d, graph.getEdge(a, b))); return true; } } 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 5d2e612117..8893d07f0d 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 @@ -255,8 +255,8 @@ public Graph search(IFas fas, List nodes) { this.numIndependenceTests = fas.getNumIndependenceTests(); - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - SearchGraphUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); + GraphUtilsSearch.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); this.logger.log("graph", "\nReturning this graph: " + this.graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java index cb7ce89e88..712df097e4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java @@ -372,7 +372,7 @@ public Graph search(List nodes) { this.graph = fas.search(); this.sepsets = fas.getSepsets(); - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); if (this.colliderDiscovery == ColliderDiscovery.FAS_SEPSETS) { orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, this.conflictRule); @@ -440,7 +440,7 @@ private static void orientCollider(Node x, Node y, Node z, ConflictRule conflict graph.addDirectedEdge(z, y); } - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } private void logTriples() { @@ -627,7 +627,7 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); } - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(a, b, c, sepset)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(a, b, c, sepset)); } } } 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 eff901aa51..897a1171b5 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 @@ -266,8 +266,8 @@ public Graph search(IFas fas, List nodes) { this.numIndependenceTests = fas.getNumIndependenceTests(); - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - SearchGraphUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); + GraphUtilsSearch.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); this.logger.log("graph", "\nReturning this graph: " + this.graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index 395922de47..6fff461b30 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -282,7 +282,7 @@ public Graph search(List targets) { this.logger.log("info", "BEGINNING step 4 (PC Orient)."); - SearchGraphUtils.pcOrientbk(this.knowledge, graph, graph.getNodes()); + GraphUtilsSearch.pcOrientbk(this.knowledge, graph, graph.getNodes()); List _visited = new LinkedList<>(getA()); orientUnshieldedTriples(this.knowledge, graph, getDepth(), _visited); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index e1e704990b..aa8d749ced 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -249,8 +249,8 @@ public Graph search(IFas fas, List nodes) { enumerateTriples(); - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, nodes); - SearchGraphUtils.pcdOrientC(getIndependenceTest(), this.knowledge, this.graph); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); + GraphUtilsSearch.pcdOrientC(getIndependenceTest(), this.knowledge, this.graph); MeekRules rules = new MeekRules(); rules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java index a7a43cd2f2..0af1540326 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java @@ -230,7 +230,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo // dagToPag.setCompleteRuleSetUsed(false); // Graph PAG_True = dagToPag.convert(); - Graph PAG_True = SearchGraphUtils.dagToPag(dag); + Graph PAG_True = GraphUtilsSearch.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, data.getVariables()); @@ -258,7 +258,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo // learn structure of constraints using empirical data Graph depCPDAG = runFGS(depData); - Graph estDepBN = SearchGraphUtils.dagFromCPDAG(depCPDAG); + Graph estDepBN = GraphUtilsSearch.dagFromCPDAG(depCPDAG); System.out.println("estDepBN: " + estDepBN.getEdges()); out.println("DepGraph(nodes,edges):" + estDepBN.getNumNodes() + "," + estDepBN.getNumEdges()); System.out.println("Dependency graph done!"); @@ -365,7 +365,7 @@ private void summarize(Graph graph, Graph trueGraph, PrintStream out) { tableColumns.add(Comparison.TableColumn.SHD); - GraphUtils.GraphComparison comparison = SearchGraphUtils.getGraphComparison(trueGraph, graph); + GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison(trueGraph, graph); List variables = new ArrayList<>(); for (Comparison.TableColumn column : tableColumns) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index 4fd4f3cf00..7deb1075bf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -391,9 +391,9 @@ private static boolean isIndependentMajorityFdr(List independe boolean independent = c < allPValues.size() / 2; if (independent) { - TetradLogger.getInstance().log("independence", "***FDR judges " + SearchLogUtils.independenceFact(x, y, condSet) + " independent"); + TetradLogger.getInstance().log("independence", "***FDR judges " + LogUtilsSearch.independenceFact(x, y, condSet) + " independent"); } else { - TetradLogger.getInstance().log("independence", "###FDR judges " + SearchLogUtils.independenceFact(x, y, condSet) + " dependent"); + TetradLogger.getInstance().log("independence", "###FDR judges " + LogUtilsSearch.independenceFact(x, y, condSet) + " dependent"); } TetradLogger.getInstance().log("independence", "c = " + c); @@ -440,9 +440,9 @@ private static boolean isIndependentMajorityIndep(List indepen boolean independent = c < allPValues.size() / 2; if (independent) { - TetradLogger.getInstance().log("independence", "***Majority = " + SearchLogUtils.independenceFact(x, y, condSet) + " independent"); + TetradLogger.getInstance().log("independence", "***Majority = " + LogUtilsSearch.independenceFact(x, y, condSet) + " independent"); } else { - TetradLogger.getInstance().log("independence", "###Majority = " + SearchLogUtils.independenceFact(x, y, condSet) + " dependent"); + TetradLogger.getInstance().log("independence", "###Majority = " + LogUtilsSearch.independenceFact(x, y, condSet) + " dependent"); } TetradLogger.getInstance().log("independence", "c = " + c); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 509ebb6298..e4ea77e4fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -514,8 +514,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { @@ -530,7 +530,7 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { graph.setEndpoint(to, from, Endpoint.ARROW); graph.setEndpoint(from, to, Endpoint.CIRCLE); this.changeFlag = true; - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it = @@ -538,8 +538,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -552,7 +552,7 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); this.changeFlag = true; - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java index 0aa3d89905..b73034a4ef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java @@ -33,17 +33,11 @@ */ public interface SepsetProducer { List getSepset(Node a, Node b); - boolean isUnshieldedCollider(Node i, Node j, Node k); - boolean isUnshieldedNoncollider(Node a, Node b, Node c); - double getScore(); - List getVariables(); - void setVerbose(boolean verbose); - boolean isIndependent(Node d, Node c, List path); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java index a51f689323..5237283a91 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java @@ -69,6 +69,44 @@ public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { return set != null && set.contains(j); } + @Override + public boolean isIndependent(Node a, Node b, List c) { + IndependenceResult result = this.independenceTest.checkIndependence(a, b, c); + this.result = result; + return result.isIndependent(); + } + + @Override + public double getScore() { + return -(result.getPValue() - this.independenceTest.getAlpha()); + } + + @Override + public List getVariables() { + return this.independenceTest.getVariables(); + } + + public boolean isVerbose() { + return this.verbose; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public Graph getDag() { + if (this.independenceTest instanceof IndTestDSep) { + return ((IndTestDSep) this.independenceTest).getGraph(); + } else { + return null; + } + } + + public void setDepth(int depth) { + this.depth = depth; + } + private List getSepsetGreedy(Node i, Node k) { if (this.extraSepsets != null) { List v = this.extraSepsets.get(i, k); @@ -91,7 +129,7 @@ private List getSepsetGreedy(Node i, Node k) { while ((choice = gen.next()) != null) { List v = GraphUtils.asList(choice, adji); - if (getIndependenceTest().checkIndependence(i, k, v).isIndependent()) { + if (this.independenceTest.checkIndependence(i, k, v).isIndependent()) { return v; } } @@ -104,7 +142,7 @@ private List getSepsetGreedy(Node i, Node k) { while ((choice = gen.next()) != null) { List v = GraphUtils.asList(choice, adjk); - if (getIndependenceTest().checkIndependence(i, k, v).isIndependent()) { + if (this.independenceTest.checkIndependence(i, k, v).isIndependent()) { return v; } } @@ -114,46 +152,5 @@ private List getSepsetGreedy(Node i, Node k) { return null; } - @Override - public boolean isIndependent(Node a, Node b, List c) { - IndependenceResult result = this.independenceTest.checkIndependence(a, b, c); - this.result = result; - return result.isIndependent(); - } - - @Override - public double getScore() { - return -(result.getPValue() - this.independenceTest.getAlpha()); - } - - @Override - public List getVariables() { - return this.independenceTest.getVariables(); - } - - private IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - public boolean isVerbose() { - return this.verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public Graph getDag() { - if (this.independenceTest instanceof IndTestDSep) { - return ((IndTestDSep) this.independenceTest).getGraph(); - } else { - return null; - } - } - - public void setDepth(int depth) { - this.depth = depth; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index dffa5054dc..018c56a8bc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -123,7 +123,7 @@ public Graph search() { } Knowledge knowledge2 = new Knowledge(knowledge); - addForbiddenReverseEdgesForDirectedEdges(SearchGraphUtils.cpdagForDag(graph), knowledge2); + addForbiddenReverseEdgesForDirectedEdges(GraphUtilsSearch.cpdagForDag(graph), knowledge2); // Keep a copy of this CPDAG. Graph referenceDag = new EdgeListGraph(this.graph); @@ -309,8 +309,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -322,15 +322,15 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) // Orient to*->from graph.setEndpoint(to, from, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it = knowledge.requiredEdgesIterator(); it.hasNext(); ) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -342,7 +342,7 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 56fdd3cf19..8e6b94469c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -205,8 +205,8 @@ public void ruleR0(Graph graph) { graph.setEndpoint(a, b, Endpoint.ARROW); graph.setEndpoint(c, b, Endpoint.ARROW); if (this.verbose) { - this.logger.log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(a, b, c)); - System.out.println(SearchLogUtils.colliderOrientedMsg(a, b, c)); + this.logger.log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(a, b, c)); + System.out.println(LogUtilsSearch.colliderOrientedMsg(a, b, c)); printWrongColliderMessage(a, b, c, graph); } this.orientSimilarPairs(graph, this.knowledge, a, b, Endpoint.ARROW); @@ -348,8 +348,8 @@ private void ruleR1(Node a, Node b, Node c, Graph graph) { this.changeFlag = true; if (this.verbose) { - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Away from collider", graph.getEdge(b, c))); - System.out.println(SearchLogUtils.edgeOrientedMsg("Away from collider", graph.getEdge(b, c))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("Away from collider", graph.getEdge(b, c))); + System.out.println(LogUtilsSearch.edgeOrientedMsg("Away from collider", graph.getEdge(b, c))); } this.orientSimilarPairs(graph, this.getKnowledge(), c, b, Endpoint.TAIL); this.orientSimilarPairs(graph, this.getKnowledge(), b, c, Endpoint.ARROW); @@ -374,8 +374,8 @@ private void ruleR2(Node a, Node b, Node c, Graph graph) { graph.setEndpoint(a, c, Endpoint.ARROW); this.orientSimilarPairs(graph, this.getKnowledge(), a, c, Endpoint.ARROW); if (this.verbose) { - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Away from ancestor", graph.getEdge(a, c))); - System.out.println(SearchLogUtils.edgeOrientedMsg("Away from ancestor", graph.getEdge(a, c))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("Away from ancestor", graph.getEdge(a, c))); + System.out.println(LogUtilsSearch.edgeOrientedMsg("Away from ancestor", graph.getEdge(a, c))); } this.changeFlag = true; @@ -433,8 +433,8 @@ public void ruleR3(Graph graph) { graph.setEndpoint(D, B, Endpoint.ARROW); this.orientSimilarPairs(graph, this.getKnowledge(), D, B, Endpoint.ARROW); if (this.verbose) { - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Double triangle", graph.getEdge(D, B))); - System.out.println(SearchLogUtils.edgeOrientedMsg("Double triangle", graph.getEdge(D, B))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("Double triangle", graph.getEdge(D, B))); + System.out.println(LogUtilsSearch.edgeOrientedMsg("Double triangle", graph.getEdge(D, B))); } this.changeFlag = true; @@ -585,8 +585,8 @@ private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Map graph.setEndpoint(c, b, Endpoint.TAIL); this.orientSimilarPairs(graph, this.getKnowledge(), c, b, Endpoint.TAIL); if (this.verbose) { - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Definite discriminating path d = " + d, graph.getEdge(b, c))); - System.out.println(SearchLogUtils.edgeOrientedMsg("Definite discriminating path d = " + d, graph.getEdge(b, c))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("Definite discriminating path d = " + d, graph.getEdge(b, c))); + System.out.println(LogUtilsSearch.edgeOrientedMsg("Definite discriminating path d = " + d, graph.getEdge(b, c))); } } else { @@ -603,8 +603,8 @@ private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Map this.orientSimilarPairs(graph, this.getKnowledge(), a, b, Endpoint.ARROW); this.orientSimilarPairs(graph, this.getKnowledge(), c, b, Endpoint.ARROW); if (this.verbose) { - this.logger.log("impliedOrientations", SearchLogUtils.colliderOrientedMsg("Definite discriminating path.. d = " + d, a, b, c)); - System.out.println(SearchLogUtils.colliderOrientedMsg("Definite discriminating path.. d = " + d, a, b, c)); + this.logger.log("impliedOrientations", LogUtilsSearch.colliderOrientedMsg("Definite discriminating path.. d = " + d, a, b, c)); + System.out.println(LogUtilsSearch.colliderOrientedMsg("Definite discriminating path.. d = " + d, a, b, c)); } } @@ -654,7 +654,7 @@ public void ruleR5(Graph graph) { if (graph.isAdjacentTo(b, c)) continue; // We know u is as required: R5 applies! - this.logger.log("colliderOrientations", SearchLogUtils.edgeOrientedMsg("Orient circle path", graph.getEdge(a, b))); + this.logger.log("colliderOrientations", LogUtilsSearch.edgeOrientedMsg("Orient circle path", graph.getEdge(a, b))); graph.setEndpoint(a, b, Endpoint.TAIL); this.orientSimilarPairs(graph, this.getKnowledge(), a, b, Endpoint.TAIL); @@ -696,7 +696,7 @@ public void ruleR6R7(Graph graph) { // We know A---Bo-*C: R6 applies! graph.setEndpoint(c, b, Endpoint.TAIL); this.orientSimilarPairs(graph, this.getKnowledge(), c, b, Endpoint.TAIL); - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Single tails (tail)", graph.getEdge(c, b))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("Single tails (tail)", graph.getEdge(c, b))); this.changeFlag = true; } @@ -704,7 +704,7 @@ public void ruleR6R7(Graph graph) { if (graph.getEndpoint(a, b) == Endpoint.CIRCLE) { // if (graph.isAdjacentTo(a, c)) continue; - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Single tails (tail)", graph.getEdge(c, b))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("Single tails (tail)", graph.getEdge(c, b))); // We know A--oBo-*C and A,C nonadjacent: R7 applies! graph.setEndpoint(c, b, Endpoint.TAIL); @@ -762,7 +762,7 @@ private void orientTailPath(List path, Graph graph) { this.orientSimilarPairs(graph, this.getKnowledge(), n2, n1, Endpoint.TAIL); this.changeFlag = true; - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("Orient circle undirectedPaths", graph.getEdge(n1, n2))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("Orient circle undirectedPaths", graph.getEdge(n1, n2))); } } @@ -893,7 +893,7 @@ private boolean ruleR8(Node a, Node c, Graph graph) { if (graph.getEndpoint(a, b) == Endpoint.TAIL) continue; // We have A-->B-->C or A--oB-->C: R8 applies! - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("R8", graph.getEdge(c, a))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("R8", graph.getEdge(c, a))); graph.setEndpoint(c, a, Endpoint.TAIL); this.orientSimilarPairs(graph, this.getKnowledge(), c, a, Endpoint.TAIL); @@ -924,7 +924,7 @@ private boolean ruleR9(Node a, Node c, Graph graph) { if (b == c) continue; // We know u is as required: R9 applies! - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("R9", graph.getEdge(c, a))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("R9", graph.getEdge(c, a))); graph.setEndpoint(c, a, Endpoint.TAIL); this.orientSimilarPairs(graph, this.getKnowledge(), c, a, Endpoint.TAIL); @@ -972,7 +972,7 @@ private void ruleR10(Node a, Node c, Graph graph) { if (graph.isAdjacentTo(m, n)) continue; // We know B,D,u1,u2 as required: R10 applies! - this.logger.log("impliedOrientations", SearchLogUtils.edgeOrientedMsg("R10", graph.getEdge(c, a))); + this.logger.log("impliedOrientations", LogUtilsSearch.edgeOrientedMsg("R10", graph.getEdge(c, a))); graph.setEndpoint(c, a, Endpoint.TAIL); this.changeFlag = true; @@ -996,8 +996,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { @@ -1012,7 +1012,7 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { graph.setEndpoint(to, from, Endpoint.ARROW); graph.setEndpoint(from, to, Endpoint.CIRCLE); this.changeFlag = true; - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it = @@ -1020,8 +1020,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -1034,7 +1034,7 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); this.changeFlag = true; - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 5b0a219303..7dd43f3202 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -310,8 +310,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) 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); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { @@ -325,15 +325,15 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) // Orient to*->from graph.setEndpoint(to, from, Endpoint.ARROW); graph.setEndpoint(from, to, Endpoint.CIRCLE); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } for (Iterator it = knowledge.requiredEdgesIterator(); it.hasNext(); ) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); + Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); + Node to = GraphUtilsSearch.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -345,7 +345,7 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index 3d9d2f5021..af6044d16f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -347,11 +347,11 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map> powerSet(List nodes) { * Appendix C of (Chickering, 2002). */ private void rebuildCPDAG(Graph graph) { - SearchGraphUtils.basicCPDAG(graph); + GraphUtilsSearch.basicCPDAG(graph); addRequiredEdges(graph); pdagWithBk(graph, getKnowledge()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java index d796c7c814..d741bbd905 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; @@ -242,7 +242,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } if (Double.isNaN(this.storedR)) { - throw new IllegalArgumentException("Conditional correlation cannot be computed: " + SearchLogUtils.independenceFact(x, y, z)); + throw new IllegalArgumentException("Conditional correlation cannot be computed: " + LogUtilsSearch.independenceFact(x, y, z)); } // Determine whether this partial correlation is statistically @@ -253,7 +253,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, pValue)); + LogUtilsSearch.independenceFactMsg(x, y, z, pValue)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java index f3c67b295c..8be8bab2ae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java @@ -33,7 +33,7 @@ import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; @@ -179,7 +179,7 @@ public IndependenceResult checkIndependence(Node xVar, Node yVar, List z) if (Double.isNaN(r)) { if (this.verbose) { - TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(xVar, yVar, z, getPValue())); + TetradLogger.getInstance().log("independencies", LogUtilsSearch.independenceFactMsg(xVar, yVar, z, getPValue())); } return new IndependenceResult(new IndependenceFact(xVar, yVar, z), false, Double.NaN); } @@ -203,13 +203,13 @@ public IndependenceResult checkIndependence(Node xVar, Node yVar, List z) //Two sided if (this.verbose) { - TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(xVar, yVar, z, getPValue())); + TetradLogger.getInstance().log("independencies", LogUtilsSearch.independenceFactMsg(xVar, yVar, z, getPValue())); } if (this.verbose) { if (indFisher) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(xVar, yVar, z, getPValue())); + LogUtilsSearch.independenceFactMsg(xVar, yVar, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java index f30a6e7284..258a7480d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.StatUtils; @@ -137,7 +137,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java index dd72c04e90..5347b38199 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java @@ -191,7 +191,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { try { r = partialCorrelation(x, y, z); } catch (SingularMatrixException e) { - System.out.println(SearchLogUtils.determinismDetected(z, x)); + System.out.println(LogUtilsSearch.determinismDetected(z, x)); this.fisherZ = Double.POSITIVE_INFINITY; return new IndependenceResult(new IndependenceFact(x, y, z), false, Double.NaN); } @@ -205,7 +205,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } @@ -279,7 +279,7 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep try { Czz.inverse(); } catch (SingularMatrixException e) { - System.out.println(SearchLogUtils.determinismDetected(z, x)); + System.out.println(LogUtilsSearch.determinismDetected(z, x)); return true; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java index e514b2336e..27a0d1bb5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; @@ -323,7 +323,7 @@ private IndependenceResult isIndependentMultinomialLogisticRegression(Node x, No if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } @@ -420,7 +420,7 @@ private IndependenceResult isIndependentRegression(Node x, Node y, List z) if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java index a1023d0a8c..e91da06f8e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; @@ -211,7 +211,7 @@ private IndependenceResult isIndependentMultinomialLogisticRegression(Node x, No if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, p)); + LogUtilsSearch.independenceFactMsg(x, y, z, p)); } } @@ -269,9 +269,9 @@ private IndependenceResult isIndependentRegression(Node x, Node y, List z) if (this.verbose) { if (indep) { - TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, p)); + TetradLogger.getInstance().log("independencies", LogUtilsSearch.independenceFactMsg(x, y, z, p)); } else { - TetradLogger.getInstance().log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, p)); + TetradLogger.getInstance().log("dependencies", LogUtilsSearch.dependenceFactMsg(x, y, z, p)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java index f48381403b..f05e48845a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java @@ -27,8 +27,7 @@ import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; -import edu.cmu.tetrad.search.WIP.SepsetMapDci; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; @@ -132,7 +131,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { final double pValue = 1.0; if (this.verbose) { - TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, pValue)); + TetradLogger.getInstance().log("independencies", LogUtilsSearch.independenceFactMsg(x, y, z, pValue)); } independent = true; break; @@ -144,7 +143,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (independent) { NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFact(x, y, z) + " score = " + SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); + LogUtilsSearch.independenceFact(x, y, z) + " score = " + LogUtilsSearch.independenceFactMsg(x, y, z, getPValue())); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java index ffd9390376..9f68a62c9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.GraphChange; import edu.cmu.tetrad.search.PossibleDConnectingPath; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; @@ -788,7 +788,7 @@ private List> findSepAndAssoc(Graph graph) { variables.remove(x); variables.remove(y); - List> subsets = SearchGraphUtils.powerSet(variables); + List> subsets = GraphUtilsSearch.powerSet(variables); IonIndependenceFacts indep = new IonIndependenceFacts(x, y, new HashSet<>()); IonIndependenceFacts assoc = new IonIndependenceFacts(x, y, new HashSet<>()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java index d49075b42b..517f79ed8d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java @@ -28,7 +28,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; @@ -132,7 +132,7 @@ public IndependenceResult checkIndependence(Node x, Node y, Node... z) { if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, Arrays.asList(z), p)); + LogUtilsSearch.independenceFactMsg(x, y, Arrays.asList(z), p)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java index 22967e0bdc..c159c3d153 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.search.IndTestChiSquare; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; @@ -569,9 +569,9 @@ private static boolean isIndependentMajorityFdr(List independe // boolean independent = c < allPValues.size() - 2; if (independent) { - TetradLogger.getInstance().log("independence", "***FDR judges " + SearchLogUtils.independenceFact(x, y, condSet) + " independent"); + TetradLogger.getInstance().log("independence", "***FDR judges " + LogUtilsSearch.independenceFact(x, y, condSet) + " independent"); } else { - TetradLogger.getInstance().log("independence", "###FDR judges " + SearchLogUtils.independenceFact(x, y, condSet) + " dependent"); + TetradLogger.getInstance().log("independence", "###FDR judges " + LogUtilsSearch.independenceFact(x, y, condSet) + " dependent"); } TetradLogger.getInstance().log("independence", "c = " + c); @@ -619,9 +619,9 @@ private static boolean isIndependentMajorityIndep(List indepen boolean independent = c < allPValues.size() / 2; if (independent) { - TetradLogger.getInstance().log("independence", "***Majority = " + SearchLogUtils.independenceFact(x, y, condSet) + " independent"); + TetradLogger.getInstance().log("independence", "***Majority = " + LogUtilsSearch.independenceFact(x, y, condSet) + " independent"); } else { - TetradLogger.getInstance().log("independence", "###Majority = " + SearchLogUtils.independenceFact(x, y, condSet) + " dependent"); + TetradLogger.getInstance().log("independence", "###Majority = " + LogUtilsSearch.independenceFact(x, y, condSet) + " dependent"); } TetradLogger.getInstance().log("independence", "c = " + c); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java index c32f937e2b..270b4e4793 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java @@ -272,7 +272,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -800,19 +800,19 @@ private void orientUnshieldedTriples(Knowledge knowledge, if (this.graph.isAdjacentTo(x, z)) { continue; } - SearchGraphUtils.CpcTripleType type = SearchGraphUtils.getCpcTripleType(x, y, z, test, depth, graph); + GraphUtilsSearch.CpcTripleType type = GraphUtilsSearch.getCpcTripleType(x, y, z, test, depth, graph); - if (type == SearchGraphUtils.CpcTripleType.COLLIDER) { + if (type == GraphUtilsSearch.CpcTripleType.COLLIDER) { if (this.colliderAllowed(x, y, z, knowledge)) { graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } colliderTriples.add(new Triple(x, y, z)); - } else if (type == SearchGraphUtils.CpcTripleType.AMBIGUOUS) { + } else if (type == GraphUtilsSearch.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java index 6f6ff25e59..aaafa021ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java @@ -272,7 +272,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -729,19 +729,19 @@ private void orientUnshieldedTriples(Knowledge knowledge, if (this.graph.isAdjacentTo(x, z)) { continue; } - SearchGraphUtils.CpcTripleType type = SearchGraphUtils.getCpcTripleType(x, y, z, test, depth, graph); + GraphUtilsSearch.CpcTripleType type = GraphUtilsSearch.getCpcTripleType(x, y, z, test, depth, graph); - if (type == SearchGraphUtils.CpcTripleType.COLLIDER) { + if (type == GraphUtilsSearch.CpcTripleType.COLLIDER) { if (this.colliderAllowed(x, y, z, knowledge)) { graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } colliderTriples.add(new Triple(x, y, z)); - } else if (type == SearchGraphUtils.CpcTripleType.AMBIGUOUS) { + } else if (type == GraphUtilsSearch.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java index aca03fa817..8a935a00c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java @@ -253,7 +253,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, independenceTest, getDepth()); MeekRules meekRules = new MeekRules(); @@ -557,7 +557,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, this.graph.setEndpoint(x, y, Endpoint.ARROW); this.graph.setEndpoint(z, y, Endpoint.ARROW); - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } this.colliderTriples.add(new Triple(x, y, z)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java index 1e627ae472..217be1ae7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java @@ -227,7 +227,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -558,19 +558,19 @@ private void orientUnshieldedTriples(Knowledge knowledge, continue; } - SearchGraphUtils.CpcTripleType type = SearchGraphUtils.getCpcTripleType(x, y, z, test, depth, graph); + GraphUtilsSearch.CpcTripleType type = GraphUtilsSearch.getCpcTripleType(x, y, z, test, depth, graph); // SearchGraphUtils.CpcTripleType type = SearchGraphUtils.getCpcTripleType2(x, y, z, test, depth, graph); - if (type == SearchGraphUtils.CpcTripleType.COLLIDER) { + if (type == GraphUtilsSearch.CpcTripleType.COLLIDER) { if (this.colliderAllowed(x, y, z, knowledge)) { graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } colliderTriples.add(new Triple(x, y, z)); - } else if (type == SearchGraphUtils.CpcTripleType.AMBIGUOUS) { + } else if (type == GraphUtilsSearch.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java index 823689c181..52d227e11a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java @@ -255,7 +255,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - SearchGraphUtils.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -570,7 +570,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, this.graph.setEndpoint(x, y, Endpoint.ARROW); this.graph.setEndpoint(z, y, Endpoint.ARROW); - TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(x, y, z)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(x, y, z)); } this.colliderTriples.add(new Triple(x, y, z)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java index 8fe98bce6c..12b03a7fbb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import java.util.ArrayList; import java.util.List; @@ -53,8 +53,8 @@ private List randomPairSimulation() { //convert those dags to CPDAGs if (this.verbose) System.out.println("converting dags to CPDAGs"); - Graph graph1 = SearchGraphUtils.cpdagFromDag(dag1); - Graph graph2 = SearchGraphUtils.cpdagFromDag(dag2); + Graph graph1 = GraphUtilsSearch.cpdagFromDag(dag1); + Graph graph2 = GraphUtilsSearch.cpdagFromDag(dag2); //run Gdistance on these two graphs if (this.verbose) System.out.println("running Gdistance on the CPDAGs"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java index 4c3ecc8726..d477e6d974 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; @@ -75,7 +75,7 @@ public double[] run(int resimSize) { Graph estGraph = fges.search(); //if (verbose) System.out.println(estGraph); - Graph estGraphDAG = SearchGraphUtils.dagFromCPDAG(estGraph); + Graph estGraphDAG = GraphUtilsSearch.dagFromCPDAG(estGraph); Dag estDAG = new Dag(estGraphDAG); //Dag estDAG = new Dag(estGraph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java index e3178283dd..04fd465e71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.BdeuScore; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; import edu.cmu.tetrad.util.RandomUtil; @@ -90,7 +90,7 @@ public double[] run(int resimSize) { //if (verbose) System.out.println(estGraph); Graph estCPDAG = new EdgeListGraph(estGraph); - Graph estGraphDAG = SearchGraphUtils.dagFromCPDAG(estCPDAG); + Graph estGraphDAG = GraphUtilsSearch.dagFromCPDAG(estCPDAG); Dag estDAG = new Dag(estGraphDAG); //===========Identify the nodes to be resimulated=========== diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java index 5e39472b75..92ba699b42 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScore; import edu.cmu.tetrad.sem.SemEstimator; import edu.cmu.tetrad.sem.SemIm; @@ -89,7 +89,7 @@ public static void main(String[] args) { for (whichFrepeat = 0; whichFrepeat < fsimRepeat.size(); whichFrepeat++) { ArrayList errorsList = new ArrayList<>(); for (int r = 0; r < fsimRepeat.get(whichFrepeat); r++) { - Graph fgsDag = SearchGraphUtils.dagFromCPDAG(oFGSGraph); + Graph fgsDag = GraphUtilsSearch.dagFromCPDAG(oFGSGraph); Dag fgsdag2 = new Dag(fgsDag); //then fit an IM to this dag and the data. GeneralizedSemEstimator seems to bug out diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java index f0c420c095..c878870926 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.RandomGraph; import edu.cmu.tetrad.search.BdeuScore; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; @@ -70,7 +70,7 @@ public static List run(int numVars, double edgesPerNode, int numCases, //create various simulated data sets ////let's do the full simulated data set first: a dag in the FGES CPDAG fit to the data set. - Graph fgesDag = SearchGraphUtils.dagFromCPDAG(oGraphOut); + Graph fgesDag = GraphUtilsSearch.dagFromCPDAG(oGraphOut); Dag fgesdag2 = new Dag(fgesDag); BayesPm simBayesPm = new BayesPm(fgesdag2, bayesPm); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java index 736973dd17..9ed9e3518d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; @@ -52,7 +52,7 @@ public static void run(String readfilename, String filenameOut, char delimiter, System.out.println(estGraph); Graph estCPDAG = new EdgeListGraph(estGraph); - Graph estGraphDAG = SearchGraphUtils.dagFromCPDAG(estCPDAG); + Graph estGraphDAG = GraphUtilsSearch.dagFromCPDAG(estCPDAG); Dag estDAG = new Dag(estGraphDAG); //===========Identify the nodes to be resimulated=========== @@ -96,7 +96,7 @@ public static void run(String readfilename, String filenameOut, char delimiter, Graph estGraphOut = fgesOut.search(); System.out.println(estGraphOut); - SearchGraphUtils.graphComparison(estGraph, estGraphOut, System.out); + GraphUtilsSearch.graphComparison(estGraph, estGraphOut, System.out); } catch (Exception IOException) { IOException.printStackTrace(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java index 86ea270b6e..9d25cff584 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.VerticalIntDataBox; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.TextTable; import java.util.ArrayList; @@ -63,7 +63,7 @@ public static Set getAllParents(Graph inputgraph, Set inputnodes) { //this method returns an array of doubles, which are standard error metrics for graph learning public static double[] errorEval(Graph estCPDAG, Graph truePattern) { - GraphUtils.GraphComparison comparison = SearchGraphUtils.getGraphComparison2(estCPDAG, truePattern); + GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison2(estCPDAG, truePattern); int adjTp = comparison.getAdjCor(); int adjFp = comparison.getAdjFp(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index b9710ef829..88492776e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -15,7 +15,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Does a comparison of algorithm results across algorithm type, sample sizes, etc. @@ -183,24 +183,24 @@ public static ComparisonResult compare(ComparisonParameters params) { if (test == null) throw new IllegalArgumentException("Test not set."); Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { if (test == null) throw new IllegalArgumentException("Test not set."); Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) throw new IllegalArgumentException("Score not set."); Fges search = new Fges(score); search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES2) { if (score == null) throw new IllegalArgumentException("Score not set."); Fges search = new Fges(score); search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { if (test == null) throw new IllegalArgumentException("Test not set."); Fci search = new Fci(test); @@ -254,7 +254,7 @@ public static String summarize(List results, List Graph correctGraph = _result.getCorrectResult(); Graph resultGraph = _result.getResultGraph(); - GraphUtils.GraphComparison comparison = SearchGraphUtils.getGraphComparison2(correctGraph, resultGraph); + GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison2(correctGraph, resultGraph); int newRow = dataSet.getNumRows(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index a733728d5d..f0877af526 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -25,7 +25,7 @@ import java.util.Collections; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Does a comparison of algorithm results across algorithm type, sample sizes, @@ -133,16 +133,16 @@ public static ComparisonResult compare(ComparisonParameters params) { if (params.getAlgorithm() == ComparisonParameters.Algorithm.PC) { Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { Fges search = new Fges(score); //search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { Fci search = new Fci(test); result.setResultGraph(search.search()); @@ -368,14 +368,14 @@ public static ComparisonResult compare(ComparisonParameters params) { } Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { if (test == null) { throw new IllegalArgumentException("Test not set."); } Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) { throw new IllegalArgumentException("Score not set."); @@ -383,7 +383,7 @@ public static ComparisonResult compare(ComparisonParameters params) { Fges search = new Fges(score); //search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(SearchGraphUtils.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { if (test == null) { throw new IllegalArgumentException("Test not set."); @@ -455,7 +455,7 @@ public static TextTable summarize(List results, List vars = dag.getNodes(); @@ -903,7 +903,7 @@ private void testFgesMb(int numVars, double edgeFactor, int numCases, int numRun System.out.println("Calculating CPDAG for DAG"); - Graph CPDAG = SearchGraphUtils.cpdagForDag(dag); + Graph CPDAG = GraphUtilsSearch.cpdagForDag(dag); int[] tiers = new int[dag.getNumNodes()]; @@ -1195,7 +1195,7 @@ public void testGFciComparison() { // dagToPag.setMaxPathLength(maxPathLength); // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(dag); + Graph truePag = GraphUtilsSearch.dagToPag(dag); System.out.println("True PAG_of_the_true_DAG done"); @@ -1255,7 +1255,7 @@ public void testGFciComparison() { ffciArrowStats.add(printCorrectArrows(dag, estPag, truePag)); ffciTailStats.add(printCorrectTails(dag, estPag, truePag)); - ffciCounts.add(SearchGraphUtils.getGraphComparison2(estPag, truePag)); + ffciCounts.add(GraphUtilsSearch.getGraphComparison2(estPag, truePag)); elapsed = ta2 - ta1; ffciElapsedTimes.add(elapsed); @@ -1326,7 +1326,7 @@ public void testCompareDagToCPDAG(int numLatents) { System.out.println("PC graph = " + left); - Graph top = SearchGraphUtils.cpdagForDag(dag); + Graph top = GraphUtilsSearch.cpdagForDag(dag); System.out.println("DAG to CPDAG graph = " + top); @@ -1376,7 +1376,7 @@ public void testComparePcVersions(int numVars, double edgeFactor, int numLatents System.out.println("Graph done"); - Graph left = SearchGraphUtils.cpdagForDag(dag);// pc1.search(); + Graph left = GraphUtilsSearch.cpdagForDag(dag);// pc1.search(); System.out.println("First FAS graph = " + left); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java index 9499b381f4..31547f7bfa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java @@ -40,7 +40,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; /** * Contains some tests for Dan Malinsky, that might be of interest to others. diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java index 414b9438cf..250bf12277 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.MillisecondTimes; import java.io.File; @@ -38,7 +38,7 @@ public class ExploreIndepTests { public static void main(String[] args) { try { String path = ExampleMixedSearch.class.getResource("test_data").getPath(); - Graph trueGraph = SearchGraphUtils.cpdagFromDag(GraphPersistence.loadGraphTxt(new File(path, "DAG_0_graph.txt"))); + Graph trueGraph = GraphUtilsSearch.cpdagFromDag(GraphPersistence.loadGraphTxt(new File(path, "DAG_0_graph.txt"))); DataSet ds = MixedUtils.loadDataSet(path, "DAG_0_data.txt"); IndTestMultinomialLogisticRegression indMix = new IndTestMultinomialLogisticRegression(ds, .05); @@ -54,15 +54,15 @@ public static void main(String[] args) { s3.setStable(true); long time = MillisecondTimes.timeMillis(); - Graph g1 = SearchGraphUtils.cpdagFromDag(s1.search()); + Graph g1 = GraphUtilsSearch.cpdagFromDag(s1.search()); System.out.println("Mix Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); time = MillisecondTimes.timeMillis(); - Graph g2 = SearchGraphUtils.cpdagFromDag(s2.search()); + Graph g2 = GraphUtilsSearch.cpdagFromDag(s2.search()); System.out.println("Wald lin Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); time = MillisecondTimes.timeMillis(); - Graph g3 = SearchGraphUtils.cpdagFromDag(s3.search()); + Graph g3 = GraphUtilsSearch.cpdagFromDag(s3.search()); System.out.println("Wald log Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); System.out.println(MixedUtils.EdgeStatHeader); diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java index 8b2995aff3..b102d9f8cb 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; @@ -228,9 +228,9 @@ private IndependenceResult isIndependentMultinomialLogisticRegression(Node x, No this.lastP = p; if (independent) { - TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, p)); + TetradLogger.getInstance().log("independencies", LogUtilsSearch.independenceFactMsg(x, y, z, p)); } else { - TetradLogger.getInstance().log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, p)); + TetradLogger.getInstance().log("dependencies", LogUtilsSearch.dependenceFactMsg(x, y, z, p)); } return new IndependenceResult(new IndependenceFact(x, y, z), independent, p); @@ -249,7 +249,7 @@ private IndependenceResult isIndependentMultinomialLogisticRegression(Node x, No if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, p)); + LogUtilsSearch.independenceFactMsg(x, y, z, p)); } } @@ -339,7 +339,7 @@ private IndependenceResult isIndependentRegression(Node x, Node y, List z) if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( - SearchLogUtils.independenceFactMsg(x, y, z, p)); + LogUtilsSearch.independenceFactMsg(x, y, z, p)); } } diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java index f8c09c81d9..b457e5fc0b 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java @@ -6,9 +6,8 @@ import edu.cmu.tetrad.search.GraphSearch; import edu.cmu.tetrad.search.IndTestProbabilistic; import edu.cmu.tetrad.search.Rfci; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.GraphSampling; -import edu.pitt.dbmi.algo.resampling.ResamplingEdgeEnsemble; import java.util.LinkedList; import java.util.List; @@ -75,7 +74,7 @@ private List runSearches() { for (Future completedTask : completedTasks) { try { Graph graph = completedTask.get(); - if (graph != null && SearchGraphUtils.isLegalPag(graph).isLegalPag()) { + if (graph != null && GraphUtilsSearch.isLegalPag(graph).isLegalPag()) { graphs.add(graph); } } catch (ExecutionException exception) { diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java index bff8982131..801f6523b5 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java @@ -251,7 +251,7 @@ public Boolean call() throws Exception { Graph depPattern = fges.search(); depPattern = GraphUtils.replaceNodes(depPattern, depData.getVariables()); - Graph estDepBN = SearchGraphUtils.dagFromCPDAG(depPattern); + Graph estDepBN = GraphUtilsSearch.dagFromCPDAG(depPattern); if (this.verbose) { this.out.println("estDepBN:"); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java index 486e38b6f8..ec2bf9f717 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.RandomGraph; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.Kci; -import edu.cmu.tetrad.search.SearchLogUtils; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.NumberFormatUtil; @@ -59,7 +59,7 @@ public void test1() { + " non-descendants = " + nondesc); for (Node y : nondesc) { - System.out.print("\t" + SearchLogUtils.independenceFact(x, y, cond)); + System.out.print("\t" + LogUtilsSearch.independenceFact(x, y, cond)); IndependenceResult result = test.checkIndependence(x, y, cond); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java index bb424b956a..3b7862687c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.DagInCpcagIterator; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; @@ -55,7 +55,7 @@ public void test1() { Dag dag = new Dag(graph); - Graph CPDAG = SearchGraphUtils.cpdagFromDag(graph); + Graph CPDAG = GraphUtilsSearch.cpdagFromDag(graph); System.out.println(CPDAG); @@ -176,7 +176,7 @@ public void test5() { Dag dag1 = new Dag(RandomGraph.randomGraph(nodes1, 0, 3, 30, 15, 15, false)); - Graph CPDAG = SearchGraphUtils.cpdagForDag(dag1); + Graph CPDAG = GraphUtilsSearch.cpdagForDag(dag1); List nodes = CPDAG.getNodes(); // Make random knowedge. diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java index 4abb830ee4..2d1e8b2ee2 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java @@ -22,7 +22,7 @@ package edu.cmu.tetrad.test; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import org.junit.Test; import java.util.ArrayList; @@ -162,7 +162,7 @@ public void test5() { graph2.removeEdge(nodes.get(0), nodes.get(1)); - int shd = SearchGraphUtils.structuralHammingDistance(graph1, graph2); + int shd = GraphUtilsSearch.structuralHammingDistance(graph1, graph2); assertEquals(3, shd); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java index c2e317e69e..c9c72f2d9b 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java @@ -195,7 +195,7 @@ public void testSearch13() { // DagToPag dagToPag = new DagToPag(trueGraph); // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(trueGraph); + Graph truePag = GraphUtilsSearch.dagToPag(trueGraph); assertEquals(graph, truePag); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index a78708ab79..87871fe913 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java @@ -109,7 +109,7 @@ public void explore1() { alg.setFaithfulnessAssumed(true); Graph estCPDAG = alg.search(); - Graph trueCPDAG = SearchGraphUtils.cpdagForDag(dag); + Graph trueCPDAG = GraphUtilsSearch.cpdagForDag(dag); estCPDAG = GraphUtils.replaceNodes(estCPDAG, vars); @@ -174,9 +174,9 @@ public void explore2() { Graph estCPDAG = ges.search(); - Graph trueCPDAG = SearchGraphUtils.cpdagForDag(dag); + Graph trueCPDAG = GraphUtilsSearch.cpdagForDag(dag); - int[][] counts = SearchGraphUtils.graphComparison(trueCPDAG, estCPDAG, null); + int[][] counts = GraphUtilsSearch.graphComparison(trueCPDAG, estCPDAG, null); int[][] expectedCounts = { {2, 0, 0, 0, 0, 1}, @@ -197,7 +197,7 @@ public void testExplore3() { Graph graph = GraphUtils.convert("A-->B,A-->C,B-->D,C-->D"); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); Graph CPDAG = fges.search(); - assertEquals(SearchGraphUtils.cpdagForDag(graph), CPDAG); + assertEquals(GraphUtilsSearch.cpdagForDag(graph), CPDAG); } @Test @@ -205,7 +205,7 @@ public void testExplore4() { Graph graph = GraphUtils.convert("A-->B,A-->C,A-->D,B-->E,C-->E,D-->E"); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); Graph CPDAG = fges.search(); - assertEquals(SearchGraphUtils.cpdagForDag(graph), CPDAG); + assertEquals(GraphUtilsSearch.cpdagForDag(graph), CPDAG); } @Test @@ -214,7 +214,7 @@ public void testExplore5() { edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); fges.setFaithfulnessAssumed(false); Graph CPDAG = fges.search(); - assertEquals(SearchGraphUtils.cpdagForDag(graph), CPDAG); + assertEquals(GraphUtilsSearch.cpdagForDag(graph), CPDAG); } @@ -672,7 +672,7 @@ public void testFromGraph() { fges.setVerbose(true); fges.setParallelized(true); Graph CPDAG1 = fges.search(); - Graph CPDAG2 = SearchGraphUtils.cpdagFromDag(dag); + Graph CPDAG2 = GraphUtilsSearch.cpdagFromDag(dag); assertEquals(CPDAG2, CPDAG1); } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java index e299ab269c..94f3b340be 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java @@ -101,11 +101,11 @@ public void test1() { // dagToPag.setMaxPathLength(maxPathLength); // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(dag); + Graph truePag = GraphUtilsSearch.dagToPag(dag); outGraph = GraphUtils.replaceNodes(outGraph, truePag.getNodes()); - int[][] counts = SearchGraphUtils.graphComparison(truePag, outGraph, null); + int[][] counts = GraphUtilsSearch.graphComparison(truePag, outGraph, null); int[][] expectedCounts = { {0, 0, 0, 0, 0, 0}, @@ -184,7 +184,7 @@ public void testFromGraph() { // dagToPag.setCompleteRuleSetUsed(false); // Graph pag2 = dagToPag.convert(); - Graph pag2 = SearchGraphUtils.dagToPag(dag); + Graph pag2 = GraphUtilsSearch.dagToPag(dag); assertEquals(pag2, pag1); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java index 8f3d6a8d12..4b612823d5 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java @@ -37,7 +37,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -189,7 +189,7 @@ public void testGFCIc() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(dag); + Graph truePag = GraphUtilsSearch.dagToPag(dag); int[] causalOrdering = new int[numVars]; @@ -251,7 +251,7 @@ public void testGFCId() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(dag); + Graph truePag = GraphUtilsSearch.dagToPag(dag); BayesPm pm = new BayesPm(dag, 2, 3); BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM); @@ -311,7 +311,7 @@ public void testFCIc() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(dag); + Graph truePag = GraphUtilsSearch.dagToPag(dag); int[] causalOrdering = new int[numVars]; @@ -375,7 +375,7 @@ public void testFCId() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = SearchGraphUtils.dagToPag(dag); + Graph truePag = GraphUtilsSearch.dagToPag(dag); BayesPm pm = new BayesPm(dag, 2, 3); BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 433b8dc132..ac66147f57 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -1671,10 +1671,10 @@ private void testForWayne3() { } private static void extractedWayne(Node x1, Node x2, Node x3, Node x4, IndependenceTest chiSq) { - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList()) + " " + chiSq.checkIndependence(x1, x2).isIndependent()); - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x3)) + " " + chiSq.checkIndependence(x1, x2, x3).isIndependent()); - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x4)) + " " + chiSq.checkIndependence(x1, x2, x4).isIndependent()); - System.out.println(SearchLogUtils.independenceFact(x1, x2, nodeList(x3, x4)) + " " + chiSq.checkIndependence(x1, x2, x3, x4).isIndependent()); + System.out.println(LogUtilsSearch.independenceFact(x1, x2, nodeList()) + " " + chiSq.checkIndependence(x1, x2).isIndependent()); + System.out.println(LogUtilsSearch.independenceFact(x1, x2, nodeList(x3)) + " " + chiSq.checkIndependence(x1, x2, x3).isIndependent()); + System.out.println(LogUtilsSearch.independenceFact(x1, x2, nodeList(x4)) + " " + chiSq.checkIndependence(x1, x2, x4).isIndependent()); + System.out.println(LogUtilsSearch.independenceFact(x1, x2, nodeList(x3, x4)) + " " + chiSq.checkIndependence(x1, x2, x3, x4).isIndependent()); } @NotNull @@ -2578,7 +2578,7 @@ public void testFcoAlgsFromDsep() { Graph trueGraph = RandomGraph.randomGraph(20, 8, 40, 100, 100, 100, false); - Graph truePag = SearchGraphUtils.dagToPag(trueGraph); + Graph truePag = GraphUtilsSearch.dagToPag(trueGraph); trueGraphMap.put(i, new HashMap<>()); trueGraphs.add(trueGraph); @@ -2697,7 +2697,7 @@ public void testDsep() { for (Node y : graph.getNodes()) { if (!graph.paths().isDescendentOf(y, x) && !parents.contains(y)) { if (!graph.paths().isDSeparatedFrom(x, y, parents)) { - System.out.println("Failure! " + SearchLogUtils.dependenceFactMsg(x, y, parents, 1.0)); + System.out.println("Failure! " + LogUtilsSearch.dependenceFactMsg(x, y, parents, 1.0)); } } } @@ -3071,8 +3071,8 @@ public void testWayne2() { g2 = GraphUtils.replaceNodes(g2, g1.getNodes()); if (g1.equals(g2)) gsCount++; - gsShd += SearchGraphUtils.structuralHammingDistance( - SearchGraphUtils.cpdagForDag(g1), SearchGraphUtils.cpdagForDag(g2)); + gsShd += GraphUtilsSearch.structuralHammingDistance( + GraphUtilsSearch.cpdagForDag(g1), GraphUtilsSearch.cpdagForDag(g2)); for (int i = 0; i < alpha.length; i++) { // test.setAlpha(alpha[i]); @@ -3086,8 +3086,8 @@ public void testWayne2() { g3 = GraphUtils.replaceNodes(g3, g1.getNodes()); if (g1.equals(g3)) pearlCounts[i]++; - pearlShd[i] += SearchGraphUtils.structuralHammingDistance( - SearchGraphUtils.cpdagForDag(g1), SearchGraphUtils.cpdagForDag(g3)); + pearlShd[i] += GraphUtilsSearch.structuralHammingDistance( + GraphUtilsSearch.cpdagForDag(g1), GraphUtilsSearch.cpdagForDag(g3)); } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index c1cf54c1ae..52c84d21a5 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -103,7 +103,7 @@ public void test1() { mimbuild.setPenaltyDiscount(1); mimbuild.setMinClusterSize(3); mimbuildStructure = mimbuild.search(partition, latentVarList, new CovarianceMatrix(data)); - int shd = SearchGraphUtils.structuralHammingDistance(mimStructure, mimbuildStructure); + int shd = GraphUtilsSearch.structuralHammingDistance(mimStructure, mimbuildStructure); assertEquals(7, shd); } else if (mimbuildMethod == 3) { // System.out.println("Mimbuild Trek\n"); @@ -111,7 +111,7 @@ public void test1() { mimbuild.setAlpha(0.1); mimbuild.setMinClusterSize(3); mimbuildStructure = mimbuild.search(partition, latentVarList, new CovarianceMatrix(data)); - int shd = SearchGraphUtils.structuralHammingDistance(mimStructure, mimbuildStructure); + int shd = GraphUtilsSearch.structuralHammingDistance(mimStructure, mimbuildStructure); assertEquals(3, shd); } else { throw new IllegalStateException(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java index 785fbb5a0f..c867eb366a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java @@ -39,7 +39,7 @@ import java.util.Comparator; import java.util.List; -import static edu.cmu.tetrad.search.SearchGraphUtils.dagToPag; +import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -217,7 +217,7 @@ public void checknumCPDAGsToStore() { IndTestDSep test = new IndTestDSep(graph); Pc pc = new Pc(test); Graph CPDAG = pc.search(); - Graph CPDAG2 = SearchGraphUtils.cpdagFromDag(graph); + Graph CPDAG2 = GraphUtilsSearch.cpdagFromDag(graph); assertEquals(CPDAG, CPDAG2); } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java index abda0f57e8..34cb86f677 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.IndTestProbabilistic; -import edu.cmu.tetrad.search.SearchGraphUtils; +import edu.cmu.tetrad.search.GraphUtilsSearch; import edu.cmu.tetrad.search.BayesImParser; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; @@ -61,7 +61,7 @@ public void testRandomDiscreteData() { // dagToPag.setCompleteRuleSetUsed(false); // Graph PAG_True = dagToPag.convert(); - Graph PAG_True = SearchGraphUtils.dagToPag(dag); + Graph PAG_True = GraphUtilsSearch.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, dataSet.getVariables()); @@ -134,7 +134,7 @@ public void testDiscreteRealData() { // dagToPag.setCompleteRuleSetUsed(false); // Graph PAG_True = dagToPag.convert(); - Graph PAG_True = SearchGraphUtils.dagToPag(dag); + Graph PAG_True = GraphUtilsSearch.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, dataSet.getVariables()); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java index 316dd979be..daa8b0b302 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java @@ -83,8 +83,8 @@ public void testDSeparation() { } if (graph.isDSeparatedFrom(x, y, z) != graph.isDSeparatedFrom(y, x, z)) { - fail(SearchLogUtils.independenceFact(x, y, z) + " should have same d-sep result as " + - SearchLogUtils.independenceFact(y, x, z)); + fail(LogUtilsSearch.independenceFact(x, y, z) + " should have same d-sep result as " + + LogUtilsSearch.independenceFact(y, x, z)); } } From 975675159f762851e45c8ebe696f7a3463d90cac Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:57:13 -0400 Subject: [PATCH 315/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/GraphUtilsSearch.java | 283 ------------------ .../java/edu/cmu/tetrad/search/MbUtils.java | 5 +- 2 files changed, 3 insertions(+), 285 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java index e3f4ca701a..855dfd2621 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java @@ -213,23 +213,6 @@ private static List sepset(Graph graph, Node a, Node c, Set containi return null; } - /** - * Orients using Meek rules, double checking noncolliders locally. - */ - public static void orientUsingMeekRulesLocally(Knowledge knowledge, - Graph graph, IndependenceTest test, int depth) { - TetradLogger.getInstance().log("info", "Starting Orientation Step D."); - boolean changed; - - do { - changed = GraphUtilsSearch.meekR1Locally(graph, knowledge, test, depth) - || GraphUtilsSearch.meekR2(graph, knowledge) || GraphUtilsSearch.meekR3(graph, knowledge) - || GraphUtilsSearch.meekR4(graph, knowledge); - } while (changed); - - TetradLogger.getInstance().log("info", "Finishing Orientation Step D."); - } - /** * Step C of PC; orients colliders using specified sepset. That is, orients * x *-* y *-* z as x *-> y <-* z just in case y is in Sepset({x, z}). @@ -289,272 +272,6 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg } - public static boolean existsLocalSepsetWithout(Node x, Node y, Node z, - IndependenceTest test, Graph graph, int depth) { - Set __nodes = new HashSet<>(graph.getAdjacentNodes(x)); - __nodes.addAll(graph.getAdjacentNodes(z)); - __nodes.remove(x); - __nodes.remove(z); - List _nodes = new LinkedList<>(__nodes); - TetradLogger.getInstance().log("adjacencies", - "Adjacents for " + x + "--" + y + "--" + z + " = " + _nodes); - - int _depth = depth; - if (_depth == -1) { - _depth = 1000; - } - _depth = FastMath.min(_depth, _nodes.size()); - - for (int d = 0; d <= _depth; d++) { - if (_nodes.size() >= d) { - ChoiceGenerator cg2 = new ChoiceGenerator(_nodes.size(), d); - int[] choice; - - while ((choice = cg2.next()) != null) { - List condSet = GraphUtils.asList(choice, _nodes); - - if (condSet.contains(y)) { - continue; - } - - // LogUtils.getInstance().finest("Trying " + condSet); - if (test.checkIndependence(x, z, condSet).isIndependent()) { - return true; - } - } - } - } - - return false; - } - - /** - * Orient away from collider. - */ - public static boolean meekR1Locally(Graph graph, Knowledge knowledge, - IndependenceTest test, int depth) { - List nodes = graph.getNodes(); - boolean changed = true; - - while (changed) { - changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg - = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - // Skip triples that are shielded. - if (graph.isAdjacentTo(b, c)) { - continue; - } - - if (graph.getEndpoint(b, a) == Endpoint.ARROW - && graph.paths().isUndirectedFromTo(a, c)) { - if (GraphUtilsSearch.existsLocalSepsetWithout(b, a, c, test, graph, - depth)) { - continue; - } - - if (GraphUtilsSearch.isArrowpointAllowed(a, c, knowledge)) { - graph.setEndpoint(a, c, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R1", graph.getEdge(a, c))); - changed = true; - } - } else if (graph.getEndpoint(c, a) == Endpoint.ARROW - && graph.paths().isUndirectedFromTo(a, b)) { - if (GraphUtilsSearch.existsLocalSepsetWithout(b, a, c, test, graph, - depth)) { - continue; - } - - if (GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge)) { - graph.setEndpoint(a, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R1", graph.getEdge(a, b))); - changed = true; - } - } - } - } - } - - return false; - } - - /** - * If - */ - public static boolean meekR2(Graph graph, Knowledge knowledge) { - List nodes = graph.getNodes(); - final boolean changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - if (graph.paths().isDirectedFromTo(b, a) - && graph.paths().isDirectedFromTo(a, c) - && graph.paths().isUndirectedFromTo(b, c)) { - if (GraphUtilsSearch.isArrowpointAllowed(b, c, knowledge)) { - graph.setEndpoint(b, c, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R2", graph.getEdge(b, c))); - } - } else if (graph.paths().isDirectedFromTo(c, a) - && graph.paths().isDirectedFromTo(a, b) - && graph.paths().isUndirectedFromTo(c, b)) { - if (GraphUtilsSearch.isArrowpointAllowed(c, b, knowledge)) { - graph.setEndpoint(c, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R2", graph.getEdge(c, b))); - } - } - } - } - - return changed; - } - - /** - * Meek's rule R3. If a--b, a--c, a--d, c-->b, c-->b, then orient a-->b. - */ - public static boolean meekR3(Graph graph, Knowledge knowledge) { - - List nodes = graph.getNodes(); - boolean changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 3) { - continue; - } - - for (Node b : adjacentNodes) { - List otherAdjacents = new LinkedList<>(adjacentNodes); - otherAdjacents.remove(b); - - if (!graph.paths().isUndirectedFromTo(a, b)) { - continue; - } - - ChoiceGenerator cg - = new ChoiceGenerator(otherAdjacents.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node c = otherAdjacents.get(combination[0]); - Node d = otherAdjacents.get(combination[1]); - - if (graph.isAdjacentTo(c, d)) { - continue; - } - - if (!graph.paths().isUndirectedFromTo(a, c)) { - continue; - } - - if (!graph.paths().isUndirectedFromTo(a, d)) { - continue; - } - - if (graph.paths().isDirectedFromTo(c, b) - && graph.paths().isDirectedFromTo(d, b)) { - if (GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge)) { - graph.setEndpoint(a, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek R3", graph.getEdge(a, b))); - changed = true; - break; - } - } - } - } - } - - return changed; - } - - public static boolean meekR4(Graph graph, Knowledge knowledge) { - if (knowledge == null) { - return false; - } - - List nodes = graph.getNodes(); - boolean changed = false; - - for (Node a : nodes) { - List adjacentNodes = graph.getAdjacentNodes(a); - - if (adjacentNodes.size() < 3) { - continue; - } - - for (Node d : adjacentNodes) { - if (!graph.isAdjacentTo(a, d)) { - continue; - } - - List otherAdjacents = new LinkedList<>(adjacentNodes); - otherAdjacents.remove(d); - - ChoiceGenerator cg - = new ChoiceGenerator(otherAdjacents.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node b = otherAdjacents.get(combination[0]); - Node c = otherAdjacents.get(combination[1]); - - if (!graph.paths().isUndirectedFromTo(a, b)) { - continue; - } - - if (!graph.paths().isUndirectedFromTo(a, c)) { - continue; - } - - if (graph.paths().isDirectedFromTo(b, c) - && graph.paths().isDirectedFromTo(d, c)) { - if (GraphUtilsSearch.isArrowpointAllowed(a, c, knowledge)) { - graph.setEndpoint(a, c, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek T1", graph.getEdge(a, c))); - changed = true; - break; - } - } else if (graph.paths().isDirectedFromTo(c, d) - && graph.paths().isDirectedFromTo(d, b)) { - if (GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge)) { - graph.setEndpoint(a, b, Endpoint.ARROW); - TetradLogger.getInstance().log("impliedOrientation", LogUtilsSearch.edgeOrientedMsg("Meek T1", graph.getEdge(a, b))); - changed = true; - break; - } - } - } - } - } - - return changed; - } - /** * Checks if an arrowpoint is allowed by background knowledge. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java index d3af42a50a..420d71c246 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java @@ -291,8 +291,9 @@ private static Set listMbDags(Graph mbCPDAG, private static void doAbbreviatedMbOrientation(Graph graph, IndependenceTest test, int depth, Node target) { - GraphUtilsSearch.orientUsingMeekRulesLocally(new Knowledge(), graph, - test, depth); + MeekRules meekRules = new MeekRules(); + meekRules.setRevertToUnshieldedColliders(false); + meekRules.orientImplied(graph); MbUtils.trimToMbNodes(graph, target, false); MbUtils.trimEdgesAmongParents(graph, target); MbUtils.trimEdgesAmongParentsOfChildren(graph, target); From fbd5295e3933c31ca38f726774076a0bc1c57e25 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:58:32 -0400 Subject: [PATCH 316/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java index 855dfd2621..83130b1fb3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java @@ -419,9 +419,6 @@ public static Graph pagToMag(Graph pag) { Graph mag = new EdgeListGraph(pag.getNodes()); for (Edge e : pag.getEdges()) mag.addEdge(new Edge(e)); - SepsetProducer sepsets = new DagSepsets(mag); - FciOrient fciOrient = new FciOrient(sepsets); - List nodes = mag.getNodes(); Graph pcafci = new EdgeListGraph(nodes); @@ -791,7 +788,7 @@ public static void arrangeByKnowledgeTiers(Graph graph) { public static Set getReachableNodes(List initialNodes, LegalPairs legalPairs, List c, List d, Graph graph, int maxPathLength) { HashSet reachable = new HashSet<>(); - MultiKeyMap visited = new MultiKeyMap(); + MultiKeyMap visited = new MultiKeyMap<>(); List nextEdges = new LinkedList<>(); for (Node x : initialNodes) { From 2c0f4672032d31e336610d9d034cd7e7f126ffbf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 13:59:56 -0400 Subject: [PATCH 317/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/graph/GraphUtils.java | 4 ++-- .../main/java/edu/cmu/tetrad/search/Cfci.java | 6 ++--- .../java/edu/cmu/tetrad/search/FciOrient.java | 14 ++++++------ .../cmu/tetrad/search/GraphUtilsSearch.java | 10 ++++----- .../main/java/edu/cmu/tetrad/search/MaxP.java | 4 ++-- .../java/edu/cmu/tetrad/search/MeekRules.java | 4 ++-- .../java/edu/cmu/tetrad/search/PcCommon.java | 4 ++-- .../main/java/edu/cmu/tetrad/search/Rfci.java | 6 ++--- .../java/edu/cmu/tetrad/search/WIP/Dci.java | 22 +++++++++---------- .../java/edu/cmu/tetrad/search/WIP/Ion.java | 14 ++++++------ 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index 8ffb68b5e9..07a97fd89b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -1844,8 +1844,8 @@ public static void retainUnshieldedColliders(Graph graph, Knowledge knowledge) { Node c = adjacentNodes.get(combination[1]); if (orig.isDefCollider(a, b, c) && !orig.isAdjacentTo(a, c)) { - if (FciOrient.isArrowpointAllowed(a, b, graph, knowledge) - && FciOrient.isArrowpointAllowed(c, b, graph, knowledge)) { + if (FciOrient.isArrowheadAllowed(a, b, graph, knowledge) + && FciOrient.isArrowheadAllowed(c, b, graph, knowledge)) { graph.setEndpoint(a, b, Endpoint.ARROW); graph.setEndpoint(c, b, Endpoint.ARROW); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 6715ce78cd..e4c99a9de1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -325,8 +325,8 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { List sepset = sepsets.get(x, z); if (type == TripleType.COLLIDER || (sepset != null && !sepset.contains(y))) { - if (isArrowpointAllowed(x, y) && - isArrowpointAllowed(z, y)) { + if (isArrowheadAllowed(x, y) && + isArrowheadAllowed(z, y)) { getGraph().setEndpoint(x, y, Endpoint.ARROW); getGraph().setEndpoint(z, y, Endpoint.ARROW); @@ -358,7 +358,7 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { * @param y The possible point node. * @return Whether the arrowpoint is allowed. */ - private boolean isArrowpointAllowed(Node x, Node y) { + private boolean isArrowheadAllowed(Node x, Node y) { if (this.graph.getEndpoint(x, y) == Endpoint.ARROW) { return true; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java index f63a867a74..f660789824 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java @@ -188,11 +188,11 @@ public void ruleR0(Graph graph) { } if (this.sepsets.isUnshieldedCollider(a, b, c)) { - if (!isArrowpointAllowed(a, b, graph, knowledge)) { + if (!isArrowheadAllowed(a, b, graph, knowledge)) { continue; } - if (!isArrowpointAllowed(c, b, graph, knowledge)) { + if (!isArrowheadAllowed(c, b, graph, knowledge)) { continue; } @@ -332,7 +332,7 @@ public void ruleR1(Node a, Node b, Node c, Graph graph) { } if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(b, c, graph, knowledge)) { + if (!isArrowheadAllowed(b, c, graph, knowledge)) { return; } @@ -353,7 +353,7 @@ public void ruleR2(Node a, Node b, Node c, Graph graph) { if ((graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(b, c) == Endpoint.ARROW) && (graph.getEndpoint(b, a) == Endpoint.TAIL || graph.getEndpoint(c, b) == Endpoint.TAIL)) { - if (!isArrowpointAllowed(a, c, graph, knowledge)) { + if (!isArrowheadAllowed(a, c, graph, knowledge)) { return; } @@ -738,11 +738,11 @@ public boolean doDdpOrientation(Node d, Node a, Node b, Node c, Graph graph) { } if (!sepset.contains(b) && doDiscriminatingPathColliderRule) { - if (!isArrowpointAllowed(a, b, graph, knowledge)) { + if (!isArrowheadAllowed(a, b, graph, knowledge)) { return false; } - if (!isArrowpointAllowed(c, b, graph, knowledge)) { + if (!isArrowheadAllowed(c, b, graph, knowledge)) { return false; } @@ -1062,7 +1062,7 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { this.logger.forceLogMessage("Finishing BK Orientation."); } - public static boolean isArrowpointAllowed(Node x, Node y, Graph graph, Knowledge knowledge) { + public static boolean isArrowheadAllowed(Node x, Node y, Graph graph, Knowledge knowledge) { if (!graph.isAdjacentTo(x, y)) return false; if (graph.getEndpoint(x, y) == Endpoint.ARROW) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java index 83130b1fb3..6dec8e0006 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java @@ -166,8 +166,8 @@ public static void pcdOrientC(IndependenceTest test, Knowledge knowledge, Graph continue; } - if (!GraphUtilsSearch.isArrowpointAllowed(x, y, knowledge) - || !GraphUtilsSearch.isArrowpointAllowed(z, y, knowledge)) { + if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge) + || !GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge)) { continue; } @@ -245,8 +245,8 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg //I think the null check needs to be here --AJ if (sepset != null && !sepset.contains(b) - && GraphUtilsSearch.isArrowpointAllowed(a, b, knowledge) - && GraphUtilsSearch.isArrowpointAllowed(c, b, knowledge)) { + && GraphUtilsSearch.isArrowheadAllowed(a, b, knowledge) + && GraphUtilsSearch.isArrowheadAllowed(c, b, knowledge)) { if (verbose) { System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); } @@ -275,7 +275,7 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg /** * Checks if an arrowpoint is allowed by background knowledge. */ - public static boolean isArrowpointAllowed(Object from, Object to, + public static boolean isArrowheadAllowed(Object from, Object to, Knowledge knowledge) { if (knowledge == null) { return true; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java index d6650cc548..cf4634cafb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java @@ -209,8 +209,8 @@ private void testColliderMaxP(Graph graph, Map scores, Node a, N adja.remove(c); adjc.remove(a); - if (!(PcCommon.isArrowpointAllowed(a, b, knowledge) - && (PcCommon.isArrowpointAllowed(c, b, knowledge)))) { + if (!(PcCommon.isArrowheadAllowed(a, b, knowledge) + && (PcCommon.isArrowheadAllowed(c, b, knowledge)))) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java index f985c19e5b..b2936b3843 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java @@ -302,7 +302,7 @@ private boolean meekR4(Node a, Node b, Graph graph, Set visited) { } private boolean direct(Node a, Node c, Graph graph, Set visited) { - if (!MeekRules.isArrowpointAllowed(a, c, this.knowledge)) return false; + if (!MeekRules.isArrowheadAllowed(a, c, this.knowledge)) return false; if (!Edges.isUndirectedEdge(graph.getEdge(a, c))) return false; Edge before = graph.getEdge(a, c); @@ -324,7 +324,7 @@ private boolean direct(Node a, Node c, Graph graph, Set visited) { return true; } - private static boolean isArrowpointAllowed(Node from, Node to, Knowledge knowledge) { + private static boolean isArrowheadAllowed(Node from, Node to, Knowledge knowledge) { if (knowledge.isEmpty()) return true; return !knowledge.isRequired(to.toString(), from.toString()) && !knowledge.isForbidden(from.toString(), to.toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java index 712df097e4..e3270a64c0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java @@ -130,7 +130,7 @@ public static boolean isArrowpointAllowed1(Node from, Node to, /** * Checks if an arrowpoint is allowed by background knowledge. */ - public static boolean isArrowpointAllowed(Object from, Object to, + public static boolean isArrowheadAllowed(Object from, Object to, Knowledge knowledge) { if (knowledge == null) { return true; @@ -620,7 +620,7 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra List s2 = new ArrayList<>(sepset); if (!s2.contains(b)) s2.add(b); - if (!sepset.contains(b) && PcCommon.isArrowpointAllowed(a, b, knowledge) && PcCommon.isArrowpointAllowed(c, b, knowledge)) { + if (!sepset.contains(b) && PcCommon.isArrowheadAllowed(a, b, knowledge) && PcCommon.isArrowheadAllowed(c, b, knowledge)) { PcCommon.orientCollider(a, b, c, conflictRule, graph); if (verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index e4ea77e4fa..f254457282 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -370,11 +370,11 @@ private void ruleR0_RFCI(List rTuples) { if (!sepset.contains(j) && this.graph.isAdjacentTo(i, j) && this.graph.isAdjacentTo(j, k)) { - if (!isArrowpointAllowed(i, j)) { + if (!isArrowheadAllowed(i, j)) { continue; } - if (!isArrowpointAllowed(k, j)) { + if (!isArrowheadAllowed(k, j)) { continue; } @@ -566,7 +566,7 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { * @param y The possible point node. * @return Whether the arrowpoint is allowed. */ - private boolean isArrowpointAllowed(Node x, Node y) { + private boolean isArrowheadAllowed(Node x, Node y) { if (this.graph.getEndpoint(x, y) == Endpoint.ARROW) { return true; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java index b7b819fead..6771c3e3de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java @@ -364,10 +364,10 @@ private void orientColliders(Graph graph) { continue; } if (!sepset.get(a, c).contains(b)) { - if (!isArrowpointAllowed(graph, a, b)) { + if (!isArrowheadAllowed(graph, a, b)) { continue; } - if (!isArrowpointAllowed(graph, c, b)) { + if (!isArrowheadAllowed(graph, c, b)) { continue; } System.out.println("Check here " + k + "\n " + sepset.get(a, c) + @@ -452,7 +452,7 @@ private void initialDoubleTriangle(Graph graph) { } //if all of the previous tests pass, orient D*-oB as D*->B - if (!isArrowpointAllowed(graph, D, B)) { + if (!isArrowheadAllowed(graph, D, B)) { continue; } @@ -464,7 +464,7 @@ private void initialDoubleTriangle(Graph graph) { } } - private boolean isArrowpointAllowed(Graph graph, Node x, Node y) { + private boolean isArrowheadAllowed(Graph graph, Node x, Node y) { if (graph.getEndpoint(x, y) == Endpoint.ARROW) { return true; } @@ -532,7 +532,7 @@ private void awayFromCollider(Graph graph, Node a, Node b, Node c) { (graph.getEndpoint(a, b) == Endpoint.ARROW)) { if (CB == Endpoint.CIRCLE || CB == Endpoint.TAIL) { if (BC == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(graph, b, c)) { + if (!isArrowheadAllowed(graph, b, c)) { return; } @@ -561,7 +561,7 @@ private void awayFromAncestor(Graph graph, Node a, Node b, Node c) { (graph.getEndpoint(b, a) == Endpoint.TAIL) || (graph.getEndpoint(c, b) == Endpoint.TAIL))) { - if (!isArrowpointAllowed(graph, a, c)) { + if (!isArrowheadAllowed(graph, a, c)) { return; } @@ -717,11 +717,11 @@ private void doDdpOrientation(Graph graph, Node l, Node a, Node b, Node c) { if (sepset.contains(b)) { graph.setEndpoint(c, b, Endpoint.TAIL); } else { - if (!isArrowpointAllowed(graph, a, b)) { + if (!isArrowheadAllowed(graph, a, b)) { return; } - if (!isArrowpointAllowed(graph, c, b)) { + if (!isArrowheadAllowed(graph, c, b)) { return; } @@ -1575,7 +1575,7 @@ private void doubleTriangle(Graph graph) { } //if all of the previous tests pass, orient D*-oB as D*->B - if (!isArrowpointAllowed(graph, D, B)) { + if (!isArrowheadAllowed(graph, D, B)) { continue; } @@ -1767,11 +1767,11 @@ private void doDdpOrientationFinal(Graph graph, Node l, Node a, Node b, Node c) } Graph newGraph2 = new EdgeListGraph(graph); - if (!isArrowpointAllowed(graph, a, b)) { + if (!isArrowheadAllowed(graph, a, b)) { return; } - if (!isArrowpointAllowed(graph, c, b)) { + if (!isArrowheadAllowed(graph, c, b)) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java index 9f68a62c9a..ce17705a61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java @@ -1105,7 +1105,7 @@ private void doubleTriangle(Graph graph) { } //if all of the previous tests pass, orient D*-oB as D*->B - if (!isArrowpointAllowed(graph, D, B)) { + if (!isArrowheadAllowed(graph, D, B)) { continue; } @@ -1184,7 +1184,7 @@ private void ruleR1(Node a, Node b, Node c, Graph graph) { } if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(graph, b, c)) { + if (!isArrowheadAllowed(graph, b, c)) { return; } @@ -1202,7 +1202,7 @@ private void ruleR2(Node a, Node b, Node c, Graph graph) { if (graph.getEndpoint(b, a) == Endpoint.TAIL && graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(b, c) == Endpoint.ARROW && graph.getEndpoint(a, c) == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(graph, a, c)) { + if (!isArrowheadAllowed(graph, a, c)) { return; } @@ -1210,7 +1210,7 @@ private void ruleR2(Node a, Node b, Node c, Graph graph) { } else if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.TAIL && graph.getEndpoint(b, c) == Endpoint.ARROW && graph.getEndpoint(a, c) == Endpoint.CIRCLE ) { - if (!isArrowpointAllowed(graph, a, c)) { + if (!isArrowheadAllowed(graph, a, c)) { return; } @@ -1218,7 +1218,7 @@ private void ruleR2(Node a, Node b, Node c, Graph graph) { } } - private boolean isArrowpointAllowed(Graph graph, Node x, Node y) { + private boolean isArrowheadAllowed(Graph graph, Node x, Node y) { if (graph.getEndpoint(x, y) == Endpoint.ARROW) { return true; } @@ -1244,7 +1244,7 @@ private void awayFromCollider(Graph graph, Node a, Node b, Node c) { (graph.getEndpoint(a, b) == Endpoint.ARROW)) { if (CB == Endpoint.CIRCLE || CB == Endpoint.TAIL) { if (BC == Endpoint.CIRCLE) { - if (!isArrowpointAllowed(graph, b, c)) { + if (!isArrowheadAllowed(graph, b, c)) { return; } @@ -1273,7 +1273,7 @@ private void awayFromAncestor(Graph graph, Node a, Node b, Node c) { (graph.getEndpoint(b, a) == Endpoint.TAIL) || (graph.getEndpoint(c, b) == Endpoint.TAIL))) { - if (!isArrowpointAllowed(graph, a, c)) { + if (!isArrowheadAllowed(graph, a, c)) { return; } From fd5b9d62d8ea73267c452614bd38532e826e9205 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 14:02:05 -0400 Subject: [PATCH 318/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../resources/javahelp/manual/boxes/search/cpc.html | 2 +- .../main/java/edu/cmu/tetrad/graph/GraphUtils.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/Cfci.java | 4 ++-- .../edu/cmu/tetrad/search/GraphUtilsSearch.java | 13 ++++--------- .../main/java/edu/cmu/tetrad/search/PcCommon.java | 10 +++++----- .../src/main/java/edu/cmu/tetrad/search/PcMb.java | 6 +++--- .../src/main/java/edu/cmu/tetrad/search/Rfci.java | 4 ++-- .../java/edu/cmu/tetrad/search/WIP/SampleVcpc.java | 6 +++--- .../edu/cmu/tetrad/search/WIP/SampleVcpcFast.java | 6 +++--- .../main/java/edu/cmu/tetrad/search/WIP/VcPc.java | 6 +++--- .../java/edu/cmu/tetrad/search/WIP/VcPcAlt.java | 6 +++--- .../java/edu/cmu/tetrad/search/WIP/VcPcFast.java | 6 +++--- 12 files changed, 33 insertions(+), 38 deletions(-) diff --git a/tetrad-gui/src/main/resources/resources/javahelp/manual/boxes/search/cpc.html b/tetrad-gui/src/main/resources/resources/javahelp/manual/boxes/search/cpc.html index d92eb41f07..988a9e6401 100644 --- a/tetrad-gui/src/main/resources/resources/javahelp/manual/boxes/search/cpc.html +++ b/tetrad-gui/src/main/resources/resources/javahelp/manual/boxes/search/cpc.html @@ -14,7 +14,7 @@


- CPC (Conservative PC) is a variant of the PC algorithm designed to improve arrowpoint orientation accuracy. The + CPC (Conservative PC) is a variant of the PC algorithm designed to improve arrowhead orientation accuracy. The types of input data permitted and the assumptions for CPC are the same as for PC. That is, input data may be used that is either entirely discrete or entirely continuous. A DAG may be used as input, in which case graphical d-separation will be used in place of conditional independence for purposes of the search. It is assumed that the diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index 07a97fd89b..ba24229e6f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -515,7 +515,7 @@ public static int countAdjErrors(Graph graph1, Graph graph2) { } /** - * Counts the arrowpoints that are in graph1 but not in graph2. + * Counts the arrowheads that are in graph1 but not in graph2. */ public static int countArrowptErrors(Graph graph1, Graph graph2) { if (graph1 == null) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index e4c99a9de1..80fd6a5df7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -352,11 +352,11 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { } /** - * Helper method. Appears to check if an arrowpoint is permitted by background knowledge. + * Helper method. Appears to check if an arrowhead is permitted by background knowledge. * * @param x The possible other node. * @param y The possible point node. - * @return Whether the arrowpoint is allowed. + * @return Whether the arrowhead is allowed. */ private boolean isArrowheadAllowed(Node x, Node y) { if (this.graph.getEndpoint(x, y) == Endpoint.ARROW) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java index 6dec8e0006..6c3b733af6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java @@ -273,7 +273,7 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg } /** - * Checks if an arrowpoint is allowed by background knowledge. + * Checks if an arrowhead is allowed by background knowledge. */ public static boolean isArrowheadAllowed(Object from, Object to, Knowledge knowledge) { @@ -375,11 +375,6 @@ public static Graph dagFromCPDAG(Graph graph, Knowledge knowledge) { } } - // FGES with incoherent forbidden knowledge may produce a cycle -// if (graph.existsDirectedCycle()) { -// throw new IllegalArgumentException("That 'cpdag' contains a directed cycle."); -// } - MeekRules rules = new MeekRules(); if (knowledge != null) { @@ -867,9 +862,9 @@ public static List> powerSet(List nodes) { } /** - * Checks if an arrowpoint is allowed by background knowledge. + * Checks if an arrowhead is allowed by background knowledge. */ - public static boolean isArrowpointAllowed1(Node from, Node to, + public static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { if (knowledge == null) { return true; @@ -1212,7 +1207,7 @@ public static GraphUtils.GraphComparison getGraphComparison(Graph trueGraph, Gra } /** - * Just counts arrowpoint errors--for cyclic edges counts an arrowpoint at + * Just counts arrowhead errors--for cyclic edges counts an arrowhead at * each node. */ public static GraphUtils.GraphComparison getGraphComparison2(Graph graph, Graph trueGraph) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java index e3270a64c0..29e6579b7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java @@ -114,21 +114,21 @@ public PcCommon(IndependenceTest independenceTest) { /** - * For the edge from*-*to, return true iff an arrowpoint is allowed as 'to'. + * For the edge from*-*to, return true iff an arrowhead is allowed as 'to'. * * @param from the from edge. * @param to the to edge. * @param knowledge the knowledge. * @return true iff an arrow point is allowed at 'to'. */ - public static boolean isArrowpointAllowed1(Node from, Node to, + public static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && !knowledge.isForbidden(from.toString(), to.toString()); } /** - * Checks if an arrowpoint is allowed by background knowledge. + * Checks if an arrowhead is allowed by background knowledge. */ public static boolean isArrowheadAllowed(Object from, Object to, Knowledge knowledge) { @@ -574,8 +574,8 @@ private boolean isNoncolliderSepset(Node j, List> sepsets) { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return PcCommon.isArrowpointAllowed1(x, y, knowledge) && - PcCommon.isArrowpointAllowed1(z, y, knowledge); + return PcCommon.isArrowheadAllowed1(x, y, knowledge) && + PcCommon.isArrowheadAllowed1(z, y, knowledge); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index 6fff461b30..3c22347530 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -823,11 +823,11 @@ private static List asList(int[] indices, List nodes) { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return PcMb.isArrowpointAllowed1(x, y, knowledge) && - PcMb.isArrowpointAllowed1(z, y, knowledge); + return PcMb.isArrowheadAllowed1(x, y, knowledge) && + PcMb.isArrowheadAllowed1(z, y, knowledge); } - private static boolean isArrowpointAllowed1(Node from, Node to, + private static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { if (knowledge == null) { return true; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index f254457282..3fbd1dfe0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -560,11 +560,11 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { /** - * Helper method. Appears to check if an arrowpoint is permitted by background knowledge. + * Helper method. Appears to check if an arrowhead is permitted by background knowledge. * * @param x The possible other node. * @param y The possible point node. - * @return Whether the arrowpoint is allowed. + * @return Whether the arrowhead is allowed. */ private boolean isArrowheadAllowed(Node x, Node y) { if (this.graph.getEndpoint(x, y) == Endpoint.ARROW) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java index 270b4e4793..16eaed4b6b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java @@ -828,11 +828,11 @@ private void orientUnshieldedTriples(Knowledge knowledge, } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return SampleVcpc.isArrowpointAllowed1(x, y, knowledge) && - SampleVcpc.isArrowpointAllowed1(z, y, knowledge); + return SampleVcpc.isArrowheadAllowed1(x, y, knowledge) && + SampleVcpc.isArrowheadAllowed1(z, y, knowledge); } - public static boolean isArrowpointAllowed1(Node from, Node to, + public static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && !knowledge.isForbidden(from.toString(), to.toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java index aaafa021ba..c2a750df41 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java @@ -760,11 +760,11 @@ private void orientUnshieldedTriples(Knowledge knowledge, private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return SampleVcpcFast.isArrowpointAllowed1(x, y, knowledge) && - SampleVcpcFast.isArrowpointAllowed1(z, y, knowledge); + return SampleVcpcFast.isArrowheadAllowed1(x, y, knowledge) && + SampleVcpcFast.isArrowheadAllowed1(z, y, knowledge); } - public static boolean isArrowpointAllowed1(Node from, Node to, + public static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && !knowledge.isForbidden(from.toString(), to.toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java index 8a935a00c7..901f84f991 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java @@ -680,11 +680,11 @@ public enum CpcTripleType { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return VcPc.isArrowpointAllowed1(x, y, knowledge) && - VcPc.isArrowpointAllowed1(z, y, knowledge); + return VcPc.isArrowheadAllowed1(x, y, knowledge) && + VcPc.isArrowheadAllowed1(z, y, knowledge); } - public static boolean isArrowpointAllowed1(Node from, Node to, + public static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && !knowledge.isForbidden(from.toString(), to.toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java index 217be1ae7a..6051133c5d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java @@ -586,11 +586,11 @@ private void orientUnshieldedTriples(Knowledge knowledge, } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return VcPcAlt.isArrowpointAllowed1(x, y, knowledge) && - VcPcAlt.isArrowpointAllowed1(z, y, knowledge); + return VcPcAlt.isArrowheadAllowed1(x, y, knowledge) && + VcPcAlt.isArrowheadAllowed1(z, y, knowledge); } - public static boolean isArrowpointAllowed1(Node from, Node to, + public static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && !knowledge.isForbidden(from.toString(), to.toString()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java index 52d227e11a..3a04190cff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java @@ -700,11 +700,11 @@ public enum CpcTripleType { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return VcPcFast.isArrowpointAllowed1(x, y, knowledge) && - VcPcFast.isArrowpointAllowed1(z, y, knowledge); + return VcPcFast.isArrowheadAllowed1(x, y, knowledge) && + VcPcFast.isArrowheadAllowed1(z, y, knowledge); } - public static boolean isArrowpointAllowed1(Node from, Node to, + public static boolean isArrowheadAllowed1(Node from, Node to, Knowledge knowledge) { return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && !knowledge.isForbidden(from.toString(), to.toString()); From 3a8cb77ea87da93a7d0f6f1093fc995d00cabdca Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 15:13:18 -0400 Subject: [PATCH 319/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/GraphUtilsSearch.java | 52 ++++++-------- .../main/java/edu/cmu/tetrad/search/MaxP.java | 4 +- .../java/edu/cmu/tetrad/search/PcCommon.java | 69 +++++++++---------- .../edu/cmu/tetrad/search/WIP/HbsmsGes.java | 2 +- .../edu/cmu/tetrad/search/WIP/SampleVcpc.java | 10 +-- .../edu/cmu/tetrad/search/WIP/VcPcAlt.java | 10 +-- .../edu/cmu/tetrad/search/WIP/VcPcFast.java | 10 +-- 7 files changed, 62 insertions(+), 95 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java index 6c3b733af6..2545ed3ea7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java @@ -147,22 +147,18 @@ public static void pcdOrientC(IndependenceTest test, Knowledge knowledge, Graph } if (test.determines(sepset, x)) { -// System.out.println(SearchLogUtils.determinismDetected(sepset, x)); continue; } if (test.determines(sepset, z)) { -// System.out.println(SearchLogUtils.determinismDetected(sepset, z)); continue; } if (test.determines(augmentedSet, x)) { -// System.out.println(SearchLogUtils.determinismDetected(augmentedSet, x)); continue; } if (test.determines(augmentedSet, z)) { -// System.out.println(SearchLogUtils.determinismDetected(augmentedSet, z)); continue; } @@ -245,25 +241,31 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg //I think the null check needs to be here --AJ if (sepset != null && !sepset.contains(b) - && GraphUtilsSearch.isArrowheadAllowed(a, b, knowledge) - && GraphUtilsSearch.isArrowheadAllowed(c, b, knowledge)) { - if (verbose) { - System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); + && GraphUtilsSearch.isArrowheadAllowed(a, b, knowledge)) { + boolean result = true; + if (knowledge != null) { + result = !knowledge.isRequired(((Object) b).toString(), ((Object) c).toString()) + && !knowledge.isForbidden(((Object) c).toString(), ((Object) b).toString()); } + if (result) { + if (verbose) { + System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); + } - if (enforceCpdag) { - if (graph.getEndpoint(b, a) == Endpoint.ARROW || graph.getEndpoint(b, c) == Endpoint.ARROW) { - continue; + if (enforceCpdag) { + if (graph.getEndpoint(b, a) == Endpoint.ARROW || graph.getEndpoint(b, c) == Endpoint.ARROW) { + continue; + } } - } - graph.removeEdge(a, b); - graph.removeEdge(c, b); + graph.removeEdge(a, b); + graph.removeEdge(c, b); - graph.addDirectedEdge(a, b); - graph.addDirectedEdge(c, b); + graph.addDirectedEdge(a, b); + graph.addDirectedEdge(c, b); - TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(a, b, c, sepset)); + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(a, b, c, sepset)); + } } } } @@ -287,7 +289,7 @@ public static boolean isArrowheadAllowed(Object from, Object to, /** * Get a graph and direct only the unshielded colliders. */ - public static void basicCPDAG(Graph graph) { + public static void basicCpdag(Graph graph) { Set undirectedEdges = new HashSet<>(); NEXT_EDGE: @@ -356,7 +358,7 @@ public static void basicCpdagRestricted2(Graph graph, Node node) { */ public static Graph cpdagFromDag(Graph dag) { Graph graph = new EdgeListGraph(dag); - GraphUtilsSearch.basicCPDAG(graph); + GraphUtilsSearch.basicCpdag(graph); MeekRules rules = new MeekRules(); rules.orientImplied(graph); return graph; @@ -861,18 +863,6 @@ public static List> powerSet(List nodes) { return subsets; } - /** - * Checks if an arrowhead is allowed by background knowledge. - */ - public static boolean isArrowheadAllowed1(Node from, Node to, - Knowledge knowledge) { - if (knowledge == null) { - return true; - } - - return !knowledge.isRequired(to.toString(), from.toString()) - && !knowledge.isForbidden(from.toString(), to.toString()); - } /** * Generates the list of DAGs in the given cpdag. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java index cf4634cafb..d6fdfbe74a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java @@ -209,8 +209,8 @@ private void testColliderMaxP(Graph graph, Map scores, Node a, N adja.remove(c); adjc.remove(a); - if (!(PcCommon.isArrowheadAllowed(a, b, knowledge) - && (PcCommon.isArrowheadAllowed(c, b, knowledge)))) { + if (!(GraphUtilsSearch.isArrowheadAllowed(a, b, knowledge) + && (GraphUtilsSearch.isArrowheadAllowed(c, b, knowledge)))) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java index 29e6579b7a..a89afd6b1c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java @@ -112,34 +112,6 @@ public PcCommon(IndependenceTest independenceTest) { this.independenceTest = independenceTest; } - - /** - * For the edge from*-*to, return true iff an arrowhead is allowed as 'to'. - * - * @param from the from edge. - * @param to the to edge. - * @param knowledge the knowledge. - * @return true iff an arrow point is allowed at 'to'. - */ - public static boolean isArrowheadAllowed1(Node from, Node to, - Knowledge knowledge) { - return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - - /** - * Checks if an arrowhead is allowed by background knowledge. - */ - public static boolean isArrowheadAllowed(Object from, Object to, - Knowledge knowledge) { - if (knowledge == null) { - return true; - - } - return !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); - } - /** * @param useHeuristic Whether the heuristic should be used for max P collider * orientation. @@ -574,8 +546,17 @@ private boolean isNoncolliderSepset(Node j, List> sepsets) { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return PcCommon.isArrowheadAllowed1(x, y, knowledge) && - PcCommon.isArrowheadAllowed1(z, y, knowledge); + boolean result = true; + if (knowledge != null) { + result = !knowledge.isRequired(((Object) y).toString(), ((Object) x).toString()) + && !knowledge.isForbidden(((Object) x).toString(), ((Object) y).toString()); + } + if (!result) return false; + if (knowledge == null) { + return true; + } + return !knowledge.isRequired(((Object) y).toString(), ((Object) z).toString()) + && !knowledge.isForbidden(((Object) z).toString(), ((Object) y).toString()); } /** @@ -620,14 +601,28 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra List s2 = new ArrayList<>(sepset); if (!s2.contains(b)) s2.add(b); - if (!sepset.contains(b) && PcCommon.isArrowheadAllowed(a, b, knowledge) && PcCommon.isArrowheadAllowed(c, b, knowledge)) { - PcCommon.orientCollider(a, b, c, conflictRule, graph); - - if (verbose) { - System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); + if (!sepset.contains(b)) { + boolean result1 = true; + if (knowledge != null) { + result1 = !knowledge.isRequired(((Object) b).toString(), ((Object) a).toString()) + && !knowledge.isForbidden(((Object) a).toString(), ((Object) b).toString()); + } + if (result1) { + boolean result = true; + if (knowledge != null) { + result = !knowledge.isRequired(((Object) b).toString(), ((Object) c).toString()) + && !knowledge.isForbidden(((Object) c).toString(), ((Object) b).toString()); + } + if (result) { + PcCommon.orientCollider(a, b, c, conflictRule, graph); + + if (verbose) { + System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset); + } + + TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(a, b, c, sepset)); + } } - - TetradLogger.getInstance().log("colliderOrientations", LogUtilsSearch.colliderOrientedMsg(a, b, c, sepset)); } } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java index ffdb43932c..6eae18ea6c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java @@ -582,7 +582,7 @@ private static List> powerSet(List nodes) { * Appendix C of (Chickering, 2002). */ private void rebuildCPDAG(Graph graph) { - GraphUtilsSearch.basicCPDAG(graph); + GraphUtilsSearch.basicCpdag(graph); addRequiredEdges(graph); pdagWithBk(graph, getKnowledge()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java index 16eaed4b6b..ef22aab022 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java @@ -828,14 +828,8 @@ private void orientUnshieldedTriples(Knowledge knowledge, } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return SampleVcpc.isArrowheadAllowed1(x, y, knowledge) && - SampleVcpc.isArrowheadAllowed1(z, y, knowledge); - } - - public static boolean isArrowheadAllowed1(Node from, Node to, - Knowledge knowledge) { - return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); + if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge)) return false; + return GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge); } public boolean isDoOrientation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java index 6051133c5d..a78017d2e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java @@ -586,14 +586,8 @@ private void orientUnshieldedTriples(Knowledge knowledge, } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return VcPcAlt.isArrowheadAllowed1(x, y, knowledge) && - VcPcAlt.isArrowheadAllowed1(z, y, knowledge); - } - - public static boolean isArrowheadAllowed1(Node from, Node to, - Knowledge knowledge) { - return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); + if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge)) return false; + return GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge); } public boolean isDoOrientation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java index 3a04190cff..72f2f85198 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java @@ -700,14 +700,8 @@ public enum CpcTripleType { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - return VcPcFast.isArrowheadAllowed1(x, y, knowledge) && - VcPcFast.isArrowheadAllowed1(z, y, knowledge); - } - - public static boolean isArrowheadAllowed1(Node from, Node to, - Knowledge knowledge) { - return knowledge == null || !knowledge.isRequired(to.toString(), from.toString()) && - !knowledge.isForbidden(from.toString(), to.toString()); + if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge)) return false; + return GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge); } /** From 552729970803a0d74ad382e16fc6cd2be5ebc62e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 15:38:06 -0400 Subject: [PATCH 320/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/FciOrient.java | 8 +- .../edu/cmu/tetrad/search/SvarFciOrient.java | 155 ++---------------- 2 files changed, 15 insertions(+), 148 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java index f660789824..146e21fb3a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java @@ -779,7 +779,7 @@ public boolean doDdpOrientation(Node d, Node a, Node b, Node c, Graph graph) { * * @param path The path to orient as all tails. */ - private void orientTailPath(List path, Graph graph) { + public void orientTailPath(List path, Graph graph) { for (int i = 0; i < path.size() - 1; i++) { Node n1 = path.get(i); Node n2 = path.get(i + 1); @@ -806,7 +806,7 @@ private void orientTailPath(List path, Graph graph) { * @return A list of uncovered partially directed undirectedPaths from n1 to * n2. */ - private List> getUcPdPaths(Node n1, Node n2, Graph graph) { + public static List> getUcPdPaths(Node n1, Node n2, Graph graph) { List> ucPdPaths = new LinkedList<>(); LinkedList soFar = new LinkedList<>(); @@ -833,7 +833,7 @@ private List> getUcPdPaths(Node n1, Node n2, Graph graph) { * @param end The node to finish the undirectedPaths at. * @param ucPdPaths The getModel list of uncovered p.d. undirectedPaths. */ - private void getUcPdPsHelper(Node curr, List soFar, Node end, + private static void getUcPdPsHelper(Node curr, List soFar, Node end, List> ucPdPaths, Graph graph) { if (soFar.contains(curr)) { @@ -878,7 +878,7 @@ private void getUcPdPsHelper(Node curr, List soFar, Node end, * @param n2 The ending node of the undirectedPaths. * @return A list of uncovered circle undirectedPaths between n1 and n2. */ - private List> getUcCirclePaths(Node n1, Node n2, Graph graph) { + public static List> getUcCirclePaths(Node n1, Node n2, Graph graph) { List> ucCirclePaths = new LinkedList<>(); List> ucPdPaths = getUcPdPaths(n1, n2, graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 8e6b94469c..5af5ca8200 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -111,7 +111,6 @@ public Graph orient(Graph graph) { // Step CI D. (Zhang's step F4.) doFinalOrientation(graph); -// graph.closeInducingPaths(); //to make sure it's a legal PAG if (this.verbose) { this.logger.log("graph", "Returning graph: " + graph); } @@ -194,11 +193,11 @@ public void ruleR0(Graph graph) { } if (this.sepsets.isUnshieldedCollider(a, b, c)) { - if (isArrowheadDisallowed(a, b, graph)) { + if (!FciOrient.isArrowheadAllowed(a, b, graph, knowledge)) { continue; } - if (isArrowheadDisallowed(c, b, graph)) { + if (!FciOrient.isArrowheadAllowed(c, b, graph, knowledge)) { continue; } @@ -222,7 +221,6 @@ private void printWrongColliderMessage(Node a, Node b, Node c, Graph graph) { } } - /** * Orients the graph according to rules in the graph (FCI step D). *

@@ -339,7 +337,7 @@ private void ruleR1(Node a, Node b, Node c, Graph graph) { } if (graph.getEndpoint(a, b) == Endpoint.ARROW && graph.getEndpoint(c, b) == Endpoint.CIRCLE) { - if (isArrowheadDisallowed(b, c, graph)) { + if (!FciOrient.isArrowheadAllowed(b, c, graph, knowledge)) { return; } @@ -367,7 +365,7 @@ private void ruleR2(Node a, Node b, Node c, Graph graph) { (graph.getEndpoint(b, a) == Endpoint.TAIL) || (graph.getEndpoint(c, b) == Endpoint.TAIL))) { - if (isArrowheadDisallowed(a, c, graph)) { + if (!FciOrient.isArrowheadAllowed(a, c, graph, knowledge)) { return; } @@ -426,7 +424,7 @@ public void ruleR3(Graph graph) { continue; } - if (isArrowheadDisallowed(D, B, graph)) { + if (!FciOrient.isArrowheadAllowed(D, B, graph, knowledge)) { continue; } @@ -578,10 +576,7 @@ private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Map ind = sepset.contains(b); } -// printDdp(d, path, a, b, c, graph); - if (ind) { -// if (sepset.contains(b)) { graph.setEndpoint(c, b, Endpoint.TAIL); this.orientSimilarPairs(graph, this.getKnowledge(), c, b, Endpoint.TAIL); if (this.verbose) { @@ -590,11 +585,11 @@ private boolean doDdpOrientation(Node d, Node a, Node b, Node c, Map } } else { - if (isArrowheadDisallowed(a, b, graph)) { + if (!FciOrient.isArrowheadAllowed(a, b, graph, knowledge)) { return false; } - if (isArrowheadDisallowed(c, b, graph)) { + if (!FciOrient.isArrowheadAllowed(c, b, graph, knowledge)) { return false; } @@ -642,7 +637,7 @@ public void ruleR5(Graph graph) { if (!(graph.getEndpoint(a, b) == Endpoint.CIRCLE)) continue; // We know Ao-oB. - List> ucCirclePaths = getUcCirclePaths(a, b, graph); + List> ucCirclePaths = FciOrient.getUcCirclePaths(a, b, graph); for (List u : ucCirclePaths) { if (u.size() < 3) continue; @@ -766,106 +761,6 @@ private void orientTailPath(List path, Graph graph) { } } - /** - * Gets a list of every uncovered partially directed path between two nodes in the graph. - *

- * Probably extremely slow. - * - * @param n1 The beginning node of the undirectedPaths. - * @param n2 The ending node of the undirectedPaths. - * @return A list of uncovered partially directed undirectedPaths from n1 to n2. - */ - private List> getUcPdPaths(Node n1, Node n2, Graph graph) { - List> ucPdPaths = new LinkedList<>(); - - LinkedList soFar = new LinkedList<>(); - soFar.add(n1); - - List adjacencies = graph.getAdjacentNodes(n1); - for (Node curr : adjacencies) { - getUcPdPsHelper(curr, soFar, n2, ucPdPaths, graph); - } - - return ucPdPaths; - } - - /** - * Used in getUcPdPaths(n1,n2) to perform a breadth-first search on the graph. - *

- * ASSUMES soFar CONTAINS AT LEAST ONE NODE! - *

- * Probably extremely slow. - * - * @param curr The getModel node to test for addition. - * @param soFar The getModel partially built-up path. - * @param end The node to finish the undirectedPaths at. - * @param ucPdPaths The getModel list of uncovered p.d. undirectedPaths. - */ - private void getUcPdPsHelper(Node curr, List soFar, Node end, - List> ucPdPaths, Graph graph) { - - if (soFar.contains(curr)) return; - - Node prev = soFar.get(soFar.size() - 1); - if (graph.getEndpoint(prev, curr) == Endpoint.TAIL || - graph.getEndpoint(curr, prev) == Endpoint.ARROW) { - return; // Adding curr would make soFar not p.d. - } else if (soFar.size() >= 2) { - Node prev2 = soFar.get(soFar.size() - 2); - if (graph.isAdjacentTo(prev2, curr)) { - return; // Adding curr would make soFar not uncovered. - } - } - - soFar.add(curr); // Adding curr is OK, so let's do it. - - if (curr.equals(end)) { - // We've reached the goal! Save soFar as a path. - ucPdPaths.add(new LinkedList<>(soFar)); - } else { - // Otherwise, try each node adjacent to the getModel one. - List adjacents = graph.getAdjacentNodes(curr); - for (Node next : adjacents) { - getUcPdPsHelper(next, soFar, end, ucPdPaths, graph); - } - } - - soFar.remove(soFar.get(soFar.size() - 1)); // For other recursive calls. - } - - /** - * Gets a list of every uncovered circle path between two nodes in the graph by iterating through the uncovered - * partially directed undirectedPaths and only keeping the circle undirectedPaths. - *

- * Probably extremely slow. - * - * @param n1 The beginning node of the undirectedPaths. - * @param n2 The ending node of the undirectedPaths. - * @return A list of uncovered circle undirectedPaths between n1 and n2. - */ - private List> getUcCirclePaths(Node n1, Node n2, Graph graph) { - List> ucCirclePaths = new LinkedList<>(); - List> ucPdPaths = getUcPdPaths(n1, n2, graph); - - for (List path : ucPdPaths) { - for (int i = 0; i < path.size() - 1; i++) { - Node j = path.get(i); - Node sj = path.get(i + 1); - - if (!(graph.getEndpoint(j, sj) == Endpoint.CIRCLE)) break; - if (!(graph.getEndpoint(sj, j) == Endpoint.CIRCLE)) break; - // This edge is OK, it's all circles. - - if (i == path.size() - 2) { - // We're at the last edge, so this is a circle path. - ucCirclePaths.add(path); - } - } - } - - return ucCirclePaths; - } - /** * Tries to apply Zhang's rule R8 to a pair of nodes A and C which are assumed to be such that Ao->C. *

@@ -916,7 +811,7 @@ private boolean ruleR8(Node a, Node c, Graph graph) { * @return Whether R9 was successfully applied. */ private boolean ruleR9(Node a, Node c, Graph graph) { - List> ucPdPsToC = getUcPdPaths(a, c, graph); + List> ucPdPsToC = FciOrient.getUcPdPaths(a, c, graph); for (List u : ucPdPsToC) { Node b = u.get(1); @@ -961,8 +856,8 @@ private void ruleR10(Node a, Node c, Graph graph) { if (!(graph.getEndpoint(d, c) == Endpoint.TAIL)) continue; // We know Ao->C and B-->C<--D. - List> ucPdPsToB = getUcPdPaths(a, b, graph); - List> ucPdPsToD = getUcPdPaths(a, d, graph); + List> ucPdPsToB = FciOrient.getUcPdPaths(a, b, graph); + List> ucPdPsToD = FciOrient.getUcPdPaths(a, d, graph); for (List u1 : ucPdPsToB) { Node m = u1.get(1); for (List u2 : ucPdPsToD) { @@ -1041,34 +936,6 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { } - /** - * Helper method. Appears to check if an arrowhead is permitted by background knowledge. - * - * @param x The possible other node. - * @param y The possible point node. - * @return Whether the arrowhead is allowed. - */ - private boolean isArrowheadDisallowed(Node x, Node y, Graph graph) { - if (graph.getEndpoint(x, y) == Endpoint.ARROW) { - return false; - } - - if (graph.getEndpoint(x, y) == Endpoint.TAIL) { - return true; - } - - if (graph.getEndpoint(y, x) == Endpoint.ARROW) { - return false; // changed by DMalinsky 02/11/2019, if already an arrowhead at x, arrowhead is allowed at y -// if (!knowledge.isForbidden(x.getName(), y.getName())) return true; - } - - if (graph.getEndpoint(y, x) == Endpoint.TAIL) { - if (!this.knowledge.isForbidden(x.getName(), y.getName())) return false; - } - - return graph.getEndpoint(y, x) != Endpoint.CIRCLE; - } - /** * @return the maximum length of any discriminating path, or -1 of unlimited. */ From 981f9e1bb9ec96efb7922a5c7be14088397262e1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 15:39:35 -0400 Subject: [PATCH 321/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/DagSepsets.java | 14 -------------- .../java/edu/cmu/tetrad/search/SepsetProducer.java | 2 +- .../edu/cmu/tetrad/search/SepsetsConservative.java | 5 ----- .../java/edu/cmu/tetrad/search/SepsetsGreedy.java | 5 ----- .../edu/cmu/tetrad/search/SepsetsPossibleDsep.java | 5 ----- .../java/edu/cmu/tetrad/search/SepsetsSet.java | 8 -------- .../java/edu/cmu/tetrad/search/ShiftSearch.java | 2 +- 7 files changed, 2 insertions(+), 39 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java index d78b009e3f..ea48641124 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java @@ -73,20 +73,6 @@ public boolean isUnshieldedCollider(Node i, Node j, Node k) { } - /** - * True iff i*-*j*-*k is an unshielded noncollider. - * - * @param i Node 1 - * @param j Node 2 - * @param k Node 3 - * @return True if the condition holds. - */ - @Override - public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { - List sepset = this.dag.getSepset(i, k); - return sepset != null && sepset.contains(j); - } - /** * Not implemented; required for an interface. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java index b73034a4ef..16404e4eeb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java @@ -34,7 +34,7 @@ public interface SepsetProducer { List getSepset(Node a, Node b); boolean isUnshieldedCollider(Node i, Node j, Node k); - boolean isUnshieldedNoncollider(Node a, Node b, Node c); + double getScore(); List getVariables(); void setVerbose(boolean verbose); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java index 3c5a102017..c68698bff8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java @@ -122,11 +122,6 @@ public boolean isUnshieldedCollider(Node i, Node j, Node k) { return ret.get(0).isEmpty(); } - public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { - List>> ret = getSepsetsLists(i, j, k, this.independenceTest, this.depth, true); - return ret.get(1).isEmpty(); - } - // The published version. public List>> getSepsetsLists(Node x, Node y, Node z, IndependenceTest test, int depth, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java index 5237283a91..8562d288e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java @@ -64,11 +64,6 @@ public boolean isUnshieldedCollider(Node i, Node j, Node k) { return set != null && !set.contains(j); } - public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { - List set = getSepsetGreedy(i, k); - return set != null && set.contains(j); - } - @Override public boolean isIndependent(Node a, Node b, List c) { IndependenceResult result = this.independenceTest.checkIndependence(a, b, c); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java index 464e07e8df..5f58360f61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java @@ -75,11 +75,6 @@ public boolean isUnshieldedCollider(Node i, Node j, Node k) { return sepset != null && !sepset.contains(j); } - public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { - List sepset = getSepset(i, k); - return sepset != null && sepset.contains(j); - } - @Override public double getScore() { return -(this.result.getPValue() - this.test.getAlpha()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java index 8da12d358c..a3b43056da 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java @@ -35,7 +35,6 @@ public class SepsetsSet implements SepsetProducer { private final SepsetMap sepsets; private final IndependenceTest test; - private double p; private boolean verbose; private IndependenceResult result; @@ -57,13 +56,6 @@ public boolean isUnshieldedCollider(Node i, Node j, Node k) { else return !sepset.contains(j); } - @Override - public boolean isUnshieldedNoncollider(Node i, Node j, Node k) { - List sepset = this.sepsets.get(i, k); - if (sepset == null) throw new IllegalArgumentException("That triple was covered: " + i + " " + j + " " + k); - return sepset.contains(j); - } - @Override public boolean isIndependent(Node a, Node b, List c) { IndependenceResult result = this.test.checkIndependence(a, b, c); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java index d2a3ea91b6..478224aa90 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java @@ -127,7 +127,7 @@ public Knowledge getKnowledge() { } public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } public int getC() { From 9541a1747468e3b913959e7d68873c118e9de750 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 15:51:39 -0400 Subject: [PATCH 322/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Rfci.java | 154 +--------- .../edu/cmu/tetrad/search/ScoredIndTest.java | 7 +- .../edu/cmu/tetrad/search/SemBicScore.java | 43 +-- .../java/edu/cmu/tetrad/search/SepsetMap.java | 8 +- .../{search => study}/RBExperiments.java | 285 +----------------- 5 files changed, 31 insertions(+), 466 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{search => study}/RBExperiments.java (73%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 3fbd1dfe0e..5e7b1ce885 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -22,7 +22,6 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; @@ -72,11 +71,6 @@ public final class Rfci implements GraphSearch { private final IndependenceTest independenceTest; - /** - * change flag for repeat rules - */ - private boolean changeFlag = true; - /** * The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. */ @@ -226,7 +220,7 @@ public Knowledge getKnowledge() { } public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } //===========================PRIVATE METHODS=========================// @@ -370,11 +364,11 @@ private void ruleR0_RFCI(List rTuples) { if (!sepset.contains(j) && this.graph.isAdjacentTo(i, j) && this.graph.isAdjacentTo(j, k)) { - if (!isArrowheadAllowed(i, j)) { + if (!FciOrient.isArrowheadAllowed(i, j, graph, knowledge)) { continue; } - if (!isArrowheadAllowed(k, j)) { + if (!FciOrient.isArrowheadAllowed(k, j, graph, knowledge)) { continue; } @@ -424,15 +418,15 @@ private List getRTuples() { ///////////////////////////////////////////////////////////////////////////// private void setMinSepSet(List sepSet, Node x, Node y) { List empty = Collections.emptyList(); - boolean indep; + boolean independent; try { - indep = this.independenceTest.checkIndependence(x, y, empty).isIndependent(); + independent = this.independenceTest.checkIndependence(x, y, empty).isIndependent(); } catch (Exception e) { - indep = false; + independent = false; } - if (indep) { + if (independent) { getSepsets().set(x, y, empty); return; } @@ -445,9 +439,9 @@ private void setMinSepSet(List sepSet, Node x, Node y) { while ((combination = cg.next()) != null) { List condSet = GraphUtils.asList(combination, sepSet); - indep = this.independenceTest.checkIndependence(x, y, condSet).isIndependent(); + independent = this.independenceTest.checkIndependence(x, y, condSet).isIndependent(); - if (indep) { + if (independent) { getSepsets().set(x, y, condSet); return; } @@ -455,136 +449,6 @@ private void setMinSepSet(List sepSet, Node x, Node y) { } } - ////////////////////////////////////////////////// - // Orients the graph according to rules for RFCI - ////////////////////////////////////////////////// - private void doFinalOrientation() { - - - FciOrient orient = new FciOrient(new SepsetsSet(this.sepsets, this.independenceTest)); - - // This loop handles Zhang's rules R1-R3 (same as in the original FCI) - this.changeFlag = true; - - while (this.changeFlag) { - this.changeFlag = false; - orient.setChangeFlag(false); - orient.rulesR1R2cycle(this.graph); - orient.ruleR3(this.graph); - this.changeFlag = orient.isChangeFlag(); - orient.ruleR4B(this.graph); // some changes to the original R4 inline - } - - // For RFCI always executes R5-10 - - // Now, by a remark on page 100 of Zhang's dissertation, we apply rule - // R5 once. - orient.ruleR5(this.graph); - - // Now, by a further remark on page 102, we apply R6,R7 as many times - // as possible. - this.changeFlag = true; - - while (this.changeFlag) { - this.changeFlag = false; - orient.setChangeFlag(false); - orient.ruleR6R7(this.graph); - this.changeFlag = orient.isChangeFlag(); - } - - // Finally, we apply R8-R10 as many times as possible. - this.changeFlag = true; - - while (this.changeFlag) { - this.changeFlag = false; - orient.setChangeFlag(false); - orient.rulesR8R9R10(this.graph); - this.changeFlag = orient.isChangeFlag(); - } - } - - /** - * Orients according to background knowledge - */ - private void fciOrientbk(Knowledge bk, Graph graph, List variables) { - this.logger.log("info", "Starting BK Orientation."); - - for (Iterator it = - bk.forbiddenEdgesIterator(); it.hasNext(); ) { - KnowledgeEdge edge = it.next(); - - //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.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.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); - } - - for (Iterator it = - bk.requiredEdgesIterator(); it.hasNext(); ) { - KnowledgeEdge edge = it.next(); - - //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); - - if (from == null || to == null) { - continue; - } - - if (graph.getEdge(from, to) == null) { - continue; - } - - graph.setEndpoint(to, from, Endpoint.TAIL); - graph.setEndpoint(from, to, Endpoint.ARROW); - this.changeFlag = true; - this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); - } - - this.logger.log("info", "Finishing BK Orientation."); - } - - - /** - * Helper method. Appears to check if an arrowhead is permitted by background knowledge. - * - * @param x The possible other node. - * @param y The possible point node. - * @return Whether the arrowhead is allowed. - */ - private boolean isArrowheadAllowed(Node x, Node y) { - if (this.graph.getEndpoint(x, y) == Endpoint.ARROW) { - return true; - } - - if (this.graph.getEndpoint(x, y) == Endpoint.TAIL) { - return false; - } - - if (this.graph.getEndpoint(y, x) == Endpoint.ARROW) { - if (!this.knowledge.isForbidden(x.getName(), y.getName())) return true; - } - - if (this.graph.getEndpoint(y, x) == Endpoint.TAIL) { - if (!this.knowledge.isForbidden(x.getName(), y.getName())) return true; - } - - return this.graph.getEndpoint(y, x) == Endpoint.CIRCLE; - } /** * @return the maximum length of any discriminating path, or -1 of unlimited. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredIndTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredIndTest.java index 59fd89f24d..c81e90ee2e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredIndTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredIndTest.java @@ -59,7 +59,7 @@ public ScoredIndTest(IndependenceTest test) { } /** - * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model + * Calculates the sample likelihood and BIC score for i, given its parents in a simple SEM model */ public double localScore(int i, int[] parents) { throw new UnsupportedOperationException(); @@ -119,11 +119,6 @@ public int getSampleSize() { return 0; } - public boolean getAlternativePenalty() { - return false; - } - - @Override public int getMaxDegree() { return 1000; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScore.java index e245e582fd..616dc45b5d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScore.java @@ -72,7 +72,7 @@ public class SemBicScore implements Score { // The rule type to use. private RuleType ruleType = RuleType.CHICKERING; - private double logN; + private final double logN; /** * Constructs the score using a covariance matrix. @@ -121,8 +121,7 @@ public SemBicScore(DataSet dataSet) { @NotNull private ICovarianceMatrix getiCovarianceMatrix(DataSet dataSet) { - ICovarianceMatrix cov = SimpleDataLoader.getCovarianceMatrix(dataSet); - return cov; + return SimpleDataLoader.getCovarianceMatrix(dataSet); } public static double getVarRy(int i, int[] parents, Matrix data, ICovarianceMatrix covariances, boolean calculateRowSubsets) @@ -254,56 +253,18 @@ public double nandyBic(int x, int y, int[] z) { * @return The score, or NaN if the score cannot be calculated. */ public double localScore(int i, int... parents) { -// S = sorted(X) -// key = tuple(S) -// if key not in self.cache: -// self.cache[key] = np.linalg.slogdet(self.cov[np.ix_(S, S)])[1] -// log_prob = self.cache[key] -// -// bisect.insort(S,y) -// key = tuple(S) -// if key not in self.cache: -// self.cache[key] = np.linalg.slogdet(self.cov[np.ix_(S, S)])[1] -// log_prob -= self.cache[key] -// -// return self.n/2 * log_prob - self.c * len(X) * np.log(self.n) - -// Arrays.sort(parents); -// -// int[] all = new int[parents.length + 1]; -// all[0] = i; -// Arrays.sort(all); -// System.arraycopy(parents, 0, all, 1, parents.length); -// -// Matrix cov1 = SemBicScore.getCov(SemBicScore.getRows(i, parents, data, calculateRowSubsets), parents, parents, data, covariances); -// double lik = FastMath.log(MatrixUtils.determinant(cov1.toArray())); -// -// Matrix cov2 = SemBicScore.getCov(SemBicScore.getRows(i, parents, data, calculateRowSubsets), all, all, data, covariances); -// lik -= FastMath.log(MatrixUtils.determinant(cov2.toArray())); - - int k = parents.length; double lik; Arrays.sort(parents); -// List _all = new ArrayList<>(); -// _all.add(i); -// for (int value : parents) _all.add(value); -// -// if (cache.containsKey(_all)) { -// lik = cache.get(_all); -// } else { try { double varey = SemBicScore.getVarRy(i, parents, this.data, this.covariances, this.calculateRowSubsets); lik = -(double) (this.sampleSize / 2.0) * log(varey); -// cache.put(_all, lik); } catch (SingularMatrixException e) { lik = NaN; } -// cache.put(_all, lik); -// } double c = getPenaltyDiscount(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java index 2100d5191c..7ca9144ac2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java @@ -33,12 +33,12 @@ *

Stores a map from pairs of nodes to separating sets--that is, for each unordered pair of nodes {node1, node2} in a * graph, stores a set of nodes conditional on which node1 and node2 are independent (where the nodes are considered as * variables) or stores null if the pair was not judged to be independent. (Note that if a sepset is non-null and empty, - * that should means that the compared nodes were found to be independent conditional on the empty set, whereas if a + * that should mean that the compared nodes were found to be independent conditional on the empty set, whereas if a * sepset is null, that should mean that no set was found yet conditional on which the compared nodes are independent. * So at the end of the search, a null sepset carries different information from an empty sepset.)> 0

We cast the * variable-like objects to Node to allow them either to be variables explicitly or else to be graph nodes that in some * model could be considered as variables. This allows us to use d-separation as a graphical indicator of what - * independendence in models ideally should be.> 0 + * independence in models ideally should be.> 0 * * @author Joseph Ramsey */ @@ -152,7 +152,7 @@ public boolean equals(Object o) { * semantic checks can be specified and do not need to stay the same from version to version. A readObject method of * this form may be added to any class, even if Tetrad sessions were previously saved out using a version of the * class that didn't include it. (That's what the "s.defaultReadObject();" is for. See J. Bloch, Effective Java, for - * help. + * help). */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { @@ -164,7 +164,7 @@ private void readObject(ObjectInputStream s) } /** - * Returns the number of {x, y} in the keyset of the map. + * Returns the number of {x, y} in the key set of the map. */ public int size() { return this.sepsets.keySet().size(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java similarity index 73% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java index 0af1540326..763fd9f50e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.study; import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.bayes.BayesPm; @@ -6,10 +6,10 @@ import edu.cmu.tetrad.bayes.DirichletEstimator; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.study.performance.Comparison; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; -import edu.cmu.tetrad.util.TextTable; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; import nu.xom.Builder; import nu.xom.Document; @@ -17,11 +17,10 @@ import org.apache.commons.math3.util.FastMath; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.nio.file.Files; import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.*; import java.util.regex.Pattern; @@ -36,11 +35,7 @@ public class RBExperiments { private static class MapUtil { public static > Map sortByValue(Map map) { List> list = new LinkedList<>(map.entrySet()); - Collections.sort(list, new Comparator>() { - public int compare(Map.Entry o1, Map.Entry o2) { - return (o2.getValue()).compareTo(o1.getValue()); - } - }); + list.sort((o1, o2) -> (o2.getValue()).compareTo(o1.getValue())); Map result = new LinkedHashMap<>(); for (Map.Entry entry : list) { @@ -60,71 +55,19 @@ private List getLatents(Graph dag) { return latents; } - public Graph makeSimpleDAG(int numLatentConfounders) { - List nodes = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - nodes.add(new DiscreteVariable(Integer.toString(i + 1))); - } - - Graph dag = new EdgeListGraph(nodes); - dag.addDirectedEdge(nodes.get(0), nodes.get(1)); - dag.addDirectedEdge(nodes.get(0), nodes.get(2)); - dag.addDirectedEdge(nodes.get(1), nodes.get(3)); - dag.addDirectedEdge(nodes.get(2), nodes.get(3)); - dag.addDirectedEdge(nodes.get(2), nodes.get(4)); - return dag; - } - - private BayesIm initializeIM(BayesIm im) { - int node = 0; - im.setProbability(node, 0, 0, 0.8); - im.setProbability(node, 0, 1, 0.2); - - - node = 1; - im.setProbability(node, 0, 0, 0.9); - im.setProbability(node, 0, 1, 0.1); - im.setProbability(node, 1, 0, 0.3); - im.setProbability(node, 1, 1, 0.7); - - node = 2; - im.setProbability(node, 0, 0, 0.8); - im.setProbability(node, 0, 1, 0.2); - im.setProbability(node, 1, 0, 0.4); - im.setProbability(node, 1, 1, 0.6); - - node = 3; - im.setProbability(node, 0, 0, 0.9); - im.setProbability(node, 0, 1, 0.1); - im.setProbability(node, 1, 0, 0.7); - im.setProbability(node, 1, 1, 0.3); - im.setProbability(node, 2, 0, 0.6); - im.setProbability(node, 2, 1, 0.4); - im.setProbability(node, 3, 0, 0.2); - im.setProbability(node, 3, 1, 0.8); - - node = 4; - im.setProbability(node, 0, 0, 0.9); - im.setProbability(node, 0, 1, 0.1); - im.setProbability(node, 1, 0, 0.6); - im.setProbability(node, 1, 1, 0.4); - - return im; - } - public static void main(String[] args) throws IOException { NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT); // read and process input arguments double alpha = 0.05, lower = 0.3, upper = 0.7; - int numCases = 100, numModels = 5, numBootstrapSamples = 10, round = 0; + int numModels = 5, numBootstrapSamples = 10; String modelName = "Alarm", filePath = "/Users/chw20/Documents/DBMI/bsc-results", dataPath = System.getProperty("user.dir"); boolean threshold1 = false, threshold2 = true; for (int i = 0; i < args.length; i++) { switch (args[i]) { case "-c": - numCases = Integer.parseInt(args[i + 1]); + case "-i": break; case "-lv": Double.parseDouble(args[i + 1]); @@ -159,9 +102,6 @@ public static void main(String[] args) throws IOException { case "-data": dataPath = args[i + 1]; break; - case "-i": - round = Integer.parseInt(args[i + 1]); - break; } } @@ -184,7 +124,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo double numLatentConfounders, boolean threshold1, boolean threshold2, double lower, double upper, String filePath, int round) { // 32827167123L - final Long seed = 878376L; + final long seed = 878376L; RandomUtil.getInstance().setSeed(seed); PrintStream out; @@ -210,7 +150,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo + numLatentConfounders + "-Cases" + numCases + "-numModels" + numModels + "-BS" + numBootstrapSamples + "-" + round + ".txt"); if (!file.exists() || file.length() == 0) { - out = new PrintStream(new FileOutputStream(file)); + out = new PrintStream(Files.newOutputStream(file.toPath())); } else { return; } @@ -222,13 +162,10 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo // simulate data from instantiated model DataSet fullData = im.simulateData(numCases, /*round * 1000000 + 71512,*/ true); - fullData = refineData(fullData); + refineData(fullData); DataSet data = DataUtils.restrictToMeasured(fullData); // get the true underlying PAG -// DagToPag dagToPag = new DagToPag(dag); -// dagToPag.setCompleteRuleSetUsed(false); -// Graph PAG_True = dagToPag.convert(); Graph PAG_True = GraphUtilsSearch.dagToPag(dag); @@ -251,7 +188,6 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo System.out.println("RB (RFCI-BSC) done!"); // // create empirical data for constraints - start = MillisecondTimes.timeMillis(); DataSet depData = createDepDataFiltering(H, data, numBootstrapSamples, threshold2, lower, upper); out.println("DepData(row,col):" + depData.getNumRows() + "," + depData.getNumColumns()); System.out.println("Dep data creation done!"); @@ -267,23 +203,16 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo BayesPm pmHat = new BayesPm(estDepBN, 2, 2); DirichletBayesIm prior = DirichletBayesIm.symmetricDirichletIm(pmHat, 0.5); BayesIm imHat = DirichletEstimator.estimate(prior, depData); - Long BscdTime = MillisecondTimes.timeMillis() - start; System.out.println("Dependency BN_Param done"); // compute scores of graphs that are output by RB search using BSC-I and // BSC-D methods - start = MillisecondTimes.timeMillis(); - allScores lnProbs = getLnProbsAll(bscPags, H, data, imHat, estDepBN); - Long mutualTime = (MillisecondTimes.timeMillis() - start) / 2; + allScores lnProbs = getLnProbsAll(bscPags, H, imHat); // normalize the scores - start = MillisecondTimes.timeMillis(); Map normalizedDep = normalProbs(lnProbs.LnBSCD); - Long dTime = MillisecondTimes.timeMillis() - start; - start = MillisecondTimes.timeMillis(); Map normalizedInd = normalProbs(lnProbs.LnBSCI); - Long iTime = MillisecondTimes.timeMillis() - start; // get the most probable PAG using each scoring method normalizedDep = MapUtil.sortByValue(normalizedDep); @@ -319,7 +248,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo } - private DataSet refineData(DataSet fullData) { + private void refineData(DataSet fullData) { for (int c = 0; c < fullData.getNumColumns(); c++) { for (int r = 0; r < fullData.getNumRows(); r++) { if (fullData.getInt(r, c) < 0) { @@ -327,8 +256,6 @@ private DataSet refineData(DataSet fullData) { } } } - - return fullData; } private BayesIm getBayesIM(String type) { @@ -421,11 +348,6 @@ private void summarize(Graph graph, Graph trueGraph, PrintStream out) { dataSet.setDouble(newRow, tableColumns.indexOf(Comparison.TableColumn.SHD), comparison.getShd()); } - int[] cols = new int[tableColumns.size()]; - for (int i = 0; i < cols.length; i++) { - cols[i] = i; - } - // out.println(getTextTable(dataSet, cols, new DecimalFormat("0.00"))); out.println(MisclassificationUtils.edgeMisclassifications(graph, trueGraph)); int SHDAdj = comparison.getEdgesAdded().size() + comparison.getEdgesRemoved().size(); @@ -437,177 +359,6 @@ private void summarize(Graph graph, Graph trueGraph, PrintStream out) { } - private double[] printCorrectArrows(Graph outGraph, Graph truePag, PrintStream out) { - int correctArrows = 0; - int totalEstimatedArrows = 0; - int totalTrueArrows = 0; - - double[] stats = new double[5]; - - for (Edge edge : outGraph.getEdges()) { - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - Endpoint ex = edge.getEndpoint1(); - Endpoint ey = edge.getEndpoint2(); - - Edge edge1 = truePag.getEdge(x, y); - - if (ex == Endpoint.ARROW) { - if (edge1 != null && edge1.getProximalEndpoint(x) == Endpoint.ARROW) { - correctArrows++; - } - totalEstimatedArrows++; - } - - if (ey == Endpoint.ARROW) { - if (edge1 != null && edge1.getProximalEndpoint(y) == Endpoint.ARROW) { - correctArrows++; - } - - totalEstimatedArrows++; - } - } - - for (Edge edge : truePag.getEdges()) { - Endpoint ex = edge.getEndpoint1(); - Endpoint ey = edge.getEndpoint2(); - - if (ex == Endpoint.ARROW) { - totalTrueArrows++; - } - - if (ey == Endpoint.ARROW) { - totalTrueArrows++; - } - } - - out.println(); - out.println("# correct arrows: " + correctArrows); - out.println("# total estimated arrows: " + totalEstimatedArrows); - out.println("# total true arrows: " + totalTrueArrows); - - out.println(); - NumberFormat nf = new DecimalFormat("0.00"); - double precision = correctArrows / (double) totalEstimatedArrows; - out.println("Arrow precision: " + nf.format(precision)); - double recall = correctArrows / (double) totalTrueArrows; - out.println("Arrow recall: " + nf.format(recall)); - - stats[0] = correctArrows; - stats[1] = totalEstimatedArrows; - stats[2] = totalTrueArrows; - stats[3] = precision; - stats[4] = recall; - - return stats; - } - - private double[] printCorrectTails(Graph outGraph, Graph truePag, PrintStream out) { - int correctTails = 0; - int totalEstimatedTails = 0; - int totalTrueTails = 0; - - double[] stats = new double[5]; - - for (Edge edge : outGraph.getEdges()) { - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - Endpoint ex = edge.getEndpoint1(); - Endpoint ey = edge.getEndpoint2(); - - Edge edge1 = truePag.getEdge(x, y); - - if (ex == Endpoint.TAIL) { - if (edge1 != null && edge1.getProximalEndpoint(x) == Endpoint.TAIL) { - correctTails++; - } - - totalEstimatedTails++; - } - - if (ey == Endpoint.TAIL) { - if (edge1 != null && edge1.getProximalEndpoint(y) == Endpoint.TAIL) { - correctTails++; - } - - totalEstimatedTails++; - } - } - - for (Edge edge : truePag.getEdges()) { - Endpoint ex = edge.getEndpoint1(); - Endpoint ey = edge.getEndpoint2(); - - if (ex == Endpoint.TAIL) { - totalTrueTails++; - } - - if (ey == Endpoint.TAIL) { - totalTrueTails++; - } - } - - out.println(); - out.println("# correct tails: " + correctTails); - out.println("# total estimated tails: " + totalEstimatedTails); - out.println("# total true tails: " + totalTrueTails); - - out.println(); - NumberFormat nf = new DecimalFormat("0.00"); - double precision = correctTails / (double) totalEstimatedTails; - out.println("Tail precision: " + nf.format(precision)); - double recall = correctTails / (double) totalTrueTails; - out.println("Tail recall: " + nf.format(recall)); - - stats[0] = correctTails; - stats[1] = totalEstimatedTails; - stats[2] = totalTrueTails; - stats[3] = precision; - stats[4] = recall; - - return stats; - } - - private TextTable getTextTable(DataSet dataSet, int[] columns, NumberFormat nf) { - TextTable table = new TextTable(dataSet.getNumRows() + 2, columns.length + 1); - - table.setToken(0, 0, "Run #"); - - for (int j = 0; j < columns.length; j++) { - table.setToken(0, j + 1, dataSet.getVariable(columns[j]).getName()); - } - - for (int i = 0; i < dataSet.getNumRows(); i++) { - table.setToken(i + 1, 0, Integer.toString(i + 1)); - } - - for (int i = 0; i < dataSet.getNumRows(); i++) { - for (int j = 0; j < columns.length; j++) { - table.setToken(i + 1, j + 1, nf.format(dataSet.getDouble(i, columns[j]))); - } - } - - NumberFormat nf2 = new DecimalFormat("0.00"); - - for (int j = 0; j < columns.length; j++) { - double sum = 0.0; - - for (int i = 0; i < dataSet.getNumRows(); i++) { - sum += dataSet.getDouble(i, columns[j]); - } - - double avg = sum / dataSet.getNumRows(); - - table.setToken(dataSet.getNumRows() + 2 - 1, j + 1, nf2.format(avg)); - } - - table.setToken(dataSet.getNumRows() + 2 - 1, 0, "Avg"); - - return table; - } - private DataSet createDepDataFiltering(Map H, DataSet data, int numBootstrapSamples, boolean threshold, double lower, double upper) { List vars = new ArrayList<>(); @@ -649,8 +400,7 @@ private Graph runFGS(DataSet data) { return fgsCPDAG; } - private allScores getLnProbsAll(List pags, Map H, DataSet data, BayesIm im, - Graph dep) { + private allScores getLnProbsAll(List pags, Map H, BayesIm im) { // Map pagLnBDeu = new HashMap(); Map pagLnBSCD = new HashMap<>(); Map pagLnBSCI = new HashMap<>(); @@ -660,7 +410,7 @@ private allScores getLnProbsAll(List pags, Map double lnInd = getLnProb(pagOrig, H); // Filtering - double lnDep = getLnProbUsingDepFiltering(pagOrig, H, im, dep); + double lnDep = getLnProbUsingDepFiltering(pagOrig, H, im); pagLnBSCD.put(pagOrig, lnDep); pagLnBSCI.put(pagOrig, lnInd); } @@ -712,12 +462,12 @@ private Graph runPagCs(DataSet data, double alpha) { return PAG_CS; } - private double getLnProbUsingDepFiltering(Graph pag, Map H, BayesIm im, Graph dep) { + private double getLnProbUsingDepFiltering(Graph pag, Map H, BayesIm im) { double lnQ = 0; for (IndependenceFact fact : H.keySet()) { BCInference.OP op; - double p = 0.0; + double p; if (pag.paths().isDSeparatedFrom(fact.getX(), fact.getY(), fact.getZ())) { op = BCInference.OP.independent; @@ -895,9 +645,4 @@ private double lnQTotal(Map pagLnProb) { private static final int MININUM_EXPONENT = -1022; - public DataSet bootStrapSampling(DataSet data, int numBootstrapSamples, int bootsrapSampleSize) { - - return DataUtils.getBootstrapSample(data, bootsrapSampleSize); - } - } From d129c194897f5278f8ccf75021415c689151f972 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 16:18:42 -0400 Subject: [PATCH 323/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/PurifyScoreBased.java | 232 ++++++++---------- .../cmu/tetrad/search/PurifySextadBased.java | 10 +- .../cmu/tetrad/search/PurifyTetradBased.java | 8 +- 3 files changed, 105 insertions(+), 145 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java index b6753f6255..169d535284 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java @@ -41,7 +41,7 @@ public class PurifyScoreBased implements IPurify { private final boolean outputMessage = true; private final TetradTest tetradTest; private final int numVars; - private List forbiddenList; + private final List> forbiddenList; // SCORE-BASED PURIFY - using BIC score function and Structural EM for // search. Probabilistic model is Gaussian. - search operator consists only @@ -75,21 +75,19 @@ public class PurifyScoreBased implements IPurify { int numObserved; int numLatent; int[] clusterId; - Hashtable observableNames, latentNames; + HashMap observableNames, latentNames; SemGraph purePartitionGraph; Graph basicGraph; ICovarianceMatrix covarianceMatrix; boolean[][] correlatedErrors, latentParent, observedParent; - List latentNodes, measuredNodes; - SemIm currentSemIm; + List latentNodes, measuredNodes; boolean modifiedGraph; - boolean extraDebugPrint; - - public PurifyScoreBased(TetradTest tetradTest) { + public PurifyScoreBased(TetradTest tetradTest, List> forbiddenList) { this.tetradTest = tetradTest; this.numVars = tetradTest.getVarNames().length; + this.forbiddenList = forbiddenList; } public List> purify(List> partition) { @@ -184,12 +182,12 @@ private List> convertIntToList(List partition) { private Graph convertSearchGraph(SemGraph input) { if (input == null) { - List nodes = new ArrayList(); + List nodes = new ArrayList<>(); nodes.add(new GraphNode("No_model.")); return new EdgeListGraph(nodes); } - List inputIndicators = new ArrayList(); - List inputLatents = new ArrayList(); + List inputIndicators = new ArrayList<>(); + List inputLatents = new ArrayList<>(); for (Node next : input.getNodes()) { if (next.getNodeType() == NodeType.MEASURED) { inputIndicators.add(next); @@ -198,7 +196,7 @@ private Graph convertSearchGraph(SemGraph input) { } } - List allNodes = new ArrayList(inputIndicators); + List allNodes = new ArrayList<>(inputIndicators); allNodes.addAll(inputLatents); Graph output = new EdgeListGraph(allNodes); @@ -208,12 +206,10 @@ private Graph convertSearchGraph(SemGraph input) { if (edge != null) { if (node1.getNodeType() == NodeType.ERROR && node2.getNodeType() == NodeType.ERROR) { - Iterator ci = input.getChildren(node1).iterator(); - Node indicator1 = - (Node) ci.next(); //Assuming error nodes have only one children in SemGraphs... + Iterator ci = input.getChildren(node1).iterator(); + Node indicator1 = ci.next(); //Assuming error nodes have only one children in SemGraphs... ci = input.getChildren(node2).iterator(); - Node indicator2 = - (Node) ci.next(); //Assuming error nodes have only one children in SemGraphs... + Node indicator2 = ci.next(); //Assuming error nodes have only one children in SemGraphs... if (indicator1.getNodeType() != NodeType.LATENT) { output.setEndpoint(indicator1, indicator2, Endpoint.ARROW); @@ -235,17 +231,17 @@ private Graph convertSearchGraph(SemGraph input) { for (int i = 0; i < inputLatents.size() - 1; i++) { for (int j = i + 1; j < inputLatents.size(); j++) { - output.setEndpoint((Node) inputLatents.get(i), - (Node) inputLatents.get(j), Endpoint.TAIL); - output.setEndpoint((Node) inputLatents.get(j), - (Node) inputLatents.get(i), Endpoint.TAIL); + output.setEndpoint(inputLatents.get(i), + inputLatents.get(j), Endpoint.TAIL); + output.setEndpoint(inputLatents.get(j), + inputLatents.get(i), Endpoint.TAIL); } } return output; } - private SemGraph scoreBasedPurify(List partition) { + private SemGraph scoreBasedPurify(List partition) { structuralEmInitialization(partition); SemGraph bestGraph = this.purePartitionGraph; System.out.println(">>>> Structural EM: initial round"); @@ -281,13 +277,12 @@ private SemGraph scoreBasedPurify(List partition) { } while (this.modifiedGraph); boolean[][] impurities = new boolean[this.numObserved][this.numObserved]; for (int i = 0; i < this.numObserved; i++) { - List parents = bestGraph.getParents( + List parents = bestGraph.getParents( bestGraph.getNode(this.measuredNodes.get(i).toString())); if (parents.size() > 1) { boolean latent_found = false; - for (Object o : parents) { - Node parent = (Node) o; - if (parent.getNodeType() == NodeType.LATENT) { + for (Node o : parents) { + if (o.getNodeType() == NodeType.LATENT) { if (latent_found) { impurities[i][i] = true; break; @@ -312,24 +307,21 @@ private SemGraph scoreBasedPurify(List partition) { return bestGraph; } - private void structuralEmInitialization(List partition) { + private void structuralEmInitialization(List partition) { // Initialize semGraph - this.observableNames = new Hashtable(); - this.latentNames = new Hashtable(); + this.observableNames = new HashMap<>(); + this.latentNames = new HashMap<>(); this.numObserved = 0; this.numLatent = 0; - this.latentNodes = new ArrayList(); - this.measuredNodes = new ArrayList(); + this.latentNodes = new ArrayList<>(); + this.measuredNodes = new ArrayList<>(); this.basicGraph = new EdgeListGraph(); for (int p = 0; p < partition.size(); p++) { - int[] next = (int[]) partition.get(p); + int[] next = partition.get(p); Node newLatent = new GraphNode("_L" + p); newLatent.setNodeType(NodeType.LATENT); this.basicGraph.addNode(newLatent); - for (Object latentNode : this.latentNodes) { - Node previousLatent = (Node) latentNode; - this.basicGraph.addDirectedEdge(previousLatent, newLatent); - } + this.latentNodes.forEach(previousLatent -> this.basicGraph.addDirectedEdge(previousLatent, newLatent)); this.latentNodes.add(newLatent); this.latentNames.put(newLatent.toString(), this.numLatent); this.numLatent++; @@ -351,7 +343,7 @@ private void structuralEmInitialization(List partition) { this.clusterId = new int[this.numObserved]; int count = 0; for (int p = 0; p < partition.size(); p++) { - int[] next = (int[]) partition.get(p); + int[] next = partition.get(p); for (int i = 0; i < next.length; i++) { this.clusterId[count++] = p; } @@ -383,9 +375,9 @@ private void structuralEmInitialization(List partition) { for (int j = 0; j < cov.length; j++) { if (this.observableNames.get(varNames[i]) != null && this.observableNames.get(varNames[j]) != null) { - this.Cyy[((Integer) this.observableNames.get( - varNames[i]))][((Integer) this.observableNames - .get(varNames[j]))] = cov[i][j]; + this.Cyy[this.observableNames.get( + varNames[i])][this.observableNames + .get(varNames[j])] = cov[i][j]; } } } @@ -439,7 +431,7 @@ private void printlnMessage() { } } - private void printClustering(List clustering) { + private void printClustering(List clustering) { for (Object o : clustering) { int[] c = (int[]) o; printCluster(c); @@ -493,12 +485,8 @@ private double gaussianEM(SemGraph semdag) { for (int i = 0; i < 3; i++) { System.out.println("--Trial " + i); SemIm semIm; - if (i == 0 && null != null) { - semIm = null; - } else { - semIm = new SemIm(semPm); - semIm.setCovMatrix(this.covarianceMatrix); - } + semIm = new SemIm(semPm); + semIm.setCovMatrix(this.covarianceMatrix); do { score = newScore; gaussianExpectation(semIm); @@ -537,7 +525,7 @@ private double gaussianEM(SemGraph semdag) { private void initializeGaussianEM(SemGraph semMag) { //Build parents and spouses indices for (int i = 0; i < this.numLatent; i++) { - Node node = (Node) this.latentNodes.get(i); + Node node = this.latentNodes.get(i); if (semMag.getParents(node).size() > 0) { this.parentsLat[i] = new int[semMag.getParents(node).size() - 1]; @@ -545,8 +533,8 @@ private void initializeGaussianEM(SemGraph semMag) { for (Node parent : semMag.getParents(node)) { if (parent.getNodeType() == NodeType.LATENT) { this.parentsLat[i][count++] = - ((Integer) this.latentNames.get( - parent.getName())); + this.latentNames.get( + parent.getName()); } } this.parentsLatCov[i] = @@ -567,34 +555,34 @@ private void initializeGaussianEM(SemGraph semMag) { if (nextEdge.getEndpoint1() == Endpoint.ARROW && nextEdge.getEndpoint2() == Endpoint.ARROW) { //By construction, getNode1() and getNode2() are error nodes. They have only one child each. - Iterator it1 = semMag.getChildren(nextEdge.getNode1()) + Iterator it1 = semMag.getChildren(nextEdge.getNode1()) .iterator(); - Node measure1 = (Node) it1.next(); - Iterator it2 = semMag.getChildren(nextEdge.getNode2()) + Node measure1 = it1.next(); + Iterator it2 = semMag.getChildren(nextEdge.getNode2()) .iterator(); - Node measure2 = (Node) it2.next(); - correlatedErrors[((Integer) this.observableNames.get( - measure1.getName()))][((Integer) this.observableNames - .get(measure2.getName()))] = true; - correlatedErrors[((Integer) this.observableNames.get( - measure2.getName()))][((Integer) this.observableNames.get(measure1.getName()))] = true; + Node measure2 = it2.next(); + correlatedErrors[this.observableNames.get( + measure1.getName())][this.observableNames + .get(measure2.getName())] = true; + correlatedErrors[this.observableNames.get( + measure2.getName())][this.observableNames.get(measure1.getName())] = true; } } for (int i = 0; i < this.numObserved; i++) { - Node node = (Node) this.measuredNodes.get(i); + Node node = this.measuredNodes.get(i); this.parents[i] = new int[semMag.getParents(node).size() - 1]; this.parentsL[i] = new boolean[semMag.getParents(node).size() - 1]; int count = 0; for (Node parent : semMag.getParents(node)) { if (parent.getNodeType() == NodeType.LATENT) { this.parents[i][count] = - ((Integer) this.latentNames.get(parent.getName())); + this.latentNames.get(parent.getName()); this.parentsL[i][count++] = true; } else if (parent.getNodeType() == NodeType.MEASURED) { this.parents[i][count] = - ((Integer) this.observableNames.get( - parent.getName())); + this.observableNames.get( + parent.getName()); this.parentsL[i][count++] = false; } } @@ -675,48 +663,47 @@ private void gaussianExpectation(SemIm semIm) { lambdaI[i][j] = 0.; } } - List parameters = semIm.getFreeParameters(); + List parameters = semIm.getFreeParameters(); double[] paramValues = semIm.getFreeParamValues(); for (int i = 0; i < parameters.size(); i++) { - Parameter parameter = (Parameter) parameters.get(i); + Parameter parameter = parameters.get(i); if (parameter.getType() == ParamType.COEF) { Node from = parameter.getNodeA(); Node to = parameter.getNodeB(); if (to.getNodeType() == NodeType.MEASURED && from.getNodeType() == NodeType.LATENT) { //latent-to-indicator edge - int position1 = (Integer) this.latentNames.get(from.getName()); - int position2 = (Integer) this.observableNames.get(to.getName()); + int position1 = this.latentNames.get(from.getName()); + int position2 = this.observableNames.get(to.getName()); lambdaL[position2][position1] = paramValues[i]; } else if (to.getNodeType() == NodeType.MEASURED && from.getNodeType() == NodeType.MEASURED) { //indicator-to-indicator edge int position1 = - (Integer) this.observableNames.get(from.getName()); - int position2 = (Integer) this.observableNames.get(to.getName()); + this.observableNames.get(from.getName()); + int position2 = this.observableNames.get(to.getName()); lambdaI[position2][position1] = paramValues[i]; } else if (to.getNodeType() == NodeType.LATENT) { //latent-to-latent edge - int position1 = (Integer) this.latentNames.get(from.getName()); - int position2 = (Integer) this.latentNames.get(to.getName()); + int position1 = this.latentNames.get(from.getName()); + int position2 = this.latentNames.get(to.getName()); beta[position2][position1] = paramValues[i]; } } else if (parameter.getType() == ParamType.VAR) { Node exo = parameter.getNodeA(); if (exo.getNodeType() == NodeType.ERROR) { - Iterator ci = semIm.getSemPm().getGraph().getChildren(exo) + Iterator ci = semIm.getSemPm().getGraph().getChildren(exo) .iterator(); - exo = - (Node) ci.next(); //Assuming error nodes have only one children in SemGraphs... + exo = ci.next(); //Assuming error nodes have only one children in SemGraphs... } if (exo.getNodeType() == NodeType.LATENT) { - fi[((Integer) this.latentNames.get( - exo.getName()))][((Integer) this.latentNames - .get(exo.getName()))] = paramValues[i]; + fi[this.latentNames.get( + exo.getName())][this.latentNames + .get(exo.getName())] = paramValues[i]; } else { - tau[((Integer) this.observableNames.get( - exo.getName()))][((Integer) this.observableNames - .get(exo.getName()))] = paramValues[i]; + tau[this.observableNames.get( + exo.getName())][this.observableNames + .get(exo.getName())] = paramValues[i]; } } else if (parameter.getType() == ParamType.COVAR) { Node exo1 = parameter.getNodeA(); @@ -727,11 +714,11 @@ private void gaussianExpectation(SemIm semIm) { exo1 = semIm.getSemPm().getGraph().getVarNode(exo1); exo2 = semIm.getSemPm().getGraph().getVarNode(exo2); - tau[((Integer) this.observableNames.get( - exo1.getName()))][((Integer) this.observableNames - .get(exo2.getName()))] = tau[((Integer) this.observableNames - .get(exo2.getName()))][((Integer) this.observableNames - .get(exo1.getName()))] = paramValues[i]; + tau[this.observableNames.get( + exo1.getName())][this.observableNames + .get(exo2.getName())] = tau[this.observableNames + .get(exo2.getName())][this.observableNames + .get(exo1.getName())] = paramValues[i]; } } @@ -820,15 +807,15 @@ private double gaussianMaximization(SemIm semIm) { } if (latent != null) { int index1 = - (Integer) this.latentNames.get(latent.getName()); - int index2 = (Integer) this.observableNames.get( + this.latentNames.get(latent.getName()); + int index2 = this.observableNames.get( observed.getName()); this.betas[index2][index1] = semIm.getParamValue(nextP); } else { int index1 = - (Integer) this.observableNames.get(node1.getName()); + this.observableNames.get(node1.getName()); int index2 = - (Integer) this.observableNames.get(node2.getName()); + this.observableNames.get(node2.getName()); if (semIm.getSemPm().getGraph().isParentOf(node1, node2)) { this.betas[index2][this.numLatent + index1] = semIm.getParamValue(nextP); @@ -846,8 +833,8 @@ private double gaussianMaximization(SemIm semIm) { exo1 = semIm.getSemPm().getGraph().getVarNode(exo1); exo2 = semIm.getSemPm().getGraph().getVarNode(exo2); - int index1 = (Integer) this.observableNames.get(exo1.getName()); - int index2 = (Integer) this.observableNames.get(exo2.getName()); + int index1 = this.observableNames.get(exo1.getName()); + int index2 = this.observableNames.get(exo2.getName()); this.covErrors[index1][index2] = this.covErrors[index2][index1] = semIm.getParamValue(nextP); @@ -861,7 +848,7 @@ private double gaussianMaximization(SemIm semIm) { if (exo.getNodeType() == NodeType.MEASURED) { int index = - (Integer) this.observableNames.get(exo.getName()); + this.observableNames.get(exo.getName()); this.covErrors[index][index] = semIm.getParamValue(nextP); } } @@ -1381,26 +1368,26 @@ private SemGraph removeMarkedImpurities(SemGraph graph, boolean[][] impurities) { printlnMessage(); printlnMessage("** PURIFY: using marked impure pairs"); - List latents = new ArrayList(); - List partition = new ArrayList(); + List latents = new ArrayList<>(); + List partition = new ArrayList<>(); for (int i = 0; i < graph.getNodes().size(); i++) { Node nextLatent = graph.getNodes().get(i); if (nextLatent.getNodeType() != NodeType.LATENT) { continue; } latents.add(graph.getNodes().get(i)); - Iterator cit = graph.getChildren(nextLatent).iterator(); - List children = new ArrayList(); + Iterator cit = graph.getChildren(nextLatent).iterator(); + List children = new ArrayList<>(); while (cit.hasNext()) { - Node cnext = (Node) cit.next(); + Node cnext = cit.next(); if (cnext.getNodeType() == NodeType.MEASURED) { children.add(cnext); } } int[] newCluster = new int[children.size()]; for (int j = 0; j < children.size(); j++) { - newCluster[j] = ((Integer) this.observableNames.get( - children.get(j).toString())); + newCluster[j] = this.observableNames.get( + children.get(j).toString()); } partition.add(newCluster); } @@ -1412,7 +1399,7 @@ private SemGraph removeMarkedImpurities(SemGraph graph, } } } - List latentCliques = new ArrayList(); + List latentCliques = new ArrayList<>(); int[] firstClique = new int[latents.size()]; for (int i = 0; i < firstClique.length; i++) { firstClique[i] = i; @@ -1422,11 +1409,11 @@ private SemGraph removeMarkedImpurities(SemGraph graph, //Now, ready to purify for (Object latentClique : latentCliques) { int[] nextLatentList = (int[]) latentClique; - List nextPartition = new ArrayList(); + List nextPartition = new ArrayList<>(); for (int j : nextLatentList) { nextPartition.add(partition.get(j)); } - List solution = findInducedPureGraph(nextPartition, impurities); + List solution = findInducedPureGraph(nextPartition, impurities); if (solution != null) { System.out.println("--Solution"); @@ -1445,7 +1432,7 @@ private SemGraph removeMarkedImpurities(SemGraph graph, graph2.setShowErrorTerms(true); Node[] latentsArray = new Node[solution.size()]; for (int p = 0; p < solution.size(); p++) { - int[] cluster = (int[]) solution.get(p); + int[] cluster = solution.get(p); latentsArray[p] = new GraphNode(ClusterUtils.LATENT_PREFIX + (p + 1)); latentsArray[p].setNodeType(NodeType.LATENT); @@ -1471,19 +1458,16 @@ private SemGraph removeMarkedImpurities(SemGraph graph, return null; } - private List findInducedPureGraph(List partition, boolean[][] impurities) { + private List findInducedPureGraph(List partition, boolean[][] impurities) { //Store the ID of all elements for fast access int[][] elements = new int[sizeCluster(partition)][3]; - int[] partitionCount = new int[partition.size()]; int countElements = 0; for (int p = 0; p < partition.size(); p++) { - int[] next = (int[]) partition.get(p); - partitionCount[p] = 0; + int[] next = partition.get(p); for (int j : next) { elements[countElements][0] = j; // global ID elements[countElements][1] = p; // set partition ID countElements++; - partitionCount[p]++; } } //Count how many impure relations are entailed by each indicator @@ -1504,7 +1488,7 @@ private List findInducedPureGraph(List partition, boolean[][] impurities) { return buildSolution2(elements, eliminated, partition); } - private int sizeCluster(List cluster) { + private int sizeCluster(List cluster) { int total = 0; for (Object o : cluster) { int[] next = (int[]) o; @@ -1513,9 +1497,9 @@ private int sizeCluster(List cluster) { return total; } - private List buildSolution2(int[][] elements, boolean[] eliminated, - List partition) { - List solution = new ArrayList(); + private List buildSolution2(int[][] elements, boolean[] eliminated, + List partition) { + List solution = new ArrayList<>(); for (Object o : partition) { int[] next = (int[]) o; int[] draftArea = new int[next.length]; @@ -1541,7 +1525,7 @@ private List buildSolution2(int[][] elements, boolean[] eliminated, } } - private double impurityScoreSearch(double initialScore) { + private void impurityScoreSearch(double initialScore) { double score, nextScore = initialScore; boolean[] changed = new boolean[1]; do { @@ -1553,7 +1537,6 @@ private double impurityScoreSearch(double initialScore) { nextScore = deleteImpuritySearch(nextScore, changed); } } while (changed[0]); - return score; } private double addImpuritySearch(double initialScore, boolean[] changed) { @@ -1643,8 +1626,7 @@ private boolean forbiddenImpurity(String name1, String name2) { if (this.forbiddenList == null) { return false; } - for (Object o : this.forbiddenList) { - Set nextPair = (Set) o; + for (Set nextPair : this.forbiddenList) { if (nextPair.contains(name1) && nextPair.contains(name2)) { return true; } @@ -1682,9 +1664,9 @@ private SemGraph updatedGraph() { if (node2.getNodeType() != NodeType.LATENT) { continue; } - int pos1 = (Integer) this.observableNames.get( + int pos1 = this.observableNames.get( output.getNodes().get(i).toString()); - int pos2 = (Integer) this.latentNames.get( + int pos2 = this.latentNames.get( output.getNodes().get(j).toString()); if (this.latentParent[pos1][pos2] && output.getEdge(node1, node2) == null) { @@ -1698,9 +1680,9 @@ private SemGraph updatedGraph() { } Node errnode1 = output.getErrorNode(output.getNodes().get(i)); Node errnode2 = output.getErrorNode(output.getNodes().get(j)); - int pos1 = (Integer) this.observableNames.get( + int pos1 = this.observableNames.get( output.getNodes().get(i).toString()); - int pos2 = (Integer) this.observableNames.get( + int pos2 = this.observableNames.get( output.getNodes().get(j).toString()); if (this.correlatedErrors[pos1][pos2] && output.getEdge(errnode1, errnode2) == null) { @@ -1802,18 +1784,6 @@ private double deleteImpuritySearch(double initialScore, return score; } - - // The number of variables in cluster that have not been eliminated. - - private int numNotEliminated(int[] cluster, boolean[] eliminated) { - int n1 = 0; - for (int j : cluster) { - if (!eliminated[j]) { - n1++; - } - } - return n1; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java index 105b475ad0..653de73c60 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java @@ -30,16 +30,15 @@ // EXPERIMENTAL!! /** - * A clean-up of Ricardo's IntSextad-based purify. + * A clean-up of Ricardo's Sextad-based purify. * * @author Joe Ramsey */ public class PurifySextadBased { - private final boolean outputMessage = true; private final DeltaSextadTest sextadTest; private final List nodes; - private double alpha = 0.05; + private final double alpha; public PurifySextadBased(DeltaSextadTest sextadTest, double alpha) { this.sextadTest = sextadTest; @@ -52,12 +51,9 @@ public PurifySextadBased(DeltaSextadTest sextadTest, double alpha) { this.alpha = alpha; } + // The input nodes may not be object-identical to the ones from the IntSextad test. public List> purify(List> clustering) { - // The input nodes may not be object identical to the ones from the IntSextad test, so we map them over then - // back by their names. - clustering.addAll(clustering); - if (clustering.isEmpty()) { throw new NullPointerException("Clusters not specified."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java index 13365e96d7..8531da48e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java @@ -26,8 +26,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.ChoiceGenerator; -import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.*; /** @@ -36,7 +34,6 @@ * @author Joe Ramsey */ public class PurifyTetradBased implements IPurify { - private final boolean outputMessage = true; private final TetradTest tetradTest; private final List nodes; @@ -48,7 +45,7 @@ public PurifyTetradBased(TetradTest tetradTest) { public List> purify(List> clustering) { - // The input nodes may not be object identical to the ones from the tetrad test, so we map them over then + // The input nodes may not be object-identical to the ones from the tetrad test, so we map them over then // back by their names. List originalNodes = new ArrayList<>(); @@ -87,7 +84,6 @@ private List> combinedSearch(List> clustering) { Set allImpurities = null; double cutoff = this.tetradTest.getSignificance(); - final int count = 0; for (List cluster : clustering) { Set impurities = listTetrads(cluster, eliminated, cutoff); @@ -113,8 +109,6 @@ private List> combinedSearch(List> clustering) { return new ArrayList<>(); } - NumberFormat nf = new DecimalFormat("0.####E00"); - while (true) { int max = 0; Node maxNode = null; From c3328a6ded20e47d84b690712f15efa76269a7d4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 16:42:40 -0400 Subject: [PATCH 324/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../BuildPureClustersIndTestParamsEditor.java | 4 +- ...BuildPureClustersIndTestParamsEditor2.java | 4 +- .../editor/BuildPureClustersParamsEditor.java | 2 +- .../model/BuildPureClustersRunner.java | 10 ++- .../model/MeasurementModelWrapper.java | 2 +- .../cmu/tetradapp/model/MimBuildRunner.java | 2 +- .../tetradapp/model/MimBuildTrekRunner.java | 2 +- .../edu/cmu/tetradapp/model/PurifyRunner.java | 2 +- .../algcomparison/algorithm/cluster/Bpc.java | 5 +- .../algcomparison/algorithm/cluster/Fofc.java | 3 + .../{BuildPureClusters.java => Bpc.java} | 9 +-- .../main/java/edu/cmu/tetrad/search/Fofc.java | 4 ++ .../main/java/edu/cmu/tetrad/search/Ftfc.java | 2 + .../search/WIP/BpcTetradPurifyWashdown.java | 2 +- .../{ => bpc_utils}/BpcAlgorithmType.java | 2 +- .../search/{ => bpc_utils}/BpcTestType.java | 2 +- .../{ => bpc_utils}/ClusterSignificance.java | 20 +++--- .../search/{ => bpc_utils}/ClusterUtils.java | 4 +- .../search/{ => bpc_utils}/IPurify.java | 2 +- .../tetrad/search/{ => bpc_utils}/Purify.java | 64 ++++++++----------- .../{ => bpc_utils}/PurifyScoreBased.java | 3 +- .../{ => bpc_utils}/PurifySextadBased.java | 4 +- .../{ => bpc_utils}/PurifyTetradBased.java | 3 +- .../search/{ => bpc_utils}/TetradTest.java | 2 +- .../{ => bpc_utils}/TetradTestContinuous.java | 4 +- .../{ => bpc_utils}/TetradTestDiscrete.java | 2 +- .../{ => bpc_utils}/TetradTestPopulation.java | 2 +- .../edu/cmu/tetrad/test/TestMimbuild.java | 4 +- .../java/edu/cmu/tetrad/test/TestPurify.java | 1 + 29 files changed, 96 insertions(+), 76 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{BuildPureClusters.java => Bpc.java} (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/BpcAlgorithmType.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/BpcTestType.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/ClusterSignificance.java (91%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/ClusterUtils.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/IPurify.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/Purify.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/PurifyScoreBased.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/PurifySextadBased.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/PurifyTetradBased.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/TetradTest.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/TetradTestContinuous.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/TetradTestDiscrete.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/TetradTestPopulation.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java index 68ff29bcfd..f6e236f4f6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java @@ -21,8 +21,8 @@ package edu.cmu.tetradapp.editor; -import edu.cmu.tetrad.search.BpcAlgorithmType; -import edu.cmu.tetrad.search.BpcTestType; +import edu.cmu.tetrad.search.bpc_utils.BpcAlgorithmType; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.DoubleTextField; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java index 93267cc97b..e47a13cac2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java @@ -21,8 +21,8 @@ package edu.cmu.tetradapp.editor; -import edu.cmu.tetrad.search.BpcAlgorithmType; -import edu.cmu.tetrad.search.BpcTestType; +import edu.cmu.tetrad.search.bpc_utils.BpcAlgorithmType; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.DoubleTextField; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java index dcbd03c7ba..21486092df 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.BpcTestType; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.model.DataWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index a331a9509a..8d1e20c13b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -29,6 +29,10 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.BpcTetradPurifyWashdown; import edu.cmu.tetrad.search.WIP.Washdown; +import edu.cmu.tetrad.search.bpc_utils.BpcAlgorithmType; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.Bpc; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; @@ -135,18 +139,18 @@ public void execute() { searchGraph = bpc.search(); } else if (algorithm == BpcAlgorithmType.BUILD_PURE_CLUSTERS) { - BuildPureClusters bpc; + Bpc bpc; DataModel source = getData(); BpcTestType testType = (BpcTestType) getParams().get("tetradTestType", BpcTestType.TETRAD_WISHART); if (source instanceof ICovarianceMatrix) { - bpc = new BuildPureClusters((ICovarianceMatrix) source, + bpc = new Bpc((ICovarianceMatrix) source, getParams().getDouble("alpha", 0.001), testType ); } else if (source instanceof DataSet) { - bpc = new BuildPureClusters( + bpc = new Bpc( (DataSet) source, getParams().getDouble("alpha", 0.001), testType ); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java index 721b3526c4..8ba18f3280 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.ClusterUtils; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; import edu.cmu.tetrad.session.ParamsResettable; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java index e623f20686..7f22eb7506 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ClusterUtils; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; import edu.cmu.tetrad.search.MimUtils; import edu.cmu.tetrad.search.Mimbuild; import edu.cmu.tetrad.sem.ReidentifyVariables; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java index d739620af4..dd4ea40e45 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ClusterUtils; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; import edu.cmu.tetrad.search.MimUtils; import edu.cmu.tetrad.search.MimbuildTrek; import edu.cmu.tetrad.sem.ReidentifyVariables; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index 8f2e0a6431..2d40e882d6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.bpc_utils.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index eff1398535..aeba31eb9c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -9,6 +9,9 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.bpc_utils.ClusterSignificance; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; @@ -50,7 +53,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { testType = BpcTestType.TETRAD_DELTA; } - BuildPureClusters bpc = new BuildPureClusters(cov, alpha, testType); + edu.cmu.tetrad.search.Bpc bpc = new edu.cmu.tetrad.search.Bpc(cov, alpha, testType); if (parameters.getInt(Params.CHECK_TYPE) == 1) { bpc.setCheckType(ClusterSignificance.CheckType.Significance); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index 9cfe543840..340516b527 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -9,6 +9,9 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.bpc_utils.ClusterSignificance; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index 8774c34c5e..e9b8c902c3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BuildPureClusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.bpc_utils.*; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; @@ -56,7 +57,7 @@ * * @author Ricardo Silva */ -public final class BuildPureClusters { +public final class Bpc { private boolean outputMessage; private ICovarianceMatrix covarianceMatrix; @@ -88,8 +89,8 @@ public final class BuildPureClusters { /** * Constructor BuildPureClusters */ - public BuildPureClusters(ICovarianceMatrix covarianceMatrix, double alpha, - BpcTestType sigTestType) { + public Bpc(ICovarianceMatrix covarianceMatrix, double alpha, + BpcTestType sigTestType) { if (covarianceMatrix == null) { throw new IllegalArgumentException("Covariance matrix cannot be null."); } @@ -98,7 +99,7 @@ public BuildPureClusters(ICovarianceMatrix covarianceMatrix, double alpha, initAlgorithm(alpha, sigTestType); } - public BuildPureClusters(DataSet dataSet, double alpha, BpcTestType sigTestType) { + public Bpc(DataSet dataSet, double alpha, BpcTestType sigTestType) { if (dataSet.isContinuous()) { this.dataSet = dataSet; this.covarianceMatrix = new CovarianceMatrix(dataSet); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index 94619aac6d..89e86063d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -23,6 +23,10 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.bpc_utils.ClusterSignificance; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.bpc_utils.TetradTestContinuous; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index b29a90c12c..0ef6a35921 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java index f8c66d4ba4..fba528bf8e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.bpc_utils.*; import java.util.ArrayList; import java.util.HashSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcAlgorithmType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcAlgorithmType.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcAlgorithmType.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcAlgorithmType.java index b65af87eac..e27c7d2bbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcAlgorithmType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcAlgorithmType.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTestType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcTestType.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTestType.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcTestType.java index e66a1e7f73..3297eba8c3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BpcTestType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcTestType.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterSignificance.java similarity index 91% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterSignificance.java index 06afd601c1..60d74b0559 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterSignificance.java @@ -1,10 +1,12 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.Fas; +import edu.cmu.tetrad.search.IndTestFisherZ; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; @@ -31,14 +33,14 @@ public enum CheckType {Significance, Clique, None} private CheckType checkType = CheckType.Clique; - ClusterSignificance(List variables, DataModel dataModel) { + public ClusterSignificance(List variables, DataModel dataModel) { if (variables == null) throw new NullPointerException("Variable null."); if (dataModel == null) throw new NullPointerException("Data model null."); this.variables = variables; this.dataModel = dataModel; } - void printClusterPValues(Set> out) { + public void printClusterPValues(Set> out) { NumberFormat nf = new DecimalFormat("0.000"); for (List _out : out) { @@ -55,7 +57,7 @@ void printClusterPValues(Set> out) { } } - static List variablesForIndices(List cluster, List variables) { + public static List variablesForIndices(List cluster, List variables) { List _cluster = new ArrayList<>(); for (int c : cluster) { @@ -65,7 +67,7 @@ static List variablesForIndices(List cluster, List variable return _cluster; } - static List> variablesForIndices2(Set> clusters, List _variables) { + public static List> variablesForIndices2(Set> clusters, List _variables) { List> variables = new ArrayList<>(); for (List cluster : clusters) { @@ -81,17 +83,17 @@ static List> variablesForIndices2(Set> clusters, List getInts(int[] indices) { + public static List getInts(int[] indices) { List cluster = new ArrayList<>(); for (int i : indices) cluster.add(i); return cluster; } - void setCheckType(CheckType checkType) { + public void setCheckType(CheckType checkType) { this.checkType = checkType; } - boolean significant(List cluster, double alpha) { + public boolean significant(List cluster, double alpha) { if (checkType == CheckType.None) { return true; } else if (checkType == CheckType.Significance) { @@ -103,7 +105,7 @@ boolean significant(List cluster, double alpha) { } } - double getModelPValue(List> clusters) { + public double getModelPValue(List> clusters) { SemIm im = estimateModel(clusters); return im.getPValue(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterUtils.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterUtils.java index 312e8e2c98..0ef76a88cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClusterUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterUtils.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.Clusters; import edu.cmu.tetrad.graph.*; @@ -180,7 +180,7 @@ public static Clusters mimClusters(Graph mim) { } - static void logClusters(Set> clusters, List variables) { + public static void logClusters(Set> clusters, List variables) { int num = 1; StringBuilder buf = new StringBuilder(); buf.append("\nClusters:\n"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/IPurify.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/IPurify.java index cf84c7e367..0db11ae951 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IPurify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/IPurify.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Purify.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Purify.java index d83438f1d9..3f4c53e037 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Purify.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; @@ -65,7 +65,7 @@ public class Purify { private CorrelationMatrix correlationMatrix; private DataSet dataSet; private Clusters clusters; - private List forbiddenList; + private List forbiddenList; private int numVars; private TetradTest tetradTest; @@ -127,10 +127,6 @@ public Purify(TetradTest tetradTest, Clusters knowledge) { this.variables = tetradTest.getVariables(); } - public void setForbiddenList(List forbiddenList) { - this.forbiddenList = forbiddenList; - } - private void initAlgorithm(double sig, BpcTestType testType, Clusters clusters) { this.clusters = clusters; this.forbiddenList = null; @@ -153,10 +149,6 @@ private void initAlgorithm(double sig, BpcTestType testType, Clusters clusters) this.outputMessage = true; } - public void setOutputMessage(boolean outputMessage) { - this.outputMessage = outputMessage; - } - /** * ****************************************************** SEARCH INTERFACE ******************************************************* */ @@ -182,7 +174,7 @@ private Graph getResultGraph() { { BpcTestType type = ((TetradTestContinuous) this.tetradTest).getTestType(); // type = TestType.TETRAD_BASED; - type = null; +// type = null; if (type == BpcTestType.TETRAD_BASED) { IPurify purifier = new PurifyTetradBased(this.tetradTest); @@ -200,7 +192,7 @@ private Graph getResultGraph() { SemGraph semGraph3 = dummyPurification(getClusters()); return Purify.convertSearchGraph(semGraph3); } else { - List pureClusters; + List pureClusters; // if (constraintSearchVariation == 0) { IPurify purifier = new PurifyTetradBased(this.tetradTest); List> partition2 = purifier.purify(ClusterUtils.convertIntToList(getClusters(), this.tetradTest.getVariables())); @@ -220,16 +212,16 @@ private List getVariables() { } private List getClusters() { - List clusters = new ArrayList(); + List clusters = new ArrayList<>(); String[] varNames = this.tetradTest.getVarNames(); for (int i = 0; i < this.clusters.getNumClusters(); i++) { - List clusterS = this.clusters.getCluster(i); + List clusterS = this.clusters.getCluster(i); int[] cluster = new int[clusterS.size()]; - Iterator it = clusterS.iterator(); + Iterator it = clusterS.iterator(); int count = 0; while (it.hasNext()) { - String nextName = (String) it.next(); + String nextName = it.next(); for (int j = 0; j < varNames.length; j++) { if (varNames[j].equals(nextName)) { cluster[count++] = j; @@ -245,12 +237,12 @@ private List getClusters() { public static Graph convertSearchGraph(SemGraph input) { if (input == null) { - List nodes = new ArrayList(); + List nodes = new ArrayList<>(); nodes.add(new GraphNode("No_model.")); return new EdgeListGraph(nodes); } - List inputIndicators = new ArrayList(); - List inputLatents = new ArrayList(); + List inputIndicators = new ArrayList<>(); + List inputLatents = new ArrayList<>(); for (Node next : input.getNodes()) { if (next.getNodeType() == NodeType.MEASURED) { inputIndicators.add(next); @@ -259,7 +251,7 @@ public static Graph convertSearchGraph(SemGraph input) { } } - List allNodes = new ArrayList(inputIndicators); + List allNodes = new ArrayList<>(inputIndicators); allNodes.addAll(inputLatents); Graph output = new EdgeListGraph(allNodes); @@ -269,12 +261,12 @@ public static Graph convertSearchGraph(SemGraph input) { if (edge != null) { if (node1.getNodeType() == NodeType.ERROR && node2.getNodeType() == NodeType.ERROR) { - Iterator ci = input.getChildren(node1).iterator(); + Iterator ci = input.getChildren(node1).iterator(); Node indicator1 = - (Node) ci.next(); //Assuming error nodes have only one children in SemGraphs... + ci.next(); //Assuming error nodes have only one children in SemGraphs... ci = input.getChildren(node2).iterator(); Node indicator2 = - (Node) ci.next(); //Assuming error nodes have only one children in SemGraphs... + ci.next(); //Assuming error nodes have only one children in SemGraphs... if (indicator1.getNodeType() != NodeType.LATENT) { output.setEndpoint(indicator1, indicator2, Endpoint.ARROW); @@ -296,10 +288,10 @@ public static Graph convertSearchGraph(SemGraph input) { for (int i = 0; i < inputLatents.size() - 1; i++) { for (int j = i + 1; j < inputLatents.size(); j++) { - output.setEndpoint((Node) inputLatents.get(i), - (Node) inputLatents.get(j), Endpoint.TAIL); - output.setEndpoint((Node) inputLatents.get(j), - (Node) inputLatents.get(i), Endpoint.TAIL); + output.setEndpoint(inputLatents.get(i), + inputLatents.get(j), Endpoint.TAIL); + output.setEndpoint(inputLatents.get(j), + inputLatents.get(i), Endpoint.TAIL); } } @@ -310,7 +302,7 @@ public static Graph convertSearchGraph(SemGraph input) { * ****************************************************** DEBUG UTILITIES ******************************************************* */ - private void printClustering(List clustering) { + private void printClustering(List clustering) { for (Object o : clustering) { int[] c = (int[]) o; printCluster(c); @@ -359,7 +351,7 @@ private void printlnMessage() { } } - private int sizeCluster(List cluster) { + private int sizeCluster(List cluster) { int total = 0; for (Object o : cluster) { int[] next = (int[]) o; @@ -374,7 +366,7 @@ private int sizeCluster(List cluster) { * impure. If there is not, then it is treated as pure. This is virtually the original Purify as described in CPS. */ - private List tetradBasedPurify(List partition) { + private List tetradBasedPurify(List partition) { boolean[] eliminated = new boolean[this.numVars]; for (int i = 0; i < this.numVars; i++) { eliminated[i] = false; @@ -407,7 +399,7 @@ private List tetradBasedPurify(List partition) { "------------------------------------------------------"); printlnMessage("Output Measurement Model"); - List output = buildSolution(partition, eliminated); + List output = buildSolution(partition, eliminated); printClustering(output); return output; @@ -428,9 +420,9 @@ private void intraConstructPhase(int[] cluster, boolean[] eliminated, List allPValues = new ArrayList<>(); int numImpurities = 0; - Set[] failures = new Set[clusterSize]; + Set[] failures = new Set[clusterSize]; for (int i = 0; i < clusterSize; i++) { - failures[i] = new HashSet(); + failures[i] = new HashSet<>(); } for (int i = 0; i < clusterSize - 3; i++) { @@ -548,7 +540,7 @@ private void intraConstructPhase(int[] cluster, boolean[] eliminated, if (eliminated[cluster[i]]) { continue; } - Set toRemove = new HashSet(); + Set toRemove = new HashSet<>(); for (Object o : failures[i]) { int[] impurity = (int[]) o; for (int j = 0; j < 4; j++) { @@ -1033,8 +1025,8 @@ private int numNotEliminated2(List cluster, boolean[] eliminated) { return n1; } - private List buildSolution(List partition, boolean[] eliminated) { - List solution = new ArrayList(); + private List buildSolution(List partition, boolean[] eliminated) { + List solution = new ArrayList<>(); for (Object o : partition) { int[] next = (int[]) o; int[] draftArea = new int[next.length]; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyScoreBased.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyScoreBased.java index 169d535284..9950025a08 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyScoreBased.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.Clusters; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.MimUtils; import edu.cmu.tetrad.sem.ParamType; import edu.cmu.tetrad.sem.Parameter; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifySextadBased.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifySextadBased.java index 653de73c60..332018045c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifySextadBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifySextadBased.java @@ -19,8 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; +import edu.cmu.tetrad.search.DeltaSextadTest; +import edu.cmu.tetrad.search.Sextad; import edu.cmu.tetrad.util.ChoiceGenerator; import java.text.DecimalFormat; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java index 8531da48e3..48a0ce957f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Tetrad; import edu.cmu.tetrad.util.ChoiceGenerator; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTest.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTest.java index c990c94097..5912c21200 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java index 9107426811..3008f77a5c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestContinuous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java @@ -19,13 +19,15 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.DeltaTetradTest; +import edu.cmu.tetrad.search.Tetrad; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.ProbUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestDiscrete.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestDiscrete.java index 73f2b6fe94..3b92ba3cf6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestPopulation.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestPopulation.java index e2f406648c..62cfc9e42d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TetradTestPopulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestPopulation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index 52c84d21a5..2e621bc3d2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -29,6 +29,8 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.Bpc; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; @@ -82,7 +84,7 @@ public void test1() { final BpcTestType testType = BpcTestType.TETRAD_WISHART; final BpcTestType purifyType = BpcTestType.TETRAD_BASED; - BuildPureClusters bpc = new BuildPureClusters( + Bpc bpc = new Bpc( data, 0.001, testType ); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index e9b5f8fec0..9c165b7260 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.bpc_utils.*; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; From 38e07f88f62d8c94322aef476cd4f9a97576a79d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 16:44:01 -0400 Subject: [PATCH 325/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java | 5 +---- .../edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java | 1 - .../java/edu/cmu/tetrad/search/{ => bpc_utils}/Tetrad.java | 2 +- .../cmu/tetrad/search/bpc_utils/TetradTestContinuous.java | 1 - .../test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java | 2 +- 6 files changed, 4 insertions(+), 8 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => bpc_utils}/Tetrad.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java index 4343e69a13..302f947ae1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.bpc_utils.Tetrad; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index 89e86063d2..1eba5c51cf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -23,10 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; -import edu.cmu.tetrad.search.bpc_utils.ClusterSignificance; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; -import edu.cmu.tetrad.search.bpc_utils.TetradTestContinuous; +import edu.cmu.tetrad.search.bpc_utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java index 48a0ce957f..91bad970f3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Tetrad; import edu.cmu.tetrad.util.ChoiceGenerator; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Tetrad.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Tetrad.java index 8e53e0f509..db8b107f3b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Tetrad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Tetrad.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.bpc_utils; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java index 3008f77a5c..525b3aa060 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java @@ -27,7 +27,6 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.DeltaTetradTest; -import edu.cmu.tetrad.search.Tetrad; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.ProbUtils; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java index bc485c99db..2787089e55 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.DeltaTetradTest; -import edu.cmu.tetrad.search.Tetrad; +import edu.cmu.tetrad.search.bpc_utils.Tetrad; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Matrix; From c0d40d01a12cd99fe6c1e41c057f92e294edd47a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:02:15 -0400 Subject: [PATCH 326/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetradapp/editor/BayesUpdaterClassifierEditor.java | 8 ++++---- .../editor/BuildPureClustersIndTestParamsEditor.java | 4 ++-- .../editor/BuildPureClustersIndTestParamsEditor2.java | 4 ++-- .../editor/BuildPureClustersParamsEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/CPDAGDisplay.java | 2 +- .../cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/PagColorer.java | 2 +- .../edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java | 4 ++-- .../knowledge_editor/KnowledgeEditorToolbar.java | 2 +- .../tetradapp/model/BayesUpdaterClassifierWrapper.java | 10 +++++----- .../cmu/tetradapp/model/BuildPureClustersRunner.java | 6 +++--- .../java/edu/cmu/tetradapp/model/CPDAGFitModel.java | 2 +- .../cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java | 2 +- .../edu/cmu/tetradapp/model/DagInCPDAGWrapper.java | 2 +- .../cmu/tetradapp/model/EdgewiseComparisonModel.java | 4 ++-- .../tetradapp/model/ExtractStructureModelWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/FasRunner.java | 2 ++ .../main/java/edu/cmu/tetradapp/model/FciRunner.java | 1 + .../cmu/tetradapp/model/GeneralAlgorithmRunner.java | 2 ++ .../java/edu/cmu/tetradapp/model/MagInPagWrapper.java | 2 +- .../cmu/tetradapp/model/MeasurementModelWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/MimBuildRunner.java | 2 +- .../edu/cmu/tetradapp/model/MimBuildTrekRunner.java | 2 +- .../edu/cmu/tetradapp/model/Misclassifications.java | 4 ++-- .../edu/cmu/tetradapp/model/PValueImproverWrapper.java | 2 ++ .../cmu/tetradapp/model/PagFromDagGraphWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/PcRunner.java | 2 ++ .../java/edu/cmu/tetradapp/model/PurifyRunner.java | 2 +- .../edu/cmu/tetradapp/model/SampleVcpcFastRunner.java | 2 ++ .../java/edu/cmu/tetradapp/model/SampleVcpcRunner.java | 2 ++ .../edu/cmu/tetradapp/model/ScoredGraphsWrapper.java | 4 ++-- .../java/edu/cmu/tetradapp/model/VcpcFastRunner.java | 2 ++ .../main/java/edu/cmu/tetradapp/model/VcpcRunner.java | 2 ++ .../tetradapp/model/datamanip/ArResidualsWrapper.java | 2 +- .../tetradapp/model/datamanip/ShiftDataWrapper.java | 2 +- .../tetradapp/model/datamanip/TimeSeriesWrapper.java | 2 +- .../tetradapp/model/datamanip/TimeSeriesWrapper2.java | 2 +- .../java/edu/cmu/tetradapp/workbench/LayoutUtils.java | 2 +- .../java/edu/cmu/tetrad/algcomparison/Comparison.java | 2 +- .../cmu/tetrad/algcomparison/TimeoutComparison.java | 4 ++-- .../tetrad/algcomparison/algorithm/cluster/Bpc.java | 7 ++++--- .../tetrad/algcomparison/algorithm/cluster/Fofc.java | 7 ++++--- .../tetrad/algcomparison/algorithm/cluster/Ftfc.java | 2 +- .../algorithm/multi/FgesConcatenated.java | 2 +- .../tetrad/algcomparison/algorithm/multi/Images.java | 1 + .../algcomparison/algorithm/oracle/cpdag/Boss.java | 1 + .../algcomparison/algorithm/oracle/cpdag/Cpc.java | 4 ++-- .../algcomparison/algorithm/oracle/cpdag/Fas.java | 2 +- .../algcomparison/algorithm/oracle/cpdag/Fges.java | 2 +- .../algorithm/oracle/cpdag/FgesMeasurement.java | 2 +- .../algcomparison/algorithm/oracle/cpdag/GesMe.java | 2 +- .../algcomparison/algorithm/oracle/cpdag/Grasp.java | 2 +- .../algcomparison/algorithm/oracle/cpdag/Pc.java | 4 ++-- .../algcomparison/algorithm/oracle/cpdag/PcMax.java | 4 ++-- .../algcomparison/algorithm/oracle/cpdag/Pcd.java | 2 +- .../algcomparison/algorithm/oracle/cpdag/Sp.java | 1 + .../algcomparison/algorithm/oracle/pag/Bfci.java | 4 ++-- .../algcomparison/algorithm/oracle/pag/Cfci.java | 2 +- .../tetrad/algcomparison/algorithm/oracle/pag/Fci.java | 4 ++-- .../algcomparison/algorithm/oracle/pag/FciMax.java | 4 ++-- .../algcomparison/algorithm/oracle/pag/Gfci.java | 4 ++-- .../algcomparison/algorithm/oracle/pag/GraspFci.java | 4 ++-- .../algorithm/oracle/pag/PagSampleRfci.java | 2 +- .../algcomparison/algorithm/oracle/pag/Rfci.java | 4 ++-- .../algcomparison/algorithm/oracle/pag/RfciBsc.java | 2 +- .../algcomparison/algorithm/oracle/pag/SpFci.java | 2 +- .../algcomparison/algorithm/oracle/pag/SvarFci.java | 2 +- .../algcomparison/algorithm/oracle/pag/SvarGfci.java | 2 +- .../simulation/TimeSeriesSemSimulation.java | 2 +- .../cmu/tetrad/algcomparison/statistic/BicDiff.java | 2 +- .../algcomparison/statistic/BicDiffPerRecord.java | 2 +- .../edu/cmu/tetrad/algcomparison/statistic/BicEst.java | 2 +- .../cmu/tetrad/algcomparison/statistic/BicTrue.java | 2 +- .../tetrad/algcomparison/statistic/BidirectedFP.java | 2 +- .../algcomparison/statistic/BidirectedPrecision.java | 2 +- .../algcomparison/statistic/BidirectedRecall.java | 2 +- .../tetrad/algcomparison/statistic/BidirectedTP.java | 2 +- .../tetrad/algcomparison/statistic/BidirectedTrue.java | 2 +- .../CommonAncestorFalseNegativeBidirected.java | 2 +- .../statistic/DefiniteDirectedPathPrecision.java | 2 +- .../statistic/DefiniteDirectedPathRecall.java | 2 +- .../LatentCommonAncestorFalseNegativeBidirected.java | 2 +- .../cmu/tetrad/algcomparison/statistic/LegalPag.java | 2 +- .../algcomparison/statistic/MaximalityCondition.java | 2 +- .../statistic/NoAlmostCyclicPathsInMagCondition.java | 2 +- .../statistic/NoCyclicPathsInMagCondition.java | 2 +- .../statistic/NoSemidirectedPrecision.java | 2 +- .../algcomparison/statistic/NoSemidirectedRecall.java | 2 +- .../NumCompatibleDefiniteDirectedEdgeAncestors.java | 2 +- .../statistic/NumCompatibleDirectedEdgeConfounded.java | 2 +- .../algcomparison/statistic/NumCompatibleEdges.java | 2 +- .../NumCompatiblePossiblyDirectedEdgeAncestors.java | 2 +- .../NumCompatiblePossiblyDirectedEdgeNonAncestors.java | 2 +- .../statistic/NumCompatibleVisibleAncestors.java | 2 +- .../statistic/NumCompatibleVisibleNonancestors.java | 2 +- .../algcomparison/statistic/NumDefinitelyDirected.java | 2 +- .../statistic/NumDefinitelyNotDirectedPaths.java | 2 +- .../statistic/NumDirectedEdgeVisible.java | 2 +- .../algcomparison/statistic/NumPossiblyDirected.java | 2 +- .../algcomparison/statistic/PagAdjacencyPrecision.java | 2 +- .../algcomparison/statistic/PagAdjacencyRecall.java | 2 +- .../edu/cmu/tetrad/algcomparison/statistic/Shd.java | 2 +- .../cmu/tetrad/calibration/DataForCalibrationRfci.java | 1 + .../src/main/java/edu/cmu/tetrad/graph/GraphUtils.java | 6 +++--- .../src/main/java/edu/cmu/tetrad/graph/Paths.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/BFci.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Bes.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Bpc.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/Ccd.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Cfci.java | 3 +++ ...aterClassifier.java => ClassifierBayesUpdater.java} | 8 ++++---- .../search/{MbClassify.java => ClassifierMb.java} | 8 ++++---- .../src/main/java/edu/cmu/tetrad/search/Cpc.java | 3 +++ .../java/edu/cmu/tetrad/search/DeltaSextadTest.java | 1 + .../java/edu/cmu/tetrad/search/DeltaTetradTest.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/Fas.java | 1 + .../java/edu/cmu/tetrad/search/FasDeterministic.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Fask.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Fci.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/FciMax.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/FciOrient.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Fges.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/FgesMb.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Fofc.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/Ftfc.java | 5 +++-- .../src/main/java/edu/cmu/tetrad/search/GFci.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Grasp.java | 1 + .../src/main/java/edu/cmu/tetrad/search/GraspFci.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/IFas.java | 1 + .../java/edu/cmu/tetrad/search/IndTestTrekSep.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Kpc.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/LingD.java | 2 ++ .../main/java/edu/cmu/tetrad/search/LingamPattern.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Lofs.java | 1 + .../src/main/java/edu/cmu/tetrad/search/MaxP.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/MbUtils.java | 3 ++- .../java/edu/cmu/tetrad/search/MnlrLikelihood.java | 1 + .../main/java/edu/cmu/tetrad/search/MvpLikelihood.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/PcMax.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/PcMb.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Pcd.java | 3 +++ .../java/edu/cmu/tetrad/search/PermutationBes.java | 1 + .../java/edu/cmu/tetrad/search/PermutationSearch.java | 1 + .../java/edu/cmu/tetrad/search/PossibleDsepFci.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Rfci.java | 2 ++ .../main/java/edu/cmu/tetrad/search/ShiftSearch.java | 1 + .../src/main/java/edu/cmu/tetrad/search/SpFci.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/SvarFci.java | 4 ++++ .../main/java/edu/cmu/tetrad/search/SvarFciOrient.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/SvarGfci.java | 3 +++ .../main/java/edu/cmu/tetrad/search/TsDagToPag.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/TsFas.java | 1 + .../src/main/java/edu/cmu/tetrad/search/TsFges.java | 3 +++ .../cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/WIP/Dci.java | 1 + .../main/java/edu/cmu/tetrad/search/WIP/FasFdr.java | 1 + .../main/java/edu/cmu/tetrad/search/WIP/GraspTol.java | 2 +- .../main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java | 4 ++-- .../main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java | 6 +++--- .../cmu/tetrad/search/WIP/IndTestFisherZRecursive.java | 1 + .../src/main/java/edu/cmu/tetrad/search/WIP/Ion.java | 4 ++-- .../java/edu/cmu/tetrad/search/WIP/IonHittingSet.java | 2 +- .../main/java/edu/cmu/tetrad/search/WIP/LofsOld.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/SampleVcpc.java | 2 ++ .../java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java | 2 ++ .../java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java | 2 ++ .../main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java | 2 ++ .../main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/AdLeafTree.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/AdTrees.java | 2 +- .../cmu/tetrad/search/{ => utils}/BayesImParser.java | 2 +- .../search/{bpc_utils => utils}/BpcAlgorithmType.java | 2 +- .../search/{bpc_utils => utils}/BpcTestType.java | 2 +- .../{bpc_utils => utils}/ClusterSignificance.java | 2 +- .../search/{bpc_utils => utils}/ClusterUtils.java | 2 +- .../tetrad/search/{ => utils}/DagInCpcagIterator.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/DagIterator.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/DagScorer.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/DagSepsets.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/DagToPag.java | 3 ++- .../cmu/tetrad/search/{ => utils}/EstimateRank.java | 2 +- .../cmu/tetrad/search/{ => utils}/FgesOrienter.java | 3 ++- .../edu/cmu/tetrad/search/{ => utils}/GraphChange.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/GraphInPag.java | 3 ++- .../tetrad/search/{ => utils}/GraphUtilsSearch.java | 3 ++- .../cmu/tetrad/search/{ => utils}/GraphoidAxioms.java | 6 +++--- .../tetrad/search/{ => utils}/HasPenaltyDiscount.java | 4 +++- .../tetrad/search/{ => utils}/HungarianAlgorithm.java | 2 +- .../tetrad/search/{bpc_utils => utils}/IPurify.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/LegalPairs.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/MeekRules.java | 4 +++- .../java/edu/cmu/tetrad/search/{ => utils}/NRooks.java | 2 +- .../tetrad/search/{ => utils}/PartialCorrelation.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/PcCommon.java | 3 ++- .../cmu/tetrad/search/{bpc_utils => utils}/Purify.java | 2 +- .../search/{bpc_utils => utils}/PurifyScoreBased.java | 2 +- .../search/{bpc_utils => utils}/PurifySextadBased.java | 3 +-- .../search/{bpc_utils => utils}/PurifyTetradBased.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/SepsetMap.java | 2 +- .../cmu/tetrad/search/{ => utils}/SepsetProducer.java | 3 ++- .../tetrad/search/{ => utils}/SepsetsConservative.java | 5 ++++- .../cmu/tetrad/search/{ => utils}/SepsetsGreedy.java | 5 ++++- .../tetrad/search/{ => utils}/SepsetsPossibleDsep.java | 4 +++- .../edu/cmu/tetrad/search/{ => utils}/SepsetsSet.java | 4 +++- .../java/edu/cmu/tetrad/search/{ => utils}/Sextad.java | 2 +- .../cmu/tetrad/search/{bpc_utils => utils}/Tetrad.java | 2 +- .../tetrad/search/{bpc_utils => utils}/TetradTest.java | 2 +- .../{bpc_utils => utils}/TetradTestContinuous.java | 2 +- .../{bpc_utils => utils}/TetradTestDiscrete.java | 2 +- .../{bpc_utils => utils}/TetradTestPopulation.java | 2 +- .../cmu/tetrad/search/{ => utils}/TeyssierScorer.java | 3 ++- .../edu/cmu/tetrad/search/{ => utils}/TsUtils.java | 6 +++++- .../edu/cmu/tetrad/simulation/GdistanceRandom.java | 2 +- .../main/java/edu/cmu/tetrad/simulation/HsimAutoC.java | 2 +- .../java/edu/cmu/tetrad/simulation/HsimAutoRun.java | 2 +- .../edu/cmu/tetrad/simulation/HsimEvalFromData.java | 2 +- .../edu/cmu/tetrad/simulation/HsimRobustCompare.java | 2 +- .../main/java/edu/cmu/tetrad/simulation/HsimRun.java | 2 +- .../main/java/edu/cmu/tetrad/simulation/HsimUtils.java | 2 +- .../main/java/edu/cmu/tetrad/study/RBExperiments.java | 2 ++ .../edu/cmu/tetrad/study/performance/Comparison.java | 3 ++- .../edu/cmu/tetrad/study/performance/Comparison2.java | 4 +++- .../cmu/tetrad/study/performance/PerformanceTests.java | 3 ++- .../tetrad/study/performance/PerformanceTestsDan.java | 2 +- .../main/java/edu/pitt/csb/mgm/ExploreIndepTests.java | 2 +- .../bayesian/constraint/search/PagSamplingRfci.java | 2 +- .../dbmi/algo/bayesian/constraint/search/RfciBsc.java | 1 + .../edu/cmu/tetrad/test/TestDagInPatternIterator.java | 4 ++-- .../java/edu/cmu/tetrad/test/TestDeltaSextadTest.java | 2 +- .../java/edu/cmu/tetrad/test/TestDeltaTetradTest.java | 2 +- .../java/edu/cmu/tetrad/test/TestEdgeListGraph.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestFci.java | 1 + .../src/test/java/edu/cmu/tetrad/test/TestFges.java | 2 ++ .../src/test/java/edu/cmu/tetrad/test/TestGFci.java | 1 + .../edu/cmu/tetrad/test/TestGeneralResamplingTest.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestGrasp.java | 3 +++ .../src/test/java/edu/cmu/tetrad/test/TestLing.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestMimbuild.java | 3 ++- .../src/test/java/edu/cmu/tetrad/test/TestPc.java | 3 ++- .../src/test/java/edu/cmu/tetrad/test/TestPurify.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java | 4 ++-- 245 files changed, 385 insertions(+), 223 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{BayesUpdaterClassifier.java => ClassifierBayesUpdater.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{MbClassify.java => ClassifierMb.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/AdLeafTree.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/AdTrees.java (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/BayesImParser.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/BpcAlgorithmType.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/BpcTestType.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/ClusterSignificance.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/ClusterUtils.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/DagInCpcagIterator.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/DagIterator.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/DagScorer.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/DagSepsets.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/DagToPag.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/EstimateRank.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/FgesOrienter.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/GraphChange.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/GraphInPag.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/GraphUtilsSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/GraphoidAxioms.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/HasPenaltyDiscount.java (77%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/HungarianAlgorithm.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/IPurify.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/LegalPairs.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/MeekRules.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/NRooks.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/PartialCorrelation.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/PcCommon.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/Purify.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/PurifyScoreBased.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/PurifySextadBased.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/PurifyTetradBased.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/SepsetMap.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/SepsetProducer.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/SepsetsConservative.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/SepsetsGreedy.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/SepsetsPossibleDsep.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/SepsetsSet.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/Sextad.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/Tetrad.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/TetradTest.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/TetradTestContinuous.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/TetradTestDiscrete.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{bpc_utils => utils}/TetradTestPopulation.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/TeyssierScorer.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/TsUtils.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java index 23b62558c6..69e8030be1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.BayesUpdaterClassifier; +import edu.cmu.tetrad.search.ClassifierBayesUpdater; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RocCalculator; @@ -49,7 +49,7 @@ * @author Jossph Ramsey */ public class BayesUpdaterClassifierEditor extends JPanel { - private final BayesUpdaterClassifier classifier; + private final ClassifierBayesUpdater classifier; private JComboBox variableDropdown; private JTabbedPane tabbedPane; private JComboBox categoryDropdown; @@ -57,7 +57,7 @@ public class BayesUpdaterClassifierEditor extends JPanel { private RocPlot rocPlot; private final JMenuItem saveRoc; - private BayesUpdaterClassifierEditor(BayesUpdaterClassifier classifier) { + private BayesUpdaterClassifierEditor(ClassifierBayesUpdater classifier) { if (classifier == null) { throw new NullPointerException(); } @@ -428,7 +428,7 @@ public BayesUpdaterClassifierEditor(BayesUpdaterClassifierWrapper wrapper) { this(wrapper.getClassifier()); } - private BayesUpdaterClassifier getClassifier() { + private ClassifierBayesUpdater getClassifier() { return this.classifier; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java index f6e236f4f6..c5a9afe8a0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor.java @@ -21,8 +21,8 @@ package edu.cmu.tetradapp.editor; -import edu.cmu.tetrad.search.bpc_utils.BpcAlgorithmType; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.utils.BpcAlgorithmType; +import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.DoubleTextField; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java index e47a13cac2..75df6eb948 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersIndTestParamsEditor2.java @@ -21,8 +21,8 @@ package edu.cmu.tetradapp.editor; -import edu.cmu.tetrad.search.bpc_utils.BpcAlgorithmType; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.utils.BpcAlgorithmType; +import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.DoubleTextField; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java index 21486092df..69b1b79fbe 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BuildPureClustersParamsEditor.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.model.DataWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java index 9975f3a14e..d5c354f217 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.workbench.DisplayEdge; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java index 7dfdc200c2..16eed98d26 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.graph.LayoutUtil; -import edu.cmu.tetrad.search.BayesImParser; +import edu.cmu.tetrad.search.utils.BayesImParser; import edu.cmu.tetradapp.model.BayesImWrapper; import nu.xom.Builder; import nu.xom.Document; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java index 44c484ba25..283544d6b1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetradapp.workbench.GraphWorkbench; import javax.swing.*; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java index 34c4944be7..7865a52764 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java @@ -24,8 +24,8 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.DagScorer; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.DagScorer; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.model.ScoredGraphsWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java index 98af33e6e1..74d8ca91b0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetradapp.util.ImageUtils; import edu.cmu.tetradapp.workbench.AbstractWorkbench; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java index bc6149a49d..e4d5f8e42f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.search.BayesUpdaterClassifier; +import edu.cmu.tetrad.search.ClassifierBayesUpdater; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -41,7 +41,7 @@ public class BayesUpdaterClassifierWrapper implements SessionModel { /** * @serial Cannot be null. */ - private final BayesUpdaterClassifier classifier; + private final ClassifierBayesUpdater classifier; /** * @serial Can be null. @@ -64,7 +64,7 @@ public BayesUpdaterClassifierWrapper(BayesImWrapper bayesImWrapper, (DataSet) dataWrapper.getSelectedDataModel(); BayesIm bayesIm = bayesImWrapper.getBayesIm(); - this.classifier = new BayesUpdaterClassifier(bayesIm, dataSet); + this.classifier = new ClassifierBayesUpdater(bayesIm, dataSet); } public BayesUpdaterClassifierWrapper(DirichletBayesImWrapper bayesImWrapper, @@ -81,7 +81,7 @@ public BayesUpdaterClassifierWrapper(DirichletBayesImWrapper bayesImWrapper, (DataSet) dataWrapper.getSelectedDataModel(); BayesIm bayesIm = bayesImWrapper.getDirichletBayesIm(); - this.classifier = new BayesUpdaterClassifier(bayesIm, dataSet); + this.classifier = new ClassifierBayesUpdater(bayesIm, dataSet); } /** @@ -95,7 +95,7 @@ public static PcRunner serializableInstance() { //==============================PUBLIC METHODS=======================// - public BayesUpdaterClassifier getClassifier() { + public ClassifierBayesUpdater getClassifier() { return this.classifier; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index 8d1e20c13b..4777a6947d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -29,10 +29,10 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.BpcTetradPurifyWashdown; import edu.cmu.tetrad.search.WIP.Washdown; -import edu.cmu.tetrad.search.bpc_utils.BpcAlgorithmType; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.utils.BpcAlgorithmType; +import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.Bpc; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.ClusterUtils; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java index 72bea687c1..0c12cddfcd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.graph.SemGraph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java index 620e8e1af2..41f6dc7341 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Dag; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java index beb3eea6a2..d8ab1f1956 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java index 6c6d94eb42..84571c9c9a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -33,7 +33,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java index 5f202aef09..b5760a8e36 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index 094c2aecde..758eff2e93 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java index 419c68c3eb..be85171c66 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index 3aa6f88b19..496e6b4fb6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -37,6 +37,8 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.session.ParamsResettable; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java index 8c04db5159..2e3b47e3f1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java index 8ba18f3280..9776dc82e7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.ClusterUtils; import edu.cmu.tetrad.session.ParamsResettable; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java index 7f22eb7506..39edc3070e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.ClusterUtils; import edu.cmu.tetrad.search.MimUtils; import edu.cmu.tetrad.search.Mimbuild; import edu.cmu.tetrad.sem.ReidentifyVariables; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java index dd4ea40e45..b7ab55863d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.ClusterUtils; import edu.cmu.tetrad.search.MimUtils; import edu.cmu.tetrad.search.MimbuildTrek; import edu.cmu.tetrad.sem.ReidentifyVariables; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java index 7ca91f17c5..c9166b24e0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.MisclassificationUtils; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -34,7 +34,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index 6791dbc338..3b48bebb20 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -27,6 +27,8 @@ import edu.cmu.tetrad.search.WIP.HbmsBeam; import edu.cmu.tetrad.search.WIP.Hbsms; import edu.cmu.tetrad.search.WIP.HbsmsGes; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.*; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java index 7a3c82724d..0da860ea1e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index 0f66696f1e..f5cd84195f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index 2d40e882d6..bf4d687e28 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.bpc_utils.*; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 60323bcbac..78830f633e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.SampleVcpcFast; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index 972fd5da78..cb0a12e464 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.SampleVcpc; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java index d97a512cc3..f6e86f3556 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.DagScorer; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.DagScorer; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index 4413323fd9..aaf22c0bed 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.VcPcFast; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index e86919e961..7597dbcca6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.VcPc; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java index 1619bb6157..5f809f435b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataModelList; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.LogDataUtils; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.model.DataWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java index 53f6ba79d0..303786edee 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataModelList; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.LogDataUtils; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java index d9f3cd0e3c..e1b8c17ffd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model.datamanip; import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.model.DataWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java index b6d5f89f02..612a627151 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model.datamanip; import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.model.DataWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java index ece6b1e2a1..83b136783a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetradapp.util.GraphEditorUtils; import edu.cmu.tetradapp.util.LayoutEditable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java index 80af45b7c6..83b15b1f35 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java @@ -41,7 +41,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java index 8d8a58f76c..d0ac1f420e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java @@ -39,7 +39,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; @@ -53,7 +53,7 @@ import java.util.*; import java.util.concurrent.*; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Nov 14, 2017 12:00:31 PM diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index aeba31eb9c..3c2018dcd5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -9,9 +9,10 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; -import edu.cmu.tetrad.search.bpc_utils.ClusterSignificance; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.BpcTestType; +import edu.cmu.tetrad.search.utils.ClusterSignificance; +import edu.cmu.tetrad.search.utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index 340516b527..a6e06bdc4f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -9,9 +9,10 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; -import edu.cmu.tetrad.search.bpc_utils.ClusterSignificance; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.BpcTestType; +import edu.cmu.tetrad.search.utils.ClusterSignificance; +import edu.cmu.tetrad.search.utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java index 7f4b0ee9ac..5aa8daadd2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java index db70b013bf..4f6a717314 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java index 027be0c29b..89085c0dd6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java @@ -12,6 +12,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 20c843f8e3..57f63944b8 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 @@ -14,6 +14,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 ef9cbb329f..707792dc2b 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 @@ -13,8 +13,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 3500dde048..0f618abe8e 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 index 9d429454c7..fbcb1f81c9 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 @@ -15,7 +15,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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/FgesMeasurement.java index f4d0dcc5bd..20251d8fb2 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/FgesMeasurement.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.RandomUtil; 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/GesMe.java index c90415d5e2..c5543e9a57 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/GesMe.java @@ -11,7 +11,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import org.apache.commons.math3.util.FastMath; 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 index a726be4ad2..0e26f03414 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 @@ -17,7 +17,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 e4c0b57361..a1b31a5684 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 @@ -13,8 +13,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 2d572618ea..d955c190e6 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 @@ -13,8 +13,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 index f73ee815ca..2eba221a64 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 @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 a926692650..23890443eb 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 @@ -15,6 +15,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 1d35427b5a..c0bb9fe26b 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 @@ -16,7 +16,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.BFci; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** 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 index b1f11b716e..8ed2c78ecc 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 @@ -19,7 +19,7 @@ import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Conserative FCI. 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 index 9e606cbd9b..7a3fb57ef7 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * FCI. 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/FciMax.java index 94a4f47fd0..9ba8a0a63e 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/FciMax.java @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * FCI. 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 971552d36d..bd3412336a 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 @@ -15,7 +15,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.GFci; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index 3be6cafc29..fb99f665e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -16,7 +16,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java index f0c3a74d0d..ed4d4fae8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java @@ -18,7 +18,7 @@ import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Jan 29, 2023 3:45:09 PM 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 index 4d97e9e2e4..c55753d48d 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * RFCI. 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/RfciBsc.java index 5b8011ff11..5a1d5c3e51 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/RfciBsc.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Jan 4, 2019 4:32:05 PM 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/SpFci.java index 89a774d692..8e059dc9b3 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/SpFci.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** 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/SvarFci.java index e9be420ab6..d1c62be3eb 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/SvarFci.java @@ -14,7 +14,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.search.TsDagToPag; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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/SvarGfci.java index b868f3baba..99ce557602 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/SvarGfci.java @@ -16,7 +16,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.search.TsDagToPag; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java index fd2db3b134..bbf3e3b1ec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java @@ -10,7 +10,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.TimeLagGraph; -import edu.cmu.tetrad.search.TsUtils; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java index 076fe19ccb..7d8da4d5ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java index 51707d2efe..51d284d940 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.abs; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java index 985495d77f..0753d4f093 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java index e874dd6aef..94a0f3988e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java index a1f86c6b24..82a25ac9be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The bidirected false negatives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java index 422a18b241..539021d9ff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The bidirected edge precision. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java index ec377259de..247e3b4fef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The bidirected edge precision. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java index 147d36f88f..c92a23ce90 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java index 4cba0b3671..5a43fed24a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java index bedc5a2ed2..dacc3beeb7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,7 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.CommonAncestorTruePositiveBidirected.existsCommonAncestor; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java index 99a4c9c19d..6cbc07c106 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java index 2db0964171..77e9523377 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java index 5851a0f693..387e2b3462 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,7 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java index 033597271a..132330a2f6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** * Legal PAG diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java index c210002e47..85a732afb2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java index 7da9ff76db..6b69c840d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** * @author jdramsey diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java index 14f17f744e..07b3ccf344 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** * @author jdramsey diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java index 40ed117429..e79b135134 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java index d1d894d1ea..f264e09ce6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java index c724f833ff..15a984e0f5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java index 87c398e5e8..78efa368db 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; import static edu.cmu.tetrad.graph.GraphUtils.compatible; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java index e99cff0d46..172ef1d852 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java index a995c074dc..de330a8bac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java index 4c99942c4e..7de8c4cea0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java index 0dc0dff6d2..3088f514a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java index a7a16cff0a..5909ef5a1d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import static edu.cmu.tetrad.graph.GraphUtils.compatible; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java index 06bec2427a..290b946da6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java index d909a5ec2f..889a8df1b1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java index c59c614d3e..dd41849879 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** * @author jdramsey diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java index d08d5fd033..0a40737be4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java index 725d422274..537d8a8556 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The adjacency precision. The true positives are the number of adjacencies in both diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java index 51ff800135..e68a6cef9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * The adjacency recall. The true positives are the number of adjacencies in both diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java index 13519abb86..9452761f5a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import org.apache.commons.math3.util.FastMath; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java index d781cf3a57..601086669f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java @@ -5,6 +5,7 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.MillisecondTimes; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index ba24229e6f..55153b698a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge.Property; import edu.cmu.tetrad.search.FciOrient; -import edu.cmu.tetrad.search.GraphUtilsSearch; -import edu.cmu.tetrad.search.SepsetProducer; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.ForkJoinPoolInstance; import edu.cmu.tetrad.util.Parameters; @@ -35,7 +35,7 @@ import java.util.*; import java.util.concurrent.RecursiveTask; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Basic graph utilities. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java index 6a44aa9f02..f337012d58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java @@ -1,7 +1,7 @@ package edu.cmu.tetrad.graph; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SepsetMap; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TaskManager; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 01cff711a5..a65fb5511d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; +import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java index 280417899f..29a79efb5b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java @@ -2,6 +2,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.jetbrains.annotations.NotNull; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index e9b8c902c3..10f4ed0c7d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.bpc_utils.*; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; 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 ede0d1b77f..ae9a342f71 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 @@ -22,6 +22,8 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.SepsetProducer; +import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 80fd6a5df7..0ad4c47dd3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetMap; +import edu.cmu.tetrad.search.utils.SepsetsConservative; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierBayesUpdater.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierBayesUpdater.java index 4fcf361299..5397ae12c8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesUpdaterClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierBayesUpdater.java @@ -45,7 +45,7 @@ * * @author Frank Wimberly based on a specification by Clark Glymour */ -public final class BayesUpdaterClassifier +public final class ClassifierBayesUpdater implements DiscreteClassifier, TetradSerializable { static final long serialVersionUID = 23L; @@ -113,7 +113,7 @@ public final class BayesUpdaterClassifier * The constructor sets the values of the private member variables. */ - public BayesUpdaterClassifier(BayesIm bayesIm, + public ClassifierBayesUpdater(BayesIm bayesIm, DataSet testData) { if (bayesIm == null) { throw new IllegalArgumentException("BayesIm must not be null."); @@ -132,8 +132,8 @@ public BayesUpdaterClassifier(BayesIm bayesIm, /** * Generates a simple exemplar of this class to test serialization. */ - public static BayesUpdaterClassifier serializableInstance() { - return new BayesUpdaterClassifier(MlBayesIm.serializableInstance(), + public static ClassifierBayesUpdater serializableInstance() { + return new ClassifierBayesUpdater(MlBayesIm.serializableInstance(), DataUtils.discreteSerializableInstance()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierMb.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierMb.java index 1b11e61086..ac05ec7a62 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbClassify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierMb.java @@ -47,7 +47,7 @@ * @author Frank Wimberly * @author Joseph Ramsey */ -public class MbClassify implements DiscreteClassifier { +public class ClassifierMb implements DiscreteClassifier { private DataSet train; private DataSet test; private Node target; @@ -61,8 +61,8 @@ public class MbClassify implements DiscreteClassifier { //============================CONSTRUCTOR===========================// - public MbClassify(String trainPath, String testPath, String targetString, - String alphaString, String depthString, String priorString, String maxMissingString) { + public ClassifierMb(String trainPath, String testPath, String targetString, + String alphaString, String depthString, String priorString, String maxMissingString) { try { String s = "MbClassify " + trainPath + " " + @@ -379,7 +379,7 @@ public static void main(String[] args) { String priorString = args[5]; String maxMissingString = args[6]; - new MbClassify(trainPath, testPath, targetString, alphaString, depthString, + new ClassifierMb(trainPath, testPath, targetString, alphaString, depthString, priorString, maxMissingString); } } 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 22a6cedfb5..f850f61ba4 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 @@ -26,6 +26,9 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Triple; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.PcCommon; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java index 2f24fca059..ddd1f3fa07 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.Sextad; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.distribution.ChiSquaredDistribution; import org.apache.commons.math3.linear.SingularMatrixException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java index 302f947ae1..b6f369dde0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.bpc_utils.Tetrad; +import edu.cmu.tetrad.search.utils.Tetrad; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index 4cd3603600..a888fec3b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index 905ad6d610..b648448873 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 6e6926902c..b92e6e102c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.linear.SingularMatrixException; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 37fce5f882..153f75d4b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.SepsetMap; +import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index af17e3760f..c3d35a0d89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.SepsetMap; +import edu.cmu.tetrad.search.utils.SepsetsPossibleDsep; +import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.*; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java index 146e21fb3a..21a550e860 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index b5a180dda2..e40dfa31bb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.DagScorer; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index 314512c057..d6ae95e371 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -22,6 +22,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.HasPenaltyDiscount; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TaskManager; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index 1eba5c51cf..76025e57c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.bpc_utils.*; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 0ef6a35921..2f35ac8287 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -23,8 +23,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; -import edu.cmu.tetrad.search.bpc_utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.BpcTestType; +import edu.cmu.tetrad.search.utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.Sextad; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index f7f3c374a0..d495c49540 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; +import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; 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 2e260193c8..e85873e9ba 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 @@ -3,6 +3,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; 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 669de6d213..a743470f1c 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 @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; +import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java index 61ded6deb4..4f3c82b21a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; +import edu.cmu.tetrad.search.utils.SepsetMap; import java.io.PrintStream; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java index a8e4d87647..2025848f8c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.EstimateRank; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java index dcaee20aaf..27d934100d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index d414334745..da08e69df2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -27,6 +27,8 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.HungarianAlgorithm; +import edu.cmu.tetrad.search.utils.NRooks; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.linear.BlockRealMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java index f9d8420520..1f47ac7cdb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java @@ -29,6 +29,8 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index e0c7e99749..31527762fc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Vector; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java index d6fdfbe74a..9fe800053e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java index 420d71c246..f0d3a6a0ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java @@ -21,8 +21,9 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java index 7c29662c21..bc80cdbac6 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.AdLeafTree; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Vector; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java index 152cb05e78..40f0041e69 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.AdLeafTree; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Vector; import org.apache.commons.math3.util.FastMath; 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 8893d07f0d..8a36ea1014 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 @@ -26,6 +26,9 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.PcCommon; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; 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 897a1171b5..e05fd861a2 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 @@ -26,6 +26,9 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.PcCommon; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index 3c22347530..f1a4cce74a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index aa8d749ced..f5aa484b0d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; 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 index 4c94219d74..94e1a355de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java @@ -2,6 +2,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.jetbrains.annotations.NotNull; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index d870e367ed..be5be4779f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -4,6 +4,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.MeekRules; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java index efdb1e0822..67510338d4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 5e7b1ce885..72b0771e9c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.SepsetMap; +import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java index 478224aa90..d579524fc6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.SublistGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 018c56a8bc..6cb5be356c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; +import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 71d96f2cce..46a5922581 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -26,6 +26,10 @@ import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.SepsetMap; +import edu.cmu.tetrad.search.utils.SepsetProducer; +import edu.cmu.tetrad.search.utils.SepsetsPossibleDsep; +import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 5af5ca8200..5e28211f2c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -26,6 +26,8 @@ import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 7dd43f3202..6b96d8587c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.SepsetProducer; +import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java index 08117e7868..9d795a3b19 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.DagSepsets; +import edu.cmu.tetrad.search.utils.DagToPag; import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index af6044d16f..c39f96e0e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index b237a90929..04d6058f73 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.utils.DagScorer; +import edu.cmu.tetrad.search.utils.HasPenaltyDiscount; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.jetbrains.annotations.NotNull; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java index fba528bf8e..e5c27ae30c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.bpc_utils.*; +import edu.cmu.tetrad.search.utils.*; import java.util.ArrayList; import java.util.HashSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java index 6771c3e3de..6ab9d5b04a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java index ea4565898b..56d565a0f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java index 36cd872bcf..4f337c3178 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.search.GraphScore; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TeyssierScorer; +import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java index d1b267a312..1bd5398ab5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java @@ -29,8 +29,8 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionCovariance; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.MeekRules; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java index 6eae18ea6c..1e5ac3bb5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java @@ -24,9 +24,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DagInCpcagIterator; -import edu.cmu.tetrad.search.MeekRules; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.DagInCpcagIterator; +import edu.cmu.tetrad.search.utils.MeekRules; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.DagScorer; import edu.cmu.tetrad.sem.Scorer; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java index 5347b38199..1e60768ee1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.PartialCorrelation; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.StatUtils; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java index ce17705a61..d525730124 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java @@ -24,9 +24,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphChange; +import edu.cmu.tetrad.search.utils.GraphChange; import edu.cmu.tetrad.search.PossibleDConnectingPath; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java index b01077bcff..b1d324c719 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java @@ -21,7 +21,7 @@ package edu.cmu.tetrad.search.WIP; -import edu.cmu.tetrad.search.GraphChange; +import edu.cmu.tetrad.search.utils.GraphChange; import java.util.ArrayList; import java.util.LinkedList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java index 5fe60781d4..7a7d0031d5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.MeekRules; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Vector; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java index 8040b24ede..0744139ce9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.search.GraphScore; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.TeyssierScorer; +import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.PermutationGenerator; import org.jetbrains.annotations.NotNull; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java index ef22aab022..34601d64e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java @@ -30,6 +30,8 @@ import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java index c2a750df41..2dddf46d64 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java @@ -30,6 +30,8 @@ import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java index e4f9a28c7c..18d97485fb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java @@ -22,7 +22,7 @@ package edu.cmu.tetrad.search.WIP; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.SepsetMap; +import edu.cmu.tetrad.search.utils.SepsetMap; import java.io.IOException; import java.io.ObjectInputStream; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java index 901f84f991..3fea155f48 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java index a78017d2e1..bbbe5feb63 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java index 72f2f85198..7087edb078 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java index d8540a44f8..63e7c4b9f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.FgesOrienter; +import edu.cmu.tetrad.search.utils.FgesOrienter; import edu.cmu.tetrad.search.GraphSearch; import edu.cmu.tetrad.search.IndependenceTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java index 38bda9584e..479032cff8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdLeafTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java index 08c1eab2f9..6db1729b76 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/AdTrees.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesImParser.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesImParser.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java index cc691dc9a2..a295613197 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BayesImParser.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.bayes.BayesPm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcAlgorithmType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcAlgorithmType.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java index e27c7d2bbe..b6c7010de2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcAlgorithmType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcTestType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcTestType.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java index 3297eba8c3..926259f688 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/BpcTestType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterSignificance.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java index 60d74b0559..1f1192b3b3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataModel; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java index 0ef76a88cc..639578bc54 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/ClusterUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Clusters; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java index c864063a28..6880d33403 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagInCpcagIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagIterator.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java index 4026e75ed1..1678fe00c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.EdgeListGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagScorer.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagScorer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagScorer.java index 80e8cbd3c7..df0bbd78f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagScorer.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagSepsets.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagSepsets.java index ea48641124..cc3d749376 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagSepsets.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagToPag.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagToPag.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagToPag.java index 16c5405c7d..efd036ae7e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagToPag.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.FciOrient; import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EstimateRank.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/EstimateRank.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/EstimateRank.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/EstimateRank.java index a704118adc..e15ba445a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EstimateRank.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/EstimateRank.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.util.ProbUtils; import org.apache.commons.math3.linear.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java index 95d3fc4840..d8ef2a68fe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.Vector; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java index 86b4493dad..76f3515038 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphChange.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphInPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphInPag.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java index 02ed14c344..0472b5a903 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphInPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.IndTestDSep; import edu.cmu.tetrad.util.ChoiceGenerator; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java index 2545ed3ea7..20da8a75d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java @@ -18,12 +18,13 @@ // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.graph.GraphUtils.TwoCycleErrors; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphoidAxioms.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphoidAxioms.java index 8c1a2e6c4c..c6708ed356 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphoidAxioms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphoidAxioms.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.IndependenceFacts; @@ -79,7 +79,7 @@ public GraphoidAxioms(Set facts, /** * The main methods. * - * @param args E.g., "java -cp tetrad-gui-7.1.3-SNAPSHOT-launch.jar edu.cmu.tetrad.search.GraphoidAxioms udags5.txt 5" + * @param args E.g., "java -cp tetrad-gui-7.1.3-SNAPSHOT-launch.jar edu.cmu.tetrad.search.utils.GraphoidAxioms udags5.txt 5" * Here, udgas5.txt is a file containing independence models, one per line, where each independence * fast is specified by, e.g., "1:23|56", indicating that 1 is independence of 2 and 3 conditional * on 5 and 6. No more than 9 variables can be handled this way. If you need more, let us know and @@ -116,7 +116,7 @@ public static void main(String... args) { axioms.compositionalGraphoid(); } } catch (IOException e) { - System.out.println("E.g., java -cp tetrad-gui-7.1.3-SNAPSHOT-launch.jar edu.cmu.tetrad.search.GraphoidAxioms udags5.txt 5\n"); + System.out.println("E.g., java -cp tetrad-gui-7.1.3-SNAPSHOT-launch.jar edu.cmu.tetrad.search.utils.GraphoidAxioms udags5.txt 5\n"); throw new RuntimeException(e); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java similarity index 77% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java index 28710c104f..9967fca0e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HasPenaltyDiscount.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java @@ -1,4 +1,6 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; + +import edu.cmu.tetrad.search.Score; /** * Interface for an algorithm can can get/set a value for penalty disoucnt. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HungarianAlgorithm.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HungarianAlgorithm.java index 3923e81f22..1e07dc62d3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HungarianAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HungarianAlgorithm.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import java.util.Arrays; import java.util.LinkedHashSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/IPurify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/IPurify.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java index 0db11ae951..b29c3f64e4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/IPurify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LegalPairs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/LegalPairs.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java index d0ea72f7ab..3c27cc2377 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LegalPairs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java index b2936b3843..92439ea1fb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java @@ -19,13 +19,15 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.ImpliedOrientation; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/NRooks.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/NRooks.java index cce9448c92..db2704add8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/NRooks.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/NRooks.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import java.util.ArrayList; import java.util.Stack; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PartialCorrelation.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PartialCorrelation.java index b5544afd70..fc85f6db7b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PartialCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PartialCorrelation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.CorrelationMatrixOnTheFly; import edu.cmu.tetrad.data.CovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java index a89afd6b1c..0273be4811 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Purify.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java index 3f4c53e037..3abc74ecf4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyScoreBased.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java index 9950025a08..5a0ecaa179 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Clusters; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifySextadBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifySextadBased.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java index 332018045c..6aae8e38ec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifySextadBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java @@ -19,10 +19,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.search.DeltaSextadTest; -import edu.cmu.tetrad.search.Sextad; import edu.cmu.tetrad.util.ChoiceGenerator; import java.text.DecimalFormat; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyTetradBased.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyTetradBased.java index 91bad970f3..fa911dd505 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyTetradBased.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java index 7ca9144ac2..b329f800b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetMap.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java index 16404e4eeb..28b20ee225 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.utils.SepsetMap; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java index c68698bff8..7b08a9a82c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsConservative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java @@ -19,11 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Cpc; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java index 8562d288e0..d15d651311 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsGreedy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java @@ -19,11 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IndTestDSep; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java index 5f58360f61..582d2110e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java @@ -19,12 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.util.SublistGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java index a3b43056da..9ac84d7957 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SepsetsSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java @@ -19,9 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Sextad.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Sextad.java index 0e6812b03f..5b11d238d3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Sextad.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Tetrad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Tetrad.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Tetrad.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Tetrad.java index db8b107f3b..21d9980ebf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/Tetrad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Tetrad.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java index 5912c21200..bfd7f9f342 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java index 525b3aa060..e02fcb7091 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestContinuous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.CovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestDiscrete.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestDiscrete.java index 3b92ba3cf6..20062f7bea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestPopulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestPopulation.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestPopulation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestPopulation.java index 62cfc9e42d..a1726398e6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/bpc_utils/TetradTestPopulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestPopulation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.bpc_utils; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java index 331fe55aa8..8e3a39206f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java @@ -1,7 +1,8 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.*; import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java index 2ee56aceed..e6c707f3d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java @@ -18,13 +18,17 @@ // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.BdeuScore; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.SemBicScore; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java index 12b03a7fbb..906d160124 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import java.util.ArrayList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java index d477e6d974..4a0e067f25 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java index 04fd465e71..2bb6e22491 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.BdeuScore; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java index 92ba699b42..a7e6c2fe1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScore; import edu.cmu.tetrad.sem.SemEstimator; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java index c878870926..e86cec8dc2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.RandomGraph; import edu.cmu.tetrad.search.BdeuScore; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java index 9ed9e3518d..bea6468286 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java index 9d25cff584..06f31befda 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.VerticalIntDataBox; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.TextTable; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java index 763fd9f50e..ed8914bbfa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java @@ -7,6 +7,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.BayesImParser; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.study.performance.Comparison; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index 88492776e0..0059b746d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -5,6 +5,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.ScoreType; import edu.cmu.tetrad.util.MillisecondTimes; @@ -15,7 +16,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Does a comparison of algorithm results across algorithm type, sample sizes, etc. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index f0877af526..34f6a9ee8b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -5,6 +5,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.ScoreType; import edu.cmu.tetrad.util.DataConvertUtils; @@ -25,7 +27,7 @@ import java.util.Collections; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Does a comparison of algorithm results across algorithm type, sample sizes, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 562f069fe8..5fcef0db0a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; @@ -40,7 +41,7 @@ import java.text.NumberFormat; import java.util.*; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Runs some basic performance tests of various algorithm. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java index 31547f7bfa..3f65d24ec4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java @@ -40,7 +40,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; /** * Contains some tests for Dan Malinsky, that might be of interest to others. diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java index 250bf12277..97f01b2738 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.MillisecondTimes; import java.io.File; diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java index b457e5fc0b..28a5afea09 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.search.GraphSearch; import edu.cmu.tetrad.search.IndTestProbabilistic; import edu.cmu.tetrad.search.Rfci; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.GraphSampling; import java.util.LinkedList; diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java index 801f6523b5..7fb8cdce5b 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java @@ -9,6 +9,7 @@ import edu.cmu.tetrad.graph.Edge.Property; import edu.cmu.tetrad.graph.EdgeTypeProbability.EdgeType; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java index 3b7862687c..c4a01d27cb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java @@ -24,8 +24,8 @@ import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DagInCpcagIterator; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.DagInCpcagIterator; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java index b379c0a075..2ef7c02e8f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.DeltaSextadTest; -import edu.cmu.tetrad.search.Sextad; +import edu.cmu.tetrad.search.utils.Sextad; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java index 2787089e55..f8b36bbf37 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.DeltaTetradTest; -import edu.cmu.tetrad.search.bpc_utils.Tetrad; +import edu.cmu.tetrad.search.utils.Tetrad; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Matrix; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java index 2d1e8b2ee2..f319d43414 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java @@ -22,7 +22,7 @@ package edu.cmu.tetrad.test; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import org.junit.Test; import java.util.ArrayList; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java index c9c72f2d9b..b43149fc47 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index 87871fe913..ac36f6a096 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java @@ -38,6 +38,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java index 94f3b340be..438385badc 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java index 4b612823d5..f75c6a57d0 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java @@ -37,7 +37,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index ac66147f57..5ee1154c12 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -50,6 +50,9 @@ import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphoidAxioms; +import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.sem.StandardizedSemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 5d8fc28f37..96d2222107 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -28,7 +28,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.search.LingD; import edu.cmu.tetrad.search.Lingam; -import edu.cmu.tetrad.search.NRooks; +import edu.cmu.tetrad.search.utils.NRooks; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index 2e621bc3d2..bb63a41dad 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -29,8 +29,9 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.bpc_utils.BpcTestType; +import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.Bpc; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java index c867eb366a..3d7c8305a4 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.MillisecondTimes; @@ -39,7 +40,7 @@ import java.util.Comparator; import java.util.List; -import static edu.cmu.tetrad.search.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index 9c165b7260..5a1f70b748 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.bpc_utils.*; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java index 34cb86f677..71f6db59f7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java @@ -7,8 +7,8 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.IndTestProbabilistic; -import edu.cmu.tetrad.search.GraphUtilsSearch; -import edu.cmu.tetrad.search.BayesImParser; +import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.BayesImParser; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; import nu.xom.Builder; From 9b62b9564dfd6a51370f54c35b3eb9f3c586893b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:07:57 -0400 Subject: [PATCH 327/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetradapp/model/BuildPureClustersRunner.java | 2 +- .../main/java/edu/cmu/tetradapp/model/MimBuildRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/GrowShrink.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java | 1 + .../src/main/java/edu/cmu/tetrad/search/mb/Iamb.java | 1 - .../src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java | 1 - .../java/edu/cmu/tetrad/search/{ => mb}/MbSearch.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java | 1 - .../main/java/edu/cmu/tetrad/search/{ => utils}/MaxP.java | 8 +++++--- .../java/edu/cmu/tetrad/search/{ => utils}/MimUtils.java | 2 +- .../edu/cmu/tetrad/search/utils/PurifyScoreBased.java | 1 - .../edu/cmu/tetrad/test/TestMarkovBlanketSearches.java | 1 + .../src/test/java/edu/cmu/tetrad/test/TestMimbuild.java | 1 + 14 files changed, 14 insertions(+), 12 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => mb}/MbSearch.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/MaxP.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/MimUtils.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index 4777a6947d..7d238aa910 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -26,13 +26,13 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.BpcTetradPurifyWashdown; import edu.cmu.tetrad.search.WIP.Washdown; import edu.cmu.tetrad.search.utils.BpcAlgorithmType; import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.Bpc; import edu.cmu.tetrad.search.utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.MimUtils; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java index 39edc3070e..d7726cbd01 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.ClusterUtils; -import edu.cmu.tetrad.search.MimUtils; +import edu.cmu.tetrad.search.utils.MimUtils; import edu.cmu.tetrad.search.Mimbuild; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java index b7ab55863d..019c1bd961 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.ClusterUtils; -import edu.cmu.tetrad.search.MimUtils; +import edu.cmu.tetrad.search.utils.MimUtils; import edu.cmu.tetrad.search.MimbuildTrek; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index dbe270fe76..177b62bb83 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -22,6 +22,7 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.mb.MbSearch; import java.util.LinkedList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index f1a4cce74a..24b88b9a3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.mb.MbSearch; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Iamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Iamb.java index 0ce306753a..f91d0b2b2d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Iamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Iamb.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.MbSearch; import java.util.LinkedList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java index 49d965d792..db3379aa2c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.MbSearch; import java.util.LinkedList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/MbSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/MbSearch.java index 08389c72a6..0216e26cca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/MbSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.mb; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java index fefdf1f423..b5b42a9495 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceResult; import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.MbSearch; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java index 9fe800053e..83afb188cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java @@ -19,12 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.PcCommon; +import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.PcMax; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MimUtils.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MimUtils.java index 2ec82b6fe0..4168502edd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MimUtils.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Clusters; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java index 5a0ecaa179..9dafe0b9d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.data.Clusters; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.MimUtils; import edu.cmu.tetrad.sem.ParamType; import edu.cmu.tetrad.sem.Parameter; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java index 724aac5836..6943f9a1ce 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.mb.MbSearch; import org.junit.Test; import java.util.ArrayList; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index bb63a41dad..dbfdb4f97a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -32,6 +32,7 @@ import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.Bpc; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MimUtils; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; From 523d7304477c8e4cb2ec6f0a42ba919197e2080d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:23:20 -0400 Subject: [PATCH 328/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../editor/BayesUpdaterClassifierEditor.java | 8 ++++---- .../java/edu/cmu/tetradapp/editor/DagEditor.java | 4 ++-- .../edu/cmu/tetradapp/editor/GraphEditor.java | 4 ++-- .../tetradapp/editor/IndependenceFactsEditor.java | 6 +++--- .../cmu/tetradapp/editor/MarkovCheckEditor.java | 6 +++--- .../edu/cmu/tetradapp/editor/SemGraphEditor.java | 4 ++-- .../cmu/tetradapp/editor/TimeLagGraphEditor.java | 4 ++-- .../tetradapp/model/AbstractMBSearchRunner.java | 2 +- .../model/BayesUpdaterClassifierWrapper.java | 10 +++++----- .../java/edu/cmu/tetradapp/model/DagWrapper.java | 4 ++-- .../java/edu/cmu/tetradapp/model/FasRunner.java | 1 + .../java/edu/cmu/tetradapp/model/FciRunner.java | 1 + .../tetradapp/model/GeneralAlgorithmRunner.java | 3 +++ .../tetradapp/model/GraphSelectionWrapper.java | 4 ++-- .../edu/cmu/tetradapp/model/GraphWrapper.java | 4 ++-- .../edu/cmu/tetradapp/model/IndTestChooser.java | 4 ++++ .../edu/cmu/tetradapp/model/IndTestProducer.java | 2 +- .../java/edu/cmu/tetradapp/model/IonRunner.java | 2 +- .../tetradapp/model/MarkovCheckIndTestModel.java | 2 +- .../java/edu/cmu/tetradapp/model/PcRunner.java | 1 + .../cmu/tetradapp/model/SampleVcpcFastRunner.java | 1 + .../edu/cmu/tetradapp/model/SampleVcpcRunner.java | 1 + .../edu/cmu/tetradapp/model/VcpcFastRunner.java | 2 ++ .../java/edu/cmu/tetradapp/model/VcpcRunner.java | 2 ++ .../algcomparison/algorithm/multi/Images.java | 2 ++ .../algorithm/oracle/cpdag/Boss.java | 1 + .../algorithm/oracle/cpdag/Fges.java | 2 +- .../algorithm/oracle/cpdag/FgesMb.java | 2 +- .../algorithm/oracle/cpdag/GesMe.java | 2 +- .../algorithm/oracle/cpdag/Grasp.java | 4 ++-- .../algorithm/oracle/cpdag/PcMb.java | 2 +- .../algcomparison/algorithm/oracle/cpdag/Pcd.java | 2 +- .../algcomparison/algorithm/oracle/cpdag/Sp.java | 1 + .../algorithm/oracle/pag/GraspFci.java | 4 ++-- .../algcomparison/algorithm/pairwise/FaskPw.java | 4 ++-- .../algcomparison/independence/BdeuTest.java | 6 +++--- .../algcomparison/independence/CciTest.java | 6 +++--- .../algcomparison/independence/ChiSquare.java | 4 ++-- .../independence/ConditionalGaussianLRT.java | 4 ++-- .../independence/DSeparationTest.java | 4 ++-- .../independence/DegenerateGaussianLRT.java | 4 ++-- .../independence/DiscreteBicTest.java | 6 +++--- .../algcomparison/independence/FisherZ.java | 4 ++-- .../algcomparison/independence/Gsquare.java | 4 ++-- .../independence/IndependenceWrapper.java | 2 +- .../tetrad/algcomparison/independence/Kci.java | 2 +- .../independence/KimEtAlScoreTests.java | 6 +++--- .../algcomparison/independence/MagSemBicTest.java | 6 +++--- .../algcomparison/independence/Mnlrlrt.java | 4 ++-- .../MultinomialLogisticRegressionWald.java | 3 ++- .../tetrad/algcomparison/independence/Mvplrt.java | 4 ++-- .../algcomparison/independence/PositiveCorr.java | 4 ++-- .../independence/ProbabilisticTest.java | 4 ++-- .../algcomparison/independence/SemBicDTest.java | 4 ++-- .../algcomparison/independence/SemBicTest.java | 6 +++--- .../cmu/tetrad/algcomparison/score/BdeuScore.java | 6 +++--- .../cmu/tetrad/algcomparison/score/CciScore.java | 8 ++++---- .../score/ConditionalGaussianBicScore.java | 4 ++-- .../algcomparison/score/DSeparationScore.java | 4 ++-- .../score/DegenerateGaussianBicScore.java | 4 ++-- .../algcomparison/score/DiscreteBicScore.java | 6 +++--- .../cmu/tetrad/algcomparison/score/EbicScore.java | 2 +- .../tetrad/algcomparison/score/FisherZScore.java | 6 +++--- .../tetrad/algcomparison/score/KimEtAlScores.java | 4 ++-- .../tetrad/algcomparison/score/MNLRBicScore.java | 4 ++-- .../tetrad/algcomparison/score/MVPBicScore.java | 4 ++-- .../algcomparison/score/MagSemBicScore.java | 8 ++++---- .../algcomparison/score/PoissonPriorScore.java | 2 +- .../algcomparison/score/PositiveCorrScore.java | 6 +++--- .../tetrad/algcomparison/score/ScoreWrapper.java | 2 +- .../tetrad/algcomparison/score/SemBicScore.java | 12 ++++++------ .../score/SemBicScoreDeterministic.java | 2 +- .../algcomparison/score/ZhangShenBoundScore.java | 2 +- .../tetrad/algcomparison/statistic/BicDiff.java | 2 +- .../algcomparison/statistic/BicDiffPerRecord.java | 2 +- .../tetrad/algcomparison/statistic/BicEst.java | 2 +- .../tetrad/algcomparison/statistic/BicTrue.java | 2 +- .../edu/cmu/tetrad/bayes/BayesProperties.java | 2 +- .../calibration/DataForCalibrationRfci.java | 2 ++ .../edu/cmu/tetrad/data/IndependenceFacts.java | 2 +- .../src/main/java/edu/cmu/tetrad/graph/Paths.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/BFci.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Bes.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Boss.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Bpc.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Ccd.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Cfci.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Cpc.java | 1 + .../main/java/edu/cmu/tetrad/search/Cstar.java | 7 +++++++ .../java/edu/cmu/tetrad/search/EbicScore.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Fas.java | 1 + .../edu/cmu/tetrad/search/FasDeterministic.java | 2 ++ .../main/java/edu/cmu/tetrad/search/FasLofs.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Fask.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Fci.java | 1 + .../main/java/edu/cmu/tetrad/search/FciMax.java | 1 + .../src/main/java/edu/cmu/tetrad/search/Fges.java | 2 ++ .../main/java/edu/cmu/tetrad/search/FgesMb.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Ftfc.java | 1 + .../src/main/java/edu/cmu/tetrad/search/GFci.java | 2 ++ .../main/java/edu/cmu/tetrad/search/Grasp.java | 3 +++ .../main/java/edu/cmu/tetrad/search/GraspFci.java | 2 ++ .../java/edu/cmu/tetrad/search/GrowShrink.java | 2 +- .../edu/cmu/tetrad/search/GrowShrinkTree.java | 1 + .../edu/cmu/tetrad/search/{mb => }/HitonMb.java | 0 .../cmu/tetrad/search/{mb => }/HitonVariant.java | 0 .../java/edu/cmu/tetrad/search/{mb => }/Iamb.java | 6 +++--- .../edu/cmu/tetrad/search/{mb => }/IambnPc.java | 5 +++-- .../edu/cmu/tetrad/search/{mb => }/InterIamb.java | 6 +++--- .../src/main/java/edu/cmu/tetrad/search/Kci.java | 2 ++ .../src/main/java/edu/cmu/tetrad/search/Kpc.java | 2 ++ .../edu/cmu/tetrad/search/{mb => }/MbSearch.java | 2 +- .../main/java/edu/cmu/tetrad/search/MbUtils.java | 1 + .../main/java/edu/cmu/tetrad/search/Mimbuild.java | 1 + .../java/edu/cmu/tetrad/search/MimbuildTrek.java | 1 + .../java/edu/cmu/tetrad/search/{mb => }/Mmhc.java | 5 ++--- .../java/edu/cmu/tetrad/search/{mb => }/Mmmb.java | 6 +++--- .../src/main/java/edu/cmu/tetrad/search/Pc.java | 1 + .../main/java/edu/cmu/tetrad/search/PcMax.java | 1 + .../src/main/java/edu/cmu/tetrad/search/PcMb.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/Pcd.java | 1 + .../edu/cmu/tetrad/search/PermutationBes.java | 1 + .../edu/cmu/tetrad/search/PermutationSearch.java | 1 + .../edu/cmu/tetrad/search/PoissonPriorScore.java | 2 ++ .../edu/cmu/tetrad/search/PossibleDsepFci.java | 1 + .../edu/cmu/tetrad/search/ResolveSepsets.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Rfci.java | 1 + .../java/edu/cmu/tetrad/search/ShiftSearch.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/Sp.java | 1 + .../main/java/edu/cmu/tetrad/search/SpFci.java | 7 +++++-- .../edu/cmu/tetrad/search/SuborderSearch.java | 1 + .../main/java/edu/cmu/tetrad/search/SvarFci.java | 1 + .../java/edu/cmu/tetrad/search/SvarFciOrient.java | 1 + .../main/java/edu/cmu/tetrad/search/SvarGfci.java | 6 ++++++ .../main/java/edu/cmu/tetrad/search/TsFas.java | 1 + .../main/java/edu/cmu/tetrad/search/TsFges.java | 2 ++ .../java/edu/cmu/tetrad/search/WIP/DMSearch.java | 6 +++--- .../main/java/edu/cmu/tetrad/search/WIP/Dci.java | 1 + .../java/edu/cmu/tetrad/search/WIP/FasDci.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/FasFdr.java | 2 ++ .../java/edu/cmu/tetrad/search/WIP/GraspTol.java | 6 +++--- .../edu/cmu/tetrad/search/WIP/IndTestCramerT.java | 4 ++-- .../WIP/IndTestFisherZGeneralizedInverse.java | 4 ++-- .../WIP/IndTestFisherZPercentIndependent.java | 4 ++-- .../search/WIP/IndTestFisherZRecursive.java | 3 +++ .../search/WIP/IndTestMixedMultipleTTest.java | 4 ++-- .../WIP/IndTestMultinomialLogisticRegression.java | 4 ++-- .../cmu/tetrad/search/WIP/IndTestSepsetDci.java | 4 ++-- .../edu/cmu/tetrad/search/WIP/OtherPermAlgs.java | 6 +++--- .../search/WIP/ProbabilisticMapIndependence.java | 4 ++-- .../cmu/tetrad/search/WIP/ResolveSepsetsDci.java | 6 +++--- .../edu/cmu/tetrad/search/WIP/SampleVcpc.java | 2 ++ .../edu/cmu/tetrad/search/WIP/SampleVcpcFast.java | 2 ++ .../search/WIP/SemBicScoreDeterministic.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/VcFas.java | 2 +- .../main/java/edu/cmu/tetrad/search/WIP/VcPc.java | 1 + .../java/edu/cmu/tetrad/search/WIP/VcPcAlt.java | 1 + .../java/edu/cmu/tetrad/search/WIP/VcPcFast.java | 1 + .../main/java/edu/cmu/tetrad/search/ZsbScore.java | 2 ++ .../ClassifierBayesUpdaterDiscrete.java} | 14 +++++++------- .../ClassifierDiscrete.java} | 4 ++-- .../ClassifierMbDiscrete.java} | 15 ++++++++++----- .../cmu/tetrad/search/{ => score}/BdeScore.java | 3 ++- .../cmu/tetrad/search/{ => score}/BdeuScore.java | 3 ++- .../ConditionalGaussianLikelihood.java | 2 +- .../{ => score}/ConditionalGaussianScore.java | 3 ++- .../{ => score}/DegenerateGaussianScore.java | 3 ++- .../search/{ => score}/DiscreteBicScore.java | 3 ++- .../tetrad/search/{ => score}/DiscreteScore.java | 5 ++--- .../cmu/tetrad/search/{ => score}/GicScores.java | 4 +++- .../cmu/tetrad/search/{ => score}/GraphScore.java | 4 +++- .../tetrad/search/{ => score}/ImagesScore.java | 6 +++++- .../tetrad/search/{ => score}/MagSemBicScore.java | 5 ++++- .../tetrad/search/{ => score}/MnlrLikelihood.java | 2 +- .../cmu/tetrad/search/{ => score}/MnlrScore.java | 2 +- .../tetrad/search/{ => score}/MvpLikelihood.java | 2 +- .../cmu/tetrad/search/{ => score}/MvpScore.java | 2 +- .../edu/cmu/tetrad/search/{ => score}/Score.java | 2 +- .../tetrad/search/{ => score}/ScoredIndTest.java | 3 ++- .../tetrad/search/{ => score}/SemBicScore.java | 2 +- .../tetrad/search/{ => score}/SemBicScorer.java | 2 +- .../tetrad/search/{ => test}/ChiSquareTest.java | 2 +- .../ConditionalCorrelationIndependence.java | 2 +- .../cmu/tetrad/search/{ => test}/GSquareTest.java | 2 +- .../search/{ => test}/IndTestChiSquare.java | 3 ++- .../{ => test}/IndTestConditionalCorrelation.java | 7 ++++--- .../{ => test}/IndTestConditionalGaussianLrt.java | 4 +++- .../cmu/tetrad/search/{ => test}/IndTestDSep.java | 3 ++- .../{ => test}/IndTestDegenerateGaussianLrt.java | 4 +++- .../tetrad/search/{ => test}/IndTestFisherZ.java | 3 ++- .../IndTestFisherZConcatenateResiduals.java | 4 +++- .../{ => test}/IndTestFisherZFisherPValue.java | 4 +++- .../tetrad/search/{ => test}/IndTestGSquare.java | 3 ++- .../cmu/tetrad/search/{ => test}/IndTestHsic.java | 3 ++- .../{ => test}/IndTestIndependenceFacts.java | 5 +++-- .../tetrad/search/{ => test}/IndTestMnlrLr.java | 4 +++- .../tetrad/search/{ => test}/IndTestMulti.java | 4 +++- .../tetrad/search/{ => test}/IndTestMvpLrt.java | 4 +++- .../search/{ => test}/IndTestPositiveCorr.java | 3 ++- .../search/{ => test}/IndTestProbabilistic.java | 3 ++- .../search/{ => test}/IndTestRegression.java | 3 ++- .../tetrad/search/{ => test}/IndTestScore.java | 5 ++++- .../tetrad/search/{ => test}/IndTestTrekSep.java | 2 +- .../search/{ => test}/IndependenceResult.java | 2 +- .../search/{ => test}/IndependenceTest.java | 2 +- .../tetrad/search/utils/ClusterSignificance.java | 2 +- .../search/{ => utils}/DeltaSextadTest.java | 3 +-- .../search/{ => utils}/DeltaTetradTest.java | 2 +- .../edu/cmu/tetrad/search/utils/FgesOrienter.java | 2 ++ .../edu/cmu/tetrad/search/utils/GraphInPag.java | 2 +- .../cmu/tetrad/search/utils/GraphUtilsSearch.java | 1 + .../tetrad/search/utils/HasPenaltyDiscount.java | 2 +- .../java/edu/cmu/tetrad/search/utils/MaxP.java | 4 ++-- .../edu/cmu/tetrad/search/utils/PcCommon.java | 1 + .../tetrad/search/utils/PurifySextadBased.java | 1 - .../tetrad/search/utils/SepsetsConservative.java | 4 ++-- .../cmu/tetrad/search/utils/SepsetsGreedy.java | 6 +++--- .../tetrad/search/utils/SepsetsPossibleDsep.java | 4 ++-- .../edu/cmu/tetrad/search/utils/SepsetsSet.java | 4 ++-- .../tetrad/search/utils/TetradTestContinuous.java | 1 - .../cmu/tetrad/search/utils/TeyssierScorer.java | 3 +++ .../java/edu/cmu/tetrad/search/utils/TsUtils.java | 6 +++--- .../java/edu/cmu/tetrad/simulation/HsimAutoC.java | 2 +- .../edu/cmu/tetrad/simulation/HsimAutoRun.java | 2 +- .../cmu/tetrad/simulation/HsimEvalFromData.java | 2 +- .../cmu/tetrad/simulation/HsimRobustCompare.java | 2 +- .../java/edu/cmu/tetrad/simulation/HsimRun.java | 2 +- .../java/edu/cmu/tetrad/study/RBExperiments.java | 3 +++ .../cmu/tetrad/study/performance/Comparison.java | 6 ++++++ .../cmu/tetrad/study/performance/Comparison2.java | 8 ++++++++ .../study/performance/PerformanceTests.java | 5 +++++ .../study/performance/PerformanceTestsDan.java | 5 +++-- .../IndTestMultinomialLogisticRegressionWald.java | 4 ++-- .../main/java/edu/pitt/csb/mgm/MixedUtils.java | 2 +- .../edu/pitt/csb/stability/SearchWrappers.java | 2 +- .../constraint/search/PagSamplingRfci.java | 2 +- .../algo/bayesian/constraint/search/RfciBsc.java | 2 ++ .../test/ExploreAutisticsNeurotypicals.java | 2 +- .../edu/cmu/tetrad/test/TestAnneAnalysis3.java | 2 +- .../tetrad/test/TestAutisticClassification.java | 4 ++-- .../java/edu/cmu/tetrad/test/TestCheckMarkov.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestCpc.java | 3 +++ .../edu/cmu/tetrad/test/TestDeltaSextadTest.java | 2 +- .../edu/cmu/tetrad/test/TestDeltaTetradTest.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestFas.java | 4 ++-- .../test/java/edu/cmu/tetrad/test/TestFci.java | 4 ++++ .../test/java/edu/cmu/tetrad/test/TestFges.java | 3 +++ .../cmu/tetrad/test/TestFisherZCalibration.java | 6 +++--- .../test/java/edu/cmu/tetrad/test/TestGFci.java | 7 +++++++ .../test/java/edu/cmu/tetrad/test/TestGrasp.java | 9 +++++++-- .../test/TestIndTestFisherGeneralizedInverse.java | 4 ++-- .../edu/cmu/tetrad/test/TestIndTestFisherZ.java | 6 +++--- .../edu/cmu/tetrad/test/TestIndTestGSquare.java | 2 +- .../edu/cmu/tetrad/test/TestIndTestWaldLr.java | 4 ++-- .../edu/cmu/tetrad/test/TestLingamPattern.java | 4 ++-- .../tetrad/test/TestMarkovBlanketSearches.java | 5 ++++- .../src/test/java/edu/cmu/tetrad/test/TestPc.java | 4 ++++ .../test/java/edu/cmu/tetrad/test/TestPcMb.java | 4 ++-- .../java/edu/cmu/tetrad/test/TestPcStableMax.java | 3 +++ .../test/java/edu/cmu/tetrad/test/TestPcd.java | 4 ++-- .../java/edu/cmu/tetrad/test/TestRfciBsc.java | 2 +- .../java/edu/cmu/tetrad/test/TestSearchGraph.java | 3 +++ .../edu/cmu/tetrad/test/TestSimulatedFmri.java | 8 ++++---- 263 files changed, 546 insertions(+), 315 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/HitonMb.java (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/HitonVariant.java (100%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/Iamb.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/IambnPc.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/InterIamb.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/MbSearch.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/Mmhc.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{mb => }/Mmmb.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ClassifierBayesUpdater.java => classify/ClassifierBayesUpdaterDiscrete.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{DiscreteClassifier.java => classify/ClassifierDiscrete.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ClassifierMb.java => classify/ClassifierMbDiscrete.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/BdeScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/BdeuScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/ConditionalGaussianLikelihood.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/ConditionalGaussianScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/DegenerateGaussianScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/DiscreteBicScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/DiscreteScore.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/GicScores.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/GraphScore.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/ImagesScore.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/MagSemBicScore.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/MnlrLikelihood.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/MnlrScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/MvpLikelihood.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/MvpScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/Score.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/ScoredIndTest.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/SemBicScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/SemBicScorer.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/ChiSquareTest.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/ConditionalCorrelationIndependence.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/GSquareTest.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestChiSquare.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestConditionalCorrelation.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestConditionalGaussianLrt.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestDSep.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestDegenerateGaussianLrt.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestFisherZ.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestFisherZConcatenateResiduals.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestFisherZFisherPValue.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestGSquare.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestHsic.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestIndependenceFacts.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestMnlrLr.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestMulti.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestMvpLrt.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestPositiveCorr.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestProbabilistic.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestRegression.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestScore.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndTestTrekSep.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndependenceResult.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/IndependenceTest.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/DeltaSextadTest.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/DeltaTetradTest.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java index 69e8030be1..e8428b5677 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ClassifierBayesUpdater; +import edu.cmu.tetrad.search.classify.ClassifierBayesUpdaterDiscrete; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RocCalculator; @@ -49,7 +49,7 @@ * @author Jossph Ramsey */ public class BayesUpdaterClassifierEditor extends JPanel { - private final ClassifierBayesUpdater classifier; + private final ClassifierBayesUpdaterDiscrete classifier; private JComboBox variableDropdown; private JTabbedPane tabbedPane; private JComboBox categoryDropdown; @@ -57,7 +57,7 @@ public class BayesUpdaterClassifierEditor extends JPanel { private RocPlot rocPlot; private final JMenuItem saveRoc; - private BayesUpdaterClassifierEditor(ClassifierBayesUpdater classifier) { + private BayesUpdaterClassifierEditor(ClassifierBayesUpdaterDiscrete classifier) { if (classifier == null) { throw new NullPointerException(); } @@ -428,7 +428,7 @@ public BayesUpdaterClassifierEditor(BayesUpdaterClassifierWrapper wrapper) { this(wrapper.getClassifier()); } - private ClassifierBayesUpdater getClassifier() { + private ClassifierBayesUpdaterDiscrete getClassifier() { return this.classifier; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java index be9529fd93..2cde3623d4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java @@ -22,8 +22,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.session.DelegatesEditing; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java index cd85dfe02e..d4dd560791 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java @@ -22,8 +22,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java index 1ccfb635d3..184a690d02 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java @@ -22,9 +22,9 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetradapp.model.IndTestModel; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java index 6b44ff1d2d..88c7746b5a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java @@ -26,9 +26,9 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetradapp.model.IndTestProducer; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java index 964d6c7bc7..463b887098 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java @@ -22,8 +22,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.session.DelegatesEditing; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java index 2c3de9113d..7d20d1bb0d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java @@ -22,8 +22,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.model.IndTestProducer; import edu.cmu.tetradapp.model.TimeLagGraphWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java index 51450513b3..22e3b0e355 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java @@ -26,8 +26,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DoubleDataBox; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; +import edu.cmu.tetrad.search.test.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java index e4d5f8e42f..1f91ef2c83 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.search.ClassifierBayesUpdater; +import edu.cmu.tetrad.search.classify.ClassifierBayesUpdaterDiscrete; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -41,7 +41,7 @@ public class BayesUpdaterClassifierWrapper implements SessionModel { /** * @serial Cannot be null. */ - private final ClassifierBayesUpdater classifier; + private final ClassifierBayesUpdaterDiscrete classifier; /** * @serial Can be null. @@ -64,7 +64,7 @@ public BayesUpdaterClassifierWrapper(BayesImWrapper bayesImWrapper, (DataSet) dataWrapper.getSelectedDataModel(); BayesIm bayesIm = bayesImWrapper.getBayesIm(); - this.classifier = new ClassifierBayesUpdater(bayesIm, dataSet); + this.classifier = new ClassifierBayesUpdaterDiscrete(bayesIm, dataSet); } public BayesUpdaterClassifierWrapper(DirichletBayesImWrapper bayesImWrapper, @@ -81,7 +81,7 @@ public BayesUpdaterClassifierWrapper(DirichletBayesImWrapper bayesImWrapper, (DataSet) dataWrapper.getSelectedDataModel(); BayesIm bayesIm = bayesImWrapper.getDirichletBayesIm(); - this.classifier = new ClassifierBayesUpdater(bayesIm, dataSet); + this.classifier = new ClassifierBayesUpdaterDiscrete(bayesIm, dataSet); } /** @@ -95,7 +95,7 @@ public static PcRunner serializableInstance() { //==============================PUBLIC METHODS=======================// - public ClassifierBayesUpdater getClassifier() { + public ClassifierBayesUpdaterDiscrete getClassifier() { return this.classifier; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java index 617d05b8af..378bf2ef59 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java @@ -22,8 +22,8 @@ import edu.cmu.tetrad.data.KnowledgeBoxInput; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.session.SimulationParamsSource; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index 758eff2e93..e2d5491c31 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java index be85171c66..c3eb75b757 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index 496e6b4fb6..93b74c93c6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -37,6 +37,9 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.session.ParamsResettable; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java index f8168a24e6..1172b58a5f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.data.KnowledgeBoxInput; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java index 18d8cc427b..243f4e8683 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java @@ -25,8 +25,8 @@ import edu.cmu.tetrad.calculator.expression.VariableExpression; import edu.cmu.tetrad.data.KnowledgeBoxInput; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; import edu.cmu.tetrad.session.SimulationParamsSource; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index f40f8bfbf8..f34bea7f29 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -27,6 +27,10 @@ import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; import edu.cmu.tetrad.search.WIP.IndTestFisherZPercentIndependent; import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; +import edu.cmu.tetrad.search.score.ImagesScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.IndTestType; import edu.pitt.csb.mgm.IndTestMultinomialLogisticRegressionWald; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java index f74bc1072e..f7c29d0e41 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java @@ -21,7 +21,7 @@ package edu.cmu.tetradapp.model; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; /** * Specifies the methods that all algorithm runners must implement. All diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java index 187b52fcbb..f82b8d2cf1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.WIP.Ion; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java index 61058a962f..8afb122dcd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index f5cd84195f..c63423b678 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 78830f633e..1bc9c09689 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.SampleVcpcFast; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index cb0a12e464..27c2c4a442 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.SampleVcpc; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index aaf22c0bed..0c8a441cd3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.VcPcFast; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 7597dbcca6..f35015551e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -25,6 +25,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.WIP.VcPc; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java index 89085c0dd6..810cd549fd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java @@ -12,6 +12,8 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.ImagesScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 57f63944b8..cea37d9c6c 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 @@ -14,6 +14,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 index fbcb1f81c9..f5d32708c8 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 @@ -14,7 +14,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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/FgesMb.java index b29b073d5d..1a2050b69a 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/FgesMb.java @@ -15,7 +15,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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/GesMe.java index c5543e9a57..c41f0bc5f9 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/GesMe.java @@ -10,7 +10,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 index 0e26f03414..6596f7034c 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 @@ -15,8 +15,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java index 04ba2805a6..fda80906b1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java @@ -15,7 +15,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 index 2eba221a64..1b1398dd81 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 @@ -6,7 +6,7 @@ import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndTestScore; +import edu.cmu.tetrad.search.test.IndTestScore; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; 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 23890443eb..4789e95522 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 @@ -15,6 +15,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index fb99f665e7..03c7eba789 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -14,8 +14,8 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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/FaskPw.java index 33002f1039..f1e1b510a1 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/FaskPw.java @@ -11,8 +11,8 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Fask; -import edu.cmu.tetrad.search.IndTestFisherZ; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java index b2cbc77302..415150d842 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java @@ -5,9 +5,9 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.BdeuScore; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java index 814585b9d2..a1ec54c269 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java @@ -5,9 +5,9 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.ConditionalCorrelationIndependence; -import edu.cmu.tetrad.search.IndTestConditionalCorrelation; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.ConditionalCorrelationIndependence; +import edu.cmu.tetrad.search.test.IndTestConditionalCorrelation; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java index 999e94a288..40b12c72ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java @@ -4,8 +4,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestChiSquare; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java index 9d5083b9fa..a5a016c166 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestConditionalGaussianLrt; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestConditionalGaussianLrt; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java index d0362573ee..7b8626503f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java @@ -4,8 +4,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java index e4ef355271..53a57a41de 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestDegenerateGaussianLrt; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDegenerateGaussianLrt; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java index 031d51310b..fb24b6ea18 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java @@ -5,9 +5,9 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.DiscreteBicScore; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.score.DiscreteBicScore; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java index b8639bb08a..b39c5d5204 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java @@ -6,8 +6,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.IndTestFisherZ; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java index aecb13e7b2..7d8f711ba6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java @@ -4,8 +4,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestGSquare; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestGSquare; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java index d7f0b4f0fc..96cb3c3f2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.algcomparison.utils.HasParameters; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java index ceb39656ea..04c3628d96 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java index 8cc7d44e9a..6dfdf61097 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java @@ -6,9 +6,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.GicScores; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.score.GicScores; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java index b9a2da006b..adda955c8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java @@ -6,9 +6,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.MagSemBicScore; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.score.MagSemBicScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java index fd5cabb8bf..ac54f1c051 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestMnlrLr; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestMnlrLr; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java index 2f55ad8f9d..c1c54021e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java @@ -3,6 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.pitt.csb.mgm.IndTestMultinomialLogisticRegressionWald; @@ -24,7 +25,7 @@ public class MultinomialLogisticRegressionWald implements IndependenceWrapper { static final long serialVersionUID = 23L; @Override - public edu.cmu.tetrad.search.IndependenceTest getTest(DataModel dataSet, Parameters parameters) { + public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { return new IndTestMultinomialLogisticRegressionWald( SimpleDataLoader.getMixedDataSet(dataSet), parameters.getDouble("alpha"), diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java index 3152f3ea03..350c3b17c2 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestMvpLrt; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestMvpLrt; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java index ff9d40aaa5..0feceed029 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java @@ -3,8 +3,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.search.IndTestPositiveCorr; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestPositiveCorr; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ProbabilisticTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ProbabilisticTest.java index 0a4c7392fc..33647960b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ProbabilisticTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ProbabilisticTest.java @@ -4,8 +4,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.IndTestProbabilistic; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestProbabilistic; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java index d2a80d8d0a..582574228d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java @@ -4,8 +4,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java index 4d5344cf76..69885e5772 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java @@ -6,9 +6,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java index dea5e4b86e..51bec2062b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -29,8 +29,8 @@ public class BdeuScore implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.BdeuScore score - = new edu.cmu.tetrad.search.BdeuScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); + edu.cmu.tetrad.search.score.BdeuScore score + = new edu.cmu.tetrad.search.score.BdeuScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setSamplePrior(parameters.getDouble(Params.PRIOR_EQUIVALENT_SAMPLE_SIZE)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); return score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java index 9c100f144f..99f4cd0f32 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java @@ -4,10 +4,10 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ConditionalCorrelationIndependence; -import edu.cmu.tetrad.search.IndTestConditionalCorrelation; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.ScoredIndTest; +import edu.cmu.tetrad.search.test.ConditionalCorrelationIndependence; +import edu.cmu.tetrad.search.test.IndTestConditionalCorrelation; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.ScoredIndTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java index 84b5487bbc..2f903bb135 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ConditionalGaussianScore; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.ConditionalGaussianScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java index c46f9c1aa1..ce699b9109 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java @@ -4,8 +4,8 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphScore; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; 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 a2fe62b423..0215819f67 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 @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.DegenerateGaussianScore; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.DegenerateGaussianScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java index d055a56630..eff6ef5b57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -29,8 +29,8 @@ public class DiscreteBicScore implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.DiscreteBicScore score - = new edu.cmu.tetrad.search.DiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); + edu.cmu.tetrad.search.score.DiscreteBicScore score + = new edu.cmu.tetrad.search.score.DiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); return score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java index 6fffc0fb11..85ef163d38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java index b9334566b9..d5b3e61b81 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java @@ -4,9 +4,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndTestFisherZ; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.ScoredIndTest; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.ScoredIndTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java index bf470c89ca..dc40752047 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java @@ -6,8 +6,8 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GicScores; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.GicScores; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java index 11dfb0cd93..45cd741508 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.MnlrScore; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.MnlrScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; 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 c1f7176952..65a945c942 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 @@ -5,8 +5,8 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.MvpScore; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.MvpScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java index 57832ab580..6389eaab39 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -31,12 +31,12 @@ public class MagSemBicScore implements ScoreWrapper { public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.MagSemBicScore semBicScore; + edu.cmu.tetrad.search.score.MagSemBicScore semBicScore; if (dataSet instanceof DataSet) { - semBicScore = new edu.cmu.tetrad.search.MagSemBicScore((DataSet) this.dataSet); + semBicScore = new edu.cmu.tetrad.search.score.MagSemBicScore((DataSet) this.dataSet); } else if (dataSet instanceof ICovarianceMatrix) { - semBicScore = new edu.cmu.tetrad.search.MagSemBicScore((ICovarianceMatrix) this.dataSet); + semBicScore = new edu.cmu.tetrad.search.score.MagSemBicScore((ICovarianceMatrix) this.dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java index e297ec4db3..373291da1a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java index ae6a0f1654..cc41cc34cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java @@ -4,9 +4,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndTestPositiveCorr; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.ScoredIndTest; +import edu.cmu.tetrad.search.test.IndTestPositiveCorr; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.ScoredIndTest; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java index 60b8a7b29d..c57baa7811 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java index ecf6c1cd65..ab3b7ffd0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -33,12 +33,12 @@ public class SemBicScore implements ScoreWrapper { public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.SemBicScore semBicScore; + edu.cmu.tetrad.search.score.SemBicScore semBicScore; if (dataSet instanceof DataSet) { - semBicScore = new edu.cmu.tetrad.search.SemBicScore((DataSet) this.dataSet); + semBicScore = new edu.cmu.tetrad.search.score.SemBicScore((DataSet) this.dataSet); } else if (dataSet instanceof ICovarianceMatrix) { - semBicScore = new edu.cmu.tetrad.search.SemBicScore((ICovarianceMatrix) this.dataSet); + semBicScore = new edu.cmu.tetrad.search.score.SemBicScore((ICovarianceMatrix) this.dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } @@ -48,10 +48,10 @@ public Score getScore(DataModel dataSet, Parameters parameters) { switch (parameters.getInt(Params.SEM_BIC_RULE)) { case 1: - semBicScore.setRuleType(edu.cmu.tetrad.search.SemBicScore.RuleType.CHICKERING); + semBicScore.setRuleType(edu.cmu.tetrad.search.score.SemBicScore.RuleType.CHICKERING); break; case 2: - semBicScore.setRuleType(edu.cmu.tetrad.search.SemBicScore.RuleType.NANDY); + semBicScore.setRuleType(edu.cmu.tetrad.search.score.SemBicScore.RuleType.NANDY); break; default: throw new IllegalStateException("Expecting 1 or 2: " + parameters.getInt(Params.SEM_BIC_RULE)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java index 25fd795fcd..9ce6ba6f25 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java index c46912dbe9..924b5207d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.ZsbScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java index 7d8da4d5ad..5a9baf7e0f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.SemBicScorer; +import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java index 51d284d940..76dc084ca0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.SemBicScorer; +import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.abs; import static org.apache.commons.math3.util.FastMath.tanh; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java index 0753d4f093..1ce364c1b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.SemBicScorer; +import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java index 94a0f3988e..b8ad971d0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.SemBicScorer; +import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java index 131410ee39..4b4b074a8c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.DiscreteBicScore; +import edu.cmu.tetrad.search.score.DiscreteBicScore; import org.apache.commons.math3.distribution.ChiSquaredDistribution; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java index 601086669f..bdcadbb101 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java @@ -5,6 +5,8 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java index bf946a9a77..f91d22e187 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.util.PermutationGenerator; import edu.cmu.tetrad.util.SublistGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java index f337012d58..77fe65ecbf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java @@ -1,6 +1,6 @@ package edu.cmu.tetrad.graph; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TaskManager; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index a65fb5511d..32ff19e586 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java index 29a79efb5b..e362113925 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java @@ -2,6 +2,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; 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 a0c5c074e1..ad9b733cc8 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 @@ -3,6 +3,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index 10f4ed0c7d..4cf7035832 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndTestGSquare; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; 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 ae9a342f71..70421c6b1c 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 @@ -22,6 +22,7 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 0ad4c47dd3..fa1142a583 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsConservative; 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 f850f61ba4..2ad85619cd 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 @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Triple; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.SepsetMap; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index eeaf488cc5..e2682c710b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -3,6 +3,13 @@ import edu.cmu.tetrad.algcomparison.independence.ChiSquare; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.ConditionalGaussianScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.ScoredIndTest; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.*; import edu.pitt.dbmi.data.reader.Delimiter; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java index 3c00e4a802..de4c9180b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.MagSemBicScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.linear.SingularMatrixException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index a888fec3b6..c7eacd5b9f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index b648448873..5275c7f7ae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java index b3ab159a3c..cdd2da03a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java @@ -25,6 +25,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.MillisecondTimes; import java.util.Collections; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index b92e6e102c..665793b061 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -27,6 +27,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.linear.SingularMatrixException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 153f75d4b6..e9aa5de983 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index c3d35a0d89..a0cdae7f95 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsPossibleDsep; import edu.cmu.tetrad.search.utils.SepsetsSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index e40dfa31bb..b765d7c869 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.DagScorer; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index d6ae95e371..b030296e86 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -22,6 +22,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.DiscreteScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.HasPenaltyDiscount; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 2f35ac8287..137ec4d89c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.utils.ClusterUtils; +import edu.cmu.tetrad.search.utils.DeltaSextadTest; import edu.cmu.tetrad.search.utils.Sextad; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index d495c49540..f656604f66 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; 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 e85873e9ba..04405de70c 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 @@ -3,6 +3,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.NumberFormatUtil; 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 a743470f1c..062f6633df 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 @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index 177b62bb83..d77412eb60 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -22,7 +22,7 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.mb.MbSearch; +import edu.cmu.tetrad.search.test.IndependenceTest; import java.util.LinkedList; import java.util.List; 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 5115eef57a..cc10b48466 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,6 +1,7 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/HitonMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonMb.java similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/HitonMb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonMb.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/HitonVariant.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonVariant.java similarity index 100% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/HitonVariant.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonVariant.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Iamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Iamb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java index f91d0b2b2d..060ffae6ef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Iamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java @@ -19,11 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.mb; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import java.util.LinkedList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/IambnPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/IambnPc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java index 99419bfd73..843359c431 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/IambnPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.mb; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import java.util.LinkedList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java index db3379aa2c..ead1ee9f01 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/InterIamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java @@ -19,11 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.mb; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import java.util.LinkedList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java index 30edba945d..84a9c13e97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java @@ -6,6 +6,8 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java index 27d934100d..b674a5d711 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndTestHsic; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.search.utils.SepsetMap; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/MbSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/MbSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java index 0216e26cca..08389c72a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/MbSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.mb; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java index f0d3a6a0ed..ca85359b76 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java @@ -22,6 +22,7 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 26c2d64098..dd74515f49 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.distribution.ChiSquaredDistribution; import org.apache.commons.math3.optim.InitialGuess; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index 1e60941ebd..e6bf5a8bc0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndTestTrekSep; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.analysis.MultivariateFunction; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmhc.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmhc.java index 63e7c4b9f2..ea52f7b9c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmhc.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.mb; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; @@ -27,8 +27,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.FgesOrienter; -import edu.cmu.tetrad.search.GraphSearch; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import java.util.HashMap; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java index b5b42a9495..5abadfda61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/mb/Mmmb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java @@ -19,11 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.mb; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; 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 8a36ea1014..3089be5978 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 @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.SepsetMap; 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 e05fd861a2..a72621688e 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 @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.SepsetMap; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index 24b88b9a3f..e8d4865dae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.mb.MbSearch; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index f5aa484b0d..6a6ba5e3f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.search.utils.SepsetMap; 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 index 94e1a355de..ee1d47d7f6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java @@ -2,6 +2,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index be5be4779f..6ee98609a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -4,6 +4,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.MeekRules; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java index eda00eb07d..0ac5edd92e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.linear.SingularMatrixException; import org.apache.commons.math3.special.Gamma; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java index 67510338d4..c64e9c4ec4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index 7deb1075bf..09b3ac0447 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 72b0771e9c..14b16707bc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java index d579524fc6..0b7e115af8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java @@ -23,6 +23,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.ImagesScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.SublistGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index d7f14e076a..df7b985d44 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -2,6 +2,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 6cb5be356c..954a2b14b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -24,6 +24,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.MagSemBicScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; @@ -121,8 +124,8 @@ public Graph search() { this.graph = alg.search(); - if (score instanceof edu.cmu.tetrad.search.MagSemBicScore) { - ((edu.cmu.tetrad.search.MagSemBicScore) score).setMag(graph); + if (score instanceof MagSemBicScore) { + ((MagSemBicScore) score).setMag(graph); } Knowledge knowledge2 = new Knowledge(knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index 72fb545e46..801e499027 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -2,6 +2,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; import java.util.List; import java.util.Map; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 46a5922581..e73d57ad2c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsPossibleDsep; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 5e28211f2c..7a823b76d5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 6b96d8587c..84e36e5652 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -23,6 +23,12 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index c39f96e0e2..856d288368 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 04d6058f73..4322f79229 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.score.DiscreteScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.DagScorer; import edu.cmu.tetrad.search.utils.HasPenaltyDiscount; import edu.cmu.tetrad.search.utils.MeekRules; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java index f269fe5111..5bfa34f7e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java @@ -5,9 +5,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.IndTestFisherZ; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.score.SemBicScore; import org.apache.commons.math3.linear.SingularMatrixException; import java.io.File; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java index 6ab9d5b04a..018af7a629 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java index f7b525e5ed..b3fc61fc42 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.ResolveSepsets; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java index 56d565a0f0..bfd51dc309 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java index 4f337c3178..4ab5cc3186 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java @@ -3,9 +3,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphScore; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java index d741bbd905..193f027d15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java @@ -27,8 +27,8 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java index 8be8bab2ae..a95351dad0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java @@ -31,8 +31,8 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java index 258a7480d0..7a333aa7eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java @@ -27,8 +27,8 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java index 1e60768ee1..cf2b96c3b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java @@ -25,6 +25,9 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.PartialCorrelation; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.StatUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java index 27a0d1bb5f..52982d25ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java @@ -29,8 +29,8 @@ import edu.cmu.tetrad.regression.LogisticRegression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java index e91da06f8e..4dd9877ade 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java @@ -29,8 +29,8 @@ import edu.cmu.tetrad.regression.LogisticRegression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java index f05e48845a..0326dba29c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java @@ -25,8 +25,8 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java index 0744139ce9..7fde44f84b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java @@ -5,9 +5,9 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.OrderedPair; -import edu.cmu.tetrad.search.GraphScore; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.PermutationGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java index 517f79ed8d..8c1e2d3f32 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java @@ -26,8 +26,8 @@ import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java index c159c3d153..505c0971b8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java @@ -24,9 +24,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodePair; -import edu.cmu.tetrad.search.IndTestChiSquare; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java index 34601d64e8..e92118a708 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java @@ -30,6 +30,8 @@ import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java index 2dddf46d64..b507d948d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java @@ -30,6 +30,8 @@ import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java index d2e6bcc10b..18f31c1408 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Vector; import org.apache.commons.math3.linear.SingularMatrixException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java index 1e20be1fab..148a0b50a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java index 3fea155f48..18d024f716 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java index bbbe5feb63..e9326ceaec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java index 7087edb078..6507236a9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java index abba6ba321..284ab8db18 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java @@ -26,6 +26,8 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierBayesUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierBayesUpdaterDiscrete.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierBayesUpdater.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierBayesUpdaterDiscrete.java index 5397ae12c8..25670622ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierBayesUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierBayesUpdaterDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.classify; import edu.cmu.tetrad.bayes.*; import edu.cmu.tetrad.data.DataSet; @@ -45,8 +45,8 @@ * * @author Frank Wimberly based on a specification by Clark Glymour */ -public final class ClassifierBayesUpdater - implements DiscreteClassifier, TetradSerializable { +public final class ClassifierBayesUpdaterDiscrete + implements ClassifierDiscrete, TetradSerializable { static final long serialVersionUID = 23L; /** @@ -113,8 +113,8 @@ public final class ClassifierBayesUpdater * The constructor sets the values of the private member variables. */ - public ClassifierBayesUpdater(BayesIm bayesIm, - DataSet testData) { + public ClassifierBayesUpdaterDiscrete(BayesIm bayesIm, + DataSet testData) { if (bayesIm == null) { throw new IllegalArgumentException("BayesIm must not be null."); } @@ -132,8 +132,8 @@ public ClassifierBayesUpdater(BayesIm bayesIm, /** * Generates a simple exemplar of this class to test serialization. */ - public static ClassifierBayesUpdater serializableInstance() { - return new ClassifierBayesUpdater(MlBayesIm.serializableInstance(), + public static ClassifierBayesUpdaterDiscrete serializableInstance() { + return new ClassifierBayesUpdaterDiscrete(MlBayesIm.serializableInstance(), DataUtils.discreteSerializableInstance()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierDiscrete.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierDiscrete.java index 938686c9e8..89a967c8e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.classify; /** @@ -27,7 +27,7 @@ * * @author Frank Wimberly */ -public interface DiscreteClassifier { +public interface ClassifierDiscrete { /** * @return an array with a classification (estimated value) of a target variable for each case in a DataSet. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierMbDiscrete.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierMb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierMbDiscrete.java index ac05ec7a62..8d16856bbd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ClassifierMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierMbDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.classify; import edu.cmu.tetrad.bayes.*; import edu.cmu.tetrad.data.DataSet; @@ -29,6 +29,11 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.MbUtils; +import edu.cmu.tetrad.search.Pc; +import edu.cmu.tetrad.search.PcMb; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.data.reader.Delimiter; @@ -47,7 +52,7 @@ * @author Frank Wimberly * @author Joseph Ramsey */ -public class ClassifierMb implements DiscreteClassifier { +public class ClassifierMbDiscrete implements ClassifierDiscrete { private DataSet train; private DataSet test; private Node target; @@ -61,8 +66,8 @@ public class ClassifierMb implements DiscreteClassifier { //============================CONSTRUCTOR===========================// - public ClassifierMb(String trainPath, String testPath, String targetString, - String alphaString, String depthString, String priorString, String maxMissingString) { + public ClassifierMbDiscrete(String trainPath, String testPath, String targetString, + String alphaString, String depthString, String priorString, String maxMissingString) { try { String s = "MbClassify " + trainPath + " " + @@ -379,7 +384,7 @@ public static void main(String[] args) { String priorString = args[5]; String maxMissingString = args[6]; - new ClassifierMb(trainPath, testPath, targetString, alphaString, depthString, + new ClassifierMbDiscrete(trainPath, testPath, targetString, alphaString, depthString, priorString, maxMissingString); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java index 0d58a14fb0..59cb34cee4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import org.apache.commons.math3.special.Gamma; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java index ceb6b9e982..96aa69c183 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import org.apache.commons.math3.special.Gamma; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java index 0282e73368..b5bbd822cf 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.Discretizer.Discretization; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index 58b2db0143..589e85e1dc 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -19,12 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import org.apache.commons.math3.util.FastMath; import java.text.DecimalFormat; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 2cfaba3aaa..82e2f1b30d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.RealMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java index 4c218a130f..400f5bb29c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import org.apache.commons.math3.util.FastMath; import javax.help.UnsupportedOperationException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java index 0444091bcf..ee1dcec795 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.search.score.Score; /** * Created by IntelliJ IDEA. User: jdramsey Date: Jul 6, 2009 Time: 3:58:26 PM To change this template use File | @@ -29,9 +30,7 @@ */ public interface DiscreteScore extends Score { void setStructurePrior(double structurePrior); - void setSamplePrior(double samplePrior); - DataSet getDataSet(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index b27231b208..e172e9e004 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -19,12 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java index b709a96c43..a01919f513 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; @@ -28,6 +28,8 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.score.Score; import javax.help.UnsupportedOperationException; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java index d512efbe7d..27268b9e8c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java @@ -19,9 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Boss; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.Grasp; +import edu.cmu.tetrad.search.score.Score; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java index a430b83507..dde7fc3f50 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; @@ -27,6 +27,9 @@ import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import javax.help.UnsupportedOperationException; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java index bc80cdbac6..338dd434a2 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import de.bwaldvogel.liblinear.*; import edu.cmu.tetrad.data.ContinuousVariable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java index ccbaafd595..8e9f884c16 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MnlrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java index 40f0041e69..cef376ff09 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java index 4dcba2fcaf..c60f3780ad 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MvpScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Score.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Score.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java index e4df41aed2..2f8059ec3c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Score.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredIndTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredIndTest.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredIndTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredIndTest.java index c81e90ee2e..002deaf06d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredIndTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredIndTest.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; +import edu.cmu.tetrad.search.test.IndependenceTest; import java.util.ArrayList; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index 616dc45b5d..dc4c7f00ff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScorer.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScorer.java index cc6d2a503c..d1b200575b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SemBicScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScorer.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java index f5e2915943..890cfc5a9d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.CellTable; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java index f76838c7e7..224345a5d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ConditionalCorrelationIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java index 07fda86a38..53d2e2ea38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.CellTable; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java index 90a3b2b03b..76299933a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java index cc7b35cacc..2080255c5e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; @@ -251,7 +252,7 @@ public void setKernelMultiplier(double multiplier) { * Sets the kernel to be used. * * @param kernel This kernel. - * @see edu.cmu.tetrad.search.ConditionalCorrelationIndependence.Kernel + * @see ConditionalCorrelationIndependence.Kernel */ public void setKernel(ConditionalCorrelationIndependence.Kernel kernel) { this.cci.setKernelMultiplier(kernel); @@ -261,7 +262,7 @@ public void setKernel(ConditionalCorrelationIndependence.Kernel kernel) { * Sets the basis used for the calculation. * * @param basis This basis. - * @see edu.cmu.tetrad.search.ConditionalCorrelationIndependence.Basis + * @see ConditionalCorrelationIndependence.Basis */ public void setBasis(ConditionalCorrelationIndependence.Basis basis) { this.cci.setBasis(basis); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java index 5a9d3085a7..a717393637 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java @@ -19,13 +19,15 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.ConditionalGaussianLikelihood; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java index 1ab93903b8..521147d6e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.IndependenceFacts; @@ -27,6 +27,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java index e1712ea73f..07bc0c6b97 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestDegenerateGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java @@ -19,11 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java index c4bc95e68a..470eb8f9b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.MatrixUtils; import edu.cmu.tetrad.util.StatUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java index 1e93ce14f8..95afd5a28c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.GraphUtils; @@ -28,6 +28,8 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.StatUtils; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java index 7412bce297..9221d50c5a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; @@ -27,6 +27,8 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestGSquare.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java index f89750b33c..13dcaf68c0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestGSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java @@ -19,11 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestHsic.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java index f644de0097..06501badfc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.cluster.KMeans; import edu.cmu.tetrad.data.BoxDataSet; @@ -27,6 +27,7 @@ import edu.cmu.tetrad.data.DoubleDataBox; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.search.kernel.Kernel; import edu.cmu.tetrad.search.kernel.KernelGaussian; import edu.cmu.tetrad.search.kernel.KernelUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java index 7888f3eb5a..d5e74e231a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java @@ -19,12 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import javax.help.UnsupportedOperationException; @@ -34,7 +35,7 @@ * Checks conditional independence against a list of conditional independence facts, manually entered. * * @author Joseph Ramsey - * @see edu.cmu.tetrad.search.ChiSquareTest + * @see ChiSquareTest */ public final class IndTestIndependenceFacts implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java index b64d7a7530..ee61b2de88 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMnlrLr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java @@ -19,11 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.score.MnlrLikelihood; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.collections4.map.HashedMap; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java index e713012f6a..8ad65b84cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMulti.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java @@ -19,11 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.ResolveSepsets; import edu.cmu.tetrad.util.TetradLogger; import java.util.HashSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java index a330d75c6a..2fd2a72ded 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestMvpLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java @@ -19,11 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.score.MvpLikelihood; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.collections4.map.HashedMap; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java index 5fdd1b4416..477da19df2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestPositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java @@ -19,13 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.StatUtils; import org.apache.commons.math3.distribution.NormalDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestProbabilistic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestProbabilistic.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java index 466e8facc0..e18e013924 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestProbabilistic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java @@ -19,13 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestRegression.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java index 4c33c3b230..fef4b13469 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import cern.colt.matrix.DoubleMatrix1D; import cern.colt.matrix.DoubleMatrix2D; @@ -32,6 +32,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; +import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java index 10db5fb470..2e642cf659 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java @@ -19,13 +19,16 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestTrekSep.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestTrekSep.java index 2025848f8c..a10477d8a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestTrekSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestTrekSep.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceResult.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java index afaa4ed76e..cb02d264d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.graph.IndependenceFact; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java index 6b53555ea6..b11253f900 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndependenceTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataModel; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java index 1f1192b3b3..edd36bdda0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fas; -import edu.cmu.tetrad.search.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java index ddd1f3fa07..1733408be8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaSextadTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java @@ -19,11 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.Sextad; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.distribution.ChiSquaredDistribution; import org.apache.commons.math3.linear.SingularMatrixException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java index b6f369dde0..16a9ed8c1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java index d8ef2a68fe..d0a6f101d4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java @@ -24,6 +24,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.score.DiscreteScore; import edu.cmu.tetrad.util.Vector; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java index 0472b5a903..b084e64038 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java @@ -22,7 +22,7 @@ package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.util.ChoiceGenerator; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java index 20da8a75d0..efbae634e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.graph.GraphUtils.TwoCycleErrors; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java index 9967fca0e2..793e0d7b00 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java @@ -1,6 +1,6 @@ package edu.cmu.tetrad.search.utils; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.score.Score; /** * Interface for an algorithm can can get/set a value for penalty disoucnt. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java index 83afb188cd..a744a9842c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.search.PcMax; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java index 0273be4811..1a32a62c6b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java index 6aae8e38ec..af1bb46715 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java @@ -21,7 +21,6 @@ package edu.cmu.tetrad.search.utils; -import edu.cmu.tetrad.search.DeltaSextadTest; import edu.cmu.tetrad.util.ChoiceGenerator; import java.text.DecimalFormat; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java index 7b08a9a82c..8ff94f512f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java @@ -25,8 +25,8 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Cpc; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java index d15d651311..1edec4238d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java @@ -24,9 +24,9 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java index 582d2110e5..4dfacde63f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java @@ -25,8 +25,8 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.SublistGenerator; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java index 9ac84d7957..15f3e117f1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java @@ -22,8 +22,8 @@ package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java index e02fcb7091..5be4a4ae2f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java @@ -26,7 +26,6 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DeltaTetradTest; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.ProbUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java index 8e3a39206f..9ab4680e91 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java @@ -3,6 +3,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.test.IndependenceTest; import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java index e6c707f3d6..4118b09dad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java @@ -25,10 +25,10 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.BdeuScore; +import edu.cmu.tetrad.search.score.BdeuScore; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java index 4a0e067f25..e8f64572d3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java @@ -10,7 +10,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java index 2bb6e22491..d820704777 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataWriter; import edu.cmu.tetrad.data.VerticalIntDataBox; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.BdeuScore; +import edu.cmu.tetrad.search.score.BdeuScore; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.DataConvertUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java index a7e6c2fe1f..f589a9af37 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.sem.SemEstimator; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java index e86cec8dc2..a0f652f938 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.BdeuScore; +import edu.cmu.tetrad.search.score.BdeuScore; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java index bea6468286..1fb4dc7b6c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; import edu.pitt.dbmi.data.reader.tabular.VerticalDiscreteTabularDatasetFileReader; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java index ed8914bbfa..3d26b52687 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java @@ -7,6 +7,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.utils.BayesImParser; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.study.performance.Comparison; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index 0059b746d0..806249b6c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -5,6 +5,12 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.ScoreType; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index 34f6a9ee8b..2be69f293c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -5,6 +5,14 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 5fcef0db0a..34875a3b1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -26,6 +26,11 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java index 3f65d24ec4..7d438e9852 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java @@ -27,7 +27,8 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.GFci; -import edu.cmu.tetrad.search.IndTestFisherZ; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; @@ -171,7 +172,7 @@ private void testIdaOutputForDan() { ICovarianceMatrix cov = new CovarianceMatrix(data); IndTestFisherZ independenceTestGFci = new IndTestFisherZ(cov, alphaGFci); - edu.cmu.tetrad.search.SemBicScore scoreGfci = new edu.cmu.tetrad.search.SemBicScore(cov); + SemBicScore scoreGfci = new SemBicScore(cov); out6.println("GFCI.PAG_of_the_true_DAG"); diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java index b102d9f8cb..795b6885a2 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java @@ -29,8 +29,8 @@ import edu.cmu.tetrad.regression.LogisticRegression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java index 9b9a64ae28..69061fd1d3 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.WIP.IndTestMixedMultipleTTest; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; import edu.cmu.tetrad.sem.TemplateExpander; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java index 8521b39ecf..da7240a708 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.pitt.csb.mgm.Mgm; import edu.pitt.csb.mgm.MixedUtils; diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java index 28a5afea09..d8bc6ab040 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.GraphSearch; -import edu.cmu.tetrad.search.IndTestProbabilistic; +import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.Rfci; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.GraphSampling; diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java index 7fb8cdce5b..82768430cc 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java @@ -9,6 +9,8 @@ import edu.cmu.tetrad.graph.Edge.Property; import edu.cmu.tetrad.graph.EdgeTypeProbability.EdgeType; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java index bb49639f46..baa5e7c6da 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; import edu.pitt.dbmi.data.reader.Delimiter; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java index 44f5564eda..4b3b50c290 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java @@ -92,7 +92,7 @@ private void run1() { for (int i = 0; i < p; i++) vars.add(new ContinuousVariable("x" + (i + 1))); CovarianceMatrix cov = getCov1(linecor, vars, n); -// edu.cmu.tetrad.search.SemBicScore score = new edu.cmu.tetrad.search.SemBicScore(cov); +// edu.cmu.tetrad.search.score.SemBicScore score = new edu.cmu.tetrad.search.score.SemBicScore(cov); edu.cmu.tetrad.search.PoissonPriorScore score = new edu.cmu.tetrad.search.PoissonPriorScore(cov); // score.setPenaltyDiscount(penalty); score.setLambda(vars.size() / 2.); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java index d07fe275c6..607d856992 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java @@ -28,8 +28,8 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fas; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Parameters; import java.io.File; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java index ec2bf9f717..f33ff7ac98 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.Kci; import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java index fd38ab67e2..aa57dcbc38 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java @@ -26,6 +26,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import org.junit.Test; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java index 2ef7c02e8f..9118a5f6a7 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DeltaSextadTest; +import edu.cmu.tetrad.search.utils.DeltaSextadTest; import edu.cmu.tetrad.search.utils.Sextad; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java index f8b36bbf37..ff22617ecb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DeltaTetradTest; +import edu.cmu.tetrad.search.utils.DeltaTetradTest; import edu.cmu.tetrad.search.utils.Tetrad; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java index 2f5dba2d8d..039ba1a0bd 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java @@ -27,8 +27,8 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; import edu.cmu.tetrad.search.Fas; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.Pc; import org.junit.Test; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java index b43149fc47..7ed6f1af4c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java @@ -27,6 +27,10 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index ac36f6a096..a044e25282 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java @@ -38,6 +38,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.*; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.GeneralizedSemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java index 508a2e648f..51b3ae07a6 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFisherZCalibration.java @@ -8,9 +8,9 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndTestFisherZ; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.sem.StandardizedSemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java index 438385badc..165116502e 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java @@ -26,6 +26,13 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.BdeuScore; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestChiSquare; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 5ee1154c12..43f8ed1ca9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -50,6 +50,11 @@ import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.DegenerateGaussianScore; +import edu.cmu.tetrad.search.score.GraphScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.*; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.GraphoidAxioms; import edu.cmu.tetrad.search.utils.TeyssierScorer; @@ -3037,7 +3042,7 @@ public void testWayne2() { IndTestDSep dsep = new IndTestDSep(graph); - edu.cmu.tetrad.search.SemBicScore score = new edu.cmu.tetrad.search.SemBicScore(dataSet); + SemBicScore score = new SemBicScore(dataSet); score.setPenaltyDiscount(1); // Random permutation over 1...|V|. @@ -3159,7 +3164,7 @@ public void testFgesCondition2() { DataSet d = im.simulateData(1000, false); IndTestFisherZ test = new IndTestFisherZ(d, 0.001); - edu.cmu.tetrad.search.SemBicScore score = new edu.cmu.tetrad.search.SemBicScore(d); + SemBicScore score = new SemBicScore(d); score.setPenaltyDiscount(2); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(score); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java index f1fb5ad2b9..84bb8c5c3c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java @@ -24,8 +24,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java index 74985e06f3..bbadec7f52 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java @@ -26,9 +26,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestFisherZ; -import edu.cmu.tetrad.search.IndependenceResult; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.Matrix; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java index 09c147a4bc..5508231abb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.IndTestGSquare; +import edu.cmu.tetrad.search.test.IndTestGSquare; import edu.pitt.dbmi.data.reader.Delimiter; import org.junit.Test; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java index e081623fef..5749b13a9a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java @@ -27,8 +27,8 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java index 9223366e21..6839bd8293 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java @@ -25,8 +25,8 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.LingamPattern; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.SemBicScore; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java index 6943f9a1ce..91293d597e 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java @@ -24,7 +24,10 @@ import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.mb.MbSearch; +import edu.cmu.tetrad.search.GrowShrink; +import edu.cmu.tetrad.search.MbSearch; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import org.junit.Test; import java.util.ArrayList; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java index 3d7c8305a4..90a6e35536 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java @@ -25,6 +25,10 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java index 545a0cd840..9988628e73 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.MbUtils; import edu.cmu.tetrad.search.PcMb; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java index 8feb59cbf7..540265ee7e 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java @@ -29,6 +29,9 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import org.junit.Test; import static org.junit.Assert.assertEquals; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java index 20aadb9bdf..c57fa38b55 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java @@ -24,8 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.IndTestDSep; -import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.Pcd; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java index 71f6db59f7..e265d430c4 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.IndTestProbabilistic; +import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.BayesImParser; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java index daa8b0b302..62b273fb89 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java @@ -25,6 +25,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.test.IndTestDSep; +import edu.cmu.tetrad.search.test.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java index 8fbbe85451..7523452a20 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java @@ -34,7 +34,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fask; -import edu.cmu.tetrad.search.IndTestFisherZ; +import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; import edu.cmu.tetrad.util.Parameters; @@ -364,7 +364,7 @@ public void testClark() { Fask fask = new Fask(data, - new edu.cmu.tetrad.search.SemBicScore(data), + new edu.cmu.tetrad.search.score.SemBicScore(data), new IndTestFisherZ(data, 0.001)); Graph out = fask.search(); @@ -404,7 +404,7 @@ public void testClark() { DataSet data = im.simulateData(N, false); Fask fask = new Fask(data, - new edu.cmu.tetrad.search.SemBicScore(data), + new edu.cmu.tetrad.search.score.SemBicScore(data), new IndTestFisherZ(data, 0.001)); Graph out = fask.search(); @@ -450,7 +450,7 @@ public void testClark2() { DataSet data = im.simulateData(1000, false); Fask fask = new Fask(data, - new edu.cmu.tetrad.search.SemBicScore(data), + new edu.cmu.tetrad.search.score.SemBicScore(data), new IndTestFisherZ(data, 0.001)); Graph out = fask.search(); From 389a178316fc8d953bce91ba86df85c94bef61e8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:32:58 -0400 Subject: [PATCH 329/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetradapp/model/IGesRunner.java | 2 +- .../java/edu/cmu/tetrad/algcomparison/score/EbicScore.java | 6 +++--- .../search/{PermutationBes.java => BesPermutation.java} | 4 ++-- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java | 5 +++-- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java | 1 + .../main/java/edu/cmu/tetrad/search/PermutationSearch.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java | 1 + .../src/main/java/edu/cmu/tetrad/search/SuborderSearch.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java | 2 +- .../java/edu/cmu/tetrad/search/{ => score}/EbicScore.java | 3 ++- .../java/edu/cmu/tetrad/search/{ => score}/ScoredGraph.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/GrowShrinkTree.java | 2 +- .../tetrad/search/{ => utils}/PossibleDConnectingPath.java | 2 +- .../edu/cmu/tetrad/search/{ => utils}/PossibleDsepFci.java | 2 +- .../java/edu/cmu/tetrad/search/utils/TeyssierScorer.java | 1 - 18 files changed, 23 insertions(+), 15 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{PermutationBes.java => BesPermutation.java} (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/EbicScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/ScoredGraph.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/GrowShrinkTree.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/PossibleDConnectingPath.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/PossibleDsepFci.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java index f141801972..d1498c10e4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.ImpliedOrientation; -import edu.cmu.tetrad.search.ScoredGraph; +import edu.cmu.tetrad.search.score.ScoredGraph; import edu.cmu.tetrad.util.Parameters; import java.beans.PropertyChangeEvent; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java index 85ef163d38..73e0809754 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java @@ -33,12 +33,12 @@ public class EbicScore implements ScoreWrapper { public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.EbicScore score; + edu.cmu.tetrad.search.score.EbicScore score; if (dataSet instanceof DataSet) { - score = new edu.cmu.tetrad.search.EbicScore((DataSet) this.dataSet, parameters.getBoolean(Params.PRECOMPUTE_COVARIANCES)); + score = new edu.cmu.tetrad.search.score.EbicScore((DataSet) this.dataSet, parameters.getBoolean(Params.PRECOMPUTE_COVARIANCES)); } else if (dataSet instanceof ICovarianceMatrix) { - score = new edu.cmu.tetrad.search.EbicScore((ICovarianceMatrix) this.dataSet); + score = new edu.cmu.tetrad.search.score.EbicScore((ICovarianceMatrix) this.dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java index ee1d47d7f6..db8cc64284 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java @@ -25,7 +25,7 @@ * @author bryanandrews * @author josephramsey */ -public class PermutationBes { +public class BesPermutation { private final List variables; private final Score score; private Knowledge knowledge = new Knowledge(); @@ -36,7 +36,7 @@ public class PermutationBes { * * @param score The score that BES (from FGES) will use. */ - public PermutationBes(@NotNull Score score) { + public BesPermutation(@NotNull Score score) { this.score = score; this.variables = score.getVariables(); } 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 ad9b733cc8..bc46ffd049 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 @@ -4,6 +4,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.GrowShrinkTree; import java.util.*; @@ -29,7 +30,7 @@ * @see PermutationSearch */ public class Boss implements SuborderSearch { - private final PermutationBes bes; + private final BesPermutation bes; private final Score score; private final List variables; private final Map> parents; @@ -53,7 +54,7 @@ public Boss(Score score) { this.parents.put(x, new HashSet<>()); } - this.bes = new PermutationBes(score); + this.bes = new BesPermutation(score); this.bes.setVerbose(false); this.numStarts = 1; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index fa1142a583..57824da80e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.PossibleDsepFci; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsConservative; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index b765d7c869..df4260649e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.GraphScore; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.ScoredGraph; import edu.cmu.tetrad.search.utils.DagScorer; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index b030296e86..da9516393d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.DiscreteScore; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.ScoredGraph; import edu.cmu.tetrad.search.utils.HasPenaltyDiscount; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index 6ee98609a1..05bed475c0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -5,6 +5,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.GrowShrinkTree; import edu.cmu.tetrad.search.utils.MeekRules; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index df7b985d44..660b91b2c2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -3,6 +3,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.GrowShrinkTree; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index 801e499027..597aea1c51 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -3,6 +3,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.GrowShrinkTree; import java.util.List; import java.util.Map; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 4322f79229..a59aeb0d57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.DiscreteScore; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.ScoredGraph; import edu.cmu.tetrad.search.utils.DagScorer; import edu.cmu.tetrad.search.utils.HasPenaltyDiscount; import edu.cmu.tetrad.search.utils.MeekRules; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java index d525730124..b4006175ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.utils.GraphChange; -import edu.cmu.tetrad.search.PossibleDConnectingPath; +import edu.cmu.tetrad.search.utils.PossibleDConnectingPath; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java index de4c9180b9..2b3dff5065 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.MagSemBicScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredGraph.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java index 42375c6aa0..affedd6079 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ScoredGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java index cc10b48466..7aabeaa540 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDConnectingPath.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDConnectingPath.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDConnectingPath.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDConnectingPath.java index 7d3a351308..bd8608a788 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDConnectingPath.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDConnectingPath.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDsepFci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDsepFci.java index c64e9c4ec4..67dfa31ff9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PossibleDsepFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDsepFci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java index 9ab4680e91..78117afb10 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.GraphScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; From b00a1a1c3b4e30a286c6165e4eb5a45cc10bb913 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:43:41 -0400 Subject: [PATCH 330/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java | 5 +---- .../main/java/edu/cmu/tetrad/search/FasDeterministic.java | 1 + .../src/main/java/edu/cmu/tetrad/search/FciOrient.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java | 1 + .../src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 1 + .../src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java | 1 + .../src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java | 1 + .../main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java | 2 +- .../tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java | 2 +- .../tetrad/search/WIP/IndTestFisherZPercentIndependent.java | 2 +- .../edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java | 2 +- .../edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java | 2 +- .../search/WIP/IndTestMultinomialLogisticRegression.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java | 2 +- .../cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java | 2 +- .../java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java | 1 + .../main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java | 1 + .../src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java | 1 + .../src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java | 1 + .../java/edu/cmu/tetrad/search/test/IndTestChiSquare.java | 2 +- .../tetrad/search/test/IndTestConditionalCorrelation.java | 2 +- .../tetrad/search/test/IndTestConditionalGaussianLrt.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestDSep.java | 2 +- .../cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java | 2 +- .../search/test/IndTestFisherZConcatenateResiduals.java | 2 +- .../cmu/tetrad/search/test/IndTestFisherZFisherPValue.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestHsic.java | 2 +- .../edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestMulti.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java | 2 +- .../java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java | 2 +- .../edu/cmu/tetrad/search/test/IndTestProbabilistic.java | 2 +- .../java/edu/cmu/tetrad/search/test/IndTestRegression.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestScore.java | 2 +- .../java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java | 1 - .../edu/cmu/tetrad/search/{ => utils}/LogUtilsSearch.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/utils/MaxP.java | 1 - .../src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java | 1 - .../csb/mgm/IndTestMultinomialLogisticRegressionWald.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java | 1 + 52 files changed, 49 insertions(+), 38 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/LogUtilsSearch.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 32ff19e586..6619b25d29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 57824da80e..a2a60c16e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -25,10 +25,7 @@ import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.PossibleDsepFci; -import edu.cmu.tetrad.search.utils.SepsetMap; -import edu.cmu.tetrad.search.utils.SepsetsConservative; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index 5275c7f7ae..4d39199568 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java index 21a550e860..5d97dbe829 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index f656604f66..45f59c253b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; 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 062f6633df..48604cc590 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 @@ -27,6 +27,7 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java index 09b3ac0447..e78d2baeb5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.search.test.IndTestChiSquare; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 954a2b14b4..fca3fed7fe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -28,6 +28,7 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 7a823b76d5..24d2562cc6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -28,6 +28,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 84e36e5652..7e06de178a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -30,6 +30,7 @@ import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java index 856d288368..0e247aa80b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java index bfd51dc309..75ac350eca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java index 193f027d15..3b96935214 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java index a95351dad0..cfaecd12a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java @@ -33,7 +33,7 @@ import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java index 7a333aa7eb..31004d7c67 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.StatUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java index cf2b96c3b5..b1364c62ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java @@ -24,10 +24,10 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.PartialCorrelation; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.StatUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java index 52982d25ad..cb47b85c17 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java index 4dd9877ade..3c3cc9d9ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java index 0326dba29c..54d7a2e10a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java index 8c1e2d3f32..0d50ef3af5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java @@ -28,7 +28,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java index 505c0971b8..6733fd004a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.search.test.IndTestChiSquare; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java index e92118a708..cbeb45d31c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java @@ -33,6 +33,7 @@ import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java index b507d948d6..2ca382853b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java @@ -33,6 +33,7 @@ import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java index 18d024f716..d01befec76 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java index e9326ceaec..1973f3db5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java index 6507236a9a..d500bb7404 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java index 76299933a7..d73365a3de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java index 2080255c5e..59039ee609 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java index a717393637..febfe278d3 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.ConditionalGaussianLikelihood; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java index 521147d6e1..fa4f71939e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java index 07bc0c6b97..38a40639ba 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java index 470eb8f9b2..7be1e9b924 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.MatrixUtils; import edu.cmu.tetrad.util.StatUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java index 95afd5a28c..655a6d058b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.StatUtils; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java index 9221d50c5a..f445595ddc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java @@ -28,7 +28,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java index 13dcaf68c0..b62fedd454 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java index 06501badfc..fbb2c65ba3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.data.DoubleDataBox; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.kernel.Kernel; import edu.cmu.tetrad.search.kernel.KernelGaussian; import edu.cmu.tetrad.search.kernel.KernelUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java index d5e74e231a..23b956df9e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import javax.help.UnsupportedOperationException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java index ee61b2de88..c96b10f2d2 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.score.MnlrLikelihood; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.collections4.map.HashedMap; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java index 8ad65b84cb..07dc7566fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.ResolveSepsets; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java index 2fd2a72ded..f9dcc01cf1 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.score.MvpLikelihood; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.collections4.map.HashedMap; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java index 477da19df2..f4dd52b26b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.StatUtils; import org.apache.commons.math3.distribution.NormalDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java index e18e013924..6ec589f8ae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java index fef4b13469..ee457ba618 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java @@ -32,7 +32,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java index 2e642cf659..d2a0f28667 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java @@ -26,9 +26,9 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java index efbae634e8..f3efd7b6c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.graph.GraphUtils.TwoCycleErrors; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.CombinationGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LogUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/LogUtilsSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java index 5e21b89d9a..671d3a4b5b 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LogUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java index a744a9842c..a1f0510f54 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.search.PcMax; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.SublistGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java index 92439ea1fb..a7c1fddb90 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java @@ -27,7 +27,6 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.ImpliedOrientation; -import edu.cmu.tetrad.search.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java index 795b6885a2..d22814e662 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java index f33ff7ac98..daec6d9cc9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.RandomGraph; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.Kci; -import edu.cmu.tetrad.search.LogUtilsSearch; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.NumberFormatUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 43f8ed1ca9..0b82e1e872 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -49,7 +49,6 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.DegenerateGaussianScore; import edu.cmu.tetrad.search.score.GraphScore; import edu.cmu.tetrad.search.score.Score; @@ -57,6 +56,7 @@ import edu.cmu.tetrad.search.test.*; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.GraphoidAxioms; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.TeyssierScorer; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java index 62b273fb89..77d46638a3 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java @@ -28,6 +28,7 @@ import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.MillisecondTimes; From f9fa022476bcc6c2f4d6930e45da43dc02ed4562 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:48:28 -0400 Subject: [PATCH 331/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/algcomparison/independence/Kci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/{ => test}/Kci.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => test}/Kci.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java index 04c3628d96..03e7a585f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java @@ -32,7 +32,7 @@ public class Kci implements IndependenceWrapper { @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { - edu.cmu.tetrad.search.Kci kci = new edu.cmu.tetrad.search.Kci(SimpleDataLoader.getContinuousDataSet(dataSet), + edu.cmu.tetrad.search.test.Kci kci = new edu.cmu.tetrad.search.test.Kci(SimpleDataLoader.getContinuousDataSet(dataSet), parameters.getDouble(Params.ALPHA)); kci.setApproximate(parameters.getBoolean(Params.KCI_USE_APPROMATION)); kci.setWidthMultiplier(parameters.getDouble(Params.KERNEL_MULTIPLIER)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java index 84a9c13e97..92c245854c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.test; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java index daec6d9cc9..22cd37c1ca 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCheckMarkov.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; import edu.cmu.tetrad.search.test.IndependenceResult; -import edu.cmu.tetrad.search.Kci; +import edu.cmu.tetrad.search.test.Kci; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; From e1be21e4c32ae17f494b6dbb302873ba4d9ff5ae Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:50:03 -0400 Subject: [PATCH 332/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/WIP/LofsOld.java | 673 ------------------ 1 file changed, 673 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java deleted file mode 100644 index 7a7d0031d5..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/LofsOld.java +++ /dev/null @@ -1,673 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search.WIP; - -import cern.colt.list.DoubleArrayList; -import cern.jet.stat.Descriptive; -import edu.cmu.tetrad.data.AndersonDarlingTest; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.regression.Regression; -import edu.cmu.tetrad.regression.RegressionDataset; -import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.utils.MeekRules; -import edu.cmu.tetrad.util.Vector; -import edu.cmu.tetrad.util.*; -import org.apache.commons.math3.util.FastMath; - -import java.util.*; - -/** - * LOFS = Ling Orientation Fixed Structure. - * - * @author Joseph Ramsey - */ -public class LofsOld { - private final Graph cpdag; - private final List dataSets; - private double alpha = 0.05; - private final ArrayList regressions; - private final List variables; - private final boolean strongR2; - private final boolean meekDone; - private final boolean meanCenterResiduals; - - public enum Score { - andersonDarling, skew, kurtosis, fifthMoment, absoluteValue, - exp, expUnstandardized, expUnstandardizedInverted, other, logcosh, entropy - } - - private Score score = Score.andersonDarling; - - //===============================CONSTRUCTOR============================// - - public LofsOld(Graph cpdag, List dataSets, boolean strongR2, boolean meekDone, boolean meanCenterResiduals) - throws IllegalArgumentException { - this.strongR2 = strongR2; - this.meekDone = meekDone; - this.meanCenterResiduals = meanCenterResiduals; - - if (cpdag == null) { - throw new IllegalArgumentException("CPDAG must be specified."); - } - - if (dataSets == null) { - throw new IllegalArgumentException("Data set must be specified."); - } - - this.cpdag = cpdag; - this.dataSets = dataSets; - - this.regressions = new ArrayList<>(); - this.variables = dataSets.get(0).getVariables(); - - for (DataSet dataSet : dataSets) { - this.regressions.add(new RegressionDataset(dataSet)); - } - } - - public Graph orient() { - Graph skeleton = GraphUtils.undirectedGraph(getCpdag()); - Graph graph = new EdgeListGraph(skeleton.getNodes()); - - List nodes = skeleton.getNodes(); -// RandomUtil.shuffle(nodes); - - if (isR1Done()) { - ruleR1(skeleton, graph, nodes); - } - - for (Edge edge : skeleton.getEdges()) { - if (!graph.isAdjacentTo(edge.getNode1(), edge.getNode2())) { - graph.addUndirectedEdge(edge.getNode1(), edge.getNode2()); - } - } - - if (isR2Done()) { - ruleR2(skeleton, graph); - } - - if (isMeekDone()) { - new MeekRules().orientImplied(graph); - } - - return graph; - } - - private void ruleR1(Graph skeleton, Graph graph, List nodes) { - for (Node node : nodes) { - SortedMap scoreReports = new TreeMap<>(); - - List adj = skeleton.getAdjacentNodes(node); - - SublistGenerator gen = new SublistGenerator(adj.size(), adj.size()); - int[] choice; - double maxScore = Double.NEGATIVE_INFINITY; - List parents = null; - - while ((choice = gen.next()) != null) { - List _parents = GraphUtils.asList(choice, adj); - - double score = score(node, _parents); - scoreReports.put(-score, _parents.toString()); - - if (score > maxScore) { - maxScore = score; - parents = _parents; - } - } - - for (double score : scoreReports.keySet()) { - TetradLogger.getInstance().log("score", "For " + node + " parents = " + scoreReports.get(score) + " score = " + -score); - } - - TetradLogger.getInstance().log("score", ""); - - if (parents == null) { - continue; - } - - if (normal(node, parents)) continue; - - for (Node _node : adj) { - if (parents.contains(_node)) { - Edge parentEdge = Edges.directedEdge(_node, node); - - if (!graph.containsEdge(parentEdge)) { - graph.addEdge(parentEdge); - } - } - } - } - } - - private void ruleR2(Graph skeleton, Graph graph) { - Set edgeList1 = skeleton.getEdges(); -// RandomUtil.shuffle(edgeList1); - - for (Edge adj : edgeList1) { - Node x = adj.getNode1(); - Node y = adj.getNode2(); - - if (!isR2Orient2Cycles() && isTwoCycle(graph, x, y)) { - continue; - } - - if (!isTwoCycle(graph, x, y) && !isUndirected(graph, x, y)) { - continue; - } - - resolveOneEdgeMax(graph, x, y, isStrongR2()); - } - } - - private boolean isTwoCycle(Graph graph, Node x, Node y) { - List edges = graph.getEdges(x, y); - return edges.size() == 2; - } - - private boolean isUndirected(Graph graph, Node x, Node y) { - List edges = graph.getEdges(x, y); - if (edges.size() == 1) { - Edge edge = graph.getEdge(x, y); - return Edges.isUndirectedEdge(edge); - } - - return false; - } - - private boolean normal(Node node, List parents) { - if (getAlpha() > .999) { - return false; - } - - return pValue(node, parents) > getAlpha(); - } - - private void resolveOneEdgeMax(Graph graph, Node x, Node y, boolean strong) { - if (RandomUtil.getInstance().nextDouble() > 0.5) { - Node temp = x; - x = y; - y = temp; - } - - TetradLogger.getInstance().log("info", "\nEDGE " + x + " --- " + y); - - SortedMap scoreReports = new TreeMap<>(); - - List neighborsx = graph.getAdjacentNodes(x); - neighborsx.remove(y); - - double max = Double.NEGATIVE_INFINITY; - boolean left = false; - boolean right = false; - - SublistGenerator genx = new SublistGenerator(neighborsx.size(), neighborsx.size()); - int[] choicex; - - while ((choicex = genx.next()) != null) { - List condxMinus = GraphUtils.asList(choicex, neighborsx); - - List condxPlus = new ArrayList<>(condxMinus); - condxPlus.add(y); - - double xPlus = score(x, condxPlus); - double xMinus = score(x, condxMinus); - - List neighborsy = graph.getAdjacentNodes(y); - neighborsy.remove(x); - - SublistGenerator geny = new SublistGenerator(neighborsy.size(), neighborsy.size()); - int[] choicey; - - while ((choicey = geny.next()) != null) { - List condyMinus = GraphUtils.asList(choicey, neighborsy); - - List condyPlus = new ArrayList<>(condyMinus); - condyPlus.add(x); - - double yPlus = score(y, condyPlus); - double yMinus = score(y, condyMinus); - - // Checking them all at once is expensive but avoids lexical ordering problems in the algorithm. - if (normal(y, condyPlus) || normal(x, condxMinus) || normal(x, condxPlus) || normal(y, condyMinus)) { - continue; - } - - final double delta = 0.0; - - if (strong) { - if (yPlus <= xPlus + delta && xMinus <= yMinus + delta) { - double score = combinedScore(xPlus, yMinus); - - if (yPlus <= yMinus + delta && xMinus <= xPlus + delta) { - String s = "\nStrong " + y + "->" + x + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = true; - right = false; - } - } else { - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } else if (xPlus <= yPlus + delta && yMinus <= xMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - if (yMinus <= yPlus + delta && xPlus <= xMinus + delta) { - String s = "\nStrong " + x + "->" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = false; - right = true; - } - } else { - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } else if (yPlus <= xPlus + delta && yMinus <= xMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } else if (xPlus <= yPlus + delta && xMinus <= yMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } else { - if (yPlus <= xPlus + delta && xMinus <= yMinus + delta) { - double score = combinedScore(xPlus, yMinus); - - String s = "\nWeak " + y + "->" + x + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = true; - right = false; - } - } else if (xPlus <= yPlus + delta && yMinus <= xMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nWeak " + x + "->" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - - if (score > max) { - max = score; - left = false; - right = true; - } - } else if (yPlus <= xPlus + delta && yMinus <= xMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } else if (xPlus <= yPlus + delta && xMinus <= yMinus + delta) { - double score = combinedScore(yPlus, xMinus); - - String s = "\nNo directed edge " + x + "--" + y + " " + score + - "\n Parents(" + x + ") = " + condxMinus + - "\n Parents(" + y + ") = " + condyMinus; - - scoreReports.put(-score, s); - } - } - } - } - - for (double score : scoreReports.keySet()) { - TetradLogger.getInstance().log("info", scoreReports.get(score)); - } - - graph.removeEdges(x, y); - - if (left) { - graph.addDirectedEdge(y, x); - } - - if (right) { - graph.addDirectedEdge(x, y); - } - - if (!graph.isAdjacentTo(x, y)) { - graph.addUndirectedEdge(x, y); - } - } - - private double combinedScore(double score1, double score2) { - return score1 + score2; - } - - private double score(Node y, List parents) { - if (this.score == Score.andersonDarling) { - return andersonDarlingPASquareStar(y, parents); - } else if (this.score == Score.kurtosis) { - return FastMath.abs(StatUtils.kurtosis(residual(y, parents))); - } else if (this.score == Score.skew) { - return FastMath.abs(StatUtils.skewness(residual(y, parents))); - } else if (this.score == Score.fifthMoment) { - return FastMath.abs(StatUtils.standardizedFifthMoment(residual(y, parents))); - } else if (this.score == Score.absoluteValue) { - return localScoreA(y, parents); - } - - throw new IllegalStateException(); - } - - //=============================PRIVATE METHODS=========================// - - private double localScoreA(Node node, List parents) { - double score = 0.0; - - List _residuals = new ArrayList<>(); - - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); - - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); - } - - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); - - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { - continue DATASET; - } - } - - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); - - double mean = Descriptive.mean(_residualsSingleDataset); - double std = Descriptive.standardDeviation(Descriptive.variance(_residualsSingleDataset.size(), - Descriptive.sum(_residualsSingleDataset), Descriptive.sumOfSquares(_residualsSingleDataset))); - - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean) / std); - } - - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); - } - } - - double[] _f = new double[_residuals.size()]; - - - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); - } - - DoubleArrayList f = new DoubleArrayList(_f); - - for (int k = 0; k < _residuals.size(); k++) { - f.set(k, FastMath.abs(f.get(k))); - } - - double _mean = Descriptive.mean(f); - double diff = _mean - FastMath.sqrt(2.0 / FastMath.PI); - score += diff * diff; - - return score; - } - - private double andersonDarlingPASquareStar(Node node, List parents) { - List _residuals = new ArrayList<>(); - - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); - - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); - } - - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); - - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { - continue DATASET; - } - } - - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); - - double mean = Descriptive.mean(_residualsSingleDataset); - - // By centering the individual residual columns, all moments of the mixture become weighted - // averages of the momentsof the individual columns. http://en.wikipedia.org/wiki/Mixture_ - // distribution#Finite_and_countable_mixtures - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - if (isMeanCenterResiduals()) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); - } - } - - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); - } - } - - double[] _f = new double[_residuals.size()]; - - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); - } - - return new AndersonDarlingTest(_f).getASquaredStar(); - } - - private double pValue(Node node, List parents) { - List _residuals = new ArrayList<>(); - - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); - - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); - } - - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); - - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { - continue DATASET; - } - } - - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); - - double mean = Descriptive.mean(_residualsSingleDataset); - - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - if (isMeanCenterResiduals()) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); - } - } - - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); - } - } - - double[] _f = new double[_residuals.size()]; - - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); - } - - return new AndersonDarlingTest(_f).getP(); - } - - private double[] residual(Node node, List parents) { - List _residuals = new ArrayList<>(); - - Node target = getVariable(this.variables, node.getName()); - List regressors = new ArrayList<>(); - - for (Node _regressor : parents) { - Node variable = getVariable(this.variables, _regressor.getName()); - regressors.add(variable); - } - - DATASET: - for (int m = 0; m < this.dataSets.size(); m++) { - RegressionResult result = this.regressions.get(m).regress(target, regressors); - Vector residualsSingleDataset = result.getResiduals(); - - for (int h = 0; h < residualsSingleDataset.size(); h++) { - if (Double.isNaN(residualsSingleDataset.get(h))) { - continue DATASET; - } - } - - DoubleArrayList _residualsSingleDataset = new DoubleArrayList(residualsSingleDataset.toArray()); - - double mean = Descriptive.mean(_residualsSingleDataset); - - for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) { - _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean)); - } - - for (int k = 0; k < _residualsSingleDataset.size(); k++) { - _residuals.add(_residualsSingleDataset.get(k)); - } - } - - double[] _f = new double[_residuals.size()]; - - for (int k = 0; k < _residuals.size(); k++) { - _f[k] = _residuals.get(k); - } - - return _f; - } - - public double getAlpha() { - return this.alpha; - } - - public void setAlpha(double alpha) { - if (alpha < 0.0 || alpha > 1.0) { - throw new IllegalArgumentException("Alpha is in range [0, 1]"); - } - - this.alpha = alpha; - } - - private Graph getCpdag() { - return this.cpdag; - } - - private Node getVariable(List variables, String name) { - for (Node node : variables) { - if (name.equals(node.getName())) { - return node; - } - } - - return null; - } - - public boolean isR1Done() { - return true; - } - - public boolean isR2Done() { - return true; - } - - public boolean isMeekDone() { - return this.meekDone; - } - - public boolean isStrongR2() { - return this.strongR2; - } - - public boolean isR2Orient2Cycles() { - return true; - } - - public Score getScore() { - return this.score; - } - - public void setScore(Score score) { - if (score == null) { - throw new NullPointerException(); - } - - this.score = score; - } - - public boolean isMeanCenterResiduals() { - return this.meanCenterResiduals; - } - -} - - From 96ae8e2278d30f39841fc830bf27a647213e0cb3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:50:56 -0400 Subject: [PATCH 333/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetradapp/model/AbstractMBSearchRunner.java | 2 +- .../edu/cmu/tetradapp/model/BuildPureClustersRunner.java | 4 ++-- .../main/java/edu/cmu/tetradapp/model/IndTestChooser.java | 6 +++--- .../src/main/java/edu/cmu/tetradapp/model/IonRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/PValueImproverWrapper.java | 6 +++--- .../java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java | 2 +- .../main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java | 2 +- .../main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java | 2 +- .../edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java | 2 +- .../tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java | 2 +- .../cmu/tetrad/algcomparison/algorithm/other/Glasso.java | 4 ++-- .../cmu/tetrad/algcomparison/independence/SemBicDTest.java | 2 +- .../algcomparison/score/SemBicScoreDeterministic.java | 4 ++-- .../src/main/java/edu/cmu/tetrad/search/WIP/README.txt | 2 -- .../{WIP => work_in_progress}/BpcTetradPurifyWashdown.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/DMSearch.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/Dci.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/FasDci.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/FasFdr.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/Glasso.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/GraspTol.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/HbmsBeam.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/Hbsms.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/HbsmsGes.java | 2 +- .../search/{WIP => work_in_progress}/IndTestCramerT.java | 2 +- .../IndTestFisherZGeneralizedInverse.java | 2 +- .../IndTestFisherZPercentIndependent.java | 2 +- .../{WIP => work_in_progress}/IndTestFisherZRecursive.java | 2 +- .../IndTestMixedMultipleTTest.java | 2 +- .../IndTestMultinomialLogisticRegression.java | 2 +- .../search/{WIP => work_in_progress}/IndTestSepsetDci.java | 2 +- .../{WIP => work_in_progress}/InverseCorrelation.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/Ion.java | 2 +- .../search/{WIP => work_in_progress}/IonHittingSet.java | 2 +- .../search/{WIP => work_in_progress}/OtherPermAlgs.java | 2 +- .../ProbabilisticMapIndependence.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/README.txt | 2 ++ .../search/{WIP => work_in_progress}/ResolveSepsetsDci.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/SampleVcpc.java | 2 +- .../search/{WIP => work_in_progress}/SampleVcpcFast.java | 2 +- .../{WIP => work_in_progress}/SemBicScoreDeterministic.java | 2 +- .../search/{WIP => work_in_progress}/SepsetMapDci.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/Sextad.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/VcFas.java | 2 +- .../cmu/tetrad/search/{WIP => work_in_progress}/VcPc.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/VcPcAlt.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/VcPcFast.java | 2 +- .../tetrad/search/{WIP => work_in_progress}/Washdown.java | 2 +- .../src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java | 2 +- tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java | 2 +- .../main/java/edu/pitt/csb/stability/SearchWrappers.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java | 2 +- .../tetrad/test/TestIndTestFisherGeneralizedInverse.java | 2 +- 54 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/BpcTetradPurifyWashdown.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/DMSearch.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/Dci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/FasDci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/FasFdr.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/Glasso.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/GraspTol.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/HbmsBeam.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/Hbsms.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/HbsmsGes.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IndTestCramerT.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IndTestFisherZGeneralizedInverse.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IndTestFisherZPercentIndependent.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IndTestFisherZRecursive.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IndTestMixedMultipleTTest.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IndTestMultinomialLogisticRegression.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IndTestSepsetDci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/InverseCorrelation.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/Ion.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/IonHittingSet.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/OtherPermAlgs.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/ProbabilisticMapIndependence.java (99%) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/README.txt rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/ResolveSepsetsDci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/SampleVcpc.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/SampleVcpcFast.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/SemBicScoreDeterministic.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/SepsetMapDci.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/Sextad.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/VcFas.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/VcPc.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/VcPcAlt.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/VcPcFast.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{WIP => work_in_progress}/Washdown.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java index 22e3b0e355..203ea949a0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DoubleDataBox; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; +import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZGeneralizedInverse; import edu.cmu.tetrad.search.test.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetradapp.util.IndTestType; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index 7d238aa910..d3c35a5c6e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -26,8 +26,8 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.WIP.BpcTetradPurifyWashdown; -import edu.cmu.tetrad.search.WIP.Washdown; +import edu.cmu.tetrad.search.work_in_progress.BpcTetradPurifyWashdown; +import edu.cmu.tetrad.search.work_in_progress.Washdown; import edu.cmu.tetrad.search.utils.BpcAlgorithmType; import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.Bpc; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index f34bea7f29..cd9ae41596 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -24,9 +24,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; -import edu.cmu.tetrad.search.WIP.IndTestFisherZPercentIndependent; -import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; +import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZGeneralizedInverse; +import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZPercentIndependent; +import edu.cmu.tetrad.search.work_in_progress.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.search.score.ImagesScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java index f82b8d2cf1..1d07690e5e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.WIP.Ion; +import edu.cmu.tetrad.search.work_in_progress.Ion; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index 3b48bebb20..c4201d1e1a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -24,9 +24,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.WIP.HbmsBeam; -import edu.cmu.tetrad.search.WIP.Hbsms; -import edu.cmu.tetrad.search.WIP.HbsmsGes; +import edu.cmu.tetrad.search.work_in_progress.HbmsBeam; +import edu.cmu.tetrad.search.work_in_progress.Hbsms; +import edu.cmu.tetrad.search.work_in_progress.HbsmsGes; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 1bc9c09689..5a0687c991 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.WIP.SampleVcpcFast; +import edu.cmu.tetrad.search.work_in_progress.SampleVcpcFast; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index 27c2c4a442..2cee04d8a1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.WIP.SampleVcpc; +import edu.cmu.tetrad.search.work_in_progress.SampleVcpc; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index 0c8a441cd3..8b668817db 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.WIP.VcPcFast; +import edu.cmu.tetrad.search.work_in_progress.VcPcFast; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index f35015551e..8f8dacd439 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.WIP.VcPc; +import edu.cmu.tetrad.search.work_in_progress.VcPc; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java index 4adb4c950d..fc7e6cccb1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Ccd; -import edu.cmu.tetrad.search.WIP.IndTestCramerT; +import edu.cmu.tetrad.search.work_in_progress.IndTestCramerT; import edu.cmu.tetrad.search.Pc; import edu.pitt.dbmi.data.reader.Delimiter; 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 index 1b1398dd81..1de37e332f 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 @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.test.IndTestScore; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; +import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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 index 5ada536be8..1b8374abcb 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 @@ -50,7 +50,7 @@ public Graph search(DataModel ds, Parameters parameters) { Matrix cov = new Matrix(SimpleDataLoader.getContinuousDataSet(ds) .getCovarianceMatrix().toArray()); - edu.cmu.tetrad.search.WIP.Glasso glasso = new edu.cmu.tetrad.search.WIP.Glasso(cov); + edu.cmu.tetrad.search.work_in_progress.Glasso glasso = new edu.cmu.tetrad.search.work_in_progress.Glasso(cov); glasso.setMaxit(parameters.getInt(Params.MAXIT)); glasso.setIa(parameters.getBoolean(Params.IA)); glasso.setIs(parameters.getBoolean(Params.IS)); @@ -59,7 +59,7 @@ public Graph search(DataModel ds, Parameters parameters) { glasso.setThr(parameters.getDouble(Params.THR)); glasso.setRhoAllEqual(1.0); - edu.cmu.tetrad.search.WIP.Glasso.Result result = glasso.search(); + edu.cmu.tetrad.search.work_in_progress.Glasso.Result result = glasso.search(); Matrix wwi = new Matrix(result.getWwi().toArray()); List variables = ds.getVariables(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java index 582574228d..a26ae3bf24 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.search.test.IndTestScore; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic; +import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java index 9ce6ba6f25..56061fb5e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java @@ -28,8 +28,8 @@ public class SemBicScoreDeterministic implements ScoreWrapper { @Override public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic semBicScore - = new edu.cmu.tetrad.search.WIP.SemBicScoreDeterministic(SimpleDataLoader.getCovarianceMatrix(dataSet)); + edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic semBicScore + = new edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic(SimpleDataLoader.getCovarianceMatrix(dataSet)); semBicScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount")); semBicScore.setDeterminismThreshold(parameters.getDouble("determinismThreshold")); return semBicScore; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt deleted file mode 100644 index e7e873c6aa..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -These classes are put here in the "Work In Progress" (WIP) directory because -they're either old (but not disposable) or require more work. \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java index e5c27ae30c..34ae687a57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java index 5bfa34f7e7..2b9bbe6e2e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/DMSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/DMSearch.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java index 018af7a629..a8bd0e0840 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java index b3fc61fc42..c2124884f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java index 75ac350eca..f206bc8fd2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Glasso.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java index f7876f91a3..92b0881135 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Vector; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java index 4ab5cc3186..aed4ba3ec3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/GraspTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraspTol.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java index 1bd5398ab5..2334500bec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Hbsms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Hbsms.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java index da6c9152d8..55f2bd655d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Hbsms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Hbsms.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java index 1e5ac3bb5f..bc02a2b7df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java index 3b96935214..22afbbb911 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java index cfaecd12a2..c00d05d9a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import cern.colt.matrix.DoubleMatrix1D; import cern.colt.matrix.DoubleMatrix2D; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java index 31004d7c67..a5223e6617 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java index b1364c62ed..205302c079 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMixedMultipleTTest.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMixedMultipleTTest.java index cb47b85c17..86a97338ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMixedMultipleTTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMixedMultipleTTest.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java index 3c3cc9d9ee..124e9bb80f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestMultinomialLogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestSepsetDci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestSepsetDci.java index 54d7a2e10a..2cc1c42579 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IndTestSepsetDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestSepsetDci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/InverseCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/InverseCorrelation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java index db31ec28da..ed9cc40ae2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/InverseCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java index b4006175ca..e15cf931a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IonHittingSet.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IonHittingSet.java index b1d324c719..b4aa1faedf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/IonHittingSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IonHittingSet.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.search.utils.GraphChange; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java index 7fde44f84b..a458c711ce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/OtherPermAlgs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/OtherPermAlgs.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java index 0d50ef3af5..3cccae99c5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ProbabilisticMapIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/README.txt b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/README.txt new file mode 100644 index 0000000000..429e929595 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/README.txt @@ -0,0 +1,2 @@ +These classes are put here in the "Work In Progress" directory because +they're either old (but not disposable) or require more work. \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ResolveSepsetsDci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ResolveSepsetsDci.java index 6733fd004a..3f07519ef5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/ResolveSepsetsDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ResolveSepsetsDci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java index cbeb45d31c..3a1b97f90f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java index 2ca382853b..61d3c76f11 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java index 18f31c1408..f6dc59f32b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java index 18d97485fb..f894c0ca16 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/SepsetMapDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.SepsetMap; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Sextad.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java index 7faae81903..876fa07f28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java index 148a0b50a0..fc57fcb448 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java index d01befec76..297259933c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.data.Knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java index 1973f3db5f..5af570e467 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java index d500bb7404..df9ed214d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.data.Knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Washdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Washdown.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java index 46b92d44e7..12472dbbf1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/WIP/Washdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.WIP; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java index 97f01b2738..908d364bcb 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Pc; -import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; +import edu.cmu.tetrad.search.work_in_progress.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java index 69061fd1d3..6774739dfd 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java @@ -26,7 +26,7 @@ import cern.colt.matrix.DoubleMatrix2D; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.WIP.IndTestMixedMultipleTTest; +import edu.cmu.tetrad.search.work_in_progress.IndTestMixedMultipleTTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java index da7240a708..ad45b43521 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/stability/SearchWrappers.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.Pc; -import edu.cmu.tetrad.search.WIP.IndTestMultinomialLogisticRegression; +import edu.cmu.tetrad.search.work_in_progress.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.search.score.SemBicScore; import edu.pitt.csb.mgm.Mgm; import edu.pitt.csb.mgm.MixedUtils; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java index a599924618..53c230d7a8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.WIP.DMSearch; +import edu.cmu.tetrad.search.work_in_progress.DMSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java index 84bb8c5c3c..3ce05938fa 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.WIP.IndTestFisherZGeneralizedInverse; +import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZGeneralizedInverse; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.sem.SemIm; From cb0f2d32fff044fa1d364e2685aff0d5846f53e6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 17:56:27 -0400 Subject: [PATCH 334/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java | 2 +- .../cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java | 2 +- .../classify/ClassifierBayesUpdaterDiscrete.java | 2 +- .../{search => classify}/classify/ClassifierDiscrete.java | 2 +- .../{search => classify}/classify/ClassifierMbDiscrete.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonMb.java | 0 .../src/main/java/edu/cmu/tetrad/search/HitonVariant.java | 0 .../edu/cmu/tetrad/search/{ => work_in_progress}/Mmhc.java | 4 +++- 8 files changed, 8 insertions(+), 6 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{search => classify}/classify/ClassifierBayesUpdaterDiscrete.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{search => classify}/classify/ClassifierDiscrete.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/{search => classify}/classify/ClassifierMbDiscrete.java (99%) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonMb.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonVariant.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Mmhc.java (97%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java index e8428b5677..554bf65d10 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.classify.ClassifierBayesUpdaterDiscrete; +import edu.cmu.tetrad.classify.classify.ClassifierBayesUpdaterDiscrete; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RocCalculator; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java index 1f91ef2c83..d3a2e64ff0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.search.classify.ClassifierBayesUpdaterDiscrete; +import edu.cmu.tetrad.classify.classify.ClassifierBayesUpdaterDiscrete; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierBayesUpdaterDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierBayesUpdaterDiscrete.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierBayesUpdaterDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierBayesUpdaterDiscrete.java index 25670622ee..11e1e56786 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierBayesUpdaterDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierBayesUpdaterDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.classify; +package edu.cmu.tetrad.classify.classify; import edu.cmu.tetrad.bayes.*; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierDiscrete.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierDiscrete.java index 89a967c8e7..e97ac2bbb3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.classify; +package edu.cmu.tetrad.classify.classify; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierMbDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierMbDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java index 8d16856bbd..0bb23b8acb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/classify/ClassifierMbDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.classify; +package edu.cmu.tetrad.classify.classify; import edu.cmu.tetrad.bayes.*; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonMb.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonVariant.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/HitonVariant.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmhc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java index ea52f7b9c7..861298f38e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java @@ -19,13 +19,15 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.GraphSearch; +import edu.cmu.tetrad.search.Mmmb; import edu.cmu.tetrad.search.utils.FgesOrienter; import edu.cmu.tetrad.search.test.IndependenceTest; From 0477389c85dc6246f185340240410b117f5b6fa8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 18:16:42 -0400 Subject: [PATCH 335/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../model/AbstractAlgorithmRunner.java | 4 +- .../cmu/tetradapp/model/AlgorithmRunner.java | 4 +- .../edu/cmu/tetradapp/model/FasRunner.java | 2 +- .../model/GeneralAlgorithmRunner.java | 3 +- .../edu/cmu/tetradapp/model/IGesRunner.java | 4 +- .../cmu/tetradapp/model/IndTestChooser.java | 2 +- .../model/LogisticRegressionRunner.java | 4 +- .../model/PValueImproverWrapper.java | 2 +- .../edu/cmu/tetradapp/model/PcRunner.java | 2 +- .../cmu/tetradapp/model/RegressionRunner.java | 4 +- .../tetradapp/model/SampleVcpcFastRunner.java | 2 +- .../cmu/tetradapp/model/SampleVcpcRunner.java | 2 +- .../model/TsPagFromDagGraphWrapper.java | 2 +- .../cmu/tetradapp/model/VcpcFastRunner.java | 7 +-- .../edu/cmu/tetradapp/model/VcpcRunner.java | 2 +- .../algorithm/oracle/pag/SvarFci.java | 2 +- .../algorithm/oracle/pag/SvarGfci.java | 2 +- .../score/PoissonPriorScore.java | 6 +-- .../score/ZhangShenBoundScore.java | 2 +- .../cmu/tetrad/search/ImpliedOrientation.java | 51 ------------------- .../java/edu/cmu/tetrad/search/LingD.java | 1 + .../java/edu/cmu/tetrad/search/Lingam.java | 1 + .../search/{ => score}/PoissonPriorScore.java | 2 +- .../tetrad/search/{ => score}/ZsbScore.java | 3 +- .../cmu/tetrad/search/test/IndTestMulti.java | 2 +- .../cmu/tetrad/search/utils/MeekRules.java | 3 +- .../{ => utils}/PermutationMatrixPair.java | 4 +- .../search/{ => utils}/ResolveSepsets.java | 3 +- .../tetrad/search/{ => utils}/TsDagToPag.java | 6 +-- .../tetrad/search/work_in_progress/Dci.java | 1 + .../search/work_in_progress/FasDci.java | 2 +- .../tetrad/study/performance/Comparison2.java | 1 + .../cmu/tetrad/test/TestAnneAnalysis3.java | 3 +- 33 files changed, 47 insertions(+), 94 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImpliedOrientation.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/PoissonPriorScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => score}/ZsbScore.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/PermutationMatrixPair.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/ResolveSepsets.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/TsDagToPag.java (98%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java index 379c089bdb..0cbcb8fc9b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.search.ImpliedOrientation; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.session.ParamsResettable; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Unmarshallable; @@ -265,7 +265,7 @@ public boolean supportsKnowledge() { return false; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { return null; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java index 0b8f68cdeb..1af7d17311 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.TripleClassifier; -import edu.cmu.tetrad.search.ImpliedOrientation; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.session.Executable; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.session.SimulationParamsSource; @@ -72,7 +72,7 @@ public interface AlgorithmRunner extends SessionModel, Executable, GraphSource, /** * @return the orientation rules for this search. */ - ImpliedOrientation getMeekRules(); + MeekRules getMeekRules(); /** * Sets the initial graph for the algorithm, if feasible. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index e2d5491c31..30ad8737c5 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -116,7 +116,7 @@ public static FasRunner serializableInstance() { return new FasRunner(Dag.serializableInstance(), new Parameters()); } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { MeekRules rules = new MeekRules(); rules.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); rules.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index 93b74c93c6..37ebb2ebaa 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -41,6 +41,7 @@ import edu.cmu.tetrad.search.test.IndTestScore; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.session.ParamsResettable; import edu.cmu.tetrad.util.Parameters; @@ -459,7 +460,7 @@ public boolean supportsKnowledge() { } @Override - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { return null; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java index d1498c10e4..0be8f135af 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IGesRunner.java @@ -25,8 +25,8 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; -import edu.cmu.tetrad.search.ImpliedOrientation; import edu.cmu.tetrad.search.score.ScoredGraph; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import java.beans.PropertyChangeEvent; @@ -56,7 +56,7 @@ public interface IGesRunner { boolean supportsKnowledge(); - ImpliedOrientation getMeekRules(); + MeekRules getMeekRules(); void propertyChange(PropertyChangeEvent evt); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index cd9ae41596..4bab5e1e53 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; +import edu.cmu.tetrad.search.utils.ResolveSepsets; import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZGeneralizedInverse; import edu.cmu.tetrad.search.work_in_progress.IndTestFisherZPercentIndependent; import edu.cmu.tetrad.search.work_in_progress.IndTestMultinomialLogisticRegression; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java index 71802c6985..e2e6fa73a7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.regression.LogisticRegression; -import edu.cmu.tetrad.search.ImpliedOrientation; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -241,7 +241,7 @@ public boolean supportsKnowledge() { return false; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { throw new UnsupportedOperationException(); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index c4201d1e1a..a10c90a290 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -271,7 +271,7 @@ public boolean supportsKnowledge() { return true; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { MeekRules rules = new MeekRules(); rules.setKnowledge((Knowledge) this.params.get("knowledge", new Knowledge())); return rules; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index c63423b678..9220450b49 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -117,7 +117,7 @@ public static PcRunner serializableInstance() { return new PcRunner(Dag.serializableInstance(), new Parameters()); } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { MeekRules rules = new MeekRules(); rules.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); rules.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java index 291774bc3e..2d8f90b06f 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java @@ -30,7 +30,7 @@ import edu.cmu.tetrad.regression.RegressionCovariance; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.ImpliedOrientation; +import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -217,7 +217,7 @@ public boolean supportsKnowledge() { return false; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { throw new UnsupportedOperationException(); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 5a0687c991..0b68ee7883 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -223,7 +223,7 @@ public boolean supportsKnowledge() { return true; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { MeekRules meekRules = new MeekRules(); meekRules.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); meekRules.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index 2cee04d8a1..2678f10fd0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -257,7 +257,7 @@ public boolean supportsKnowledge() { return true; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { MeekRules meekRules = new MeekRules(); meekRules.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); meekRules.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java index d97a6fd884..766fdf2e8d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Dag; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.TsDagToPag; +import edu.cmu.tetrad.search.utils.TsDagToPag; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index 8b668817db..edac77de70 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -33,10 +33,7 @@ import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.util.IndTestType; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * Extends AbstractAlgorithmRunner to produce a wrapper for the PC algorithm. @@ -256,7 +253,7 @@ public boolean supportsKnowledge() { return true; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { MeekRules meekRules = new MeekRules(); meekRules.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); meekRules.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 8f8dacd439..18e237705b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -256,7 +256,7 @@ public boolean supportsKnowledge() { return true; } - public ImpliedOrientation getMeekRules() { + public MeekRules getMeekRules() { MeekRules meekRules = new MeekRules(); meekRules.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles()); meekRules.setKnowledge((Knowledge) getParams().get("knowledge", new Knowledge())); 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/SvarFci.java index d1c62be3eb..bc61af3f4e 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/SvarFci.java @@ -15,7 +15,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.utils.TsUtils; -import edu.cmu.tetrad.search.TsDagToPag; +import edu.cmu.tetrad.search.utils.TsDagToPag; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; 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/SvarGfci.java index 99ce557602..fca200a421 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/SvarGfci.java @@ -17,7 +17,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.utils.TsUtils; -import edu.cmu.tetrad.search.TsDagToPag; +import edu.cmu.tetrad.search.utils.TsDagToPag; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java index 373291da1a..66040e4ca6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java @@ -33,12 +33,12 @@ public class PoissonPriorScore implements ScoreWrapper { public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.PoissonPriorScore score; + edu.cmu.tetrad.search.score.PoissonPriorScore score; if (dataSet instanceof DataSet) { - score = new edu.cmu.tetrad.search.PoissonPriorScore((DataSet) this.dataSet, parameters.getBoolean(Params.PRECOMPUTE_COVARIANCES)); + score = new edu.cmu.tetrad.search.score.PoissonPriorScore((DataSet) this.dataSet, parameters.getBoolean(Params.PRECOMPUTE_COVARIANCES)); } else if (dataSet instanceof ICovarianceMatrix) { - score = new edu.cmu.tetrad.search.PoissonPriorScore((ICovarianceMatrix) this.dataSet); + score = new edu.cmu.tetrad.search.score.PoissonPriorScore((ICovarianceMatrix) this.dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java index 924b5207d9..efc80e7abd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.ZsbScore; +import edu.cmu.tetrad.search.score.ZsbScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImpliedOrientation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImpliedOrientation.java deleted file mode 100644 index c9cd19c076..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ImpliedOrientation.java +++ /dev/null @@ -1,51 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.search; - -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; - -import java.util.Set; - -/** - * Adds any orientations implied by the given orientation. - * - * @author Joseph Ramsey - */ -public interface ImpliedOrientation { - - /** - * Sets knowledge. - */ - void setKnowledge(Knowledge knowledge); - - /** - * Adds implied orientations. - * - * @return Affected nodes. - */ - Set orientImplied(Graph graph); -} - - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index da08e69df2..c562b36cb3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -29,6 +29,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.HungarianAlgorithm; import edu.cmu.tetrad.search.utils.NRooks; +import edu.cmu.tetrad.search.utils.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.linear.BlockRealMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 15fa832ce0..95f71e20ab 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -22,6 +22,7 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.search.utils.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index 0ac5edd92e..91532c80e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index 284ab8db18..c9e07457bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -19,13 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.CorrelationMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java index 07dc7566fa..83e3911faa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMulti.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.ResolveSepsets; +import edu.cmu.tetrad.search.utils.ResolveSepsets; import edu.cmu.tetrad.util.TetradLogger; import java.util.HashSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java index a7c1fddb90..316d9c41c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java @@ -26,7 +26,6 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ImpliedOrientation; import edu.cmu.tetrad.util.TetradLogger; import java.util.*; @@ -40,7 +39,7 @@ * * @author Joseph Ramsey */ -public class MeekRules implements ImpliedOrientation { +public class MeekRules { private Knowledge knowledge = new Knowledge(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java index 825f5a3641..bbdc40530c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java @@ -19,8 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; +import edu.cmu.tetrad.search.LingD; +import edu.cmu.tetrad.search.Lingam; import edu.cmu.tetrad.util.Matrix; import java.util.Arrays; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java index e78d2baeb5..49d1e1f076 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java @@ -19,14 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndTestChiSquare; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.ProbUtils; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java index 9d795a3b19..a6ae1e0f2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsDagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java @@ -19,12 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.DagSepsets; -import edu.cmu.tetrad.search.utils.DagToPag; +import edu.cmu.tetrad.search.Fci; +import edu.cmu.tetrad.search.FciOrient; import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java index a8bd0e0840..d924aa4761 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.ResolveSepsets; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java index c2124884f0..59197281cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasDci.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.ResolveSepsets; +import edu.cmu.tetrad.search.utils.ResolveSepsets; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index 2be69f293c..da1dd16838 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -14,6 +14,7 @@ import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.TsDagToPag; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.ScoreType; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java index 4b3b50c290..bfafa03507 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java @@ -8,6 +8,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Boss; import edu.cmu.tetrad.search.PermutationSearch; +import edu.cmu.tetrad.search.score.PoissonPriorScore; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -93,7 +94,7 @@ private void run1() { CovarianceMatrix cov = getCov1(linecor, vars, n); // edu.cmu.tetrad.search.score.SemBicScore score = new edu.cmu.tetrad.search.score.SemBicScore(cov); - edu.cmu.tetrad.search.PoissonPriorScore score = new edu.cmu.tetrad.search.PoissonPriorScore(cov); + PoissonPriorScore score = new PoissonPriorScore(cov); // score.setPenaltyDiscount(penalty); score.setLambda(vars.size() / 2.); From 6a79dfcf690a2b71635b0e46952c86591caa6c28 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 18:20:40 -0400 Subject: [PATCH 336/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/classify/classify/ClassifierMbDiscrete.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/GraspFci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/GrowShrink.java | 2 +- .../tetrad/search/{GraphSearch.java => IGraphSearch.java} | 2 +- .../edu/cmu/tetrad/search/{MbSearch.java => IMbSearch.java} | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java | 3 ++- .../src/main/java/edu/cmu/tetrad/search/InterIamb.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/SvarGfci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java | 2 +- .../java/edu/cmu/tetrad/search/{ => utils}/MbUtils.java | 4 +--- .../src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java | 4 ++-- .../edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java | 2 +- .../cmu/tetrad/search/work_in_progress/SampleVcpcFast.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/VcPc.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/VcPcFast.java | 2 +- tetrad-lib/src/main/java/edu/pitt/csb/mgm/Mgm.java | 4 ++-- .../algo/bayesian/constraint/search/PagSamplingRfci.java | 4 ++-- .../pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java | 2 +- .../java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java | 6 +++--- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java | 4 ++-- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java | 2 +- 46 files changed, 53 insertions(+), 54 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{GraphSearch.java => IGraphSearch.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{MbSearch.java => IMbSearch.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/MbUtils.java (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java index 0bb23b8acb..b2dc1f5c1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.MbUtils; +import edu.cmu.tetrad.search.utils.MbUtils; import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.PcMb; import edu.cmu.tetrad.search.test.IndTestChiSquare; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 6619b25d29..a81da55855 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -55,7 +55,7 @@ * @see Boss * @see GFci */ -public final class BFci implements GraphSearch { +public final class BFci implements IGraphSearch { // The PAG being constructed. private Graph graph; 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 70421c6b1c..7f961a5832 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 @@ -41,7 +41,7 @@ * @author Frank C. Wimberly * @author Joseph Ramsey */ -public final class Ccd implements GraphSearch { +public final class Ccd implements IGraphSearch { private final IndependenceTest independenceTest; private final List nodes; private boolean applyR1; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index a2a60c16e1..9790bd397b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -46,7 +46,7 @@ * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 */ -public final class Cfci implements GraphSearch { +public final class Cfci implements IGraphSearch { /** * The PAG being constructed. 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 2ad85619cd..bd40059542 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 @@ -42,7 +42,7 @@ * * @author Joseph Ramsey (this version). */ -public final class Cpc implements GraphSearch { +public final class Cpc implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java index cdd2da03a3..07271c5085 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java @@ -39,7 +39,7 @@ * * @author Joseph Ramsey */ -public final class FasLofs implements GraphSearch { +public final class FasLofs implements IGraphSearch { private final Lofs.Rule rule; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 665793b061..70725db721 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -126,7 +126,7 @@ * * @author Joseph Ramsey */ -public final class Fask implements GraphSearch { +public final class Fask implements IGraphSearch { // The method to use for finding the adjacencies. public enum AdjacencyMethod {FAS_STABLE, FGES, EXTERNAL_GRAPH, NONE} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index e9aa5de983..49cbf2aaa6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -50,7 +50,7 @@ * @author Joseph Ramsey * @author Choh-Man Teng */ -public final class Fci implements GraphSearch { +public final class Fci implements IGraphSearch { private SepsetMap sepsets; private Knowledge knowledge = new Knowledge(); private final List variables = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index a0cdae7f95..4760f368f5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -44,7 +44,7 @@ * @author Choh-Man Teng * @see Fci */ -public final class FciMax implements GraphSearch { +public final class FciMax implements IGraphSearch { /** * The SepsetMap being constructed. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index df4260649e..5367e61263 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -61,7 +61,7 @@ * @author Ricardo Silva, Summer 2003 * @author Joseph Ramsey, Revisions 5/2015 */ -public final class Fges implements GraphSearch, DagScorer { +public final class Fges implements IGraphSearch, DagScorer { private final Set emptySet = new HashSet<>(); private final int[] count = new int[1]; private final int depth = 10000; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index 45f59c253b..462332de4e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -49,7 +49,7 @@ * @author ps7z * @author josephramsey */ -public final class GFci implements GraphSearch { +public final class GFci implements IGraphSearch { private Graph graph; private Knowledge knowledge = new Knowledge(); private IndependenceTest independenceTest; 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 48604cc590..f77ff1c59b 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 @@ -53,7 +53,7 @@ * @see GFci * @see Grasp */ -public final class GraspFci implements GraphSearch { +public final class GraspFci implements IGraphSearch { // The PAG being constructed. private Graph graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index d77412eb60..8a01f9bd80 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -35,7 +35,7 @@ * * @author Joseph Ramsey */ -public class GrowShrink implements MbSearch { +public class GrowShrink implements IMbSearch { /** * The independence test used to perform the search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java index d7959f3c7a..763b6aa861 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraphSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java @@ -26,7 +26,7 @@ /** * Interface for a search method that searches and returns a graph. */ -public interface GraphSearch { +public interface IGraphSearch { Graph search(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IMbSearch.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IMbSearch.java index 08389c72a6..33378e14f5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IMbSearch.java @@ -30,7 +30,7 @@ * * @author josephramsey */ -public interface MbSearch { +public interface IMbSearch { /** * Given the target this returns all the nodes in the Markov Blanket. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java index 060ffae6ef..42e1fc8108 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java @@ -31,7 +31,7 @@ /** * Implements IAMB. */ -public class Iamb implements MbSearch { +public class Iamb implements IMbSearch { /** * The independence test used to perform the search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java index 843359c431..e4e3077ea3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.MbUtils; import java.util.LinkedList; import java.util.List; @@ -33,7 +34,7 @@ * Created by IntelliJ IDEA. User: jdramsey Date: Jan 26, 2006 Time: 10:29:07 PM To change this template use File | * Settings | File Templates. */ -public class IambnPc implements MbSearch { +public class IambnPc implements IMbSearch { /** * The independence test used to perform the search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java index ead1ee9f01..ca07f59ce5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java @@ -31,7 +31,7 @@ /** * Implements the Inter-IAMB algorithm. */ -public class InterIamb implements MbSearch { +public class InterIamb implements IMbSearch { /** * The independence test used to perform the search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java index b674a5d711..5b6baf79d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java @@ -44,7 +44,7 @@ * * @author Robert Tillman. */ -public class Kpc implements GraphSearch { +public class Kpc implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java index 5abadfda61..b202c1cb09 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java @@ -36,7 +36,7 @@ * * @author Joseph Ramsey */ -public final class Mmmb implements MbSearch { +public final class Mmmb implements IMbSearch { /** * True if the symmetric algorithm is to be used. 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 3089be5978..b4755ede80 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 @@ -46,7 +46,7 @@ * * @author Joseph Ramsey. */ -public class Pc implements GraphSearch { +public class Pc implements IGraphSearch { /** * The independence test used for the PC search.g 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 a72621688e..6cfdbb1136 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 @@ -45,7 +45,7 @@ * * @author Joseph Ramsey. */ -public class PcMax implements GraphSearch { +public class PcMax implements IGraphSearch { /** * The independence test used for the PC search.g diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index e8d4865dae..d56620b789 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -39,7 +39,7 @@ * * @author Joseph Ramsey */ -public final class PcMb implements MbSearch, GraphSearch { +public final class PcMb implements IMbSearch, IGraphSearch { /** * The independence test used to perform the search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index 6a6ba5e3f4..96186b5a4d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -43,7 +43,7 @@ * * @author Joseph Ramsey. */ -public class Pcd implements GraphSearch { +public class Pcd implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 14b16707bc..1640f767cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -50,7 +50,7 @@ * @author Joseph Ramsey * @author Choh-Man Teng */ -public final class Rfci implements GraphSearch { +public final class Rfci implements IGraphSearch { /** * The RFCI-PAG being constructed. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index fca3fed7fe..922543d675 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -54,7 +54,7 @@ * @see GFci * @see Grasp */ -public final class SpFci implements GraphSearch { +public final class SpFci implements IGraphSearch { // The PAG being constructed. private Graph graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index e73d57ad2c..211771ee15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -53,7 +53,7 @@ * @author Choh-Man Teng * @author Daniel Malinsky */ -public final class SvarFci implements GraphSearch { +public final class SvarFci implements IGraphSearch { /** * The PAG being constructed. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 7e06de178a..b976156c8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -48,7 +48,7 @@ * @author Daniel Malinsky * @see GFci */ -public final class SvarGfci implements GraphSearch { +public final class SvarGfci implements IGraphSearch { // The PAG being constructed. private Graph graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index a59aeb0d57..71da7db607 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -57,7 +57,7 @@ * @author Joseph Ramsey, Revisions 5/2015 * @author Daniel Malinsky */ -public final class TsFges implements GraphSearch, DagScorer { +public final class TsFges implements IGraphSearch, DagScorer { /** * Internal. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java index d0a6f101d4..980dcb46f1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java @@ -55,7 +55,7 @@ * of the edges in the oriented graph * @author AJ Sedgewick, 5/2015 */ -public final class FgesOrienter implements GraphSearch, DagScorer { +public final class FgesOrienter implements IGraphSearch, DagScorer { /** * The covariance matrix for continuous data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java index ca85359b76..e047f63279 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java @@ -19,12 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java index 1a32a62c6b..5932e0b2ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java @@ -41,7 +41,7 @@ * * @author josephramsey */ -public final class PcCommon implements GraphSearch { +public final class PcCommon implements IGraphSearch { public enum FasType {REGULAR, STABLE} public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java index 861298f38e..1bdef7913c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphSearch; +import edu.cmu.tetrad.search.IGraphSearch; import edu.cmu.tetrad.search.Mmmb; import edu.cmu.tetrad.search.utils.FgesOrienter; import edu.cmu.tetrad.search.test.IndependenceTest; @@ -40,7 +40,7 @@ * * @author Joseph Ramsey (this version). */ -public class Mmhc implements GraphSearch { +public class Mmhc implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java index 3a1b97f90f..fb54b1aa6e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java @@ -50,7 +50,7 @@ * * @author Joseph Ramsey (this version). */ -public final class SampleVcpc implements GraphSearch { +public final class SampleVcpc implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java index 61d3c76f11..449dd6faf7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java @@ -50,7 +50,7 @@ * * @author Joseph Ramsey (this version). */ -public final class SampleVcpcFast implements GraphSearch { +public final class SampleVcpcFast implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java index 297259933c..a025aba063 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java @@ -43,7 +43,7 @@ * * @author Joseph Ramsey (this version). */ -public final class VcPc implements GraphSearch { +public final class VcPc implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java index 5af570e467..ecbc3802c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java @@ -41,7 +41,7 @@ * * @author Joseph Ramsey (this version). */ -public final class VcPcAlt implements GraphSearch { +public final class VcPcAlt implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java index df9ed214d2..f81bec77ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java @@ -43,7 +43,7 @@ * * @author Joseph Ramsey (this version). */ -public final class VcPcFast implements GraphSearch { +public final class VcPcFast implements IGraphSearch { /** * The independence test used for the PC search. diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/Mgm.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/Mgm.java index 20d4652d36..60942af5cf 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/Mgm.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/Mgm.java @@ -34,7 +34,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.GraphSearch; +import edu.cmu.tetrad.search.IGraphSearch; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; import edu.cmu.tetrad.util.MillisecondTimes; @@ -52,7 +52,7 @@ * Mixed Gaussian-Categorical Graphical Models * Created by ajsedgewick on 7/15/15. */ -public class Mgm extends ConvexProximal implements GraphSearch { +public class Mgm extends ConvexProximal implements IGraphSearch { private final DoubleFactory2D factory2D = DoubleFactory2D.dense; private final DoubleFactory1D factory1D = DoubleFactory1D.dense; diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java index d8bc6ab040..a7222f4011 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.GraphSearch; +import edu.cmu.tetrad.search.IGraphSearch; import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.Rfci; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; @@ -18,7 +18,7 @@ * * @author Kevin V. Bui (kvb2univpitt@gmail.com) */ -public class PagSamplingRfci implements GraphSearch { +public class PagSamplingRfci implements IGraphSearch { private final int NUM_THREADS = 10; diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java index 82768430cc..32fb161871 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java @@ -30,7 +30,7 @@ * * @author Chirayu Kong Wongchokprasitti, PhD (chw20@pitt.edu) */ -public class RfciBsc implements GraphSearch { +public class RfciBsc implements IGraphSearch { private final Rfci rfci; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java index aa57dcbc38..045a00fa30 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java @@ -116,7 +116,7 @@ private void checkSearch(String inputGraph, String outputGraph) { // Set up search. IndependenceTest independence = new IndTestDSep(graph); - GraphSearch search = new Cpc(independence); + IGraphSearch search = new Cpc(independence); // Run search Graph resultGraph = search.search(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java index 7ed6f1af4c..0611bcad96 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java @@ -406,7 +406,7 @@ private Graph getPag(DataSet data) { SemBicScore score = new SemBicScore(new CovarianceMatrix(data)); score.setPenaltyDiscount(4.0); - GraphSearch search = new Pc(test); + IGraphSearch search = new Pc(test); return search.search(); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java index 91293d597e..a33f8194d5 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMarkovBlanketSearches.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.GrowShrink; -import edu.cmu.tetrad.search.MbSearch; +import edu.cmu.tetrad.search.IMbSearch; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; import org.junit.Test; @@ -48,7 +48,7 @@ public void testSubgraph1() { IndTestDSep test = new IndTestDSep(graph); - MbSearch search = new GrowShrink(test); + IMbSearch search = new GrowShrink(test); List blanket = search.findMb(test.getVariable("T")); List b = new ArrayList<>(); @@ -68,7 +68,7 @@ public void testSubgraph2() { "PC3b-->C3,PC1b-->PC2a,PC1a<--PC3b,U,V"); IndTestDSep test = new IndTestDSep(graph); - MbSearch mbSearch = new GrowShrink(test); + IMbSearch mbSearch = new GrowShrink(test); List blanket = mbSearch.findMb(test.getVariable("T")); List mbd = GraphUtils.markovBlanketDag(graph.getNode("T"), graph).getNodes(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java index 90a6e35536..c8f4361098 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java @@ -331,7 +331,7 @@ private double[] printStats(String[] algorithms, int t, SemBicScore score = new SemBicScore(new CovarianceMatrix(data)); score.setPenaltyDiscount(2.0); - GraphSearch search; + IGraphSearch search; switch (t) { case 0: @@ -700,7 +700,7 @@ private double[] printStatsPcRegression(String[] algorithms, int t, SemBicScore score = new SemBicScore(new CovarianceMatrix(data)); score.setPenaltyDiscount(4.0); - GraphSearch search; + IGraphSearch search; Graph out; Node target = null; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java index 9988628e73..0df0a5bf21 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcMb.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.MbUtils; +import edu.cmu.tetrad.search.utils.MbUtils; import edu.cmu.tetrad.search.PcMb; import edu.cmu.tetrad.util.RandomUtil; import org.junit.Test; From e33ed24d68a2b69ab0381c38cf4f4571c2f3a36d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 18:48:42 -0400 Subject: [PATCH 337/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../model/GeneralAlgorithmRunner.java | 5 ++--- .../cmu/tetradapp/model/IndTestChooser.java | 4 ++-- .../algorithm/oracle/cpdag/Pcd.java | 8 ++++---- .../algcomparison/independence/BdeuTest.java | 4 ++-- .../independence/DiscreteBicTest.java | 4 ++-- .../independence/KimEtAlScoreTests.java | 4 ++-- .../independence/MagSemBicTest.java | 4 ++-- .../independence/SemBicDTest.java | 4 ++-- .../independence/SemBicTest.java | 4 ++-- .../tetrad/algcomparison/score/CciScore.java | 4 ++-- .../algcomparison/score/FisherZScore.java | 4 ++-- .../score/PositiveCorrScore.java | 4 ++-- .../java/edu/cmu/tetrad/search/Cstar.java | 20 +++++++++---------- .../java/edu/cmu/tetrad/search/FasLofs.java | 4 ++-- .../tetrad/search/score/DiscreteScore.java | 1 - .../{ScoredIndTest.java => IndTestScore.java} | 4 ++-- .../{IndTestScore.java => ScoreIndTest.java} | 8 ++++---- .../cmu/tetrad/search/utils/FgesOrienter.java | 11 +++++----- .../test/TestAutisticClassification.java | 4 ++-- 19 files changed, 51 insertions(+), 54 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/{ScoredIndTest.java => IndTestScore.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/{IndTestScore.java => ScoreIndTest.java} (97%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index 37ebb2ebaa..4b196e527f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -36,9 +36,8 @@ import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; @@ -597,7 +596,7 @@ public IndependenceTest getIndependenceTest() { // Grabbing this independence score for the independence tests interface. JR 2020.8.24 Score score = wrapper.getScore(getDataModelList().get(0), this.parameters); - this.independenceTests.add(new IndTestScore(score)); + this.independenceTests.add(new ScoreIndTest(score)); } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index 4bab5e1e53..a450414e8e 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -138,7 +138,7 @@ private IndependenceTest getContinuousTest(DataSet dataSet, return new IndTestFisherZGeneralizedInverse(dataSet, params.getDouble("alpha", 0.001)); } if (IndTestType.SEM_BIC == testType) { - return new IndTestScore(new SemBicScore(new CovarianceMatrix(dataSet))); + return new ScoreIndTest(new SemBicScore(new CovarianceMatrix(dataSet))); } { @@ -175,7 +175,7 @@ private IndependenceTest getMultiContinuousTest(List dataSets, } ImagesScore imagesScore = new ImagesScore(scores); - return new IndTestScore(imagesScore); + return new ScoreIndTest(imagesScore); } { 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 index 1de37e332f..56bae60a62 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 @@ -6,7 +6,7 @@ import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; @@ -33,18 +33,18 @@ public Pcd() { @Override public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - IndTestScore test; + ScoreIndTest test; if (dataSet instanceof ICovarianceMatrix) { SemBicScoreDeterministic score = new SemBicScoreDeterministic((ICovarianceMatrix) dataSet); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setDeterminismThreshold(parameters.getDouble(Params.DETERMINISM_THRESHOLD)); - test = new IndTestScore(score); + test = new ScoreIndTest(score); } else if (dataSet instanceof DataSet) { SemBicScoreDeterministic score = new SemBicScoreDeterministic(new CovarianceMatrix((DataSet) dataSet)); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setDeterminismThreshold(parameters.getDouble(Params.DETERMINISM_THRESHOLD)); - test = new IndTestScore(score); + test = new ScoreIndTest(score); } else { throw new IllegalArgumentException("Expecting a dataset or a covariance matrix."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java index 415150d842..683f745368 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.search.score.BdeuScore; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -34,7 +34,7 @@ public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { BdeuScore score = new BdeuScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setSamplePrior(parameters.getDouble(Params.PRIOR_EQUIVALENT_SAMPLE_SIZE)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); - return new IndTestScore(score); + return new ScoreIndTest(score); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java index fb24b6ea18..5595ccd25d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.search.score.DiscreteBicScore; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -34,7 +34,7 @@ public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { DiscreteBicScore score = new DiscreteBicScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); - return new IndTestScore(score); + return new ScoreIndTest(score); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java index 6dfdf61097..cdde406376 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.search.score.GicScores; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -72,7 +72,7 @@ public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - return new IndTestScore(score, dataSet); + return new ScoreIndTest(score, dataSet); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java index adda955c8f..36c32243c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.score.MagSemBicScore; import edu.cmu.tetrad.util.Parameters; @@ -41,7 +41,7 @@ public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { } score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - return new IndTestScore(score, dataSet); + return new ScoreIndTest(score, dataSet); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java index a26ae3bf24..f85d3723b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; @@ -25,7 +25,7 @@ public class SemBicDTest implements IndependenceWrapper { public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { SemBicScoreDeterministic score = new SemBicScoreDeterministic(new CovarianceMatrix((ICovarianceMatrix) dataSet)); score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount")); - return new IndTestScore(score, dataSet); + return new ScoreIndTest(score, dataSet); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java index 69885e5772..9a10095ee3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Parameters; @@ -42,7 +42,7 @@ public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); - return new IndTestScore(score, dataSet); + return new ScoreIndTest(score, dataSet); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java index 99f4cd0f32..0e69f776e4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.search.test.ConditionalCorrelationIndependence; import edu.cmu.tetrad.search.test.IndTestConditionalCorrelation; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.score.ScoredIndTest; +import edu.cmu.tetrad.search.score.IndTestScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -51,7 +51,7 @@ public Score getScore(DataModel dataSet, Parameters parameters) { throw new IllegalStateException("Basis not configured."); } - return new ScoredIndTest(cci); + return new IndTestScore(cci); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java index d5b3e61b81..2ca525c20b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.score.ScoredIndTest; +import edu.cmu.tetrad.search.score.IndTestScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -35,7 +35,7 @@ public Score getScore(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble(Params.ALPHA); this.alpha = alpha; IndTestFisherZ test = new IndTestFisherZ((DataSet) dataSet, alpha); - return new ScoredIndTest(test); + return new IndTestScore(test); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java index cc41cc34cc..0cd3a528ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndTestPositiveCorr; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.score.ScoredIndTest; +import edu.cmu.tetrad.search.score.IndTestScore; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; @@ -28,7 +28,7 @@ public Score getScore(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble("alpha"); this.alpha = alpha; IndTestPositiveCorr test = new IndTestPositiveCorr((DataSet) dataSet, alpha); - return new ScoredIndTest(test); + return new IndTestScore(test); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index e2682c710b..f170b0efd1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -5,11 +5,11 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.ConditionalGaussianScore; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.score.ScoredIndTest; +import edu.cmu.tetrad.search.score.IndTestScore; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestFisherZ; -import edu.cmu.tetrad.search.test.IndTestScore; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.util.*; import edu.pitt.dbmi.data.reader.Delimiter; @@ -178,7 +178,7 @@ public LinkedList> getRecords(DataSet dataSet, List pos } } - if (test instanceof IndTestScore && ((IndTestScore) test).getWrappedScore() instanceof SemBicScore) { + if (test instanceof ScoreIndTest && ((ScoreIndTest) test).getWrappedScore() instanceof SemBicScore) { this.test = test; } else if (test instanceof IndTestFisherZ) { this.test = test; @@ -694,29 +694,29 @@ private Graph getPatternPcStable(DataSet sample) { } private Graph getPatternFges(DataSet sample) { - Score score = new ScoredIndTest(getIndependenceTest(sample, this.test)); + Score score = new IndTestScore(getIndependenceTest(sample, this.test)); Fges fges = new Fges(score); fges.setVerbose(false); return fges.search(); } private IndependenceTest getIndependenceTest(DataSet sample, IndependenceTest test) { - if (test instanceof IndTestScore && ((IndTestScore) test).getWrappedScore() instanceof SemBicScore) { + if (test instanceof ScoreIndTest && ((ScoreIndTest) test).getWrappedScore() instanceof SemBicScore) { SemBicScore score = new SemBicScore(new CorrelationMatrix(sample)); - score.setPenaltyDiscount(((SemBicScore) ((IndTestScore) test).getWrappedScore()).getPenaltyDiscount()); - return new IndTestScore(score); + score.setPenaltyDiscount(((SemBicScore) ((ScoreIndTest) test).getWrappedScore()).getPenaltyDiscount()); + return new ScoreIndTest(score); } else if (test instanceof IndTestFisherZ) { double alpha = test.getAlpha(); return new IndTestFisherZ(new CorrelationMatrix(sample), alpha); } else if (test instanceof ChiSquare) { double alpha = test.getAlpha(); return new IndTestFisherZ(sample, alpha); - } else if (test instanceof IndTestScore && ((IndTestScore) test).getWrappedScore() instanceof ConditionalGaussianScore) { - ConditionalGaussianScore score = (ConditionalGaussianScore) ((IndTestScore) test).getWrappedScore(); + } else if (test instanceof ScoreIndTest && ((ScoreIndTest) test).getWrappedScore() instanceof ConditionalGaussianScore) { + ConditionalGaussianScore score = (ConditionalGaussianScore) ((ScoreIndTest) test).getWrappedScore(); double penaltyDiscount = score.getPenaltyDiscount(); ConditionalGaussianScore _score = new ConditionalGaussianScore(sample, penaltyDiscount, false); _score.setStructurePrior(0); - return new IndTestScore(_score); + return new ScoreIndTest(_score); } else { throw new IllegalArgumentException("That test is not configured: " + test); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java index 07271c5085..679677e646 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.score.SemBicScore; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.MillisecondTimes; @@ -83,7 +83,7 @@ public Graph search() { SemBicScore score = new SemBicScore(new CovarianceMatrix(this.dataSet)); score.setPenaltyDiscount(this.penaltyDiscount); - IndependenceTest test = new IndTestScore(score, this.dataSet); + IndependenceTest test = new ScoreIndTest(score, this.dataSet); System.out.println("FAS"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java index ee1dcec795..018a9feb58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java @@ -22,7 +22,6 @@ package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.search.score.Score; /** * Created by IntelliJ IDEA. User: jdramsey Date: Jul 6, 2009 Time: 3:58:26 PM To change this template use File | diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredIndTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredIndTest.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java index 002deaf06d..d7b07dded9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredIndTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java @@ -34,7 +34,7 @@ * * @author Joseph Ramsey */ -public class ScoredIndTest implements Score { +public class IndTestScore implements Score { private final IndependenceTest test; @@ -47,7 +47,7 @@ public class ScoredIndTest implements Score { /** * Constructs the score using a covariance matrix. */ - public ScoredIndTest(IndependenceTest test) { + public IndTestScore(IndependenceTest test) { this.variables = new ArrayList<>(); for (Node node : test.getVariables()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java index d2a0f28667..35428d43bf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java @@ -43,7 +43,7 @@ * @author Don Crimbchin (djc2@andrew.cmu.edu) * @author josephramsey */ -public class IndTestScore implements IndependenceTest { +public class ScoreIndTest implements IndependenceTest { private final Score score; private final List variables; @@ -51,11 +51,11 @@ public class IndTestScore implements IndependenceTest { private final DataModel data; private boolean verbose; - public IndTestScore(Score score) { + public ScoreIndTest(Score score) { this(score, null); } - public IndTestScore(Score score, DataModel data) { + public ScoreIndTest(Score score, DataModel data) { if (score == null) throw new NullPointerException(); this.score = score; this.variables = score.getVariables(); @@ -65,7 +65,7 @@ public IndTestScore(Score score, DataModel data) { /** * @return an Independence test for a subset of the variables. */ - public IndTestScore indTestSubset(List vars) { + public ScoreIndTest indTestSubset(List vars) { throw new UnsupportedOperationException(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java index 980dcb46f1..3a9114a6c5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.BdeuScore; -import edu.cmu.tetrad.search.score.DiscreteScore; import edu.cmu.tetrad.util.Vector; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; @@ -111,7 +110,7 @@ public final class FgesOrienter implements IGraphSearch, DagScorer { /** * The score for discrete searches. */ - private DiscreteScore IDiscreteScore; + private edu.cmu.tetrad.search.score.DiscreteScore DiscreteScore; /** * The logger for this class. The config needs to be set. @@ -350,15 +349,15 @@ public double getScore(Graph dag) { /** * @return the discrete scoring function being used. By default, BDeu. */ - public DiscreteScore getDiscreteScore() { - return this.IDiscreteScore; + public edu.cmu.tetrad.search.score.DiscreteScore getDiscreteScore() { + return this.DiscreteScore; } /** * Sets the discrete scoring function to use. */ - public void setDiscreteScore(DiscreteScore IDiscreteScore) { - this.IDiscreteScore = IDiscreteScore; + public void setDiscreteScore(edu.cmu.tetrad.search.score.DiscreteScore DiscreteScore) { + this.DiscreteScore = DiscreteScore; } /** diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java index 607d856992..7208d6605c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java @@ -28,7 +28,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fas; -import edu.cmu.tetrad.search.test.IndTestScore; +import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Parameters; @@ -459,7 +459,7 @@ public void testForBiwei() { DataSet dataSet = datasets.get(i); SemBicScore score = new SemBicScore(new CovarianceMatrix(dataSet)); - Fas fas = new Fas(new IndTestScore(score)); + Fas fas = new Fas(new ScoreIndTest(score)); Graph graph = fas.search(); System.out.println(graph); From 8eab0faf9639ffcf70691ca6be7624f90542b5cd Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 6 May 2023 18:49:54 -0400 Subject: [PATCH 338/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java index 96aa69c183..b1aa602dd7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java @@ -33,6 +33,8 @@ /** * Calculates the BDeu score. + * + * @author josephramsey */ public class BdeuScore implements DiscreteScore { private final int[][] data; From 65412758db128e2c6d485ce545b9a407f968e4aa Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 10:14:28 -0400 Subject: [PATCH 339/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../model/PValueImproverWrapper.java | 7 ++-- .../main/java/edu/cmu/tetrad/search/BFci.java | 13 +++---- .../main/java/edu/cmu/tetrad/search/Bes.java | 12 +++++- .../edu/cmu/tetrad/search/BesPermutation.java | 17 ++++++++- .../main/java/edu/cmu/tetrad/search/Boss.java | 13 ++++--- .../main/java/edu/cmu/tetrad/search/Bpc.java | 37 ++++++++----------- .../main/java/edu/cmu/tetrad/search/Ccd.java | 14 ++++--- .../java/edu/cmu/tetrad/search/Cstar.java | 31 ++++++++++------ .../edu/cmu/tetrad/search/FactorAnalysis.java | 14 ++++--- .../main/java/edu/cmu/tetrad/search/Fas.java | 32 +++++++++++----- .../java/edu/cmu/tetrad/search/FastIca.java | 16 ++++---- .../java/edu/cmu/tetrad/search/Grasp.java | 19 +++++++--- .../java/edu/cmu/tetrad/search/GraspFci.java | 16 +++++--- .../java/edu/cmu/tetrad/search/SpFci.java | 17 ++++++--- .../edu/cmu/tetrad/search/score/BdeScore.java | 9 ++++- .../cmu/tetrad/search/score/BdeuScore.java | 7 +++- .../search/score/DegenerateGaussianScore.java | 12 +++++- .../{HbmsBeam.java => HbsmsBeam.java} | 32 ++++++++-------- 18 files changed, 198 insertions(+), 120 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/{HbmsBeam.java => HbsmsBeam.java} (94%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index a10c90a290..9a8d80030b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -23,8 +23,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; -import edu.cmu.tetrad.search.work_in_progress.HbmsBeam; +import edu.cmu.tetrad.search.work_in_progress.HbsmsBeam; import edu.cmu.tetrad.search.work_in_progress.Hbsms; import edu.cmu.tetrad.search.work_in_progress.HbsmsGes; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; @@ -222,7 +221,7 @@ public void execute() { DataSet dataSet = (DataSet) dataModel; if (getAlgorithmType() == AlgorithmType.BEAM) { - search = new HbmsBeam(graph2, dataSet, knowledge); + search = new HbsmsBeam(graph2, dataSet, knowledge); } else if (getAlgorithmType() == AlgorithmType.FGES) { search = new HbsmsGes(graph2, dataSet); search.setKnowledge(knowledge); @@ -233,7 +232,7 @@ public void execute() { CovarianceMatrix covarianceMatrix = (CovarianceMatrix) dataModel; if (getAlgorithmType() == AlgorithmType.BEAM) { - search = new HbmsBeam(graph2, covarianceMatrix, knowledge); + search = new HbsmsBeam(graph2, covarianceMatrix, knowledge); } else if (getAlgorithmType() == AlgorithmType.FGES) { throw new IllegalArgumentException("GES method requires a dataset; a covariance matrix was provided."); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index a81da55855..626e2d501e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -38,17 +38,16 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** + *

Changes the implementation of the GFCI algorithm to use Boss + * instead of FGES as the initial step. This tends to produce a accurate PAG than + * GFCI as a result, for the latent variables case. The reference for GFCI + * is here:

*

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

+ *

For BOSS only a score is needed, but there are steps in GFCI that require + * a test, so for this method, both a test and a score need to be given.

* - *

This uses PermutationSearch (see), calling the BOSS algorithm (see).

- * - *

An independence test must be provided for the definite discriminating path step - * of FCI. Otherwise, the provided score is used throughout.

- * - * @author Juan Miguel Ogarrio - * @author ps7z * @author jdramsey * @author bryan andrews * @see PermutationSearch diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java index e362113925..6e1e12e267 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java @@ -19,11 +19,21 @@ /** - * Implements the backward equivalence search of FGES. + *

Extracts the backward step of GES for use GES but also in other + * algorithms. The GES algorithm consists of a forward phase (FES = Forward + * Equivalence Search) and a backward phase (BES = Backward Equivalence Search). + * We find the BES step by itself is useful in a number of algorithms, so we + * extract this step and give as a separate algorithm.

+ *

The idea of the backward search is to start with a model that is + * Markov and removed edges from it and do the corresponding reorientations, + * improving the score each time, until the score can no longer be improved.

+ *

We use the optimized implementation used in the FGES implementation + * of GES.

* * @author bryanandrews * @author josephramsey * @see Fges + * @see Boss */ public class Bes { private final List variables; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java index db8cc64284..1723e9d8e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java @@ -19,11 +19,24 @@ /** - *

Implements the backward equivalence search of FGES, taking permutations - * as input and returning updated permutations as output.

+ *

Implements a version of the BES (Best Equivalent Search) algorithm + * that takes a permutation as input and yields a permtuation as output, + * where the related DAG or CPDAG models are implied by the ordering or + * variables in these permutations. BES is the second step of the GES + * algorithm (e.g., FGES). The first step in GES starts with an + * empty graph and adds edges (with corresponding reorientations of + * edges), yielding a Markov model. The second step, this one, BES, + * starts with this Markov model and then tries to remove edges from + * it (with corresponding reorientation) to improve the BES scores.

+ *

The advantage of doing this is that BES can then be used as + * a step in certain permutation-based algorithms like BOSS to allow + * correct models to be inferred under the assumption of faithfulness.

* * @author bryanandrews * @author josephramsey + * @see Fges + * @see Bes + * @see Boss */ public class BesPermutation { private final List variables; 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 bc46ffd049..1224562097 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 @@ -11,11 +11,12 @@ import static edu.cmu.tetrad.util.RandomUtil.shuffle; /** - *

Implements the BOSS (Best Order Permutation Search) algorithm. This procedure uses - * an optimization of the BOSS algorithm (reference to be included in a future version), - * looking for a permutation such that when a DAG is built it has the fewest number of - * edges (i.e., is a most 'frugal' or a 'sparsest' DAG). Returns the CPDAG of this discovered - * frugal DAG.

+ *

Implements an algorithms called BOSS (Bost order Score Search), which + * intercalalates calls to a permutation discvoery step with called to BES, in order + * to find an optimal permutation implying a DAG and therefore a CPDAG that is + * highly accurate. This follows up on work by Raskutti and Uhler on the SP + * (Sparsest Permutation) algorithm and work by Lam, Andrews and Ramsey on the + * GRaSP algorithm and is currently under development.

* *

Knowledge can be used with this search. If tiered knowledge is used, then the procedure * is carried out for each tier separately, given the variable preceding that tier, which @@ -27,6 +28,8 @@ * * @author bryanandrews * @author josephramsey + * @see Sp + * @see Grasp * @see PermutationSearch */ public class Boss implements SuborderSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index 4cf7035832..78628b72a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -35,28 +35,23 @@ /** - * BuildPureClusters is an implementation of the automated clustering and purification methods - * described on the report "Learning Measurement Models" CMU-CALD-03-100. - *

- * The output is only the purified model. Future versions may include options to visualize the - * measurement pattern in the GUI (it shows up in the console window, though.) - *

- * References: - *

- * Silva, R.; Scheines, R.; Spirtes, P.; Glymour, C. (2003). "Learning measurement models". + *

Implements the Build Pure Clusters algorithm, which allows one to identify + * clusters of measured variables in a dataset that are explained by single latents. + * The algorithm outputs these clusters, which can then be used for further analysis. + * The reference is this:

+ *

Silva, R., Scheines, R., Glymour, C., Spirtes, P., & Chickering, D. M. (2006). + * Learning the Structure of Linear Latent Variable Models. Journal of Machine Learning + * Research, 7(2).

+ *

Some more References: + *

Silva, R.; Scheines, R.; Spirtes, P.; Glymour, C. (2003). "Learning measurement models". * Technical report CMU-CALD-03-100, Center for Automated Learning and Discovery, Carnegie Mellon - * University. - *

- * Bollen, K. (1990). "Outlier screening and distribution-free test for vanishing tetrads." - * Sociological Methods and Research 19, 80-92. - *

- * Wishart, J. (1928). "Sampling errors in the theory of two factors". British Journal of - * Psychology 19, 180-187. - *

- * Bron, C. and Kerbosch, J. (1973) "Algorithm 457: Finding all cliques of an undirected graph". - * Communications of ACM 16, 575-577. - *

- * --Cleaned up by jdramsey 2022-03-28 + * University.

+ *

Bollen, K. (1990). "Outlier screening and distribution-free test for vanishing tetrads." + * Sociological Methods and Research 19, 80-92.

+ *

Wishart, J. (1928). "Sampling errors in the theory of two factors". British Journal of + * Psychology 19, 180-187.

Bron, C. and Kerbosch, J. (1973) "Algorithm 457: Finding all cliques of an undirected graph". + * Communications of ACM 16, 575-577.

* * @author Ricardo Silva */ 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 7f961a5832..22629c0e31 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 @@ -32,11 +32,15 @@ import java.util.*; /** - *

This class provides the data structures and methods for carrying out the Cyclic Causal Discovery algorithm (CCD) - * described by Thomas Richardson and Peter Spirtes in Chapter 7 of Computation, Causation, and Discovery by Glymour and - * Cooper eds. The comments that appear below are keyed to the algorithm specification on pp. 269-271. The search - * method returns an instance of a Graph but it also constructs two lists of node triples which represent the underlines - * and dotted underlines that the algorithm discovers.

+ *

Implemented the Cyclic Causal Discovery (CCD) algorithm by Thomas Richardson. + * A reference for this is here:

+ *

Mooij, J. M., & Claassen, T. (2020, August). Constraint-based causal discovery + * using partial ancestral graphs in the presence of cycles. In Conference on Uncertainty + * in Artificial Intelligence (pp. 1159-1168). PMLR.

+ *

See also Chapter 7 of Glymour and Cooper, eds., Computation, Causation, and Discovery

+ *

The graph takes continuous data from a cyclic model as input and returns a cyclic + * PAG graphs, with various types of underlining, that represents a Markov equivalence of + * the true DAG.

* * @author Frank C. Wimberly * @author Joseph Ramsey diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index f170b0efd1..63793a9774 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -20,18 +20,17 @@ import java.util.concurrent.*; /** - * An adaptation of the CStaR algorithm (Steckoven et al., 2012). - *

- * Stekhoven, D. J., Moraes, I., Sveinbjörnsson, G., Hennig, L., Maathuis, M. H., and Bühlmann, P. (2012). - * Causal stability ranking. Bioinformatics, 28(21), 2819-2823. - *

- * Meinshausen, N., and Bühlmann, P. (2010). Stability selection. Journal of the Royal Statistical Society: - * Series B (Statistical Methodology), 72(4), 417-473. - *

- * Colombo, D., and Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. - * The Journal of Machine Learning Research, 15(1), 3741-3782. + *

Iplements the CStaR algorithm (Steckoven et al., 2012), which finds a CPDAG of thd data and then + * tries all orientations of the undirected edges about a variable in the CPDAG to estimate a + * minimum bound on the effect for a given edge. Soem references include the following:

+ *

Stekhoven, D. J., Moraes, I., Sveinbjörnsson, G., Hennig, L., Maathuis, M. H., and Bühlmann, P. (2012). + * Causal stability ranking. Bioinformatics, 28(21), 2819-2823.

+ *

Meinshausen, N., and Bühlmann, P. (2010). Stability selection. Journal of the Royal Statistical Society: + * Series B (Statistical Methodology), 72(4), 417-473.

+ *

Colombo, D., and Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. + * The Journal of Machine Learning Research, 15(1), 3741-3782.

* - * @author jdramsey@andrew.cmu.edu + * @author josephramsey */ public class Cstar { private boolean parallelized = false; @@ -778,8 +777,16 @@ private List runCallablesDoubleArray(List> task return results; } - public enum CpdagAlgorithm {FGES, PC_STABLE, GRaSP} + /** + * An enumeration of the options available for estiting the CPDAG + * used for the algorthm. + */ + public enum CpdagAlgorithm {PC_STABLE, FGES, GRaSP} + /** + * An enumeration of the methods for selecting samples from the full + * dataset. + */ public enum SampleStyle {BOOTSTRAP, SPLIT} private static class Tuple { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index 469463bbd0..03b38626d5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -33,12 +33,14 @@ import static org.apache.commons.math3.util.FastMath.abs; /** - * Useful references: "Factor Analysis of Data Matrices" - Paul Horst (1965) This work has good specifications and - * explanations of factor analysis algorithm and methods of communality estimation. - *

- * "Applied Factor Analysis" - R.J. Rummel (1970) This book is a good companion to the book listed above. While it - * doesn't specify any actual algorithm, it has a great introduction to the subject that gives the reader a good - * appreciation of the philosophy and the mathematics behind factor analysis. + *

Implements the classical Factor Analysis algorithm. Some references include:

+ *

Horst, P. (1965). Factor analysis of data matrices. Holt, Rinehart and Winston. + * This work has good specifications and explanations of factor analysis algorithm and + * methods of communality estimation.

+ *

Rummel, R. J. (1988). Applied factor analysis. Northwestern University Press. This + * book is a good companion to the book listed above. While it doesn't specify any actual + * algorithm, it has a great introduction to the subject that gives the reader a good + * appreciation of the philosophy and the mathematics behind factor analysis.

* * @author Mike Freenor */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index c7eacd5b9f..9b8a498ad8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -33,18 +33,30 @@ import java.util.*; /** - * Implements the "fast adjacency search" used in several causal algorithm in this package. In the fast adjacency - * search, at a given stage of the search, an edge X*-*Y is removed from the graph if X _||_ Y | S, where S is a subset - * of size d either of adj(X) or of adj(Y), where d is the depth of the search. The fast adjacency search performs this - * procedure for each pair of adjacent edges in the graph and for each depth d = 0, 1, 2, ..., d1, where d1 is either - * the maximum depth or else the first such depth at which no edges can be removed. The interpretation of this adjacency - * search is different for different algorithm, depending on the assumptions of the algorithm. A mapping from {x, y} to - * S({x, y}) is returned for edges x *-* y that have been removed. - *

- * Optionally uses Heuristic 3 from Causation, Prediction and Search, which (like FAS-Stable) renders the output - * invariant to the order of the input variables (See Tsagris). + *

Implements the adjacency search of the PC algorithm (see), which is a useful algorithm + * in many contexts, including as the first step of FCI (see). Se we call it the "Fast + * Adjacency Search" (FAS), to give it a name.

+ * + *

The idea of FAS is that at a given stage of the search, an edge X*-*Y is removed from the + * graph if X _||_ Y | S, where S is a subset of size d either of adj(X) or of adj(Y), where d + * is the depth of the search. The fast adjacency search performs this procedure for each pair + * of adjacent edges in the graph and for each depth d = 0, 1, 2, ..., d1, where d1 is either + * the maximum depth or else the first such depth at which no edges can be removed. The + * interpretation of this adjacency search is different for different algorithm, depending on + * the assumptions of the algorithm. A mapping from {x, y} to S({x, y}) is returned for edges + * x *-* y that have been removed.

+ * + *

Optionally uses Heuristic 3 from Causation, Prediction and Search, which (like FAS-Stable) + * renders the output invariant to the order of the input variables (See Tsagris).

+ * + *

This algorithm was described in the earlier edition of this book:

+ * + *

Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + * prediction, and search. MIT press.

* * @author Joseph Ramsey. + * @see Pc + * @see Fci */ public class Fas implements IFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index a1cd04e4da..1d9fc66a9b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -31,11 +31,13 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * A Java implementation of FastIca following the R package fastICA. The only - * difference (I believe) is that the R package can handle complex numbers, - * whereas this implementation cannot. - *

- * The documention of the R version is as follows, all of which is true of this + *

Translates a version of the FastICA algorithm used in R from Fortran + * into Java for use in Tetrad. This can be used in various algorithms that + * assume linearity and non-gaussianity, as for example LiNGAM and LiNG-D. + * There is one difference from the R, in that in R FastICA can operate over + * complex numbers, whereeas here it is restricted to real numbers.

+ * + *

The documention of the R version is as follows, all of which is true of this * translation (so far as I know) except for its being in R and its allowing * complex values. *

@@ -134,9 +136,8 @@ * A. Hyvarinen and E. Oja (2000) Independent Component Analysis: Algorithms and * Applications, _Neural Networks_, *13(4-5)*:411-430 *

- * This code has been well-tested. * - * @author Joseph Ramsey (of the translation, that is, not the original.) + * @author josephramsey */ public class FastIca { @@ -672,7 +673,6 @@ private void scale(Matrix x) { Vector u = x.getRow(i).scalarMult(1.0 / rms(x.getRow(i))); x.assignRow(i, u); } - } private void center(Matrix x) { 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 04405de70c..037ed4838b 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 @@ -20,16 +20,23 @@ /** - *

Implements the GRaSP algorithms, with various execution flags. GRaSP can use - * either a score or an independence test; you can provide both, though if you do - * you need to use the paremeters to choose which one will be used. The score - * options is more scalable and accurate, though the independence option is - * perhaps a little easier ot deal with theoretically.

- *

Reference:

+ *

Implements the GRaSP algorithms, which uses a certain procedure to search + * in the space of permutations of variables for ones that imply CPDAGs that are + * especailly close to the CPDAG of the true model. The reference is here:

*

Lam, W. Y., Andrews, B., & Ramsey, J. (2022, August). Greedy relaxations of * the sparsest permutation algorithm. In Uncertainty in Artificial Intelligence * (pp. 1052-1062). PMLR.

* + *

GRaSP can use either a score or an independence test; you can provide + * both, though if you do you need to use the paremeters to choose which one will + * be used. The score options is more scalable and accurate, though the independence + * option is perhaps a little easier ot deal with theoretically

+ * + *

Knowledge can be used with this search. If tiered knowledge is used, then + * the procedure is carried out for each tier separately, given the variable preceding + * that tier, which allows the SP algorithm to address tiered (e.g., time series) + * problems with larger numbers of variables.

+ * * @author bryanandrews * @author josephramsey */ 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 f77ff1c59b..e9226e0b23 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 @@ -41,17 +41,21 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - *

Replaces FGES in GFCI by GRaSP using a score, which is another score-based - * (but more accurate) algorithm.

+ *

Changes the implementation of the GFCI algorithm to use Boss + * instead of GRaSP as the initial step. This tends to produce a accurate PAG than + * GFCI as a result, for the latent variables case. The reference for GFCI + * is here:

*

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

+ *

For BOSS only a score is needed, but there are steps in GFCI that require + * a test, so for this method, both a test and a score need to be given.

* - * @author peterspirtes - * @author josephramsey - * @author bryanandrews + * @author jdramsey + * @author bryan andrews + * @see Boss * @see GFci - * @see Grasp + * @see Fci */ public final class GraspFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 922543d675..67db2decfd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -42,17 +42,22 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - *

Replaces FGES in GFCI by SP using a score, which is another score-based - * (but more accurate) algorithm.

+ *

Changes the implementation of the GFCI algorithm to use Boss + * instead of SP (Sparest Permutation) as the initial step. This tends to + * produce a accurate PAG than GFCI as a result, for the latent variables + * case. The reference for GFCI is here:

*

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

+ *

For BOSS only a score is needed, but there are steps in GFCI that require + * a test, so for this method, both a test and a score need to be given.

* - * @author peterspirtes - * @author josephramsey - * @author bryanandrews + * @author jdramsey + * @author bryan andrews + * @see Boss * @see GFci - * @see Grasp + * @see BFci + * @see Sp */ public final class SpFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java index 59cb34cee4..c9e2c154f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java @@ -30,10 +30,15 @@ import java.util.List; /** - * Calculates the BDe score. + *

Calculates the BDe score (Bayes Dirichlet Equivalent) score for analyzing + * discrete multinomial data. A good discussion of BD* scores can be found here:

+ *

Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: + * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). + * https://doi.org/10.1007/BF00994016

* * @author josephramsey - */ + * @see BdeuScore + * */ public class BdeScore implements DiscreteScore { private final DataSet dataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java index b1aa602dd7..500984bf6a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java @@ -32,9 +32,14 @@ import java.util.List; /** - * Calculates the BDeu score. + *

Calculates the BDeu score, which the BDe (Bayes Dirichlet Equivalent) score + * with uniform priors. A good discussion of BD* scores can be found here:

+ *

Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: + * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). + * https://doi.org/10.1007/BF00994016

* * @author josephramsey + * @see BdeScore */ public class BdeuScore implements DiscreteScore { private final int[][] data; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 82e2f1b30d..918a23269e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -40,8 +40,16 @@ import static org.apache.commons.math3.util.FastMath.log; /** - *

Implements a degenerate Gaussian BIC score for FGES.

- * ... + *

This implements the degenerate Gaussian BIC score for FGES. + * The degenerate Gaussian score replaces each discrete variable + * in the data with a list of 0/1 continuous indicator columns for + * each of the categories but one (the last one implied). This + * data, now all continuous, is given to the SEM BIC score and + * methods used to help determine conditional independence for the + * mixed continuous/discrete case from this information. The + * references is as follows:

+ * + * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf * * @author Bryan Andrews */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java index 2334500bec..0b820f4efa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java @@ -47,7 +47,7 @@ * @author Joseph Ramsey */ -public final class HbmsBeam implements Hbsms { +public final class HbsmsBeam implements Hbsms { private final CovarianceMatrix cov; private Knowledge knowledge; private final Graph externalGraph; @@ -61,7 +61,7 @@ public final class HbmsBeam implements Hbsms { private final Scorer scorer; private int beamWidth = 1; - public HbmsBeam(Graph graph, DataSet data, Knowledge knowledge) { + public HbsmsBeam(Graph graph, DataSet data, Knowledge knowledge) { if (graph == null) graph = new EdgeListGraph(data.getVariables()); this.knowledge = knowledge; @@ -71,7 +71,7 @@ public HbmsBeam(Graph graph, DataSet data, Knowledge knowledge) { this.scorer = new DagScorer(this.cov); } - public HbmsBeam(Graph graph, CovarianceMatrix cov, Knowledge knowledge) { + public HbsmsBeam(Graph graph, CovarianceMatrix cov, Knowledge knowledge) { if (graph == null) graph = new EdgeListGraph(cov.getVariables()); this.knowledge = knowledge; @@ -294,18 +294,18 @@ private Graph makeMove(Graph graph, Move move) { Edge firstEdge = move.getFirstEdge(); Edge secondEdge = move.getSecondEdge(); - if (firstEdge != null && move.getType() == HbmsBeam.Move.Type.ADD) { + if (firstEdge != null && move.getType() == HbsmsBeam.Move.Type.ADD) { graph.removeEdge(firstEdge.getNode1(), firstEdge.getNode2()); graph.addEdge(firstEdge); - } else if (firstEdge != null && move.getType() == HbmsBeam.Move.Type.REMOVE) { + } else if (firstEdge != null && move.getType() == HbsmsBeam.Move.Type.REMOVE) { graph.removeEdge(firstEdge); - } else if (firstEdge != null && move.getType() == HbmsBeam.Move.Type.DOUBLE_REMOVE) { + } else if (firstEdge != null && move.getType() == HbsmsBeam.Move.Type.DOUBLE_REMOVE) { graph.removeEdge(firstEdge); graph.removeEdge(secondEdge); - } else if (firstEdge != null && move.getType() == HbmsBeam.Move.Type.REDIRECT) { + } else if (firstEdge != null && move.getType() == HbsmsBeam.Move.Type.REDIRECT) { graph.removeEdge(graph.getEdge(firstEdge.getNode1(), firstEdge.getNode2())); graph.addEdge(firstEdge); - } else if (firstEdge != null && secondEdge != null && move.getType() == HbmsBeam.Move.Type.ADD_COLLIDER) { + } else if (firstEdge != null && secondEdge != null && move.getType() == HbsmsBeam.Move.Type.ADD_COLLIDER) { Edge existingEdge1 = graph.getEdge(firstEdge.getNode1(), firstEdge.getNode2()); Edge existingEdge2 = graph.getEdge(secondEdge.getNode1(), secondEdge.getNode2()); @@ -319,10 +319,10 @@ private Graph makeMove(Graph graph, Move move) { graph.addEdge(firstEdge); graph.addEdge(secondEdge); - } else if (firstEdge != null && secondEdge != null && move.getType() == HbmsBeam.Move.Type.REMOVE_COLLIDER) { + } else if (firstEdge != null && secondEdge != null && move.getType() == HbsmsBeam.Move.Type.REMOVE_COLLIDER) { graph.removeEdge(firstEdge); graph.removeEdge(secondEdge); - } else if (firstEdge != null && secondEdge != null && move.getType() == HbmsBeam.Move.Type.SWAP) { + } else if (firstEdge != null && secondEdge != null && move.getType() == HbsmsBeam.Move.Type.SWAP) { graph.removeEdge(firstEdge); Edge secondEdgeStar = graph.getEdge(secondEdge.getNode1(), secondEdge.getNode2()); @@ -363,7 +363,7 @@ private List getAddMoves(Graph graph) { if (!graph.paths().isAncestorOf(nodes.get(j), nodes.get(i))) { Edge edge = Edges.directedEdge(nodes.get(i), nodes.get(j)); - moves.add(new Move(edge, HbmsBeam.Move.Type.ADD)); + moves.add(new Move(edge, HbsmsBeam.Move.Type.ADD)); } } } @@ -393,7 +393,7 @@ private List getRedirectMoves(Graph graph) { continue; } - moves.add(new Move(Edges.directedEdge(j, i), HbmsBeam.Move.Type.REDIRECT)); + moves.add(new Move(Edges.directedEdge(j, i), HbsmsBeam.Move.Type.REDIRECT)); } return moves; @@ -430,14 +430,14 @@ public enum Type { private final Edge edge; private Edge secondEdge; - private final HbmsBeam.Move.Type type; + private final HbsmsBeam.Move.Type type; - public Move(Edge edge, HbmsBeam.Move.Type type) { + public Move(Edge edge, HbsmsBeam.Move.Type type) { this.edge = edge; this.type = type; } - public Move(Edge edge, Edge secondEdge, HbmsBeam.Move.Type type) { + public Move(Edge edge, Edge secondEdge, HbsmsBeam.Move.Type type) { this.edge = edge; this.secondEdge = secondEdge; this.type = type; @@ -451,7 +451,7 @@ public Edge getSecondEdge() { return this.secondEdge; } - public HbmsBeam.Move.Type getType() { + public HbsmsBeam.Move.Type getType() { return this.type; } From 5cb797c51fc2c2a7bc8c1160b8ec2fc339093e0c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 10:44:43 -0400 Subject: [PATCH 340/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/FasDeterministic.java | 5 +++- .../main/java/edu/cmu/tetrad/search/Fask.java | 27 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index 4d39199568..4e37383681 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -36,7 +36,10 @@ import java.util.*; /** - * This adjusts FAS for the deterministic case. + *

Adjusts FAS (see) for the deterministic case by refusing to removed edges + * based on conditional independence tests that are judged to be deterministic. + * That is, if X _||_ Y | Z, but Z determines X or Y, then the edge X---Y is + * not removed.

* * @author Joseph Ramsey. * @see Fas diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 70725db721..7d05a4fe94 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -45,15 +45,20 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Runs the FASK (Fast Adjacency Skewness) algorithm. The reference is Sanchez-Romero, R., Ramsey, J. D., - * Zhang, K., Glymour, M. R., Huang, B., and Glymour, C. (2019). Estimating feedforward and feedback - * effective connections from fMRI time series: Assessments of statistical methods. Network Neuroscience, - * 3(2), 274-306, though it has been improved in some ways from that version, and some pairwise methods from - * Hyvärinen, A., and Smith, S. M. (2013). Pairwise likelihood ratios for estimation of non-Gaussian structural - * equation models. Journal of Machine Learning Research, 14(Jan), 111-152 have been included for - * comparison (and potential use!--they are quite good!). - *

- * This method (and the Hyvarinen and Smith methods) make the assumption that the data are generated by + *

Implements the FASK (Fast Adjacency Skewness) algorithm, which makes decisions for adjacency + * and orientation using a combination of conditional independence testing, judgments of nonlinear + * adjacency, and pairwsie orientation due to non-Gaussianity. The reference is this: + *

Sanchez-Romero, R., Ramsey, J. D., Zhang, K., Glymour, M. R., Huang, B., and Glymour, C. + * (2019). Estimating feedforward and feedback effective connections from fMRI time series: Assessments + * of statistical methods. Network Neuroscience, 3(2), 274-30

+ * + *

Some adjustments have been made in some ways from that version, and some additional pairwise options + * have been added from this reference:

+ * + *

Hyvärinen, A., and Smith, S. M. (2013). Pairwise likelihood ratios for estimation of non-Gaussian structural + * equation models. Journal of Machine Learning Research, 14(Jan), 111-152.

+ * + *

This method (and the Hyvarinen and Smith methods) make the assumption that the data are generated by * a linear, non-Gaussian causal process and attempts to recover the causal graph for that process. They * do not attempt to recover the parametrization of this graph; for this a separate estimation algorithm * would be needed, such as linear regression regressing each node onto its parents. A further assumption @@ -61,7 +66,8 @@ * orientation methods, since they orient with respect only to the two variables at the endpoints of an edge * and so are happy with all other variables being considered latent with respect to that single edge. However, * if the built-in adjacency search is used (FAS-Stable), the existence of latents will throw this method - * off. + * off.

+ * *

* As was shown in the Hyvarinen and Smith paper above, FASK works quite well even if the graph contains * feedback loops in most configurations, including 2-cycles. 2-cycles can be detected fairly well if the @@ -123,6 +129,7 @@ * --faskAdjacencyMethod 1 --depth -1 --test sem-bic-test --score sem-bic-score --semBicRule 1 * --penaltyDiscount 2 --skewEdgeThreshold 0.3 --faskLeftRightRule 1 --faskDelta -0.3 * --twoCycleScreeningThreshold 0 --orientationAlpha 0.1 -structurePrior 0 + *

* * @author Joseph Ramsey */ From 5aeaeca5aceddcb4ece4fa76aecd876ec0ea515f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 10:56:02 -0400 Subject: [PATCH 341/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Fask.java | 16 ++++++----- .../main/java/edu/cmu/tetrad/search/Fci.java | 27 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 7d05a4fe94..8bb1fcf60e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -135,14 +135,18 @@ */ public final class Fask implements IGraphSearch { - // The method to use for finding the adjacencies. + /** + * The method to use for finding the initial adjacencies. + */ public enum AdjacencyMethod {FAS_STABLE, FGES, EXTERNAL_GRAPH, NONE} - // The left-right rule to use. Options include the FASK left-right rule and three left-right rules - // from the Hyvarinen and Smith pairwise orientation paper: Robust Skew, Skew, and Tanh. In that - // paper, "empirical" versions were given in which the variables are multiplied through by the - // signs of the skewnesses; we follow this advice here (with good results). These others are provided - // for comparison; in general they are quite good. + /** + * The left-right rule to use. Options include the FASK left-right rule and three left-right rules + * from the Hyvarinen and Smith pairwise orientation paper: Robust Skew, Skew, and Tanh. In that + * paper, "empirical" versions were given in which the variables are multiplied through by the + * signs of the skewnesses; we follow this advice here (with good results). These others are provided + * for those who prefer them. + */ public enum LeftRight {FASK1, FASK2, RSKEW, SKEW, TANH} // The score to be used for the FAS adjacency search. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 49cbf2aaa6..b2bbc4a5c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -37,18 +37,29 @@ import java.util.Set; /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

- * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + *

Implements the Fast Causal Inference (FCI) algorithm due to Peter Spirtes, which addressed + * the case where latent common causes cannot be assumed not to exist with respect to the data set + * being analyzed. That is, it is assumed that there may be variables that are not included in the + * data that nonetheless may be causes of two or more variables that are included in data.

+ * + *

Two alternatives are provided for doing the final orientation step, one due to Peter Spirtes, + * which is arrow complete, and another due to Jiji Zhang, which is arrow and tail complete.

+ * + *

This algorithm, with the Spirtes final orientation rules, was given in an earlier version of + * this book:

+ * + *

Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + * prediction, and search. MIT press.

+ * + *

The algorithm with the Zhang final orintation rules was given in this reference:

+ * + *

Zhang, J. (2008). On the completeness of orientation rules for causal discovery in the presence + * of latent confounders and selection bias. Artificial Intelligence, 172(16-17), 1873-1896.

* * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 - * @author Joseph Ramsey * @author Choh-Man Teng + * @author josephramsey */ public final class Fci implements IGraphSearch { private SepsetMap sepsets; From 067f6023bf1f775294a74ee7b3e6169c173557b4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 11:25:07 -0400 Subject: [PATCH 342/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algcomparison/algorithm/multi/FaskVote.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/Cstar.java | 4 +++- .../src/main/java/edu/cmu/tetrad/search/Fask.java | 4 ++-- .../search/{ => work_in_progress}/FaskVote.java | 11 ++++++++++- 4 files changed, 16 insertions(+), 5 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/FaskVote.java (89%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java index 28dd6e0199..0b499d74ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java @@ -70,7 +70,7 @@ public Graph search(List dataSets, Parameters parameters) { _dataSets.add((DataSet) d); } - edu.cmu.tetrad.search.FaskVote search = new edu.cmu.tetrad.search.FaskVote(_dataSets, this.score, this.test); + edu.cmu.tetrad.search.work_in_progress.FaskVote search = new edu.cmu.tetrad.search.work_in_progress.FaskVote(_dataSets, this.score, this.test); search.setKnowledge(this.knowledge); return search.search(parameters); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index 63793a9774..a2b065af3a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -425,7 +425,9 @@ public Graph makeGraph(List records) { return graph; } - // A single record in the returned table. + /** + * A single record in the returned table for CSTaR. + */ public static class Record implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 8bb1fcf60e..3540d9564e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -136,12 +136,12 @@ public final class Fask implements IGraphSearch { /** - * The method to use for finding the initial adjacencies. + * The method to use for finding the initial adjacencies for FASK. */ public enum AdjacencyMethod {FAS_STABLE, FGES, EXTERNAL_GRAPH, NONE} /** - * The left-right rule to use. Options include the FASK left-right rule and three left-right rules + * The left-right rule to use for FASK. Options include the FASK left-right rule and three left-right rules * from the Hyvarinen and Smith pairwise orientation paper: Robust Skew, Skew, and Tanh. In that * paper, "empirical" versions were given in which the variables are multiplied through by the * signs of the skewnesses; we follow this advice here (with good results). These others are provided diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java similarity index 89% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java index 08090f3c28..0e931799d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.algcomparison.algorithm.multi.Images; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; @@ -8,6 +8,7 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.Fask; import edu.cmu.tetrad.util.Parameters; import java.util.ArrayList; @@ -16,6 +17,14 @@ import static edu.cmu.tetrad.util.Params.*; /** + *

Runs IMaGES on a list of algorithms and then produces a graph over the + * ImaGES adjacencies where each edge orientation is voted on by running FASK on each + * dataset in turn and voting on edge orientation.

+ * + *

Moving this to the work_in_progress directory because this functionality + * can be generalized to arbitrary GraphSearch algorithms, not just FASK, given + * an adjacency graph, as an alternative to bootstrapping.

+ * * @author Madelyn Glymour * @author Joseph Ramsey 9/5/2020 */ From ff87f6d386270166c941ac8065bbb3ad2c7e9358 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 11:46:03 -0400 Subject: [PATCH 343/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algorithm/multi/FasLofs.java | 4 +-- .../algorithm/multi/FaskLofsConcatenated.java | 4 +-- .../algorithm/multi/FaskVote.java | 2 ++ .../{ => work_in_progress}/FasLofs.java | 25 ++++++++++++++++--- 4 files changed, 28 insertions(+), 7 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/FasLofs.java (83%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java index bdda1f3c3f..3c121c6e5e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java @@ -33,14 +33,14 @@ public FasLofs(Lofs.Rule rule) { this.rule = rule; } - private Graph getGraph(edu.cmu.tetrad.search.FasLofs search) { + private Graph getGraph(edu.cmu.tetrad.search.work_in_progress.FasLofs search) { return search.search(); } @Override public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - edu.cmu.tetrad.search.FasLofs search = new edu.cmu.tetrad.search.FasLofs((DataSet) dataSet, this.rule); + edu.cmu.tetrad.search.work_in_progress.FasLofs search = new edu.cmu.tetrad.search.work_in_progress.FasLofs((DataSet) dataSet, this.rule); search.setDepth(parameters.getInt(Params.DEPTH)); search.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); search.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java index ded02c1fd5..3e99674be8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.FasLofs; +import edu.cmu.tetrad.search.work_in_progress.FasLofs; import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -47,7 +47,7 @@ public Graph search(List dataModels, Parameters parameters) { DataSet dataSet = DataUtils.concatenate(dataSets); - edu.cmu.tetrad.search.FasLofs search = new FasLofs(dataSet, this.rule); + FasLofs search = new FasLofs(dataSet, this.rule); search.setDepth(parameters.getInt(Params.DEPTH)); search.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); search.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java index 0b499d74ac..2f619a118d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java @@ -8,6 +8,7 @@ import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; import edu.cmu.tetrad.annotation.AlgType; 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; @@ -36,6 +37,7 @@ dataType = DataType.Continuous ) @Bootstrapping +@Experimental public class FaskVote implements MultiDataSetAlgorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java similarity index 83% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java index 679677e646..a245132468 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java @@ -19,12 +19,16 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.search.Fas; +import edu.cmu.tetrad.search.Fask; +import edu.cmu.tetrad.search.IGraphSearch; +import edu.cmu.tetrad.search.Lofs; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; @@ -33,11 +37,26 @@ import java.util.Collections; /** - * Fast adjacency search followed by robust skew orientation. Checks are done for adding + *

Runs Fast Adjacency Search (FAS) and then orients each edge using the robust + * skew orientation algorithm. Checks are done for adding * two-cycles. The two-cycle checks do not require non-Gaussianity. The robust skew - * orientation of edges left or right does. + * orientation of edges left or right does.

+ * + *

Moving this to the work_in_progress package because the functionality can be + * generalized. Instead of hard-coding FAS, an arbitrary algorithm can be used + * to obtain adjacencies. Instead of hard-coding robust skew, and arbitrary algorithm + * can be used to to pairwise orientation. Instead of orienting all edges, an + * option can be given to just orient the edges that are unoriented in the input + * graph (see, e.g., PC LiNGAM). This was an early attempt at this. For PC-LiNGAM, + * see this paper:

+ * + *

Hoyer, P. O., Hyvarinen, A., Scheines, R., Spirtes, P. L., Ramsey, J., Lacerda, G., + * & Shimizu, S. (2012). Causal discovery of linear acyclic models with arbitrary + * distributions. arXiv preprint arXiv:1206.3260.

* * @author Joseph Ramsey + * @see Fas + * @see Fask */ public final class FasLofs implements IGraphSearch { From c2a98819836bde05f51e44b9cdb3ac21a9e5248f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 11:52:02 -0400 Subject: [PATCH 344/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/graph/GraphUtils.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/BFci.java | 5 +---- .../src/main/java/edu/cmu/tetrad/search/Fci.java | 2 ++ .../main/java/edu/cmu/tetrad/search/FciMax.java | 13 +++++++------ .../src/main/java/edu/cmu/tetrad/search/GFci.java | 5 +---- .../main/java/edu/cmu/tetrad/search/GraspFci.java | 5 +---- .../src/main/java/edu/cmu/tetrad/search/Rfci.java | 1 + .../main/java/edu/cmu/tetrad/search/SpFci.java | 5 +---- .../java/edu/cmu/tetrad/search/SvarFciOrient.java | 1 + .../edu/cmu/tetrad/search/utils/DagToPag.java | 1 - .../cmu/tetrad/search/{ => utils}/FciOrient.java | 15 ++++++++++++--- .../edu/cmu/tetrad/search/utils/TsDagToPag.java | 1 - 12 files changed, 28 insertions(+), 28 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/FciOrient.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index 55153b698a..0c080648ab 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -22,7 +22,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge.Property; -import edu.cmu.tetrad.search.FciOrient; +import edu.cmu.tetrad.search.utils.FciOrient; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 626e2d501e..2bba7bc863 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -25,10 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.utils.SepsetProducer; -import edu.cmu.tetrad.search.utils.SepsetsGreedy; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index b2bbc4a5c4..817b187148 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.FciOrient; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.MillisecondTimes; @@ -60,6 +61,7 @@ * @author Alex Smith, December 2008 * @author Choh-Man Teng * @author josephramsey + * @see FciOrient */ public final class Fci implements IGraphSearch { private SepsetMap sepsets; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index 4760f368f5..4250cf6996 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.FciOrient; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsPossibleDsep; import edu.cmu.tetrad.search.utils.SepsetsSet; @@ -34,14 +35,14 @@ import java.util.concurrent.RecursiveTask; /** - * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + *

Modifies FCI to do orientation of unshielded colliders (X*-*Y*-*Z with X and Z not adjacent) + * using the max-P rule (see the PC-Max algorithm). This reference is relevant:

+ * + *

Raghu, V. K., Zhao, W., Pu, J., Leader, J. K., Wang, R., Herman, J., ... & Wilson, D. O. + * (2019). Feasibility of lung cancer prediction from low-dose CT scan and smoking factors using + * causal models. Thorax, 74(7), 643-649.

* - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 * @author Joseph Ramsey - * @author Choh-Man Teng * @see Fci */ public final class FciMax implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index 462332de4e..c2a76b8071 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -26,10 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.utils.SepsetProducer; -import edu.cmu.tetrad.search.utils.SepsetsGreedy; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; 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 e9226e0b23..8837255d33 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 @@ -26,10 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.utils.SepsetProducer; -import edu.cmu.tetrad.search.utils.SepsetsGreedy; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 1640f767cd..846786926b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.FciOrient; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.search.utils.SepsetsSet; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 67db2decfd..0991b38acd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -27,10 +27,7 @@ import edu.cmu.tetrad.search.score.MagSemBicScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.utils.SepsetProducer; -import edu.cmu.tetrad.search.utils.SepsetsGreedy; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 24d2562cc6..5b57e6ae7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -27,6 +27,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; +import edu.cmu.tetrad.search.utils.FciOrient; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagToPag.java index efd036ae7e..75cdfbd040 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagToPag.java @@ -23,7 +23,6 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.FciOrient; import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java index 5d97dbe829..c2ffed1afa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java @@ -18,11 +18,14 @@ // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.Fci; +import edu.cmu.tetrad.search.GFci; +import edu.cmu.tetrad.search.Rfci; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; @@ -32,20 +35,26 @@ import java.util.*; /** - *

This class performs the final orientation steps of the FCI algorithms. - * There are two versions of these final orientation steps, one due to + *

Performs the final orientation steps of the FCI algorithms, which + * is a useful tool to use in a variety of FCI-like algorithms.

+ * + *

There are two versions of these final orientation steps, one due to * Peter Spirtes (the original, in Causation, Prediction and Search), * which is arrow complete, and the other which Jiji Zhang worked out * in his Ph.D. dissertation, which is both arrow and tail complete. The * references for these are as follows.

+ * *

Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). * Causation, prediction, and search. MIT press.

+ * *

Zhang, J. (2008). On the completeness of orientation rules for causal * discovery in the presence of latent confounders and selection bias. * Artificial Intelligence, 172(16-17), 1873-1896.

+ * *

These final rules are used in all algorithms in Tetrad that * follow and refine the FCI algorithm--for example, the GFCI and RFCI * algorihtms.

+ * *

We've made the methods for each of the separate rules publicly * accessible in case someone wants to use the individual rules in the * context of their own algorithms.

diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java index a6ae1e0f2b..206b8f2329 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fci; -import edu.cmu.tetrad.search.FciOrient; import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; From a8b6362a9aace8333152341f7f9d3f24cb183e25 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 12:01:38 -0400 Subject: [PATCH 345/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Bpc.java | 2 ++ .../main/java/edu/cmu/tetrad/search/Fges.java | 29 ++++++++++++------- .../java/edu/cmu/tetrad/search/FgesMb.java | 5 ++-- .../main/java/edu/cmu/tetrad/search/Fofc.java | 14 +++++++-- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index 78628b72a1..c6966fbe2d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -54,6 +54,8 @@ * Communications of ACM 16, 575-577.

* * @author Ricardo Silva + * @see Fofc + * @see Ftfc */ public final class Bpc { private boolean outputMessage; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 5367e61263..3ff8da9912 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -45,21 +45,30 @@ import static org.apache.commons.math3.util.FastMath.min; /** - * FGES is an implementation of the GES algorithm, as specified in - * Chickering (2002) "Optimal structure identification with greedy search" - * Journal of Machine Learning Research. It works for both BayesNets and SEMs. - *

- * To speed things up, it has been assumed that variables X and Y with zero + *

Imlements the Greedy Equivalence Search (GES) algorithm, originally due to + * Chris Meek but developed significantly by Max Chickering, with some + * optimizations that allow it to scale accurately to thousands of variables + * for the sparse case.

+ * + *

Specificlly, FGES is an implementation of the GES algorithm as specified + * in this paper:

+ + *

Chickering (2002) "Optimal structure identification with greedy search" + * Journal of Machine Learning Research.

+ * + *

It works for both BayesNets and SEMs.

+ * + *

To speed things up, it has been assumed that variables X and Y with zero * correlation do not correspond to edges in the graph. This is a restricted * form of the heuristicSpeedup assumption, something GES does not assume. This * the graph. This is a restricted form of the heuristicSpeedup assumption, * something GES does not assume. This heuristicSpeedup assumption needs to be - * explicitly turned on using setHeuristicSpeedup(true). - *

- * A number of other optimizations were added 5/2015. See code for details. + * explicitly turned on using setHeuristicSpeedup(true).

+ * + *

A number of other optimizations were also. See code for details.

* - * @author Ricardo Silva, Summer 2003 - * @author Joseph Ramsey, Revisions 5/2015 + * @author Ricardo Silva + * @author josephramsey */ public final class Fges implements IGraphSearch, DagScorer { private final Set emptySet = new HashSet<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index da9516393d..25a7a739a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -39,12 +39,13 @@ import java.util.concurrent.*; /** - * This code restricts the FGES algorithm to the operations needed just + *

Restricts the FGES algorithm (see) to the operations needed just * to find the graph over the Markov blanket of a variable X (or a graph * over the Markov blankets of a list of variables X1,..,Xn), together - * with the target X (or, respectively, the targets X1,...,Xn). + * with the target X (or, respectively, the targets X1,...,Xn).

* * @author josephramsey + * @see Fges */ public final class FgesMb { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index 76025e57c7..d837e7e8cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -37,11 +37,19 @@ /** - * Implements FindOneFactorCluster by Erich Kummerfeld (adaptation of a two factor - * quartet algorithm to a one factor tetrad algorithm). + *

Implements the Find One Factor Clusters (FOFC) algorithm by Erich Kummerfeld, which + * uses reasoning about vanishing tetrads of algorithms to infer clusters of the + * measured variables in a dataset that each be explained by a single latent variable. + * A reference is the following

* - * @author Joseph Ramsey + *

Kummerfeld, E., & Ramsey, J. (2016, August). Causal clustering for 1-factor measurement + * models. In Proceedings of the 22nd ACM SIGKDD international conference on knowledge + * discovery and data mining (pp. 1655-1664).

+ * + * @author josephramsey * @author erichkummerfeld + * @see Ftfc + * @see Bpc */ public class Fofc { public enum Algorithm {SAG, GAP} From 0b0ee157899c2c9888be1fda1292439bccb47830 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 12:21:56 -0400 Subject: [PATCH 346/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Fofc.java | 19 +- .../main/java/edu/cmu/tetrad/search/Ftfc.java | 385 +++++++++--------- 2 files changed, 215 insertions(+), 189 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index d837e7e8cd..f2e931e6ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -46,12 +46,29 @@ * models. In Proceedings of the 22nd ACM SIGKDD international conference on knowledge * discovery and data mining (pp. 1655-1664).

* - * @author josephramsey + *

The algorithm employs tests of vanishing tetrads (list of 4 variables that follow + * a certain pattern in the exchangeability of latent paths with respect to the data). + * The notion of vanishng tetrads is old one but is explained in this book:

+ * + *

Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + * prediction, and search. MIT press.

+ * + * @author peterspirtes * @author erichkummerfeld + * @author josephramsey * @see Ftfc * @see Bpc */ public class Fofc { + + /** + * Gives the options to be used in FOFC to sort through the various possibilities + * for forming clusters to find the best options. SAG (Seed and Grow) looks + * for good seed clusters and then grows them by adding one variable at a time. + * GAP (Grow and Pick) grows out all the cluster initially and then just + * picks from among these. SAG is generally faster; GAP is generally slower but + * more accurate. + */ public enum Algorithm {SAG, GAP} private final CorrelationMatrix corr; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 137ec4d89c..d93bba1a33 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -38,22 +38,36 @@ /** - * Implements FindOneFactorCluster by Erich Kummerfeld (adaptation of a two factor - * sextet algorithm to a one factor IntSextad algorithm). + *

Implements the Find Two Factor Clusters (FOFC) algorithm by Erich Kummerfeld + * and Peter Spirtes, which uses reasoning about vanishing tetrads of algorithms to + * infer clusters of the measured variables in a dataset that each be explained by + * a single latent variable. A reference for the one-factor versiono of the algorithm + * (FOFC) is the following

* - * @author Joseph Ramsey + *

Kummerfeld, E., & Ramsey, J. (2016, August). Causal clustering for 1-factor measurement + * models. In Proceedings of the 22nd ACM SIGKDD international conference on knowledge + * discovery and data mining (pp. 1655-1664).

+ * + *

The two-factor version of the algorithm substitutes sextad tests for + * tetrad tests and searches for clusters of at leat 6 variables that can be + * explained by two latent factors by calculating vanishing sextads.

+ * + * @author peterspirtes * @author erichkummerfeld + * @author josephramsey + * @see Fofc + * @see Bpc */ public class Ftfc { - public Algorithm getAlgorithm() { - return this.algorithm; - } - - public void setAlgorithm(Algorithm algorithm) { - this.algorithm = algorithm; - } - + /** + * Gives the options to be used in FOFC to sort through the various possibilities + * for forming clusters to find the best options. SAG (Seed and Grow) looks + * for good seed clusters and then grows them by adding one variable at a time. + * GAP (Grow and Pick) grows out all the cluster initially and then just + * picks from among these. SAG is generally faster; GAP is generally slower but + * more accurate. + */ public enum Algorithm {SAG, GAP} private final CorrelationMatrix corr; @@ -72,7 +86,7 @@ public enum Algorithm {SAG, GAP} private List> clusters; private boolean verbose; - private Algorithm algorithm = Algorithm.GAP; + private final Algorithm algorithm; /** * Conctructor. @@ -182,102 +196,102 @@ private Set> estimateClustersSAG() { } - // renjiey - private int findFrequentestIndex(Integer[] outliers) { - Map map = new HashMap<>(); - - for (Integer outlier : outliers) { - if (map.containsKey(outlier)) { - map.put(outlier, map.get(outlier) + 1); - } else { - map.put(outlier, 1); - } - } - - Set> set = map.entrySet(); - Iterator> it = set.iterator(); - int nums = 0;// how many times variable occur - int key = 0;// the number occur the most times - - while (it.hasNext()) { - Map.Entry entry = it.next(); - if (entry.getValue() > nums) { - nums = entry.getValue(); - key = entry.getKey(); - } - } - - return (key); - } - - // This is the main function. It remove variables in the data such that the remaining correlation matrix - // does not contain extreme value - // Inputs: correlation matrix, upper and lower bound for unacceptable correlations - // Output: and dynamic array of removed variables - // renjiey - private ArrayList removeVariables(Matrix correlationMatrix, double lowerBound, double upperBound, - double percentBound) { - Integer[] outlier = new Integer[correlationMatrix.rows() * (correlationMatrix.rows() - 1)]; - int count = 0; - for (int i = 2; i < (correlationMatrix.rows() + 1); i++) { - for (int j = 1; j < i; j++) { - - if ((abs(correlationMatrix.get(i - 1, j - 1)) < lowerBound) - || (abs(correlationMatrix.get(i - 1, j - 1)) > upperBound)) { - outlier[count * 2] = i; - outlier[count * 2 + 1] = j; - - } else { - outlier[count * 2] = 0; - outlier[count * 2 + 1] = 0; - } - count = count + 1; - } - } - - //find out the variables that should be deleted - ArrayList removedVariables = new ArrayList<>(); - - // Added the percent bound jdramsey - while (outlier.length > 1 && removedVariables.size() < percentBound * correlationMatrix.rows()) { - //find out the variable that occurs most frequently in outlier - int worstVariable = findFrequentestIndex(outlier); - if (worstVariable > 0) { - removedVariables.add(worstVariable); - } - - //remove the correlations having the bad variable (change the relevant variables to 0) - for (int i = 1; i < outlier.length + 1; i++) { - if (outlier[i - 1] == worstVariable) { - outlier[i - 1] = 0; - - if (i % 2 != 0) { - outlier[i] = 0; - } else { - outlier[i - 2] = 0; - } - } - } - - //delete zero elements in outlier - outlier = removeZeroIndex(outlier); - } - - log(removedVariables.size() + " variables removed: " + variablesForIndices(removedVariables), true); - - return (removedVariables); - } - - // renjiey - private Integer[] removeZeroIndex(Integer[] outlier) { - List list = new ArrayList<>(Arrays.asList(outlier)); - for (Integer element : outlier) { - if (element < 1) { - list.remove(element); - } - } - return list.toArray(new Integer[1]); - } +// // renjiey +// private int findFrequentestIndex(Integer[] outliers) { +// Map map = new HashMap<>(); +// +// for (Integer outlier : outliers) { +// if (map.containsKey(outlier)) { +// map.put(outlier, map.get(outlier) + 1); +// } else { +// map.put(outlier, 1); +// } +// } +// +// Set> set = map.entrySet(); +// Iterator> it = set.iterator(); +// int nums = 0;// how many times variable occur +// int key = 0;// the number occur the most times +// +// while (it.hasNext()) { +// Map.Entry entry = it.next(); +// if (entry.getValue() > nums) { +// nums = entry.getValue(); +// key = entry.getKey(); +// } +// } +// +// return (key); +// } + +// // This is the main function. It removea variables in the data such that the remaining correlation matrix +// // does not contain extreme value +// // Inputs: correlation matrix, upper and lower bound for unacceptable correlations +// // Output: and dynamic array of removed variables +// // renjiey +// private ArrayList removeVariables(Matrix correlationMatrix, double lowerBound, double upperBound, +// double percentBound) { +// Integer[] outlier = new Integer[correlationMatrix.rows() * (correlationMatrix.rows() - 1)]; +// int count = 0; +// for (int i = 2; i < (correlationMatrix.rows() + 1); i++) { +// for (int j = 1; j < i; j++) { +// +// if ((abs(correlationMatrix.get(i - 1, j - 1)) < lowerBound) +// || (abs(correlationMatrix.get(i - 1, j - 1)) > upperBound)) { +// outlier[count * 2] = i; +// outlier[count * 2 + 1] = j; +// +// } else { +// outlier[count * 2] = 0; +// outlier[count * 2 + 1] = 0; +// } +// count = count + 1; +// } +// } +// +// //find out the variables that should be deleted +// ArrayList removedVariables = new ArrayList<>(); +// +// // Added the percent bound jdramsey +// while (outlier.length > 1 && removedVariables.size() < percentBound * correlationMatrix.rows()) { +// //find out the variable that occurs most frequently in outlier +// int worstVariable = findFrequentestIndex(outlier); +// if (worstVariable > 0) { +// removedVariables.add(worstVariable); +// } +// +// //remove the correlations having the bad variable (change the relevant variables to 0) +// for (int i = 1; i < outlier.length + 1; i++) { +// if (outlier[i - 1] == worstVariable) { +// outlier[i - 1] = 0; +// +// if (i % 2 != 0) { +// outlier[i] = 0; +// } else { +// outlier[i - 2] = 0; +// } +// } +// } +// +// //delete zero elements in outlier +// outlier = removeZeroIndex(outlier); +// } +// +// log(removedVariables.size() + " variables removed: " + variablesForIndices(removedVariables), true); +// +// return (removedVariables); +// } + +// // renjiey +// private Integer[] removeZeroIndex(Integer[] outlier) { +// List list = new ArrayList<>(Arrays.asList(outlier)); +// for (Integer element : outlier) { +// if (element < 1) { +// list.remove(element); +// } +// } +// return list.toArray(new Integer[1]); +// } private Set> findPurepentads(List variables) { if (variables.size() < 6) { @@ -456,7 +470,7 @@ private Set> combinePurePentads(Set> purePentads, Li } for (List c : new HashSet<>(purePentads)) { - if (_cluster.containsAll(c)) { + if (new HashSet<>(_cluster).containsAll(c)) { purePentads.remove(c); } } @@ -574,12 +588,7 @@ private Set> combinePurePentads(Set> purePentads, Li List> list = new ArrayList<>(grown); - Collections.sort(list, new Comparator>() { - @Override - public int compare(List o1, List o2) { - return o2.size() - o1.size(); - } - }); + list.sort((o1, o2) -> o2.size() - o1.size()); List all = new ArrayList<>(); @@ -785,11 +794,11 @@ private double significance(List cluster) { return 1.0 - q; } - private int dofDrton(int n) { - int dof = ((n - 2) * (n - 3)) / 2 - 2; - if (dof < 0) dof = 0; - return dof; - } +// private int dofDrton(int n) { +// int dof = ((n - 2) * (n - 3)) / 2 - 2; +// if (dof < 0) dof = 0; +// return dof; +// } private int dofHarman(int n) { int dof = n * (n - 5) / 2 + 1; @@ -879,72 +888,72 @@ private SemIm estimateClusterModel(List sextet) { return est.estimate(); } - private SemIm estimateModel(List> clusters) { - Graph g = new EdgeListGraph(); - - List upperLatents = new ArrayList<>(); - List lowerLatents = new ArrayList<>(); - - for (int i = 0; i < clusters.size(); i++) { - List cluster = clusters.get(i); - Node l1 = new GraphNode("L1." + (i + 1)); - l1.setNodeType(NodeType.LATENT); - - Node l2 = new GraphNode("L2." + (i + 1)); - l2.setNodeType(NodeType.LATENT); - - upperLatents.add(l1); - lowerLatents.add(l2); - - g.addNode(l1); - g.addNode(l2); - - for (Integer aCluster : cluster) { - Node n = this.variables.get(aCluster); - g.addNode(n); - g.addDirectedEdge(l1, n); - g.addDirectedEdge(l2, n); - } - } - - for (int i = 0; i < upperLatents.size(); i++) { - for (int j = i + 1; j < upperLatents.size(); j++) { - g.addDirectedEdge(upperLatents.get(i), upperLatents.get(j)); - g.addDirectedEdge(lowerLatents.get(i), lowerLatents.get(j)); - } - } - - for (int i = 0; i < upperLatents.size(); i++) { - for (int j = 0; j < lowerLatents.size(); j++) { - if (i == j) continue; - g.addDirectedEdge(upperLatents.get(i), lowerLatents.get(j)); - } - } - - SemPm pm = new SemPm(g); - - for (Node node : upperLatents) { - Parameter p = pm.getParameter(node, node); - p.setFixed(true); - p.setStartingValue(1.0); - } - - for (Node node : lowerLatents) { - Parameter p = pm.getParameter(node, node); - p.setFixed(true); - p.setStartingValue(1.0); - } - - SemEstimator est; - - if (this.dataModel instanceof DataSet) { - est = new SemEstimator((DataSet) this.dataModel, pm, new SemOptimizerEm()); - } else { - est = new SemEstimator((CovarianceMatrix) this.dataModel, pm, new SemOptimizerEm()); - } - - return est.estimate(); - } +// private SemIm estimateModel(List> clusters) { +// Graph g = new EdgeListGraph(); +// +// List upperLatents = new ArrayList<>(); +// List lowerLatents = new ArrayList<>(); +// +// for (int i = 0; i < clusters.size(); i++) { +// List cluster = clusters.get(i); +// Node l1 = new GraphNode("L1." + (i + 1)); +// l1.setNodeType(NodeType.LATENT); +// +// Node l2 = new GraphNode("L2." + (i + 1)); +// l2.setNodeType(NodeType.LATENT); +// +// upperLatents.add(l1); +// lowerLatents.add(l2); +// +// g.addNode(l1); +// g.addNode(l2); +// +// for (Integer aCluster : cluster) { +// Node n = this.variables.get(aCluster); +// g.addNode(n); +// g.addDirectedEdge(l1, n); +// g.addDirectedEdge(l2, n); +// } +// } +// +// for (int i = 0; i < upperLatents.size(); i++) { +// for (int j = i + 1; j < upperLatents.size(); j++) { +// g.addDirectedEdge(upperLatents.get(i), upperLatents.get(j)); +// g.addDirectedEdge(lowerLatents.get(i), lowerLatents.get(j)); +// } +// } +// +// for (int i = 0; i < upperLatents.size(); i++) { +// for (int j = 0; j < lowerLatents.size(); j++) { +// if (i == j) continue; +// g.addDirectedEdge(upperLatents.get(i), lowerLatents.get(j)); +// } +// } +// +// SemPm pm = new SemPm(g); +// +// for (Node node : upperLatents) { +// Parameter p = pm.getParameter(node, node); +// p.setFixed(true); +// p.setStartingValue(1.0); +// } +// +// for (Node node : lowerLatents) { +// Parameter p = pm.getParameter(node, node); +// p.setFixed(true); +// p.setStartingValue(1.0); +// } +// +// SemEstimator est; +// +// if (this.dataModel instanceof DataSet) { +// est = new SemEstimator((DataSet) this.dataModel, pm, new SemOptimizerEm()); +// } else { +// est = new SemEstimator((CovarianceMatrix) this.dataModel, pm, new SemOptimizerEm()); +// } +// +// return est.estimate(); +// } private List sextet(int n1, int n2, int n3, int n4, int n5, int n6) { List sextet = new ArrayList<>(); @@ -979,8 +988,8 @@ private List pentad(int n1, int n2, int n3, int n4, int n5) { private boolean vanishes(List sextet) { - PermutationGenerator gen = new PermutationGenerator(6); - int[] perm; +// PermutationGenerator gen = new PermutationGenerator(6); +// int[] perm; // while ((perm = gen.next()) != null) { // int n1 = sextet.get(perm[0]); From ccebb2f8522de9884e5ebbd4bedf54bede3b83d8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 12:26:15 -0400 Subject: [PATCH 347/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/GFci.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index c2a76b8071..c7afc57b7d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -37,14 +37,26 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - *

Implements a version of FCI that started by running the FGES algorithm and - * then correct the result to be correct for latent variables models.

+ *

Implements a modification of FCI that started by running the FGES algorithm and + * then fixes that result to be correct for latent variables models. First, colliders + * from the FGES results are copied into the final circle-circle graph, and some + * independence reasoning is used to add the remaining colliders into the graph. + * Then, the FCI final orentation rules are applied. The reference is here:

+ * *

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016.

* + *

Because the method both runs FGES (a score-based algorithm) and does + * additional checking of conditional independencies, both as part of its + * collider orientation step and also as part of the the definite discriminating + * path step in the final FCI orientation rules, both a score and a + * test need to be used to construct a GFCI algorihtm.

+ * * @author Juan Miguel Ogarrio - * @author ps7z + * @author peterspirtes * @author josephramsey + * @see Fci + * @see FciOrient */ public final class GFci implements IGraphSearch { private Graph graph; From ae2b9809862a48ea02e6958f00b507e84cd85d3a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 12:41:26 -0400 Subject: [PATCH 348/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../editor/GraphSelectionEditor.java | 2 +- .../editor/SimulationGraphEditor.java | 2 +- .../model/GeneralAlgorithmRunner.java | 2 +- .../cmu/tetradapp/model/GraphSettable.java | 2 +- .../cmu/tetradapp/model/RegressionModel.java | 2 +- .../edu/cmu/tetradapp/model/Simulation.java | 2 +- .../cmu/tetradapp/util/FinalizingEditor.java | 2 +- .../cmu/tetrad/algcomparison/Comparison.java | 2 +- .../algcomparison/algorithm/Algorithm.java | 2 +- .../algcomparison/algorithm/Algorithms.java | 2 +- .../algorithm/ExternalAlgorithm.java | 2 +- .../algorithm/FirstInflection.java | 2 +- .../algorithm/MultiDataSetAlgorithm.java | 2 +- .../tetrad/algcomparison/algorithm/StARS.java | 2 +- .../algorithm/StabilitySelection.java | 2 +- .../algcomparison/algorithm/cluster/Bpc.java | 2 +- .../algorithm/cluster/ClusterAlgorithm.java | 2 +- .../algcomparison/algorithm/cluster/Fofc.java | 2 +- .../algcomparison/algorithm/cluster/Ftfc.java | 2 +- .../algorithm/continuous/dag/LingD.java | 2 +- .../algorithm/continuous/dag/Lingam.java | 2 +- .../external/ExternalAlgorithmBNTPc.java | 2 +- .../ExternalAlgorithmBnlearnMmhc.java | 2 +- .../ExternalAlgorithmIntersection.java | 2 +- .../external/ExternalAlgorithmPcalgGes.java | 2 +- .../external/ExternalAlgorithmPcalgPc.java | 2 +- .../external/ExternalAlgorithmTetrad.java | 2 +- .../algcomparison/algorithm/mixed/Mgm.java | 2 +- .../algorithm/multi/FasLofs.java | 2 +- .../algcomparison/algorithm/multi/Fask.java | 2 +- .../algorithm/multi/FaskConcatenated.java | 2 +- .../algorithm/multi/FaskLofsConcatenated.java | 2 +- .../algorithm/multi/FaskVote.java | 2 +- .../algorithm/multi/FgesConcatenated.java | 2 +- .../algcomparison/algorithm/multi/Images.java | 2 +- .../algorithm/oracle/cpdag/Cpc.java | 2 +- .../algorithm/oracle/cpdag/Fas.java | 2 +- .../algorithm/oracle/cpdag/Fges.java | 2 +- .../algorithm/oracle/cpdag/FgesMb.java | 2 +- .../oracle/cpdag/FgesMeasurement.java | 2 +- .../algorithm/oracle/cpdag/GesMe.java | 2 +- .../algorithm/oracle/cpdag/Pc.java | 2 +- .../algorithm/oracle/cpdag/PcMax.java | 2 +- .../algorithm/oracle/cpdag/PcMb.java | 2 +- .../algorithm/oracle/cpdag/Pcd.java | 2 +- .../oracle/cpdag/SingleGraphAlg.java | 2 +- .../algorithm/oracle/pag/Bfci.java | 2 +- .../algorithm/oracle/pag/Cfci.java | 2 +- .../algorithm/oracle/pag/Fci.java | 2 +- .../algorithm/oracle/pag/FciMax.java | 2 +- .../algorithm/oracle/pag/Gfci.java | 2 +- .../algorithm/oracle/pag/GraspFci.java | 2 +- .../algorithm/oracle/pag/Rfci.java | 2 +- .../algorithm/oracle/pag/SpFci.java | 2 +- .../algorithm/oracle/pag/SvarFci.java | 2 +- .../algorithm/oracle/pag/SvarGfci.java | 2 +- .../algorithm/other/FactorAnalysis.java | 2 +- .../algcomparison/algorithm/other/Glasso.java | 2 +- .../algcomparison/algorithm/pairwise/Eb.java | 2 +- .../algorithm/pairwise/FaskPw.java | 2 +- .../algcomparison/algorithm/pairwise/R1.java | 2 +- .../algcomparison/algorithm/pairwise/R2.java | 2 +- .../algcomparison/algorithm/pairwise/R3.java | 2 +- .../algorithm/pairwise/Rskew.java | 2 +- .../algorithm/pairwise/RskewE.java | 2 +- .../algorithm/pairwise/Skew.java | 2 +- .../algorithm/pairwise/SkewE.java | 2 +- .../algorithm/pairwise/Tanh.java | 2 +- .../examples/CompareExternalAlgorithms.java | 2 +- .../examples/ExampleCompareFromFiles.java | 2 +- .../examples/ExampleCompareSimulation.java | 2 +- .../examples/ExampleCompareSimulation2.java | 2 +- .../ExampleCompareSimulationTimeSeries.java | 2 +- .../examples/ExampleNonlinearSave.java | 2 +- .../algcomparison/examples/ExampleSave.java | 2 +- .../examples/MVPCompareFromFiles.java | 2 +- .../algcomparison/examples/RunConfig.java | 2 +- .../tetrad/algcomparison/examples/Save.java | 2 +- .../examples/SaveDGSimulations.java | 2 +- .../tetrad/algcomparison/graph/Cyclic.java | 2 +- .../algcomparison/graph/ErdosRenyi.java | 2 +- .../algcomparison/graph/RandomForward.java | 2 +- .../algcomparison/graph/RandomGraph.java | 2 +- .../graph/RandomSingleFactorMim.java | 2 +- .../graph/RandomTwoFactorMim.java | 2 +- .../tetrad/algcomparison/graph/ScaleFree.java | 2 +- .../algcomparison/graph/SingleGraph.java | 2 +- .../algcomparison/independence/BdeuTest.java | 2 +- .../algcomparison/independence/CciTest.java | 2 +- .../algcomparison/independence/ChiSquare.java | 2 +- .../independence/ConditionalGaussianLRT.java | 2 +- .../independence/DSeparationTest.java | 2 +- .../independence/DiscreteBicTest.java | 2 +- .../algcomparison/independence/FisherZ.java | 2 +- .../algcomparison/independence/Gsquare.java | 2 +- .../independence/IndependenceWrapper.java | 2 +- .../algcomparison/independence/Kci.java | 2 +- .../independence/KimEtAlScoreTests.java | 2 +- .../independence/MagSemBicTest.java | 2 +- .../algcomparison/independence/Mnlrlrt.java | 2 +- .../MultinomialLogisticRegressionWald.java | 2 +- .../algcomparison/independence/Mvplrt.java | 2 +- .../independence/PositiveCorr.java | 2 +- .../independence/SemBicDTest.java | 2 +- .../independence/SemBicTest.java | 2 +- .../tetrad/algcomparison/score/BdeuScore.java | 2 +- .../tetrad/algcomparison/score/CciScore.java | 2 +- .../score/ConditionalGaussianBicScore.java | 2 +- .../algcomparison/score/DSeparationScore.java | 2 +- .../algcomparison/score/DiscreteBicScore.java | 2 +- .../tetrad/algcomparison/score/EbicScore.java | 2 +- .../algcomparison/score/FisherZScore.java | 2 +- .../algcomparison/score/KimEtAlScores.java | 2 +- .../algcomparison/score/MagSemBicScore.java | 2 +- .../score/PoissonPriorScore.java | 2 +- .../score/PositiveCorrScore.java | 2 +- .../algcomparison/score/ScoreWrapper.java | 2 +- .../algcomparison/score/SemBicScore.java | 2 +- .../score/SemBicScoreDeterministic.java | 2 +- .../score/ZhangShenBoundScore.java | 2 +- .../simulation/BayesNetSimulation.java | 2 +- .../simulation/BooleanGlassSimulation.java | 2 +- .../ConditionalGaussianSimulation.java | 2 +- .../simulation/GeneralSemSimulation.java | 2 +- .../GeneralSemSimulationSpecial1.java | 2 +- .../simulation/LeeHastieSimulation.java | 2 +- .../simulation/LinearFisherModel.java | 2 +- .../simulation/SemSimulation.java | 2 +- .../simulation/SemThenDiscretize.java | 2 +- .../algcomparison/simulation/Simulation.java | 2 +- .../algcomparison/simulation/Simulations.java | 2 +- .../simulation/StandardizedSemSimulation.java | 2 +- .../simulation/TimeSeriesSemSimulation.java | 2 +- .../algcomparison/statistic/AdjacencyFn.java | 2 +- .../algcomparison/statistic/AdjacencyFp.java | 2 +- .../algcomparison/statistic/AdjacencyFpr.java | 2 +- .../statistic/AdjacencyPrecision.java | 2 +- .../statistic/AdjacencyRecall.java | 2 +- .../algcomparison/statistic/AdjacencyTn.java | 2 +- .../algcomparison/statistic/AdjacencyTp.java | 2 +- .../algcomparison/statistic/AdjacencyTpr.java | 2 +- .../statistic/AncestorPrecision.java | 2 +- .../statistic/AncestorRecall.java | 2 +- .../statistic/AncestralPrecision.java | 2 +- .../statistic/AncestralRecall.java | 2 +- .../algcomparison/statistic/ArrowheadFn.java | 2 +- .../algcomparison/statistic/ArrowheadFp.java | 2 +- .../algcomparison/statistic/ArrowheadFpr.java | 2 +- .../statistic/ArrowheadPrecision.java | 2 +- .../ArrowheadPrecisionCommonEdges.java | 2 +- .../statistic/ArrowheadRecall.java | 2 +- .../statistic/ArrowheadRecallCommonEdges.java | 2 +- .../algcomparison/statistic/ArrowheadTn.java | 2 +- .../algcomparison/statistic/ArrowheadTp.java | 2 +- .../statistic/AverageDegreeEst.java | 2 +- .../statistic/AverageDegreeTrue.java | 2 +- .../algcomparison/statistic/BicDiff.java | 2 +- .../statistic/BicDiffPerRecord.java | 2 +- .../algcomparison/statistic/BicEst.java | 2 +- .../algcomparison/statistic/BicTrue.java | 2 +- .../statistic/BidirectedEst.java | 2 +- .../algcomparison/statistic/BidirectedFP.java | 2 +- .../statistic/BidirectedLatentPrecision.java | 2 +- .../statistic/BidirectedPrecision.java | 2 +- .../statistic/BidirectedRecall.java | 2 +- .../algcomparison/statistic/BidirectedTP.java | 2 +- .../statistic/BidirectedTrue.java | 2 +- ...CommonAncestorFalseNegativeBidirected.java | 2 +- ...CommonAncestorFalsePositiveBidirected.java | 2 +- .../CommonAncestorTruePositiveBidirected.java | 2 +- ...ommonMeasuredAncestorRecallBidirected.java | 2 +- .../statistic/CorrectSkeleton.java | 2 +- .../DefiniteDirectedPathPrecision.java | 2 +- .../statistic/DefiniteDirectedPathRecall.java | 2 +- .../algcomparison/statistic/DensityEst.java | 2 +- .../algcomparison/statistic/DensityTrue.java | 2 +- .../statistic/ElapsedCpuTime.java | 2 +- .../statistic/FalseNegativesAdjacencies.java | 2 +- .../statistic/FalsePositiveAdjacencies.java | 2 +- .../statistic/GraphExactlyRight.java | 2 +- ...CommonAncestorFalseNegativeBidirected.java | 2 +- ...CommonAncestorFalsePositiveBidirected.java | 2 +- .../LatentCommonAncestorRecallBidirected.java | 2 +- ...tCommonAncestorTruePositiveBidirected.java | 2 +- .../algcomparison/statistic/LegalPag.java | 2 +- .../statistic/MathewsCorrAdj.java | 2 +- .../statistic/MathewsCorrArrow.java | 2 +- .../statistic/MaximalityCondition.java | 2 +- .../NoAlmostCyclicPathsCondition.java | 2 +- .../NoAlmostCyclicPathsInMagCondition.java | 2 +- .../statistic/NoCyclicPathsCondition.java | 2 +- .../NoCyclicPathsInMagCondition.java | 2 +- .../statistic/NoSemidirectedPrecision.java | 2 +- .../statistic/NoSemidirectedRecall.java | 2 +- .../statistic/NodesInCyclesPrecision.java | 2 +- .../statistic/NodesInCyclesRecall.java | 2 +- .../statistic/NonancestorPrecision.java | 2 +- .../statistic/NonancestorRecall.java | 2 +- .../statistic/NumAmbiguousTriples.java | 2 +- .../NumBidirectedBothNonancestorAncestor.java | 2 +- .../statistic/NumBidirectedEdgesEst.java | 2 +- .../statistic/NumBidirectedEdgesTrue.java | 2 +- .../algcomparison/statistic/NumColoredDD.java | 2 +- .../algcomparison/statistic/NumColoredNL.java | 2 +- .../algcomparison/statistic/NumColoredPD.java | 2 +- .../algcomparison/statistic/NumColoredPL.java | 2 +- .../NumCommonMeasuredAncestorBidirected.java | 2 +- ...mpatibleDefiniteDirectedEdgeAncestors.java | 2 +- .../NumCompatibleDirectedEdgeConfounded.java | 2 +- ...NumCompatibleDirectedEdgeNonAncestors.java | 2 +- .../statistic/NumCompatibleEdges.java | 2 +- ...mpatiblePossiblyDirectedEdgeAncestors.java | 2 +- ...tiblePossiblyDirectedEdgeNonAncestors.java | 2 +- .../NumCompatibleVisibleAncestors.java | 2 +- .../NumCompatibleVisibleNonancestors.java | 2 +- .../statistic/NumCorrectDDAncestors.java | 2 +- .../statistic/NumCorrectPDAncestors.java | 2 +- .../statistic/NumCorrectVisibleAncestors.java | 2 +- .../statistic/NumDefinitelyDirected.java | 2 +- .../NumDefinitelyNotDirectedPaths.java | 2 +- .../statistic/NumDirectedEdgeAncestors.java | 2 +- ...NumDirectedEdgeBnaMeasuredCounfounded.java | 2 +- .../NumDirectedEdgeNoMeasureAncestors.java | 2 +- .../NumDirectedEdgeNotAncNotRev.java | 2 +- .../statistic/NumDirectedEdgeReversed.java | 2 +- .../statistic/NumDirectedEdgeVisible.java | 2 +- .../statistic/NumDirectedEdges.java | 2 +- .../statistic/NumDirectedPathsEst.java | 2 +- .../statistic/NumDirectedPathsTrue.java | 2 +- .../NumDirectedShouldBePartiallyDirected.java | 2 +- .../statistic/NumIncorrectDDAncestors.java | 2 +- .../statistic/NumIncorrectPDAncestors.java | 2 +- .../NumIncorrectVisibleAncestors.java | 2 +- .../NumLatentCommonAncestorBidirected.java | 2 +- .../statistic/NumNondirectedEdges.java | 2 +- .../statistic/NumPartiallyOrientedEdges.java | 2 +- .../statistic/NumPossiblyDirected.java | 2 +- .../statistic/NumUndirectedEdges.java | 2 +- .../statistic/NumVisibleEst.java | 2 +- .../statistic/NumberOfEdgesEst.java | 2 +- .../statistic/NumberOfEdgesTrue.java | 2 +- .../statistic/PagAdjacencyPrecision.java | 2 +- .../statistic/PagAdjacencyRecall.java | 2 +- .../statistic/ParameterColumn.java | 2 +- .../statistic/PercentAmbiguous.java | 2 +- .../statistic/PercentBidirectedEdges.java | 2 +- ...ortionSemidirectedPathsNotReversedEst.java | 2 +- ...rtionSemidirectedPathsNotReversedTrue.java | 2 +- .../statistic/SemidirectedPrecision.java | 2 +- .../statistic/SemidirectedRecall.java | 2 +- .../tetrad/algcomparison/statistic/Shd.java | 2 +- .../algcomparison/statistic/Statistic.java | 2 +- .../algcomparison/statistic/Statistics.java | 2 +- .../statistic/TailPrecision.java | 2 +- .../algcomparison/statistic/TailRecall.java | 2 +- .../TrueDagFalseNegativesArrows.java | 2 +- .../statistic/TrueDagFalseNegativesTails.java | 2 +- .../statistic/TrueDagFalsePositiveArrow.java | 2 +- .../statistic/TrueDagFalsePositiveTails.java | 2 +- .../statistic/TrueDagPrecisionArrow.java | 2 +- .../statistic/TrueDagPrecisionTails.java | 2 +- .../statistic/TrueDagRecallArrows.java | 2 +- .../statistic/TrueDagRecallTails.java | 2 +- .../statistic/TrueDagTruePositiveArrow.java | 2 +- ...agTruePositiveDirectedPathNonancestor.java | 2 +- .../statistic/TrueDagTruePositiveTails.java | 2 +- .../statistic/TwoCycleFalseNegative.java | 2 +- .../statistic/TwoCycleFalsePositive.java | 2 +- .../statistic/TwoCyclePrecision.java | 2 +- .../statistic/TwoCycleRecall.java | 2 +- .../statistic/TwoCycleTruePositive.java | 2 +- .../statistic/utils/AdjacencyConfusion.java | 2 +- .../statistic/utils/ArrowConfusion.java | 2 +- .../statistic/utils/BidirectedConfusion.java | 2 +- .../statistic/utils/SimulationPath.java | 2 +- .../statistic/utils/TailConfusion.java | 2 +- .../algcomparison/utils/ParameterValues.java | 2 +- .../tetrad/algcomparison/utils/TakesData.java | 2 +- .../utils/TakesExternalGraph.java | 2 +- .../java/edu/cmu/tetrad/data/DataType.java | 2 +- .../java/edu/cmu/tetrad/data/IDataReader.java | 2 +- .../LoadContinuousDataAndGraphs.java | 2 +- .../LoadContinuousDataAndSingleGraph.java | 2 +- .../LoadContinuousDataSmithSim.java | 2 +- .../data/simulation/LoadDataAndGraphs.java | 2 +- .../LoadDataFromFileWithoutGraph.java | 2 +- .../main/java/edu/cmu/tetrad/search/BFci.java | 12 +++++------ .../main/java/edu/cmu/tetrad/search/GFci.java | 7 +++++++ .../java/edu/cmu/tetrad/search/GraspFci.java | 18 ++++++++-------- .../main/java/edu/cmu/tetrad/search/Sp.java | 14 +++++++++---- .../java/edu/cmu/tetrad/search/SpFci.java | 21 ++++++++++++------- .../java/edu/cmu/tetrad/search/test/Kci.java | 2 +- .../edu/cmu/tetrad/search/utils/AdTrees.java | 2 +- .../edu/cmu/tetrad/simulation/Vicinity.java | 2 +- .../conditions/BryanSensitivityStudy.java | 2 +- .../study/examples/conditions/Condition1.java | 2 +- .../study/examples/conditions/Condition2.java | 2 +- .../conditions/ExampleCompareFromFiles.java | 2 +- .../conditions/ExampleCompareSimulation.java | 2 +- .../ExampleCompareSimulationDiscrete.java | 2 +- .../conditions/ExampleFirstInflection.java | 2 +- .../examples/conditions/ExampleSave.java | 2 +- .../examples/conditions/ExampleStars.java | 2 +- .../examples/conditions/LingamStudy.java | 2 +- .../tetrad/study/performance/Comparison.java | 2 +- .../tetrad/study/performance/Comparison2.java | 2 +- .../study/performance/ComparisonResult.java | 2 +- .../study/performance/ComparisonScript.java | 2 +- .../study/performance/ExploreComparison.java | 2 +- .../edu/cmu/tetrad/util/Experimental.java | 2 +- .../edu/cmu/tetrad/util/ParamDescription.java | 2 +- .../cmu/tetrad/util/ParamDescriptions.java | 2 +- .../java/edu/cmu/tetrad/util/Parameters.java | 2 +- .../java/edu/cmu/tetrad/test/FaskGraphs.java | 2 +- .../LoadContinuousDataAndSingleGraph.java | 2 +- .../LoadContinuousDataAndSingleGraphKun.java | 2 +- .../test/LoadContinuousDataSmithSim.java | 2 +- .../edu/cmu/tetrad/test/LoadMadelynData.java | 2 +- .../edu/cmu/tetrad/test/SpecialDataClark.java | 2 +- .../test/SpecialExampleSimulationClark.java | 2 +- .../cmu/tetrad/test/SpecialGraphClark.java | 2 +- .../test/TestAutisticClassification.java | 2 +- .../TestConditionalGaussianSimulation.java | 2 +- .../java/edu/cmu/tetrad/test/TestCopy.java | 2 +- .../tetrad/test/TestFaskSimpleSimulaton.java | 2 +- .../tetrad/test/TestGenerateMixedData.java | 2 +- .../cmu/tetrad/test/TestImagesSimulation.java | 2 +- .../tetrad/test/TestKunMeasurementError.java | 2 +- .../cmu/tetrad/test/TestSimulatedFmri.java | 2 +- .../cmu/tetrad/test/TestSimulatedFmri2.java | 2 +- .../cmu/tetrad/test/TestSimulatedFmri3.java | 2 +- 331 files changed, 371 insertions(+), 353 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java index 64afebd6f4..67fb6f1b02 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java @@ -55,7 +55,7 @@ /** * Lets the user select a subgraph of a possible large graph and display it. * - * @author jdramsey + * @author josephramsey * @author Zhou Yuan */ public class GraphSelectionEditor extends JPanel implements GraphEditable, TripleClassifier { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationGraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationGraphEditor.java index 8e10a2cc6c..8a6f45a895 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationGraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationGraphEditor.java @@ -33,7 +33,7 @@ * Displays a list of graphs with tabs to select among them, similar to the Data * Editor. For use in displaying simulations. * - * @author jdramsey + * @author josephramsey */ public final class SimulationGraphEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index 4b196e527f..53af1f5847 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -54,7 +54,7 @@ /** * Stores an algorithms in the format of the algorithm comparison API. * - * @author jdramsey + * @author josephramsey */ public class GeneralAlgorithmRunner implements AlgorithmRunner, ParamsResettable, Unmarshallable, IndTestProducer, diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSettable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSettable.java index e3f895076d..f60ec1ec0f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSettable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSettable.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.util.Parameters; /** - * @author jdramsey + * @author josephramsey */ public interface GraphSettable extends GraphSource { Parameters getParameters(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionModel.java index 6b550dd2fa..f1a7a2a805 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionModel.java @@ -5,7 +5,7 @@ /** * Methods common to regression models. * - * @author jdramsey + * @author josephramsey */ public interface RegressionModel { List getVariableNames(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java index 90bc8a49a2..e942bc107b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java @@ -40,7 +40,7 @@ * parents. It essentially stores an ordered pair of [Graph, List[DataSet]]. It * is edited by SimulationEditor. * - * @author jdramsey + * @author josephramsey */ public class Simulation extends DataWrapper implements GraphSource, MultipleGraphSource { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/FinalizingEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/FinalizingEditor.java index 1a07e11209..bdc0e4e03f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/FinalizingEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/FinalizingEditor.java @@ -4,7 +4,7 @@ * Actions an editor needs to perform before closing. If it's OK to close the * finalizeEditor method will return true; otherwise, false. * - * @author jdramsey + * @author josephramsey */ public interface FinalizingEditor { boolean finalizeEditor(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java index 83b15b1f35..0f14b2304f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java @@ -59,7 +59,7 @@ * Script to do a comparison of a list of algorithms using a list of statistics * and a list of parameters and their values. * - * @author jdramsey + * @author josephramsey * @author Daniel Malinsky */ public class Comparison { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithm.java index 48eacb6ad0..644dd0b60f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithm.java @@ -12,7 +12,7 @@ /** * Interface that algorithm must implement. * - * @author jdramsey + * @author josephramsey */ public interface Algorithm extends HasParameters, TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java index 14e7ff8435..82b4564980 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java @@ -6,7 +6,7 @@ /** * A list of algorithm to be compared. * - * @author jdramsey + * @author josephramsey */ public class Algorithms { private final List algorithms = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ExternalAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ExternalAlgorithm.java index e9017e8c0a..59041b89f6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ExternalAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ExternalAlgorithm.java @@ -10,7 +10,7 @@ /** * Tags an an algorithm that loads up external graphs for inclusion in reports. * - * @author jdramsey + * @author josephramsey */ public abstract class ExternalAlgorithm implements Algorithm { protected String path; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java index cd4285afdd..3a1ab05555 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java @@ -14,7 +14,7 @@ /** * First inflection point. * - * @author jdramsey + * @author josephramsey */ public class FirstInflection implements Algorithm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/MultiDataSetAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/MultiDataSetAlgorithm.java index 74d13d096a..29d52c7ba9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/MultiDataSetAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/MultiDataSetAlgorithm.java @@ -10,7 +10,7 @@ /** * Implements an algorithm that takes multiple data sets as input. * - * @author jdramsey + * @author josephramsey */ public interface MultiDataSetAlgorithm extends Algorithm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java index 2c0266a363..f45af3dd92 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java @@ -19,7 +19,7 @@ /** * StARS * - * @author jdramsey + * @author josephramsey */ public class StARS implements Algorithm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java index 4108585118..f70ead92c9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java @@ -20,7 +20,7 @@ /** * Stability selection. * - * @author jdramsey + * @author josephramsey */ public class StabilitySelection implements Algorithm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index 3c2018dcd5..2ef47921b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -24,7 +24,7 @@ /** * Build Pure Clusters. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "BPC", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/ClusterAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/ClusterAlgorithm.java index 99fbb6224e..e483c9d15d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/ClusterAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/ClusterAlgorithm.java @@ -3,7 +3,7 @@ /** * Tags an algorithm that generates clusters. * - * @author jdramsey + * @author josephramsey */ public interface ClusterAlgorithm { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index a6e06bdc4f..daca5ee169 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -24,7 +24,7 @@ /** * Find One Factor Clusters. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FOFC", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java index 5aa8daadd2..c9af36cbf1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java @@ -18,7 +18,7 @@ /** * FTFC. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FTFC", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java index 854e71980d..973435c3a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java @@ -21,7 +21,7 @@ /** * LiNG-D. - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "LiNG-D", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 6faa4f06cb..3d1e23e5e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -22,7 +22,7 @@ /** * LiNGAM. - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "LiNGAM", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java index 699c919518..2dae6458b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java @@ -45,7 +45,7 @@ * write.matrix(A, file=name, sep="\t") * } * - * @author jdramsey + * @author josephramsey */ public class ExternalAlgorithmBNTPc extends ExternalAlgorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java index f051fbbe3e..2b8d3f90fe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java @@ -39,7 +39,7 @@ * write.matrix(A, file=name, sep="\t") * } * - * @author jdramsey + * @author josephramsey */ public class ExternalAlgorithmBnlearnMmhc extends ExternalAlgorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java index 28e6e44193..790853fa5b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java @@ -38,7 +38,7 @@ * write.matrix(A, file=name, sep="\t") * } * - * @author jdramsey + * @author josephramsey */ public class ExternalAlgorithmIntersection extends ExternalAlgorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java index 692a973688..05d60b4bce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java @@ -44,7 +44,7 @@ * write.matrix(A, file=name, sep="\t") * } * - * @author jdramsey + * @author josephramsey */ public class ExternalAlgorithmPcalgGes extends ExternalAlgorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java index bdbf20bdc2..2fac9fea4d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java @@ -46,7 +46,7 @@ * write.matrix(A, file=name, sep="\t") * } * - * @author jdramsey + * @author josephramsey */ public class ExternalAlgorithmPcalgPc extends ExternalAlgorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java index 5d1c121637..7a48574e6e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java @@ -42,7 +42,7 @@ * write.matrix(A, file=name, sep="\t") * } * - * @author jdramsey + * @author josephramsey */ public class ExternalAlgorithmTetrad extends ExternalAlgorithm { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java index 153e8279d3..f86023a935 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java @@ -15,7 +15,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "MGM", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java index 3c121c6e5e..ef152c8bd2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java @@ -22,7 +22,7 @@ * 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 + * @author josephramsey */ public class FasLofs implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java index 540f77e6a2..d0f7c41aa6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java @@ -30,7 +30,7 @@ * 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 + * @author josephramsey */ @Bootstrapping @edu.cmu.tetrad.annotation.Algorithm( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java index bd64a5a58a..c9a3dc6af6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java @@ -26,7 +26,7 @@ * datasets should be taken at a time (randomly). This cannot given multiple * values. * - * @author jdramsey + * @author josephramsey */ //@edu.cmu.tetrad.annotation.Algorithm( // name = "FASK Concatenated", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java index 3e99674be8..868d1289e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java @@ -24,7 +24,7 @@ * datasets should be taken at a time (randomly). This cannot given multiple * values. * - * @author jdramsey + * @author josephramsey */ @Bootstrapping public class FaskLofsConcatenated implements MultiDataSetAlgorithm, HasKnowledge { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java index 2f619a118d..8e83f3af32 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java @@ -28,7 +28,7 @@ * values. * * @author mglymour - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FASK-Vote", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java index 4f6a717314..7bc008d2e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java @@ -23,7 +23,7 @@ * datasets should be taken at a time (randomly). This cannot given multiple * values. * - * @author jdramsey + * @author josephramsey */ @Bootstrapping public class FgesConcatenated implements MultiDataSetAlgorithm, HasKnowledge { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java index 810cd549fd..8356781186 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java @@ -31,7 +31,7 @@ * datasets should be taken at a time (randomly). This cannot given multiple * values. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "IMaGES", 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 707792dc2b..fa71ecaccc 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 @@ -25,7 +25,7 @@ /** * CPC. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "CPC", 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 0f618abe8e..9837d6cb5e 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 @@ -25,7 +25,7 @@ /** * FAS. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FAS", 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 index f5d32708c8..8d6c9d6c2a 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 @@ -27,7 +27,7 @@ /** * FGES (the heuristic version). * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FGES", 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/FgesMb.java index 1a2050b69a..38d7945345 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/FgesMb.java @@ -28,7 +28,7 @@ /** * FGES (the heuristic version). * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FGES-MB", 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/FgesMeasurement.java index 20251d8fb2..5f25fc4831 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/FgesMeasurement.java @@ -23,7 +23,7 @@ /** * FGES (the heuristic version). * - * @author jdramsey + * @author josephramsey */ @Bootstrapping public class FgesMeasurement implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { 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/GesMe.java index c41f0bc5f9..414d91ac75 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/GesMe.java @@ -27,7 +27,7 @@ /** * FGES (the heuristic version). * - * @author jdramsey + * @author josephramsey */ @Bootstrapping @Experimental 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 a1b31a5684..cc87a75b98 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 @@ -25,7 +25,7 @@ /** * PC. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "PC", 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 d955c190e6..e167d0138b 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 @@ -25,7 +25,7 @@ /** * PC-Max. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "PC-Max", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java index fda80906b1..6dc5baef61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java @@ -27,7 +27,7 @@ /** * PC. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "PC-MB", 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 index 56bae60a62..dfb5fdfe57 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 @@ -19,7 +19,7 @@ /** * PC. * - * @author jdramsey + * @author josephramsey */ @Bootstrapping public class Pcd implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { 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/SingleGraphAlg.java index 9993219c6a..92b8d14e42 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/SingleGraphAlg.java @@ -15,7 +15,7 @@ /** * PC. * - * @author jdramsey + * @author josephramsey */ public class SingleGraphAlg implements Algorithm, HasKnowledge { 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 c0bb9fe26b..319614d190 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 @@ -36,7 +36,7 @@ * J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "BFCI", 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 index 8ed2c78ecc..9fbdfebe49 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 @@ -24,7 +24,7 @@ /** * Conserative FCI. * - * @author jdramsey + * @author josephramsey */ @Bootstrapping public class Cfci implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { 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 index 7a3fb57ef7..fed07d1f10 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 @@ -26,7 +26,7 @@ /** * FCI. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FCI", 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/FciMax.java index 9ba8a0a63e..5eb4af9622 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/FciMax.java @@ -26,7 +26,7 @@ /** * FCI. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FCI-Max", 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 bd3412336a..0fd2c25255 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 @@ -30,7 +30,7 @@ /** * GFCI. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "GFCI", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index 03c7eba789..f3a8c78e56 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -37,7 +37,7 @@ * J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "GRASP-FCI", 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 index c55753d48d..dc9f71ebc6 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 @@ -26,7 +26,7 @@ /** * RFCI. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "RFCI", 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/SpFci.java index 8e059dc9b3..f3f9001b10 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/SpFci.java @@ -34,7 +34,7 @@ * J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "SP-FCI", 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/SvarFci.java index bc61af3f4e..4503ece8ef 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/SvarFci.java @@ -26,7 +26,7 @@ /** * SvarFCI. * - * @author jdramsey + * @author josephramsey * @author dmalinsky */ @edu.cmu.tetrad.annotation.Algorithm( 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/SvarGfci.java index fca200a421..5369370c21 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/SvarGfci.java @@ -28,7 +28,7 @@ /** * SvarFCI. * - * @author jdramsey + * @author josephramsey * @author Daniel Malinsky */ @edu.cmu.tetrad.annotation.Algorithm( 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/FactorAnalysis.java index 5f13cd9133..89534b2876 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/FactorAnalysis.java @@ -17,7 +17,7 @@ import java.util.Vector; /** - * @author jdramsey + * @author josephramsey */ @Bootstrapping public class FactorAnalysis implements Algorithm { 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 index 1b8374abcb..bad9c9fefc 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 @@ -21,7 +21,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "GLASSO", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java index 5ed8f33ff2..350f892725 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java @@ -21,7 +21,7 @@ /** * EB. * - * @author jdramsey + * @author josephramsey */ //@Experimental //@edu.cmu.tetrad.annotation.Algorithm( 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/FaskPw.java index f1e1b510a1..49a77e834e 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/FaskPw.java @@ -23,7 +23,7 @@ /** * FASK-PW (pairwise). * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "FASK-PW", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java index 4f34e1edbe..d63298ce79 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java @@ -21,7 +21,7 @@ /** * R1. * - * @author jdramsey + * @author josephramsey */ //@Experimental //@edu.cmu.tetrad.annotation.Algorithm( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java index 13389b2a0b..b3f50a5db3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java @@ -21,7 +21,7 @@ /** * R2. * - * @author jdramsey + * @author josephramsey */ //@Experimental //@edu.cmu.tetrad.annotation.Algorithm( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java index a159901bd6..1f5bf8e03d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java @@ -21,7 +21,7 @@ /** * R3. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "R3", 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 index 014a6b2eb4..29a78f263e 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 @@ -21,7 +21,7 @@ /** * RSkew. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "RSkew", 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/RskewE.java index 96843f8493..85d132b92b 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/RskewE.java @@ -21,7 +21,7 @@ /** * RSkewE. * - * @author jdramsey + * @author josephramsey */ //@Experimental //@edu.cmu.tetrad.annotation.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 index 885fa8a15c..ce404c2b04 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 @@ -21,7 +21,7 @@ /** * Skew. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "Skew", 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/SkewE.java index 9f3c487fbc..b90084b60a 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/SkewE.java @@ -21,7 +21,7 @@ /** * SkewE. * - * @author jdramsey + * @author josephramsey */ //@Experimental //@edu.cmu.tetrad.annotation.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/Tanh.java index b69e81a75d..9e81e1cf5f 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/Tanh.java @@ -21,7 +21,7 @@ /** * Tanh. * - * @author jdramsey + * @author josephramsey */ @Bootstrapping public class Tanh implements Algorithm, TakesExternalGraph { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/CompareExternalAlgorithms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/CompareExternalAlgorithms.java index ecdcc7987c..3368058acb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/CompareExternalAlgorithms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/CompareExternalAlgorithms.java @@ -40,7 +40,7 @@ * saves them. For other formats, specialty data loaders can be written to implement the * Simulation interface. * - * @author jdramsey + * @author josephramsey */ public class CompareExternalAlgorithms { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareFromFiles.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareFromFiles.java index b725c80598..f529ea986d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareFromFiles.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareFromFiles.java @@ -39,7 +39,7 @@ * saves them. For other formats, specialty data loaders can be written to implement the * Simulation interface. * - * @author jdramsey + * @author josephramsey */ public class ExampleCompareFromFiles { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation.java index d59043812d..957c23bfc8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation.java @@ -35,7 +35,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class ExampleCompareSimulation { public static void main(String... args) { 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..2ee80adae1 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 @@ -35,7 +35,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class ExampleCompareSimulation2 { public static void main(String... args) { 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 7bd5af9bc1..bd85c6a946 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 @@ -36,7 +36,7 @@ /** * An example script to simulate time series data and run a comparison analysis on it. * - * @author jdramsey, dmalinsky + * @author josephramsey, dmalinsky */ public class ExampleCompareSimulationTimeSeries { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleNonlinearSave.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleNonlinearSave.java index 785d9e50f7..679a08bb9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleNonlinearSave.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleNonlinearSave.java @@ -30,7 +30,7 @@ /** * An example script to save out data files and graphs from a simulation. * - * @author jdramsey + * @author josephramsey */ public class ExampleNonlinearSave { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleSave.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleSave.java index 6fff80f500..3f4b2b3c28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleSave.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleSave.java @@ -30,7 +30,7 @@ /** * An example script to save out data files and graphs from a simulation. * - * @author jdramsey + * @author josephramsey */ public class ExampleSave { public static void main(String... args) { 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..cac434e9a6 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 @@ -37,7 +37,7 @@ * saves them. For other formats, specialty data loaders can be written to implement the * Simulation interface. * - * @author jdramsey + * @author josephramsey */ public class MVPCompareFromFiles { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/RunConfig.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/RunConfig.java index 64966ced91..422eaf585e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/RunConfig.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/RunConfig.java @@ -26,7 +26,7 @@ /** * An example script to save out data files and graphs from a simulation. * - * @author jdramsey + * @author josephramsey */ public class RunConfig { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/Save.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/Save.java index 0c181cf518..9021418126 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/Save.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/Save.java @@ -31,7 +31,7 @@ /** * An example script to save out data files and graphs from a simulation. * - * @author jdramsey + * @author josephramsey */ public class Save { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/SaveDGSimulations.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/SaveDGSimulations.java index 72f5861a18..d9a7b809dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/SaveDGSimulations.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/SaveDGSimulations.java @@ -30,7 +30,7 @@ /** * An example script to save out data files and graphs from a simulation. * - * @author jdramsey + * @author josephramsey */ public class SaveDGSimulations { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java index af1aaa2c2d..75b36da608 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java @@ -9,7 +9,7 @@ /** * Returns a cyclic graph build up from small cyclic graph components. * - * @author jdramsey + * @author josephramsey */ public class Cyclic implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java index 22d3fabe05..e394d1e783 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java @@ -10,7 +10,7 @@ /** * Creates a random graph by the Erdos-Renyi method (probabiliy of edge fixed, # edges not). * - * @author jdramsey + * @author josephramsey */ public class ErdosRenyi implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java index 2bf0afd2ff..fa1c7f5a3b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java @@ -9,7 +9,7 @@ /** * Creates a random graph by adding forward edges. * - * @author jdramsey + * @author josephramsey */ public class RandomForward implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomGraph.java index 34dba2f1c2..bc08a4c7b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomGraph.java @@ -9,7 +9,7 @@ /** * An interface to represent a random graph of some sort. * - * @author jdramsey + * @author josephramsey */ public interface RandomGraph extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java index 52a20afdde..59e3c1ef44 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java @@ -10,7 +10,7 @@ /** * Creates a random graph by adding forward edges. * - * @author jdramsey + * @author josephramsey */ public class RandomSingleFactorMim implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java index 7a32f4de70..327c5a99f5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java @@ -10,7 +10,7 @@ /** * Creates a random graph by adding forward edges. * - * @author jdramsey + * @author josephramsey */ public class RandomTwoFactorMim implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java index cd1b3c664e..f088762d8b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java @@ -8,7 +8,7 @@ /** * Returns a scale free graph. * - * @author jdramsey + * @author josephramsey */ public class ScaleFree implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java index f6440310d4..1ca56b4db5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java @@ -9,7 +9,7 @@ /** * Stores a single graph for use in simulations, etc. * - * @author jdramsey + * @author josephramsey */ public class SingleGraph implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java index 683f745368..0d2f15f485 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java @@ -17,7 +17,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "BDeu Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java index a1ec54c269..26ad54af3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java @@ -19,7 +19,7 @@ /** * Wrapper for Daudin Conditional Independence test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "CCI-Test (Conditional Correlation Independence Test)", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java index 40b12c72ba..9802c1b407 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java @@ -15,7 +15,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "Chi Square Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java index a5a016c166..be840413c0 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java @@ -16,7 +16,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "CG-LRT (Conditional Gaussian Likelihood Ratio Test)", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java index 7b8626503f..6f864463fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DSeparationTest.java @@ -14,7 +14,7 @@ /** * Wrapper for D-separation test. Requires a true DAG as input. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "D-Separation Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java index 5595ccd25d..923ffa7699 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java @@ -17,7 +17,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "Discrete BIC Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java index b39c5d5204..58cc6d3509 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java @@ -17,7 +17,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "Fisher Z Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java index 7d8f711ba6..c72729a45b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java @@ -15,7 +15,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "G Square Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java index 96cb3c3f2b..574cb5bfa8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/IndependenceWrapper.java @@ -12,7 +12,7 @@ /** * Interface that algorithm must implement. * - * @author jdramsey + * @author josephramsey */ public interface IndependenceWrapper extends HasParameters, TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java index 03e7a585f2..ec47a3353a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java @@ -17,7 +17,7 @@ *

* Note that should work with Linear, Gaussian variables but is general. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "KCI-Test (Kernel Conditional Independence Test)", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java index cdde406376..eb831e0d17 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/KimEtAlScoreTests.java @@ -18,7 +18,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "Kim et al. BIC Tests", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java index 36c32243c6..ee518b7b7c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java @@ -18,7 +18,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "MAG SEM BIC Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java index ac54f1c051..03364279ff 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java @@ -15,7 +15,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @Experimental @TestOfIndependence( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java index c1c54021e8..b55a1a7ff8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java @@ -13,7 +13,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ //@TestOfIndependence( // name = "Multinomial Logistic Retression Wald Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java index 350c3b17c2..ae98e64be2 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java @@ -15,7 +15,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @Experimental @TestOfIndependence( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java index 0feceed029..d893d4193f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java @@ -13,7 +13,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ public class PositiveCorr implements IndependenceWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java index f85d3723b5..bcf82f36a4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java @@ -15,7 +15,7 @@ /** * Wrapper for Fisher Z test. Ignore this for now * - * @author jdramsey + * @author josephramsey */ public class SemBicDTest implements IndependenceWrapper { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java index 9a10095ee3..fdfff20e8e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java @@ -18,7 +18,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @TestOfIndependence( name = "SEM BIC Test", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java index 51bec2062b..1b94eca0e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java @@ -14,7 +14,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "BDeu Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java index 0e69f776e4..d1388e8a4e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java @@ -17,7 +17,7 @@ ///** // * Wrapper for CCI Score. // * -// * @author jdramsey +// * @author josephramsey // */ //@edu.cmu.tetrad.annotation.Score(name = "CCI-Score (Conditional Correlation Independence Score)", command = "cci-score", dataType = DataType.Continuous) //@General diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java index 2f903bb135..435e70bf81 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java @@ -16,7 +16,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "CG-BIC (Conditional Gaussian BIC Score)", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java index ce699b9109..9f36f0563b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DSeparationScore.java @@ -14,7 +14,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "D-separation Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java index eff6ef5b57..8042a40496 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java @@ -14,7 +14,7 @@ /** * Wrapper for Discrete BIC test. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "Discrete BIC Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java index 73e0809754..9586b2631a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java @@ -16,7 +16,7 @@ /** * Wrapper for linear, Gaussian Extended BIC score (Chen and Chen). * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "EBIC Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java index 2ca525c20b..6ed232ac22 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java @@ -16,7 +16,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ //@edu.cmu.tetrad.annotation.Score( // name = "Fisher Z Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java index dc40752047..48702ddf31 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/KimEtAlScores.java @@ -17,7 +17,7 @@ /** * Wrapper for linear, Gaussian Extended BIC score (Chen and Chen). * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "Kim et al. Scores", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java index 6389eaab39..763fa1517b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java @@ -15,7 +15,7 @@ /** * Wrapper for linear, Gaussian SEM BIC score. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "MAG SEM BIC Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java index 66040e4ca6..b11c242321 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java @@ -16,7 +16,7 @@ /** * Wrapper for the Poisson prior score (Bryan) * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "Poisson Prior Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java index 0cd3a528ac..51b8955f83 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java @@ -15,7 +15,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ public class PositiveCorrScore implements ScoreWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java index c57baa7811..424ae85e72 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java @@ -13,7 +13,7 @@ /** * Interface that algorithm must implement. * - * @author jdramsey + * @author josephramsey */ public interface ScoreWrapper extends HasParameters, TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java index ab3b7ffd0e..3c8dc111a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java @@ -16,7 +16,7 @@ /** * Wrapper for linear, Gaussian SEM BIC score. * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "Sem BIC Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java index 56061fb5e3..202e7c1ea3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java @@ -13,7 +13,7 @@ /** * Wrapper for Fisher Z test. * - * @author jdramsey + * @author josephramsey */ //@edu.cmu.tetrad.annotation.Score( // name = "Sem BIC Score Deterministic", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java index efc80e7abd..2fa7b84aae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java @@ -17,7 +17,7 @@ /** * Wrapper for linear, Gaussian Extended BIC score (Chen and Chen). * - * @author jdramsey + * @author josephramsey */ @edu.cmu.tetrad.annotation.Score( name = "ZS Bound Score", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java index b65893c0f9..26ae8a3d2d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java @@ -19,7 +19,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class BayesNetSimulation implements Simulation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java index 396f3aa3d5..fa779699e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java @@ -22,7 +22,7 @@ * A version of the Lee and Hastic simulation which is guaranteed to generate a discrete * data set. * - * @author jdramsey + * @author josephramsey */ @Experimental public class BooleanGlassSimulation implements Simulation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java index c9a535bd53..b421c9fa55 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java @@ -18,7 +18,7 @@ /** * A simulation method based on the conditional Gaussian assumption. * - * @author jdramsey + * @author josephramsey */ public class ConditionalGaussianSimulation implements Simulation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java index 78de5a3af3..e1a5d52f2c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java @@ -22,7 +22,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class GeneralSemSimulation implements Simulation { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java index 2c7751a50b..8dbaca08e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java @@ -22,7 +22,7 @@ * some carefully selected functions to test nonlinearity and non-Gaussianity. * * @author ekummerfeld@gmail.com - * @author jdramsey + * @author josephramsey */ public class GeneralSemSimulationSpecial1 implements Simulation { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java index 765a0a983f..976529e3b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java @@ -22,7 +22,7 @@ * A version of the Lee and Hastic simulation which is guaranteed ot generate a * discrete data set. * - * @author jdramsey + * @author josephramsey */ public class LeeHastieSimulation implements Simulation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java index 7648fc0d59..c7ba1f8c53 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java @@ -20,7 +20,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class LinearFisherModel implements Simulation, TakesData { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java index 77ed568ed4..c12b596b1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java @@ -20,7 +20,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class SemSimulation implements Simulation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java index fd35da69d9..f1011b34ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java @@ -17,7 +17,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class SemThenDiscretize implements Simulation { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java index 7fd203fdcf..b2a85b46bf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java @@ -12,7 +12,7 @@ /** * The interface that simulations must implement. * - * @author jdramsey + * @author josephramsey */ public interface Simulation extends HasParameters, TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java index 4ef7fec019..55d55fef28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java @@ -6,7 +6,7 @@ /** * A list of simulations to be compared. * - * @author jdramsey + * @author josephramsey */ public class Simulations { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java index 799cfc3d06..4ddf4e3f81 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java @@ -18,7 +18,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class StandardizedSemSimulation implements Simulation { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java index bbf3e3b1ec..4cde2c0e65 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java @@ -21,7 +21,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey * @author Daniel Malinsky */ public class TimeSeriesSemSimulation implements Simulation, HasKnowledge { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java index 6982775598..48fd031997 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java @@ -8,7 +8,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyFn implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java index be26807466..de0c03dbf7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java @@ -8,7 +8,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyFp implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java index 746a99d479..c246828498 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java @@ -8,7 +8,7 @@ * The adjacency true positive rate. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyFpr implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java index 59abd4278f..35cb5c3710 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java @@ -8,7 +8,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java index 526f2f3086..581fae634f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java @@ -8,7 +8,7 @@ * The adjacency recall. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java index cde628ef62..171db3f306 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java @@ -8,7 +8,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyTn implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java index e7cc4c6bd5..47ae933c34 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java @@ -8,7 +8,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyTp implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java index 0901220971..fb3d852bcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java @@ -8,7 +8,7 @@ * The adjacency true positive rate. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyTpr implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java index cc18b6360b..3c1f4f39a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java @@ -7,7 +7,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class AncestorPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java index f726831e16..2e1c9d7554 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java @@ -7,7 +7,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class AncestorRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java index 22356536c5..1a29a936c3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class AncestralPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java index 2a0dfc6b02..bd5361c5a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class AncestralRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java index cbcc6ce8c4..a7216c1efa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly, for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadFn implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java index 864d746ae5..91a24b88e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly, for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadFp implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java index fc39c2c976..0f280d5cd7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java @@ -8,7 +8,7 @@ * The adjacency true positive rate. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadFpr implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java index 0ee4442ee3..e2e6215945 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java index 9d95c3bfef..26ecb60502 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadPrecisionCommonEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java index d761391292..a2b563e8aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java index ebb5a8db00..2691de8fb5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadRecallCommonEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java index 8f25f9c662..d51c0dc2cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadTn implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java index 3c8481882d..bf34010eae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class ArrowheadTp implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java index e234649984..f2e5cd56ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java @@ -7,7 +7,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AverageDegreeEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java index 7832463e8f..f3528f5c42 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java @@ -7,7 +7,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class AverageDegreeTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java index 5a9baf7e0f..ec0520ea9b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java @@ -10,7 +10,7 @@ /** * Difference between the true and estiamted BIC scores. * - * @author jdramsey + * @author josephramsey */ public class BicDiff implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java index 76dc084ca0..df5f61da87 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java @@ -12,7 +12,7 @@ /** * Difference between the true and estiamted BIC scores. * - * @author jdramsey + * @author josephramsey */ public class BicDiffPerRecord implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java index 1ce364c1b5..abf5d7fe6a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java @@ -10,7 +10,7 @@ /** * Estimated BIC score. * - * @author jdramsey + * @author josephramsey */ public class BicEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java index b8ad971d0e..46cb40a18b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java @@ -10,7 +10,7 @@ /** * True BIC score. * - * @author jdramsey + * @author josephramsey */ public class BicTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java index 68b505cd2e..d80d173ec6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class BidirectedEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java index 82a25ac9be..08e3bb7862 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java @@ -9,7 +9,7 @@ /** * The bidirected false negatives. * - * @author jdramsey + * @author josephramsey */ public class BidirectedFP implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java index 65b56bb751..c540c1b23a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class BidirectedLatentPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java index 539021d9ff..3ae798f65e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java @@ -10,7 +10,7 @@ /** * The bidirected edge precision. * - * @author jdramsey + * @author josephramsey */ public class BidirectedPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java index 247e3b4fef..1230fb6539 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java @@ -10,7 +10,7 @@ /** * The bidirected edge precision. * - * @author jdramsey + * @author josephramsey */ public class BidirectedRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java index c92a23ce90..735d7f0b28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class BidirectedTP implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java index 5a43fed24a..0d08d28dc9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class BidirectedTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java index dacc3beeb7..3f7b8600de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class CommonAncestorFalseNegativeBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java index 10cd60aab1..e64f36df59 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class CommonAncestorFalsePositiveBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java index 4be16b9729..b7b6dbb28b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class CommonAncestorTruePositiveBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java index 7223100dab..00b423678b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java @@ -14,7 +14,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class CommonMeasuredAncestorRecallBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java index cb133cac78..5608b676cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java @@ -7,7 +7,7 @@ /** * Outputs 1 if the skeleton is correct, 0 if not.. * - * @author jdramsey + * @author josephramsey */ public class CorrectSkeleton implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java index 6cbc07c106..41759f0b7e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java @@ -12,7 +12,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class DefiniteDirectedPathPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java index 77e9523377..5972fcd408 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class DefiniteDirectedPathRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java index 0f3680e5b5..cc11667629 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java @@ -7,7 +7,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class DensityEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java index c67f23c4a7..0eed569e52 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java @@ -7,7 +7,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class DensityTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java index ae775dd3cc..2e7545be0f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java @@ -9,7 +9,7 @@ * the elapsed time is calculated by the comparison class and recorded if this statistic is * used. * - * @author jdramsey + * @author josephramsey */ public class ElapsedCpuTime implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java index aecaf5396a..f6c9e0b2b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class FalseNegativesAdjacencies implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java index 8fb6e31717..e6204327d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class FalsePositiveAdjacencies implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java index 7d7fa5c8c9..83d74ec393 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java @@ -7,7 +7,7 @@ /** * Return a 1 if the graph is exactly right, 0 otherwise. * - * @author jdramsey + * @author josephramsey */ public class GraphExactlyRight implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java index 387e2b3462..1ab552e314 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class LatentCommonAncestorFalseNegativeBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java index 21b9dda345..2c178a3e85 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class LatentCommonAncestorFalsePositiveBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java index 91bbd4c38f..f9cc5aa0d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java @@ -13,7 +13,7 @@ /** * The bidirected true positives. * - * @author jdramseyHow + * @author josephramseyHow */ public class LatentCommonAncestorRecallBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java index 4f3f9bd5f2..6ef5e769ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class LatentCommonAncestorTruePositiveBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java index 132330a2f6..26b4a2ce34 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java @@ -7,7 +7,7 @@ /** * Legal PAG * - * @author jdramsey + * @author josephramsey */ public class LegalPag implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java index 83f9d34ba9..18061912b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java @@ -13,7 +13,7 @@ *

* We calculate the correlation directly from the confusion matrix. * - * @author jdramsey + * @author josephramsey */ public class MathewsCorrAdj implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java index 525cb0b171..b3975700fd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java @@ -17,7 +17,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly, for false negatives * - * @author jdramsey + * @author josephramsey */ public class MathewsCorrArrow implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java index 85a732afb2..6149dfc1bf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java @@ -8,7 +8,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class MaximalityCondition implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java index 697a28ea06..c527f0a55e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.Node; /** - * @author jdramsey + * @author josephramsey */ public class NoAlmostCyclicPathsCondition implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java index 6b69c840d1..7089ed884d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** - * @author jdramsey + * @author josephramsey */ public class NoAlmostCyclicPathsInMagCondition implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java index 4224c9983a..635e89c9aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Node; /** - * @author jdramsey + * @author josephramsey */ public class NoCyclicPathsCondition implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java index 07b3ccf344..6fbd698689 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** - * @author jdramsey + * @author josephramsey */ public class NoCyclicPathsInMagCondition implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java index e79b135134..4dee2776a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NoSemidirectedPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java index f264e09ce6..ee391671aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NoSemidirectedRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java index 913fffb5c0..481d1ca9ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java @@ -12,7 +12,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class NodesInCyclesPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java index e95e978a52..63390eb0cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java @@ -12,7 +12,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class NodesInCyclesRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java index 4e1bf39f32..ac8f9f7c93 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java @@ -7,7 +7,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class NonancestorPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java index 065e56ab9b..5ed3f7920f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java @@ -7,7 +7,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class NonancestorRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java index e6708d7a29..9cc31ab181 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java @@ -9,7 +9,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class NumAmbiguousTriples implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java index 94706150d0..83035bdbc7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java @@ -9,7 +9,7 @@ /** * The bidirected edge precision. * - * @author jdramsey + * @author josephramsey */ public class NumBidirectedBothNonancestorAncestor implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java index 65315f0a68..145726a791 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java @@ -9,7 +9,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class NumBidirectedEdgesEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java index 3a1f506cef..967959c5b1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java @@ -9,7 +9,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class NumBidirectedEdgesTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java index 91ee79435e..0b328cf48e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumColoredDD implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java index a7945e4eaa..ecceefef46 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumColoredNL implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java index c90b0a41b4..7bf8e8d5eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumColoredPD implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java index 25ae87b73d..948a2fe7fe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumColoredPL implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java index ba3778a3b6..56c1811d42 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java @@ -14,7 +14,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCommonMeasuredAncestorBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java index 15a984e0f5..823efffcc8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatibleDefiniteDirectedEdgeAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java index 78efa368db..171221ed67 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatibleDirectedEdgeConfounded implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java index 95e8641d1f..a89c8e27f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java @@ -8,7 +8,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatibleDirectedEdgeNonAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java index 172ef1d852..ec6891bc15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatibleEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java index de330a8bac..dcbfde283e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatiblePossiblyDirectedEdgeAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java index 7de8c4cea0..ea35dc8144 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatiblePossiblyDirectedEdgeNonAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java index 3088f514a1..9afe5913a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatibleVisibleAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java index 5909ef5a1d..58cb49cc66 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java @@ -12,7 +12,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCompatibleVisibleNonancestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java index 417fae9d2e..62778571be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java @@ -6,7 +6,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCorrectDDAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java index 9d72d563e3..6722f99f94 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java @@ -6,7 +6,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCorrectPDAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java index 88ad589a6b..462431fbee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java @@ -6,7 +6,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumCorrectVisibleAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java index 290b946da6..e9368e9cc4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java @@ -10,7 +10,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDefinitelyDirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java index 889a8df1b1..725b674e5d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java @@ -7,7 +7,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDefinitelyNotDirectedPaths implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java index 28619f104e..b922269dea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedEdgeAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java index 376d4053eb..22dbdb45c9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java @@ -12,7 +12,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedEdgeBnaMeasuredCounfounded implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java index e10f2969ac..ee48bfc69c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedEdgeNoMeasureAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java index efc39b3155..52786ca76b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedEdgeNotAncNotRev implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java index 6f0cb81353..aa95b60422 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedEdgeReversed implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java index dd41849879..97276c8fbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.search.utils.GraphUtilsSearch; /** - * @author jdramsey + * @author josephramsey */ public class NumDirectedEdgeVisible implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java index 1fccae2230..5551988c54 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Graph; /** - * @author jdramsey + * @author josephramsey */ public class NumDirectedEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java index 38d2a70151..bca1ea9b5d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedPathsEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java index 5d46442f6d..218aa463a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedPathsTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java index e738a78d79..010133c651 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumDirectedShouldBePartiallyDirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java index 98df13d3ce..8eb31fd41f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java @@ -6,7 +6,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumIncorrectDDAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java index 1dc0a749a7..caf9e3aa97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java @@ -6,7 +6,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumIncorrectPDAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java index 4ca9e56c64..75510db7dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java @@ -6,7 +6,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumIncorrectVisibleAncestors implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java index ebbbeb3745..6a9198ea4c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumLatentCommonAncestorBidirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java index db1ccb27a4..62d132233d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Graph; /** - * @author jdramsey + * @author josephramsey */ public class NumNondirectedEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java index 4d29318a78..63780c07b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Graph; /** - * @author jdramsey + * @author josephramsey */ public class NumPartiallyOrientedEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java index 0a40737be4..d4e5e840a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java @@ -7,7 +7,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class NumPossiblyDirected implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java index bcbc2057b9..fb1f668f9f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Graph; /** - * @author jdramsey + * @author josephramsey */ public class NumUndirectedEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java index 20353e7355..fc23324264 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.graph.Graph; /** - * @author jdramsey + * @author josephramsey */ public class NumVisibleEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java index d3b92147a8..e64f42b76b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java @@ -7,7 +7,7 @@ /** * Prints the number of edges in the estimated graph. * - * @author jdramsey + * @author josephramsey */ public class NumberOfEdgesEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java index e09c934c63..668f2bdc0c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java @@ -7,7 +7,7 @@ /** * Prints the number of edges in the true graph. * - * @author jdramsey + * @author josephramsey */ public class NumberOfEdgesTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java index 537d8a8556..7e4d416ea9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java @@ -10,7 +10,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class PagAdjacencyPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java index e68a6cef9a..9b34663dba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java @@ -10,7 +10,7 @@ * The adjacency recall. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class PagAdjacencyRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java index 897c616c73..64094bec26 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java @@ -8,7 +8,7 @@ * are listed. The parameter must have numerical values, and these will be * represented as continuous. * - * @author jdramsey + * @author josephramsey */ public class ParameterColumn implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java index 1e420b9941..3d7510d7aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java @@ -12,7 +12,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class PercentAmbiguous implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java index 3dbe4812da..b945129fa0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java @@ -9,7 +9,7 @@ * The adjacency precision. The true positives are the number of adjacencies in both * the true and estimated graphs. * - * @author jdramsey + * @author josephramsey */ public class PercentBidirectedEdges implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java index 465f6bc19f..2170cd5fa3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java @@ -8,7 +8,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class ProportionSemidirectedPathsNotReversedEst implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java index a5a0a39e8a..d8b8787fd5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java @@ -8,7 +8,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class ProportionSemidirectedPathsNotReversedTrue implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java index 4541dde7d4..7bbecf35cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class SemidirectedPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java index c042a8e471..a57c881253 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class SemidirectedRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java index 9452761f5a..912f625bc1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java @@ -10,7 +10,7 @@ * Calculates the structural Hamming distance (SHD) between the estimated graph and * the true graph. * - * @author jdramsey + * @author josephramsey */ public class Shd implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java index ed29492913..c88f2a3734 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java @@ -8,7 +8,7 @@ /** * The interface that each statistic needs to implement. * - * @author jdramsey + * @author josephramsey */ public interface Statistic extends Serializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistics.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistics.java index 5dc6fff9cb..6d8214554e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistics.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistics.java @@ -8,7 +8,7 @@ /** * A list of statistics and their utility weights. * - * @author jdramsey + * @author josephramsey */ public class Statistics { private final List statistics = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java index 1e86e822bb..1392f9e62a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class TailPrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java index e705d48691..0b7e965664 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java @@ -11,7 +11,7 @@ * X to Y or else does not contain an arrowhead at X for an edge from X to Y, one false * positive is counted. Similarly for false negatives. * - * @author jdramsey + * @author josephramsey */ public class TailRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java index 3a0a375239..84a63e7dcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagFalseNegativesArrows implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java index addacbdb40..e7dd509e7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagFalseNegativesTails implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java index 3f2f5aabad..3604306810 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagFalsePositiveArrow implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java index 657a8730d6..07bf4e60e6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java @@ -8,7 +8,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagFalsePositiveTails implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java index 387cb17bf4..c33e8af61f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java @@ -8,7 +8,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class TrueDagPrecisionArrow implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java index 4c8926a912..386cedb33a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagPrecisionTails implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java index b099b1cf51..5067ed945b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagRecallArrows implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java index 55bee428d0..143d17646a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java @@ -11,7 +11,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagRecallTails implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java index 9958fa6b0e..3fc37c0359 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java @@ -8,7 +8,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagTruePositiveArrow implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java index 2630d28f8a..78639caae4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java @@ -9,7 +9,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagTruePositiveDirectedPathNonancestor implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java index 57211e175d..a4ed824e13 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java @@ -8,7 +8,7 @@ /** * The bidirected true positives. * - * @author jdramsey + * @author josephramsey */ public class TrueDagTruePositiveTails implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java index a2f1527fb8..f50491b1dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java @@ -10,7 +10,7 @@ * Thus, if the true does not contains X->Y,Y->X and estimated graph does contain it, * one false positive is counted. * - * @author jdramsey, rubens (November 2016) + * @author josephramsey, rubens (November 2016) */ public class TwoCycleFalseNegative implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java index ae6cf30f81..be81cb8d29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java @@ -11,7 +11,7 @@ * Thus, if the true does not contains X->Y,Y->X and estimated graph does contain it, * one false positive is counted. * - * @author jdramsey, rubens (November 2016) + * @author josephramsey, rubens (November 2016) */ public class TwoCycleFalsePositive implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java index dd4ee7398c..171c744a23 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java @@ -10,7 +10,7 @@ * Thus, if the true does not contains X->Y,Y->X and estimated graph does contain it, * one false positive is counted. * - * @author jdramsey, rubens (November 2016) + * @author josephramsey, rubens (November 2016) */ public class TwoCyclePrecision implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java index bb775346fd..5c446a196d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java @@ -10,7 +10,7 @@ * Thus, if the true contains X->Y,Y->X and estimated graph does not contain it, one false negative * is counted. * - * @author jdramsey, rubens (November 2016) + * @author josephramsey, rubens (November 2016) */ public class TwoCycleRecall implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java index 08be2507c0..3ae2d3fb0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java @@ -10,7 +10,7 @@ * Thus, if the true does not contains X->Y,Y->X and estimated graph does contain it, * one false positive is counted. * - * @author jdramsey, rubens (November 2016) + * @author josephramsey, rubens (November 2016) */ public class TwoCycleTruePositive implements Statistic { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java index 3cb630942e..3b9a4e74fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java @@ -10,7 +10,7 @@ /** * A confusion matrix for adjacencies--i.e. TP, FP, TN, FN for counts of adjacencies. * - * @author jdramsey + * @author josephramsey */ public class AdjacencyConfusion { private int tp; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java index 90a2e93c40..c9a8e323f7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java @@ -12,7 +12,7 @@ * A true positive arrow is counted for X*->Y in the estimated graph if X is not adjacent * to Y or X--Y or X<--Y. * - * @author jdramsey, rubens (November, 2016) + * @author josephramsey, rubens (November, 2016) */ public class ArrowConfusion { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/BidirectedConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/BidirectedConfusion.java index b2b7043bdf..d652fa02ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/BidirectedConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/BidirectedConfusion.java @@ -10,7 +10,7 @@ /** * A confusion matrix for bidireced edges--i.e. TP, FP, TN, FN for counts of bidirected edges. * - * @author jdramsey + * @author josephramsey */ public class BidirectedConfusion { private int tp; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/SimulationPath.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/SimulationPath.java index f5e3ccdbbe..79c1861aa0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/SimulationPath.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/SimulationPath.java @@ -4,7 +4,7 @@ * Some simulations may wish to implement this interface to specify a simulation * path, which will be printed in the output. * - * @author jdramsey + * @author josephramsey */ public interface SimulationPath { String getPath(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/TailConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/TailConfusion.java index 02abb43621..d40ae29e39 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/TailConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/TailConfusion.java @@ -12,7 +12,7 @@ * A true positive arrow is counted for X*->Y in the estimated graph if X is not adjacent * to Y or X--Y or X<--Y. * - * @author jdramsey, rubens (November, 2016) + * @author josephramsey, rubens (November, 2016) */ public class TailConfusion { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/ParameterValues.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/ParameterValues.java index 937c44b03f..8a8be08613 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/ParameterValues.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/ParameterValues.java @@ -5,7 +5,7 @@ /** * Tags a class that can return values for parameters. * - * @author jdramsey + * @author josephramsey */ public interface ParameterValues { Map parameterValues(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesData.java index 6a412b3f6d..a21d17c258 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesData.java @@ -3,7 +3,7 @@ /** * Tags a gadget that takes a data model list as argument to its constructor. * - * @author jdramsey + * @author josephramsey */ public interface TakesData { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesExternalGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesExternalGraph.java index 557ae84042..05a192a4b3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesExternalGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/TakesExternalGraph.java @@ -5,7 +5,7 @@ /** * Tags an algorithm that can take an external graph as input. * - * @author jdramsey + * @author josephramsey */ public interface TakesExternalGraph { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataType.java index 13c22ecb6d..9a216c27b3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataType.java @@ -4,7 +4,7 @@ * The type of the data set--continuous if all continuous variables, discrete if * all discrete variables; otherwise, mixed. * - * @author jdramsey + * @author josephramsey */ public enum DataType { Continuous, Discrete, Mixed, Graph, Covariance, All diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java index 0f70818abc..d687cda4cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java @@ -1,7 +1,7 @@ package edu.cmu.tetrad.data; /** - * @author jdramsey + * @author josephramsey */ public interface IDataReader { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java index 897a618044..7d8ea8f57f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java @@ -21,7 +21,7 @@ import java.util.Objects; /** - * @author jdramsey + * @author josephramsey */ public class LoadContinuousDataAndGraphs implements Simulation { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java index d2b3b99d70..47a061d3b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java @@ -19,7 +19,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ @Experimental public class LoadContinuousDataAndSingleGraph implements Simulation, HasParameterValues { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java index 9023b83a9c..74606fbdd1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java @@ -21,7 +21,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ @Experimental public class LoadContinuousDataSmithSim implements Simulation, HasParameterValues { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java index 1528d7da9b..364aab12b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java @@ -18,7 +18,7 @@ import java.util.Objects; /** - * @author jdramsey + * @author josephramsey */ public class LoadDataAndGraphs implements Simulation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java index 4a25430f81..27f5ede646 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java @@ -19,7 +19,7 @@ import java.util.Map; /** - * @author jdramsey + * @author josephramsey */ public class LoadDataFromFileWithoutGraph implements Simulation, SimulationPath, ParameterValues { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 2bba7bc863..7061e4d475 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -35,21 +35,21 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - *

Changes the implementation of the GFCI algorithm to use Boss - * instead of FGES as the initial step. This tends to produce a accurate PAG than - * GFCI as a result, for the latent variables case. The reference for GFCI - * is here:

+ *

Uses BOSS in place of FGES for the initial step in the GFCI algorithm. + * This tends to produce a accurate PAG than GFCI as a result, for the latent + * variables case. This is a simple substitution; the reference for GFCI is here:

*

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

*

For BOSS only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

* - * @author jdramsey + * @author josephramsey * @author bryan andrews - * @see PermutationSearch * @see Boss * @see GFci + * @see GraspFci + * @see SpFci */ public final class BFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index c7afc57b7d..ccf670846d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -52,11 +52,18 @@ * path step in the final FCI orientation rules, both a score and a * test need to be used to construct a GFCI algorihtm.

* + *

Note that various score-based algorithms could be used in place of FGES + * for the initial step; in this repository we give three other options, + * GRaSP-FCI, BFCI (BOSS FCI), and SP-FCI (see).

+ * * @author Juan Miguel Ogarrio * @author peterspirtes * @author josephramsey * @see Fci * @see FciOrient + * @see GraspFci + * @see BFci + * @see SpFci */ public final class GFci implements IGraphSearch { private Graph graph; 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 8837255d33..417dfbe66e 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 @@ -38,21 +38,21 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - *

Changes the implementation of the GFCI algorithm to use Boss - * instead of GRaSP as the initial step. This tends to produce a accurate PAG than - * GFCI as a result, for the latent variables case. The reference for GFCI - * is here:

+ *

Uses GRaSP in place of FGES for the initial step in the GFCI algorithm. + * This tends to produce a accurate PAG than GFCI as a result, for the latent + * variables case. This is a simple substitution; the reference for GFCI is here:

*

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

- *

For BOSS only a score is needed, but there are steps in GFCI that require + *

For GRaSP only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

* - * @author jdramsey - * @author bryan andrews - * @see Boss + * @author josephramsey + * @author bryanandrews + * @see Grasp * @see GFci - * @see Fci + * @see BFci + * @see SpFci */ public final class GraspFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 660b91b2c2..0c475782da 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -15,10 +15,14 @@ * return all such sparsest permutations and their corresponding DAGs, but in this version * it return one of them, and converts the result into a CPDAG.

* - *

Knowledge can be used with this search. If tiered knowledge is used, then the procedure - * is carried out for each tier separately, given the variable preceding that tier, which - * allows the SP algorithm to address tiered (e.g., time series) problems with more than 11 - * variables.

+ *

Note that SP considers all permutations of the algorithm, which is exponential in the + * number of variables. So SP without knowledge is limited to about 10 variables per + * knowledge tier.

+ * + *

However, notably, tiered Knowledge can be used with this search. If tiered knowledge + * is used, then the procedure is carried out for each tier separately, given the variable + * preceding that tier, which allows the SP algorithm to address tiered (e.g., time series) + * problems with more than 11 variables.

* *

This class is meant to be used in the context of the PermutationSearch class (see). * the proper use is PermutationSearch search = new PermutationSearch(new Sp(score));

@@ -29,6 +33,8 @@ * @author bryanandrews * @author josephramsey * @see PermutationSearch + * @see Knowledge + * @see SpFci */ public class Sp implements SuborderSearch { private final Score score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 0991b38acd..05a41ec408 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -39,22 +39,27 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - *

Changes the implementation of the GFCI algorithm to use Boss - * instead of SP (Sparest Permutation) as the initial step. This tends to - * produce a accurate PAG than GFCI as a result, for the latent variables - * case. The reference for GFCI is here:

+ /** + *

Uses SP in place of FGES for the initial step in the GFCI algorithm. + * This tends to produce a accurate PAG than GFCI as a result, for the latent + * variables case. This is a simple substitution; the reference for GFCI is here:

*

J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

- *

For BOSS only a score is needed, but there are steps in GFCI that require + * + *

For SP only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

+ * + *

Note that SP considers all permutations of the algorithm, which is + * exponential in the number of variables. So SP is limited to about 10 + * variables.

* - * @author jdramsey + * @author josephramsey * @author bryan andrews - * @see Boss + * @see Grasp * @see GFci * @see BFci - * @see Sp + * @see GraspFci */ public final class SpFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java index 92c245854c..98e4f0a563 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java @@ -42,7 +42,7 @@ * approach with S-Plus illustrations (Vol. 18). OUP Oxford. * * @author Vineet Raghu on 7/3/2016 - * @author jdramsey refactoring 7/4/2018 + * @author josephramsey refactoring 7/4/2018 */ public class Kci implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java index 6db1729b76..119c071891 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java @@ -8,7 +8,7 @@ /** * Stores AD trees for data sets for reuse. * - * @author jdramsey + * @author josephramsey */ public class AdTrees { private static final Map adTrees = new HashMap<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/Vicinity.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/Vicinity.java index 0f2f9cf5bd..b49fb79a10 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/Vicinity.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/Vicinity.java @@ -15,7 +15,7 @@ * Vicinity5 improves on Vicinity4 by allowing for the nodes to not be distributed evenly throughout * the location space. This is needed for fMRI data when the voxels are not perfect cubes. * - * @author jdramsey + * @author josephramsey * @author Erich Kummerfeld */ public class Vicinity { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/BryanSensitivityStudy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/BryanSensitivityStudy.java index 57b7c6e75e..ade3643795 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/BryanSensitivityStudy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/BryanSensitivityStudy.java @@ -37,7 +37,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class BryanSensitivityStudy { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition1.java index 93bf6a3ad9..9ece3834f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition1.java @@ -39,7 +39,7 @@ * saves them. For other formats, specialty data loaders can be written to implement the * Simulation interface. * - * @author jdramsey + * @author josephramsey */ public class Condition1 { public void generateTetradResults() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition2.java index befb0e6741..1997c9d8ef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/Condition2.java @@ -36,7 +36,7 @@ * saves them. For other formats, specialty data loaders can be written to implement the * Simulation interface. * - * @author jdramsey + * @author josephramsey */ public class Condition2 { public void generateTetradResults() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareFromFiles.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareFromFiles.java index 93e5bbb2ca..202bd2676a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareFromFiles.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareFromFiles.java @@ -38,7 +38,7 @@ * saves them. For other formats, specialty data loaders can be written to implement the * Simulation interface. * - * @author jdramsey + * @author josephramsey */ public class ExampleCompareFromFiles { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulation.java index 6dda705e02..2c3af2a69f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulation.java @@ -35,7 +35,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class ExampleCompareSimulation { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulationDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulationDiscrete.java index 2fc2b434ac..ac648703e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulationDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleCompareSimulationDiscrete.java @@ -39,7 +39,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class ExampleCompareSimulationDiscrete { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleFirstInflection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleFirstInflection.java index 1a3cef52b7..4a2848daae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleFirstInflection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleFirstInflection.java @@ -36,7 +36,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class ExampleFirstInflection { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleSave.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleSave.java index 762e5edee7..5c4982074f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleSave.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleSave.java @@ -33,7 +33,7 @@ /** * An example script to save out data files and graphs from a simulation. * - * @author jdramsey + * @author josephramsey */ public class ExampleSave { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleStars.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleStars.java index 2c4de94fea..9fc9d1f820 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleStars.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/ExampleStars.java @@ -37,7 +37,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class ExampleStars { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java index 6bca10b28b..aa6ccf3d38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java @@ -40,7 +40,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class LingamStudy { public static void main(String... args) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index 806249b6c1..7921ac087a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -27,7 +27,7 @@ /** * Does a comparison of algorithm results across algorithm type, sample sizes, etc. * - * @author jdramsey 2016.03.24 + * @author josephramsey 2016.03.24 */ public class Comparison { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index da1dd16838..adb2c2e8c9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -42,7 +42,7 @@ * Does a comparison of algorithm results across algorithm type, sample sizes, * etc. * - * @author jdramsey 2016.03.24 + * @author josephramsey 2016.03.24 * @author dmalinsky 2016.05.20 */ public class Comparison2 { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonResult.java index fb8e66ffe8..0aa80d70eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonResult.java @@ -7,7 +7,7 @@ * . * Result of a comparison. * - * @author jdramsey 2016.03.24 + * @author josephramsey 2016.03.24 */ public class ComparisonResult { private final ComparisonParameters params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonScript.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonScript.java index dfedd1f981..4089d0f21a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonScript.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ComparisonScript.java @@ -9,7 +9,7 @@ /** * Runs algorithm on data set (simulation is OK), printing out error statistics. * - * @author jdramsey 2016.03.24 + * @author josephramsey 2016.03.24 * @author dmalinsky 2016.03.28 */ public class ComparisonScript { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ExploreComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ExploreComparison.java index 8a013b5c7b..a06271d22a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ExploreComparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/ExploreComparison.java @@ -8,7 +8,7 @@ /** * Runs algorithm on data set (simulation is OK), printing out error statistics. * - * @author jdramsey 2016.03.24 + * @author josephramsey 2016.03.24 */ public class ExploreComparison { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Experimental.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Experimental.java index c21fc4de9c..5f0f8a93b8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Experimental.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Experimental.java @@ -3,7 +3,7 @@ /** * Tags a file as experimental so it's not listed in the configuration. * - * @author jdramsey + * @author josephramsey */ public interface Experimental { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescription.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescription.java index 9ea842cf8c..a062774ce8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescription.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescription.java @@ -5,7 +5,7 @@ /** * Describes a parameter. * - * @author jdramsey + * @author josephramsey * @author Zhou Yuan zhy19@pitt.edu */ public class ParamDescription { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescriptions.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescriptions.java index 969f855712..4d1aaca255 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescriptions.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ParamDescriptions.java @@ -13,7 +13,7 @@ * Stores descriptions of the parameters for the simulation box. All parameters * that go into the interface need to be described here. * - * @author jdramsey + * @author josephramsey * @author Zhou Yuan zhy19@pitt.edu * @author Kevin V. Bui (kvb2@pitt.edu) */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java index e4fa477eaa..87e5d61f3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java @@ -8,7 +8,7 @@ * for known parameters. Returns a list of parameters with their values, for the * parameters whose values have been retrieved, using the toString method. * - * @author jdramsey + * @author josephramsey */ public class Parameters implements TetradSerializable { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java index 097dc395bc..60a08a0ff8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java @@ -19,7 +19,7 @@ /** * Loads autistic/typical data files from a given directory and runs FASK on each one. * - * @author jdramsey + * @author josephramsey */ public class FaskGraphs { private final List filenames = new ArrayList<>(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java index 33455d1a98..9636218707 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java @@ -17,7 +17,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class LoadContinuousDataAndSingleGraph implements Simulation, HasParameterValues { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java index 88a0ad9343..a643827d67 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java @@ -13,7 +13,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class LoadContinuousDataAndSingleGraphKun implements Simulation, HasParameterValues { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java index ad97bd2cfd..e89065b288 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java @@ -16,7 +16,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class LoadContinuousDataSmithSim implements Simulation, HasParameterValues { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java index 111688b7be..d67dc8d2b9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java @@ -17,7 +17,7 @@ import java.util.List; /** - * @author jdramsey + * @author josephramsey */ public class LoadMadelynData implements Simulation, HasParameterValues { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java index 6b5fe22e6b..129c99fc89 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java @@ -26,7 +26,7 @@ import static org.apache.commons.math3.util.FastMath.abs; /** - * @author jdramsey + * @author josephramsey */ public class SpecialDataClark implements Simulation { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialExampleSimulationClark.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialExampleSimulationClark.java index 6b7db7ee84..eee02294a0 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialExampleSimulationClark.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialExampleSimulationClark.java @@ -11,7 +11,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class SpecialExampleSimulationClark { public static void main(String... args) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java index 7c4bad4ff4..a8e78a2b73 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java @@ -13,7 +13,7 @@ /** * A special graph for testing a model of Clark's. * - * @author jdramsey + * @author josephramsey */ public class SpecialGraphClark implements RandomGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java index 7208d6605c..8fb503a550 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAutisticClassification.java @@ -42,7 +42,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class TestAutisticClassification { enum Type {LEAVE_ONE_OUT, TRAIN_TEST} diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestConditionalGaussianSimulation.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestConditionalGaussianSimulation.java index 69b30f2916..0ee839daa8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestConditionalGaussianSimulation.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestConditionalGaussianSimulation.java @@ -34,7 +34,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class TestConditionalGaussianSimulation { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java index d958cfd595..e9b421f311 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java @@ -42,7 +42,7 @@ public final class TestCopy { /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public static void main(String... args) { Parameters parameters = new Parameters(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java index e3833af8f5..7a71dce7b3 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java @@ -28,7 +28,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class TestFaskSimpleSimulaton { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGenerateMixedData.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGenerateMixedData.java index 19a82f0b81..1ea41ec1f4 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGenerateMixedData.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGenerateMixedData.java @@ -29,7 +29,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class TestGenerateMixedData { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestImagesSimulation.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestImagesSimulation.java index 0a3e0bfecf..1e8bc4113c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestImagesSimulation.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestImagesSimulation.java @@ -33,7 +33,7 @@ /** * An example script to simulate data and run a comparison analysis on it. * - * @author jdramsey + * @author josephramsey */ public class TestImagesSimulation { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKunMeasurementError.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKunMeasurementError.java index dc13967d37..5bfbda6c65 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKunMeasurementError.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKunMeasurementError.java @@ -37,7 +37,7 @@ /** * Pulling this test out for Madelyn. * - * @author jdramsey + * @author josephramsey */ public class TestKunMeasurementError { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java index 7523452a20..a423a9b4f2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri.java @@ -45,7 +45,7 @@ /** * Pulling this test out for Madelyn. * - * @author jdramsey + * @author josephramsey */ public class TestSimulatedFmri { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri2.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri2.java index 9b3a70dc28..84d95b34e1 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri2.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri2.java @@ -34,7 +34,7 @@ /** * My script. * - * @author jdramsey + * @author josephramsey */ public class TestSimulatedFmri2 { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri3.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri3.java index b46855e9cd..800cea1490 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri3.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmri3.java @@ -33,7 +33,7 @@ /** * Pulling this test out for Madelyn. * - * @author jdramsey + * @author josephramsey */ public class TestSimulatedFmri3 { From f3aad67fff98399e57489f396337316b5d87a88b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 12:48:03 -0400 Subject: [PATCH 349/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java | 2 +- .../main/java/edu/cmu/tetradapp/app/AboutTetradAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/CloseSessionAction.java | 2 +- .../java/edu/cmu/tetradapp/app/ConstructTemplateAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/ContributorsAction.java | 2 +- .../java/edu/cmu/tetradapp/app/CopySubsessionAction.java | 2 +- .../java/edu/cmu/tetradapp/app/CutSubsessionAction.java | 2 +- .../edu/cmu/tetradapp/app/DecompressibleInputStream.java | 2 +- .../java/edu/cmu/tetradapp/app/DeleteSubsessionAction.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/ExitAction.java | 2 +- .../java/edu/cmu/tetradapp/app/FontSelectionAction.java | 2 +- .../java/edu/cmu/tetradapp/app/LaunchFlowchartAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/LaunchManualAction.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/LicenseAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/LoadSessionAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/NewSessionAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/NoteDisplayComp.java | 2 +- .../main/java/edu/cmu/tetradapp/app/NumberFormatAction.java | 2 +- .../java/edu/cmu/tetradapp/app/PasteSubsessionAction.java | 2 +- .../java/edu/cmu/tetradapp/app/RunSimulationAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/SaveSessionAction.java | 2 +- .../java/edu/cmu/tetradapp/app/SaveSessionAsAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/SessionDisplayComp.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/SessionEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/app/SessionEditorEdge.java | 2 +- .../main/java/edu/cmu/tetradapp/app/SessionEditorNode.java | 2 +- .../java/edu/cmu/tetradapp/app/SessionEditorToolbar.java | 2 +- .../java/edu/cmu/tetradapp/app/SessionEditorWorkbench.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/SessionUtils.java | 2 +- .../java/edu/cmu/tetradapp/app/SessionVersionAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/SessionWrappers.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/StdDisplayComp.java | 2 +- .../java/edu/cmu/tetradapp/app/SubsessionSelection.java | 2 +- .../edu/cmu/tetradapp/app/TestSessionEditorWorkbench.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/TetFileFilter.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java | 2 +- .../java/edu/cmu/tetradapp/app/TetradInternalFrame.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java | 2 +- .../src/main/java/edu/cmu/tetradapp/app/WarrantyAction.java | 2 +- .../main/java/edu/cmu/tetradapp/app/WindowMenuListener.java | 2 +- .../java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/AllPathsAction.java | 2 +- .../edu/cmu/tetradapp/editor/BayesDataParamsEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/BayesEstimatorEditor.java | 2 +- .../cmu/tetradapp/editor/BayesEstimatorEditorWizard.java | 2 +- .../tetradapp/editor/BayesEstimatorNodeEditingTable.java | 4 ++-- .../main/java/edu/cmu/tetradapp/editor/BayesImEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/BayesImEditorObs.java | 2 +- .../java/edu/cmu/tetradapp/editor/BayesImEditorWizard.java | 2 +- .../edu/cmu/tetradapp/editor/BayesImEditorWizardObs.java | 2 +- .../edu/cmu/tetradapp/editor/BayesImNodeEditingTable.java | 4 ++-- .../cmu/tetradapp/editor/BayesImNodeEditingTableObs.java | 2 +- .../java/edu/cmu/tetradapp/editor/BayesImParamsEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/BayesPmEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/BayesPmEditorWizard.java | 4 ++-- .../java/edu/cmu/tetradapp/editor/BayesPmParamsEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/BayesUpdaterEditor.java | 2 +- .../edu/cmu/tetradapp/editor/BayesUpdaterEditorObs.java | 2 +- .../cmu/tetradapp/editor/BootstrapSamplerParamsEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/CPDAGFitEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/ClusterEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/CopySubgraphAction.java | 2 +- .../java/edu/cmu/tetradapp/editor/CovMatrixDisplay.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/CovMatrixJTable.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/CovMatrixTable.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/DagEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/DagGraphToolbar.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/DataCellEditor.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/DataDisplay.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/DataEditor.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/DataToken.java | 2 +- .../cmu/tetradapp/editor/DirichletBayesImCountsWizard.java | 2 +- .../edu/cmu/tetradapp/editor/DirichletBayesImEditor.java | 2 +- .../tetradapp/editor/DirichletBayesImNodeCountsTable.java | 4 ++-- .../tetradapp/editor/DirichletBayesImNodeProbsTable.java | 4 ++-- .../cmu/tetradapp/editor/DirichletBayesImParamsEditor.java | 2 +- .../cmu/tetradapp/editor/DirichletBayesImProbsWizard.java | 2 +- .../tetradapp/editor/DirichletEstimatorParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/DiscDetIndepParamsEditor.java | 2 +- .../cmu/tetradapp/editor/EMBayesEstimatorEditorWizard.java | 2 +- .../cmu/tetradapp/editor/EMBayesEstimatorParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/EdgewiseComparisonEditor.java | 2 +- .../tetradapp/editor/EdgewiseComparisonParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/EmBayesEstimatorEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/EvidenceEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/EvidenceEditorObs.java | 2 +- .../edu/cmu/tetradapp/editor/EvidenceWizardMultiple.java | 2 +- .../edu/cmu/tetradapp/editor/EvidenceWizardMultipleObs.java | 2 +- .../java/edu/cmu/tetradapp/editor/EvidenceWizardSingle.java | 2 +- .../edu/cmu/tetradapp/editor/EvidenceWizardSingleObs.java | 2 +- .../edu/cmu/tetradapp/editor/GeneralAlgorithmEditor.java | 2 +- .../cmu/tetradapp/editor/GeneralizedExpressionEditor.java | 2 +- .../editor/GeneralizedExpressionParameterizer.java | 2 +- .../cmu/tetradapp/editor/GeneralizedSemEstimatorEditor.java | 2 +- .../edu/cmu/tetradapp/editor/GeneralizedSemImEditor.java | 2 +- .../edu/cmu/tetradapp/editor/GeneralizedSemPmEditor.java | 2 +- .../edu/cmu/tetradapp/editor/GeneralizedTemplateEditor.java | 2 +- .../tetradapp/editor/GraphAdjacencyIntersectionWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/GraphEditable.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/GraphFileMenu.java | 2 +- .../edu/cmu/tetradapp/editor/GraphIntersectionsEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/GraphParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/GraphPropertiesAction.java | 2 +- .../java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/GraphToolbar.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/HistogramView.java | 2 +- .../java/edu/cmu/tetradapp/editor/IndTestMenuItems.java | 2 +- .../java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java | 2 +- .../edu/cmu/tetradapp/editor/IndependenceFactsEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/LoadDataAction.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/LoadDataDialog.java | 2 +- .../java/edu/cmu/tetradapp/editor/LoadDataSettings.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/LogParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/LogisticRegressionEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java | 2 +- .../edu/cmu/tetradapp/editor/MisclassificationsEditor.java | 2 +- .../tetradapp/editor/MissingDataInjectorParamsEditor.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/NoteEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/NumberCellEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/NumberCellRenderer.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/PagColorer.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/ParameterEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/PasteSubgraphAction.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/PathsAction.java | 2 +- .../edu/cmu/tetradapp/editor/RandomDagScaleFreeEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/RandomGraphEditor.java | 2 +- .../edu/cmu/tetradapp/editor/RandomMimParamsEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/RegressionEditor.java | 4 ++-- .../java/edu/cmu/tetradapp/editor/SaveComponentImage.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/SaveDataAction.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/SaveScreenshot.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/ScatterPlot.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/ScatterPlotView.java | 2 +- .../java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java | 2 +- .../edu/cmu/tetradapp/editor/SelectBidirectedAction.java | 2 +- .../java/edu/cmu/tetradapp/editor/SelectDirectedAction.java | 2 +- .../java/edu/cmu/tetradapp/editor/SelectLatentsAction.java | 2 +- .../edu/cmu/tetradapp/editor/SelectUndirectedAction.java | 2 +- .../java/edu/cmu/tetradapp/editor/SemEstimatorEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/SemGraphToolbar.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/SemImEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/SemImParamsEditor.java | 2 +- .../src/main/java/edu/cmu/tetradapp/editor/SemPmEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/SemUpdaterEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/SimulationEditor.java | 2 +- .../edu/cmu/tetradapp/editor/SimulationParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/SplitCasesParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/StandardizedSemImEditor.java | 2 +- .../tetradapp/editor/StructEMBayesSearchEditorWizard.java | 2 +- .../edu/cmu/tetradapp/editor/StructEmBayesSearchEditor.java | 2 +- .../java/edu/cmu/tetradapp/editor/SubgraphSelection.java | 2 +- .../java/edu/cmu/tetradapp/editor/TabularDataJTable.java | 2 +- .../java/edu/cmu/tetradapp/editor/TabularDataTable.java | 2 +- .../main/java/edu/cmu/tetradapp/editor/TestHistogram.java | 2 +- .../java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java | 2 +- .../edu/cmu/tetradapp/editor/TimeSeriesDataDisplay.java | 2 +- .../cmu/tetradapp/editor/TimeSeriesDataDisplayJTable.java | 4 ++-- .../java/edu/cmu/tetradapp/editor/UnderliningsAction.java | 2 +- .../java/edu/cmu/tetradapp/editor/UpdatedBayesImWizard.java | 6 +++--- .../edu/cmu/tetradapp/editor/UpdatedBayesImWizardObs.java | 6 +++--- .../editor/datamanip/ContinuousDiscretizationEditor.java | 2 +- .../editor/datamanip/DiscreteDiscretizationEditor.java | 2 +- .../editor/datamanip/DiscretizationParamsEditor.java | 2 +- .../edu/cmu/tetradapp/editor/datamanip/RangeEditor.java | 2 +- .../tetradapp/knowledge_editor/IndependenceFactsEditor.java | 2 +- .../tetradapp/knowledge_editor/KnowledgeDisplayEdge.java | 2 +- .../tetradapp/knowledge_editor/KnowledgeDisplayNode.java | 2 +- .../tetradapp/knowledge_editor/KnowledgeEditorToolbar.java | 2 +- .../edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java | 2 +- .../cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java | 2 +- .../cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java | 2 +- .../cmu/tetradapp/knowledge_editor/KnowledgeWorkbench.java | 2 +- .../edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/AbstractMimRunner.java | 2 +- .../main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/BayesImWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/BayesImWrapperObs.java | 2 +- .../main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java | 2 +- .../cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java | 2 +- .../edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java | 2 +- .../java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java | 2 +- .../java/edu/cmu/tetradapp/model/CorrMatrixConverter.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/DagWrapper.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/DataCenterer.java | 2 +- .../main/java/edu/cmu/tetradapp/model/DataStandardizer.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/DataWrapper.java | 2 +- .../edu/cmu/tetradapp/model/DirichletBayesImWrapper.java | 2 +- .../edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java | 2 +- .../edu/cmu/tetradapp/model/EdgewiseComparisonModel.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/EditorUtils.java | 2 +- .../edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java | 2 +- .../tetradapp/model/ExtraCategoryInterpolatorWrapper.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/FasRunner.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/FciRunner.java | 2 +- .../cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java | 2 +- .../edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java | 2 +- .../edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/GraphComparisonParams.java | 2 +- .../java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/GraphSource.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java | 2 +- .../edu/cmu/tetradapp/model/IdentifiabilityWrapper.java | 2 +- .../tetradapp/model/ImpliedCovarianceDataAllWrapper.java | 2 +- .../cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/IndTestChooser.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/IndTestModel.java | 2 +- .../main/java/edu/cmu/tetradapp/model/IndTestProducer.java | 2 +- .../edu/cmu/tetradapp/model/IndependenceFactsModel.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/Indexable.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/IonRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/KnowledgeEditable.java | 2 +- .../edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java | 2 +- .../edu/cmu/tetradapp/model/MeasurementModelWrapper.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/MimRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/Misclassifications.java | 2 +- .../edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java | 2 +- .../edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/MultipleDataSource.java | 2 +- .../java/edu/cmu/tetradapp/model/MultipleGraphSource.java | 2 +- .../edu/cmu/tetradapp/model/NonparanormalTransform.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/NoteModel.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/PcRunner.java | 2 +- .../tetradapp/model/ReplaceMissingWithRandomWrapper.java | 2 +- .../edu/cmu/tetradapp/model/RowSummingExactWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java | 2 +- .../main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/SessionNodeWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/SessionWrapper.java | 2 +- .../edu/cmu/tetradapp/model/StandardizedSemImWrapper.java | 2 +- .../edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java | 2 +- .../java/edu/cmu/tetradapp/model/TabularComparison.java | 2 +- .../main/java/edu/cmu/tetradapp/model/TetradMetadata.java | 2 +- .../java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java | 2 +- .../java/edu/cmu/tetradapp/model/UnlistedSessionModel.java | 2 +- .../main/java/edu/cmu/tetradapp/model/UpdaterWrapper.java | 2 +- .../main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java | 2 +- .../src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java | 2 +- .../main/java/edu/cmu/tetradapp/util/CopyLayoutAction.java | 2 +- .../java/edu/cmu/tetradapp/util/DesktopControllable.java | 2 +- .../main/java/edu/cmu/tetradapp/util/DesktopController.java | 2 +- .../main/java/edu/cmu/tetradapp/util/DoubleTextField.java | 2 +- .../edu/cmu/tetradapp/util/EditorWindowIndirectRef.java | 2 +- .../main/java/edu/cmu/tetradapp/util/GraphEditorUtils.java | 2 +- .../src/main/java/edu/cmu/tetradapp/util/GraphHistory.java | 2 +- .../src/main/java/edu/cmu/tetradapp/util/GraphUtils.java | 2 +- .../src/main/java/edu/cmu/tetradapp/util/ImageUtils.java | 2 +- .../src/main/java/edu/cmu/tetradapp/util/IndTestType.java | 2 +- .../src/main/java/edu/cmu/tetradapp/util/IntTextField.java | 2 +- .../main/java/edu/cmu/tetradapp/util/InternalClipboard.java | 2 +- .../main/java/edu/cmu/tetradapp/util/LayoutEditable.java | 2 +- .../main/java/edu/cmu/tetradapp/util/LayoutSelection.java | 2 +- .../src/main/java/edu/cmu/tetradapp/util/LicenseUtils.java | 2 +- .../main/java/edu/cmu/tetradapp/util/PasteLayoutAction.java | 2 +- .../edu/cmu/tetradapp/util/SessionEditorIndirectRef.java | 2 +- .../edu/cmu/tetradapp/util/SessionWrapperIndirectRef.java | 2 +- .../main/java/edu/cmu/tetradapp/util/SortingComboBox.java | 2 +- .../main/java/edu/cmu/tetradapp/util/StringTextField.java | 2 +- .../edu/cmu/tetradapp/util/TetradMetadataIndirectRef.java | 2 +- .../java/edu/cmu/tetradapp/util/TextAreaOutputStream.java | 2 +- .../main/java/edu/cmu/tetradapp/util/WatchedProcess.java | 2 +- .../java/edu/cmu/tetradapp/workbench/AbstractWorkbench.java | 6 +++--- .../main/java/edu/cmu/tetradapp/workbench/CausalOrder.java | 2 +- .../main/java/edu/cmu/tetradapp/workbench/DisplayEdge.java | 2 +- .../main/java/edu/cmu/tetradapp/workbench/DisplayNode.java | 2 +- .../edu/cmu/tetradapp/workbench/DistanceFromSelected.java | 2 +- .../java/edu/cmu/tetradapp/workbench/GraphNodeError.java | 2 +- .../java/edu/cmu/tetradapp/workbench/GraphNodeLatent.java | 2 +- .../java/edu/cmu/tetradapp/workbench/GraphNodeLocked.java | 2 +- .../java/edu/cmu/tetradapp/workbench/GraphNodeMeasured.java | 2 +- .../edu/cmu/tetradapp/workbench/GraphNodeRandomized.java | 2 +- .../java/edu/cmu/tetradapp/workbench/GraphWorkbench.java | 2 +- .../main/java/edu/cmu/tetradapp/workbench/LagWorkbench.java | 2 +- .../main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java | 2 +- .../edu/cmu/tetradapp/workbench/MeasuredDisplayComp.java | 2 +- .../cmu/tetradapp/workbench/MeasuredDisplaySmallComp.java | 2 +- .../main/java/edu/cmu/tetradapp/workbench/Rubberband.java | 2 +- .../edu/cmu/tetradapp/workbench/TimeLagGraphWorkbench.java | 2 +- .../test/java/edu/cmu/tetradapp/test/TestDataWrapper.java | 2 +- .../java/edu/cmu/tetradapp/test/TestGraphWorkbench.java | 2 +- .../java/edu/cmu/tetradapp/test/TestIndependenceFacts.java | 2 +- .../test/java/edu/cmu/tetradapp/test/TestSerialization.java | 2 +- .../src/test/java/edu/cmu/tetradapp/test/TestVersion.java | 2 +- .../edu/cmu/tetradapp/test/TestWatchedProcessDialogs.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/BayesUtils.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/BayesXmlParser.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/BayesXmlRenderer.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/CellTableProbs.java | 2 +- .../cmu/tetrad/bayes/CptInvariantMarginalCalculator.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java | 2 +- .../java/edu/cmu/tetrad/bayes/DirichletDataSetProbs.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/DirichletEstimator.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/DiscreteProbs.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/EmBayesProperties.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java | 2 +- .../edu/cmu/tetrad/bayes/ExtraCategoryInterpolator.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/IntAveDataSetProbs.java | 2 +- .../java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/Manipulation.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/ModeInterpolator.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/Proposition.java | 2 +- .../java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java | 2 +- .../main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java | 2 +- .../src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java | 2 +- .../cmu/tetrad/classify/classify/ClassifierMbDiscrete.java | 2 +- .../java/edu/cmu/tetrad/cluster/ClusteringAlgorithm.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java | 2 +- .../edu/cmu/tetrad/cluster/metrics/SquaredErrorLoss.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/AbstractVariable.java | 2 +- .../main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/BoxDataSet.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/CaseExpander.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java | 2 +- .../edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java | 2 +- .../main/java/edu/cmu/tetrad/data/ContinuousVariable.java | 2 +- .../main/java/edu/cmu/tetrad/data/CorrelationMatrix.java | 2 +- .../java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java | 2 +- .../java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataBox.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/DataFilter.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModel.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/DataModelList.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataSet.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/DataWriter.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/DelimiterType.java | 2 +- .../edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java | 2 +- .../main/java/edu/cmu/tetrad/data/DiscreteVariableType.java | 2 +- .../main/java/edu/cmu/tetrad/data/DiscretizationSpec.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/Discretizer.java | 2 +- .../edu/cmu/tetrad/data/GeneralAndersonDarlingTest.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java | 2 +- .../main/java/edu/cmu/tetrad/data/IndependenceFacts.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java | 2 +- .../java/edu/cmu/tetrad/data/KnowledgeTransferable.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/Lineizer.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/MeanInterpolator.java | 2 +- .../cmu/tetrad/data/MultiGeneralAndersonDarlingTest.java | 2 +- .../main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/RegexTokenizer.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java | 2 +- .../src/main/java/edu/cmu/tetrad/data/VariableSource.java | 2 +- .../java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java | 2 +- .../src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java | 2 +- .../edu/cmu/tetrad/graph/GraphGeneratorRandomNumEdges.java | 2 +- .../src/main/java/edu/cmu/tetrad/graph/GraphNode.java | 2 +- .../src/main/java/edu/cmu/tetrad/graph/GraphUtils.java | 2 +- .../main/java/edu/cmu/tetrad/graph/IndependenceFact.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java | 2 +- .../src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java | 4 ++-- .../java/edu/cmu/tetrad/graph/MisclassificationUtils.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java | 2 +- .../main/java/edu/cmu/tetrad/graph/NodeEqualityMode.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java | 2 +- .../src/main/java/edu/cmu/tetrad/graph/RandomGraph.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java | 2 +- .../src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java | 2 +- .../main/java/edu/cmu/tetrad/graph/TripleClassifier.java | 2 +- .../src/main/java/edu/cmu/tetrad/regression/Regression.java | 2 +- .../edu/cmu/tetrad/regression/RegressionCovariance.java | 2 +- .../java/edu/cmu/tetrad/regression/RegressionDataset.java | 2 +- .../java/edu/cmu/tetrad/regression/RegressionResult.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java | 2 +- .../main/java/edu/cmu/tetrad/search/FasDeterministic.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/GrowShrink.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/LingamPattern.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/ShiftSearch.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java | 2 +- .../tetrad/search/score/ConditionalGaussianLikelihood.java | 2 +- .../cmu/tetrad/search/score/ConditionalGaussianScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/EbicScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/GicScores.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/GraphScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/ImagesScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/IndTestScore.java | 2 +- .../java/edu/cmu/tetrad/search/score/PoissonPriorScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/ScoredGraph.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/SemBicScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java | 2 +- .../search/test/ConditionalCorrelationIndependence.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/GSquareTest.java | 2 +- .../main/java/edu/cmu/tetrad/search/test/IndTestDSep.java | 2 +- .../java/edu/cmu/tetrad/search/test/IndTestFisherZ.java | 2 +- .../search/test/IndTestFisherZConcatenateResiduals.java | 2 +- .../cmu/tetrad/search/test/IndTestFisherZFisherPValue.java | 2 +- .../java/edu/cmu/tetrad/search/test/IndTestGSquare.java | 2 +- .../cmu/tetrad/search/test/IndTestIndependenceFacts.java | 2 +- .../edu/cmu/tetrad/search/test/IndTestPositiveCorr.java | 2 +- .../edu/cmu/tetrad/search/test/IndTestProbabilistic.java | 2 +- .../java/edu/cmu/tetrad/search/test/IndTestRegression.java | 2 +- .../java/edu/cmu/tetrad/search/test/IndependenceTest.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java | 2 +- .../edu/cmu/tetrad/search/utils/DagInCpcagIterator.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/DagIterator.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/DagScorer.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/DagSepsets.java | 2 +- .../java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java | 2 +- .../java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/FciOrient.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java | 2 +- .../java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java | 4 ++-- .../main/java/edu/cmu/tetrad/search/utils/LegalPairs.java | 2 +- .../java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/utils/MaxP.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/MeekRules.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/SepsetMap.java | 2 +- .../java/edu/cmu/tetrad/search/utils/SepsetProducer.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java | 2 +- .../search/work_in_progress/BpcTetradPurifyWashdown.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/FasLofs.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/FaskVote.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/Glasso.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java | 2 +- .../cmu/tetrad/search/work_in_progress/IndTestCramerT.java | 2 +- .../work_in_progress/IndTestFisherZGeneralizedInverse.java | 2 +- .../work_in_progress/IndTestFisherZPercentIndependent.java | 2 +- .../search/work_in_progress/IndTestFisherZRecursive.java | 2 +- .../search/work_in_progress/IndTestMixedMultipleTTest.java | 2 +- .../IndTestMultinomialLogisticRegression.java | 2 +- .../tetrad/search/work_in_progress/InverseCorrelation.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/Ion.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java | 2 +- .../work_in_progress/ProbabilisticMapIndependence.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java | 2 +- .../cmu/tetrad/search/work_in_progress/SampleVcpcFast.java | 2 +- .../search/work_in_progress/SemBicScoreDeterministic.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/VcFas.java | 2 +- .../java/edu/cmu/tetrad/search/work_in_progress/VcPc.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/VcPcFast.java | 2 +- .../edu/cmu/tetrad/search/work_in_progress/Washdown.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java | 2 +- .../java/edu/cmu/tetrad/sem/GeneralizedSemEstimator.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ISemIm.java | 2 +- .../main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/ParamComparison.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/ParameterPair.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Ricf.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/SemEstimator.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/SemEvidence.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/SemManipulation.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/SemOptimizer.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java | 2 +- .../main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java | 4 ++-- .../src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java | 2 +- .../java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java | 6 +++--- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/SemProposition.java | 2 +- .../main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java | 4 ++-- tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java | 2 +- .../src/main/java/edu/cmu/tetrad/sem/TemplateExpander.java | 2 +- .../cmu/tetrad/session/CouldNotCreateModelException.java | 2 +- .../src/main/java/edu/cmu/tetrad/session/Executable.java | 2 +- .../java/edu/cmu/tetrad/session/ExecutionRestarter.java | 2 +- .../java/edu/cmu/tetrad/session/ModificationRegistery.java | 2 +- .../main/java/edu/cmu/tetrad/session/ParamsResettable.java | 2 +- .../src/main/java/edu/cmu/tetrad/session/Session.java | 2 +- .../main/java/edu/cmu/tetrad/session/SessionAdapter.java | 2 +- .../src/main/java/edu/cmu/tetrad/session/SessionEvent.java | 2 +- .../main/java/edu/cmu/tetrad/session/SessionListener.java | 2 +- .../src/main/java/edu/cmu/tetrad/session/SessionModel.java | 2 +- .../src/main/java/edu/cmu/tetrad/session/SessionNode.java | 2 +- .../main/java/edu/cmu/tetrad/session/SessionSupport.java | 2 +- .../main/java/edu/cmu/tetrad/session/SimulationStudy.java | 2 +- .../tetrad/gene/algorithm/reveal/TestRevealEvaluator.java | 2 +- .../study/gene/tetrad/gene/algorithm/util/OutputGraph.java | 2 +- .../study/gene/tetrad/gene/graph/DisplayNameHandler.java | 2 +- .../study/gene/tetrad/gene/graph/ManualLagGraphParams.java | 2 +- .../study/gene/tetrad/gene/graph/RandomActiveLagGraph.java | 2 +- .../study/gene/tetrad/gene/graph/StoredLagGraphParams.java | 2 +- .../study/gene/tetrad/gene/history/BasalInitializer.java | 2 +- .../study/gene/tetrad/gene/history/BasicLagGraph.java | 2 +- .../study/gene/tetrad/gene/history/BooleanFunction.java | 2 +- .../gene/tetrad/gene/history/BooleanGlassFunction.java | 2 +- .../tetrad/study/gene/tetrad/gene/history/DishModel.java | 2 +- .../tetrad/study/gene/tetrad/gene/history/GeneHistory.java | 2 +- .../study/gene/tetrad/gene/history/GraphInitializer.java | 2 +- .../study/gene/tetrad/gene/history/GraphRandomizer.java | 2 +- .../study/gene/tetrad/gene/history/IndexedConnectivity.java | 2 +- .../study/gene/tetrad/gene/history/IndexedLagGraph.java | 2 +- .../study/gene/tetrad/gene/history/IndexedParent.java | 2 +- .../cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java | 2 +- .../tetrad/study/gene/tetrad/gene/history/LaggedFactor.java | 2 +- .../study/gene/tetrad/gene/history/LinearFunction.java | 2 +- .../tetrad/study/gene/tetrad/gene/history/Polynomial.java | 2 +- .../study/gene/tetrad/gene/history/PolynomialFunction.java | 2 +- .../study/gene/tetrad/gene/history/PolynomialTerm.java | 2 +- .../study/gene/tetrad/gene/history/PreviousStepOnly.java | 2 +- .../study/gene/tetrad/gene/history/RandomDistribution.java | 2 +- .../study/gene/tetrad/gene/history/SimpleRandomizer.java | 2 +- .../study/gene/tetrad/gene/history/TestBooleanFunction.java | 2 +- .../gene/tetrad/gene/history/TestIndexedConnectivity.java | 2 +- .../study/gene/tetrad/gene/history/TestIndexedLagGraph.java | 2 +- .../study/gene/tetrad/gene/history/TestPolynomial.java | 2 +- .../study/gene/tetrad/gene/history/TestPolynomialTerm.java | 2 +- .../gene/tetrad/gene/history/TestSimpleRandomizer.java | 2 +- .../study/gene/tetrad/gene/history/UpdateFunction.java | 2 +- .../tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java | 2 +- .../gene/tetrad/gene/simulation/MeasurementSimulator.java | 2 +- .../tetrad/gene/simulation/TestMeasurementSimulator.java | 2 +- .../tetrad/study/gene/tetrad/gene/util/HandleyConvert.java | 2 +- .../study/gene/tetradapp/model/BooleanGlassGeneIm.java | 2 +- .../study/gene/tetradapp/model/BooleanGlassGenePm.java | 2 +- .../edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java | 2 +- .../gene/tetradapp/model/MeasurementSimulatorParams.java | 2 +- .../edu/cmu/tetrad/study/performance/PerformanceTests.java | 2 +- .../cmu/tetrad/study/performance/PerformanceTestsDan.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/ArrUtils.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/ChoiceGenerator.java | 2 +- .../main/java/edu/cmu/tetrad/util/CombinationGenerator.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/CutoffFinder.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Function.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Im.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/Integrator.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/JOptionUtils.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/LogUtils.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/MathUtils.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/MatrixUtils.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/MultiDimIntTable.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/NamingProtocol.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/NumberFormatUtil.java | 2 +- .../java/edu/cmu/tetrad/util/PartialCorrelationPdf.java | 2 +- .../main/java/edu/cmu/tetrad/util/PermutationGenerator.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Pm.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Point.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/RandomUtil.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/RocCalculator.java | 2 +- .../main/java/edu/cmu/tetrad/util/SelectionGenerator.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/SublistGenerator.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/TaskManager.java | 2 +- .../main/java/edu/cmu/tetrad/util/TetradSerializable.java | 2 +- .../edu/cmu/tetrad/util/TetradSerializableExcluded.java | 2 +- .../java/edu/cmu/tetrad/util/TetradSerializableUtils.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/TextTable.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/Unmarshallable.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/Discrete.java | 2 +- .../main/java/edu/cmu/tetrad/util/dist/Distribution.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/Exponential.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/Gamma.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java | 2 +- .../java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/Normal.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/Poisson.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/Split.java | 2 +- .../main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java | 2 +- .../src/main/java/edu/cmu/tetrad/util/dist/Uniform.java | 2 +- .../csb/mgm/IndTestMultinomialLogisticRegressionWald.java | 2 +- .../edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestAndersonDarling.java | 2 +- .../edu/cmu/tetrad/test/TestBayesDiscreteBicScorer.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestBayesIm.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestBayesXml.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestBoxDataSet.java | 2 +- .../java/edu/cmu/tetrad/test/TestCellProbabilities.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestChoiceGenerator.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestCovarianceMatrix.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java | 2 +- .../java/edu/cmu/tetrad/test/TestCptInvariantUpdater.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDag.java | 2 +- .../java/edu/cmu/tetrad/test/TestDagInPatternIterator.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestDagScorer.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestDataSetCellProbs.java | 2 +- .../java/edu/cmu/tetrad/test/TestDelimiterTokenizer.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestDelimiterType.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestDiscreteProbs.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestDiscretizer.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestExpressionParser.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFdr.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestFgesFa.java | 2 +- .../edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestGeneralizedSem.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestGraphConverter.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestGraphUtils.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestHistogram.java | 2 +- .../tetrad/test/TestIndTestFisherGeneralizedInverse.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestIndependenceFact.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestKnowledge.java | 2 +- .../java/edu/cmu/tetrad/test/TestLargeSemSimulator.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestLingamPattern.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestMathUtils.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestMatrix.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestMatrixUtils.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestMimbuild.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPoint.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestPurify.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestRegression.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java | 2 +- .../java/edu/cmu/tetrad/test/TestRowSummingUpdater.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSem.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSemEstimator.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSemEvidence.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSemGraph.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemIm.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestSemProposition.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSemUpdater.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSemXml.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestSerialization.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSession.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSessionEvent.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestSessionNode.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestSessionSupport.java | 2 +- .../test/java/edu/cmu/tetrad/test/TestStandardizedSem.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestStatUtils.java | 2 +- .../src/test/java/edu/cmu/tetrad/test/TestTimeLagGraph.java | 2 +- .../java/edu/cmu/tetrad/test/TestUniformGraphGenerator.java | 2 +- 690 files changed, 709 insertions(+), 709 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java index 8605288b95..be4a052eb3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java @@ -50,7 +50,7 @@ * enough to create a copy of this class with a different name and modify * it. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class Tetrad implements PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/AboutTetradAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/AboutTetradAction.java index 2d1f4b8e89..b1515e3e41 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/AboutTetradAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/AboutTetradAction.java @@ -35,7 +35,7 @@ /** * Closes the frontmost session of the given desktop. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class AboutTetradAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CloseSessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CloseSessionAction.java index 891d74cebd..d091485332 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CloseSessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CloseSessionAction.java @@ -32,7 +32,7 @@ /** * Closes the frontmost session of the given desktop. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class CloseSessionAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java index acccfe1ba5..5315c0be28 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ConstructTemplateAction.java @@ -40,7 +40,7 @@ * Adds a new template session subgraph to the frontmost session editor. of one * of three types. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class ConstructTemplateAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ContributorsAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ContributorsAction.java index cd0da48795..802fc5bc00 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ContributorsAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ContributorsAction.java @@ -30,7 +30,7 @@ /** * Closes the frontmost session of the given desktop. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class ContributorsAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CopySubsessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CopySubsessionAction.java index a530d1a904..3888c4309e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CopySubsessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CopySubsessionAction.java @@ -36,7 +36,7 @@ * Copies a selection of session nodes in the frontmost session editor, to the * clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class CopySubsessionAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CutSubsessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CutSubsessionAction.java index 07c779b471..2c335661b3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CutSubsessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/CutSubsessionAction.java @@ -36,7 +36,7 @@ * Copies a selection of session nodes in the frontmost session editor to the * clipboard and deletes them from the session editor. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class CutSubsessionAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DecompressibleInputStream.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DecompressibleInputStream.java index b80c3cf261..0928496dec 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DecompressibleInputStream.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DecompressibleInputStream.java @@ -32,7 +32,7 @@ *

* Dec 6, 2017 11:10:24 AM * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Kevin V. Bui (kvb2@pitt.edu) */ public class DecompressibleInputStream extends ObjectInputStream { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DeleteSubsessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DeleteSubsessionAction.java index cccb56f997..8a866f1e7d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DeleteSubsessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/DeleteSubsessionAction.java @@ -32,7 +32,7 @@ /** * Deletes a selection of session nodes from the frontmost session editor. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class DeleteSubsessionAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ExitAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ExitAction.java index f894df3824..cac44684d1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ExitAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/ExitAction.java @@ -29,7 +29,7 @@ /** * Exits the Tetrad application. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class ExitAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/FontSelectionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/FontSelectionAction.java index cbe6d29a9f..f1c44ade06 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/FontSelectionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/FontSelectionAction.java @@ -39,7 +39,7 @@ * Copies a selection of session nodes in the frontmost session editor, to the * clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class FontSelectionAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchFlowchartAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchFlowchartAction.java index 4eab8cb76d..c88e04b8bc 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchFlowchartAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchFlowchartAction.java @@ -31,7 +31,7 @@ /** * Closes the frontmost session of the given desktop. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class LaunchFlowchartAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchManualAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchManualAction.java index 0e9976dfb4..97e6ead663 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchManualAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LaunchManualAction.java @@ -31,7 +31,7 @@ /** * Closes the frontmost session of the given desktop. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class LaunchManualAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LicenseAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LicenseAction.java index d01242a88f..8946854881 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LicenseAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LicenseAction.java @@ -31,7 +31,7 @@ /** * Closes the frontmost session of the given desktop. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class LicenseAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LoadSessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LoadSessionAction.java index 16b17283a8..61e6bd0981 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LoadSessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/LoadSessionAction.java @@ -42,7 +42,7 @@ /** * Opens a session from a file. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class LoadSessionAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NewSessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NewSessionAction.java index 4381f40cee..64e9ceede4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NewSessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NewSessionAction.java @@ -29,7 +29,7 @@ /** * Opens a session from a file. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class NewSessionAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NoteDisplayComp.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NoteDisplayComp.java index c423b881dc..fe135b282d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NoteDisplayComp.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NoteDisplayComp.java @@ -29,7 +29,7 @@ /** * Provides a modified appearance for session nodes to be used for notes. * - * @author Joseph Ramsey + * @author josephramsey */ public class NoteDisplayComp extends JComponent implements SessionDisplayComp { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NumberFormatAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NumberFormatAction.java index c5523f581d..5e4edc718e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NumberFormatAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/NumberFormatAction.java @@ -44,7 +44,7 @@ * Presents a dialog allowing the user to change the number format used to * render real numbers throughout Tetrad. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class NumberFormatAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/PasteSubsessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/PasteSubsessionAction.java index b7a5ceaecb..8573b2fb36 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/PasteSubsessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/PasteSubsessionAction.java @@ -39,7 +39,7 @@ * Copies a parentally closed selection of session nodes in the frontmost * session editor to the clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class PasteSubsessionAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/RunSimulationAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/RunSimulationAction.java index f6ec600dd7..ae32ca8fcb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/RunSimulationAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/RunSimulationAction.java @@ -32,7 +32,7 @@ /** * Sets up parameters for logging. * - * @author Joseph Ramsey + * @author josephramsey */ class RunSimulationAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAction.java index 2bef562b14..7dcbde965b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAction.java @@ -38,7 +38,7 @@ /** * Saves a session from a file. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Kevin V. Bui (kvb2@pitt.edu) */ final class SaveSessionAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAsAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAsAction.java index 7950e5785e..e0f59332b7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAsAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SaveSessionAsAction.java @@ -38,7 +38,7 @@ /** * Saves a session from a file. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class SaveSessionAsAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionDisplayComp.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionDisplayComp.java index 6d5b37ca0a..86e9b453fa 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionDisplayComp.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionDisplayComp.java @@ -26,7 +26,7 @@ /** * The appearance of a session node. * - * @author Joseph Ramsey + * @author josephramsey */ public interface SessionDisplayComp extends DisplayComp { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditor.java index 83b5aafe24..9e8b5de72f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditor.java @@ -39,7 +39,7 @@ /** * Displays a toolbar and workbench for editing Session's. * - * @author Joseph Ramsey + * @author josephramsey * @see SessionEditorWorkbench * @see SessionEditorToolbar */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorEdge.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorEdge.java index 02f288b044..30e2e494f4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorEdge.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorEdge.java @@ -29,7 +29,7 @@ /** * Presents an edge in the Tetrad SessionWorkbench. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class SessionEditorEdge extends DisplayEdge { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java index e5eea9c487..88db426939 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorNode.java @@ -55,7 +55,7 @@ * parents being added to appropriate SessionNodes underlying. Double clicking * these nodes launches corresponding model editors. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see SessionEditorWorkbench * @see edu.cmu.tetrad.graph.Edge * @see edu.cmu.tetrad.session.SessionNode diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java index 4c243f85cc..5814ff2c0c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorToolbar.java @@ -38,7 +38,7 @@ * can take in the session editor workbench, whether it's selecting and moving a * node, adding a node of a particular type, or adding an edge. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see SessionEditor * @see SessionEditorToolbar */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorWorkbench.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorWorkbench.java index 80ed3009d1..f7d185ef3c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorWorkbench.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionEditorWorkbench.java @@ -39,7 +39,7 @@ * Adds the functionality needed to turn an abstract workbench into a workbench * usable for editing sessions. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class SessionEditorWorkbench extends AbstractWorkbench { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionUtils.java index 776ffbff68..fff709b2e3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionUtils.java @@ -35,7 +35,7 @@ /** * Some utility methods relevant to sessions. * - * @author Joseph Ramsey + * @author josephramsey */ final class SessionUtils { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionVersionAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionVersionAction.java index ed39a7ac12..9c9bbc372f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionVersionAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionVersionAction.java @@ -36,7 +36,7 @@ /** * Saves a session from a file. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class SessionVersionAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionWrappers.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionWrappers.java index 910b0c13d2..17de4a268e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionWrappers.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SessionWrappers.java @@ -32,7 +32,7 @@ * A collection of public static methods to help construct SessionWrappers * manually. * - * @author Joseph Ramsey + * @author josephramsey */ final class SessionWrappers { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/StdDisplayComp.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/StdDisplayComp.java index 07e95bf827..1d3acd0afb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/StdDisplayComp.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/StdDisplayComp.java @@ -31,7 +31,7 @@ /** * Appearance of session nodes for standard nodes. * - * @author Joseph Ramsey + * @author josephramsey */ public class StdDisplayComp extends JComponent implements SessionDisplayComp { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SubsessionSelection.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SubsessionSelection.java index c5423cf6b2..6f1a29d4e0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SubsessionSelection.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/SubsessionSelection.java @@ -38,7 +38,7 @@ * clone of the session elements list is made on creation, and once the data is * retrieved, it is deleted. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class SubsessionSelection implements Transferable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TestSessionEditorWorkbench.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TestSessionEditorWorkbench.java index 2df293283a..77efd54575 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TestSessionEditorWorkbench.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TestSessionEditorWorkbench.java @@ -30,7 +30,7 @@ /** * Tests the basic functionality of the SessionEditorWorkbench. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class TestSessionEditorWorkbench extends TestCase { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetFileFilter.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetFileFilter.java index 2ec542c8dd..e3d0d26f92 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetFileFilter.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetFileFilter.java @@ -27,7 +27,7 @@ /** * Filters out all but .tet file when loading and saving. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class TetFileFilter extends FileFilter { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java index dc22e88edd..e76a2edf9a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradDesktop.java @@ -48,7 +48,7 @@ * Constructs a desktop for the Tetrad application. * * @author Don Crimbchin (djc2@andrew.cmu.edu) - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Raul Salinas wsalinas@andrew.cmu.edu */ public final class TetradDesktop extends JPanel implements DesktopControllable, diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradInternalFrame.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradInternalFrame.java index 1936bcb8c4..a48b0cf078 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradInternalFrame.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradInternalFrame.java @@ -32,7 +32,7 @@ /** * Extends JInternalFrame to ask the user if she wants to close the window. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TetradInternalFrame extends JInternalFrame { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java index 5dc7630d9d..ecf8fb1869 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/TetradMenuBar.java @@ -37,7 +37,7 @@ /** * The main menubar for Tetrad. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Chirayu Kong Wongchokprasitti chw20@pitt.edu */ final class TetradMenuBar extends JMenuBar { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WarrantyAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WarrantyAction.java index b6693ad7c2..29c12ed727 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WarrantyAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WarrantyAction.java @@ -31,7 +31,7 @@ /** * Closes the frontmost session of the given desktop. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class WarrantyAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java index cbe2b5bb7e..28b9b49af2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/app/WindowMenuListener.java @@ -33,7 +33,7 @@ * internal frames currently on the desktop. When the user selects one of these * titles, the corresponding internal frame is moved to the front. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Chirayu Kong Wongchokprasitti chw20@pitt.edu */ final class WindowMenuListener implements MenuListener, ActionListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java index a10890e514..7c0be82291 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AbstractSearchEditor.java @@ -56,7 +56,7 @@ * threading for you, provide a stop button for algorithm, and do logging. The * execute button used must be getExecuteButton(), or else logging won't work. * - * @author Joseph Ramsey + * @author josephramsey */ public abstract class AbstractSearchEditor extends JPanel implements GraphEditable, IndTestTypeSetter { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AllPathsAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AllPathsAction.java index 1fc36c9866..0e118527e2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AllPathsAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AllPathsAction.java @@ -42,7 +42,7 @@ * Puts up a panel showing some graph properties, e.g., number of nodes and * edges in the graph, etc. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class AllPathsAction extends AbstractAction implements ClipboardOwner { private final GraphWorkbench workbench; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesDataParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesDataParamsEditor.java index b4568dbda3..13cbf6a92a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesDataParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesDataParamsEditor.java @@ -31,7 +31,7 @@ /** * Edits the parameters for simulating new datasets from a Bayes net. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class BayesDataParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditor.java index 8951140fcc..a10d47c5fe 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditor.java @@ -43,7 +43,7 @@ * probabilities of node values given combinations of parent values. * * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BayesEstimatorEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditorWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditorWizard.java index ad9cd057ce..02739fa28c 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditorWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorEditorWizard.java @@ -41,7 +41,7 @@ * of parent values for node N, the probabilities for the values of N * conditional on that combination of parent values must sum to 1.0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class BayesEstimatorEditorWizard extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorNodeEditingTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorNodeEditingTable.java index d60fdb0a75..b974785351 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorNodeEditingTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesEstimatorNodeEditingTable.java @@ -44,7 +44,7 @@ /** * This is the JTable which displays the getModel parameter set (an Model). * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class BayesEstimatorNodeEditingTable extends JTable { private int focusRow; @@ -433,7 +433,7 @@ private int getLastY() { * edited. As they are being edited for a given row, the only condition is * that they be greater than or equal to 0.0. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ static final class Model extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditor.java index 13252534fc..fb1642ea95 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditor.java @@ -36,7 +36,7 @@ * probabilities of node values given combinations of parent values. * * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BayesImEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorObs.java index e37dcc96dc..e394d7282f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorObs.java @@ -36,7 +36,7 @@ * nodes have been specified). * * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ ///////////////////////////////////////////////////////////////// // allow the user to set the probabilities of given combinations diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizard.java index eca04780fb..bd13713142 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizard.java @@ -41,7 +41,7 @@ * of parent values for node N, the probabilities for the values of N * conditional on that combination of parent values must sum to 1.0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class BayesImEditorWizard extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizardObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizardObs.java index 26170e598f..cb40b63b0f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizardObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImEditorWizardObs.java @@ -31,7 +31,7 @@ * Allows the user to choose a variable in a Bayes net and edit the parameters * associated with that variable. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ ////////////////////////////////////// // there is only one JPD table diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTable.java index 86c410aa6d..6c907e451c 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTable.java @@ -44,7 +44,7 @@ /** * This is the JTable which displays the model parameter set. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class BayesImNodeEditingTable extends JTable { private int focusRow; @@ -433,7 +433,7 @@ private int getLastY() { * edited. As they are being edited for a given row, the only condition is * that they be greater than or equal to 0.0. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ static final class Model extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTableObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTableObs.java index e31f5a1c69..878076accd 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTableObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImNodeEditingTableObs.java @@ -46,7 +46,7 @@ /** * This is the JTable which displays the getModel parameter set (an Model). * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ //////////////////////////////////////////////////////// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImParamsEditor.java index 48c73cca36..129ee40c19 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesImParamsEditor.java @@ -30,7 +30,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BayesImParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditor.java index 5139c43d75..b3a3dbd3e7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditor.java @@ -35,7 +35,7 @@ * editing tetrad-style graphs. * * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BayesPmEditor extends JPanel implements PropertyChangeListener, DelegatesEditing { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditorWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditorWizard.java index ef70076339..4728537884 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditorWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmEditorWizard.java @@ -43,7 +43,7 @@ * A wizard to let the user go through a workbench systematically and set the * number of categories for each node along with the names of each category. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class BayesPmEditorWizard extends JPanel { @@ -433,7 +433,7 @@ public void setEditingLatentVariablesAllowed(boolean editingLatentVariablesAllow /** * Edits categories for each variable of a Bayes PM. * - * @author Joseph Ramsey + * @author josephramsey */ class CategoryEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmParamsEditor.java index 8498109e80..44838fd5a1 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesPmParamsEditor.java @@ -30,7 +30,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class BayesPmParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditor.java index b63a25ab3e..ce1d9ab210 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditor.java @@ -37,7 +37,7 @@ /** * Lets the user calculate updated probabilities for a Bayes net. * - * @author Joseph Ramsey + * @author josephramsey */ public class BayesUpdaterEditor extends JPanel implements DelegatesEditing { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditorObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditorObs.java index 62b7ad8047..a570d8faa3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditorObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterEditorObs.java @@ -38,7 +38,7 @@ /** * Lets the user calculate updated probabilities for a Bayes net. * - * @author Joseph Ramsey + * @author josephramsey */ public class BayesUpdaterEditorObs extends JPanel implements DelegatesEditing { private static final int SINGLE_VALUE = 0; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BootstrapSamplerParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BootstrapSamplerParamsEditor.java index f1c9ed88ff..4c520554e3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BootstrapSamplerParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BootstrapSamplerParamsEditor.java @@ -30,7 +30,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly based on similar classes by Joe Ramsey */ public class BootstrapSamplerParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java index d5c354f217..eeab7ac3b7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java @@ -43,7 +43,7 @@ * Assumes that the search method of the CPDAG search has been run and shows the * various options for DAG's consistent with correlation information over the variables. * - * @author Joseph Ramsey + * @author josephramsey */ public class CPDAGDisplay extends JPanel implements GraphEditable { private GraphWorkbench workbench; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGFitEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGFitEditor.java index 4d2f486441..e9850f1f6c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGFitEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGFitEditor.java @@ -35,7 +35,7 @@ * Provides a little display/editor for notes in the session workbench. This * may be elaborated in the future to allow marked up text. * - * @author Joseph Ramsey + * @author josephramsey */ public class CPDAGFitEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ClusterEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ClusterEditor.java index 3f7e3a9830..6dfe012d00 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ClusterEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ClusterEditor.java @@ -43,7 +43,7 @@ /** * Edits which variables get assigned to which clusters. * - * @author Joseph Ramsey + * @author josephramsey */ public final class ClusterEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CopySubgraphAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CopySubgraphAction.java index 2158c7d2fd..15dfda3095 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CopySubgraphAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CopySubgraphAction.java @@ -34,7 +34,7 @@ * Copies a selection of session nodes in the frontmost session editor, to the * clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class CopySubgraphAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixDisplay.java index 038b793657..a5ed9dac80 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixDisplay.java @@ -33,7 +33,7 @@ /** * Presents a covariance matrix as a JTable. * - * @author Joseph Ramsey + * @author josephramsey */ public class CovMatrixDisplay extends JPanel implements DataModelContainer { private final CovMatrixJTable covMatrixJTable; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixJTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixJTable.java index 16ef59bace..d395db7329 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixJTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixJTable.java @@ -43,7 +43,7 @@ /** * Presents a covariance matrix as a JTable. * - * @author Joseph Ramsey + * @author josephramsey */ public class CovMatrixJTable extends JTable implements DataModelContainer, PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixTable.java index df13062dbc..98a360a4a2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CovMatrixTable.java @@ -36,7 +36,7 @@ * Wraps a covMatrix which is possibly smaller than the display window in a * larger AbstractTableModel which will fill the window. * - * @author Joseph Ramsey + * @author josephramsey */ class CovMatrixTable extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java index 2cde3623d4..17771c69db 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagEditor.java @@ -62,7 +62,7 @@ * editing tetrad-style graphs. * * @author Aaron Powers - * @author Joseph Ramsey + * @author josephramsey * @author Zhou Yuan */ public final class DagEditor extends JPanel diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagGraphToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagGraphToolbar.java index e52a918718..14c6af86e3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagGraphToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DagGraphToolbar.java @@ -46,7 +46,7 @@ * tool, allows the user to create new bidirected edges. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey * @see GraphEditor */ class DagGraphToolbar extends JPanel implements PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataCellEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataCellEditor.java index 60ab834069..354f33975f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataCellEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataCellEditor.java @@ -32,7 +32,7 @@ /** * Edits a cell in a data table. * - * @author Joseph Ramsey + * @author josephramsey */ class DataCellEditor extends DefaultCellEditor { private final NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataDisplay.java index 2100063c09..4335a75821 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataDisplay.java @@ -33,7 +33,7 @@ /** * Displays a DataSet object as a JTable. * - * @author Joseph Ramsey + * @author josephramsey */ public class DataDisplay extends JPanel implements DataModelContainer, PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataEditor.java index b986da1a49..7969f3228b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataEditor.java @@ -43,7 +43,7 @@ * Displays data objects and allows users to edit these objects as well as load * and save them. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DataEditor extends JPanel implements KnowledgeEditable, PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataToken.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataToken.java index 395151737f..ac559ab4fc 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataToken.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DataToken.java @@ -25,7 +25,7 @@ /** * Represents the tokens used for reading in data in Tetrad. * - * @author Joseph Ramsey + * @author josephramsey */ public enum DataToken implements Token { WHITESPACE("WHITESPACE"), diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImCountsWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImCountsWizard.java index 27f321a154..c9e424c7f1 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImCountsWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImCountsWizard.java @@ -41,7 +41,7 @@ * of parent values for node N, the probabilities for the values of N * conditional on that combination of parent values must sum to 1.0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class DirichletBayesImCountsWizard extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImEditor.java index d68025516e..0cfa80af7b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImEditor.java @@ -38,7 +38,7 @@ * probabilities of node values given combinations of parent values. * * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class DirichletBayesImEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeCountsTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeCountsTable.java index f20dac7878..1cacc351b5 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeCountsTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeCountsTable.java @@ -45,7 +45,7 @@ /** * This is the JTable which displays the getModel parameter set (an Model). * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class DirichletBayesImNodeCountsTable extends JTable { private int focusRow; @@ -446,7 +446,7 @@ private int getLastY() { * edited. As they are being edited for a given row, the only condition is * that they be greater than or equal to 0.0. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ static final class Model extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeProbsTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeProbsTable.java index 07cf44fe12..b6cfc19579 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeProbsTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImNodeProbsTable.java @@ -45,7 +45,7 @@ /** * This is the JTable which displays the getModel parameter set (an Model). * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class DirichletBayesImNodeProbsTable extends JTable { private int focusRow; @@ -436,7 +436,7 @@ private int getLastY() { * edited. As they are being edited for a given row, the only condition is * that they be greater than or equal to 0.0. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ static final class Model extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImParamsEditor.java index 65ab8d1000..f469e0bab8 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImParamsEditor.java @@ -31,7 +31,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class DirichletBayesImParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImProbsWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImProbsWizard.java index e13dd38cfb..eb217c7633 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImProbsWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletBayesImProbsWizard.java @@ -41,7 +41,7 @@ * of parent values for node N, the probabilities for the values of N * conditional on that combination of parent values must sum to 1.0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class DirichletBayesImProbsWizard extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletEstimatorParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletEstimatorParamsEditor.java index 532f31eaff..1f657e16a8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletEstimatorParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DirichletEstimatorParamsEditor.java @@ -31,7 +31,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class DirichletEstimatorParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DiscDetIndepParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DiscDetIndepParamsEditor.java index 8758d18951..5b3c805b02 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DiscDetIndepParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DiscDetIndepParamsEditor.java @@ -31,7 +31,7 @@ /** * Edits the properties of a measurement params. * - * @author Joseph Ramsey + * @author josephramsey */ class DiscDetIndepParamsEditor extends JComponent { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorEditorWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorEditorWizard.java index 5df42c8068..30e14bc5d4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorEditorWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorEditorWizard.java @@ -42,7 +42,7 @@ * of parent values for node N, the probabilities for the values of N * conditional on that combination of parent values must sum to 1.0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly adapted for EM Bayes estimation. */ final class EMBayesEstimatorEditorWizard extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorParamsEditor.java index abced1193e..45c7864a6a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EMBayesEstimatorParamsEditor.java @@ -31,7 +31,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly based on similar classes by Joe Ramsey */ public class EMBayesEstimatorParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonEditor.java index b0e6ad873d..76e739aee6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonEditor.java @@ -31,7 +31,7 @@ * Provides a little display/editor for notes in the session workbench. This may * be elaborated in the future to allow marked up text. * - * @author Joseph Ramsey + * @author josephramsey */ public class EdgewiseComparisonEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonParamsEditor.java index 6a17e6b5a8..762401d6fd 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EdgewiseComparisonParamsEditor.java @@ -34,7 +34,7 @@ /** * Edits the parameters for generating random graphs. * - * @author Joseph Ramsey + * @author josephramsey */ public class EdgewiseComparisonParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EmBayesEstimatorEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EmBayesEstimatorEditor.java index 4fdcf6fdcd..6535eec7e7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EmBayesEstimatorEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EmBayesEstimatorEditor.java @@ -40,7 +40,7 @@ * probabilities of node values given combinations of parent values. * * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly - adapted for EM Bayes estimator and Strucural EM * Bayes estimator */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditor.java index a4c1a9b427..8f123e24c7 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditor.java @@ -39,7 +39,7 @@ * disjunctive) are known for which variables, and which variables are * manipulated. * - * @author Joseph Ramsey + * @author josephramsey */ class EvidenceEditor extends JPanel { private final Evidence evidence; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditorObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditorObs.java index e64628531c..0b12ac72ae 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditorObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceEditorObs.java @@ -40,7 +40,7 @@ * disjunctive) are known for which variables, and which variables are * manipulated. * - * @author Joseph Ramsey + * @author josephramsey */ class EvidenceEditorObs extends JPanel { private final Evidence evidence; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultiple.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultiple.java index 181ab5b97a..9edbc599f2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultiple.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultiple.java @@ -42,7 +42,7 @@ * Bayes updating results. * * @author William Taysom -- Jun 14, 2003 - * @author Joseph Ramsey + * @author josephramsey */ class EvidenceWizardMultiple extends JPanel { private final UpdaterWrapper updaterWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultipleObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultipleObs.java index ec9e9265e6..ec288850e4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultipleObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardMultipleObs.java @@ -43,7 +43,7 @@ * Bayes updating results. * * @author William Taysom -- Jun 14, 2003 - * @author Joseph Ramsey + * @author josephramsey */ class EvidenceWizardMultipleObs extends JPanel { private final UpdaterWrapper updaterWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingle.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingle.java index f30e8836ba..50d0b4dfe9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingle.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingle.java @@ -36,7 +36,7 @@ * Bayes updating results. * * @author William Taysom -- Jun 14, 2003 - * @author Joseph Ramsey + * @author josephramsey */ class EvidenceWizardSingle extends JPanel { private final UpdaterWrapper updaterWrapper; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingleObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingleObs.java index 4c2c315378..96fae251ed 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingleObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/EvidenceWizardSingleObs.java @@ -36,7 +36,7 @@ * Bayes updating results. * * @author William Taysom -- Jun 14, 2003 - * @author Joseph Ramsey + * @author josephramsey */ //////////////////////////////////////////////////////////////////////// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralAlgorithmEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralAlgorithmEditor.java index eaa90a3abd..8f929c8b56 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralAlgorithmEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralAlgorithmEditor.java @@ -45,7 +45,7 @@ /** * Edits some algorithm to search for Markov blanket CPDAGs. * - * @author Joseph Ramsey + * @author josephramsey * @author Chirayu Kong Wongchokprasitti, PhD (chw20@pitt.edu) * @author Zhou Yuan (zhy19@pitt.edu) * @author Kevin V. Bui (kvb2@pitt.edu) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionEditor.java index 0a33d7a2ea..997361a444 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionEditor.java @@ -44,7 +44,7 @@ /** * Edits an expression for a node in the generalized SEM PM. * - * @author Joseph Ramsey + * @author josephramsey */ class GeneralizedExpressionEditor extends JComponent { /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionParameterizer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionParameterizer.java index 3653db204e..9a0c95d1ed 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionParameterizer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedExpressionParameterizer.java @@ -39,7 +39,7 @@ /** * Edits an expression for a node in the generalized SEM PM. * - * @author Joseph Ramsey + * @author josephramsey */ class GeneralizedExpressionParameterizer extends JComponent { private final Node node; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemEstimatorEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemEstimatorEditor.java index e259d9774a..33cfd007ca 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemEstimatorEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemEstimatorEditor.java @@ -46,7 +46,7 @@ * Edits a SEM PM model. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey */ public final class GeneralizedSemEstimatorEditor extends JPanel implements DelegatesEditing, LayoutEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemImEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemImEditor.java index 26b22fedfb..7997123859 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemImEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemImEditor.java @@ -47,7 +47,7 @@ * Edits a SEM PM model. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey */ public final class GeneralizedSemImEditor extends JPanel implements DelegatesEditing, LayoutEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemPmEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemPmEditor.java index 7a3a59e2f2..6f5cf1cd6d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemPmEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedSemPmEditor.java @@ -49,7 +49,7 @@ * Edits a SEM PM model. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey */ public final class GeneralizedSemPmEditor extends JPanel implements DelegatesEditing, LayoutEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedTemplateEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedTemplateEditor.java index 33a93fcd6c..0861c99032 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedTemplateEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GeneralizedTemplateEditor.java @@ -46,7 +46,7 @@ /** * Edits an expression for a node in the generalized SEM PM. * - * @author Joseph Ramsey + * @author josephramsey */ class GeneralizedTemplateEditor extends JComponent { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java index 76fc6018a6..a1e88fd365 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java @@ -37,7 +37,7 @@ * adjacencies that are shared by all graphs, the the adjacencies that * are shared by all but one graph, and so on down to one graph. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphAdjacencyIntersectionWrapper implements SessionModel, DoNotAddOldModel { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditable.java index df8c240079..d3d75ad1e5 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditable.java @@ -31,7 +31,7 @@ * Interface for graph editors, useful for situations where graph editors need to * be treated generally. * - * @author Joseph Ramsey + * @author josephramsey */ public interface GraphEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java index d4dd560791..1498dc7f1d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphEditor.java @@ -60,7 +60,7 @@ * editing tetrad-style graphs. * * @author Aaron Powers - * @author Joseph Ramsey + * @author josephramsey * @author Zhou Yuan 8/22/2018 */ public final class GraphEditor extends JPanel implements GraphEditable, LayoutEditable, IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphFileMenu.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphFileMenu.java index 13f3790f7f..a25efa9a7a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphFileMenu.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphFileMenu.java @@ -29,7 +29,7 @@ * editing tetrad-style graphs. * * @author Aaron Powers - * @author Joseph Ramsey + * @author josephramsey */ public final class GraphFileMenu extends JMenu { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphIntersectionsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphIntersectionsEditor.java index 1553d7e0eb..b339d347f4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphIntersectionsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphIntersectionsEditor.java @@ -32,7 +32,7 @@ * Provides a little display/editor for notes in the session workbench. This * may be elaborated in the future to allow marked up text. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphIntersectionsEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphParamsEditor.java index 5d2165d485..ecf3ed3789 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphParamsEditor.java @@ -30,7 +30,7 @@ /** * Edits the parameters for generating random graphs. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphParamsEditor extends JPanel implements ParameterEditor { private Parameters params = new Parameters(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphPropertiesAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphPropertiesAction.java index 45a54a6a2a..0554952e16 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphPropertiesAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphPropertiesAction.java @@ -37,7 +37,7 @@ * Puts up a panel showing some graph properties, e.g., number of nodes and * edges in the graph, etc. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class GraphPropertiesAction extends AbstractAction implements ClipboardOwner { private GraphWorkbench workbench; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java index 67fb6f1b02..e8b1d583e7 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphSelectionEditor.java @@ -544,7 +544,7 @@ public List> getTriplesLists(Node node) { * Puts up a panel showing some graph properties, e.g., number of nodes and * edges in the graph, etc. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public static class GraphSelectionTextInputAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphToolbar.java index edec2db064..0e32080168 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphToolbar.java @@ -43,7 +43,7 @@ * tool, allows the user to create new bidirected edges. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey * @see GraphEditor */ public class GraphToolbar extends JPanel implements PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/HistogramView.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/HistogramView.java index 4de11ff7a1..c926413d1d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/HistogramView.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/HistogramView.java @@ -42,7 +42,7 @@ /** * View for the Histogram class. Shows a histogram and gives controls for conditioning, etc. * - * @author Joseph Ramsey + * @author josephramsey */ public class HistogramView extends JPanel { private final HistogramPanel histogramPanel; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java index 91036b845d..6532143f10 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestMenuItems.java @@ -33,7 +33,7 @@ /** * A common way to add menu items to independence test menus to make these menus consistent across editors. * - * @author Joseph Ramsey + * @author josephramsey */ class IndTestMenuItems { static void addIndependenceTestChoices(JMenu test, IndTestTypeSetter setter) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java index 62b90ee344..664e83ebec 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndTestTypeSetter.java @@ -27,7 +27,7 @@ /** * Helps to set independence test types. * - * @author Joseph Ramsey + * @author josephramsey */ interface IndTestTypeSetter { void setTestType(IndTestType testType); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java index 184a690d02..b8443791cb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/IndependenceFactsEditor.java @@ -52,7 +52,7 @@ /** * Lists independence facts specified by user and allows the list to be sorted by independence fact or by p value. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndependenceFactsEditor extends JPanel { private IndTestModel model; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataAction.java index ab8bf66b24..fc57102d99 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataAction.java @@ -36,7 +36,7 @@ /** * New data loading action. * - * @author Joseph Ramsey + * @author josephramsey */ final class LoadDataAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataDialog.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataDialog.java index 8530bdd33d..ee4ce561bd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataDialog.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataDialog.java @@ -50,7 +50,7 @@ * Panel (to be put in a dialog) for letting the user choose how a data file * should be loaded. * - * @author Joseph Ramsey + * @author josephramsey */ public final class LoadDataDialog extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataSettings.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataSettings.java index 7744241ac4..cdaf5aa8e1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataSettings.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadDataSettings.java @@ -63,7 +63,7 @@ * Panel (to be put in a dialog) for letting the user choose how a data file * should be loaded. * - * @author Joseph Ramsey + * @author josephramsey */ public final class LoadDataSettings extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java index bdaf2850b9..f41af49425 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java @@ -34,7 +34,7 @@ /** * Saves out a PNG image for a component. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class LoadGraph extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java index faa104df41..05e4311340 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java @@ -32,7 +32,7 @@ import java.util.prefs.Preferences; /** - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class LoadGraphPcalg extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java index ecf0deb077..d77c46b810 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java @@ -34,7 +34,7 @@ /** * Saves out a PNG image for a component. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class LoadGraphTxt extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogParamsEditor.java index 821edf51c7..1364c17547 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogParamsEditor.java @@ -32,7 +32,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly based on similar classes by Joe Ramsey */ public class LogParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java index 1c587e3f5a..d66c7e7b29 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java @@ -44,7 +44,7 @@ * to show the graph of the target with significant regressors from the * regression as parents. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly - adapted for EM Bayes estimator and Strucural EM * Bayes estimator */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java index 88c7746b5a..9eb209de98 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java @@ -61,7 +61,7 @@ /** * Lists independence facts specified by user and allows the list to be sorted by independence fact or by p value. * - * @author Joseph Ramsey + * @author josephramsey */ public class MarkovCheckEditor extends JPanel { private Graph dag; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MisclassificationsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MisclassificationsEditor.java index eafcb10c38..b06e3456ee 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MisclassificationsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MisclassificationsEditor.java @@ -34,7 +34,7 @@ * Provides a little display/editor for notes in the session workbench. This may * be elaborated in the future to allow marked up text. * - * @author Joseph Ramsey + * @author josephramsey */ public class MisclassificationsEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MissingDataInjectorParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MissingDataInjectorParamsEditor.java index 2accb30c18..12a03ab817 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MissingDataInjectorParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MissingDataInjectorParamsEditor.java @@ -31,7 +31,7 @@ /** * Edits the parameters for simulating data from Bayes nets. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly based on similar classes by Joe Ramsey */ public class MissingDataInjectorParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NoteEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NoteEditor.java index 1c2f66927a..ebc7bb382f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NoteEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NoteEditor.java @@ -33,7 +33,7 @@ * Provides a little display/editor for notes in the session workbench. This * may be elaborated in the future to allow marked up text. * - * @author Joseph Ramsey + * @author josephramsey */ public class NoteEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellEditor.java index af55f7f43f..283e62fc70 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellEditor.java @@ -32,7 +32,7 @@ * This is an editor for a JTable cell for editing numbers in conjunction with * tetrad.datatable.NumberCellRenderer. * - * @author Joseph Ramsey + * @author josephramsey * @see NumberCellRenderer */ class NumberCellEditor extends DefaultCellEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellRenderer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellRenderer.java index 7c1d689a42..45235b9b81 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellRenderer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/NumberCellRenderer.java @@ -32,7 +32,7 @@ * This a renderer for a JTable cell for rending numbers in conjunction with * tetrad.datatable.NumberCellEditor. * - * @author Joseph Ramsey + * @author josephramsey * @see NumberCellEditor */ class NumberCellRenderer extends DefaultTableCellRenderer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java index 283544d6b1..3685c93676 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java @@ -30,7 +30,7 @@ /** * Colors a graph using the PAG coloring. Optionally checks to make sure it's legal PAG. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class PagColorer extends JCheckBoxMenuItem { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ParameterEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ParameterEditor.java index cbb1aeccbd..d15c57cb19 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ParameterEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ParameterEditor.java @@ -30,7 +30,7 @@ * setParantModel, then setup. It is also assumed * that the implementing class will implement JComponent. * - * @author Joseph Ramsey + * @author josephramsey */ public interface ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PasteSubgraphAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PasteSubgraphAction.java index 3ba509a98a..c1db84394d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PasteSubgraphAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PasteSubgraphAction.java @@ -37,7 +37,7 @@ * Copies a parentally closed selection of session nodes in the frontmost * session editor to the clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class PasteSubgraphAction extends AbstractAction implements ClipboardOwner { /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PathsAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PathsAction.java index d2bc729f53..b51a099c25 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PathsAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PathsAction.java @@ -44,7 +44,7 @@ /** * Puts up a panel letting the user show undirectedPaths about some node in the graph. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class PathsAction extends AbstractAction implements ClipboardOwner { private final GraphWorkbench workbench; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomDagScaleFreeEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomDagScaleFreeEditor.java index a3be5d8d89..c526f95ba5 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomDagScaleFreeEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomDagScaleFreeEditor.java @@ -34,7 +34,7 @@ /** * Edits the parameters for generating random graphs. * - * @author Joseph Ramsey + * @author josephramsey */ class RandomDagScaleFreeEditor extends JPanel { private final IntTextField numNodesField; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomGraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomGraphEditor.java index f1ddfb349b..0a958ef5cf 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomGraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomGraphEditor.java @@ -36,7 +36,7 @@ /** * Edits the parameters for generating random graphs. * - * @author Joseph Ramsey + * @author josephramsey */ class RandomGraphEditor extends JPanel { private final Parameters parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomMimParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomMimParamsEditor.java index 3e712510b1..6e2d750696 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomMimParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RandomMimParamsEditor.java @@ -31,7 +31,7 @@ /** * Edits the parameters for generating random graphs. * - * @author Joseph Ramsey + * @author josephramsey */ class RandomMimParamsEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java index 121d087419..1a328a5d44 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java @@ -46,7 +46,7 @@ * * @author Tyler Gibosn * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly - adapted for EM Bayes estimator and Strucural EM * Bayes estimator */ @@ -207,7 +207,7 @@ private void runRegression() { * TextTable.emptyComponent is just a white JPanel, for initial * use. After that, call TextTable.component. * - * @author Joseph Ramsey + * @author josephramsey */ private static class TextWithTable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveComponentImage.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveComponentImage.java index b4088f76a9..f78e8ab796 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveComponentImage.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveComponentImage.java @@ -34,7 +34,7 @@ /** * Saves out a PNG image for a component. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SaveComponentImage extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveDataAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveDataAction.java index e6d028bd1f..ae002dd01a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveDataAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveDataAction.java @@ -37,7 +37,7 @@ /** * Saves data to disk. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class SaveDataAction extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java index 7db920803d..76803efbc8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java @@ -38,7 +38,7 @@ /** * Saves out a PNG image for a component. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SaveGraph extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveScreenshot.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveScreenshot.java index 50627d6c8a..bee8626ea7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveScreenshot.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveScreenshot.java @@ -34,7 +34,7 @@ /** * Saves out a PNG image for a component. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class SaveScreenshot extends AbstractAction { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlot.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlot.java index 73cb2ce291..4c74c3b55c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlot.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlot.java @@ -44,7 +44,7 @@ * create the scatterplot. * * @author Adrian Tang - * @author Joseph Ramsey + * @author josephramsey */ public class ScatterPlot { private final String x; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlotView.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlotView.java index becc297678..7f8e1ae77c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlotView.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterPlotView.java @@ -46,7 +46,7 @@ * to chart the ScatterPlot. * * @author Adrian Tang - * @author Joseph Ramsey + * @author josephramsey */ public class ScatterPlotView extends JPanel { private final ScatterPlot scatterPlot; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java index 7865a52764..466b15ddda 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java @@ -49,7 +49,7 @@ * Assumes that the search method of the CPDAG search has been run and shows the * various options for DAG's consistent with correlation information over the variables. * - * @author Joseph Ramsey + * @author josephramsey */ public class ScoredGraphsDisplay extends JPanel implements GraphEditable { private GraphWorkbench workbench; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectBidirectedAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectBidirectedAction.java index 8896f412bd..b2c193078b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectBidirectedAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectBidirectedAction.java @@ -37,7 +37,7 @@ * Copies a selection of session nodes in the frontmost session editor, to the * clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SelectBidirectedAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectDirectedAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectDirectedAction.java index 7ebf7ae29e..305a6bcc58 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectDirectedAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectDirectedAction.java @@ -37,7 +37,7 @@ * Copies a selection of session nodes in the frontmost session editor, to the * clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SelectDirectedAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectLatentsAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectLatentsAction.java index b44f28fcbc..541ca29b16 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectLatentsAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectLatentsAction.java @@ -39,7 +39,7 @@ * Copies a selection of session nodes in the frontmost session editor, to the * clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SelectLatentsAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectUndirectedAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectUndirectedAction.java index 02df6f40ba..6e59533494 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectUndirectedAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SelectUndirectedAction.java @@ -37,7 +37,7 @@ * Copies a selection of session nodes in the frontmost session editor, to the * clipboard. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SelectUndirectedAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemEstimatorEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemEstimatorEditor.java index 4b2860e076..ec6d14ba67 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemEstimatorEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemEstimatorEditor.java @@ -60,7 +60,7 @@ /** * Lets the user interact with a SEM estimator. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SemEstimatorEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java index 463b887098..540c29ca6e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphEditor.java @@ -61,7 +61,7 @@ * editing tetrad-style graphs. * * @author Aaron Powers - * @author Joseph Ramsey + * @author josephramsey * @author Zhou Yuan */ public final class SemGraphEditor extends JPanel diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphToolbar.java index e22d0cb78f..317818b089 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemGraphToolbar.java @@ -46,7 +46,7 @@ * tool, allows the user to create new bidirected edges. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey * @see GraphEditor */ class SemGraphToolbar extends JPanel implements PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImEditor.java index 3ab54f2948..b19870cb02 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImEditor.java @@ -67,7 +67,7 @@ * Edits a SEM instantiated model. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey */ public final class SemImEditor extends JPanel implements LayoutEditable, DoNotScroll { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImParamsEditor.java index 4e4e7c7113..86da5e30da 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemImParamsEditor.java @@ -33,7 +33,7 @@ /** * Edits the parameters for simulating data from SEMs. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SemImParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemPmEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemPmEditor.java index 9ad28638b5..4988fdffd2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemPmEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemPmEditor.java @@ -51,7 +51,7 @@ * Edits a SEM PM model. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey */ public final class SemPmEditor extends JPanel implements DelegatesEditing, LayoutEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemUpdaterEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemUpdaterEditor.java index 42ff57b1b2..fbe20e4ee2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemUpdaterEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SemUpdaterEditor.java @@ -39,7 +39,7 @@ /** * Lets the user calculate updated probabilities for a SEM. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemUpdaterEditor extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationEditor.java index 96d70d3ede..7fa2ff4c20 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationEditor.java @@ -50,7 +50,7 @@ * parents, and using the information those objects contain. For a Simulation * you need a RandomGraph and you need to pick a particular style of Simulation. * - * @author Joseph Ramsey + * @author josephramsey * @author Kevin V. Bui (kvb2@pitt.edu) */ public final class SimulationEditor extends JPanel implements KnowledgeEditable, PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationParamsEditor.java index a805117ce8..a09efde85c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SimulationParamsEditor.java @@ -28,7 +28,7 @@ /** * Edits the parameters for generating random graphs. * - * @author Joseph Ramsey + * @author josephramsey */ public class SimulationParamsEditor extends JPanel implements ParameterEditor { private Parameters params = new Parameters(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SplitCasesParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SplitCasesParamsEditor.java index c23dcf9dd4..625c1ff326 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SplitCasesParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SplitCasesParamsEditor.java @@ -42,7 +42,7 @@ * whether the data should be split in original order or in a shuffled order. * The other set of parameters is what the breakpoints should be. * - * @author Joseph Ramsey + * @author josephramsey */ public class SplitCasesParamsEditor extends JPanel implements ParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java index e334599487..771131ee4a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java @@ -39,7 +39,7 @@ * variances are equal to 1, and (c) the error covariance matrix is always * positive definite. Simulations produce standardized data. * - * @author Joseph Ramsey + * @author josephramsey */ public final class StandardizedSemImEditor extends JPanel implements LayoutEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEMBayesSearchEditorWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEMBayesSearchEditorWizard.java index ec7cbe427b..198ea5dcb4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEMBayesSearchEditorWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEMBayesSearchEditorWizard.java @@ -43,7 +43,7 @@ * of parent values for node N, the probabilities for the values of N * conditional on that combination of parent values must sum to 1.0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly adapted for EM Bayes estimation and Structural EM * bayes estimation. */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEmBayesSearchEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEmBayesSearchEditor.java index f27ba5366e..881462a25a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEmBayesSearchEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StructEmBayesSearchEditor.java @@ -43,7 +43,7 @@ * probabilities of node values given combinations of parent values. * * @author Aaron Powers - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly - adapted for EM Bayes estimator and Strucural EM * Bayes estimator */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SubgraphSelection.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SubgraphSelection.java index b908f743a5..8b28042317 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SubgraphSelection.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SubgraphSelection.java @@ -36,7 +36,7 @@ * of the graph elements list is made on creation, and once the data is * retrieved, it is deleted. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class SubgraphSelection implements Transferable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataJTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataJTable.java index bb3b60418e..dedb747d6a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataJTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataJTable.java @@ -49,7 +49,7 @@ /** * Displays a DataSet object as a JTable. * - * @author Joseph Ramsey + * @author josephramsey */ public class TabularDataJTable extends JTable implements DataModelContainer, PropertyChangeListener { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataTable.java index 0e4cc57976..382e3bf178 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TabularDataTable.java @@ -37,7 +37,7 @@ * Wraps a dataSet which is possibly smaller than the display window in a larger * AbstractTableModel which will fill the window. * - * @author Joseph Ramsey + * @author josephramsey */ class TabularDataTable extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TestHistogram.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TestHistogram.java index 98ffa09f38..62ddb2e5f8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TestHistogram.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TestHistogram.java @@ -30,7 +30,7 @@ /** * Tests data loaders against sample files. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestHistogram extends TestCase { public TestHistogram(String name) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java index 7d20d1bb0d..52038c17cf 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeLagGraphEditor.java @@ -55,7 +55,7 @@ * editing tetrad-style graphs. * * @author Aaron Powers - * @author Joseph Ramsey + * @author josephramsey * @author Zhou Yuan */ public final class TimeLagGraphEditor extends JPanel diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplay.java index a0f2c7c45b..9a72148d24 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplay.java @@ -30,7 +30,7 @@ /** * Displays a DataSet object as a JTable. * - * @author Joseph Ramsey + * @author josephramsey */ public class TimeSeriesDataDisplay extends JPanel implements DataModelContainer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplayJTable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplayJTable.java index 8c0cadd046..abfd896764 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplayJTable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/TimeSeriesDataDisplayJTable.java @@ -33,7 +33,7 @@ /** * Displays a DataSet object as a JTable. * - * @author Joseph Ramsey + * @author josephramsey */ public class TimeSeriesDataDisplayJTable extends JTable implements DataModelContainer { @@ -77,7 +77,7 @@ public DataModel getDataModel() { * Wraps a dataSet which is possibly smaller than the display window in a larger * AbstractTableModel which will fill the window. * - * @author Joseph Ramsey + * @author josephramsey */ class TimeSeriesDataDisplayTable extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UnderliningsAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UnderliningsAction.java index 8bd18a35c7..055eac9b69 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UnderliningsAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UnderliningsAction.java @@ -43,7 +43,7 @@ * Puts up a panel showing some graph properties, e.g., number of nodes and * edges in the graph, etc. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class UnderliningsAction extends AbstractAction implements ClipboardOwner { private final GraphWorkbench workbench; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizard.java index 53a7fd4797..8b7585ecf7 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizard.java @@ -51,7 +51,7 @@ * of parent values for selectedNode N, the probabilities for the values of N * conditional on that combination of parent values must sum to 1.0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class UpdatedBayesImWizard extends JPanel { private final Evidence evidence; @@ -499,7 +499,7 @@ public Node getSelectedNode() { /** * This is the JTable which displays the getModel parameter set. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see BayesImEditorWizard * @see UpdaterEditingTableModel */ @@ -639,7 +639,7 @@ private int getNumParents() { * These conditional probabilities may be edited. As they are being edited for * a given row, the only condition is that they be greater than or equal to 0.0. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class UpdaterEditingTableModel extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizardObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizardObs.java index 1d58107688..16c40cea79 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizardObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/UpdatedBayesImWizardObs.java @@ -48,7 +48,7 @@ * Allows the user to choose a variable in a Bayes net and edit the parameters * associated with that variable. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ ///////////////////////////////////////////////////////////////////// @@ -521,7 +521,7 @@ public Node getSelectedNode() { /** * This is the JTable which displays the getModel parameter set. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see BayesImEditorWizard * @see UpdaterEditingTableModel */ @@ -663,7 +663,7 @@ private int getNumParents() { * These conditional probabilities may be edited. As they are being edited for * a given row, the only condition is that they be greater than or equal to 0.0. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ final class UpdaterEditingTableModelObs extends AbstractTableModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ContinuousDiscretizationEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ContinuousDiscretizationEditor.java index 91bdc9f506..4cf4501f60 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ContinuousDiscretizationEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ContinuousDiscretizationEditor.java @@ -37,7 +37,7 @@ /** * Edits discretization parameters for a continuous variable. * - * @author Joseph Ramsey + * @author josephramsey * @author Tyler Gibson */ class ContinuousDiscretizationEditor extends JPanel implements DiscretizationEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscreteDiscretizationEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscreteDiscretizationEditor.java index 828ce9bbd3..ef09f0671b 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscreteDiscretizationEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscreteDiscretizationEditor.java @@ -36,7 +36,7 @@ /** * Edits discretization parameters for a discrete variable. * - * @author Joseph Ramsey + * @author josephramsey */ class DiscreteDiscretizationEditor extends JPanel implements DiscretizationEditor { private RemapEditor remapEditor; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscretizationParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscretizationParamsEditor.java index 7321e89ff8..bd23f62745 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscretizationParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/DiscretizationParamsEditor.java @@ -43,7 +43,7 @@ * discretized. * * @author Tyler Gibson - * @author Joseph Ramsey + * @author josephramsey */ public class DiscretizationParamsEditor extends JPanel implements FinalizingParameterEditor { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/RangeEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/RangeEditor.java index fd344ba2f7..405f686893 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/RangeEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/RangeEditor.java @@ -36,7 +36,7 @@ /** * An editor that allows one to edit a range while discretizing continuous data. * - * @author Joseph Ramsey + * @author josephramsey * @author Tyler Gibson */ @SuppressWarnings("SuspiciousMethodCalls") diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/IndependenceFactsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/IndependenceFactsEditor.java index d17930c1ce..ecdb660587 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/IndependenceFactsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/IndependenceFactsEditor.java @@ -41,7 +41,7 @@ * tiers is Tier0 --> Tier1 --> Tier2 --> ..., but special graphical structures * among the tiers may be set as well. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndependenceFactsEditor extends JPanel { private final IndependenceFactsModel facts; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayEdge.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayEdge.java index d47250947d..4d3ed4cc92 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayEdge.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayEdge.java @@ -54,7 +54,7 @@ * the original node from the tracking edge and (2) the node which is nearest to * the mouse release position. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler */ public class KnowledgeDisplayEdge extends JComponent implements IDisplayEdge { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayNode.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayNode.java index 05efe505b8..a56b19abf9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayNode.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeDisplayNode.java @@ -38,7 +38,7 @@ /** * This class represents a knowledge variable on screen. * - * @author Joseph Ramsey + * @author josephramsey */ public class KnowledgeDisplayNode extends DisplayNode { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java index 74d8ca91b0..759e460b3b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java @@ -47,7 +47,7 @@ * can take in the session editor workbench, whether it's selecting and moving a * node, adding a node of a particular type, or adding an edge. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ class KnowledgeEditorToolbar extends JPanel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java index 9c4e7962c9..6e35790831 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java @@ -36,7 +36,7 @@ * latent variables (no error variables). (b) The graph may contain only * directed edges (c) The graph may contain no directed cycles. * - * @author Joseph Ramsey + * @author josephramsey */ public class KnowledgeGraph implements Graph, TetradSerializableExcluded { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java index d3d331a2dd..ccdb43bbb9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java @@ -31,7 +31,7 @@ * edge is always directed, X-->Y, and is either required or forbidden as * indicated in the constructor. * - * @author Joseph Ramsey + * @author josephramsey */ public class KnowledgeModelEdge extends Edge implements TetradSerializableExcluded { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java index 0f3a993c7b..1ca1fd762b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java @@ -34,7 +34,7 @@ /** * Represents a node that's just a string name. * - * @author Joseph Ramsey + * @author josephramsey */ public class KnowledgeModelNode implements Node, TetradSerializableExcluded { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeWorkbench.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeWorkbench.java index e7e7f11ce4..185e18399e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeWorkbench.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeWorkbench.java @@ -35,7 +35,7 @@ * Extends AbstractWorkbench in the ways needed to display required and * forbidden edges and edit a Knowledge object. * - * @author Joseph Ramsey + * @author josephramsey * @see edu.cmu.tetradapp.workbench.AbstractWorkbench */ public class KnowledgeWorkbench extends AbstractWorkbench { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java index 0cbcb8fc9b..c9425f7bc9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java @@ -40,7 +40,7 @@ * either a dataModel model or a workbench model as parent. Contains basic * methods for executing algorithm and returning results. * - * @author Joseph Ramsey + * @author josephramsey */ public abstract class AbstractAlgorithmRunner implements AlgorithmRunner, ParamsResettable, Unmarshallable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java index 3e694c2686..369e66c18d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java @@ -33,7 +33,7 @@ * either a dataModel model or a workbench model as parent. Contains basic * methods for executing algorithm and returning results. * - * @author Joseph Ramsey + * @author josephramsey */ public abstract class AbstractMimRunner implements MimRunner, ParamsResettable { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java index 1af7d17311..ec1c36eef1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AlgorithmRunner.java @@ -36,7 +36,7 @@ * source graph is, and must know what their result graph is (if it has been * calculated). * - * @author Joseph Ramsey + * @author josephramsey */ public interface AlgorithmRunner extends SessionModel, Executable, GraphSource, TripleClassifier, SimulationParamsSource, MultipleGraphSource { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java index 91bc8b0263..a831fbede3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java @@ -42,7 +42,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class BayesEstimatorWrapper implements SessionModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java index d39d4be4c3..d893a3dc70 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java @@ -39,7 +39,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class BayesImWrapper implements SessionModel, Memorable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java index 502d0912f6..11df4d9c54 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java @@ -40,7 +40,7 @@ // Wraps a Bayes Im (observed variables only) for use // in the Tetrad application. // -// @author Joseph Ramsey +// @author josephramsey /////////////////////////////////////////////////////////// public class BayesImWrapperObs implements SessionModel, Memorable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java index 0716e4d708..7a8a4490f8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java @@ -44,7 +44,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class BayesPmWrapper implements SessionModel { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java index d3a2e64ff0..8a24b910b8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java @@ -33,7 +33,7 @@ /** * Wraps a DirichletEstimator. * - * @author Joseph Ramsey + * @author josephramsey */ public class BayesUpdaterClassifierWrapper implements SessionModel { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java index e912e7634d..7858771708 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java @@ -32,7 +32,7 @@ * Wraps a data model so that a random sample will automatically be drawn on * construction from a BayesIm. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BootstrapSamplerWrapper extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java index 0c12cddfcd..f599edfa15 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java @@ -46,7 +46,7 @@ * Compares a target workbench with a reference workbench by counting errors of * omission and commission. (for edge presence only, not orientation). * - * @author Joseph Ramsey + * @author josephramsey * @author Erin Korber (added remove latents functionality July 2004) */ public final class CPDAGFitModel implements SessionModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java index 98f98c1223..2e057364c2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java @@ -34,7 +34,7 @@ /** * Converts a continuous data set to a correlation matrix. * - * @author Joseph Ramsey + * @author josephramsey */ public class ConvertToPositiveSkew extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java index 0f827d970c..fa6e71333e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java @@ -31,7 +31,7 @@ /** * Converts a continuous data set to a correlation matrix. * - * @author Joseph Ramsey + * @author josephramsey */ public class CorrMatrixConverter extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java index 378bf2ef59..53a82b87ab 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java @@ -40,7 +40,7 @@ * Holds a tetrad dag with all of the constructors necessary for it to serve as * a model for the tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class DagWrapper implements GraphSource, KnowledgeBoxInput, IndTestProducer, SimulationParamsSource, MultipleGraphSource { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java index 48d8236eca..4496cb3106 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java @@ -31,7 +31,7 @@ /** * Converts a continuous data set to a correlation matrix. * - * @author Joseph Ramsey + * @author josephramsey */ public class DataCenterer extends DataWrapper { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java index 9c04df3179..35abc35089 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java @@ -32,7 +32,7 @@ /** * Standardizes all columns in a continuous data set. * - * @author Joseph Ramsey + * @author josephramsey */ public class DataStandardizer extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java index 64aacbb6c0..5f014dd105 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java @@ -38,7 +38,7 @@ * Wraps a DataModel as a model class for a Session, providing constructors for * the parents of Tetrad that are specified by Tetrad. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class DataWrapper implements KnowledgeEditable, KnowledgeBoxInput, DoNotAddOldModel, SimulationParamsSource, MultipleDataSource { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java index ada92c8df1..eb6e4aed5a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java @@ -36,7 +36,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class DirichletBayesImWrapper implements KnowledgeBoxInput { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java index 10ef5bc8a2..8ccfec9f44 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java @@ -36,7 +36,7 @@ /** * Wraps a DirichletEstimator. * - * @author Joseph Ramsey + * @author josephramsey */ public class DirichletEstimatorWrapper implements SessionModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java index 84571c9c9a..fe6084dbd2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java @@ -40,7 +40,7 @@ * Compares a target workbench with a reference workbench by counting errors of * omission and commission. (for edge presence only, not orientation). * - * @author Joseph Ramsey + * @author josephramsey * @author Erin Korber (added remove latents functionality July 2004) */ public final class EdgewiseComparisonModel implements SessionModel, DoNotAddOldModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EditorUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EditorUtils.java index df90e4a3c1..314635762d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EditorUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EditorUtils.java @@ -34,7 +34,7 @@ /** * Some basic utilities for editor stuff. * - * @author Joseph Ramsey + * @author josephramsey */ public class EditorUtils { public static Point getTopLeftPoint(List modelElements) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java index d47670f543..c352ac23b1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java @@ -37,7 +37,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey * @author Frank Wimberly adapted for EM Bayes estimator and structural EM Bayes * estimator */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java index 15e552f9bd..b82b452ee9 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java @@ -32,7 +32,7 @@ * Wraps a data model so that a random sample will automatically be drawn on * construction from a BayesIm. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class ExtraCategoryInterpolatorWrapper extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index 30ad8737c5..145c2e8a87 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -37,7 +37,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the PC algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class FasRunner extends AbstractAlgorithmRunner implements IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java index c3eb75b757..67c886e138 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java @@ -38,7 +38,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the FCI algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class FciRunner extends AbstractAlgorithmRunner implements IndTestProducer, IonInput { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java index 54fbc3fb95..592f72c832 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java @@ -39,7 +39,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class GeneralizedSemEstimatorWrapper implements SessionModel, GraphSource { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java index ee2aa45595..522db22442 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java @@ -37,7 +37,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class GeneralizedSemImWrapper implements KnowledgeBoxInput { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java index 3333666299..5b255fe31c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java @@ -40,7 +40,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class GeneralizedSemPmWrapper implements KnowledgeBoxInput { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java index d88535857a..8b4e7bff5e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java @@ -39,7 +39,7 @@ /** * Stores a reference to a file to which records can be appended. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphComparisonParams extends SessionAdapter implements ExecutionRestarter { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java index 1172b58a5f..cc19f7ea55 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java @@ -38,7 +38,7 @@ * Holds a tetrad-style graph with all of the constructors necessary for it to * serve as a model for the tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphSelectionWrapper implements GraphSource, KnowledgeBoxInput, IonInput, IndTestProducer { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSource.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSource.java index 54750b618c..628417ea55 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSource.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSource.java @@ -26,7 +26,7 @@ /** * Indicates a class that is capable of producing a graph on demand. * - * @author Joseph Ramsey + * @author josephramsey */ public interface GraphSource { Graph getGraph(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java index 243f4e8683..2da94935ba 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java @@ -46,7 +46,7 @@ * Holds a tetrad-style graph with all of the constructors necessary for it to * serve as a model for the tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphWrapper implements KnowledgeBoxInput, IonInput, IndTestProducer, SimulationParamsSource, GraphSettable, MultipleGraphSource { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java index 23cfb52060..bbad35cddf 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java @@ -34,7 +34,7 @@ /** * Wraps a Bayes Updater for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ /////////////////////////////////////// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java index 68364414b0..2783feba02 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java @@ -37,7 +37,7 @@ * Wraps a data model so that a random sample will automatically be drawn on * construction from a SemIm. Includes latents. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class ImpliedCovarianceDataAllWrapper extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java index dfbf8c2c05..b7de7afd6c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java @@ -37,7 +37,7 @@ * Wraps a data model so that a random sample will automatically be drawn on * construction from a SemIm. Measured variables only. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class ImpliedCovarianceDataWrapper extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java index a450414e8e..1e419dfe54 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestChooser.java @@ -41,7 +41,7 @@ /** * Chooses an independence test for a particular data source. * - * @author Joseph Ramsey + * @author josephramsey */ final class IndTestChooser { public IndependenceTest getTest(Object dataSource, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java index 6e83c0a8e4..037f9661f3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java @@ -34,7 +34,7 @@ /** * Stores a list of independence facts. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndTestModel implements SessionModel { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java index f7c29d0e41..bcea662fd9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestProducer.java @@ -29,7 +29,7 @@ * source graph is, and must know what their result graph is (if it has been * calculated). * - * @author Joseph Ramsey + * @author josephramsey */ public interface IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java index d0f01df30f..304d8f02a0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java @@ -37,7 +37,7 @@ /** * Stores a list of independence facts. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndependenceFactsModel implements KnowledgeBoxInput { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Indexable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Indexable.java index 4f5a80d9c8..c85b6665d7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Indexable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Indexable.java @@ -24,7 +24,7 @@ /** * Sets an index. * - * @author Joseph Ramsey + * @author josephramsey */ public interface Indexable { void setIndex(int index); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java index 1d07690e5e..0d506c2065 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java @@ -42,7 +42,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the FCI algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class IonRunner extends AbstractAlgorithmRunner implements IndTestProducer, DoNotAddOldModel, IonInput { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeEditable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeEditable.java index 4263637d75..3bba4e01dd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeEditable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeEditable.java @@ -30,7 +30,7 @@ * Interface to indicate a class whose knowledge is capable of being edited by * the knowledge editor. * - * @author Joseph Ramsey + * @author josephramsey */ public interface KnowledgeEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java index 8afb122dcd..6982bbb004 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java @@ -34,7 +34,7 @@ /** * Stores a list of independence facts. * - * @author Joseph Ramsey + * @author josephramsey */ public class MarkovCheckIndTestModel implements SessionModel, GraphSource { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java index 9776dc82e7..d721cd2d76 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java @@ -39,7 +39,7 @@ * Compares a target workbench with a reference workbench by counting errors of * omission and commission. (for edge presence only, not orientation). * - * @author Joseph Ramsey + * @author josephramsey * @author Erin Korber (added remove latents functionality July 2004) */ public final class MeasurementModelWrapper implements ParamsResettable, diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimRunner.java index adae350a0e..24ecdf94a5 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimRunner.java @@ -34,7 +34,7 @@ * source graph is, and must know what their result graph is (if it has been * calculated). * - * @author Joseph Ramsey + * @author josephramsey */ public interface MimRunner extends SessionModel, Executable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java index c9166b24e0..8d92346bb9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java @@ -41,7 +41,7 @@ * Compares a target workbench with a reference workbench by counting errors of * omission and commission. (for edge presence only, not orientation). * - * @author Joseph Ramsey + * @author josephramsey * @author Erin Korber (added remove latents functionality July 2004) */ public final class Misclassifications implements SessionModel, DoNotAddOldModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java index a3e190b21c..c11877df98 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java @@ -35,7 +35,7 @@ * Wraps a data model so that a random sample will automatically be drawn on * construction from a BayesIm. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly based on similar class by Ramsey */ public class MissingDataInjectorWrapper extends DataWrapper { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java index 0834bea4ef..fc73dc061d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java @@ -32,7 +32,7 @@ * Wraps a data model so that a random sample will automatically be drawn on * construction from a BayesIm. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class ModeInterpolatorWrapper extends DataWrapper { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleDataSource.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleDataSource.java index c7c5478fab..f6f80bb84f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleDataSource.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleDataSource.java @@ -28,7 +28,7 @@ /** * Indicates a class that can returns multiple models. * - * @author Joseph Ramsey + * @author josephramsey */ interface MultipleDataSource { List getDataModels(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleGraphSource.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleGraphSource.java index f9a457c36d..15c63fdab4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleGraphSource.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MultipleGraphSource.java @@ -28,7 +28,7 @@ /** * Indicates a class that can returns multiple graphs. * - * @author Joseph Ramsey + * @author josephramsey */ interface MultipleGraphSource { List getGraphs(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java index f6f49b0296..9bd8adcf84 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java @@ -30,7 +30,7 @@ /** * Converts a continuous data set to a correlation matrix. * - * @author Joseph Ramsey + * @author josephramsey */ public class NonparanormalTransform extends DataWrapper { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java index 4fdd45bb29..479ffe32ba 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java @@ -35,7 +35,7 @@ * stored on the theory that maybe someday the name of the node can be * displayed in the interface. That day is not this day. * - * @author Joseph Ramsey + * @author josephramsey */ public class NoteModel implements SessionModel { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index 9220450b49..4e33d78d02 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -36,7 +36,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the PC algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class PcRunner extends AbstractAlgorithmRunner implements IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java index 4aea28a5bb..8b86340e79 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java @@ -33,7 +33,7 @@ * Wraps a data model so that a random sample will automatically be drawn on * construction from a BayesIm. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @author Frank Wimberly based on similar class by Ramsey */ public class ReplaceMissingWithRandomWrapper extends DataWrapper { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java index 11abb6761b..946e1a09be 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java @@ -34,7 +34,7 @@ /** * Wraps a Bayes Updater for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class RowSummingExactWrapper implements SessionModel, UpdaterWrapper, Unmarshallable { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 0b68ee7883..07246eff68 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -40,7 +40,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the PC algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class SampleVcpcFastRunner extends AbstractAlgorithmRunner implements IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index 2678f10fd0..cf3387ced2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -42,7 +42,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the PC algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class SampleVcpcRunner extends AbstractAlgorithmRunner implements IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java index f6e86f3556..99c4cc2b73 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java @@ -43,7 +43,7 @@ /** * Holds a list of graphs. * - * @author Joseph Ramsey + * @author josephramsey */ public class ScoredGraphsWrapper implements SessionModel, GraphSource, Unmarshallable, DoNotAddOldModel { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java index c3d8e6c0b8..1e3e89a240 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java @@ -38,7 +38,7 @@ /** * Wraps a SemEstimator for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemEstimatorWrapper implements SessionModel, Unmarshallable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java index 01f4da9cc0..5fce5eacae 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java @@ -39,7 +39,7 @@ * Holds a tetrad dag with all of the constructors necessary for it to serve as * a model for the tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemGraphWrapper implements GraphSource, KnowledgeBoxInput, SimulationParamsSource, DoNotAddOldModel, MultipleGraphSource { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java index 7a0698f776..2ed899f633 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java @@ -39,7 +39,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemImWrapper implements SessionModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java index 472bd47931..482780d37e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java @@ -40,7 +40,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemPmWrapper implements SessionModel { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java index 7252848395..b04a1e8d9a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java @@ -31,7 +31,7 @@ /** * Wraps a Bayes Updater for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemUpdaterWrapper implements SessionModel { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java index 33a9702764..36c870cc59 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java @@ -33,7 +33,7 @@ * A node in a SessionWrapper; wraps a SessionNode and presents it as a * GraphNode. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see edu.cmu.tetrad.session.SessionNode * @see edu.cmu.tetrad.graph.GraphNode * @see SessionWrapper diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java index 98475528c2..0dd938353c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java @@ -43,7 +43,7 @@ * Wraps a Session as a Graph so that an AbstractWorkbench can be used to edit * it. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see edu.cmu.tetrad.session.Session * @see edu.cmu.tetrad.graph.Graph */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java index 6fae185899..13a7289254 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java @@ -36,7 +36,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class StandardizedSemImWrapper implements KnowledgeBoxInput { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java index 21ac5aa37f..d357040a94 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java @@ -37,7 +37,7 @@ /** * Wraps a Bayes Pm for use in the Tetrad application. * - * @author Joseph Ramsey + * @author josephramsey * @author Frank Wimberly adapted for EM Bayes estimator and structural EM Bayes * search */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java index ff3499070d..7d3ac56337 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java @@ -40,7 +40,7 @@ * Compares a target workbench with a reference workbench by counting errors of * omission and commission. (for edge presence only, not orientation). * - * @author Joseph Ramsey + * @author josephramsey * @author Erin Korber (added remove latents functionality July 2004) */ public final class TabularComparison implements SessionModel, SimulationParamsSource, diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java index b2172d8509..51a9ebb0b7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java @@ -37,7 +37,7 @@ * in the future without disturbing serialization. It must be the case that * metadata can load even if the SessionWrapper cannot load. * - * @author Joseph Ramsey + * @author josephramsey */ public class TetradMetadata implements TetradSerializable, TetradMetadataIndirectRef { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java index a1c5e9ac76..12ec9b2621 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java @@ -39,7 +39,7 @@ * Holds a tetrad dag with all of the constructors necessary for it to serve as * a model for the tetrad application. * - * @author Joseph Ramsey + * @author josephramsey */ public class TimeLagGraphWrapper implements GraphSource, KnowledgeBoxInput { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UnlistedSessionModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UnlistedSessionModel.java index 9611b67690..ff123e63f2 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UnlistedSessionModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UnlistedSessionModel.java @@ -27,7 +27,7 @@ * Tags a session model as unlisted, in the sense that it doesn't show up in * lists of models presented to the user but may be constructed by the session. * - * @author joseph Ramsey + * @author josephramsey */ public interface UnlistedSessionModel extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UpdaterWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UpdaterWrapper.java index 5cf99facd4..76ea9f589b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UpdaterWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UpdaterWrapper.java @@ -27,7 +27,7 @@ /** * Stuff the GUI needs to know. Wrapped so that the GUI can access the params. * - * @author Joseph Ramsey + * @author josephramsey */ public interface UpdaterWrapper { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index edac77de70..5adf7f4a90 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -38,7 +38,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the PC algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class VcpcFastRunner extends AbstractAlgorithmRunner implements IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 18e237705b..bc8f17771c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -41,7 +41,7 @@ /** * Extends AbstractAlgorithmRunner to produce a wrapper for the PC algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class VcpcRunner extends AbstractAlgorithmRunner implements IndTestProducer { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/CopyLayoutAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/CopyLayoutAction.java index d66b1eaaaf..5347fc36bf 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/CopyLayoutAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/CopyLayoutAction.java @@ -33,7 +33,7 @@ * Copies the getModel graph in a given container, storing it so that another * container can be laid out the same way. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class CopyLayoutAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopControllable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopControllable.java index 9d2c0a8b6c..0dabf7cb01 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopControllable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopControllable.java @@ -28,7 +28,7 @@ * the desktop without a package cycle. See TetradDesktop for meaning of * methods. * - * @author Joseph Ramsey + * @author josephramsey * @see edu.cmu.tetradapp.app.TetradDesktop */ public interface DesktopControllable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopController.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopController.java index 7bd6245e37..3d3746633e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopController.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DesktopController.java @@ -35,7 +35,7 @@ *

Not pretty, but easier and cleaner by far than passing the reference to the * desktop down through all of the relevant classes in tetradapp. * - * @author Joseph Ramsey + * @author josephramsey */ public class DesktopController implements DesktopControllable { private static DesktopControllable INSTANCE; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DoubleTextField.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DoubleTextField.java index 9afb61c014..d1933aa6be 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DoubleTextField.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/DoubleTextField.java @@ -35,7 +35,7 @@ * otherwise annoying GUI-related functions like keeping the textbox the right * size and listening to itself. * - * @author Joseph Ramsey + * @author josephramsey */ public class DoubleTextField extends JTextField { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/EditorWindowIndirectRef.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/EditorWindowIndirectRef.java index d222896919..e2890485f1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/EditorWindowIndirectRef.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/EditorWindowIndirectRef.java @@ -25,7 +25,7 @@ * Indirect reference for EditorWindow, to avoid package cycle while allowing * app components to access desktop. * - * @author Joseph Ramsey + * @author josephramsey * @see DesktopController */ public interface EditorWindowIndirectRef { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphEditorUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphEditorUtils.java index 4d46064614..b82cc7a236 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphEditorUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphEditorUtils.java @@ -31,7 +31,7 @@ /** * Stores some static methods useful for graph editing. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphEditorUtils { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphHistory.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphHistory.java index c59ffab690..e4666e9661 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphHistory.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphHistory.java @@ -29,7 +29,7 @@ /** * Stores a history of graph objects. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphHistory { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphUtils.java index 9403b0f592..9a69889441 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/GraphUtils.java @@ -12,7 +12,7 @@ /** * Created by jdramsey on 12/8/15. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphUtils { public static Graph makeRandomGraph(Graph graph, Parameters parameters) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/ImageUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/ImageUtils.java index 731650c0b2..5bfdbc5a73 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/ImageUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/ImageUtils.java @@ -28,7 +28,7 @@ /** * Static utility methods of general use in the application. * - * @author Joseph Ramsey + * @author josephramsey */ public final class ImageUtils { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java index a356309bb6..7c7a0ac9c4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java @@ -30,7 +30,7 @@ * A typesafe enumeration of the types of independence tests that are used for basic * search algorithm in this package. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IndTestType implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IntTextField.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IntTextField.java index 4e0aebc6e8..7980cb3da3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IntTextField.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IntTextField.java @@ -35,7 +35,7 @@ * variables to be within a certain range; see the setFilter * method. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IntTextField extends JTextField { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/InternalClipboard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/InternalClipboard.java index 06f9746281..930caa7b4b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/InternalClipboard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/InternalClipboard.java @@ -28,7 +28,7 @@ * accidentally pasted to other applications. Data that should be pastable to * other applications should use the System clipboard, Toolkit.getDefaultToolkit().getSystemClipboard(). * - * @author Joseph Ramsey + * @author josephramsey */ public class InternalClipboard extends Clipboard { private static final InternalClipboard ourInstance = new InternalClipboard(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutEditable.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutEditable.java index 85a3d4f899..afc22f5c0f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutEditable.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutEditable.java @@ -33,7 +33,7 @@ /** * Interface to indicate a class that has a graph in it that can be laid out. * - * @author Joseph Ramsey + * @author josephramsey */ public interface LayoutEditable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutSelection.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutSelection.java index aa393b869f..7fe572d48f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutSelection.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LayoutSelection.java @@ -32,7 +32,7 @@ /** * Holds a graph for purposes of layout out another graph later on. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class LayoutSelection implements Transferable { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LicenseUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LicenseUtils.java index 98c30f43fd..6a5b86a71a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LicenseUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/LicenseUtils.java @@ -28,7 +28,7 @@ * Some utilities for loading license-related files and making sure they get the * right versions stamped in them. * - * @author Joseph Ramsey + * @author josephramsey */ public final class LicenseUtils { public static String copyright() { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/PasteLayoutAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/PasteLayoutAction.java index ec2503988a..2fb8f8697b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/PasteLayoutAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/PasteLayoutAction.java @@ -34,7 +34,7 @@ * Pastes a layout into a LayoutEditable gadget, which lays out the graph in * that gadget according to the stored graph. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class PasteLayoutAction extends AbstractAction implements ClipboardOwner { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionEditorIndirectRef.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionEditorIndirectRef.java index 9726093b36..5b688705ba 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionEditorIndirectRef.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionEditorIndirectRef.java @@ -25,7 +25,7 @@ * Indirect reference for SessionEditor, to avoid package cycle while allowing * app components to access desktop. * - * @author Joseph Ramsey + * @author josephramsey * @see DesktopController */ public interface SessionEditorIndirectRef { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionWrapperIndirectRef.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionWrapperIndirectRef.java index 741801f770..edd546ce51 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionWrapperIndirectRef.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SessionWrapperIndirectRef.java @@ -25,7 +25,7 @@ * Indirect reference for SessionWrapper, to avoid package cycle while allowing * app components to access desktop. * - * @author Joseph Ramsey + * @author josephramsey * @see DesktopController */ public interface SessionWrapperIndirectRef { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SortingComboBox.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SortingComboBox.java index 510cd763a5..640b3c5c25 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SortingComboBox.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/SortingComboBox.java @@ -27,7 +27,7 @@ * Extends JComboBox so that the items it contains are automatically sorted as * they are added. * - * @author Joseph Ramsey + * @author josephramsey */ public class SortingComboBox extends JComboBox { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/StringTextField.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/StringTextField.java index ad6d237b7f..5c7fc3edf8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/StringTextField.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/StringTextField.java @@ -33,7 +33,7 @@ * but which also handles other GUI-related functions like keeping the text box * the right size and handling focus events. * - * @author Joseph Ramsey + * @author josephramsey */ public final class StringTextField extends JTextField { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TetradMetadataIndirectRef.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TetradMetadataIndirectRef.java index 2e1edcfe9a..4779509462 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TetradMetadataIndirectRef.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TetradMetadataIndirectRef.java @@ -25,7 +25,7 @@ * Indirect reference for TetradMetadata, to avoid package cycle while allowing * app components to access desktop. * - * @author Joseph Ramsey + * @author josephramsey * @see DesktopController */ public interface TetradMetadataIndirectRef { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TextAreaOutputStream.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TextAreaOutputStream.java index 4116d13431..e65dd7fa1c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TextAreaOutputStream.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/TextAreaOutputStream.java @@ -29,7 +29,7 @@ /** * An output stream to pipe stuff written to it directly to a JTextArea. * - * @author Joseph Ramsey + * @author josephramsey */ public class TextAreaOutputStream extends OutputStream implements TetradLogger.LogDisplayOutputStream { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/WatchedProcess.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/WatchedProcess.java index 26ed6dbf55..4337cce520 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/WatchedProcess.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/WatchedProcess.java @@ -31,7 +31,7 @@ * complete is too long. The process to be run should override the watch() * method. * - * @author Joseph Ramsey + * @author josephramsey */ public abstract class WatchedProcess { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/AbstractWorkbench.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/AbstractWorkbench.java index 3f26135e04..51c7169f23 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/AbstractWorkbench.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/AbstractWorkbench.java @@ -42,7 +42,7 @@ * functionality). * * @author Aaron Powell - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler * @see DisplayNode * @see DisplayEdge @@ -2435,7 +2435,7 @@ public boolean isDoPagColoring() { * wrapped JComponents stay in the right place in the workbench--that is, * halfway along their respective edge, slightly off to the side. * - * @author Joseph Ramsey + * @author josephramsey */ private static final class GraphEdgeLabel extends JComponent implements PropertyChangeListener { @@ -2546,7 +2546,7 @@ public JComponent getLabel() { * wrapped JComponents stay in the right place in the workbench--that is, * slightly off to the right of the display node. * - * @author Joseph Ramsey + * @author josephramsey */ private static final class GraphNodeLabel extends JComponent { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/CausalOrder.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/CausalOrder.java index 522352c397..fc6b4fd25f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/CausalOrder.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/CausalOrder.java @@ -34,7 +34,7 @@ * Lays out a graph by placing springs between the nodes and letting the system * settle (one node at a time). * - * @author Joseph Ramsey + * @author josephramsey */ final class CausalOrder { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayEdge.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayEdge.java index fdd0d8064e..8d8f667e5e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayEdge.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayEdge.java @@ -51,7 +51,7 @@ * the original node from the tracking edge and (2) the node which is nearest to * the mouse release position. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler */ public class DisplayEdge extends JComponent implements IDisplayEdge { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayNode.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayNode.java index 1909f1dec9..3e3cd23d30 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayNode.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DisplayNode.java @@ -36,7 +36,7 @@ * This class represents a node in a workbench; it is an abstract class, but * extensions of it represent measured and latent variables. * - * @author Joseph Ramsey + * @author josephramsey */ public class DisplayNode extends JComponent implements Node, TetradSerializableExcluded { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DistanceFromSelected.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DistanceFromSelected.java index 7d234186e2..33258ce977 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DistanceFromSelected.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/DistanceFromSelected.java @@ -36,7 +36,7 @@ * Lays out a graph by placing springs between the nodes and letting the system * settle (one node at a time). * - * @author Joseph Ramsey + * @author josephramsey */ final class DistanceFromSelected { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeError.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeError.java index 0359d25b76..0e0167adeb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeError.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeError.java @@ -38,7 +38,7 @@ * border, with the variable name in it. Clicking on the oval pops up a dialog * that lets the user modify the name of the variable. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler */ public class GraphNodeError extends DisplayNode { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLatent.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLatent.java index d2aee94f32..e1a1f1abef 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLatent.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLatent.java @@ -39,7 +39,7 @@ * the user modify the name of the variable and whether the variable is * latent. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler */ public class GraphNodeLatent extends DisplayNode { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLocked.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLocked.java index 40566c7093..6d65bd47ac 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLocked.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeLocked.java @@ -37,7 +37,7 @@ * Represents a locked policy variable in the workbench. Appears as a * padlock. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler */ public class GraphNodeLocked extends DisplayNode { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeMeasured.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeMeasured.java index 3af28e7c8e..0b75e19622 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeMeasured.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeMeasured.java @@ -38,7 +38,7 @@ * dialog that lets the user modify the name of the variable and whether the * variable is latent. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphNodeMeasured extends DisplayNode { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeRandomized.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeRandomized.java index 9f5d0850de..dcb44df221 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeRandomized.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphNodeRandomized.java @@ -37,7 +37,7 @@ * Represents a randomized policy variable in the workbench. Appears as a * die. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler */ public class GraphNodeRandomized extends DisplayNode { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphWorkbench.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphWorkbench.java index e86540d10d..5489bf8771 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphWorkbench.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/GraphWorkbench.java @@ -30,7 +30,7 @@ /** * Extends AbstractWorkbench in the ways needed to display tetrad-style graphs. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler * @see AbstractWorkbench */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LagWorkbench.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LagWorkbench.java index a6665e5972..e3065b1c43 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LagWorkbench.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LagWorkbench.java @@ -33,7 +33,7 @@ /** * Extends AbstractWorkbench in the ways needed to display tetrad-style graphs. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler * @see edu.cmu.tetradapp.workbench.AbstractWorkbench */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java index 7f4b474404..8698259807 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java @@ -35,7 +35,7 @@ * Builds a menu for layout operations on graphs. Interacts with classes that * implement the LayoutEditable interface. * - * @author Joseph Ramsey + * @author josephramsey */ public class LayoutMenu extends JMenu { private final LayoutEditable layoutEditable; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplayComp.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplayComp.java index 6859ba8c50..b657085a0f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplayComp.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplayComp.java @@ -28,7 +28,7 @@ /** * The display component for measured nodes--an opaque rounded rectangle. * - * @author Joseph Ramsey + * @author josephramsey */ public class MeasuredDisplayComp extends JComponent implements DisplayComp { private boolean selected; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplaySmallComp.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplaySmallComp.java index 21a54fbced..fcbb01c4ca 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplaySmallComp.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/MeasuredDisplaySmallComp.java @@ -28,7 +28,7 @@ /** * The display component for measured nodes--an opaque rounded rectangle. * - * @author Joseph Ramsey + * @author josephramsey */ public class MeasuredDisplaySmallComp extends JComponent implements DisplayComp { private boolean selected; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/Rubberband.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/Rubberband.java index bf3ea763b3..b874c93240 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/Rubberband.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/Rubberband.java @@ -30,7 +30,7 @@ /** * Instantiates a rubberband suitable for selections. * - * @author Joseph Ramsey + * @author josephramsey */ class Rubberband extends JComponent { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/TimeLagGraphWorkbench.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/TimeLagGraphWorkbench.java index 44995957ec..181bc3cd40 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/TimeLagGraphWorkbench.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/TimeLagGraphWorkbench.java @@ -32,7 +32,7 @@ /** * Extends AbstractWorkbench in the ways needed to display tetrad-style graphs. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler * @see edu.cmu.tetradapp.workbench.AbstractWorkbench */ diff --git a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestDataWrapper.java b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestDataWrapper.java index 0c4d013921..e580bf705c 100644 --- a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestDataWrapper.java +++ b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestDataWrapper.java @@ -41,7 +41,7 @@ /** * Tests the basic functionality of the DataWrapper. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestDataWrapper { diff --git a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestGraphWorkbench.java b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestGraphWorkbench.java index 7fcfe5f826..4e6ae87777 100644 --- a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestGraphWorkbench.java +++ b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestGraphWorkbench.java @@ -30,7 +30,7 @@ /** * Tests the GraphWorkbench class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestGraphWorkbench { diff --git a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestIndependenceFacts.java b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestIndependenceFacts.java index 97eba4c2bc..9d14f1fbca 100644 --- a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestIndependenceFacts.java +++ b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestIndependenceFacts.java @@ -39,7 +39,7 @@ /** * Tests the Knowledge class. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestIndependenceFacts { private IndependenceFactsModel facts; diff --git a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestSerialization.java b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestSerialization.java index 0bd9041fa5..f11f5c089b 100644 --- a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestSerialization.java +++ b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestSerialization.java @@ -113,7 +113,7 @@ * *

Or Joshua Block, Effective Java.

fd * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSerialization { diff --git a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestVersion.java b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestVersion.java index d15b11f05c..8e9d628385 100644 --- a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestVersion.java +++ b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestVersion.java @@ -31,7 +31,7 @@ * Tests the Version class, to make sure it can load versions from string * representations and generate string representations correctly. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class TestVersion { diff --git a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestWatchedProcessDialogs.java b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestWatchedProcessDialogs.java index 5fed778937..1b4590de7a 100644 --- a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestWatchedProcessDialogs.java +++ b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/TestWatchedProcessDialogs.java @@ -34,7 +34,7 @@ * to set this to false while debugging, but Tetrad must not be posted with this * set to false. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestWatchedProcessDialogs { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java index 10dab75142..2ca3e9efbc 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java @@ -39,7 +39,7 @@ * the condition B. Then the maximum likelihood estimate of condition A is * calculated. * - * @author Joseph Ramsey + * @author josephramsey */ public final class ApproximateUpdater implements ManipulatingBayesUpdater { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java index 27231e9d6a..a6f37f54ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java @@ -52,7 +52,7 @@ * conditional probability tables of the Bayes net. See implementations for * details. * - * @author Joseph Ramsey + * @author josephramsey * @see edu.cmu.tetrad.graph.Dag * @see BayesPm */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java index 0ab11a930e..c594abbc4d 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java @@ -36,7 +36,7 @@ * fly without constructing the entire table. (To force the entire table to be * constructed, use StoredCellProbs.) * - * @author Joseph Ramsey + * @author josephramsey */ public final class BayesImProbs implements DiscreteProbs, TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java index b421204044..f90faca3d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java @@ -42,7 +42,7 @@ * parameters. Specific values for the Bayes net are stored in a BayesIM object * (see). * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see edu.cmu.tetrad.graph.Dag * @see BayesIm */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java index 4b4b074a8c..1a32c4907f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java @@ -35,7 +35,7 @@ /** * Calculates some scores for Bayes nets as a whole. * - * @author Joseph Ramsey + * @author josephramsey */ public final class BayesProperties { private final DataSet dataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java index f42c100614..c0f75cc569 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java @@ -32,7 +32,7 @@ * well--that is, P(AND_i{Xi = xi'} | evidence). Also, not all updaters can take * manipulation information into account. See implementations for details. * - * @author Joseph Ramsey + * @author josephramsey * @see Evidence * @see Proposition * @see Manipulation diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUtils.java index 224a4b372a..cb6b745665 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUtils.java @@ -30,7 +30,7 @@ /** * Static utility methods for Bayes nets. * - * @author Joseph Ramsey + * @author josephramsey */ final class BayesUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlParser.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlParser.java index 657f1b42d6..74e4a77f5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlParser.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlParser.java @@ -34,7 +34,7 @@ /** * Parses Bayes elements back to objects. * - * @author Joseph Ramsey + * @author josephramsey */ public final class BayesXmlParser { private Map namesToVars; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlRenderer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlRenderer.java index 77f3345884..2644e376eb 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlRenderer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesXmlRenderer.java @@ -32,7 +32,7 @@ /** * Renders Bayes nets and related models in XML. * - * @author Joseph Ramsey + * @author josephramsey */ public final class BayesXmlRenderer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CellTableProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CellTableProbs.java index 38fa7f8ced..76f16bf079 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CellTableProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CellTableProbs.java @@ -31,7 +31,7 @@ * Estimates probabilities from data by constructing the entire cell count table * for the data. * - * @author Joseph Ramsey + * @author josephramsey */ public final class CellTableProbs implements DiscreteProbs { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java index f575c63ac5..f4778a751a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java @@ -32,7 +32,7 @@ * Calculates marginals of the form P(V=v') for an updated Bayes net for * purposes of the CPT Invariant Updater. * - * @author Joseph Ramsey + * @author josephramsey */ public final class CptInvariantMarginalCalculator implements TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java index ed5d64bc09..75199c8b14 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java @@ -36,7 +36,7 @@ * probabilities of variables with respect to their parents that change from * non-updated to updated values. * - * @author Joseph Ramsey + * @author josephramsey */ public final class CptInvariantUpdater implements ManipulatingBayesUpdater { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java index 999f8c0cac..c968987467 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java @@ -33,7 +33,7 @@ /** * Estimates maximum likelihood probabilities directly from data on the fly. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DataSetProbs implements DiscreteProbs { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java index 6c65e9054b..d9416a0a01 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java @@ -74,7 +74,7 @@ *

* Thanks to Bill Taysom for an earlier version. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class DirichletBayesIm implements BayesIm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletDataSetProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletDataSetProbs.java index 7ab14d6a4c..54639b0c89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletDataSetProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletDataSetProbs.java @@ -32,7 +32,7 @@ * Estimates probabilities directly from data on the fly using maximum * likelihood method. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DirichletDataSetProbs implements DiscreteProbs { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletEstimator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletEstimator.java index d0b52e55f9..b70ee35a4d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletEstimator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletEstimator.java @@ -29,7 +29,7 @@ * Estimates a DirichletBayesIm from a DirichletBayesIm (the prior) and a data * set. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DirichletEstimator { public static DirichletBayesIm estimate(DirichletBayesIm prior, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DiscreteProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DiscreteProbs.java index 2873210b37..a081284d16 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DiscreteProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DiscreteProbs.java @@ -29,7 +29,7 @@ * Interface containing methods to calculate probabilities for systems of * discrete variables. See instantiations for more details. * - * @author Joseph Ramsey + * @author josephramsey */ interface DiscreteProbs { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/EmBayesProperties.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/EmBayesProperties.java index 2549b2edf7..7f0e55a45a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/EmBayesProperties.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/EmBayesProperties.java @@ -38,7 +38,7 @@ /** * Calculates some scores for Bayes nets as a whole. * - * @author Joseph Ramsey + * @author josephramsey */ public final class EmBayesProperties { public interface Estimator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java index dc4e73fe46..ee936da79c 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java @@ -35,7 +35,7 @@ * Stores information for a variable source about evidence we have for each variable as * well as whether each variable has been manipulated. * - * @author Joseph Ramsey + * @author josephramsey */ public final class Evidence implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ExtraCategoryInterpolator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ExtraCategoryInterpolator.java index 8d79abb9a4..fddc994968 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ExtraCategoryInterpolator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ExtraCategoryInterpolator.java @@ -32,7 +32,7 @@ * with an extra category that represents the missing values, with missing * values being reported as belong this category. * - * @author Joseph Ramsey + * @author josephramsey */ public final class ExtraCategoryInterpolator implements DataFilter { public DataSet filter(DataSet dataSet) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/IntAveDataSetProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/IntAveDataSetProbs.java index 86f8832ab0..8e563c06a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/IntAveDataSetProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/IntAveDataSetProbs.java @@ -37,7 +37,7 @@ * then return the average over the estimated probabilities calculated this * way. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IntAveDataSetProbs implements DiscreteProbs { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java index 29e0c7d11c..7b2d7056aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java @@ -29,7 +29,7 @@ * X, so the updating operation on the manipulated model will produce different * results. * - * @author Joseph Ramsey + * @author josephramsey */ public interface ManipulatingBayesUpdater extends BayesUpdater { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java index f81c55eaea..e172d822a8 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java @@ -32,7 +32,7 @@ * Stores information for a variable source about evidence we have for each variable as * well as whether each variable has been manipulated. * - * @author Joseph Ramsey + * @author josephramsey */ public final class Manipulation implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java index ae02b24d03..0ea1905834 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java @@ -70,7 +70,7 @@ * Thanks to Pucktada Treeratpituk, Frank Wimberly, and Willie Wheeler for * advice and earlier versions. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class MlBayesIm implements BayesIm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java index dd2c484926..adb8d8e7eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java @@ -68,7 +68,7 @@ * Thanks to Pucktada Treeratpituk, Frank Wimberly, and Willie Wheeler for * advise and earlier versions.> 0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class MlBayesImObs implements BayesIm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ModeInterpolator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ModeInterpolator.java index 9b1877c3a1..e8ff6463eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ModeInterpolator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ModeInterpolator.java @@ -33,7 +33,7 @@ * Creates a data set in which missing values in each column are filled using * the mode of that column. * - * @author Joseph Ramsey + * @author josephramsey */ public final class ModeInterpolator implements DataFilter { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java index 7bfb504f0a..c6c2996e9f 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java @@ -41,7 +41,7 @@ * saying that all categories for that variable are allowed, so the proposition * by default allows all categories for all variables--i.e. it is a tautology. * - * @author Joseph Ramsey + * @author josephramsey */ public final class Proposition implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java index 002a9e51a0..8b02bcd740 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java @@ -35,7 +35,7 @@ * the variables in the Bayes net are in evidence. Can be excruciatingly slow if * numVars - numVarsInEvidence is more than 15. * - * @author Joseph Ramsey + * @author josephramsey */ public final class RowSummingExactUpdater implements ManipulatingBayesUpdater { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java index f7fea827a8..e3c7f3b7fa 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java @@ -36,7 +36,7 @@ * of values per variables this could get to be a very large table, it might not * be a good idea to use this class except for unit testing.> 0 * - * @author Joseph Ramsey + * @author josephramsey */ public final class StoredCellProbs implements TetradSerializable, DiscreteProbs { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java index 46c7377ebb..ccc83d42ba 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java @@ -35,7 +35,7 @@ * of values per variables this could get to be a very large table, it might not * be a good idea to use this class except for unit testing.> 0 * - * @author Joseph Ramsey + * @author josephramsey */ ////////////////////////////////////////////////////////////////////// diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java index 95a45a380c..50183a58dc 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java @@ -41,7 +41,7 @@ * from a variable conditional on its parents are not calculated; rather, these * are simply looked up in the underlying Bayes IM and returned. * - * @author Joseph Ramsey + * @author josephramsey */ public final class UpdatedBayesIm implements BayesIm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java index b2dc1f5c1f..15a1edf1e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java @@ -50,7 +50,7 @@ * then updated for each case in the test data to produce classifications. * * @author Frank Wimberly - * @author Joseph Ramsey + * @author josephramsey */ public class ClassifierMbDiscrete implements ClassifierDiscrete { private DataSet train; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/ClusteringAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/ClusteringAlgorithm.java index 9479b8ff1f..10416b9839 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/ClusteringAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/ClusteringAlgorithm.java @@ -32,7 +32,7 @@ * parameters set so that it can be passed to another class to do clustering on * data. * - * @author Joseph Ramsey + * @author josephramsey */ public interface ClusteringAlgorithm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java index 9b730fa442..72a8e670c2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java @@ -40,7 +40,7 @@ * Note that this algorithm is guaranteed to converge, since the total squared * error is guaranteed to be reduced at each step. * - * @author Joseph Ramsey + * @author josephramsey */ public class KMeans implements ClusteringAlgorithm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/metrics/SquaredErrorLoss.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/metrics/SquaredErrorLoss.java index 7bb9a36df8..336fb05000 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/metrics/SquaredErrorLoss.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/metrics/SquaredErrorLoss.java @@ -27,7 +27,7 @@ * Euclidean dissimilarity metric--i.e., the sum of the differences in * corresponding variable values. * - * @author Joseph Ramsey + * @author josephramsey */ public class SquaredErrorLoss implements Dissimilarity { public double dissimilarity(Vector v1, Vector v2) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java index 1a77662c73..c2cb6ddf43 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java @@ -32,7 +32,7 @@ * other purposes. * * @author Willie Wheeler 7/99 - * @author Joseph Ramsey modifications 12/00 + * @author josephramsey modifications 12/00 */ public abstract class AbstractVariable implements Variable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java index d63269a139..a073c906c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java @@ -36,7 +36,7 @@ * Note that in the calculation, points x such that log(1 - normal_cdf(x)) * is infinite are ignored. * - * @author Joseph Ramsey + * @author josephramsey */ public class AndersonDarlingTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java index 004f90da59..51be9599b3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java @@ -59,7 +59,7 @@ * the data set, but it may be retrieved by algorithms and used. *

* - * @author Joseph Ramsey + * @author josephramsey * @see edu.cmu.tetrad.data.Variable * @see Knowledge */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CaseExpander.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CaseExpander.java index 9d62d76fd3..406aa63ef9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CaseExpander.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CaseExpander.java @@ -27,7 +27,7 @@ * assigned multiplicies other than n = 1 are copied out n times. This increases * the number of rows in the data set. * - * @author Joseph Ramsey + * @author josephramsey */ public final class CaseExpander implements DataFilter { 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 e32a9e05c7..eef4ce76b8 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 @@ -30,7 +30,7 @@ * Stores a cell count table of arbitrary dimension. Provides methods for * incrementing particular cells and for calculating marginals. * - * @author Joseph Ramsey + * @author josephramsey * @see edu.cmu.tetrad.util.MultiDimIntTable */ public final class CellTable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java index c21fc74a63..4791d96ad4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java @@ -31,7 +31,7 @@ /** * Stores clusters of variables for MimBuild, Purify, etc. * - * @author Joseph Ramsey + * @author josephramsey * @author Ricardo Silva */ public final class Clusters implements TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java index eb5cbf48f0..f059c69e76 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java @@ -36,7 +36,7 @@ * order to remember how discretizations were done so that the user doesn't have * to keep typing in information over and over again. * - * @author Joseph Ramsey + * @author josephramsey */ public final class ContinuousDiscretizationSpec implements TetradSerializable, DiscretizationSpec { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java index 81f1d6a834..1e89e27e61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java @@ -37,7 +37,7 @@ * missing value marker for is Double.NaN. * * @author Willie Wheeler 07/99 - * @author Joseph Ramsey modifications 12/00 + * @author josephramsey modifications 12/00 */ public final class ContinuousVariable extends AbstractVariable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java index 88a5ab64c1..be5ae81e08 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java @@ -34,7 +34,7 @@ * Stores a correlation matrix together with variable names and sample size; * intended as a representation of a data set. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class CorrelationMatrix extends CovarianceMatrix { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java index 26b239bc3c..9135094aa3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java @@ -42,7 +42,7 @@ * positive definiteness is "spot-checked"--that is, checked for various * submatrices. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see CorrelationMatrix */ public class CorrelationMatrixOnTheFly implements ICovarianceMatrix { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java index 1c1c16df4a..5c25f27c89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java @@ -38,7 +38,7 @@ * positive definiteness is "spot-checked"--that is, checked for various * submatrices. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see edu.cmu.tetrad.data.CorrelationMatrix */ public class CovarianceMatrix implements ICovarianceMatrix { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java index 0797f21160..864067c8e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java @@ -44,7 +44,7 @@ * positive definiteness is "spot-checked"--that is, checked for various * submatrices. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see CorrelationMatrix */ public class CovarianceMatrixOnTheFly implements ICovarianceMatrix { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataBox.java index 572be82bee..cd372d746a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataBox.java @@ -27,7 +27,7 @@ * Stores a 2D array of data. Different implementations may store data in * different ways, allowing for space or time efficiency. * - * @author Joseph Ramsey + * @author josephramsey */ public interface DataBox extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataFilter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataFilter.java index 6b4a57e8c1..84a12f1716 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataFilter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataFilter.java @@ -26,7 +26,7 @@ * Interface implemented by classes whose purpose is to generate modifications * of data sets. See implementations for details. * - * @author Joseph Ramsey + * @author josephramsey */ public interface DataFilter { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModel.java index 3b41cce511..e5aca1aa1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModel.java @@ -33,7 +33,7 @@ * data sets, covariance and correlation matrices, graphs, and lists of other * data models. So this is primarily a taqging interface. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public interface DataModel extends KnowledgeTransferable, VariableSource { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java index 3d97f10056..42ee88e069 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java @@ -32,7 +32,7 @@ /** * Stores a list of data models and keeps track of which one is selected. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see DataModel */ public final class DataModelList extends AbstractList diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataSet.java index 6cb666627a..254fc84689 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataSet.java @@ -33,7 +33,7 @@ * a fixed number of columns and a fixed number of rows, the length of each * column being constant. * - * @author Joseph Ramsey + * @author josephramsey */ public interface DataSet extends DataModel { long serialVersionUID = 23L; 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 4ad8c4f7d1..e3f72ad353 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 @@ -34,7 +34,7 @@ /** * Provides static methods for saving data to files. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DataWriter { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java index d0c3c8f68d..8cc3f0bfee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java @@ -31,7 +31,7 @@ * new field. SECTION_MARKER is replaces tabs by " *\t *". LAUNCH_TIME replaces * tabs by ",". Custom replaces tabs by a specified regular expression. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DelimiterType implements TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java index e05775c7a1..a3a65be494 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java @@ -36,7 +36,7 @@ * order to remember how discretizations were done so that the user doesn't have * to keep typing in information over and over again. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DiscreteDiscretizationSpec implements TetradSerializable, DiscretizationSpec { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java index 08c27cad6a..76908e5736 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java @@ -48,7 +48,7 @@ *

* The index value used to indicate missing data is -99. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DiscreteVariable extends AbstractVariable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java index 7457ffbfe9..26869e79fc 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java @@ -32,7 +32,7 @@ * discrete variable is an ordinal discrete variable for which relative * distances between categories can be specified. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DiscreteVariableType implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscretizationSpec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscretizationSpec.java index 686bd91942..9a3be8e079 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscretizationSpec.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscretizationSpec.java @@ -24,7 +24,7 @@ /** * A continuous or discrete discretization spec (see). * - * @author Joseph Ramsey + * @author josephramsey */ public interface DiscretizationSpec { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java index f41ec3c24e..d0c9805403 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java @@ -34,7 +34,7 @@ * is discretized by specifying a mapping from old value names to new * value names, the idea being that old values may be merged. * - * @author Joseph Ramsey + * @author josephramsey * @author Tyler Gibson */ public class Discretizer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/GeneralAndersonDarlingTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/GeneralAndersonDarlingTest.java index b2e5a346a2..e423b60a09 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/GeneralAndersonDarlingTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/GeneralAndersonDarlingTest.java @@ -34,7 +34,7 @@ * Note that in the calculation, points x such that log(1 - dist.get(x))) * is infinite are ignored. * - * @author Joseph Ramsey + * @author josephramsey */ public class GeneralAndersonDarlingTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java index 4c3909e477..bdcaa08fde 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java @@ -35,7 +35,7 @@ /** * Model for a conditional histogram for mixed continuous and discrete variables. * - * @author Joseph Ramsey + * @author josephramsey */ public class Histogram { private Node target; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java index f91d22e187..d9e0456300 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java @@ -33,7 +33,7 @@ /** * Stores a list of independence facts. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndependenceFacts implements DataModel { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java index bcaefe2a37..29b634ff50 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java @@ -49,7 +49,7 @@ * following character is encountered. Thus, "X*a" will match "X123a" and * "X45a". * - * @author Joseph Ramsey + * @author josephramsey * @author Kevin V. Bui (kvb2@pitt.edu) */ public final class Knowledge implements TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java index 485edcf9df..37ad4d89f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java @@ -29,7 +29,7 @@ /** * Implements a knowledge edge X-->Y as a simple ordered pair of strings. * - * @author Joseph Ramsey + * @author josephramsey */ public final class KnowledgeEdge implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeTransferable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeTransferable.java index b6574887ed..b70711c07c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeTransferable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeTransferable.java @@ -27,7 +27,7 @@ * Interface implemented by classes that are capable of participating in the * transfer of knowledge objects. * - * @author Joseph Ramsey + * @author josephramsey * @see Knowledge */ public interface KnowledgeTransferable extends TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Lineizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Lineizer.java index 5efd8a4989..6cef7dfdda 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Lineizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Lineizer.java @@ -26,7 +26,7 @@ import java.io.Reader; /** - * @author Joseph Ramsey + * @author josephramsey * Returns one line at a time, with a method to determine whether another * line is available. Blank lines and lines beginning with the given comment * marker are skipped. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MeanInterpolator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MeanInterpolator.java index 31588ab418..7e615c9057 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MeanInterpolator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MeanInterpolator.java @@ -25,7 +25,7 @@ * Returns a data set in which missing values in each column are filled using * the mean of that column. * - * @author Joseph Ramsey + * @author josephramsey */ public final class MeanInterpolator implements DataFilter { public DataSet filter(DataSet dataSet) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MultiGeneralAndersonDarlingTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MultiGeneralAndersonDarlingTest.java index d872d0425f..a6c291fcea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MultiGeneralAndersonDarlingTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/MultiGeneralAndersonDarlingTest.java @@ -34,7 +34,7 @@ * Note that in the calculation, points x such that log(1 - distributions.get(x))) * is infinite are ignored. * - * @author Joseph Ramsey + * @author josephramsey */ public class MultiGeneralAndersonDarlingTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java index accb657850..88075d1c36 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java @@ -73,7 +73,7 @@ * very large data sets, it makes more sense to disallow memory-hogging * manipulations than to throw out-of-memory errors. * - * @author Joseph Ramsey + * @author josephramsey * @see edu.cmu.tetrad.data.Variable * @see Knowledge */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/RegexTokenizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/RegexTokenizer.java index c63165d523..6c1637e0dc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/RegexTokenizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/RegexTokenizer.java @@ -29,7 +29,7 @@ * specified bythe given CPDAG. Meant to function just like StringTokenizer, * with more control over what counts as a tokenization delimiter. * - * @author Joseph Ramsey + * @author josephramsey */ public final class RegexTokenizer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java index 55b2f3d9fe..c1e00b4568 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java @@ -36,7 +36,7 @@ * order to remember how discretizations were done so that the user doesn't have * to keep typing in information over and over again. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SplitCasesSpec implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java index 0989adae00..c6f60275a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java @@ -33,7 +33,7 @@ /** * Stores time series data as a list of continuous columns. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TimeSeriesData implements DataModel { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java index 037ee9ac0f..1f11dfa785 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java @@ -32,7 +32,7 @@ * external data (in String form, say) is to be converted into raw data of the * type used in the column in question. * - * @author Joseph Ramsey + * @author josephramsey */ public interface Variable extends Node { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java index c0f41e437c..a6b9445cd2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java @@ -32,7 +32,7 @@ * purposes--creating data sets, creating graphs, comparing one data to another, * and so on. * - * @author Joseph Ramsey + * @author josephramsey */ public interface VariableSource extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java index dbec0c5bf2..427a88ec10 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java @@ -29,7 +29,7 @@ /** * Stores a 2D array of double data. * - * @author Joseph Ramsey + * @author josephramsey */ public class VerticalDoubleDataBox implements DataBox { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java index 893ea1ebbb..1d1b0e70c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java @@ -34,7 +34,7 @@ * directed edges, with no cycles. Variables are permitted to be either measured * or latent, with at most one edge per node pair, and no edges to self. * - * @author Joseph Ramsey + * @author josephramsey */ public final class Dag implements Graph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java index 174c8a0224..eded621d40 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java @@ -37,7 +37,7 @@ * Note that because speed is of the essence, and Edge cannot be compared to an * object of any other type; this will throw an exception. * - * @author Joseph Ramsey + * @author josephramsey */ public class Edge implements TetradSerializable, Comparable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java index 2d9fa6b87d..ec9a7a2b35 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java @@ -38,7 +38,7 @@ * another edge X --> Y may not be added, although an edge Y --> X may be added. * Edges from nodes to themselves may also be added.> 0 * - * @author Joseph Ramsey + * @author josephramsey * @author Erin Korber additions summer 2004 * @see edu.cmu.tetrad.graph.Endpoint */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java index af8b4e2ee1..7f07590323 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edges.java @@ -39,7 +39,7 @@ * uniform way of testing whether an edge is in fact, e.g., a directed edge (or * any of the other types). * - * @author Joseph Ramsey + * @author josephramsey */ public final class Edges { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java index 8865b025eb..9cdf8ae47a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java @@ -28,7 +28,7 @@ * Tetrad-style graphs: null (-), arrow (->), circle (-o), start (-*), * and null (no endpoint). * - * @author Joseph Ramsey + * @author josephramsey */ public enum Endpoint implements TetradSerializable { TAIL, ARROW, CIRCLE, STAR, NULL; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java index 1e969993b9..6a9ca2cd6b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java @@ -37,7 +37,7 @@ * randomUtil, in order to be able to cancelAll operations, they must be * serializable.) * - * @author Joseph Ramsey + * @author josephramsey * @see Endpoint */ public interface Graph extends TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphGeneratorRandomNumEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphGeneratorRandomNumEdges.java index c236dee6f0..ff5d0ef6a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphGeneratorRandomNumEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphGeneratorRandomNumEdges.java @@ -55,7 +55,7 @@ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, * USA." * - * @author Joseph Ramsey + * @author josephramsey */ public final class GraphGeneratorRandomNumEdges { private static final int ANY_DAG = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java index fed7ca6b70..ef830aa6ec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java @@ -31,7 +31,7 @@ * Implements a basic node in a graph--that is, a node that is not itself a * variable. * - * @author Joseph Ramsey + * @author josephramsey * @author Willie Wheeler */ public class GraphNode implements Node { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index 0c080648ab..a3dd331ca2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -40,7 +40,7 @@ /** * Basic graph utilities. * - * @author Joseph Ramsey + * @author josephramsey */ public final class GraphUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java index 02fc0d077a..75adcfcc0c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java @@ -32,7 +32,7 @@ * Stores a triple (x, y, z) of nodes. Note that (x, y, z) = (z, y, x). Useful * for marking graphs. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IndependenceFact implements Comparable, TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java index d6e56bcbec..b5c619aaf2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java @@ -29,7 +29,7 @@ * taken from previous time lags. This is intended to be interpreted as a * repeating time series graph for purposes of simulation. * - * @author Joseph Ramsey + * @author josephramsey */ public class LagGraph implements Graph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java index 0d56f9b273..9504073f1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java @@ -100,7 +100,7 @@ public static boolean arrangeBySourceGraph(Graph resultGraph, Graph sourceGraph) * Lays out a graph by placing springs between the nodes and letting the system * settle (one node at a time). * - * @author Joseph Ramsey + * @author josephramsey */ public static final class KamadaKawaiLayout { @@ -587,7 +587,7 @@ private void setComponentNodes(List componentNodes) { * Lays out a graph by linearly summing repulsive force between all nodes and * attractive force between adjacent nodes. * - * @author Joseph Ramsey + * @author josephramsey */ public static final class FruchtermanReingoldLayout { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/MisclassificationUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/MisclassificationUtils.java index 03af96210b..3cb198d5be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/MisclassificationUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/MisclassificationUtils.java @@ -30,7 +30,7 @@ /** * Some utilities for generating misclassification tables for graphs. * - * @author Joseph Ramsey + * @author josephramsey */ public class MisclassificationUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java index 2bace52d68..e3b0cb6e42 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java @@ -31,7 +31,7 @@ * Represents an object with a name, node type, and position that can serve as a * node in a graph. * - * @author Joseph Ramsey + * @author josephramsey * @see NodeType */ public interface Node extends TetradSerializable, Comparable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeEqualityMode.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeEqualityMode.java index b735635da7..c61a466fbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeEqualityMode.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeEqualityMode.java @@ -25,7 +25,7 @@ * Sets whether nodes are compared by the equals method or by object * identity. * - * @author Joseph Ramsey + * @author josephramsey */ public class NodeEqualityMode { public enum Type {NAME, OBJECT} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java index aca351ec49..ab4d246cc7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java @@ -29,7 +29,7 @@ * A typesafe enum of the types of the types of nodes in a graph (MEASURED, * LATENT, ERROR). * - * @author Joseph Ramsey + * @author josephramsey */ public final class NodeType implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java index 80f1858e10..b0a27babff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java @@ -622,7 +622,7 @@ public static void addTwoCycles(Graph graph, int numTwoCycles) { * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, * USA." * - * @author Joseph Ramsey + * @author josephramsey */ public static final class UniformGraphGenerator { public static final int ANY_DAG = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java index 56d990be62..ccab9b93f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java @@ -48,7 +48,7 @@ * This avoids the problem of not knowing whether the exogenous node for a * node is itself or its associated error node. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SemGraph implements Graph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java index d19156fbc3..8ab0902dca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java @@ -29,7 +29,7 @@ * Represents a time series graph--that is, a graph with a fixed number S of lags, with edges into initial lags * only--that is, into nodes in the first R lags, for some R. Edge structure repeats every R nodes. * - * @author Joseph Ramsey + * @author josephramsey */ public class TimeLagGraph implements Graph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java index c9b21eade6..46ffdefc6a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java @@ -30,7 +30,7 @@ * Stores a triple (x, y, z) of nodes. Note that (x, y, z) = (z, y, x). Useful * for marking graphs. * - * @author Joseph Ramsey, after Frank Wimberly. + * @author josephramsey, after Frank Wimberly. */ public final class Triple implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TripleClassifier.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TripleClassifier.java index ede95b4100..17117c400b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TripleClassifier.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TripleClassifier.java @@ -26,7 +26,7 @@ /** * Marks a search algorithm as a triad classifier and returns the triad classifications if makes. * - * @author Joseph Ramsey + * @author josephramsey */ public interface TripleClassifier { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/Regression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/Regression.java index 0b8edbe331..3b6b620981 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/Regression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/Regression.java @@ -30,7 +30,7 @@ * Implements a multiple regression model, allowing data to be specified * either as a tabular data set or as a covariance matrix plus list of means. * - * @author Joseph Ramsey + * @author josephramsey */ public interface Regression { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java index b950021a85..a31578f4b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java @@ -36,7 +36,7 @@ * Implements a regression model from correlations--that is, from a correlation * matrix, a list of standard deviations, and a list of means. * - * @author Joseph Ramsey + * @author josephramsey */ public class RegressionCovariance implements Regression { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java index d862eb002e..c57a9172eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java @@ -34,7 +34,7 @@ /** * Implements a regression model from tabular continuous data. * - * @author Joseph Ramsey + * @author josephramsey */ public class RegressionDataset implements Regression { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java index 47ec8847f1..4b9f5cbad4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java @@ -33,7 +33,7 @@ * Stores the various components of a regression result so they can be passed * around together more easily. * - * @author Joseph Ramsey + * @author josephramsey */ public class RegressionResult implements TetradSerializable { static final long serialVersionUID = 23L; 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 22629c0e31..299102a258 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 @@ -43,7 +43,7 @@ * the true DAG.

* * @author Frank C. Wimberly - * @author Joseph Ramsey + * @author josephramsey */ public final class Ccd implements IGraphSearch { private final IndependenceTest independenceTest; 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 bd40059542..72c60bb73b 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 @@ -40,7 +40,7 @@ * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested * locally. * - * @author Joseph Ramsey (this version). + * @author josephramsey (this version). */ public final class Cpc implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index 9b8a498ad8..b493b59565 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -54,7 +54,7 @@ *

Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, * prediction, and search. MIT press.

* - * @author Joseph Ramsey. + * @author josephramsey. * @see Pc * @see Fci */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java index 4e37383681..05fdea05fb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java @@ -41,7 +41,7 @@ * That is, if X _||_ Y | Z, but Z determines X or Y, then the edge X---Y is * not removed.

* - * @author Joseph Ramsey. + * @author josephramsey. * @see Fas */ public class FasDeterministic implements IFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 3540d9564e..c379e28847 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -131,7 +131,7 @@ * --twoCycleScreeningThreshold 0 --orientationAlpha 0.1 -structurePrior 0 *

* - * @author Joseph Ramsey + * @author josephramsey */ public final class Fask implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index 4250cf6996..3d2859c005 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -42,7 +42,7 @@ * (2019). Feasibility of lung cancer prediction from low-dose CT scan and smoking factors using * causal models. Thorax, 74(7), 643-649.

* - * @author Joseph Ramsey + * @author josephramsey * @see Fci */ public final class FciMax implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index 8a01f9bd80..b7b456d515 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -33,7 +33,7 @@ *

Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. * Advances in neural information processing systems, 12.

* - * @author Joseph Ramsey + * @author josephramsey */ public class GrowShrink implements IMbSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java index 1f47ac7cdb..4be21de3ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java @@ -50,7 +50,7 @@ * It is assumed that the CPDAG is the result of a CPDAG search such as PC or GES. In any * case, it is important that the residuals be independent for ICA to work. * - * @author Joseph Ramsey + * @author josephramsey */ public class LingamPattern { private final Graph cpdag; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 31527762fc..2e1725be4d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -46,7 +46,7 @@ * Lofs.Score. The options for rules to use to do the orientations are given in the * enum, Lofs.Rule. Most of these are taken from the literature and ca be googled.

* - * @author Joseph Ramsey + * @author josephramsey * @see Score * @see Rule */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java index b202c1cb09..6f749557eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java @@ -34,7 +34,7 @@ * Implements the Min-Max Markov Blanks (MMMB) algorithm as defined in Tsamardinos, Aliferis, and Statnikov, Time and * Sample Efficient Discovery of Markov Blankets and Direct Causal Relations (KDD 2003). * - * @author Joseph Ramsey + * @author josephramsey */ public final class Mmmb implements IMbSearch { 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 b4755ede80..6bc8501975 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 @@ -44,7 +44,7 @@ * modified rule set in step D due to Chris Meek. For the modified rule set, see Chris * Meek (1995), "Causal inference and causal explanation with background knowledge." * - * @author Joseph Ramsey. + * @author josephramsey. */ public class Pc implements IGraphSearch { 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 6cfdbb1136..477c0483f1 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 @@ -43,7 +43,7 @@ * Prediction, and Search," 2nd edition, with a modified rule set in step D due to Chris Meek. For the modified rule * set, see Chris Meek (1995), "Causal inference and causal explanation with background knowledge." * - * @author Joseph Ramsey. + * @author josephramsey. */ public class PcMax implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index d56620b789..fbf82fa4ce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -37,7 +37,7 @@ * independence information. This CPDAG may be used to generate the actual list of DAG's that might be Markov * blankets. Note that this code has been converted to be consistent with the CPC algorithm.

* - * @author Joseph Ramsey + * @author josephramsey */ public final class PcMb implements IMbSearch, IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index 96186b5a4d..bba876eef8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -41,7 +41,7 @@ * Prediction, and Search," 2nd edition, with a modified rule set in step D due to Chris Meek. For the modified rule * set, see Chris Meek (1995), "Causal inference and causal explanation with background knowledge." * - * @author Joseph Ramsey. + * @author josephramsey. */ public class Pcd implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 846786926b..a14e812d83 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -48,7 +48,7 @@ * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 - * @author Joseph Ramsey + * @author josephramsey * @author Choh-Man Teng */ public final class Rfci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java index 0b7e115af8..9574de660a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java @@ -39,7 +39,7 @@ /** * Tries to find a good shifting of variables to minimize average BIC * - * @author Joseph Ramsey + * @author josephramsey */ public class ShiftSearch { private final List dataSets; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 211771ee15..7d90ba1a12 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -49,7 +49,7 @@ * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 - * @author Joseph Ramsey + * @author josephramsey * @author Choh-Man Teng * @author Daniel Malinsky */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 5b57e6ae7a..07c8045b4f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -49,7 +49,7 @@ * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 - * @author Joseph Ramsey + * @author josephramsey * @author Choh-Man Teng * @author Daniel Malinsky *

diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java index 71da7db607..11d0d0f20d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java @@ -54,7 +54,7 @@ * A number of other optimizations were added 5/2015. See code for details. * * @author Ricardo Silva, Summer 2003 - * @author Joseph Ramsey, Revisions 5/2015 + * @author josephramsey, Revisions 5/2015 * @author Daniel Malinsky */ public final class TsFges implements IGraphSearch, DagScorer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java index b5bbd822cf..07b179c465 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java @@ -43,7 +43,7 @@ * continuous mixedVariables are jointly Gaussian conditional on the discrete mixedVariables; in all other cases, it will * be less than maximal. For an algorithm like FGS this is fine. * - * @author Joseph Ramsey + * @author josephramsey */ public class ConditionalGaussianLikelihood { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index 589e85e1dc..f568fc2220 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -36,7 +36,7 @@ /** * Implements a conditional Gaussian BIC score for FGS. * - * @author Joseph Ramsey + * @author josephramsey */ public class ConditionalGaussianScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java index 2b3dff5065..076886615e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java @@ -38,7 +38,7 @@ /** * Implements the extended BIC (EBIC) score (Chen and Chen).. * - * @author Joseph Ramsey + * @author josephramsey */ public class EbicScore implements Score { private DataSet dataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index e172e9e004..2d2085d239 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -41,7 +41,7 @@ * high dimensions. The Journal of Machine Learning Research, 13(1), 1037-1057. * Foster and George.

* - * @author Joseph Ramsey + * @author josephramsey */ public class GicScores implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java index a01919f513..65d47c935d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java @@ -42,7 +42,7 @@ * consistent score criterion. This is not a true score; rather, a 0 is returned * in case dseparation holds and a 1 in case dseparation does not hold. * - * @author Joseph Ramsey + * @author josephramsey */ public class GraphScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java index 27268b9e8c..663c3e42ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java @@ -42,7 +42,7 @@ * ensure that all of the scores share the same (object-identical) * variables.

* - * @author Joseph Ramsey + * @author josephramsey * @see Fges * @see Grasp * @see Boss diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java index d7b07dded9..d0b2cadd5e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java @@ -32,7 +32,7 @@ /** * Implements Chickering and Meek's (2002) locally consistent score criterion. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndTestScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index 91532c80e0..fabdb76d7e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -36,7 +36,7 @@ /** * Implements Poisson prior score (Bryan). * - * @author Joseph Ramsey + * @author josephramsey */ public class PoissonPriorScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java index affedd6079..14715ac0d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java @@ -29,7 +29,7 @@ /** * Stores a graph with a score. * - * @author Joseph Ramsey + * @author josephramsey */ public class ScoredGraph implements Comparable, TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index dc4c7f00ff..8d0c2b3331 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -42,7 +42,7 @@ /** * Implements the continuous BIC score for FGES. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemBicScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index c9e07457bd..f14f3f6adf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -43,7 +43,7 @@ * high‐dimensional data. Statistical Analysis and Data Mining: The * ASA Data Science Journal, 3(5), 350-358

* - * @author Joseph Ramsey + * @author josephramsey */ public class ZsbScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java index 890cfc5a9d..2fe394235a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java @@ -34,7 +34,7 @@ * Calculates marginal chi square test results for a discrete dataset. * * @author Frank Wimberly original version - * @author Joseph Ramsey revision 10/01, believe it or now also 2020. + * @author josephramsey revision 10/01, believe it or now also 2020. */ public class ChiSquareTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java index 224345a5d6..30820c3021 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java @@ -49,7 +49,7 @@ *

* We use Nadaraya-Watson kernel regression, though we further restrict the sample size to nearby points. * - * @author Joseph Ramsey + * @author josephramsey */ public final class ConditionalCorrelationIndependence { public enum Kernel {Epinechnikov, Gaussian} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java index 53d2e2ea38..6e9a838377 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java @@ -38,7 +38,7 @@ * Categorical Data, 2nd Edition, 142. * * @author Frank Wimberly original version - * @author Joseph Ramsey revision 10/01 + * @author josephramsey revision 10/01 */ public final class GSquareTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java index fa4f71939e..1b5cb7c000 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java @@ -38,7 +38,7 @@ * Checks independence facts for variables associated with the nodes in a given graph by * checking d-separation facts on the underlying nodes. * - * @author Joseph Ramsey + * @author josephramsey */ public class IndTestDSep implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java index 7be1e9b924..f6346bf472 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java @@ -45,7 +45,7 @@ * Checks conditional independence of variable in a continuous data set using Fisher's Z test. * See Spirtes, Glymour, and Scheines, "Causation, Prediction and Search," 2nd edition, page 94. * - * @author Joseph Ramsey + * @author josephramsey * @author Frank Wimberly */ public final class IndTestFisherZ implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java index 655a6d058b..0ffbd7971e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java @@ -41,7 +41,7 @@ /** * Calculates independence from pooled residuals. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IndTestFisherZConcatenateResiduals implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java index f445595ddc..5b9eb1d9dc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java @@ -41,7 +41,7 @@ /** * Calculates independence from pooled residuals. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IndTestFisherZFisherPValue implements IndependenceTest { private final List variables; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java index b62fedd454..61cc66b1a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java @@ -39,7 +39,7 @@ * Analysis of Cross-Classified Categorical Data," 2nd edition. The formula for degrees of freedom used in this test are * equivalent to the formulation on page 142 of Fienberg. * - * @author Joseph Ramsey + * @author josephramsey * @see GSquareTest */ public final class IndTestGSquare implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java index 23b956df9e..5836e0696d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java @@ -34,7 +34,7 @@ /** * Checks conditional independence against a list of conditional independence facts, manually entered. * - * @author Joseph Ramsey + * @author josephramsey * @see ChiSquareTest */ public final class IndTestIndependenceFacts implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java index f4dd52b26b..cc06f2d132 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java @@ -45,7 +45,7 @@ * Checks conditional independence of variable in a continuous data set using Fisher's Z test. See Spirtes, Glymour, and * Scheines, "Causation, Prediction and Search," 2nd edition, page 94. * - * @author Joseph Ramsey + * @author josephramsey * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z */ public final class IndTestPositiveCorr implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java index 6ec589f8ae..1c1a8dbd14 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java @@ -36,7 +36,7 @@ /** * Uses BCInference by Cooper and Bui to calculate probabilistic conditional independence judgments. * - * @author Joseph Ramsey 3/2014 + * @author josephramsey 3/2014 */ public class IndTestProbabilistic implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java index ee457ba618..e9afbdfa0c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java @@ -49,7 +49,7 @@ * calculated using generalized inverses, so linearly dependent variables do not throw exceptions. Must supply a * continuous data set; don't know how to do this with covariance or correlation matrices. * - * @author Joseph Ramsey + * @author josephramsey * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z */ public final class IndTestRegression implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java index b11253f900..208ada5de1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java @@ -36,7 +36,7 @@ * These classes are capable of serving as conditional independence "oracles" * for constraint-based searches.

* - * @author Joseph Ramsey + * @author josephramsey */ public interface IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java index 479032cff8..b4df56d6a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java @@ -14,7 +14,7 @@ *

* Continuous variables in the data set are ignored. * - * @author Joseph Ramsey + * @author josephramsey */ public class AdLeafTree { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java index 639578bc54..f73914f18d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java @@ -35,7 +35,7 @@ *

The method of this class are used only internally and so are not documented * for public use.

* - * @author Joseph Ramsey + * @author josephramsey */ public class ClusterUtils { public static final String LATENT_PREFIX = "_L"; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java index 6880d33403..39ad47e44d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java @@ -30,7 +30,7 @@ * Given a pattern, lists all of the DAGs in that pattern. In the form of an iterator--call hasNext() to see if there's * another one and next() to get it. next() will return null if there are no more. * - * @author Joseph Ramsey + * @author josephramsey */ public class DagInCpcagIterator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java index 1678fe00c4..5aaa6eeec5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java @@ -32,7 +32,7 @@ * Given a graph, lists all DAGs that result from directing the undirected edges in that graph every possible way. Uses * a Meek-algorithm-type method. * - * @author Joseph Ramsey + * @author josephramsey */ public class DagIterator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagScorer.java index df0bbd78f4..6b13c99104 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagScorer.java @@ -26,7 +26,7 @@ /** * Interface for a method that scores a DAG. * - * @author Joseph Ramsey + * @author josephramsey */ public interface DagScorer { double scoreDag(Graph dag); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagSepsets.java index cc3d749376..a59bcaad32 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagSepsets.java @@ -32,7 +32,7 @@ * Determines sepsets, collider, and noncolliders by examining d-separation facts in * a DAG. * - * @author Joseph Ramsey + * @author josephramsey */ public class DagSepsets implements SepsetProducer { private final EdgeListGraph dag; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java index 1733408be8..ee04cd5417 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java @@ -37,7 +37,7 @@ * Sociological Methods and Research 19, 80-92 and Bollen and Ting, Confirmatory Tetrad * Analysis. * - * @author Joseph Ramsey + * @author josephramsey */ public class DeltaSextadTest { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java index 16a9ed8c1b..44918936b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java @@ -34,7 +34,7 @@ * for vanishing tetrads." Sociological Methods and Research 19, 80-92 and Bollen and Ting, Confirmatory Tetrad * Analysis. * - * @author Joseph Ramsey + * @author josephramsey */ public class DeltaTetradTest { private DataSet dataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java index c2ffed1afa..275bbb26f1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java @@ -61,7 +61,7 @@ * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 - * @author Joseph Ramsey + * @author josephramsey * @author Choh-Man Teng * @see Fci * @see GFci diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java index 3a9114a6c5..d27205e12b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java @@ -48,7 +48,7 @@ * A number of other optimizations were added 5/2015. See code for details. * * @author Ricardo Silva, Summer 2003 - * @author Joseph Ramsey, Revisions 5/2015 + * @author josephramsey, Revisions 5/2015 *

* This Orients a given undirected graph such that the edges in the graph are a superset * of the edges in the oriented graph diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java index f3efd7b6c6..96983371ef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java @@ -44,7 +44,7 @@ * Graph utilities for search algorithm. Lots of orientation method, for * instance. * - * @author Joseph Ramsey + * @author josephramsey */ public final class GraphUtilsSearch { @@ -1597,7 +1597,7 @@ public enum CpcTripleType { /** * Simple class to store edges for the reachability search. * - * @author Joseph Ramsey + * @author josephramsey */ private static class ReachabilityEdge { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java index 3c27cc2377..6cdfe77acb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java @@ -29,7 +29,7 @@ * Determines whether nodes indexed as (n1, center, n2) form a legal pair of edges in a graph for purposes of some * algorithm that uses this information. The pair would be n1---center---n2. * - * @author Joseph Ramsey + * @author josephramsey */ public interface LegalPairs { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java index 671d3a4b5b..8571340ba8 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LogUtilsSearch.java @@ -32,7 +32,7 @@ /** * Contains utilities for logging search steps. * - * @author Joseph Ramsey + * @author josephramsey */ public class LogUtilsSearch { public static String edgeOrientedMsg(String reason, Edge edge) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java index a1f0510f54..c05698a7c8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java @@ -39,7 +39,7 @@ *

Ramsey, J. (2016). Improving accuracy and scalability of the pc * algorithm by maximizing p-value. arXiv preprint arXiv:1610.00378.

* - * @author Joseph Ramsey + * @author josephramsey * @see PcMax */ public final class MaxP { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java index 316d9c41c1..12bd1468ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java @@ -37,7 +37,7 @@ *

* Rule R4 is only performed if knowledge is nonempty. * - * @author Joseph Ramsey + * @author josephramsey */ public class MeekRules { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java index b329f800b7..8cc8cc4729 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java @@ -40,7 +40,7 @@ * model could be considered as variables. This allows us to use d-separation as a graphical indicator of what * independence in models ideally should be.> 0 * - * @author Joseph Ramsey + * @author josephramsey */ public final class SepsetMap implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java index 28b20ee225..f12c7cfc45 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java @@ -29,7 +29,7 @@ /** *

A covenience structure that can generate and keep track of sepsets

* - * @author Joseph Ramsey + * @author josephramsey * @see SepsetMap */ public interface SepsetProducer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java index 4118b09dad..5dfa7612b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java @@ -46,7 +46,7 @@ * Contains some utilities for doing autoregression. Should probably be improved * by somebody. * - * @author Joseph Ramsey + * @author josephramsey * @author Daniel Malinsky (some improvements) */ public class TsUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java index 34ae687a57..dcaad7e21e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/BpcTetradPurifyWashdown.java @@ -34,7 +34,7 @@ /** * Implements a really simple idea for building pure clusters, just using the Purify algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class BpcTetradPurifyWashdown { private final List variables; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java index f206bc8fd2..fe0a25d294 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java @@ -50,7 +50,7 @@ * This variant does each depth twice, gathering up the p values in the first round, using FDR to estimate a cutoff * for acceptance, and rerunning using the specified cutoff. * - * @author Joseph Ramsey. + * @author josephramsey. */ public class FasFdr implements IFas { private final Matrix cov; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java index a245132468..15a3d27781 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java @@ -54,7 +54,7 @@ * & Shimizu, S. (2012). Causal discovery of linear acyclic models with arbitrary * distributions. arXiv preprint arXiv:1206.3260.

* - * @author Joseph Ramsey + * @author josephramsey * @see Fas * @see Fask */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java index 0e931799d8..4690b422ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java @@ -26,7 +26,7 @@ * an adjacency graph, as an alternative to bootstrapping.

* * @author Madelyn Glymour - * @author Joseph Ramsey 9/5/2020 + * @author josephramsey 9/5/2020 */ public class FaskVote { private final IndependenceWrapper test; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java index 92b0881135..4b887ebbcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java @@ -28,7 +28,7 @@ /** * A translation from Tibshirani's 2008 Fortran implementation of glasso. * - * @author Joseph Ramsey + * @author josephramsey */ public class Glasso { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java index 0b820f4efa..a9f568c98f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java @@ -44,7 +44,7 @@ *

* Improves the P value of a SEM IM by adding, removing, or reversing single edges. * - * @author Joseph Ramsey + * @author josephramsey */ public final class HbsmsBeam implements Hbsms { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java index bc02a2b7df..9f812fef71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java @@ -42,7 +42,7 @@ *

Heuristic Best Significant Model Search using the GES algorithm.

*

Improves the P value of a SEM IM by adding, removing, or reversing single edges.

* - * @author Joseph Ramsey + * @author josephramsey */ public final class HbsmsGes implements Hbsms { private Knowledge knowledge = new Knowledge(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java index 22afbbb911..115d3c9fdd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java @@ -41,7 +41,7 @@ * Checks conditional independence for continuous variables using Cramer's T-test formula (Cramer, Mathematical Methods * of Statistics (1951), page 413). * - * @author Joseph Ramsey + * @author josephramsey */ public final class IndTestCramerT implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java index c00d05d9a6..9b5dbbc766 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java @@ -46,7 +46,7 @@ * calculated using generalized inverses, so linearly dependent variables do not throw exceptions. Must supply a * continuous data set; don't know how to do this with covariance or correlation matrices. * - * @author Joseph Ramsey + * @author josephramsey * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z */ public final class IndTestFisherZGeneralizedInverse implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java index a5223e6617..11ea240c31 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java @@ -42,7 +42,7 @@ /** * Calculates independence from pooled residuals. * - * @author Joseph Ramsey + * @author josephramsey */ public final class IndTestFisherZPercentIndependent implements IndependenceTest { private final List variables; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java index 205302c079..ef9baa7f7e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java @@ -51,7 +51,7 @@ * Checks conditional independence of variable in a continuous data set using Fisher's Z test. See Spirtes, Glymour, and * Scheines, "Causation, Prediction and Search," 2nd edition, page 94. * - * @author Joseph Ramsey + * @author josephramsey * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z */ public final class IndTestFisherZRecursive implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMixedMultipleTTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMixedMultipleTTest.java index 86a97338ba..fef4805674 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMixedMultipleTTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMixedMultipleTTest.java @@ -48,7 +48,7 @@ * This logisticRegression makes multiple assumptions: 1. IIA 2. Large sample size (multiple regressions needed on subsets of * sample) * - * @author Joseph Ramsey + * @author josephramsey * @author Augustus Mayo. */ public class IndTestMixedMultipleTTest implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java index 124e9bb80f..7fd3cbfd73 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java @@ -46,7 +46,7 @@ * This logisticRegression makes multiple assumptions: 1. IIA 2. Large sample size (multiple regressions needed on subsets of * sample) * - * @author Joseph Ramsey + * @author josephramsey * @author Augustus Mayo. */ public class IndTestMultinomialLogisticRegression implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java index ed9cc40ae2..3aa8a84014 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java @@ -33,7 +33,7 @@ /** * Returns edges whose entries in the precision matrix exceed a certain threshold. * - * @author Joseph Ramsey + * @author josephramsey */ public class InverseCorrelation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java index e15cf931a7..1ad7eb3cca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java @@ -40,7 +40,7 @@ * form an input PAG_of_the_true_DAG that are consistent (same d-separations and d-connections) with every input PAG_of_the_true_DAG. * * @author Robert Tillman - * @author Joseph Ramsey + * @author josephramsey */ public class Ion { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java index 1bdef7913c..ee9f4ea8fe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java @@ -38,7 +38,7 @@ /** * Implements the MMHC algorithm. * - * @author Joseph Ramsey (this version). + * @author josephramsey (this version). */ public class Mmhc implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java index 3cccae99c5..8ac2c55412 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java @@ -40,7 +40,7 @@ /** * Uses BCInference by Cooper and Bui to calculate probabilistic conditional independence judgments. * - * @author Joseph Ramsey 3/2014 + * @author josephramsey 3/2014 */ public class ProbabilisticMapIndependence implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java index fb54b1aa6e..2457cf2dd3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java @@ -48,7 +48,7 @@ * Implements a conservative version of PC, in which the Markov condition is assumed but faithfulness is tested * locally. * - * @author Joseph Ramsey (this version). + * @author josephramsey (this version). */ public final class SampleVcpc implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java index 449dd6faf7..b547bc2d29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java @@ -48,7 +48,7 @@ * Implements a conservative version of PC, in which the Markov condition is assumed but faithfulness is tested * locally. * - * @author Joseph Ramsey (this version). + * @author josephramsey (this version). */ public final class SampleVcpcFast implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java index f6dc59f32b..58e1ad5b00 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SemBicScoreDeterministic.java @@ -37,7 +37,7 @@ /** * Implements the continuous BIC score for FGES. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemBicScoreDeterministic implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java index fc57fcb448..087b879fbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcFas.java @@ -38,7 +38,7 @@ * search is different for different algorithm, depending on the assumptions of the algorithm. A mapping from {x, y} to * S({x, y}) is returned for edges x *-* y that have been removed. * - * @author Joseph Ramsey. + * @author josephramsey. */ public class VcFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java index a025aba063..7482a866af 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java @@ -41,7 +41,7 @@ * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested * locally. * - * @author Joseph Ramsey (this version). + * @author josephramsey (this version). */ public final class VcPc implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java index ecbc3802c1..d5de714f1c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java @@ -39,7 +39,7 @@ * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested * locally. * - * @author Joseph Ramsey (this version). + * @author josephramsey (this version). */ public final class VcPcAlt implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java index f81bec77ca..07b169ec0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java @@ -41,7 +41,7 @@ * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested * locally. * - * @author Joseph Ramsey (this version). + * @author josephramsey (this version). */ public final class VcPcFast implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java index 12472dbbf1..598a2fbec7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Washdown.java @@ -59,7 +59,7 @@ * Clearly we can use any goodness of fit test we think is appropriate - * the default being the chi-square test. * - * @author Joseph Ramsey + * @author josephramsey */ public class Washdown { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java index cf2354760f..714b920a29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java @@ -46,7 +46,7 @@ * require repeated estimation of DAG models over the same variables. * Assumes all variables are measured. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DagScorer implements TetradSerializable, Scorer { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemEstimator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemEstimator.java index 5a881b62b9..c10bbdd7e6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemEstimator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemEstimator.java @@ -44,7 +44,7 @@ /** * Estimates a Generalized SEM I'M given a Generalized SEM PM and a data set. * - * @author Joseph Ramsey + * @author josephramsey */ public class GeneralizedSemEstimator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java index c7087dec0b..32beada7c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java @@ -51,7 +51,7 @@ * model allows arbitrary equations for variables. This instantiated model * gives values for all of the parameters of the parameterized model. * - * @author Joseph Ramsey + * @author josephramsey */ public class GeneralizedSemIm implements Im, Simulator { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java index a6abf64021..8c6f447743 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java @@ -38,7 +38,7 @@ * equations of the model with parameters represented symbolically (i.e. * no values for parameters). * - * @author Joseph Ramsey + * @author josephramsey */ public final class GeneralizedSemPm implements Pm, TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ISemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ISemIm.java index bcd24dea3c..a4215439a9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ISemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ISemIm.java @@ -30,7 +30,7 @@ /** * An interface for SemIM's; see implementations. * - * @author Joseph Ramsey + * @author josephramsey */ public interface ISemIm extends Simulator { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java index ed7458b84a..ba3c2a51ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java @@ -47,7 +47,7 @@ * Stores a SEM model, pared down, for purposes of simulating data sets with * large numbers of variables and sample sizes. * - * @author Joseph Ramsey + * @author josephramsey */ public final class LargeScaleSimulation { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamComparison.java index 5794806e4d..fe3565d7ad 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamComparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamComparison.java @@ -25,7 +25,7 @@ * A typesafe enum of the types of the various comparisons parameter may have * with respect to one another for SEM estimation. * - * @author Joseph Ramsey + * @author josephramsey */ public class ParamComparison { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java index 98a1ee841c..bce31fa620 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java @@ -31,7 +31,7 @@ * model; VAR parmaeters are variances among the error terms; COVAR freeParameters * are (non-variance) covariances among the error terms. * - * @author Joseph Ramsey + * @author josephramsey */ public class ParamType implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java index b47a578a59..91ad8ad3b3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java @@ -36,7 +36,7 @@ * (COEF, COVAR), and the node(s) it is associated with. * * @author Don Crimbchin (djc2@andrew.cmu.edu) - * @author Joseph Ramsey + * @author josephramsey */ public final class Parameter implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java index bb3bca2d45..14846201d4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java @@ -28,7 +28,7 @@ * HashSets. The hashCode() method is overridden so that the hashcode of (a1, * b1) == the hashcode of (a2, b2) just in case a1 == a2 and b1 == b2. * - * @author Joseph Ramsey + * @author josephramsey */ public class ParameterPair implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Ricf.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Ricf.java index 8411cfc63d..59f81a19e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Ricf.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Ricf.java @@ -46,7 +46,7 @@ * class. The reason for reimplementing in this case is to take advantage of linear algebra optimizations in the COLT * library. * - * @author Joseph Ramsey + * @author josephramsey */ public class Ricf { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java index f38fddeb33..f5d2e12bf2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java @@ -40,7 +40,7 @@ * @author Frank Wimberly * @author Ricardo Silva * @author Don Crimbchin - * @author Joseph Ramsey + * @author josephramsey */ public final class SemEstimator implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java index d8a48379f0..de05c4a98a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java @@ -33,7 +33,7 @@ * Stores information for a SemIm about evidence we have for each variable as * well as whether each variable has been manipulated. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SemEvidence implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java index d7662d1911..5e37f6c1d5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java @@ -68,7 +68,7 @@ * * @author Frank Wimberly * @author Ricardo Silva - * @author Joseph Ramsey + * @author josephramsey */ public final class SemIm implements Im, ISemIm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java index b95f6bb205..96a918a4e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java @@ -33,7 +33,7 @@ * Stores information for a BayesIm about evidence we have for each variable as * well as whether each variable has been manipulated. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SemManipulation implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizer.java index 1626ee8e78..bac841b767 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizer.java @@ -27,7 +27,7 @@ * Interface for algorithm that optimize the fitting function of a SemIm model * by adjusting its freeParameters in search of a global maximum. * - * @author Joseph Ramsey + * @author josephramsey */ public interface SemOptimizer extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java index a9fadca9e8..2ba722cc2a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java @@ -38,7 +38,7 @@ * variables, SemOptimizerRegression should be more efficient. * * @author Ricardo Silva - * @author Joseph Ramsey Cleanup, modernization. + * @author josephramsey Cleanup, modernization. */ public class SemOptimizerEm implements SemOptimizer { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java index 7ebc58c267..487546221a 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java @@ -37,7 +37,7 @@ * Optimizes a SEM using Powell's method from the Apache library. * * @author Ricardo Silva - * @author Joseph Ramsey + * @author josephramsey */ public class SemOptimizerPowell implements SemOptimizer { static final long serialVersionUID = 23L; @@ -130,7 +130,7 @@ public int getNumRestarts() { * Wraps the SEM maximum likelihood fitting function for purposes of being * evaluated using the PAL ConjugateDirection optimizer. * - * @author Joseph Ramsey + * @author josephramsey */ static class FittingFunction implements MultivariateFunction { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java index 202e9b0ea3..1bc72fc203 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java @@ -30,7 +30,7 @@ /** * Optimizes a SEM using RICF (see that class). * - * @author Joseph Ramsey + * @author josephramsey */ public class SemOptimizerRicf implements SemOptimizer { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java index 76d02189d6..b9e6a24563 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java @@ -34,7 +34,7 @@ * Optimizes a SEM by randomly selecting points in cubes of decreasing size about * a given point. * - * @author Joseph Ramsey + * @author josephramsey */ public class SemOptimizerScattershot implements SemOptimizer { static final long serialVersionUID = 23L; @@ -266,7 +266,7 @@ private void randomPointAboutCenter(double[] pTemp, double[] fixedP, double widt /** * Evaluates a fitting function for an array of freeParameters. * - * @author Joseph Ramsey + * @author josephramsey */ interface FittingFunction { @@ -283,7 +283,7 @@ interface FittingFunction { * Wraps a Sem for purposes of calculating its fitting function for given * parameter values. * - * @author Joseph Ramsey + * @author josephramsey */ static class SemFittingFunction implements FittingFunction { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java index 4a201ff025..170d24e1e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java @@ -41,7 +41,7 @@ * serialization--e.g. java.rmu.MarshalledObject. * * @author Donald Crimbchin - * @author Joseph Ramsey + * @author josephramsey */ public final class SemPm implements Pm, TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java index 6cc6f435a4..366e0abd69 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java @@ -39,7 +39,7 @@ * saying that all categories for that variable are allowed, so the proposition * by default allows all categories for all variables--i.e. it is a tautology. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SemProposition implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java index fdc892527f..517677f38d 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java @@ -231,7 +231,7 @@ private double secondPartialDerivative(FittingFunction f, int i, int j, /** * Evaluates a fitting function for an array of freeParameters. * - * @author Joseph Ramsey + * @author josephramsey */ interface FittingFunction { @@ -251,7 +251,7 @@ interface FittingFunction { * Wraps a Sem for purposes of calculating its fitting function for given * parameter values. * - * @author Joseph Ramsey + * @author josephramsey */ static class SemFittingFunction implements FittingFunction { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java index 7a2a37bb97..bbb7135e17 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java @@ -40,7 +40,7 @@ * in the Bayes net, possibly with additional information about which variables * in the Bayes net have been manipulated. * - * @author Joseph Ramsey + * @author josephramsey * @see edu.cmu.tetrad.bayes.Evidence * @see edu.cmu.tetrad.bayes.Proposition * @see edu.cmu.tetrad.bayes.Manipulation diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java index db98b12a5f..2b6d6eb703 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java @@ -747,7 +747,7 @@ public SemPm getSemPm() { * Stores a coefficient range--i.e. the edge and coefficient value for which the range is needed, * plus the low and high ends of the range to which the coefficient value may be adjusted. * - * @author Joseph Ramsey + * @author josephramsey */ public static final class ParameterRange implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/TemplateExpander.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/TemplateExpander.java index 0aff8b2744..4381b12f84 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/TemplateExpander.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/TemplateExpander.java @@ -36,7 +36,7 @@ * expanded template may not be parseable. If it is not, the original template was ill-formedm, and * the expansion should be disgarded. * - * @author Joseph Ramsey + * @author josephramsey */ public class TemplateExpander { private static final TemplateExpander INSTANCE = new TemplateExpander(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/CouldNotCreateModelException.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/CouldNotCreateModelException.java index 25bfe72443..8f84119f89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/CouldNotCreateModelException.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/CouldNotCreateModelException.java @@ -26,7 +26,7 @@ * Indicates that a model could not be created. As to which model it was, call * the getModelClass() method. * - * @author Joseph Ramsey + * @author josephramsey */ public class CouldNotCreateModelException extends Exception { private final Class modelClass; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Executable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Executable.java index 9f21e7f12f..8959130ee5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Executable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Executable.java @@ -25,7 +25,7 @@ /** * Interface indicating that a class can be executed as an algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public interface Executable { @SuppressWarnings("UnusedDeclaration") diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ExecutionRestarter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ExecutionRestarter.java index 0b718885c4..9881eaec90 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ExecutionRestarter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ExecutionRestarter.java @@ -27,7 +27,7 @@ * Interface indicating that a parameter object can and should be reinitialized * at each new execution in a simulation edu.cmu.tetrad.study. * - * @author Joseph Ramsey + * @author josephramsey * @see SimulationStudy */ public interface ExecutionRestarter extends TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ModificationRegistery.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ModificationRegistery.java index 6996ce449c..3645827250 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ModificationRegistery.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ModificationRegistery.java @@ -34,7 +34,7 @@ * have been made that will require models downstream to be reconstructed. * * @author William Taysom - * @author Joseph Ramsey + * @author josephramsey */ public final class ModificationRegistery { private static final Set EDITED_MODELS = new HashSet<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ParamsResettable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ParamsResettable.java index 7dc158b30b..94416b6f9c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ParamsResettable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/ParamsResettable.java @@ -25,7 +25,7 @@ /** * Tags models whose parameters can be reset. * - * @author Joseph Ramsey + * @author josephramsey */ public interface ParamsResettable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java index 80cfca51d5..92538ce7e9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java @@ -69,7 +69,7 @@ * various models that the Session can construct, this has to be tested * separately.> 0 * - * @author Joseph Ramsey + * @author josephramsey * @see SessionNode * @see SessionListener * @see SessionAdapter diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionAdapter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionAdapter.java index c72f61a1e8..53cff2d9cf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionAdapter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionAdapter.java @@ -25,7 +25,7 @@ /** * Basic implementation of SessionListener with empty methods. * - * @author Joseph Ramsey + * @author josephramsey */ public class SessionAdapter implements SessionListener { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionEvent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionEvent.java index dbbc1c50f6..b9de670545 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionEvent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionEvent.java @@ -28,7 +28,7 @@ * been added or removed, an edge has been added or removed, a model has been * created or destroyed. * - * @author Joseph Ramsey + * @author josephramsey */ public class SessionEvent extends EventObject { public static final int NODE_ADDED = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionListener.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionListener.java index 6be5472fce..010f6a67a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionListener.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionListener.java @@ -27,7 +27,7 @@ * Listens for SessionEvents on a Session--nodes being added or removed, parents * being added or removed, models being created or destroyed. * - * @author Joseph Ramsey + * @author josephramsey */ public interface SessionListener extends EventListener { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionModel.java index 44e8076223..16bb646666 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionModel.java @@ -30,7 +30,7 @@ * test (C.equals(save(load(C))), and (2) that sample models from every * published version of Tetrad in which C has changed will load correctly. * - * @author Joseph Ramsey + * @author josephramsey */ public interface SessionModel extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java index e4416b6be6..eca9fcad38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java @@ -59,7 +59,7 @@ * This node keeps track of its parents and its children and keeps these two * sets of SessionNodes in sync.> 0 * - * @author Joseph Ramsey + * @author josephramsey * @see Session * @see SessionListener * @see SessionAdapter diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionSupport.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionSupport.java index c5db23290d..b326a111e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionSupport.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionSupport.java @@ -27,7 +27,7 @@ /** * Handles firing of SessionSupport events to listeners. * - * @author Joseph Ramsey + * @author josephramsey */ public class SessionSupport { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SimulationStudy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SimulationStudy.java index d911ddc5e6..ec34c5c2a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SimulationStudy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SimulationStudy.java @@ -32,7 +32,7 @@ * session graph in depth-first order and executes each node encountered a * specified number of times. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SimulationStudy { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java index 4f6993798e..64bf78313d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/reveal/TestRevealEvaluator.java @@ -29,7 +29,7 @@ * Test the Reveal evaluator. * * @author Frank Wimberly - * @author Joseph Ramsey (translation to unit test) + * @author josephramsey (translation to unit test) */ public class TestRevealEvaluator extends TestCase { private static final int ngenes = 6; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java index 795ecb4cd9..28d6baba3c 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java @@ -25,7 +25,7 @@ /** * Represents a graph that's output by a genetic search algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public interface OutputGraph { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/DisplayNameHandler.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/DisplayNameHandler.java index 1c72dcbe3b..4235d30ac9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/DisplayNameHandler.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/DisplayNameHandler.java @@ -27,7 +27,7 @@ * Translates display names of lagged variables (e.g. "V1:L1") into model names * (e.g. "V1:1") and vice-versa. * - * @author Joseph Ramsey + * @author josephramsey */ public final class DisplayNameHandler { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java index 2169885389..b64d5f9e01 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java @@ -30,7 +30,7 @@ * Stores the parameters needed to generate a new lag graph, whether randomized * or manually constructed. * - * @author Joseph Ramsey + * @author josephramsey */ public class ManualLagGraphParams implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java index a00ce2955f..d8300c3268 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java @@ -27,7 +27,7 @@ /** * Constructs as a randomized update workbench. * - * @author Joseph Ramsey + * @author josephramsey */ public class RandomActiveLagGraph extends ActiveLagGraph implements SessionModel { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java index 24ea69e281..001b3c7143 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java @@ -26,7 +26,7 @@ /** * Stores a file for reading in a lag graph from a file. * - * @author Joseph Ramsey + * @author josephramsey */ public class StoredLagGraphParams implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java index 917c39d64f..543366ced4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java @@ -35,7 +35,7 @@ * and to a random value chosen from a N(basal, initStDev) distribution * otherwise. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BasalInitializer implements Initializer { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java index e8c5d0173f..ba7961470d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java @@ -42,7 +42,7 @@ * >= 0, although of course lagged factors used for edge specifications must * have lags >= 1. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class BasicLagGraph implements LagGraph { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java index 59b174f709..42a254ad95 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java @@ -31,7 +31,7 @@ * Stores a boolean function from a set of boolean-valued parents to a single * boolean-valued column. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BooleanFunction implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java index 2537ffd773..6545543812 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java @@ -61,7 +61,7 @@ * the only condition being that the false value must be less than the true * value. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class BooleanGlassFunction implements UpdateFunction { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java index 2e5185f337..ae5fd14883 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java @@ -36,7 +36,7 @@ * modelled currently.) Causes of differentiation may be nutrition, temperature, * etc. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class DishModel implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java index 972afa40ce..0190bed0b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java @@ -29,7 +29,7 @@ /** * Implements the basic machinery used by all history objects. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class GeneHistory implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphInitializer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphInitializer.java index b0b8a8a191..3a1610cdeb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphInitializer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphInitializer.java @@ -26,7 +26,7 @@ * Instantiations of this interface know how to randomize lag graphs in * particular ways. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public interface GraphInitializer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphRandomizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphRandomizer.java index 3414c823bd..138883f6b3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphRandomizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GraphRandomizer.java @@ -27,7 +27,7 @@ * Instantiations of this interface know how to randomize update graphs in * particular ways. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public interface GraphRandomizer extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java index 8bac0b616d..9a5ee5171c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java @@ -36,7 +36,7 @@ * time to the next. However, for certain uses of lag graphs, the graph itself * may be assumed to be static, so this optimization is useful. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class IndexedConnectivity implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java index 5dc76bf2a3..f8f2cc1a03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java @@ -36,7 +36,7 @@ * next. However, for certain uses of lag graphs, the graph itself may be * assumed to be static, so this optimization is useful. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class IndexedLagGraph implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java index da51e521a5..86af808f8e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java @@ -30,7 +30,7 @@ * Holds an ordered pair (index, lag) to represent a causal parent of a factor, * where the factor at the given index is independently known. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class IndexedParent implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java index 38a5e8db11..9230a127f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java @@ -29,7 +29,7 @@ import java.util.SortedSet; /** - * @author Joseph Ramsey + * @author josephramsey */ public interface LagGraph extends TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java index 656a1c9cc0..8b923cc7e9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java @@ -29,7 +29,7 @@ /** * Identifies a particular factor (by name) at a particular lag (integer). * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class LaggedFactor implements Comparable, TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java index 575a28b087..b79e0708d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java @@ -32,7 +32,7 @@ *

Implements a linear update function, Gi.0 = L(Parents(G0.0)) + ei, where P * is a polynomial function and ei is a random noise term. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class LinearFunction implements UpdateFunction { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java index 23514fa4b2..575042217e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java @@ -32,7 +32,7 @@ * Implements a polynomial as a sum of a list of terms whose variables are * identified as integers in the set {0, 1, 2, ...}. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class Polynomial implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java index 765015bc3a..91028b3749 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java @@ -32,7 +32,7 @@ *

Implements a polynomial update function, Gi.0 = P(Parents(G0.0)) + ei, * where P is a polynomial function and ei is a random noise term. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class PolynomialFunction implements UpdateFunction { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java index 1554c7925f..ba4421dcf6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java @@ -36,7 +36,7 @@ * 1.7xyz^2 -> 1.7*(V0)(V1)(V2)(V2)

  • -5.0z^3y^2 -> -5.0*(V2)(V2)(V2)(V1)(V1) * * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class PolynomialTerm implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PreviousStepOnly.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PreviousStepOnly.java index 0ffd818c61..55acff9ce5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PreviousStepOnly.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PreviousStepOnly.java @@ -27,7 +27,7 @@ /** * Initializes a graph by adding the previous time step only of each variable. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class PreviousStepOnly implements GraphInitializer { public PreviousStepOnly() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/RandomDistribution.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/RandomDistribution.java index bae6244cea..732d3a133d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/RandomDistribution.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/RandomDistribution.java @@ -27,7 +27,7 @@ * A distribution from which noise values are drawn. Each call to nextRandom() * draws a new noise value from the distribution. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public interface RandomDistribution extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java index 83ef6ee549..d636cffd97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java @@ -41,7 +41,7 @@ * account of the fact that one edge has already been added in each case, so * that the total indegree for each factor is correctly distributed. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SimpleRandomizer implements GraphInitializer { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestBooleanFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestBooleanFunction.java index 2cbbb700b7..87f71a6c0c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestBooleanFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestBooleanFunction.java @@ -32,7 +32,7 @@ /** * Tests the BooleanFunction class. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestBooleanFunction extends TestCase { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedConnectivity.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedConnectivity.java index 760f0ef553..29197f8bf7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedConnectivity.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedConnectivity.java @@ -29,7 +29,7 @@ * Tests the IndexedConnectivity class by constructing graphs with randomly * chosen parameters and seeing if they have the required properties. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestIndexedConnectivity extends TestCase { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedLagGraph.java index 55cd6d5d0d..6012325d77 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestIndexedLagGraph.java @@ -29,7 +29,7 @@ * Tests the IndexedLagGraph class by constructing graphs with randomly chosen * parameters and seeing if they have the required properties. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestIndexedLagGraph extends TestCase { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomial.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomial.java index 33dd96f9f2..18124c99ce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomial.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomial.java @@ -31,7 +31,7 @@ /** * Tests the Polynomial class. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestPolynomial extends TestCase { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomialTerm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomialTerm.java index a52edfad93..47a13b1d97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomialTerm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestPolynomialTerm.java @@ -28,7 +28,7 @@ /** * Tests the PolynomialTerm class. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestPolynomialTerm extends TestCase { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestSimpleRandomizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestSimpleRandomizer.java index da6279ad27..4f4e969c5c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestSimpleRandomizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/TestSimpleRandomizer.java @@ -32,7 +32,7 @@ * Tests the SimpleRandomizer class by constructing graphs with randomly chosen * parameters and seeing if they have the required properties. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestSimpleRandomizer extends TestCase { LagGraph lagGraph = new BasicLagGraph(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/UpdateFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/UpdateFunction.java index 29f51838fe..c0683e7eab 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/UpdateFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/UpdateFunction.java @@ -38,7 +38,7 @@ * is no requirement that the function be checked against the graph explicitly * to make sure the graph is actually implemented. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public interface UpdateFunction extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java index 4451571680..6a48b08273 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simexp/LinearSimExp1.java @@ -34,7 +34,7 @@ /** * Implements a particular simulation for experimental purposes. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class LinearSimExp1 { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java index 5c033c5ea9..e04a260937 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java @@ -55,7 +55,7 @@ * see the TestMeasurementSimulator class. This is a JUnit test class that * contains several examples of code use.> 0 * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey * @see TestMeasurementSimulator */ public class MeasurementSimulator implements TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java index 2b0dd95f63..6c448fdf05 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/TestMeasurementSimulator.java @@ -35,7 +35,7 @@ * Tests the MeasurementSimulator class using diagnostics devised by Richard * Scheines. The diagnostics are described in the Javadocs, below. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TestMeasurementSimulator extends TestCase { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/HandleyConvert.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/HandleyConvert.java index 888a9c0da9..bff01b013c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/HandleyConvert.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/util/HandleyConvert.java @@ -37,7 +37,7 @@ * * and converts them into LagGraphs. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class HandleyConvert { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java index 7493841d72..0f523170b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java @@ -39,7 +39,7 @@ /** * Wraps the MeasurementSimulator class as an instantiated model. * - * @author Joseph Ramsey + * @author josephramsey */ public class BooleanGlassGeneIm implements SessionModel { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java index a2be25ce02..d3cd736784 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java @@ -30,7 +30,7 @@ * just presents the underlying workbench. There are no additional parameters to * the PM. * - * @author Joseph Ramsey + * @author josephramsey */ public class BooleanGlassGenePm extends GenePm implements SessionModel { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java index 3a8846d4a0..b85b5ae017 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java @@ -30,7 +30,7 @@ /** * Implements a parametric gene model. * - * @author Joseph Ramsey + * @author josephramsey */ public abstract class GenePm implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java index 91cb1d775a..51e4314541 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java @@ -34,7 +34,7 @@ /** * Wraps MeasurementSimulator so that it may be used as a parameter object. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class MeasurementSimulatorParams implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 34875a3b1f..188e92375a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -51,7 +51,7 @@ /** * Runs some basic performance tests of various algorithm. * - * @author Joseph Ramsey + * @author josephramsey */ public class PerformanceTests { private PrintStream out = System.out; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java index 7d438e9852..8c03438a81 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java @@ -46,7 +46,7 @@ /** * Contains some tests for Dan Malinsky, that might be of interest to others. * - * @author Joseph Ramsey. + * @author josephramsey. */ public class PerformanceTestsDan { private void testIdaOutputForDan() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ArrUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ArrUtils.java index 14db4be481..b11ad6c9c8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ArrUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ArrUtils.java @@ -27,7 +27,7 @@ /** * Some utilities for handling arrays. * - * @author Joseph Ramsey + * @author josephramsey */ final class ArrUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ChoiceGenerator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ChoiceGenerator.java index fd4c9e125a..10e744f7a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ChoiceGenerator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ChoiceGenerator.java @@ -39,7 +39,7 @@ * To see what this class does, try calling ChoiceGenerator.testPrint(5, 3), for * instance. * - * @author Joseph Ramsey + * @author josephramsey */ @SuppressWarnings("WeakerAccess") public final class ChoiceGenerator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CombinationGenerator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CombinationGenerator.java index 026db66a2e..1fbf58bf6c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CombinationGenerator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CombinationGenerator.java @@ -31,7 +31,7 @@ * by this class is an array x[] of b integers i, 0 <= i < a, such that x[j] < * x[j + 1] for each j from 0 to b - 1. * - * @author Joseph Ramsey + * @author josephramsey */ public final class CombinationGenerator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CutoffFinder.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CutoffFinder.java index e836a855b9..b2fbde566d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CutoffFinder.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/CutoffFinder.java @@ -26,7 +26,7 @@ * Provides a static method for finding the cutoff value for a symmetric * probability distribution function about the origin. * - * @author Joseph Ramsey + * @author josephramsey */ public class CutoffFinder { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Function.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Function.java index f6c40fc56e..b4d2e7ab15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Function.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Function.java @@ -26,7 +26,7 @@ * Interface for a single-argument, double-valued function that can be passed to * mathematical routines. (Apologies in advance to ML programmers.) * - * @author Joseph Ramsey + * @author josephramsey */ public interface Function { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Im.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Im.java index 99e8205f4a..3692210abd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Im.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Im.java @@ -24,7 +24,7 @@ /** * Tagging interface for instantiated models. * - * @author Joseph Ramsey + * @author josephramsey */ public interface Im extends TetradSerializable { long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java index 3015b9cba1..d2659f88b5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java @@ -23,7 +23,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey * Returns values of the given square matrix, where the indices are remapped via * the given indices array. If the supplied matrix is 6 x 6, for example, and * the indices set are [5 4 2 1], then getValue(1, 2) will return element [4][2] diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Integrator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Integrator.java index cda1b6cb0f..714db2a5f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Integrator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Integrator.java @@ -25,7 +25,7 @@ /** * Integrates under a function from one endpoint to another. * - * @author Joseph Ramsey + * @author josephramsey */ public class Integrator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JOptionUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JOptionUtils.java index fe634c0458..7512ff0292 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JOptionUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JOptionUtils.java @@ -27,7 +27,7 @@ /** * Stores some utility items for displaying JOptionPane messages. * - * @author Joseph Ramsey + * @author josephramsey */ public class JOptionUtils { private static JComponent COMPONENT; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LogUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LogUtils.java index 973fb18bf6..40692019c4 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LogUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/LogUtils.java @@ -32,7 +32,7 @@ * formatter that outputs the text of the logging messages only. To remove the * stream, call removeStream(stream). * - * @author Joseph Ramsey + * @author josephramsey */ @SuppressWarnings("UnusedDeclaration") public class LogUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MathUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MathUtils.java index b9d70cb899..a6f16e38ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MathUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MathUtils.java @@ -26,7 +26,7 @@ /** * Some extra mathematical functions not contained in org.apache.commons.math3.util.FastMath. * - * @author Joseph Ramsey + * @author josephramsey */ public class MathUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java index 8a8eb7ddec..9f7abea4e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java @@ -34,7 +34,7 @@ * this fixes is that a BlockRealMatrix cannot represent a matrix with zero * rows; this uses an Array2DRowRealMatrix to represent that case. * - * @author Joseph Ramsey + * @author josephramsey */ public class Matrix implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java index 1def73dc36..5a8a6ba5d0 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java @@ -42,7 +42,7 @@ * impliedCovar, SEMimpliedCovar. * * @author Tianjiao Chu - * @author Joseph Ramsey + * @author josephramsey * @author Kevin V. Bui */ public final class MatrixUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MultiDimIntTable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MultiDimIntTable.java index 602640e43e..91b28836c0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MultiDimIntTable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MultiDimIntTable.java @@ -32,7 +32,7 @@ * the dimensionality is set to null, the table cannot be used until a non-null * dimensionality is set.> 0 * - * @author Joseph Ramsey + * @author josephramsey */ public class MultiDimIntTable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NamingProtocol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NamingProtocol.java index d43a0f6fec..2492102afc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NamingProtocol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NamingProtocol.java @@ -25,7 +25,7 @@ * Specifies the protocol used in Tetrad for variable names. This protocol * should be used throughout Tetrad. * - * @author Joseph Ramsey + * @author josephramsey */ public class NamingProtocol { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NumberFormatUtil.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NumberFormatUtil.java index 0992e4a70e..cef6df3223 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NumberFormatUtil.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/NumberFormatUtil.java @@ -28,7 +28,7 @@ /** * Provides an application-wide "memory" of the number format to be used. * - * @author Joseph Ramsey + * @author josephramsey */ public class NumberFormatUtil { private static final NumberFormatUtil INSTANCE = new NumberFormatUtil(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java index d13da5a56c..ed3a3c98df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java @@ -30,7 +30,7 @@ * true partial correlation is equal to zero. Uses the equation (29.13.4) from * Cramer's _Mathematical Methods of Statistics_. * - * @author Joseph Ramsey + * @author josephramsey */ public class PartialCorrelationPdf implements Function, TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PermutationGenerator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PermutationGenerator.java index 3e0a5fa76e..e20293641a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PermutationGenerator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PermutationGenerator.java @@ -37,7 +37,7 @@ * To see what this class does, try calling PermutationGenerator.testPrint(5), * for instance. * - * @author Joseph Ramsey + * @author josephramsey */ public final class PermutationGenerator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Pm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Pm.java index 34fd9bb081..5a4f69a6ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Pm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Pm.java @@ -24,7 +24,7 @@ /** * Tagging interface for parametric models. * - * @author Joseph Ramsey + * @author josephramsey */ public interface Pm { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Point.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Point.java index 705b72c2e4..34709c856f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Point.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Point.java @@ -27,7 +27,7 @@ /** * Implements an n-dimensional point. * - * @author Joseph Ramsey + * @author josephramsey */ public class Point implements Comparable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java index 6102545587..cd28849e8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java @@ -25,7 +25,7 @@ /** * Stores a (x, y) point without having to use awt classes. Immutable. * - * @author Joseph Ramsey + * @author josephramsey */ public class PointXy implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RandomUtil.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RandomUtil.java index 85f18c3e5c..197a52e63d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RandomUtil.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RandomUtil.java @@ -41,7 +41,7 @@ *

    * To see what distributions are currently supported, look at the methods of the class. These many change over time. * - * @author Joseph Ramsey + * @author josephramsey */ public class RandomUtil { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RocCalculator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RocCalculator.java index 86c49b34cd..4eb5330c49 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RocCalculator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/RocCalculator.java @@ -31,7 +31,7 @@ * Calculates a ROC curve and AUC (area under curve) for a list of scored cases * whose inclusion in category C is known. * - * @author Joseph Ramsey and Frank Wimberly + * @author josephramsey and Frank Wimberly */ public class RocCalculator { public static final int ASCENDING = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SelectionGenerator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SelectionGenerator.java index 974463cf8b..9da76c6872 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SelectionGenerator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SelectionGenerator.java @@ -32,7 +32,7 @@ * To see what this class does, try calling SelectionGenerator.testPrint(5, 3), for * instance. * - * @author Joseph Ramsey + * @author josephramsey */ @SuppressWarnings("WeakerAccess") public final class SelectionGenerator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java index 9829e2099f..3c43de910d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java @@ -49,7 +49,7 @@ * to the the expiration date. Commercial (for profit) use requires written * permission." * - * @author Joseph Ramsey + * @author josephramsey */ public final class StatUtils { private static final double logCoshExp = StatUtils.logCoshExp(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SublistGenerator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SublistGenerator.java index 5dab1d92c5..d3202d59b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SublistGenerator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/SublistGenerator.java @@ -40,7 +40,7 @@ * To see what this class does, try calling ChoiceGenerator.testPrint(5, 3), for * instance. * - * @author Joseph Ramsey + * @author josephramsey */ public final class SublistGenerator { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TaskManager.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TaskManager.java index 1e94617084..4a97199271 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TaskManager.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TaskManager.java @@ -4,7 +4,7 @@ * This cancels all processes that check the TaskManager.getInstance().isCanceled() * method. * - * @author Joseph Ramsey + * @author josephramsey */ public class TaskManager { private static final TaskManager instance = new TaskManager(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java index 4a4405bc14..db71e2b1c5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java @@ -51,7 +51,7 @@ *

    *

    See TestSerialization and TestSerializiableUtils.> 0 * - * @author Joseph Ramsey + * @author josephramsey */ public interface TetradSerializable extends Serializable { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableExcluded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableExcluded.java index 3848f067d6..9bb8154437 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableExcluded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableExcluded.java @@ -31,7 +31,7 @@ * of those interfaces are not actually serialized.> 0 *

    See TestSerialization and TestSerializiableUtils.> 0 * - * @author Joseph Ramsey + * @author josephramsey */ public interface TetradSerializableExcluded extends Serializable { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java index ad9ac580ae..c1caa2fd7e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java @@ -47,7 +47,7 @@ * Contains methods used by TestSerialization to ensure that previous "stable" * versions of Tetrad will by loadable by later "stable" versions of Tetrad. * - * @author Joseph Ramsey + * @author josephramsey * @see #safelySerializableTypes */ public class TetradSerializableUtils { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TextTable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TextTable.java index ca9443c82c..4431eef624 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TextTable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TextTable.java @@ -26,7 +26,7 @@ * columns either left justified or right justified, with a given number of * spaces between columns. * - * @author Joseph Ramsey + * @author josephramsey */ public class TextTable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Unmarshallable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Unmarshallable.java index 18f949538c..da14a1367f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Unmarshallable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Unmarshallable.java @@ -26,7 +26,7 @@ /** *

    Interface to tag classes that should not be cloned by marshalling.> 0 * - * @author Joseph Ramsey + * @author josephramsey */ public interface Unmarshallable extends Serializable { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java index 4381a14e70..fe3d08da26 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java @@ -32,7 +32,7 @@ * where "a" is the major version, "b" is the minor version, "c" is the minor * subversion, and "d" is the incremental release number for subversions. * - * @author Joseph Ramsey + * @author josephramsey */ @SuppressWarnings("RedundantIfStatement") public class Version implements TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java index 48d032da81..ff6117ac95 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java @@ -27,7 +27,7 @@ * Implements a Beta distribution for purposes of drawing random numbers. * The parameters are alpha and beta. See Wikipedia. * - * @author Joseph Ramsey + * @author josephramsey */ public class Beta implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java index 4208e31fc4..13583534cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java @@ -31,7 +31,7 @@ * Methods are provided to allow parameters to be manipulated in an interface. * See Wikipedia. * - * @author Joseph Ramsey + * @author josephramsey */ public class ChiSquare implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java index 5cd476c628..6d69152193 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java @@ -31,7 +31,7 @@ * A value of n is returned if a number drawn uniformly from [0, 1] is less * than the n + 1th p value. * - * @author Joseph Ramsey + * @author josephramsey */ public class Discrete implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java index f8c6814ca2..4aab29244e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java @@ -29,7 +29,7 @@ * interface. A single random number generator is used throughout Tetrad * to ensure randomness. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ @SuppressWarnings("UnusedDeclaration") public interface Distribution extends TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java index e2b868635d..813381fa21 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java @@ -27,7 +27,7 @@ * Wraps a chi square distribution for purposes of drawing random samples. * Methods are provided to allow parameters to be manipulated in an interface. * - * @author Joseph Ramsey + * @author josephramsey */ public class Exponential implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java index 4c3e919c56..daa557b4b8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java @@ -27,7 +27,7 @@ * Wraps a chi square distribution for purposes of drawing random samples. * Methods are provided to allow parameters to be manipulated in an interface. * - * @author Joseph Ramsey + * @author josephramsey */ public class Gamma implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java index 51621c7495..d31b4d0ed6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java @@ -27,7 +27,7 @@ /** * Represents a lognormal distribution for purposes of sampling. * - * @author Joseph Ramsey + * @author josephramsey */ public class LogNormal implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java index d6636c9227..0747cbf615 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java @@ -27,7 +27,7 @@ * Wraps a chi square distribution for purposes of drawing random samples. * Methods are provided to allow parameters to be manipulated in an interface. * - * @author Joseph Ramsey + * @author josephramsey */ public class MixtureOfGaussians implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java index 3a809d826c..1dd7074822 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java @@ -32,7 +32,7 @@ * A normal distribution that allows its parameters to be set and allows * random sampling. The parameters are 0 = mean, 1 = standard deviation. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class Normal implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java index 0ccb602ca5..06bb9e3e9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java @@ -27,7 +27,7 @@ * Wraps a chi square distribution for purposes of drawing random samples. * Methods are provided to allow parameters to be manipulated in an interface. * - * @author Joseph Ramsey + * @author josephramsey */ public class Poisson implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java index 4974fda85c..f3d5837313 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java @@ -25,7 +25,7 @@ * A pretend distribution that always returns the given value when * nextRandom() is called. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class SingleValue implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java index fd450b32f6..f1f859f093 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java @@ -32,7 +32,7 @@ * Wraps a chi square distribution for purposes of drawing random samples. * Methods are provided to allow parameters to be manipulated in an interface. * - * @author Joseph Ramsey + * @author josephramsey */ @SuppressWarnings("WeakerAccess") public class Split implements Distribution { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java index 1b2365c911..8bf5c16480 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java @@ -32,7 +32,7 @@ * A normal distribution that allows its parameters to be set and allows * random sampling. The parameters are 0 = mean, 1 = standard deviation. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class TruncatedNormal implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java index bffa2b17a6..3f3c74f38a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java @@ -32,7 +32,7 @@ * For given a, b (a < b), returns a point chosen uniformly from [a, b]. The * parameters are 0 = a, 1 = b. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public class Uniform implements Distribution { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java index d22814e662..c346d35194 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java @@ -47,7 +47,7 @@ * This logisticRegression makes multiple assumptions: 1. IIA 2. Large sample size (multiple regressions needed on subsets of * sample) * - * @author Joseph Ramsey + * @author josephramsey * @author Augustus Mayo. */ public class IndTestMultinomialLogisticRegressionWald implements IndependenceTest { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java index baa5e7c6da..464a2b1e0c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java @@ -37,7 +37,7 @@ import java.util.Set; /** - * @author Joseph Ramsey + * @author josephramsey */ public final class ExploreAutisticsNeurotypicals { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAndersonDarling.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAndersonDarling.java index 56dd25a902..ba60219689 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAndersonDarling.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAndersonDarling.java @@ -34,7 +34,7 @@ /** * Tests to make sure the DelimiterType enumeration hasn't been tampered with. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestAndersonDarling { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesDiscreteBicScorer.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesDiscreteBicScorer.java index 9c29b08356..7fa2b07121 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesDiscreteBicScorer.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesDiscreteBicScorer.java @@ -39,7 +39,7 @@ import static org.junit.Assert.assertEquals; /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestBayesDiscreteBicScorer { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesIm.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesIm.java index 09f1470b03..b2bb4c6315 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesIm.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesIm.java @@ -33,7 +33,7 @@ /** * Tests the BayesIm. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestBayesIm { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesXml.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesXml.java index d974c5c3c3..592b9ed872 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesXml.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBayesXml.java @@ -38,7 +38,7 @@ /** * Tests the Bayes XML parsing/rendering. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestBayesXml { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBoxDataSet.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBoxDataSet.java index 0a5edc3324..c9b75e277f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBoxDataSet.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestBoxDataSet.java @@ -40,7 +40,7 @@ * to be made from Column-based DataSets to COLT-matrix-based datasets. All * tests should work for both. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestBoxDataSet { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCellProbabilities.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCellProbabilities.java index 00a6f1babd..66aa240bae 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCellProbabilities.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCellProbabilities.java @@ -39,7 +39,7 @@ import static junit.framework.TestCase.assertEquals; /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestCellProbabilities { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestChoiceGenerator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestChoiceGenerator.java index 1dfd540ead..f6395c77bc 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestChoiceGenerator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestChoiceGenerator.java @@ -34,7 +34,7 @@ * Implements basic tests of the choice generator. The choice generator should visit every * choice in a choose b exactly once, and then return null. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestChoiceGenerator { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java index e9b421f311..a8c8d3be0e 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCopy.java @@ -35,7 +35,7 @@ /** * Tests to make sure the DelimiterType enumeration hasn't been tampered with. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestCopy { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCovarianceMatrix.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCovarianceMatrix.java index 0fd9a5f144..86dc8e6d64 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCovarianceMatrix.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCovarianceMatrix.java @@ -34,7 +34,7 @@ /** * Tests CovarianceMatrix. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class TestCovarianceMatrix { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java index 045a00fa30..2ffa23f01e 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCpc.java @@ -42,7 +42,7 @@ /** * Tests the BooleanFunction class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestCpc { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCptInvariantUpdater.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCptInvariantUpdater.java index e8ca49b140..67343be4fb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCptInvariantUpdater.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestCptInvariantUpdater.java @@ -34,7 +34,7 @@ /** * Tests the BayesUpdqater * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestCptInvariantUpdater { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDag.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDag.java index 3d1987b5f5..8c9939a278 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDag.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDag.java @@ -37,7 +37,7 @@ * Tests the functions of EndpointMatrixGraph and EdgeListGraph through the * Graph interface. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestDag { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java index c4a01d27cb..50ed5fb8df 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java @@ -35,7 +35,7 @@ import static org.junit.Assert.fail; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestDagInPatternIterator { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagScorer.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagScorer.java index f1fe8177be..d8fbb6b9f8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagScorer.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagScorer.java @@ -38,7 +38,7 @@ * Tests the MeasurementSimulator class using diagnostics devised by Richard * Scheines. The diagnostics are described in the Javadocs, below. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestDagScorer { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDataSetCellProbs.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDataSetCellProbs.java index b4ebf8cbf6..3542df3d69 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDataSetCellProbs.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDataSetCellProbs.java @@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals; /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestDataSetCellProbs { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterTokenizer.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterTokenizer.java index d2953d7b22..9b21093556 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterTokenizer.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterTokenizer.java @@ -30,7 +30,7 @@ /** * Tests to make sure the DelimiterType enumeration hasn't been tampered with. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestDelimiterTokenizer { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterType.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterType.java index 30a4c62629..7a79740670 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterType.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDelimiterType.java @@ -29,7 +29,7 @@ /** * Tests to make sure the DelimiterType enumeration hasn't been tampered with. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestDelimiterType { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java index 9118a5f6a7..94dab7fa2a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java @@ -44,7 +44,7 @@ /** * Tests the BooleanFunction class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestDeltaSextadTest { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java index ff22617ecb..9aaadca69c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaTetradTest.java @@ -43,7 +43,7 @@ /** * TODO: Some of these tests give answers different from Bollen now. Why? * - * @author Joseph Ramsey + * @author josephramsey */ public class TestDeltaTetradTest { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscreteProbs.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscreteProbs.java index 89f22becb1..d805eca4e7 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscreteProbs.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscreteProbs.java @@ -37,7 +37,7 @@ /** * Tests the BayesIm. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestDiscreteProbs extends TestCase { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscretizer.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscretizer.java index c284c05bbb..91c4550573 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscretizer.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDiscretizer.java @@ -42,7 +42,7 @@ /** * Tests the column discretizer. * - * @author Joseph Ramsey jdramsey@andrew.cmu.edu + * @author josephramsey */ public final class TestDiscretizer { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java index f319d43414..8c397f57c4 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java @@ -37,7 +37,7 @@ * Tests the functions of EndpointMatrixGraph and EdgeListGraph through the * Graph interface. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestEdgeListGraph { private Node x1, x2, x3, x4, x5; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestExpressionParser.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestExpressionParser.java index f59d065496..2e6a995d91 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestExpressionParser.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestExpressionParser.java @@ -37,7 +37,7 @@ /** * Tests the PC search. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestExpressionParser { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java index 039ba1a0bd..65af05ac37 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFas.java @@ -38,7 +38,7 @@ import static org.junit.Assert.assertEquals; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestFas { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java index 0611bcad96..dcd26c4b1c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java @@ -50,7 +50,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestFci { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFdr.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFdr.java index 466fa03279..1884448b3c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFdr.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFdr.java @@ -33,7 +33,7 @@ /** * Implements some tests of the FDR (False Discovery Rate) test. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestFdr { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index a044e25282..b6c25cb9ef 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java @@ -64,7 +64,7 @@ import static org.junit.Assert.assertTrue; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestFges { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFgesFa.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFgesFa.java index 009a166ae2..d550b781e1 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFgesFa.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFgesFa.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.util.Params; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestFgesFa { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java index a1a16231aa..7051019a93 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java @@ -31,7 +31,7 @@ /** * Tests to make sure the Fruchterman Reingold layout will run. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestFruchtermanReingoldLayout { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java index 165116502e..ff41042af4 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java @@ -55,7 +55,7 @@ import static org.junit.Assert.assertTrue; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestGFci { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralizedSem.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralizedSem.java index b29202b8d9..cfa4c04783 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralizedSem.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralizedSem.java @@ -40,7 +40,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ @Ignore public class TestGeneralizedSem { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java index 5e51ad4ecf..eddb7a3cc9 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java @@ -36,7 +36,7 @@ * Tests the functions of EndpointMatrixGraph and EdgeListGraph through the * Graph interface. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestGraph { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphConverter.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphConverter.java index 82a62e2a14..b692d858bb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphConverter.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphConverter.java @@ -29,7 +29,7 @@ /** * Tests the GraphConverter class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestGraphConverter { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphUtils.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphUtils.java index 1d5cb6bd21..37bd28bd72 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphUtils.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraphUtils.java @@ -35,7 +35,7 @@ import static org.junit.Assert.fail; /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestGraphUtils { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 0b82e1e872..d9a8f5df67 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -80,7 +80,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ @SuppressWarnings("ALL") public final class TestGrasp { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java index b716dd097c..5ca4690be0 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java @@ -45,7 +45,7 @@ /** * Tests the Knowledge class. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestHistogram { private Knowledge knowledge; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java index 3ce05938fa..7f7dd93efc 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherGeneralizedInverse.java @@ -36,7 +36,7 @@ /** * Tests the IndTestTimeSeries class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestIndTestFisherGeneralizedInverse { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java index bbadec7f52..8c2d95c95e 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestFisherZ.java @@ -42,7 +42,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestIndTestFisherZ { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java index 5508231abb..b398e8e2e4 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java @@ -39,7 +39,7 @@ /** * Tests the IndTestTimeSeries class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestIndTestGSquare { private final String[] discreteFiles = { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java index 5749b13a9a..b841d57810 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestWaldLr.java @@ -45,7 +45,7 @@ /** * Tests the IndTestTimeSeries class. * - * @author Joseph Ramsey + * @author josephramsey */ @Ignore public class TestIndTestWaldLr { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndependenceFact.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndependenceFact.java index 153bb71aa5..a9c22f6f61 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndependenceFact.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndependenceFact.java @@ -34,7 +34,7 @@ /** * Implements some tests of the FDR (False Discovery Rate) test. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestIndependenceFact { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKnowledge.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKnowledge.java index 20d2d84979..eaeaa4eb44 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKnowledge.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKnowledge.java @@ -39,7 +39,7 @@ /** * Tests to make sure the DelimiterType enumeration hasn't been tampered with. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestKnowledge { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLargeSemSimulator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLargeSemSimulator.java index 666e0c21ba..30561bcd1d 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLargeSemSimulator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLargeSemSimulator.java @@ -38,7 +38,7 @@ * Tests the MeasurementSimulator class using diagnostics devised by Richard * Scheines. The diagnostics are described in the Javadocs, below. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestLargeSemSimulator { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 96d2222107..75acd0baf8 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -41,7 +41,7 @@ import static org.junit.Assert.assertEquals; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestLing { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java index 6839bd8293..01e01a55a2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java @@ -42,7 +42,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestLingamPattern { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMathUtils.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMathUtils.java index a55df54aee..3362150f8d 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMathUtils.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMathUtils.java @@ -32,7 +32,7 @@ /** * Tests some extra mathematical functions not contained in org.apache.commons.math3.util.FastMath. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestMathUtils { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrix.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrix.java index 9705f485bb..ecaf5392e2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrix.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrix.java @@ -29,7 +29,7 @@ /** * Tests basic functionality of the tetrad.util.Point class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestMatrix { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrixUtils.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrixUtils.java index 00b88f33ff..05d0319018 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrixUtils.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMatrixUtils.java @@ -41,7 +41,7 @@ /** * Tests the MatrixUtils class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestMatrixUtils { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index dbfdb4f97a..a775cd6446 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -51,7 +51,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ @Ignore public class TestMimbuild { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java index c8f4361098..36b7257efb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java @@ -51,7 +51,7 @@ /** * Tests the PC search. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestPc { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java index 540265ee7e..7df2f70c88 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcStableMax.java @@ -40,7 +40,7 @@ /** * Tests the PC search. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestPcStableMax { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java index c57fa38b55..75f8c952cf 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPcd.java @@ -35,7 +35,7 @@ /** * Tests the BooleanFunction class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestPcd { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPoint.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPoint.java index a59b56537d..3b4f65f346 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPoint.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPoint.java @@ -30,7 +30,7 @@ /** * Tests basic functionality of the tetrad.util.Point class. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestPoint { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java index 5a1f70b748..5f1e402049 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPurify.java @@ -39,7 +39,7 @@ import static org.junit.Assert.assertEquals; /** - * @author Joseph Ramsey + * @author josephramsey */ @Ignore public class TestPurify { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRegression.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRegression.java index ecfcc8568c..ca9662fa3d 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRegression.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRegression.java @@ -42,7 +42,7 @@ * model as well as a correlation linear regression model. (Space for more * in the future.) * - * @author Joseph Ramsey + * @author josephramsey */ public class TestRegression { DataSet data; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java index 5405ca8bfa..751c6d5ff5 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java @@ -39,7 +39,7 @@ import static org.junit.Assert.assertTrue; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestRicf { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRowSummingUpdater.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRowSummingUpdater.java index 3f6761fcdd..fd9ec8294f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRowSummingUpdater.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRowSummingUpdater.java @@ -33,7 +33,7 @@ /** * Tests the BayesUpdqater * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestRowSummingUpdater { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java index 77d46638a3..05ad621e96 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSearchGraph.java @@ -45,7 +45,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestSearchGraph { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSem.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSem.java index 188ee05460..6c02f476c9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSem.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSem.java @@ -40,7 +40,7 @@ /** * Tests Sem. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSem { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEstimator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEstimator.java index 894dd19b6b..a1d2151614 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEstimator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEstimator.java @@ -35,7 +35,7 @@ * Tests the MeasurementSimulator class using diagnostics devised by Richard * Scheines. The diagnostics are described in the Javadocs, below. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSemEstimator { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEvidence.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEvidence.java index 505655aaa7..e849b71f6b 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEvidence.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemEvidence.java @@ -36,7 +36,7 @@ * Tests the MeasurementSimulator class using diagnostics devised by Richard * Scheines. The diagnostics are described in the Javadocs, below. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSemEvidence { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemGraph.java index aaac7402e3..a77d1f6144 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemGraph.java @@ -29,7 +29,7 @@ import junit.framework.TestSuite; /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestSemGraph extends TestCase { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemIm.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemIm.java index ad86e5e356..d59d9de37e 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemIm.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemIm.java @@ -40,7 +40,7 @@ * Tests the MeasurementSimulator class using diagnostics devised by Richard * Scheines. The diagnostics are described in the Javadocs, below. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSemIm { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemProposition.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemProposition.java index 567066d6cf..58d4f57907 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemProposition.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemProposition.java @@ -39,7 +39,7 @@ * Tests the MeasurementSimulator class using diagnostics devised by Richard * Scheines. The diagnostics are described in the Javadocs, below. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSemProposition { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemUpdater.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemUpdater.java index 5f8720e0c5..e92ad32411 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemUpdater.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemUpdater.java @@ -34,7 +34,7 @@ import java.util.List; /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestSemUpdater { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemXml.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemXml.java index 39dee289fa..0bea06ea6c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemXml.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSemXml.java @@ -44,7 +44,7 @@ /** * Tests the Bayes XML parsing/rendering. * - * @author Joseph Ramsey + * @author josephramsey */ public final class TestSemXml extends TestCase { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSerialization.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSerialization.java index 1808e40193..45285c1452 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSerialization.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSerialization.java @@ -114,7 +114,7 @@ * *

    Or Joshua Block, Effective Java.> 0 fd * - * @author Joseph Ramsey + * @author josephramsey * // * @see edu.cmu.tetradapp.util.TetradSerializableUtils */ public class TestSerialization { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSession.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSession.java index 2d00ba99ac..4a2ebbb772 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSession.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSession.java @@ -31,7 +31,7 @@ /** * Tests the basic functionality of the Session. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSession { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionEvent.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionEvent.java index 0ba3249a9f..ae4b8bab21 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionEvent.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionEvent.java @@ -32,7 +32,7 @@ * can be constructed properly and whether the information can be extracted from * them properly. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSessionEvent { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionNode.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionNode.java index a9cd1ac49f..3406d1b1d3 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionNode.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionNode.java @@ -47,7 +47,7 @@ * happens: (a) parents are added or removed; (b) models are created or * destroyed. The adding and removing of listeners must also be tested. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSessionNode { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionSupport.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionSupport.java index db2a93e5f3..c6d36d4088 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionSupport.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSessionSupport.java @@ -32,7 +32,7 @@ * add and remove listeners, construct SessionEvents, and fire the SessionEvents * correctly. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestSessionSupport { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java index 11b18d0672..fcbeaf8584 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java @@ -43,7 +43,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ public class TestStandardizedSem { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStatUtils.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStatUtils.java index 3f16bcf001..3680dd3a30 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStatUtils.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStatUtils.java @@ -47,7 +47,7 @@ /** * Tests basic functionality of the statistical utilities. * - * @author Joseph Ramsey + * @author josephramsey */ public class TestStatUtils { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestTimeLagGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestTimeLagGraph.java index 26ebc085f6..90a3a1dedd 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestTimeLagGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestTimeLagGraph.java @@ -31,7 +31,7 @@ /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestTimeLagGraph { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestUniformGraphGenerator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestUniformGraphGenerator.java index 9baee59a47..226556c89c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestUniformGraphGenerator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestUniformGraphGenerator.java @@ -34,7 +34,7 @@ import static org.junit.Assert.assertEquals; /** - * @author Joseph Ramsey + * @author josephramsey */ public final class TestUniformGraphGenerator { From 1237ffb67049347a07ea04c1d4651a0d67caee39 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 13:13:02 -0400 Subject: [PATCH 350/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Ida.java | 18 ++++++++++++++---- .../edu/cmu/tetrad/search/MimbuildTrek.java | 2 +- .../search/{ => work_in_progress}/Iamb.java | 3 ++- .../search/{ => work_in_progress}/IambnPc.java | 4 +++- .../{ => work_in_progress}/InterIamb.java | 3 ++- .../search/{ => work_in_progress}/Kpc.java | 13 ++++++++++--- .../tetrad/search/work_in_progress/Mmhc.java | 1 - .../search/{ => work_in_progress}/Mmmb.java | 3 ++- 8 files changed, 34 insertions(+), 13 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Iamb.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/IambnPc.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/InterIamb.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Kpc.java (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Mmmb.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index 528266e84b..6388b1a8ab 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -19,12 +19,20 @@ import static org.apache.commons.math3.util.FastMath.min; /** - *

    Implements the IDA algorithm

    + *

    Implements the IDA algorithm, as given in Maathuis et al. (2009) + * The reference is here:

    + * *

    Maathuis, Marloes H., Markus Kalisch, and Peter Bühlmann. * "Estimating high-dimensional intervention effects from observational data." * The Annals of Statistics 37.6A (2009): 3133-3164.

    * + *

    The IDA algorithm seeks to give a list of possible parents + * of a given variable Y and their corresponding lower-bounded effects on + * Y.

    + * * @author josephramsey + * @see Cstar + * @see NodeEffects */ public class Ida { private final DataSet dataSet; @@ -60,8 +68,9 @@ public Ida(DataSet dataSet, Graph cpdag, List possibleCauses) { * Returns the minimum effects of X on Y for X in V \ {Y}, sorted downward by minimum effect * * @param y The child variable. - * @return Two sorted lists, one of nodes, the other of corresponding minimum effects, sorted downward by - * minimum effect size. + * @return Two sorted lists, one of possible parents, the other of corresponding minimum effects, + * sorted downward by minimum effect size. + * @see Ida */ public NodeEffects getSortedMinEffects(Node y) { Map allEffects = calculateMinimumEffectsOnY(y); @@ -81,7 +90,8 @@ public NodeEffects getSortedMinEffects(Node y) { } /** - * A list of nodes and corresponding minimum effects. + * Gives a list of nodes (parents or children) and corresponding minimum effects + * for the IDA algorithm. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index e6bf5a8bc0..2e51e7c6a9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -42,7 +42,7 @@ import java.util.List; /** - * An implemetation of Mimbuild based on the treks and ranks. + * Implments Mimbuild using the theory of treks and ranks. * * @author adambrodie */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Iamb.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Iamb.java index 42e1fc8108..5fa48e9191 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Iamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Iamb.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IMbSearch; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IambnPc.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IambnPc.java index e4e3077ea3..674c34cc06 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IambnPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IambnPc.java @@ -19,10 +19,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IMbSearch; +import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.MbUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InterIamb.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InterIamb.java index ca07f59ce5..02f98dad7e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/InterIamb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InterIamb.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IMbSearch; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Kpc.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Kpc.java index 5b6baf79d0..d98b1eb232 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Kpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Kpc.java @@ -19,11 +19,13 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.Fas; +import edu.cmu.tetrad.search.IGraphSearch; import edu.cmu.tetrad.search.test.IndTestHsic; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; @@ -39,8 +41,13 @@ import java.util.Set; /** - * Kernelized PC algorithm. This is the same as the PC class, the nonparametric kernel-based HSIC test is used for - * independence testing and the parameters for this test can be set directly when Kpc is initialized. + *

    Kernelized PC algorithm. This is the same as the PC class, the nonparametric + * kernel-based HSIC test is used for independence testing and the parameters for + * this test can be set directly when Kpc is initialized.

    + * + *

    Moving this to the work_in_progress package because it has not been tested + * in a very long time, and there is another option available that has been + * tested, namely, to run PC using the KCI test due to Kun Zhang.

    * * @author Robert Tillman. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java index ee9f4ea8fe..2fe38b35be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmhc.java @@ -27,7 +27,6 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IGraphSearch; -import edu.cmu.tetrad.search.Mmmb; import edu.cmu.tetrad.search.utils.FgesOrienter; import edu.cmu.tetrad.search.test.IndependenceTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmmb.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmmb.java index 6f749557eb..94c4fcd872 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mmmb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Mmmb.java @@ -19,9 +19,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.IMbSearch; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.MillisecondTimes; From 32aad3c2fb3aaef431f0ebc25df37d4d94e5144f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 13:13:29 -0400 Subject: [PATCH 351/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index 6388b1a8ab..62891a9a0f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -145,10 +145,6 @@ public double trueEffect(Node x, Node y, Graph trueDag) { trueDag = GraphUtils.replaceNodes(trueDag, this.dataSet.getVariables()); - if (trueDag == null) { - throw new NullPointerException("True graph is null."); - } - List regressors = new ArrayList<>(); regressors.add(x); regressors.addAll(trueDag.getParents(x)); From 788e159cad415599005c3c2acfd2f9ef810ff6a6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 13:19:19 -0400 Subject: [PATCH 352/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/Lingam.java | 5 +++- .../{LingamPattern.java => PcLingam.java} | 29 +++++++++++++------ .../cmu/tetrad/test/TestLingamPattern.java | 4 +-- 3 files changed, 26 insertions(+), 12 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{LingamPattern.java => PcLingam.java} (91%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 95f71e20ab..4609cffca5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -27,7 +27,8 @@ /** *

    Implements an interpretation of the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, - * and Kerminen, A linear nongaussian acyclic model for causal discovery, JMLR 7 (2006).

    + * and Kerminen, a linear nongaussian acyclic model for causal discovery, JMLR 7 (2006).

    + * *

    The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, @@ -38,9 +39,11 @@ * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges * in the final graph; these are finicky. So there's more work to do, and the implementation may * improve in the future.

    + * *

    Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; * these were not compared head to head, though the initial impression was that N Rooks was better, * so this version uses it.

    + * *

    This implementation has two parameters, a threshold (for N Rooks) on the minimum values * in absolute value for including entries in a possible strong diagonal for W, and a threshold * for BHat for including edges in the final graph.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java similarity index 91% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java index 4be21de3ca..3c9b642669 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingamPattern.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java @@ -42,17 +42,28 @@ import java.util.List; /** - * Implements the Lingam CPDAG algorithm as specified in Hoyer et al., "Causal discovery of linear acyclic models with - * arbitrary distributions," UAI 2008. The test for normality used for residuals is Anderson-Darling, following 'ad.test' - * in the nortest package of R. The default alpha level is 0.05--that is, p values from AD below 0.05 are taken to - * indicate nongaussianity. - *

    - * It is assumed that the CPDAG is the result of a CPDAG search such as PC or GES. In any - * case, it is important that the residuals be independent for ICA to work. + *

    Implements the PC-LiNGAM algorithm which first finds a CPDAG for the variables + * and then uses a non-Gaussian orientation method to orient the undirected edges. The + * reference is as follows: * + *

    >Hoyer et al., "Causal discovery of linear acyclic models with arbitrary + * distributions," UAI 2008.

    + * + *

    The test for normality used for residuals is Anderson-Darling, following 'ad.test' + * in the nortest package of R. The default alpha level is 0.05--that is, p values from AD + * below 0.05 are taken to indicate nongaussianity.

    + * + *

    It is assumed that the CPDAG is the result of a CPDAG search such as PC or GES. In any + * case, it is important that the residuals be independent for ICA to work.

    + * + *

    This may be replaced by a more general algorithm that allows alternatives for the + * CPDAG search and for the the non-Gaussian orientation method.

    + * + * @author peterspirtes + * @author patrickhoyer * @author josephramsey */ -public class LingamPattern { +public class PcLingam { private final Graph cpdag; private final DataSet dataSet; private double[] pValues; @@ -66,7 +77,7 @@ public class LingamPattern { * @param cpdag The CPDAG whose unoriented edges are to be oriented. * @param dataSet Teh dataset to use. */ - public LingamPattern(Graph cpdag, DataSet dataSet) + public PcLingam(Graph cpdag, DataSet dataSet) throws IllegalArgumentException { if (cpdag == null) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java index 01e01a55a2..94760f3607 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.LingamPattern; +import edu.cmu.tetrad.search.PcLingam; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.sem.SemIm; @@ -77,7 +77,7 @@ public void test1() { Score score = new SemBicScore(new CovarianceMatrix(dataSet)); Graph estnumCPDAGsToStore = new Fges(score).search(); - LingamPattern lingam = new LingamPattern(estnumCPDAGsToStore, dataSet); + PcLingam lingam = new PcLingam(estnumCPDAGsToStore, dataSet); lingam.search(); double[] pvals = lingam.getPValues(); From 97eda8f7238905617e5d8e30da2a5b6ba286da73 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 13:20:55 -0400 Subject: [PATCH 353/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index c562b36cb3..d9487c55a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -44,11 +44,13 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

    This class implements the LiNG-D algorithm as well as a number of ancillary - * methods for LiNG-D and LiNGAM.

    + *

    Implements the LiNG-D algorithm as well as a number of ancillary + * methods for LiNG-D and LiNGAM. The reference is here:

    + * *

    Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering * cyclic causal models by independent components analysis. arXiv preprint * arXiv:1206.3273.

    + * *

    The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, @@ -59,13 +61,18 @@ * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges * in the final graph; these are finicky. So there's more work to do, and the implementation may * improve in the future.

    + * *

    Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; * these were not compared head to head, though the initial impression was that N Rooks was better, * so this version uses it.

    + * *

    This implementation has two parameters, a threshold (for N Rooks) on the minimum values * in absolute value for including entries in a possible strong diagonal for W, and a threshold * for BHat for including edges in the final graph.

    * + * @author peterspirtes + * @author gustavolacerda + * @author patrickhoyer * @author josephramsey */ public class LingD { From aec505dad553c1d8391697a63a8af2fe23ae064a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 13:24:21 -0400 Subject: [PATCH 354/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/Lofs.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 2e1725be4d..e2492693fc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -41,10 +41,12 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

    These are methods for linear, non-Gaussian Orientation with a Fixed graph - * Structure (LOFS). The options for different types of scores are given in the enum - * Lofs.Score. The options for rules to use to do the orientations are given in the - * enum, Lofs.Rule. Most of these are taken from the literature and ca be googled.

    + *

    Implements a number of methods which take a fixed graph as input and use linear, + * non-Gaussian methods to orient the edges in the graph. where the acronym stands for + * linear, non-Gaussian Orientation with a Fixed graph Structure (LOFS). The options + * for different types of scores are given in the enum Lofs.Score. The options for rules + * to use to do the orientations are given in the enum, Lofs.Rule. Most of these are + * taken from the literature and ca be googled.

    * * @author josephramsey * @see Score From 661fbfc311281ffec9d9cb9dafe6291523331b46 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 13:26:51 -0400 Subject: [PATCH 355/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index e2492693fc..191d7b53be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -53,12 +53,18 @@ * @see Rule */ public class Lofs { + + /** + * The options for scores that can be used for some scores. + */ public enum Score { andersonDarling, skew, kurtosis, fifthMoment, absoluteValue, exp, expUnstandardized, expUnstandardizedInverted, other, logcosh, entropy } - // orientStrongerDirection list of past and present rules. + /** + * A list of rules for doing the non-Gaussian orientations. + */ public enum Rule { IGCI, R1TimeLag, R1, R2, R3, Tanh, EB, Skew, SkewE, RSkew, RSkewE, Patel, Patel25, Patel50, Patel75, Patel90, FastICA, RC From d88d1e185db9745ea5684ed26193a27a5cff6956 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 13:49:06 -0400 Subject: [PATCH 356/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../datamanip/ShiftDataParamsEditor.java | 2 +- .../algcomparison/algorithm/multi/Images.java | 1 + .../algorithm/oracle/cpdag/Boss.java | 2 +- .../algorithm/oracle/cpdag/Sp.java | 2 +- .../main/java/edu/cmu/tetrad/search/Boss.java | 1 + .../{FasDeterministic.java => Fasd.java} | 6 +- .../main/java/edu/cmu/tetrad/search/Fci.java | 7 +- .../main/java/edu/cmu/tetrad/search/Pc.java | 26 ++++- .../java/edu/cmu/tetrad/search/PcMax.java | 7 +- .../main/java/edu/cmu/tetrad/search/Pcd.java | 7 +- .../main/java/edu/cmu/tetrad/search/Sp.java | 1 + .../edu/cmu/tetrad/search/SuborderSearch.java | 5 +- .../search/{TsFas.java => SvarFas.java} | 14 +-- .../java/edu/cmu/tetrad/search/SvarFci.java | 7 +- .../edu/cmu/tetrad/search/SvarFciOrient.java | 21 +--- .../search/{TsFges.java => SvarFges.java} | 108 +++++++++--------- .../java/edu/cmu/tetrad/search/SvarGfci.java | 2 +- .../search/{ => utils}/PermutationSearch.java | 5 +- .../search/{ => utils}/ShiftSearch.java | 9 +- .../cmu/tetrad/test/TestAnneAnalysis3.java | 2 +- 20 files changed, 128 insertions(+), 107 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{FasDeterministic.java => Fasd.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{TsFas.java => SvarFas.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{TsFges.java => SvarFges.java} (93%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/PermutationSearch.java (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/ShiftSearch.java (94%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ShiftDataParamsEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ShiftDataParamsEditor.java index 6f48a613e5..e7a88375b3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ShiftDataParamsEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/datamanip/ShiftDataParamsEditor.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataModelList; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.ShiftSearch; +import edu.cmu.tetrad.search.utils.ShiftSearch; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TaskManager; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java index 8356781186..a5d77f9a0d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java @@ -14,6 +14,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.ImagesScore; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.PermutationSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 cea37d9c6c..34af671681 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 @@ -13,8 +13,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.PermutationSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 4789e95522..b13809e9c6 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 @@ -14,8 +14,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.PermutationSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 1224562097..8b7d6cf40f 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 @@ -5,6 +5,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GrowShrinkTree; +import edu.cmu.tetrad.search.utils.PermutationSearch; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java index 05fdea05fb..c60cc19436 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java @@ -44,7 +44,7 @@ * @author josephramsey. * @see Fas */ -public class FasDeterministic implements IFas { +public class Fasd implements IFas { /** * The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node @@ -110,12 +110,12 @@ public class FasDeterministic implements IFas { /** * Constructs a new FastAdjacencySearch. */ - public FasDeterministic(Graph graph, IndependenceTest test) { + public Fasd(Graph graph, IndependenceTest test) { this.graph = graph; this.test = test; } - public FasDeterministic(IndependenceTest test) { + public Fasd(IndependenceTest test) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 817b187148..f0d68e4f42 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -57,11 +57,12 @@ *

    Zhang, J. (2008). On the completeness of orientation rules for causal discovery in the presence * of latent confounders and selection bias. Artificial Intelligence, 172(16-17), 1873-1896.

    * - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 - * @author Choh-Man Teng + * @author peterspirtes + * @author clarkglymour + * @author jijizhang * @author josephramsey * @see FciOrient + * @see Pc */ public final class Fci implements IGraphSearch { private SepsetMap sepsets; 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 6bc8501975..8fd67e0047 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 @@ -39,12 +39,28 @@ import java.util.Set; /** - * Implements the PC ("Peter/Clark") algorithm, as specified in Chapter 6 of Spirtes, - * Glymour, and Scheines, "Causation, Prediction, and Search," 2nd edition, with a - * modified rule set in step D due to Chris Meek. For the modified rule set, see Chris - * Meek (1995), "Causal inference and causal explanation with background knowledge." + *

    Implements the PC (Peter and Clark) algorithm, which uses conditional + * independence testing as an oracle to first of all remove extraneous edges + * from a complete graph, then to orient the unshielded colliders in the graph, + * and finally to make any additional orientations that are capable of avoiding + * additional unshielded colliders in the graph. An earlier version of this + * algorithm was proposed earlier than this, but the standard reference for + * the algorithm is in Chapter 6 of the following book:

    * - * @author josephramsey. + *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + * prediction, and search. MIT press.

    + * + *

    A modified rule set capable of dealing effectively with knowledge of required + * and forbidden edges is due to Chris Meek, with this reference: + * + *

    Meek, C. (1995), "Causal inference and causal explanation with background + * knowledge."

    + * + * @author peterspirtes + * @author chrismeek + * @author clarkglymour + * @author josephramsey + * @see Fci */ public class Pc implements IGraphSearch { 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 477c0483f1..e240d34d97 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 @@ -39,11 +39,12 @@ import java.util.Set; /** - * Implements the PC ("Peter/Clark") algorithm, as specified in Chapter 6 of Spirtes, Glymour, and Scheines, "Causation, - * Prediction, and Search," 2nd edition, with a modified rule set in step D due to Chris Meek. For the modified rule - * set, see Chris Meek (1995), "Causal inference and causal explanation with background knowledge." + * Modifies the PC algorithm to use the Max P rule for orienting ushielded colliders. * * @author josephramsey. + * @see PcMax + * @see Pc + * @see Fasd */ public class PcMax implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index bba876eef8..ea588df7bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -37,11 +37,12 @@ import java.util.Set; /** - * Implements the PC ("Peter/Clark") algorithm, as specified in Chapter 6 of Spirtes, Glymour, and Scheines, "Causation, - * Prediction, and Search," 2nd edition, with a modified rule set in step D due to Chris Meek. For the modified rule - * set, see Chris Meek (1995), "Causal inference and causal explanation with background knowledge." + * Modifies the PC algorithm to handle the deterministic case. * + * @author peterspirtes * @author josephramsey. + * @see Fasd + * @see Pc */ public class Pcd implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 0c475782da..4ab6668ed4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -4,6 +4,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GrowShrinkTree; +import edu.cmu.tetrad.search.utils.PermutationSearch; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index 597aea1c51..1f6e4dc75c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -4,13 +4,14 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GrowShrinkTree; +import edu.cmu.tetrad.search.utils.PermutationSearch; import java.util.List; import java.util.Map; import java.util.Set; /** - * Interface to help implement suborder searches for various types of permutation algorithms. + * An interface for suborder searches for various types of permutation algorithms. * A "suborder search" is a search for permutation <x1a,...x1n, x2a,...,x2m, x3a,...,x3l>> * that searches for a good permutation of x2a,...,x2m with x1a,...,x1n as a prefix. * This is used by PermutationSearch to form a complete permutation search algorithm, @@ -19,6 +20,8 @@ * * @author bryanandrews * @see PermutationSearch + * @see Boss + * @see Sp */ public interface SuborderSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java index 0e247aa80b..4374a1e17e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java @@ -36,15 +36,15 @@ import java.util.*; /** - * This is a copy of Fas.java for the SvarFCI algorithm. The main difference is that if an edge is removed, it will also - * remove all homologous edges to preserve the time-repeating structure assumed by SvarFCI. Based on (but not identicial - * to) code by Entner and Hoyer for their 2010 paper. Modified by DMalinsky 4/21/2016. + *

    Adapts Fas.java for the SvarFCI algorithm. The main difference is that if an edge is + * removed, it will also remove all homologous edges to preserve the time-repeating s + * tructure assumed by SvarFCI. Based on (but not identical to) code by Entner and Hoyer + * for their 2010 paper. Modified by dmalinsky 4/21/2016.

    * - * @author josephramsey - * @author DMalinsky + * @author dmalinsky * @see Fas */ -public class TsFas implements IFas { +public class SvarFas implements IFas { /** * The search graph. It is assumed going in that all the true adjacencies of x are in this graph for every node @@ -100,7 +100,7 @@ public class TsFas implements IFas { /** * Constructs a new FastAdjacencySearch. */ - public TsFas(IndependenceTest test) { + public SvarFas(IndependenceTest test) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 7d90ba1a12..36d89ca94e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -47,11 +47,8 @@ * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. * (By a remark of Zhang's, the rule applications can be staged in this way.) * - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 - * @author josephramsey - * @author Choh-Man Teng * @author Daniel Malinsky + * @see Fci */ public final class SvarFci implements IGraphSearch { @@ -129,7 +126,7 @@ public void setDepth(int depth) { public Graph search() { getIndependenceTest().getVariables(); - return search(new TsFas(getIndependenceTest())); + return search(new SvarFas(getIndependenceTest())); // return search(new Fas(getIndependenceTest())); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 07c8045b4f..93b2245f75 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -39,23 +39,12 @@ /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

    - * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + *

    Adapts FciOrientfor the SvarFCI algorithm. The main difference is that if an edge is orient, + * it will also orient all homologous edges to preserve the time-repeating structure assumed by + * SvarFCI. Based on (but not identicial to) code by Entner and Hoyer for their 2010 paper. Modified + * by DMalinsky 4/20/2016.

    * - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 - * @author josephramsey - * @author Choh-Man Teng - * @author Daniel Malinsky - *

    - * This is a copy of FciOrient.java for the SvarFCI algorithm. The main difference is that if an edge is orient, it will - * also orient all homologous edges to preserve the time-repeating structure assumed by SvarFCI. Based on (but not - * identicial to) code by Entner and Hoyer for their 2010 paper. Modified by DMalinsky 4/20/2016. + * @author dmalinsky */ public final class SvarFciOrient { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java similarity index 93% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java index 11d0d0f20d..98872f0fd2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/TsFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java @@ -40,24 +40,26 @@ /** - * GesSearch is an implementation of the GES algorithm, as specified in Chickering (2002) "Optimal structure - * identification with greedy search" Journal of Machine Learning Research. It works for both BayesNets and SEMs. - *

    - * Some code optimization could be done for the scoring part of the graph for discrete models (method scoreGraphChange). - * Some of Andrew Moore's approaches for caching sufficient statistics, for instance. - *

    - * To speed things up, it has been assumed that variables X and Y with zero correlation do not correspond to edges in - * the graph. This is a restricted form of the heuristicSpeedup assumption, something GES does not assume. This - * the graph. This is a restricted form of the heuristicSpeedup assumption, something GES does not assume. This - * heuristicSpeedup assumption needs to be explicitly turned on using setHeuristicSpeedup(true). - *

    - * A number of other optimizations were added 5/2015. See code for details. + * Adapts FGES to the SVAR case. FGES is an implementation of the GES algorithm, as specified in + * Chickering (2002) "Optimal structure identification with greedy search" Journal of Machine + * Learning Research. It works for both BayesNets and SEMs.

    + * + *

    Some code optimization could be done for the scoring part of the graph for discrete models + * (method scoreGraphChange). Some of Andrew Moore's approaches for caching sufficient statistics, + * for instance.

    + * + *

    To speed things up, it has been assumed that variables X and Y with zero correlation do not + * correspond to edges in the graph. This is a restricted form of the heuristicSpeedup assumption, + * something GES does not assume. This is the graph. This is a restricted form of the + * heuristicSpeedup assumption, something GES does not assume. This heuristicSpeedup assumption + * needs to be explicitly turned on using setHeuristicSpeedup(true).

    + * + *

    A number of other optimizations were added 5/2015. See code for details.

    * - * @author Ricardo Silva, Summer 2003 - * @author josephramsey, Revisions 5/2015 * @author Daniel Malinsky + * @see Fges */ -public final class TsFges implements IGraphSearch, DagScorer { +public final class SvarFges implements IGraphSearch, DagScorer { /** * Internal. @@ -175,7 +177,7 @@ private enum Mode { * values in case of conditional independence. See Chickering (2002), * locally consistent scoring criterion. */ - public TsFges(Score score) { + public SvarFges(Score score) { if (score == null) throw new NullPointerException(); setScore(score); this.graph = new EdgeListGraph(getVariables()); @@ -479,12 +481,12 @@ public NodeTaskEmptyGraph(int from, int to, List nodes, Set emptySet protected Boolean compute() { for (int i = this.from; i < this.to; i++) { if ((i + 1) % 1000 == 0) { - TsFges.this.count[0] += 1000; - TsFges.this.out.println("Initializing effect edges: " + (TsFges.this.count[0])); + SvarFges.this.count[0] += 1000; + SvarFges.this.out.println("Initializing effect edges: " + (SvarFges.this.count[0])); } Node y = this.nodes.get(i); - TsFges.this.neighbors.put(y, this.emptySet); + SvarFges.this.neighbors.put(y, this.emptySet); for (int j = i + 1; j < this.nodes.size(); j++) { if (Thread.currentThread().isInterrupted()) { @@ -503,17 +505,17 @@ protected Boolean compute() { } } - if (TsFges.this.adjacencies != null && !TsFges.this.adjacencies.isAdjacentTo(x, y)) { + if (SvarFges.this.adjacencies != null && !SvarFges.this.adjacencies.isAdjacentTo(x, y)) { continue; } - int child = TsFges.this.hashIndices.get(y); - int parent = TsFges.this.hashIndices.get(x); - double bump = TsFges.this.score.localScoreDiff(parent, child); + int child = SvarFges.this.hashIndices.get(y); + int parent = SvarFges.this.hashIndices.get(x); + double bump = SvarFges.this.score.localScoreDiff(parent, child); if (bump > 0) { Edge edge = Edges.undirectedEdge(x, y); - TsFges.this.effectEdgesGraph.addEdge(edge); + SvarFges.this.effectEdgesGraph.addEdge(edge); } if (bump > 0.0) { @@ -546,7 +548,7 @@ public InitializeFromEmptyGraphTask() { protected Boolean compute() { Queue tasks = new ArrayDeque<>(); - int numNodesPerTask = FastMath.max(100, nodes.size() / TsFges.this.maxThreads); + int numNodesPerTask = FastMath.max(100, nodes.size() / SvarFges.this.maxThreads); for (int i = 0; i < nodes.size(); i += numNodesPerTask) { NodeTaskEmptyGraph task = new NodeTaskEmptyGraph(i, FastMath.min(nodes.size(), i + numNodesPerTask), @@ -561,7 +563,7 @@ protected Boolean compute() { } } - while (tasks.size() > TsFges.this.maxThreads) { + while (tasks.size() > SvarFges.this.maxThreads) { NodeTaskEmptyGraph _task = tasks.poll(); if (_task != null) { @@ -627,21 +629,21 @@ protected Boolean compute() { if (this.to - this.from <= this.chunk) { for (int i = this.from; i < this.to; i++) { if ((i + 1) % 1000 == 0) { - TsFges.this.count[0] += 1000; - TsFges.this.out.println("Initializing effect edges: " + (TsFges.this.count[0])); + SvarFges.this.count[0] += 1000; + SvarFges.this.out.println("Initializing effect edges: " + (SvarFges.this.count[0])); } Node y = nodes.get(i); Set g = new HashSet<>(); - for (Node n : TsFges.this.graph.getAdjacentNodes(y)) { - for (Node m : TsFges.this.graph.getAdjacentNodes(n)) { - if (TsFges.this.graph.isAdjacentTo(y, m)) { + for (Node n : SvarFges.this.graph.getAdjacentNodes(y)) { + for (Node m : SvarFges.this.graph.getAdjacentNodes(n)) { + if (SvarFges.this.graph.isAdjacentTo(y, m)) { continue; } - if (TsFges.this.graph.isDefCollider(m, n, y)) { + if (SvarFges.this.graph.isDefCollider(m, n, y)) { continue; } @@ -660,11 +662,11 @@ protected Boolean compute() { } } - if (TsFges.this.adjacencies != null && !TsFges.this.adjacencies.isAdjacentTo(x, y)) { + if (SvarFges.this.adjacencies != null && !SvarFges.this.adjacencies.isAdjacentTo(x, y)) { continue; } - if (TsFges.this.removedEdges.contains(Edges.undirectedEdge(x, y))) { + if (SvarFges.this.removedEdges.contains(Edges.undirectedEdge(x, y))) { continue; } @@ -734,15 +736,15 @@ protected Boolean compute() { } if ((i + 1) % 1000 == 0) { - TsFges.this.count[0] += 1000; - TsFges.this.out.println("Initializing effect edges: " + (TsFges.this.count[0])); + SvarFges.this.count[0] += 1000; + SvarFges.this.out.println("Initializing effect edges: " + (SvarFges.this.count[0])); } Node y = nodes.get(i); List cond = new ArrayList<>(); - Set D = new HashSet<>(TsFges.this.graph.paths().getDconnectedVars(y, cond)); + Set D = new HashSet<>(SvarFges.this.graph.paths().getDconnectedVars(y, cond)); D.remove(y); - TsFges.this.effectEdgesGraph.getAdjacentNodes(y).forEach(D::remove); + SvarFges.this.effectEdgesGraph.getAdjacentNodes(y).forEach(D::remove); for (Node x : D) { if (existsKnowledge()) { @@ -755,7 +757,7 @@ protected Boolean compute() { } } - if (TsFges.this.adjacencies != null && !TsFges.this.adjacencies.isAdjacentTo(x, y)) { + if (SvarFges.this.adjacencies != null && !SvarFges.this.adjacencies.isAdjacentTo(x, y)) { continue; } @@ -984,18 +986,18 @@ protected Boolean compute() { List adj; - if (TsFges.this.mode == Mode.heuristicSpeedup) { - adj = TsFges.this.effectEdgesGraph.getAdjacentNodes(x); - } else if (TsFges.this.mode == Mode.coverNoncolliders) { + if (SvarFges.this.mode == Mode.heuristicSpeedup) { + adj = SvarFges.this.effectEdgesGraph.getAdjacentNodes(x); + } else if (SvarFges.this.mode == Mode.coverNoncolliders) { Set g = new HashSet<>(); - for (Node n : TsFges.this.graph.getAdjacentNodes(x)) { - for (Node m : TsFges.this.graph.getAdjacentNodes(n)) { - if (TsFges.this.graph.isAdjacentTo(x, m)) { + for (Node n : SvarFges.this.graph.getAdjacentNodes(x)) { + for (Node m : SvarFges.this.graph.getAdjacentNodes(n)) { + if (SvarFges.this.graph.isAdjacentTo(x, m)) { continue; } - if (TsFges.this.graph.isDefCollider(m, n, x)) { + if (SvarFges.this.graph.isDefCollider(m, n, x)) { continue; } @@ -1004,8 +1006,8 @@ protected Boolean compute() { } adj = new ArrayList<>(g); - } else if (TsFges.this.mode == Mode.allowUnfaithfulness) { - HashSet D = new HashSet<>(TsFges.this.graph.paths().getDconnectedVars(x, new ArrayList<>())); + } else if (SvarFges.this.mode == Mode.allowUnfaithfulness) { + HashSet D = new HashSet<>(SvarFges.this.graph.paths().getDconnectedVars(x, new ArrayList<>())); D.remove(x); adj = new ArrayList<>(D); } else { @@ -1013,13 +1015,13 @@ protected Boolean compute() { } for (Node w : adj) { - if (TsFges.this.adjacencies != null && !(TsFges.this.adjacencies.isAdjacentTo(w, x))) { + if (SvarFges.this.adjacencies != null && !(SvarFges.this.adjacencies.isAdjacentTo(w, x))) { continue; } if (w == x) continue; - if (!TsFges.this.graph.isAdjacentTo(w, x)) { + if (!SvarFges.this.graph.isAdjacentTo(w, x)) { clearArrow(w, x); calculateArrowsForward(w, x); } @@ -1144,7 +1146,7 @@ protected Boolean compute() { if (this.to - this.from <= this.chunk) { for (int _w = this.from; _w < this.to; _w++) { Node w = this.adj.get(_w); - Edge e = TsFges.this.graph.getEdge(w, this.r); + Edge e = SvarFges.this.graph.getEdge(w, this.r); if (e != null) { if (e.pointsTowards(this.r)) { @@ -1152,7 +1154,7 @@ protected Boolean compute() { clearArrow(this.r, w); calculateArrowsBackward(w, this.r); - } else if (Edges.isUndirectedEdge(TsFges.this.graph.getEdge(w, this.r))) { + } else if (Edges.isUndirectedEdge(SvarFges.this.graph.getEdge(w, this.r))) { clearArrow(w, this.r); clearArrow(this.r, w); @@ -1660,7 +1662,7 @@ private boolean existsUnblockedSemiDirectedPath(Node from, Node to, Set co } Edge edge = this.graph.getEdge(t, u); - Node c = TsFges.traverseSemiDirected(t, edge); + Node c = SvarFges.traverseSemiDirected(t, edge); if (c == null) continue; if (cond.contains(c)) continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index b976156c8f..688a50a9df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -118,7 +118,7 @@ public Graph search() { chooseScore(); } - TsFges fges = new TsFges(this.score); + SvarFges fges = new SvarFges(this.score); fges.setKnowledge(this.knowledge); fges.setVerbose(this.verbose); fges.setNumCPDAGsToStore(0); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationSearch.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationSearch.java index 05bed475c0..ea9519767c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationSearch.java @@ -1,9 +1,12 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Boss; +import edu.cmu.tetrad.search.Sp; +import edu.cmu.tetrad.search.SuborderSearch; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GrowShrinkTree; import edu.cmu.tetrad.search.utils.MeekRules; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java index 9574de660a..255fe1514a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.ImagesScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; @@ -37,7 +38,11 @@ import java.util.List; /** - * Tries to find a good shifting of variables to minimize average BIC + *

    >Tries to find a good shifting of variables to minimize average BIC for + * time-series data. The idea is that the data one is presented with may have + * the variables temporally shifted with respect to one another. ShiftSearch + * attempts to find a shifting of the variables that reduces this temporal + * shifting. * * @author josephramsey */ diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java index bfafa03507..0cf2a364c5 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Boss; -import edu.cmu.tetrad.search.PermutationSearch; +import edu.cmu.tetrad.search.utils.PermutationSearch; import edu.cmu.tetrad.search.score.PoissonPriorScore; import org.jetbrains.annotations.NotNull; import org.junit.Test; From 10ed76a8fc0672d4faea3068a1c792c4c23fe663 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 14:00:07 -0400 Subject: [PATCH 357/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Lofs.java | 5 ++-- .../java/edu/cmu/tetrad/search/Mimbuild.java | 30 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 191d7b53be..610477618b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -55,7 +55,8 @@ public class Lofs { /** - * The options for scores that can be used for some scores. + * Gives a list of options for non-Gaussian transformations that can be used + * for some scores. */ public enum Score { andersonDarling, skew, kurtosis, fifthMoment, absoluteValue, @@ -63,7 +64,7 @@ public enum Score { } /** - * A list of rules for doing the non-Gaussian orientations. + * Give a list of options for rules for doing the non-Gaussian orientations. */ public enum Rule { IGCI, R1TimeLag, R1, R2, R3, Tanh, EB, Skew, SkewE, RSkew, RSkewE, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index dd74515f49..98576ea305 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -42,13 +42,28 @@ import java.util.List; /** - *

    >An implemetation of Mimbuild. The search will first infer the covariance matrix - * over the latents and then will use GRaSP to infer the structure grpah over the - * latents, using the SemBicScore with the given penalty discount (default 2).

    The covariance matrix over the latents may be retried if one desires to use - * a different method to infer the structure graph over the latents.

    + *

    >Provides an implemntation of Mimbuild, an algorithm that takes a clustering + * of variables, each of which is explained by a single latent, then forms the + * implied covariance matrix over the latent variables, then runs a CPDAG search + * to in the structure over the latent themselves.

    + * + *

    Specifically, the search will first infer the covariance matrix over the + * latents and then will use the GRaSP algorithm (see) to infer the structure + * graph over the latents, using the SEM Bic score with the given penalty discount + * (default 2).

    One may wish to obtain the implied correlation matrix over the latents and + * run one's own choice of CPDDAG algroithm on it with one's on test or score; + * a method is available to return this covariance matrix.

    + * + *

    A suitable clustering for Mimbuild may be obtained using the BPC or FOFC + * algorithm (see).

    * * @author josephramsey + * @see Bpc + * @see Fofc + * @see #getLatentsCov() + * */ public class Mimbuild { @@ -67,9 +82,6 @@ public class Mimbuild { */ private Knowledge knowledge = new Knowledge(); - /** - * The estimated covariance matrix over the latents. - */ private ICovarianceMatrix latentsCov; /** @@ -178,6 +190,8 @@ public void setKnowledge(Knowledge knowledge) { } /** + * The estimated covariance matrix over the latents. + */ /** * Returns the inferred covariance matrix over the late4nt variables. * * @return Thsi covariance matrix. From 5cb01fbfe802b0296b0fedb4ea67d5839d977ab2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 14:00:34 -0400 Subject: [PATCH 358/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 98576ea305..cffe46549b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -63,7 +63,6 @@ * @see Bpc * @see Fofc * @see #getLatentsCov() - * */ public class Mimbuild { From 9c95183865841b0e8e5fe91e27e69505c3e753e3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 14:00:46 -0400 Subject: [PATCH 359/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 05a41ec408..a0b79973a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -39,7 +39,6 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - /** *

    Uses SP in place of FGES for the initial step in the GFCI algorithm. * This tends to produce a accurate PAG than GFCI as a result, for the latent * variables case. This is a simple substitution; the reference for GFCI is here:

    From bf1f40c8e9442ae6c0a393fd64665580eb6756bc Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 14:02:44 -0400 Subject: [PATCH 360/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java | 1 + .../edu/cmu/tetrad/search/{ => utils}/BesPermutation.java | 6 ++++-- .../edu/cmu/tetrad/search/{ => work_in_progress}/Bes.java | 4 +++- 4 files changed, 9 insertions(+), 3 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/BesPermutation.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => work_in_progress}/Bes.java (99%) 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 8b7d6cf40f..e3d242d347 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 @@ -4,6 +4,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.BesPermutation; import edu.cmu.tetrad.search.utils.GrowShrinkTree; import edu.cmu.tetrad.search.utils.PermutationSearch; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 3ff8da9912..8a937699f7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -29,6 +29,7 @@ import edu.cmu.tetrad.search.utils.DagScorer; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; +import edu.cmu.tetrad.search.work_in_progress.Bes; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java index 1723e9d8e7..c7e552b064 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BesPermutation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java @@ -1,9 +1,11 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.work_in_progress.Bes; +import edu.cmu.tetrad.search.Boss; +import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.jetbrains.annotations.NotNull; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Bes.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Bes.java index 6e1e12e267..a57505b012 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Bes.java @@ -1,7 +1,9 @@ -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.search.Boss; +import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.SublistGenerator; From a24677b90e7c3cd0073f119a8f89b535248d52e0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 14:04:20 -0400 Subject: [PATCH 361/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java | 2 +- .../cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Boss.java | 2 +- .../edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Sp.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java | 1 - .../edu/cmu/tetrad/search/{utils => }/PermutationSearch.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java | 1 - .../src/main/java/edu/cmu/tetrad/search/SuborderSearch.java | 1 - .../src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java | 2 +- 8 files changed, 5 insertions(+), 8 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{utils => }/PermutationSearch.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java index a5d77f9a0d..12000d6dc5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java @@ -14,7 +14,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.ImagesScore; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.utils.PermutationSearch; +import edu.cmu.tetrad.search.PermutationSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 34af671681..98cf4a9ddd 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 @@ -14,7 +14,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.utils.PermutationSearch; +import edu.cmu.tetrad.search.PermutationSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 b13809e9c6..234baa6de1 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 @@ -15,7 +15,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.utils.PermutationSearch; +import edu.cmu.tetrad.search.PermutationSearch; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; 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 e3d242d347..f947290216 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 @@ -6,7 +6,6 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.BesPermutation; import edu.cmu.tetrad.search.utils.GrowShrinkTree; -import edu.cmu.tetrad.search.utils.PermutationSearch; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index ea9519767c..9ac415f829 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.utils; +package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 4ab6668ed4..0c475782da 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -4,7 +4,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GrowShrinkTree; -import edu.cmu.tetrad.search.utils.PermutationSearch; import java.util.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index 1f6e4dc75c..e008c4c713 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -4,7 +4,6 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GrowShrinkTree; -import edu.cmu.tetrad.search.utils.PermutationSearch; import java.util.List; import java.util.Map; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java index 0cf2a364c5..bfafa03507 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestAnneAnalysis3.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Boss; -import edu.cmu.tetrad.search.utils.PermutationSearch; +import edu.cmu.tetrad.search.PermutationSearch; import edu.cmu.tetrad.search.score.PoissonPriorScore; import org.jetbrains.annotations.NotNull; import org.junit.Test; From 0cb288ea639dd39c3b696ede0798dcf6f5ad4b18 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 14:11:38 -0400 Subject: [PATCH 362/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetrad/search/score/GicScores.java | 12 +++++++++--- .../edu/cmu/tetrad/search/score/SemBicScore.java | 9 ++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index 2d2085d239..d1294ab450 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -25,8 +25,6 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.util.FastMath; @@ -35,8 +33,9 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

    Implements scores motivated by the Generalized Information Criterion (GIC) + *

    Implements scores motivated by the Generalized Information Criterion (GIC) * approach as given in Kim et al. (2012).

    + * *

    Kim, Y., Kwon, S., & Choi, H. (2012). Consistent model selection criteria on * high dimensions. The Journal of Machine Learning Research, 13(1), 1037-1057. * Foster and George.

    @@ -310,6 +309,13 @@ public void setPenaltyDiscount(double penaltyDiscount) { this.penaltyDiscount = penaltyDiscount; } + /** + * Gives the options for the rules to use for calculating the scores. The "GIC" + * rules, and RICc, are the rules proposed in the Kim et al. paper for + * generalized information criteria.' + * + * @see GicScores + */ public enum RuleType {MANUAL, BIC, NANDY, GIC2, RIC, RICc, GIC5, GIC6} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index 8d0c2b3331..a979a4cd12 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -46,6 +46,12 @@ */ public class SemBicScore implements Score { + /** + * Gives two options for calculating the BIC score, one describe by Chickering and the + * other due to Nandy et al. + */ + public enum RuleType {CHICKERING, NANDY} + // The sample size of the covariance matrix. private final int sampleSize; // A map from variable names to their indices. @@ -510,9 +516,6 @@ public SemBicScore subset(List pi2) { ICovarianceMatrix cov = getCovariances().getSubmatrix(cols); return new SemBicScore(cov); } - - public enum RuleType {CHICKERING, NANDY} - } From a605cd02bd549da9827bdbcd41dfa8668a24549b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 14:21:59 -0400 Subject: [PATCH 363/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../score/ConditionalGaussianLikelihood.java | 4 ++-- .../cmu/tetrad/search/score/DiscreteScore.java | 5 +++-- .../cmu/tetrad/search/score/MagSemBicScore.java | 2 +- .../cmu/tetrad/search/score/SemBicScorer.java | 2 +- .../test/ConditionalCorrelationIndependence.java | 9 +++++++++ .../test/IndTestDegenerateGaussianLrt.java | 2 +- .../cmu/tetrad/search/test/IndependenceTest.java | 6 +++--- .../java/edu/cmu/tetrad/search/test/Kci.java | 16 +++++++++------- .../edu/cmu/tetrad/search/test/ScoreIndTest.java | 7 ++++--- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java index 07b179c465..86e6274239 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java @@ -82,8 +82,8 @@ public void setRows(List rows) { } /** - * A return value for a likelihood--returns a likelihood value and the degrees of freedom - * for it. + * Gives return value for a conditional Gaussain likelihood, returning a likelihood + * value and the degrees of freedom for it. */ public static class Ret { private final double lik; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java index 018a9feb58..1d945fd7c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java @@ -24,8 +24,9 @@ import edu.cmu.tetrad.data.DataSet; /** - * Created by IntelliJ IDEA. User: jdramsey Date: Jul 6, 2009 Time: 3:58:26 PM To change this template use File | - * Settings | File Templates. + * Gives an interface that can be used by various discrete scores. + * + * @author josephramsey */ public interface DiscreteScore extends Score { void setStructurePrior(double structurePrior); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java index dde7fc3f50..2e32926836 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java @@ -35,7 +35,7 @@ import java.util.*; /** - * This ia BIC score for a linear, Gaussian MAG (Mixed Ancestral Graph). It + * Gives ia BIC score for a linear, Gaussian MAG (Mixed Ancestral Graph). It * will perform the same as SemBicScore for DAGs. * * @author Bryan Andrews diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScorer.java index d1b200575b..aa90a5f607 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScorer.java @@ -12,7 +12,7 @@ import java.util.Map; /** - * Scores a DAG using the SemBicScore. + * Scores an entire DAG using the SemBicScore. * * @author josephramsey * @see SemBicScore diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java index 30820c3021..eb11739cd1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java @@ -52,8 +52,17 @@ * @author josephramsey */ public final class ConditionalCorrelationIndependence { + + /** + * Gives a choice of kernels to use for the independence judgmnts for conditional correlation independence. + * @see ConditionalCorrelationIndependence + */ public enum Kernel {Epinechnikov, Gaussian} + /** + * Gives a choice of basis functions to use for judgments of independence for conditional correlation independence. + * @see ConditionalCorrelationIndependence + */ public enum Basis {Polynomial, Cosine} /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java index 38a40639ba..334b6461c7 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java @@ -42,7 +42,7 @@ import static org.apache.commons.math3.util.FastMath.*; -/* +/** * Implements a degenerate Gaussian score as a LRT. * * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java index 208ada5de1..4c4f4c4e08 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java @@ -32,9 +32,9 @@ import java.util.List; /** - *

    Interface implemented by classes that do conditional independence testing. - * These classes are capable of serving as conditional independence "oracles" - * for constraint-based searches.

    + *

    Gives an interface that can be implemented by classes that do conditional + * independence testing. These classes are capable of serving as conditional + * independence "oracles" for constraint-based searches.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java index 98e4f0a563..57011e4b64 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java @@ -29,18 +29,20 @@ import static org.apache.commons.math3.util.FastMath.*; /*** - * Kernal Independence Test (KCI). + *

    Gives an implementation of the Kernal Independence Test (KCI) by Kun Zhang, which is a + * general test of conditional independence. The reference is here:

    * - * Zhang, K., Peters, J., Janzing, D., and Schölkopf, B. (2012). Kernel-based conditional independence - * test and application in causal discovery. arXiv preprint arXiv:1202.3775. + *

    Zhang, K., Peters, J., Janzing, D., and Schölkopf, B. (2012). Kernel-based conditional independence + * test and application in causal discovery. arXiv preprint arXiv:1202.3775.

    * - * Please see that paper, especially Theorem 4 and Proposition 5. + *

    Please see that paper, especially Theorem 4 and Proposition 5.

    * - * Using optimal kernel bandwidths suggested by Bowman and Azzalini (1997): + *

    Using optimal kernel bandwidths suggested by Bowman and Azzalini (1997):

    * - * Bowman, A. W., and Azzalini, A. (1997). Applied smoothing techniques for data analysis: the kernel - * approach with S-Plus illustrations (Vol. 18). OUP Oxford. + *

    Bowman, A. W., and Azzalini, A. (1997). Applied smoothing techniques for data analysis: the kernel + * approach with S-Plus illustrations (Vol. 18). OUP Oxford.

    * + * @author kunzhang * @author Vineet Raghu on 7/3/2016 * @author josephramsey refactoring 7/4/2018 */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java index 35428d43bf..a621240151 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java @@ -37,10 +37,11 @@ import java.util.List; /** - * Interface implemented by classes that do conditional independence testing. These classes are capable of serving as - * conditional independence "oracles" for constraint-based searches. + *

    Gives a way of interpreting a score as an independence test. The contract is that + * the score returned will be negative for independence and positive for dependence; + * this simply reports these differences.

    * - * @author Don Crimbchin (djc2@andrew.cmu.edu) + * @author doncrimbchin * @author josephramsey */ public class ScoreIndTest implements IndependenceTest { From b7160f366761cfdc243ebc09bc4535e42650a409 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 17:26:59 -0400 Subject: [PATCH 364/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/IndTestScore.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index cffe46549b..9b0edaa12a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -42,7 +42,7 @@ import java.util.List; /** - *

    >Provides an implemntation of Mimbuild, an algorithm that takes a clustering + *

    Provides an implemntation of Mimbuild, an algorithm that takes a clustering * of variables, each of which is explained by a single latent, then forms the * implied covariance matrix over the latent variables, then runs a CPDAG search * to in the structure over the latent themselves.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java index d0b2cadd5e..2da520d89c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java @@ -30,7 +30,9 @@ import java.util.List; /** - * Implements Chickering and Meek's (2002) locally consistent score criterion. + * Gives a method of interpreting a test as a score. Various independence tests + * will calcualte p-values; this simply reports alpha - p as a score, which will + * be higher for greater dependence. * * @author josephramsey */ @@ -81,7 +83,6 @@ public double localScoreDiff(int x, int y, int[] z) { return this.test.getScore(); } - /** * Specialized scoring method for a single parent. Used to speed up the effect edges search. */ From 5c08c6e56670028f0fc0ef355fc7ba304590d1f1 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 17:57:10 -0400 Subject: [PATCH 365/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetradapp/editor/BayesUpdaterClassifierEditor.java | 2 +- .../tetradapp/model/BayesUpdaterClassifierWrapper.java | 2 +- .../{classify => }/ClassifierBayesUpdaterDiscrete.java | 2 +- .../classify/{classify => }/ClassifierDiscrete.java | 2 +- .../classify/{classify => }/ClassifierMbDiscrete.java | 2 +- .../java/edu/cmu/tetrad/search/test/IndTestHsic.java | 10 +++++++--- .../edu/cmu/tetrad/util/TetradSerializableUtils.java | 10 +++++----- 7 files changed, 17 insertions(+), 13 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/classify/{classify => }/ClassifierBayesUpdaterDiscrete.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/classify/{classify => }/ClassifierDiscrete.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/classify/{classify => }/ClassifierMbDiscrete.java (99%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java index 554bf65d10..e42948c25a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/BayesUpdaterClassifierEditor.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.classify.classify.ClassifierBayesUpdaterDiscrete; +import edu.cmu.tetrad.classify.ClassifierBayesUpdaterDiscrete; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RocCalculator; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java index 8a24b910b8..a8d96cb077 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.bayes.BayesIm; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.classify.classify.ClassifierBayesUpdaterDiscrete; +import edu.cmu.tetrad.classify.ClassifierBayesUpdaterDiscrete; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.TetradSerializableUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierBayesUpdaterDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierBayesUpdaterDiscrete.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierBayesUpdaterDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierBayesUpdaterDiscrete.java index 11e1e56786..9d23dcf292 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierBayesUpdaterDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierBayesUpdaterDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.classify.classify; +package edu.cmu.tetrad.classify; import edu.cmu.tetrad.bayes.*; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierDiscrete.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierDiscrete.java index e97ac2bbb3..02f71e60dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.classify.classify; +package edu.cmu.tetrad.classify; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierMbDiscrete.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierMbDiscrete.java index 15a1edf1e2..21e10dc3c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/classify/ClassifierMbDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierMbDiscrete.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.classify.classify; +package edu.cmu.tetrad.classify; import edu.cmu.tetrad.bayes.*; import edu.cmu.tetrad.data.DataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java index fbb2c65ba3..798c6911d3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java @@ -43,11 +43,15 @@ import java.util.List; /** - * Checks the conditional independence X _||_ Y | S, where S is a set of continuous variable, and X and Y are discrete - * variable not in S, using the Hilbert-Schmidth Independence Criterion (HSIC), a kernel based nonparametric test for - * conditional independence. + * Checks the conditional independence X _||_ Y | S, where S is a set of continuous variable, + * and X and Y are discrete variable not in S, using the Hilbert-Schmidth Independence + * Criterion (HSIC), a kernel based nonparametric test for conditional independence. + * + * The Kpc algorithm by Tillman had run PC using this test; to run Kpc, simply select this test + * for PC. * * @author Robert Tillman + * @see edu.cmu.tetrad.search.work_in_progress.Kpc */ public final class IndTestHsic implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java index c1caa2fd7e..6334fb40e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java @@ -723,8 +723,7 @@ private Method serializableInstanceMethod(Class clazz) { * @return all of the classes x in the given directory (recursively) such * that clazz.isAssignableFrom(x). */ - private List getAssignableClasses(File path, - Class clazz) { + private List getAssignableClasses(File path, Class clazz) { if (!path.isDirectory()) { throw new IllegalArgumentException("Not a directory: " + path); } @@ -752,16 +751,17 @@ private List getAssignableClasses(File path, } packagePath = packagePath.substring(0, index); + Class _clazz; try { - Class _clazz = - getClass().getClassLoader().loadClass(packagePath); + _clazz = getClass().getClassLoader().loadClass(packagePath); if (clazz.isAssignableFrom(_clazz) && !_clazz.isInterface()) { classes.add(_clazz); } } catch (ClassNotFoundException e) { - e.printStackTrace(); + System.out.println("Clazz not found: : " + path); +// e.printStackTrace(); } } } From e99c1c08e6ee221cf4ebf605fd133f0b3c201767 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 18:01:56 -0400 Subject: [PATCH 366/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java index 6334fb40e5..5e3747d97b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializableUtils.java @@ -760,7 +760,7 @@ private List getAssignableClasses(File path, Class cl classes.add(_clazz); } } catch (ClassNotFoundException e) { - System.out.println("Clazz not found: : " + path); + System.out.println("Package not found: : " + packagePath); // e.printStackTrace(); } } From 7ef29308dbd07ac3fbe5d765a409b278445bca0f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 18:16:48 -0400 Subject: [PATCH 367/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Cfci.java | 12 ++++----- .../edu/cmu/tetrad/search/MimbuildTrek.java | 2 +- .../cmu/tetrad/search/score/GraphScore.java | 25 ++++++++++++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 9790bd397b..d0fbd53c9d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -35,16 +35,14 @@ /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

    - * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + * Adjusts FCI (see) to use conservative orientation as in CPC (see). Because the + * collider orienatation is conservative, there may be ambiguous triples; these + * may be retrieved using that accessor method. * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 + * @see Fci + * @see #getAmbiguousTriples() */ public final class Cfci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index 2e51e7c6a9..b648e14c5c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -42,7 +42,7 @@ import java.util.List; /** - * Implments Mimbuild using the theory of treks and ranks. + * Implements Mimbuild using the theory of treks and ranks. * * @author adambrodie */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java index 65d47c935d..a7f469de08 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java @@ -38,11 +38,30 @@ import java.util.Set; /** - * A "score" that implmenets implements Chickering and Meek's (2002) locally - * consistent score criterion. This is not a true score; rather, a 0 is returned - * in case dseparation holds and a 1 in case dseparation does not hold. + *

    Implements a pscudo-"score" that implmenets implements Chickering and Meek's + * (2002) locally consistent score criterion. This is not a true score; rather, a + * -1 is returned in case dseparation holds and a 1 in case dseparation does not hold. + * This is only meant to be used in the context of FGES, and allows the + * search to follow its path prescribed by the locally consistent scoring + * criterion. For a reference to the latter, pleasee this article:

    + * + *

    Chickering (2002) "Optimal structure identification with greedy search" + * Journal of Machine Learning Research.

    + * + *

    For further discussion of using d-separation in the GES search, see:

    + * + *

    Nandy, P., Hauser, A., & Maathuis, M. H. (2018). High-dimensional consistency + * in score-based and hybrid structure learning. The Annals of Statistics, 46(6A), + * 3151-3183.

    + * + *

    For more discussion please see:

    + * + *

    Shen, X., Zhu, S., Zhang, J., Hu, S., & Chen, Z. (2022, August). Reframed GES + * with a neural conditional dependence measure. In Uncertainty in Artificial + * Intelligence (pp. 1782-1791). PMLR.

    * * @author josephramsey + * @see Fges */ public class GraphScore implements Score { From cf0cb33c1e3621706af1cb6c32993deb51306507 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 18:23:06 -0400 Subject: [PATCH 368/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/score/ZsbScore.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index f14f3f6adf..e5a28386dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -39,10 +39,25 @@ /** *

    Implements the Zhang-Shen bound score. This is an adaptation of * Theorem 1 in the following:

    + * *

    Zhang, Y., & Shen, X. (2010). Model selection procedure for * high‐dimensional data. Statistical Analysis and Data Mining: The * ASA Data Science Journal, 3(5), 350-358

    * + *

    The score uses Theorem 1 in the above to numerically search + * for a lambda value that is bounded by a given probability risk, + * between 0 and 1, if outputting a local false positive parent for + * a variable. There is a parameter m0, which is a maximum number + * of parents for a particular variable, which is free. The solution + * of this score is to increase m0 from 0 upward, re-evaluating + * with each scoring that is done using that variable as a target + * node. Thus, over time, a lower bound on m0 is estimated with + * more and more precision. So as the score is used in the context + * of FGES or GRaSP, for instance, so long as the score for a given + * node is visited more than once, the scores output by the procedure + * can be expected to improve, though setting m0 to 0 for all variables + * does not give bad results even by itself.

    + * * @author josephramsey */ public class ZsbScore implements Score { From 9c01f19fe58a5f8620a84d039ca6dfc078ea3195 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 18:32:04 -0400 Subject: [PATCH 369/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/score/BdeScore.java | 2 +- .../cmu/tetrad/search/score/BdeuScore.java | 2 +- .../score/ConditionalGaussianScore.java | 21 ++++++++++++++++++- .../edu/cmu/tetrad/search/score/ZsbScore.java | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java index c9e2c154f9..e931414be2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java @@ -32,7 +32,7 @@ /** *

    Calculates the BDe score (Bayes Dirichlet Equivalent) score for analyzing * discrete multinomial data. A good discussion of BD* scores can be found here:

    - *

    Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: + *

    Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). * https://doi.org/10.1007/BF00994016

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java index 500984bf6a..e70eb2417b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java @@ -34,7 +34,7 @@ /** *

    Calculates the BDeu score, which the BDe (Bayes Dirichlet Equivalent) score * with uniform priors. A good discussion of BD* scores can be found here:

    - *

    Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: + *

    Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). * https://doi.org/10.1007/BF00994016

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index f568fc2220..a4df20ebb4 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -34,9 +34,13 @@ import java.util.List; /** - * Implements a conditional Gaussian BIC score for FGS. + * Implements a conditional Gaussian BIC score for FGS, which calculates a BIC + * score for mixed discrete/Gaussian data using the conditional Gaussian + * likelihood function (see). * * @author josephramsey + * @see ConditionalGaussianLikelihood + * @see DegenerateGaussianScore */ public class ConditionalGaussianScore implements Score { @@ -54,6 +58,21 @@ public class ConditionalGaussianScore implements Score { /** * Constructs the score using a covariance matrix. + * + * @param dataSet A dataset with a mixture of continuous and discrete variables. + * It may be all continuous or all discrete. + * @param penaltyDiscount A multiplier on the penalty term in the BIC score. + * @param discretize When a discrete variable is a child of a continuous variable, one + * (expensive) way to solve the problem is to do a numerical integration. + * A less expensive (and often more accurate) way to solve the problem + * is to discretize the child with a certian number of discrete categories. + * if this parameter is set to True, a separate copy of all variables + * is maintained that is discretized in this way, and these are substituted + * for the discrete children when this sort of problem needs to be solved. + * This information needs to be known in the constructor since one needs + * to know right away whether ot create this separate discretized version + * of the continuous columns. + * @see #setNumCategoriesToDiscretize */ public ConditionalGaussianScore(DataSet dataSet, double penaltyDiscount, boolean discretize) { if (dataSet == null) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index e5a28386dd..755577b3cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -40,7 +40,7 @@ *

    Implements the Zhang-Shen bound score. This is an adaptation of * Theorem 1 in the following:

    * - *

    Zhang, Y., & Shen, X. (2010). Model selection procedure for + *

    Zhang, Y., & Shen, X. (2010). Model selection procedure for * high‐dimensional data. Statistical Analysis and Data Mining: The * ASA Data Science Journal, 3(5), 350-358

    * From 8bcd5d2b5f064cb3f47cda5a0756384cc93d3642 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 18:39:11 -0400 Subject: [PATCH 370/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java | 4 ++-- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java | 3 ++- .../src/main/java/edu/cmu/tetrad/search/GrowShrink.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/GicScores.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/GraphScore.java | 4 ++-- .../src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java | 2 +- 15 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index c6966fbe2d..27a7ee9bff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -39,7 +39,7 @@ * clusters of measured variables in a dataset that are explained by single latents. * The algorithm outputs these clusters, which can then be used for further analysis. * The reference is this:

    - *

    Silva, R., Scheines, R., Glymour, C., Spirtes, P., & Chickering, D. M. (2006). + *

    Silva, R., Scheines, R., Glymour, C., Spirtes, P., & Chickering, D. M. (2006). * Learning the Structure of Linear Latent Variable Models. Journal of Machine Learning * Research, 7(2).

    *

    Some more References: 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 299102a258..efbc0fe583 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 @@ -34,7 +34,7 @@ /** *

    Implemented the Cyclic Causal Discovery (CCD) algorithm by Thomas Richardson. * A reference for this is here:

    - *

    Mooij, J. M., & Claassen, T. (2020, August). Constraint-based causal discovery + *

    Mooij, J. M., & Claassen, T. (2020, August). Constraint-based causal discovery * using partial ancestral graphs in the presence of cycles. In Conference on Uncertainty * in Artificial Intelligence (pp. 1159-1168). PMLR.

    *

    See also Chapter 7 of Glymour and Cooper, eds., Computation, Causation, and Discovery

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index b493b59565..21d5f017ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -51,7 +51,7 @@ * *

    This algorithm was described in the earlier edition of this book:

    * - *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, * prediction, and search. MIT press.

    * * @author josephramsey. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index f0d68e4f42..a271e11460 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -49,7 +49,7 @@ *

    This algorithm, with the Spirtes final orientation rules, was given in an earlier version of * this book:

    * - *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, * prediction, and search. MIT press.

    * *

    The algorithm with the Zhang final orintation rules was given in this reference:

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index f2e931e6ac..3dc87a98b0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -42,7 +42,7 @@ * measured variables in a dataset that each be explained by a single latent variable. * A reference is the following

    * - *

    Kummerfeld, E., & Ramsey, J. (2016, August). Causal clustering for 1-factor measurement + *

    Kummerfeld, E., & Ramsey, J. (2016, August). Causal clustering for 1-factor measurement * models. In Proceedings of the 22nd ACM SIGKDD international conference on knowledge * discovery and data mining (pp. 1655-1664).

    * @@ -50,7 +50,7 @@ * a certain pattern in the exchangeability of latent paths with respect to the data). * The notion of vanishng tetrads is old one but is explained in this book:

    * - *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, * prediction, and search. MIT press.

    * * @author peterspirtes diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index d93bba1a33..85bea3dace 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -44,7 +44,7 @@ * a single latent variable. A reference for the one-factor versiono of the algorithm * (FOFC) is the following

    * - *

    Kummerfeld, E., & Ramsey, J. (2016, August). Causal clustering for 1-factor measurement + *

    Kummerfeld, E., & Ramsey, J. (2016, August). Causal clustering for 1-factor measurement * models. In Proceedings of the 22nd ACM SIGKDD international conference on knowledge * discovery and data mining (pp. 1655-1664).

    * 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 037ed4838b..38de2ffb27 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 @@ -23,7 +23,8 @@ *

    Implements the GRaSP algorithms, which uses a certain procedure to search * in the space of permutations of variables for ones that imply CPDAGs that are * especailly close to the CPDAG of the true model. The reference is here:

    - *

    Lam, W. Y., Andrews, B., & Ramsey, J. (2022, August). Greedy relaxations of + * + *

    Lam, W. Y., Andrews, B., & Ramsey, J. (2022, August). Greedy relaxations of * the sparsest permutation algorithm. In Uncertainty in Artificial Intelligence * (pp. 1052-1062). PMLR.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index b7b456d515..011e8a4761 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -30,7 +30,7 @@ /** *

    Implements the Grow-Shrink algorithm of Margaritis and Thrun, a simple yet correct * and useful Markov blanket search.

    - *

    Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. + *

    Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. * Advances in neural information processing systems, 12.

    * * @author josephramsey diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index d9487c55a1..452c01ea97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -47,7 +47,7 @@ *

    Implements the LiNG-D algorithm as well as a number of ancillary * methods for LiNG-D and LiNGAM. The reference is here:

    * - *

    Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering + *

    Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering * cyclic causal models by independent components analysis. arXiv preprint * arXiv:1206.3273.

    * 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 8fd67e0047..dad3b6dd69 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 @@ -47,7 +47,7 @@ * algorithm was proposed earlier than this, but the standard reference for * the algorithm is in Chapter 6 of the following book:

    * - *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, + *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, * prediction, and search. MIT press.

    * *

    A modified rule set capable of dealing effectively with knowledge of required diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 0c475782da..4b97d7ef96 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -27,7 +27,7 @@ *

    This class is meant to be used in the context of the PermutationSearch class (see). * the proper use is PermutationSearch search = new PermutationSearch(new Sp(score));

    * - *

    Raskutti, G., & Uhler, C. (2018). Learning directed acyclic graph models based on + *

    Raskutti, G., & Uhler, C. (2018). Learning directed acyclic graph models based on * sparsest permutations. Stat, 7(1), e183.

    * * @author bryanandrews diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index d1294ab450..0325b211f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -36,7 +36,7 @@ *

    Implements scores motivated by the Generalized Information Criterion (GIC) * approach as given in Kim et al. (2012).

    * - *

    Kim, Y., Kwon, S., & Choi, H. (2012). Consistent model selection criteria on + *

    Kim, Y., Kwon, S., & Choi, H. (2012). Consistent model selection criteria on * high dimensions. The Journal of Machine Learning Research, 13(1), 1037-1057. * Foster and George.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java index a7f469de08..0b48785032 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GraphScore.java @@ -50,13 +50,13 @@ * *

    For further discussion of using d-separation in the GES search, see:

    * - *

    Nandy, P., Hauser, A., & Maathuis, M. H. (2018). High-dimensional consistency + *

    Nandy, P., Hauser, A., & Maathuis, M. H. (2018). High-dimensional consistency * in score-based and hybrid structure learning. The Annals of Statistics, 46(6A), * 3151-3183.

    * *

    For more discussion please see:

    * - *

    Shen, X., Zhu, S., Zhang, J., Hu, S., & Chen, Z. (2022, August). Reframed GES + *

    Shen, X., Zhu, S., Zhang, J., Hu, S., & Chen, Z. (2022, August). Reframed GES * with a neural conditional dependence measure. In Uncertainty in Artificial * Intelligence (pp. 1782-1791). PMLR.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java index 275bbb26f1..3501708f79 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java @@ -44,7 +44,7 @@ * in his Ph.D. dissertation, which is both arrow and tail complete. The * references for these are as follows.

    * - *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). + *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). * Causation, prediction, and search. MIT press.

    * *

    Zhang, J. (2008). On the completeness of orientation rules for causal diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java index 78117afb10..7faaa737eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java @@ -20,7 +20,7 @@ * keep track of the score using the Teyssier and Kohler method. You can move a variable to a new position, * and you can bookmark a state and come back to it. * - *

    Teyssier, M., & Koller, D. (2012). Ordering-based search: A simple and effective algorithm for + *

    Teyssier, M., & Koller, D. (2012). Ordering-based search: A simple and effective algorithm for * learning Bayesian networks. arXiv preprint arXiv:1207.1429.

    * * @author josephramsey From e05d1e7715e7a0e251c37c9512b855908199500a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 18:57:51 -0400 Subject: [PATCH 371/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Bpc.java | 2 +- .../main/java/edu/cmu/tetrad/search/Fasd.java | 1 + .../main/java/edu/cmu/tetrad/search/Fask.java | 12 ++++++------ .../java/edu/cmu/tetrad/search/Mimbuild.java | 2 +- .../main/java/edu/cmu/tetrad/search/Rfci.java | 19 ++++++++++++------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index 27a7ee9bff..c08a4cf9f7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -49,7 +49,7 @@ *

    Bollen, K. (1990). "Outlier screening and distribution-free test for vanishing tetrads." * Sociological Methods and Research 19, 80-92.

    *

    Wishart, J. (1928). "Sampling errors in the theory of two factors". British Journal of - * Psychology 19, 180-187.

    *

    Bron, C. and Kerbosch, J. (1973) "Algorithm 457: Finding all cliques of an undirected graph". * Communications of ACM 16, 575-577.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java index c60cc19436..5ca8abadd9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java @@ -41,6 +41,7 @@ * That is, if X _||_ Y | Z, but Z determines X or Y, then the edge X---Y is * not removed.

    * + * @author peterspirtes * @author josephramsey. * @see Fas */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index c379e28847..cfdb785a4f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -136,16 +136,16 @@ public final class Fask implements IGraphSearch { /** - * The method to use for finding the initial adjacencies for FASK. + * Enumerates the alternatives to use for finding the initial adjacencies for FASK. */ public enum AdjacencyMethod {FAS_STABLE, FGES, EXTERNAL_GRAPH, NONE} /** - * The left-right rule to use for FASK. Options include the FASK left-right rule and three left-right rules - * from the Hyvarinen and Smith pairwise orientation paper: Robust Skew, Skew, and Tanh. In that - * paper, "empirical" versions were given in which the variables are multiplied through by the - * signs of the skewnesses; we follow this advice here (with good results). These others are provided - * for those who prefer them. + * Enumerates the options left-right rules to use for FASK. Options include the FASK left-right + * rule and three left-right rules from the Hyvarinen and Smith pairwise orientation paper: Robust + * Skew, Skew, and Tanh. In that paper, "empirical" versions were given in which the variables are + * multiplied through by the signs of the skewnesses; we follow this advice here (with good results). + * These others are provided for those who prefer them. */ public enum LeftRight {FASK1, FASK2, RSKEW, SKEW, TANH} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 9b0edaa12a..1f7188ea1a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -50,7 +50,7 @@ *

    Specifically, the search will first infer the covariance matrix over the * latents and then will use the GRaSP algorithm (see) to infer the structure * graph over the latents, using the SEM Bic score with the given penalty discount - * (default 2).

    * *

    One may wish to obtain the implied correlation matrix over the latents and * run one's own choice of CPDDAG algroithm on it with one's on test or score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index a14e812d83..94d26cb113 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -38,18 +38,23 @@ /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

    - * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is - * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + *

    Implements the Really Fast Causal Inference (RFCI) algorithm, which aims to + * do a correct inference of inferrable causal structure under the assumption + * that unmeasured common causes of variables in the data may exist. The graph + * returned is slightly different from the partial ancestral graph (PAG) returned + * by the FCI algorithm. The goal of of the algorithm is to avoid certain + * expensive steps in the FCI procedure in a correct way. This was introduced + * here:

    + * + *

    Colombo, D., Maathuis, M. H., Kalisch, M., & Richardson, T. S. (2012). Learning + * high-dimensional directed acyclic graphs with latent and selection variables. The + * Annals of Statistics, 294-321.

    * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 * @author josephramsey * @author Choh-Man Teng + * @see Fci */ public final class Rfci implements IGraphSearch { From 4830c613411e43b54d7c83a72a61e0d5f43f1f57 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 18:59:37 -0400 Subject: [PATCH 372/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java | 2 +- .../src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java | 2 +- .../cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java | 2 +- .../algcomparison/simulation/TimeSeriesSemSimulation.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java index 766fdf2e8d..abed21dbbe 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java @@ -31,7 +31,7 @@ /** * @author Tyler Gibson - * @author Daniel Malinsky + * @author danielmalinsky */ public class TsPagFromDagGraphWrapper extends GraphWrapper implements DoNotAddOldModel { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java index 0f14b2304f..9bb2d118f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java @@ -60,7 +60,7 @@ * and a list of parameters and their values. * * @author josephramsey - * @author Daniel Malinsky + * @author danielmalinsky */ public class Comparison { 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/SvarGfci.java index 5369370c21..78de3875b0 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/SvarGfci.java @@ -29,7 +29,7 @@ * SvarFCI. * * @author josephramsey - * @author Daniel Malinsky + * @author danielmalinsky */ @edu.cmu.tetrad.annotation.Algorithm( name = "SvarGFCI", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java index 4cde2c0e65..d4b271f577 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java @@ -22,7 +22,7 @@ /** * @author josephramsey - * @author Daniel Malinsky + * @author danielmalinsky */ public class TimeSeriesSemSimulation implements Simulation, HasKnowledge { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 36d89ca94e..b1ccc38858 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -47,7 +47,7 @@ * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. * (By a remark of Zhang's, the rule applications can be staged in this way.) * - * @author Daniel Malinsky + * @author danielmalinsky * @see Fci */ public final class SvarFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java index 98872f0fd2..9b3bb047ff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java @@ -56,7 +56,7 @@ * *

    A number of other optimizations were added 5/2015. See code for details.

    * - * @author Daniel Malinsky + * @author danielmalinsky * @see Fges */ public final class SvarFges implements IGraphSearch, DagScorer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 688a50a9df..79211273cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -45,7 +45,7 @@ /** * Adapts GFCI to the SVAR case. * - * @author Daniel Malinsky + * @author danielmalinsky * @see GFci */ public final class SvarGfci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java index 206b8f2329..e6c9c4f622 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java @@ -35,7 +35,7 @@ /** * This class finds the PAG to which a DAG belongs, for a time series model. * - * @author Daniel Malinsky + * @author danielmalinsky * @see Fci * @see DagToPag */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java index 5dfa7612b9..1504fedb1e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java @@ -47,7 +47,7 @@ * by somebody. * * @author josephramsey - * @author Daniel Malinsky (some improvements) + * @author danielmalinsky (some improvements) */ public class TsUtils { From 1dcfea74a4adbfd8085cce910dc623d40684269e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 19:13:28 -0400 Subject: [PATCH 373/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 1 + .../src/main/java/edu/cmu/tetrad/search/GraspFci.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 1 + .../main/java/edu/cmu/tetrad/search/test/IndTestHsic.java | 6 +++--- .../cmu/tetrad/search/{work_in_progress => utils}/Bes.java | 2 +- .../java/edu/cmu/tetrad/search/utils/BesPermutation.java | 1 - .../edu/cmu/tetrad/search/{kernel => utils}/Kernel.java | 2 +- .../cmu/tetrad/search/{kernel => utils}/KernelGaussian.java | 2 +- .../cmu/tetrad/search/{kernel => utils}/KernelUtils.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java | 4 ++-- .../test/java/edu/cmu/tetrad/test/TestKernelGaussian.java | 2 +- 13 files changed, 15 insertions(+), 12 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{work_in_progress => utils}/Bes.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{kernel => utils}/Kernel.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{kernel => utils}/KernelGaussian.java (99%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{kernel => utils}/KernelUtils.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 7061e4d475..18213c4c56 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -50,6 +50,7 @@ * @see GFci * @see GraspFci * @see SpFci + * @see Fges */ public final class BFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 8a937699f7..84d7d229a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.search.utils.DagScorer; import edu.cmu.tetrad.search.utils.GraphUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; -import edu.cmu.tetrad.search.work_in_progress.Bes; +import edu.cmu.tetrad.search.utils.Bes; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index ccf670846d..67220ffd71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -64,6 +64,7 @@ * @see GraspFci * @see BFci * @see SpFci + * @see Fges */ public final class GFci implements IGraphSearch { private Graph graph; 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 417dfbe66e..4bf1f231bd 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 @@ -53,6 +53,7 @@ * @see GFci * @see BFci * @see SpFci + * @see Fges */ public final class GraspFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index a0b79973a6..791d2e9754 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -59,6 +59,7 @@ * @see GFci * @see BFci * @see GraspFci + * @see Fges */ public final class SpFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java index 798c6911d3..0c45a69d31 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java @@ -28,9 +28,9 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.kernel.Kernel; -import edu.cmu.tetrad.search.kernel.KernelGaussian; -import edu.cmu.tetrad.search.kernel.KernelUtils; +import edu.cmu.tetrad.search.utils.Kernel; +import edu.cmu.tetrad.search.utils.KernelGaussian; +import edu.cmu.tetrad.search.utils.KernelUtils; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RandomUtil; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Bes.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Bes.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Bes.java index a57505b012..8c5ea2ad73 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Bes.java @@ -1,4 +1,4 @@ -package edu.cmu.tetrad.search.work_in_progress; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java index c7e552b064..969928ded1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.work_in_progress.Bes; import edu.cmu.tetrad.search.Boss; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.Score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/Kernel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/Kernel.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java index 5db02ac387..4ff6134b37 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/Kernel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.kernel; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/KernelGaussian.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelGaussian.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/KernelGaussian.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelGaussian.java index eef48509d4..97299d0c0b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/KernelGaussian.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelGaussian.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.kernel; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/KernelUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelUtils.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/KernelUtils.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelUtils.java index 99654c1cad..0e7492fb6e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/kernel/KernelUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelUtils.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.kernel; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java index 255fe1514a..da23d0cf9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java @@ -38,11 +38,11 @@ import java.util.List; /** - *

    >Tries to find a good shifting of variables to minimize average BIC for + *

    Tries to find a good shifting of variables to minimize average BIC for * time-series data. The idea is that the data one is presented with may have * the variables temporally shifted with respect to one another. ShiftSearch * attempts to find a shifting of the variables that reduces this temporal - * shifting. + * shifting.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKernelGaussian.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKernelGaussian.java index 8d4fc4f580..3b5fe52ae1 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKernelGaussian.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestKernelGaussian.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.VerticalDoubleDataBox; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.kernel.KernelGaussian; +import edu.cmu.tetrad.search.utils.KernelGaussian; import org.junit.Test; import java.util.Collections; From b7d31554fe4f5f4d31ccfed90ad5ab38c42b1880 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 21:50:04 -0400 Subject: [PATCH 374/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/search/utils/BayesImParser.java | 2 +- .../tetrad/search/utils/BpcAlgorithmType.java | 2 +- .../cmu/tetrad/search/utils/BpcTestType.java | 2 +- .../search/utils/ClusterSignificance.java | 2 +- .../cmu/tetrad/search/utils/ClusterUtils.java | 2 +- .../search/utils/DagInCpcagIterator.java | 5 +++-- .../cmu/tetrad/search/utils/DagIterator.java | 4 ++-- .../cmu/tetrad/search/utils/FgesOrienter.java | 19 +++---------------- .../cmu/tetrad/search/utils/GraphChange.java | 3 ++- .../cmu/tetrad/search/utils/GraphInPag.java | 2 +- .../tetrad/search/utils/GraphUtilsSearch.java | 3 +-- .../tetrad/search/utils/GrowShrinkTree.java | 2 +- .../search/utils/HasPenaltyDiscount.java | 2 +- .../search/utils/HungarianAlgorithm.java | 4 ++-- .../edu/cmu/tetrad/search/utils/IPurify.java | 2 +- .../edu/cmu/tetrad/search/utils/Kernel.java | 3 ++- .../tetrad/search/utils/KernelGaussian.java | 3 ++- .../cmu/tetrad/search/utils/KernelUtils.java | 2 +- .../cmu/tetrad/search/utils/LegalPairs.java | 5 +++-- .../edu/cmu/tetrad/search/utils/MbUtils.java | 2 +- .../edu/cmu/tetrad/search/utils/MimUtils.java | 2 +- .../edu/cmu/tetrad/search/utils/PcCommon.java | 2 +- .../tetrad/search/utils/PossibleDsepFci.java | 2 +- .../edu/cmu/tetrad/search/utils/Purify.java | 5 +++-- .../tetrad/search/utils/PurifyScoreBased.java | 5 +++-- .../search/utils/PurifySextadBased.java | 4 ++-- .../search/utils/PurifyTetradBased.java | 4 ++-- .../tetrad/search/utils/ResolveSepsets.java | 6 +++--- .../tetrad/search/utils/SepsetProducer.java | 3 ++- .../search/utils/SepsetsConservative.java | 6 +++--- .../tetrad/search/utils/SepsetsGreedy.java | 4 ++-- .../search/utils/SepsetsPossibleDsep.java | 4 ++-- .../cmu/tetrad/search/utils/SepsetsSet.java | 3 ++- .../cmu/tetrad/search/utils/TetradTest.java | 2 +- .../search/utils/TetradTestDiscrete.java | 2 +- .../search/utils/TetradTestPopulation.java | 4 ++-- .../cmu/tetrad/search/utils/TsDagToPag.java | 2 +- 37 files changed, 63 insertions(+), 68 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java index a295613197..7ceb03026b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java @@ -37,7 +37,7 @@ import java.util.Map; /** - * This class takes an xml element representing a bayes im and converts it to + * Takes an xml element representing a bayes im and converts it to * a BayesIM * * @author mattheweasterday diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java index b6c7010de2..cf91eb2f89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.util.TetradSerializable; /** - * An enumeration of the test types for BuildPureClusters, and Purify. + * Enumerates the algorihtm types for BuildPureClusters, and Purify. */ public enum BpcAlgorithmType implements TetradSerializable { BUILD_PURE_CLUSTERS, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java index 926259f688..f0eb6a50fb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.util.TetradSerializable; /** - * An enumeration of the test types for BuildPureClusters, and Purify. + * Enumerates the test types for BuildPureClusters, and Purify. */ public enum BpcTestType implements TetradSerializable { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java index edd36bdda0..de2540ed36 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java @@ -18,7 +18,7 @@ import java.util.Set; /** - *

    Some methods to check significance of clusters for clustering algroithms. It is assumed + *

    Provides some methods to check significance of clusters for clustering algroithms. It is assumed * that for each cluster there is a single latent that is a parent of all the nodes * in the cluster. Significance of these models is returned.

    *

    The methods in this class are used only internally and so have package scope only.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java index f73914f18d..83edca84b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterUtils.java @@ -31,7 +31,7 @@ import java.util.Set; /** - *

    Some general utilities for dealing with clustering input and output.

    + *

    Provides some general utilities for dealing with clustering input and output.

    *

    The method of this class are used only internally and so are not documented * for public use.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java index 39ad47e44d..edc440e464 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagInCpcagIterator.java @@ -27,8 +27,9 @@ import java.util.*; /** - * Given a pattern, lists all of the DAGs in that pattern. In the form of an iterator--call hasNext() to see if there's - * another one and next() to get it. next() will return null if there are no more. + * Given a CPDAG, lists all the DAGs in that DPCAG. In the form of an iterator-- + * call hasNext() to see if there's another one and next() to get it. next() will + * return null if there are no more. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java index 5aaa6eeec5..662ccb7476 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DagIterator.java @@ -29,8 +29,8 @@ import java.util.LinkedList; /** - * Given a graph, lists all DAGs that result from directing the undirected edges in that graph every possible way. Uses - * a Meek-algorithm-type method. + * Given a graph, lists all DAGs that result from directing the undirected edges in + * that graph every possible way. Uses a Meek-algorithm-type method. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java index d27205e12b..ad2567d673 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java @@ -35,24 +35,11 @@ /** - * GesSearch is an implementation of the GES algorithm, as specified in Chickering (2002) "Optimal structure - * identification with greedy search" Journal of Machine Learning Research. It works for both BayesNets and SEMs. - *

    - * Some code optimization could be done for the scoring part of the graph for discrete models (method scoreGraphChange). - * Some of Andrew Moore's approaches for caching sufficient statistics, for instance. - *

    - * To speed things up, it has been assumed that variables X and Y with zero correlation do not correspond to edges in - * the graph. This is a restricted form of the faithfulness assumption, something GES does not assume. This - * faithfulness assumption needs to be explicitly turned on using setHeuristicSpeedup(true). - *

    - * A number of other optimizations were added 5/2015. See code for details. - * - * @author Ricardo Silva, Summer 2003 - * @author josephramsey, Revisions 5/2015 - *

    * This Orients a given undirected graph such that the edges in the graph are a superset - * of the edges in the oriented graph + * of the edges in the oriented graph, using FGES method. + * * @author AJ Sedgewick, 5/2015 + * @see Fges */ public final class FgesOrienter implements IGraphSearch, DagScorer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java index 76f3515038..77bfcd75ac 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java @@ -27,13 +27,14 @@ /** - *

    GraphChange is a data structure created mainly for use in the ION search algorithm. + *

    Provides s a data structure created mainly for use in the ION search algorithm. * However, it models a general concept: storage for a variety of seperate changes one could * possibly apply to a PAG.

    *

    By convention, the NodePairs in the orients ArrayList are ordered such that Node1 is the * "from" node and Node2 is the "to" node (ie 1 o-> 2).

    * * @author Trevor Burns + * @see Ion */ public class GraphChange { private final List removes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java index b084e64038..77f7a8fab4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java @@ -30,7 +30,7 @@ import java.util.Set; /** - * This class contains methods which can be used to determine whether a directed graph + * Contains methods which can be used to determine whether a directed graph * is in the equivalence class determined by the given PAG. See p. 300 Def. 12.1.1 of * CPS for a specification. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java index 96983371ef..2c5db955fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java @@ -41,8 +41,7 @@ import static org.apache.commons.math3.util.FastMath.max; /** - * Graph utilities for search algorithm. Lots of orientation method, for - * instance. + * Provides some graph utilities for search algorithm. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java index 7aabeaa540..70e998aa1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java @@ -7,7 +7,7 @@ import java.util.*; /** - *

    A tree-based score-caching data structure useful for permutation searches. + *

    Provides a tree-based score-caching data structure useful for permutation searches. * The use of this caching data structure speeds these algorithms up * significantly.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java index 793e0d7b00..01a1e36459 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HasPenaltyDiscount.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.search.score.Score; /** - * Interface for an algorithm can can get/set a value for penalty disoucnt. + * Provides an interface for an algorithm can can get/set a value for penalty disoucnt. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HungarianAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HungarianAlgorithm.java index 1e07dc62d3..d60f2a1f2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HungarianAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/HungarianAlgorithm.java @@ -5,8 +5,8 @@ import java.util.Set; /** - *

    An implemetation of the Kuhn–Munkres assignment algorithm of the year 1957. - * ....

    + *

    Provides an implemetation of the Kuhn–Munkres assignment algorithm of + * the year 1957. https://en.wikipedia.org/wiki/Hungarian_algorithm.

    *

    From: https://github.com/aalmi/HungarianAlgorithm

    *

    This is not our code; please see the references given. We've just * made a few tweaks to make it work better in Tetrad. Thanks aalmi.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java index b29c3f64e4..eaec254fd8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java @@ -27,7 +27,7 @@ import java.util.List; /** - * An interface for Purify algorithm. + * Provides an interface for Purify algorithm. * @author josephramsey */ public interface IPurify { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java index 4ff6134b37..8773725a89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java @@ -25,7 +25,8 @@ import edu.cmu.tetrad.graph.Node; /** - * Interface implemented by classes that evaluate scalar valued kernels + * Gives an implemented that is implemented by classes that evaluate scalar + * valued kernels * * @author Robert Tillman */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelGaussian.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelGaussian.java index 97299d0c0b..fb122be158 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelGaussian.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelGaussian.java @@ -26,7 +26,8 @@ import org.apache.commons.math3.util.FastMath; /** - * Gaussian kernel for a given bandwidth. Default bandwidth is set using the median distance heuristic. + * Soces the Gaussian kernel for a given bandwidth. Default bandwidth is set using the + * median distance heuristic. * * @author Robert Tillman */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelUtils.java index 0e7492fb6e..151f66fe0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/KernelUtils.java @@ -29,7 +29,7 @@ import java.util.List; /** - * Various kernel utilities + * Provides various kernel utilities. * * @author Robert Tillman */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java index 6cdfe77acb..07117ab286 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/LegalPairs.java @@ -26,8 +26,9 @@ import java.util.List; /** - * Determines whether nodes indexed as (n1, center, n2) form a legal pair of edges in a graph for purposes of some - * algorithm that uses this information. The pair would be n1---center---n2. + * Determines whether nodes indexed as (n1, center, n2) form a legal pair of + * edges in a graph for purposes of some algorithm that uses this information. + * The pair would be n1---center---n2. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java index e047f63279..4a4872e3e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java @@ -28,7 +28,7 @@ import java.util.*; /** - * Some useful utilities for dealing with Markov blankets and Markov blanket DAGs. + * Provides some useful utilities for dealing with Markov blankets and Markov blanket DAGs. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MimUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MimUtils.java index 4168502edd..857687542b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MimUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MimUtils.java @@ -29,7 +29,7 @@ import java.util.List; /** - * Holds some utility methods for Purify, Build Clusters, and Mimbuild. + * Provides some utility methods for Purify, Build Clusters, and Mimbuild. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java index 5932e0b2ea..d07281bc34 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java @@ -36,7 +36,7 @@ import java.util.Set; /** - * Common implementation of variaous PC-like algorithms, with options for + * Prodies some common implementation pieces of variaous PC-like algorithms, with options for * collider discovery type, FAS type, and conflict rule. * * @author josephramsey diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDsepFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDsepFci.java index 67dfa31ff9..a5d4268ca0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDsepFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDsepFci.java @@ -36,7 +36,7 @@ import java.util.List; /** - * This class implements the Possible-D-Sep search step of Spirtes, et al's (1993) FCI algorithm (pp 144-145). + * Implements the Possible-D-Sep search step of Spirtes, et al's (1993) FCI algorithm (pp 144-145). * Specifically, the methods in this class perform step D. of the algorithm. The algorithm implemented by this * class is a bit broader, however, because it allows for the possibility that some pairs of variables have already been * compared by a different algorithm. Specifically, if the prevCheck variable is provided in the diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java index 3abc74ecf4..fe16b35a49 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java @@ -35,8 +35,9 @@ import java.util.*; /** - * Purify is a implementation of the automated purification methods described on CPS and the report "Learning - * Measurement Models" CMU-CALD-03-100. + * Implements the Purify algorithm, which is a implementation of the automated + * purification methods described on CPS and the report "Learning Measurement Models" + * CMU-CALD-03-100. *

    * No background knowledge is allowed yet. Future versions of this algorithm will include it. *

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java index 9dafe0b9d2..a904109756 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyScoreBased.java @@ -34,8 +34,9 @@ import java.util.*; /** - * Created by IntelliJ IDEA. User: josephramsey Date: May 17, 2010 Time: 6:17:53 PM To change this template use File | - * Settings | File Templates. + * Implements a score-based Purify method. + * + * @author ricardosilva */ public class PurifyScoreBased implements IPurify { private final boolean outputMessage = true; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java index af1bb46715..ecbbb13258 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifySextadBased.java @@ -30,9 +30,9 @@ // EXPERIMENTAL!! /** - * A clean-up of Ricardo's Sextad-based purify. + * Implments a sextad-based Purify method. * - * @author Joe Ramsey + * @author ricardosilva */ public class PurifySextadBased { private final DeltaSextadTest sextadTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyTetradBased.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyTetradBased.java index fa911dd505..c8854fb0be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyTetradBased.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PurifyTetradBased.java @@ -29,9 +29,9 @@ import java.util.*; /** - * A clean-up of Ricardo's tetrad-based purify. + * Implements a tetrad-based purify method. * - * @author Joe Ramsey + * @author ricardosilva */ public class PurifyTetradBased implements IPurify { private final TetradTest tetradTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java index 49d1e1f076..97f3daca0a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java @@ -36,10 +36,10 @@ import java.util.List; /** - * Utilities for resolving inconsistencies that arise between sepsets learned for overlapping datasets. This occurs - * frequently when using the DCI and ION algorithm. f + * Provides some utilities for resolving inconsistencies that arise between sepsets + * learned for overlapping datasets. This occurs frequently when using the DCI and ION algorithm. * - * @author Robert Tillman + * @author roberttillman */ public final class ResolveSepsets { public enum Method { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java index f12c7cfc45..b465dc0f70 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java @@ -27,7 +27,8 @@ import java.util.List; /** - *

    A covenience structure that can generate and keep track of sepsets

    + *

    Provides a covenience interface for classes that can generate and keep + * track of sepsets.

    * * @author josephramsey * @see SepsetMap diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java index 8ff94f512f..5a2d219588 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsConservative.java @@ -34,9 +34,9 @@ import java.util.List; /** - *

    A SepsetProcuder that selects the first sepset it comes to from among the extra - * sepsets or the adjacents of i or k, or null if none is found. This version uses - * conservative reasoning (see the CPC algorithm).

    + *

    Provides a SepsetProcuder that selects the first sepset it comes to from + * among the extra sepsets or the adjacents of i or k, or null if none is found. + * This version uses conservative reasoning (see the CPC algorithm).

    * * @author josephramsey * @see SepsetProducer diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java index 1edec4238d..58cf4092b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsGreedy.java @@ -33,8 +33,8 @@ import java.util.List; /** - *

    A SepsetProcuder that selects the first sepset it comes to from among the extra - * sepsets or the adjacents of i or k, or null if none is found.

    + *

    Provides a SepsetProcuder that selects the first sepset it comes to from + * among the extra sepsets or the adjacents of i or k, or null if none is found.

    * * @author josephramsey * @see SepsetProducer diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java index 4dfacde63f..6ea554a3dc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsPossibleDsep.java @@ -34,8 +34,8 @@ import java.util.List; /** - *

    A sepset producer using conditional independence tests to generate the Sepset map, - * for the case where possible dsep sets are required.

    + *

    Provides a sepset producer using conditional independence tests to generate + * the Sepset map, for the case where possible dsep sets are required.

    * * @author josephramsey * @see SepsetProducer diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java index 15f3e117f1..2eb64bbe46 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetsSet.java @@ -28,7 +28,8 @@ import java.util.List; /** - *

    A sepset producer using conditional independence tests to generate the Sepset map.

    + *

    Provides a sepset producer using conditional independence tests to generate + * the Sepset map.

    * * @author josephramsey * @see SepsetProducer diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java index bfd7f9f342..20c87aa612 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java @@ -28,7 +28,7 @@ import java.util.List; /** - * Interface implemented by classes that test tetrad constraints. For the continuous case, + * Provides an interface for classes that test tetrad constraints. For the continuous case, * we have a variety of tests, including a distribution-free one (which may not be * currently practical when the number of variables is too large). * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestDiscrete.java index 20062f7bea..5056615212 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestDiscrete.java @@ -33,7 +33,7 @@ //import edu.cmu.tetrad.sem.MimBuildEstimator; /** - * Implementation of a test of tetrad constraints with discrete variables. We are assuming that variables are ordinal or + * Implements a test of tetrad constraints with discrete variables. We are assuming that variables are ordinal or * binary. Such tests are a core statistical procedure in algorithm BuildPureClusters and Purify. An "underlying * latent variable" approach is used to test tetrads indirectly by fitting discrete one-factor and two-factor models. * See Bartholomew and Knott (1999) for details. A two-stage procedure for fitting polychorics correlations (Olsson, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestPopulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestPopulation.java index a1726398e6..0db373b5e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestPopulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestPopulation.java @@ -30,8 +30,8 @@ import java.util.List; /** - * Implements a test of tetrad constraints in a known correlation matrix. It might be useful for debugging - * BuildPureClusters/Purify-like algorithm. + * Implements a test of tetrad constraints in a known correlation matrix. It might be + * useful for debugging BuildPureClusters/Purify-like algorithm. * * @author Ricardo Silva */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java index e6c9c4f622..3ae7370470 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsDagToPag.java @@ -33,7 +33,7 @@ /** - * This class finds the PAG to which a DAG belongs, for a time series model. + * Finds the PAG to which a DAG belongs, for a time series model. * * @author danielmalinsky * @see Fci From 4519723ce7542166edb5ac1b5af16ab8315b89d7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 22:05:57 -0400 Subject: [PATCH 375/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetradapp/editor/CPDAGDisplay.java | 8 +-- .../edu/cmu/tetradapp/editor/PagColorer.java | 4 +- .../tetradapp/editor/ScoredGraphsDisplay.java | 4 +- .../KnowledgeEditorToolbar.java | 4 +- .../cmu/tetradapp/model/CPDAGFitModel.java | 8 +-- .../model/CPDAGFromDagGraphWrapper.java | 4 +- .../tetradapp/model/DagInCPDAGWrapper.java | 4 +- .../model/EdgewiseComparisonModel.java | 8 +-- .../model/ExtractStructureModelWrapper.java | 4 +- .../edu/cmu/tetradapp/model/FasRunner.java | 4 +- .../edu/cmu/tetradapp/model/FciRunner.java | 4 +- .../model/GeneralAlgorithmRunner.java | 4 +- .../cmu/tetradapp/model/MagInPagWrapper.java | 4 +- .../tetradapp/model/Misclassifications.java | 6 +-- .../model/PValueImproverWrapper.java | 6 +-- .../model/PagFromDagGraphWrapper.java | 4 +- .../edu/cmu/tetradapp/model/PcRunner.java | 4 +- .../tetradapp/model/SampleVcpcFastRunner.java | 5 +- .../cmu/tetradapp/model/SampleVcpcRunner.java | 5 +- .../tetradapp/model/ScoredGraphsWrapper.java | 4 +- .../cmu/tetradapp/model/VcpcFastRunner.java | 5 +- .../edu/cmu/tetradapp/model/VcpcRunner.java | 5 +- .../cmu/tetradapp/workbench/LayoutUtils.java | 4 +- .../cmu/tetrad/algcomparison/Comparison.java | 14 +++--- .../algcomparison/TimeoutComparison.java | 8 +-- .../algcomparison/algorithm/cluster/Bpc.java | 4 +- .../algcomparison/algorithm/cluster/Fofc.java | 4 +- .../algcomparison/algorithm/cluster/Ftfc.java | 4 +- .../algorithm/multi/FgesConcatenated.java | 4 +- .../algorithm/oracle/cpdag/Cpc.java | 4 +- .../algorithm/oracle/cpdag/Fas.java | 4 +- .../oracle/cpdag/FgesMeasurement.java | 4 +- .../algorithm/oracle/cpdag/GesMe.java | 4 +- .../algorithm/oracle/cpdag/Pc.java | 4 +- .../algorithm/oracle/cpdag/PcMax.java | 4 +- .../algorithm/oracle/cpdag/Pcd.java | 4 +- .../algorithm/oracle/pag/Bfci.java | 2 +- .../algorithm/oracle/pag/Cfci.java | 2 +- .../algorithm/oracle/pag/Fci.java | 2 +- .../algorithm/oracle/pag/FciMax.java | 2 +- .../algorithm/oracle/pag/Gfci.java | 2 +- .../algorithm/oracle/pag/GraspFci.java | 2 +- .../algorithm/oracle/pag/PagSampleRfci.java | 2 +- .../algorithm/oracle/pag/Rfci.java | 2 +- .../algorithm/oracle/pag/RfciBsc.java | 2 +- .../algorithm/oracle/pag/SpFci.java | 2 +- .../algcomparison/statistic/BicDiff.java | 6 +-- .../statistic/BicDiffPerRecord.java | 6 +-- .../algcomparison/statistic/BicEst.java | 4 +- .../algcomparison/statistic/BicTrue.java | 4 +- .../algcomparison/statistic/BidirectedFP.java | 2 +- .../statistic/BidirectedPrecision.java | 2 +- .../statistic/BidirectedRecall.java | 2 +- .../algcomparison/statistic/BidirectedTP.java | 2 +- .../statistic/BidirectedTrue.java | 2 +- ...CommonAncestorFalseNegativeBidirected.java | 2 +- .../DefiniteDirectedPathPrecision.java | 4 +- .../statistic/DefiniteDirectedPathRecall.java | 4 +- ...CommonAncestorFalseNegativeBidirected.java | 2 +- .../algcomparison/statistic/LegalPag.java | 4 +- .../statistic/MaximalityCondition.java | 4 +- .../NoAlmostCyclicPathsInMagCondition.java | 4 +- .../NoCyclicPathsInMagCondition.java | 4 +- .../statistic/NoSemidirectedPrecision.java | 4 +- .../statistic/NoSemidirectedRecall.java | 4 +- ...mpatibleDefiniteDirectedEdgeAncestors.java | 4 +- .../NumCompatibleDirectedEdgeConfounded.java | 4 +- .../statistic/NumCompatibleEdges.java | 4 +- ...mpatiblePossiblyDirectedEdgeAncestors.java | 4 +- ...tiblePossiblyDirectedEdgeNonAncestors.java | 4 +- .../NumCompatibleVisibleAncestors.java | 4 +- .../NumCompatibleVisibleNonancestors.java | 4 +- .../statistic/NumDefinitelyDirected.java | 4 +- .../NumDefinitelyNotDirectedPaths.java | 4 +- .../statistic/NumDirectedEdgeVisible.java | 4 +- .../statistic/NumPossiblyDirected.java | 4 +- .../statistic/PagAdjacencyPrecision.java | 2 +- .../statistic/PagAdjacencyRecall.java | 2 +- .../tetrad/algcomparison/statistic/Shd.java | 4 +- .../calibration/DataForCalibrationRfci.java | 4 +- .../java/edu/cmu/tetrad/graph/GraphUtils.java | 6 +-- .../main/java/edu/cmu/tetrad/search/BFci.java | 8 +-- .../main/java/edu/cmu/tetrad/search/Cfci.java | 8 +-- .../main/java/edu/cmu/tetrad/search/Cpc.java | 6 +-- .../main/java/edu/cmu/tetrad/search/Fask.java | 4 +- .../main/java/edu/cmu/tetrad/search/Fges.java | 4 +- .../main/java/edu/cmu/tetrad/search/GFci.java | 8 +-- .../java/edu/cmu/tetrad/search/GraspFci.java | 8 +-- .../main/java/edu/cmu/tetrad/search/Pc.java | 6 +-- .../java/edu/cmu/tetrad/search/PcLingam.java | 6 +-- .../java/edu/cmu/tetrad/search/PcMax.java | 6 +-- .../main/java/edu/cmu/tetrad/search/PcMb.java | 4 +- .../main/java/edu/cmu/tetrad/search/Pcd.java | 6 +-- .../java/edu/cmu/tetrad/search/SpFci.java | 10 ++-- .../edu/cmu/tetrad/search/SvarFciOrient.java | 10 ++-- .../java/edu/cmu/tetrad/search/SvarGfci.java | 10 ++-- .../cmu/tetrad/search/utils/FciOrient.java | 11 ++--- .../cmu/tetrad/search/utils/FgesOrienter.java | 2 +- ...UtilsSearch.java => GraphSearchUtils.java} | 49 ++++++++++++------- .../edu/cmu/tetrad/search/utils/MaxP.java | 4 +- .../edu/cmu/tetrad/search/utils/MbUtils.java | 2 +- .../edu/cmu/tetrad/search/utils/PcCommon.java | 28 ++++++++++- .../tetrad/search/utils/ResolveSepsets.java | 12 ++++- .../search/work_in_progress/HbsmsBeam.java | 6 +-- .../search/work_in_progress/HbsmsGes.java | 8 +-- .../tetrad/search/work_in_progress/Ion.java | 4 +- .../tetrad/search/work_in_progress/Kpc.java | 6 +-- .../search/work_in_progress/SampleVcpc.java | 14 +++--- .../work_in_progress/SampleVcpcFast.java | 10 ++-- .../tetrad/search/work_in_progress/VcPc.java | 4 +- .../search/work_in_progress/VcPcAlt.java | 14 +++--- .../search/work_in_progress/VcPcFast.java | 8 +-- .../tetrad/simulation/GdistanceRandom.java | 6 +-- .../edu/cmu/tetrad/simulation/HsimAutoC.java | 4 +- .../cmu/tetrad/simulation/HsimAutoRun.java | 4 +- .../tetrad/simulation/HsimEvalFromData.java | 4 +- .../tetrad/simulation/HsimRobustCompare.java | 4 +- .../edu/cmu/tetrad/simulation/HsimRun.java | 6 +-- .../edu/cmu/tetrad/simulation/HsimUtils.java | 4 +- .../edu/cmu/tetrad/study/RBExperiments.java | 8 +-- .../tetrad/study/performance/Comparison.java | 14 +++--- .../tetrad/study/performance/Comparison2.java | 18 +++---- .../study/performance/PerformanceTests.java | 32 ++++++------ .../performance/PerformanceTestsDan.java | 2 +- .../edu/pitt/csb/mgm/ExploreIndepTests.java | 10 ++-- .../constraint/search/PagSamplingRfci.java | 4 +- .../bayesian/constraint/search/RfciBsc.java | 4 +- .../tetrad/test/TestDagInPatternIterator.java | 6 +-- .../cmu/tetrad/test/TestEdgeListGraph.java | 4 +- .../java/edu/cmu/tetrad/test/TestFci.java | 4 +- .../java/edu/cmu/tetrad/test/TestFges.java | 16 +++--- .../java/edu/cmu/tetrad/test/TestGFci.java | 8 +-- .../test/TestGeneralResamplingTest.java | 10 ++-- .../java/edu/cmu/tetrad/test/TestGrasp.java | 12 ++--- .../edu/cmu/tetrad/test/TestMimbuild.java | 6 +-- .../test/java/edu/cmu/tetrad/test/TestPc.java | 6 +-- .../java/edu/cmu/tetrad/test/TestRfciBsc.java | 6 +-- 137 files changed, 427 insertions(+), 387 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/{GraphUtilsSearch.java => GraphSearchUtils.java} (97%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java index eeab7ac3b7..4f5252d183 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.workbench.DisplayEdge; @@ -49,7 +49,7 @@ public class CPDAGDisplay extends JPanel implements GraphEditable { private GraphWorkbench workbench; public CPDAGDisplay(Graph graph) { - List dags = GraphUtilsSearch.generateCpdagDags(graph, false); + List dags = GraphSearchUtils.generateCpdagDags(graph, false); if (dags.size() == 0) { JOptionPane.showMessageDialog( @@ -81,7 +81,7 @@ public CPDAGDisplay(Graph graph) { String option = (String) box.getSelectedItem(); if ("Orient --- only".equals(option)) { - List _dags = GraphUtilsSearch.generateCpdagDags(graph, false); + List _dags = GraphSearchUtils.generateCpdagDags(graph, false); dags.clear(); dags.addAll(_dags); SpinnerNumberModel model1 = @@ -97,7 +97,7 @@ public CPDAGDisplay(Graph graph) { totalLabel.setText(" of " + dags.size()); CPDAGDisplay.this.workbench.setGraph(dags.get(0)); } else if ("Orient ---, <->".equals(option)) { - List _dags = GraphUtilsSearch.generateCpdagDags(graph, true); + List _dags = GraphSearchUtils.generateCpdagDags(graph, true); dags.clear(); dags.addAll(_dags); SpinnerNumberModel model1 = diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java index 3685c93676..cde3377865 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PagColorer.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetradapp.workbench.GraphWorkbench; import javax.swing.*; @@ -60,7 +60,7 @@ public PagColorer(GraphWorkbench workbench) { breakDown("Would you like to verify that this is a legal PAG?", 60), "Legal PAG check", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (ret == JOptionPane.YES_NO_OPTION) { - GraphUtilsSearch.LegalPagRet legalPag = GraphUtilsSearch.isLegalPag(graph); + GraphSearchUtils.LegalPagRet legalPag = GraphSearchUtils.isLegalPag(graph); String reason = breakDown(legalPag.getReason(), 60); if (!legalPag.isLegalPag()) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java index 466b15ddda..8d002bc996 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.DagScorer; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.model.ScoredGraphsWrapper; @@ -72,7 +72,7 @@ public ScoredGraphsDisplay(ScoredGraphsWrapper scoredGraphsWrapper) { } public ScoredGraphsDisplay(Graph graph, DagScorer scorer) { - List _dags = GraphUtilsSearch.generateCpdagDags(graph, true); + List _dags = GraphSearchUtils.generateCpdagDags(graph, true); for (Graph _graph : _dags) { double score = Double.NaN; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java index 759e460b3b..5036e6932f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeEditorToolbar.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.LayoutUtil; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetradapp.util.ImageUtils; import edu.cmu.tetradapp.workbench.AbstractWorkbench; @@ -234,7 +234,7 @@ private void setWorkbenchMode(JToggleButton button) { KnowledgeGraph graph = (KnowledgeGraph) this.workbench.getGraph(); Knowledge knowledge = graph.getKnowledge(); try { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); this.workbench.setGraph(graph); } catch (IllegalArgumentException ex) { System.out.print(ex.getMessage()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java index f599edfa15..69b2292d25 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.graph.SemGraph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -89,7 +89,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn for (int i = 0; i < dataModels.size(); i++) { DataSet dataSet = (DataSet) dataModels.get(0); - Graph dag = GraphUtilsSearch.dagFromCPDAG(graphs.get(0)); + Graph dag = GraphSearchUtils.dagFromCPDAG(graphs.get(0)); BayesPm pm = new BayesPmWrapper(dag, new DataWrapper(dataSet)).getBayesPm(); this.bayesPms.add(pm); this.bayesIms.add(estimate(dataSet, pm)); @@ -100,7 +100,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn for (int i = 0; i < dataModels.size(); i++) { DataSet dataSet = (DataSet) dataModels.get(0); - Graph dag = GraphUtilsSearch.dagFromCPDAG(graphs.get(0)); + Graph dag = GraphSearchUtils.dagFromCPDAG(graphs.get(0)); try { SemPm pm = new SemPm(dag); @@ -109,7 +109,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn } catch (Exception e) { e.printStackTrace(); - Graph mag = GraphUtilsSearch.pagToMag(graphs.get(0)); + Graph mag = GraphSearchUtils.pagToMag(graphs.get(0)); // Ricf.RicfResult result = estimatePag(dataSet, mag); SemGraph graph = new SemGraph(mag); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java index 41f6dc7341..f45791a9a7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Dag; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -66,7 +66,7 @@ public static CPDAGFromDagGraphWrapper serializableInstance() { private static Graph getCPDAG(Graph graph) { - return GraphUtilsSearch.cpdagFromDag(graph); + return GraphSearchUtils.cpdagFromDag(graph); } @Override diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java index d8ab1f1956..a663bcf815 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -47,7 +47,7 @@ public DagInCPDAGWrapper(Graph graph) { } private static Graph getGraph(Graph graph) { - return GraphUtilsSearch.dagFromCPDAG(graph); + return GraphSearchUtils.dagFromCPDAG(graph); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java index fe6084dbd2..c188360f1d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -33,7 +33,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** @@ -112,7 +112,7 @@ public String getComparisonString() { Graph comparisonGraph = getComparisonGraph(referenceGraph, params); - return GraphUtilsSearch.graphComparisonString(refName, comparisonGraph, + return GraphSearchUtils.graphComparisonString(refName, comparisonGraph, targetName, this.targetGraph, false); } @@ -143,7 +143,7 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return GraphUtilsSearch.cpdagForDag(graph); + return GraphSearchUtils.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); return dagToPag(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java index b5760a8e36..0883519ea3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -80,7 +80,7 @@ public static ExtractStructureModelWrapper serializableInstance() { private static Graph getCPDAG(Dag dag) { - return GraphUtilsSearch.cpdagFromDag(dag); + return GraphSearchUtils.cpdagFromDag(dag); } @Override diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index 145c2e8a87..34d0cce24f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -149,7 +149,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java index 67c886e138..90c1347497 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; import edu.cmu.tetradapp.util.IndTestType; @@ -130,7 +130,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java index 53af1f5847..6d18a3612b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralAlgorithmRunner.java @@ -39,7 +39,7 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.session.ParamsResettable; @@ -411,7 +411,7 @@ public void execute() { if (_knowledge.getVariablesNotInTiers().size() < _knowledge.getVariables().size()) { for (Graph graph : graphList) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, _knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, _knowledge); } } } else { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java index 2e3b47e3f1..976655e2cd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -47,7 +47,7 @@ public MagInPagWrapper(Graph graph) { } private static Graph getGraph(Graph graph) { - return GraphUtilsSearch.pagToMag(graph); + return GraphSearchUtils.pagToMag(graph); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java index 8d92346bb9..093da81a7f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.MisclassificationUtils; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -34,7 +34,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** @@ -150,7 +150,7 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return GraphUtilsSearch.cpdagForDag(graph); + return GraphSearchUtils.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); return dagToPag(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index 9a8d80030b..ab368e9e69 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.search.work_in_progress.HbsmsBeam; import edu.cmu.tetrad.search.work_in_progress.Hbsms; import edu.cmu.tetrad.search.work_in_progress.HbsmsGes; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.*; @@ -258,12 +258,12 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(this.graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(this.graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(this.graph, knowledge); } else { LayoutUtil.circleLayout(this.graph, 200, 200, 150); } - setResultGraph(GraphUtilsSearch.cpdagForDag(this.graph)); + setResultGraph(GraphSearchUtils.cpdagForDag(this.graph)); } public boolean supportsKnowledge() { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java index 0da860ea1e..9725bb2986 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -47,7 +47,7 @@ public PagFromDagGraphWrapper(Graph graph) { throw new IllegalArgumentException("The source graph is not a DAG."); } - Graph pag = GraphUtilsSearch.dagToPag(graph); + Graph pag = GraphSearchUtils.dagToPag(graph); setGraph(pag); TetradLogger.getInstance().log("info", "\nGenerating allow_latent_common_causes from DAG."); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index 4e33d78d02..6161fd6ed8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -146,7 +146,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 07246eff68..a9315136d4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -23,10 +23,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.work_in_progress.SampleVcpcFast; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.util.Parameters; @@ -162,7 +161,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index cf3387ced2..fea134c2f5 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -23,10 +23,9 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.work_in_progress.SampleVcpc; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; @@ -196,7 +195,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java index 99c4cc2b73..6968a51458 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.utils.DagScorer; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -73,7 +73,7 @@ private ScoredGraphsWrapper() { } public ScoredGraphsWrapper(Graph graph, DagScorer scorer) { - List dags = GraphUtilsSearch.generateCpdagDags(graph, true); + List dags = GraphSearchUtils.generateCpdagDags(graph, true); this.graphsToScores = new HashMap<>(); this.graphScorer = scorer; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index 5adf7f4a90..2f0a63b124 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -23,11 +23,10 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.work_in_progress.VcPcFast; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -186,7 +185,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index bc8f17771c..a4fcff0ac4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -23,11 +23,10 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.work_in_progress.VcPc; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -189,7 +188,7 @@ public void execute() { if (getSourceGraph() != null) { LayoutUtil.arrangeBySourceGraph(graph, getSourceGraph()); } else if (knowledge.isDefaultToKnowledgeLayout()) { - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { LayoutUtil.circleLayout(graph, 200, 200, 150); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java index 83b136783a..fec5474da2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetradapp.util.GraphEditorUtils; import edu.cmu.tetradapp.util.LayoutEditable; @@ -487,7 +487,7 @@ public static void knowledgeLayout(LayoutEditable layoutEditable) { } Knowledge knowledge = layoutEditable.getKnowledge(); - GraphUtilsSearch.arrangeByKnowledgeTiers(graph, knowledge); + GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); layoutEditable.layoutByGraph(graph); } catch (Exception e1) { JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java index 9bb2d118f0..2ef23fa643 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java @@ -41,7 +41,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; @@ -563,12 +563,12 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param if (isSaveCPDAGs()) { File file3 = new File(dir3, "cpdag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(GraphUtilsSearch.cpdagForDag(graph), file3, false); + GraphPersistence.saveGraph(GraphSearchUtils.cpdagForDag(graph), file3, false); } if (isSavePags()) { File file4 = new File(dir4, "pag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(GraphUtilsSearch.dagToPag(graph), file4, false); + GraphPersistence.saveGraph(GraphSearchUtils.dagToPag(graph), file4, false); } } @@ -650,12 +650,12 @@ public void saveToFilesSingleSimulation(String dataPath, Simulation simulation, if (isSaveCPDAGs()) { File file3 = new File(dir3, "cpdag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(GraphUtilsSearch.cpdagForDag(graph), file3, false); + GraphPersistence.saveGraph(GraphSearchUtils.cpdagForDag(graph), file3, false); } if (isSavePags()) { File file4 = new File(dir4, "pag." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(GraphUtilsSearch.dagToPag(graph), file4, false); + GraphPersistence.saveGraph(GraphSearchUtils.dagToPag(graph), file4, false); } } } catch (IOException e) { @@ -1236,9 +1236,9 @@ private void doRun(List algorithmSimulationWrappers, if (this.comparisonGraph == ComparisonGraph.true_DAG) { comparisonGraph = new EdgeListGraph(trueGraph); } else if (this.comparisonGraph == ComparisonGraph.CPDAG_of_the_true_DAG) { - comparisonGraph = GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueGraph)); + comparisonGraph = GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueGraph)); } else if (this.comparisonGraph == ComparisonGraph.PAG_of_the_true_DAG) { - comparisonGraph = GraphUtilsSearch.dagToPag(trueGraph); + comparisonGraph = GraphSearchUtils.dagToPag(trueGraph); } else { throw new IllegalArgumentException("Unrecognized graph type."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java index d0ac1f420e..1af29b2eaf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java @@ -39,7 +39,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; @@ -53,7 +53,7 @@ import java.util.*; import java.util.concurrent.*; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Nov 14, 2017 12:00:31 PM @@ -508,7 +508,7 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param if (isSaveCPDAGs()) { File file3 = new File(dir3, "pattern." + (j + 1) + ".txt"); - GraphPersistence.saveGraph(GraphUtilsSearch.cpdagForDag(graph), file3, false); + GraphPersistence.saveGraph(GraphSearchUtils.cpdagForDag(graph), file3, false); } if (isSavePags()) { @@ -1148,7 +1148,7 @@ private void doRun(List algorithmSimulationWrappers, if (this.comparisonGraph == ComparisonGraph.true_DAG) { comparisonGraph = new EdgeListGraph(trueGraph); } else if (this.comparisonGraph == ComparisonGraph.CPDAG_of_the_true_DAG) { - comparisonGraph = GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueGraph)); + comparisonGraph = GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueGraph)); } else if (this.comparisonGraph == ComparisonGraph.PAG_of_the_true_DAG) { comparisonGraph = dagToPag(new EdgeListGraph(trueGraph)); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index 2ef47921b4..71e1991ce6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -12,7 +12,7 @@ import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.utils.ClusterSignificance; import edu.cmu.tetrad.search.utils.ClusterUtils; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; @@ -121,7 +121,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index daca5ee169..1b07d22566 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -12,7 +12,7 @@ import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.utils.ClusterSignificance; import edu.cmu.tetrad.search.utils.ClusterUtils; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; @@ -135,7 +135,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(graph); + return GraphSearchUtils.cpdagForDag(graph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java index c9af36cbf1..0be579f502 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -78,7 +78,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java index 7bc008d2e0..e5828dc0d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -135,7 +135,7 @@ public Graph getComparisonGraph(Graph graph) { if (this.compareToTrue) { return new EdgeListGraph(graph); } else { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } } 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 fa71ecaccc..544c786939 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -88,7 +88,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } @Override 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 9837d6cb5e..8ef7452fa7 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -82,7 +82,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } @Override 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/FgesMeasurement.java index 5f25fc4831..75604842af 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/FgesMeasurement.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.RandomUtil; @@ -85,7 +85,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } @Override 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/GesMe.java index 414d91ac75..2951bcb3bd 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/GesMe.java @@ -11,7 +11,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.*; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import org.apache.commons.math3.util.FastMath; @@ -191,7 +191,7 @@ public Graph getComparisonGraph(Graph graph) { if (this.compareToTrue) { return new EdgeListGraph(graph); } else { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } } 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 cc87a75b98..7402f5fcd3 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -90,7 +90,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } @Override 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 e167d0138b..4e26e0563e 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 @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -90,7 +90,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(new EdgeListGraph(graph)); + return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); } @Override 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 index dfb5fdfe57..f098fc6da0 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 @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.search.test.ScoreIndTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -71,7 +71,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphUtilsSearch.cpdagForDag(graph); + return GraphSearchUtils.cpdagForDag(graph); } @Override 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 319614d190..9c756f0364 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 @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** 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 index 9fbdfebe49..7a77406aab 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 @@ -19,7 +19,7 @@ import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Conserative FCI. 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 index fed07d1f10..a9718f6ea4 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 @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * FCI. 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/FciMax.java index 5eb4af9622..ddb4f7ebe1 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/FciMax.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * FCI. 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 0fd2c25255..650d414be0 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 @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index f3a8c78e56..44ab36c0be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java index ed4d4fae8f..9a475540be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java @@ -18,7 +18,7 @@ import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Jan 29, 2023 3:45:09 PM 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 index dc9f71ebc6..d3eda155b1 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 @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * RFCI. 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/RfciBsc.java index 5a1d5c3e51..50434f273a 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/RfciBsc.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Jan 4, 2019 4:32:05 PM 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/SpFci.java index f3f9001b10..38b596a857 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/SpFci.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java index ec0520ea9b..66eaa2722c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; @@ -27,8 +27,8 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - double _true = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(trueGraph), dataModel); - double est = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(estGraph), dataModel); + double _true = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(trueGraph), dataModel); + double est = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(estGraph), dataModel); return (_true - est); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java index df5f61da87..966c61d5d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.abs; @@ -30,8 +30,8 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - double _true = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(trueGraph), dataModel); - double est = SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(estGraph), dataModel); + double _true = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(trueGraph), dataModel); + double est = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(estGraph), dataModel); if (abs(_true) < 0.0001) _true = 0.0; if (abs(est) < 0.0001) est = 0.0; return (_true - est) / ((DataSet) dataModel).getNumRows(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java index abf5d7fe6a..6eec5446ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; @@ -28,7 +28,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { // double _true = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(trueGraph), dataModel); - return SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(estGraph), dataModel); + return SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(estGraph), dataModel); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java index 46cb40a18b..26d379dfc7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.score.SemBicScorer; import static org.apache.commons.math3.util.FastMath.tanh; @@ -28,7 +28,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { // double est = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(estGraph), dataModel); - return SemBicScorer.scoreDag(GraphUtilsSearch.dagFromCPDAG(trueGraph), dataModel); + return SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(trueGraph), dataModel); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java index 08e3bb7862..45f7fada34 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected false negatives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java index 3ae798f65e..4ce4d4789f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected edge precision. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java index 1230fb6539..e551513687 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected edge precision. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java index 735d7f0b28..7c0bc14b6b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java index 0d08d28dc9..d4e2a1cc44 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java index 3f7b8600de..4bc51d0e5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,7 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.CommonAncestorTruePositiveBidirected.existsCommonAncestor; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java index 41759f0b7e..bd3f9d20ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -32,7 +32,7 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fp = 0; List nodes = trueGraph.getNodes(); - Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); + Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); GraphUtils.addPagColoring(estGraph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java index 5972fcd408..44e5db0301 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -30,7 +30,7 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fn = 0; List nodes = trueGraph.getNodes(); - Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); + Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); for (Node x : nodes) { for (Node y : nodes) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java index 1ab552e314..5e0ced6ef6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,7 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected true positives. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java index 26b4a2ce34..3394b87327 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * Legal PAG @@ -24,7 +24,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - GraphUtilsSearch.LegalPagRet legalPag = GraphUtilsSearch.isLegalPag(estGraph); + GraphSearchUtils.LegalPagRet legalPag = GraphSearchUtils.isLegalPag(estGraph); System.out.println(legalPag.getReason()); if (legalPag.isLegalPag()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java index 6149dfc1bf..d294c17b4a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -27,7 +27,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { Graph pag = estGraph; - Graph mag = GraphUtilsSearch.pagToMag(estGraph); + Graph mag = GraphSearchUtils.pagToMag(estGraph); List nodes = pag.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java index 7089ed884d..30bc869919 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * @author josephramsey @@ -25,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph mag = GraphUtilsSearch.pagToMag(estGraph); + Graph mag = GraphSearchUtils.pagToMag(estGraph); for (Edge e : mag.getEdges()) { Node x = e.getNode1(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java index 6fbd698689..086956faae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * @author josephramsey @@ -23,7 +23,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph mag = GraphUtilsSearch.pagToMag(estGraph); + Graph mag = GraphSearchUtils.pagToMag(estGraph); for (Node n : mag.getNodes()) { if (mag.paths().existsDirectedPathFromTo(n, n)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java index 4dee2776a1..511701e73f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fp = 0; - Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); + Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); List nodes = estGraph.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java index ee391671aa..5d79af132d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fn = 0; - Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); + Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); List nodes = trueGraph.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java index 823efffcc8..e882b793a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java index 171221ed67..dff8657a12 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java index ec6891bc15..caaa289d6c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -30,7 +30,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java index dcbfde283e..35b0d77c8e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java index ea35dc8144..757094026e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java index 9afe5913a2..f07c83e18c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -28,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java index 58cb49cc66..c0cd6b2d69 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -29,7 +29,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java index e9368e9cc4..18c30bf881 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * The bidirected true positives. @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); + Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java index 725b674e5d..d90dd0c772 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * The bidirected true positives. @@ -26,7 +26,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); + Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java index 97276c8fbe..f653202e56 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * @author josephramsey @@ -25,7 +25,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0; - Graph pag = GraphUtilsSearch.dagToPag(trueGraph); + Graph pag = GraphSearchUtils.dagToPag(trueGraph); for (Edge edge : pag.getEdges()) { if (pag.paths().defVisible(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java index d4e5e840a3..7f302e2eb6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * The bidirected true positives. @@ -26,7 +26,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = GraphUtilsSearch.cpdagForDag(trueGraph); + Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java index 7e4d416ea9..9caa84159c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The adjacency precision. The true positives are the number of adjacencies in both diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java index 9b34663dba..478cd3de50 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The adjacency recall. The true positives are the number of adjacencies in both diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java index 912f625bc1..88d8ce5095 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Shd.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import org.apache.commons.math3.util.FastMath; /** @@ -27,7 +27,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison(trueGraph, estGraph); + GraphUtils.GraphComparison comparison = GraphSearchUtils.getGraphComparison(trueGraph, estGraph); return comparison.getShd(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java index bdcadbb101..2f56322915 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestFisherZ; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.MillisecondTimes; import org.apache.commons.math3.util.FastMath; @@ -110,7 +110,7 @@ public static void main(String[] args) throws IOException { // // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(dag); + Graph truePag = GraphSearchUtils.dagToPag(dag); System.out.println("true PAG construction Done!"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index a3dd331ca2..007703bc81 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge.Property; import edu.cmu.tetrad.search.utils.FciOrient; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.ForkJoinPoolInstance; @@ -35,7 +35,7 @@ import java.util.*; import java.util.concurrent.RecursiveTask; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Basic graph utilities. @@ -1766,7 +1766,7 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return GraphUtilsSearch.cpdagForDag(graph); + return GraphSearchUtils.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); return dagToPag(graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 18213c4c56..1698ad391b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -272,8 +272,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -292,8 +292,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index d0fbd53c9d..020a6e0210 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -520,8 +520,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -544,8 +544,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; 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 72c60bb73b..f26568fdcd 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 @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.MillisecondTimes; @@ -285,8 +285,8 @@ public Graph search() { this.graph = search.search(); this.sepsets = fas.getSepsets(); - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, independenceTest.getVariables()); - GraphUtilsSearch.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, independenceTest.getVariables()); + GraphSearchUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); TetradLogger.getInstance().log("graph", "\nReturning this graph: " + this.graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index cfdb785a4f..79cbe6c138 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.linear.SingularMatrixException; import org.apache.commons.math3.util.FastMath; @@ -292,7 +292,7 @@ public Graph search() { TetradLogger.getInstance().forceLogMessage(""); - GraphUtilsSearch.pcOrientbk(this.knowledge, G, G.getNodes()); + GraphSearchUtils.pcOrientbk(this.knowledge, G, G.getNodes()); Graph graph = new EdgeListGraph(G.getNodes()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 84d7d229a2..a1d26fed2a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -27,7 +27,7 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.ScoredGraph; import edu.cmu.tetrad.search.utils.DagScorer; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.search.utils.Bes; import edu.cmu.tetrad.util.MillisecondTimes; @@ -224,7 +224,7 @@ public Graph search() { this.logger.forceLogMessage("Elapsed time = " + (elapsedTime) / 1000. + " s"); } - this.modelScore = scoreDag(GraphUtilsSearch.dagFromCPDAG(graph), true); + this.modelScore = scoreDag(GraphSearchUtils.dagFromCPDAG(graph), true); return graph; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index 67220ffd71..df307de815 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -301,8 +301,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -321,8 +321,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; 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 4bf1f231bd..d920606ed2 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 @@ -343,8 +343,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -363,8 +363,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; 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 dad3b6dd69..32e6d2919e 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 @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.MillisecondTimes; @@ -275,8 +275,8 @@ public Graph search(IFas fas, List nodes) { this.numIndependenceTests = fas.getNumIndependenceTests(); - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); - GraphUtilsSearch.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, nodes); + GraphSearchUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); this.logger.log("graph", "\nReturning this graph: " + this.graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java index 3c9b642669..14dd8b0be7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; @@ -105,7 +105,7 @@ public Graph search() { TetradLogger.getInstance().log("info", "Making list of all dags in CPDAG..."); - List dags = GraphUtilsSearch.getAllGraphsByDirectingUndirectedEdges(_cpdag); + List dags = GraphSearchUtils.getAllGraphsByDirectingUndirectedEdges(_cpdag); TetradLogger.getInstance().log("normalityTests", "Anderson Darling P value for Variables\n"); NumberFormat nf = new DecimalFormat("0.0000"); @@ -152,7 +152,7 @@ public Graph search() { TetradLogger.getInstance().log("normalityTests", getDataSet().getVariable(j) + ": " + nf.format(scores.get(maxj).pvals[j])); } - Graph ngDagCPDAG = GraphUtilsSearch.cpdagFromDag(dag); + Graph ngDagCPDAG = GraphSearchUtils.cpdagFromDag(dag); List nodes = ngDagCPDAG.getNodes(); 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 e240d34d97..9c97bd089a 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 @@ -27,7 +27,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.MillisecondTimes; @@ -271,8 +271,8 @@ public Graph search(IFas fas, List nodes) { this.numIndependenceTests = fas.getNumIndependenceTests(); - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); - GraphUtilsSearch.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, nodes); + GraphSearchUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); this.logger.log("graph", "\nReturning this graph: " + this.graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index fbf82fa4ce..f3e49a1f03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; @@ -285,7 +285,7 @@ public Graph search(List targets) { this.logger.log("info", "BEGINNING step 4 (PC Orient)."); - GraphUtilsSearch.pcOrientbk(this.knowledge, graph, graph.getNodes()); + GraphSearchUtils.pcOrientbk(this.knowledge, graph, graph.getNodes()); List _visited = new LinkedList<>(getA()); orientUnshieldedTriples(this.knowledge, graph, getDepth(), _visited); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index ea588df7bd..c9ca427b05 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -254,8 +254,8 @@ public Graph search(IFas fas, List nodes) { enumerateTriples(); - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); - GraphUtilsSearch.pcdOrientC(getIndependenceTest(), this.knowledge, this.graph); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, nodes); + GraphSearchUtils.pcdOrientC(getIndependenceTest(), this.knowledge, this.graph); MeekRules rules = new MeekRules(); rules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 791d2e9754..db21b986c5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -137,7 +137,7 @@ public Graph search() { } Knowledge knowledge2 = new Knowledge(knowledge); - addForbiddenReverseEdgesForDirectedEdges(GraphUtilsSearch.cpdagForDag(graph), knowledge2); + addForbiddenReverseEdgesForDirectedEdges(GraphSearchUtils.cpdagForDag(graph), knowledge2); // Keep a copy of this CPDAG. Graph referenceDag = new EdgeListGraph(this.graph); @@ -323,8 +323,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -343,8 +343,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 93b2245f75..4f15d48635 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -28,7 +28,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.FciOrient; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -885,8 +885,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { @@ -909,8 +909,8 @@ private void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 79211273cb..bf7aef47f3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.search.utils.SepsetsGreedy; @@ -320,8 +320,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { @@ -342,8 +342,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java index 3501708f79..fc99a9c82c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java @@ -26,9 +26,6 @@ import edu.cmu.tetrad.search.Fci; import edu.cmu.tetrad.search.GFci; import edu.cmu.tetrad.search.Rfci; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.utils.SepsetProducer; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; @@ -1028,8 +1025,8 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; @@ -1054,8 +1051,8 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), variables); - Node to = GraphUtilsSearch.translate(edge.getTo(), variables); + Node from = GraphSearchUtils.translate(edge.getFrom(), variables); + Node to = GraphSearchUtils.translate(edge.getTo(), variables); if (from == null || to == null) { continue; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java index ad2567d673..45b6169a6e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FgesOrienter.java @@ -1351,7 +1351,7 @@ private Set reorientNode(Graph graph, Node a) { nodes.add(a); List edges = graph.getEdges(a); - GraphUtilsSearch.basicCpdagRestricted2(graph, a); + GraphSearchUtils.basicCpdagRestricted2(graph, a); addRequiredEdges(graph); Set visited = meekOrientRestricted(graph, getKnowledge()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphSearchUtils.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphSearchUtils.java index 2c5db955fa..539bb886a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphUtilsSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphSearchUtils.java @@ -45,7 +45,7 @@ * * @author josephramsey */ -public final class GraphUtilsSearch { +public final class GraphSearchUtils { /** * Orients according to background knowledge. @@ -56,8 +56,8 @@ public static void pcOrientbk(Knowledge bk, Graph graph, List nodes) { KnowledgeEdge edge = it.next(); //match strings to variables in the graph. - Node from = GraphUtilsSearch.translate(edge.getFrom(), nodes); - Node to = GraphUtilsSearch.translate(edge.getTo(), nodes); + Node from = GraphSearchUtils.translate(edge.getFrom(), nodes); + Node to = GraphSearchUtils.translate(edge.getTo(), nodes); if (from == null || to == null) { continue; @@ -78,8 +78,8 @@ public static void pcOrientbk(Knowledge bk, Graph graph, List nodes) { KnowledgeEdge edge = it.next(); //match strings to variables in this graph - Node from = GraphUtilsSearch.translate(edge.getFrom(), nodes); - Node to = GraphUtilsSearch.translate(edge.getTo(), nodes); + Node from = GraphSearchUtils.translate(edge.getFrom(), nodes); + Node to = GraphSearchUtils.translate(edge.getTo(), nodes); if (from == null || to == null) { continue; @@ -129,7 +129,7 @@ public static void pcdOrientC(IndependenceTest test, Knowledge knowledge, Graph continue; } - List sepset = GraphUtilsSearch.sepset(graph, x, z, new HashSet<>(), new HashSet<>(), + List sepset = GraphSearchUtils.sepset(graph, x, z, new HashSet<>(), new HashSet<>(), test); if (sepset == null) { @@ -162,8 +162,8 @@ public static void pcdOrientC(IndependenceTest test, Knowledge knowledge, Graph continue; } - if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge) - || !GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge)) { + if (!GraphSearchUtils.isArrowheadAllowed(x, y, knowledge) + || !GraphSearchUtils.isArrowheadAllowed(z, y, knowledge)) { continue; } @@ -241,7 +241,7 @@ public static void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledg //I think the null check needs to be here --AJ if (sepset != null && !sepset.contains(b) - && GraphUtilsSearch.isArrowheadAllowed(a, b, knowledge)) { + && GraphSearchUtils.isArrowheadAllowed(a, b, knowledge)) { boolean result = true; if (knowledge != null) { result = !knowledge.isRequired(((Object) b).toString(), ((Object) c).toString()) @@ -358,14 +358,14 @@ public static void basicCpdagRestricted2(Graph graph, Node node) { */ public static Graph cpdagFromDag(Graph dag) { Graph graph = new EdgeListGraph(dag); - GraphUtilsSearch.basicCpdag(graph); + GraphSearchUtils.basicCpdag(graph); MeekRules rules = new MeekRules(); rules.orientImplied(graph); return graph; } public static Graph dagFromCPDAG(Graph graph) { - return GraphUtilsSearch.dagFromCPDAG(graph, null); + return GraphSearchUtils.dagFromCPDAG(graph, null); } public static Graph dagFromCPDAG(Graph graph, Knowledge knowledge) { @@ -392,7 +392,7 @@ public static Graph dagFromCPDAG(Graph graph, Knowledge knowledge) { Node y = edge.getNode2(); if (Edges.isUndirectedEdge(edge) && !graph.paths().isAncestorOf(y, x)) { - GraphUtilsSearch.direct(x, y, dag); + GraphSearchUtils.direct(x, y, dag); rules.orientImplied(dag); continue NEXT; } @@ -475,6 +475,10 @@ public static Graph pagToMag(Graph pag) { return mag; } + /** + * Stores a result for checking whether a graph is a legal PAG--(a) whether it is (a + * boolean), and (b) the reason why it is not, if it is not (a String). + */ public static class LegalPagRet { private final boolean legalPag; private final String reason; @@ -511,7 +515,7 @@ public static LegalPagRet isLegalPag(Graph pag) { return new LegalPagRet(false, legalMag.getReason() + " in a MAG implied by this graph"); } - Graph pag2 = GraphUtilsSearch.dagToPag(mag); + Graph pag2 = GraphSearchUtils.dagToPag(mag); if (!pag.equals(pag2)) { String edgeMismatch = ""; @@ -538,6 +542,10 @@ public static LegalPagRet isLegalPag(Graph pag) { return new LegalPagRet(true, "This is a legal PAG"); } + /** + * Stores a result for checking whether a graph is a legal MAG--(a) whether it is (a + * boolean), and (b) the reason why it is not, if it is not (a String). + */ public static class LegalMagRet { private final boolean legalMag; private final String reason; @@ -872,7 +880,7 @@ public static List generateCpdagDags(Graph cpdag, boolean orientBidirecte cpdag = GraphUtils.removeBidirectedOrientations(cpdag); } - return GraphUtilsSearch.getDagsInCpdagMeek(cpdag, new Knowledge()); + return GraphSearchUtils.getDagsInCpdagMeek(cpdag, new Knowledge()); } public static List getDagsInCpdagMeek(Graph cpdag, Knowledge knowledge) { @@ -944,6 +952,7 @@ public static List getAllGraphsByDirectingUndirectedEdges(Graph skeleton) return graphs; } + // The published version. public static CpcTripleType getCpcTripleType(Node x, Node y, Node z, IndependenceTest test, int depth, @@ -1035,8 +1044,8 @@ public static int structuralHammingDistance(Graph trueGraph, Graph estGraph) { try { estGraph = GraphUtils.replaceNodes(estGraph, trueGraph.getNodes()); - trueGraph = GraphUtilsSearch.cpdagForDag(trueGraph); - estGraph = GraphUtilsSearch.cpdagForDag(estGraph); + trueGraph = GraphSearchUtils.cpdagForDag(trueGraph); + estGraph = GraphSearchUtils.cpdagForDag(estGraph); // Will check mixedness later. if (trueGraph.paths().existsDirectedCycle()) { @@ -1068,7 +1077,7 @@ public static int structuralHammingDistance(Graph trueGraph, Graph estGraph) { return -99; } - int error = GraphUtilsSearch.structuralHammingDistanceOneEdge(e1, e2); + int error = GraphSearchUtils.structuralHammingDistanceOneEdge(e1, e2); shd += error; } } @@ -1536,7 +1545,7 @@ public static String graphComparisonString(String trueGraphName, Graph trueGraph } public static int[][] graphComparison(Graph trueCpdag, Graph estCpdag, PrintStream out) { - GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison2(estCpdag, trueCpdag); + GraphUtils.GraphComparison comparison = GraphSearchUtils.getGraphComparison2(estCpdag, trueCpdag); if (out != null) { out.println("Adjacencies:"); @@ -1589,6 +1598,10 @@ public static Graph dagToPag(Graph trueGraph) { return new DagToPag(trueGraph).convert(); } + /** + * Gives the options for triple type for a conservative unshielded collider orientation, + * which may be "collider" or "noncollider" or "ambiguous". + */ public enum CpcTripleType { COLLIDER, NONCOLLIDER, AMBIGUOUS } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java index c05698a7c8..ecc0517e07 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java @@ -212,8 +212,8 @@ private void testColliderMaxP(Graph graph, Map scores, Node a, N adja.remove(c); adjc.remove(a); - if (!(GraphUtilsSearch.isArrowheadAllowed(a, b, knowledge) - && (GraphUtilsSearch.isArrowheadAllowed(c, b, knowledge)))) { + if (!(GraphSearchUtils.isArrowheadAllowed(a, b, knowledge) + && (GraphSearchUtils.isArrowheadAllowed(c, b, knowledge)))) { return; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java index 4a4872e3e2..b4f8fa784e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java @@ -238,7 +238,7 @@ public static List generateMbDags(Graph mbCPDAG, * @return An example DAG in this CPDAG. */ public static Graph getOneMbDag(Graph mbCpdag) { - return GraphUtilsSearch.dagFromCPDAG(mbCpdag); + return GraphSearchUtils.dagFromCPDAG(mbCpdag); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java index d07281bc34..45def9e711 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java @@ -42,16 +42,42 @@ * @author josephramsey */ public final class PcCommon implements IGraphSearch { + + /** + * Gives the type of FAS used, regular or stable. + * + * @see Pc + * @see Cpc + * @see PcMax + */ public enum FasType {REGULAR, STABLE} + /** + * Give the options for the collider discovery algroithm to use--FAS with sepsets reasoning, + * FAS with conservative reasoning, or FAS with Max P reasoning. + * + * @see Fas + * @see Cpc + * @see PcMax + */ public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P} + /** + * Gives the type of conflict to be used, priority (when there is a conflict, keep the + * orientation that has already been made, bidirected (when there is a conflict, orient + * a bidirected edge), or overwrite (when there is a conflict, use the new orientation). + * + * @see Pc + * @see Cpc + * @see PcMax + */ public enum ConflictRule {PRIORITY, BIDIRECTED, OVERWRITE} /** * The independence test used for the PC search. */ private final IndependenceTest independenceTest; + /** * The logger for this class. The config needs to be set. */ @@ -346,7 +372,7 @@ public Graph search(List nodes) { this.graph = fas.search(); this.sepsets = fas.getSepsets(); - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, nodes); if (this.colliderDiscovery == ColliderDiscovery.FAS_SEPSETS) { orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, this.conflictRule); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java index 97f3daca0a..9798ea1308 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java @@ -36,12 +36,20 @@ import java.util.List; /** - * Provides some utilities for resolving inconsistencies that arise between sepsets - * learned for overlapping datasets. This occurs frequently when using the DCI and ION algorithm. + *

    Provides some utilities for resolving inconsistencies that arise + * between sepsets learned for overlapping datasets. This occurs frequently when + * using the DCI and ION algorithm. A reference is here:

    + * + *

    Tillman, R. E., & Eberhardt, F. (2014). Learning causal structure from + * multiple datasets with similar variable sets. Behaviormetrika, 41(1), 41-64.

    * * @author roberttillman */ public final class ResolveSepsets { + + /** + * Gives the method to be used to resolve sepsets when they conflict. + */ public enum Method { fisher, fisher2, tippett, worsleyfriston, stouffer, mudholkergeorge, mudholkergeorge2, average, averagetest, random, fdr, majority diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java index a9f568c98f..d37198aab6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java @@ -30,7 +30,7 @@ import edu.cmu.tetrad.regression.RegressionCovariance; import edu.cmu.tetrad.regression.RegressionResult; import edu.cmu.tetrad.search.utils.MeekRules; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; @@ -84,7 +84,7 @@ public HbsmsBeam(Graph graph, CovarianceMatrix cov, Knowledge knowledge) { public Graph search() { EdgeListGraph _graph = new EdgeListGraph(this.externalGraph); addRequiredEdges(_graph); - Graph bestGraph = GraphUtilsSearch.dagFromCPDAG(_graph); + Graph bestGraph = GraphSearchUtils.dagFromCPDAG(_graph); if (getGraph().getNumEdges() == 0) { System.out.println("Found one!"); @@ -106,7 +106,7 @@ public Graph search() { if (this.trueModel != null) { this.trueModel = GraphUtils.replaceNodes(this.trueModel, bestGraph.getNodes()); - this.trueModel = GraphUtilsSearch.cpdagForDag(this.trueModel); + this.trueModel = GraphSearchUtils.cpdagForDag(this.trueModel); } System.out.println("Initial Score = " + this.nf.format(bestScore)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java index 9f812fef71..33229eac3d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.utils.DagInCpcagIterator; import edu.cmu.tetrad.search.utils.MeekRules; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.DagScorer; import edu.cmu.tetrad.sem.Scorer; import edu.cmu.tetrad.sem.SemIm; @@ -62,7 +62,7 @@ public HbsmsGes(Graph graph, DataSet data) { DagInCpcagIterator iterator = new DagInCpcagIterator(graph, getKnowledge(), allowArbitraryOrientations, allowNewColliders); graph = iterator.next(); - graph = GraphUtilsSearch.cpdagForDag(graph); + graph = GraphSearchUtils.cpdagForDag(graph); if (GraphUtils.containsBidirectedEdge(graph)) { throw new IllegalArgumentException("Contains bidirected edge."); @@ -110,7 +110,7 @@ public boolean equals(Object o) { } public Score scoreGraph(Graph graph) { - Graph dag = GraphUtilsSearch.dagFromCPDAG(graph, getKnowledge()); + Graph dag = GraphSearchUtils.dagFromCPDAG(graph, getKnowledge()); this.scorer.score(dag); return new Score(this.scorer); @@ -582,7 +582,7 @@ private static List> powerSet(List nodes) { * Appendix C of (Chickering, 2002). */ private void rebuildCPDAG(Graph graph) { - GraphUtilsSearch.basicCpdag(graph); + GraphSearchUtils.basicCpdag(graph); addRequiredEdges(graph); pdagWithBk(graph, getKnowledge()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java index 1ad7eb3cca..fd907c8700 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.utils.GraphChange; import edu.cmu.tetrad.search.utils.PossibleDConnectingPath; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; @@ -788,7 +788,7 @@ private List> findSepAndAssoc(Graph graph) { variables.remove(x); variables.remove(y); - List> subsets = GraphUtilsSearch.powerSet(variables); + List> subsets = GraphSearchUtils.powerSet(variables); IonIndependenceFacts indep = new IonIndependenceFacts(x, y, new HashSet<>()); IonIndependenceFacts assoc = new IonIndependenceFacts(x, y, new HashSet<>()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Kpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Kpc.java index d98b1eb232..b2258a2805 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Kpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Kpc.java @@ -28,7 +28,7 @@ import edu.cmu.tetrad.search.IGraphSearch; import edu.cmu.tetrad.search.test.IndTestHsic; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.search.utils.SepsetMap; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -259,8 +259,8 @@ public Graph search(List nodes) { enumerateTriples(); - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, nodes); - GraphUtilsSearch.orientCollidersUsingSepsets(this.sepset, this.knowledge, this.graph, this.verbose, true); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, nodes); + GraphSearchUtils.orientCollidersUsingSepsets(this.sepset, this.knowledge, this.graph, this.verbose, true); MeekRules rules = new MeekRules(); rules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles); rules.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java index 2457cf2dd3..400b3e6292 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java @@ -32,7 +32,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; @@ -277,7 +277,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -805,10 +805,10 @@ private void orientUnshieldedTriples(Knowledge knowledge, if (this.graph.isAdjacentTo(x, z)) { continue; } - GraphUtilsSearch.CpcTripleType type = GraphUtilsSearch.getCpcTripleType(x, y, z, test, depth, graph); + GraphSearchUtils.CpcTripleType type = GraphSearchUtils.getCpcTripleType(x, y, z, test, depth, graph); - if (type == GraphUtilsSearch.CpcTripleType.COLLIDER) { + if (type == GraphSearchUtils.CpcTripleType.COLLIDER) { if (this.colliderAllowed(x, y, z, knowledge)) { graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); @@ -817,7 +817,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } colliderTriples.add(new Triple(x, y, z)); - } else if (type == GraphUtilsSearch.CpcTripleType.AMBIGUOUS) { + } else if (type == GraphSearchUtils.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); @@ -833,8 +833,8 @@ private void orientUnshieldedTriples(Knowledge knowledge, } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge)) return false; - return GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge); + if (!GraphSearchUtils.isArrowheadAllowed(x, y, knowledge)) return false; + return GraphSearchUtils.isArrowheadAllowed(z, y, knowledge); } public boolean isDoOrientation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java index b547bc2d29..ed08b77a18 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java @@ -32,7 +32,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.SemIm; @@ -277,7 +277,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -734,10 +734,10 @@ private void orientUnshieldedTriples(Knowledge knowledge, if (this.graph.isAdjacentTo(x, z)) { continue; } - GraphUtilsSearch.CpcTripleType type = GraphUtilsSearch.getCpcTripleType(x, y, z, test, depth, graph); + GraphSearchUtils.CpcTripleType type = GraphSearchUtils.getCpcTripleType(x, y, z, test, depth, graph); - if (type == GraphUtilsSearch.CpcTripleType.COLLIDER) { + if (type == GraphSearchUtils.CpcTripleType.COLLIDER) { if (this.colliderAllowed(x, y, z, knowledge)) { graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); @@ -746,7 +746,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } colliderTriples.add(new Triple(x, y, z)); - } else if (type == GraphUtilsSearch.CpcTripleType.AMBIGUOUS) { + } else if (type == GraphSearchUtils.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java index 7482a866af..809e5b61ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -257,7 +257,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, independenceTest, getDepth()); MeekRules meekRules = new MeekRules(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java index d5de714f1c..519ca96fc0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -231,7 +231,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -562,10 +562,10 @@ private void orientUnshieldedTriples(Knowledge knowledge, continue; } - GraphUtilsSearch.CpcTripleType type = GraphUtilsSearch.getCpcTripleType(x, y, z, test, depth, graph); + GraphSearchUtils.CpcTripleType type = GraphSearchUtils.getCpcTripleType(x, y, z, test, depth, graph); // SearchGraphUtils.CpcTripleType type = SearchGraphUtils.getCpcTripleType2(x, y, z, test, depth, graph); - if (type == GraphUtilsSearch.CpcTripleType.COLLIDER) { + if (type == GraphSearchUtils.CpcTripleType.COLLIDER) { if (this.colliderAllowed(x, y, z, knowledge)) { graph.setEndpoint(x, y, Endpoint.ARROW); graph.setEndpoint(z, y, Endpoint.ARROW); @@ -574,7 +574,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } colliderTriples.add(new Triple(x, y, z)); - } else if (type == GraphUtilsSearch.CpcTripleType.AMBIGUOUS) { + } else if (type == GraphSearchUtils.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); @@ -590,8 +590,8 @@ private void orientUnshieldedTriples(Knowledge knowledge, } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge)) return false; - return GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge); + if (!GraphSearchUtils.isArrowheadAllowed(x, y, knowledge)) return false; + return GraphSearchUtils.isArrowheadAllowed(z, y, knowledge); } public boolean isDoOrientation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java index 07b169ec0e..ee4ccdb4e6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -259,7 +259,7 @@ public Graph search() { if (this.verbose) { System.out.println("CPC orientation..."); } - GraphUtilsSearch.pcOrientbk(this.knowledge, this.graph, allNodes); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, allNodes); orientUnshieldedTriples(this.knowledge, getIndependenceTest(), getDepth()); // orientUnshieldedTriplesConcurrent(knowledge, getIndependenceTest(), getMaxIndegree()); MeekRules meekRules = new MeekRules(); @@ -704,8 +704,8 @@ public enum CpcTripleType { } private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { - if (!GraphUtilsSearch.isArrowheadAllowed(x, y, knowledge)) return false; - return GraphUtilsSearch.isArrowheadAllowed(z, y, knowledge); + if (!GraphSearchUtils.isArrowheadAllowed(x, y, knowledge)) return false; + return GraphSearchUtils.isArrowheadAllowed(z, y, knowledge); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java index 906d160124..29088dad42 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.ArrayList; import java.util.List; @@ -53,8 +53,8 @@ private List randomPairSimulation() { //convert those dags to CPDAGs if (this.verbose) System.out.println("converting dags to CPDAGs"); - Graph graph1 = GraphUtilsSearch.cpdagFromDag(dag1); - Graph graph2 = GraphUtilsSearch.cpdagFromDag(dag2); + Graph graph1 = GraphSearchUtils.cpdagFromDag(dag1); + Graph graph2 = GraphSearchUtils.cpdagFromDag(dag2); //run Gdistance on these two graphs if (this.verbose) System.out.println("running Gdistance on the CPDAGs"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java index e8f64572d3..8ea4dbbc53 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; @@ -75,7 +75,7 @@ public double[] run(int resimSize) { Graph estGraph = fges.search(); //if (verbose) System.out.println(estGraph); - Graph estGraphDAG = GraphUtilsSearch.dagFromCPDAG(estGraph); + Graph estGraphDAG = GraphSearchUtils.dagFromCPDAG(estGraph); Dag estDAG = new Dag(estGraphDAG); //Dag estDAG = new Dag(estGraph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java index d820704777..0f87221aeb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.BdeuScore; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; import edu.cmu.tetrad.util.RandomUtil; @@ -90,7 +90,7 @@ public double[] run(int resimSize) { //if (verbose) System.out.println(estGraph); Graph estCPDAG = new EdgeListGraph(estGraph); - Graph estGraphDAG = GraphUtilsSearch.dagFromCPDAG(estCPDAG); + Graph estGraphDAG = GraphSearchUtils.dagFromCPDAG(estCPDAG); Dag estDAG = new Dag(estGraphDAG); //===========Identify the nodes to be resimulated=========== diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java index f589a9af37..a40c95ed5c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.sem.SemEstimator; import edu.cmu.tetrad.sem.SemIm; @@ -89,7 +89,7 @@ public static void main(String[] args) { for (whichFrepeat = 0; whichFrepeat < fsimRepeat.size(); whichFrepeat++) { ArrayList errorsList = new ArrayList<>(); for (int r = 0; r < fsimRepeat.get(whichFrepeat); r++) { - Graph fgsDag = GraphUtilsSearch.dagFromCPDAG(oFGSGraph); + Graph fgsDag = GraphSearchUtils.dagFromCPDAG(oFGSGraph); Dag fgsdag2 = new Dag(fgsDag); //then fit an IM to this dag and the data. GeneralizedSemEstimator seems to bug out diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java index a0f652f938..5d560ba3a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.graph.RandomGraph; import edu.cmu.tetrad.search.score.BdeuScore; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; @@ -70,7 +70,7 @@ public static List run(int numVars, double edgesPerNode, int numCases, //create various simulated data sets ////let's do the full simulated data set first: a dag in the FGES CPDAG fit to the data set. - Graph fgesDag = GraphUtilsSearch.dagFromCPDAG(oGraphOut); + Graph fgesDag = GraphSearchUtils.dagFromCPDAG(oGraphOut); Dag fgesdag2 = new Dag(fgesDag); BayesPm simBayesPm = new BayesPm(fgesdag2, bayesPm); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java index 1fb4dc7b6c..509ff50ad1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; @@ -52,7 +52,7 @@ public static void run(String readfilename, String filenameOut, char delimiter, System.out.println(estGraph); Graph estCPDAG = new EdgeListGraph(estGraph); - Graph estGraphDAG = GraphUtilsSearch.dagFromCPDAG(estCPDAG); + Graph estGraphDAG = GraphSearchUtils.dagFromCPDAG(estCPDAG); Dag estDAG = new Dag(estGraphDAG); //===========Identify the nodes to be resimulated=========== @@ -96,7 +96,7 @@ public static void run(String readfilename, String filenameOut, char delimiter, Graph estGraphOut = fgesOut.search(); System.out.println(estGraphOut); - GraphUtilsSearch.graphComparison(estGraph, estGraphOut, System.out); + GraphSearchUtils.graphComparison(estGraph, estGraphOut, System.out); } catch (Exception IOException) { IOException.printStackTrace(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java index 06f31befda..044fc26f58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimUtils.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.VerticalIntDataBox; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.TextTable; import java.util.ArrayList; @@ -63,7 +63,7 @@ public static Set getAllParents(Graph inputgraph, Set inputnodes) { //this method returns an array of doubles, which are standard error metrics for graph learning public static double[] errorEval(Graph estCPDAG, Graph truePattern) { - GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison2(estCPDAG, truePattern); + GraphUtils.GraphComparison comparison = GraphSearchUtils.getGraphComparison2(estCPDAG, truePattern); int adjTp = comparison.getAdjCor(); int adjFp = comparison.getAdjFp(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java index 3d26b52687..d27418f066 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java @@ -11,7 +11,7 @@ import edu.cmu.tetrad.search.test.IndTestChiSquare; import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.utils.BayesImParser; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.study.performance.Comparison; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; @@ -172,7 +172,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo // get the true underlying PAG - Graph PAG_True = GraphUtilsSearch.dagToPag(dag); + Graph PAG_True = GraphSearchUtils.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, data.getVariables()); @@ -199,7 +199,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo // learn structure of constraints using empirical data Graph depCPDAG = runFGS(depData); - Graph estDepBN = GraphUtilsSearch.dagFromCPDAG(depCPDAG); + Graph estDepBN = GraphSearchUtils.dagFromCPDAG(depCPDAG); System.out.println("estDepBN: " + estDepBN.getEdges()); out.println("DepGraph(nodes,edges):" + estDepBN.getNumNodes() + "," + estDepBN.getNumEdges()); System.out.println("Dependency graph done!"); @@ -297,7 +297,7 @@ private void summarize(Graph graph, Graph trueGraph, PrintStream out) { tableColumns.add(Comparison.TableColumn.SHD); - GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison(trueGraph, graph); + GraphUtils.GraphComparison comparison = GraphSearchUtils.getGraphComparison(trueGraph, graph); List variables = new ArrayList<>(); for (Comparison.TableColumn column : tableColumns) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index 7921ac087a..3811b0e4f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -11,7 +11,7 @@ import edu.cmu.tetrad.search.test.IndTestChiSquare; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.ScoreType; import edu.cmu.tetrad.util.MillisecondTimes; @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Does a comparison of algorithm results across algorithm type, sample sizes, etc. @@ -190,24 +190,24 @@ public static ComparisonResult compare(ComparisonParameters params) { if (test == null) throw new IllegalArgumentException("Test not set."); Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { if (test == null) throw new IllegalArgumentException("Test not set."); Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) throw new IllegalArgumentException("Score not set."); Fges search = new Fges(score); search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES2) { if (score == null) throw new IllegalArgumentException("Score not set."); Fges search = new Fges(score); search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { if (test == null) throw new IllegalArgumentException("Test not set."); Fci search = new Fci(test); @@ -261,7 +261,7 @@ public static String summarize(List results, List Graph correctGraph = _result.getCorrectResult(); Graph resultGraph = _result.getResultGraph(); - GraphUtils.GraphComparison comparison = GraphUtilsSearch.getGraphComparison2(correctGraph, resultGraph); + GraphUtils.GraphComparison comparison = GraphSearchUtils.getGraphComparison2(correctGraph, resultGraph); int newRow = dataSet.getNumRows(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index adb2c2e8c9..3803345c51 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -13,7 +13,7 @@ import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.TsDagToPag; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; @@ -36,7 +36,7 @@ import java.util.Collections; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Does a comparison of algorithm results across algorithm type, sample sizes, @@ -144,16 +144,16 @@ public static ComparisonResult compare(ComparisonParameters params) { if (params.getAlgorithm() == ComparisonParameters.Algorithm.PC) { Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { Fges search = new Fges(score); //search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { Fci search = new Fci(test); result.setResultGraph(search.search()); @@ -379,14 +379,14 @@ public static ComparisonResult compare(ComparisonParameters params) { } Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { if (test == null) { throw new IllegalArgumentException("Test not set."); } Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) { throw new IllegalArgumentException("Score not set."); @@ -394,7 +394,7 @@ public static ComparisonResult compare(ComparisonParameters params) { Fges search = new Fges(score); //search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphUtilsSearch.cpdagForDag(new EdgeListGraph(trueDag))); + result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { if (test == null) { throw new IllegalArgumentException("Test not set."); @@ -466,7 +466,7 @@ public static TextTable summarize(List results, List vars = dag.getNodes(); @@ -909,7 +909,7 @@ private void testFgesMb(int numVars, double edgeFactor, int numCases, int numRun System.out.println("Calculating CPDAG for DAG"); - Graph CPDAG = GraphUtilsSearch.cpdagForDag(dag); + Graph CPDAG = GraphSearchUtils.cpdagForDag(dag); int[] tiers = new int[dag.getNumNodes()]; @@ -1201,7 +1201,7 @@ public void testGFciComparison() { // dagToPag.setMaxPathLength(maxPathLength); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(dag); + Graph truePag = GraphSearchUtils.dagToPag(dag); System.out.println("True PAG_of_the_true_DAG done"); @@ -1261,7 +1261,7 @@ public void testGFciComparison() { ffciArrowStats.add(printCorrectArrows(dag, estPag, truePag)); ffciTailStats.add(printCorrectTails(dag, estPag, truePag)); - ffciCounts.add(GraphUtilsSearch.getGraphComparison2(estPag, truePag)); + ffciCounts.add(GraphSearchUtils.getGraphComparison2(estPag, truePag)); elapsed = ta2 - ta1; ffciElapsedTimes.add(elapsed); @@ -1332,7 +1332,7 @@ public void testCompareDagToCPDAG(int numLatents) { System.out.println("PC graph = " + left); - Graph top = GraphUtilsSearch.cpdagForDag(dag); + Graph top = GraphSearchUtils.cpdagForDag(dag); System.out.println("DAG to CPDAG graph = " + top); @@ -1382,7 +1382,7 @@ public void testComparePcVersions(int numVars, double edgeFactor, int numLatents System.out.println("Graph done"); - Graph left = GraphUtilsSearch.cpdagForDag(dag);// pc1.search(); + Graph left = GraphSearchUtils.cpdagForDag(dag);// pc1.search(); System.out.println("First FAS graph = " + left); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java index 8c03438a81..4f2e516522 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java @@ -41,7 +41,7 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * Contains some tests for Dan Malinsky, that might be of interest to others. diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java index 908d364bcb..f3ce0bc0ac 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.graph.GraphPersistence; import edu.cmu.tetrad.search.Pc; import edu.cmu.tetrad.search.work_in_progress.IndTestMultinomialLogisticRegression; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.MillisecondTimes; import java.io.File; @@ -38,7 +38,7 @@ public class ExploreIndepTests { public static void main(String[] args) { try { String path = ExampleMixedSearch.class.getResource("test_data").getPath(); - Graph trueGraph = GraphUtilsSearch.cpdagFromDag(GraphPersistence.loadGraphTxt(new File(path, "DAG_0_graph.txt"))); + Graph trueGraph = GraphSearchUtils.cpdagFromDag(GraphPersistence.loadGraphTxt(new File(path, "DAG_0_graph.txt"))); DataSet ds = MixedUtils.loadDataSet(path, "DAG_0_data.txt"); IndTestMultinomialLogisticRegression indMix = new IndTestMultinomialLogisticRegression(ds, .05); @@ -54,15 +54,15 @@ public static void main(String[] args) { s3.setStable(true); long time = MillisecondTimes.timeMillis(); - Graph g1 = GraphUtilsSearch.cpdagFromDag(s1.search()); + Graph g1 = GraphSearchUtils.cpdagFromDag(s1.search()); System.out.println("Mix Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); time = MillisecondTimes.timeMillis(); - Graph g2 = GraphUtilsSearch.cpdagFromDag(s2.search()); + Graph g2 = GraphSearchUtils.cpdagFromDag(s2.search()); System.out.println("Wald lin Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); time = MillisecondTimes.timeMillis(); - Graph g3 = GraphUtilsSearch.cpdagFromDag(s3.search()); + Graph g3 = GraphSearchUtils.cpdagFromDag(s3.search()); System.out.println("Wald log Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); System.out.println(MixedUtils.EdgeStatHeader); diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java index a7222f4011..1c779a44fe 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/PagSamplingRfci.java @@ -6,7 +6,7 @@ import edu.cmu.tetrad.search.IGraphSearch; import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.Rfci; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.GraphSampling; import java.util.LinkedList; @@ -74,7 +74,7 @@ private List runSearches() { for (Future completedTask : completedTasks) { try { Graph graph = completedTask.get(); - if (graph != null && GraphUtilsSearch.isLegalPag(graph).isLegalPag()) { + if (graph != null && GraphSearchUtils.isLegalPag(graph).isLegalPag()) { graphs.add(graph); } } catch (ExecutionException exception) { diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java index 32fb161871..b529a6676d 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java @@ -11,7 +11,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.score.BdeuScore; import edu.cmu.tetrad.search.test.IndTestProbabilistic; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; @@ -254,7 +254,7 @@ public Boolean call() throws Exception { Graph depPattern = fges.search(); depPattern = GraphUtils.replaceNodes(depPattern, depData.getVariables()); - Graph estDepBN = GraphUtilsSearch.dagFromCPDAG(depPattern); + Graph estDepBN = GraphSearchUtils.dagFromCPDAG(depPattern); if (this.verbose) { this.out.println("estDepBN:"); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java index 50ed5fb8df..b8280069a0 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.utils.DagInCpcagIterator; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; @@ -55,7 +55,7 @@ public void test1() { Dag dag = new Dag(graph); - Graph CPDAG = GraphUtilsSearch.cpdagFromDag(graph); + Graph CPDAG = GraphSearchUtils.cpdagFromDag(graph); System.out.println(CPDAG); @@ -176,7 +176,7 @@ public void test5() { Dag dag1 = new Dag(RandomGraph.randomGraph(nodes1, 0, 3, 30, 15, 15, false)); - Graph CPDAG = GraphUtilsSearch.cpdagForDag(dag1); + Graph CPDAG = GraphSearchUtils.cpdagForDag(dag1); List nodes = CPDAG.getNodes(); // Make random knowedge. diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java index 8c397f57c4..e362036fb2 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestEdgeListGraph.java @@ -22,7 +22,7 @@ package edu.cmu.tetrad.test; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import org.junit.Test; import java.util.ArrayList; @@ -162,7 +162,7 @@ public void test5() { graph2.removeEdge(nodes.get(0), nodes.get(1)); - int shd = GraphUtilsSearch.structuralHammingDistance(graph1, graph2); + int shd = GraphSearchUtils.structuralHammingDistance(graph1, graph2); assertEquals(3, shd); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java index dcd26c4b1c..b081c4c3f5 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -200,7 +200,7 @@ public void testSearch13() { // DagToPag dagToPag = new DagToPag(trueGraph); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(trueGraph); + Graph truePag = GraphSearchUtils.dagToPag(trueGraph); assertEquals(graph, truePag); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index b6c25cb9ef..f6f2de24b2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java @@ -41,7 +41,7 @@ import edu.cmu.tetrad.search.score.*; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.GeneralizedSemIm; import edu.cmu.tetrad.sem.GeneralizedSemPm; @@ -114,7 +114,7 @@ public void explore1() { alg.setFaithfulnessAssumed(true); Graph estCPDAG = alg.search(); - Graph trueCPDAG = GraphUtilsSearch.cpdagForDag(dag); + Graph trueCPDAG = GraphSearchUtils.cpdagForDag(dag); estCPDAG = GraphUtils.replaceNodes(estCPDAG, vars); @@ -179,9 +179,9 @@ public void explore2() { Graph estCPDAG = ges.search(); - Graph trueCPDAG = GraphUtilsSearch.cpdagForDag(dag); + Graph trueCPDAG = GraphSearchUtils.cpdagForDag(dag); - int[][] counts = GraphUtilsSearch.graphComparison(trueCPDAG, estCPDAG, null); + int[][] counts = GraphSearchUtils.graphComparison(trueCPDAG, estCPDAG, null); int[][] expectedCounts = { {2, 0, 0, 0, 0, 1}, @@ -202,7 +202,7 @@ public void testExplore3() { Graph graph = GraphUtils.convert("A-->B,A-->C,B-->D,C-->D"); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); Graph CPDAG = fges.search(); - assertEquals(GraphUtilsSearch.cpdagForDag(graph), CPDAG); + assertEquals(GraphSearchUtils.cpdagForDag(graph), CPDAG); } @Test @@ -210,7 +210,7 @@ public void testExplore4() { Graph graph = GraphUtils.convert("A-->B,A-->C,A-->D,B-->E,C-->E,D-->E"); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); Graph CPDAG = fges.search(); - assertEquals(GraphUtilsSearch.cpdagForDag(graph), CPDAG); + assertEquals(GraphSearchUtils.cpdagForDag(graph), CPDAG); } @Test @@ -219,7 +219,7 @@ public void testExplore5() { edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); fges.setFaithfulnessAssumed(false); Graph CPDAG = fges.search(); - assertEquals(GraphUtilsSearch.cpdagForDag(graph), CPDAG); + assertEquals(GraphSearchUtils.cpdagForDag(graph), CPDAG); } @@ -677,7 +677,7 @@ public void testFromGraph() { fges.setVerbose(true); fges.setParallelized(true); Graph CPDAG1 = fges.search(); - Graph CPDAG2 = GraphUtilsSearch.cpdagFromDag(dag); + Graph CPDAG2 = GraphSearchUtils.cpdagFromDag(dag); assertEquals(CPDAG2, CPDAG1); } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java index ff41042af4..317cfd80e9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java @@ -33,7 +33,7 @@ import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; @@ -109,11 +109,11 @@ public void test1() { // dagToPag.setMaxPathLength(maxPathLength); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(dag); + Graph truePag = GraphSearchUtils.dagToPag(dag); outGraph = GraphUtils.replaceNodes(outGraph, truePag.getNodes()); - int[][] counts = GraphUtilsSearch.graphComparison(truePag, outGraph, null); + int[][] counts = GraphSearchUtils.graphComparison(truePag, outGraph, null); int[][] expectedCounts = { {0, 0, 0, 0, 0, 0}, @@ -192,7 +192,7 @@ public void testFromGraph() { // dagToPag.setCompleteRuleSetUsed(false); // Graph pag2 = dagToPag.convert(); - Graph pag2 = GraphUtilsSearch.dagToPag(dag); + Graph pag2 = GraphSearchUtils.dagToPag(dag); assertEquals(pag2, pag1); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java index f75c6a57d0..ad2bc4553c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGeneralResamplingTest.java @@ -37,7 +37,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -189,7 +189,7 @@ public void testGFCIc() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(dag); + Graph truePag = GraphSearchUtils.dagToPag(dag); int[] causalOrdering = new int[numVars]; @@ -251,7 +251,7 @@ public void testGFCId() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(dag); + Graph truePag = GraphSearchUtils.dagToPag(dag); BayesPm pm = new BayesPm(dag, 2, 3); BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM); @@ -311,7 +311,7 @@ public void testFCIc() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(dag); + Graph truePag = GraphSearchUtils.dagToPag(dag); int[] causalOrdering = new int[numVars]; @@ -375,7 +375,7 @@ public void testFCId() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphUtilsSearch.dagToPag(dag); + Graph truePag = GraphSearchUtils.dagToPag(dag); BayesPm pm = new BayesPm(dag, 2, 3); BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index d9a8f5df67..081213cd78 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -54,7 +54,7 @@ import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.*; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.GraphoidAxioms; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.TeyssierScorer; @@ -2586,7 +2586,7 @@ public void testFcoAlgsFromDsep() { Graph trueGraph = RandomGraph.randomGraph(20, 8, 40, 100, 100, 100, false); - Graph truePag = GraphUtilsSearch.dagToPag(trueGraph); + Graph truePag = GraphSearchUtils.dagToPag(trueGraph); trueGraphMap.put(i, new HashMap<>()); trueGraphs.add(trueGraph); @@ -3079,8 +3079,8 @@ public void testWayne2() { g2 = GraphUtils.replaceNodes(g2, g1.getNodes()); if (g1.equals(g2)) gsCount++; - gsShd += GraphUtilsSearch.structuralHammingDistance( - GraphUtilsSearch.cpdagForDag(g1), GraphUtilsSearch.cpdagForDag(g2)); + gsShd += GraphSearchUtils.structuralHammingDistance( + GraphSearchUtils.cpdagForDag(g1), GraphSearchUtils.cpdagForDag(g2)); for (int i = 0; i < alpha.length; i++) { // test.setAlpha(alpha[i]); @@ -3094,8 +3094,8 @@ public void testWayne2() { g3 = GraphUtils.replaceNodes(g3, g1.getNodes()); if (g1.equals(g3)) pearlCounts[i]++; - pearlShd[i] += GraphUtilsSearch.structuralHammingDistance( - GraphUtilsSearch.cpdagForDag(g1), GraphUtilsSearch.cpdagForDag(g3)); + pearlShd[i] += GraphSearchUtils.structuralHammingDistance( + GraphSearchUtils.cpdagForDag(g1), GraphSearchUtils.cpdagForDag(g3)); } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java index a775cd6446..76f4cfe7bf 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestMimbuild.java @@ -31,7 +31,7 @@ import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.Bpc; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MimUtils; import edu.cmu.tetrad.sem.ReidentifyVariables; import edu.cmu.tetrad.sem.SemIm; @@ -107,7 +107,7 @@ public void test1() { mimbuild.setPenaltyDiscount(1); mimbuild.setMinClusterSize(3); mimbuildStructure = mimbuild.search(partition, latentVarList, new CovarianceMatrix(data)); - int shd = GraphUtilsSearch.structuralHammingDistance(mimStructure, mimbuildStructure); + int shd = GraphSearchUtils.structuralHammingDistance(mimStructure, mimbuildStructure); assertEquals(7, shd); } else if (mimbuildMethod == 3) { // System.out.println("Mimbuild Trek\n"); @@ -115,7 +115,7 @@ public void test1() { mimbuild.setAlpha(0.1); mimbuild.setMinClusterSize(3); mimbuildStructure = mimbuild.search(partition, latentVarList, new CovarianceMatrix(data)); - int shd = GraphUtilsSearch.structuralHammingDistance(mimStructure, mimbuildStructure); + int shd = GraphSearchUtils.structuralHammingDistance(mimStructure, mimbuildStructure); assertEquals(3, shd); } else { throw new IllegalStateException(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java index 36b7257efb..dfd9243721 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java @@ -29,7 +29,7 @@ import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.MillisecondTimes; @@ -44,7 +44,7 @@ import java.util.Comparator; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphUtilsSearch.dagToPag; +import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -222,7 +222,7 @@ public void checknumCPDAGsToStore() { IndTestDSep test = new IndTestDSep(graph); Pc pc = new Pc(test); Graph CPDAG = pc.search(); - Graph CPDAG2 = GraphUtilsSearch.cpdagFromDag(graph); + Graph CPDAG2 = GraphSearchUtils.cpdagFromDag(graph); assertEquals(CPDAG, CPDAG2); } } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java index e265d430c4..e0a678cb03 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndTestProbabilistic; -import edu.cmu.tetrad.search.utils.GraphUtilsSearch; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.BayesImParser; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; @@ -61,7 +61,7 @@ public void testRandomDiscreteData() { // dagToPag.setCompleteRuleSetUsed(false); // Graph PAG_True = dagToPag.convert(); - Graph PAG_True = GraphUtilsSearch.dagToPag(dag); + Graph PAG_True = GraphSearchUtils.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, dataSet.getVariables()); @@ -134,7 +134,7 @@ public void testDiscreteRealData() { // dagToPag.setCompleteRuleSetUsed(false); // Graph PAG_True = dagToPag.convert(); - Graph PAG_True = GraphUtilsSearch.dagToPag(dag); + Graph PAG_True = GraphSearchUtils.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, dataSet.getVariables()); From 035f6420b925b59f45b1ab1f9125aa313fd016dd Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 22:09:15 -0400 Subject: [PATCH 376/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/utils/ClusterSignificance.java | 6 ++++++ .../java/edu/cmu/tetrad/search/utils/ResolveSepsets.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java index de2540ed36..d283c38742 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java @@ -26,6 +26,12 @@ * @author josephramsey */ public class ClusterSignificance { + + /** + * Gives the options for checking significance of clusters--could check the + * significance using a regression model, or could check to see if the cluster + * is a clique, or could not do the check. + */ public enum CheckType {Significance, Clique, None} private final List variables; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java index 9798ea1308..bbe502de7b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java @@ -36,7 +36,7 @@ import java.util.List; /** - *

    Provides some utilities for resolving inconsistencies that arise + *

    Provides some utilities for resolving inconsistencies that arise * between sepsets learned for overlapping datasets. This occurs frequently when * using the DCI and ION algorithm. A reference is here:

    * From e3174aa484f644f60cf7d6da346dd2b1e79c4686 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 22:11:57 -0400 Subject: [PATCH 377/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java index 1504fedb1e..b9ff86d1d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java @@ -265,6 +265,9 @@ public static DataSet createShiftedData(DataSet data, int[] shifts) { return new BoxDataSet(new DoubleDataBox(shiftedData.toArray()), data.getVariables()); } + /** + * Gives a result consisting of the residuals and collapsed var graphs. + */ public static class VarResult { private final DataSet residuals; From f8cd817905c3d5117bcf7cac99ae5f5fd869e556 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 22:29:08 -0400 Subject: [PATCH 378/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/score/BdeScore.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java | 3 +++ .../tetrad/search/score/ConditionalGaussianLikelihood.java | 5 ++++- .../cmu/tetrad/search/score/ConditionalGaussianScore.java | 5 ++++- .../edu/cmu/tetrad/search/score/DegenerateGaussianScore.java | 3 +++ .../java/edu/cmu/tetrad/search/score/DiscreteBicScore.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/score/EbicScore.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/score/GicScores.java | 3 +++ .../main/java/edu/cmu/tetrad/search/score/ImagesScore.java | 3 +++ .../main/java/edu/cmu/tetrad/search/score/IndTestScore.java | 3 +++ .../java/edu/cmu/tetrad/search/score/MagSemBicScore.java | 3 +++ .../java/edu/cmu/tetrad/search/score/MnlrLikelihood.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java | 3 +++ .../java/edu/cmu/tetrad/search/score/PoissonPriorScore.java | 3 +++ .../main/java/edu/cmu/tetrad/search/score/SemBicScore.java | 3 +++ .../src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java | 3 +++ 16 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java index e931414be2..6888aa5f9b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java @@ -36,6 +36,9 @@ * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). * https://doi.org/10.1007/BF00994016

    * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey * @see BdeuScore * */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java index e70eb2417b..33aa7e6cb2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java @@ -38,6 +38,9 @@ * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). * https://doi.org/10.1007/BF00994016

    * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey * @see BdeScore */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java index 86e6274239..4c097e9fa5 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java @@ -43,7 +43,10 @@ * continuous mixedVariables are jointly Gaussian conditional on the discrete mixedVariables; in all other cases, it will * be less than maximal. For an algorithm like FGS this is fine. * - * @author josephramsey + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * + * * @author josephramsey */ public class ConditionalGaussianLikelihood { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index a4df20ebb4..7ff9e19215 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -38,7 +38,10 @@ * score for mixed discrete/Gaussian data using the conditional Gaussian * likelihood function (see). * - * @author josephramsey + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * + * * @author josephramsey * @see ConditionalGaussianLikelihood * @see DegenerateGaussianScore */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 918a23269e..b8e9e14944 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -51,6 +51,9 @@ * * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author Bryan Andrews */ public class DegenerateGaussianScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java index 400f5bb29c..f34979de41 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java @@ -35,6 +35,9 @@ /** * Calculates the discrete BIC score. * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey */ public class DiscreteBicScore implements DiscreteScore { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java index 076886615e..c92f364995 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java @@ -38,6 +38,9 @@ /** * Implements the extended BIC (EBIC) score (Chen and Chen).. * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey */ public class EbicScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index 0325b211f0..6d6d79b019 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -40,6 +40,9 @@ * high dimensions. The Journal of Machine Learning Research, 13(1), 1037-1057. * Foster and George.

    * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey */ public class GicScores implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java index 663c3e42ea..209995aef0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java @@ -42,6 +42,9 @@ * ensure that all of the scores share the same (object-identical) * variables.

    * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey * @see Fges * @see Grasp diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java index 2da520d89c..dedff94eec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java @@ -34,6 +34,9 @@ * will calcualte p-values; this simply reports alpha - p as a score, which will * be higher for greater dependence. * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey */ public class IndTestScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java index 2e32926836..b51bf99b15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java @@ -38,6 +38,9 @@ * Gives ia BIC score for a linear, Gaussian MAG (Mixed Ancestral Graph). It * will perform the same as SemBicScore for DAGs. * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author Bryan Andrews */ public class MagSemBicScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java index 338dd434a2..df59eb5739 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java @@ -42,6 +42,9 @@ /** * Calculates Mixed Variables Polynomial likelihood. * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author Bryan Andrews */ public class MnlrLikelihood { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java index 8e9f884c16..bdc65f94fb 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java @@ -30,6 +30,9 @@ /** * Implements a mixed variable polynomial BIC score for fGES. * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author Bryan Andrews */ public class MnlrScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index fabdb76d7e..5f5ca3cdcb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -36,6 +36,9 @@ /** * Implements Poisson prior score (Bryan). * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey */ public class PoissonPriorScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index a979a4cd12..e930f96fd0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -42,6 +42,9 @@ /** * Implements the continuous BIC score for FGES. * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey */ public class SemBicScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index 755577b3cc..6937abc356 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -58,6 +58,9 @@ * can be expected to improve, though setting m0 to 0 for all variables * does not give bad results even by itself.

    * + *

    As for all scores in Tetrad, higher scores mean more dependence, and negative + * scores indicates independence.

    + * * @author josephramsey */ public class ZsbScore implements Score { From 407cb7c6f693dfb2481807f4c61a5cbfdb6689f5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 22:42:01 -0400 Subject: [PATCH 379/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java | 6 ++++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java | 6 ++++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java | 3 +++ .../main/java/edu/cmu/tetrad/search/FactorAnalysis.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java | 5 +++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java | 5 +++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java | 7 +++++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java | 7 +++++++ .../src/main/java/edu/cmu/tetrad/search/GraspFci.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/GrowShrink.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/Mimbuild.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/PcLingam.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java | 5 +++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java | 4 ++++ .../main/java/edu/cmu/tetrad/search/PermutationSearch.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java | 4 ++++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 4 ++++ .../main/java/edu/cmu/tetrad/search/SuborderSearch.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/SvarFas.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/SvarFci.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/SvarFges.java | 4 ++++ .../src/main/java/edu/cmu/tetrad/search/SvarGfci.java | 4 ++++ 39 files changed, 161 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 1698ad391b..8e320bd9c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -38,12 +38,17 @@ *

    Uses BOSS in place of FGES for the initial step in the GFCI algorithm. * This tends to produce a accurate PAG than GFCI as a result, for the latent * variables case. This is a simple substitution; the reference for GFCI is here:

    + * *

    J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

    + * *

    For BOSS only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey * @author bryan andrews * @see Boss @@ -51,6 +56,7 @@ * @see GraspFci * @see SpFci * @see Fges + * @see Knowledge */ public final class BFci implements IGraphSearch { 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 f947290216..7478780dec 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 @@ -27,11 +27,15 @@ *

    This class is meant to be used in the context of the PermutationSearch class (see). * the proper use is PermutationSearch search = new PermutationSearch(new Sp(score));

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author bryanandrews * @author josephramsey * @see Sp * @see Grasp * @see PermutationSearch + * @see Knowledge */ public class Boss implements SuborderSearch { private final BesPermutation bes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index c08a4cf9f7..8fcbac083a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -53,6 +53,9 @@ *

    Bron, C. and Kerbosch, J. (1973) "Algorithm 457: Finding all cliques of an undirected graph". * Communications of ACM 16, 575-577.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author Ricardo Silva * @see Fofc * @see Ftfc 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 efbc0fe583..c4b7c926b1 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 @@ -42,6 +42,9 @@ * PAG graphs, with various types of underlining, that represents a Markov equivalence of * the true DAG.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author Frank C. Wimberly * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 020a6e0210..9b1095cb3a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -39,10 +39,14 @@ * collider orienatation is conservative, there may be ambiguous triples; these * may be retrieved using that accessor method. * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 * @see Fci * @see #getAmbiguousTriples() + * @see Knowledge */ public final class Cfci implements IGraphSearch { 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 f26568fdcd..43f0729bed 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 @@ -40,7 +40,13 @@ * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested * locally. * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey (this version). + * @see Pc + * @see PcMax + * @see Knowledge */ public final class Cpc implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index a2b065af3a..5b59f66514 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -30,6 +30,9 @@ *

    Colombo, D., and Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. * The Journal of Machine Learning Research, 15(1), 3741-3782.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author josephramsey */ public class Cstar { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index 03b38626d5..447ac0b8ab 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -42,6 +42,9 @@ * algorithm, it has a great introduction to the subject that gives the reader a good * appreciation of the philosophy and the mathematics behind factor analysis.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author Mike Freenor */ public class FactorAnalysis { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index 21d5f017ed..3f1367c917 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -54,9 +54,13 @@ *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, * prediction, and search. MIT press.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey. * @see Pc * @see Fci + * @see Knowledge */ public class Fas implements IFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java index 5ca8abadd9..8ebd333a4f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java @@ -41,9 +41,13 @@ * That is, if X _||_ Y | Z, but Z determines X or Y, then the edge X---Y is * not removed.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author peterspirtes * @author josephramsey. * @see Fas + * @see Knowledge */ public class Fasd implements IFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 79cbe6c138..283dbbc9f7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -131,7 +131,12 @@ * --twoCycleScreeningThreshold 0 --orientationAlpha 0.1 -structurePrior 0 *

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey + * @see Knowledge + * @see Lofs */ public final class Fask implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index a271e11460..3d8e73a029 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -57,12 +57,16 @@ *

    Zhang, J. (2008). On the completeness of orientation rules for causal discovery in the presence * of latent confounders and selection bias. Artificial Intelligence, 172(16-17), 1873-1896.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author peterspirtes * @author clarkglymour * @author jijizhang * @author josephramsey * @see FciOrient * @see Pc + * @see Knowledge */ public final class Fci implements IGraphSearch { private SepsetMap sepsets; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index 3d2859c005..a7db8d70e9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -42,8 +42,13 @@ * (2019). Feasibility of lung cancer prediction from low-dose CT scan and smoking factors using * causal models. Thorax, 74(7), 643-649.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey * @see Fci + * @see PcMax + * @see Knowledge */ public final class FciMax implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index a1d26fed2a..ba3cbd7d5b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -68,8 +68,15 @@ * *

    A number of other optimizations were also. See code for details.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author Ricardo Silva * @author josephramsey + * @see Grasp + * @see Boss + * @see Sp + * @see Knowledge */ public final class Fges implements IGraphSearch, DagScorer { private final Set emptySet = new HashSet<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index 25a7a739a2..6acf5ace09 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -44,8 +44,12 @@ * over the Markov blankets of a list of variables X1,..,Xn), together * with the target X (or, respectively, the targets X1,...,Xn).

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey * @see Fges + * @see Knowledge */ public final class FgesMb { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index df307de815..8760c6ee20 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -56,6 +56,9 @@ * for the initial step; in this repository we give three other options, * GRaSP-FCI, BFCI (BOSS FCI), and SP-FCI (see).

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author Juan Miguel Ogarrio * @author peterspirtes * @author josephramsey @@ -65,6 +68,7 @@ * @see BFci * @see SpFci * @see Fges + * @see Knowledge */ public final class GFci implements IGraphSearch { private Graph graph; 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 38de2ffb27..4f01d45883 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 @@ -38,8 +38,15 @@ * that tier, which allows the SP algorithm to address tiered (e.g., time series) * problems with larger numbers of variables.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author bryanandrews * @author josephramsey + * @see Fges + * @see Boss + * @see Sp + * @see Knowledge */ public class Grasp { private final List variables; 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 d920606ed2..160266e61a 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 @@ -47,6 +47,9 @@ *

    For GRaSP only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey * @author bryanandrews * @see Grasp @@ -54,6 +57,7 @@ * @see BFci * @see SpFci * @see Fges + * @see Knowledge */ public final class GraspFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index 011e8a4761..cf89797f8b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -33,6 +33,9 @@ *

    Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. * Advances in neural information processing systems, 12.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author josephramsey */ public class GrowShrink implements IMbSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 452c01ea97..79665bfee4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -70,6 +70,9 @@ * in absolute value for including entries in a possible strong diagonal for W, and a threshold * for BHat for including edges in the final graph.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author peterspirtes * @author gustavolacerda * @author patrickhoyer diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 4609cffca5..91b3a58b47 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -48,6 +48,9 @@ * in absolute value for including entries in a possible strong diagonal for W, and a threshold * for BHat for including edges in the final graph.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author josephramsey */ public class Lingam { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 610477618b..d230e37402 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -48,9 +48,13 @@ * to use to do the orientations are given in the enum, Lofs.Rule. Most of these are * taken from the literature and ca be googled.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey * @see Score * @see Rule + * @see Knowledge */ public class Lofs { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 1f7188ea1a..55be85dfb6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -59,10 +59,14 @@ *

    A suitable clustering for Mimbuild may be obtained using the BPC or FOFC * algorithm (see).

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey * @see Bpc * @see Fofc * @see #getLatentsCov() + * @see Knowledge */ public class Mimbuild { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index b648e14c5c..e12612ee74 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -44,7 +44,11 @@ /** * Implements Mimbuild using the theory of treks and ranks. * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author adambrodie + * @see Knowledge */ public class MimbuildTrek { 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 32e6d2919e..3c134342cd 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 @@ -56,11 +56,15 @@ *

    Meek, C. (1995), "Causal inference and causal explanation with background * knowledge."

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author peterspirtes * @author chrismeek * @author clarkglymour * @author josephramsey * @see Fci + * @see Knowledge */ public class Pc implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java index 14dd8b0be7..125b28be5a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java @@ -59,6 +59,9 @@ *

    This may be replaced by a more general algorithm that allows alternatives for the * CPDAG search and for the the non-Gaussian orientation method.

    * + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    + * * @author peterspirtes * @author patrickhoyer * @author josephramsey 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 9c97bd089a..13b41ad6bb 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 @@ -41,10 +41,14 @@ /** * Modifies the PC algorithm to use the Max P rule for orienting ushielded colliders. * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey. * @see PcMax * @see Pc * @see Fasd + * @see Knowledge */ public class PcMax implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index f3e49a1f03..d28c8001c0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -37,7 +37,12 @@ * independence information. This CPDAG may be used to generate the actual list of DAG's that might be Markov * blankets. Note that this code has been converted to be consistent with the CPC algorithm.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey + * @see FgesMb + * @see Knowledge */ public final class PcMb implements IMbSearch, IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index c9ca427b05..2a0ccce1e4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -39,10 +39,14 @@ /** * Modifies the PC algorithm to handle the deterministic case. * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author peterspirtes * @author josephramsey. * @see Fasd * @see Pc + * @see Knowledge */ public class Pcd implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index 9ac415f829..ef554e1662 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -23,10 +23,14 @@ * many more varaibles than otherwise, so long as tiered knowledge is available * to organize the search.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author bryanandrews * @see SuborderSearch * @see Boss * @see Sp + * @see Knowledge */ public class PermutationSearch { private final SuborderSearch suborderSearch; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 94d26cb113..f729995ccd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -50,11 +50,15 @@ * high-dimensional directed acyclic graphs with latent and selection variables. The * Annals of Statistics, 294-321.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author Erin Korber, June 2004 * @author Alex Smith, December 2008 * @author josephramsey * @author Choh-Man Teng * @see Fci + * @see Knowledge */ public final class Rfci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 4b97d7ef96..305a9b3b49 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -30,11 +30,15 @@ *

    Raskutti, G., & Uhler, C. (2018). Learning directed acyclic graph models based on * sparsest permutations. Stat, 7(1), e183.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author bryanandrews * @author josephramsey * @see PermutationSearch * @see Knowledge * @see SpFci + * @see Knowledge */ public class Sp implements SuborderSearch { private final Score score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index db21b986c5..c775126922 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -53,6 +53,9 @@ * exponential in the number of variables. So SP is limited to about 10 * variables.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author josephramsey * @author bryan andrews * @see Grasp @@ -60,6 +63,7 @@ * @see BFci * @see GraspFci * @see Fges + * @see Knowledge */ public final class SpFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index e008c4c713..b993cab829 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -17,10 +17,14 @@ * where PermutationSearch handles an optimization for tiered knowledge where each * tier can be search separately in order. (See the documentation for that class.) * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author bryanandrews * @see PermutationSearch * @see Boss * @see Sp + * @see Knowledge */ public interface SuborderSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java index 4374a1e17e..539bfd15da 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java @@ -41,8 +41,12 @@ * tructure assumed by SvarFCI. Based on (but not identical to) code by Entner and Hoyer * for their 2010 paper. Modified by dmalinsky 4/21/2016.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author dmalinsky * @see Fas + * @see Knowledge */ public class SvarFas implements IFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index b1ccc38858..b52231515e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -47,8 +47,12 @@ * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. * (By a remark of Zhang's, the rule applications can be staged in this way.) * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author danielmalinsky * @see Fci + * @see Knowledge */ public final class SvarFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 4f15d48635..b455bb466a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -44,7 +44,11 @@ * SvarFCI. Based on (but not identicial to) code by Entner and Hoyer for their 2010 paper. Modified * by DMalinsky 4/20/2016.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author dmalinsky + * @see Knowledge */ public final class SvarFciOrient { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java index 9b3bb047ff..cc56df49dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java @@ -56,8 +56,12 @@ * *

    A number of other optimizations were added 5/2015. See code for details.

    * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author danielmalinsky * @see Fges + * @see Knowledge */ public final class SvarFges implements IGraphSearch, DagScorer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index bf7aef47f3..1a88acc56e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -45,8 +45,12 @@ /** * Adapts GFCI to the SVAR case. * + *

    This class is configured to respect knowledge of forbidden and required + * edges, including knowledge of temporal tiers.

    + * * @author danielmalinsky * @see GFci + * @see Knowledge */ public final class SvarGfci implements IGraphSearch { From 6fedea23f16dcd6985064681cc1e77b03cb0d4fe Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 22:44:26 -0400 Subject: [PATCH 380/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/score/BdeScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java | 2 +- .../cmu/tetrad/search/score/ConditionalGaussianLikelihood.java | 2 +- .../edu/cmu/tetrad/search/score/ConditionalGaussianScore.java | 2 +- .../edu/cmu/tetrad/search/score/DegenerateGaussianScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/EbicScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/GicScores.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java | 2 +- .../main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java | 2 +- .../java/edu/cmu/tetrad/search/score/PoissonPriorScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java index 6888aa5f9b..eed645a1d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java @@ -37,7 +37,7 @@ * https://doi.org/10.1007/BF00994016

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey * @see BdeuScore diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java index 33aa7e6cb2..c415d19338 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java @@ -39,7 +39,7 @@ * https://doi.org/10.1007/BF00994016

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey * @see BdeScore diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java index 4c097e9fa5..e895828e9f 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java @@ -44,7 +44,7 @@ * be less than maximal. For an algorithm like FGS this is fine. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index 7ff9e19215..7c80085ed8 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -39,7 +39,7 @@ * likelihood function (see). * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * * @author josephramsey * @see ConditionalGaussianLikelihood diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index b8e9e14944..45bed7ba20 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -52,7 +52,7 @@ * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author Bryan Andrews */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java index f34979de41..c251c068d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java @@ -36,7 +36,7 @@ * Calculates the discrete BIC score. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java index c92f364995..65b6f091a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java @@ -39,7 +39,7 @@ * Implements the extended BIC (EBIC) score (Chen and Chen).. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index 6d6d79b019..d6f208bcb3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -41,7 +41,7 @@ * Foster and George.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java index 209995aef0..f6edeaa436 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java @@ -43,7 +43,7 @@ * variables.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey * @see Fges diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java index dedff94eec..45e6c1bdd1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java @@ -35,7 +35,7 @@ * be higher for greater dependence. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java index b51bf99b15..0e2647670f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java @@ -39,7 +39,7 @@ * will perform the same as SemBicScore for DAGs. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author Bryan Andrews */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java index df59eb5739..fc990c5000 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java @@ -43,7 +43,7 @@ * Calculates Mixed Variables Polynomial likelihood. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author Bryan Andrews */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java index bdc65f94fb..bca9fdb132 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java @@ -31,7 +31,7 @@ * Implements a mixed variable polynomial BIC score for fGES. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author Bryan Andrews */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index 5f5ca3cdcb..ef5a397642 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -37,7 +37,7 @@ * Implements Poisson prior score (Bryan). * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index e930f96fd0..6a65bd56ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -43,7 +43,7 @@ * Implements the continuous BIC score for FGES. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index 6937abc356..adbeed6479 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -59,7 +59,7 @@ * does not give bad results even by itself.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicates independence.

    + * scores indicate independence.

    * * @author josephramsey */ From df14293e39677aab5744101ba6beddcd9a5edfbc Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 7 May 2023 22:47:35 -0400 Subject: [PATCH 381/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index 6a65bd56ee..7ad5de7f82 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -40,7 +40,8 @@ import static org.apache.commons.math3.util.FastMath.log; /** - * Implements the continuous BIC score for FGES. + * Implements the linear, Gaussian BIC score, with a 'penalty discount' multiplier + * on the BIC penalty. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    From 90be3ee1dd0345142c7f293633fb12aab7d4e41b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 04:26:33 -0400 Subject: [PATCH 382/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algorithm/oracle/pag/GraspFci.java | 6 - .../main/java/edu/cmu/tetrad/search/BFci.java | 51 ++- .../main/java/edu/cmu/tetrad/search/Boss.java | 5 + .../main/java/edu/cmu/tetrad/search/Bpc.java | 36 +- .../main/java/edu/cmu/tetrad/search/Ccd.java | 15 +- .../main/java/edu/cmu/tetrad/search/Cfci.java | 2 + .../main/java/edu/cmu/tetrad/search/Cpc.java | 82 ++-- .../java/edu/cmu/tetrad/search/Cstar.java | 21 +- .../edu/cmu/tetrad/search/FactorAnalysis.java | 33 +- .../main/java/edu/cmu/tetrad/search/Fas.java | 32 +- .../main/java/edu/cmu/tetrad/search/Fasd.java | 79 ++-- .../main/java/edu/cmu/tetrad/search/Fask.java | 65 ++- .../java/edu/cmu/tetrad/search/FastIca.java | 60 +-- .../main/java/edu/cmu/tetrad/search/Fci.java | 125 +++--- .../java/edu/cmu/tetrad/search/FciMax.java | 276 ++++++------ .../main/java/edu/cmu/tetrad/search/Fges.java | 23 +- .../java/edu/cmu/tetrad/search/FgesMb.java | 404 ++++++++---------- .../main/java/edu/cmu/tetrad/search/Fofc.java | 6 + .../main/java/edu/cmu/tetrad/search/Ftfc.java | 16 +- .../main/java/edu/cmu/tetrad/search/GFci.java | 160 ++++--- .../java/edu/cmu/tetrad/search/GraspFci.java | 212 +++------ .../main/java/edu/cmu/tetrad/search/IFas.java | 12 +- .../edu/cmu/tetrad/search/IGraphSearch.java | 2 +- .../java/edu/cmu/tetrad/search/IMbSearch.java | 2 +- .../main/java/edu/cmu/tetrad/search/Ida.java | 8 +- .../java/edu/cmu/tetrad/search/LingD.java | 6 + .../java/edu/cmu/tetrad/search/Lingam.java | 10 +- .../java/edu/cmu/tetrad/search/Mimbuild.java | 2 - .../edu/cmu/tetrad/search/MimbuildTrek.java | 54 ++- .../java/edu/cmu/tetrad/search/PcMax.java | 34 +- .../main/java/edu/cmu/tetrad/search/PcMb.java | 24 +- .../cmu/tetrad/search/PermutationSearch.java | 53 ++- .../main/java/edu/cmu/tetrad/search/Rfci.java | 4 +- .../study/performance/PerformanceTests.java | 4 +- 34 files changed, 978 insertions(+), 946 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index 44ab36c0be..927c0f75e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -103,12 +103,6 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setVerbose(parameters.getBoolean(Params.VERBOSE)); search.setKnowledge(this.knowledge); - Object obj = parameters.get(Params.PRINT_STREAM); - - if (obj instanceof PrintStream) { - search.setOut((PrintStream) obj); - } - return search.search(); } else { GraspFci algorithm = new GraspFci(this.test, this.score); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 8e320bd9c1..d4ea3c26f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -91,6 +91,15 @@ public final class BFci implements IGraphSearch { private boolean doDiscriminatingPathRule = true; //============================CONSTRUCTORS============================// + + /** + * Constructor. The test and score should be for the same data. + * + * @param test The test to use. + * @param score The score to use. + * @see IndependenceTest + * @see Score + */ public BFci(IndependenceTest test, Score score) { if (score == null) { throw new NullPointerException(); @@ -160,43 +169,52 @@ public void setMaxDegree(int maxDegree) { // The maxDegree for the fast adjacency search. } - public Knowledge getKnowledge() { - return this.knowledge; - } - + /** + * Sets the knowledge to be used for the search. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } /** - * @return true if Zhang's complete rule set should be used, false if only - * R1-R4 (the rule set of the original FCI) should be used. False by + * Returns True if Zhang's complete rule set should be used, false if only + * 1-R4 (the rule set of the original FCI) should be used. False by * default. + * + * @return This. */ public boolean isCompleteRuleSetUsed() { return this.completeRuleSetUsed; } /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set - * should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. + * Sets whether the complete (Zhang's) ruleset should be used. + * + * @param completeRuleSetUsed True if Zhang's complete rule set should be used, false if + * only R1-R4 (the rule set of the original FCI) should be used. + * False by default. */ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { this.completeRuleSetUsed = completeRuleSetUsed; } /** - * @return the maximum length of any discriminating path, or -1 of + * Returns the maximum length of any discriminating path, or -1 of * unlimited. + * + * @return This maximum. */ public int getMaxPathLength() { return this.maxPathLength; } /** - * @param maxPathLength the maximum length of any discriminating path, or -1 - * if unlimited. + * Returns the maximum length of any discriminating path, or -1 + * if unlimited. + * + * @param maxPathLength This maximum. */ public void setMaxPathLength(int maxPathLength) { if (maxPathLength < -1) { @@ -206,13 +224,6 @@ public void setMaxPathLength(int maxPathLength) { this.maxPathLength = maxPathLength; } - /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - /** * Sets whether verbose output should be printed. * @@ -224,6 +235,8 @@ public void setVerbose(boolean verbose) { /** * The independence test being used for some steps in final orientation. + * + * @return This test. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; 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 7478780dec..79cc6a585b 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 @@ -130,6 +130,11 @@ public void searchSuborder(List prefix, List suborder, Map + * *

    Silva, R., Scheines, R., Glymour, C., Spirtes, P., & Chickering, D. M. (2006). * Learning the Structure of Linear Latent Variable Models. Journal of Machine Learning * Research, 7(2).

    - *

    Some more References: + * + *

    Some more References:

    + * *

    Silva, R.; Scheines, R.; Spirtes, P.; Glymour, C. (2003). "Learning measurement models". * Technical report CMU-CALD-03-100, Center for Automated Learning and Discovery, Carnegie Mellon * University.

    + * *

    Bollen, K. (1990). "Outlier screening and distribution-free test for vanishing tetrads." * Sociological Methods and Research 19, 80-92.

    + * *

    Wishart, J. (1928). "Sampling errors in the theory of two factors". British Journal of * Psychology 19, 180-187.

    + * *

    Bron, C. and Kerbosch, J. (1973) "Algorithm 457: Finding all cliques of an undirected graph". * Communications of ACM 16, 575-577.

    * - *

    This class is not configured to respect knowledge of forbidden and required - * edges.

    + *

    This class is not configured to respect knowledge of forbidden and required + * edges.

    * * @author Ricardo Silva * @see Fofc @@ -70,7 +76,7 @@ public final class Bpc { private int[] labels; private boolean scoreTestMode; - /** + /* * Color code for the different edges that show up during search */ final int EDGE_NONE = 0; @@ -90,7 +96,12 @@ public final class Bpc { //**************************** INITIALIZATION ***********************************/ /** - * Constructor BuildPureClusters + * Constructor. + * + * @param covarianceMatrix The covariance matrix to analyze. + * @param alpha The significance cutoff to use. + * @param sigTestType The type of the significance test to use. + * @see BpcTestType */ public Bpc(ICovarianceMatrix covarianceMatrix, double alpha, BpcTestType sigTestType) { @@ -102,6 +113,14 @@ public Bpc(ICovarianceMatrix covarianceMatrix, double alpha, initAlgorithm(alpha, sigTestType); } + /** + * Constructor. + * + * @param dataSet The dataset to analyze. + * @param alpha The significance cutoff to use. + * @param sigTestType The type of the significance test to use. + * @see BpcTestType + */ public Bpc(DataSet dataSet, double alpha, BpcTestType sigTestType) { if (dataSet.isContinuous()) { this.dataSet = dataSet; @@ -115,7 +134,10 @@ public Bpc(DataSet dataSet, double alpha, BpcTestType sigTestType) { /** - * @return the result search graph, or null if there is no model. + * Runs the search and returns the graph, or null if there is no model. This + * will be a graph with clusters having their latents as parents. + * + * @return This graph. */ public Graph search() { long start = MillisecondTimes.timeMillis(); @@ -167,6 +189,8 @@ public Graph search() { /** * Returns the wrapped covariance matrix. + * + * @return This. */ public ICovarianceMatrix getCovarianceMatrix() { return this.covarianceMatrix; 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 c4b7c926b1..6b7ab5535e 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 @@ -68,12 +68,15 @@ public Ccd(IndependenceTest test) { //======================================== PUBLIC METHODS ====================================// /** - * The search method assumes that the IndependenceTest provided to the constructor is a conditional independence - * oracle for the SEM (or Bayes network) which describes the causal structure of the population. The method returns - * a PAG instantiated as a Tetrad GaSearchGraph which represents the equivalence class of digraphs which are - * d-separation equivalent to the digraph of the underlying model (SEM or BN). Although they are not returned - * by the search method it also computes two lists of triples which, respectively store the underlines and dotted - * underlines of the PAG. + * The search method assumes that the IndependenceTest provided to the constructor is a + * conditional independence oracle for the SEM (or Bayes network) which describes the + * causal structure of the population. The method returns a PAG instantiated as a Tetrad + * GaSearchGraph which represents the equivalence class of digraphs which are d-separation + * equivalent to the digraph of the underlying model (SEM or BN). Although they are not + * returned by the search method it also computes two lists of triples which, respectively + * store the underlines and dotted underlines of the PAG. + * + * @return The CCD cyclic PAG for the data. */ public Graph search() { Map> supSepsets = new HashMap<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 9b1095cb3a..c2133cc85a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -117,6 +117,8 @@ public final class Cfci implements IGraphSearch { /** * Constructs a new FCI search for the given independence test and background knowledge. + * + * @param independenceTest The independence to use as an oracle. */ public Cfci(IndependenceTest independenceTest) { if (independenceTest == null) { 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 43f0729bed..899631fe5a 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 @@ -37,8 +37,8 @@ import java.util.Set; /** - * Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested - * locally. + *

    Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested + * locally.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    @@ -165,14 +165,18 @@ public void setDepth(int depth) { } /** - * @return the elapsed time of search in milliseconds, after search() has been run. + * Returns the elapsed time of search in milliseconds, after search() has been run. + * + * @return This time. */ public long getElapsedTime() { return this.elapsedTime; } /** - * @return the knowledge specification used in the search. Non-null. + * Returns the knowledge specification used in the search. Non-null. + * + * @return this knowledge. */ public Knowledge getKnowledge() { return this.knowledge; @@ -180,76 +184,58 @@ public Knowledge getKnowledge() { /** * Sets the knowledge specification used in the search. Non-null. + * + * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } /** - * @return the independence test used in the search, set in the constructor. This is not returning a copy, for fear - * of duplicating the data set! + * Rreturn the independence test used in the search, set in the constructor. + * + * @return This. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } /** - * @return the depth of the search--that is, the maximum number of variables conditioned on in any conditional - * independence test. + * Returns the depth of the search--that is, the maximum number of variables + * conditioned on in any conditional independence test. + * + * @return This. */ public int getDepth() { return this.depth; } /** - * @return the set of ambiguous triples found during the most recent run of the algorithm. Non-null after a call to - * search(). + * Returns the set of ambiguous triples found during the most recent run of the algorithm. + * Non-null after a call to search(). + * + * @return This set. */ public Set getAmbiguousTriples() { return new HashSet<>(this.ambiguousTriples); } /** - * @return the set of collider triples found during the most recent run of the algorithm. Non-null after a call to - * search(). - */ - public Set getColliderTriples() { - return new HashSet<>(this.colliderTriples); - } - - /** - * @return the set of noncollider triples found during the most recent run of the algorithm. Non-null after a call - * to search(). - */ - public Set getNoncolliderTriples() { - return new HashSet<>(this.noncolliderTriples); - } - - /** - * Returns the edges in the search graph. + * Returns the edges in the search graph as a set of undirected edges. * * @return These edges. */ public Set getAdjacencies() { - return new HashSet<>(this.graph.getEdges()); + return new HashSet<>(GraphUtils.undirectedGraph(this.graph).getEdges()); } /** - * Returns the non-adjacencies in the seaarch graph. + * Runs CPC starting with a fully connected graph over all the variables in the domain + * of the independence test. See PC for caveats. The number of possible cycles and + * bidirected edges is far less with CPC than with PC. * - * @return These non-adjacencies. - */ - public Set getNonadjacencies() { - Graph complete = GraphUtils.completeGraph(this.graph); - Set nonAdjacencies = complete.getEdges(); - Graph undirected = GraphUtils.undirectedGraph(this.graph); - nonAdjacencies.removeAll(undirected.getEdges()); - return new HashSet<>(nonAdjacencies); - } - - /** - * Runs CPC starting with a fully connected graph over all of the variables in the domain of the independence test. - * See PC for caveats. The number of possible cycles and bidirected edges is far less with CPC than with PC. + * @return The e-pattern for the search, which is a graphical representation of a set + * of possible CPDAGs. */ public Graph search() { this.logger.log("info", "Starting CPC algorithm"); @@ -331,21 +317,27 @@ public Graph getGraph() { } /** - * @param verbose Whether verbose output should be printed. + * Sets whether verbose output should be printed. + * + * @param verbose True if so. */ public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * @param stable Whether the stable FAS search should be used. + * Sets whether the stable FAS search should be used. + * + * @param stable True if so. */ public void setStable(boolean stable) { this.stable = stable; } /** - * @param useHeuristic Whethe the heuristic should be used for max p. + * Sets whether the heuristic should be used for max p. + * + * @param useHeuristic True if so. */ public void setUseHeuristic(boolean useHeuristic) { this.useHeuristic = useHeuristic; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index 5b59f66514..95c4b75b81 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -4,8 +4,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.score.ConditionalGaussianScore; -import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.IndTestScore; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.IndependenceTest; @@ -48,13 +48,13 @@ public class Cstar { private boolean verbose; /** - * Constructs a new object. + * Constructor. */ public Cstar() { } /** - * Returns a list of of records for making a CSTaR table. + * Returns a list of records for making a CSTaR table. * * @param allRecords the list of all records. * @return The list for the CSTaR table. @@ -101,6 +101,12 @@ public static LinkedList cStar(LinkedList> allRecords return cstar; } + /** + * Sets whether the algorithm should be parallelized. Different runs of the algorithms + * can be run in different threads in parallel. + * + * @param parallelized True if so. + */ public void setParallelized(boolean parallelized) { this.parallelized = parallelized; } @@ -112,8 +118,10 @@ public void setParallelized(boolean parallelized) { * @param possibleCauses A set of variables in the datasets over which to search. * @param possibleEffects The effect variables. * @param test This test is only used to make more tests like it for subsamples. + * @see Record */ - public LinkedList> getRecords(DataSet dataSet, List possibleCauses, List possibleEffects, + public LinkedList> getRecords(DataSet dataSet, List possibleCauses, + List possibleEffects, IndependenceTest test) { return getRecords(dataSet, possibleCauses, possibleEffects, test, null); } @@ -128,6 +136,7 @@ public LinkedList> getRecords(DataSet dataSet, List pos * @param path A path where interim results are to be stored. If null, interim results will not be stored. * If the path is specified, then if the process is stopped and restarted, previously * computed interim results will be loaded. + * @see Record */ public LinkedList> getRecords(DataSet dataSet, List possibleCauses, List possibleEffects, IndependenceTest test, String path) { System.out.println("path = " + path); @@ -413,6 +422,8 @@ public Boolean call() { /** * Makes a graph of the estimated predictors to the effect. + * + * @param records The list of records obtained from a method above. */ public Graph makeGraph(List records) { List outNodes = new ArrayList<>(); @@ -429,7 +440,7 @@ public Graph makeGraph(List records) { } /** - * A single record in the returned table for CSTaR. + * Represents a single record in the returned table for CSTaR. */ public static class Record implements TetradSerializable { static final long serialVersionUID = 23L; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index 447ac0b8ab..36fffa7a6c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -123,7 +123,7 @@ public Matrix successiveResidual() { unitVector.set(i, 0, 1); } - for (int i = 0; i < getNumFactors(); i++) { + for (int i = 0; i < this.numFactors; i++) { boolean found = successiveResidualHelper(residual, unitVector); if (!found) break; @@ -208,8 +208,10 @@ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { hVectors.add(uVector.scalarMult(1.0 / alpha2)); - if (!Double.isNaN(alpha1) && abs((alpha2 - alpha1)) < getThreshold()) { - break; + if (!Double.isNaN(alpha1)) { + if (abs((alpha2 - alpha1)) < this.threshold) { + break; + } } alpha1 = alpha2; @@ -234,22 +236,29 @@ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { return result; } + /** + * Sets the threshold. + * + * @param threshold This threshold. + */ public void setThreshold(double threshold) { this.threshold = threshold; } - public double getThreshold() { - return this.threshold; - } - - public int getNumFactors() { - return this.numFactors; - } - + /** + * Sets the nubmer of factors to find. + * + * @param numFactors This number. + */ public void setNumFactors(int numFactors) { this.numFactors = numFactors; } + /** + * Returns the matrix of residuals. + * + * @return This matrix. + */ public Matrix getResidual() { return this.residual; } @@ -306,7 +315,7 @@ private boolean successiveResidualHelper(Matrix residual, Matrix approximationVe Matrix li = f.transpose().times(ui); double di = FastMath.sqrt(li.get(0, 0)); - if (abs((d - di)) <= getThreshold()) { + if (abs((d - di)) <= this.threshold) { break; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index 3f1367c917..f97fc0b061 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -57,6 +57,8 @@ *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    * + * @author peterspirtes + * @author clarkglymour * @author josephramsey. * @see Pc * @see Fci @@ -108,7 +110,9 @@ public class Fas implements IFas { //==========================CONSTRUCTORS=============================// /** - * Constructs a new FastAdjacencySearch. + * Constructor. + * + * @param test The test to use for oracle conditional independence test results. */ public Fas(IndependenceTest test) { this.test = test; @@ -116,6 +120,16 @@ public Fas(IndependenceTest test) { //==========================PUBLIC METHODS===========================// + /** + * Runs the search and returns the resulting (undirected) graph. + * + * @return This graph. + */ + @Override + public Graph search() { + return search(test.getVariables()); + } + /** * Discovers all adjacencies in data. The procedure is to remove edges in the graph which connect pairs of * variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are @@ -124,7 +138,8 @@ public Fas(IndependenceTest test) { * more edges can be removed from the graph. The edges which remain in the graph after this procedure are the * adjacencies in the data. * - * @return a SepSet, which indicates which variables are independent conditional on which other variables + * @param nodes A list of nodes to search over. + * @return An undirected graph that summarizes the conditional independendencies that obtain in the data. */ public Graph search(List nodes) { long startTime = MillisecondTimes.timeMillis(); @@ -259,9 +274,6 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } - /** - * The number of independence tests. - */ /** * Returns the nubmer of independence tests that were done. * @@ -290,16 +302,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * Runs the search and returns the resulting (undirected) graph. - * - * @return This graph. - */ - @Override - public Graph search() { - return search(test.getVariables()); - } - /** * Returns the elapsed time of the search. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java index 8ebd333a4f..3d6a9777d6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java @@ -55,7 +55,7 @@ public class Fasd implements IFas { * The search graph. It is assumed going in that all of the true adjacencies of x are in this graph for every node * x. It is hoped (i.e. true in the large sample limit) that true adjacencies are never removed. */ - private final Graph graph; + private Graph graph; /** * The independence test. This should be appropriate to the types @@ -84,11 +84,6 @@ public class Fasd implements IFas { */ private final TetradLogger logger = TetradLogger.getInstance(); - /** - * The number of dependence judgements. Temporary. - */ - private int numDependenceJudgement; - /** * The sepsets found during the search. */ @@ -99,8 +94,6 @@ public class Fasd implements IFas { */ private Graph externalGraph; -// private List pValues = new ArrayList(); - private final NumberFormat nf = new DecimalFormat("0.00E0"); /** @@ -114,17 +107,32 @@ public class Fasd implements IFas { /** * Constructs a new FastAdjacencySearch. + * + * @param graph An initial graph of edges that will be removed. + * @param test A test to use as a conditional independence oracle. */ public Fasd(Graph graph, IndependenceTest test) { this.graph = graph; this.test = test; } + /** + * Constructs a new FastAdjacencySearch. + * + * @param test A test to use as a conditional independence oracle. + */ public Fasd(IndependenceTest test) { this.graph = new EdgeListGraph(test.getVariables()); this.test = test; } + /** + * @throws UnsupportedOperationException This contructor is not implemented. + */ + public Graph search(List nodes) { + throw new UnsupportedOperationException("Constructor not implemented."); + } + /** * Discovers all adjacencies in data. The procedure is to remove edges in the graph which connect pairs of * variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are @@ -184,10 +192,12 @@ public Graph search() { return this.graph; } - public int getDepth() { - return this.depth; - } + /** + * Sets the maximum number of variables conditoined on in any test. + * + * @param depth This maximum. + */ public void setDepth(int depth) { if (depth < -1) { throw new IllegalArgumentException( @@ -197,10 +207,11 @@ public void setDepth(int depth) { this.depth = depth; } - public Knowledge getKnowledge() { - return this.knowledge; - } - + /** + * Sets the knowledge to be used in the search. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { throw new NullPointerException("Cannot set knowledge to null"); @@ -208,18 +219,30 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } + /** + * Returns the nubmer of conditional independence tests done in the course of search. + * + * @return This number. + */ public int getNumIndependenceTests() { return this.numIndependenceTests; } - public int getNumDependenceJudgments() { - return this.numDependenceJudgement; - } - + /** + * Returns the map of node pairs to sepsets from the search. + * + * @return This map. + */ public SepsetMap getSepsets() { return this.sepset; } + /** + * Sets the external graph. Adjacencies not in this external graph will not be judged + * adjacent in the search result. + * + * @param externalGraph This graph. + */ public void setExternalGraph(Graph externalGraph) { this.externalGraph = externalGraph; } @@ -228,15 +251,15 @@ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output will be printed. + * + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } - @Override - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - return null; - } @Override public long getElapsedTime() { @@ -291,10 +314,6 @@ private boolean searchAtDepth0(List nodes, IndependenceTest test, Map nodes, IndependenceTest test, Map variables = this.dataSet.getVariables(); @@ -499,24 +505,43 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } - public Graph getExternalGraph() { - return this.externalGraph; - } - + /** + * Sets the extermal graph to use. This graph will be used as a set of adjacencies ot be + * included in the graph is the "external graph" options is selected. It doesn't matter + * what the orientations of the graph are; the graph will be reoriented using the left-right + * rule selected. + * + * @param externalGraph This graph. + */ public void setExternalGraph(Graph externalGraph) { this.externalGraph = externalGraph; } + /** + * Sets the skew edge threshold. + * + * @param skewEdgeThreshold This threshold. + */ public void setSkewEdgeThreshold(double skewEdgeThreshold) { this.skewEdgeThreshold = skewEdgeThreshold; } + /** + * Sets the cutoff for two cycle screening. + * + * @param twoCycleScreeningCutoff This cutoff. + */ public void setTwoCycleScreeningCutoff(double twoCycleScreeningCutoff) { if (twoCycleScreeningCutoff < 0) throw new IllegalStateException("Two cycle screening threshold must be >= 0"); this.twoCycleScreeningCutoff = twoCycleScreeningCutoff; } + /** + * Sets the orientation alpha. + * + * @param orientationAlpha This alpha. + */ public void setOrientationAlpha(double orientationAlpha) { if (orientationAlpha < 0 || orientationAlpha > 1) throw new IllegalArgumentException("Two cycle testing alpha should be in [0, 1]."); @@ -524,18 +549,40 @@ public void setOrientationAlpha(double orientationAlpha) { this.orientationAlpha = orientationAlpha; } + /** + * Sets the left-right rule used + * + * @param leftRight This rule. + * @see LeftRight + */ public void setLeftRight(LeftRight leftRight) { this.leftRight = leftRight; } + /** + * Sets the the adjacency method used. + * + * @param adjacencyMethod This method. + * @see AdjacencyMethod + */ public void setAdjacencyMethod(AdjacencyMethod adjacencyMethod) { this.adjacencyMethod = adjacencyMethod; } + /** + * Sets the delta to use. + * + * @param delta This delta. + */ public void setDelta(double delta) { this.delta = delta; } + /** + * Sets whether the empirical option is selected. + * + * @param empirical True if so. + */ public void setEmpirical(boolean empirical) { this.empirical = empirical; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index 1d9fc66a9b..943c8dc8a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -243,6 +243,8 @@ public FastIca(Matrix X, int numComponents) { * If algorithmType == PARALLEL the components are extracted simultaneously * (the default). if algorithmType == DEFLATION the components are extracted * one at a time. + * + * @param algorithmType This type. */ public void setAlgorithmType(int algorithmType) { if (!(algorithmType == FastIca.DEFLATION || algorithmType == FastIca.PARALLEL)) { @@ -253,14 +255,9 @@ public void setAlgorithmType(int algorithmType) { } /** - * The function type to be used, either LOGCOSH or EXP. - */ - public int getFunction() { - return this.function; - } - - /** - * The function type to be used, either LOGCOSH or EXP. + * Sets the function type to be used, either LOGCOSH or EXP. + * + * @param function This function, LOGCOSH or EXP. */ public void setFunction(int function) { if (!(function == FastIca.LOGCOSH || function == FastIca.EXP)) { @@ -271,16 +268,10 @@ public void setFunction(int function) { } /** - * Constant in range [1, 2] used in approximation to neg-entropy when 'fun - * == "logcosh"' - */ - public double getAlpha() { - return this.alpha; - } - - /** - * Constant in range [1, 2] used in approximation to neg-entropy when 'fun + * Sets the FastICA alpha constant in range [1, 2] used in approximation to neg-entropy when 'fun * == "logcosh"' + * + * @param alpha this constant. */ public void setAlpha(double alpha) { if (!(alpha >= 1 && alpha <= 2)) { @@ -293,13 +284,17 @@ public void setAlpha(double alpha) { /** * A logical value indicating whether rows of the data matrix 'X' should be * standardized beforehand. + * + * @param rowNorm True if so. */ public void setRowNorm(boolean rowNorm) { this.rowNorm = rowNorm; } /** - * Maximum number of iterations to perform. + * Sets the maximum number of iterations to allow. + * + * @param maxIterations This maximum. */ public void setMaxIterations(int maxIterations) { if (maxIterations < 1) { @@ -310,16 +305,10 @@ public void setMaxIterations(int maxIterations) { } /** - * A positive scalar giving the tolerance at which the un-mixing matrix is - * considered to have converged. - */ - public double getTolerance() { - return this.tolerance; - } - - /** - * A positive scalar giving the tolerance at which the un-mixing matrix is + * Sets a positive scalar giving the tolerance at which the un-mixing matrix is * considered to have converged. + * + * @param tolerance This value. */ public void setTolerance(double tolerance) { if (!(tolerance > 0)) { @@ -330,22 +319,19 @@ public void setTolerance(double tolerance) { } /** - * A logical value indicating the level of output as the algorithm runs. - */ - public boolean isVerbose() { - return this.verbose; - } - - /** - * A logical value indicating the level of output as the algorithm runs. + * Sets whether verbose output should be printed. + * + * @param verbose True if so. */ public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * Initial un-mixing matrix of dimension (n.comp,n.comp). If NULL (default) - * then a matrix of normal r.v.'s is used. + * Sets the initial un-mixing matrix of dimension (n.comp,n.comp). If NULL (default) + * then a random matrix of normal r.v.'s is used. + * + * @param wInit This matrix. */ public void setWInit(Matrix wInit) { this.wInit = wInit; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 3d8e73a029..6f6a94647d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -87,7 +87,9 @@ public final class Fci implements IGraphSearch { //============================CONSTRUCTORS============================// /** - * Constructs a new FCI search for the given independence test and background knowledge. + * Constructor. + * + * @param independenceTest The test to use for oracle conditional independence information. */ public Fci(IndependenceTest independenceTest) { if (independenceTest == null) { @@ -99,8 +101,10 @@ public Fci(IndependenceTest independenceTest) { } /** - * Constructs a new FCI search for the given independence test and background knowledge and a list of variables to - * search over. + * Constructor. + * + * @param independenceTest The test to use for oracle conditional independence information. + * @param searchVars A specific list of variables to search over. */ public Fci(IndependenceTest independenceTest, List searchVars) { if (independenceTest == null) { @@ -132,23 +136,6 @@ public Fci(IndependenceTest independenceTest, List searchVars) { //========================PUBLIC METHODS==========================// - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + depth); - } - - this.depth = depth; - } - - public long getElapsedTime() { - return this.elapsedTime; - } - public Graph search() { long start = MillisecondTimes.timeMillis(); @@ -173,7 +160,7 @@ public Graph search() { // Optional step: Possible Dsep. (Needed for correctness but very time-consuming.) SepsetsSet sepsets1 = new SepsetsSet(this.sepsets, this.independenceTest); - if (isPossibleDsepSearchDone()) { + if (this.possibleDsepSearchDone) { new FciOrient(sepsets1).ruleR0(graph); graph.paths().removeByPossibleDsep(independenceTest, sepsets); @@ -204,14 +191,43 @@ public Graph search() { } /** - * Retrieves the sepset map from FAS. + * Sets the depth of search, which is the maximum number of variables conditioned on + * in any test. + * + * @param depth This maximum. + */ + public void setDepth(int depth) { + if (depth < -1) { + throw new IllegalArgumentException( + "Depth must be -1 (unlimited) or >= 0: " + depth); + } + + this.depth = depth; + } + + /** + * Returns the elapsed time of search. + * + * @return This time. + */ + public long getElapsedTime() { + return this.elapsedTime; + } + + /** + * Returns the sepset map from FAS. + * + * @return This map. + * @see SepsetMap */ public SepsetMap getSepsets() { return this.sepsets; } /** - * Retrieves the background knowledge that was set. + * Returns the background knowledge that was set. + * + * @return This knowledge. */ public Knowledge getKnowledge() { return this.knowledge; @@ -219,6 +235,8 @@ public Knowledge getKnowledge() { /** * Sets background knowledge for the search. + * + * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { @@ -229,44 +247,28 @@ public void setKnowledge(Knowledge knowledge) { } /** - * @return true if Zhang's complete rule set should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. - */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; - } - - /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule - * set of the original FCI) should be used. False by default. + * Sets whether the Zhang complete rule set should be used; if false if only R1-R4 (the rule + * set of the original FCI) should be used. False by default. + * + * @param completeRuleSetUsed True for the complete Zhang ruleset. */ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { this.completeRuleSetUsed = completeRuleSetUsed; } /** - * True iff the (time-consuming) possible dsep step should be done. - */ - public boolean isPossibleDsepSearchDone() { - return this.possibleDsepSearchDone; - } - - /** - * True iff the (time-consuming) possible dsep step should be done. + * Sets whether the (time-consuming) possible dsep step should be done. + * + * @param possibleDsepSearchDone True if so. */ public void setPossibleDsepSearchDone(boolean possibleDsepSearchDone) { this.possibleDsepSearchDone = possibleDsepSearchDone; } /** - * @return the maximum length of any discriminating path, or -1 of unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength == Integer.MAX_VALUE ? -1 : this.maxPathLength; - } - - /** - * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. + * Sets the maximum length of any discriminating path, or -1 if unlimited. + * + * @param maxPathLength This maximum. */ public void setMaxPathLength(int maxPathLength) { if (maxPathLength < -1) { @@ -277,35 +279,38 @@ public void setMaxPathLength(int maxPathLength) { } /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - - /** - * True iff verbose output should be printed. + * Sets whether verbose output should be printed. + * + * @param verbose True if so. */ public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * The independence test. + * Returns the independence test used in search. + * + * @return This test. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } /** - * The FAS heuristic. + * Sets which PC heuristic should be used in the intitial adjacency search. + * + * @param heuristic The neuristic option. + * @see Pc */ public void setHeuristic(int heuristic) { this.heuristic = heuristic; } /** - * The FAS stable option. + * Sets whether the stable options hould be used in the initial adjacency search. + * + * @param stable True if so. + * @see Pc */ public void setStable(boolean stable) { this.stable = stable; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index a7db8d70e9..b691dfbf27 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -121,7 +121,7 @@ public final class FciMax implements IGraphSearch { //============================CONSTRUCTORS============================// /** - * Constructs a new FCI search for the given independence test and background knowledge. + * Constructor. */ public FciMax(IndependenceTest independenceTest) { if (independenceTest == null) { @@ -133,8 +133,10 @@ public FciMax(IndependenceTest independenceTest) { } /** - * Constructs a new FCI search for the given independence test and background knowledge and a list of variables to - * search over. + * Constructor. + * + * @param independenceTest The test to use for oracle conditional independence information. + * @param searchVars A specific list of variables to search over. */ public FciMax(IndependenceTest independenceTest, List searchVars) { if (independenceTest == null) { @@ -166,23 +168,11 @@ public FciMax(IndependenceTest independenceTest, List searchVars) { //========================PUBLIC METHODS==========================// - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + depth); - } - - this.depth = depth; - } - - public long getElapsedTime() { - return this.elapsedTime; - } - + /** + * Performs the search and returns the PAG. + * + * @return This PAG. + */ public Graph search() { long start = MillisecondTimes.timeMillis(); @@ -208,7 +198,7 @@ public Graph search() { // The original FCI, with or without JiJi Zhang's orientation rules // Optional step: Possible Dsep. (Needed for correctness but very time-consuming.) - if (isPossibleDsepSearchDone()) { + if (this.possibleDsepSearchDone) { new FciOrient(new SepsetsSet(this.sepsets, this.independenceTest)).ruleR0(graph); graph.paths().removeByPossibleDsep(independenceTest, sepsets); @@ -238,6 +228,138 @@ public Graph search() { return graph; } + /** + * Sets the maximum nubmer of variables conditonied in any test. + * + * @param depth This maximum. + */ + public void setDepth(int depth) { + if (depth < -1) { + throw new IllegalArgumentException( + "Depth must be -1 (unlimited) or >= 0: " + depth); + } + + this.depth = depth; + } + + /** + * Returns the elapsed time of search. + * + * @return This time. + */ + public long getElapsedTime() { + return this.elapsedTime; + } + + /** + * Retrieves the map from variable pairs to sepsets from the FAS search. + * + * @return This map. + */ + public SepsetMap getSepsets() { + return this.sepsets; + } + + /** + * Retrieves the background knowledge that was set. + * + * @return This knoweldge, + */ + public Knowledge getKnowledge() { + return this.knowledge; + } + + /** + * Sets background knowledge for the search. + * + * @param knowledge This knowledge, + */ + public void setKnowledge(Knowledge knowledge) { + if (knowledge == null) { + throw new NullPointerException(); + } + + this.knowledge = knowledge; + } + + /** + * Sets whether Zhang's complete ruleset is used in the search. + * + * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule + * set of the original FCI) should be used. False by default. + */ + public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { + this.completeRuleSetUsed = completeRuleSetUsed; + } + + /** + * Sets whether the (time-consuming) possible dsep step should be done. + * + * @param possibleDsepSearchDone True if so. + */ + public void setPossibleDsepSearchDone(boolean possibleDsepSearchDone) { + this.possibleDsepSearchDone = possibleDsepSearchDone; + } + + /** + * Sets the maximum length of any discriminating path, or -1 if unlimited. + * + * @param maxPathLength This maximum. + */ + public void setMaxPathLength(int maxPathLength) { + if (maxPathLength < -1) { + throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); + } + + this.maxPathLength = maxPathLength; + } + + /** + * Sets whether verbose output should be printed. + * + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * Returns the independence test used in search. + * + * @return This test. + */ + public IndependenceTest getIndependenceTest() { + return this.independenceTest; + } + + /** + * Sets the FAS heuristic from PC used in search. + * + * @param heuristic This heuristic. + * @see Pc + */ + public void setHeuristic(int heuristic) { + this.heuristic = heuristic; + } + + /** + * Sets whetehr the stable option will be used for search. + * + * @param stable True if so. + */ + public void setStable(boolean stable) { + this.stable = stable; + } + + /** + * Sets whether the discriminating path rule will be used in search. + * + * @param doDiscriminatingPathRule True if so. + */ + public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { + this.doDiscriminatingPathRule = doDiscriminatingPathRule; + } + private void addColliders(Graph graph) { Map scores = new ConcurrentHashMap<>(); @@ -359,118 +481,6 @@ private void doNode(Graph graph, Map scores, Node b) { } } } - - /** - * Retrieves the sepset map from FAS. - */ - public SepsetMap getSepsets() { - return this.sepsets; - } - - /** - * Retrieves the background knowledge that was set. - */ - public Knowledge getKnowledge() { - return this.knowledge; - } - - /** - * Sets background knowledge for the search. - */ - public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException(); - } - - this.knowledge = knowledge; - } - - /** - * @return true if Zhang's complete rule set should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. - */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; - } - - /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule - * set of the original FCI) should be used. False by default. - */ - public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { - this.completeRuleSetUsed = completeRuleSetUsed; - } - - /** - * True iff the (time-consuming) possible dsep step should be done. - */ - public boolean isPossibleDsepSearchDone() { - return this.possibleDsepSearchDone; - } - - /** - * True iff the (time-consuming) possible dsep step should be done. - */ - public void setPossibleDsepSearchDone(boolean possibleDsepSearchDone) { - this.possibleDsepSearchDone = possibleDsepSearchDone; - } - - /** - * @return the maximum length of any discriminating path, or -1 of unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength == Integer.MAX_VALUE ? -1 : this.maxPathLength; - } - - /** - * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. - */ - public void setMaxPathLength(int maxPathLength) { - if (maxPathLength < -1) { - throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); - } - - this.maxPathLength = maxPathLength; - } - - /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - - /** - * True iff verbose output should be printed. - */ - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - /** - * The independence test. - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - /** - * The FAS heuristic. - */ - public void setHeuristic(int heuristic) { - this.heuristic = heuristic; - } - - /** - * The FAS stable option. - */ - public void setStable(boolean stable) { - this.stable = stable; - } - - public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { - this.doDiscriminatingPathRule = doDiscriminatingPathRule; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index ba3cbd7d5b..a256aec455 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -158,7 +158,7 @@ public final class Fges implements IGraphSearch, DagScorer { private boolean parallelized = false; /** - * Construct a Score and pass it in here. The totalScore should return a + * Constroctor. Construct a Score and pass it in here. The totalScore should return a * positive value in case of conditional dependence and a negative values in * case of conditional independence. See Chickering (2002), locally * consistent scoring criterion. This by default uses all the processors on @@ -180,11 +180,7 @@ public Fges(Score score) { //==========================PUBLIC METHODS==========================// - public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { - this.faithfulnessAssumed = faithfulnessAssumed; - } - - /** + /** * Greedy equivalence search: Start from the empty graph, add edges till * model is significant. Then start deleting edges till a minimum is * achieved. @@ -237,7 +233,20 @@ public Graph search() { } /** - * @return the background knowledge. + * Sets whether one-edge faithfulness should be assumed. This assumption is that if X and Y + * are unconditionally depedendent, then there is an edge between X and Y in the graph. + * This could in principle be false, as for a path cancelation wheter one path is A->B->C->D + * and the other path is A->D. + * @param faithfulnessAssumed True if so. + */ + public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { + this.faithfulnessAssumed = faithfulnessAssumed; + } + + /** + * Returns the background knowledge. + * + * @return This knowledge */ public Knowledge getKnowledge() { return knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index 6acf5ace09..77f0633dd8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -102,7 +102,7 @@ public final class FgesMb { /** * The number of top CPDAGs to store. */ - private int numCPDAGsToStore; + private int numCpdagsToStore; /** * True if verbose output should be printed. */ @@ -140,7 +140,7 @@ public final class FgesMb { //==========================PUBLIC METHODS==========================// /** - * Construct a Score and pass it in here. The totalScore should return a + * Constructor. Construct a Score and pass it in here. The totalScore should return a * positive value in case of conditional dependence and a negative values in * case of conditional independence. See Chickering (2002), locally * consistent scoring criterion. @@ -153,31 +153,12 @@ public FgesMb(Score score) { this.graph = new EdgeListGraph(getVariables()); } - // Used to find semidirected paths for cycle checking. - private static Node traverseSemiDirected(Node node, Edge edge) { - if (node == edge.getNode1()) { - if (edge.getEndpoint1() == Endpoint.TAIL) { - return edge.getNode2(); - } - } else if (node == edge.getNode2()) { - if (edge.getEndpoint2() == Endpoint.TAIL) { - return edge.getNode1(); - } - } - return null; - } - - /** - * @return true if it is assumed that all path pairs with one length 1 path - * do not cancel. - */ - public boolean isFaithfulnessAssumed() { - return this.faithfulnessAssumed; - } - /** * Set to true if it is assumed that all path pairs with one length 1 path * do not cancel. + * + * @param faithfulnessAssumed True if so. + * @see Fges#setFaithfulnessAssumed(boolean) */ public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { this.faithfulnessAssumed = faithfulnessAssumed; @@ -194,6 +175,12 @@ public Graph search(Node target) { return search(Collections.singletonList(target)); } + /** + * Searches over a specific list of target variables. + * + * @param targets The targets. + * @return The union of the edges for the Markov blanekt graph for each target. + */ public Graph search(List targets) { // Assumes one-edge faithfulness. @@ -259,125 +246,10 @@ public Graph search(List targets) { return mbgraph; } - private void calcDConnections(List targets) { - this.sortedArrows = new ConcurrentSkipListSet<>(); - this.lookupArrows = new ConcurrentHashMap<>(); - this.neighbors = new ConcurrentHashMap<>(); - - this.effectEdgesGraph = new EdgeListGraph(); - - for (Node target : targets) { - this.effectEdgesGraph.addNode(target); - } - - Set emptySet = new HashSet<>(); - - for (Node target : targets) { - for (Node x : this.fgesScore.getVariables()) { - if (targets.contains(x)) { - continue; - } - - int child = this.hashIndices.get(target); - int parent = this.hashIndices.get(x); - double bump = this.fgesScore.localScoreDiff(parent, child); - - if (bump > 0) { - this.effectEdgesGraph.addNode(x); - - addUnconditionalArrows(x, target, emptySet); - - class MbAboutNodeTask extends RecursiveTask { - - public MbAboutNodeTask() { - } - - @Override - protected Boolean compute() { - Queue tasks = new ArrayDeque<>(); - - for (Node y : FgesMb.this.fgesScore.getVariables()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (x == y) { - continue; - } - - MbTask mbTask = new MbTask(x, y, target); - mbTask.fork(); - - for (NodeTaskEmptyGraph _task : new ArrayList<>(tasks)) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - if (_task.isDone()) { - _task.join(); - tasks.remove(_task); - } - } - - while (tasks.size() > Runtime.getRuntime().availableProcessors()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - NodeTaskEmptyGraph _task = tasks.poll(); - assert _task != null; - _task.join(); - } - } - - for (NodeTaskEmptyGraph task : tasks) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - task.join(); - } - - return true; - } - } - - this.pool.invoke(new MbAboutNodeTask()); - } - } - } - } - - private void addUnconditionalArrows(Node x, Node y, Set emptySet) { - if (existsKnowledge()) { - if (getKnowledge().isForbidden(x.getName(), y.getName()) && getKnowledge().isForbidden(y.getName(), x.getName())) { - return; - } - - if (invalidSetByKnowledge(y, emptySet)) { - return; - } - } - - if (this.adjacencies != null && !this.adjacencies.isAdjacentTo(x, y)) { - return; - } - - int child = this.hashIndices.get(y); - int parent = this.hashIndices.get(x); - double bump = this.fgesScore.localScoreDiff(parent, child); - - Edge edge = Edges.undirectedEdge(x, y); - this.effectEdgesGraph.addEdge(edge); - - if (bump > 0.0) { - addArrow(x, y, emptySet, emptySet, bump); - addArrow(y, x, emptySet, emptySet, bump); - } - } - /** - * @return the background knowledge. + * Returns the background knowledge. + * + * @return This knowledge. */ public Knowledge getKnowledge() { return this.knowledge; @@ -396,6 +268,11 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } + /** + * Returns the elapsed time of the search. + * + * @return This time. + */ public long getElapsedTime() { return this.elapsedTime; } @@ -403,54 +280,57 @@ public long getElapsedTime() { /** * If the true graph is set, askterisks will be printed in log output for * the true edges. + * + * @param trueGraph The true graph. */ public void setTrueGraph(Graph trueGraph) { this.trueGraph = trueGraph; } /** - * @return the totalScore of the given DAG, up to a constant. + * Returns the totalScore of the given DAG, up to a constant. + * + * @param dag The dag to score. + * @return The scre of the DAG. */ public double getScore(Graph dag) { return scoreDag(dag); } /** - * @return the list of top scoring graphs. + * Returns the list of top scoring graphs. + * + * @return The top scoring graphs. */ public LinkedList getTopGraphs() { return this.topGraphs; } /** - * @return the number of CPDAGs to store. + * Returns the number of CPDAGs to store. + * + * @return This number. */ public int getnumCPDAGsToStore() { - return this.numCPDAGsToStore; + return this.numCpdagsToStore; } /** * Sets the number of CPDAGs to store. This should be set to zero for fast * search. + * + * @param numCpdagsToStore This number. */ - public void setNumCPDAGsToStore(int numCPDAGsToStore) { - if (numCPDAGsToStore < 0) { - throw new IllegalArgumentException("# graphs to store must at least 0: " + numCPDAGsToStore); + public void setNumCpdagsToStore(int numCpdagsToStore) { + if (numCpdagsToStore < 0) { + throw new IllegalArgumentException("# graphs to store must at least 0: " + numCpdagsToStore); } - this.numCPDAGsToStore = numCPDAGsToStore; - } - - /** - * @return the initial graph for the search. The search is initialized to - * this graph and proceeds from there. - */ - public Graph getexternalGraph() { - return this.externalGraph; + this.numCpdagsToStore = numCpdagsToStore; } /** - * Sets the initial graph. + * Sets the external graph. The search graph is initialized to this. */ public void setExternalGraph(Graph externalGraph) { if (externalGraph != null) { @@ -471,38 +351,28 @@ public void setExternalGraph(Graph externalGraph) { /** * Sets whether verbose output should be produced. + * + * @param verbose True if so. */ public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * @return the output stream that output (except for log output) should be - * sent to. - */ - public PrintStream getOut() { - return this.out; - } - /** * Sets the output stream that output (except for log output) should be sent * to. By detault System.out. + * + * @param out The output print stream, by default System.out. */ public void setOut(PrintStream out) { this.out = out; } /** - * @return the set of preset adjacenies for the algorithm; edges not in this - * adjacencies graph will not be added. - */ - public Graph getAdjacencies() { - return this.adjacencies; - } - - /** - * Sets the set of preset adjacenies for the algorithm; edges not in this + * Sets the graph of preset adjacenies for the algorithm; edges not in this * adjacencies graph will not be added. + * + * @param adjacencies This graph. */ public void setAdjacencies(Graph adjacencies) { this.adjacencies = adjacencies; @@ -511,7 +381,7 @@ public void setAdjacencies(Graph adjacencies) { /** * A bound on cycle length. * - * @param cycleBound The bound, >= 1, or -1 for unlimited. + * @param cycleBound The bound, ≥ 1, or -1 for unlimited. */ public void setCycleBound(int cycleBound) { if (!(cycleBound == -1 || cycleBound >= 1)) { @@ -522,55 +392,13 @@ public void setCycleBound(int cycleBound) { /** * Creates a new processors pool with the specified number of threads. + * + * @param parallelized True if parallelized, */ public void setParallelized(boolean parallelized) { this.parallelized = parallelized; } - /** - * For BIC totalScore, a multiplier on the penalty term. For continuous - * searches. - * - * @deprecated Use the getters on the individual scores instead. - */ - public double getPenaltyDiscount() { - if (this.fgesScore instanceof HasPenaltyDiscount) { - return ((HasPenaltyDiscount) this.fgesScore).getPenaltyDiscount(); - } else { - return 2.0; - } - } - - /** - * For BIC totalScore, a multiplier on the penalty term. For continuous - * searches. - * - * @deprecated Use the setters on the individual scores instead. - */ - public void setPenaltyDiscount(double penaltyDiscount) { - if (this.fgesScore instanceof HasPenaltyDiscount) { - ((HasPenaltyDiscount) this.fgesScore).setPenaltyDiscount(penaltyDiscount); - } - } - - /** - * @deprecated Use the setters on the individual scores instead. - */ - public void setSamplePrior(double samplePrior) { - if (this.fgesScore instanceof DiscreteScore) { - ((DiscreteScore) this.fgesScore).setSamplePrior(samplePrior); - } - } - - /** - * @deprecated Use the setters on the individual scores instead. - */ - public void setStructurePrior(double expectedNumParents) { - if (this.fgesScore instanceof DiscreteScore) { - ((DiscreteScore) this.fgesScore).setStructurePrior(expectedNumParents); - } - } - /** * The maximum of parents any nodes can have in output CPDAG. * @@ -593,6 +421,140 @@ public void setMaxDegree(int maxDegree) { } //===========================PRIVATE METHODS========================// + + + // Used to find semidirected paths for cycle checking. + private static Node traverseSemiDirected(Node node, Edge edge) { + if (node == edge.getNode1()) { + if (edge.getEndpoint1() == Endpoint.TAIL) { + return edge.getNode2(); + } + } else if (node == edge.getNode2()) { + if (edge.getEndpoint2() == Endpoint.TAIL) { + return edge.getNode1(); + } + } + return null; + } + + + private void calcDConnections(List targets) { + this.sortedArrows = new ConcurrentSkipListSet<>(); + this.lookupArrows = new ConcurrentHashMap<>(); + this.neighbors = new ConcurrentHashMap<>(); + + this.effectEdgesGraph = new EdgeListGraph(); + + for (Node target : targets) { + this.effectEdgesGraph.addNode(target); + } + + Set emptySet = new HashSet<>(); + + for (Node target : targets) { + for (Node x : this.fgesScore.getVariables()) { + if (targets.contains(x)) { + continue; + } + + int child = this.hashIndices.get(target); + int parent = this.hashIndices.get(x); + double bump = this.fgesScore.localScoreDiff(parent, child); + + if (bump > 0) { + this.effectEdgesGraph.addNode(x); + + addUnconditionalArrows(x, target, emptySet); + + class MbAboutNodeTask extends RecursiveTask { + + public MbAboutNodeTask() { + } + + @Override + protected Boolean compute() { + Queue tasks = new ArrayDeque<>(); + + for (Node y : FgesMb.this.fgesScore.getVariables()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + if (x == y) { + continue; + } + + MbTask mbTask = new MbTask(x, y, target); + mbTask.fork(); + + for (NodeTaskEmptyGraph _task : new ArrayList<>(tasks)) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + if (_task.isDone()) { + _task.join(); + tasks.remove(_task); + } + } + + while (tasks.size() > Runtime.getRuntime().availableProcessors()) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + NodeTaskEmptyGraph _task = tasks.poll(); + assert _task != null; + _task.join(); + } + } + + for (NodeTaskEmptyGraph task : tasks) { + if (Thread.currentThread().isInterrupted()) { + break; + } + + task.join(); + } + + return true; + } + } + + this.pool.invoke(new MbAboutNodeTask()); + } + } + } + } + + private void addUnconditionalArrows(Node x, Node y, Set emptySet) { + if (existsKnowledge()) { + if (getKnowledge().isForbidden(x.getName(), y.getName()) && getKnowledge().isForbidden(y.getName(), x.getName())) { + return; + } + + if (invalidSetByKnowledge(y, emptySet)) { + return; + } + } + + if (this.adjacencies != null && !this.adjacencies.isAdjacentTo(x, y)) { + return; + } + + int child = this.hashIndices.get(y); + int parent = this.hashIndices.get(x); + double bump = this.fgesScore.localScoreDiff(parent, child); + + Edge edge = Edges.undirectedEdge(x, y); + this.effectEdgesGraph.addEdge(edge); + + if (bump > 0.0) { + addArrow(x, y, emptySet, emptySet, bump); + addArrow(y, x, emptySet, emptySet, bump); + } + } + //Sets the discrete scoring function to use. private void setFgesScore(Score totalScore) { this.fgesScore = totalScore; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index 3dc87a98b0..6595e84367 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -138,6 +138,12 @@ public Fofc(DataSet dataSet, BpcTestType testType, Algorithm algorithm, double a this.corr = new CorrelationMatrix(dataSet); } + /** + * Runs the search and returns a graph of clusters with the ir respective + * latent parents. + * + * @return This graph. + */ public Graph search() { Set> allClusters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 85bea3dace..39f48cb6e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -27,8 +27,14 @@ import edu.cmu.tetrad.search.utils.ClusterUtils; import edu.cmu.tetrad.search.utils.DeltaSextadTest; import edu.cmu.tetrad.search.utils.Sextad; -import edu.cmu.tetrad.sem.*; -import edu.cmu.tetrad.util.*; +import edu.cmu.tetrad.sem.SemEstimator; +import edu.cmu.tetrad.sem.SemIm; +import edu.cmu.tetrad.sem.SemOptimizerEm; +import edu.cmu.tetrad.sem.SemPm; +import edu.cmu.tetrad.util.ChoiceGenerator; +import edu.cmu.tetrad.util.ProbUtils; +import edu.cmu.tetrad.util.RandomUtil; +import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; import java.util.*; @@ -127,6 +133,12 @@ public Ftfc(DataSet dataSet, Algorithm algorithm, double alpha) { this.corr = new CorrelationMatrix(dataSet); } + /** + * Runs the search and returns a graph of clusters, each of which has two common + * latent parents. + * + * @return This graph. + */ public Graph search() { Set> allClusters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index 8760c6ee20..b5ac64b289 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -97,6 +97,12 @@ public GFci(IndependenceTest test, Score score) { } //========================PUBLIC METHODS==========================// + + /** + * Runs the graph and returns the search PAG. + * + * @return This PAG. + */ public Graph search() { this.independenceTest.setVerbose(verbose); List nodes = getIndependenceTest().getVariables(); @@ -142,7 +148,9 @@ public Graph search() { } /** - * @param maxDegree The maximum indegree of the output graph. + * Sets the maximum indegree of the output graph. + * + * @param maxDegree This maximum. */ public void setMaxDegree(int maxDegree) { if (maxDegree < -1) { @@ -154,53 +162,19 @@ public void setMaxDegree(int maxDegree) { } /** - * Returns The maximum indegree of the output graph. + * Returns the knowledge used in search. + * + * @return This knowledge */ - public int getMaxDegree() { - return this.maxDegree; - } - - // Due to Spirtes. - public void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { - this.graph = new EdgeListGraph(graph); - this.graph.reorientAllWith(Endpoint.CIRCLE); - fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); - - List nodes = this.graph.getNodes(); - - for (Node b : nodes) { - List adjacentNodes = this.graph.getAdjacentNodes(b); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node a = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - if (fgesGraph.isDefCollider(a, b, c)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { - List sepset = sepsets.getSepset(a, c); - - if (sepset != null && !sepset.contains(b)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - } - } - } - } - } - public Knowledge getKnowledge() { return this.knowledge; } + /** + * Sets the knowledge to use in search. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { throw new NullPointerException(); @@ -210,15 +184,8 @@ public void setKnowledge(Knowledge knowledge) { } /** - * @return true if Zhang's complete rule set should be used, false if only - * R1-R4 (the rule set of the original FCI) should be used. False by - * default. - */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; - } - - /** + * Sets whether Zhang's complete rules is used. + * * @param completeRuleSetUsed set to true if Zhang's complete rule set * should be used, false if only R1-R4 (the rule set of the original FCI) * should be used. False by default. @@ -228,14 +195,8 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { } /** - * @return the maximum length of any discriminating path, or -1 of - * unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength; - } - - /** + * Sets the maximum path lenth for the discriminating path rule. + * * @param maxPathLength the maximum length of any discriminating path, or -1 * if unlimited. */ @@ -248,53 +209,80 @@ public void setMaxPathLength(int maxPathLength) { } /** - * True iff verbose output should be printed. + * Sets whether verbose output should be printed. + * + * @param verbose True if so. */ - public boolean isVerbose() { - return this.verbose; - } - public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * The independence test. + * Returns the independence test used in search. + * + * @return This test. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } - public ICovarianceMatrix getCovMatrix() { - return this.covarianceMatrix; - } - - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } - - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } - - public PrintStream getOut() { - return this.out; - } - + /** + * Sets the print stream used for output, default Sysem.out. + * + * @param out This print stream. + */ public void setOut(PrintStream out) { this.out = out; } - public void setIndependenceTest(IndependenceTest independenceTest) { - this.independenceTest = independenceTest; - } - + /** + * Sets whether one-edge faithfulness is assumed. For FGES + * @param faithfulnessAssumed True if so. + * @see Fges#setFaithfulnessAssumed(boolean) + */ public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { this.faithfulnessAssumed = faithfulnessAssumed; } //===========================================PRIVATE METHODS=======================================// + // Due to Spirtes. + private void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { + this.graph = new EdgeListGraph(graph); + this.graph.reorientAllWith(Endpoint.CIRCLE); + fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); + + List nodes = this.graph.getNodes(); + + for (Node b : nodes) { + List adjacentNodes = this.graph.getAdjacentNodes(b); + + if (adjacentNodes.size() < 2) { + continue; + } + + ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); + int[] combination; + + while ((combination = cg.next()) != null) { + Node a = adjacentNodes.get(combination[0]); + Node c = adjacentNodes.get(combination[1]); + + if (fgesGraph.isDefCollider(a, b, c)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { + List sepset = sepsets.getSepset(a, c); + + if (sepset != null && !sepset.contains(b)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } + } + } + } + } + /** * Orients according to background knowledge */ 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 160266e61a..08ec717651 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 @@ -20,7 +20,6 @@ /////////////////////////////////////////////////////////////////////////////// package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; @@ -30,9 +29,7 @@ import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; -import java.io.PrintStream; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; @@ -68,9 +65,9 @@ public final class GraspFci implements IGraphSearch { private Knowledge knowledge = new Knowledge(); // The conditional independence test. - private IndependenceTest independenceTest; + private final IndependenceTest independenceTest; - // Flag for complete rule set, true if should use complete rule set, false otherwise. + // Flag for complete rule set, true if one should use complete rule set, false otherwise. private boolean completeRuleSetUsed = true; // The maximum length for any discriminating path. -1 if unlimited; otherwise, a positive integer. @@ -82,15 +79,9 @@ public final class GraspFci implements IGraphSearch { // True iff verbose output should be printed. private boolean verbose; - // The covariance matrix beign searched over. Assumes continuous data. - ICovarianceMatrix covarianceMatrix; - // The sample size. int sampleSize; - // The print stream that output is directed to. - private PrintStream out = System.out; - // The score. private final Score score; private int numStarts = 1; @@ -100,7 +91,6 @@ public final class GraspFci implements IGraphSearch { private boolean useScore = true; private boolean doDiscriminatingPathRule = true; private boolean ordered = false; - private int graspDepth = 3; private int uncoveredDepth = 1; private int nonSingularDepth = 1; @@ -115,15 +105,21 @@ public GraspFci(IndependenceTest test, Score score) { } //========================PUBLIC METHODS==========================// + + /** + * Run the search and return s a PAG. + * + * @return The PAG. + */ public Graph search() { - List nodes = getIndependenceTest().getVariables(); + List nodes = this.independenceTest.getVariables(); if (nodes == null) { throw new NullPointerException("Nodes from test were null."); } this.logger.log("info", "Starting FCI algorithm."); - this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); + this.logger.log("info", "Independence test = " + this.independenceTest + "."); this.graph = new EdgeListGraph(nodes); @@ -135,6 +131,7 @@ public Graph search() { alg.setUseScore(useScore); alg.setUseRaskuttiUhler(useRaskuttiUhler); alg.setUseDataOrder(useDataOrder); + int graspDepth = 3; alg.setDepth(graspDepth); alg.setUncoveredDepth(uncoveredDepth); alg.setNonSingularDepth(nonSingularDepth); @@ -171,100 +168,18 @@ public Graph search() { return this.graph; } - private List possibleParents(Node x, List adjx, - Knowledge knowledge, Node y) { - List possibleParents = new LinkedList<>(); - String _x = x.getName(); - - for (Node z : adjx) { - if (z == x) continue; - if (z == y) continue; - String _z = z.getName(); - - if (possibleParentOf(_z, _x, knowledge)) { - possibleParents.add(z); - } - } - - return possibleParents; - } - - private boolean possibleParentOf(String z, String x, Knowledge knowledge) { - return !knowledge.isForbidden(z, x) && !knowledge.isRequired(x, z); - } - - - // Due to Spirtes. - public void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { - this.graph = new EdgeListGraph(graph); - this.graph.reorientAllWith(Endpoint.CIRCLE); - fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); - - List nodes = this.graph.getNodes(); - - for (Node b : nodes) { - List adjacentNodes = this.graph.getAdjacentNodes(b); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node a = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - if (fgesGraph.isDefCollider(a, b, c)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - -// if (graph.getEndpoint(b, a) == Endpoint.CIRCLE && knowledge.isForbidden(a.getName(), b.getName())) { -// graph.setEndpoint(b, a, Endpoint.ARROW); -// } -// -// if (graph.getEndpoint(c, b) == Endpoint.CIRCLE && knowledge.isForbidden(c.getName(), b.getName())) { -// graph.setEndpoint(b, c, Endpoint.ARROW); -// } - } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { - List sepset = sepsets.getSepset(a, c); - - if (sepset != null && !sepset.contains(b)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - } - -// if (graph.getEndpoint(b, a) == Endpoint.CIRCLE && knowledge.isForbidden(a.getName(), b.getName())) { -// graph.setEndpoint(b, a, Endpoint.ARROW); -// } -// -// if (graph.getEndpoint(c, b) == Endpoint.CIRCLE && knowledge.isForbidden(c.getName(), b.getName())) { -// graph.setEndpoint(b, c, Endpoint.ARROW); -// } - } - } - } - } - - public Knowledge getKnowledge() { - return this.knowledge; - } - - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - /** - * @return true if Zhang's complete rule set should be used, false if only - * R1-R4 (the rule set of the original FCI) should be used. False by - * default. + * Sets the knoweldge used in search. + * + * @param knowledge This knoweldge. */ - public boolean isCompleteRuleSetUsed() { - return this.completeRuleSetUsed; + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge(knowledge); } /** + * Sets whether Zhang's complete rules set is used. + * * @param completeRuleSetUsed set to true if Zhang's complete rule set * should be used, false if only R1-R4 (the rule set of the original FCI) * should be used. False by default. @@ -274,14 +189,8 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { } /** - * @return the maximum length of any discriminating path, or -1 of - * unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength; - } - - /** + * Sets the maximum length of any discriminating path searched. + * * @param maxPathLength the maximum length of any discriminating path, or -1 * if unlimited. */ @@ -294,47 +203,14 @@ public void setMaxPathLength(int maxPathLength) { } /** - * True iff verbose output should be printed. + * Sets whether verbose output should be printed. + * + * @param verbose True if so. */ - public boolean isVerbose() { - return this.verbose; - } - public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * The independence test. - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } - - public ICovarianceMatrix getCovMatrix() { - return this.covarianceMatrix; - } - - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } - - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } - - public PrintStream getOut() { - return this.out; - } - - public void setOut(PrintStream out) { - this.out = out; - } - - public void setIndependenceTest(IndependenceTest independenceTest) { - this.independenceTest = independenceTest; - } - //===========================================PRIVATE METHODS=======================================// /** @@ -410,11 +286,6 @@ public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { this.doDiscriminatingPathRule = doDiscriminatingPathRule; } - public void setGraspDepth(int graspDepth) { - if (graspDepth < -1) throw new IllegalArgumentException("GRaSP depth should be >= -1."); - this.graspDepth = graspDepth; - } - public void setSingularDepth(int uncoveredDepth) { if (uncoveredDepth < -1) throw new IllegalArgumentException("Uncovered depth should be >= -1."); this.uncoveredDepth = uncoveredDepth; @@ -429,4 +300,41 @@ public void setOrdered(boolean ordered) { this.ordered = ordered; } + // Due to Spirtes. + public void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { + this.graph = new EdgeListGraph(graph); + this.graph.reorientAllWith(Endpoint.CIRCLE); + fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); + + List nodes = this.graph.getNodes(); + + for (Node b : nodes) { + List adjacentNodes = this.graph.getAdjacentNodes(b); + + if (adjacentNodes.size() < 2) { + continue; + } + + ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); + int[] combination; + + while ((combination = cg.next()) != null) { + Node a = adjacentNodes.get(combination[0]); + Node c = adjacentNodes.get(combination[1]); + + if (fgesGraph.isDefCollider(a, b, c)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { + List sepset = sepsets.getSepset(a, c); + + if (sepset != null && !sepset.contains(b)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } + } + } + } + } + } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java index 4f3c82b21a..88148c1ff8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java @@ -31,31 +31,21 @@ import java.util.List; /** - * An interface for fast adjacency searches (i.e. PC adjacency searches). + * Gives an interface for fast adjacency searches (i.e. PC adjacency searches). * * @author josephramsey */ public interface IFas { void setKnowledge(Knowledge knowledge); - SepsetMap getSepsets(); - void setDepth(int depth); - Graph search(); - Graph search(List nodes); - long getElapsedTime(); - int getNumIndependenceTests(); - List getNodes(); - List getAmbiguousTriples(Node node); - void setVerbose(boolean verbose); - void setOut(PrintStream out); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java index 763b6aa861..2e61f1f1f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Graph; /** - * Interface for a search method that searches and returns a graph. + * Gives an interface for a search method that searches and returns a graph. */ public interface IGraphSearch { Graph search(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IMbSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IMbSearch.java index 33378e14f5..047b4d2b84 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IMbSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IMbSearch.java @@ -26,7 +26,7 @@ import java.util.List; /** - * An interface for Markov blanket searches. + * Gives an interface for Markov blanket searches. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index 62891a9a0f..ce3651cb4e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -133,7 +133,7 @@ public String toString() { /** * Calculates the true effect of (x, y) given the true DAG (which - * must be provided. + * must be provided). * * @param trueDag The true DAG. * @return The true effect of (x, y). @@ -152,6 +152,10 @@ public double trueEffect(Node x, Node y, Graph trueDag) { return abs(getBeta(regressors, y)); } + /** + * Returns the distance between the effects and the true effect. + * @return This difference. + */ public double distance(LinkedList effects, double trueEffect) { effects = new LinkedList<>(effects); if (effects.isEmpty()) return Double.NaN; // counted as not estimated. @@ -179,7 +183,7 @@ public double distance(LinkedList effects, double trueEffect) { * sorted low to high in absolute value. *

    * 1. First, estimate a pattern P from the data. - * 2. Then, consider all combinations C of siblings Z of X (Z--X) that include all of the parents of X in P. + * 2. Then, consider all combinations C of siblings Z of X (Z--X) that include all the parents of X in P. * 3. For each such C, regress Y onto {X} U C and record the coefficient beta for X in the regression. * 4. Report the list of such betas, sorted low to high. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 79665bfee4..bbc3b2076e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -90,6 +90,12 @@ public class LingD { public LingD() { } + /** + * Fits a LiNG-D model to the given dataset using a default method for estimting + * W. + * @param D A continuous dataset. + * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. + */ public List fit(DataSet D) { Matrix W = LingD.estimateW(D, 5000, 1e-6, 1.2); return fitW(W); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 91b3a58b47..5a7d60a8e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -63,15 +63,21 @@ public class Lingam { public Lingam() { } + /** + * Fits a LiNGAM model to the given dataset using a default method for estimting + * W. + * @param D A continuous dataset. + * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. + */ public Matrix fit(DataSet D) { Matrix W = LingD.estimateW(D, 5000, 1e-6, 1.2); return fitW(W); } /** - * Searches given the W matrix from ICA. + * Searches given a W matrix is that is provided by the user, WX = e. * - * @param W the W matrix from ICA, WX = e. + * @param W A W matrix estimated by the user, possibly by some other method. * @return The estimated B Hat matrix. */ public Matrix fitW(Matrix W) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 55be85dfb6..49959a6055 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -193,8 +193,6 @@ public void setKnowledge(Knowledge knowledge) { } /** - * The estimated covariance matrix over the latents. - */ /** * Returns the inferred covariance matrix over the late4nt variables. * * @return Thsi covariance matrix. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index e12612ee74..6d2816f37f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -95,6 +95,14 @@ public MimbuildTrek() { //=================================== PUBLIC METHODS =========================================// + /** + * Does the search and returns the graph. + * + * @param clustering A clustering of the variables, each of which is explained by a single latent. + * @param latentNames The names of the latents, which cannot be known by the clustering algorithm. + * @param measuresCov The covariance matrix over the measured variables, from the data. + * @return A graph over the latents. + */ public Graph search(List> clustering, List latentNames, ICovarianceMatrix measuresCov) { List _latentNames = new ArrayList<>(latentNames); @@ -149,39 +157,53 @@ public Graph search(List> clustering, List latentNames, ICova return this.structureGraph; } + /** + * The clustering used. + * + * @return This clusterng. + */ public List> getClustering() { return this.clustering; } - public double getAlpha() { - return this.alpha; - } - + /** + * The alpha to use. + * + * @param alpha This alpha. + */ public void setAlpha(double alpha) { this.alpha = alpha; } - public Knowledge getKnowledge() { - return this.knowledge; - } - + /** + * The knowledge to use in the search. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } + /** + * The covaraince matrix over the latents that is implied by the clustering. + * + * @return This covarianc matrix. + */ public ICovarianceMatrix getLatentsCov() { return this.latentsCov; } - public double getMinimum() { - return this.minimum; - } - + /** + * The p-value of the model. + * @return This p-value. + */ public double getpValue() { return this.pValue; } /** + * The full graph discovered. + * * @return the allowUnfaithfulness discovered graph, with latents and indicators. */ public Graph getFullGraph() { @@ -203,12 +225,10 @@ public Graph getFullGraph() { return graph; } - public double getEpsilon() { - return this.epsilon; - } - /** - * Parameter convergence threshold. Default = 1e-4. + * Sets the parameter convergence threshold. Default = 1e-4. + * + * @param epsilon This threshold. */ public void setEpsilon(double epsilon) { if (epsilon < 0) throw new IllegalArgumentException("Epsilon mut be >= 0: " + epsilon); 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 13b41ad6bb..0217e733d1 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 @@ -24,7 +24,6 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphSearchUtils; @@ -94,7 +93,7 @@ public class PcMax implements IGraphSearch { private final TetradLogger logger = TetradLogger.getInstance(); /** - * The number of indepdendence tests in the last search. + * The number of independence tests in the last search. */ private int numIndependenceTests; @@ -131,7 +130,7 @@ public boolean isAggressivelyPreventCycles() { } /** - * @param aggressivelyPreventCycles Set to true just in case edges will not be addeds if they would create cycles. + * @param aggressivelyPreventCycles Set to true just in case edges will not be added if they would create cycles. */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { this.aggressivelyPreventCycles = aggressivelyPreventCycles; @@ -182,7 +181,7 @@ public int getDepth() { * checked. * * @param depth The depth of the search. The default is 1000. A value of -1 may be used to indicate that the depth - * should be high (1000). A value of Integer.MAX_VALUE may not be used, due to a bug on multi-core + * should be high (1000). A value of Integer.MAX_VALUE may not be used, due to a bug on multicore * machines. */ public void setDepth(int depth) { @@ -210,13 +209,13 @@ public Graph search() { } /** - * Runs PC starting with a commplete graph over the given list of nodes, using the given independence test and + * Runs PC starting with a complete graph over the given list of nodes, using the given independence test and * knowledge and returns the resultant graph. The returned graph will be a CPDAG if the independence information * is consistent with the hypothesis that there are no latent common causes. It may, however, contain cycles or * bidirected edges if this assumption is not born out, either due to the actual presence of latent common causes, * or due to statistical errors in conditional independence judgments. *

    - * All of the given nodes must be in the domatein of the given conditional independence test. + * All the given nodes must be in the domain of the given conditional independence test. */ public Graph search(List nodes) { nodes = new ArrayList<>(nodes); @@ -253,23 +252,12 @@ public Graph search(IFas fas, List nodes) { search.setFasType(PcCommon.FasType.REGULAR); } -// if (concurrent) { -// search.setConcurrent(PcAll.Concurrent.YES); -// } else { -// search.setConcurrent(PcAll.Concurrent.NO); -// } - search.setColliderDiscovery(PcCommon.ColliderDiscovery.MAX_P); search.setConflictRule(conflictRule); search.setUseHeuristic(useMaxP); search.setMaxPathLength(maxPPathLength); -// search.setExternalGraph(externalGraph); search.setVerbose(verbose); -// fas.setKnowledge(getKnowledge()); -// fas.setDepth(getDepth()); -// fas.setVerbose(this.verbose); - this.graph = search.search(); this.sepsets = fas.getSepsets(); @@ -300,14 +288,6 @@ public Set getAdjacencies() { return new HashSet<>(this.graph.getEdges()); } - public Set getNonadjacencies() { - Graph complete = GraphUtils.completeGraph(this.graph); - Set nonAdjacencies = complete.getEdges(); - Graph undirected = GraphUtils.undirectedGraph(this.graph); - nonAdjacencies.removeAll(undirected.getEdges()); - return new HashSet<>(nonAdjacencies); - } - public int getNumIndependenceTests() { return this.numIndependenceTests; } @@ -324,10 +304,6 @@ public void setStable(boolean stable) { this.stable = stable; } -// 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/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index d28c8001c0..fe2c143a0b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -150,11 +150,11 @@ public PcMb(IndependenceTest test, int depth) { //===============================PUBLIC METHODS=======================// - - public boolean isAggressivelyPreventCycles() { - return this.aggressivelyPreventCycles; - } - + /** + * Sets whether cycles should be aggressively prevented, using a cycle checker. + * + * @param aggressivelyPreventCycles True if so. + */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { this.aggressivelyPreventCycles = aggressivelyPreventCycles; } @@ -349,7 +349,9 @@ public Graph search(List targets) { } /** - * Does a CPDAG search. + * Does the search. + * + * @return a CPDAG. */ public Graph search() { this.numIndependenceTests = 0; @@ -477,14 +479,14 @@ public List findMb(Node target) { } /** - * @return Ibid. + * @return The test used in search. */ public IndependenceTest getTest() { return this.test; } /** - * @return Ibid. + * @return The knowledge used in search. */ public Knowledge getKnowledge() { return this.knowledge; @@ -499,10 +501,6 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } - public Graph getGraph() { - return this.graph; - } - //================================PRIVATE METHODS====================// private Set getA() { @@ -836,7 +834,7 @@ private boolean colliderAllowed(Node x, Node y, Node z, Knowledge knowledge) { } private static boolean isArrowheadAllowed1(Node from, Node to, - Knowledge knowledge) { + Knowledge knowledge) { if (knowledge == null) { return true; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index ef554e1662..3fa398a5a4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -4,9 +4,6 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Boss; -import edu.cmu.tetrad.search.Sp; -import edu.cmu.tetrad.search.SuborderSearch; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.GrowShrinkTree; import edu.cmu.tetrad.search.utils.MeekRules; @@ -41,6 +38,12 @@ public class PermutationSearch { private Knowledge knowledge = new Knowledge(); private boolean verbose = false; + /** + * Constructs a new PermutationSearch using the given SuborderSearch. + * + * @param suborderSearch The SuborderSearch (see). + * @see SuborderSearch + */ public PermutationSearch(SuborderSearch suborderSearch) { this.suborderSearch = suborderSearch; this.variables = suborderSearch.getVariables(); @@ -58,6 +61,11 @@ public PermutationSearch(SuborderSearch suborderSearch) { } } + /** + * Performe the search and return a CPDAG. + * + * @return The CPDAG. + */ public Graph search() { List tasks = new ArrayList<>(); if (!this.knowledge.isEmpty() && this.knowledge.getVariablesNotInTiers().isEmpty()) { @@ -87,11 +95,30 @@ public Graph search() { } // TO DO: moved to a better place like GraphUtils + + /** + * Construct a graph given a specification of the parents for each node. + * + * @param nodes The nodes. + * @param parents A map from each node to its parents. + * @param cpDag Whether a CPDAG is wanted, if false, a DAG. + * @return The construted graph. + */ public static Graph getGraph(List nodes, Map> parents, boolean cpDag) { return getGraph(nodes, parents, null, cpDag); } // TO DO: moved to a better place like GraphUtils + + /** + * Construct a graph given a specification of the parents for each node. + * + * @param nodes The nodes. + * @param parents A map from each node to its parents. + * @param knowledge the knoweldge to use to construct the graph. + * @param cpDag Whether a CPDAG is wanted, if false, a DAG. + * @return The construted graph. + */ public static Graph getGraph(List nodes, Map> parents, Knowledge knowledge, boolean cpDag) { Graph graph = new EdgeListGraph(nodes); @@ -110,22 +137,26 @@ public static Graph getGraph(List nodes, Map> parents, Kno return graph; } + /** + * Returns the variables. + * @return This lsit. + */ public List getVariables() { return new ArrayList<>(this.variables); } - public boolean isVerbose() { - return this.verbose; - } - + /** + * Sets whether verbose output should be printed. + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } - public Knowledge getKnowledge() { - return this.knowledge; - } - + /** + * Sets the knowledge to be used in the search. + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; this.suborderSearch.setKnowledge(knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index f729995ccd..09b3756530 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -112,7 +112,7 @@ public final class Rfci implements IGraphSearch { //============================CONSTRUCTORS============================// /** - * Constructs a new FCI search for the given independence test and background knowledge. + * Constructs a new RFCI search for the given independence test and background knowledge. */ public Rfci(IndependenceTest independenceTest) { if (independenceTest == null) { @@ -124,7 +124,7 @@ public Rfci(IndependenceTest independenceTest) { } /** - * Constructs a new FCI search for the given independence test and background knowledge and a list of variables to + * Constructs a new RFCI search for the given independence test and background knowledge and a list of variables to * search over. */ public Rfci(IndependenceTest independenceTest, List searchVars) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 057f91ac48..16aca54dbc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -979,7 +979,7 @@ private void testFgesMb(int numVars, double edgeFactor, int numCases, int numRun fges = new FgesMb(score); fges.setVerbose(false); - fges.setNumCPDAGsToStore(0); + fges.setNumCpdagsToStore(0); fges.setOut(System.out); // fges.setHeuristicSpeedup(faithfulness); fges.setMaxDegree(maxIndegree); @@ -1024,7 +1024,7 @@ private void testFgesMb(int numVars, double edgeFactor, int numCases, int numRun fges = new FgesMb(score); fges.setVerbose(false); - fges.setNumCPDAGsToStore(0); + fges.setNumCpdagsToStore(0); fges.setOut(System.out); // fges.setHeuristicSpeedup(faithfulness); fges.setMaxDegree(maxIndegree); From ff4f1cba3a5deab1a09101e6035afe246f233edf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 04:39:07 -0400 Subject: [PATCH 383/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Rfci.java | 65 +++++--- .../java/edu/cmu/tetrad/search/SpFci.java | 144 ++++++++++-------- .../cmu/tetrad/search/test/ChiSquareTest.java | 4 +- 3 files changed, 127 insertions(+), 86 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 09b3756530..34a53b1d60 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -152,23 +152,9 @@ public Rfci(IndependenceTest independenceTest, List searchVars) { //========================PUBLIC METHODS==========================// - public int getDepth() { - return this.depth; - } - - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + depth); - } - - this.depth = depth; - } - - public long getElapsedTime() { - return this.elapsedTime; - } - + /** + * @return + */ public Graph search() { return search(getIndependenceTest().getVariables()); } @@ -179,6 +165,13 @@ public Graph search(List nodes) { return search(new Fas(getIndependenceTest()), nodes); } + /** + * Runs the search and returns the RFCI PAG. + * + * @param fas The type of FAS to use for the initial step. + * @param nodes The nodes to search over. + * @return The RFCI PAG. + */ public Graph search(IFas fas, List nodes) { long beginTime = MillisecondTimes.timeMillis(); independenceTest.setVerbose(verbose); @@ -224,14 +217,52 @@ public Graph search(IFas fas, List nodes) { return this.graph; } + /** + * Sets the maximum number of variables conditioned on in any test. + * + * @param depth This maximum. + */ + public void setDepth(int depth) { + if (depth < -1) { + throw new IllegalArgumentException( + "Depth must be -1 (unlimited) or >= 0: " + depth); + } + + this.depth = depth; + } + + /** + * Returns the elapsed time of the search. + * + * @return This time. + */ + public long getElapsedTime() { + return this.elapsedTime; + } + + /** + * Returns the map from node pairs to sepsets found in search. + * + * @return This map. + */ public SepsetMap getSepsets() { return this.sepsets; } + /** + * Returns the knowledge used in search. + * + * @return This knowledge. + */ public Knowledge getKnowledge() { return this.knowledge; } + /** + * Sets the knowledge used in search. + * + * @param knowledge This knoweldge. + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index c775126922..1e6109d279 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -39,16 +39,16 @@ import static edu.cmu.tetrad.graph.GraphUtils.gfciExtraEdgeRemovalStep; /** - *

    Uses SP in place of FGES for the initial step in the GFCI algorithm. - * This tends to produce a accurate PAG than GFCI as a result, for the latent + *

    Uses SP in place of FGES for the initial step in the GFCI algorithm. + * This tends to produce a accurate PAG than GFCI as a result, for the latent * variables case. This is a simple substitution; the reference for GFCI is here:

    *

    J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

    - * + * *

    For SP only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

    - * + * *

    Note that SP considers all permutations of the algorithm, which is * exponential in the number of variables. So SP is limited to about 10 * variables.

    @@ -106,6 +106,13 @@ public final class SpFci implements IGraphSearch { private boolean doDiscriminatingPathRule = true; //============================CONSTRUCTORS============================// + + /** + * Constructor; requires by ta test and a score, over the same variables. + * + * @param test The test. + * @param score The score. + */ public SpFci(IndependenceTest test, Score score) { if (score == null) { throw new NullPointerException(); @@ -118,7 +125,7 @@ public SpFci(IndependenceTest test, Score score) { //========================PUBLIC METHODS==========================// /** - * @return the discovered CPDAG. + * @return The discovered PAG. */ public Graph search() { List nodes = getIndependenceTest().getVariables(); @@ -167,6 +174,11 @@ public Graph search() { return this.graph; } + /** + * Sets the max degree of the search. + * + * @param maxDegree This maximum. + */ public void setMaxDegree(int maxDegree) { if (maxDegree < -1) { throw new IllegalArgumentException("Depth must be -1 (unlimited) or >= 0: " + maxDegree); @@ -177,47 +189,13 @@ public void setMaxDegree(int maxDegree) { /** * Returns The maximum indegree of the output graph. + * + * @return This maximum. */ public int getMaxDegree() { return this.maxDegree; } - // Due to Spirtes. - public void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { - this.graph = new EdgeListGraph(graph); - this.graph.reorientAllWith(Endpoint.CIRCLE); - fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); - - List nodes = this.graph.getNodes(); - - for (Node b : nodes) { - List adjacentNodes = this.graph.getAdjacentNodes(b); - - if (adjacentNodes.size() < 2) { - continue; - } - - ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); - int[] combination; - - while ((combination = cg.next()) != null) { - Node a = adjacentNodes.get(combination[0]); - Node c = adjacentNodes.get(combination[1]); - - if (fgesGraph.isDefCollider(a, b, c)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { - List sepset = sepsets.getSepset(a, c); - - if (sepset != null && !sepset.contains(b)) { - this.graph.setEndpoint(a, b, Endpoint.ARROW); - this.graph.setEndpoint(c, b, Endpoint.ARROW); - } - } - } - } - } public Knowledge getKnowledge() { return this.knowledge; @@ -266,57 +244,89 @@ public void setMaxPathLength(int maxPathLength) { } /** - * True iff verbose output should be printed. + * Sets whether verbose output is printed. + * + * @param verbose True if so. */ - public boolean isVerbose() { - return this.verbose; - } - public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * The independence test. + * Returns the independence test used in search. + * + * @return This test. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } - public ICovarianceMatrix getCovMatrix() { - return this.covarianceMatrix; - } - - public ICovarianceMatrix getCovarianceMatrix() { - return this.covarianceMatrix; - } - - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } - - public PrintStream getOut() { - return this.out; - } - + /** + * Sets the output stream used to print. + * + * @param out This print stream. + */ public void setOut(PrintStream out) { this.out = out; } - public void setIndependenceTest(IndependenceTest independenceTest) { - this.independenceTest = independenceTest; - } - + /** + * Sets the maximum number of variables conditioned on. + * + * @param depth This maximum. + */ public void setDepth(int depth) { this.depth = depth; } + /** + * Sets whether the discriminating path search is done. + * + * @param doDiscriminatingPathRule True if so. + */ public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { this.doDiscriminatingPathRule = doDiscriminatingPathRule; } //===========================================PRIVATE METHODS=======================================// + // Due to Spirtes. + private void modifiedR0(Graph fgesGraph, SepsetProducer sepsets) { + this.graph = new EdgeListGraph(graph); + this.graph.reorientAllWith(Endpoint.CIRCLE); + fciOrientbk(this.knowledge, this.graph, this.graph.getNodes()); + + List nodes = this.graph.getNodes(); + + for (Node b : nodes) { + List adjacentNodes = this.graph.getAdjacentNodes(b); + + if (adjacentNodes.size() < 2) { + continue; + } + + ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2); + int[] combination; + + while ((combination = cg.next()) != null) { + Node a = adjacentNodes.get(combination[0]); + Node c = adjacentNodes.get(combination[1]); + + if (fgesGraph.isDefCollider(a, b, c)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } else if (fgesGraph.isAdjacentTo(a, c) && !this.graph.isAdjacentTo(a, c)) { + List sepset = sepsets.getSepset(a, c); + + if (sepset != null && !sepset.contains(b)) { + this.graph.setEndpoint(a, b, Endpoint.ARROW); + this.graph.setEndpoint(c, b, Endpoint.ARROW); + } + } + } + } + } + /** * Orients according to background knowledge */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java index 2fe394235a..975f20584f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java @@ -33,8 +33,8 @@ /** * Calculates marginal chi square test results for a discrete dataset. * - * @author Frank Wimberly original version - * @author josephramsey revision 10/01, believe it or now also 2020. + * @author frankwimberly + * @author josephramsey */ public class ChiSquareTest { From 3f571e7d0d4ba59501ea95b7f5469e1e9bc5bef2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 04:43:27 -0400 Subject: [PATCH 384/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/SvarFciOrient.java | 12 ++--- .../java/edu/cmu/tetrad/search/SvarGfci.java | 54 +++++++------------ 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index b455bb466a..10eadb4dca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -213,12 +213,6 @@ public void ruleR0(Graph graph) { } } - private void printWrongColliderMessage(Node a, Node b, Node c, Graph graph) { - if (this.truePag != null && graph.isDefCollider(a, b, c) && !this.truePag.isDefCollider(a, b, c)) { - System.out.println("R0" + ": Orienting collider by mistake: " + a + "*->" + b + "<-*" + c); - } - } - /** * Orients the graph according to rules in the graph (FCI step D). *

    @@ -232,6 +226,12 @@ public void doFinalOrientation(Graph graph) { } } + private void printWrongColliderMessage(Node a, Node b, Node c, Graph graph) { + if (this.truePag != null && graph.isDefCollider(a, b, c) && !this.truePag.isDefCollider(a, b, c)) { + System.out.println("R0" + ": Orienting collider by mistake: " + a + "*->" + b + "<-*" + c); + } + } + private void spirtesFinalOrientation(Graph graph) { this.changeFlag = true; boolean firstTime = true; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 1a88acc56e..6240a17927 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -112,6 +112,11 @@ public SvarGfci(IndependenceTest test, Score score) { this.independenceTest = test; } + /** + * Runs the search and returns a PAG. + * + * @return a PAG. + */ public Graph search() { this.logger.log("info", "Starting svarGFCI algorithm."); this.logger.log("info", "Independence test = " + this.independenceTest + "."); @@ -174,15 +179,11 @@ public Graph search() { return this.graph; } - public void setMaxIndegree(int maxIndegree) { - if (maxIndegree < -1) { - throw new IllegalArgumentException( - "Depth must be -1 (unlimited) or >= 0: " + maxIndegree); - } - - this.maxIndegree = maxIndegree; - } - + /** + * Sets the knowledge for the search. + * + * @param knowledge The knowledge. + */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { throw new NullPointerException(); @@ -192,7 +193,9 @@ public void setKnowledge(Knowledge knowledge) { } /** - * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule + * Sets whether the complete ruleset is used. + * + * @param completeRuleSetUsed True if Zhang's complete rule set should be used, False if only R1-R4 (the rule * set of the original FCI) should be used. False by default. */ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { @@ -200,6 +203,8 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { } /** + * Sets the maximum length of any discriminating path. + * * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. */ public void setMaxPathLength(int maxPathLength) { @@ -210,34 +215,15 @@ public void setMaxPathLength(int maxPathLength) { this.maxPathLength = maxPathLength; } + /** + * Sets whether verbose output is printed. + * + * @param verbose true if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - - public void setCovarianceMatrix(ICovarianceMatrix covarianceMatrix) { - this.covarianceMatrix = covarianceMatrix; - } - - public void setIndependenceTest(IndependenceTest independenceTest) { - this.independenceTest = independenceTest; - } - - public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { - this.faithfulnessAssumed = faithfulnessAssumed; - } - - public void setSamplePrior(double samplePrior) { - this.samplePrior = samplePrior; - } - - public void setStructurePrior(double structurePrior) { - this.structurePrior = structurePrior; - } - private void chooseScore() { double penaltyDiscount = this.penaltyDiscount; From 1c214b064938a20ffe2a1b83cc9085c9622eb27e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 04:55:09 -0400 Subject: [PATCH 385/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/search/score/GicScores.java | 19 ---------- .../tetrad/search/score/MagSemBicScore.java | 6 --- .../tetrad/search/score/MnlrLikelihood.java | 21 ++++++++++ .../cmu/tetrad/search/score/MnlrScore.java | 38 ++++++++++++++++--- .../edu/cmu/tetrad/search/score/MvpScore.java | 25 ++++++++++-- .../search/score/PoissonPriorScore.java | 4 -- 6 files changed, 75 insertions(+), 38 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index d6f208bcb3..dc38e83dce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -99,25 +99,6 @@ public GicScores(DataSet dataSet/*, double correlationThreshold*/) { throw new NullPointerException(); } -// this.correlationThreshold = correlationThreshold; - -// dataSet = DataUtils.center(dataSet); -// -// double[][] cov = new double[dataSet.getNumColumns()][dataSet.getNumColumns()]; -// -// for (int i = 0; i < dataSet.getNumColumns(); i++) { -// for (int j = 0; j < dataSet.getNumColumns(); j++) { -// double sum = 0.0; -// -// for (int k = 0; k < dataSet.getNumRows(); k++) { -// sum += dataSet.getDouble(k, i) * dataSet.getDouble(k, j); -// } -// -// cov[i][j] = sum / dataSet.getNumRows(); -// } -// } - -// CovarianceMatrix covarianceMatrix = new CovarianceMatrix(dataSet.getVariables(), cov, dataSet.getNumRows()); ICovarianceMatrix covarianceMatrix = (SimpleDataLoader.getCovarianceMatrix(dataSet)); this.data = dataSet.getDoubleData(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java index 0e2647670f..d9175949f4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java @@ -164,12 +164,6 @@ public double localScore(int i, int... js) { List head = heads.get(l); Set tail = tails.get(l); -// System.out.print("head: "); -// System.out.println(head); -// System.out.print("tail: "); -// System.out.println(tail); -// System.out.println(); - head.remove(v1); int h = head.size(); int max = h + tail.size(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java index fc990c5000..76404ed6ed 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java @@ -80,6 +80,12 @@ public void write(int b) { } }); + /** + * Constructor. + * @param dataSet The dataset to analyze. + * @param structurePrior The structure prior. + * @param fDegree The f degree. + */ public MnlrLikelihood(DataSet dataSet, double structurePrior, int fDegree) { if (dataSet == null) { @@ -120,6 +126,12 @@ public MnlrLikelihood(DataSet dataSet, double structurePrior, int fDegree) { } + /** + * Returns the likelihood of a child given its parents. + * @param child_index The index the child. + * @param parents The indices of the parents. + * @return The likelihood. + */ public double getLik(int child_index, int[] parents) { double lik = 0; @@ -200,6 +212,12 @@ public double getLik(int child_index, int[] parents) { return lik; } + /** + * Returns the degrees of freedom of a child given its parents. + * @param child_index The index of the child. + * @param parents The indices of the parents. + * @return The degrees of freedom. + */ public double getDoF(int child_index, int[] parents) { double dof = 0; @@ -236,6 +254,9 @@ public double getDoF(int child_index, int[] parents) { return dof; } + /** + * Returns the structur prior for k parents. + */ public double getStructurePrior(int k) { if (this.structurePrior < 0) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java index bca9fdb132..eeba75f76c 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java @@ -48,6 +48,12 @@ public class MnlrScore implements Score { // Log number of instances private final double logn; + /** + * Constructor. + * @param dataSet The mixed dataset being analyzed. + * @param structurePrior The structure prior + * @param fDegree The f degree. + */ public MnlrScore(DataSet dataSet, double structurePrior, int fDegree) { if (dataSet == null) { @@ -60,6 +66,9 @@ public MnlrScore(DataSet dataSet, double structurePrior, int fDegree) { this.logn = FastMath.log(dataSet.getNumRows()); } + /** + * The local score of the child given its parents. + */ public double localScore(int i, int... parents) { double lik = this.likelihood.getLik(i, parents); @@ -75,38 +84,57 @@ public double localScore(int i, int... parents) { } } + /** + * localScore(y | z, x) - localScore(y | z). + */ public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. + * Returns the sample size. + * @return This size. */ - - public int getSampleSize() { return this.dataSet.getNumRows(); } + /** + * A method for FGES returning a judgment of whether an edge with a given + * bump counts as a effect edge. + * @param bump The bump. + * @return True if so. + * @see edu.cmu.tetrad.search.Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; } + /** + * Returns the variables. + * @return This lsit. + */ @Override public List getVariables() { return this.variables; } + /** + * Returns a maximum degree used by some algorithms. + * @return This maximum. + */ @Override public int getMaxDegree() { return (int) FastMath.ceil(FastMath.log(this.dataSet.getNumRows())); } + /** + * @throws UnsupportedOperationException Method not implemented. + */ @Override public boolean determines(List z, Node y) { - return false; + throw new UnsupportedOperationException("Method not implemented."); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java index c60f3780ad..209ab30df7 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java @@ -45,6 +45,12 @@ public class MvpScore implements Score { // Log number of instances private final double logn; + /** + * Constructor. + * @param dataSet The mixed dataset being analyzed. + * @param structurePrior The structure prior + * @param fDegree The f degree. + */ public MvpScore(DataSet dataSet, double structurePrior, int fDegree, boolean discretize) { if (dataSet == null) { @@ -57,6 +63,9 @@ public MvpScore(DataSet dataSet, double structurePrior, int fDegree, boolean dis this.logn = FastMath.log(dataSet.getNumRows()); } + /** + * The local score of the child given its parents. + */ public double localScore(int i, int... parents) { double lik = this.likelihood.getLik(i, parents); @@ -76,20 +85,28 @@ public double localScore(int i, int... parents) { } } + /** + * localScore(y | z, x) - localScore(y | z). + */ public double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } - /** - * Specialized scoring method for a single parent. Used to speed up the effect edges search. + * Returns the sample size. + * @return This size. */ - - public int getSampleSize() { return this.dataSet.getNumRows(); } + /** + * A method for FGES returning a judgment of whether an edge with a given + * bump counts as a effect edge. + * @param bump The bump. + * @return True if so. + * @see edu.cmu.tetrad.search.Fges + */ @Override public boolean isEffectEdge(double bump) { return bump > 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index ef5a397642..d5aecd4469 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -156,10 +156,6 @@ public boolean isEffectEdge(double bump) { return bump > 0; } - public boolean isVerbose() { - return this.verbose; - } - public void setVerbose(boolean verbose) { this.verbose = verbose; } From 1435efec49b26d1ba04b38cd79d5c0e50544acd0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 04:56:39 -0400 Subject: [PATCH 386/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/score/Score.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java index 2f8059ec3c..7e0a734784 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java @@ -29,18 +29,9 @@ * Interface for a score suitable for FGES */ public interface Score { - - /** - * @param node The index of the node. - * @param parents The indices of the node's parents. - * @return The score, or NaN if the score cannot be calculated. - */ double localScore(int node, int... parents); - List getVariables(); - int getSampleSize(); - String toString(); //==============================DEFAULT METHODS=========================// From 35cee6763d5cf84ccdace6714facbb83b413109b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 15:31:53 -0400 Subject: [PATCH 387/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algcomparison/independence/Mnlrlrt.java | 2 +- .../independence/PositiveCorr.java | 2 +- .../algcomparison/score/MNLRBicScore.java | 58 -------- .../score/PositiveCorrScore.java | 2 +- .../cmu/tetrad/search/score/MnlrScore.java | 1 + .../cmu/tetrad/search/test/ChiSquareTest.java | 12 +- .../ConditionalCorrelationIndependence.java | 15 +- .../cmu/tetrad/search/test/GSquareTest.java | 8 +- .../tetrad/search/test/IndTestChiSquare.java | 29 ++-- .../test/IndTestConditionalCorrelation.java | 32 ++-- .../test/IndTestConditionalGaussianLrt.java | 37 +++-- .../cmu/tetrad/search/test/IndTestDSep.java | 60 +++++--- .../test/IndTestDegenerateGaussianLrt.java | 51 ++++--- .../tetrad/search/test/IndTestFisherZ.java | 38 +++-- .../IndTestFisherZConcatenateResiduals.java | 43 +++--- .../test/IndTestFisherZFisherPValue.java | 37 ++++- .../tetrad/search/test/IndTestGSquare.java | 65 +++++++-- .../cmu/tetrad/search/test/IndTestHsic.java | 85 ++++++----- .../search/test/IndTestIndependenceFacts.java | 1 - .../cmu/tetrad/search/test/IndTestMvpLrt.java | 73 +++++++-- .../tetrad/search/test/IndTestRegression.java | 7 +- .../tetrad/search/test/IndTestTrekSep.java | 83 +++++++++-- .../search/test/IndependenceResult.java | 4 +- .../tetrad/search/test/IndependenceTest.java | 47 +++++- .../java/edu/cmu/tetrad/search/test/Kci.java | 138 ++++++++++++------ .../cmu/tetrad/search/test/ScoreIndTest.java | 69 +++++---- .../IndTestMnlrLr.java | 5 +- .../IndTestPositiveCorr.java | 4 +- .../MnlrLikelihood.java | 2 +- 29 files changed, 660 insertions(+), 350 deletions(-) delete mode 100755 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{test => work_in_progress}/IndTestMnlrLr.java (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{test => work_in_progress}/IndTestPositiveCorr.java (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{score => work_in_progress}/MnlrLikelihood.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java index 03364279ff..da1117c090 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java @@ -5,7 +5,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.search.test.IndTestMnlrLr; +import edu.cmu.tetrad.search.work_in_progress.IndTestMnlrLr; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java index d893d4193f..ff32dc399e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java @@ -3,7 +3,7 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.search.test.IndTestPositiveCorr; +import edu.cmu.tetrad.search.work_in_progress.IndTestPositiveCorr; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java deleted file mode 100755 index 45cd741508..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MNLRBicScore.java +++ /dev/null @@ -1,58 +0,0 @@ -package edu.cmu.tetrad.algcomparison.score; - -import edu.cmu.tetrad.annotation.Experimental; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.SimpleDataLoader; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.score.MnlrScore; -import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.util.Parameters; - -import java.util.ArrayList; -import java.util.List; - -/** - * Wrapper for MVP BIC Score. - * - * @author Bryan Andrews - */ -@Experimental -@edu.cmu.tetrad.annotation.Score( - name = "Multinomial Logistic Regression BIC Score", - command = "mnlr-bic-score", - dataType = DataType.Mixed -) -public class MNLRBicScore implements ScoreWrapper { - - static final long serialVersionUID = 23L; - - @Override - public Score getScore(DataModel dataSet, Parameters parameters) { - return new MnlrScore(SimpleDataLoader.getMixedDataSet(dataSet), - 1, - parameters.getInt("fDegree", 1)); - } - - @Override - public String getDescription() { - return "Multinomial Logistic Regression BIC Score"; - } - - @Override - public DataType getDataType() { - return DataType.Mixed; - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add("fDegree"); - return parameters; - } - - @Override - public Node getVariable(String name) { - return null; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java index 51b8955f83..5299be0a4e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java @@ -4,7 +4,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.test.IndTestPositiveCorr; +import edu.cmu.tetrad.search.work_in_progress.IndTestPositiveCorr; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.IndTestScore; import edu.cmu.tetrad.util.Parameters; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java index eeba75f76c..b4e26315ec 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.work_in_progress.MnlrLikelihood; import org.apache.commons.math3.util.FastMath; import java.util.List; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java index 975f20584f..50537a3dda 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ChiSquareTest.java @@ -90,6 +90,10 @@ public ChiSquareTest(DataSet dataSet, double alpha) { * Calculates chi square for a conditional crosstabulation table for independence question 0 _||_ 1 | 2, 3, ...max * 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. + * + * @param testIndices These indices, in order. + * @return a Chi square test result. + * @see Result */ public Result calcChiSquare(int[] testIndices) { @@ -195,6 +199,8 @@ public Result calcChiSquare(int[] testIndices) { } /** + * Returns a judgment of whether a set of parent variables determines a child variables. + * * @param testIndices An array of indices for variables in the dataset supplied in the constructor. * @param p The probability that some marginal for some table dominates. A good value is 0.99. * @return True if the variable at index 0 is determined by the variables at the other indices. @@ -252,7 +258,9 @@ public boolean isDetermined(int[] testIndices, double p) { } /** - * @return the getModel significance level being used for tests. + * Returns the model significance level being used for tests. + * + * @return this level. */ public double getAlpha() { return this.alpha; @@ -260,6 +268,8 @@ public double getAlpha() { /** * Sets the significance level to be used for tests. + * + * @param alpha This significance level. */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java index eb11739cd1..c77fb6e7e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ConditionalCorrelationIndependence.java @@ -55,12 +55,14 @@ public final class ConditionalCorrelationIndependence { /** * Gives a choice of kernels to use for the independence judgmnts for conditional correlation independence. + * * @see ConditionalCorrelationIndependence */ public enum Kernel {Epinechnikov, Gaussian} /** * Gives a choice of basis functions to use for judgments of independence for conditional correlation independence. + * * @see ConditionalCorrelationIndependence */ public enum Basis {Polynomial, Cosine} @@ -139,7 +141,9 @@ public ConditionalCorrelationIndependence(DataSet dataSet) { //=================PUBLIC METHODS====================// /** - * @return the p-value of the test. Can be compared to alpha. + * Returns the p-value of the test, x _||_ y | z. Can be compared to alpha. + * + * @return This p-value. */ public double isIndependent(Node x, Node y, List z) { try { @@ -285,7 +289,7 @@ public double[] residuals(Node x, List z, List rows) { } /** - * Number of functions to use in (truncated) basis + * Sets the number of functions to use in (truncated) basis * * @param numFunctions This number. */ @@ -350,8 +354,11 @@ public double getPValue(double score) { } /** - * @return the minimal scores value calculated by the method for the most - * recent independence check. + * Returns the minimal scores value calculated by the method for the most + * recent independence check, less the cutoff so that negative scores correspond + * to independence. + * + * @return This minimal score. */ public double getScore() { return abs(this.score) - this.cutoff;// alpha - getPValue(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java index 6e9a838377..c94c7bf203 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java @@ -33,9 +33,11 @@ import java.util.List; /** - * Performs conditional independence tests of discrete data using the G Square method. - * Degrees of freedom are calculated as in Fienberg, The Analysis of Cross-Classified - * Categorical Data, 2nd Edition, 142. + *

    Performs conditional independence tests of discrete data using the G Square method. + * Degrees of freedom are calculated as in Fienberg (2007), this reference:

    + * + *

    Fienberg, S. E. (2007). The analysis of cross-classified categorical data. + * Springer Science & Business Media.

    * * @author Frank Wimberly original version * @author josephramsey revision 10/01 diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java index d73365a3de..06f0c63fda 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestChiSquare.java @@ -136,21 +136,27 @@ public IndependenceTest indTestSubset(List nodes) { } /** - * @return the chi Square value. + * Returns the chi Square value. + * + * @return This value. */ public double getChiSquare() { return this.xSquare; } /** - * @return degrees of freedom associated with the most recent call of isIndependent + * Returns the degrees of freedom associated with the most recent call of isIndependent. + * + * @return These degrees. */ public int getDf() { return this.df; } /** - * @return the p value associated with the most recent call of isIndependent. + * Returns the p value associated with the most recent call of isIndependent. + * + * @return This p-value. */ public double getPValue() { return this.pValue; @@ -159,9 +165,6 @@ public double getPValue() { /** * Determines whether variable x is independent of variable y given a list of conditioning varNames z. * - * @param x the one variable being compared. - * @param y the second variable being compared. - * @param z the list of conditioning varNames. * @return True iff x _||_ y | z. */ public IndependenceResult checkIndependence(Node x, Node y, List z) { @@ -211,11 +214,13 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** + * Returns True if the variables z determing the variable z. + * * @param z The list of variables z1,...,zn with respect to which we want to know whether z determines x oir z. - * @param x1 The one variable whose determination by z we want to know. + * @param x The one variable whose determination by z we want to know. * @return true if it is estimated that z determines x or z determines y. */ - public boolean determines(List z, Node x1) { + public boolean determines(List z, Node x) { if (z == null) { throw new NullPointerException(); } @@ -229,7 +234,7 @@ public boolean determines(List z, Node x1) { // For testing x, y given z1,...,zn, set up an array of length // n + 2 containing the indices of these variables in order. int[] testIndices = new int[1 + z.size()]; - testIndices[0] = this.variables.indexOf(x1); + testIndices[0] = this.variables.indexOf(x); for (int i = 0; i < z.size(); i++) { testIndices[i + 1] = this.variables.indexOf(z.get(i)); @@ -250,7 +255,7 @@ public boolean determines(List z, Node x1) { if (countDetermined) { StringBuilder sb = new StringBuilder(); - sb.append("Determination found: ").append(x1).append( + sb.append("Determination found: ").append(x).append( " is determined by {"); for (int i = 0; i < z.size(); i++) { @@ -289,8 +294,10 @@ public void setAlpha(double alpha) { } /** - * @return the list of variables over which this independence checker is capable of determinine + * Returns the list of variables over which this independence checker is capable of determinine * independence relations-- that is, all the variables in the given graph or the given data set. + * + * @return This list. */ public List getVariables() { return Collections.unmodifiableList(this.variables); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java index 59039ee609..3b76e737cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java @@ -35,7 +35,7 @@ /** * Checks conditional independence of variable in a continuous data set using a * conditional correlation test for the nonlinear nonGaussian with additive error - * case. + * case. This is for additive (but otherwise general) models. * * @author josephramsey */ @@ -102,10 +102,10 @@ public IndTestConditionalCorrelation(DataSet dataSet, double alpha) { //==========================PUBLIC METHODS=============================// /** - * Creates a new IndTestCramerT instance for a subset of the variables. + * @throws UnsupportedOperationException This method is not implemented. */ public IndependenceTest indTestSubset(List vars) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("This method is not implemented."); } /** @@ -156,30 +156,36 @@ public void setAlpha(double alpha) { } /** - * @return The getModel significance level. + * Returns the model significance level. + * + * @return This level. */ public double getAlpha() { return this.alpha; } /** - * @return the list of variables over which this independence checker is capable + * Returns the list of variables over which this independence checker is capable * of determinine independence relations-- that is, all the variables in the given * graph or the given data set. + * + * @return This list. */ public List getVariables() { return this.variables; } /** - * @throws UnsupportedOperationException Since such code is not avialable. + * @throws UnsupportedOperationException Since such code is not available. */ public boolean determines(List z, Node x) throws UnsupportedOperationException { - throw new UnsupportedOperationException("The 'determine' method is not implemented"); + throw new UnsupportedOperationException("The 'determines' method is not implemented"); } /** - * @return the data set being analyzed. + * Returns the data set being analyzed. + * + * @return This dataset. */ public DataSet getData() { return this.dataSet; @@ -197,7 +203,9 @@ public double getScore() { } /** - * @return a string representation of this test. + * Returns a string representation of this test. + * + * @return This string. */ public String toString() { return "Conditional Correlation, q = " + IndTestConditionalCorrelation.nf.format(getAlpha()); @@ -271,10 +279,10 @@ public void setBasis(ConditionalCorrelationIndependence.Basis basis) { /** * Sets the kernal regression sample size. * - * @param i This size. + * @param size This size. */ - public void setKernelRegressionSampleSize(int i) { - this.cci.setKernelRegressionSampleSize(i); + public void setKernelRegressionSampleSize(int size) { + this.cci.setKernelRegressionSampleSize(size); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java index febfe278d3..5524781582 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java @@ -82,16 +82,18 @@ public IndTestConditionalGaussianLrt(DataSet data, double alpha, boolean discret } /** - * @return an Independence test for a subset of the searchVariables. + * @throws javax.help.UnsupportedOperationException Method not implemented */ public IndependenceTest indTestSubset(List vars) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("This method is not implemented."); } /** - * @return True if the given independence question is judged true, False if not. - * The independence question is of the form x _||_ y | z, z = z1,...,zn, where - * x, y, z1,...,zn are searchVariables in the list returned by getVariableNames(). + * Returns and independence result that states whetehr x _||_y | z and what the + * p-value of the test is. + * + * @return an independence result (see) + * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, List z) { this.likelihood.setNumCategoriesToDiscretize(this.numCategoriesToDiscretize); @@ -151,31 +153,36 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * @return the probability associated with the most recently executed independence test, of Double.NaN if p value is - * not meaningful for tis test. + * Returns the probability associated with the most recently executed independence test, + * or Double.NaN if p value is not meaningful for this test. */ public double getPValue() { return this.pValue; } /** - * @return the list of searchVariables over which this independence checker is capable of determinining independence + * Returns the list of variables over which this independence checker is capable of determining independence * relations. + * + * @return This list. */ public List getVariables() { return new ArrayList<>(this.data.getVariables()); } /** - * @return true if y is determined the variable in z. + * Returns true if y is determined the variable in z. + * + * @return True if so. */ public boolean determines(List z, Node y) { return false; //stub } /** - * @return the significance level of the independence test. - * @throws UnsupportedOperationException if there is no significance level. + * Returns the significance level of the independence test. + * + * @return This level. */ public double getAlpha() { return this.alpha; @@ -183,6 +190,8 @@ public double getAlpha() { /** * Sets the significance level. + * + * @param alpha This level. */ public void setAlpha(double alpha) { this.alpha = alpha; @@ -191,7 +200,7 @@ public void setAlpha(double alpha) { /** * Returns the data. * - * @return This. + * @return This data. */ public DataSet getData() { return this.data; @@ -209,7 +218,9 @@ public double getScore() { } /** - * @return a string representation of this test. + * Returns a string representation of this test. + * + * @return This string. */ public String toString() { NumberFormat nf = new DecimalFormat("0.0000"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java index 1b5cb7c000..2da7682599 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDSep.java @@ -35,8 +35,10 @@ import java.util.List; /** - * Checks independence facts for variables associated with the nodes in a given graph by - * checking d-separation facts on the underlying nodes. + *

    Checks independence facts for variables associated with the nodes in a given graph by + * checking d-separation facts on the underlying nodes. We use the IndependenceTest + * interface here so that this d-separation test can be used in place of a statistical + * conditional independence test in algorithms to provide oracle information.

    * * @author josephramsey */ @@ -136,7 +138,9 @@ public IndTestDSep(IndependenceFacts facts, boolean keepLatents) { } /** - * Returns a test over a buset of the variables. + * Returns a test over a subset of the variables. + * + * @return This test. */ public IndependenceTest indTestSubset(List vars) { if (vars.isEmpty()) { @@ -163,7 +167,9 @@ public IndependenceTest indTestSubset(List vars) { } /** - * @return the list of observed varialbes in the given graph. + * Returns the list of observed varialbes in the given graph. + * + * @return This lsit. */ private List calcVars(List nodes, boolean keepLatents) { if (keepLatents) { @@ -176,12 +182,10 @@ private List calcVars(List nodes, boolean keepLatents) { } /** - * Checks the indicated d-separation fact. + * Checks the indicated d-separation fact, dsep(x , y | z). * - * @param x one node. - * @param y a second node. - * @param z a List of nodes (conditioning variables) - * @return True iff x _||_ y | z + * @return An independence result for dsep(x, y | z). + * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (z == null) { @@ -237,8 +241,10 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * Auxiliary method to calculate dseparation facts directly from nodes instead + * Auxiliary method to calculate dsep(x, y | z) directly from nodes instead * of from variables. + * + * @return True if so. */ public boolean isDSeparated(Node x, Node y, List z) { if (z == null) { @@ -255,25 +261,29 @@ public boolean isDSeparated(Node x, Node y, List z) { } /** - * Needed for IndependenceTest interface. P value is not meaningful here. + * This obviousy does not return an actual p-value, though it does return + * a number that is positive for depdendence and negative for independence, + * satisfying the contract. + * + * @return This value. */ public double getPValue() { return this.pvalue; } + /** - * @return the list of TetradNodes over which this independence checker is capable + * Return the list of TetradNodes over which this independence checker is capable * of determinine independence relations-- that is, all the variables in the given * graph or the given data set. + * + * @return This list. */ public List getVariables() { return Collections.unmodifiableList(_observedVars); } /** - * We're assuming faithfuless (i.e., calculating d-separation facts), so is markes - * no sense to give judgments of determination of a varialbe by a set of variables. - * * @throws UnsupportedOperationException Since this method is not feasible. */ public boolean determines(List z, Node x1) { @@ -281,9 +291,11 @@ public boolean determines(List z, Node x1) { } /** - * Returns an alpha level, 0.5. + * Returns an alpha level, 0.5. This is an arbitrary nubmer that will help decide whether + * a pseudo p-value returned by the test represents a dependence or an independence. * * @return 0.5. + * @see #getPValue() */ public double getAlpha() { return 0.5; @@ -291,7 +303,8 @@ public double getAlpha() { /** * @throws UnsupportedOperationException it makes no sense to set an alpha level - * for a d-separation test. + * for a d-separation test away from the default. + * @see #getAlpha() */ public void setAlpha(double alpha) { throw new UnsupportedOperationException("Method mot implemented."); @@ -314,7 +327,9 @@ public Node getVariable(String name) { } /** - * @return the underlying graph. + * Returns the underlying graph that is being used to calculate d-separation relationships. + * + * @return This graph. */ public Graph getGraph() { return this.graph; @@ -337,7 +352,9 @@ public DataSet getData() { } /** - * @return 1 for d-connections, -1 for d-separations + * Returns 1 for d-connections, -1 for d-separations + * + * @return This number. */ @Override public double getScore() { @@ -345,7 +362,9 @@ public double getScore() { } /** - * @return True just in case verbose output should be printed. + * Returns True just in case verbose output should be printed. + * + * @return True if so. */ public boolean isVerbose() { return verbose; @@ -353,6 +372,7 @@ public boolean isVerbose() { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java index 334b6461c7..cc7c5ec5b7 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java @@ -43,9 +43,11 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Implements a degenerate Gaussian score as a LRT. + *

    Implements a degenerate Gaussian score as a LRT. The reference is here:

    * - * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2019, July). Learning high-dimensional + * directed acyclic graphs with mixed data-types. In The 2019 ACM SIGKDD Workshop + * on Causal Discovery (pp. 4-21). PMLR.

    * * @author Bryan Andrews */ @@ -69,7 +71,7 @@ public class IndTestDegenerateGaussianLrt implements IndependenceTest { private final Map> embedding; /** - * A return value for a likelihood--returns a likelihood value and the degrees of freedom + * Stores a return value for a likelihood--i.e., a likelihood value and the degrees of freedom * for it. */ public static class Ret { @@ -195,17 +197,17 @@ public IndTestDegenerateGaussianLrt(DataSet dataSet) { /** - * @param vars A sublist of the dataset variables. - * @return an Independence test for a subset of the searchVariables. + * @throws UnsupportedOperationException This method is not implemented. */ public IndependenceTest indTestSubset(List vars) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("This method is not implemented."); } /** - * @return True if the given independence question is judged true, False if not. The independence question is of the - * form x _||_ y | z, z = [z1,...,zn], where x, y, z1,...,zn are searchVariables in the list returned by - * getVariableNames(). + * Returns an independence result specifying whether x _||_ y | Z and what its p-value are. + * + * @return This result + * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, List z) { @@ -272,31 +274,38 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * @return the probability associated with the most recently executed independence test, of Double.NaN if p value is + * Returns the probability associated with the most recently executed independence test, of Double.NaN if p value is * not meaningful for tis test. + * + * @return This p-value. */ public double getPValue() { return this.pValue; } /** - * @return the list of searchVariables over which this independence checker is capable of determinining independence + * Returns the list of searchVariables over which this independence checker is capable of determinining independence * relations. + * + * @return This list. */ public List getVariables() { return new ArrayList<>(this.variables); } /** - * @return true if y is determined the variable in z. + * Returns true if y is determined the variable in z. + * + * @return True if so. */ public boolean determines(List z, Node y) { return false; //stub } /** - * @return the significance level of the independence test. - * @throws UnsupportedOperationException if there is no significance level. + * Returns the significance level of the independence test. + * + * @return this level. */ public double getAlpha() { return this.alpha; @@ -304,13 +313,17 @@ public double getAlpha() { /** * Sets the significance level. + * + * @param alpha This level. */ public void setAlpha(double alpha) { this.alpha = alpha; } /** - * @return The dataset being analyzed. + * Returns the dataset being analyzed. + * + * @return This data. */ public DataSet getData() { return this.dataSet; @@ -320,6 +333,7 @@ public DataSet getData() { /** * Returns a value that more positive for stronger dependence and positive * only if dependence holds. + * * @return This value. * @see Fges */ @@ -329,7 +343,9 @@ public double getScore() { } /** - * @return a string representation of this test. + * Returns a string representation of this test. + * + * @return This string. */ public String toString() { NumberFormat nf = new DecimalFormat("0.0000"); @@ -338,6 +354,7 @@ public String toString() { /** * Returns true iff verbose output should be printed. + * * @return True if so. */ @Override @@ -347,6 +364,7 @@ public boolean isVerbose() { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ @Override @@ -354,7 +372,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** * Calculates the sample log likelihood */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java index f6346bf472..f0fc8f779b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java @@ -143,7 +143,7 @@ public IndTestFisherZ(Matrix data, List variables, double alpha) { * Constructs a new independence test that will determine conditional independence facts using the given correlation * matrix and the given significance level. * - * @param covMatrix The covaraince matrix. + * @param covMatrix The covariance matrix. * @param alpha The alpha level of the test. */ public IndTestFisherZ(ICovarianceMatrix covMatrix, double alpha) { @@ -195,11 +195,8 @@ public IndependenceTest indTestSubset(List vars) { } /** - * Determines whether variable x is independent of variable y given a list of conditioning variables z. + * Determines whether variable x _||_ y | z given a list of conditioning variables z. * - * @param x the one variable being compared. - * @param y the second variable being compared. - * @param z the list of conditioning variables. * @return Independence result for x _||_ y | z. * @throws RuntimeException if a matrix singularity is encountered. * @see IndependenceResult @@ -233,7 +230,9 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * @return the probability associated with the most recently computed independence test. + * Returns the probability associated with the most recently computed independence test. + * + * @return This probability. */ public double getPValue() { return this.p; @@ -242,9 +241,6 @@ public double getPValue() { /** * Returns the p-value for x _||_ y | z. * - * @param x Node 1 - * @param y Node 2 - * @param z The conditioning varialbes. * @return The p-value. * @throws SingularMatrixException If a singularity occurs when invering a matrix. */ @@ -284,7 +280,9 @@ public double getBic() { } /** - * Gets the getModel significance level. + * Gets the model significance level. + * + * @return This alpha. */ public double getAlpha() { return this.alpha; @@ -293,6 +291,8 @@ public double getAlpha() { /** * Sets the significance level at which independence judgments should be made. Affects the cutoff for partial * correlations to be considered statistically equal to zero. + * + * @param alpha This alpha. */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { @@ -303,15 +303,17 @@ public void setAlpha(double alpha) { } /** - * @return the list of variables over which this independence checker is capable of determinine independence + * Returns the list of variables over which this independence checker is capable of determinine independence * relations-- that is, all the variables in the given graph or the given data set. + * + * @return This list. */ public List getVariables() { return this.variables; } /** - * Sets teh variables to a new list of the same size. Useful if multiple independence tests + * Sets the variables to a new list of the same size. Useful if multiple independence tests * are needed with object-identical sets of variables. * * @param variables The new list of variables. @@ -323,21 +325,27 @@ public void setVariables(List variables) { } /** - * @return the variable with the given name. + * Returns the variable with the given name. + * + * @return This variable. */ public Node getVariable(String name) { return this.nameMap.get(name); } /** - * @return the data set being analyzed. + * Returns the data set being analyzed. + * + * @return This data. */ public DataSet getData() { return this.dataSet; } /** - * @return the correlation matrix being analyzed. + * Returns the correlation matrix being analyzed. + * + * @return This correlation matrix. */ public ICovarianceMatrix getCov() { return this.cor; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java index 0ffbd7971e..db6d5f5c3e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java @@ -39,9 +39,10 @@ import java.util.List; /** - * Calculates independence from pooled residuals. + * Calculates independence from pooled residuals using the Fisher Z method. * * @author josephramsey + * @see IndTestFisherZ */ public final class IndTestFisherZConcatenateResiduals implements IndependenceTest { @@ -69,8 +70,9 @@ public final class IndTestFisherZConcatenateResiduals implements IndependenceTes /** * Constructor. + * * @param dataSets The continuous datasets to analyze. - * @param alpha The alpha significance cutoff value. + * @param alpha The alpha significance cutoff value. */ public IndTestFisherZConcatenateResiduals(List dataSets, double alpha) { System.out.println("# data sets = " + dataSets.size()); @@ -107,13 +109,11 @@ public IndependenceTest indTestSubset(List vars) { } /** - * Determines whether variable x is independent of variable y given a list of conditioning variables z. + * Determines whether x _||_ y | z. * - * @param x the one variable being compared. - * @param y the second variable being compared. - * @param z the list of conditioning variables. - * @return True iff x _||_ y | z. - * @throws RuntimeException if a matrix singularity is encountered. + * @return an independence result + * @see IndependenceResult + * @throws org.apache.commons.math3.linear.SingularMatrixException if a matrix singularity is encountered. */ public IndependenceResult checkIndependence(Node x, Node y, List z) { @@ -177,15 +177,6 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } - private Node getVariable(List variables, String name) { - for (Node node : variables) { - if (name.equals(node.getName())) { - return node; - } - } - - return null; - } /** * @return the probability associated with the most recently computed independence test. @@ -232,6 +223,7 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep /** * Returns the concatenated data. + * * @return This data */ public DataSet getData() { @@ -240,6 +232,7 @@ public DataSet getData() { /** * Returns teh covaraince matrix of the concatenated data. + * * @return This covariance matrix. */ @Override @@ -254,8 +247,9 @@ public ICovarianceMatrix getCov() { } /** - * Return a number that is positive when dependence holds and more positive + * Returns a number that is positive when dependence holds and more positive * for greater dependence. + * * @return This number * @see Fges */ @@ -273,6 +267,7 @@ public String toString() { /** * Return True if verbose output should be printed. + * * @return True if so. */ public boolean isVerbose() { @@ -281,6 +276,7 @@ public boolean isVerbose() { /** * Sets whether verbose output is printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { @@ -324,6 +320,17 @@ private double[] residuals(Node node, List parents) { return _f; } + + private Node getVariable(List variables, String name) { + for (Node node : variables) { + if (name.equals(node.getName())) { + return node; + } + } + + return null; + } + } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java index 5b9eb1d9dc..b18d184b8b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java @@ -39,8 +39,13 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Calculates independence from pooled residuals. + *

    Calculates independence from multiple datasets from using the Fisher method + * of pooling independence results. See this paper for details:

    * + *

    Tillman, R. E., & Eberhardt, F. (2014). Learning causal structure from + * multiple datasets with similar variable sets. Behaviormetrika, 41(1), 41-64.

    + * + * @author robertillman * @author josephramsey */ public final class IndTestFisherZFisherPValue implements IndependenceTest { @@ -57,8 +62,9 @@ public final class IndTestFisherZFisherPValue implements IndependenceTest { /** * Constructor. + * * @param dataSets The continuous datasets to analyze. - * @param alpha The alpha significance cutoff value. + * @param alpha The alpha significance cutoff value. */ public IndTestFisherZFisherPValue(List dataSets, double alpha) { @@ -156,7 +162,9 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * @return the probability associated with the most recently computed independence test. + * Returns the probability associated with the most recently computed independence test. + * + * @return This p-value. */ public double getPValue() { return this.pValue; @@ -165,6 +173,8 @@ public double getPValue() { /** * Sets the significance level at which independence judgments should be made. Affects the cutoff for partial * correlations to be considered statistically equal to zero. + * + * @param This alpha. */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { @@ -176,14 +186,18 @@ public void setAlpha(double alpha) { /** * Gets the getModel significance level. + * + * @return this alpha. */ public double getAlpha() { return this.alpha; } /** - * @return the list of variables over which this independence checker is capable of determinine independence + * Returns the list of variables over which this independence checker is capable of determinine independence * relations-- that is, all the variables in the given graph or the given data set. + * + * @return This list. */ public List getVariables() { return this.variables; @@ -198,6 +212,7 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep /** * Returns the concatenated data. + * * @return This data */ public DataSet getData() { @@ -205,7 +220,8 @@ public DataSet getData() { } /** - * Returns teh covaraince matrix of the concatenated data. + * Returns the covariance matrix of the concatenated data. + * * @return This covariance matrix. */ public ICovarianceMatrix getCov() { @@ -219,8 +235,9 @@ public ICovarianceMatrix getCov() { } /** - * Return a number that is positive when dependence holds and more positive + * Returns a number that is positive when dependence holds and more positive * for greater dependence. + * * @return This number * @see Fges */ @@ -230,14 +247,17 @@ public double getScore() { } /** - * @return a string representation of this test. + * Returns a string representation of this test. + * + * @return This string. */ public String toString() { return "Fisher Z, Fisher P Value Percent = " + round(.5 * 100); } /** - * Return True if verbose output should be printed. + * Returns True if verbose output should be printed. + * * @return True if so. */ public boolean isVerbose() { @@ -246,6 +266,7 @@ public boolean isVerbose() { /** * Sets whether verbose output is printed. + * * @param verbose True if so. */ public void setVerbose(boolean verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java index 61cc66b1a6..ead054a529 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java @@ -111,7 +111,9 @@ public IndTestGSquare(DataSet dataSet, double alpha) { } /** - * Creates a new IndTestGSquare for a subset of the variables. + * Creates a new IndTestGSquare for a sublist of the variables. + * + * @param vars This sublist. */ public IndependenceTest indTestSubset(List vars) { if (vars.isEmpty()) { @@ -134,7 +136,9 @@ public IndependenceTest indTestSubset(List vars) { } /** - * @return the p value associated with the most recent call of isIndependent. + * Returns the p value associated with the most recent call of isIndependent. + * + * @return This p-value. */ public double getPValue() { return this.pValue; @@ -146,7 +150,7 @@ public double getPValue() { * @param x the one variable being compared. * @param y the second variable being compared. * @param z the list of conditioning varNames. - * @return true iff x _||_ y | z. + * @return True iff x _||_ y | z. */ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (x == null) { @@ -222,24 +226,32 @@ public double getAlpha() { } /** - * @return the list of variables over which this independence checker is capable of determinine independence + * Return the list of variables over which this independence checker is capable of determinine independence * relations-- that is, all the variables in the given graph or the given data set. + * + * @return This list. */ public List getVariables() { return Collections.unmodifiableList(this.variables); } - + /** + * Returns a String representation of this test. + * + * @return This string. + */ public String toString() { return "G Square, alpha = " + IndTestGSquare.nf.format(getAlpha()); } /** - * @param z The list of variables z1,...,zn with respect to which we want to know whether z determines x oir z. - * @param x1 The one variable whose determination by z we want to know. + * Returns a judgment whether the variables in z determine x. + * + * @param z The list of variables z1,...,zn with respect to which we want to know whether z determines x oir z. + * @param x The one variable whose determination by z we want to know. * @return true if it is estimated that z determines x or z determines y. */ - public boolean determines(List z, Node x1) { + public boolean determines(List z, Node x) { if (z == null) { throw new NullPointerException(); } @@ -253,7 +265,7 @@ public boolean determines(List z, Node x1) { // For testing x, y given z1,...,zn, set up an array of length // n + 2 containing the indices of these variables in order. int[] testIndices = new int[1 + z.size()]; - testIndices[0] = this.variables.indexOf(x1); + testIndices[0] = this.variables.indexOf(x); for (int i = 0; i < z.size(); i++) { testIndices[i + 1] = this.variables.indexOf(z.get(i)); @@ -270,11 +282,11 @@ public boolean determines(List z, Node x1) { // System.out.println("Testing " + x + " _||_ " + y + " | " + z); boolean determined = - this.gSquareTest.isDetermined(testIndices, getDeterminationP()); + this.gSquareTest.isDetermined(testIndices, this.determinationP); if (determined) { StringBuilder sb = new StringBuilder(); - sb.append("Determination found: ").append(x1).append( + sb.append("Determination found: ").append(x).append( " is determined by {"); for (int i = 0; i < z.size(); i++) { @@ -293,29 +305,50 @@ public boolean determines(List z, Node x1) { return determined; } - public double getDeterminationP() { - return this.determinationP; - } - + /** + * Sets the threshold for making judgments of detemrination. + * + * @param determinationP This threshold. + */ public void setDeterminationP(double determinationP) { this.determinationP = determinationP; } + /** + * Returns the data. + * + * @return This data. + */ public DataSet getData() { return this.dataSet; } + /** + * Returns the score, alpha - p. + * + * @return This score. + */ @Override public double getScore() { - return getPValue(); + return alpha - getPValue(); } + /** + * Returns True if verbose output is printed. + * + * @return True if so. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output is printed. + * + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java index 0c45a69d31..f702c168a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java @@ -27,10 +27,10 @@ import edu.cmu.tetrad.data.DoubleDataBox; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.utils.Kernel; import edu.cmu.tetrad.search.utils.KernelGaussian; import edu.cmu.tetrad.search.utils.KernelUtils; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.RandomUtil; @@ -43,12 +43,12 @@ import java.util.List; /** - * Checks the conditional independence X _||_ Y | S, where S is a set of continuous variable, + *

    Checks the conditional independence X _||_ Y | S, where S is a set of continuous variable, * and X and Y are discrete variable not in S, using the Hilbert-Schmidth Independence - * Criterion (HSIC), a kernel based nonparametric test for conditional independence. + * Criterion (HSIC), a kernel based nonparametric test for conditional independence.

    * - * The Kpc algorithm by Tillman had run PC using this test; to run Kpc, simply select this test - * for PC. + *

    The Kpc algorithm by Tillman had run PC using this test; to run Kpc, simply select this test + * for PC.

    * * @author Robert Tillman * @see edu.cmu.tetrad.search.work_in_progress.Kpc @@ -123,6 +123,13 @@ public IndTestHsic(DataSet dataSet, double alpha) { this.dataSet = dataSet; } + /** + * Constructs a new HSIC Independence test. The given significance level is used. + * + * @param data A matrix of continuous data. + * @param variables The list of variables for the data. + * @param alpha The alpha level of the test. + */ public IndTestHsic(Matrix data, List variables, double alpha) { DataSet dataSet = new BoxDataSet(new DoubleDataBox(data.toArray()), variables); @@ -137,6 +144,8 @@ public IndTestHsic(Matrix data, List variables, double alpha) { /** * Creates a new IndTestHsic instance for a subset of the variables. + * + * @return This sublist. */ public IndependenceTest indTestSubset(List vars) { if (vars.isEmpty()) { @@ -166,7 +175,7 @@ public IndependenceTest indTestSubset(List vars) { * @param x the one variable being compared. * @param y the second variable being compared. * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. + * @return True iff x _||_ y | z. */ public IndependenceResult checkIndependence(Node y, Node x, List z) { @@ -508,12 +517,10 @@ public double empiricalHSICincompleteCholesky(Matrix Gy, Matrix Gx, Matrix Gz, i return empHSIC; } - public double getThreshold() { - return this.thresh; - } - /** - * @return the probability associated with the most recently computed independence test. + * Returns the probability associated with the most recently computed independence test. + * + * @return This p-value. */ public double getPValue() { return this.pValue; @@ -521,6 +528,8 @@ public double getPValue() { /** * Sets the significance level at which independence judgments should be made. + * + * @param alpha This alpha. */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { @@ -534,6 +543,8 @@ public void setAlpha(double alpha) { /** * Sets the precision for the Incomplete Choleksy factorization method for approximating Gram matrices. A value <= 0 * indicates that the Incomplete Cholesky method should not be used and instead use the exact matrices. + * + * @param precision This precision. */ public void setIncompleteCholesky(double precision) { this.useIncompleteCholesky = precision; @@ -541,13 +552,17 @@ public void setIncompleteCholesky(double precision) { /** * Set the number of bootstrap samples to use + * + * @param numBootstraps This number. */ - public void setPerms(int perms) { - this.perms = perms; + public void setPerms(int numBootstraps) { + this.perms = numBootstraps; } /** - * Sets the regularizer + * Sets the regularizer. + * + * @param regularizer This value. */ public void setRegularizer(double regularizer) { this.regularizer = regularizer; @@ -555,35 +570,27 @@ public void setRegularizer(double regularizer) { /** * Gets the getModel significance level. + * + * @return This alpha. */ public double getAlpha() { return this.alpha; } /** - * Gets the getModel precision for the Incomplete Cholesky - */ - public double getPrecision() { - return this.useIncompleteCholesky; - } - - /** - * Gets the getModel number of bootstrap samples used - */ - public int getPerms() { - return this.perms; - } - - /** - * @return the list of variables over which this independence checker is capable of determinine independence + * Returns the list of variables over which this independence checker is capable of determinine independence * relations-- that is, all the variables in the given graph or the given data set. + * + * @return This list. */ public List getVariables() { return this.variables; } /** - * @return the variable with the given name. + * Returns the variable with the given name. + * + * @return This string. */ public Node getVariable(String name) { for (int i = 0; i < getVariables().size(); i++) { @@ -597,25 +604,37 @@ public Node getVariable(String name) { /** - * @return the data set being analyzed. + * Returns the data set being analyzed. + * + * @return This data. */ public DataSet getData() { return this.dataSet; } + /** + * Returns the score for this this test, alpha - p. + * + * @return This score. + */ @Override public double getScore() { - return getPValue(); + return alpha - getPValue(); } /** - * @return a string representation of this test. + * Returns a string representation of this test. + * + * @return This string. */ public String toString() { return "HSIC, alpha = " + IndTestHsic.nf.format(getAlpha()); } + /** + * @throws UnsupportedOperationException Method not supported. + */ public boolean determines(List z, Node x) throws UnsupportedOperationException { throw new UnsupportedOperationException("Method not implemented"); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java index 5836e0696d..2e03aa8c40 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestIndependenceFacts.java @@ -35,7 +35,6 @@ * Checks conditional independence against a list of conditional independence facts, manually entered. * * @author josephramsey - * @see ChiSquareTest */ public final class IndTestIndependenceFacts implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java index f9dcc01cf1..7bc940f09c 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java @@ -24,8 +24,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.search.score.MvpLikelihood; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.collections4.map.HashedMap; import org.apache.commons.math3.distribution.ChiSquaredDistribution; @@ -35,8 +35,12 @@ import java.util.Map; /** - * Performs a test of conditional independence X _||_ Y | Z1...Zn where all searchVariables are either continuous or discrete. - * This test is valid for both ordinal and non-ordinal discrete searchVariables. + *

    Performs a test of conditional independence X _||_ Y | Z1...Zn where all + * variables are either continuous or discrete. This test is valid for both ordinal + * and non-ordinal discrete searchVariables.

    + * + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of + * mixed variables. International journal of data science and analytics, 6, 3-18.

    * * @author Bryan Andrews */ @@ -53,6 +57,14 @@ public class IndTestMvpLrt implements IndependenceTest { // P Values private double pValue = Double.NaN; + /** + * Constructor. + * + * @param data The mixed continuous/discrete dataset. + * @param alpha The significance level. + * @param fDegree The f degree. + * @param discretize True if continuous children should be discretized. + */ public IndTestMvpLrt(DataSet data, double alpha, int fDegree, boolean discretize) { this.data = data; this.likelihood = new MvpLikelihood(data, -1, fDegree, discretize); @@ -69,16 +81,20 @@ public IndTestMvpLrt(DataSet data, double alpha, int fDegree, boolean discretize } /** - * @return an Independence test for a subset of the searchVariables. + * Returns an independence test for a sublist of the searchVariables. + * + * @return this test. + * @see IndependenceTest */ public IndependenceTest indTestSubset(List vars) { throw new UnsupportedOperationException(); } /** - * @return true if the given independence question is judged true, false if not. The independence question is of the - * form x _||_ y | z, z = [z1,...,zn], where x, y, z1,...,zn are searchVariables in the list returned by - * getVariableNames(). + * Returns an independence result for x _||_ y | z. + * + * @return This result. + * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, List z) { @@ -141,31 +157,36 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * @return the probability associated with the most recently executed independence test, of Double.NaN if p value is - * not meaningful for tis test. + * Returns The probability associated with the most recently executed independence test, of Double.NaN if p value is + * not meaningful for this test. + * + * @return This p-value. */ public double getPValue() { return this.pValue; } /** - * @return the list of searchVariables over which this independence checker is capable of determinining independence + * Returns the list of searchVariables over which this independence checker is capable of determinining independence * relations. + * + * @return This list. */ public List getVariables() { return this.data.getVariables(); } - /** - * @return true if y is determined the variable in z. + * @throws javax.help.UnsupportedOperationException Method not implemented. */ public boolean determines(List z, Node y) { - return false; //stub + throw new UnsupportedOperationException("Method not implemented."); } /** - * @return the significance level of the independence test. + * Returns the significance level of the independence test. + * + * @return This level. * @throws UnsupportedOperationException if there is no significance level. */ public double getAlpha() { @@ -174,27 +195,47 @@ public double getAlpha() { /** * Sets the significance level. + * + * @param alpha This level. */ public void setAlpha(double alpha) { this.alpha = alpha; } + /** + * Returns the data. + * + * @return This data. + */ public DataSet getData() { return this.data; } - + /** + * Returns alph - p. + * + * @return This score. + */ @Override - public double getScore() { return getAlpha() - getPValue(); } + /** + * Returns true if verbose output is printed. + * + * @return True if so. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Returns whether verbose output should be printed. + * + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java index e9afbdfa0c..d3e759bc35 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java @@ -45,12 +45,11 @@ import java.util.List; /** - * Checks independence of X _||_ Y | Z for variables X and Y and list Z of variables. Partial correlations are - * calculated using generalized inverses, so linearly dependent variables do not throw exceptions. Must supply a - * continuous data set; don't know how to do this with covariance or correlation matrices. + * Checks independence of X _||_ Y | Z for variables X and Y and list Z of variables by + * regressing X on {Y} U Z and testing whether the coefficient for Y is zero. * * @author josephramsey - * @author Frank Wimberly adapted IndTestCramerT for Fisher's Z + * @author Frank Wimberly */ public final class IndTestRegression implements IndependenceTest { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestTrekSep.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestTrekSep.java index a10477d8a2..3136cfb32e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestTrekSep.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestTrekSep.java @@ -60,6 +60,12 @@ public final class IndTestTrekSep implements IndependenceTest { /** * Constructs a new independence test that will determine conditional independence facts using the given correlation * matrix and the given significance level. + * + * @param covMatrix The covariance over the measures. + * @param alpha The significance level. + * @param clustering The clustering of the measured variables. In each cluster, all measured variable in + * the cluster are explained by a single latent. + * @param latents The list of latent variables for the clusters, in order. */ public IndTestTrekSep(ICovarianceMatrix covMatrix, double alpha, List> clustering, List latents) { this.clustering = clustering; @@ -74,7 +80,9 @@ public IndTestTrekSep(ICovarianceMatrix covMatrix, double alpha, List //==========================PUBLIC METHODS=============================// /** - * Creates a new independence test instance for a subset of the variables. + * Creates a new independence test instance for a sublist of the variables. + * + * @param vars The sublist. */ public IndependenceTest indTestSubset(List vars) { if (vars.isEmpty()) { @@ -106,8 +114,8 @@ public IndependenceTest indTestSubset(List vars) { * @param x the one variable being compared. * @param y the second variable being compared. * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. - * @throws RuntimeException if a matrix singularity is encountered. + * @return True iff x _||_ y | z. + * @throws org.apache.commons.math3.linear.SingularMatrixException if a matrix singularity is encountered. */ public IndependenceResult checkIndependence(Node x, Node y, List z) { int n = sampleSize(); @@ -158,7 +166,9 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } /** - * @return the probability associated with the most recently computed independence test. + * Returns the probability associated with the most recently computed independence test. + * + * @return This p-value. */ public double getPValue() { return this.pValue; @@ -167,6 +177,8 @@ public double getPValue() { /** * Sets the significance level at which independence judgments should be made. Affects the cutoff for partial * correlations to be considered statistically equal to zero. + * + * @param alpha This significance level. */ public void setAlpha(double alpha) { if (alpha < 0.0 || alpha > 1.0) { @@ -177,30 +189,39 @@ public void setAlpha(double alpha) { } /** - * Gets the getModel significance level. + * Gets the model significance level. + * + * @return This alpha. */ public double getAlpha() { return this.alpha; } /** - * @return the list of variables over which this independence checker is capable of determinine independence + * Returns the list of variables over which this independence checker is capable of determinine independence * relations-- that is, all the variables in the given graph or the given data set. + * + * @return This list. */ public List getVariables() { return this.latents; } /** - * @return the variable with the given name. + * Returns the variable with the given name. + * + * @return This variable. */ public Node getVariable(String name) { return this.nameMap.get(name); } /** - * If isDeterminismAllowed(), deters to IndTestFisherZD; otherwise throws + * If isDeterminismAllowed(), defers to IndTestFisherZD; otherwise throws * UnsupportedOperationException. + * + * @return True if so + * @throws UnsupportedOperationException If the above condition is not met. */ public boolean determines(List z, Node x) throws UnsupportedOperationException { int[] parents = new int[z.size()]; @@ -237,29 +258,49 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep } /** - * @return the data set being analyzed. + * Returns the data set being analyzed. + * + * @return This data. */ public DataSet getData() { return this.dataSet; } /** - * @return a string representation of this test. + * Returns a string representation of this test. + * + * @return This string. */ public String toString() { return "t-Separation test, alpha = " + IndTestTrekSep.nf.format(getAlpha()); } + /** + * Sets the varialbe to this list (of the same length). Useful is multiple test are used that + * need the same object-identical lists of variables. + * + * @param variables This list. + */ public void setVariables(List variables) { if (variables.size() != this.variables.size()) throw new IllegalArgumentException("Wrong # of variables."); this.variables = new ArrayList<>(variables); this.covMatrix.setVariables(variables); } + /** + * Returns the covariance matrix. + * + * @return This matrix. + */ public ICovarianceMatrix getCov() { return this.covMatrix; } + /** + * Returns a singleton list consisting just of the dataset for this test. + * + * @return This lsit. + */ @Override public List getDataSets() { @@ -270,21 +311,41 @@ public List getDataSets() { return dataSets; } + /** + * Returns the sample size. + * + * @return This size. + */ @Override public int getSampleSize() { return this.covMatrix.getSampleSize(); } + /** + * Returns alpha - p. + * + * @return This nubmer. + */ @Override public double getScore() { - return getPValue(); + return alpha - getPValue(); } + /** + * Returns true if verbose output should be printed. + * + * @return True if so. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output should be printed. + * + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java index cb02d264d7..e106312f69 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java @@ -7,8 +7,8 @@ import edu.cmu.tetrad.util.TetradSerializableUtils; /** - * Stores a single conditional independence result, e.g., whether - * X _||_ Y | Z1,..,Zn holds or does not. + *

    Stores a single conditional independence result, e.g., whether + * X _||_ Y | Z1,..,Zn holds or does not, and the p-value of the test.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java index 4c4f4c4e08..8077f42a82 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java @@ -63,7 +63,9 @@ public interface IndependenceTest { DataModel getData(); /** - * @return A score that is higher with more likely models. + * Return A score that is higher with more likely models. + * + * @return This score. */ double getScore(); @@ -91,14 +93,18 @@ public interface IndependenceTest { //==============================DEFAULT METHODS=========================// /** - * @return an Independence test for a subset of the variables. + * Returns an Independence test for a sublist of the variables. + * + * @param vars The sublist of variables. */ default IndependenceTest indTestSubset(List vars) { throw new UnsupportedOperationException("Independence subset feature is not implemented."); } /** - * @return and IndependenceResult (see). + * Checks the independence fact in question and returns and independence result. + * + * @return The independence result. * @see IndependenceResult */ default IndependenceResult checkIndependence(Node x, Node y, Node... z) { @@ -106,6 +112,11 @@ default IndependenceResult checkIndependence(Node x, Node y, Node... z) { return checkIndependence(x, y, zList); } + /** + * Returns the sample size. + * + * @return This size. + */ default int getSampleSize() { DataModel data = getData(); if (data instanceof CovarianceMatrix) { @@ -118,7 +129,9 @@ default int getSampleSize() { } /** - * @return the variable by the given name. + * Returns The variable by the given name. + * + * @return This variables. */ default Node getVariable(String name) { for (int i = 0; i < getVariables().size(); i++) { @@ -132,7 +145,9 @@ default Node getVariable(String name) { } /** - * @return the list of names for the variables in getNodesInEvidence. + * Returns the list of names for the variables in getNodesInEvidence. + * + * @return this list. */ default List getVariableNames() { List variables = getVariables(); @@ -144,14 +159,18 @@ default List getVariableNames() { } /** - * @return true if y is determined the variable in z. + * Returns true if y is determined the variable in z. + * + * @return True if so. */ default boolean determines(List z, Node y) { throw new UnsupportedOperationException("Determines method is not implmeented."); } /** - * @return the significance level of the independence test. + * Returns the significance level of the independence test. + * + * @return This level. * @throws UnsupportedOperationException if there is no significance level. */ default double getAlpha() { @@ -160,15 +179,29 @@ default double getAlpha() { /** * Sets the significance level. + * + * @param alpha This level. */ default void setAlpha(double alpha) { throw new UnsupportedOperationException("The setAlpha() method is not implemented for this test."); } + /** + * Returns the covariance matrix. + * + * @return This matrix. + * @throws UnsupportedOperationException If this method is not suppored for a particular test. + */ default ICovarianceMatrix getCov() { throw new UnsupportedOperationException("The getCov() method is not implemented for this test."); } + /** + * Returns the datasets for this test + * + * @return these datasets. + * @throws javax.help.UnsupportedOperationException If this method is not supported for a particular test. + */ default List getDataSets() { throw new UnsupportedOperationException("The getDataSets() method is not implemented for this test."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java index 57011e4b64..be91839b03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java @@ -6,8 +6,6 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.test.IndependenceResult; -import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; import edu.cmu.tetrad.util.Vector; @@ -121,16 +119,19 @@ public Kci(DataSet data, double alpha) { //====================================PUBLIC METHODS==================================// /** - * Returns an Independence test for a subset of the variables. + * @throws javax.help.UnsupportedOperationException Method not implemented. */ public IndependenceTest indTestSubset(List vars) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("Method not implemented."); } /** * Returns True if the given independence question is judged true, false if not. The independence question is of the * form x _||_ y | z, z = [z1,...,zn], where x, y, z1,...,zn are variables in the list returned by * getVariableNames(). + * + * @return The independence result. + * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, List z) { if (Thread.currentThread().isInterrupted()) { @@ -236,6 +237,8 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { /** * Returns the list of variables over which this independence checker is capable of determinining independence * relations. + * + * @return This list. */ public List getVariables() { return this.variables; @@ -243,6 +246,8 @@ public List getVariables() { /** * Returns the variable by the given name. + * + * @return This variable. */ public Node getVariable(String name) { return this.data.getVariable(name); @@ -250,6 +255,8 @@ public Node getVariable(String name) { /** * Returns true if y is determined the variable in z. + * + * @return True if so. */ public boolean determines(List z, Node y) { throw new UnsupportedOperationException(); @@ -258,7 +265,7 @@ public boolean determines(List z, Node y) { /** * Returns the significance level of the independence test. * - * @throws UnsupportedOperationException if there is no significance level. + * @return This alpha. */ public double getAlpha() { return this.alpha; @@ -266,13 +273,17 @@ public double getAlpha() { /** * Sets the significance level. + * + * @param alpha This alpha. */ public void setAlpha(double alpha) { this.alpha = alpha; } /** - * @return a string representation of this test. + * Returns a string representation of this test. + * + * @return This string. */ public String toString() { return "KCI, alpha = " + new DecimalFormat("0.0###").format(getAlpha()); @@ -280,87 +291,120 @@ public String toString() { /** - * @return The data model for the independence test. + * Returns The data model for the independence test. + * + * @return This data. */ public DataModel getData() { return this.data; } - + /** + * @throws UnsupportedOperationException Method not implemented. + */ public ICovarianceMatrix getCov() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("Method not implemented."); } + /** + * Returns a list consisting of the dataset for this test. + * + * @return This dataset in a list. + */ public List getDataSets() { LinkedList L = new LinkedList<>(); L.add(this.data); return L; } + /** + * Returns the sample size. + * + * @return This size. + */ public int getSampleSize() { return this.data.getNumRows(); } - public List getCovMatrices() { - throw new UnsupportedOperationException(); - } - + /** + * Returns alpha - p. + * + * @return This number. + */ public double getScore() { return getAlpha() - facts.get(latestFact).getPValue(); } - public boolean isApproximate() { - return this.approximate; - } - + /** + * Sets whether the approximate algorithm should be used. + * + * @param approximate True if so. + */ public void setApproximate(boolean approximate) { this.approximate = approximate; } - private double getWidthMultiplier() { - return this.widthMultiplier; - } - + /** + * Sets the width multiplier. + * + * @param widthMultiplier This multipler. + */ public void setWidthMultiplier(double widthMultiplier) { if (widthMultiplier <= 0) throw new IllegalStateException("Width must be > 0"); this.widthMultiplier = widthMultiplier; } - private int getNumBootstraps() { - return this.numBootstraps; - } - + /** + * Sets the number of bootstraps to do. + * + * @param numBootstraps This number. + */ public void setNumBootstraps(int numBootstraps) { if (numBootstraps < 1) throw new IllegalArgumentException("Num bootstraps should be >= 1: " + numBootstraps); this.numBootstraps = numBootstraps; } - - public double getThreshold() { - return this.threshold; - } - + /** + * Sets the threshold. + * + * @param threshold This number. + */ public void setThreshold(double threshold) { if (threshold < 0.0) throw new IllegalArgumentException("Threshold must be >= 0.0: " + threshold); this.threshold = threshold; } + /** + * Sets the epsilon. + * + * @param epsilon This number. + */ public void setEpsilon(double epsilon) { this.epsilon = epsilon; } + /** + * Returns true if verbose output is printed. + * + * @return True if so. + */ @Override public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output is printed. + * + * @param verbose True if so. + */ @Override public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * KCI independence for the unconditional case. Uses Theorem 4 from the paper. + /* + * Returns the KCI independence result for the unconditional case. Uses Theorem 4 from the paper. * * @return true just in case independence holds. */ @@ -372,11 +416,11 @@ private IndependenceResult isIndependentUnconditional(Node x, Node y, Independen Matrix H = Matrix.identity(N).minus(Ones.times(Ones.transpose()).scalarMult(1.0 / N)); - Matrix kx = center(kernelMatrix(_data, x, null, getWidthMultiplier(), hash, N, _h), H); - Matrix ky = center(kernelMatrix(_data, y, null, getWidthMultiplier(), hash, N, _h), H); + Matrix kx = center(kernelMatrix(_data, x, null, this.widthMultiplier, hash, N, _h), H); + Matrix ky = center(kernelMatrix(_data, y, null, this.widthMultiplier, hash, N, _h), H); try { - if (isApproximate()) { + if (this.approximate) { double sta = kx.times(ky).trace(); double mean_appr = kx.trace() * ky.trace() / N; double var_appr = 2 * kx.times(kx).trace() * ky.times(ky).trace() / (N * N); @@ -398,8 +442,8 @@ private IndependenceResult isIndependentUnconditional(Node x, Node y, Independen } } - /** - * KCI independence for the conditional case. Uses Theorem 3 from the paper. + /* + * Returns the KCI independence result for the conditional case. Uses Theorem 3 from the paper. * * @return true just in case independence holds. */ @@ -409,9 +453,9 @@ private IndependenceResult isIndependentConditional(Node x, Node y, List z Matrix ky; try { - Matrix KXZ = center(kernelMatrix(_data, x, z, getWidthMultiplier(), hash, N, _h), H); - Matrix Ky = center(kernelMatrix(_data, y, null, getWidthMultiplier(), hash, N, _h), H); - Matrix KZ = center(kernelMatrix(_data, null, z, getWidthMultiplier(), hash, N, _h), H); + Matrix KXZ = center(kernelMatrix(_data, x, z, this.widthMultiplier, hash, N, _h), H); + Matrix Ky = center(kernelMatrix(_data, y, null, this.widthMultiplier, hash, N, _h), H); + Matrix KZ = center(kernelMatrix(_data, null, z, this.widthMultiplier, hash, N, _h), H); Matrix Rz = (KZ.plus(I.scalarMult(this.epsilon)).inverse().scalarMult(this.epsilon)); @@ -442,7 +486,7 @@ private IndependenceResult theorem4(Matrix kx, Matrix ky, IndependenceFact fact, // Calculate formula (9). int sum = 0; - for (int j = 0; j < getNumBootstraps(); j++) { + for (int j = 0; j < this.numBootstraps; j++) { double tui = 0.0; for (double lambdax : evx) { @@ -457,7 +501,7 @@ private IndependenceResult theorem4(Matrix kx, Matrix ky, IndependenceFact fact, } // Calculate p. - double p = sum / (double) getNumBootstraps(); + double p = sum / (double) this.numBootstraps; boolean indep = p > getAlpha(); IndependenceResult result = new IndependenceResult(fact, indep, p); this.facts.put(fact, result); @@ -493,7 +537,7 @@ private IndependenceResult proposition5(Matrix kx, Matrix ky, IndependenceFact f Matrix uuprod = prod > N ? UU.times(UU.transpose()) : UU.transpose().times(UU); - if (isApproximate()) { + if (this.approximate) { double sta = kx.times(ky).trace(); double mean_appr = uuprod.trace(); double var_appr = 2.0 * uuprod.times(uuprod).trace(); @@ -513,7 +557,7 @@ private IndependenceResult proposition5(Matrix kx, Matrix ky, IndependenceFact f // Calculate formulas (13) and (14). int sum = 0; - for (int j = 0; j < getNumBootstraps(); j++) { + for (int j = 0; j < this.numBootstraps; j++) { double s = 0.0; for (double lambdaStar : eigenu) { @@ -525,7 +569,7 @@ private IndependenceResult proposition5(Matrix kx, Matrix ky, IndependenceFact f if (s > T) sum++; } - double p = sum / (double) getNumBootstraps(); + double p = sum / (double) this.numBootstraps; boolean indep = p > getAlpha(); IndependenceResult result = new IndependenceResult(fact, indep, p); this.facts.put(fact, result); @@ -680,7 +724,7 @@ public Eigendecomposition invoke() { double[] arr = ed.getRealEigenvalues(); List indx = series(arr.length); // 1 2 3... - topIndices = getTopIndices(arr, indx, getThreshold()); + topIndices = getTopIndices(arr, indx, Kci.this.threshold); this.D = new Matrix(topIndices.size(), topIndices.size()); @@ -706,7 +750,7 @@ public Eigendecomposition invoke() { double[] evxAll = svd.getSingularValues(); List indx = series(evxAll.length); // 1 2 3... - topIndices = getTopIndices(evxAll, indx, getThreshold()); + topIndices = getTopIndices(evxAll, indx, Kci.this.threshold); D = new Matrix(topIndices.size(), topIndices.size()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java index a621240151..e53421d620 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java @@ -41,7 +41,6 @@ * the score returned will be negative for independence and positive for dependence; * this simply reports these differences.

    * - * @author doncrimbchin * @author josephramsey */ public class ScoreIndTest implements IndependenceTest { @@ -71,13 +70,11 @@ public ScoreIndTest indTestSubset(List vars) { } /** - * Determines whether variable x is independent of variable y given a list of conditioning variables z. + * Determines whether x _||_ y | z * - * @param x the one variable being compared. - * @param y the second variable being compared. - * @param z the list of conditioning variables. - * @return true iff x _||_ y | z. + * @return The independence result. * @throws RuntimeException if a matrix singularity is encountered. + * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, List z) { List z1 = new ArrayList<>(z); @@ -103,34 +100,30 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { return new IndependenceResult(new IndependenceFact(x, y, z), independent, getPValue()); } - private int[] varIndices(List z) { - int[] indices = new int[z.size()]; - - for (int i = 0; i < z.size(); i++) { - indices[i] = this.variables.indexOf(z.get(i)); - } - - return indices; - } - /** - * @return the probability associated with the most recently executed independence test, of Double.NaN if p value is - * not meaningful for tis test. + * Returns the probability associated with the most recently executed independence test, of Double.NaN if p value is + * not meaningful for this test. + * + * @return This p-value. */ public double getPValue() { return this.bump; } /** - * @return the list of variables over which this independence checker is capable of determinining independence + * Returns the list of variables over which this independence checker is capable of determinining independence * relations. + * + * @return This list. */ public List getVariables() { return this.variables; } /** - * @return the variable by the given name. + * Returns the variable by the given name. + * + * @return This variable. */ public Node getVariable(String name) { for (Node node : this.variables) { @@ -143,14 +136,18 @@ public Node getVariable(String name) { } /** - * @return true if y is determined the variable in z. + * Returns true if y is determined the variable in z. + * + * @return True is so. */ public boolean determines(List z, Node y) { return this.score.determines(z, y); } /** - * @return the significance level of the independence test. + * Returns the significance level of the independence test. + * + * @return This level. * @throws UnsupportedOperationException if there is no significance level. */ public double getAlpha() { @@ -159,6 +156,7 @@ public double getAlpha() { /** * Sets the significance level. + * * @param alpha This level. */ public void setAlpha(double alpha) { @@ -173,6 +171,7 @@ public DataModel getData() { /** * Returns the covariance matrix. + * * @return This matrix. */ public ICovarianceMatrix getCov() { @@ -183,11 +182,12 @@ public ICovarianceMatrix getCov() { * @throws UnsupportedOperationException Not implemented. */ public List getDataSets() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("Method not implemented"); } /** * Returns the sample size. + * * @return This size. */ public int getSampleSize() { @@ -195,15 +195,18 @@ public int getSampleSize() { } /** - * @return A score that is higher with more likely models. + * Returns A score that is higher with more likely models. + * + * @return This score. */ public double getScore() { return this.bump; } /** - * Returns the score that this test wraps. - * @return This score + * Returns the score object that this test wraps. + * + * @return This score object. * @see Score */ public Score getWrappedScore() { @@ -212,6 +215,7 @@ public Score getWrappedScore() { /** * Returns true if verbose ouput should be printed. + * * @return True if so. */ @Override @@ -221,6 +225,7 @@ public boolean isVerbose() { /** * Sets whether verbose output should be printed. + * * @param verbose True if so. */ @Override @@ -230,12 +235,24 @@ public void setVerbose(boolean verbose) { /** * Returns a String representation of this test. + * * @return This string. */ @Override public String toString() { return this.score.toString() + " Interpreted as a Test"; } + + + private int[] varIndices(List z) { + int[] indices = new int[z.size()]; + + for (int i = 0; i < z.size(); i++) { + indices[i] = this.variables.indexOf(z.get(i)); + } + + return indices; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMnlrLr.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMnlrLr.java index c96b10f2d2..2eacc41d80 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMnlrLr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMnlrLr.java @@ -19,13 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.test; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.score.MnlrLikelihood; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.collections4.map.HashedMap; import org.apache.commons.math3.distribution.ChiSquaredDistribution; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestPositiveCorr.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestPositiveCorr.java index cc06f2d132..0dee79c38d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestPositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestPositiveCorr.java @@ -19,13 +19,15 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.test; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.test.IndependenceResult; +import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.StatUtils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrLikelihood.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrLikelihood.java index 76404ed6ed..00b4152448 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrLikelihood.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.score; +package edu.cmu.tetrad.search.work_in_progress; import de.bwaldvogel.liblinear.*; import edu.cmu.tetrad.data.ContinuousVariable; From b10080c0edd22eb32c321893e37106482fbb3aaa Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 16:08:19 -0400 Subject: [PATCH 388/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/score/BdeScore.java | 4 +-- .../cmu/tetrad/search/score/BdeuScore.java | 4 +-- .../score/ConditionalGaussianLikelihood.java | 12 ++++--- .../score/ConditionalGaussianScore.java | 7 +++-- .../search/score/DegenerateGaussianScore.java | 19 ++++++------ .../tetrad/search/score/DiscreteBicScore.java | 7 ++++- .../cmu/tetrad/search/score/EbicScore.java | 5 ++- .../cmu/tetrad/search/score/GicScores.java | 3 +- .../cmu/tetrad/search/score/ImagesScore.java | 20 ++++++------ .../cmu/tetrad/search/score/IndTestScore.java | 7 +++-- .../tetrad/search/score/MagSemBicScore.java | 2 +- .../tetrad/search/score/MvpLikelihood.java | 5 ++- .../edu/cmu/tetrad/search/score/MvpScore.java | 5 ++- .../search/score/PoissonPriorScore.java | 9 +++++- .../edu/cmu/tetrad/search/score/Score.java | 31 ++++++++++++++++++- .../edu/cmu/tetrad/search/score/ZsbScore.java | 4 +-- .../tetrad/search/test/IndependenceTest.java | 3 +- .../MnlrScore.java | 3 +- 18 files changed, 105 insertions(+), 45 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{score => work_in_progress}/MnlrScore.java (98%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java index eed645a1d9..5e041c3904 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeScore.java @@ -32,9 +32,9 @@ /** *

    Calculates the BDe score (Bayes Dirichlet Equivalent) score for analyzing * discrete multinomial data. A good discussion of BD* scores can be found here:

    + * *

    Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: - * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). - * https://doi.org/10.1007/BF00994016

    + * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995).

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java index c415d19338..b71e4f69ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/BdeuScore.java @@ -34,9 +34,9 @@ /** *

    Calculates the BDeu score, which the BDe (Bayes Dirichlet Equivalent) score * with uniform priors. A good discussion of BD* scores can be found here:

    + * *

    Heckerman, D., Geiger, D. & Chickering, D.M. Learning Bayesian networks: - * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995). - * https://doi.org/10.1007/BF00994016

    + * The combination of knowledge and statistical data. Mach Learn 20, 197–243 (1995).

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java index e895828e9f..a59cfff22f 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java @@ -39,14 +39,18 @@ import static org.apache.commons.math3.util.FastMath.log; /** - * Implements a conditional Gaussian likelihood. Please note that this likelihood will be maximal only if the - * continuous mixedVariables are jointly Gaussian conditional on the discrete mixedVariables; in all other cases, it will - * be less than maximal. For an algorithm like FGS this is fine. + *

    Implements a conditional Gaussian likelihood. Please note that this likelihood will be + * maximal only if the continuous variables are jointly Gaussian conditional on the + * discrete variables; in all other cases, it will be less than maximal. The reference is here:

    + * + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of mixed variables. + * International journal of data science and analytics, 6, 3-18.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    * - * * @author josephramsey + * @author bryanandrews + * @author josephramsey */ public class ConditionalGaussianLikelihood { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index 7c80085ed8..28f8496990 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -34,9 +34,12 @@ import java.util.List; /** - * Implements a conditional Gaussian BIC score for FGS, which calculates a BIC + *

    Implements a conditional Gaussian BIC score for FGS, which calculates a BIC * score for mixed discrete/Gaussian data using the conditional Gaussian - * likelihood function (see). + * likelihood function (see). The reference is here:

    + * + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of mixed variables. + * International journal of data science and analytics, 6, 3-18.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 45bed7ba20..329104638a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -40,16 +40,15 @@ import static org.apache.commons.math3.util.FastMath.log; /** - *

    This implements the degenerate Gaussian BIC score for FGES. - * The degenerate Gaussian score replaces each discrete variable - * in the data with a list of 0/1 continuous indicator columns for - * each of the categories but one (the last one implied). This - * data, now all continuous, is given to the SEM BIC score and - * methods used to help determine conditional independence for the - * mixed continuous/discrete case from this information. The - * references is as follows:

    - * - * http://proceedings.mlr.press/v104/andrews19a/andrews19a.pdf + *

    This implements the degenerate Gaussian BIC score for FGES. The degenerate Gaussian score + * replaces each discrete variable in the data with a list of 0/1 continuous indicator columns for + * each of the categories but one (the last one implied). This data, now all continuous, is given + * to the SEM BIC score and methods used to help determine conditional independence for the + * mixed continuous/discrete case from this information. The references is as follows:

    + * + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2019, July). Learning high-dimensional + * directed acyclic graphs with mixed data-types. In The 2019 ACM SIGKDD Workshop on + * Causal Discovery (pp. 4-21). PMLR.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java index c251c068d2..55b69e6f1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteBicScore.java @@ -33,7 +33,12 @@ import static org.apache.commons.math3.util.FastMath.log; /** - * Calculates the discrete BIC score. + * Calculates the discrete BIC score. The likelihood for this score is calculated + * as SUM(ln(P(X | Z) P(Z)) across all cells in all conditional probability tables + * for the discrete model. The parameters are counted as SUM(rows * (cols - 1)) + * for all conditional probability tables in the model. Then the BIC score is + * calculated as 2L - ck ln N, where c is a multiplier on the penalty ("penalty + * discount"). * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java index 65b6f091a7..47ace32cc0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java @@ -36,7 +36,10 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Implements the extended BIC (EBIC) score (Chen and Chen).. + *

    Implements the extended BIC (EBIC) score. The reference is here:

    + * + *

    Chen, J., & Chen, Z. (2008). Extended Bayesian information criteria for + * model selection with large model spaces. Biometrika, 95(3), 759-771.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java index dc38e83dce..7e64928ccb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/GicScores.java @@ -37,8 +37,7 @@ * approach as given in Kim et al. (2012).

    * *

    Kim, Y., Kwon, S., & Choi, H. (2012). Consistent model selection criteria on - * high dimensions. The Journal of Machine Learning Research, 13(1), 1037-1057. - * Foster and George.

    + * high dimensions. The Journal of Machine Learning Research, 13(1), 1037-1057.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java index f6edeaa436..9bae442ec4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ImagesScore.java @@ -34,16 +34,16 @@ * used for the IMaGES algorithm. The idea is that one pick and algorithm * that takes (only) a score as input, such as FGES or GRaSP or BOSS, * and then constructs an ImagesScore (which class) with a list of - * datasets as input, feeds this ImagesScore to this algorithm through - * the contructor, and then runs the algorithm to get an estimate - * of the structure.

    - *

    Importantly, only the variables from the first score will be - * returned from the getVariables method, so it is up to the user to - * ensure that all of the scores share the same (object-identical) - * variables.

    + * datasets as input, using same object-identical variables, and feeds this + * Images score to this algorithm through the contructor. One then runs the + * algorithm to get an estimate of the structure.

    * - *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicate independence.

    + *

    Importantly, only the variables from the first score will be returned + * from the getVariables method, so it is up to the user to ensure that all of + * the scores share the same (object-identical) variables.

    + * + *

    As for all scores in Tetrad, higher scores mean more dependence, and + * negative scores indicate independence.

    * * @author josephramsey * @see Fges @@ -60,7 +60,7 @@ public class ImagesScore implements Score { /** * Constructs an IMaGES score using the given list of individual scores. - * These scores will be be averaged to obtain the IMaGES score itself. + * These scores will be averaged to obtain the IMaGES score itself. * * @param scores The list of scores. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java index 45e6c1bdd1..43d1bdee5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java @@ -31,13 +31,16 @@ /** * Gives a method of interpreting a test as a score. Various independence tests - * will calcualte p-values; this simply reports alpha - p as a score, which will - * be higher for greater dependence. + * will calculate p-values; they simply report alpha - p as a score, which will + * be higher for greater dependence. This class wraps such an independence test + * and returns the score reported by that test. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    * * @author josephramsey + * @see IndependenceTest + * @see IndependenceTest#getScore() */ public class IndTestScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java index d9175949f4..ecb38833cf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java @@ -35,7 +35,7 @@ import java.util.*; /** - * Gives ia BIC score for a linear, Gaussian MAG (Mixed Ancestral Graph). It + * Gives a BIC score for a linear, Gaussian MAG (Mixed Ancestral Graph). It * will perform the same as SemBicScore for DAGs. * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java index cef376ff09..d53aae8827 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java @@ -38,7 +38,10 @@ /** - * Calculates Mixed Variables Polynomial likelihood. + *

    Calculates Mixed Variables Polynomial likelihood. The reference is here:

    + * + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of + * mixed variables. International journal of data science and analytics, 6, 3-18.

    * * @author Bryan Andrews */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java index 209ab30df7..fab22cf17e 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java @@ -28,7 +28,10 @@ import java.util.List; /** - * Implements a mixed variable polynomial BIC score for fGES. + *

    Implements a mixed variable polynomial BIC score. The reference is here:

    + * + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of + * mixed variables. International journal of data science and analytics, 6, 3-18.

    * * @author Bryan Andrews */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index d5aecd4469..9d30d4bdc5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -34,7 +34,14 @@ import static org.apache.commons.math3.util.FastMath.*; /** - * Implements Poisson prior score (Bryan). + *

    Implements Poisson prior score, a novel (unpubished) score that replaces the + * penalty term in BIC by the log of the Poisson distribution. The Poisson distribution + * has a lambda parameter, which is made a parameter of this score and acts like + * a structure prior for the score.

    + * + *

    Here is the Wikipedia page for the Poisson distribution, for reference:

    + * + *

    https://en.wikipedia.org/wiki/Poisson_distribution

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java index 7e0a734784..3f49300405 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java @@ -26,12 +26,41 @@ import java.util.List; /** - * Interface for a score suitable for FGES + * Interface for a score. Most methods are given defaults so that such a score will be + * easy to implement in Python usign JPype. + * + * @author josephramsey */ public interface Score { + + /** + * The score of a node given its parents. + * + * @param node The node. + * @param parents The parents. + * @return The score. + */ double localScore(int node, int... parents); + + /** + * The variables of the score. + * + * @return This list. + */ List getVariables(); + + /** + * The sample size of the data. + * + * @return This size. + */ int getSampleSize(); + + /** + * A string representation of the score. + * + * @return This string. + */ String toString(); //==============================DEFAULT METHODS=========================// diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index adbeed6479..109437f1dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -58,8 +58,8 @@ * can be expected to improve, though setting m0 to 0 for all variables * does not give bad results even by itself.

    * - *

    As for all scores in Tetrad, higher scores mean more dependence, and negative - * scores indicate independence.

    + *

    As for all scores in Tetrad, higher scores mean more dependence, + * and negative scores indicate independence.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java index 8077f42a82..fafcf3f250 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceTest.java @@ -34,7 +34,8 @@ /** *

    Gives an interface that can be implemented by classes that do conditional * independence testing. These classes are capable of serving as conditional - * independence "oracles" for constraint-based searches.

    + * independence "oracles" for constraint-based searches. Many methods are given + * defaults so that such a test will be easy to implement in Python using JPype.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrScore.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrScore.java index b4e26315ec..ed1924bb85 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MnlrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrScore.java @@ -19,10 +19,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.score; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.work_in_progress.MnlrLikelihood; import org.apache.commons.math3.util.FastMath; From cbe6b615e4a1f5d816cfb03f0a4e5716f3cc07b2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 16:22:13 -0400 Subject: [PATCH 389/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Fges.java | 7 +++-- .../cmu/tetrad/search/score/ScoredGraph.java | 4 ++- .../cmu/tetrad/search/score/SemBicScore.java | 29 +++++++++++++++++-- .../edu/cmu/tetrad/search/score/ZsbScore.java | 8 +++-- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index a256aec455..c6115b5f77 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -26,10 +26,10 @@ import edu.cmu.tetrad.search.score.GraphScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.ScoredGraph; +import edu.cmu.tetrad.search.utils.Bes; import edu.cmu.tetrad.search.utils.DagScorer; import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; -import edu.cmu.tetrad.search.utils.Bes; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; @@ -53,7 +53,7 @@ * *

    Specificlly, FGES is an implementation of the GES algorithm as specified * in this paper:

    - + * *

    Chickering (2002) "Optimal structure identification with greedy search" * Journal of Machine Learning Research.

    * @@ -180,7 +180,7 @@ public Fges(Score score) { //==========================PUBLIC METHODS==========================// - /** + /** * Greedy equivalence search: Start from the empty graph, add edges till * model is significant. Then start deleting edges till a minimum is * achieved. @@ -237,6 +237,7 @@ public Graph search() { * are unconditionally depedendent, then there is an edge between X and Y in the graph. * This could in principle be false, as for a path cancelation wheter one path is A->B->C->D * and the other path is A->D. + * * @param faithfulnessAssumed True if so. */ public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java index 14715ac0d1..e5153baba3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java @@ -27,7 +27,9 @@ import org.jetbrains.annotations.NotNull; /** - * Stores a graph with a score. + * Stores a graph with a score for the graph. The equals, hashcode, and compare methods + * are overridden so that it will be easy to put these stored graphs into sets and + * lists. * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index 7ad5de7f82..595a3a6752 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -40,13 +40,38 @@ import static org.apache.commons.math3.util.FastMath.log; /** - * Implements the linear, Gaussian BIC score, with a 'penalty discount' multiplier - * on the BIC penalty. + *

    Implements the linear, Gaussian BIC score, with a 'penalty discount' multiplier + * on the BIC penalty. The formula used for the score is BIC = 2L - ck ln n, where + * c is the penalty discount and L is the linear, Gaussian log likelihood--that is, + * the sum of the log likelihoods of the individual records, which are assumed to + * be i.i.d.

    + * + *

    For FGES, Chickering uses the standard linear, Gaussian BIC score, so we will + * for lack of a better reference give his paper:

    + * + *

    Chickering (2002) "Optimal structure identification with greedy search" + * Journal of Machine Learning Research.

    + * + *

    The version of the score due to Nandy et al. is given in this reference:

    + * + *

    Nandy, P., Hauser, A., & Maathuis, M. H. (2018). High-dimensional consistency + * in score-based and hybrid structure learning. The Annals of Statistics, 46(6A), + * 3151-3183.

    + * + *

    This score may be used anywhere though where a linear, Gaussian score is needed. + * Anectodally, the score is fairly robust to non-Gaussianity, though with some + * additional unfaithfulness over and above waht the score would give for Guassian + * data, a detriment that can be overcome to an extent by use a permutation + * algorithm such as SP, GRaSP, or BOSS

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    * * @author josephramsey + * @see edu.cmu.tetrad.search.Fges + * @see edu.cmu.tetrad.search.Sp + * @see edu.cmu.tetrad.search.Grasp + * @see edu.cmu.tetrad.search.Boss */ public class SemBicScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java index 109437f1dd..93265f2e03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ZsbScore.java @@ -37,8 +37,8 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

    Implements the Zhang-Shen bound score. This is an adaptation of - * Theorem 1 in the following:

    + *

    Implements an unpublished score based on a risk bound due to + * Zhang and Shen. It adapts Theorem 1 in the following reference:

    * *

    Zhang, Y., & Shen, X. (2010). Model selection procedure for * high‐dimensional data. Statistical Analysis and Data Mining: The @@ -58,6 +58,10 @@ * can be expected to improve, though setting m0 to 0 for all variables * does not give bad results even by itself.

    * + *

    This score is conservative for large, dense models and faster + * than other available scores in this package. The risk bound is + * easily interpreted.

    + * *

    As for all scores in Tetrad, higher scores mean more dependence, * and negative scores indicate independence.

    * From f8367f2e3dec78aa839136bb4c7c7e25f4e32786 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 17:31:41 -0400 Subject: [PATCH 390/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Ccd.java | 2 + .../main/java/edu/cmu/tetrad/search/Cfci.java | 6 +- .../main/java/edu/cmu/tetrad/search/Cpc.java | 19 ++- .../java/edu/cmu/tetrad/search/Cstar.java | 7 +- .../edu/cmu/tetrad/search/FactorAnalysis.java | 9 ++ .../main/java/edu/cmu/tetrad/search/Fasd.java | 26 +++- .../main/java/edu/cmu/tetrad/search/Fask.java | 3 +- .../java/edu/cmu/tetrad/search/FastIca.java | 8 +- .../main/java/edu/cmu/tetrad/search/Fges.java | 10 +- .../java/edu/cmu/tetrad/search/FgesMb.java | 9 +- .../edu/cmu/tetrad/search/GrowShrink.java | 1 + .../main/java/edu/cmu/tetrad/search/IFas.java | 65 +++++++++- .../edu/cmu/tetrad/search/IGraphSearch.java | 6 + .../main/java/edu/cmu/tetrad/search/Ida.java | 1 + .../main/java/edu/cmu/tetrad/search/Pc.java | 92 ++++++++++---- .../java/edu/cmu/tetrad/search/PcMax.java | 112 +++++++++++++----- .../main/java/edu/cmu/tetrad/search/PcMb.java | 58 ++++++--- .../main/java/edu/cmu/tetrad/search/Pcd.java | 4 +- .../main/java/edu/cmu/tetrad/search/Rfci.java | 100 ++++++++++------ .../java/edu/cmu/tetrad/search/SpFci.java | 27 ++++- .../java/edu/cmu/tetrad/search/SvarFas.java | 10 +- .../java/edu/cmu/tetrad/search/SvarFci.java | 110 +++++++++++------ .../java/edu/cmu/tetrad/search/SvarFges.java | 1 - .../search/work_in_progress/FasFdr.java | 8 -- 24 files changed, 505 insertions(+), 189 deletions(-) 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 6b7ab5535e..c15fc13c42 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 @@ -34,9 +34,11 @@ /** *

    Implemented the Cyclic Causal Discovery (CCD) algorithm by Thomas Richardson. * A reference for this is here:

    + * *

    Mooij, J. M., & Claassen, T. (2020, August). Constraint-based causal discovery * using partial ancestral graphs in the presence of cycles. In Conference on Uncertainty * in Artificial Intelligence (pp. 1159-1168). PMLR.

    + * *

    See also Chapter 7 of Glymour and Cooper, eds., Computation, Causation, and Discovery

    *

    The graph takes continuous data from a cyclic model as input and returns a cyclic * PAG graphs, with various types of underlining, that represents a Markov equivalence of diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index c2133cc85a..04d2d2ab15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -271,14 +271,18 @@ public void setKnowledge(Knowledge knowledge) { } /** - * @return true if Zhang's complete rule set should be used, false if only R1-T1 (the rule set of the original FCI) + * Returns true if Zhang's complete rule set should be used, false if only R1-T1 (the rule set of the original FCI) * should be used. False by default. + * + * @return True for the complete ruleset. */ public boolean isCompleteRuleSetUsed() { return this.completeRuleSetUsed; } /** + * Sets whether the complete ruleset should be used. + * * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-T1 (the rule * set of the original FCI) should be used. False by default. */ 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 899631fe5a..8e2e65c718 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 @@ -37,8 +37,11 @@ import java.util.Set; /** - *

    Implements a convervative version of PC, in which the Markov condition is assumed but faithfulness is tested - * locally.

    + *

    Implements a convervative version of PC, in which the Markov condition is assumed + * but faithfulness is tested locally. The reference is here:

    + * + *

    Ramsey, J., Zhang, J., & Spirtes, P. L. (2012). Adjacency-faithfulness and + * conservative causal inference. arXiv preprint arXiv:1206.6843.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    @@ -116,8 +119,10 @@ public final class Cpc implements IGraphSearch { //=============================CONSTRUCTORS==========================// /** - * Constructs a CPC algorithm that uses the given independence test as oracle. This does not make a copy of the - * independence test, for fear of duplicating the data set! + * Constructs a CPC algorithm that uses the given independence test as oracle. This does + * not make a copy of the independence test, for fear of duplicating the data set! + * + * @param independenceTest The test to user for oracle conditional independence information. */ public Cpc(IndependenceTest independenceTest) { if (independenceTest == null) { @@ -130,7 +135,9 @@ public Cpc(IndependenceTest independenceTest) { //==============================PUBLIC METHODS========================// /** - * @return true just in case edges will not be added if they would create cycles. + * Returns true just in case edges will not be added if they would create cycles. + * + * @return True if so. */ public boolean isAggressivelyPreventCycles() { return this.aggressivelyPreventCycles; @@ -147,7 +154,7 @@ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { /** * Sets the maximum number of variables conditioned on in any conditional independence test. If set to -1, the value - * of 1000 will be used. May not be set to Integer.MAX_VALUE, due to a Java bug on multi-core systems. + * of 1000 will be used. May not be set to Integer.MAX_VALUE, due to a Java bug on multicore systems. * * @param depth This maximum. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index 95c4b75b81..e0a26b1c8b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -20,13 +20,16 @@ import java.util.concurrent.*; /** - *

    Iplements the CStaR algorithm (Steckoven et al., 2012), which finds a CPDAG of thd data and then + *

    Implements the CStaR algorithm (Steckoven et al., 2012), which finds a CPDAG of thd data and then * tries all orientations of the undirected edges about a variable in the CPDAG to estimate a - * minimum bound on the effect for a given edge. Soem references include the following:

    + * minimum bound on the effect for a given edge. Some references include the following:

    + * *

    Stekhoven, D. J., Moraes, I., Sveinbjörnsson, G., Hennig, L., Maathuis, M. H., and Bühlmann, P. (2012). * Causal stability ranking. Bioinformatics, 28(21), 2819-2823.

    + * *

    Meinshausen, N., and Bühlmann, P. (2010). Stability selection. Journal of the Royal Statistical Society: * Series B (Statistical Methodology), 72(4), 417-473.

    + * *

    Colombo, D., and Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. * The Journal of Machine Learning Research, 15(1), 3741-3782.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index 36fffa7a6c..e3c8051a2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -37,6 +37,7 @@ *

    Horst, P. (1965). Factor analysis of data matrices. Holt, Rinehart and Winston. * This work has good specifications and explanations of factor analysis algorithm and * methods of communality estimation.

    + * *

    Rummel, R. J. (1988). Applied factor analysis. Northwestern University Press. This * book is a good companion to the book listed above. While it doesn't specify any actual * algorithm, it has a great introduction to the subject that gives the reader a good @@ -112,6 +113,8 @@ public FactorAnalysis(DataSet dataSet) { * END PSEUDO-CODE *

    * At the end of the method, the list of column vectors is actually assembled into a TetradMatrix. + * + * @return The matrix of residuals. */ public Matrix successiveResidual() { this.factorLoadingVectors = new LinkedList<>(); @@ -147,6 +150,12 @@ public Matrix successiveResidual() { return result; } + /** + * Returns the matrix result for the varimax algorithm. + * + * @param factorLoadingMatrix The matrix of factor loadings. + * @return The result matrix. + */ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { if (factorLoadingMatrix.columns() == 1) return factorLoadingMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java index 3d6a9777d6..c9c9184b9e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fasd.java @@ -141,7 +141,7 @@ public Graph search(List nodes) { * more edges can be removed from the graph. The edges which remain in the graph after this procedure are the * adjacencies in the data. * - * @return a SepSet, which indicates which variables are independent conditional on which other variables + * @return a graph which indicates which variables are independent conditional on which other variables */ public Graph search() { this.logger.log("info", "Starting Fast Adjacency Search."); @@ -260,22 +260,42 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - + /** + * Returns the elapsed time. + * + * @return This time. + */ @Override public long getElapsedTime() { return 0; } + /** + * Returns the nodes beign searched over. + * + * @return This list. + */ @Override public List getNodes() { return this.test.getVariables(); } + /** + * Returns an empty list. Not used. + * + * @param node Whichever node. + * @return An empty list. + */ @Override public List getAmbiguousTriples(Node node) { - return null; + return new ArrayList<>(); } + /** + * Sets the output to send prints to. + * + * @param out This print stream. + */ @Override public void setOut(PrintStream out) { this.out = out; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 6f4fc9a1a0..1489f5d65c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -47,7 +47,8 @@ /** *

    Implements the FASK (Fast Adjacency Skewness) algorithm, which makes decisions for adjacency * and orientation using a combination of conditional independence testing, judgments of nonlinear - * adjacency, and pairwsie orientation due to non-Gaussianity. The reference is this: + * adjacency, and pairwsie orientation due to non-Gaussianity. The reference is this:

    + * *

    Sanchez-Romero, R., Ramsey, J. D., Zhang, K., Glymour, M. R., Huang, B., and Glymour, C. * (2019). Estimating feedforward and feedback effective connections from fMRI time series: Assessments * of statistical methods. Network Neuroscience, 3(2), 274-30

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index 943c8dc8a5..63ee54746c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -35,7 +35,11 @@ * into Java for use in Tetrad. This can be used in various algorithms that * assume linearity and non-gaussianity, as for example LiNGAM and LiNG-D. * There is one difference from the R, in that in R FastICA can operate over - * complex numbers, whereeas here it is restricted to real numbers.

    + * complex numbers, whereeas here it is restricted to real numbers. A + * useful reference is this:

    + * + *

    Oja, E., & Hyvarinen, A. (2000). Independent component analysis: + * algorithms and applications. Neural networks, 13(4-5), 411-430.

    * *

    The documention of the R version is as follows, all of which is true of this * translation (so far as I know) except for its being in R and its allowing @@ -44,7 +48,7 @@ * Description: *

    * This is an R and C code implementation of the FastICA algorithm of Aapo - * Hyvarinen et al. (URL: ...) to perform Independent + * Hyvarinen et al. (URL: http://www.cis.hut.fi/aapo/) to perform Independent * Component Analysis (ICA) and Projection Pursuit. *

    * Usage: diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index c6115b5f77..2a7c48e00b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -49,9 +49,15 @@ *

    Imlements the Greedy Equivalence Search (GES) algorithm, originally due to * Chris Meek but developed significantly by Max Chickering, with some * optimizations that allow it to scale accurately to thousands of variables - * for the sparse case.

    + * for the sparse case. The reference is this:

    * - *

    Specificlly, FGES is an implementation of the GES algorithm as specified + *

    Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). + * A million variables and more: the fast greedy equivalence search algorithm + * for learning high-dimensional graphical causal models, with an application + * to functional magnetic resonance images. International journal of data science + * and analytics, 3, 121-129.

    + * + *

    Specifically, FGES is an implementation of the GES algorithm as specified * in this paper:

    * *

    Chickering (2002) "Optimal structure identification with greedy search" diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index 77f0633dd8..d9829a729e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -42,7 +42,14 @@ *

    Restricts the FGES algorithm (see) to the operations needed just * to find the graph over the Markov blanket of a variable X (or a graph * over the Markov blankets of a list of variables X1,..,Xn), together - * with the target X (or, respectively, the targets X1,...,Xn).

    + * with the target X (or, respectively, the targets X1,...,Xn). The + * reference is this:

    + * + *

    Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). + * A million variables and more: the fast greedy equivalence search algorithm + * for learning high-dimensional graphical causal models, with an application + * to functional magnetic resonance images. International journal of data science + * and analytics, 3, 121-129.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index cf89797f8b..099962da3e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -30,6 +30,7 @@ /** *

    Implements the Grow-Shrink algorithm of Margaritis and Thrun, a simple yet correct * and useful Markov blanket search.

    + * *

    Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. * Advances in neural information processing systems, 12.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java index 88148c1ff8..40dd541604 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IFas.java @@ -22,7 +22,6 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.utils.SepsetMap; @@ -35,17 +34,75 @@ * * @author josephramsey */ -public interface IFas { +public interface IFas extends IGraphSearch { + + /** + * Sets the knoweledge for the search. + * + * @param knowledge This knowledge. + */ void setKnowledge(Knowledge knowledge); + + /** + * Returns the sepset map discovered during search--that is, the map from + * node pairs to the sepsets used in the search to removed the corresponding + * edges from the complete graph. + * + * @return This map. + */ SepsetMap getSepsets(); + + /** + * Sets the depth of the search--that is, the maximum number of variables + * conditioned on in the search. + * + * @param depth This maximum. + */ void setDepth(int depth); - Graph search(); - Graph search(List nodes); + + /** + * Returns the elapsed time of the search. + * + * @return This time. + */ long getElapsedTime(); + + /** + * Returns the number of independence tests done in the search. + * + * @return This number. + */ int getNumIndependenceTests(); + + /** + * Returns the nodes searched over. + * + * @return This list. + */ List getNodes(); + + /** + * Returns the list of ambiguous triples found for a given node. + * + * @param node The node + * @return The list. + * @see Cpc + * @see Cfci + */ List getAmbiguousTriples(Node node); + + /** + * Sets whether verbose output should be printed. + * + * @param verbose True if so. + */ void setVerbose(boolean verbose); + + /** + * sets the print stream to send text to. + * + * @param out This print stream. + */ void setOut(PrintStream out); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java index 2e61f1f1f9..308fb79003 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IGraphSearch.java @@ -27,6 +27,12 @@ * Gives an interface for a search method that searches and returns a graph. */ public interface IGraphSearch { + + /** + * Runs the search and returns a graph. + * + * @return The discovered graph. + */ Graph search(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index ce3651cb4e..785de18481 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -154,6 +154,7 @@ public double trueEffect(Node x, Node y, Graph trueDag) { /** * Returns the distance between the effects and the true effect. + * * @return This difference. */ public double distance(LinkedList effects, double trueEffect) { 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 3c134342cd..ba6f3fd8d6 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 @@ -139,13 +139,17 @@ public Pc(IndependenceTest independenceTest) { //==============================PUBLIC METHODS========================// /** - * @return true iff edges will not be added if they would create cycles. + * Returns true iff edges will not be added if they would create cycles. + * + * @return True if so. */ public boolean isAggressivelyPreventCycles() { return this.aggressivelyPreventCycles; } /** + * Sets whether cycles should be aggressively checked. + * * @param aggressivelyPreventCycles Set to true just in case edges will not be addeds if they would create cycles. */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { @@ -153,14 +157,18 @@ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { } /** - * @return the independence test being used in the search. + * Returns the independence test being used in the search. + * + * @return this test. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } /** - * @return the knowledge specification used in the search. Non-null. + * Returns the knowledge specification used in the search. Non-null. + * + * @return This knowledge. */ public Knowledge getKnowledge() { return this.knowledge; @@ -168,6 +176,8 @@ public Knowledge getKnowledge() { /** * Sets the knowledge specification to be used in the search. May not be null. + * + * @param knowledge The knowledge. */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { @@ -178,15 +188,20 @@ public void setKnowledge(Knowledge knowledge) { } /** - * @return the sepset map from the most recent search. Non-null after the first call to search(). + * Returns the sepset map from the most recent search. Non-null after the first call + * to search(). + * + * @return This map. */ public SepsetMap getSepsets() { return this.sepsets; } /** - * @return the current depth of search--that is, the maximum number of conditioning nodes for any conditional - * independence checked. + * Returns the current depth of search--that is, the maximum number of conditioning nodes + * for any conditional independence checked. + * + * @return This depth. */ public int getDepth() { return this.depth; @@ -213,11 +228,19 @@ public void setDepth(int depth) { } /** - * Runs PC starting with a complete graph over all nodes of the given conditional independence test, using the given - * independence test and knowledge and returns the resultant graph. The returned graph will be a CPDAG if the - * independence information is consistent with the hypothesis that there are no latent common causes. It may, - * however, contain cycles or bidirected edges if this assumption is not born out, either due to the actual presence - * of latent common causes, or due to statistical errors in conditional independence judgments. + * Runs PC starting with a complete graph over all nodes of the given conditional + * independence test, using the given independence test and knowledge and returns the + * resultant graph. The returned graph will be a CPDAG if the independence information is + * consistent with the hypothesis that there are no latent common causes. It may, however, + * contain cycles or bidirected edges if this assumption is not born out, either due to + * the actual presence of latent common causes, or due to statistical errors in conditional + * independence judgments. + * + * @return The found CPDAG. In some cases there may be some errant bidirected edges or + * cycles, depending on the settings and whether the faithfulness assumption holds. If + * the faithfulness assumption holds, bidirected edges will indicate the existence of + * latent variables, so a latent variable search like FCI should be run. + * @see Fci */ @Override public Graph search() { @@ -225,13 +248,18 @@ public Graph search() { } /** - * Runs PC starting with a commplete graph over the given list of nodes, using the given independence test and - * knowledge and returns the resultant graph. The returned graph will be a CPDAG if the independence information - * is consistent with the hypothesis that there are no latent common causes. It may, however, contain cycles or - * bidirected edges if this assumption is not born out, either due to the actual presence of latent common causes, - * or due to statistical errors in conditional independence judgments. + * Runs PC starting with a commplete graph over the given list of nodes, using the given + * independence test and knowledge and returns the resultant graph. The returned graph + * will be a CPDAG if the independence information is consistent with the hypothesis that + * there are no latent common causes. It may, however, contain cycles or bidirected edges + * if this assumption is not born out, either due to the actual presence of latent common + * causes, or due to statistical errors in conditional independence judgments. *

    - * All of the given nodes must be in the domatein of the given conditional independence test. + * All the given nodes must be in the domatein of the given conditional independence test. + * + * @param nodes The sublist of nodes to search over. + * @return The search graph. + * @see #search() */ public Graph search(List nodes) { nodes = new ArrayList<>(nodes); @@ -241,6 +269,16 @@ public Graph search(List nodes) { return search(fas, nodes); } + /** + * Runs the search using a particular implementation of the fast adjacency search + * (FAS), over the given sublist of nodes. + * + * @param fas The fast adjacency search to use. + * @param nodes The sublist of nodes. + * @return The result graph + * @see #search() + * @see IFas + */ public Graph search(IFas fas, List nodes) { this.logger.log("info", "Starting PC algorithm"); this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); @@ -294,21 +332,27 @@ public Graph search(IFas fas, List nodes) { } /** - * @return the elapsed time of the search, in milliseconds. + * Returns the elapsed time of the search, in milliseconds. + * + * @return this time. */ public long getElapsedTime() { return this.elapsedTime; } /** - * @return The edges of the searched graph. + * Returns The edges of the searched graph. + * + * @return This set. */ public Set getAdjacencies() { return new HashSet<>(this.graph.getEdges()); } /** - * @return the non-adjacencies of the searched graph. + * Returns the non-adjacencies of the searched graph. + * + * @return This set. */ public Set getNonadjacencies() { Graph complete = GraphUtils.completeGraph(this.graph); @@ -319,14 +363,18 @@ public Set getNonadjacencies() { } /** - * @return the number of independence tests performed in the search. + * Returns the number of independence tests performed in the search. + * + * @return This number. */ public int getNumIndependenceTests() { return this.numIndependenceTests; } /** - * @return the nodes of the search graph. + * Returns the nodes of the search graph. + * + * @return This list. */ public List getNodes() { return this.graph.getNodes(); 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 0217e733d1..32971221b4 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 @@ -38,7 +38,11 @@ import java.util.Set; /** - * Modifies the PC algorithm to use the Max P rule for orienting ushielded colliders. + *

    Modifies the PC algorithm to use the Max P rule for orienting ushielded + * colliders. The reference is this:

    + * + *

    Ramsey, J. (2016). Improving accuracy and scalability of the pc algorithm + * by maximizing p-value. arXiv preprint arXiv:1610.00378.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    @@ -99,9 +103,6 @@ public class PcMax implements IGraphSearch { private boolean verbose; private boolean stable; - // private boolean concurrent; - private boolean useMaxP = false; - private int maxPPathLength = -1; private PcCommon.ConflictRule conflictRule = PcCommon.ConflictRule.OVERWRITE; //=============================CONSTRUCTORS==========================// @@ -123,28 +124,37 @@ public PcMax(IndependenceTest independenceTest) { //==============================PUBLIC METHODS========================// /** - * @return true iff edges will not be added if they would create cycles. + * Returns true iff edges will not be added if they would create cycles. + * + * @return True if so. */ public boolean isAggressivelyPreventCycles() { return this.aggressivelyPreventCycles; } /** - * @param aggressivelyPreventCycles Set to true just in case edges will not be added if they would create cycles. + * Sets whether cycles should be aggressively checked. + * + * @param aggressivelyPreventCycles Set to true just in case edges will not be added + * if they would create cycles. */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { this.aggressivelyPreventCycles = aggressivelyPreventCycles; } /** - * @return the independence test being used in the search. + * Returns the independence test being used in the search. + * + * @return This test. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } /** - * @return the knowledge specification used in the search. Non-null. + * Returns the knowledge specification used in the search. Non-null. + * + * @return this knowledge. */ public Knowledge getKnowledge() { return this.knowledge; @@ -152,6 +162,8 @@ public Knowledge getKnowledge() { /** * Sets the knowledge specification to be used in the search. May not be null. + * + * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { @@ -162,15 +174,20 @@ public void setKnowledge(Knowledge knowledge) { } /** - * @return the sepset map from the most recent search. Non-null after the first call to search(). + * Returns the sepset map from the most recent search. Non-null after the first call to + * search(). + * + * @return This map. */ public SepsetMap getSepsets() { return this.sepsets; } /** - * @return the current depth of search--that is, the maximum number of conditioning nodes for any conditional - * independence checked. + * Returns the current depth of search--that is, the maximum number of conditioning nodes + * for any conditional independence checked. + * + * @return This depth. */ public int getDepth() { return this.depth; @@ -197,11 +214,14 @@ public void setDepth(int depth) { } /** - * Runs PC starting with a complete graph over all nodes of the given conditional independence test, using the given - * independence test and knowledge and returns the resultant graph. The returned graph will be a CPDAG if the - * independence information is consistent with the hypothesis that there are no latent common causes. It may, - * however, contain cycles or bidirected edges if this assumption is not born out, either due to the actual presence - * of latent common causes, or due to statistical errors in conditional independence judgments. + * Runs PC starting with a complete graph over all nodes of the given conditional independence + * test, using the given independence test and knowledge and returns the resultant graph. The + * returned graph will be a CPDAG if the independence information is consistent with the + * hypothesis that there are no latent common causes. It may however, contain cycles or bidirected + * edges if this assumption is not born out, either due to the actual presence of latent common + * causes, or due to statistical errors in conditional independence judgments. + * + * @return The CPDAG found. */ @Override public Graph search() { @@ -209,13 +229,17 @@ public Graph search() { } /** - * Runs PC starting with a complete graph over the given list of nodes, using the given independence test and - * knowledge and returns the resultant graph. The returned graph will be a CPDAG if the independence information - * is consistent with the hypothesis that there are no latent common causes. It may, however, contain cycles or - * bidirected edges if this assumption is not born out, either due to the actual presence of latent common causes, - * or due to statistical errors in conditional independence judgments. + * Runs PC starting with a complete graph over the given list of nodes, using the given + * independence test and knowledge and returns the resultant graph. The returned graph will + * be a CPDAG if the independence information is consistent with the hypothesis that there are + * no latent common causes. It may, however, contain cycles or bidirected edges if this + * assumption is not born out, either due to the actual presence of latent common causes, or + * due to statistical errors in conditional independence judgments. *

    * All the given nodes must be in the domain of the given conditional independence test. + * + * @param nodes the sublist of nodes to search over. + * @return The CPDAG found. */ public Graph search(List nodes) { nodes = new ArrayList<>(nodes); @@ -225,6 +249,16 @@ public Graph search(List nodes) { return search(fas, nodes); } + /** + * Runs the search using a particular implementation of the fast adjacency search + * (FAS), over the given sublist of nodes. + * + * @param fas The fast adjacency search to use. + * @param nodes The sublist of nodes. + * @return The result graph + * @see #search() + * @see IFas + */ public Graph search(IFas fas, List nodes) { this.logger.log("info", "Starting PC algorithm"); this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); @@ -254,8 +288,8 @@ public Graph search(IFas fas, List nodes) { search.setColliderDiscovery(PcCommon.ColliderDiscovery.MAX_P); search.setConflictRule(conflictRule); - search.setUseHeuristic(useMaxP); - search.setMaxPathLength(maxPPathLength); + search.setUseHeuristic(true); + search.setMaxPathLength(-1); search.setVerbose(verbose); this.graph = search.search(); @@ -278,40 +312,54 @@ public Graph search(IFas fas, List nodes) { } /** - * @return the elapsed time of the search, in milliseconds. + * Returns the elapsed time of the search, in milliseconds. + * + * @return This time. */ public long getElapsedTime() { return this.elapsedTime; } + /** + * Returns the adjacencies in the graph. + * @return This set. + */ public Set getAdjacencies() { return new HashSet<>(this.graph.getEdges()); } + /** + * Returns the number of independence test performed in the search. + * @return This numbger. + */ public int getNumIndependenceTests() { return this.numIndependenceTests; } + /** + * Returns the nodes in graph. + * @return This list. + */ public List getNodes() { return this.graph.getNodes(); } + /** + * Sets whether verbose output should be printed. + * @param verbose True is fo. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** + * Sets whether the stable option should be used. + * @param stable True if so. + */ public void setStable(boolean stable) { this.stable = stable; } - public void setUseMaxP(boolean useMaxP) { - this.useMaxP = useMaxP; - } - - public void setMaxPPathLength(int maxPPathLength) { - this.maxPPathLength = maxPPathLength; - } - public void setConflictRule(PcCommon.ConflictRule conflictRule) { this.conflictRule = conflictRule; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index fe2c143a0b..cca252d49b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -33,9 +33,13 @@ import java.util.*; /** - *

    Searches for a CPDAG representing all the Markov blankets for a given target T consistent with the given - * independence information. This CPDAG may be used to generate the actual list of DAG's that might be Markov - * blankets. Note that this code has been converted to be consistent with the CPC algorithm.

    + *

    Searches for a CPDAG representing all the Markov blankets for a given target T consistent + * with the given independence information. This CPDAG may be used to generate the actual list + * of DAG's that might be Markov blankets. Note that this code has been converted to be consistent + * with the CPC algorithm. The reference is here:

    + * + *

    Bai, X., Padman, R., Ramsey, J., & Spirtes, P. (2008). Tabu search-enhanced graphical models + * for classification in high dimensions. INFORMS Journal on Computing, 20(3), 423-437.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    @@ -406,42 +410,56 @@ public Graph search() { } /** - * @return the set of triples identified as ambiguous by the CPC algorithm during the most recent search. + * Returns the set of triples identified as ambiguous by the CPC algorithm during the + * most recent search. + * + * @return This set. */ public Set getAmbiguousTriples() { return new HashSet<>(this.ambiguousTriples); } /** - * @return the number of independence tests performed during the most recent search. + * Returns the number of independence tests performed during the most recent search. + * + * @return This number. */ public int getNumIndependenceTests() { return this.numIndependenceTests; } /** - * @return the target of the most recent search. + * Returns the targets of the most recent search. + * + * @return This list. */ public List getTargets() { return this.targets; } /** - * @return the elapsed time of the most recent search. + * Returns the elapsed time of the most recent search. + * + * @return This time. */ public long getElapsedTime() { return this.elapsedTime; } /** - * @return "PC-MB." + * Returns "PC-MB." + * + * @return This string. */ public String getAlgorithmName() { return "PC-MB"; } /** - * @return Ibid. + * Returns the depth of the search--that is, the maximum number of variables + * conditioned on in any conditional independence test. + * + * @return This depth. */ public int getDepth() { return this.depth; @@ -450,7 +468,7 @@ public int getDepth() { /** * Sets the maximum number of conditioning variables for any conditional independence test. * - * @param depth Ibid. + * @param depth This depth. */ public void setDepth(int depth) { // If it's -1 to set it to some unreasonably high number like 1000 @@ -462,14 +480,19 @@ public void setDepth(int depth) { } /** - * @return Ibid. + * Returns the result graph. + * + * @return This graph. */ public Graph resultGraph() { return this.resultGraph; } /** - * @return just the Markov blanket (not the Markov blanket DAG). + * Returns the Markov blanket variables (not the Markov blanket DAG). + * + * @param target The target variable. + * @return This list. */ public List findMb(Node target) { Graph graph = search(Collections.singletonList(target)); @@ -479,14 +502,18 @@ public List findMb(Node target) { } /** - * @return The test used in search. + * Returns the test used in search. + * + * @return This test. */ public IndependenceTest getTest() { return this.test; } /** - * @return The knowledge used in search. + * Returns The knowledge used in search. + * + * @return This knowledge. */ public Knowledge getKnowledge() { return this.knowledge; @@ -495,7 +522,8 @@ public Knowledge getKnowledge() { /** * Sets knowledge, to which the algorithm is in fact sensitive. * - * @param knowledge See the Knowledge class. + * @param knowledge This knowledge. + * @see Knowledge */ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index 2a0ccce1e4..3fd0f41faf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -37,7 +37,9 @@ import java.util.Set; /** - * Modifies the PC algorithm to handle the deterministic case. + * Modifies the PC algorithm to handle the deterministic case. Edges removals + * or orientations based on conditional independence test involving deterministic + * relationships are not done. * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index 34a53b1d60..be6d73731c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -153,12 +153,20 @@ public Rfci(IndependenceTest independenceTest, List searchVars) { //========================PUBLIC METHODS==========================// /** - * @return + * Runs the search and returns the RFCI PAG. + * + * @return This PAG. */ public Graph search() { return search(getIndependenceTest().getVariables()); } + /** + * Searches of a specific sublist of nodes. + * + * @param nodes The sublist. + * @return The RFCI PAG + */ public Graph search(List nodes) { nodes = new ArrayList<>(nodes); @@ -267,6 +275,58 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } + + /** + * Returns the maximum length of any discriminating path, or -1 of unlimited. + * + * @return This number. + */ + public int getMaxPathLength() { + return this.maxPathLength == Integer.MAX_VALUE ? -1 : this.maxPathLength; + } + + /** + * Sets the maximum path length for discriminating paths. + * + * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. + */ + public void setMaxPathLength(int maxPathLength) { + if (maxPathLength < -1) { + throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); + } + + this.maxPathLength = maxPathLength == -1 + ? Integer.MAX_VALUE : maxPathLength; + } + + /** + * Returns whether verbose output should be printed. + * + * @return True if so. + */ + public boolean isVerbose() { + return this.verbose; + } + + /** + * Sets whether verbose output is printed. + * + * @param verbose True if so. + */ + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + /** + * Returns the independence test. + * + * @return This test. + */ + public IndependenceTest getIndependenceTest() { + return this.independenceTest; + } + + //===========================PRIVATE METHODS=========================// private List getSepset(Node i, Node k) { @@ -492,44 +552,6 @@ private void setMinSepSet(List sepSet, Node x, Node y) { } } } - - - /** - * @return the maximum length of any discriminating path, or -1 of unlimited. - */ - public int getMaxPathLength() { - return this.maxPathLength == Integer.MAX_VALUE ? -1 : this.maxPathLength; - } - - /** - * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. - */ - public void setMaxPathLength(int maxPathLength) { - if (maxPathLength < -1) { - throw new IllegalArgumentException("Max path length must be -1 (unlimited) or >= 0: " + maxPathLength); - } - - this.maxPathLength = maxPathLength == -1 - ? Integer.MAX_VALUE : maxPathLength; - } - - /** - * True iff verbose output should be printed. - */ - public boolean isVerbose() { - return this.verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - /** - * The independence test. - */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 1e6109d279..32252b5ee4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -125,7 +125,9 @@ public SpFci(IndependenceTest test, Score score) { //========================PUBLIC METHODS==========================// /** - * @return The discovered PAG. + * Runs the search and returns the discovered PAG. + * + * @return This PAG. */ public Graph search() { List nodes = getIndependenceTest().getVariables(); @@ -196,17 +198,28 @@ public int getMaxDegree() { return this.maxDegree; } - + /** + * Returns the knowledge. + * + * @return This knowedge. + */ public Knowledge getKnowledge() { return this.knowledge; } + /** + * Sets the knoweldge used in the search. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } /** - * @return true if Zhang's complete rule set should be used, false if only + * Returns whether the complete rule set is used. + * + * @return True if Zhang's complete rule set should be used, Talse if only * R1-R4 (the rule set of the original FCI) should be used. False by * default. */ @@ -215,6 +228,8 @@ public boolean isCompleteRuleSetUsed() { } /** + * Sets whether Zhang's complete ruleset is used. + * * @param completeRuleSetUsed set to true if Zhang's complete rule set * should be used, false if only R1-R4 (the rule set of the original FCI) * should be used. False by default. @@ -224,14 +239,18 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { } /** - * @return the maximum length of any discriminating path, or -1 of + * Returns the maximum length of any discriminating path, or -1 of * unlimited. + * + * @return This length. */ public int getMaxPathLength() { return this.maxPathLength; } /** + * Sets the max path length for discriminating paths. + * * @param maxPathLength the maximum length of any discriminating path, or -1 * if unlimited. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java index 539bfd15da..c7a54721a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java @@ -36,7 +36,7 @@ import java.util.*; /** - *

    Adapts Fas.java for the SvarFCI algorithm. The main difference is that if an edge is + *

    Adapts FAS for the SvarFCI algorithm. The main difference is that if an edge is * removed, it will also remove all homologous edges to preserve the time-repeating s * tructure assumed by SvarFCI. Based on (but not identical to) code by Entner and Hoyer * for their 2010 paper. Modified by dmalinsky 4/21/2016.

    @@ -226,14 +226,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * @throws UnsupportedOperationException This method is not used. - */ - @Override - public Graph search(List nodes) { - throw new UnsupportedOperationException("This method is not used."); - } - /** * @throws UnsupportedOperationException This method is not used. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index b52231515e..84ef6ff68a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -97,7 +97,6 @@ public final class SvarFci implements IGraphSearch { * True iff verbose output should be printed. */ private boolean verbose; - private double penaltyDiscount = 2; //============================CONSTRUCTORS============================// @@ -115,10 +114,22 @@ public SvarFci(IndependenceTest independenceTest) { //========================PUBLIC METHODS==========================// + /** + * Returns the depth of search--i.e., the maximum number of conditioning variables + * for tests. + * + * @return This maximum. + */ public int getDepth() { return this.depth; } + /** + * Sets the depth of search. + * + * @param depth This depth + * @see #getDepth() + */ public void setDepth(int depth) { if (depth < -1) { throw new IllegalArgumentException( @@ -128,13 +139,24 @@ public void setDepth(int depth) { this.depth = depth; } + /** + * Runs the search and returns the PAG. + * + * @return This PAG. + */ public Graph search() { getIndependenceTest().getVariables(); return search(new SvarFas(getIndependenceTest())); // return search(new Fas(getIndependenceTest())); } - + /** + * Runs the search using a particular implementation of FAS. + * + * @param fas The FAS to use. + * @return The PAG. + * @see IFas + */ public Graph search(IFas fas) { this.logger.log("info", "Starting FCI algorithm."); this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); @@ -150,33 +172,31 @@ public Graph search(IFas fas) { SepsetProducer sp = new SepsetsPossibleDsep(this.graph, this.independenceTest, this.knowledge, this.depth, this.maxPathLength); sp.setVerbose(this.verbose); - if (isPossibleDsepSearchDone()) { - SvarFciOrient svarFciOrient = new SvarFciOrient(new SepsetsSet(this.sepsets, this.independenceTest), this.independenceTest); - svarFciOrient.setKnowledge(this.knowledge); - svarFciOrient.ruleR0(this.graph); + SvarFciOrient svarFciOrient = new SvarFciOrient(new SepsetsSet(this.sepsets, this.independenceTest), this.independenceTest); + svarFciOrient.setKnowledge(this.knowledge); + svarFciOrient.ruleR0(this.graph); - for (Edge edge : new ArrayList<>(this.graph.getEdges())) { - Node x = edge.getNode1(); - Node y = edge.getNode2(); + for (Edge edge : new ArrayList<>(this.graph.getEdges())) { + Node x = edge.getNode1(); + Node y = edge.getNode2(); - List sepset = sp.getSepset(x, y); + List sepset = sp.getSepset(x, y); - if (sepset != null) { - this.graph.removeEdge(x, y); - this.sepsets.set(x, y, sepset); + if (sepset != null) { + this.graph.removeEdge(x, y); + this.sepsets.set(x, y, sepset); - System.out.println("Possible DSEP Removed " + x + "--- " + y + " sepset = " + sepset); + System.out.println("Possible DSEP Removed " + x + "--- " + y + " sepset = " + sepset); - // This is another added component to enforce repeating structure, specifically for possibleDsep - removeSimilarPairs(getIndependenceTest(), x, y, sepset); // added 4.27.2016 - } + // This is another added component to enforce repeating structure, specifically for possibleDsep + removeSimilarPairs(getIndependenceTest(), x, y, sepset); // added 4.27.2016 } - - // Reorient all edges as o-o. - this.graph.reorientAllWith(Endpoint.CIRCLE); } + // Reorient all edges as o-o. + this.graph.reorientAllWith(Endpoint.CIRCLE); + // Step CI C (Zhang's step F3.) long time5 = MillisecondTimes.timeMillis(); //fciOrientbk(getKnowledge(), graph, independenceTest.getVariable()); - Robert Tillman 2008 @@ -195,14 +215,29 @@ public Graph search(IFas fas) { return this.graph; } + /** + * Returns the map from node pairs to sepsets. + * + * @return This map. + */ public SepsetMap getSepsets() { return this.sepsets; } + /** + * Returns the knowledge for the search. + * + * @return This knowledge. + */ public Knowledge getKnowledge() { return this.knowledge; } + /** + * Sets the knowledge for the search. + * + * @param knowledge This knowledge. + */ public void setKnowledge(Knowledge knowledge) { if (knowledge == null) { throw new NullPointerException(); @@ -212,6 +247,8 @@ public void setKnowledge(Knowledge knowledge) { } /** + * Returns whether Zhang's complete ruleset is to be used. + * * @return true if Zhang's complete rule set should be used, false if only R1-R4 (the rule set of the original FCI) * should be used. False by default. */ @@ -220,6 +257,8 @@ public boolean isCompleteRuleSetUsed() { } /** + * Sets whether Zhang's complete ruleset is to be used. + * * @param completeRuleSetUsed set to true if Zhang's complete rule set should be used, false if only R1-R4 (the rule * set of the original FCI) should be used. False by default. */ @@ -227,19 +266,18 @@ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { this.completeRuleSetUsed = completeRuleSetUsed; } - public boolean isPossibleDsepSearchDone() { - return true; - } - /** - * @return the maximum length of any discriminating path, or -1 of unlimited. + * Returns the maximum length of any discriminating path, or -1 of unlimited. + * @return This length. */ public int getMaxPathLength() { return this.maxPathLength == Integer.MAX_VALUE ? -1 : this.maxPathLength; } /** - * @param maxPathLength the maximum length of any discriminating path, or -1 if unlimited. + * Sets the maximum length of any discriminating path, or -1 if unlimited. + * + * @param maxPathLength This length. */ public void setMaxPathLength(int maxPathLength) { if (maxPathLength < -1) { @@ -250,31 +288,31 @@ public void setMaxPathLength(int maxPathLength) { } /** - * True iff verbose output should be printed. + * Returns whether verbose output is to be printed. + * + * @return True if so. */ public boolean isVerbose() { return this.verbose; } + /** + * Sets whether verbose output is to be printed. + * @param verbose True if so. + */ public void setVerbose(boolean verbose) { this.verbose = verbose; } /** - * The independence test. + * Returns independence test. + * + * @return This test. */ public IndependenceTest getIndependenceTest() { return this.independenceTest; } - public double getPenaltyDiscount() { - return this.penaltyDiscount; - } - - public void setPenaltyDiscount(double penaltyDiscount) { - this.penaltyDiscount = penaltyDiscount; - } - //===========================PRIVATE METHODS=========================// // removeSimilarPairs based on orientSimilarPairs in SvarFciOrient.java by Entner and Hoyer diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java index cc56df49dd..c10dd46441 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java @@ -1919,7 +1919,6 @@ public void removeSimilarEdges(Node x, Node y) { this.removedEdges.add(Edges.undirectedEdge(x1, y1)); } } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java index fe0a25d294..57596bd252 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasFdr.java @@ -181,14 +181,6 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - /** - * @throws UnsupportedOperationException This method is not used. - */ - @Override - public Graph search(List nodes) { - throw new UnsupportedOperationException("Method not used."); - } - @Override public long getElapsedTime() { return 0; From 1dbb0934565d9d1bcd7db8e835500eddd290de9c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 17:46:03 -0400 Subject: [PATCH 391/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../algorithm/oracle/cpdag/Cpc.java | 9 +- .../algorithm/oracle/cpdag/PcMax.java | 18 +- .../java/edu/cmu/tetrad/search/PcMax.java | 302 ++++++++++-------- .../edu/cmu/tetrad/search/utils/MaxP.java | 1 - 4 files changed, 166 insertions(+), 164 deletions(-) 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 544c786939..a35c5914b8 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 @@ -68,8 +68,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setVerbose(parameters.getBoolean(Params.VERBOSE)); 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)); +// search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); +// search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); return search.search(); } else { Cpc pcAll = new Cpc(this.test); @@ -105,13 +105,8 @@ public DataType getDataType() { 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.TIME_LAG); parameters.add(Params.VERBOSE); 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 4e26e0563e..0fec5afa93 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 @@ -23,13 +23,13 @@ import java.util.List; /** - * PC-Max. + * CPC. * * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( name = "PC-Max", - command = "pc-max", + command = "pcmax", algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping @@ -39,8 +39,6 @@ public class PcMax implements Algorithm, HasKnowledge, TakesIndependenceWrapper, static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - - private Graph externalGraph = null; private List bootstrapGraphs = new ArrayList<>(); @@ -68,9 +66,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setKnowledge(this.knowledge); -// search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); - search.setUseMaxP(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); + search.setKnowledge(knowledge); + search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); return search.search(); } else { @@ -107,11 +104,8 @@ public DataType getDataType() { 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.TIME_LAG); @@ -140,10 +134,6 @@ public void setIndependenceWrapper(IndependenceWrapper test) { this.test = test; } - public void setExternalGraph(Graph externalGraph) { - this.externalGraph = externalGraph; - } - @Override public List getBootstrapGraphs() { return this.bootstrapGraphs; 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 32971221b4..a16989fa63 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 @@ -24,7 +24,8 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.graph.GraphUtils; +import edu.cmu.tetrad.graph.Triple; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.PcCommon; @@ -32,9 +33,7 @@ import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Set; /** @@ -53,10 +52,10 @@ * @see Fasd * @see Knowledge */ -public class PcMax implements IGraphSearch { +public final class PcMax implements IGraphSearch { /** - * The independence test used for the PC search.g + * The independence test used for the PC search. */ private final IndependenceTest independenceTest; @@ -66,24 +65,31 @@ public class PcMax implements IGraphSearch { private Knowledge knowledge = new Knowledge(); /** - * Sepset information accumulated in the search. + * The maximum number of nodes conditioned on in the search. */ - private SepsetMap sepsets; + private int depth = 1000; + + private Graph graph; /** - * The maximum number of nodes conditioned on in the search. The default it 1000. + * Elapsed time of last search. */ - private int depth = 1000; + private long elapsedTime; /** - * The graph that's constructed during the search. + * Set of unshielded colliders from the triple orientation step. */ - private Graph graph; + private Set colliderTriples; /** - * Elapsed time of the most recent search. + * Set of unshielded noncolliders from the triple orientation step. */ - private long elapsedTime; + private Set noncolliderTriples; + + /** + * Set of ambiguous unshielded triples. + */ + private Set ambiguousTriples; /** * True if cycles are to be aggressively prevented. May be expensive for large graphs (but also useful for large @@ -97,25 +103,31 @@ public class PcMax implements IGraphSearch { private final TetradLogger logger = TetradLogger.getInstance(); /** - * The number of independence tests in the last search. + * The sepsets. */ - private int numIndependenceTests; + private SepsetMap sepsets; + /** + * Whether verbose output about independencies is output. + */ private boolean verbose; + private boolean stable; - private PcCommon.ConflictRule conflictRule = PcCommon.ConflictRule.OVERWRITE; + private boolean useHeuristic = false; + private int maxPPathLength = -1; + private final PcCommon.ConflictRule conflictRule = PcCommon.ConflictRule.OVERWRITE; //=============================CONSTRUCTORS==========================// /** - * Constructs a new PC search using the given independence test as oracle. + * Constructs a CPC algorithm that uses the given independence test as oracle. This does + * not make a copy of the independence test, for fear of duplicating the data set! * - * @param independenceTest The oracle for conditional independence facts. This does not make a copy of the - * independence test, for fear of duplicating the data set! + * @param independenceTest The test to user for oracle conditional independence information. */ public PcMax(IndependenceTest independenceTest) { if (independenceTest == null) { - throw new NullPointerException("Independence test is null."); + throw new NullPointerException(); } this.independenceTest = independenceTest; @@ -124,7 +136,7 @@ public PcMax(IndependenceTest independenceTest) { //==============================PUBLIC METHODS========================// /** - * Returns true iff edges will not be added if they would create cycles. + * Returns true just in case edges will not be added if they would create cycles. * * @return True if so. */ @@ -133,22 +145,40 @@ public boolean isAggressivelyPreventCycles() { } /** - * Sets whether cycles should be aggressively checked. + * Sets to true just in case edges will not be added if they would create cycles. * - * @param aggressivelyPreventCycles Set to true just in case edges will not be added - * if they would create cycles. + * @param aggressivelyPreventCycles True if so. */ public void setAggressivelyPreventCycles(boolean aggressivelyPreventCycles) { this.aggressivelyPreventCycles = aggressivelyPreventCycles; } /** - * Returns the independence test being used in the search. + * Sets the maximum number of variables conditioned on in any conditional independence test. If set to -1, the value + * of 1000 will be used. May not be set to Integer.MAX_VALUE, due to a Java bug on multicore systems. * - * @return This test. + * @param depth This maximum. */ - public IndependenceTest getIndependenceTest() { - return this.independenceTest; + public void setDepth(int depth) { + if (depth < -1) { + throw new IllegalArgumentException("Depth must be -1 or >= 0: " + depth); + } + + if (depth == Integer.MAX_VALUE) { + throw new IllegalArgumentException("Depth must not be Integer.MAX_VALUE, " + + "due to a known bug."); + } + + this.depth = depth; + } + + /** + * Returns the elapsed time of search in milliseconds, after search() has been run. + * + * @return This time. + */ + public long getElapsedTime() { + return this.elapsedTime; } /** @@ -161,119 +191,79 @@ public Knowledge getKnowledge() { } /** - * Sets the knowledge specification to be used in the search. May not be null. + * Sets the knowledge specification used in the search. Non-null. * * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { - if (knowledge == null) { - throw new NullPointerException("Knowledge is null."); - } - this.knowledge = knowledge; } /** - * Returns the sepset map from the most recent search. Non-null after the first call to - * search(). + * Rreturn the independence test used in the search, set in the constructor. * - * @return This map. + * @return This. */ - public SepsetMap getSepsets() { - return this.sepsets; + public IndependenceTest getIndependenceTest() { + return this.independenceTest; } /** - * Returns the current depth of search--that is, the maximum number of conditioning nodes - * for any conditional independence checked. + * Returns the depth of the search--that is, the maximum number of variables + * conditioned on in any conditional independence test. * - * @return This depth. + * @return This. */ public int getDepth() { return this.depth; } /** - * Sets the depth of the search--that is, the maximum number of conditioning nodes for any conditional independence - * checked. - * - * @param depth The depth of the search. The default is 1000. A value of -1 may be used to indicate that the depth - * should be high (1000). A value of Integer.MAX_VALUE may not be used, due to a bug on multicore - * machines. - */ - public void setDepth(int depth) { - if (depth < -1) { - throw new IllegalArgumentException("Depth must be -1 or >= 0: " + depth); - } - - if (depth > 1000) { - throw new IllegalArgumentException("Depth must be <= 1000."); - } - - this.depth = depth; - } - - /** - * Runs PC starting with a complete graph over all nodes of the given conditional independence - * test, using the given independence test and knowledge and returns the resultant graph. The - * returned graph will be a CPDAG if the independence information is consistent with the - * hypothesis that there are no latent common causes. It may however, contain cycles or bidirected - * edges if this assumption is not born out, either due to the actual presence of latent common - * causes, or due to statistical errors in conditional independence judgments. + * Returns the set of ambiguous triples found during the most recent run of the algorithm. + * Non-null after a call to search(). * - * @return The CPDAG found. + * @return This set. */ - @Override - public Graph search() { - return search(this.independenceTest.getVariables()); + public Set getAmbiguousTriples() { + return new HashSet<>(this.ambiguousTriples); } /** - * Runs PC starting with a complete graph over the given list of nodes, using the given - * independence test and knowledge and returns the resultant graph. The returned graph will - * be a CPDAG if the independence information is consistent with the hypothesis that there are - * no latent common causes. It may, however, contain cycles or bidirected edges if this - * assumption is not born out, either due to the actual presence of latent common causes, or - * due to statistical errors in conditional independence judgments. - *

    - * All the given nodes must be in the domain of the given conditional independence test. + * Returns the edges in the search graph as a set of undirected edges. * - * @param nodes the sublist of nodes to search over. - * @return The CPDAG found. + * @return These edges. */ - public Graph search(List nodes) { - nodes = new ArrayList<>(nodes); - - IFas fas = new Fas(getIndependenceTest()); - fas.setVerbose(this.verbose); - return search(fas, nodes); + public Set getAdjacencies() { + return new HashSet<>(GraphUtils.undirectedGraph(this.graph).getEdges()); } /** - * Runs the search using a particular implementation of the fast adjacency search - * (FAS), over the given sublist of nodes. + * Runs CPC starting with a fully connected graph over all the variables in the domain + * of the independence test. See PC for caveats. The number of possible cycles and + * bidirected edges is far less with CPC than with PC. * - * @param fas The fast adjacency search to use. - * @param nodes The sublist of nodes. - * @return The result graph - * @see #search() - * @see IFas + * @return The e-pattern for the search, which is a graphical representation of a set + * of possible CPDAGs. */ - public Graph search(IFas fas, List nodes) { - this.logger.log("info", "Starting PC algorithm"); + public Graph search() { + this.logger.log("info", "Starting CPC algorithm"); this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); + this.ambiguousTriples = new HashSet<>(); + this.colliderTriples = new HashSet<>(); + this.noncolliderTriples = new HashSet<>(); + + Fas fas = new Fas(getIndependenceTest()); long startTime = MillisecondTimes.timeMillis(); - if (getIndependenceTest() == null) { - throw new NullPointerException("Null independence test."); - } + fas.setKnowledge(getKnowledge()); + fas.setDepth(getDepth()); + fas.setVerbose(this.verbose); - List allNodes = getIndependenceTest().getVariables(); - if (!new HashSet<>(allNodes).containsAll(nodes)) { - throw new IllegalArgumentException("All of the given nodes must " + - "be in the domain of the independence test provided."); - } + // Note that we are ignoring the sepset map returned by this method + // on purpose; it is not used in this search. + this.graph = fas.search(); + this.sepsets = fas.getSepsets(); PcCommon search = new PcCommon(independenceTest); search.setDepth(depth); @@ -288,83 +278,111 @@ public Graph search(IFas fas, List nodes) { search.setColliderDiscovery(PcCommon.ColliderDiscovery.MAX_P); search.setConflictRule(conflictRule); - search.setUseHeuristic(true); - search.setMaxPathLength(-1); + search.setUseHeuristic(useHeuristic); + search.setMaxPathLength(maxPPathLength); search.setVerbose(verbose); this.graph = search.search(); this.sepsets = fas.getSepsets(); - this.numIndependenceTests = fas.getNumIndependenceTests(); - - GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, nodes); + GraphSearchUtils.pcOrientbk(this.knowledge, this.graph, independenceTest.getVariables()); GraphSearchUtils.orientCollidersUsingSepsets(this.sepsets, this.knowledge, this.graph, this.verbose, false); - this.logger.log("graph", "\nReturning this graph: " + this.graph); + TetradLogger.getInstance().log("graph", "\nReturning this graph: " + this.graph); + + long endTime = MillisecondTimes.timeMillis(); + this.elapsedTime = endTime - startTime; + + TetradLogger.getInstance().log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); + TetradLogger.getInstance().log("info", "Finishing CPC algorithm."); - this.elapsedTime = MillisecondTimes.timeMillis() - startTime; + this.colliderTriples = search.getColliderTriples(); + this.noncolliderTriples = search.getNoncolliderTriples(); + this.ambiguousTriples = search.getAmbiguousTriples(); - this.logger.log("info", "Elapsed time = " + (this.elapsedTime) / 1000. + " s"); - this.logger.log("info", "Finishing PC Algorithm."); - this.logger.flush(); + logTriples(); + TetradLogger.getInstance().flush(); return this.graph; } /** - * Returns the elapsed time of the search, in milliseconds. + * Returns a map for x _||_ y | z1,..,zn from {x, y} to {z1,...,zn}. * - * @return This time. + * @return This map. */ - public long getElapsedTime() { - return this.elapsedTime; + public SepsetMap getSepsets() { + return this.sepsets; } /** - * Returns the adjacencies in the graph. - * @return This set. + * The graph that's constructed during the search. + * + * @return This graph. */ - public Set getAdjacencies() { - return new HashSet<>(this.graph.getEdges()); + public Graph getGraph() { + return this.graph; } /** - * Returns the number of independence test performed in the search. - * @return This numbger. + * Sets whether verbose output should be printed. + * + * @param verbose True if so. */ - public int getNumIndependenceTests() { - return this.numIndependenceTests; + public void setVerbose(boolean verbose) { + this.verbose = verbose; } /** - * Returns the nodes in graph. - * @return This list. + * Sets whether the stable FAS search should be used. + * + * @param stable True if so. */ - public List getNodes() { - return this.graph.getNodes(); + public void setStable(boolean stable) { + this.stable = stable; } /** - * Sets whether verbose output should be printed. - * @param verbose True is fo. + * Sets whether the heuristic should be used for max p. + * + * @param useHeuristic True if so. */ - public void setVerbose(boolean verbose) { - this.verbose = verbose; + public void setUseHeuristic(boolean useHeuristic) { + this.useHeuristic = useHeuristic; } /** - * Sets whether the stable option should be used. - * @param stable True if so. + * Sets the max path length for the max p heuristic. + * + * @param maxPPathLength This length. */ - public void setStable(boolean stable) { - this.stable = stable; + public void setMaxPPathLength(int maxPPathLength) { + this.maxPPathLength = maxPPathLength; } - public void setConflictRule(PcCommon.ConflictRule conflictRule) { - this.conflictRule = conflictRule; - } -} + //==========================PRIVATE METHODS===========================// + private void logTriples() { + TetradLogger.getInstance().log("info", "\nCollider triples:"); + for (Triple triple : this.colliderTriples) { + TetradLogger.getInstance().log("info", "Collider: " + triple); + } + + TetradLogger.getInstance().log("info", "\nNoncollider triples:"); + + for (Triple triple : this.noncolliderTriples) { + TetradLogger.getInstance().log("info", "Noncollider: " + triple); + } + + TetradLogger.getInstance().log("info", "\nAmbiguous triples (i.e. list of triples for which " + + "\nthere is ambiguous data about whether they are colliders or not):"); + + for (Triple triple : getAmbiguousTriples()) { + TetradLogger.getInstance().log("info", "Ambiguous: " + triple); + } + } + +} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java index ecc0517e07..32c8e89708 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.PcMax; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; From 54ec77c1ec88ae009dd6b1f2e704c74e1275acaa Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 17:46:28 -0400 Subject: [PATCH 392/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Cpc.java | 3 --- 1 file changed, 3 deletions(-) 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 a35c5914b8..bd180bebda 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 @@ -67,9 +67,6 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); 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(); } else { Cpc pcAll = new Cpc(this.test); From cd5f8bb09489aa2d3a00f627c122cad4a0649b44 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 17:48:55 -0400 Subject: [PATCH 393/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/algcomparison/independence/MagSemBicTest.java | 2 +- .../edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java | 6 +++--- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 2 +- .../cmu/tetrad/search/score/ConditionalGaussianScore.java | 1 + .../cmu/tetrad/search/score/DegenerateGaussianScore.java | 1 + .../main/java/edu/cmu/tetrad/search/score/EbicScore.java | 4 +--- .../search/{score => work_in_progress}/MagSemBicScore.java | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{score => work_in_progress}/MagSemBicScore.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java index ee518b7b7c..bf6ad0cd18 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java @@ -8,7 +8,7 @@ import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.search.test.ScoreIndTest; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.score.MagSemBicScore; +import edu.cmu.tetrad.search.work_in_progress.MagSemBicScore; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java index 763fa1517b..d6a045fb33 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java @@ -31,12 +31,12 @@ public class MagSemBicScore implements ScoreWrapper { public Score getScore(DataModel dataSet, Parameters parameters) { this.dataSet = dataSet; - edu.cmu.tetrad.search.score.MagSemBicScore semBicScore; + edu.cmu.tetrad.search.work_in_progress.MagSemBicScore semBicScore; if (dataSet instanceof DataSet) { - semBicScore = new edu.cmu.tetrad.search.score.MagSemBicScore((DataSet) this.dataSet); + semBicScore = new edu.cmu.tetrad.search.work_in_progress.MagSemBicScore((DataSet) this.dataSet); } else if (dataSet instanceof ICovarianceMatrix) { - semBicScore = new edu.cmu.tetrad.search.score.MagSemBicScore((ICovarianceMatrix) this.dataSet); + semBicScore = new edu.cmu.tetrad.search.work_in_progress.MagSemBicScore((ICovarianceMatrix) this.dataSet); } else { throw new IllegalArgumentException("Expecting either a dataset or a covariance matrix."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 32252b5ee4..0adaa7ae86 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.score.MagSemBicScore; +import edu.cmu.tetrad.search.work_in_progress.MagSemBicScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.*; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index 28f8496990..bac386b9d4 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.work_in_progress.MagSemBicScore; import org.apache.commons.math3.util.FastMath; import java.text.DecimalFormat; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 329104638a..a69932e5a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; +import edu.cmu.tetrad.search.work_in_progress.MagSemBicScore; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.RealMatrix; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java index 47ace32cc0..a95a23f1c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java @@ -24,9 +24,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.score.MagSemBicScore; -import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.work_in_progress.MagSemBicScore; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.Matrix; import org.apache.commons.math3.linear.SingularMatrixException; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MagSemBicScore.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MagSemBicScore.java index ecb38833cf..eef555eeec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MagSemBicScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.score; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.ICovarianceMatrix; From 350f9bdaac72df885c94645ff2b23c0dfc4d8a66 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 17:53:41 -0400 Subject: [PATCH 394/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index 9d30d4bdc5..e87972d90b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -46,6 +46,7 @@ *

    As for all scores in Tetrad, higher scores mean more dependence, and negative * scores indicate independence.

    * + * @author bryanandrews * @author josephramsey */ public class PoissonPriorScore implements Score { From dceead937f041c4e6f274d37a049014e93c9a7f0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 18:12:45 -0400 Subject: [PATCH 395/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../edu/cmu/tetrad/search/utils/AdTrees.java | 33 ------------------- .../tetrad/search/utils/BayesImParser.java | 12 ++++--- .../java/edu/cmu/tetrad/search/utils/Bes.java | 1 + .../tetrad/search/utils/BesPermutation.java | 21 +++++++----- .../tetrad/search/utils/BpcAlgorithmType.java | 2 +- .../search/utils/ClusterSignificance.java | 7 ++-- .../tetrad/search/utils/DeltaTetradTest.java | 1 - .../cmu/tetrad/search/utils/EstimateRank.java | 18 +++++++--- .../edu/cmu/tetrad/search/utils/IPurify.java | 2 ++ .../edu/cmu/tetrad/search/utils/Kernel.java | 1 - .../edu/cmu/tetrad/search/utils/MaxP.java | 1 - .../edu/cmu/tetrad/search/utils/Purify.java | 1 - .../tetrad/search/utils/SepsetProducer.java | 5 ++- .../cmu/tetrad/search/utils/TetradTest.java | 15 +++++++++ .../tetrad/search/utils/TeyssierScorer.java | 3 +- .../GraphChange.java | 3 +- .../tetrad/search/work_in_progress/Ion.java | 1 - .../work_in_progress/IonHittingSet.java | 2 -- 18 files changed, 63 insertions(+), 66 deletions(-) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{utils => work_in_progress}/GraphChange.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java deleted file mode 100644 index 119c071891..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdTrees.java +++ /dev/null @@ -1,33 +0,0 @@ -package edu.cmu.tetrad.search.utils; - -import edu.cmu.tetrad.data.DataSet; - -import java.util.HashMap; -import java.util.Map; - -/** - * Stores AD trees for data sets for reuse. - * - * @author josephramsey - */ -public class AdTrees { - private static final Map adTrees = new HashMap<>(); - - /** - * Returns an ADLeafTree for the given dataset. - * - * @param dataSet A discrete dataset. - * @return The AdLeafTree - * @see AdLeafTree - */ - public static AdLeafTree getAdLeafTree(DataSet dataSet) { - AdLeafTree tree = AdTrees.adTrees.get(dataSet); - - if (tree == null) { - tree = new AdLeafTree(dataSet); - AdTrees.adTrees.put(dataSet, tree); - } - - return tree; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java index 7ceb03026b..dcfeb2fe9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java @@ -49,6 +49,14 @@ public class BayesImParser { public BayesImParser() { } + /** + * Sets whether to use display names. + * @param useDisplayNames True if so. + */ + public void setUseDisplayNames(boolean useDisplayNames) { + this.useDisplayNames = useDisplayNames; + } + /** * Takes an xml representation of a Bayes IM and reinstantiates the IM * @@ -249,10 +257,6 @@ private Map mapDisplayNames(Element element1, boolean useDisplay return null; } } - - public void setUseDisplayNames(boolean useDisplayNames) { - this.useDisplayNames = useDisplayNames; - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Bes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Bes.java index 8c5ea2ad73..a53990e979 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Bes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Bes.java @@ -26,6 +26,7 @@ * Equivalence Search) and a backward phase (BES = Backward Equivalence Search). * We find the BES step by itself is useful in a number of algorithms, so we * extract this step and give as a separate algorithm.

    + * *

    The idea of the backward search is to start with a model that is * Markov and removed edges from it and do the corresponding reorientations, * improving the score each time, until the score can no longer be improved.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java index 969928ded1..eded419fea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java @@ -83,15 +83,9 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge(knowledge); } - private void buildIndexing(List nodes, Map hashIndices) { - - int i = -1; - - for (Node n : nodes) { - hashIndices.put(n, ++i); - } - } - + /** + * Runs BES. + */ public void bes(Graph graph, List order, List suborder) { Map hashIndices = new HashMap<>(); SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>(); @@ -574,4 +568,13 @@ public Set getParents() { return parents; } } + + private void buildIndexing(List nodes, Map hashIndices) { + + int i = -1; + + for (Node n : nodes) { + hashIndices.put(n, ++i); + } + } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java index cf91eb2f89..d1465106a9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.util.TetradSerializable; /** - * Enumerates the algorihtm types for BuildPureClusters, and Purify. + * Enumerates the algorithm types for BuildPureClusters, and Purify. */ public enum BpcAlgorithmType implements TetradSerializable { BUILD_PURE_CLUSTERS, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java index d283c38742..4004ced6cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ClusterSignificance.java @@ -18,10 +18,9 @@ import java.util.Set; /** - *

    Provides some methods to check significance of clusters for clustering algroithms. It is assumed - * that for each cluster there is a single latent that is a parent of all the nodes - * in the cluster. Significance of these models is returned.

    - *

    The methods in this class are used only internally and so have package scope only.

    + *

    Provides some methods to check significance of clusters for clustering algroithms. + * It is assumed that for each cluster there is a single latent that is a parent of all + * the nodes in the cluster. Significance of these models is returned.

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java index 44918936b4..e16a2262d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java @@ -85,7 +85,6 @@ public DeltaTetradTest(DataSet dataSet) { for (int i = 0; i < this.variables.size(); i++) { this.variablesHash.put(this.variables.get(i), i); } - } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/EstimateRank.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/EstimateRank.java index e15ba445a6..aa7fd76345 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/EstimateRank.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/EstimateRank.java @@ -29,10 +29,14 @@ /** * Estimates the rank of a matrix. + * + * @author adambrodie */ public class EstimateRank { - //Compute canonical correlations from data. + /** + * Compute canonical correlations from data. + */ public static double[] CanCor(double[][] A, double[][] B) { RealMatrix Ua = new SingularValueDecomposition(new BlockRealMatrix(A)).getU(); RealMatrix UTa = Ua.transpose(); @@ -40,7 +44,9 @@ public static double[] CanCor(double[][] A, double[][] B) { return new SingularValueDecomposition(UTa.multiply(Ub)).getSingularValues(); } - //Compute canonical correlations from covariance matrix. + /** + * Compute canonical correlations from covariance matrix. + */ public static double[] CanCor(int[] iA, int[] iB, double[][] cov) { RealMatrix covA = new BlockRealMatrix(cov).getSubMatrix(iA, iA); RealMatrix covB = new BlockRealMatrix(cov).getSubMatrix(iB, iB); @@ -56,7 +62,9 @@ public static double[] CanCor(int[] iA, int[] iB, double[][] cov) { return Cors; } - //Estimate rank from data. + /** + * Estimate rank from data. + */ public static int Estimate(double[][] A, double[][] B, double alpha) { double[] Cors = CanCor(A, B); int rank = 0; @@ -79,7 +87,9 @@ public static int Estimate(double[][] A, double[][] B, double alpha) { return rank; } - //Estimate rank from covariance matrix. + /** + * Estimate rank from covariance matrix. + */ public static int Estimate(int[] iA, int[] iB, double[][] cov, int N, double alpha) { double[] Cors = CanCor(iA, iB, cov); int rank = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java index eaec254fd8..8672736821 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/IPurify.java @@ -28,10 +28,12 @@ /** * Provides an interface for Purify algorithm. + * * @author josephramsey */ public interface IPurify { List> purify(List> partition); + void setTrueGraph(Graph mim); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java index 8773725a89..df34b255d3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Kernel.java @@ -30,7 +30,6 @@ * * @author Robert Tillman */ - public interface Kernel { /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java index 32c8e89708..3281b15635 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MaxP.java @@ -39,7 +39,6 @@ * algorithm by maximizing p-value. arXiv preprint arXiv:1610.00378.

    * * @author josephramsey - * @see PcMax */ public final class MaxP { private final IndependenceTest independenceTest; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java index fe16b35a49..7e8a7af0ec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Purify.java @@ -56,7 +56,6 @@ * * @author Ricardo Silva */ - public class Purify { private boolean outputMessage; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java index b465dc0f70..7486da157b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetProducer.java @@ -22,7 +22,6 @@ package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.SepsetMap; import java.util.List; @@ -35,11 +34,15 @@ */ public interface SepsetProducer { List getSepset(Node a, Node b); + boolean isUnshieldedCollider(Node i, Node j, Node k); double getScore(); + List getVariables(); + void setVerbose(boolean verbose); + boolean isIndependent(Node d, Node c, List path); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java index 20c87aa612..3fd8b7921e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTest.java @@ -36,20 +36,35 @@ */ public interface TetradTest { DataSet getDataSet(); + int tetradScore(int i, int j, int k, int q); + boolean tetradScore3(int i, int j, int k, int q); + boolean tetradScore1(int i, int j, int k, int q); + boolean tetradHolds(int i, int j, int k, int q); + double tetradPValue(int i, int j, int k, int q); + boolean oneFactorTest(int a, int b, int c, int d); + boolean oneFactorTest(int a, int b, int c, int d, int e); + boolean twoFactorTest(int a, int b, int c, int d); + boolean twoFactorTest(int a, int b, int c, int d, int e); + boolean twoFactorTest(int a, int b, int c, int d, int e, int f); + double getSignificance(); + void setSignificance(double sig); + String[] getVarNames(); + List getVariables(); + ICovarianceMatrix getCovMatrix(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java index 7faaa737eb..c268d56184 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java @@ -47,7 +47,8 @@ public class TeyssierScorer { /** * Constructor that takes both a test or a score. Only one of these is used, dependeint * on how the parameters are set. - * @param test The test. + * + * @param test The test. * @param score The score * @see IndependenceTest * @see Score diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraphChange.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraphChange.java index 77bfcd75ac..43994cb564 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphChange.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraphChange.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search.utils; +package edu.cmu.tetrad.search.work_in_progress; import edu.cmu.tetrad.graph.*; @@ -34,7 +34,6 @@ * "from" node and Node2 is the "to" node (ie 1 o-> 2).

    * * @author Trevor Burns - * @see Ion */ public class GraphChange { private final List removes; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java index fd907c8700..a8d8739806 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java @@ -24,7 +24,6 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphChange; import edu.cmu.tetrad.search.utils.PossibleDConnectingPath; import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.ChoiceGenerator; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IonHittingSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IonHittingSet.java index b4aa1faedf..354ab26fd0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IonHittingSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IonHittingSet.java @@ -21,8 +21,6 @@ package edu.cmu.tetrad.search.work_in_progress; -import edu.cmu.tetrad.search.utils.GraphChange; - import java.util.ArrayList; import java.util.LinkedList; import java.util.List; From 5c962038755a2f0a239f55730b9f4fd28ac86e08 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 18:30:57 -0400 Subject: [PATCH 396/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Ftfc.java | 17 ++++++++-------- .../java/edu/cmu/tetrad/search/SvarFas.java | 1 + .../java/edu/cmu/tetrad/search/SvarFci.java | 20 ++++++++++++++----- .../edu/cmu/tetrad/search/SvarFciOrient.java | 1 + .../java/edu/cmu/tetrad/search/SvarFges.java | 1 + .../java/edu/cmu/tetrad/search/SvarGfci.java | 1 + 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index 39f48cb6e3..d4764f425a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -44,15 +44,16 @@ /** - *

    Implements the Find Two Factor Clusters (FOFC) algorithm by Erich Kummerfeld - * and Peter Spirtes, which uses reasoning about vanishing tetrads of algorithms to - * infer clusters of the measured variables in a dataset that each be explained by - * a single latent variable. A reference for the one-factor versiono of the algorithm - * (FOFC) is the following

    + *

    Implements the Find Two Factor Clusters (FOFC) algorithm, which uses reasoning + * about vanishing tetrads of algorithms to infer clusters of the measured variables + * in a dataset that each be explained by a single latent variable. The reference + * is as follows:

    * - *

    Kummerfeld, E., & Ramsey, J. (2016, August). Causal clustering for 1-factor measurement - * models. In Proceedings of the 22nd ACM SIGKDD international conference on knowledge - * discovery and data mining (pp. 1655-1664).

    + *

    Kummerfeld, E. & Ramsey, J. & Yang, R. & Spirtes, P. & Scheines, R. (2014). + * Causal Clustering for 2-Factor Measurement Models. In T. Calders, F. Esposito, + * E. Hullermeier, and R. Meo, editors, Machine Learning and Knowledge Discovery in + * Databases, volume 8725 of Lecture Notes in Computer Science, pages 34-49. Springer + * Berlin Heidelberg.

    * *

    The two-factor version of the algorithm substitutes sextad tests for * tetrad tests and searches for clusters of at leat 6 variables that can be diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java index c7a54721a6..745bbbeb8c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java @@ -47,6 +47,7 @@ * @author dmalinsky * @see Fas * @see Knowledge + * @see SvarFci */ public class SvarFas implements IFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 84ef6ff68a..1013cc7865 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -39,13 +39,23 @@ import java.util.List; /** - * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's + *

    Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems"). - *

    - * This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is + * Insufficient Systems").

    + * + *

    This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. - * (By a remark of Zhang's, the rule applications can be staged in this way.) + * (By a remark of Zhang's, the rule applications can be staged in this way.)

    + * + *

    Some references are as follows:

    + * + *

    Malinsky, D., & Spirtes, P. (2018, August). Causal structure learning from multivariate + * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD + * workshop on causal discovery (pp. 23-47). PMLR.

    + * + *

    Malinsky, D., & Spirtes, P. (2019, April). Learning the structure of a nonstationary + * vector autoregression. In The 22nd International Conference on Artificial Intelligence + * and Statistics (pp. 2986-2994). PMLR.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java index 10eadb4dca..75fc8c8b38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java @@ -49,6 +49,7 @@ * * @author dmalinsky * @see Knowledge + * @see SvarFci */ public final class SvarFciOrient { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java index c10dd46441..33edd8d3fd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java @@ -62,6 +62,7 @@ * @author danielmalinsky * @see Fges * @see Knowledge + * @see SvarFci */ public final class SvarFges implements IGraphSearch, DagScorer { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index 6240a17927..d8ca7e654b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -51,6 +51,7 @@ * @author danielmalinsky * @see GFci * @see Knowledge + * @see SvarFci */ public final class SvarGfci implements IGraphSearch { From c80ce092e5887d7a0c09d47efa9f6ad70bbaf3e3 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 18:34:34 -0400 Subject: [PATCH 397/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 1013cc7865..0377bda804 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -47,16 +47,12 @@ * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. * (By a remark of Zhang's, the rule applications can be staged in this way.)

    * - *

    Some references are as follows:

    + *

    The references is as follows:

    * *

    Malinsky, D., & Spirtes, P. (2018, August). Causal structure learning from multivariate * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD * workshop on causal discovery (pp. 23-47). PMLR.

    * - *

    Malinsky, D., & Spirtes, P. (2019, April). Learning the structure of a nonstationary - * vector autoregression. In The 22nd International Conference on Artificial Intelligence - * and Statistics (pp. 2986-2994). PMLR.

    - * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    * From a1d6d158a6bcb0de8a64dd18e8970a54ea1ff658 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 19:31:37 -0400 Subject: [PATCH 398/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Ftfc.java | 2 +- .../java/edu/cmu/tetrad/search/PcMax.java | 2 +- .../java/edu/cmu/tetrad/search/SvarFas.java | 18 ++++++++++---- .../java/edu/cmu/tetrad/search/SvarFci.java | 20 +++++++++------- .../java/edu/cmu/tetrad/search/SvarFges.java | 24 +++++++++---------- .../java/edu/cmu/tetrad/search/SvarGfci.java | 20 ++++++++++++---- .../search/{ => utils}/SvarFciOrient.java | 5 ++-- 7 files changed, 56 insertions(+), 35 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{ => utils}/SvarFciOrient.java (99%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java index d4764f425a..967df83148 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ftfc.java @@ -49,7 +49,7 @@ * in a dataset that each be explained by a single latent variable. The reference * is as follows:

    * - *

    Kummerfeld, E. & Ramsey, J. & Yang, R. & Spirtes, P. & Scheines, R. (2014). + *

    Kummerfeld, E. & Ramsey, J. & Yang, R. & Spirtes, P. & Scheines, R. (2014). * Causal Clustering for 2-Factor Measurement Models. In T. Calders, F. Esposito, * E. Hullermeier, and R. Meo, editors, Machine Learning and Knowledge Discovery in * Databases, volume 8725 of Lecture Notes in Computer Science, pages 34-49. Springer 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 a16989fa63..06932c20dc 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 @@ -37,7 +37,7 @@ import java.util.Set; /** - *

    Modifies the PC algorithm to use the Max P rule for orienting ushielded + *

    Modifies the PC algorithm to use the Max P rule for orienting ushielded * colliders. The reference is this:

    * *

    Ramsey, J. (2016). Improving accuracy and scalability of the pc algorithm diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java index 745bbbeb8c..fc94191549 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java @@ -36,10 +36,20 @@ import java.util.*; /** - *

    Adapts FAS for the SvarFCI algorithm. The main difference is that if an edge is - * removed, it will also remove all homologous edges to preserve the time-repeating s - * tructure assumed by SvarFCI. Based on (but not identical to) code by Entner and Hoyer - * for their 2010 paper. Modified by dmalinsky 4/21/2016.

    + *

    Adapts FAS for the time series setting, assuming the data is generated by a + * SVAR (structural vector autoregression). The main difference is that time order is + * imposed, and if an edge is removed, it will also remove all homologous edges to + * preserve the time-repeating structure assumed by SvarFCI. Based on (but not identical + * to) code by Entner and Hoyer for their 2010 paper. Modified by dmalinsky 4/21/2016.

    + * + *

    The references are as follows:

    + * + *

    Malinsky, D., & Spirtes, P. (2018, August). Causal structure learning from multivariate + * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD + * workshop on causal discovery (pp. 23-47). PMLR.

    + * + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + * graphical models, 121-128.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java index 0377bda804..710d3fe4de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFci.java @@ -27,10 +27,7 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.SepsetMap; -import edu.cmu.tetrad.search.utils.SepsetProducer; -import edu.cmu.tetrad.search.utils.SepsetsPossibleDsep; -import edu.cmu.tetrad.search.utils.SepsetsSet; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; @@ -39,20 +36,25 @@ import java.util.List; /** - *

    Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's - * Augmented FCI rules (found in sec. 4.1 of Zhang's 2006 PhD dissertation, "Causal Inference and Reasoning in Causally - * Insufficient Systems").

    + *

    Adapts FCI for the time series setting, assuming the data is generated by a + * SVAR (structural vector autoregression). The main difference is that time order is + * imposed, and if an edge is removed, it will also remove all homologous edges to + * preserve the time-repeating structure assumed by SvarFCI. Based on (but not identical + * to) code by Entner and Hoyer for their 2010 paper. Modified by dmalinsky 4/21/2016.

    * *

    This class is based off a copy of FCI.java taken from the repository on 2008/12/16, revision 7306. The extension is * done by extending doFinalOrientation() with methods for Zhang's rules R5-R10 which implements the augmented search. * (By a remark of Zhang's, the rule applications can be staged in this way.)

    * - *

    The references is as follows:

    + *

    The references are as follows:

    * - *

    Malinsky, D., & Spirtes, P. (2018, August). Causal structure learning from multivariate + *

    Malinsky, D., & Spirtes, P. (2018, August). Causal structure learning from multivariate * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD * workshop on causal discovery (pp. 23-47). PMLR.

    * + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + * graphical models, 121-128.

    + * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java index 33edd8d3fd..d0d43f9d11 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java @@ -38,23 +38,21 @@ import java.util.*; import java.util.concurrent.*; - /** - * Adapts FGES to the SVAR case. FGES is an implementation of the GES algorithm, as specified in - * Chickering (2002) "Optimal structure identification with greedy search" Journal of Machine - * Learning Research. It works for both BayesNets and SEMs.

    + *

    Adapts FGES for the time series setting, assuming the data is generated by a + * SVAR (structural vector autoregression). The main difference is that time order is + * imposed, and if an edge is removed, it will also remove all homologous edges to + * preserve the time-repeating structure assumed by SvarFCI. Based on (but not identical + * to) code by Entner and Hoyer for their 2010 paper. Modified by dmalinsky 4/21/2016.

    * - *

    Some code optimization could be done for the scoring part of the graph for discrete models - * (method scoreGraphChange). Some of Andrew Moore's approaches for caching sufficient statistics, - * for instance.

    + *

    The references are as follows:

    * - *

    To speed things up, it has been assumed that variables X and Y with zero correlation do not - * correspond to edges in the graph. This is a restricted form of the heuristicSpeedup assumption, - * something GES does not assume. This is the graph. This is a restricted form of the - * heuristicSpeedup assumption, something GES does not assume. This heuristicSpeedup assumption - * needs to be explicitly turned on using setHeuristicSpeedup(true).

    + *

    Malinsky, D., & Spirtes, P. (2018, August). Causal structure learning from multivariate + * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD + * workshop on causal discovery (pp. 23-47). PMLR.

    * - *

    A number of other optimizations were added 5/2015. See code for details.

    + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + * graphical models, 121-128.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java index d8ca7e654b..d9f11e506c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -29,10 +29,7 @@ import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestDSep; import edu.cmu.tetrad.search.test.IndependenceTest; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; -import edu.cmu.tetrad.search.utils.LogUtilsSearch; -import edu.cmu.tetrad.search.utils.SepsetProducer; -import edu.cmu.tetrad.search.utils.SepsetsGreedy; +import edu.cmu.tetrad.search.utils.*; import edu.cmu.tetrad.util.ChoiceGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.math3.util.FastMath; @@ -43,7 +40,20 @@ /** - * Adapts GFCI to the SVAR case. + *

    Adapts GFCI for the time series setting, assuming the data is generated by a + * SVAR (structural vector autoregression). The main difference is that time order is + * imposed, and if an edge is removed, it will also remove all homologous edges to + * preserve the time-repeating structure assumed by SvarFCI. Based on (but not identical + * to) code by Entner and Hoyer for their 2010 paper. Modified by dmalinsky 4/21/2016.

    + * + *

    The references are as follows:

    + * + *

    Malinsky, D., & Spirtes, P. (2018, August). Causal structure learning from multivariate + * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD + * workshop on causal discovery (pp. 23-47). PMLR.

    + * + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + * graphical models, 121-128.

    * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SvarFciOrient.java similarity index 99% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SvarFciOrient.java index 75fc8c8b38..1cbc3e671a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SvarFciOrient.java @@ -19,13 +19,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.utils; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.Endpoint; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.SvarFci; import edu.cmu.tetrad.search.test.IndependenceTest; import edu.cmu.tetrad.search.utils.FciOrient; import edu.cmu.tetrad.search.utils.GraphSearchUtils; @@ -39,7 +40,7 @@ /** - *

    Adapts FciOrientfor the SvarFCI algorithm. The main difference is that if an edge is orient, + *

    Adapts FciOrient for the SvarFCI algorithm. The main difference is that if an edge is orient, * it will also orient all homologous edges to preserve the time-repeating structure assumed by * SvarFCI. Based on (but not identicial to) code by Entner and Hoyer for their 2010 paper. Modified * by DMalinsky 4/20/2016.

    From df8063c6963b2bcfa980db64df8f9c31c16e12e4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 8 May 2023 19:41:09 -0400 Subject: [PATCH 399/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index 1489f5d65c..ca3a9b12c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -136,6 +136,7 @@ * edges, including knowledge of temporal tiers.

    * * @author josephramsey + * @author rubensanchez * @see Knowledge * @see Lofs */ From 6dd12696dd61d9f52bc8b19c5523e1b396f145bf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 07:41:08 -0400 Subject: [PATCH 400/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java | 8 ++++---- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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 79cc6a585b..654f10a18f 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 @@ -12,11 +12,11 @@ import static edu.cmu.tetrad.util.RandomUtil.shuffle; /** - *

    Implements an algorithms called BOSS (Bost order Score Search), which - * intercalalates calls to a permutation discvoery step with called to BES, in order - * to find an optimal permutation implying a DAG and therefore a CPDAG that is + *

    Implements an algorithm called BOSS (Bost order Score Search), which + * intercalates calls to a permutation discovery step with calls to BES, in order + * to find an optimal permutation implying a DAG and, therefore a CPDAG that is * highly accurate. This follows up on work by Raskutti and Uhler on the SP - * (Sparsest Permutation) algorithm and work by Lam, Andrews and Ramsey on the + * (Sparsest Permutation) algorithm and work by Lam, Andrews, and Ramsey on the * GRaSP algorithm and is currently under development.

    * *

    Knowledge can be used with this search. If tiered knowledge is used, then the procedure diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index e0a26b1c8b..f6a7308e43 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -20,7 +20,7 @@ import java.util.concurrent.*; /** - *

    Implements the CStaR algorithm (Steckoven et al., 2012), which finds a CPDAG of thd data and then + *

    Implements the CStaR algorithm (Steckoven et al., 2012), which finds a CPDAG of that data and then * tries all orientations of the undirected edges about a variable in the CPDAG to estimate a * minimum bound on the effect for a given edge. Some references include the following:

    * From 991cd7d21f7a13863d699aaa1456f5fae2fa047f Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 08:31:52 -0400 Subject: [PATCH 401/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../main/java/edu/cmu/tetrad/search/Boss.java | 234 +++++++----------- .../cmu/tetrad/search/PermutationSearch.java | 4 +- .../main/java/edu/cmu/tetrad/search/Sp.java | 201 +++++++-------- .../tetrad/search/utils/BesPermutation.java | 43 ++-- .../tetrad/search/utils/GrowShrinkTree.java | 111 ++------- 5 files changed, 229 insertions(+), 364 deletions(-) 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 654f10a18f..6f3961e0cb 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 @@ -38,14 +38,14 @@ * @see Knowledge */ public class Boss implements SuborderSearch { - private final BesPermutation bes; private final Score score; private final List variables; private final Map> parents; - private final Map scores; private Map gsts; - private int numStarts; private Knowledge knowledge = new Knowledge(); + private BesPermutation bes = null; + private int numStarts = 1; + /** * This algorithm will work with an arbitrary score. @@ -56,204 +56,134 @@ public Boss(Score score) { this.score = score; this.variables = score.getVariables(); this.parents = new HashMap<>(); - this.scores = new HashMap<>(); - for (Node x : this.variables) { this.parents.put(x, new HashSet<>()); } - - this.bes = new BesPermutation(score); - this.bes.setVerbose(false); - this.numStarts = 1; } - /** - * Searches over the given suborder using the given prefix. Useful if tiered knowledge is available. - * - * @param prefix The prefix--variables alwasys allowed for conditioning. - * @param suborder The suborder--these are the variables being searched over. - * @param gsts The grow-shrink tree used for caching. - * @see GrowShrinkTree - */ @Override public void searchSuborder(List prefix, List suborder, Map gsts) { + assert this.numStarts > 0; this.gsts = gsts; - makeValidKnowledgeOrder(suborder); - List bestSuborder = new ArrayList<>(suborder); - double bestScore = update(prefix, suborder); - - Map> required = new HashMap<>(); - for (Node y : suborder) { - for (Node z : suborder) { - if (this.knowledge.isRequired(y.getName(), z.getName())) { - if (!required.containsKey(y)) required.put(y, new HashSet<>()); - required.get(y).add(z); - } - } - } + + List bestSuborder = null; + double score, bestScore = Double.NEGATIVE_INFINITY; + boolean improved; for (int i = 0; i < this.numStarts; i++) { shuffle(suborder); makeValidKnowledgeOrder(suborder); - double s1, s2, s3; - s1 = update(prefix, suborder); + do { - s2 = s1; - do { - s3 = s1; - for (Node x : new ArrayList<>(suborder)) { - if (betterMutation(prefix, suborder, required, x)) { - s1 = update(prefix, suborder); - } - } - } while (s1 > s3); - do { - s3 = s1; - List Z = new ArrayList<>(prefix); - Z.addAll(suborder); - 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); - } while (s1 > s2); - - if (s1 > bestScore) { + improved = false; + for (Node x : new ArrayList<>(suborder)) { + if (betterMutation(prefix, suborder, x)) improved = true; + } + } while (improved); + + if (this.bes != null) bes(prefix, suborder); + + score = update(prefix, suborder); + if (score > bestScore) { bestSuborder = new ArrayList<>(suborder); - bestScore = s1; + bestScore = score; } } - for (int i = 0; i < suborder.size(); i++) { - suborder.set(i, bestSuborder.get(i)); - } + suborder.clear(); + suborder.addAll(bestSuborder); update(prefix, suborder); } - /** - * Sets the knowledge to be used in the search. - * - * @param knowledge This knowledge. - */ - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - this.bes.setKnowledge(knowledge); - } - - /** - * Sets the number of times the procedure should be restarted in search of a better - * score. - * - * @param numStarts This number. - */ - public void setNumStarts(int numStarts) { - this.numStarts = numStarts; - } - - /** - * Returns the variables. - * - * @return A list of these. - */ - @Override - public List getVariables() { - return variables; - } - - /** - * Returns a map from nodes to their parents. - * - * @return This map. - */ - @Override - public Map> getParents() { - return parents; - } - /** - * Returns the score being used for the search. - * - * @return This score. - * @see Score - */ - @Override - public Score getScore() { - return score; - } + private boolean betterMutation(List prefix, List suborder, Node x) { + Set all = new HashSet<>(suborder); + all.addAll(prefix); - private boolean betterMutation(List prefix, List suborder, Map> required, Node x) { ListIterator itr = suborder.listIterator(); double[] scores = new double[suborder.size() + 1]; - int i = 0; - Set Z = new HashSet<>(prefix); + + int i = 0; double score = 0; int curr = 0; while (itr.hasNext()) { Node z = itr.next(); - scores[i++] = gsts.get(x).trace(new HashSet<>(Z), new HashSet<>()) + score; + + // THE CORRECTNESS OF THIS NEEDS TO BE VERIFIED + if (this.knowledge.isRequired(x.getName(), z.getName())) break; + + scores[i++] = this.gsts.get(x).trace(Z, all) + score; if (z != x) { - score += gsts.get(z).trace(new HashSet<>(Z), new HashSet<>()); + score += this.gsts.get(z).trace(Z, all); Z.add(z); } else curr = i - 1; } - scores[i] = gsts.get(x).trace(new HashSet<>(Z), new HashSet<>()) + score; + + scores[i] = this.gsts.get(x).trace(Z, all) + score; + int best = i; Z.add(x); score = 0; - int best = i; while (itr.hasPrevious()) { Node z = itr.previous(); + + // THE CORRECTNESS OF THIS NEEDS TO BE VERIFIED + if(this.knowledge.isRequired(z.getName(), x.getName())) break; + if (z != x) { Z.remove(z); - score += gsts.get(z).trace(new HashSet<>(Z), new HashSet<>()); + score += gsts.get(z).trace(Z, all); } + scores[--i] += score; - if (scores[i] > scores[best] && !violatesKnowledge(suborder, required)) best = i; + if (scores[i] + 1e-6 > scores[best]) best = i; } - if (best == curr) return false; - else if (best > curr) best--; - - suborder.remove(curr); + if (scores[curr] + 1e-6 > scores[best]) return false; + if (best > curr) best--; + suborder.remove(x); suborder.add(best, x); return true; } + public void useBes(boolean use) { + this.bes = null; + if (use) { + this.bes = new BesPermutation(this.score); + this.bes.setVerbose(false); + } + } + + private void bes(List prefix, List suborder) { + List all = new ArrayList<>(prefix); + all.addAll(suborder); + + Graph graph = PermutationSearch.getGraph(all, this.parents, this.knowledge, true); + this.bes.bes(graph, all, suborder); + graph.paths().makeValidOrder(suborder); + } + private double update(List prefix, List suborder) { double score = 0; + Set all = new HashSet<>(suborder); + all.addAll(prefix); - Iterator itr = suborder.iterator(); Set Z = new HashSet<>(prefix); - while (itr.hasNext()) { - Node x = itr.next(); - parents.get(x).clear(); - scores.put(x, gsts.get(x).trace(new HashSet<>(Z), parents.get(x))); - score += scores.get(x); + + for (Node x : suborder) { + Set parents = this.parents.get(x); + parents.clear(); + score += this.gsts.get(x).trace(Z, all, parents); Z.add(x); } return score; } - private boolean violatesKnowledge(List suborder, Map> required) { - for (int i = 0; i < suborder.size(); i++) { - Node y = suborder.get(i); - if (required.containsKey(y)) { - for (Node z : required.get(y)) { - if (suborder.subList(0, i).contains(z)) { - return true; - } - } - } - } - return false; - } - private void makeValidKnowledgeOrder(List order) { if (!this.knowledge.isEmpty()) { order.sort((a, b) -> { @@ -264,7 +194,29 @@ private void makeValidKnowledgeOrder(List order) { }); } } -} + @Override + public void setKnowledge(Knowledge knowledge) { + this.knowledge = knowledge; + this.bes.setKnowledge(knowledge); + } + + public void setNumStarts(int numStarts) { + this.numStarts = numStarts; + } + + @Override + public List getVariables() { + return this.variables; + } + @Override + public Map> getParents() { + return this.parents; + } + @Override + public Score getScore() { + return this.score; + } +} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index 3fa398a5a4..cc6e523c7e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -77,12 +77,12 @@ public Graph search() { end++; } if (!this.knowledge.isTierForbiddenWithin(i)) { - tasks.add(new int[]{start, end}); + tasks.add(new int[] {start, end}); } } } else { this.order.addAll(this.variables); - tasks.add(new int[]{0, this.variables.size()}); + tasks.add(new int[] {0, this.variables.size()}); } for (int[] task : tasks) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 305a9b3b49..38e4abe205 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -48,9 +48,9 @@ public class Sp implements SuborderSearch { private Map gsts; private Knowledge knowledge = new Knowledge(); + /** * This algorithm will work with an arbitrary score. - * * @param score The Score to use. */ public Sp(Score score) { @@ -108,52 +108,9 @@ public void searchSuborder(List prefix, List suborder, Map getVariables() { - return variables; - } - - /** - * Returns the map from nodes to their parents. - * - * @return This map. - */ - @Override - public Map> getParents() { - return parents; - } - - /** - * Returns the score being used for this search. - * - * @return This score. - * @see Score - */ - @Override - public Score getScore() { - return score; - } - private void makeValidKnowledgeOrder(List order) { if (!this.knowledge.isEmpty()) { order.sort((a, b) -> { @@ -179,99 +136,119 @@ private boolean violatesKnowledge(List suborder, Map> requ return false; } + @Override + public void setKnowledge(Knowledge knowledge) { + this.knowledge = knowledge; + } + private double update(List prefix, List suborder) { double score = 0; + Set all = new HashSet<>(suborder); + all.addAll(prefix); - Iterator itr = suborder.iterator(); Set Z = new HashSet<>(prefix); - while (itr.hasNext()) { - Node x = itr.next(); - parents.get(x).clear(); - scores.put(x, gsts.get(x).trace(new HashSet<>(Z), parents.get(x))); - score += scores.get(x); + + for (Node x : suborder) { + Set parents = this.parents.get(x); + parents.clear(); + score += this.gsts.get(x).trace(Z, all, parents); Z.add(x); } return score; } - private static class SwapIterator implements Iterator { - private int[] next; - private final int n; - private final int[] perm; - private final int[] dirs; - - public SwapIterator(int size) { - this.n = size; - if (this.n <= 0) { - this.perm = null; - this.dirs = null; - } else { - this.perm = new int[n]; - this.dirs = new int[n]; - for (int i = 0; i < n; i++) { - this.perm[i] = i; - this.dirs[i] = -1; - } - this.dirs[0] = 0; + @Override + public List getVariables() { + return variables; + } + + @Override + public Map> getParents() { + return parents; + } + + @Override + public Score getScore() { + return score; + } + +} + +class SwapIterator implements Iterator { + private int[] next; + private final int n; + private final int[] perm; + private final int[] dirs; + + public SwapIterator(int size) { + this.n = size; + if (this.n <= 0) { + this.perm = null; + this.dirs = null; + } else { + this.perm = new int[n]; + this.dirs = new int[n]; + for (int i = 0; i < n; i++) { + this.perm[i] = i; + this.dirs[i] = -1; } + this.dirs[0] = 0; } + } - @Override - public int[] next() { - int[] next = makeNext(); - this.next = null; - return next; - } + @Override + public int[] next() { + int[] next = makeNext(); + this.next = null; + return next; + } - @Override - public boolean hasNext() { - return makeNext() != null; - } + @Override + public boolean hasNext() { + return makeNext() != null; + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } - private int[] makeNext() { - if (this.next != null) return this.next; - if ((this.dirs == null) || (this.perm == null)) return null; + private int[] makeNext() { + if (this.next != null) return this.next; + if ((this.dirs == null) || (this.perm == null)) return null; - int i = -1; - int x = -1; - for (int j = 0; j < n; j++) - if ((this.dirs[j] != 0) && (this.perm[j] > x)) { - x = this.perm[j]; - i = j; - } + int i = -1; + int x = -1; + for (int j = 0; j < n; j++) + if ((this.dirs[j] != 0) && (this.perm[j] > x)) { + x = this.perm[j]; + i = j; + } - if (i == -1) return null; + if (i == -1) return null; - int k = i + this.dirs[i]; - this.next = new int[]{i, k}; + int k = i + this.dirs[i]; + this.next = new int[] {i, k}; - swap(i, k, this.dirs); - swap(i, k, this.perm); + swap(i, k, this.dirs); + swap(i, k, this.perm); - if ((k == 0) || (k == n - 1) || (this.perm[k + this.dirs[k]] > x)) - this.dirs[k] = 0; + if ((k == 0) || (k == n - 1) || (this.perm[k + this.dirs[k]] > x)) + this.dirs[k] = 0; - for (int j = 0; j < n; j++) - if (this.perm[j] > x) - this.dirs[j] = (j < k) ? +1 : -1; + for (int j = 0; j < n; j++) + if (this.perm[j] > x) + this.dirs[j] = (j < k) ? +1 : -1; - return this.next; - } + return this.next; + } - private static void swap(int i, int j, int[] arr) { - int x = arr[i]; - arr[i] = arr[j]; - arr[j] = x; - } + private static void swap(int i, int j, int[] arr) { + int x = arr[i]; + arr[i] = arr[j]; + arr[j] = x; } } - - diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java index eded419fea..726bd9728e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java @@ -44,6 +44,7 @@ public class BesPermutation { private final Score score; private Knowledge knowledge = new Knowledge(); private boolean verbose = true; + private int depth = -1; /** * Constructor. @@ -80,12 +81,23 @@ public void setVerbose(boolean verbose) { * @param knowledge This knowledge. */ public void setKnowledge(Knowledge knowledge) { - this.knowledge = new 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); + } } - /** - * Runs BES. - */ public void bes(Graph graph, List order, List suborder) { Map hashIndices = new HashMap<>(); SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>(); @@ -222,9 +234,13 @@ private double scoreGraphChange(Node x, Node y, Set parents, Map revertToCPDAG(Graph graph) { MeekRules rules = new MeekRules(); - rules.setKnowledge(knowledge); + rules.setKnowledge(getKnowledge()); rules.setAggressivelyPreventCycles(true); boolean meekVerbose = false; rules.setVerbose(meekVerbose); @@ -405,10 +421,10 @@ private int getChunkSize(int n) { } private void calculateArrowsBackward(Node a, Node b, Graph - graph, Map arrowsMapBackward, Map hashIndices, int[] arrowIndex, SortedSet sortedArrowsBack) { + graph, Map arrowsMapBackward, Map hashIndices, + int[] arrowIndex, SortedSet sortedArrowsBack) { if (existsKnowledge()) { - if (!knowledge.noEdgeRequired(a.getName(), b.getName())) { + if (!getKnowledge().noEdgeRequired(a.getName(), b.getName())) { return; } } @@ -423,7 +439,6 @@ private void calculateArrowsBackward(Node a, Node b, Graph if (storedConfig != null && storedConfig.equals(config)) return; arrowsMapBackward.put(directedEdge(a, b), new ArrowConfigBackward(naYX, parents)); - int depth = -1; int _depth = min(depth, _naYX.size()); final SublistGenerator gen = new SublistGenerator(_naYX.size(), _depth);//_naYX.size()); @@ -489,6 +504,7 @@ public int hashCode() { } } + private static class Arrow implements Comparable { private final double bump; @@ -568,13 +584,4 @@ public Set getParents() { return parents; } } - - private void buildIndexing(List nodes, Map hashIndices) { - - int i = -1; - - for (Node n : nodes) { - hashIndices.put(n, ++i); - } - } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java index 70e998aa1b..20eaaf30ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java @@ -6,13 +6,6 @@ import java.util.*; -/** - *

    Provides a tree-based score-caching data structure useful for permutation searches. - * The use of this caching data structure speeds these algorithms up - * significantly.

    - * - * @author bryanandrews - */ public class GrowShrinkTree { private final Score score; private final Map index; @@ -22,14 +15,7 @@ public class GrowShrinkTree { private List forbidden; private GSTNode root; - /** - * Constructor for a grow-shrink tree. - * - * @param score A score. - * @param index A node-index map. - * @param node The root node. - */ - public GrowShrinkTree(Score score, Map index, Node node) { + public GrowShrinkTree(Score score, Map index, Node node) { this.score = score; this.index = index; this.node = node; @@ -39,108 +25,52 @@ public GrowShrinkTree(Score score, Map index, Node node) { this.forbidden = new ArrayList<>(); } - /** - * Trace down the tree and updates parents. - * - * @param prefix The prefix (mutated during call). - * @param parents The parents (modified in place). - * @return The grow-shrink score. - */ - public double trace(Set prefix, Set parents) { - return this.root.trace(prefix, parents); + public double trace(Collection prefix, Collection all) { + Set available = new HashSet<>(all); + available.remove(this.node); + this.forbidden.forEach(available::remove); + return this.root.trace(new HashSet<>(prefix), available, new HashSet<>()); + } + + public double trace(Collection prefix, Collection all, Set parents) { + Set available = new HashSet<>(all); + available.remove(this.node); + this.forbidden.forEach(available::remove); + return this.root.trace(new HashSet<>(prefix), available, parents); } - /** - * Gets the root node. - * - * @return The root node. - */ public Node getNode() { return this.node; } - /** - * Gets the index of a node. - * - * @param node The node. - * @return The index. - */ public Integer getIndex(Node node) { return this.index.get(node); } - /** - * Wraps the localScore call of the score. - * - * @return The value return by the score. - */ public Double localScore() { return this.score.localScore(this.nodeIndex); } - /** - * Wraps the localScore call of the score. - * - * @param X The parents. - * @return The value return by the score. - */ public Double localScore(int[] X) { return this.score.localScore(this.nodeIndex, X); } - /** - * True if node is a required parent. - * - * @param node The node. - * @return The boolean. - */ public boolean isRequired(Node node) { return this.required.contains(node); } - /** - * True if node is a forbidden parent. - * - * @param node The node. - * @return The boolean. - */ public boolean isForbidden(Node node) { return this.forbidden.contains(node); } - /** - * Gets the list of variables. - * - * @return The list of variables. - */ public List getVariables() { return this.score.getVariables(); } - /** - * Gets the list of required parents. - * - * @return The list of required parents. - */ - public List getRequired() { - return this.required; - } + public List getRequired() { return this.required; } - /** - * Gets the list of forbidden parents. - * - * @return The list of forbidden parents. - */ - public List getForbidden() { - return this.forbidden; - } + public List getForbidden() { return this.forbidden; } - /** - * Sets the background knowledge. - * - * @param required A list of required parents. - * @param forbidden A list of forbidden parents. - */ public void setKnowledge(List required, List forbidden) { this.root = new GSTNode(this); this.required = required; @@ -180,16 +110,14 @@ private GSTNode(GrowShrinkTree tree, Node add, Set parents) { this.growScore = this.tree.localScore(X); } - public double trace(Set prefix, Set parents) { + public double trace(Set prefix, Set available, Set parents) { if (!this.grow) { this.grow = true; this.branches = new ArrayList<>(); List required = new ArrayList<>(); - for (Node add : this.tree.getVariables()) { - if (parents.contains(add) || add == this.tree.getNode()) continue; - if (this.tree.isForbidden(add)) continue; + for (Node add : available) { GSTNode branch = new GSTNode(this.tree, add, parents); if (this.tree.isRequired(add)) required.add(branch); else if (branch.getGrowScore() >= this.growScore) this.branches.add(branch); @@ -201,10 +129,11 @@ public double trace(Set prefix, Set parents) { for (GSTNode branch : this.branches) { Node add = branch.getAdd(); + available.remove(add); if (prefix.contains(add)) { prefix.remove(add); parents.add(add); - return branch.trace(prefix, parents); + return branch.trace(prefix, available, parents); } } @@ -237,7 +166,7 @@ public double trace(Set prefix, Set parents) { parents.remove(best); this.remove.add(best); } - } while (best != null); + } while(best != null); } parents.removeAll(this.remove); From a8100fbcb8b047b47ce6fca141507abb48849e48 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 09:07:29 -0400 Subject: [PATCH 402/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../src/main/java/edu/cmu/tetrad/search/Boss.java | 12 ++++++++++-- .../edu/cmu/tetrad/search/utils/GrowShrinkTree.java | 2 +- .../edu/cmu/tetrad/search/utils/TeyssierScorer.java | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) 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 6f3961e0cb..2b0da5fef8 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 @@ -91,7 +91,11 @@ public void searchSuborder(List prefix, List suborder, Map order) { @Override public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; - this.bes.setKnowledge(knowledge); + + if (this.bes != null) { + this.bes.setKnowledge(knowledge); + } } public void setNumStarts(int numStarts) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java index 20eaaf30ea..709c55383f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GrowShrinkTree.java @@ -7,7 +7,7 @@ import java.util.*; public class GrowShrinkTree { - private final Score score; + private final Score score; private final Map index; private final Node node; private final int nodeIndex; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java index c268d56184..3bc46641db 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TeyssierScorer.java @@ -665,7 +665,7 @@ private Pair getGrowShrinkScore(int p) { Node n = this.pi.get(p); Set prefix = new HashSet<>(getPrefix(p)); LinkedHashSet parents = new LinkedHashSet<>(); - double sMax = this.trees.get(n).trace(prefix, parents); + double sMax = this.trees.get(n).trace(prefix, this.variables, parents); return new Pair(parents, Double.isNaN(sMax) ? Double.NEGATIVE_INFINITY : sMax); } From 83d02aa5403b637e33260c97dd7ccd0d3e4f159e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 15:19:35 -0400 Subject: [PATCH 403/464] Fixing documentation and doing general cleamup, etc. Putting code up up to standards into a separate package. --- .../tetrad/algcomparison/score/DegenerateGaussianBicScore.java | 2 +- .../edu/cmu/tetrad/search/score/DegenerateGaussianScore.java | 2 ++ tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) 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 9f4b58530e..125a2d4d52 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 @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.score.DegenerateGaussianScore; +import edu.cmu.tetrad.search.DegenerateGaussianScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index a113deb361..29ec8002b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.score.SemBicScore; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.RealMatrix; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 081213cd78..29fb6a620f 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -49,7 +49,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.score.DegenerateGaussianScore; +import edu.cmu.tetrad.search.DegenerateGaussianScore; import edu.cmu.tetrad.search.score.GraphScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; From dad242d79a6240f27f3abe4b8c5fdb937b2fa77a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 19:31:07 -0400 Subject: [PATCH 404/464] Issue with DGS. --- .../edu/cmu/tetrad/search/score/DegenerateGaussianScore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 29ec8002b9..9670143066 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -142,7 +142,7 @@ public DegenerateGaussianScore(DataSet dataSet) { /** * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model. - * + *s * @param i The child indes. * @param parents The indices of the parents. */ From c6628f084d40c839e2bb7dce10c3d27a4b25a822 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 22:19:55 -0400 Subject: [PATCH 405/464] Ruben fixes. --- .../src/main/java/edu/cmu/tetrad/search/Boss.java | 10 +++++----- .../src/main/java/edu/cmu/tetrad/search/Cfci.java | 6 +++--- .../src/main/java/edu/cmu/tetrad/search/Cpc.java | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) 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 2b0da5fef8..e46e901c8f 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 @@ -12,12 +12,12 @@ import static edu.cmu.tetrad.util.RandomUtil.shuffle; /** - *

    Implements an algorithm called BOSS (Bost order Score Search), which - * intercalates calls to a permutation discovery step with calls to BES, in order - * to find an optimal permutation implying a DAG and, therefore a CPDAG that is + *

    Implements an algorithm called BOSS (Best Order Score Search), which + * intercalates calls to a permutation discovery step with calls to BES in order + * to find an optimal permutation implying a DAG and, therefore, a CPDAG that is * highly accurate. This follows up on work by Raskutti and Uhler on the SP * (Sparsest Permutation) algorithm and work by Lam, Andrews, and Ramsey on the - * GRaSP algorithm and is currently under development.

    + * GRaSP algorithm is currently under development.

    * *

    Knowledge can be used with this search. If tiered knowledge is used, then the procedure * is carried out for each tier separately, given the variable preceding that tier, which @@ -27,7 +27,7 @@ *

    This class is meant to be used in the context of the PermutationSearch class (see). * the proper use is PermutationSearch search = new PermutationSearch(new Sp(score));

    * - *

    This class is configured to respect knowledge of forbidden and required + *

    This class is configured to respect the knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    * * @author bryanandrews diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 04d2d2ab15..57b10ad293 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -36,15 +36,15 @@ /** * Adjusts FCI (see) to use conservative orientation as in CPC (see). Because the - * collider orienatation is conservative, there may be ambiguous triples; these + * collider orientatation is conservative, there may be ambiguous triples; these * may be retrieved using that accessor method. * *

    This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

    * - * @author Erin Korber, June 2004 - * @author Alex Smith, December 2008 + * @author josephramsey * @see Fci + * @see Cpc * @see #getAmbiguousTriples() * @see Knowledge */ 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 8e2e65c718..e7bf5011a8 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 @@ -40,7 +40,7 @@ *

    Implements a convervative version of PC, in which the Markov condition is assumed * but faithfulness is tested locally. The reference is here:

    * - *

    Ramsey, J., Zhang, J., & Spirtes, P. L. (2012). Adjacency-faithfulness and + *

    Ramsey, J., Zhang, J., & Spirtes, P. L. (2012). Adjacency-faithfulness and * conservative causal inference. arXiv preprint arXiv:1206.6843.

    * *

    This class is configured to respect knowledge of forbidden and required From 23dcb2169bf8af15a8f9820874bbec8fda8599cf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 22:26:44 -0400 Subject: [PATCH 406/464] DG fixes --- .../tetrad/algcomparison/score/DegenerateGaussianBicScore.java | 2 +- .../edu/cmu/tetrad/search/score/DegenerateGaussianScore.java | 2 +- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 125a2d4d52..9f4b58530e 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 @@ -26,7 +26,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.DegenerateGaussianScore; +import edu.cmu.tetrad.search.score.DegenerateGaussianScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 9670143066..9f698c5b35 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -19,7 +19,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////////////// -package edu.cmu.tetrad.search; +package edu.cmu.tetrad.search.score; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Node; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index 29fb6a620f..081213cd78 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java @@ -49,7 +49,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.IndependenceFacts; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.DegenerateGaussianScore; +import edu.cmu.tetrad.search.score.DegenerateGaussianScore; import edu.cmu.tetrad.search.score.GraphScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; From 6bce7f331dc4eb1e26f6b21ce1d4ec2ac8103d3b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 9 May 2023 23:02:25 -0400 Subject: [PATCH 407/464] Ruben typo fixes. --- .../src/main/java/edu/cmu/tetrad/search/FastIca.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/FciMax.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java | 9 ++++----- .../src/main/java/edu/cmu/tetrad/search/FgesMb.java | 2 +- .../main/java/edu/cmu/tetrad/search/utils/MeekRules.java | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index 63ee54746c..b01073c027 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -38,7 +38,7 @@ * complex numbers, whereeas here it is restricted to real numbers. A * useful reference is this:

    * - *

    Oja, E., & Hyvarinen, A. (2000). Independent component analysis: + *

    Oja, E., & Hyvarinen, A. (2000). Independent component analysis: * algorithms and applications. Neural networks, 13(4-5), 411-430.

    * *

    The documention of the R version is as follows, all of which is true of this diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index 6f6a94647d..ab7d07aa12 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -52,7 +52,7 @@ *

    Spirtes, P., Glymour, C. N., Scheines, R., & Heckerman, D. (2000). Causation, * prediction, and search. MIT press.

    * - *

    The algorithm with the Zhang final orintation rules was given in this reference:

    + *

    The algorithm with the Zhang final orientation rules was given in this reference:

    * *

    Zhang, J. (2008). On the completeness of orientation rules for causal discovery in the presence * of latent confounders and selection bias. Artificial Intelligence, 172(16-17), 1873-1896.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index b691dfbf27..81aa01952d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -38,7 +38,7 @@ *

    Modifies FCI to do orientation of unshielded colliders (X*-*Y*-*Z with X and Z not adjacent) * using the max-P rule (see the PC-Max algorithm). This reference is relevant:

    * - *

    Raghu, V. K., Zhao, W., Pu, J., Leader, J. K., Wang, R., Herman, J., ... & Wilson, D. O. + *

    Raghu, V. K., Zhao, W., Pu, J., Leader, J. K., Wang, R., Herman, J., ... & Wilson, D. O. * (2019). Feasibility of lung cancer prediction from low-dose CT scan and smoking factors using * causal models. Thorax, 74(7), 643-649.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 2a7c48e00b..0d1a7664c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -51,7 +51,7 @@ * optimizations that allow it to scale accurately to thousands of variables * for the sparse case. The reference is this:

    * - *

    Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). + *

    Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). * A million variables and more: the fast greedy equivalence search algorithm * for learning high-dimensional graphical causal models, with an application * to functional magnetic resonance images. International journal of data science @@ -67,10 +67,9 @@ * *

    To speed things up, it has been assumed that variables X and Y with zero * correlation do not correspond to edges in the graph. This is a restricted - * form of the heuristicSpeedup assumption, something GES does not assume. This - * the graph. This is a restricted form of the heuristicSpeedup assumption, - * something GES does not assume. This heuristicSpeedup assumption needs to be - * explicitly turned on using setHeuristicSpeedup(true).

    + * form of the heuristic speedup assumption, something GES does not assume. + * This heuristicSpeedup assumption needs to be explicitly turned on using + * setHeuristicSpeedup(true).

    * *

    A number of other optimizations were also. See code for details.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index d9829a729e..faa681278f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -45,7 +45,7 @@ * with the target X (or, respectively, the targets X1,...,Xn). The * reference is this:

    * - *

    Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). + *

    Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). * A million variables and more: the fast greedy equivalence search algorithm * for learning high-dimensional graphical causal models, with an application * to functional magnetic resonance images. International journal of data science diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java index 12bd1468ac..62df488269 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java @@ -155,7 +155,7 @@ public void setVerbose(boolean verbose) { /** * Sets whether orientations in the graph should be reverted to its - * unshielded colliders before performing any Meek rule orintations. + * unshielded colliders before performing any Meek rule orientations. * * @param revertToUnshieldedColliders True if so. */ From 00044d00b9df81d2df6c7334c5407e48597553c6 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Wed, 10 May 2023 14:44:13 -0500 Subject: [PATCH 408/464] added erichs orientation stats --- .../algcomparison/examples/TestBoss.java | 14 ++- .../statistic/OrientationPrecision.java | 38 ++++++++ .../statistic/OrientationRecall.java | 38 ++++++++ .../statistic/utils/OrientationConfusion.java | 94 +++++++++++++++++++ 4 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java 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 57183a3f67..4688b1d19a 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 @@ -28,7 +28,9 @@ 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.DegenerateGaussianBicScore; import edu.cmu.tetrad.algcomparison.score.SemBicScore; +import edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation; import edu.cmu.tetrad.algcomparison.simulation.SemSimulation; import edu.cmu.tetrad.algcomparison.simulation.Simulations; import edu.cmu.tetrad.algcomparison.statistic.*; @@ -43,7 +45,7 @@ public class TestBoss { public static void main(String... args) { Parameters parameters = new Parameters(); - parameters.set(Params.NUM_RUNS, 10); + parameters.set(Params.NUM_RUNS, 1); parameters.set(Params.DIFFERENT_GRAPHS, true); parameters.set(Params.NUM_MEASURES, 60); parameters.set(Params.AVG_DEGREE, 6); @@ -67,13 +69,15 @@ public static void main(String... args) { statistics.add(new ElapsedCpuTime()); Algorithms algorithms = new Algorithms(); - algorithms.add(new Fges(new SemBicScore())); - algorithms.add(new Boss(new SemBicScore())); - algorithms.add(new Grasp(new FisherZ(), new SemBicScore())); +// algorithms.add(new Fges(new SemBicScore())); + algorithms.add(new Fges(new DegenerateGaussianBicScore())); +// algorithms.add(new Boss(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())); +// simulations.add(new SemSimulation(new RandomForward())); + simulations.add(new LeeHastieSimulation(new RandomForward())); Comparison comparison = new Comparison(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java new file mode 100644 index 0000000000..6c5948ca35 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java @@ -0,0 +1,38 @@ +package edu.cmu.tetrad.algcomparison.statistic; + +import edu.cmu.tetrad.algcomparison.statistic.utils.AdjacencyConfusion; +import edu.cmu.tetrad.algcomparison.statistic.utils.OrientationConfusion; +import edu.cmu.tetrad.data.DataModel; +import edu.cmu.tetrad.graph.Graph; + +/** + * The orientation precision. + * + * @author bryanandrews, osephramsey + */ +public class OrientationPrecision implements Statistic { + static final long serialVersionUID = 23L; + + @Override + public String getAbbreviation() { + return "OP"; + } + + @Override + public String getDescription() { + return "Orientation Precision"; + } + + @Override + public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { + OrientationConfusion oriConfusion = new OrientationConfusion(trueGraph, estGraph); + int oriTp = oriConfusion.getTp(); + int oriFp = oriConfusion.getFp(); + return oriTp / (double) (oriTp + oriFp); + } + + @Override + public double getNormValue(double value) { + return value; + } +} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java new file mode 100644 index 0000000000..8b03918be6 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java @@ -0,0 +1,38 @@ +package edu.cmu.tetrad.algcomparison.statistic; + +import edu.cmu.tetrad.algcomparison.statistic.utils.AdjacencyConfusion; +import edu.cmu.tetrad.algcomparison.statistic.utils.OrientationConfusion; +import edu.cmu.tetrad.data.DataModel; +import edu.cmu.tetrad.graph.Graph; + +/** + * The orientation recall. + * + * @author bryanandrews, josephramsey + */ +public class OrientationRecall implements Statistic { + static final long serialVersionUID = 23L; + + @Override + public String getAbbreviation() { + return "OR"; + } + + @Override + public String getDescription() { + return "Orientation Recall"; + } + + @Override + public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { + OrientationConfusion oriConfusion = new OrientationConfusion(trueGraph, estGraph); + int oriTp = oriConfusion.getTp(); + int oriFn = oriConfusion.getFn(); + return oriTp / (double) (oriTp + oriFn); + } + + @Override + public double getNormValue(double value) { + return value; + } +} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java new file mode 100644 index 0000000000..521bfae1e9 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java @@ -0,0 +1,94 @@ +package edu.cmu.tetrad.algcomparison.statistic.utils; + +import edu.cmu.tetrad.graph.*; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * A confusion matrix for orientations: + * + * True | Estimated | Orientation + * -------------------------------- + * a <- b | a <- b | tp, tn + * | a -> b | fp, fn + * | a −− b | fn + * | a .. b | fn + * -------------------------------- + * a .. b | a <- b | fp + * | a -> b | fp + * | a −− b | + * | a .. b | + * + * @author bryanandrews, josephramsey + */ +public class OrientationConfusion { + private int tp; + private int fp; + private int fn; + private int tn; + + public OrientationConfusion(Graph truth, Graph est) { + this.tp = 0; + this.fp = 0; + this.fn = 0; + this.tn = 0; + + for (Edge edge : truth.getEdges()) { + if (!edge.isDirected()) continue; + Node a = edge.getNode1(); + Node b = edge.getNode1(); + + if (!est.isAdjacentTo(a, b)) { + this.fp++; + continue; + } + + Edge other = est.getEdge(a, b); + boolean m1 = edge.getEndpoint1() == other.getProximalEndpoint(a); + boolean m2 = edge.getEndpoint1() == other.getProximalEndpoint(a); + + if (m1 && m2) { + this.tp++; + this.tn++; + continue; + } + + if (!m1 && !m2) { + this.fp++; + this.fn++; + continue; + } + + if (other.getEndpoint1() != Endpoint.TAIL) continue; + if (other.getEndpoint2() != Endpoint.TAIL) continue; + this.fp++; + } + + for (Edge edge : est.getEdges()) { + if (!edge.isDirected()) continue; + Node a = edge.getNode1(); + Node b = edge.getNode1(); + + if (!truth.isAdjacentTo(a, b)) this.fp++; + } + } + + public int getTp() { + return this.tp; + } + + public int getFp() { + return this.fp; + } + + public int getFn() { + return this.fn; + } + + public int getTn() { + return this.tn; + } + +} From b39a89378b6b3f91e977c1d2751794e36f9b00f9 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Wed, 10 May 2023 15:08:45 -0500 Subject: [PATCH 409/464] fixed erichs orientation stats --- .../statistic/utils/OrientationConfusion.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java index 521bfae1e9..c708a4b675 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java @@ -21,6 +21,8 @@ * | a −− b | * | a .. b | * + * The true graph should be a DAG! + * * @author bryanandrews, josephramsey */ public class OrientationConfusion { @@ -38,16 +40,16 @@ public OrientationConfusion(Graph truth, Graph est) { for (Edge edge : truth.getEdges()) { if (!edge.isDirected()) continue; Node a = edge.getNode1(); - Node b = edge.getNode1(); + Node b = edge.getNode2(); if (!est.isAdjacentTo(a, b)) { - this.fp++; + this.fn++; continue; } Edge other = est.getEdge(a, b); boolean m1 = edge.getEndpoint1() == other.getProximalEndpoint(a); - boolean m2 = edge.getEndpoint1() == other.getProximalEndpoint(a); + boolean m2 = edge.getEndpoint2() == other.getProximalEndpoint(b); if (m1 && m2) { this.tp++; @@ -63,13 +65,13 @@ public OrientationConfusion(Graph truth, Graph est) { if (other.getEndpoint1() != Endpoint.TAIL) continue; if (other.getEndpoint2() != Endpoint.TAIL) continue; - this.fp++; + this.fn++; } for (Edge edge : est.getEdges()) { if (!edge.isDirected()) continue; Node a = edge.getNode1(); - Node b = edge.getNode1(); + Node b = edge.getNode2(); if (!truth.isAdjacentTo(a, b)) this.fp++; } From a2379bcf3c162992a34f3c21929d8e8583065e9d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 11 May 2023 15:07:54 -0400 Subject: [PATCH 410/464] Ruben typo fixes. --- .../cmu/tetrad/graph/GraphPersistence.java | 2 +- .../edu/cmu/tetrad/test/TestRubenData.java | 134 ++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java 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 c3f636839e..b2c2a43e8b 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 @@ -57,7 +57,7 @@ public static Graph loadGraphRuben(File file) { final String missingValueMarker = "*"; final boolean hasHeader = false; - DataSet dataSet = SimpleDataLoader.loadContinuousData(file, commentMarker, quoteCharacter, missingValueMarker, hasHeader, Delimiter.TAB); + DataSet dataSet = SimpleDataLoader.loadContinuousData(file, commentMarker, quoteCharacter, missingValueMarker, hasHeader, Delimiter.COMMA); List nodes = dataSet.getVariables(); Graph graph = new EdgeListGraph(nodes); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java new file mode 100644 index 0000000000..95729a7160 --- /dev/null +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java @@ -0,0 +1,134 @@ +package edu.cmu.tetrad.test; + +import edu.cmu.tetrad.algcomparison.Comparison; +import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; +import edu.cmu.tetrad.algcomparison.graph.RandomForward; +import edu.cmu.tetrad.algcomparison.independence.FisherZ; +import edu.cmu.tetrad.algcomparison.simulation.SemSimulation; +import edu.cmu.tetrad.algcomparison.simulation.Simulations; +import edu.cmu.tetrad.algcomparison.statistic.*; +import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.SimpleDataLoader; +import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphPersistence; +import edu.cmu.tetrad.graph.GraphUtils; +import edu.cmu.tetrad.search.Boss; +import edu.cmu.tetrad.search.PermutationSearch; +import edu.cmu.tetrad.search.score.SemBicScore; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.util.MillisecondTimes; +import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetrad.util.Params; +import edu.pitt.dbmi.data.reader.Delimiter; + +import java.io.File; +import java.io.IOException; +import java.text.DecimalFormat; +import java.text.NumberFormat; + +public class TestRubenData { + + public static void main(String... arge) { + new TestRubenData().test2(); + } + + public void test1() { + NumberFormat nf = new DecimalFormat("0.000"); + int count = 40; + double aps = 0.0, ars = 0.0, ops = 0.0, ors = 0.0, bds = 0.0, es = 0.0; // sums. + + for (int index = 0; index < count; index++) { + String path1 = "/Users/josephramsey/Downloads/ruben_data/bold_data/bold_data_" + index + ".txt"; + String path2 = "/Users/josephramsey/Downloads/ruben_data/graphs/graph_" + index + ".txt"; + + try { + DataSet data = SimpleDataLoader.loadContinuousData(new File(path1), + "//", + '\"', "*", true, Delimiter.COMMA); + + Graph graph = GraphPersistence.loadGraphTxt(new File(path2)); + + graph = GraphSearchUtils.cpdagForDag(graph); + + SemBicScore score = new SemBicScore(data); + score.setPenaltyDiscount(2); +// Fges alg = new Fges(score); + PermutationSearch alg = new PermutationSearch(new Boss(score)); + + long start = MillisecondTimes.cpuTimeMillis(); + Graph g = alg.search(); + long stop = MillisecondTimes.cpuTimeMillis(); + double elapsed = (stop - start) / 1000.0; + + g = GraphUtils.replaceNodes(g, graph.getNodes()); + + double ap = new AdjacencyPrecision().getValue(graph, g, data); + double ar = new AdjacencyRecall().getValue(graph, g, data); + double op = new OrientationPrecision().getValue(graph, g, data); + double or = new OrientationRecall().getValue(graph, g, data); + double bd = new BicDiff().getValue(graph, g, data); + + aps += ap; + ars += ar; + ops += op; + ors += or; + bds += bd; + + es += elapsed; + + System.out.println(index + ". AP = " + nf.format(ap) + " AR = " + nf.format(ar) + " OP = " + nf.format(op) + " OR = " + nf.format(or) + " BD = " + nf.format(bd) + " E = " + nf.format(elapsed)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + // averages + double apa = aps / count; + double ara = ars / count; + double opa = ops / count; + double ora = ors / count; + double bda = bds / count; + double ea = es / count; + + System.out.println(); + System.out.println("BOSS averages:"); + System.out.println("AP = " + nf.format(apa) + " AR = " + nf.format(ara) + " OP = " + nf.format(opa) + " OR = " + nf.format(ora) + "BD = " + nf.format(bda) + " E = " + nf.format(ea)); + } + + /** + * Test for Bryan. + */ + public void test2() { + Parameters parameters = new Parameters(); + parameters.set(Params.NUM_MEASURES, 100); + parameters.set(Params.AVG_DEGREE, 20); + parameters.set(Params.COEF_LOW, 0); + parameters.set(Params.COEF_HIGH, 1); + parameters.set(Params.VAR_LOW, 1); + parameters.set(Params.VAR_HIGH, 1); + parameters.set(Params.PENALTY_DISCOUNT, 2); + parameters.set(Params.NUM_RUNS, 1); + + Algorithms algorithms = new Algorithms(); + algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Boss(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); + algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Grasp( + new FisherZ(), + new edu.cmu.tetrad.algcomparison.score.SemBicScore())); + algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); + + Statistics statistics = new Statistics(); + statistics.add(new AdjacencyPrecision()); + statistics.add(new AdjacencyRecall()); + statistics.add(new OrientationPrecision()); + statistics.add(new OrientationRecall()); + statistics.add(new BicDiff()); + statistics.add(new ElapsedCpuTime()); + + Simulations simulations = new Simulations(); + simulations.add(new SemSimulation(new RandomForward())); + + Comparison comparison = new Comparison(); + comparison.setComparisonGraph(Comparison.ComparisonGraph.CPDAG_of_the_true_DAG); + comparison.compareFromSimulations("erich_out", simulations, algorithms, statistics, parameters); + } +} From a676c1b42dbc98fce7dde3b5e4e7ce7105e52b7e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 12 May 2023 05:03:28 -0400 Subject: [PATCH 411/464] Ruben typo fixes. --- .../edu/cmu/tetrad/test/TestRubenData.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java index 95729a7160..5235df2c7d 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java @@ -21,15 +21,19 @@ import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.data.reader.Delimiter; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.HashSet; +import java.util.Set; public class TestRubenData { public static void main(String... arge) { - new TestRubenData().test2(); + new TestRubenData().test3(); } public void test1() { @@ -131,4 +135,29 @@ public void test2() { comparison.setComparisonGraph(Comparison.ComparisonGraph.CPDAG_of_the_true_DAG); comparison.compareFromSimulations("erich_out", simulations, algorithms, statistics, parameters); } + + public void test3() { + String path = "/Users/josephramsey/Downloads/emails.txt"; + + File file = new File(path); + + try { + BufferedReader in = new BufferedReader(new FileReader(file)); + + String line = in.readLine(); + String[] tokens = line.split(";"); + + Set emails = new HashSet<>(); + + for (String token : tokens) { + emails.add(token.trim()); + } + + System.out.println(emails.size()); + + } catch (Exception e) { + throw new RuntimeException(e); + } + + } } From 7c2c298312357c3f592d428e6aaf837d4fdd1199 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 12 May 2023 09:47:31 -0400 Subject: [PATCH 412/464] Fix cyclic reference problem for graphs... --- .../knowledge_editor/KnowledgeGraph.java | 132 +++++++++++- .../statistic/NumAmbiguousTriples.java | 2 +- .../statistic/PercentAmbiguous.java | 2 +- .../main/java/edu/cmu/tetrad/graph/Dag.java | 136 +++++++++++- .../edu/cmu/tetrad/graph/EdgeListGraph.java | 197 ++++++++++++++++-- .../main/java/edu/cmu/tetrad/graph/Graph.java | 43 +++- .../cmu/tetrad/graph/GraphPersistence.java | 12 +- .../java/edu/cmu/tetrad/graph/GraphUtils.java | 24 +-- .../java/edu/cmu/tetrad/graph/LagGraph.java | 133 +++++++++++- .../main/java/edu/cmu/tetrad/graph/Paths.java | 4 +- .../java/edu/cmu/tetrad/graph/SemGraph.java | 133 +++++++++++- .../edu/cmu/tetrad/graph/TimeLagGraph.java | 133 +++++++++++- .../main/java/edu/cmu/tetrad/search/Ccd.java | 12 +- .../main/java/edu/cmu/tetrad/search/Cfci.java | 2 +- .../main/java/edu/cmu/tetrad/search/PcMb.java | 2 +- .../cmu/tetrad/search/utils/GraphInPag.java | 4 +- .../edu/cmu/tetrad/search/utils/PcCommon.java | 2 +- .../search/utils/PossibleDConnectingPath.java | 4 +- .../tetrad/search/work_in_progress/Dci.java | 4 +- .../search/work_in_progress/GraphChange.java | 2 +- .../tetrad/search/work_in_progress/Ion.java | 18 +- .../search/work_in_progress/SampleVcpc.java | 6 +- .../work_in_progress/SampleVcpcFast.java | 6 +- .../tetrad/search/work_in_progress/VcPc.java | 6 +- .../search/work_in_progress/VcPcAlt.java | 6 +- .../search/work_in_progress/VcPcFast.java | 6 +- .../study/performance/PerformanceTests.java | 2 +- .../java/edu/cmu/tetrad/util/JsonUtils.java | 8 +- .../java/edu/cmu/tetrad/test/TestGraph.java | 78 +++---- 29 files changed, 957 insertions(+), 162 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java index 6e35790831..8da56915ec 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java @@ -54,6 +54,10 @@ public class KnowledgeGraph implements Graph, TetradSerializableExcluded { private final Paths paths; + private Set underLineTriples; + private Set dottedUnderLineTriples; + private Set ambiguousTriples; + //============================CONSTRUCTORS=============================// /** @@ -92,11 +96,6 @@ public final void transferAttributes(Graph graph) this.getGraph().transferAttributes(graph); } - @Override - public Underlines underlines() { - return graph.underlines(); - } - @Override public Paths paths() { return this.paths; @@ -416,6 +415,129 @@ public void addAttribute(String key, Object value) { this.attributes.put(key, value); } + public Set getAmbiguousTriples() { + return new HashSet<>(this.ambiguousTriples); + } + + public void setAmbiguousTriples(Set triples) { + this.ambiguousTriples.clear(); + + for (Triple triple : triples) { + addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public Set getUnderLines() { + return new HashSet<>(this.underLineTriples); + } + + public Set getDottedUnderlines() { + return new HashSet<>(this.dottedUnderLineTriples); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isAmbiguousTriple(Node x, Node y, Node z) { + return this.ambiguousTriples.contains(new Triple(x, y, z)); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isUnderlineTriple(Node x, Node y, Node z) { + return this.underLineTriples.contains(new Triple(x, y, z)); + } + + public void addAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.add(new Triple(x, y, z)); + } + + public void addUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.underLineTriples.add(new Triple(x, y, z)); + } + + public void addDottedUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.dottedUnderLineTriples.add(triple); + } + + public void removeAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.remove(new Triple(x, y, z)); + } + + public void removeUnderlineTriple(Node x, Node y, Node z) { + this.underLineTriples.remove(new Triple(x, y, z)); + } + + public void removeDottedUnderlineTriple(Node x, Node y, Node z) { + this.dottedUnderLineTriples.remove(new Triple(x, y, z)); + } + + public void setUnderLineTriples(Set triples) { + this.underLineTriples.clear(); + + for (Triple triple : triples) { + addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void setDottedUnderLineTriples(Set triples) { + this.dottedUnderLineTriples.clear(); + + for (Triple triple : triples) { + addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void removeTriplesNotInGraph() { + for (Triple triple : new HashSet<>(this.ambiguousTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.ambiguousTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) + || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.ambiguousTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.underLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.underLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.underLineTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.dottedUnderLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) || !containsNode(triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || isAdjacentTo(triple.getY(), triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + } + } + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java index 9cc31ab181..ccd32637d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java @@ -26,7 +26,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - return estGraph.underlines().getAmbiguousTriples().size(); + return estGraph.getAmbiguousTriples().size(); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java index 3d7510d7aa..7b1d4fefb5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java @@ -48,7 +48,7 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { Node a = _adj.get(0); Node c = _adj.get(1); - if (estGraph.underlines().isAmbiguousTriple(a, b, c)) { + if (estGraph.isAmbiguousTriple(a, b, c)) { numAmbiguous++; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java index 1d1b0e70c6..a78e81218d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java @@ -24,10 +24,7 @@ import java.beans.PropertyChangeListener; import java.io.IOException; import java.io.ObjectInputStream; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Represents a directed acyclic graph--that is, a graph containing only @@ -44,6 +41,10 @@ public final class Dag implements Graph { */ private final Graph graph; + private Set underLineTriples = new HashSet<>(); + private Set dottedUnderLineTriples = new HashSet<>(); + private Set ambiguousTriples = new HashSet<>(); + //===============================CONSTRUCTORS=======================// /** @@ -339,10 +340,6 @@ public void transferAttributes(Graph graph) throws IllegalArgumentException { this.graph.transferAttributes(graph); } - public Underlines underlines() { - return this.graph.underlines(); - } - public Paths paths() { return this.graph.paths(); } @@ -383,6 +380,129 @@ public void addAttribute(String key, Object value) { this.graph.addAttribute(key, value); } + public Set getAmbiguousTriples() { + return new HashSet<>(this.ambiguousTriples); + } + + public void setAmbiguousTriples(Set triples) { + this.ambiguousTriples.clear(); + + for (Triple triple : triples) { + addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public Set getUnderLines() { + return new HashSet<>(this.underLineTriples); + } + + public Set getDottedUnderlines() { + return new HashSet<>(this.dottedUnderLineTriples); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isAmbiguousTriple(Node x, Node y, Node z) { + return this.ambiguousTriples.contains(new Triple(x, y, z)); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isUnderlineTriple(Node x, Node y, Node z) { + return this.underLineTriples.contains(new Triple(x, y, z)); + } + + public void addAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.add(new Triple(x, y, z)); + } + + public void addUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.underLineTriples.add(new Triple(x, y, z)); + } + + public void addDottedUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.dottedUnderLineTriples.add(triple); + } + + public void removeAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.remove(new Triple(x, y, z)); + } + + public void removeUnderlineTriple(Node x, Node y, Node z) { + this.underLineTriples.remove(new Triple(x, y, z)); + } + + public void removeDottedUnderlineTriple(Node x, Node y, Node z) { + this.dottedUnderLineTriples.remove(new Triple(x, y, z)); + } + + public void setUnderLineTriples(Set triples) { + this.underLineTriples.clear(); + + for (Triple triple : triples) { + addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void setDottedUnderLineTriples(Set triples) { + this.dottedUnderLineTriples.clear(); + + for (Triple triple : triples) { + addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void removeTriplesNotInGraph() { + for (Triple triple : new HashSet<>(this.ambiguousTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.ambiguousTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) + || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.ambiguousTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.underLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.underLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.underLineTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.dottedUnderLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) || !containsNode(triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || isAdjacentTo(triple.getY(), triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + } + } + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java index ec9a7a2b35..d5f2c3b840 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java @@ -42,7 +42,7 @@ * @author Erin Korber additions summer 2004 * @see edu.cmu.tetrad.graph.Endpoint */ -public class EdgeListGraph implements Graph { +public class EdgeListGraph implements Graph, TripleClassifier { static final long serialVersionUID = 23L; @@ -72,14 +72,16 @@ public class EdgeListGraph implements Graph { */ private final Map namesHash; - private Underlines underlines; - - private final Paths paths; +// private final Paths paths; private final Map attributes = new HashMap<>(); private transient PropertyChangeSupport pcs; + private Set underLineTriples = new HashSet<>(); + private Set dottedUnderLineTriples = new HashSet<>(); + private Set ambiguousTriples = new HashSet<>(); + //==============================CONSTUCTORS===========================// /** @@ -90,8 +92,11 @@ public EdgeListGraph() { this.nodes = new ArrayList<>(); this.edgesSet = new HashSet<>(); this.namesHash = new HashMap<>(); - this.underlines = new Underlines(this); - this.paths = new Paths(this); +// this.paths = new Paths(this); +// this.underLineTriples = new HashSet<>(); +// this.dottedUnderLineTriples = new HashSet<>(); +// this.ambiguousTriples = new HashSet<>(); + } /** @@ -115,11 +120,13 @@ public EdgeListGraph(Graph graph) throws IllegalArgumentException { // Keep attributes from the original graph transferAttributes(graph); - this.underlines = new Underlines(graph.underlines()); - for (Node node : this.nodes) { this.namesHash.put(node.getName(), node); } + + this.underLineTriples = graph.getUnderLines(); + this.dottedUnderLineTriples = graph.getDottedUnderlines(); + this.ambiguousTriples = graph.getAmbiguousTriples(); } public EdgeListGraph(EdgeListGraph graph) throws IllegalArgumentException { @@ -130,11 +137,12 @@ public EdgeListGraph(EdgeListGraph graph) throws IllegalArgumentException { } this.edgesSet = new HashSet<>(graph.edgesSet); this.namesHash = new HashMap<>(graph.namesHash); +// this.paths = new Paths(this); - this.underlines = new Underlines(graph.underlines()); + this.underLineTriples = graph.getUnderLines(); + this.dottedUnderLineTriples = graph.getDottedUnderlines(); + this.ambiguousTriples = graph.getAmbiguousTriples(); - this.paths = new Paths(this); - this.underlines = new Underlines(graph.underlines); } /** @@ -437,15 +445,15 @@ public boolean isChildOf(Node node1, Node node2) { @Override public List getSepset(Node x, Node y) { - return paths.getSepset(x, y); + return new Paths(this).getSepset(x, y); } public boolean isDSeparatedFrom(Node x, Node y, List z) { - return !paths.isDConnectedTo(x, y, z); + return !new Paths(this).isDConnectedTo(x, y, z); } public boolean isDSeparatedFrom(List x, List y, List z) { - return !paths.isDConnectedTo(x, y, z); + return !new Paths(this).isDConnectedTo(x, y, z); } /** @@ -511,14 +519,9 @@ public void transferAttributes(Graph graph) this.attributes.putAll(graph.getAllAttributes()); } - @Override - public Underlines underlines() { - return underlines; - } - @Override public Paths paths() { - return paths; + return new Paths(this); } /** @@ -564,7 +567,7 @@ public boolean removeEdge(Node node1, Node node2) { + node2); } - this.underlines.removeTriplesNotInGraph(); + removeTriplesNotInGraph(); return removeEdges(edges); } @@ -997,7 +1000,7 @@ public boolean removeNode(Node node) { this.nodes.remove(node); this.namesHash.remove(node.getName()); - this.underlines.removeTriplesNotInGraph(); + removeTriplesNotInGraph(); getPcs().firePropertyChange("nodeRemoved", node, null); return changed; @@ -1162,4 +1165,154 @@ public void addAttribute(String key, Object value) { public void addPropertyChangeListener(PropertyChangeListener l) { getPcs().addPropertyChangeListener(l); } + + public Set getAmbiguousTriples() { + return new HashSet<>(this.ambiguousTriples); + } + + public void setAmbiguousTriples(Set triples) { + this.ambiguousTriples.clear(); + + for (Triple triple : triples) { + addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public Set getUnderLines() { + return new HashSet<>(this.underLineTriples); + } + + public Set getDottedUnderlines() { + return new HashSet<>(this.dottedUnderLineTriples); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isAmbiguousTriple(Node x, Node y, Node z) { + return this.ambiguousTriples.contains(new Triple(x, y, z)); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isUnderlineTriple(Node x, Node y, Node z) { + return this.underLineTriples.contains(new Triple(x, y, z)); + } + + public void addAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.add(new Triple(x, y, z)); + } + + public void addUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.underLineTriples.add(new Triple(x, y, z)); + } + + public void addDottedUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.dottedUnderLineTriples.add(triple); + } + + public void removeAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.remove(new Triple(x, y, z)); + } + + public void removeUnderlineTriple(Node x, Node y, Node z) { + this.underLineTriples.remove(new Triple(x, y, z)); + } + + public void removeDottedUnderlineTriple(Node x, Node y, Node z) { + this.dottedUnderLineTriples.remove(new Triple(x, y, z)); + } + + public void setUnderLineTriples(Set triples) { + this.underLineTriples.clear(); + + for (Triple triple : triples) { + addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void setDottedUnderLineTriples(Set triples) { + this.dottedUnderLineTriples.clear(); + + for (Triple triple : triples) { + addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void removeTriplesNotInGraph() { + for (Triple triple : new HashSet<>(this.ambiguousTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.ambiguousTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) + || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.ambiguousTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.underLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.underLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.underLineTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.dottedUnderLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) || !containsNode(triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || isAdjacentTo(triple.getY(), triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + } + } + } + + + /** + * @return the names of the triple classifications. Coordinates with + * getTriplesList + */ + public List getTriplesClassificationTypes() { + List names = new ArrayList<>(); + names.add("Underlines"); + names.add("Dotted Underlines"); + names.add("Ambiguous Triples"); + return names; + } + + + /** + * @return the list of triples corresponding to + * getTripleClassificationNames for the given node. + */ + public List> getTriplesLists(Node node) { + List> triplesList = new ArrayList<>(); + triplesList.add(GraphUtils.getUnderlinedTriplesFromGraph(node, this)); + triplesList.add(GraphUtils.getDottedUnderlinedTriplesFromGraph(node, this)); + triplesList.add(GraphUtils.getAmbiguousTriplesFromGraph(node, this)); + return triplesList; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java index 6a9ca2cd6b..b953e57145 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Graph.java @@ -24,10 +24,7 @@ import edu.cmu.tetrad.util.TetradSerializable; import java.beans.PropertyChangeListener; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Implements a graph capable of storing edges of type N1 *-# N2 where * and @@ -360,8 +357,6 @@ public interface Graph extends TetradSerializable { void transferAttributes(Graph graph) throws IllegalArgumentException; - Underlines underlines(); - Paths paths(); /** @@ -390,6 +385,42 @@ public interface Graph extends TetradSerializable { void removeAttribute(String key); void addAttribute(String key, Object value); + + Set getUnderLines(); + + Set getDottedUnderlines(); + + Set getAmbiguousTriples(); + + /** + * States whether r-s-r is an underline triple or not. + */ + boolean isAmbiguousTriple(Node x, Node y, Node z); + + /** + * States whether r-s-r is an underline triple or not. + */ + boolean isUnderlineTriple(Node x, Node y, Node z); + + void addAmbiguousTriple(Node x, Node y, Node z); + + void addUnderlineTriple(Node x, Node y, Node z); + + void addDottedUnderlineTriple(Node x, Node y, Node z); + + void removeAmbiguousTriple(Node x, Node y, Node z); + + void removeUnderlineTriple(Node x, Node y, Node z); + + void removeDottedUnderlineTriple(Node x, Node y, Node z); + + void setUnderLineTriples(Set triples); + + void setDottedUnderLineTriples(Set triples); + + void setAmbiguousTriples(Set triples); + + void removeTriplesNotInGraph(); } 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 b2c2a43e8b..4a3faf943f 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 @@ -658,7 +658,7 @@ public static Element convertToXml(Graph graph) { edges.appendChild(_edge); } - Set ambiguousTriples = graph.underlines().getAmbiguousTriples(); + Set ambiguousTriples = graph.getAmbiguousTriples(); if (!ambiguousTriples.isEmpty()) { Element underlinings = new Element("ambiguities"); @@ -672,7 +672,7 @@ public static Element convertToXml(Graph graph) { } } - Set underlineTriples = graph.underlines().getUnderLines(); + Set underlineTriples = graph.getUnderLines(); if (!underlineTriples.isEmpty()) { Element underlinings = new Element("underlines"); @@ -686,7 +686,7 @@ public static Element convertToXml(Graph graph) { } } - Set dottedTriples = graph.underlines().getDottedUnderlines(); + Set dottedTriples = graph.getDottedUnderlines(); if (!dottedTriples.isEmpty()) { Element dottedUnderlinings = new Element("dottedUnderlines"); @@ -921,7 +921,7 @@ public static Graph parseGraphXml(Element graphElement, Map nodes) if ("ambiguities".equals(graphElement.getChildElements().get(p).getLocalName())) { Element ambiguitiesElement = graphElement.getChildElements().get(p); Set triples = parseTriples(variables, ambiguitiesElement, "ambiguity"); - graph.underlines().setAmbiguousTriples(triples); + graph.setAmbiguousTriples(triples); p++; } @@ -932,7 +932,7 @@ public static Graph parseGraphXml(Element graphElement, Map nodes) if ("underlines".equals(graphElement.getChildElements().get(p).getLocalName())) { Element ambiguitiesElement = graphElement.getChildElements().get(p); Set triples = parseTriples(variables, ambiguitiesElement, "underline"); - graph.underlines().setUnderLineTriples(triples); + graph.setUnderLineTriples(triples); p++; } @@ -943,7 +943,7 @@ public static Graph parseGraphXml(Element graphElement, Map nodes) if ("dottedunderlines".equals(graphElement.getChildElements().get(p).getLocalName())) { Element ambiguitiesElement = graphElement.getChildElements().get(p); Set triples = parseTriples(variables, ambiguitiesElement, "dottedunderline"); - graph.underlines().setDottedUnderLineTriples(triples); + graph.setDottedUnderLineTriples(triples); } return graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index 007703bc81..9a1e64249c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -425,16 +425,16 @@ public static Graph replaceNodes(Graph originalGraph, List newVariables) { convertedGraph.addEdge(newEdge); } - for (Triple triple : originalGraph.underlines().getUnderLines()) { - convertedGraph.underlines().addUnderlineTriple(convertedGraph.getNode(triple.getX().getName()), convertedGraph.getNode(triple.getY().getName()), convertedGraph.getNode(triple.getZ().getName())); + for (Triple triple : originalGraph.getUnderLines()) { + convertedGraph.addUnderlineTriple(convertedGraph.getNode(triple.getX().getName()), convertedGraph.getNode(triple.getY().getName()), convertedGraph.getNode(triple.getZ().getName())); } - for (Triple triple : originalGraph.underlines().getDottedUnderlines()) { - convertedGraph.underlines().addDottedUnderlineTriple(convertedGraph.getNode(triple.getX().getName()), convertedGraph.getNode(triple.getY().getName()), convertedGraph.getNode(triple.getZ().getName())); + for (Triple triple : originalGraph.getDottedUnderlines()) { + convertedGraph.addDottedUnderlineTriple(convertedGraph.getNode(triple.getX().getName()), convertedGraph.getNode(triple.getY().getName()), convertedGraph.getNode(triple.getZ().getName())); } - for (Triple triple : originalGraph.underlines().getAmbiguousTriples()) { - convertedGraph.underlines().addAmbiguousTriple(convertedGraph.getNode(triple.getX().getName()), convertedGraph.getNode(triple.getY().getName()), convertedGraph.getNode(triple.getZ().getName())); + for (Triple triple : originalGraph.getAmbiguousTriples()) { + convertedGraph.addAmbiguousTriple(convertedGraph.getNode(triple.getX().getName()), convertedGraph.getNode(triple.getY().getName()), convertedGraph.getNode(triple.getZ().getName())); } return convertedGraph; @@ -696,7 +696,7 @@ public static List getAmbiguousTriplesFromGraph(Node node, Graph graph) Node x = adj.get(choice[0]); Node z = adj.get(choice[1]); - if (graph.underlines().isAmbiguousTriple(x, node, z)) { + if (graph.isAmbiguousTriple(x, node, z)) { ambiguousTriples.add(new Triple(x, node, z)); } } @@ -710,7 +710,7 @@ public static List getAmbiguousTriplesFromGraph(Node node, Graph graph) */ public static List getUnderlinedTriplesFromGraph(Node node, Graph graph) { List underlinedTriples = new ArrayList<>(); - Set allUnderlinedTriples = graph.underlines().getUnderLines(); + Set allUnderlinedTriples = graph.getUnderLines(); List adj = graph.getAdjacentNodes(node); if (adj.size() < 2) { @@ -738,7 +738,7 @@ public static List getUnderlinedTriplesFromGraph(Node node, Graph graph) */ public static List getDottedUnderlinedTriplesFromGraph(Node node, Graph graph) { List dottedUnderlinedTriples = new ArrayList<>(); - Set allDottedUnderlinedTriples = graph.underlines().getDottedUnderlines(); + Set allDottedUnderlinedTriples = graph.getDottedUnderlines(); List adj = graph.getAdjacentNodes(node); if (adj.size() < 2) { @@ -1479,17 +1479,17 @@ public static String graphToText(Graph graph, boolean doPagColoring) { fmt.format("%s%n", graphNodeAttributes); } - Set ambiguousTriples = graph.underlines().getAmbiguousTriples(); + Set ambiguousTriples = graph.getAmbiguousTriples(); if (!ambiguousTriples.isEmpty()) { fmt.format("%n%n%s", GraphUtils.triplesToText(ambiguousTriples, "Ambiguous triples (i.e. list of triples for which there is ambiguous data about whether they are colliders or not):")); } - Set underLineTriples = graph.underlines().getUnderLines(); + Set underLineTriples = graph.getUnderLines(); if (!underLineTriples.isEmpty()) { fmt.format("%n%n%s", GraphUtils.triplesToText(underLineTriples, "Underline triples:")); } - Set dottedUnderLineTriples = graph.underlines().getDottedUnderlines(); + Set dottedUnderLineTriples = graph.getDottedUnderlines(); if (!dottedUnderLineTriples.isEmpty()) { fmt.format("%n%n%s", GraphUtils.triplesToText(dottedUnderLineTriples, "Dotted underline triples:")); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java index b5c619aaf2..91ad581790 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java @@ -40,6 +40,11 @@ public class LagGraph implements Graph { private final Map attributes = new HashMap<>(); + private Set underLineTriples = new HashSet<>(); + private Set dottedUnderLineTriples = new HashSet<>(); + private Set ambiguousTriples = new HashSet<>(); + + private Paths paths; // New methods. @@ -283,11 +288,6 @@ public void transferAttributes(Graph graph) throws IllegalArgumentException { this.getGraph().transferAttributes(graph); } - @Override - public Underlines underlines() { - return graph.underlines(); - } - @Override public Paths paths() { return this.paths; @@ -343,6 +343,129 @@ public void addAttribute(String key, Object value) { this.attributes.put(key, value); } + public Set getAmbiguousTriples() { + return new HashSet<>(this.ambiguousTriples); + } + + public void setAmbiguousTriples(Set triples) { + this.ambiguousTriples.clear(); + + for (Triple triple : triples) { + addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public Set getUnderLines() { + return new HashSet<>(this.underLineTriples); + } + + public Set getDottedUnderlines() { + return new HashSet<>(this.dottedUnderLineTriples); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isAmbiguousTriple(Node x, Node y, Node z) { + return this.ambiguousTriples.contains(new Triple(x, y, z)); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isUnderlineTriple(Node x, Node y, Node z) { + return this.underLineTriples.contains(new Triple(x, y, z)); + } + + public void addAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.add(new Triple(x, y, z)); + } + + public void addUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.underLineTriples.add(new Triple(x, y, z)); + } + + public void addDottedUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.dottedUnderLineTriples.add(triple); + } + + public void removeAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.remove(new Triple(x, y, z)); + } + + public void removeUnderlineTriple(Node x, Node y, Node z) { + this.underLineTriples.remove(new Triple(x, y, z)); + } + + public void removeDottedUnderlineTriple(Node x, Node y, Node z) { + this.dottedUnderLineTriples.remove(new Triple(x, y, z)); + } + + public void setUnderLineTriples(Set triples) { + this.underLineTriples.clear(); + + for (Triple triple : triples) { + addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void setDottedUnderLineTriples(Set triples) { + this.dottedUnderLineTriples.clear(); + + for (Triple triple : triples) { + addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void removeTriplesNotInGraph() { + for (Triple triple : new HashSet<>(this.ambiguousTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.ambiguousTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) + || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.ambiguousTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.underLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.underLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.underLineTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.dottedUnderLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) || !containsNode(triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || isAdjacentTo(triple.getY(), triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + } + } + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java index 77fe65ecbf..69fb8a80fd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java @@ -619,7 +619,7 @@ private boolean reachable(Edge e1, Edge e2, Node a, List z) { boolean collider = e1.getProximalEndpoint(b) == Endpoint.ARROW && e2.getProximalEndpoint(b) == Endpoint.ARROW; - if ((!collider || graph.underlines().isUnderlineTriple(a, b, c)) && !z.contains(b)) { + if ((!collider || graph.isUnderlineTriple(a, b, c)) && !z.contains(b)) { return true; } @@ -662,7 +662,7 @@ private boolean isAncestor(Node b, List z) { private boolean reachable(Node a, Node b, Node c, List z) { boolean collider = graph.isDefCollider(a, b, c); - if ((!collider || graph.underlines().isUnderlineTriple(a, b, c)) && !z.contains(b)) { + if ((!collider || graph.isUnderlineTriple(a, b, c)) && !z.contains(b)) { return true; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java index ccab9b93f9..c1261e5750 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java @@ -84,6 +84,10 @@ public final class SemGraph implements Graph { private final Map attributes = new HashMap<>(); private final Paths paths; + private Set underLineTriples = new HashSet<>(); + private Set dottedUnderLineTriples = new HashSet<>(); + private Set ambiguousTriples = new HashSet<>(); + //=========================CONSTRUCTORS============================// /** @@ -276,11 +280,6 @@ public void transferAttributes(Graph graph) throw new UnsupportedOperationException(); } - @Override - public Underlines underlines() { - return graph.underlines(); - } - @Override public Paths paths() { return this.paths; @@ -790,9 +789,133 @@ public void addAttribute(String key, Object value) { this.attributes.put(key, value); } + public Set getAmbiguousTriples() { + return new HashSet<>(this.ambiguousTriples); + } + + public void setAmbiguousTriples(Set triples) { + this.ambiguousTriples.clear(); + + for (Triple triple : triples) { + addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public Set getUnderLines() { + return new HashSet<>(this.underLineTriples); + } + + public Set getDottedUnderlines() { + return new HashSet<>(this.dottedUnderLineTriples); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isAmbiguousTriple(Node x, Node y, Node z) { + return this.ambiguousTriples.contains(new Triple(x, y, z)); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isUnderlineTriple(Node x, Node y, Node z) { + return this.underLineTriples.contains(new Triple(x, y, z)); + } + + public void addAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.add(new Triple(x, y, z)); + } + + public void addUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.underLineTriples.add(new Triple(x, y, z)); + } + + public void addDottedUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.dottedUnderLineTriples.add(triple); + } + + public void removeAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.remove(new Triple(x, y, z)); + } + + public void removeUnderlineTriple(Node x, Node y, Node z) { + this.underLineTriples.remove(new Triple(x, y, z)); + } + + public void removeDottedUnderlineTriple(Node x, Node y, Node z) { + this.dottedUnderLineTriples.remove(new Triple(x, y, z)); + } + + public void setUnderLineTriples(Set triples) { + this.underLineTriples.clear(); + + for (Triple triple : triples) { + addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void setDottedUnderLineTriples(Set triples) { + this.dottedUnderLineTriples.clear(); + + for (Triple triple : triples) { + addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void removeTriplesNotInGraph() { + for (Triple triple : new HashSet<>(this.ambiguousTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.ambiguousTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) + || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.ambiguousTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.underLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.underLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.underLineTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.dottedUnderLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) || !containsNode(triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || isAdjacentTo(triple.getY(), triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + } + } + } } + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java index 8ab0902dca..26ffb0fbd4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java @@ -51,6 +51,10 @@ public class TimeLagGraph implements Graph { private final Map attributes = new HashMap<>(); private Paths paths; + private Set underLineTriples = new HashSet<>(); + private Set dottedUnderLineTriples = new HashSet<>(); + private Set ambiguousTriples = new HashSet<>(); + public TimeLagGraph() { } @@ -475,11 +479,6 @@ public void transferAttributes(Graph graph) throws IllegalArgumentException { getGraph().transferAttributes(graph); } - @Override - public Underlines underlines() { - return graph.underlines(); - } - @Override public Paths paths() { return this.paths; @@ -662,6 +661,130 @@ public void removeAttribute(String key) { public void addAttribute(String key, Object value) { this.attributes.put(key, value); } + + public Set getAmbiguousTriples() { + return new HashSet<>(this.ambiguousTriples); + } + + public void setAmbiguousTriples(Set triples) { + this.ambiguousTriples.clear(); + + for (Triple triple : triples) { + addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public Set getUnderLines() { + return new HashSet<>(this.underLineTriples); + } + + public Set getDottedUnderlines() { + return new HashSet<>(this.dottedUnderLineTriples); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isAmbiguousTriple(Node x, Node y, Node z) { + return this.ambiguousTriples.contains(new Triple(x, y, z)); + } + + /** + * States whether r-s-r is an underline triple or not. + */ + public boolean isUnderlineTriple(Node x, Node y, Node z) { + return this.underLineTriples.contains(new Triple(x, y, z)); + } + + public void addAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.add(new Triple(x, y, z)); + } + + public void addUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.underLineTriples.add(new Triple(x, y, z)); + } + + public void addDottedUnderlineTriple(Node x, Node y, Node z) { + Triple triple = new Triple(x, y, z); + + if (!triple.alongPathIn(this)) { + return; + } + + this.dottedUnderLineTriples.add(triple); + } + + public void removeAmbiguousTriple(Node x, Node y, Node z) { + this.ambiguousTriples.remove(new Triple(x, y, z)); + } + + public void removeUnderlineTriple(Node x, Node y, Node z) { + this.underLineTriples.remove(new Triple(x, y, z)); + } + + public void removeDottedUnderlineTriple(Node x, Node y, Node z) { + this.dottedUnderLineTriples.remove(new Triple(x, y, z)); + } + + public void setUnderLineTriples(Set triples) { + this.underLineTriples.clear(); + + for (Triple triple : triples) { + addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void setDottedUnderLineTriples(Set triples) { + this.dottedUnderLineTriples.clear(); + + for (Triple triple : triples) { + addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + } + } + + public void removeTriplesNotInGraph() { + for (Triple triple : new HashSet<>(this.ambiguousTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.ambiguousTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) + || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.ambiguousTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.underLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) + || !containsNode(triple.getZ())) { + this.underLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || !isAdjacentTo(triple.getY(), triple.getZ())) { + this.underLineTriples.remove(triple); + } + } + + for (Triple triple : new HashSet<>(this.dottedUnderLineTriples)) { + if (!containsNode(triple.getX()) || !containsNode(triple.getY()) || !containsNode(triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + continue; + } + + if (!isAdjacentTo(triple.getX(), triple.getY()) || isAdjacentTo(triple.getY(), triple.getZ())) { + this.dottedUnderLineTriples.remove(triple); + } + } + } } 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 c15fc13c42..ccda3c058b 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 @@ -163,7 +163,7 @@ private void stepB(Graph graph) { Node b = triple.getY(); Node c = triple.getZ(); - graph.underlines().addUnderlineTriple(a, b, c); + graph.addUnderlineTriple(a, b, c); } } @@ -248,7 +248,7 @@ private void stepC(Graph psi, SepsetProducer sepsets) { for (Node node : adjx) { if (psi.getEdge(node, x).getProximalEndpoint(x) == Endpoint.ARROW - && psi.underlines().isUnderlineTriple(y, x, node)) { + && psi.isUnderlineTriple(y, x, node)) { continue EDGE; } } @@ -334,7 +334,7 @@ private void doNodeStepD(Graph psi, SepsetProducer sepsets, Map(B))) { - psi.underlines().addDottedUnderlineTriple(a, b, c); + psi.addDottedUnderlineTriple(a, b, c); supSepsets.put(new Triple(a, b, c), B); break; } @@ -345,7 +345,7 @@ private void doNodeStepD(Graph psi, SepsetProducer sepsets, Map> supSepset, Graph psi) { TetradLogger.getInstance().log("info", "\nStep E"); - for (Triple triple : psi.underlines().getDottedUnderlines()) { + for (Triple triple : psi.getDottedUnderlines()) { Node a = triple.getX(); Node b = triple.getY(); Node c = triple.getZ(); @@ -403,7 +403,7 @@ private void stepE(Map> supSepset, Graph psi) { } private void stepF(Graph psi, SepsetProducer sepsets, Map> supSepsets) { - for (Triple triple : psi.underlines().getDottedUnderlines()) { + for (Triple triple : psi.getDottedUnderlines()) { Node a = triple.getX(); Node b = triple.getY(); Node c = triple.getZ(); @@ -477,7 +477,7 @@ private boolean orientAwayFromArrowVisit(Node a, Node b, Node c, Graph graph) { return false; } - if (!(graph.underlines().isUnderlineTriple(a, b, c))) { + if (!(graph.isUnderlineTriple(a, b, c))) { return false; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 57b10ad293..7a990ddc27 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -348,7 +348,7 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { } else { Triple triple = new Triple(x, y, z); this.ambiguousTriples.add(triple); - getGraph().underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + getGraph().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); if (this.verbose) { TetradLogger.getInstance().log("tripleClassifications", "AmbiguousTriples: " + Triple.pathString(this.graph, x, y, z)); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index cca252d49b..ec00ce7ad9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -708,7 +708,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, Graph graph, int depth } else if (type == TripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); this.ambiguousTriples.add(triple); - graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); this.logger.log("tripleClassifications", "tripleClassifications: " + Triple.pathString(graph, x, y, z)); } else { this.logger.log("tripleClassifications", "tripleClassifications: " + Triple.pathString(graph, x, y, z)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java index 77f7a8fab4..8358494fdf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphInPag.java @@ -138,7 +138,7 @@ public static boolean graphInPagStep3(Graph pag, Graph dag) { } public static boolean graphInPagStep4(Graph pag, Graph dag) { - Set pagUnderLines = pag.underlines().getUnderLines(); + Set pagUnderLines = pag.getUnderLines(); for (Triple underline : pagUnderLines) { Node A = underline.getX(); @@ -158,7 +158,7 @@ public static boolean graphInPagStep4(Graph pag, Graph dag) { } public static boolean graphInPagStep5(Graph pag, Graph dag) { - for (Triple triple : pag.underlines().getDottedUnderlines()) { + for (Triple triple : pag.getDottedUnderlines()) { Node A = triple.getX(); Node B = triple.getY(); Node C = triple.getZ(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java index 45def9e711..e0a9f8a297 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java @@ -507,7 +507,7 @@ private void orientUnshieldedTriplesConservative(Knowledge knowledge) { } else { Triple triple = new Triple(x, y, z); this.ambiguousTriples.add(triple); - this.graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + this.graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); } } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDConnectingPath.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDConnectingPath.java index bd8608a788..1e3ebbabbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDConnectingPath.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PossibleDConnectingPath.java @@ -205,7 +205,7 @@ private static void findPaths(Graph pag, Set> paths, Node previous, N if (pag.isDefCollider(previous, current, adj)) { pass = isConditionClosure; } else { - pass = !isCondition || !pag.underlines().isUnderlineTriple(previous, current, adj) && PossibleDConnectingPath.isOpen(pag, previous, current, adj); + pass = !isCondition || !pag.isUnderlineTriple(previous, current, adj) && PossibleDConnectingPath.isOpen(pag, previous, current, adj); } if (pass) { @@ -252,7 +252,7 @@ private static void findPathsOfLength(Graph pag, Set> paths, Node pre if (pag.isDefCollider(previous, current, adj)) { pass = isConditionClosure; } else { - pass = !isCondition || !pag.underlines().isUnderlineTriple(previous, current, adj) && PossibleDConnectingPath.isOpen(pag, previous, current, adj); + pass = !isCondition || !pag.isUnderlineTriple(previous, current, adj) && PossibleDConnectingPath.isOpen(pag, previous, current, adj); } if (pass) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java index d924aa4761..9becf6c12a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Dci.java @@ -1330,7 +1330,7 @@ private void allColliderCombinations(Graph graph, Set removedEdges, Set()); + graph.setUnderLineTriples(new HashSet<>()); this.output.add(graph); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraphChange.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraphChange.java index 43994cb564..362f4d7aa6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraphChange.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/GraphChange.java @@ -121,7 +121,7 @@ public Graph applyTo(Graph graph) { makeNewEdges(output); for (Triple t : this.nonColliders) - output.underlines().addUnderlineTriple(t.getX(), t.getY(), t.getZ()); + output.addUnderlineTriple(t.getX(), t.getY(), t.getZ()); for (Edge e : this.removes) if (!output.removeEdge(e)) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java index a8d8739806..e6493c6adf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java @@ -110,7 +110,7 @@ public Ion(List pags) { } for (Triple triple : getAllTriples(pag)) { if (pag.isDefNoncollider(triple.getX(), triple.getY(), triple.getZ())) { - pag.underlines().addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + pag.addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); } } } @@ -287,7 +287,7 @@ public List search() { boolean okay = true; for (Triple collider : gc.getColliders()) { - if (pag.underlines().isUnderlineTriple(collider.getX(), collider.getY(), collider.getZ())) { + if (pag.isUnderlineTriple(collider.getX(), collider.getY(), collider.getZ())) { okay = false; break; } @@ -455,7 +455,7 @@ public List search() { continue; } // makes each triple a noncollider - pag.underlines().addUnderlineTriple(trek.get(i - 2), trek.get(i - 1), trek.get(i)); + pag.addUnderlineTriple(trek.get(i - 2), trek.get(i - 1), trek.get(i)); } } // stop looping once the empty set is found @@ -524,9 +524,9 @@ public List search() { } for (Graph outputPag : this.finalResult) { if (!predictsFalseIndependence(associations, outputPag)) { - Set underlineTriples = new HashSet<>(outputPag.underlines().getUnderLines()); + Set underlineTriples = new HashSet<>(outputPag.getUnderLines()); for (Triple triple : underlineTriples) { - outputPag.underlines().removeUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + outputPag.removeUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); } outputSet.add(outputPag); } @@ -712,10 +712,10 @@ private void transferLocal(Graph graph) { } } } - for (Triple triple : pag.underlines().getUnderLines()) { + for (Triple triple : pag.getUnderLines()) { Triple graphTriple = new Triple(graph.getNode(triple.getX().getName()), graph.getNode(triple.getY().getName()), graph.getNode(triple.getZ().getName())); if (graphTriple.alongPathIn(graph)) { - graph.underlines().addUnderlineTriple(graphTriple.getX(), graphTriple.getY(), graphTriple.getZ()); + graph.addUnderlineTriple(graphTriple.getX(), graphTriple.getY(), graphTriple.getZ()); this.definiteNoncolliders.add(graphTriple); } } @@ -862,7 +862,7 @@ private Set getPossibleTriples(Graph pag) { Set possibleTriples = new HashSet<>(); for (Triple triple : getAllTriples(pag)) { if (pag.isAdjacentTo(triple.getX(), triple.getY()) && pag.isAdjacentTo(triple.getY(), triple.getZ()) - && !pag.underlines().isUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()) && + && !pag.isUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()) && !this.definiteNoncolliders.contains(triple) && !pag.isDefCollider(triple.getX(), triple.getY(), triple.getZ())) { possibleTriples.add(triple); @@ -923,7 +923,7 @@ private List> findChanges(Map, List 0) { Triple colider = new Triple(possPath.get(i - 1), current, next); - if (possible.getPag().underlines().isUnderlineTriple(possPath.get(i - 1), current, next)) + if (possible.getPag().isUnderlineTriple(possPath.get(i - 1), current, next)) continue; Edge edge1 = possible.getPag().getEdge(colider.getX(), colider.getY()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java index 400b3e6292..27235110c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpc.java @@ -289,7 +289,7 @@ public Graph search() { } - List ambiguousTriples = new ArrayList<>(this.graph.underlines().getAmbiguousTriples()); + List ambiguousTriples = new ArrayList<>(this.graph.getAmbiguousTriples()); int[] dims = new int[ambiguousTriples.size()]; @@ -316,7 +316,7 @@ public Graph search() { for (int k = 0; k < combination.length; k++) { Triple triple = ambiguousTriples.get(k); - _graph.underlines().removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + _graph.removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); if (combination[k] == 0) { newColliders.get(_graph).add(triple); @@ -820,7 +820,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } else if (type == GraphSearchUtils.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); - graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); Edge edge = Edges.undirectedEdge(x, z); definitelyNonadjacencies.add(edge); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java index ed08b77a18..fde75d9337 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SampleVcpcFast.java @@ -289,7 +289,7 @@ public Graph search() { } - List ambiguousTriples = new ArrayList<>(this.graph.underlines().getAmbiguousTriples()); + List ambiguousTriples = new ArrayList<>(this.graph.getAmbiguousTriples()); int[] dims = new int[ambiguousTriples.size()]; @@ -317,7 +317,7 @@ public Graph search() { for (int k = 0; k < combination.length; k++) { // System.out.println("k = " + combination[k]); Triple triple = ambiguousTriples.get(k); - _graph.underlines().removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + _graph.removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); if (combination[k] == 0) { @@ -749,7 +749,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } else if (type == GraphSearchUtils.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); - graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); Edge edge = Edges.undirectedEdge(x, z); definitelyNonadjacencies.add(edge); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java index 809e5b61ee..794afd129e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPc.java @@ -267,7 +267,7 @@ public Graph search() { meekRules.orientImplied(this.graph); - List ambiguousTriples = new ArrayList<>(this.graph.underlines().getAmbiguousTriples()); + List ambiguousTriples = new ArrayList<>(this.graph.getAmbiguousTriples()); int[] dims = new int[ambiguousTriples.size()]; @@ -295,7 +295,7 @@ public Graph search() { for (int k = 0; k < combination.length; k++) { Triple triple = ambiguousTriples.get(k); - _graph.underlines().removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + _graph.removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); if (combination[k] == 0) { newColliders.get(_graph).add(triple); @@ -568,7 +568,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } else if (type == CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); this.ambiguousTriples.add(triple); - this.graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + this.graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); Edge edge = Edges.undirectedEdge(x, z); this.definitelyNonadjacencies.add(edge); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java index 519ca96fc0..3d9b566d5a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcAlt.java @@ -243,7 +243,7 @@ public Graph search() { } - List ambiguousTriples = new ArrayList<>(this.graph.underlines().getAmbiguousTriples()); + List ambiguousTriples = new ArrayList<>(this.graph.getAmbiguousTriples()); int[] dims = new int[ambiguousTriples.size()]; @@ -270,7 +270,7 @@ public Graph search() { for (int k = 0; k < combination.length; k++) { Triple triple = ambiguousTriples.get(k); - _graph.underlines().removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + _graph.removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); if (combination[k] == 0) { @@ -577,7 +577,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } else if (type == GraphSearchUtils.CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); ambiguousTriples.add(triple); - graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); Edge edge = Edges.undirectedEdge(x, z); definitelyNonadjacencies.add(edge); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java index ee4ccdb4e6..7dceb3c381 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/VcPcFast.java @@ -270,7 +270,7 @@ public Graph search() { meekRules.orientImplied(this.graph); - List ambiguousTriples = new ArrayList<>(this.graph.underlines().getAmbiguousTriples()); + List ambiguousTriples = new ArrayList<>(this.graph.getAmbiguousTriples()); int[] dims = new int[ambiguousTriples.size()]; @@ -299,7 +299,7 @@ public Graph search() { for (int k = 0; k < combination.length; k++) { Triple triple = ambiguousTriples.get(k); - _graph.underlines().removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + _graph.removeAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); if (combination[k] == 0) { newColliders.get(_graph).add(triple); @@ -581,7 +581,7 @@ private void orientUnshieldedTriples(Knowledge knowledge, } else if (type == CpcTripleType.AMBIGUOUS) { Triple triple = new Triple(x, y, z); this.ambiguousTriples.add(triple); - this.graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + this.graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); Edge edge = Edges.undirectedEdge(x, z); this.definitelyNonadjacencies.add(edge); } else { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 16aca54dbc..ed93620f72 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -471,7 +471,7 @@ public void testCpcStable(int numVars, double edgeFactor, int numCases, double a GraphSearchUtils.graphComparison(trueCPDAG, outGraph, this.out); - this.out.println("# ambiguous triples = " + outGraph.underlines().getAmbiguousTriples().size()); + this.out.println("# ambiguous triples = " + outGraph.getAmbiguousTriples().size()); this.out.close(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java index 47a6da613f..4b0942f9d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java @@ -40,23 +40,23 @@ public static Graph parseJSONObjectToTetradGraph(JSONObject jObj) { // ambiguousTriples Set ambiguousTriples = JsonUtils.parseJSONArrayToTetradTriples(jObj.getJSONArray("ambiguousTriples")); for (Triple triple : ambiguousTriples) { - graph.underlines().addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); + graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ()); } // underLineTriples Set underLineTriples = JsonUtils.parseJSONArrayToTetradTriples(jObj.getJSONArray("underLineTriples")); for (Triple triple : underLineTriples) { - graph.underlines().addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + graph.addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); } // dottedUnderLineTriples Set dottedUnderLineTriples = JsonUtils.parseJSONArrayToTetradTriples(jObj.getJSONArray("dottedUnderLineTriples")); for (Triple triple : dottedUnderLineTriples) { - graph.underlines().addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); + graph.addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ()); } // stuffRemovedSinceLastTripleAccess - graph.underlines().removeTriplesNotInGraph(); + graph.removeTriplesNotInGraph(); // highlightedEdges Set highlightedEdges = JsonUtils.parseJSONArrayToTetradEdges(graph, jObj.getJSONArray("highlightedEdges")); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java index eddb7a3cc9..814dee850a 100755 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGraph.java @@ -64,17 +64,17 @@ public void testXml() { Set ambiguousTriples = new HashSet<>(); ambiguousTriples.add(pickRandomTriple(graph)); ambiguousTriples.add(pickRandomTriple(graph)); - graph.underlines().setAmbiguousTriples(ambiguousTriples); + graph.setAmbiguousTriples(ambiguousTriples); Set underlineTriples = new HashSet<>(); underlineTriples.add(pickRandomTriple(graph)); underlineTriples.add(pickRandomTriple(graph)); - graph.underlines().setUnderLineTriples(underlineTriples); + graph.setUnderLineTriples(underlineTriples); Set dottedUnderlineTriples = new HashSet<>(); dottedUnderlineTriples.add(pickRandomTriple(graph)); dottedUnderlineTriples.add(pickRandomTriple(graph)); - graph.underlines().setDottedUnderLineTriples(dottedUnderlineTriples); + graph.setDottedUnderLineTriples(dottedUnderlineTriples); Map nodes = new HashMap<>(); @@ -110,39 +110,39 @@ public void testTripleCode() { graph.addDirectedEdge(y, z); graph.addDirectedEdge(z, w); - graph.underlines().addAmbiguousTriple(x, z, w); - graph.underlines().addUnderlineTriple(x, z, w); - graph.underlines().addDottedUnderlineTriple(x, z, w); + graph.addAmbiguousTriple(x, z, w); + graph.addUnderlineTriple(x, z, w); + graph.addDottedUnderlineTriple(x, z, w); - graph.underlines().addUnderlineTriple(y, z, w); - graph.underlines().addUnderlineTriple(y, z, x); + graph.addUnderlineTriple(y, z, w); + graph.addUnderlineTriple(y, z, x); - assertTrue(graph.underlines().getAmbiguousTriples().size() == 1); - assertTrue(graph.underlines().getUnderLines().size() == 3); - assertTrue(graph.underlines().getDottedUnderlines().size() == 1); + assertTrue(graph.getAmbiguousTriples().size() == 1); + assertTrue(graph.getUnderLines().size() == 3); + assertTrue(graph.getDottedUnderlines().size() == 1); - assertTrue(graph.underlines().isAmbiguousTriple(x, z, w)); - assertTrue(!graph.underlines().isAmbiguousTriple(y, z, w)); + assertTrue(graph.isAmbiguousTriple(x, z, w)); + assertTrue(!graph.isAmbiguousTriple(y, z, w)); - graph.underlines().removeAmbiguousTriple(x, z, w); - graph.underlines().removeUnderlineTriple(x, z, w); - graph.underlines().removeDottedUnderlineTriple(x, z, w); + graph.removeAmbiguousTriple(x, z, w); + graph.removeUnderlineTriple(x, z, w); + graph.removeDottedUnderlineTriple(x, z, w); - assertTrue(graph.underlines().getAmbiguousTriples().size() == 0); - assertTrue(graph.underlines().getUnderLines().size() == 2); - assertTrue(graph.underlines().getDottedUnderlines().size() == 0); + assertTrue(graph.getAmbiguousTriples().size() == 0); + assertTrue(graph.getUnderLines().size() == 2); + assertTrue(graph.getDottedUnderlines().size() == 0); - graph.underlines().addAmbiguousTriple(x, z, w); - graph.underlines().addUnderlineTriple(x, z, w); - graph.underlines().addDottedUnderlineTriple(x, z, w); + graph.addAmbiguousTriple(x, z, w); + graph.addUnderlineTriple(x, z, w); + graph.addDottedUnderlineTriple(x, z, w); graph.removeNode(z); - graph.underlines().removeTriplesNotInGraph(); + graph.removeTriplesNotInGraph(); - assertTrue(graph.underlines().getAmbiguousTriples().size() == 0); - assertTrue(graph.underlines().getUnderLines().size() == 0); - assertTrue(graph.underlines().getDottedUnderlines().size() == 0); + assertTrue(graph.getAmbiguousTriples().size() == 0); + assertTrue(graph.getUnderLines().size() == 0); + assertTrue(graph.getDottedUnderlines().size() == 0); graph.addNode(z); @@ -150,20 +150,20 @@ public void testTripleCode() { graph.addDirectedEdge(y, z); graph.addDirectedEdge(z, w); - graph.underlines().addAmbiguousTriple(x, z, w); - graph.underlines().addUnderlineTriple(x, z, w); - graph.underlines().addDottedUnderlineTriple(x, z, w); + graph.addAmbiguousTriple(x, z, w); + graph.addUnderlineTriple(x, z, w); + graph.addDottedUnderlineTriple(x, z, w); - graph.underlines().addUnderlineTriple(y, z, w); - graph.underlines().addUnderlineTriple(y, z, x); + graph.addUnderlineTriple(y, z, w); + graph.addUnderlineTriple(y, z, x); graph.removeEdge(z, w); - graph.underlines().removeTriplesNotInGraph(); + graph.removeTriplesNotInGraph(); - assertTrue(graph.underlines().getAmbiguousTriples().size() == 0); - assertTrue(graph.underlines().getUnderLines().size() == 1); - assertTrue(graph.underlines().getDottedUnderlines().size() == 0); + assertTrue(graph.getAmbiguousTriples().size() == 0); + assertTrue(graph.getUnderLines().size() == 1); + assertTrue(graph.getDottedUnderlines().size() == 0); graph.addDirectedEdge(z, w); @@ -171,13 +171,13 @@ public void testTripleCode() { triples.add(new Triple(x, z, w)); triples.add(new Triple(x, y, z)); - graph.underlines().setAmbiguousTriples(triples); + graph.setAmbiguousTriples(triples); triples.remove(new Triple(x, y, z)); - graph.underlines().setAmbiguousTriples(triples); - graph.underlines().setUnderLineTriples(triples); - graph.underlines().setDottedUnderLineTriples(triples); + graph.setAmbiguousTriples(triples); + graph.setUnderLineTriples(triples); + graph.setDottedUnderLineTriples(triples); } From 5aa9a5a5c05e7cad9b9cd8045cacdf991803b4b4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 12 May 2023 14:50:42 -0400 Subject: [PATCH 413/464] Fixed JSON loading bugs. --- .../main/java/edu/cmu/tetrad/util/JsonUtils.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java index 4b0942f9d8..11d3e5cd38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/JsonUtils.java @@ -58,11 +58,11 @@ public static Graph parseJSONObjectToTetradGraph(JSONObject jObj) { // stuffRemovedSinceLastTripleAccess graph.removeTriplesNotInGraph(); - // highlightedEdges - Set highlightedEdges = JsonUtils.parseJSONArrayToTetradEdges(graph, jObj.getJSONArray("highlightedEdges")); - for (Edge edge : highlightedEdges) { - edge.setHighlighted(true); - } +// // highlightedEdges +// Set highlightedEdges = JsonUtils.parseJSONArrayToTetradEdges(graph, jObj.getJSONArray("highlightedEdges")); +// for (Edge edge : highlightedEdges) { +// edge.setHighlighted(true); +// } return graph; } @@ -98,12 +98,12 @@ public static Set parseJSONArrayToTetradEdges(Graph graph, JSONArray jArra } public static Edge parseJSONObjectToTetradEdge(Graph graph, JSONObject jObj) { - Endpoint[] TYPES = new Endpoint[]{Endpoint.TAIL, Endpoint.ARROW, Endpoint.CIRCLE, Endpoint.STAR, Endpoint.NULL}; +// Endpoint[] TYPES = new Endpoint[]{Endpoint.TAIL, Endpoint.ARROW, Endpoint.CIRCLE, Endpoint.STAR, Endpoint.NULL}; Node node1 = graph.getNode(jObj.getJSONObject("node1").getString("name")); Node node2 = graph.getNode(jObj.getJSONObject("node2").getString("name")); - Endpoint endpoint1 = TYPES[jObj.getJSONObject("endpoint1").getInt("ordinal")]; - Endpoint endpoint2 = TYPES[jObj.getJSONObject("endpoint2").getInt("ordinal")]; + Endpoint endpoint1 = Endpoint.valueOf(jObj.getString("endpoint1")); + Endpoint endpoint2 = Endpoint.valueOf(jObj.getString("endpoint2")); Edge edge = new Edge(node1, node2, endpoint1, endpoint2); try { From 594e7ab96ce8b41e48dce85a8196481942012062 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 12 May 2023 15:17:13 -0400 Subject: [PATCH 414/464] Fixed bug where saved node positions were not used after relading a JSON graph file. --- .../src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java | 2 +- tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java index a49746a84f..e3239ed047 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java @@ -50,7 +50,7 @@ public void actionPerformed(ActionEvent e) { Preferences.userRoot().put("fileSaveLocation", file.getParent()); Graph graph = GraphPersistence.loadGraphJson(file); - LayoutUtil.circleLayout(graph, 200, 200, 150); +// LayoutUtil.circleLayout(graph, 200, 200, 150); this.graphEditable.setGraph(graph); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java index e263e437b4..dbf722ec82 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Set; +// This used ot be a field in the graph classes but that led to a circular dependency +// between the graph and the graph reader/writer. So now it's a separate class. public class Underlines implements TripleClassifier, TetradSerializable { static final long serialVersionUID = 23L; From 8e71ea4e7e5bd18c00b83b1f34f4bb76ff41d09d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 06:20:37 -0400 Subject: [PATCH 415/464] Typo. --- .../src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java | 3 +++ tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java index e3239ed047..c1afb87471 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphJson.java @@ -50,6 +50,9 @@ public void actionPerformed(ActionEvent e) { Preferences.userRoot().put("fileSaveLocation", file.getParent()); Graph graph = GraphPersistence.loadGraphJson(file); + + // The saved node positions should be used instead of just arranging the + // nodes in a circle. // LayoutUtil.circleLayout(graph, 200, 200, 150); this.graphEditable.setGraph(graph); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index bbc3b2076e..0c2474cc54 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -283,7 +283,7 @@ public static boolean isStable(Matrix bHat) { } /** - * Scares the given matrix M by diving each entry (i, j) by M(j, j) + * Scales the given matrix M by diving each entry (i, j) by M(j, j) * * @param M The matrix to scale. * @return The scaled matrix. From 09d65fc1f14d3edfd4e80ec1c3c181a073bf137e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 07:11:01 -0400 Subject: [PATCH 416/464] Fixed LiNGAM to use the Hungarian algorithm. --- .../algorithm/continuous/dag/Lingam.java | 3 -- .../java/edu/cmu/tetrad/search/LingD.java | 54 +++---------------- .../java/edu/cmu/tetrad/search/Lingam.java | 14 +---- 3 files changed, 8 insertions(+), 63 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 3d1e23e5e3..8fa59e8355 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -45,12 +45,10 @@ public Graph search(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); double bThreshold = parameters.getDouble(Params.THRESHOLD_B); - double spineThreshold = parameters.getDouble(Params.THRESHOLD_SPINE); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); lingam.setBThreshold(bThreshold); - lingam.setSpineThreshold(spineThreshold); Matrix bHat = lingam.fitW(W); Graph graph = LingD.makeGraph(bHat, data.getVariables()); @@ -96,7 +94,6 @@ public List getParameters() { parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_TOLERANCE); parameters.add(Params.THRESHOLD_B); - parameters.add(Params.THRESHOLD_SPINE); return parameters; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 0c2474cc54..00a4307f75 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -110,7 +110,7 @@ public List fit(DataSet D) { * @return A list of estimated B Hat matrices generated by LiNG-D. */ public List fitW(Matrix W) { - List pairs = nRooks(W.transpose(), spineThreshold); + List pairs = pairsNRook(W.transpose(), spineThreshold); if (pairs.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); @@ -215,44 +215,14 @@ public static Graph makeGraph(Matrix B, List variables) { /** * Finds a column permutation of the W matrix that maximizes the sum - * of 1 / |Wii| for diagonal elements Wii in W. This will be speeded up - * if W is a thresholded matrix. + * of 1 / |Wii| for diagonal elements Wii in W. * - * @param W The W matrix, WX = e. - * @param spineThrehold The threshold used in NRooks to search for alternative strong diagonals. + * @param W The W matrix, WX = e. * @return The model with the strongest diagonal, as a permutation matrix pair. * @see PermutationMatrixPair */ - public static PermutationMatrixPair strongestDiagonal(Matrix W, double spineThrehold) { - List pairs = nRooks(W.transpose(), spineThrehold); - - if (pairs.isEmpty()) { - throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); - } - - PermutationMatrixPair bestPair = null; - double sum1 = Double.NEGATIVE_INFINITY; - - for (PermutationMatrixPair pair : pairs) { - Matrix permutedMatrix = pair.getPermutedMatrix(); - - double sum = 0.0; - for (int j = 0; j < permutedMatrix.rows(); j++) { - double a = permutedMatrix.get(j, j); - sum += abs(a); - } - - if (sum > sum1) { - sum1 = sum; - bestPair = pair; - } - } - - if (bestPair == null) { - throw new IllegalArgumentException("Could not find a best N Rooks solution with that threshold."); - } - - return bestPair; + public static PermutationMatrixPair hungarianDiagonal(Matrix W) { + return hungarian(W.transpose()); } /** @@ -345,13 +315,7 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold } @NotNull - public static List nRooks(Matrix W, double spineThreshold) { - return pairsNRook(W, spineThreshold); -// return pairsHungarian(W); - } - - @NotNull - private static List pairsHungarian(Matrix W) { + private static PermutationMatrixPair hungarian(Matrix W) { double[][] costMatrix = new double[W.rows()][W.columns()]; for (int i = 0; i < W.rows(); i++) { @@ -367,14 +331,10 @@ private static List pairsHungarian(Matrix W) { HungarianAlgorithm alg = new HungarianAlgorithm(costMatrix); int[][] assignment = alg.findOptimalAssignment(); - List pairs = new ArrayList<>(); - int[] perm = new int[assignment.length]; for (int i = 0; i < perm.length; i++) perm[i] = assignment[i][1]; - PermutationMatrixPair pair = new PermutationMatrixPair(W, perm, null); - pairs.add(pair); - return pairs; + return new PermutationMatrixPair(W, perm, null); } @NotNull diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 5a7d60a8e5..9bc81b8009 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -54,7 +54,6 @@ * @author josephramsey */ public class Lingam { - private double spineThreshold = 0.5; private double bThreshold = 0.1; /** @@ -81,7 +80,7 @@ public Matrix fit(DataSet D) { * @return The estimated B Hat matrix. */ public Matrix fitW(Matrix W) { - PermutationMatrixPair bestPair = LingD.strongestDiagonal(W, spineThreshold); + PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); return LingD.getScaledBHat(bestPair, bThreshold); } @@ -94,16 +93,5 @@ public void setBThreshold(double bThreshold) { if (bThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + bThreshold); this.bThreshold = bThreshold; } - - /** - * Sets the threshold used to prune the matrix for purpose of searching for alterantive strong dia=gonals.. - * - * @param spineThreshold The threshold, a non-negative number. - */ - public void setSpineThreshold(double spineThreshold) { - if (spineThreshold < 0) - throw new IllegalArgumentException("Expecting a non-negative number: " + spineThreshold); - this.spineThreshold = spineThreshold; - } } From 67ad0220050480306a4459241113c5bbabc08c58 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 07:40:21 -0400 Subject: [PATCH 417/464] Fixed LiNGAM to use the Hungarian algorithm. --- .../java/edu/cmu/tetrad/search/Lingam.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 9bc81b8009..506fa96fdb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -32,21 +32,15 @@ *

    The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, - * and no attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes - * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM - * since it was tangential to the effort to get LiNG-D to work. Also, only a passing effort - * to get either of these algorithms to handle real data. There are two tuning parameters--a - * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges - * in the final graph; these are finicky. So there's more work to do, and the implementation may - * improve in the future.

    + * and no attempt was made here to ensure that LiNGAM outputs a DAG. Fpr acuyclic inputs, + * it does tend to. Also, no attempt was made to implement DirectLiNGAM since it was tangential + * to the effort to get LiNG-D to work. Also, only a passing effort to get either of these + * algorithms to handle real data. There are one tuning parameters (in addition to the FastICA + * paramters that are exposed)--a threshold on the B matrix for finding edges in the final + * graph. A future version may use bootstrapping with a p-value; this has not been addressed + * here.

    * - *

    Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; - * these were not compared head to head, though the initial impression was that N Rooks was better, - * so this version uses it.

    - * - *

    This implementation has two parameters, a threshold (for N Rooks) on the minimum values - * in absolute value for including entries in a possible strong diagonal for W, and a threshold - * for BHat for including edges in the final graph.

    + *

    We are using the Hungarian Algorithm to fine best diagonal for the W matrix.

    * *

    This class is not configured to respect knowledge of forbidden and required * edges.

    @@ -57,14 +51,14 @@ public class Lingam { private double bThreshold = 0.1; /** - * Constructs a new LiNGAM algorithm with the given alpha level (used for pruning). + * Constructor.. */ public Lingam() { } /** - * Fits a LiNGAM model to the given dataset using a default method for estimting - * W. + * Fits a LiNGAM model to the given dataset using a default method for estimmting W. + * * @param D A continuous dataset. * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. */ From ef4a018ac53b01cb8cf61715aefdf95818c9eae0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 07:41:53 -0400 Subject: [PATCH 418/464] Fixed LiNGAM to use the Hungarian algorithm. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 506fa96fdb..c9319156de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -68,7 +68,7 @@ public Matrix fit(DataSet D) { } /** - * Searches given a W matrix is that is provided by the user, WX = e. + * Searches given a W matrix is that is provided by the user (where WX = e). * * @param W A W matrix estimated by the user, possibly by some other method. * @return The estimated B Hat matrix. @@ -79,7 +79,8 @@ public Matrix fitW(Matrix W) { } /** - * The threshold to use for estimated B Hat matrices for the LiNGAM algorithm. + * The threshold to use for set small elemtns to zerp in the B Hat matrices for the + * LiNGAM algorithm. * * @param bThreshold Some value >= 0. */ From 3d0ed5a838cf243e7fdc1c14cc383d2d46cbcc47 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 07:45:28 -0400 Subject: [PATCH 419/464] Fixed LiNGAM to use the Hungarian algorithm. --- .../java/edu/cmu/tetrad/search/LingD.java | 20 ++++--------------- .../java/edu/cmu/tetrad/search/Lingam.java | 7 +++++-- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 00a4307f75..e7fa35fdfd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -44,27 +44,15 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

    Implements the LiNG-D algorithm as well as a number of ancillary - * methods for LiNG-D and LiNGAM. The reference is here:

    + *

    Implements the LiNG-D algorithm as well as a number of ancillary methods for + * LiNG-D and LiNGAM. The reference is here:

    * *

    Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering * cyclic causal models by independent components analysis. arXiv preprint * arXiv:1206.3273.

    * - *

    The focus for this implementation was making super-simple code, not so much - * because the method was trivial (it's not) but out of an attempt to compartmentalize. - * Bootstrapping and other forms of improving the estimate of BHat were not addressed, - * and no attempt was made here to ensure that LiNGAM outputs a DAG. For high sample sizes - * for an acyclic model it does tend to. No attempt was made to implement DirectLiNGAM - * since it was tangential to the effort to get LiNG-D to work. Also, only a passing effort - * to get either of these algorithms to handle real data. There are two tuning parameters--a - * threshold for finding a strong diagonal and a threshold on the B matrix for finding edges - * in the final graph; these are finicky. So there's more work to do, and the implementation may - * improve in the future.

    - * - *

    Both N Rooks and Hungarian Algorithm were tested for finding the best strong diagonal; - * these were not compared head to head, though the initial impression was that N Rooks was better, - * so this version uses it.

    + *

    We use the N Rooks algorithm to find alternative cyclic models, as in the above + * paper.

    * *

    This implementation has two parameters, a threshold (for N Rooks) on the minimum values * in absolute value for including entries in a possible strong diagonal for W, and a threshold diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index c9319156de..d3b9a071c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -26,8 +26,11 @@ import edu.cmu.tetrad.util.Matrix; /** - *

    Implements an interpretation of the LiNGAM algorithm in Shimizu, Hoyer, Hyvarinen, - * and Kerminen, a linear nongaussian acyclic model for causal discovery, JMLR 7 (2006).

    + *

    Implements an interpretation of the LiNGAM algorithm. The reference is here:

    + * + *

    Shimizu, S., Hoyer, P. O., Hyvärinen, A., Kerminen, A., & Jordan, M. (2006). A linear + * non-Gaussian acyclic model for causal discovery. Journal of Machine Learning Research, + * 7(10).

    * *

    The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. From c5861cee1f18d8b4f43147903d5b6c033156527a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 07:51:15 -0400 Subject: [PATCH 420/464] Fixed LiNGAM to use the Hungarian algorithm. --- .../java/edu/cmu/tetrad/search/LingD.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index e7fa35fdfd..5a86892bc5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -54,9 +54,10 @@ *

    We use the N Rooks algorithm to find alternative cyclic models, as in the above * paper.

    * - *

    This implementation has two parameters, a threshold (for N Rooks) on the minimum values - * in absolute value for including entries in a possible strong diagonal for W, and a threshold - * for BHat for including edges in the final graph.

    + *

    This implementation has two parameters, a threshold (for N Rooks) on the minimum + * values in absolute value for including entries in a possible strong diagonal for W, + * and a threshold for B Hat for setting zeros for small betas (i.e., pruning edges from + * the final graph.

    * *

    This class is not configured to respect knowledge of forbidden and required * edges.

    @@ -71,15 +72,13 @@ public class LingD { private double bThreshold = 0.1; /** - * Constructor. The W matrix needs to be estimated separately (e.g., using - * the Lingam.estimateW(.) method using the ICA method in Tetrad, or some - * method in Python or R) and passed into the search(W) method. + * Constructor. */ public LingD() { } /** - * Fits a LiNG-D model to the given dataset using a default method for estimting + * Fits a LiNG-D model to the given dataset using a default method for estimating * W. * @param D A continuous dataset. * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. @@ -91,7 +90,7 @@ public List fit(DataSet D) { /** * Performs the LiNG-D algorithm given a W matrix, which needs to be discovered - * elsewhere. The local algorithm is assumed--in fact, the W matrix is simply + * elsewhere. The 'local algorithm' is assumed--in fact, the W matrix is simply * thresholded without bootstrapping. * * @param W The W matrix to be used. @@ -115,7 +114,7 @@ public List fitW(Matrix W) { } /** - * Sets the threshold used to prune the B matrix for the local algorithms. + * Sets the threshold used to prune the B matrix for the local algorithm. * * @param bThreshold The threshold, a non-negative number. */ @@ -125,7 +124,8 @@ public void setBThreshold(double bThreshold) { } /** - * Sets the threshold used to prune the matrix for purpose of searching for alterantive strong dia=gonals.. + * Sets the threshold used to prune the matrix for purpose of searching for alterantive + * strong diagonals.. * * @param spineThreshold The threshold, a non-negative number. */ @@ -136,8 +136,8 @@ public void setSpineThreshold(double spineThreshold) { } /** - * Estimates the W matrix using FastICA. Assumes the "parallel" option, using - * the "exp" function. + * Estimates the W matrix using FastICA. Assumes the "parallel" option, using the + * "exp" function. * * @param data The dataset to estimate W for. * @param fastIcaMaxIter Maximum number of iterations of ICA. @@ -259,7 +259,7 @@ public static Matrix scale(Matrix M) { } /** - * Thresholds the givem matrix, sending any small entries to zero. + * Thresholds the givem matrix, sending any small entries in absolute value to zero. * * @param M The matrix to threshold. * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. @@ -281,8 +281,8 @@ public static Matrix threshold(Matrix M, double threshold) { } /** - * Returns the BHat matrix, permuted to causal order (lower triangle) and - * scaled so that the diagonal consists only of 1's. + * Returns the BHat matrix, permuted to the variable order of the original + * data and scaled so that the diagonal consists only of 1's. * * @param pair The (column permutation, thresholded, column permuted W matrix) * pair. From 21501593298ad4cb59c0a5afa2284a586f999392 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 07:55:12 -0400 Subject: [PATCH 421/464] Typo. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index d3b9a071c7..c05c518a80 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -60,7 +60,7 @@ public Lingam() { } /** - * Fits a LiNGAM model to the given dataset using a default method for estimmting W. + * Fits a LiNGAM model to the given dataset using a default method for estimating W. * * @param D A continuous dataset. * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. From b9d180acbdc1fcd9c79aaa47c3c8db8536e8cdad Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 07:58:38 -0400 Subject: [PATCH 422/464] Fixed test. --- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java | 1 - 1 file changed, 1 deletion(-) diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java index 75acd0baf8..8d1212de8c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java @@ -92,7 +92,6 @@ public void test1() { Lingam lingam = new Lingam(); lingam.setBThreshold(bThreshold); - lingam.setSpineThreshold(spineThreshold); Matrix lingamBhat = lingam.fit(dataSet); Graph lingamGraph = LingD.makeGraph(lingamBhat, dataSet.getVariables()); System.out.println("Lingam graph = " + lingamGraph); From 96fcb6fd3a5f747e60c2f042aa0e24831e4a2d64 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 08:15:32 -0400 Subject: [PATCH 423/464] Typo. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index c05c518a80..f2828f4288 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -28,9 +28,9 @@ /** *

    Implements an interpretation of the LiNGAM algorithm. The reference is here:

    * - *

    Shimizu, S., Hoyer, P. O., Hyvärinen, A., Kerminen, A., & Jordan, M. (2006). A linear - * non-Gaussian acyclic model for causal discovery. Journal of Machine Learning Research, - * 7(10).

    + *

    Shimizu, S., Hoyer, P. O., Hyvärinen, A., Kerminen, A., & Jordan, M. (2006). + * A linear non-Gaussian acyclic model for causal discovery. Journal of Machine Learning + * Research, 7(10).

    * *

    The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. From 228ca8c8a056463c490e601f9a4fd7d8891569f5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 08:19:11 -0400 Subject: [PATCH 424/464] Typo. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 1 + tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 1 + 2 files changed, 2 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 5a86892bc5..7de721c7ec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -66,6 +66,7 @@ * @author gustavolacerda * @author patrickhoyer * @author josephramsey + * @see Lingam */ public class LingD { private double spineThreshold = 0.5; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index f2828f4288..f7b763039c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -49,6 +49,7 @@ * edges.

    * * @author josephramsey + * @see LingD */ public class Lingam { private double bThreshold = 0.1; From 6f7f5af9614ccf67b1293db8b70f94501197f86d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 09:23:55 -0400 Subject: [PATCH 425/464] Typo. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index f7b763039c..281cc2efeb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -43,7 +43,7 @@ * graph. A future version may use bootstrapping with a p-value; this has not been addressed * here.

    * - *

    We are using the Hungarian Algorithm to fine best diagonal for the W matrix.

    + *

    We are using the Hungarian Algorithm to find the best diagonal for the W matrix.

    * *

    This class is not configured to respect knowledge of forbidden and required * edges.

    From e42e9647c36b11de6558d09195a69c04c145b40b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 09:37:20 -0400 Subject: [PATCH 426/464] Typo. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 281cc2efeb..f0a426027d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -43,7 +43,8 @@ * graph. A future version may use bootstrapping with a p-value; this has not been addressed * here.

    * - *

    We are using the Hungarian Algorithm to find the best diagonal for the W matrix.

    + *

    We are using the Hungarian Algorithm to find the best diagonal for the W matrix + * and are not doing any searches over all permutations.

    * *

    This class is not configured to respect knowledge of forbidden and required * edges.

    From 24c0f67bb85033fb6372c4d3d32e91a747310464 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 09:44:39 -0400 Subject: [PATCH 427/464] Fixing docs. --- .../main/java/edu/cmu/tetrad/search/Lingam.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index f0a426027d..2677a946e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -35,13 +35,13 @@ *

    The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, - * and no attempt was made here to ensure that LiNGAM outputs a DAG. Fpr acuyclic inputs, - * it does tend to. Also, no attempt was made to implement DirectLiNGAM since it was tangential - * to the effort to get LiNG-D to work. Also, only a passing effort to get either of these - * algorithms to handle real data. There are one tuning parameters (in addition to the FastICA - * paramters that are exposed)--a threshold on the B matrix for finding edges in the final - * graph. A future version may use bootstrapping with a p-value; this has not been addressed - * here.

    + * and no attempt was made here to ensure that LiNGAM outputs a DAG. Fpr acyclic inputs, + * it does tend to, thought for cyclic inputs it tends to produce the cyclic DAG, so long + * as coefficients are bounded somewhat away from zero. No attempt was made to implement + * DirectLiNGAM since it was tangential to the effort to get LiNG-D to work. Only a passing + * effort was made to ensure good performance on real data. There is one tuning parameters + * (in addition to the FastICA paramters that are exposed), a threshold on the B Hat matrix + * for finding edges in the final graph.

    * *

    We are using the Hungarian Algorithm to find the best diagonal for the W matrix * and are not doing any searches over all permutations.

    From 3f8602c4765d0b6ab53808070e78e0b9bf88d243 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 09:54:36 -0400 Subject: [PATCH 428/464] Fixing docs. --- .../src/main/java/edu/cmu/tetrad/search/Lingam.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 2677a946e5..a7675f9cef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -36,12 +36,12 @@ * because the method was trivial (it's not) but out of an attempt to compartmentalize. * Bootstrapping and other forms of improving the estimate of BHat were not addressed, * and no attempt was made here to ensure that LiNGAM outputs a DAG. Fpr acyclic inputs, - * it does tend to, thought for cyclic inputs it tends to produce the cyclic DAG, so long - * as coefficients are bounded somewhat away from zero. No attempt was made to implement - * DirectLiNGAM since it was tangential to the effort to get LiNG-D to work. Only a passing - * effort was made to ensure good performance on real data. There is one tuning parameters - * (in addition to the FastICA paramters that are exposed), a threshold on the B Hat matrix - * for finding edges in the final graph.

    + * it does tend to for acyclic inputs in simulation, though for cyclic inputs it tends + * to produce the cyclic DAG, so long as coefficients are bounded somewhat away from zero. + * No attempt was made to implement DirectLiNGAM since it was tangential to the effort + * to get LiNG-D to work. Only a passing effort was made to ensure good performance on + * real data. There is one tuning parameters (in addition to the FastICA paramters that + * are exposed), a threshold on the B Hat matrix for finding edges in the final graph.

    * *

    We are using the Hungarian Algorithm to find the best diagonal for the W matrix * and are not doing any searches over all permutations.

    From 33087ef97b81554b3e2ad20013ed6f1817ba3a55 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 11:10:09 -0400 Subject: [PATCH 429/464] Fixed Matrix.rows() and Matrix.cols() to getNumRows and getNumCols Added guaranteeAcyclic parameters to LiNGAM. --- docs/manual/index.html | 23 ++++++ .../editor/FactorAnalysisAction.java | 14 ++-- .../model/ConvertToPositiveSkew.java | 4 +- .../tetradapp/model/EdgeWeightComparison.java | 6 +- .../tetradapp/model/FactorAnalysisRunner.java | 14 ++-- .../model/PValueImproverWrapper.java | 2 +- .../datamanip/CovMatrixAverageWrapper.java | 6 +- .../datamanip/CovMatrixDifferenceWrapper.java | 10 +-- .../model/datamanip/CovMatrixSumWrapper.java | 8 +- .../SubsetSelectedVariablesWrapper.java | 2 +- .../algorithm/continuous/dag/Lingam.java | 5 +- .../algorithm/oracle/cpdag/GesMe.java | 10 +-- .../algorithm/other/FactorAnalysis.java | 20 ++--- .../java/edu/cmu/tetrad/cluster/KMeans.java | 44 +++++----- .../cmu/tetrad/data/CorrelationMatrix.java | 2 +- .../edu/cmu/tetrad/data/CovarianceMatrix.java | 2 +- .../tetrad/data/CovarianceMatrixOnTheFly.java | 2 +- .../java/edu/cmu/tetrad/data/DataUtils.java | 82 +++++++++---------- .../edu/cmu/tetrad/data/TimeSeriesData.java | 4 +- .../regression/RegressionCovariance.java | 2 +- .../tetrad/regression/RegressionDataset.java | 54 ++++++------ .../edu/cmu/tetrad/search/FactorAnalysis.java | 46 +++++------ .../java/edu/cmu/tetrad/search/FastIca.java | 62 +++++++------- .../main/java/edu/cmu/tetrad/search/Fofc.java | 6 +- .../java/edu/cmu/tetrad/search/LingD.java | 33 ++++---- .../java/edu/cmu/tetrad/search/Lingam.java | 59 ++++++++++++- .../main/java/edu/cmu/tetrad/search/Lofs.java | 4 +- .../java/edu/cmu/tetrad/search/Mimbuild.java | 22 ++--- .../edu/cmu/tetrad/search/MimbuildTrek.java | 12 +-- .../java/edu/cmu/tetrad/search/PcLingam.java | 4 +- .../tetrad/search/score/MvpLikelihood.java | 12 +-- .../cmu/tetrad/search/score/SemBicScore.java | 6 +- .../cmu/tetrad/search/test/IndTestHsic.java | 4 +- .../java/edu/cmu/tetrad/search/test/Kci.java | 12 +-- .../search/utils/PermutationMatrixPair.java | 8 +- .../cmu/tetrad/search/utils/ShiftSearch.java | 3 +- .../edu/cmu/tetrad/search/utils/TsUtils.java | 16 ++-- .../search/work_in_progress/Glasso.java | 10 +-- .../work_in_progress/IndTestCramerT.java | 2 +- .../IndTestFisherZPercentIndependent.java | 4 +- .../work_in_progress/InverseCorrelation.java | 4 +- .../work_in_progress/MnlrLikelihood.java | 10 +-- .../cmu/tetrad/sem/LargeScaleSimulation.java | 4 +- .../edu/cmu/tetrad/sem/SemEstimatorGibbs.java | 2 +- .../main/java/edu/cmu/tetrad/sem/SemIm.java | 16 ++-- .../cmu/tetrad/sem/SemStdErrorEstimator.java | 4 +- .../edu/cmu/tetrad/sem/StandardizedSemIm.java | 4 +- .../main/java/edu/cmu/tetrad/util/Matrix.java | 46 +++++------ .../java/edu/cmu/tetrad/util/MatrixUtils.java | 22 ++--- .../main/java/edu/cmu/tetrad/util/Params.java | 1 + .../java/edu/cmu/tetrad/util/StatUtils.java | 16 ++-- .../test/ExploreAutisticsNeurotypicals.java | 2 +- .../cmu/tetrad/test/TestStandardizedSem.java | 2 +- 53 files changed, 430 insertions(+), 344 deletions(-) diff --git a/docs/manual/index.html b/docs/manual/index.html index 15742d3997..4035d90625 100755 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -5567,6 +5567,29 @@

    fastIcaA

    id="thresholdBHat_value_type">Double
  • +

    guaranteeAcyclic

    +
      +
    • Short Description: True if the output should be + guaranteed to be acyclic +
    • +
    • Long Description: The estimated B matrix + is further thresholded by setting small coefficients to zero + until an acyclic model is produced. +
    • +
    • Default Value: true
    • +
    • Lower Bound: +
    • +
    • Upper + Bound:
    • +
    • Value Type: Boolean
    • +
    +

    thresholdSpine

      factors = new Vector<>(); - for (int i = 0; i < rotatedSolution.columns(); i++) { + for (int i = 0; i < rotatedSolution.getNumColumns(); i++) { ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1)); factor.setNodeType(NodeType.LATENT); graph.addNode(factor); factors.add(factor); } - for (int i = 0; i < rotatedSolution.rows(); i++) { - for (int j = 0; j < rotatedSolution.columns(); j++) { + for (int i = 0; i < rotatedSolution.getNumRows(); i++) { + for (int j = 0; j < rotatedSolution.getNumColumns(); j++) { if (FastMath.abs(rotatedSolution.get(i, j)) > threshold) { graph.addDirectedEdge(factors.get(j), observedVariables.get(i)); //HEY JOE -- rotatedSolution.get(i, j) is the edge coeficient @@ -172,10 +172,10 @@ private JPanel createDialog(FactorAnalysis analysis) { } private String tableString(Matrix matrix, NumberFormat nf, double threshold) { - TextTable table = new TextTable(matrix.rows() + 1, matrix.columns() + 1); + TextTable table = new TextTable(matrix.getNumRows() + 1, matrix.getNumColumns() + 1); - for (int i = 0; i < matrix.rows() + 1; i++) { - for (int j = 0; j < matrix.columns() + 1; j++) { + for (int i = 0; i < matrix.getNumRows() + 1; i++) { + for (int j = 0; j < matrix.getNumColumns() + 1; j++) { if (i > 0 && j == 0) { table.setToken(i, 0, "X" + i); } else if (i == 0 && j > 0) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java index 2e057364c2..a65b54a5e9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java @@ -58,11 +58,11 @@ private ConvertToPositiveSkew(DataWrapper wrapper) { Matrix matrix2D = dataSet.getDoubleData(); - for (int j = 0; j < matrix2D.columns(); j++) { + for (int j = 0; j < matrix2D.getNumColumns(); j++) { double[] c = matrix2D.getColumn(j).toArray(); double skew = StatUtils.skewness(c); - for (int i = 0; i < matrix2D.rows(); i++) { + for (int i = 0; i < matrix2D.getNumRows(); i++) { matrix2D.set(i, j, matrix2D.get(i, j) * FastMath.signum(skew)); } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java index 7dd2199ba5..35301a8210 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java @@ -62,12 +62,12 @@ public String getDisplayString() { Matrix referenceMatrix = ref.getEdgeCoef(); Matrix targetMatrix = this.target.getEdgeCoef(); - if (targetMatrix.columns() != referenceMatrix.columns() || targetMatrix.rows() != referenceMatrix.rows()) + if (targetMatrix.getNumColumns() != referenceMatrix.getNumColumns() || targetMatrix.getNumRows() != referenceMatrix.getNumRows()) return "The SEM IM's you selected don't have the same number of variables! No comparison is possible here."; double score = 0; - for (int i = 0; i < ref.getEdgeCoef().rows(); i++) { - for (int j = 0; j < ref.getEdgeCoef().columns(); j++) { + for (int i = 0; i < ref.getEdgeCoef().getNumRows(); i++) { + for (int j = 0; j < ref.getEdgeCoef().getNumColumns(); j++) { score += (targetMatrix.get(i, j) - referenceMatrix.get(i, j)) * (targetMatrix.get(i, j) - referenceMatrix.get(i, j)); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java index efd938aa11..0a55e663c6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java @@ -87,7 +87,7 @@ public void execute() { this.output += tableString(unrotatedSolution, nf, Double.POSITIVE_INFINITY); - if (unrotatedSolution.columns() != 1) { + if (unrotatedSolution.getNumColumns() != 1) { this.output += "\n\nRotated Matrix (using sequential varimax):\n"; this.output += tableString(this.rotatedSolution, nf, this.threshold); } @@ -103,15 +103,15 @@ public void execute() { Vector factors = new Vector<>(); - for (int i = 0; i < getRotatedSolution().columns(); i++) { + for (int i = 0; i < getRotatedSolution().getNumColumns(); i++) { ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1)); factor.setNodeType(NodeType.LATENT); graph.addNode(factor); factors.add(factor); } - for (int i = 0; i < getRotatedSolution().rows(); i++) { - for (int j = 0; j < getRotatedSolution().columns(); j++) { + for (int i = 0; i < getRotatedSolution().getNumRows(); i++) { + for (int j = 0; j < getRotatedSolution().getNumColumns(); j++) { if (FastMath.abs(getRotatedSolution().get(i, j)) > getThreshold()) { graph.addDirectedEdge(factors.get(j), observedVariables.get(i)); } @@ -122,10 +122,10 @@ public void execute() { } private String tableString(Matrix matrix, NumberFormat nf, double threshold) { - TextTable table = new TextTable(matrix.rows() + 1, matrix.columns() + 1); + TextTable table = new TextTable(matrix.getNumRows() + 1, matrix.getNumColumns() + 1); - for (int i = 0; i < matrix.rows() + 1; i++) { - for (int j = 0; j < matrix.columns() + 1; j++) { + for (int i = 0; i < matrix.getNumRows() + 1; i++) { + for (int j = 0; j < matrix.getNumColumns() + 1; j++) { if (i > 0 && j == 0) { table.setToken(i, 0, "X" + i); } else if (i == 0 && j > 0) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index ab368e9e69..4083dc8023 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -348,7 +348,7 @@ public DataSet simulateDataCholesky(int sampleSize, Matrix covar, List var for (int row = 0; row < sampleSize; row++) { // Step 1. Generate normal samples. - double[] exoData = new double[cholesky.rows()]; + double[] exoData = new double[cholesky.getNumRows()]; for (int i = 0; i < exoData.length; i++) { exoData[i] = RandomUtil.getInstance().nextNormal(0, 1); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java index 0fd030b930..81ee8a58e4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java @@ -63,10 +63,10 @@ private void calcAverage(List wrappers) { cov.add(((ICovarianceMatrix) selectedDataModel).getMatrix()); } - Matrix cov3 = new Matrix(cov.get(0).rows(), cov.get(0).rows()); + Matrix cov3 = new Matrix(cov.get(0).getNumRows(), cov.get(0).getNumRows()); - for (int i = 0; i < cov.get(0).rows(); i++) { - for (int j = 0; j < cov.get(0).rows(); j++) { + for (int i = 0; i < cov.get(0).getNumRows(); i++) { + for (int j = 0; j < cov.get(0).getNumRows(); j++) { double c = 0.0; for (Matrix matrix : cov) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java index 4858a4c0e4..1bf4417223 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java @@ -73,21 +73,21 @@ public CovMatrixDifferenceWrapper(DataWrapper wrapper1, DataWrapper wrapper2, Pa } private Matrix calcDifference(Matrix corr1, Matrix corr2) { - if (corr1.rows() != corr2.rows()) { + if (corr1.getNumRows() != corr2.getNumRows()) { throw new IllegalArgumentException("Covariance matrices must be the same size."); } - Matrix corr3 = new Matrix(corr2.rows(), corr2.rows()); + Matrix corr3 = new Matrix(corr2.getNumRows(), corr2.getNumRows()); - for (int i = 0; i < corr3.rows(); i++) { - for (int j = 0; j < corr3.rows(); j++) { + for (int i = 0; i < corr3.getNumRows(); i++) { + for (int j = 0; j < corr3.getNumRows(); j++) { double v = corr1.get(i, j) - corr2.get(i, j); corr3.set(i, j, v); // corr3.set(j, i, v); } } - for (int i = 0; i < corr3.rows(); i++) { + for (int i = 0; i < corr3.getNumRows(); i++) { corr3.set(i, i, FastMath.abs(corr3.get(i, i))); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java index fb15256303..438f147d7b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java @@ -71,14 +71,14 @@ public CovMatrixSumWrapper(DataWrapper wrapper1, DataWrapper wrapper2) { } private Matrix calcSum(Matrix corr1, Matrix corr2) { - if (corr1.rows() != corr2.rows()) { + if (corr1.getNumRows() != corr2.getNumRows()) { throw new IllegalArgumentException("Covariance matrices must be the same size."); } - Matrix corr3 = new Matrix(corr2.rows(), corr2.rows()); + Matrix corr3 = new Matrix(corr2.getNumRows(), corr2.getNumRows()); - for (int i = 0; i < corr3.rows(); i++) { - for (int j = 0; j < corr3.rows(); j++) { + for (int i = 0; i < corr3.getNumRows(); i++) { + for (int j = 0; j < corr3.getNumRows(); j++) { double v = corr1.get(i, j) + corr2.get(i, j); corr3.set(i, j, v); corr3.set(j, i, v); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java index 21bb8c1c34..4fbfd95e62 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java @@ -110,7 +110,7 @@ private static DataModel createCovarianceModel(ICovarianceMatrix data) { selectedIndices, selectedIndices).copy(); - return new CovarianceMatrix(DataUtils.createContinuousVariables(nodeNames), newMatrix, matrix.rows()); + return new CovarianceMatrix(DataUtils.createContinuousVariables(nodeNames), newMatrix, matrix.getNumRows()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java index 8fa59e8355..32339af02a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java @@ -44,11 +44,11 @@ public Graph search(DataModel dataSet, Parameters parameters) { int maxIter = parameters.getInt(Params.FAST_ICA_MAX_ITER); double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - double bThreshold = parameters.getDouble(Params.THRESHOLD_B); Matrix W = LingD.estimateW(data, maxIter, tol, alpha); edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setBThreshold(bThreshold); + lingam.setBThreshold(parameters.getDouble(Params.THRESHOLD_B)); + lingam.setAcyclicityGuaranteed(parameters.getBoolean(Params.GUARANTEE_ACYCLIC)); Matrix bHat = lingam.fitW(W); Graph graph = LingD.makeGraph(bHat, data.getVariables()); @@ -94,6 +94,7 @@ public List getParameters() { parameters.add(Params.FAST_ICA_A); parameters.add(Params.FAST_ICA_TOLERANCE); parameters.add(Params.THRESHOLD_B); + parameters.add(Params.GUARANTEE_ACYCLIC); return parameters; } 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/GesMe.java index 2951bcb3bd..22be190fef 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/GesMe.java @@ -68,7 +68,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { output += tableString(unrotated, nf, Double.POSITIVE_INFINITY); - if (unrotated.columns() != 1) { + if (unrotated.getNumColumns() != 1) { output += "\n\nRotated Matrix (using sequential varimax):\n"; output += tableString(rotated, nf, parameters.getDouble("fa_threshold")); } @@ -160,7 +160,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { output += tableString(L, nf, Double.POSITIVE_INFINITY); - if (L.columns() != 1) { + if (L.getNumColumns() != 1) { output += "\n\nL:\n"; output += tableString(L, nf, threshold); } @@ -228,10 +228,10 @@ public void setCompareToTrue(boolean compareToTrue) { } private String tableString(Matrix matrix, NumberFormat nf, double threshold) { - TextTable table = new TextTable(matrix.rows() + 1, matrix.columns() + 1); + TextTable table = new TextTable(matrix.getNumRows() + 1, matrix.getNumColumns() + 1); - for (int i = 0; i < matrix.rows() + 1; i++) { - for (int j = 0; j < matrix.columns() + 1; j++) { + for (int i = 0; i < matrix.getNumRows() + 1; i++) { + for (int j = 0; j < matrix.getNumColumns() + 1; j++) { if (i > 0 && j == 0) { table.setToken(i, 0, "X" + i); } else if (i == 0 && j > 0) { 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/FactorAnalysis.java index 89534b2876..6d0e7a49c5 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/FactorAnalysis.java @@ -53,30 +53,30 @@ public Graph search(DataModel ds, Parameters parameters) { Vector factors = new Vector<>(); if (parameters.getBoolean("useVarimax")) { - for (int i = 0; i < rotatedSolution.columns(); i++) { + for (int i = 0; i < rotatedSolution.getNumColumns(); i++) { ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1)); factor.setNodeType(NodeType.LATENT); graph.addNode(factor); factors.add(factor); } - for (int i = 0; i < rotatedSolution.rows(); i++) { - for (int j = 0; j < rotatedSolution.columns(); j++) { + for (int i = 0; i < rotatedSolution.getNumRows(); i++) { + for (int j = 0; j < rotatedSolution.getNumColumns(); j++) { if (FastMath.abs(rotatedSolution.get(i, j)) > threshold) { graph.addDirectedEdge(factors.get(j), observedVariables.get(i)); } } } } else { - for (int i = 0; i < unrotatedSolution.columns(); i++) { + for (int i = 0; i < unrotatedSolution.getNumColumns(); i++) { ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1)); factor.setNodeType(NodeType.LATENT); graph.addNode(factor); factors.add(factor); } - for (int i = 0; i < unrotatedSolution.rows(); i++) { - for (int j = 0; j < unrotatedSolution.columns(); j++) { + for (int i = 0; i < unrotatedSolution.getNumRows(); i++) { + for (int j = 0; j < unrotatedSolution.getNumColumns(); j++) { if (FastMath.abs(unrotatedSolution.get(i, j)) > threshold) { graph.addDirectedEdge(factors.get(j), observedVariables.get(i)); } @@ -91,7 +91,7 @@ public Graph search(DataModel ds, Parameters parameters) { output += tableString(unrotatedSolution, nf, Double.POSITIVE_INFINITY); - if (unrotatedSolution.columns() != 1) { + if (unrotatedSolution.getNumColumns() != 1) { output += "\n\nRotated Matrix (using sequential varimax):\n"; output += tableString(rotatedSolution, nf, threshold); } @@ -114,10 +114,10 @@ public Graph search(DataModel ds, Parameters parameters) { } private String tableString(Matrix matrix, NumberFormat nf, double threshold) { - TextTable table = new TextTable(matrix.rows() + 1, matrix.columns() + 1); + TextTable table = new TextTable(matrix.getNumRows() + 1, matrix.getNumColumns() + 1); - for (int i = 0; i < matrix.rows() + 1; i++) { - for (int j = 0; j < matrix.columns() + 1; j++) { + for (int i = 0; i < matrix.getNumRows() + 1; i++) { + for (int j = 0; j < matrix.getNumColumns() + 1; j++) { if (i > 0 && j == 0) { table.setToken(i, 0, "X" + i); } else if (i == 0 && j > 0) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java index 72a8e670c2..491a5162e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/cluster/KMeans.java @@ -161,26 +161,26 @@ public void cluster(Matrix data) { this.centers = pickCenters(this.numCenters, data); this.clusters = new ArrayList<>(); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { this.clusters.add(-1); } } else if (this.initializationType == KMeans.RANDOM_CLUSTERS) { - this.centers = new Matrix(this.numCenters, data.columns()); + this.centers = new Matrix(this.numCenters, data.getNumColumns()); // Randomly assign points to clusters and get the initial centers of // mass from that assignment. this.clusters = new ArrayList<>(); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { this.clusters.add(RandomUtil.getInstance() - .nextInt(this.centers.rows())); + .nextInt(this.centers.getNumRows())); } moveCentersToMeans(); } else if (this.initializationType == KMeans.EXPLICIT_POINTS) { this.clusters = new ArrayList<>(); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { this.clusters.add(-1); } } @@ -254,7 +254,7 @@ public void setMaxIterations(int maxIterations) { } public int getNumClusters() { - return this.centers.rows(); + return this.centers.getNumRows(); } public List getCluster(int k) { @@ -289,7 +289,7 @@ public int iterations() { private double squaredError(int k) { double squaredError = 0.0; - for (int i = 0; i < this.data.rows(); i++) { + for (int i = 0; i < this.data.getNumRows(); i++) { if (this.clusters.get(i) == k) { Vector datum = this.data.getRow(i); Vector center = this.centers.getRow(k); @@ -307,7 +307,7 @@ private double squaredError(int k) { private double totalSquaredError() { double totalSquaredError = 0.0; - for (int k = 0; k < this.centers.rows(); k++) { + for (int k = 0; k < this.centers.getNumRows(); k++) { totalSquaredError += squaredError(k); } @@ -325,11 +325,11 @@ public String toString() { StringBuilder buf = new StringBuilder(); buf.append("Cluster Result (").append(this.clusters.size()) - .append(" cases, ").append(this.centers.columns()) - .append(" feature(s), ").append(this.centers.rows()) + .append(" cases, ").append(this.centers.getNumColumns()) + .append(" feature(s), ").append(this.centers.getNumRows()) .append(" clusters)"); - for (int k = 0; k < this.centers.rows(); k++) { + for (int k = 0; k < this.centers.getNumRows(); k++) { buf.append("\n\tCluster #").append(k + 1).append(": n = ").append(counts.get(k)); buf.append(" Squared Error = ").append(n1.format(squaredError(k))); } @@ -343,12 +343,12 @@ public String toString() { private int reassignPoints() { int numChanged = 0; - for (int i = 0; i < this.data.rows(); i++) { + for (int i = 0; i < this.data.getNumRows(); i++) { Vector datum = this.data.getRow(i); double minDissimilarity = Double.POSITIVE_INFINITY; int cluster = -1; - for (int k = 0; k < this.centers.rows(); k++) { + for (int k = 0; k < this.centers.getNumRows(); k++) { Vector center = this.centers.getRow(k); double dissimilarity = getMetric().dissimilarity(datum, center); @@ -369,13 +369,13 @@ private int reassignPoints() { } private void moveCentersToMeans() { - for (int k = 0; k < this.centers.rows(); k++) { - double[] sums = new double[this.centers.columns()]; + for (int k = 0; k < this.centers.getNumRows(); k++) { + double[] sums = new double[this.centers.getNumColumns()]; int count = 0; - for (int i = 0; i < this.data.rows(); i++) { + for (int i = 0; i < this.data.getNumRows(); i++) { if (this.clusters.get(i) == k) { - for (int j = 0; j < this.data.columns(); j++) { + for (int j = 0; j < this.data.getNumColumns(); j++) { sums[j] += this.data.get(i, j); } @@ -384,7 +384,7 @@ private void moveCentersToMeans() { } if (count != 0) { - for (int j = 0; j < this.centers.columns(); j++) { + for (int j = 0; j < this.centers.getNumColumns(); j++) { this.centers.set(k, j, sums[j] / count); } } @@ -395,7 +395,7 @@ private Matrix pickCenters(int numCenters, Matrix data) { SortedSet indexSet = new TreeSet<>(); while (indexSet.size() < numCenters) { - int candidate = RandomUtil.getInstance().nextInt(data.rows()); + int candidate = RandomUtil.getInstance().nextInt(data.getNumRows()); indexSet.add(candidate); } @@ -408,9 +408,9 @@ private Matrix pickCenters(int numCenters, Matrix data) { rows[++i] = row; } - int[] cols = new int[data.columns()]; + int[] cols = new int[data.getNumColumns()]; - for (int j = 0; j < data.columns(); j++) { + for (int j = 0; j < data.getNumColumns(); j++) { cols[j] = j; } @@ -418,7 +418,7 @@ private Matrix pickCenters(int numCenters, Matrix data) { } private Vector countClusterSizes() { - Vector counts = new Vector(this.centers.rows()); + Vector counts = new Vector(this.centers.getNumRows()); for (int cluster : this.clusters) { if (cluster == -1) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java index be5ae81e08..2ebd4aee6f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java @@ -84,7 +84,7 @@ public void setMatrix(Matrix matrix) { throw new IllegalArgumentException("Matrix must be square."); } - for (int i = 0; i < matrix.rows(); i++) { + for (int i = 0; i < matrix.getNumRows(); i++) { if (FastMath.abs(matrix.get(i, i) - 1.0) > 1.e-5) { throw new IllegalArgumentException( "For a correlation matrix, " + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java index 5c25f27c89..9366f70754 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java @@ -345,7 +345,7 @@ public final void setSampleSize(int sampleSize) { * @return the size of the square matrix. */ public final int getSize() { - return this._covariancesMatrix.columns(); + return this._covariancesMatrix.getNumColumns(); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java index 864067c8e3..0e2d324c6b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java @@ -730,7 +730,7 @@ private void checkMatrix() { "Sample size must be at least 1."); } - if (numVars != matrix.rows() || numVars != matrix.columns()) { + if (numVars != matrix.getNumRows() || numVars != matrix.getNumColumns()) { throw new IllegalArgumentException("Number of variables does not " + "equal the dimension of the matrix."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java index d05ccc08e2..e43383c0af 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java @@ -229,8 +229,8 @@ public static DataSet discreteSerializableInstance() { * @return true iff the data sets contains a missing value. */ public static boolean containsMissingValue(Matrix data) { - for (int i = 0; i < data.rows(); i++) { - for (int j = 0; j < data.columns(); j++) { + for (int i = 0; i < data.getNumRows(); i++) { + for (int j = 0; j < data.getNumColumns(); j++) { if (Double.isNaN(data.get(i, j))) { return true; } @@ -272,9 +272,9 @@ public static DataSet logData(DataSet dataSet, double a, boolean isUnlog, int ba Matrix data = dataSet.getDoubleData(); Matrix X = data.like(); - for (int j = 0; j < data.columns(); j++) { - double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.rows()); - double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.rows()); + for (int j = 0; j < data.getNumColumns(); j++) { + double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); + double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); if (dataSet.getVariable(j) instanceof DiscreteVariable) { X.assignColumn(j, new Vector(x1)); @@ -308,29 +308,29 @@ public static DataSet logData(DataSet dataSet, double a, boolean isUnlog, int ba public static Matrix standardizeData(Matrix data) { Matrix data2 = data.copy(); - for (int j = 0; j < data2.columns(); j++) { + for (int j = 0; j < data2.getNumColumns(); j++) { double sum = 0.0; - for (int i = 0; i < data2.rows(); i++) { + for (int i = 0; i < data2.getNumRows(); i++) { sum += data2.get(i, j); } - double mean = sum / data.rows(); + double mean = sum / data.getNumRows(); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { data2.set(i, j, data.get(i, j) - mean); } double norm = 0.0; - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { double v = data2.get(i, j); norm += v * v; } - norm = FastMath.sqrt(norm / (data.rows() - 1)); + norm = FastMath.sqrt(norm / (data.getNumRows() - 1)); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { data2.set(i, j, data2.get(i, j) / norm); } } @@ -442,16 +442,16 @@ public static double[] center(double[] d) { public static Matrix centerData(Matrix data) { Matrix data2 = data.copy(); - for (int j = 0; j < data2.columns(); j++) { + for (int j = 0; j < data2.getNumColumns(); j++) { double sum = 0.0; - for (int i = 0; i < data2.rows(); i++) { + for (int i = 0; i < data2.getNumRows(); i++) { sum += data2.get(i, j); } - double mean = sum / data.rows(); + double mean = sum / data.getNumRows(); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { data2.set(i, j, data.get(i, j) - mean); } } @@ -742,16 +742,16 @@ public static Matrix concatenate(Matrix... dataSets) { int totalSampleSize = 0; for (Matrix dataSet : dataSets) { - totalSampleSize += dataSet.rows(); + totalSampleSize += dataSet.getNumRows(); } - int numColumns = dataSets[0].columns(); + int numColumns = dataSets[0].getNumColumns(); Matrix allData = new Matrix(totalSampleSize, numColumns); int q = 0; int r; for (Matrix dataSet : dataSets) { - r = dataSet.rows(); + r = dataSet.getNumRows(); for (int i = 0; i < r; i++) { for (int j = 0; j < numColumns; j++) { @@ -780,7 +780,7 @@ public static DataSet concatenate(List dataSets) { for (DataSet dataSet : dataSets) { Matrix _data = dataSet.getDoubleData(); - r = _data.rows(); + r = _data.getNumRows(); for (int i = 0; i < r; i++) { for (int j = 0; j < numColumns; j++) { @@ -810,13 +810,13 @@ public static DataSet restrictToMeasured(DataSet fullDataSet) { } public static Vector means(Matrix data) { - Vector means = new Vector(data.columns()); + Vector means = new Vector(data.getNumColumns()); for (int j = 0; j < means.size(); j++) { double sum = 0.0; int count = 0; - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { if (Double.isNaN(data.get(i, j))) { continue; } @@ -862,16 +862,16 @@ public static Vector means(double[][] data) { } public static Matrix cov(Matrix data) { - for (int j = 0; j < data.columns(); j++) { + for (int j = 0; j < data.getNumColumns(); j++) { double sum = 0.0; - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { sum += data.get(i, j); } - double mean = sum / data.rows(); + double mean = sum / data.getNumRows(); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { data.set(i, j, data.get(i, j) - mean); } } @@ -882,10 +882,10 @@ public static Matrix cov(Matrix data) { RealMatrix q2 = DataUtils.times(q1, q); Matrix prod = new Matrix(q2.getData()); - double factor = 1.0 / (data.rows() - 1); + double factor = 1.0 / (data.getNumRows() - 1); - for (int i = 0; i < prod.rows(); i++) { - for (int j = 0; j < prod.columns(); j++) { + for (int i = 0; i < prod.getNumRows(); i++) { + for (int j = 0; j < prod.getNumColumns(); j++) { prod.set(i, j, prod.get(i, j) * factor); } } @@ -939,9 +939,9 @@ private static RealMatrix times(RealMatrix m, RealMatrix n) { } public static Vector mean(Matrix data) { - Vector mean = new Vector(data.columns()); + Vector mean = new Vector(data.getNumColumns()); - for (int i = 0; i < data.columns(); i++) { + for (int i = 0; i < data.getNumColumns(); i++) { mean.set(i, StatUtils.mean(data.getColumn(i).toArray())); } @@ -970,7 +970,7 @@ public static DataSet choleskySimulation(CovarianceMatrix cov) { for (int row = 0; row < sampleSize; row++) { // Step 1. Generate normal samples. - double[] exoData = new double[cholesky.rows()]; + double[] exoData = new double[cholesky.getNumRows()]; for (int i = 0; i < exoData.length; i++) { exoData[i] = RandomUtil.getInstance().nextNormal(0, 1); @@ -1009,7 +1009,7 @@ public static DataSet choleskySimulation(CovarianceMatrix cov) { * given dataset. */ public static Matrix getBootstrapSample(Matrix data, int sampleSize) { - int actualSampleSize = data.rows(); + int actualSampleSize = data.getNumRows(); int[] rows = new int[sampleSize]; @@ -1017,7 +1017,7 @@ public static Matrix getBootstrapSample(Matrix data, int sampleSize) { rows[i] = RandomUtil.getInstance().nextInt(actualSampleSize); } - int[] cols = new int[data.columns()]; + int[] cols = new int[data.getNumColumns()]; for (int i = 0; i < cols.length; i++) cols[i] = i; return data.getSelection(rows, cols); @@ -1394,9 +1394,9 @@ public static DataSet getNonparanormalTransformed(DataSet dataSet) { double std = Double.NaN; - for (int j = 0; j < data.columns(); j++) { - double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.rows()); - double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.rows()); + for (int j = 0; j < data.getNumColumns(); j++) { + double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); + double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); double a2Orig = new AndersonDarlingTest(x1).getASquaredStar(); @@ -1467,11 +1467,11 @@ public static DataSet getNonparanormalTransformed(DataSet dataSet) { private static double[] ranks(Matrix data, double[] x) { double[] ranks = new double[x.length]; - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { double d = x[i]; int count = 0; - for (int k = 0; k < data.rows(); k++) { + for (int k = 0; k < data.getNumRows(); k++) { if (x[k] <= d) { count++; } @@ -1533,8 +1533,8 @@ public static double getEss(ICovarianceMatrix covariances) { double sum = 0; - for (int i = 0; i < C.rows(); i++) { - for (int j = 0; j < C.columns(); j++) { + for (int i = 0; i < C.getNumRows(); i++) { + for (int j = 0; j < C.getNumColumns(); j++) { sum += C.get(i, j); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java index c6f60275a6..c2730cfd17 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java @@ -81,7 +81,7 @@ public TimeSeriesData(Matrix matrix, List varNames) { } } this.data2 = matrix; - if (varNames.size() != matrix.columns()) { + if (varNames.size() != matrix.getNumColumns()) { throw new IllegalArgumentException( "Number of columns in the data " + "must match the number of variables."); @@ -176,7 +176,7 @@ public Matrix getData() { } public int getNumTimePoints() { - return getData().rows(); + return getData().getNumRows(); } public int getNumVars() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java index a31578f4b4..fe5b736b01 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionCovariance.java @@ -173,7 +173,7 @@ public RegressionResult regress(Node target, List regressors) { Matrix bStar = rX.inverse().times(rY); - Vector b = new Vector(bStar.rows() + 1); + Vector b = new Vector(bStar.getNumRows() + 1); for (int k = 1; k < b.size(); k++) { double sdY = this.sd.get(yIndex); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java index c57a9172eb..0da0a775ad 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionDataset.java @@ -80,7 +80,7 @@ public RegressionDataset(DataSet data) { public RegressionDataset(Matrix data, List variables) { this.data = data; this.variables = variables; - setRows(new int[data.rows()]); + setRows(new int[data.getNumRows()]); for (int i = 0; i < getRows().length; i++) getRows()[i] = i; } @@ -135,10 +135,10 @@ public RegressionResult regress(Node target, List regressors) { Matrix x; if (regressors.size() > 0) { - x = new Matrix(xSub.rows(), xSub.columns() + 1); + x = new Matrix(xSub.getNumRows(), xSub.getNumColumns() + 1); - for (int i = 0; i < x.rows(); i++) { - for (int j = 0; j < x.columns(); j++) { + for (int i = 0; i < x.getNumRows(); i++) { + for (int j = 0; j < x.getNumColumns(); j++) { if (j == 0) { x.set(i, 0, 1); } else { @@ -147,10 +147,10 @@ public RegressionResult regress(Node target, List regressors) { } } } else { - x = new Matrix(xSub.rows(), xSub.columns()); + x = new Matrix(xSub.getNumRows(), xSub.getNumColumns()); - for (int i = 0; i < x.rows(); i++) { - for (int j = 0; j < x.columns(); j++) { + for (int i = 0; i < x.getNumRows(); i++) { + for (int j = 0; j < x.getNumColumns(); j++) { x.set(i, j, xSub.get(i, j)); } } @@ -163,7 +163,7 @@ public RegressionResult regress(Node target, List regressors) { Matrix b = xTxInv.times(xTy); Matrix yHat = x.times(b); - if (yHat.columns() == 0) yHat = y.like(); + if (yHat.getNumColumns() == 0) yHat = y.like(); Matrix res = y.minus(yHat); // y.copy().assign(yHat, PlusMult.plusMult(-1)); @@ -172,7 +172,7 @@ public RegressionResult regress(Node target, List regressors) { Matrix b2 = b.copy(); Matrix yHat2 = x.times(b2); - if (yHat.columns() == 0) yHat2 = y.like(); + if (yHat.getNumColumns() == 0) yHat2 = y.like(); Matrix res2 = y.minus(yHat2); // y.copy().assign(yHat, PlusMult.plusMult(-1)); this.res2 = res2.getColumn(0); @@ -182,11 +182,11 @@ public RegressionResult regress(Node target, List regressors) { double tss = RegressionDataset.tss(y); double r2 = 1.0 - (rss / tss); - Vector sqErr = new Vector(x.columns()); - Vector t = new Vector(x.columns()); - Vector p = new Vector(x.columns()); + Vector sqErr = new Vector(x.getNumColumns()); + Vector t = new Vector(x.getNumColumns()); + Vector p = new Vector(x.getNumColumns()); - for (int i = 0; i < x.columns(); i++) { + for (int i = 0; i < x.getNumColumns(); i++) { double _s = se * se * xTxInv.get(i, i); double _se = FastMath.sqrt(_s); double _t = b.get(i, 0) / _se; @@ -205,7 +205,7 @@ public RegressionResult regress(Node target, List regressors) { vNames[i] = regressors.get(i).getName(); } - double[] bArray = b.columns() == 0 ? new double[0] : b.getColumn(0).toArray(); + double[] bArray = b.getNumColumns() == 0 ? new double[0] : b.getColumn(0).toArray(); double[] tArray = t.toArray(); double[] pArray = p.toArray(); double[] seArray = sqErr.toArray(); @@ -234,14 +234,14 @@ public static RegressionResult regress(double[] target, double[][] regressors) { Matrix b = xTxInv.times(xTy); Matrix yHat = x.times(b); - if (yHat.columns() == 0) yHat = y.like(); + if (yHat.getNumColumns() == 0) yHat = y.like(); Matrix res = y.minus(yHat); // y.copy().assign(yHat, PlusMult.plusMult(-1)); Vector _yHat = yHat.getColumn(0); Vector _res = res.getColumn(0); - yHat.columns(); + yHat.getNumColumns(); // y.copy().assign(yHat, PlusMult.plusMult(-1)); @@ -250,11 +250,11 @@ public static RegressionResult regress(double[] target, double[][] regressors) { double tss = RegressionDataset.tss(y); double r2 = 1.0 - (rss / tss); - Vector sqErr = new Vector(x.columns()); - Vector t = new Vector(x.columns()); - Vector p = new Vector(x.columns()); + Vector sqErr = new Vector(x.getNumColumns()); + Vector t = new Vector(x.getNumColumns()); + Vector p = new Vector(x.getNumColumns()); - for (int i = 0; i < x.columns(); i++) { + for (int i = 0; i < x.getNumColumns(); i++) { double _s = se * se * xTxInv.get(i, i); double _se = FastMath.sqrt(_s); double _t = b.get(i, 0) / _se; @@ -265,7 +265,7 @@ public static RegressionResult regress(double[] target, double[][] regressors) { p.set(i, _p); } - double[] bArray = b.columns() == 0 ? new double[0] : b.getColumn(0).toArray(); + double[] bArray = b.getNumColumns() == 0 ? new double[0] : b.getColumn(0).toArray(); double[] tArray = t.toArray(); double[] pArray = p.toArray(); double[] seArray = sqErr.toArray(); @@ -290,7 +290,7 @@ private Graph createOutputGraph(String target, Matrix x, Graph graph = new EdgeListGraph(); graph.addNode(targetNode); - for (int i = 0; i < x.columns(); i++) { + for (int i = 0; i < x.getNumColumns(); i++) { String variableName = (i > 0) ? regressors.get(i - 1).getName() : "const"; //Add a node and edge to the output graph for significant predictors: @@ -322,10 +322,10 @@ private Graph createOutputGraph(String target, Matrix x, private static double rss(Matrix x, Matrix y, Matrix b) { double rss = 0.0; - for (int i = 0; i < x.rows(); i++) { + for (int i = 0; i < x.getNumRows(); i++) { double yH = 0.0; - for (int j = 0; j < x.columns(); j++) { + for (int j = 0; j < x.getNumColumns(); j++) { yH += b.get(j, 0) * x.get(i, j); } @@ -341,15 +341,15 @@ private static double tss(Matrix y) { // first calculate the mean double mean = 0.0; - for (int i = 0; i < y.rows(); i++) { + for (int i = 0; i < y.getNumRows(); i++) { mean += y.get(i, 0); } - mean /= y.rows(); + mean /= y.getNumRows(); double ssm = 0.0; - for (int i = 0; i < y.rows(); i++) { + for (int i = 0; i < y.getNumRows(); i++) { double d = mean - y.get(i, 0); ssm += d * d; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java index e3c8051a2b..7771630c0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FactorAnalysis.java @@ -120,9 +120,9 @@ public Matrix successiveResidual() { this.factorLoadingVectors = new LinkedList<>(); Matrix residual = this.covariance.getMatrix().copy(); - Matrix unitVector = new Matrix(residual.rows(), 1); + Matrix unitVector = new Matrix(residual.getNumRows(), 1); - for (int i = 0; i < unitVector.rows(); i++) { + for (int i = 0; i < unitVector.getNumRows(); i++) { unitVector.set(i, 0, 1); } @@ -137,10 +137,10 @@ public Matrix successiveResidual() { this.factorLoadingVectors.removeFirst(); - Matrix result = new Matrix(residual.rows(), this.factorLoadingVectors.size()); + Matrix result = new Matrix(residual.getNumRows(), this.factorLoadingVectors.size()); - for (int i = 0; i < result.rows(); i++) { - for (int j = 0; j < result.columns(); j++) { + for (int i = 0; i < result.getNumRows(); i++) { + for (int j = 0; j < result.getNumColumns(); j++) { result.set(i, j, this.factorLoadingVectors.get(j).get(i, 0)); } } @@ -157,7 +157,7 @@ public Matrix successiveResidual() { * @return The result matrix. */ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { - if (factorLoadingMatrix.columns() == 1) + if (factorLoadingMatrix.getNumColumns() == 1) return factorLoadingMatrix; LinkedList residuals = new LinkedList<>(); @@ -166,9 +166,9 @@ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { Matrix normalizedFactorLoadings = FactorAnalysis.normalizeRows(factorLoadingMatrix); residuals.add(normalizedFactorLoadings); - Matrix unitColumn = new Matrix(factorLoadingMatrix.rows(), 1); + Matrix unitColumn = new Matrix(factorLoadingMatrix.getNumRows(), 1); - for (int i = 0; i < factorLoadingMatrix.rows(); i++) { + for (int i = 0; i < factorLoadingMatrix.getNumRows(); i++) { unitColumn.set(i, 0, 1); } @@ -178,13 +178,13 @@ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { Matrix wVector = sumCols.scalarMult(1.0 / FastMath.sqrt(unitColumn.transpose().times(r).times(sumCols).get(0, 0))); Matrix vVector = r.times(wVector); - for (int k = 0; k < normalizedFactorLoadings.columns(); k++) { + for (int k = 0; k < normalizedFactorLoadings.getNumColumns(); k++) { //time to find the minimum value in the v vector int lIndex = 0; double minValue = Double.POSITIVE_INFINITY; - for (int i = 0; i < vVector.rows(); i++) { + for (int i = 0; i < vVector.getNumRows(); i++) { if (vVector.get(i, 0) < minValue) { minValue = vVector.get(i, 0); lIndex = i; @@ -197,17 +197,17 @@ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { r = residuals.getLast(); - hVectors.add(new Matrix(r.columns(), 1)); + hVectors.add(new Matrix(r.getNumColumns(), 1)); Vector rowFromFactorLoading = r.getRow(lIndex); - for (int j = 0; j < hVectors.getLast().rows(); j++) { + for (int j = 0; j < hVectors.getLast().getNumRows(); j++) { hVectors.getLast().set(j, 0, rowFromFactorLoading.get(j)); } for (int i = 0; i < 200; i++) { Matrix bVector = r.times(hVectors.get(i)); double averageSumSquaresBVector = unitColumn.transpose().times(FactorAnalysis.matrixExp(bVector, 2)) - .scalarMult(1.0 / (double) bVector.rows()).get(0, 0); + .scalarMult(1.0 / (double) bVector.getNumRows()).get(0, 0); Matrix betaVector = FactorAnalysis.matrixExp(bVector, 3).minus(bVector.scalarMult(averageSumSquaresBVector)); Matrix uVector = r.transpose().times(betaVector); @@ -235,7 +235,7 @@ public Matrix successiveFactorVarimax(Matrix factorLoadingMatrix) { Matrix result = factorLoadingMatrix.like(); if (!rotatedFactorVectors.isEmpty()) { - for (int i = 0; i < rotatedFactorVectors.get(0).rows(); i++) { + for (int i = 0; i < rotatedFactorVectors.get(0).getNumRows(); i++) { for (int j = 0; j < rotatedFactorVectors.size(); j++) { result.set(i, j, rotatedFactorVectors.get(j).get(i, 0)); } @@ -341,19 +341,19 @@ private boolean successiveResidualHelper(Matrix residual, Matrix approximationVe //as usual, vectors are treated as matrices to simplify operations elsewhere private static Matrix normalizeRows(Matrix matrix) { LinkedList normalizedRows = new LinkedList<>(); - for (int i = 0; i < matrix.rows(); i++) { + for (int i = 0; i < matrix.getNumRows(); i++) { Vector vector = matrix.getRow(i); - Matrix colVector = new Matrix(matrix.columns(), 1); - for (int j = 0; j < matrix.columns(); j++) + Matrix colVector = new Matrix(matrix.getNumColumns(), 1); + for (int j = 0; j < matrix.getNumColumns(); j++) colVector.set(j, 0, vector.get(j)); normalizedRows.add(FactorAnalysis.normalizeVector(colVector)); } - Matrix result = new Matrix(matrix.rows(), matrix.columns()); - for (int i = 0; i < matrix.rows(); i++) { + Matrix result = new Matrix(matrix.getNumRows(), matrix.getNumColumns()); + for (int i = 0; i < matrix.getNumRows(); i++) { Matrix normalizedRow = normalizedRows.get(i); - for (int j = 0; j < matrix.columns(); j++) { + for (int j = 0; j < matrix.getNumColumns(); j++) { result.set(i, j, normalizedRow.get(j, 0)); } } @@ -367,9 +367,9 @@ private static Matrix normalizeVector(Matrix vector) { } private static Matrix matrixExp(Matrix matrix, double exponent) { - Matrix result = new Matrix(matrix.rows(), matrix.columns()); - for (int i = 0; i < matrix.rows(); i++) { - for (int j = 0; j < matrix.columns(); j++) { + Matrix result = new Matrix(matrix.getNumRows(), matrix.getNumColumns()); + for (int i = 0; i < matrix.getNumRows(); i++) { + for (int j = 0; j < matrix.getNumColumns(); j++) { result.set(i, j, FastMath.pow(matrix.get(i, j), exponent)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index b01073c027..c755df6511 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -348,8 +348,8 @@ public void setWInit(Matrix wInit) { * @return this list, as an FastIca.IcaResult object. */ public IcaResult findComponents() { - int n = this.X.columns(); - int p = this.X.rows(); + int n = this.X.getNumColumns(); + int p = this.X.getNumRows(); if (this.numComponents > min(n, p)) { TetradLogger.getInstance().log("info", "Requested number of components is too large."); @@ -359,12 +359,12 @@ public IcaResult findComponents() { if (this.wInit == null) { this.wInit = new Matrix(this.numComponents, this.numComponents); - for (int i = 0; i < this.wInit.rows(); i++) { - for (int j = 0; j < this.wInit.columns(); j++) { + for (int i = 0; i < this.wInit.getNumRows(); i++) { + for (int j = 0; j < this.wInit.getNumColumns(); j++) { this.wInit.set(i, j, RandomUtil.getInstance().nextNormal(0, 1)); } } - } else if (this.wInit.rows() != this.wInit.columns()) { + } else if (this.wInit.getNumRows() != this.wInit.getNumColumns()) { throw new IllegalArgumentException("wInit is the wrong size."); } @@ -389,7 +389,7 @@ public IcaResult findComponents() { Matrix D = new Matrix(s.getS().getData()); Matrix U = new Matrix(s.getU().getData()); - for (int i = 0; i < D.rows(); i++) { + for (int i = 0; i < D.getNumRows(); i++) { D.set(i, i, 1.0 / FastMath.sqrt(D.get(i, i))); } @@ -430,9 +430,9 @@ private Matrix icaDeflation(Matrix X, TetradLogger.getInstance().log("info", "Deflation FastIca using exponential approx. to neg-entropy function"); } - Matrix W = new Matrix(X.rows(), X.rows()); + Matrix W = new Matrix(X.getNumRows(), X.getNumRows()); - for (int i = 0; i < X.rows(); i++) { + for (int i = 0; i < X.getNumRows(); i++) { if (verbose) { TetradLogger.getInstance().log("fastIcaDetails", "Component " + (i + 1)); } @@ -454,36 +454,36 @@ private Matrix icaDeflation(Matrix X, while (_tolerance > tolerance && ++it <= maxIterations) { Vector wx = X.transpose().times(w); - Vector gwx0 = new Vector(X.columns()); + Vector gwx0 = new Vector(X.getNumColumns()); - for (int j = 0; j < X.columns(); j++) { + for (int j = 0; j < X.getNumColumns(); j++) { gwx0.set(j, g(alpha, wx.get(j))); } - Matrix gwx = new Matrix(X.rows(), X.columns()); + Matrix gwx = new Matrix(X.getNumRows(), X.getNumColumns()); - for (int _i = 0; _i < X.rows(); _i++) { + for (int _i = 0; _i < X.getNumRows(); _i++) { gwx.assignRow(i, gwx0); } // A weighting of X by gwx0. - Matrix xgwx = new Matrix(X.rows(), X.columns()); + Matrix xgwx = new Matrix(X.getNumRows(), X.getNumColumns()); - for (int _i = 0; _i < X.rows(); _i++) { - for (int j = 0; j < X.columns(); j++) { + for (int _i = 0; _i < X.getNumRows(); _i++) { + for (int j = 0; j < X.getNumColumns(); j++) { xgwx.set(_i, j, X.get(_i, j) * gwx0.get(j)); } } - Vector v1 = new Vector(X.rows()); + Vector v1 = new Vector(X.getNumRows()); - for (int k = 0; k < X.rows(); k++) { + for (int k = 0; k < X.getNumRows(); k++) { v1.set(k, mean(xgwx.getRow(k))); } - Vector g_wx = new Vector(X.columns()); + Vector g_wx = new Vector(X.getNumColumns()); - for (int k = 0; k < X.columns(); k++) { + for (int k = 0; k < X.getNumColumns(); k++) { double t = g(alpha, wx.get(k)); g_wx.set(k, (1.0 - t * t)); } @@ -500,16 +500,16 @@ private Matrix icaDeflation(Matrix X, for (int u = 0; u < i; u++) { double k = 0.0; - for (int j = 0; j < X.rows(); j++) { + for (int j = 0; j < X.getNumRows(); j++) { k += w1.get(j) * W.get(u, j); } - for (int j = 0; j < X.rows(); j++) { + for (int j = 0; j < X.getNumRows(); j++) { t.set(j, t.get(j) + k * W.get(u, j)); } } - for (int j = 0; j < X.rows(); j++) { + for (int j = 0; j < X.getNumRows(); j++) { w1.set(j, w1.get(j) - t.get(j)); } } @@ -518,7 +518,7 @@ private Matrix icaDeflation(Matrix X, _tolerance = 0.0; - for (int k = 0; k < X.rows(); k++) { + for (int k = 0; k < X.getNumRows(); k++) { _tolerance += w1.get(k) * w.get(k); } @@ -575,12 +575,12 @@ private double rms(Vector w) { private Matrix icaParallel(Matrix X, int numComponents, double tolerance, double alpha, int maxIterations, boolean verbose, Matrix wInit) { - int p = X.columns(); + int p = X.getNumColumns(); Matrix W = wInit; SingularValueDecomposition sW = new SingularValueDecomposition(W.getApacheData()); Matrix D = new Matrix(sW.getS().getData()); - for (int i = 0; i < D.rows(); i++) D.set(i, i, 1.0 / D.get(i, i)); + for (int i = 0; i < D.getNumRows(); i++) D.set(i, i, 1.0 / D.get(i, i)); Matrix WTemp = new Matrix(sW.getU()).times(D); WTemp = WTemp.times(new Matrix(sW.getU()).transpose()); @@ -608,8 +608,8 @@ private Matrix icaParallel(Matrix X, int numComponents, Matrix v1 = gwx.times(X.transpose().scalarMult(1.0 / p)); Matrix g_wx = gwx.like(); - for (int i = 0; i < g_wx.rows(); i++) { - for (int j = 0; j < g_wx.columns(); j++) { + for (int i = 0; i < g_wx.getNumRows(); i++) { + for (int j = 0; j < g_wx.getNumColumns(); j++) { double v = g_wx.get(i, j); double w = alpha * (1.0 - v * v); g_wx.set(i, j, w); @@ -629,7 +629,7 @@ private Matrix icaParallel(Matrix X, int numComponents, SingularValueDecomposition sW1 = new SingularValueDecomposition(W1.getApacheData()); Matrix U = new Matrix(sW1.getU()); Matrix sD = new Matrix(sW1.getS()); - for (int i = 0; i < sD.rows(); i++) + for (int i = 0; i < sD.getNumRows(); i++) sD.set(i, i, 1.0 / sD.get(i, i)); Matrix W1Temp = U.times(sD); @@ -659,18 +659,18 @@ private Matrix icaParallel(Matrix X, int numComponents, } private void scale(Matrix x) { - for (int i = 0; i < x.rows(); i++) { + for (int i = 0; i < x.getNumRows(); i++) { Vector u = x.getRow(i).scalarMult(1.0 / rms(x.getRow(i))); x.assignRow(i, u); } } private void center(Matrix x) { - for (int i = 0; i < x.rows(); i++) { + for (int i = 0; i < x.getNumRows(); i++) { Vector u = x.getRow(i); double mean = mean(u); - for (int j = 0; j < x.columns(); j++) { + for (int j = 0; j < x.getNumColumns(); j++) { x.set(i, j, x.get(i, j) - mean); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java index 6595e84367..70b4b0f2a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fofc.java @@ -223,9 +223,9 @@ private int findFrequentestIndex(Integer[] outliers) { // renjiey private ArrayList removeVariables(Matrix correlationMatrix, double lowerBound, double upperBound, double percentBound) { - Integer[] outlier = new Integer[correlationMatrix.rows() * (correlationMatrix.rows() - 1)]; + Integer[] outlier = new Integer[correlationMatrix.getNumRows() * (correlationMatrix.getNumRows() - 1)]; int count = 0; - for (int i = 2; i < (correlationMatrix.rows() + 1); i++) { + for (int i = 2; i < (correlationMatrix.getNumRows() + 1); i++) { for (int j = 1; j < i; j++) { if ((abs(correlationMatrix.get(i - 1, j - 1)) < lowerBound) @@ -245,7 +245,7 @@ private ArrayList removeVariables(Matrix correlationMatrix, double lowe ArrayList removedVariables = new ArrayList<>(); // Added the percent bound jdramsey - while (outlier.length > 1 && removedVariables.size() < percentBound * correlationMatrix.rows()) { + while (outlier.length > 1 && removedVariables.size() < percentBound * correlationMatrix.getNumRows()) { //find out the variable that occurs most frequently in outlier int worstVariable = findFrequentestIndex(outlier); if (worstVariable > 0) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 7de721c7ec..a7985dd16f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -78,6 +78,11 @@ public class LingD { public LingD() { } + public static boolean isAcyclic(Matrix scaledBHat, List variables) { + Graph g = makeGraph(scaledBHat, variables); + return !g.paths().existsDirectedCycle(); + } + /** * Fits a LiNG-D model to the given dataset using a default method for estimating * W. @@ -166,7 +171,7 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT Matrix X = data.getDoubleData(); X = DataUtils.centerData(X).transpose(); - FastIca fastIca = new FastIca(X, X.rows()); + FastIca fastIca = new FastIca(X, X.getNumRows()); fastIca.setVerbose(false); fastIca.setMaxIterations(fastIcaMaxIter); fastIca.setAlgorithmType(FastIca.PARALLEL); @@ -191,8 +196,8 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT public static Graph makeGraph(Matrix B, List variables) { Graph g = new EdgeListGraph(variables); - for (int j = 0; j < B.columns(); j++) { - for (int i = 0; i < B.rows(); i++) { + for (int j = 0; j < B.getNumColumns(); j++) { + for (int i = 0; i < B.getNumRows(); i++) { if (B.get(i, j) != 0) { g.addDirectedEdge(variables.get(j), variables.get(i)); } @@ -250,8 +255,8 @@ public static boolean isStable(Matrix bHat) { public static Matrix scale(Matrix M) { Matrix _M = M.like(); - for (int i = 0; i < _M.rows(); i++) { - for (int j = 0; j < _M.columns(); j++) { + for (int i = 0; i < _M.getNumRows(); i++) { + for (int j = 0; j < _M.getNumColumns(); j++) { _M.set(i, j, M.get(i, j) / M.get(j, j)); } } @@ -272,8 +277,8 @@ public static Matrix threshold(Matrix M, double threshold) { Matrix _M = M.copy(); - for (int i = 0; i < M.rows(); i++) { - for (int j = 0; j < M.columns(); j++) { + for (int i = 0; i < M.getNumRows(); i++) { + for (int j = 0; j < M.getNumColumns(); j++) { if (abs(M.get(i, j)) < threshold) _M.set(i, j, 0.0); } } @@ -295,7 +300,7 @@ public static Matrix threshold(Matrix M, double threshold) { public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold) { Matrix WTilde = pair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); - Matrix BHat = Matrix.identity(WTilde.columns()).minus(WTilde); + Matrix BHat = Matrix.identity(WTilde.getNumColumns()).minus(WTilde); BHat = threshold(BHat, bThreshold); int[] perm = pair.getRowPerm(); int[] inverse = LingD.inversePermutation(perm); @@ -305,10 +310,10 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold @NotNull private static PermutationMatrixPair hungarian(Matrix W) { - double[][] costMatrix = new double[W.rows()][W.columns()]; + double[][] costMatrix = new double[W.getNumRows()][W.getNumColumns()]; - for (int i = 0; i < W.rows(); i++) { - for (int j = 0; j < W.columns(); j++) { + for (int i = 0; i < W.getNumRows(); i++) { + for (int j = 0; j < W.getNumColumns(); j++) { if (W.get(i, j) != 0) { costMatrix[i][j] = 1.0 / abs(W.get(i, j)); } else { @@ -328,10 +333,10 @@ private static PermutationMatrixPair hungarian(Matrix W) { @NotNull private static List pairsNRook(Matrix W, double spineThreshold) { - boolean[][] allowablePositions = new boolean[W.rows()][W.columns()]; + boolean[][] allowablePositions = new boolean[W.getNumRows()][W.getNumColumns()]; - for (int i = 0; i < W.rows(); i++) { - for (int j = 0; j < W.columns(); j++) { + for (int i = 0; i < W.getNumRows(); i++) { + for (int j = 0; j < W.getNumColumns(); j++) { allowablePositions[i][j] = abs(W.get(i, j)) > spineThreshold; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index a7675f9cef..c19ebd4f68 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -22,9 +22,15 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.graph.GraphNode; +import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** *

      Implements an interpretation of the LiNGAM algorithm. The reference is here:

      * @@ -54,6 +60,7 @@ */ public class Lingam { private double bThreshold = 0.1; + private boolean acyclicityGuaranteed = true; /** * Constructor.. @@ -80,7 +87,46 @@ public Matrix fit(DataSet D) { */ public Matrix fitW(Matrix W) { PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); - return LingD.getScaledBHat(bestPair, bThreshold); + Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); + + List coefs = new ArrayList<>(); + + for (int i = 0; i < scaledBHat.getNumRows(); i++) { + for (int j = 0; j < scaledBHat.getNumColumns(); j++) { + if (i != j && scaledBHat.get(i, j) != 0) { + coefs.add(Math.abs(scaledBHat.get(i, j))); + } + } + } + + Collections.sort(coefs); + + if (!acyclicityGuaranteed) { + return scaledBHat; + } + + List dummyVars = new ArrayList<>(); + + for (int i = 0; i < scaledBHat.getNumRows(); i++) { + dummyVars.add(new GraphNode("dummy" + i)); + } + + do { + + F: + for (double coef : coefs) { + for (int i = 0; i < scaledBHat.getNumRows(); i++) { + for (int j = 0; j < scaledBHat.getNumColumns(); j++) { + if (coef == scaledBHat.get(i, j)) { + scaledBHat.set(i, j, 0.0); + break F; + } + } + } + } + } while (!LingD.isAcyclic(scaledBHat, dummyVars)); + + return scaledBHat; } /** @@ -93,5 +139,16 @@ public void setBThreshold(double bThreshold) { if (bThreshold < 0) throw new IllegalArgumentException("Expecting a non-negative number: " + bThreshold); this.bThreshold = bThreshold; } + + /** + * Whether or not the LiNGAM algorithm is guaranteed to produce an acyclic graph. This is + * is implemnted by setting small coefficients in B hat to zero until an acyclic model is + * found. + * + * @param acyclicityGuaranteed True if so. + */ + public void setAcyclicityGuaranteed(boolean acyclicityGuaranteed) { + this.acyclicityGuaranteed = acyclicityGuaranteed; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index d230e37402..142ec78f78 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -772,12 +772,12 @@ private void resolveOneEdgeMaxR3(Graph graph, Node x, Node y) { // rowIndex is for the W matrix, not for the data. public double scoreRow(int rowIndex, Matrix data, List> rows, List> parameters) { if (this.col == null) { - this.col = new double[data.rows()]; + this.col = new double[data.getNumRows()]; } List cols = rows.get(rowIndex); - for (int i = 0; i < data.rows(); i++) { + for (int i = 0; i < data.getNumRows(); i++) { if (Thread.currentThread().isInterrupted()) { break; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index 49959a6055..b92bfeda8e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -280,8 +280,8 @@ private Matrix getCov(ICovarianceMatrix _measurescov, List latents, Node[] Matrix measurescov = _measurescov.getMatrix(); Matrix latentscov = new Matrix(latents.size(), latents.size()); - for (int i = 0; i < latentscov.rows(); i++) { - for (int j = i; j < latentscov.columns(); j++) { + for (int i = 0; i < latentscov.getNumRows(); i++) { + for (int j = i; j < latentscov.getNumColumns(); j++) { if (i == j) latentscov.set(i, j, 1.0); else { final double v = .5; @@ -317,7 +317,7 @@ private Matrix getCov(ICovarianceMatrix _measurescov, List latents, Node[] } // Variances of the measures. - double[] delta = new double[measurescov.rows()]; + double[] delta = new double[measurescov.getNumRows()]; Arrays.fill(delta, 1); @@ -411,13 +411,13 @@ private double[] getAllParams(Node[][] indicators, Matrix latentscov, double[][] int count = 0; // Non-redundant elements of cov(latents) - for (int i = 0; i < latentscov.rows(); i++) { - for (int j = i; j < latentscov.columns(); j++) { + for (int i = 0; i < latentscov.getNumRows(); i++) { + for (int j = i; j < latentscov.getNumColumns(); j++) { count++; } } - System.out.println("# nnonredundant elemnts of cov(error) = " + latentscov.rows() * (latentscov.rows() + 1) / 2); + System.out.println("# nnonredundant elemnts of cov(error) = " + latentscov.getNumRows() * (latentscov.getNumRows() + 1) / 2); int _loadings = 0; @@ -441,8 +441,8 @@ private double[] getAllParams(Node[][] indicators, Matrix latentscov, double[][] double[] values = new double[count]; count = 0; - for (int i = 0; i < latentscov.rows(); i++) { - for (int j = i; j < latentscov.rows(); j++) { + for (int i = 0; i < latentscov.getNumRows(); i++) { + for (int j = i; j < latentscov.getNumRows(); j++) { values[count++] = latentscov.get(i, j); } } @@ -555,7 +555,7 @@ public double value(double[] values) { Matrix implied = impliedCovariance(this.indicatorIndices, this.loadings, this.measurescov, this.latentscov, this.delta); - Matrix I = Matrix.identity(implied.rows()); + Matrix I = Matrix.identity(implied.getNumRows()); Matrix diff = I.minus((implied.times(this.measuresCovInverse))); // time hog. times(). return 0.5 * (diff.times(diff)).trace(); @@ -565,7 +565,7 @@ public double value(double[] values) { private Matrix impliedCovariance(int[][] indicatorIndices, double[][] loadings, Matrix cov, Matrix loadingscov, double[] delta) { - Matrix implied = new Matrix(cov.rows(), cov.columns()); + Matrix implied = new Matrix(cov.getNumRows(), cov.getNumColumns()); for (int i = 0; i < loadings.length; i++) { for (int j = 0; j < loadings.length; j++) { @@ -578,7 +578,7 @@ private Matrix impliedCovariance(int[][] indicatorIndices, double[][] loadings, } } - for (int i = 0; i < implied.rows(); i++) { + for (int i = 0; i < implied.getNumRows(); i++) { implied.set(i, i, implied.get(i, i) + delta[i]); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index 6d2816f37f..1172ab6349 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -266,8 +266,8 @@ private Matrix getCov(ICovarianceMatrix _measurescov, List latents, Node[] Matrix measurescov = _measurescov.getMatrix(); Matrix latentscov = new Matrix(latents.size(), latents.size()); - for (int i = 0; i < latentscov.rows(); i++) { - for (int j = i; j < latentscov.columns(); j++) { + for (int i = 0; i < latentscov.getNumRows(); i++) { + for (int j = i; j < latentscov.getNumColumns(); j++) { if (i == j) latentscov.set(i, j, 1.0); else { final double v = .5; @@ -303,7 +303,7 @@ private Matrix getCov(ICovarianceMatrix _measurescov, List latents, Node[] } // Variances of the measures. - double[] delta = new double[measurescov.rows()]; + double[] delta = new double[measurescov.getNumRows()]; Arrays.fill(delta, 1); @@ -524,7 +524,7 @@ public double value(double[] values) { Matrix implied = impliedCovariance(this.indicatorIndices, this.loadings, this.measurescov, this.latentscov, this.delta); - Matrix I = Matrix.identity(implied.rows()); + Matrix I = Matrix.identity(implied.getNumRows()); Matrix diff = I.minus((implied.times(this.measuresCovInverse))); // time hog. times(). return 0.5 * (diff.times(diff)).trace(); @@ -534,7 +534,7 @@ public double value(double[] values) { private Matrix impliedCovariance(int[][] indicatorIndices, double[][] loadings, Matrix cov, Matrix loadingscov, double[] delta) { - Matrix implied = new Matrix(cov.rows(), cov.columns()); + Matrix implied = new Matrix(cov.getNumRows(), cov.getNumColumns()); for (int i = 0; i < loadings.length; i++) { for (int j = 0; j < loadings.length; j++) { @@ -547,7 +547,7 @@ private Matrix impliedCovariance(int[][] indicatorIndices, double[][] loadings, } } - for (int i = 0; i < implied.rows(); i++) { + for (int i = 0; i < implied.getNumRows(); i++) { implied.set(i, i, implied.get(i, i) + delta[i]); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java index 125b28be5a..bdf9eed0a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java @@ -225,7 +225,7 @@ private Score getScore(Graph dag, Matrix data, List variables) { List nodes = dag.getNodes(); double score = 0.0; double[] pValues = new double[nodes.size()]; - Matrix residuals = new Matrix(data.rows(), data.columns()); + Matrix residuals = new Matrix(data.getNumRows(), data.getNumColumns()); for (int i = 0; i < nodes.size(); i++) { Node _target = nodes.get(i); @@ -258,7 +258,7 @@ private Score getScore(Graph dag, Matrix data, List variables) { score += diff * diff; } - for (int j = 0; j < residuals.columns(); j++) { + for (int j = 0; j < residuals.getNumColumns(); j++) { double[] x = residuals.getColumn(j).toArray(); double p = new AndersonDarlingTest(x).getP(); pValues[j] = p; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java index d53aae8827..022ca07b98 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java @@ -222,9 +222,9 @@ public double getLik(int child_index, int[] parents) { private double multipleRegression(Vector Y, Matrix X) { - int n = X.rows(); + int n = X.getNumRows(); Vector r; - if (X.columns() >= n) { + if (X.getNumColumns() >= n) { Vector ones = new Vector(n); for (int i = 0; i < n; i++) ones.set(i, 1); r = ones.scalarMult(ones.dotProduct(Y) / (double) n).minus(Y); @@ -265,13 +265,13 @@ private double multipleRegression(Vector Y, Matrix X) { private double approxMultinomialRegression(Matrix Y, Matrix X) { - int n = X.rows(); - int d = Y.columns(); + int n = X.getNumRows(); + int d = Y.getNumColumns(); double lik = 0.0; Matrix P; - if (d >= n || X.columns() >= n) { + if (d >= n || X.getNumColumns() >= n) { Matrix ones = new Matrix(n, 1); for (int i = 0; i < n; i++) ones.set(i, 0, 1); P = ones.times(ones.transpose().times(Y).scalarMult(1 / (double) n)); @@ -293,7 +293,7 @@ private double approxMultinomialRegression(Matrix Y, Matrix X) { for (int j = 0; j < d; j++) { min = FastMath.min(min, P.get(i, j)); } - if (X.columns() > 1 && min < bound) { + if (X.getNumColumns() > 1 && min < bound) { min = (bound - center) / (min - center); for (int j = 0; j < d; j++) { P.set(i, j, min * P.get(i, j) + center * (1 - min)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index 595a3a6752..521b196740 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -173,9 +173,9 @@ public static double getVarRy(int i, int[] parents, Matrix data, ICovarianceMatr @NotNull public static Matrix bStar(Matrix b) { - Matrix byx = new Matrix(b.rows() + 1, 1); + Matrix byx = new Matrix(b.getNumRows() + 1, 1); byx.set(0, 0, 1); - for (int j = 0; j < b.rows(); j++) byx.set(j + 1, 0, -b.get(j, 0)); + for (int j = 0; j < b.getNumRows(); j++) byx.set(j + 1, 0, -b.get(j, 0)); return byx; } @@ -234,7 +234,7 @@ private static List getRows(int i, int[] parents, Matrix data, boolean List rows = new ArrayList<>(); K: - for (int k = 0; k < data.rows(); k++) { + for (int k = 0; k < data.getNumRows(); k++) { if (Double.isNaN(data.get(k, i))) continue; for (int p : parents) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java index f702c168a8..46e363ac63 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java @@ -442,7 +442,7 @@ private double empiricalHSIC(Matrix Ky, Matrix Kx, Matrix Kz, int m) { */ public double empiricalHSICincompleteCholesky(Matrix Gy, Matrix Gx, Matrix Gz, int m) { // centralize Choleksy - int kz = Gz.columns(); + int kz = Gz.getNumColumns(); Matrix H = KernelUtils.constructH(m); Matrix Gcy = H.times(Gy); @@ -648,7 +648,7 @@ private int sampleSize() { private double matrixProductEntry(Matrix X, Matrix Y, int i, int j) { double entry = 0.0; - for (int k = 0; k < X.columns(); k++) { + for (int k = 0; k < X.getNumColumns(); k++) { entry += X.get(i, k) * Y.get(k, j); } return entry; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java index be91839b03..352b3d43fb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java @@ -523,14 +523,14 @@ private IndependenceResult proposition5(Matrix kx, Matrix ky, IndependenceFact f Matrix vdx = vx.times(dx); Matrix vdy = vy.times(dy); - int prod = vx.columns() * vy.columns(); + int prod = vx.getNumColumns() * vy.getNumColumns(); Matrix UU = new Matrix(N, prod); // stack - for (int i = 0; i < vx.columns(); i++) { - for (int j = 0; j < vy.columns(); j++) { + for (int i = 0; i < vx.getNumColumns(); i++) { + for (int j = 0; j < vy.getNumColumns(); j++) { for (int k = 0; k < N; k++) { - UU.set(k, i * dy.columns() + j, vdx.get(k, i) * vdy.get(k, j)); + UU.set(k, i * dy.getNumColumns() + j, vdx.get(k, i) * vdy.get(k, j)); } } } @@ -696,7 +696,7 @@ private class Eigendecomposition { private List topEigenvalues; public Eigendecomposition(Matrix k) { - if (k.rows() == 0 || k.columns() == 0) { + if (k.getNumRows() == 0 || k.getNumColumns() == 0) { throw new IllegalArgumentException("Empty matrix to decompose. Please don't do that to me."); } @@ -762,7 +762,7 @@ public Eigendecomposition invoke() { V = new Matrix(V0.getRowDimension(), topIndices.size()); - for (int i = 0; i < V.columns(); i++) { + for (int i = 0; i < V.getNumColumns(); i++) { double[] t = V0.getColumn(topIndices.get(i)); V.assignColumn(i, new Vector(t)); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java index bbdc40530c..75b902bb1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java @@ -53,13 +53,13 @@ public class PermutationMatrixPair { */ public PermutationMatrixPair(Matrix M, int[] rowPerm, int[] colPerm) { if (rowPerm == null) { - rowPerm = new int[M.rows()]; - for (int i = 0; i < M.rows(); i++) rowPerm[i] = i; + rowPerm = new int[M.getNumRows()]; + for (int i = 0; i < M.getNumRows(); i++) rowPerm[i] = i; } if (colPerm == null) { - colPerm = new int[M.columns()]; - for (int i = 0; i < M.columns(); i++) colPerm[i] = i; + colPerm = new int[M.getNumColumns()]; + for (int i = 0; i < M.getNumColumns(); i++) colPerm[i] = i; } this.rowPerm = Arrays.copyOf(rowPerm, rowPerm.length); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java index da23d0cf9a..31539cb853 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ShiftSearch.java @@ -27,7 +27,6 @@ import edu.cmu.tetrad.search.score.ImagesScore; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.score.SemBicScore; -import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.SublistGenerator; import org.apache.commons.math3.util.FastMath; @@ -204,7 +203,7 @@ private List ensureNumRows(List dataSets, int numRows) { for (DataModel _dataSet : dataSets) { DataSet dataSet = (DataSet) _dataSet; Matrix mat = dataSet.getDoubleData(); - Matrix mat2 = mat.getPart(0, numRows - 1, 0, mat.columns() - 1); + Matrix mat2 = mat.getPart(0, numRows - 1, 0, mat.getNumColumns() - 1); truncatedData.add(new BoxDataSet(new DoubleDataBox(mat2.toArray()), dataSet.getVariables())); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java index b9ff86d1d7..3ddd14e7a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TsUtils.java @@ -111,7 +111,7 @@ public static DataSet ar2(DataSet timeSeries, int numLags) { int index = timeSeries.getVariables().indexOf(target); if (missingVariables.contains(target)) { - for (int i2 = 0; i2 < residuals.rows(); i2++) { + for (int i2 = 0; i2 < residuals.getNumRows(); i2++) { residuals.set(i2, index, Double.NaN); } @@ -249,14 +249,14 @@ public static DataSet createShiftedData(DataSet data, int[] shifts) { _shifts[i] = shiftRange - (shifts[i] - min); } - if (shiftRange > data2.rows()) { + if (shiftRange > data2.getNumRows()) { throw new IllegalArgumentException("Range of shifts greater than sample size."); } - int shiftedDataLength = data2.rows() - shiftRange; - Matrix shiftedData = new Matrix(shiftedDataLength, data2.columns()); + int shiftedDataLength = data2.getNumRows() - shiftRange; + Matrix shiftedData = new Matrix(shiftedDataLength, data2.getNumColumns()); - for (int j = 0; j < shiftedData.columns(); j++) { + for (int j = 0; j < shiftedData.getNumColumns(); j++) { for (int i = 0; i < shiftedDataLength; i++) { shiftedData.set(i, j, data2.get(i + _shifts[j], j)); } @@ -356,10 +356,10 @@ public static DataSet difference(DataSet data, int d) { Matrix _data = data.getDoubleData(); for (int k = 1; k <= d; k++) { - Matrix _data2 = new Matrix(_data.rows() - 1, _data.columns()); + Matrix _data2 = new Matrix(_data.getNumRows() - 1, _data.getNumColumns()); - for (int i = 1; i < _data.rows(); i++) { - for (int j = 0; j < _data.columns(); j++) { + for (int i = 1; i < _data.getNumRows(); i++) { + for (int j = 0; j < _data.getNumColumns(); j++) { _data2.set(i - 1, j, _data.get(i, j) - _data.get(i - 1, j)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java index 4b887ebbcf..84f0114082 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Glasso.java @@ -106,7 +106,7 @@ public Matrix getWwi() { } public Glasso(Matrix cov) { - this.n = cov.rows(); + this.n = cov.getNumRows(); this.ss = cov; } @@ -294,8 +294,8 @@ public Result search() { private double sum_abs(Matrix m) { double sum = 0.0; - for (int i = 0; i < m.rows(); i++) { - for (int j = 0; j < m.columns(); j++) { + for (int i = 0; i < m.getNumRows(); i++) { + for (int j = 0; j < m.getNumColumns(); j++) { sum += FastMath.abs(m.get(i, j)); } } @@ -473,8 +473,8 @@ private void inv(int n, Matrix ww, Matrix xs, Matrix wwi) { } private void zero(Matrix wwi) { - for (int i = 0; i < wwi.rows(); i++) { - for (int j = 0; j < wwi.columns(); j++) { + for (int i = 0; i < wwi.getNumRows(); i++) { + for (int j = 0; j < wwi.getNumColumns(); j++) { wwi.set(i, j, 0.0); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java index 115d3c9fdd..94677a05b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java @@ -221,7 +221,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { } // Invert submatrix. - if (submatrix.rank() != submatrix.rows()) { + if (submatrix.rank() != submatrix.getNumRows()) { // if (TetradAlgebra.rank(submatrix) != submatrix.rows()) { throw new IllegalArgumentException( "Matrix singularity detected while using correlations " + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java index 11ea240c31..c96aa12993 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java @@ -76,7 +76,7 @@ public IndTestFisherZPercentIndependent(List dataSets, double alpha) { } this.ncov = new ArrayList<>(); - for (Matrix d : this.data) this.ncov.add(d.transpose().times(d).scalarMult(1.0 / d.rows())); + for (Matrix d : this.data) this.ncov.add(d.transpose().times(d).scalarMult(1.0 / d.getNumRows())); setAlpha(alpha); this.rows = new int[dataSets.get(0).getNumRows()]; @@ -102,7 +102,7 @@ public IndependenceResult checkIndependence(Node x, Node y, List z) { all[i + 2] = this.variablesMap.get(z.get(i)); } - int sampleSize = this.data.get(0).rows(); + int sampleSize = this.data.get(0).getNumRows(); List pValues = new ArrayList<>(); for (Matrix matrix : this.ncov) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java index 3aa8a84014..e6d5b8d5a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/InverseCorrelation.java @@ -55,8 +55,8 @@ public Graph search() { Graph graph = new EdgeListGraph(this.data.getVariables()); - for (int i = 0; i < inverse.rows(); i++) { - for (int j = i + 1; j < inverse.columns(); j++) { + for (int i = 0; i < inverse.getNumRows(); i++) { + for (int j = i + 1; j < inverse.getNumColumns(); j++) { double a = inverse.get(i, j); double b = inverse.get(i, i); double c = inverse.get(j, j); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrLikelihood.java index 00b4152448..cf08792413 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/MnlrLikelihood.java @@ -283,7 +283,7 @@ public double getEBICprior() { private double multipleRegression(Vector Y, Matrix X) { - int n = X.rows(); + int n = X.getNumRows(); Vector r; try { @@ -317,8 +317,8 @@ private double multipleRegression(Vector Y, Matrix X) { private double MultinomialLogisticRegression(Matrix targets, Matrix subset) { Problem problem = new Problem(); - problem.l = targets.rows(); // number of training examples - problem.n = subset.columns(); // number of features + problem.l = targets.getNumRows(); // number of training examples + problem.n = subset.getNumColumns(); // number of features problem.x = new FeatureNode[problem.l][problem.n]; // feature nodes problem.bias = 0; for (int i = 0; i < problem.l; i++) { @@ -335,7 +335,7 @@ private double MultinomialLogisticRegression(Matrix targets, Matrix subset) { double num; double den; - for (int i = 0; i < targets.columns(); i++) { + for (int i = 0; i < targets.getNumColumns(); i++) { System.setOut(this.nullout); problem.y = targets.getColumn(i).toArray(); // target values models.add(i, Linear.train(problem, parameter)); @@ -345,7 +345,7 @@ private double MultinomialLogisticRegression(Matrix targets, Matrix subset) { for (int j = 0; j < problem.l; j++) { num = 0; den = 0; - for (int i = 0; i < targets.columns(); i++) { + for (int i = 0; i < targets.getNumColumns(); i++) { double[] p = new double[models.get(i).getNrClass()]; Linear.predictProbability(models.get(i), problem.x[j], p); if (targets.get(j, i) == 1) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java index ba3c2a51ba..b7f6094624 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java @@ -219,12 +219,12 @@ public DataSet simulateDataReducedForm(int sampleSize) { NormalDistribution normal = new NormalDistribution(new Well1024a(++this.seed), 0, 1); Matrix B = new Matrix(getCoefficientMatrix()); - Matrix iMinusBInv = Matrix.identity(B.rows()).minus(B).inverse(); + Matrix iMinusBInv = Matrix.identity(B.getNumRows()).minus(B).inverse(); double[][] all = new double[this.variableNodes.size()][sampleSize]; for (int row = 0; row < sampleSize; row++) { - Vector e = new Vector(B.rows()); + Vector e = new Vector(B.getNumRows()); for (int j = 0; j < e.size(); j++) { e.set(j, normal.sample() * sqrt(this.errorVars[j])); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java index a5b1a44bcb..53e3045031 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java @@ -437,7 +437,7 @@ private double negchi2(int param, double x, List parameters) { // this is only called when flatprior is false, which it will never be with the getModel code double answer = 0.0; - int n = this.dataSet.columns(); + int n = this.dataSet.getNumColumns(); int numParameters = parameters.size(); double[] xvec = new double[numParameters]; double[] temp = new double[numParameters]; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java index 5e37f6c1d5..a562de792a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java @@ -329,7 +329,7 @@ private SemIm(SemIm semIm, Matrix covariances, Vector means) { this(semIm); - if (covariances.rows() != covariances.columns()) { + if (covariances.getNumRows() != covariances.getNumColumns()) { throw new IllegalArgumentException( "Expecting covariances to be square."); } @@ -344,7 +344,7 @@ private SemIm(SemIm semIm, Matrix covariances, "Number of means does not equal " + "number of variables."); } - if (covariances.rows() != this.semPm.getVariableNodes().size()) { + if (covariances.getNumRows() != this.semPm.getVariableNodes().size()) { throw new IllegalArgumentException( "Dimension of covariance matrix " + "does not equal number of variables."); @@ -1056,7 +1056,7 @@ private double getFgls() { this.sampleCovInv = sampleCovar.inverse(); } - Matrix I = Matrix.identity(implCovarMeas.rows()); + Matrix I = Matrix.identity(implCovarMeas.getNumRows()); Matrix diff = I.minus((implCovarMeas.times(this.sampleCovInv))); return 0.5 * (diff.times(diff)).trace(); @@ -1279,7 +1279,7 @@ public DataSet simulateDataCholesky(int sampleSize, boolean latentDataSaved) { for (int row = 0; row < sampleSize; row++) { // Step 1. Generate normal samples. - double[] exoData = new double[cholesky.rows()]; + double[] exoData = new double[cholesky.getNumRows()]; for (int i = 0; i < exoData.length; i++) { exoData[i] = RandomUtil.getInstance().nextNormal(0, 1); @@ -1386,7 +1386,7 @@ private DataSet simulateDataRecursive(int sampleSize, DataSet initialValues, for (int row = 0; row < sampleSize; row++) { // Step 1. Generate normal samples. - double[] exoData = new double[cholesky.rows()]; + double[] exoData = new double[cholesky.getNumRows()]; for (int i = 0; i < exoData.length; i++) { if (errorType == 1) { @@ -1505,7 +1505,7 @@ public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) // Calculate inv(I - edgeCoefC) Matrix B = edgeCoef().transpose(); - Matrix iMinusBInv = Matrix.identity(B.rows()).minus(B).inverse(); + Matrix iMinusBInv = Matrix.identity(B.getNumRows()).minus(B).inverse(); // Pick error values e, for each calculate inv * e. Matrix sim = new Matrix(sampleSize, numVars); @@ -1514,7 +1514,7 @@ public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) for (int row = 0; row < sampleSize; row++) { // Step 1. Generate normal samples. - Vector e = new Vector(this.edgeCoef.columns()); + Vector e = new Vector(this.edgeCoef.getNumColumns()); for (int i = 0; i < e.size(); i++) { // e.set(i, RandomUtil.getInstance().nextNormal(0, sqrt(errCovar.get(i, i)))); @@ -1569,7 +1569,7 @@ public Vector simulateOneRecord(Vector e) { // Calculate inv(I - edgeCoefC) Matrix edgeCoef = edgeCoef().copy().transpose(); - Matrix iMinusB = Matrix.identity(edgeCoef.rows()).minus(edgeCoef); + Matrix iMinusB = Matrix.identity(edgeCoef.getNumRows()).minus(edgeCoef); Matrix inv = iMinusB.inverse(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java index 517677f38d..de656905cf 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemStdErrorEstimator.java @@ -124,8 +124,8 @@ public void computeStdErrors(ISemIm estSem) { } ROWS: - for (int i = 0; i < hess.rows(); i++) { - for (int j = 0; j < hess.columns(); j++) { + for (int i = 0; i < hess.getNumRows(); i++) { + for (int j = 0; j < hess.getNumColumns(); j++) { if (hess.get(i, j) != 0) { continue ROWS; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java index 2b6d6eb703..3be488e8fc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java @@ -574,7 +574,7 @@ public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) // Calculate inv(I - edgeCoefC) Matrix B = edgeCoef().transpose(); - Matrix iMinusBInv = Matrix.identity(B.rows()).minus(B).inverse(); + Matrix iMinusBInv = Matrix.identity(B.getNumRows()).minus(B).inverse(); // Pick error values e, for each calculate inv * e. Matrix sim = new Matrix(sampleSize, numVars); @@ -582,7 +582,7 @@ public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) for (int row = 0; row < sampleSize; row++) { // Step 1. Generate normal samples. - Vector e = new Vector(edgeCoef().columns()); + Vector e = new Vector(edgeCoef().getNumColumns()); for (int i = 0; i < e.size(); i++) { e.set(i, RandomUtil.getInstance().nextNormal(0, sqrt(errCovar(errorVariances(), false).get(i, i)))); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java index 9f7abea4e7..0413f11316 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java @@ -76,7 +76,7 @@ public Matrix(Matrix m) { } public void assign(Matrix matrix) { - if (this.apacheData.getRowDimension() != matrix.rows() || this.apacheData.getColumnDimension() != matrix.columns()) { + if (this.apacheData.getRowDimension() != matrix.getNumRows() || this.apacheData.getColumnDimension() != matrix.getNumColumns()) { throw new IllegalArgumentException("Mismatched matrix size."); } @@ -87,7 +87,7 @@ public void assign(Matrix matrix) { } } - public int columns() { + public int getNumColumns() { return this.n; } @@ -121,13 +121,13 @@ public Matrix getSelection(int[] rows, int[] cols) { } public Matrix copy() { - if (zeroDimension()) return new Matrix(rows(), columns()); + if (zeroDimension()) return new Matrix(getNumRows(), getNumColumns()); return new Matrix(this.apacheData.copy()); } public Vector getColumn(int j) { if (zeroDimension()) { - return new Vector(rows()); + return new Vector(getNumRows()); } return new Vector(this.apacheData.getColumn(j)); @@ -135,7 +135,7 @@ public Vector getColumn(int j) { public Matrix times(Matrix m) { if (this.zeroDimension() || m.zeroDimension()) - return new Matrix(this.rows(), m.columns()); + return new Matrix(this.getNumRows(), m.getNumColumns()); else { return new Matrix(this.apacheData.multiply(m.apacheData)); } @@ -183,7 +183,7 @@ public void set(int i, int j, double v) { public Vector getRow(int i) { if (zeroDimension()) { - return new Vector(columns()); + return new Vector(getNumColumns()); } return new Vector(this.apacheData.getRow(i)); @@ -196,7 +196,7 @@ public Matrix getPart(int i, int j, int k, int l) { public Matrix inverse() throws SingularMatrixException { if (!isSquare()) throw new IllegalArgumentException("I can only invert square matrices."); - if (rows() == 0) { + if (getNumRows() == 0) { return new Matrix(0, 0); } @@ -205,7 +205,7 @@ public Matrix inverse() throws SingularMatrixException { public Matrix symmetricInverse() { if (!isSquare()) throw new IllegalArgumentException(); - if (rows() == 0) return new Matrix(0, 0); + if (getNumRows() == 0) return new Matrix(0, 0); return new Matrix(new CholeskyDecomposition(this.apacheData).getSolver().getInverse()); } @@ -243,7 +243,7 @@ public double det() { } public Matrix transpose() { - if (zeroDimension()) return new Matrix(columns(), rows()); + if (zeroDimension()) return new Matrix(getNumColumns(), getNumRows()); return new Matrix(this.apacheData.transpose()); } @@ -261,7 +261,7 @@ public boolean equals(Matrix m, double tolerance) { } public boolean isSquare() { - return rows() == columns(); + return getNumRows() == getNumColumns(); } public boolean isSymmetric(double tolerance) { @@ -270,7 +270,7 @@ public boolean isSymmetric(double tolerance) { public Matrix minus(Matrix mb) { - if (mb.rows() == 0 || mb.columns() == 0) return this; + if (mb.getNumRows() == 0 || mb.getNumColumns() == 0) return this; return new Matrix(this.apacheData.subtract(mb.apacheData)); } @@ -279,7 +279,7 @@ public double norm1() { } public Matrix plus(Matrix mb) { - if (mb.rows() == 0 || mb.columns() == 0) return this; + if (mb.getNumRows() == 0 || mb.getNumColumns() == 0) return this; return new Matrix(this.apacheData.add(mb.apacheData)); } @@ -288,14 +288,14 @@ public int rank() { return singularValueDecomposition.getRank(); } - public int rows() { + public int getNumRows() { return this.m; } public Matrix scalarMult(double scalar) { Matrix newMatrix = copy(); - for (int i = 0; i < rows(); i++) { - for (int j = 0; j < columns(); j++) { + for (int i = 0; i < getNumRows(); i++) { + for (int j = 0; j < getNumColumns(); j++) { newMatrix.set(i, j, get(i, j) * scalar); } } @@ -322,12 +322,12 @@ public static Matrix sparseMatrix(int m, int n) { public Vector sum(int direction) { if (direction == 1) { - Vector sums = new Vector(columns()); + Vector sums = new Vector(getNumColumns()); - for (int j = 0; j < columns(); j++) { + for (int j = 0; j < getNumColumns(); j++) { double sum = 0.0; - for (int i = 0; i < rows(); i++) { + for (int i = 0; i < getNumRows(); i++) { sum += this.apacheData.getEntry(i, j); } @@ -336,12 +336,12 @@ public Vector sum(int direction) { return sums; } else if (direction == 2) { - Vector sums = new Vector(rows()); + Vector sums = new Vector(getNumRows()); - for (int i = 0; i < rows(); i++) { + for (int i = 0; i < getNumRows(); i++) { double sum = 0.0; - for (int j = 0; j < columns(); j++) { + for (int j = 0; j < getNumColumns(); j++) { sum += this.apacheData.getEntry(i, j); } @@ -359,11 +359,11 @@ public double zSum() { } private boolean zeroDimension() { - return rows() == 0 || columns() == 0; + return getNumRows() == 0 || getNumColumns() == 0; } public String toString() { - if (rows() == 0) { + if (getNumRows() == 0) { return "Empty"; } else { return MatrixUtils.toString(toArray()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java index 5a8a6ba5d0..ec47c098d7 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MatrixUtils.java @@ -455,10 +455,10 @@ public static Matrix impliedCovar2(Matrix edgeCoef, Matrix errCovar) { final int sampleSize = 10000; - Matrix iMinusBInverse = Matrix.identity(edgeCoef.rows()).minus(edgeCoef).inverse(); + Matrix iMinusBInverse = Matrix.identity(edgeCoef.getNumRows()).minus(edgeCoef).inverse(); - Matrix sample = new Matrix(sampleSize, edgeCoef.columns()); - Vector e = new Vector((edgeCoef.columns())); + Matrix sample = new Matrix(sampleSize, edgeCoef.getNumColumns()); + Vector e = new Vector((edgeCoef.getNumColumns())); for (int i = 0; i < sampleSize; i++) { for (int j = 0; j < e.size(); j++) { @@ -489,7 +489,7 @@ public static Matrix impliedCovar(Matrix edgeCoef, Matrix errCovar) { // return g.times(errCovar).times(g.transpose()); // return g.transpose().times(errCovar).times(g); // I - B - Matrix m1 = Matrix.identity(edgeCoef.rows()).minus(edgeCoef); + Matrix m1 = Matrix.identity(edgeCoef.getNumRows()).minus(edgeCoef); // // // (I - B) ^ -1 Matrix m3 = m1.inverse(); @@ -506,8 +506,8 @@ public static Matrix impliedCovar(Matrix edgeCoef, Matrix errCovar) { } private static boolean containsNaN(Matrix m) { - for (int i = 0; i < m.rows(); i++) { - for (int j = 0; j < m.columns(); j++) { + for (int i = 0; i < m.getNumRows(); i++) { + for (int j = 0; j < m.getNumColumns(); j++) { if (Double.isNaN(m.get(i, j))) { return true; } @@ -627,7 +627,7 @@ public static double[][] vechToVecLeft(int n) { */ public static boolean hasDimensions(double[][] m, int i, int j) { Matrix _m = new Matrix(m); - return _m.rows() == i && _m.columns() == j; + return _m.getNumRows() == i && _m.getNumColumns() == j; } public static double[][] zeros(int rows, int cols) { @@ -671,22 +671,22 @@ public static Matrix cholesky(Matrix covar) { * matrix is returned for convenience, but m is modified in the process. */ public static Matrix convertCovToCorr(Matrix m) { - if (m.rows() != m.columns()) throw new IllegalArgumentException("Not a square matrix."); + if (m.getNumRows() != m.getNumColumns()) throw new IllegalArgumentException("Not a square matrix."); if (!MatrixUtils.isSymmetric(m.toArray(), 0.001)) { throw new IllegalArgumentException("Not symmetric with tolerance " + 0.001); } Matrix corr = m.like(); - for (int i = 0; i < m.rows(); i++) { - for (int j = i + 1; j < m.columns(); j++) { + for (int i = 0; i < m.getNumRows(); i++) { + for (int j = i + 1; j < m.getNumColumns(); j++) { double v = m.get(i, j) / sqrt(m.get(i, i) * m.get(j, j)); corr.set(i, j, v); corr.set(j, i, v); } } - for (int i = 0; i < m.columns(); i++) { + for (int i = 0; i < m.getNumColumns(); i++) { corr.set(i, i, 1.0); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java index 897a9722a9..7237b35671 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Params.java @@ -81,6 +81,7 @@ public final class Params { public static final String ICA_ALGORITHM = "icaAlgorithm"; public static final String ICA_FUNCTION = "icaFunction"; public static final String THRESHOLD_B = "thresholdBHat"; + public static final String GUARANTEE_ACYCLIC = "guaranteeAcyclic"; public static final String THRESHOLD_SPINE = "thresholdSpine"; public static final String ORIENTATION_ALPHA = "orientationAlpha"; public static final String FISHER_EPSILON = "fisherEpsilon"; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java index 3c43de910d..10cef3cc77 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/StatUtils.java @@ -1691,8 +1691,8 @@ public static double partialCovarianceWhittaker(Matrix submatrix) { // cov(X, Y | Z) = cov(X, Y) - cov(X, Z) inverse(cov(Z, Z)) cov(Z, Y) double covXy = submatrix.get(0, 1); - int[] _z = new int[submatrix.rows() - 2]; - for (int i = 0; i < submatrix.rows() - 2; i++) _z[i] = i + 2; + int[] _z = new int[submatrix.getNumRows() - 2]; + for (int i = 0; i < submatrix.getNumRows() - 2; i++) _z[i] = i + 2; Matrix covXz = submatrix.getSelection(new int[]{0}, _z); Matrix covZy = submatrix.getSelection(_z, new int[]{1}); @@ -1715,9 +1715,9 @@ public static double partialCovarianceWhittaker(Matrix covariance, int x, int y, // submatrix = TetradAlgebra.in verse(submatrix); // return -1.0 * submatrix.get(0, 1); - if (x > covariance.rows()) throw new IllegalArgumentException(); - if (y > covariance.rows()) throw new IllegalArgumentException(); - for (int aZ : z) if (aZ > covariance.rows()) throw new IllegalArgumentException(); + if (x > covariance.getNumRows()) throw new IllegalArgumentException(); + if (y > covariance.getNumRows()) throw new IllegalArgumentException(); + for (int aZ : z) if (aZ > covariance.getNumRows()) throw new IllegalArgumentException(); int[] selection = new int[z.length + 2]; @@ -1763,9 +1763,9 @@ public static double partialCorrelationPrecisionMatrix(Matrix submatrix) throws * of the desired variables in covariance */ public static double partialCorrelation(Matrix covariance, int x, int y, int... z) { - if (x > covariance.rows()) throw new IllegalArgumentException(); - if (y > covariance.rows()) throw new IllegalArgumentException(); - for (int aZ : z) if (aZ > covariance.rows()) throw new IllegalArgumentException(); + if (x > covariance.getNumRows()) throw new IllegalArgumentException(); + if (y > covariance.getNumRows()) throw new IllegalArgumentException(); + for (int aZ : z) if (aZ > covariance.getNumRows()) throw new IllegalArgumentException(); int[] selection = new int[z.length + 2]; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java index 464a2b1e0c..ff352f84cb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java @@ -469,7 +469,7 @@ private static void printDataTranspose(String path, String prefix, DataSet dataS List tvars = new ArrayList<>(); - for (int i = 0; i < mt.columns(); i++) tvars.add(new ContinuousVariable("S" + (i + 1))); + for (int i = 0; i < mt.getNumColumns(); i++) tvars.add(new ContinuousVariable("S" + (i + 1))); dataSet = new BoxDataSet(new DoubleDataBox(mt.toArray()), tvars); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java index fcbeaf8584..12991a80e3 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java @@ -356,7 +356,7 @@ private boolean isStandardized(StandardizedSemIm sem) { System.out.println("cov" + cov); - for (int i = 0; i < cov.rows(); i++) { + for (int i = 0; i < cov.getNumRows(); i++) { if (!(FastMath.abs(cov.get(i, i) - 1) < .1)) { return false; } From 7dc00e86b2757d1939a0fda223e88bc05891934e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 11:40:42 -0400 Subject: [PATCH 430/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../java/edu/cmu/tetrad/search/Lingam.java | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index c19ebd4f68..ce52719cf3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -26,11 +26,16 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; import java.util.List; +import static org.apache.commons.math3.util.FastMath.abs; + /** *

      Implements an interpretation of the LiNGAM algorithm. The reference is here:

      * @@ -89,18 +94,6 @@ public Matrix fitW(Matrix W) { PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); - List coefs = new ArrayList<>(); - - for (int i = 0; i < scaledBHat.getNumRows(); i++) { - for (int j = 0; j < scaledBHat.getNumColumns(); j++) { - if (i != j && scaledBHat.get(i, j) != 0) { - coefs.add(Math.abs(scaledBHat.get(i, j))); - } - } - } - - Collections.sort(coefs); - if (!acyclicityGuaranteed) { return scaledBHat; } @@ -111,22 +104,36 @@ public Matrix fitW(Matrix W) { dummyVars.add(new GraphNode("dummy" + i)); } - do { - - F: - for (double coef : coefs) { - for (int i = 0; i < scaledBHat.getNumRows(); i++) { - for (int j = 0; j < scaledBHat.getNumColumns(); j++) { - if (coef == scaledBHat.get(i, j)) { - scaledBHat.set(i, j, 0.0); - break F; - } - } + class Record { + double coef; + int i; + int j; + } + + LinkedList coefs = new LinkedList<>(); + + for (int i = 0; i < scaledBHat.getNumRows(); i++) { + for (int j = 0; j < scaledBHat.getNumColumns(); j++) { + if (i != j && scaledBHat.get(i, j) != 0.0) { + Record record = new Record(); + record.coef = scaledBHat.get(i, j); + record.i = i; + record.j = j; + + coefs.add(record); } } - } while (!LingD.isAcyclic(scaledBHat, dummyVars)); + } + + coefs.sort(Comparator.comparingDouble(o -> abs(o.coef))); - return scaledBHat; + while (true) { + Record coef = coefs.removeFirst(); + scaledBHat.set(coef.i, coef.j, 0.0); + if (LingD.isAcyclic(scaledBHat, dummyVars)) { + return scaledBHat; + } + } } /** From 9ebff2358968e8b0a50470d2c32c92c1a3313390 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 11:44:58 -0400 Subject: [PATCH 431/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../java/edu/cmu/tetrad/search/Lingam.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index ce52719cf3..bfab839259 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -45,14 +45,17 @@ * *

      The focus for this implementation was making super-simple code, not so much * because the method was trivial (it's not) but out of an attempt to compartmentalize. - * Bootstrapping and other forms of improving the estimate of BHat were not addressed, - * and no attempt was made here to ensure that LiNGAM outputs a DAG. Fpr acyclic inputs, - * it does tend to for acyclic inputs in simulation, though for cyclic inputs it tends - * to produce the cyclic DAG, so long as coefficients are bounded somewhat away from zero. - * No attempt was made to implement DirectLiNGAM since it was tangential to the effort - * to get LiNG-D to work. Only a passing effort was made to ensure good performance on - * real data. There is one tuning parameters (in addition to the FastICA paramters that - * are exposed), a threshold on the B Hat matrix for finding edges in the final graph.

      + * Bootstrapping and other forms of improving the estimate of B Hat were not addressed. + * A parameter is included to set whether an acyclic model is to be enforced; it this + * is set to true, then as in the above reference small coefficients are set to zero + * until an acyclic model is achieved. Even without this fpr acyclic inputs, in our + * esperience, it does tend to produce an acyclic model in simulation, though for cyclic + * inputs it tends to produce the cyclic DAG, so long as coefficients are bounded somewhat + * away from zero. No attempt was made to implement DirectLiNGAM since it was tangential + * to the effort to get LiNG-D to work. Only a passing effort was made to ensure good + * performance on real data. There is an additional tuning parameters (in addition to the + * FastICA paramters that are exposed), a threshold on the absolute value of entries in the + * B Hat matrix for finding edges in the final graph.

      * *

      We are using the Hungarian Algorithm to find the best diagonal for the W matrix * and are not doing any searches over all permutations.

      From 57bbdb42e962c13997ab42e8550ab03f86783908 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 11:51:49 -0400 Subject: [PATCH 432/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../src/main/java/edu/cmu/tetrad/search/Lingam.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index bfab839259..6276e33f5a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -97,9 +97,9 @@ public Matrix fitW(Matrix W) { PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); - if (!acyclicityGuaranteed) { - return scaledBHat; - } +// if (!acyclicityGuaranteed) { +// return scaledBHat; +// } List dummyVars = new ArrayList<>(); @@ -131,11 +131,12 @@ class Record { coefs.sort(Comparator.comparingDouble(o -> abs(o.coef))); while (true) { - Record coef = coefs.removeFirst(); - scaledBHat.set(coef.i, coef.j, 0.0); - if (LingD.isAcyclic(scaledBHat, dummyVars)) { + if (!acyclicityGuaranteed || LingD.isAcyclic(scaledBHat, dummyVars)) { return scaledBHat; } + + Record coef = coefs.removeFirst(); + scaledBHat.set(coef.i, coef.j, 0.0); } } From 6bde2f111d70c7956db8451564737e0758e334ad Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 11:54:16 -0400 Subject: [PATCH 433/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 6276e33f5a..a4ebde8596 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -97,10 +97,6 @@ public Matrix fitW(Matrix W) { PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); -// if (!acyclicityGuaranteed) { -// return scaledBHat; -// } - List dummyVars = new ArrayList<>(); for (int i = 0; i < scaledBHat.getNumRows(); i++) { From 46f62749c78481a71e9a3be130c6ffbf498c976b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 20:27:14 -0400 Subject: [PATCH 434/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../java/edu/cmu/tetrad/search/LingD.java | 16 ++++++- .../java/edu/cmu/tetrad/search/Lingam.java | 48 ++++++++++++------- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index a7985dd16f..106651d6c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -83,6 +83,20 @@ public static boolean isAcyclic(Matrix scaledBHat, List variables) { return !g.paths().existsDirectedCycle(); } + public static boolean containsTwoCycle(Matrix scaledBHat, List variables) { + Graph g = makeGraph(scaledBHat, variables); + + for (int i = 0; i < variables.size(); i++) { + for (int j = 0; j < variables.size(); j++) { + if (g.getEdges(variables.get(i), variables.get(j)).size() > 1) { + return true; + } + } + } + + return false; + } + /** * Fits a LiNG-D model to the given dataset using a default method for estimating * W. @@ -153,8 +167,6 @@ public void setSpineThreshold(double spineThreshold) { */ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaTolerance, double fastIcaA) { - data = data.copy(); - double[][] _data = data.getDoubleData().transpose().toArray(); TetradLogger.getInstance().forceLogMessage("Anderson Darling P-values Per Variables (p < alpha means Non-Guassian)"); TetradLogger.getInstance().forceLogMessage(""); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index a4ebde8596..be4c90e7c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -26,8 +26,7 @@ import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; +import edu.cmu.tetrad.util.TetradLogger; import java.util.ArrayList; import java.util.Comparator; @@ -35,6 +34,7 @@ import java.util.List; import static org.apache.commons.math3.util.FastMath.abs; +import static org.apache.commons.math3.util.FastMath.round; /** *

      Implements an interpretation of the LiNGAM algorithm. The reference is here:

      @@ -94,15 +94,11 @@ public Matrix fit(DataSet D) { * @return The estimated B Hat matrix. */ public Matrix fitW(Matrix W) { + double smallest = 0.01; + PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); - List dummyVars = new ArrayList<>(); - - for (int i = 0; i < scaledBHat.getNumRows(); i++) { - dummyVars.add(new GraphNode("dummy" + i)); - } - class Record { double coef; int i; @@ -113,7 +109,7 @@ class Record { for (int i = 0; i < scaledBHat.getNumRows(); i++) { for (int j = 0; j < scaledBHat.getNumColumns(); j++) { - if (i != j && scaledBHat.get(i, j) != 0.0) { + if (i != j && scaledBHat.get(i, j) > 0.1) { Record record = new Record(); record.coef = scaledBHat.get(i, j); record.i = i; @@ -126,13 +122,33 @@ class Record { coefs.sort(Comparator.comparingDouble(o -> abs(o.coef))); - while (true) { - if (!acyclicityGuaranteed || LingD.isAcyclic(scaledBHat, dummyVars)) { - return scaledBHat; + if (acyclicityGuaranteed) { + List dummyVars = new ArrayList<>(); + + for (int i = 0; i < scaledBHat.getNumRows(); i++) { + dummyVars.add(new GraphNode("dummy" + i)); + } + + Record coef = coefs.getFirst(); + + while (true) { + if (LingD.isAcyclic(scaledBHat, dummyVars)) { + TetradLogger.getInstance().forceLogMessage("Effective threshold = " + coef.coef); + return scaledBHat; + } + + coef = coefs.removeFirst(); + scaledBHat.set(coef.i, coef.j, 0.0); + } + } else { + int theshold = (int) round(0.05 * coefs.size()); + + for (int i = 0; i < theshold; i++) { + Record coef = coefs.removeFirst(); + scaledBHat.set(coef.i, coef.j, 0.0); } - Record coef = coefs.removeFirst(); - scaledBHat.set(coef.i, coef.j, 0.0); + return scaledBHat; } } @@ -148,8 +164,8 @@ public void setBThreshold(double bThreshold) { } /** - * Whether or not the LiNGAM algorithm is guaranteed to produce an acyclic graph. This is - * is implemnted by setting small coefficients in B hat to zero until an acyclic model is + * Whether the LiNGAM algorithm is guaranteed to produce an acyclic graph. This is + * implemnted by setting small coefficients in B hat to zero until an acyclic model is * found. * * @param acyclicityGuaranteed True if so. From 7968771e6d2fec8b6396731e4a3f8aed863c4792 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 23:14:19 -0400 Subject: [PATCH 435/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../java/edu/cmu/tetrad/search/LingD.java | 9 +-- .../java/edu/cmu/tetrad/search/Lingam.java | 80 ++++++++++++------- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 106651d6c1..a9d3df9440 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -44,7 +44,7 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

      Implements the LiNG-D algorithm as well as a number of ancillary methods for + *

      Implements the ICA LiNG-D algorithm as well as a number of ancillary methods for * LiNG-D and LiNGAM. The reference is here:

      * *

      Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering @@ -54,10 +54,9 @@ *

      We use the N Rooks algorithm to find alternative cyclic models, as in the above * paper.

      * - *

      This implementation has two parameters, a threshold (for N Rooks) on the minimum - * values in absolute value for including entries in a possible strong diagonal for W, - * and a threshold for B Hat for setting zeros for small betas (i.e., pruning edges from - * the final graph.

      + *

      For the N Rooks algorithm, the spine threshold is a number between 0 and 1. For B Hat, + * the threshold is a number between 0 and 1. The default values are 0.5 and 0.1, + * respectively.

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index be4c90e7c4..8a2dd40c46 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -33,38 +33,73 @@ import java.util.LinkedList; import java.util.List; -import static org.apache.commons.math3.util.FastMath.abs; -import static org.apache.commons.math3.util.FastMath.round; +import static org.apache.commons.math3.util.FastMath.*; /** - *

      Implements an interpretation of the LiNGAM algorithm. The reference is here:

      + *

      Implements the ICA LiNGAM algorithm. The reference is here:

      * *

      Shimizu, S., Hoyer, P. O., Hyvärinen, A., Kerminen, A., & Jordan, M. (2006). * A linear non-Gaussian acyclic model for causal discovery. Journal of Machine Learning * Research, 7(10).

      * - *

      The focus for this implementation was making super-simple code, not so much - * because the method was trivial (it's not) but out of an attempt to compartmentalize. - * Bootstrapping and other forms of improving the estimate of B Hat were not addressed. - * A parameter is included to set whether an acyclic model is to be enforced; it this - * is set to true, then as in the above reference small coefficients are set to zero - * until an acyclic model is achieved. Even without this fpr acyclic inputs, in our - * esperience, it does tend to produce an acyclic model in simulation, though for cyclic - * inputs it tends to produce the cyclic DAG, so long as coefficients are bounded somewhat - * away from zero. No attempt was made to implement DirectLiNGAM since it was tangential - * to the effort to get LiNG-D to work. Only a passing effort was made to ensure good - * performance on real data. There is an additional tuning parameters (in addition to the - * FastICA paramters that are exposed), a threshold on the absolute value of entries in the - * B Hat matrix for finding edges in the final graph.

      + *

      The focus for this implementation was making to make a version of LiNGAM that + * woudl be compatible with LiNG-D (see). There are two parameters, one to choose + * whether an acyclic result will be guaranteed, and another to set a threshold on + * the absolute value of the coefficients in the B Hat matrix. The latter is used + * to find edges in the final graph.

      * - *

      We are using the Hungarian Algorithm to find the best diagonal for the W matrix - * and are not doing any searches over all permutations.

      + *

      LiNGAM is a method for estimating a causal graph from a dataset. It is based on + * the assumption that the data are generated by a linear model with non-Gaussian + * noise. The method is based on the following assumptions:

      + * + *
        + *
      1. The data are generated by a linear model with non-Gaussian noise.
      2. + *
      3. The noise is independent across variables.
      4. + *
      5. The noises for all but possibly one variable are non-Gaussian.
      6. + *
      + * + *

      Under these assumptions, the method estimates a matrix W such that WX = e, where + * X is the data matrix, e is a matrix of noise, and W is a matrix of coefficients. + * The matrix W is then used to estimate a matrix B Hat, where B Hat is the matrix + * of coefficients in the linear model that generated the data. The graph is then + * estimated by finding edges in B Hat.

      + * + *

      There is an option to guarantee acyclicity of the output, which will set + * small coeffients to zero until an acyclic model is achieved. If this option + * is not selected, coefficients above threshold will be sorted to high and + * 5% of the lowest coefficients in B Hat set ot zero, which allows for certain + * cyclic structures to be recovered.

      + * + *

      There are two methods for estimating W. The first is the default method, + * which is to use the LiNG-D algorithm to estimate W. The second is to provide + * a W matrix estimated by some other method. The latter method is useful for + * comparing the performance of LiNGAM to other methods.

      + * + *

      There is an option to set a threshold on the coefficients in B Hat. This + * threshold is used to find edges in the final graph.

      + * + *

      The method is implemented as follows:

      + * + *
        + *
      1. Estimate W using LiNG-D or using a user-provided W matrix.
      2. + *
      3. Estimate B Hat from W.
      4. + *
      5. Set a threshold on the absolute value of the coefficients in B Hat.
      6. + *
      7. Find edges in B Hat.
      8. + *
      9. Set small coefficients to zero until an acyclic model is achieved, if + * acyclicity is guaranteed.
      10. + *
      + * + *

      We are using the Hungarian Algorithm to find the best diagonal for W

      + * + *

      This class is not configured to respect knowledge of forbidden and + * required edges.

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      * * @author josephramsey * @see LingD + * @see edu.cmu.tetrad.search.utils.HungarianAlgorithm */ public class Lingam { private double bThreshold = 0.1; @@ -94,8 +129,6 @@ public Matrix fit(DataSet D) { * @return The estimated B Hat matrix. */ public Matrix fitW(Matrix W) { - double smallest = 0.01; - PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); @@ -141,13 +174,6 @@ class Record { scaledBHat.set(coef.i, coef.j, 0.0); } } else { - int theshold = (int) round(0.05 * coefs.size()); - - for (int i = 0; i < theshold; i++) { - Record coef = coefs.removeFirst(); - scaledBHat.set(coef.i, coef.j, 0.0); - } - return scaledBHat; } } From 5e5a731509db40c9213c6021cce654cd399b6346 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 23:16:29 -0400 Subject: [PATCH 436/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index a9d3df9440..066b088027 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -82,20 +82,6 @@ public static boolean isAcyclic(Matrix scaledBHat, List variables) { return !g.paths().existsDirectedCycle(); } - public static boolean containsTwoCycle(Matrix scaledBHat, List variables) { - Graph g = makeGraph(scaledBHat, variables); - - for (int i = 0; i < variables.size(); i++) { - for (int j = 0; j < variables.size(); j++) { - if (g.getEdges(variables.get(i), variables.get(j)).size() > 1) { - return true; - } - } - } - - return false; - } - /** * Fits a LiNG-D model to the given dataset using a default method for estimating * W. From e02f3c890b327a2288f78ddf840c45453a465137 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 23:24:53 -0400 Subject: [PATCH 437/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../java/edu/cmu/tetrad/search/LingD.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 066b088027..911b8dea48 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -51,12 +51,36 @@ * cyclic causal models by independent components analysis. arXiv preprint * arXiv:1206.3273.

      * - *

      We use the N Rooks algorithm to find alternative cyclic models, as in the above - * paper.

      + *

      We use the N Rooks algorithm to find alternative strongest diagonals for + * permutations of the W matrix. The parameter that N Rooks requires is a + * spine threshold, which is the lowest number in absolute value that a W matrix + * entry can take in order to be part of a strongest diagonal; the implied + * permutation is the permutation that permutes rows so that this combination + * lies along the diagonal of W, which is then scaled, and the separate satisfactory + * B Hat matrices reported.

      * - *

      For the N Rooks algorithm, the spine threshold is a number between 0 and 1. For B Hat, - * the threshold is a number between 0 and 1. The default values are 0.5 and 0.1, - * respectively.

      + *

      The B Hat matrices are further thresholded using a coefficinet threshold; + * values in B hat less than this minimum in absolute value are sent to zero + * and will not correspond to edges in the output model.

      + * + *

      There are also a number of methods that are used in the paper, but are not + * included in this class. These are included in the class Lingam.

      + * + *

      LiNG-D is a method for estimating a directed acyclic graph (DAG) from a + * dataset. The graph is estimated by finding a permutation of the columns of the + * dataset so that the resulting matrix has a strong diagonal. This permutation + * is then used to estimate a DAG. The method is an extension of LiNGAM, which + * estimates a DAG from a dataset using independent components analysis (ICA). + * LiNG-D is a more robust method than LiNGAM, and is particularly useful when + * the underlying DAG is cyclic. LiNG-D is also useful when the underlying DAG + * is acyclic, and it is often more accurate than LiNGAM in this case.

      + * + *

      LiNG-D works as follows. Let X be a dataset. The method first estimates a + * W matrix using ICA. This is done by using the FastICA algorithm to estimate + * independent components, and then using the inverse of the mixing matrix to + * estimate W. Let W be the estimated W matrix, and let B be the true B matrix + * (the matrix of coefficients in the underlying DAG). Let W' be a permutation + * of W such that the diagonal of W' is the * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      @@ -85,6 +109,7 @@ public static boolean isAcyclic(Matrix scaledBHat, List variables) { /** * Fits a LiNG-D model to the given dataset using a default method for estimating * W. + * * @param D A continuous dataset. * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. */ From e1be74d83571ac1c62c0240b4f5927148cd43361 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 23:33:40 -0400 Subject: [PATCH 438/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 14 +++----------- .../main/java/edu/cmu/tetrad/search/Lingam.java | 3 --- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 911b8dea48..41d13c08e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -59,7 +59,7 @@ * lies along the diagonal of W, which is then scaled, and the separate satisfactory * B Hat matrices reported.

      * - *

      The B Hat matrices are further thresholded using a coefficinet threshold; + *

      The B Hat matrices are further thresholded using a coefficient threshold; * values in B hat less than this minimum in absolute value are sent to zero * and will not correspond to edges in the output model.

      * @@ -71,16 +71,8 @@ * dataset so that the resulting matrix has a strong diagonal. This permutation * is then used to estimate a DAG. The method is an extension of LiNGAM, which * estimates a DAG from a dataset using independent components analysis (ICA). - * LiNG-D is a more robust method than LiNGAM, and is particularly useful when - * the underlying DAG is cyclic. LiNG-D is also useful when the underlying DAG - * is acyclic, and it is often more accurate than LiNGAM in this case.

      - * - *

      LiNG-D works as follows. Let X be a dataset. The method first estimates a - * W matrix using ICA. This is done by using the FastICA algorithm to estimate - * independent components, and then using the inverse of the mixing matrix to - * estimate W. Let W be the estimated W matrix, and let B be the true B matrix - * (the matrix of coefficients in the underlying DAG). Let W' be a permutation - * of W such that the diagonal of W' is the + * LiNG-D is particularly useful when the underlying data may have multiple + * consistent cyclic models.

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 8a2dd40c46..e880777361 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -91,9 +91,6 @@ * *

      We are using the Hungarian Algorithm to find the best diagonal for W

      * - *

      This class is not configured to respect knowledge of forbidden and - * required edges.

      - * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      * From cd32a87070fcc40fc793c9dd3e6a10af35045375 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 23:39:18 -0400 Subject: [PATCH 439/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/Lingam.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 41d13c08e1..7595dbd4e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -54,7 +54,7 @@ *

      We use the N Rooks algorithm to find alternative strongest diagonals for * permutations of the W matrix. The parameter that N Rooks requires is a * spine threshold, which is the lowest number in absolute value that a W matrix - * entry can take in order to be part of a strongest diagonal; the implied + * entry can take to be part of a strongest diagonal; the implied * permutation is the permutation that permutes rows so that this combination * lies along the diagonal of W, which is then scaled, and the separate satisfactory * B Hat matrices reported.

      diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index e880777361..59081ace16 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -43,7 +43,7 @@ * Research, 7(10).

      * *

      The focus for this implementation was making to make a version of LiNGAM that - * woudl be compatible with LiNG-D (see). There are two parameters, one to choose + * would be compatible with LiNG-D (see). There are two parameters, one to choose * whether an acyclic result will be guaranteed, and another to set a threshold on * the absolute value of the coefficients in the B Hat matrix. The latter is used * to find edges in the final graph.

      @@ -64,10 +64,10 @@ * of coefficients in the linear model that generated the data. The graph is then * estimated by finding edges in B Hat.

      * - *

      There is an option to guarantee acyclicity of the output, which will set - * small coeffients to zero until an acyclic model is achieved. If this option - * is not selected, coefficients above threshold will be sorted to high and - * 5% of the lowest coefficients in B Hat set ot zero, which allows for certain + *

      There is an option to guarantee the acyclicity of the output, which will set + * small coefficients to zero until an acyclic model is achieved. If this option + * is not selected, coefficients above the threshold will be sorted to high and + * 5% of the lowest coefficients in B Hat set to zero, which allows for certain * cyclic structures to be recovered.

      * *

      There are two methods for estimating W. The first is the default method, @@ -91,7 +91,7 @@ * *

      We are using the Hungarian Algorithm to find the best diagonal for W

      * - *

      This class is not configured to respect knowledge of forbidden and required + *

      This class is not configured to respect knowledge of forbidden and required * edges.

      * * @author josephramsey From 8f126ab466df77daa582fe05f03cb5454f6a243d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 13 May 2023 23:45:31 -0400 Subject: [PATCH 440/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java | 4 ++-- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 7595dbd4e7..3bbeca234c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -136,7 +136,7 @@ public List fitW(Matrix W) { } /** - * Sets the threshold used to prune the B matrix for the local algorithm. + * The threshold to use for set small elements to zero in the B Hat matrices. * * @param bThreshold The threshold, a non-negative number. */ @@ -147,7 +147,7 @@ public void setBThreshold(double bThreshold) { /** * Sets the threshold used to prune the matrix for purpose of searching for alterantive - * strong diagonals.. + * strong diagonals. * * @param spineThreshold The threshold, a non-negative number. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 59081ace16..c183acb630 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -176,8 +176,7 @@ class Record { } /** - * The threshold to use for set small elemtns to zerp in the B Hat matrices for the - * LiNGAM algorithm. + * The threshold to use for set small elements to zero in the B Hat matrices. * * @param bThreshold Some value >= 0. */ From e6aae4efc165c01990f5be1e9e5389d0ed706061 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 14 May 2023 00:20:06 -0400 Subject: [PATCH 441/464] Fixed LiNGAM thresholding algorithm for the acyclic case. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index c183acb630..df8df0f17f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -56,6 +56,7 @@ *
    • The data are generated by a linear model with non-Gaussian noise.
    • *
    • The noise is independent across variables.
    • *
    • The noises for all but possibly one variable are non-Gaussian.
    • + *
    • There is no unobserved confounding.
    • * * *

      Under these assumptions, the method estimates a matrix W such that WX = e, where @@ -89,7 +90,8 @@ * acyclicity is guaranteed. * * - *

      We are using the Hungarian Algorithm to find the best diagonal for W

      + *

      We are using the Hungarian Algorithm to find the best diagonal for W to solve + * the linear assignment problem.

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      From b2f40610742b60f7fec36383b2b04c2d2eb3551b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 14 May 2023 00:41:26 -0400 Subject: [PATCH 442/464] Docs for BOSS. --- .../main/java/edu/cmu/tetrad/search/Boss.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) 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 e46e901c8f..07a5e257ce 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 @@ -12,23 +12,45 @@ import static edu.cmu.tetrad.util.RandomUtil.shuffle; /** - *

      Implements an algorithm called BOSS (Best Order Score Search), which - * intercalates calls to a permutation discovery step with calls to BES in order - * to find an optimal permutation implying a DAG and, therefore, a CPDAG that is - * highly accurate. This follows up on work by Raskutti and Uhler on the SP - * (Sparsest Permutation) algorithm and work by Lam, Andrews, and Ramsey on the - * GRaSP algorithm is currently under development.

      + *

      Implements an algorithm called BOSS (Best Order Score Search). This + * follows up on work by Raskutti and Uhler on the SP (Sparsest Permutation) + * algorithm and work by Lam, Andrews, and Ramsey on the GRaSP algorithm is + * currently under development.

      + * + *

      This algorithm is based on the intuition that the permutation search is + * more effective when the variables are ordered in a way that is close to the + * true causal ordering. The permutation search is a greedy algorithm that + * starts with an arbitrary ordering and then tries to improve the ordering + * by swapping adjacent variables. The permutation search is not guaranteed + * to find the optimal ordering, but it is guaranteed to find an ordering that + * implies a DAG. The permutation search is also very fast, so it can be + * called many times in order to find the best ordering. This algorithm + * intercalates calls to the permutation search with calls to BES, which + * finds a DAG for a given ordering. The algorithm then keeps track of the + * best DAG found so far and the ordering that implies that DAG.

      + * + *

      The algorithm works as follows:

      + * + *
        + *
      1. Start with an arbitrary ordering.
      2. + *
      3. Run the permutation search to find a better ordering.
      4. + *
      5. Run BES on the new ordering to find a DAG.
      6. + *
      7. Repeat steps 2 and 3 until the model score can no longer be improved..
      8. + *
      9. Return the CPDAG of the best DAG found.
      10. + *
      + * + * The BES step is needed for correctness, though with large models is has very + * little effect on the output, since nearly all edges are alreayy oriented, so + * a parameter is included to turn that step off. + * + *

      The permutation search step uses an repeated insert operation.

      * *

      Knowledge can be used with this search. If tiered knowledge is used, then the procedure * is carried out for each tier separately, given the variable preceding that tier, which - * allows the SP algorithm to address tiered (e.g., time series) problems with larger numbers of + * allows the Boss algorithm to address tiered (e.g., time series) problems with larger numbers of * variables.

      * *

      This class is meant to be used in the context of the PermutationSearch class (see). - * the proper use is PermutationSearch search = new PermutationSearch(new Sp(score));

      - * - *

      This class is configured to respect the knowledge of forbidden and required - * edges, including knowledge of temporal tiers.

      * * @author bryanandrews * @author josephramsey From 414b00b7432c4fabc0f7ba6d5bd198fc766c019c Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 14 May 2023 11:14:15 -0400 Subject: [PATCH 443/464] Docs for BOSS. --- .../main/java/edu/cmu/tetrad/search/Boss.java | 83 ++++++++++--------- 1 file changed, 46 insertions(+), 37 deletions(-) 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 07a5e257ce..541fe764f3 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 @@ -68,7 +68,6 @@ public class Boss implements SuborderSearch { private BesPermutation bes = null; private int numStarts = 1; - /** * This algorithm will work with an arbitrary score. * @@ -121,6 +120,52 @@ public void searchSuborder(List prefix, List suborder, Map getVariables() { + return this.variables; + } + + @Override + public Map> getParents() { + return this.parents; + } + + @Override + public Score getScore() { + return this.score; + } private boolean betterMutation(List prefix, List suborder, Node x) { Set all = new HashSet<>(suborder); @@ -176,15 +221,6 @@ private boolean betterMutation(List prefix, List suborder, Node x) { return true; } - public void useBes(boolean use) { - this.bes = null; - if (use) { - this.bes = new BesPermutation(this.score); - this.bes.setVerbose(false); - this.bes.setKnowledge(knowledge); - } - } - private void bes(List prefix, List suborder) { List all = new ArrayList<>(prefix); all.addAll(suborder); @@ -222,31 +258,4 @@ private void makeValidKnowledgeOrder(List order) { } } - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = knowledge; - - if (this.bes != null) { - this.bes.setKnowledge(knowledge); - } - } - - public void setNumStarts(int numStarts) { - this.numStarts = numStarts; - } - - @Override - public List getVariables() { - return this.variables; - } - - @Override - public Map> getParents() { - return this.parents; - } - - @Override - public Score getScore() { - return this.score; - } } \ No newline at end of file From 06950003c0addbaa5e2b966da9b36dacc420763e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 14 May 2023 11:27:36 -0400 Subject: [PATCH 444/464] Docs for BOSS. --- .../java/edu/cmu/tetrad/search/Lingam.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index df8df0f17f..2e28d7340a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -131,30 +131,29 @@ public Matrix fitW(Matrix W) { PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); - class Record { - double coef; - int i; - int j; - } - - LinkedList coefs = new LinkedList<>(); + if (acyclicityGuaranteed) { + class Record { + double coef; + int i; + int j; + } - for (int i = 0; i < scaledBHat.getNumRows(); i++) { - for (int j = 0; j < scaledBHat.getNumColumns(); j++) { - if (i != j && scaledBHat.get(i, j) > 0.1) { - Record record = new Record(); - record.coef = scaledBHat.get(i, j); - record.i = i; - record.j = j; + LinkedList coefs = new LinkedList<>(); - coefs.add(record); + for (int i = 0; i < scaledBHat.getNumRows(); i++) { + for (int j = 0; j < scaledBHat.getNumColumns(); j++) { + if (i != j && scaledBHat.get(i, j) > 0.1) { + Record record = new Record(); + record.coef = scaledBHat.get(i, j); + record.i = i; + record.j = j; + + coefs.add(record); + } } } - } - coefs.sort(Comparator.comparingDouble(o -> abs(o.coef))); - - if (acyclicityGuaranteed) { + coefs.sort(Comparator.comparingDouble(o -> abs(o.coef))); List dummyVars = new ArrayList<>(); for (int i = 0; i < scaledBHat.getNumRows(); i++) { From 85e5b8ffee8f2e33a9cff9fd5da66cd22d4b54d4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 14 May 2023 12:25:55 -0400 Subject: [PATCH 445/464] Docs for BOSS. --- .../main/java/edu/cmu/tetrad/search/LingD.java | 16 ++++++++++++++-- .../main/java/edu/cmu/tetrad/search/Lingam.java | 7 +------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 3bbeca234c..2f25f67564 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphNode; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.HungarianAlgorithm; import edu.cmu.tetrad.search.utils.NRooks; @@ -93,8 +94,19 @@ public class LingD { public LingD() { } - public static boolean isAcyclic(Matrix scaledBHat, List variables) { - Graph g = makeGraph(scaledBHat, variables); + /** + * Determines whether a BHat matrix parses to an acyclic graph.. + * + * @param scaledBHat The BHat matrix.. + */ + public static boolean isAcyclic(Matrix scaledBHat) { + List dummyVars = new ArrayList<>(); + + for (int i = 0; i < scaledBHat.getNumRows(); i++) { + dummyVars.add(new GraphNode("dummy" + i)); + } + + Graph g = makeGraph(scaledBHat, dummyVars); return !g.paths().existsDirectedCycle(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 2e28d7340a..448dccd91d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -154,16 +154,11 @@ class Record { } coefs.sort(Comparator.comparingDouble(o -> abs(o.coef))); - List dummyVars = new ArrayList<>(); - - for (int i = 0; i < scaledBHat.getNumRows(); i++) { - dummyVars.add(new GraphNode("dummy" + i)); - } Record coef = coefs.getFirst(); while (true) { - if (LingD.isAcyclic(scaledBHat, dummyVars)) { + if (LingD.isAcyclic(scaledBHat)) { TetradLogger.getInstance().forceLogMessage("Effective threshold = " + coef.coef); return scaledBHat; } From 8d1592401f01bbc05c7c2ebf539e46db2cb8339a Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 14 May 2023 23:14:24 -0400 Subject: [PATCH 446/464] Fixed some LiNGAM bugs. --- .../src/main/java/edu/cmu/tetrad/search/LingD.java | 4 ++-- .../src/main/java/edu/cmu/tetrad/search/Lingam.java | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java index 2f25f67564..dd0d8a421a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java @@ -305,7 +305,7 @@ public static Matrix threshold(Matrix M, double threshold) { for (int i = 0; i < M.getNumRows(); i++) { for (int j = 0; j < M.getNumColumns(); j++) { - if (abs(M.get(i, j)) < threshold) _M.set(i, j, 0.0); + if (abs(M.get(i, j)) < abs(threshold)) _M.set(i, j, 0.0); } } @@ -327,7 +327,7 @@ public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold Matrix WTilde = pair.getPermutedMatrix().transpose(); WTilde = LingD.scale(WTilde); Matrix BHat = Matrix.identity(WTilde.getNumColumns()).minus(WTilde); - BHat = threshold(BHat, bThreshold); + BHat = threshold(BHat, abs(bThreshold)); int[] perm = pair.getRowPerm(); int[] inverse = LingD.inversePermutation(perm); PermutationMatrixPair inversePair = new PermutationMatrixPair(BHat, inverse, inverse); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java index 448dccd91d..78c2cf1bd1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java @@ -129,7 +129,7 @@ public Matrix fit(DataSet D) { */ public Matrix fitW(Matrix W) { PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); - Matrix scaledBHat = LingD.getScaledBHat(bestPair, bThreshold); + Matrix scaledBHat = LingD.getScaledBHat(bestPair, abs(bThreshold)); if (acyclicityGuaranteed) { class Record { @@ -142,7 +142,7 @@ class Record { for (int i = 0; i < scaledBHat.getNumRows(); i++) { for (int j = 0; j < scaledBHat.getNumColumns(); j++) { - if (i != j && scaledBHat.get(i, j) > 0.1) { + if (i != j && scaledBHat.get(i, j) != 0) { Record record = new Record(); record.coef = scaledBHat.get(i, j); record.i = i; @@ -157,7 +157,7 @@ class Record { Record coef = coefs.getFirst(); - while (true) { + while (!coefs.isEmpty()) { if (LingD.isAcyclic(scaledBHat)) { TetradLogger.getInstance().forceLogMessage("Effective threshold = " + coef.coef); return scaledBHat; @@ -166,7 +166,11 @@ class Record { coef = coefs.removeFirst(); scaledBHat.set(coef.i, coef.j, 0.0); } + + TetradLogger.getInstance().forceLogMessage("Effective threshold = " + abs(coef.coef)); + return scaledBHat; } else { + TetradLogger.getInstance().forceLogMessage("Threshold = " + abs(bThreshold)); return scaledBHat; } } From 92f51eed5e7aff35dc65789b7352618f46d993c4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 14 May 2023 23:34:40 -0400 Subject: [PATCH 447/464] Changing name of LiNGAM TO ICA-LINGAM AND LING-D TO ICA-LING-D --- .../dag/{LingD.java => IcaLingD.java} | 24 ++++++++-------- .../dag/{Lingam.java => IcaLingam.java} | 24 ++++++++-------- .../search/{LingD.java => IcaLingD.java} | 16 +++++------ .../search/{Lingam.java => IcaLingam.java} | 22 ++++++--------- .../search/utils/PermutationMatrixPair.java | 8 +++--- .../examples/conditions/LingamStudy.java | 4 +-- ...tern.java => TestIcaIcaLingamPattern.java} | 2 +- .../test/{TestLing.java => TestIcaLing.java} | 28 +++++++++---------- 8 files changed, 62 insertions(+), 66 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/{LingD.java => IcaLingD.java} (82%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/{Lingam.java => IcaLingam.java} (80%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{LingD.java => IcaLingD.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/search/{Lingam.java => IcaLingam.java} (93%) rename tetrad-lib/src/test/java/edu/cmu/tetrad/test/{TestLingamPattern.java => TestIcaIcaLingamPattern.java} (99%) rename tetrad-lib/src/test/java/edu/cmu/tetrad/test/{TestLing.java => TestIcaLing.java} (90%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingD.java similarity index 82% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingD.java index 973435c3a1..a1811e4955 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingD.java @@ -24,13 +24,13 @@ * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( - name = "LiNG-D", - command = "ling-d", + name = "ICA-LiNG-D", + command = "ica-ling-d", algoType = AlgType.forbid_latent_common_causes, dataType = DataType.Continuous ) @Bootstrapping -public class LingD implements Algorithm, ReturnsBootstrapGraphs { +public class IcaLingD implements Algorithm, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; @@ -46,30 +46,30 @@ public Graph search(DataModel dataSet, Parameters parameters) { double bThreshold = parameters.getDouble(Params.THRESHOLD_B); double spineThreshold = parameters.getDouble(Params.THRESHOLD_SPINE); - Matrix W = edu.cmu.tetrad.search.LingD.estimateW(data, maxIter, tol, alpha); + Matrix W = edu.cmu.tetrad.search.IcaLingD.estimateW(data, maxIter, tol, alpha); - edu.cmu.tetrad.search.LingD lingD = new edu.cmu.tetrad.search.LingD(); - lingD.setBThreshold(bThreshold); - lingD.setSpineThreshold(spineThreshold); - List bHats = lingD.fitW(W); + edu.cmu.tetrad.search.IcaLingD icaLingD = new edu.cmu.tetrad.search.IcaLingD(); + icaLingD.setBThreshold(bThreshold); + icaLingD.setSpineThreshold(spineThreshold); + List bHats = icaLingD.fitW(W); int count = 0; for (Matrix bHat : bHats) { TetradLogger.getInstance().forceLogMessage("LiNG-D Model #" + (++count)); - Graph graph = edu.cmu.tetrad.search.LingD.makeGraph(bHat, dataSet.getVariables()); + Graph graph = edu.cmu.tetrad.search.IcaLingD.makeGraph(bHat, dataSet.getVariables()); TetradLogger.getInstance().forceLogMessage(bHat.toString()); TetradLogger.getInstance().forceLogMessage(graph.toString()); - TetradLogger.getInstance().forceLogMessage("Stable = " + edu.cmu.tetrad.search.LingD.isStable(bHat)); + TetradLogger.getInstance().forceLogMessage("Stable = " + edu.cmu.tetrad.search.IcaLingD.isStable(bHat)); } if (bHats.size() > 0) { - return edu.cmu.tetrad.search.LingD.makeGraph(bHats.get(0), dataSet.getVariables()); + return edu.cmu.tetrad.search.IcaLingD.makeGraph(bHats.get(0), dataSet.getVariables()); } else { throw new IllegalArgumentException("LiNG-D couldn't find a model."); } } else { - LingD algorithm = new LingD(); + IcaLingD algorithm = new IcaLingD(); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingam.java similarity index 80% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingam.java index 32339af02a..dcd3afcefd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingam.java @@ -10,7 +10,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.LingD; +import edu.cmu.tetrad.search.IcaLingD; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -25,13 +25,13 @@ * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( - name = "LiNGAM", - command = "lingam", + name = "ICA-LiNGAM", + command = "ica-lingam", algoType = AlgType.forbid_latent_common_causes, dataType = DataType.Continuous ) @Bootstrapping -public class Lingam implements Algorithm, ReturnsBootstrapGraphs { +public class IcaLingam implements Algorithm, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; @@ -45,19 +45,19 @@ public Graph search(DataModel dataSet, Parameters parameters) { double alpha = parameters.getDouble(Params.FAST_ICA_A); double tol = parameters.getDouble(Params.FAST_ICA_TOLERANCE); - Matrix W = LingD.estimateW(data, maxIter, tol, alpha); - edu.cmu.tetrad.search.Lingam lingam = new edu.cmu.tetrad.search.Lingam(); - lingam.setBThreshold(parameters.getDouble(Params.THRESHOLD_B)); - lingam.setAcyclicityGuaranteed(parameters.getBoolean(Params.GUARANTEE_ACYCLIC)); + Matrix W = IcaLingD.estimateW(data, maxIter, tol, alpha); + edu.cmu.tetrad.search.IcaLingam icaLingam = new edu.cmu.tetrad.search.IcaLingam(); + icaLingam.setBThreshold(parameters.getDouble(Params.THRESHOLD_B)); + icaLingam.setAcyclicityGuaranteed(parameters.getBoolean(Params.GUARANTEE_ACYCLIC)); - Matrix bHat = lingam.fitW(W); - Graph graph = LingD.makeGraph(bHat, data.getVariables()); + Matrix bHat = icaLingam.fitW(W); + Graph graph = IcaLingD.makeGraph(bHat, data.getVariables()); TetradLogger.getInstance().forceLogMessage(bHat.toString()); TetradLogger.getInstance().forceLogMessage(graph.toString()); return graph; } else { - Lingam algorithm = new Lingam(); + IcaLingam algorithm = new IcaLingam(); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, @@ -78,7 +78,7 @@ public Graph getComparisonGraph(Graph graph) { } public String getDescription() { - return "LiNGAM (Linear Non-Gaussian Acyclic Model"; + return "ICA-LiNGAM (ICA Linear Non-Gaussian Acyclic Model"; } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java index dd0d8a421a..fe5171ac9e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/LingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java @@ -67,7 +67,7 @@ *

      There are also a number of methods that are used in the paper, but are not * included in this class. These are included in the class Lingam.

      * - *

      LiNG-D is a method for estimating a directed acyclic graph (DAG) from a + *

      ICA-LiNG-D is a method for estimating a directed acyclic graph (DAG) from a * dataset. The graph is estimated by finding a permutation of the columns of the * dataset so that the resulting matrix has a strong diagonal. This permutation * is then used to estimate a DAG. The method is an extension of LiNGAM, which @@ -82,16 +82,16 @@ * @author gustavolacerda * @author patrickhoyer * @author josephramsey - * @see Lingam + * @see IcaLingam */ -public class LingD { +public class IcaLingD { private double spineThreshold = 0.5; private double bThreshold = 0.1; /** * Constructor. */ - public LingD() { + public IcaLingD() { } /** @@ -118,7 +118,7 @@ public static boolean isAcyclic(Matrix scaledBHat) { * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. */ public List fit(DataSet D) { - Matrix W = LingD.estimateW(D, 5000, 1e-6, 1.2); + Matrix W = IcaLingD.estimateW(D, 5000, 1e-6, 1.2); return fitW(W); } @@ -140,7 +140,7 @@ public List fitW(Matrix W) { List results = new ArrayList<>(); for (PermutationMatrixPair pair : pairs) { - Matrix bHat = LingD.getScaledBHat(pair, bThreshold); + Matrix bHat = IcaLingD.getScaledBHat(pair, bThreshold); results.add(bHat); } @@ -325,11 +325,11 @@ public static Matrix threshold(Matrix M, double threshold) { */ public static Matrix getScaledBHat(PermutationMatrixPair pair, double bThreshold) { Matrix WTilde = pair.getPermutedMatrix().transpose(); - WTilde = LingD.scale(WTilde); + WTilde = IcaLingD.scale(WTilde); Matrix BHat = Matrix.identity(WTilde.getNumColumns()).minus(WTilde); BHat = threshold(BHat, abs(bThreshold)); int[] perm = pair.getRowPerm(); - int[] inverse = LingD.inversePermutation(perm); + int[] inverse = IcaLingD.inversePermutation(perm); PermutationMatrixPair inversePair = new PermutationMatrixPair(BHat, inverse, inverse); return inversePair.getPermutedMatrix(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java similarity index 93% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java index 78c2cf1bd1..edf1e7765b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java @@ -22,18 +22,14 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.GraphNode; -import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.PermutationMatrixPair; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; -import java.util.ArrayList; import java.util.Comparator; import java.util.LinkedList; -import java.util.List; -import static org.apache.commons.math3.util.FastMath.*; +import static org.apache.commons.math3.util.FastMath.abs; /** *

      Implements the ICA LiNGAM algorithm. The reference is here:

      @@ -48,7 +44,7 @@ * the absolute value of the coefficients in the B Hat matrix. The latter is used * to find edges in the final graph.

      * - *

      LiNGAM is a method for estimating a causal graph from a dataset. It is based on + *

      ICA-LiNGAM is a method for estimating a causal graph from a dataset. It is based on * the assumption that the data are generated by a linear model with non-Gaussian * noise. The method is based on the following assumptions:

      * @@ -97,17 +93,17 @@ * edges.

      * * @author josephramsey - * @see LingD + * @see IcaLingD * @see edu.cmu.tetrad.search.utils.HungarianAlgorithm */ -public class Lingam { +public class IcaLingam { private double bThreshold = 0.1; private boolean acyclicityGuaranteed = true; /** * Constructor.. */ - public Lingam() { + public IcaLingam() { } /** @@ -117,7 +113,7 @@ public Lingam() { * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. */ public Matrix fit(DataSet D) { - Matrix W = LingD.estimateW(D, 5000, 1e-6, 1.2); + Matrix W = IcaLingD.estimateW(D, 5000, 1e-6, 1.2); return fitW(W); } @@ -128,8 +124,8 @@ public Matrix fit(DataSet D) { * @return The estimated B Hat matrix. */ public Matrix fitW(Matrix W) { - PermutationMatrixPair bestPair = LingD.hungarianDiagonal(W); - Matrix scaledBHat = LingD.getScaledBHat(bestPair, abs(bThreshold)); + PermutationMatrixPair bestPair = IcaLingD.hungarianDiagonal(W); + Matrix scaledBHat = IcaLingD.getScaledBHat(bestPair, abs(bThreshold)); if (acyclicityGuaranteed) { class Record { @@ -158,7 +154,7 @@ class Record { Record coef = coefs.getFirst(); while (!coefs.isEmpty()) { - if (LingD.isAcyclic(scaledBHat)) { + if (IcaLingD.isAcyclic(scaledBHat)) { TetradLogger.getInstance().forceLogMessage("Effective threshold = " + coef.coef); return scaledBHat; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java index 75b902bb1f..e4cdda97e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PermutationMatrixPair.java @@ -21,8 +21,8 @@ package edu.cmu.tetrad.search.utils; -import edu.cmu.tetrad.search.LingD; -import edu.cmu.tetrad.search.Lingam; +import edu.cmu.tetrad.search.IcaLingD; +import edu.cmu.tetrad.search.IcaLingam; import edu.cmu.tetrad.util.Matrix; import java.util.Arrays; @@ -33,8 +33,8 @@ * Returns the matrix permuted by these row and column permutations. * * @author josephramsey - * @see Lingam - * @see LingD + * @see IcaLingam + * @see IcaLingD */ public class PermutationMatrixPair { private final int[] rowPerm; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java index aa6ccf3d38..a3fe10a495 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/examples/conditions/LingamStudy.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.continuous.dag.Lingam; +import edu.cmu.tetrad.algcomparison.algorithm.continuous.dag.IcaLingam; import edu.cmu.tetrad.algcomparison.algorithm.multi.Fask; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fas; import edu.cmu.tetrad.algcomparison.algorithm.pairwise.R3; @@ -63,7 +63,7 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new Lingam()); + algorithms.add(new IcaLingam()); algorithms.add(new R3(new Fas(new FisherZ()))); algorithms.add(new Rskew(new Fas(new FisherZ()))); algorithms.add(new Fask(new FisherZ(), new SemBicScore())); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaIcaLingamPattern.java similarity index 99% rename from tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java rename to tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaIcaLingamPattern.java index 94760f3607..05ba5899a9 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLingamPattern.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaIcaLingamPattern.java @@ -44,7 +44,7 @@ /** * @author josephramsey */ -public class TestLingamPattern { +public class TestIcaIcaLingamPattern { @Test public void test1() { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaLing.java similarity index 90% rename from tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java rename to tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaLing.java index 8d1212de8c..b07449e07d 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestLing.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaLing.java @@ -26,8 +26,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.LingD; -import edu.cmu.tetrad.search.Lingam; +import edu.cmu.tetrad.search.IcaLingD; +import edu.cmu.tetrad.search.IcaLingam; import edu.cmu.tetrad.search.utils.NRooks; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.Parameters; @@ -43,7 +43,7 @@ /** * @author josephramsey */ -public class TestLing { +public class TestIcaLing { @Test public void test1() { @@ -90,13 +90,13 @@ public void test1() { double spineThreshold = 0.5; System.out.println("W threshold = " + bThreshold); - Lingam lingam = new Lingam(); - lingam.setBThreshold(bThreshold); - Matrix lingamBhat = lingam.fit(dataSet); - Graph lingamGraph = LingD.makeGraph(lingamBhat, dataSet.getVariables()); + IcaLingam icaLingam = new IcaLingam(); + icaLingam.setBThreshold(bThreshold); + Matrix lingamBhat = icaLingam.fit(dataSet); + Graph lingamGraph = IcaLingD.makeGraph(lingamBhat, dataSet.getVariables()); System.out.println("Lingam graph = " + lingamGraph); - boolean lingamStable = LingD.isStable(lingamBhat); + boolean lingamStable = IcaLingD.isStable(lingamBhat); System.out.println(lingamStable ? "Is Stable" : "Not stable"); lingamGraph = GraphUtils.replaceNodes(lingamGraph, trueGraph.getNodes()); @@ -109,10 +109,10 @@ public void test1() { // associated column-permuted W thresholded W matrices. For the constrained N rooks problme we // are allowed to place a "rook" at any position in the thresholded W matrix that is not zero. System.out.println("LiNG-D"); - LingD lingD = new LingD(); - lingD.setBThreshold(bThreshold); - lingD.setSpineThreshold(spineThreshold); - List bHats = lingD.fit(dataSet); + IcaLingD icaLingD = new IcaLingD(); + icaLingD.setBThreshold(bThreshold); + icaLingD.setSpineThreshold(spineThreshold); + List bHats = icaLingD.fit(dataSet); if (bHats.isEmpty()) { throw new IllegalArgumentException("Could not find an N Rooks solution with that threshold."); @@ -123,10 +123,10 @@ public void test1() { for (Matrix bHat : bHats) { System.out.println("BHat = " + bHat); - Graph lingGraph = LingD.makeGraph(bHat, dataSet.getVariables()); + Graph lingGraph = IcaLingD.makeGraph(bHat, dataSet.getVariables()); System.out.println("\nGraph = " + lingGraph); - boolean stable = LingD.isStable(bHat); + boolean stable = IcaLingD.isStable(bHat); System.out.println(stable ? "Is Stable" : "Not stable"); // For this example, there is exactly one graph (or should be, unless the example was changed). From de63474fc4a2957cb1465903d092d1147d0c685e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 00:10:05 -0400 Subject: [PATCH 448/464] Changing name of LiNGAM TO ICA-LINGAM AND LING-D TO ICA-LING-D --- .../main/java/edu/cmu/tetrad/search/IcaLingD.java | 2 +- .../main/java/edu/cmu/tetrad/search/IcaLingam.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java index fe5171ac9e..9a4bff983b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java @@ -45,7 +45,7 @@ import static org.apache.commons.math3.util.FastMath.*; /** - *

      Implements the ICA LiNG-D algorithm as well as a number of ancillary methods for + *

      Implements the ICA-LiNG-D algorithm as well as a number of ancillary methods for * LiNG-D and LiNGAM. The reference is here:

      * *

      Lacerda, G., Spirtes, P. L., Ramsey, J., & Hoyer, P. O. (2012). Discovering diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java index edf1e7765b..679024b563 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java @@ -32,13 +32,13 @@ import static org.apache.commons.math3.util.FastMath.abs; /** - *

      Implements the ICA LiNGAM algorithm. The reference is here:

      + *

      Implements the ICA-LiNGAM algorithm. The reference is here:

      * *

      Shimizu, S., Hoyer, P. O., Hyvärinen, A., Kerminen, A., & Jordan, M. (2006). * A linear non-Gaussian acyclic model for causal discovery. Journal of Machine Learning * Research, 7(10).

      * - *

      The focus for this implementation was making to make a version of LiNGAM that + *

      The focus for this implementation was making to make a version of ICA-LiNGAM that * would be compatible with LiNG-D (see). There are two parameters, one to choose * whether an acyclic result will be guaranteed, and another to set a threshold on * the absolute value of the coefficients in the B Hat matrix. The latter is used @@ -68,9 +68,9 @@ * cyclic structures to be recovered.

      * *

      There are two methods for estimating W. The first is the default method, - * which is to use the LiNG-D algorithm to estimate W. The second is to provide + * which is to use the ICA-LiNG-D algorithm to estimate W. The second is to provide * a W matrix estimated by some other method. The latter method is useful for - * comparing the performance of LiNGAM to other methods.

      + * comparing the performance of ICA-LiNGAM to other methods.

      * *

      There is an option to set a threshold on the coefficients in B Hat. This * threshold is used to find edges in the final graph.

      @@ -107,7 +107,7 @@ public IcaLingam() { } /** - * Fits a LiNGAM model to the given dataset using a default method for estimating W. + * Fits an ICA-LiNGAM model to the given dataset using a default method for estimating W. * * @param D A continuous dataset. * @return The BHat matrix, where B[i][j] gives the coefficient of j->i if nonzero. @@ -182,7 +182,7 @@ public void setBThreshold(double bThreshold) { } /** - * Whether the LiNGAM algorithm is guaranteed to produce an acyclic graph. This is + * Whether the ICA-LiNGAM algorithm is guaranteed to produce an acyclic graph. This is * implemnted by setting small coefficients in B hat to zero until an acyclic model is * found. * From f87526a747e14388b849f6148fbb0525abd7bdd6 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 00:18:40 -0400 Subject: [PATCH 449/464] Changing name of LiNGAM TO ICA-LINGAM AND LING-D TO ICA-LING-D --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java index 679024b563..98ab9eab64 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java @@ -89,7 +89,7 @@ *

      We are using the Hungarian Algorithm to find the best diagonal for W to solve * the linear assignment problem.

      * - *

      This class is not configured to respect knowledge of forbidden and required + *

      This class is not configured to respect knowledge of forbidden and required * edges.

      * * @author josephramsey From c32698e64be7465c60758b0e8b8a513cde9eab3b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 00:37:00 -0400 Subject: [PATCH 450/464] Documentation. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index b5ac64b289..a1bc3a1253 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -56,6 +56,8 @@ * for the initial step; in this repository we give three other options, * GRaSP-FCI, BFCI (BOSS FCI), and SP-FCI (see).

      * + *

      For more information on the algorithm, see the reference above.

      + * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      * @@ -73,13 +75,12 @@ public final class GFci implements IGraphSearch { private Graph graph; private Knowledge knowledge = new Knowledge(); - private IndependenceTest independenceTest; + private final IndependenceTest independenceTest; private boolean completeRuleSetUsed = true; private int maxPathLength = -1; private int maxDegree = -1; private final TetradLogger logger = TetradLogger.getInstance(); private boolean verbose; - private ICovarianceMatrix covarianceMatrix; private PrintStream out = System.out; private boolean faithfulnessAssumed = true; private final Score score; From 77ced6eb74bb2936a422c76d7bc4aa545aa6ada4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 00:38:44 -0400 Subject: [PATCH 451/464] Documentation. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 0adaa7ae86..2c7255a761 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -42,8 +42,9 @@ *

      Uses SP in place of FGES for the initial step in the GFCI algorithm. * This tends to produce a accurate PAG than GFCI as a result, for the latent * variables case. This is a simple substitution; the reference for GFCI is here:

      + * *

      J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm - * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for + * for Latent Variable Models," JMLR 2016. Here, SP has been substituted for * FGES.

      * *

      For SP only a score is needed, but there are steps in GFCI that require @@ -63,6 +64,7 @@ * @see BFci * @see GraspFci * @see Fges + * @see Sp * @see Knowledge */ public final class SpFci implements IGraphSearch { From 726b4e112e61941cf21d6f4dfe3dbf9aa46b2733 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 08:53:33 -0400 Subject: [PATCH 452/464] Documentation. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 5 +++-- tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index a1bc3a1253..1f53c97f58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -43,8 +43,9 @@ * independence reasoning is used to add the remaining colliders into the graph. * Then, the FCI final orentation rules are applied. The reference is here:

      * - *

      J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm - * for Latent Variable Models," JMLR 2016.

      + *

      Ogarrio, J. M., Spirtes, P., & Ramsey, J. (2016, August). A hybrid causal + * search algorithm for latent variable models. In Conference on probabilistic graphical + * models (pp. 368-379). PMLR.

      * *

      Because the method both runs FGES (a score-based algorithm) and does * additional checking of conditional independencies, both as part of its diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 2c7255a761..9904acc251 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -47,6 +47,11 @@ * for Latent Variable Models," JMLR 2016. Here, SP has been substituted for * FGES.

      * + *

      The reference for the SP algorithm is here:

      + * + *

      Raskutti, G., & Uhler, C. (2018). Learning directed acyclic graph models based + * on sparsest permutations. Stat, 7(1), e183.

      + * *

      For SP only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

      * From 4ca6c52eaf204e57aab49721b4e636c0f0c7762e Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 09:09:12 -0400 Subject: [PATCH 453/464] Documentation. --- .../main/java/edu/cmu/tetrad/search/GFci.java | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index 1f53c97f58..c8472ea721 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -20,7 +20,6 @@ /////////////////////////////////////////////////////////////////////////////// package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.ICovarianceMatrix; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.data.KnowledgeEdge; import edu.cmu.tetrad.graph.*; @@ -90,6 +89,14 @@ public final class GFci implements IGraphSearch { private int depth = -1; //============================CONSTRUCTORS============================// + + /** + * Constructs a new GFci algorithm with the given independence test and + * score. + * + * @param test The independence test to use. + * @param score The score to use. + */ public GFci(IndependenceTest test, Score score) { if (score == null) { throw new NullPointerException(); @@ -239,6 +246,7 @@ public void setOut(PrintStream out) { /** * Sets whether one-edge faithfulness is assumed. For FGES + * * @param faithfulnessAssumed True if so. * @see Fges#setFaithfulnessAssumed(boolean) */ @@ -246,6 +254,33 @@ public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { this.faithfulnessAssumed = faithfulnessAssumed; } + /** + * Sets whether the discriminating path rule should be used. + * + * @param doDiscriminatingPathRule True if so. + */ + public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { + this.doDiscriminatingPathRule = doDiscriminatingPathRule; + } + + /** + * Sets whether the possible d-sep search should be done. + * + * @param possibleDsepSearchDone True if so. + */ + public void setPossibleDsepSearchDone(boolean possibleDsepSearchDone) { + this.possibleDsepSearchDone = possibleDsepSearchDone; + } + + /** + * Sets the depth of the search for the possible d-sep search. + * + * @param depth This depth. + */ + public void setDepth(int depth) { + this.depth = depth; + } + //===========================================PRIVATE METHODS=======================================// // Due to Spirtes. @@ -333,16 +368,4 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) this.logger.log("info", "Finishing BK Orientation."); } - - public void setDoDiscriminatingPathRule(boolean doDiscriminatingPathRule) { - this.doDiscriminatingPathRule = doDiscriminatingPathRule; - } - - public void setPossibleDsepSearchDone(boolean possibleDsepSearchDone) { - this.possibleDsepSearchDone = possibleDsepSearchDone; - } - - public void setDepth(int depth) { - this.depth = depth; - } } From dd6e8d5576b525dda77cae21c6fc87a90d13d006 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 09:11:17 -0400 Subject: [PATCH 454/464] Documentation. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index c8472ea721..f731aeb9fd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -193,11 +193,11 @@ public void setKnowledge(Knowledge knowledge) { } /** - * Sets whether Zhang's complete rules is used. + * Sets whether Zhang's complete rules are used. * * @param completeRuleSetUsed set to true if Zhang's complete rule set * should be used, false if only R1-R4 (the rule set of the original FCI) - * should be used. False by default. + * should be used. True by default. */ public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) { this.completeRuleSetUsed = completeRuleSetUsed; From 95e6ddd18f034a6706854bdd8c87e451a84be479 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 10:31:19 -0400 Subject: [PATCH 455/464] Documentation. --- .../main/java/edu/cmu/tetrad/search/Fges.java | 22 ++++++++++++------- .../main/java/edu/cmu/tetrad/search/GFci.java | 3 ++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index 0d1a7664c7..8df10ce3a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -46,10 +46,11 @@ import static org.apache.commons.math3.util.FastMath.min; /** - *

      Imlements the Greedy Equivalence Search (GES) algorithm, originally due to - * Chris Meek but developed significantly by Max Chickering, with some - * optimizations that allow it to scale accurately to thousands of variables - * for the sparse case. The reference is this:

      + *

      Imlements the Fast Greedy Equivalence Search (GGES) algorithm. This is + * an implementation of the Greedy Equivalence Search algroithm, originally + * due to Chris Meek but developed significantly by Max Chickering. FGES uses + * with some optimizations that allow it to scale accurately to thousands + * of variables accurately for the sparse case. The reference for FGES is this:

      * *

      Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). * A million variables and more: the fast greedy equivalence search algorithm @@ -57,20 +58,25 @@ * to functional magnetic resonance images. International journal of data science * and analytics, 3, 121-129.

      * - *

      Specifically, FGES is an implementation of the GES algorithm as specified - * in this paper:

      + *

      The reference for Chickering's GES is this:

      * *

      Chickering (2002) "Optimal structure identification with greedy search" * Journal of Machine Learning Research.

      * - *

      It works for both BayesNets and SEMs.

      + *

      FGES works for the continuous case, the discrete case, and the mixed + * continuous/discrete case, so long as a BIC score is available for the type + * of data in question.

      * *

      To speed things up, it has been assumed that variables X and Y with zero * correlation do not correspond to edges in the graph. This is a restricted * form of the heuristic speedup assumption, something GES does not assume. - * This heuristicSpeedup assumption needs to be explicitly turned on using + * This heuristic speedup assumption needs to be explicitly turned on using * setHeuristicSpeedup(true).

      * + *

      Also, edges to be added or remove from the graph in the forward or + * backward phase, respectively are cached, together with the ancillary information + * needed to do the additions or removals, to reduce rescoring.

      + * *

      A number of other optimizations were also. See code for details.

      * *

      This class is configured to respect knowledge of forbidden and required diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java index f731aeb9fd..5ed170bfcc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java @@ -363,7 +363,8 @@ private void fciOrientbk(Knowledge knowledge, Graph graph, List variables) graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); - this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + this.logger.log("knowledgeOrientation", LogUtilsSearch.edgeOrientedMsg("Knowledge", + graph.getEdge(from, to))); } this.logger.log("info", "Finishing BK Orientation."); From b53ae8d8d6f7f3262284717a4ddf89bd1f4c9278 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 16:51:51 -0400 Subject: [PATCH 456/464] Documentation. --- .../main/java/edu/cmu/tetrad/search/BFci.java | 3 +++ .../main/java/edu/cmu/tetrad/search/Bpc.java | 20 +++++++++++++++---- .../main/java/edu/cmu/tetrad/search/Ccd.java | 11 ++++++---- .../main/java/edu/cmu/tetrad/search/Cfci.java | 4 ++-- .../main/java/edu/cmu/tetrad/search/Cpc.java | 18 +++++++++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index d4ea3c26f0..466272e89e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -43,6 +43,9 @@ * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

      * + *

      BOSS is a an algorithm that is currently being written up for publication, + * so we don't yet have a reference for it.

      + * *

      For BOSS only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

      * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java index d954e8595d..a15cb9b78d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Bpc.java @@ -35,15 +35,27 @@ /** - *

      Implements the Build Pure Clusters algorithm, which allows one to identify - * clusters of measured variables in a dataset that are explained by single latents. - * The algorithm outputs these clusters, which can then be used for further analysis. - * The reference is this:

      + *

      Implements the Build Pure Clusters (BPC) algorithm, which allows one to identify + * clusters of measured variables in a dataset that are explained by a single latent. + * The algorithm outputs these clusters, which can then be used for further analysis, + * such as inferring structure over the latents. For the latter, see for instance the + * MimBuild algorithm.

      + * + *

      The reference for BPC is this:

      * *

      Silva, R., Scheines, R., Glymour, C., Spirtes, P., & Chickering, D. M. (2006). * Learning the Structure of Linear Latent Variable Models. Journal of Machine Learning * Research, 7(2).

      * + *

      For a more detailed description of the algorithm, see the paper above. The + * algorithm is based on the idea of finding cliques in the graph of the covariance + * matrix. The algorithm is initialized by finding all maximal cliques in the graph + * of the covariance matrix. Then, the algorithm iterates over the cliques, and + * for each clique, it tests whether the clique is explained by a single latent. + * If so, the clique is added to the set of clusters. If not, the clique is + * partitioned into smaller cliques, and the process is repeated for each of the + * smaller cliques. The algorithm stops when all cliques have been tested.

      + * *

      Some more References:

      * *

      Silva, R.; Scheines, R.; Spirtes, P.; Glymour, C. (2003). "Learning measurement models". 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 ccda3c058b..6d2b2d04cb 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 @@ -35,11 +35,14 @@ *

      Implemented the Cyclic Causal Discovery (CCD) algorithm by Thomas Richardson. * A reference for this is here:

      * - *

      Mooij, J. M., & Claassen, T. (2020, August). Constraint-based causal discovery - * using partial ancestral graphs in the presence of cycles. In Conference on Uncertainty - * in Artificial Intelligence (pp. 1159-1168). PMLR.

      + *

      Richardson, T. S. (2013). A discovery algorithm for directed cyclic graphs. arXiv + * preprint arXiv:1302.3599.

      + * + *

      See also Chapter 7 of:

      + * + *

      Glymour, C. N., & Cooper, G. F. (Eds.). (1999). Computation, causation, and + * discovery. Aaai Press.

      * - *

      See also Chapter 7 of Glymour and Cooper, eds., Computation, Causation, and Discovery

      *

      The graph takes continuous data from a cyclic model as input and returns a cyclic * PAG graphs, with various types of underlining, that represents a Markov equivalence of * the true DAG.

      diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 7a990ddc27..5ed421e62f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -35,9 +35,9 @@ /** - * Adjusts FCI (see) to use conservative orientation as in CPC (see). Because the + *

      Adjusts FCI (see) to use conservative orientation as in CPC (see). Because the * collider orientatation is conservative, there may be ambiguous triples; these - * may be retrieved using that accessor method. + * may be retrieved using that accessor method.

      * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      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 e7bf5011a8..d570748db0 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 @@ -43,6 +43,23 @@ *

      Ramsey, J., Zhang, J., & Spirtes, P. L. (2012). Adjacency-faithfulness and * conservative causal inference. arXiv preprint arXiv:1206.6843.

      * + *

      Conservative triple orientation is a method for orienting unshielded triples + * X*=-*Y*-*Z as one of the following: (a) Collider, X->Y<-Z, (b) Noncollider, + * X-->Y-->Z, or X<-Y<-Z, or X<-Y->Z, (c) ambiguous between (a) or (b). One does \ + * this by conditioning on subsets of adj(X) or adj(Z). One first checks conditional + * independence of X and Z conditional on each of these subsets, then lists + * all of these subsets conditional on which X and Z are *independent*, then looks + * thoough this list to see if Y is in them. If Y is in all of these subset, the + * triple is judged to be a noncollider; if it is in none of these subsets, the + * triple is judged to be a collider, and if it is in some of these subsets and + * not in others of the subsets, then it is judged to be ambiguous.

      + * + *

      Ambiguous triple are marked in the final graph using an underline, and the + * final graph is called an "e-patterh", and represents a collection of CPDAGs. + * To find an element of this collection, one first needs to choose for each + * ambiguous triple whether it should be a collider or a noncollider and then + * run the Meek rules given the result of these decisions.

      + * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      * @@ -50,6 +67,7 @@ * @see Pc * @see PcMax * @see Knowledge + * @see edu.cmu.tetrad.search.utils.MeekRules */ public final class Cpc implements IGraphSearch { From fa82ee3d55f159b270d6125ffe81397212b4f6d4 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 18:25:03 -0400 Subject: [PATCH 457/464] Documentation. --- .../java/edu/cmu/tetrad/search/Cstar.java | 20 +-- .../main/java/edu/cmu/tetrad/search/Fci.java | 3 + .../java/edu/cmu/tetrad/search/FciMax.java | 26 +++- .../java/edu/cmu/tetrad/search/Grasp.java | 19 ++- .../java/edu/cmu/tetrad/search/GraspFci.java | 11 +- .../edu/cmu/tetrad/search/GrowShrink.java | 28 +++- .../main/java/edu/cmu/tetrad/search/Ida.java | 3 +- .../main/java/edu/cmu/tetrad/search/Lofs.java | 7 +- .../java/edu/cmu/tetrad/search/Mimbuild.java | 7 +- .../edu/cmu/tetrad/search/MimbuildTrek.java | 1 + .../main/java/edu/cmu/tetrad/search/Pc.java | 2 +- .../java/edu/cmu/tetrad/search/PcMax.java | 18 ++- .../main/java/edu/cmu/tetrad/search/Pcd.java | 4 +- .../cmu/tetrad/search/PermutationSearch.java | 13 +- .../main/java/edu/cmu/tetrad/search/Sp.java | 123 +++++++++--------- .../java/edu/cmu/tetrad/search/SpFci.java | 4 +- 16 files changed, 186 insertions(+), 103 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index f6a7308e43..215caab724 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -20,23 +20,25 @@ import java.util.concurrent.*; /** - *

      Implements the CStaR algorithm (Steckoven et al., 2012), which finds a CPDAG of that data and then - * tries all orientations of the undirected edges about a variable in the CPDAG to estimate a - * minimum bound on the effect for a given edge. Some references include the following:

      + *

      Implements the CStaR algorithm (Steckoven et al., 2012), which finds a CPDAG of that + * data and then tries all orientations of the undirected edges about a variable in the + * CPDAG to estimate a minimum bound on the effect for a given edge. Some references include + * the following:

      * - *

      Stekhoven, D. J., Moraes, I., Sveinbjörnsson, G., Hennig, L., Maathuis, M. H., and Bühlmann, P. (2012). - * Causal stability ranking. Bioinformatics, 28(21), 2819-2823.

      + *

      Stekhoven, D. J., Moraes, I., Sveinbjörnsson, G., Hennig, L., Maathuis, M. H., and + * Bühlmann, P. (2012). Causal stability ranking. Bioinformatics, 28(21), 2819-2823.

      * - *

      Meinshausen, N., and Bühlmann, P. (2010). Stability selection. Journal of the Royal Statistical Society: - * Series B (Statistical Methodology), 72(4), 417-473.

      + *

      Meinshausen, N., and Bühlmann, P. (2010). Stability selection. Journal of the Royal + * Statistical Society: Series B (Statistical Methodology), 72(4), 417-473.

      * - *

      Colombo, D., and Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. - * The Journal of Machine Learning Research, 15(1), 3741-3782.

      + *

      Colombo, D., and Maathuis, M. H. (2014). Order-independent constraint-based causal + * structure learning. The Journal of Machine Learning Research, 15(1), 3741-3782.

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      * * @author josephramsey + * @see Ida */ public class Cstar { private boolean parallelized = false; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java index ab7d07aa12..28c2c0317e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fci.java @@ -57,6 +57,7 @@ *

      Zhang, J. (2008). On the completeness of orientation rules for causal discovery in the presence * of latent confounders and selection bias. Artificial Intelligence, 172(16-17), 1873-1896.

      * + * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      * @@ -66,6 +67,8 @@ * @author josephramsey * @see FciOrient * @see Pc + * @see Fas + * @see FciOrient * @see Knowledge */ public final class Fci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index 81aa01952d..8e71fcddf1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -35,19 +35,35 @@ import java.util.concurrent.RecursiveTask; /** - *

      Modifies FCI to do orientation of unshielded colliders (X*-*Y*-*Z with X and Z not adjacent) - * using the max-P rule (see the PC-Max algorithm). This reference is relevant:

      + *

      Modifies FCI to do orientation of unshielded colliders (X*-*Y*-*Z with X and Z + * not adjacent) using the max-P rule (see the PC-Max algorithm). This reference + * is relevant:

      * - *

      Raghu, V. K., Zhao, W., Pu, J., Leader, J. K., Wang, R., Herman, J., ... & Wilson, D. O. - * (2019). Feasibility of lung cancer prediction from low-dose CT scan and smoking factors using - * causal models. Thorax, 74(7), 643-649.

      + *

      Raghu, V. K., Zhao, W., Pu, J., Leader, J. K., Wang, R., Herman, J., ... & + * Wilson, D. O. (2019). Feasibility of lung cancer prediction from low-dose CT scan + * and smoking factors using causal models. Thorax, 74(7), 643-649.

      + * + *

      Max-P triple orientation is a method for orienting unshielded triples + * X*=-*Y*-*Z as one of the following: (a) Collider, X->Y<-Z, or (b) Noncollider, + * X-->Y-->Z, or X<-Y<-Z, or X<-Y->Z. One does this by conditioning on subsets of + * adj(X) or adj(Z). One first checks conditional independence of X and Z + * conditional on each of these subsets, and lists the p-values for each test. + * Then, one chooses the conditioning set out of all of these that maximizes + * the p-value. If this conditioning set contains Y, then the triple is judged + * to be a noncollider; otherwise, it is judged to be a collider.

      + * + *

      All unshielded triples in the graph given by FAS are judged as colliders + * or non-colliders and the colliders oriented. Then the final FCI orientation + * rules are applied, as in FCI.

      * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      * * @author josephramsey * @see Fci + * @see Fas * @see PcMax + * @see FciOrient * @see Knowledge */ public final class FciMax implements IGraphSearch { 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 4f01d45883..4cc3c49050 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 @@ -28,10 +28,25 @@ * the sparsest permutation algorithm. In Uncertainty in Artificial Intelligence * (pp. 1052-1062). PMLR.

      * - *

      GRaSP can use either a score or an independence test; you can provide + *

      GRaSP can use either a score or an independence test; you can provide * both, though if you do you need to use the paremeters to choose which one will * be used. The score options is more scalable and accurate, though the independence - * option is perhaps a little easier ot deal with theoretically

      + * option is perhaps a little easier ot deal with theoretically and are useful for + * generating unit test results.

      + * + *

      As shown the reference above, GRaSP generates results for the linear, Gaussian + * case for N = 1000 with precisions for adjacencies and arrowheads near 1 and + * recalls of about 0.85, when the linear, Gaussian BIC score is used with a penalty + * of 2. For N = 10,000 recalls also rise up to about 1, so it can be an extraordinarily + * accurate search for the linear, Gaussian case. But in principle, it can be used + * with any sort of data, so long as a BIC score is available for that data. So + * it can be used for the discrete case and for the mixed continuous/discrete case + * as well.

      + * + *

      The version of GRaSP described in the above reference is limited to about 100 + * varibles in execution time, after which it become impracticably slow. Recent + * optimizations allow it to scale further than that; hopefully these will be + * written up soon and made available.

      * *

      Knowledge can be used with this search. If tiered knowledge is used, then * the procedure is carried out for each tier separately, given the variable preceding 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 08ec717651..5a477b1023 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 @@ -41,6 +41,13 @@ *

      J.M. Ogarrio and P. Spirtes and J. Ramsey, "A Hybrid Causal Search Algorithm * for Latent Variable Models," JMLR 2016. Here, BOSS has been substituted for * FGES.

      + * + *

      For the first step, the GRaSP algorithm is used, with the same + * modifications as in the GFCI algorithm.

      + * + *

      For the second step, the FCI final orientation algorithm is used, with the same + * modifications as in the GFCI algorithm.

      + * *

      For GRaSP only a score is needed, but there are steps in GFCI that require * a test, so for this method, both a test and a score need to be given.

      * @@ -51,9 +58,7 @@ * @author bryanandrews * @see Grasp * @see GFci - * @see BFci - * @see SpFci - * @see Fges + * @see FciOrient * @see Knowledge */ public final class GraspFci implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java index 099962da3e..3ad5a88091 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrink.java @@ -28,16 +28,36 @@ import java.util.List; /** - *

      Implements the Grow-Shrink algorithm of Margaritis and Thrun, a simple yet correct - * and useful Markov blanket search.

      + *

      Implements the Grow-Shrink algorithm of Margaritis and Thrun, a simple yet + * correct and useful Markov blanket search.

      * - *

      Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local neighborhoods. - * Advances in neural information processing systems, 12.

      + *

      Margaritis, D., & Thrun, S. (1999). Bayesian network induction via local + * neighborhoods. Advances in neural information processing systems, 12.

      + * + *

      Grow-Shrink learns the Markov blanket of a node, given a conditional independence + * test over a list of possible nodes. The Markov blanket is a set of nodes (or, in this + * case a list of distinct nodes), conditional on which every other node in the set is + * independent of X. In this case, a minimal Markov blanket is learned, which is to say, + * a Mavkov boundary of X.

      + * + *

      Graphically, in a DAG, the Markov blanket of X is the set of parents, children, and + * parents of children of X; GrowShrink will, for a faithful test, learn this set for X. + * However, a graph over the nodes together with X is not learned; other algorithms are + * available to do that (see, e.g., FgesMb, PcMb).

      + * + *

      We include GrowShrink in our algorithm suite mainly because it is a CMU algorithm + * (see the above reference). Markov blanket search has been explored in some detail in + * the literature and several algorithms are available. See for instance the BNLEARN + * package in R:

      + * + *

      https://www.bnlearn.com/

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      * * @author josephramsey + * @see FgesMb + * @see PcMb */ public class GrowShrink implements IMbSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index 785de18481..0f2d1445bb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -19,8 +19,7 @@ import static org.apache.commons.math3.util.FastMath.min; /** - *

      Implements the IDA algorithm, as given in Maathuis et al. (2009) - * The reference is here:

      + *

      Implements the IDA algorithm. The reference is here:

      * *

      Maathuis, Marloes H., Markus Kalisch, and Peter Bühlmann. * "Estimating high-dimensional intervention effects from observational data." diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 142ec78f78..38ba8d83dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -46,7 +46,12 @@ * linear, non-Gaussian Orientation with a Fixed graph Structure (LOFS). The options * for different types of scores are given in the enum Lofs.Score. The options for rules * to use to do the orientations are given in the enum, Lofs.Rule. Most of these are - * taken from the literature and ca be googled.

      + * taken from the literature and can be googled, though we should certainly give + * this reference for several of them, to which we are indebted:

      + * + *

      Hyvärinen, A., & Smith, S. M. (2013). Pairwise likelihood ratios for estimation + * of non-Gaussian structural equation models. The Journal of Machine Learning Research, + * 14(1), 111-152.

      * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java index b92bfeda8e..708e5bfc3e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Mimbuild.java @@ -42,7 +42,7 @@ import java.util.List; /** - *

      Provides an implemntation of Mimbuild, an algorithm that takes a clustering + *

      Provides an implementation of Mimbuild, an algorithm that takes a clustering * of variables, each of which is explained by a single latent, then forms the * implied covariance matrix over the latent variables, then runs a CPDAG search * to in the structure over the latent themselves.

      @@ -53,19 +53,20 @@ * (default 2).

      * *

      One may wish to obtain the implied correlation matrix over the latents and - * run one's own choice of CPDDAG algroithm on it with one's on test or score; + * run one's own choice of CPDDAG algorithm on it with one's own test or score; * a method is available to return this covariance matrix.

      * *

      A suitable clustering for Mimbuild may be obtained using the BPC or FOFC * algorithm (see).

      * - *

      This class is configured to respect knowledge of forbidden and required + *

      This class is configured to respect the knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      * * @author josephramsey * @see Bpc * @see Fofc * @see #getLatentsCov() + * @see Grasp * @see Knowledge */ public class Mimbuild { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java index 1172ab6349..1e8d1d9b56 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MimbuildTrek.java @@ -49,6 +49,7 @@ * * @author adambrodie * @see Knowledge + * @see Mimbuild */ public class MimbuildTrek { 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 ba6f3fd8d6..83364d90be 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 @@ -43,7 +43,7 @@ * independence testing as an oracle to first of all remove extraneous edges * from a complete graph, then to orient the unshielded colliders in the graph, * and finally to make any additional orientations that are capable of avoiding - * additional unshielded colliders in the graph. An earlier version of this + * additional unshielded colliders in the graph. An version of this * algorithm was proposed earlier than this, but the standard reference for * the algorithm is in Chapter 6 of the following book:

      * 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 06932c20dc..29623c42d3 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 @@ -43,13 +43,27 @@ *

      Ramsey, J. (2016). Improving accuracy and scalability of the pc algorithm * by maximizing p-value. arXiv preprint arXiv:1610.00378.

      * + *

      Max-P triple orientation is a method for orienting unshielded triples + * X*=-*Y*-*Z as one of the following: (a) Collider, X->Y<-Z, or (b) Noncollider, + * X-->Y-->Z, or X<-Y<-Z, or X<-Y->Z. One does this by conditioning on subsets of + * adj(X) or adj(Z). One first checks conditional independence of X and Z + * conditional on each of these subsets, and lists the p-values for each test. + * Then, one chooses the conditioning set out of all of these that maximizes + * the p-value. If this conditioning set contains Y, then the triple is judged + * to be a noncollider; otherwise, it is judged to be a collider.

      + * + *

      All unshielded triples in the graph supplied by FAS are oriented using + * this procedure, and then the Meek orientation rules are applied to generate + * the final CPDAG.

      + * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      * * @author josephramsey. - * @see PcMax * @see Pc - * @see Fasd + * @see Fas + * @see edu.cmu.tetrad.search.utils.MaxP + * @see edu.cmu.tetrad.search.utils.MeekRules * @see Knowledge */ public final class PcMax implements IGraphSearch { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java index 3fd0f41faf..ca69f7e884 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pcd.java @@ -37,9 +37,9 @@ import java.util.Set; /** - * Modifies the PC algorithm to handle the deterministic case. Edges removals + *

      Modifies the PC algorithm to handle the deterministic case. Edges removals * or orientations based on conditional independence test involving deterministic - * relationships are not done. + * relationships are not done.

      * *

      This class is configured to respect knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index cc6e523c7e..034953d944 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java @@ -13,14 +13,15 @@ /** *

      Implements common elements of a permutation search. The specific parts * for each permutation search are implemented as a SuborderSearch.

      - *

      This class specificaly handls an optimization for tiered knowledge, whereby - * tiers in the knowledge can be searched one at a time in order form lowest - * to highest, taking all variables from previous tiesrs as a fixed previs - * for an later tier. This allos these permutation searches to search over - * many more varaibles than otherwise, so long as tiered knowledge is available + * + *

      This class specifically handles an optimization for tiered knowledge, whereby + * tiers in the knowledge can be searched one at a time in order from the lowest + * to highest, taking all variables from previous tiers as a fixed previs + * for a later tier. This allows these permutation searches to search over + * many more variables than otherwise, so long as tiered knowledge is available * to organize the search.

      * - *

      This class is configured to respect knowledge of forbidden and required + *

      This class is configured to respect the knowledge of forbidden and required * edges, including knowledge of temporal tiers.

      * * @author bryanandrews diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java index 38e4abe205..503495e3a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Sp.java @@ -51,6 +51,7 @@ public class Sp implements SuborderSearch { /** * This algorithm will work with an arbitrary score. + * * @param score The Score to use. */ public Sp(Score score) { @@ -173,82 +174,84 @@ public Score getScore() { return score; } -} -class SwapIterator implements Iterator { - private int[] next; - private final int n; - private final int[] perm; - private final int[] dirs; - - public SwapIterator(int size) { - this.n = size; - if (this.n <= 0) { - this.perm = null; - this.dirs = null; - } else { - this.perm = new int[n]; - this.dirs = new int[n]; - for (int i = 0; i < n; i++) { - this.perm[i] = i; - this.dirs[i] = -1; + static class SwapIterator implements Iterator { + private int[] next; + private final int n; + private final int[] perm; + private final int[] dirs; + + public SwapIterator(int size) { + this.n = size; + if (this.n <= 0) { + this.perm = null; + this.dirs = null; + } else { + this.perm = new int[n]; + this.dirs = new int[n]; + for (int i = 0; i < n; i++) { + this.perm[i] = i; + this.dirs[i] = -1; + } + this.dirs[0] = 0; } - this.dirs[0] = 0; } - } - @Override - public int[] next() { - int[] next = makeNext(); - this.next = null; - return next; - } + @Override + public int[] next() { + int[] next = makeNext(); + this.next = null; + return next; + } - @Override - public boolean hasNext() { - return makeNext() != null; - } + @Override + public boolean hasNext() { + return makeNext() != null; + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } - private int[] makeNext() { - if (this.next != null) return this.next; - if ((this.dirs == null) || (this.perm == null)) return null; + private int[] makeNext() { + if (this.next != null) return this.next; + if ((this.dirs == null) || (this.perm == null)) return null; - int i = -1; - int x = -1; - for (int j = 0; j < n; j++) - if ((this.dirs[j] != 0) && (this.perm[j] > x)) { - x = this.perm[j]; - i = j; - } + int i = -1; + int x = -1; + for (int j = 0; j < n; j++) + if ((this.dirs[j] != 0) && (this.perm[j] > x)) { + x = this.perm[j]; + i = j; + } - if (i == -1) return null; + if (i == -1) return null; - int k = i + this.dirs[i]; - this.next = new int[] {i, k}; + int k = i + this.dirs[i]; + this.next = new int[]{i, k}; - swap(i, k, this.dirs); - swap(i, k, this.perm); + swap(i, k, this.dirs); + swap(i, k, this.perm); - if ((k == 0) || (k == n - 1) || (this.perm[k + this.dirs[k]] > x)) - this.dirs[k] = 0; + if ((k == 0) || (k == n - 1) || (this.perm[k + this.dirs[k]] > x)) + this.dirs[k] = 0; - for (int j = 0; j < n; j++) - if (this.perm[j] > x) - this.dirs[j] = (j < k) ? +1 : -1; + for (int j = 0; j < n; j++) + if (this.perm[j] > x) + this.dirs[j] = (j < k) ? +1 : -1; - return this.next; - } + return this.next; + } - private static void swap(int i, int j, int[] arr) { - int x = arr[i]; - arr[i] = arr[j]; - arr[j] = x; + private static void swap(int i, int j, int[] arr) { + int x = arr[i]; + arr[i] = arr[j]; + arr[j] = x; + } } } + + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 9904acc251..1b440eeaa6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -66,11 +66,9 @@ * @author bryan andrews * @see Grasp * @see GFci - * @see BFci - * @see GraspFci - * @see Fges * @see Sp * @see Knowledge + * @see FciOrient */ public final class SpFci implements IGraphSearch { From 7d85f1a1f4b138d828ac61a7765bb38e246e8414 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 15 May 2023 20:17:30 -0400 Subject: [PATCH 458/464] Documentation. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java | 2 +- .../src/main/java/edu/cmu/tetrad/search/package-info.java | 5 +++++ .../java/edu/cmu/tetrad/search/score/package-info.java | 6 ++++++ .../java/edu/cmu/tetrad/search/test/package-info.java | 6 ++++++ .../java/edu/cmu/tetrad/search/utils/package-info.java | 5 +++++ .../cmu/tetrad/search/work_in_progress/package-info.java | 8 ++++++++ 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/package-info.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/package-info.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/package-info.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/package-info.java create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/package-info.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 5ed421e62f..0a3fd7c651 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -35,7 +35,7 @@ /** - *

      Adjusts FCI (see) to use conservative orientation as in CPC (see). Because the + *

      Adjusts FCI (see) to use conservative orientation as in CPC (see). Because the * collider orientatation is conservative, there may be ambiguous triples; these * may be retrieved using that accessor method.

      * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/package-info.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/package-info.java new file mode 100644 index 0000000000..73b93909b9 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/package-info.java @@ -0,0 +1,5 @@ + +/** + * Contains classes for searching for (mostly structural) causal models given data. + */ +package edu.cmu.tetrad.search; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/package-info.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/package-info.java new file mode 100644 index 0000000000..9e38065bad --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/package-info.java @@ -0,0 +1,6 @@ + +/** + * Contains classes for various various sorts of scores for running score-based + * algorithms. + */ +package edu.cmu.tetrad.search.score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/package-info.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/package-info.java new file mode 100644 index 0000000000..b49dbce299 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/package-info.java @@ -0,0 +1,6 @@ + +/** + * Contains classes for running conditional independence tests for various + * sorts of data. + */ +package edu.cmu.tetrad.search.test; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/package-info.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/package-info.java new file mode 100644 index 0000000000..98afaa96c9 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/package-info.java @@ -0,0 +1,5 @@ + +/** + * Contains some utility classes for search algorithms. + */ +package edu.cmu.tetrad.search.utils; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/package-info.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/package-info.java new file mode 100644 index 0000000000..3da7c915f8 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/package-info.java @@ -0,0 +1,8 @@ + +/** + * Contains some classes that aren't ready for prime time. Please use these + * classes at your own risk, and don't expect them to work 100%. They are + * provided for your convenience, but are not supported, though if you + * find a bug, please report it. + */ +package edu.cmu.tetrad.search.work_in_progress; From 6977baefbdcecea74dfde07c323d40104b312008 Mon Sep 17 00:00:00 2001 From: Yasuhiro Shimodaira <89838961+yasu-sh@users.noreply.github.com> Date: Tue, 16 May 2023 10:26:52 +0900 Subject: [PATCH 459/464] File selection dialog returns null when press cancel and no need to execute data transactions. The message is displayed as LoadGraph performs. --- .../edu/cmu/tetradapp/editor/SaveGraph.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java index 76803efbc8..019b8e8b7e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java @@ -82,16 +82,34 @@ public void actionPerformed(ActionEvent e) { if (this.type == Type.xml) { File file = EditorUtils.getSaveFile("graph", "xml", parent, false, this.title); + + if (file == null) { + System.out.println("File was null."); + return; + } + PrintWriter out = GraphPersistence.saveGraph(graph, file, true); Preferences.userRoot().put("fileSaveLocation", file.getParent()); out.close(); } else if (this.type == Type.text) { File file = EditorUtils.getSaveFile("graph", "txt", parent, false, this.title); + + if (file == null) { + System.out.println("File was null."); + return; + } + PrintWriter out = GraphPersistence.saveGraph(graph, file, false); Preferences.userRoot().put("fileSaveLocation", file.getParent()); out.close(); } else if (this.type == Type.r) { File file = EditorUtils.getSaveFile("graph", "r.txt", parent, false, this.title); + + if (file == null) { + System.out.println("File was null."); + return; + } + try { String text = GraphPersistence.graphRMatrixTxt(graph); @@ -109,6 +127,12 @@ public void actionPerformed(ActionEvent e) { } } else if (this.type == Type.json) { File file = EditorUtils.getSaveFile("graph", "json", parent, false, this.title); + + if (file == null) { + System.out.println("File was null."); + return; + } + try { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String text = gson.toJson(graph); @@ -127,6 +151,12 @@ public void actionPerformed(ActionEvent e) { } } else if (this.type == Type.dot) { File file = EditorUtils.getSaveFile("graph", "dot", parent, false, this.title); + + if (file == null) { + System.out.println("File was null."); + return; + } + try { String text = GraphPersistence.graphToDot(graph); @@ -144,6 +174,12 @@ public void actionPerformed(ActionEvent e) { } } else if (this.type == Type.pcalg) { File file = EditorUtils.getSaveFile("graph", "pcalg.csv", parent, false, this.title); + + if (file == null) { + System.out.println("File was null."); + return; + } + try { String text = GraphPersistence.graphToPcalg(graph); @@ -161,6 +197,12 @@ public void actionPerformed(ActionEvent e) { } } else if (this.type == Type.lavaan) { File file = EditorUtils.getSaveFile("graph", "lavaan.txt", parent, false, this.title); + + if (file == null) { + System.out.println("File was null."); + return; + } + try { String text = GraphPersistence.graphToLavaan(graph); From 5b87cd8dec95aa55a18380d54a844fad4262f242 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 18 May 2023 11:09:52 -0400 Subject: [PATCH 460/464] Bryan's recs on the docs. --- .../java/edu/cmu/tetrad/search/IcaLingD.java | 53 ++++++++++++------- .../java/edu/cmu/tetrad/search/IcaLingam.java | 14 ++--- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java index 9a4bff983b..cbd158407c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java @@ -52,28 +52,43 @@ * cyclic causal models by independent components analysis. arXiv preprint * arXiv:1206.3273.

      * - *

      We use the N Rooks algorithm to find alternative strongest diagonals for - * permutations of the W matrix. The parameter that N Rooks requires is a - * spine threshold, which is the lowest number in absolute value that a W matrix - * entry can take to be part of a strongest diagonal; the implied - * permutation is the permutation that permutes rows so that this combination - * lies along the diagonal of W, which is then scaled, and the separate satisfactory - * B Hat matrices reported.

      + *

      ICA-LING-D is a method for estimating a possible cyclic linear models graph + * from a dataset. It is based on the assumption that the data are generated by a + * linear model with non-Gaussian noise. The method is based on the following assumptions:

      + * + *
        + *
      1. The data are generated by a linear model with non-Gaussian noise.
      2. + *
      3. The noise is independent across variables.
      4. + *
      5. The noises for all but possibly one variable are non-Gaussian.
      6. + *
      7. There is no unobserved confounding.
      8. + *
      * - *

      The B Hat matrices are further thresholded using a coefficient threshold; - * values in B hat less than this minimum in absolute value are sent to zero - * and will not correspond to edges in the output model.

      + *

      lower bound of the absolute value of the coefficients in the W matrix.

      + + *

      Under these assumptions, the method estimates a matrix W such that WX = e, where + * X is the data matrix, e is a matrix of noise, and W is a matrix of coefficients. + * The matrix W is then used to estimate a matrix B Hat, where B Hat is the matrix + * of coefficients in the linear model that generated the data. The graph is then + * estimated by finding edges in B Hat.

      * + * + *

      We use the N Rooks algorithm to find alternative diagonals for + * permutations of the W matrix. The parameter that N Rooks requires is a + * threshold for entries in W to be included in possible diagonals, which is + * the lowest number in absolute value that a W matrix entry can take to be part + * of a diagonal; the implied permutation is the permutation that permutes rows + * so that this combination lies along the diagonal of W, which is then scaled, + * and the separate satisfactory B Hat matrices reported.

      * - *

      There are also a number of methods that are used in the paper, but are not - * included in this class. These are included in the class Lingam.

      + *

      The W Hat matrices are further thresholded, setting values below + * this threshold in absolute value to zero.

      * - *

      ICA-LiNG-D is a method for estimating a directed acyclic graph (DAG) from a - * dataset. The graph is estimated by finding a permutation of the columns of the - * dataset so that the resulting matrix has a strong diagonal. This permutation - * is then used to estimate a DAG. The method is an extension of LiNGAM, which - * estimates a DAG from a dataset using independent components analysis (ICA). - * LiNG-D is particularly useful when the underlying data may have multiple - * consistent cyclic models.

      + *

      ICA-LiNG-D, which takes this W as an imput, is a method for estimating + * a directed graph (DG) from a dataset. The graph is estimated by finding a + * permutation of the columns of the dataset so that the resulting matrix has + * a strong diagonal. This permutation is then used to estimate a DG. The method + * is an relaxation of LiNGAM, which estimates a DAG from a dataset using + * independent components analysis (ICA). LiNG-D is particularly useful when the + * underlying data may have multiple consistent cyclic models.

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java index 98ab9eab64..4994074523 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java @@ -38,11 +38,11 @@ * A linear non-Gaussian acyclic model for causal discovery. Journal of Machine Learning * Research, 7(10).

      * - *

      The focus for this implementation was making to make a version of ICA-LiNGAM that + *

      The focus for this implementation was to make a version of ICA-LiNGAM that * would be compatible with LiNG-D (see). There are two parameters, one to choose * whether an acyclic result will be guaranteed, and another to set a threshold on - * the absolute value of the coefficients in the B Hat matrix. The latter is used - * to find edges in the final graph.

      + * the lower bound of the absolute value of the coefficients in the B Hat matrix. + * The latter is used to find edges in the final graph.

      * *

      ICA-LiNGAM is a method for estimating a causal graph from a dataset. It is based on * the assumption that the data are generated by a linear model with non-Gaussian @@ -63,9 +63,8 @@ * *

      There is an option to guarantee the acyclicity of the output, which will set * small coefficients to zero until an acyclic model is achieved. If this option - * is not selected, coefficients above the threshold will be sorted to high and - * 5% of the lowest coefficients in B Hat set to zero, which allows for certain - * cyclic structures to be recovered.

      + * is not selected, coefficients below the selected threshold will be set to + * zero, which allows for certain cyclic structures to be recovered.

      * *

      There are two methods for estimating W. The first is the default method, * which is to use the ICA-LiNG-D algorithm to estimate W. The second is to provide @@ -79,7 +78,8 @@ * *

        *
      1. Estimate W using LiNG-D or using a user-provided W matrix.
      2. - *
      3. Estimate B Hat from W.
      4. + *
      5. Find the strongest diagonal for W using a linear assignment process.
      6. + *
      7. Permute the matrix for this strongest diagonal and scele the matrix to produce B Hat
      8. *
      9. Set a threshold on the absolute value of the coefficients in B Hat.
      10. *
      11. Find edges in B Hat.
      12. *
      13. Set small coefficients to zero until an acyclic model is achieved, if From 18874cf373784b6375a08ab6d6c6f64964f9c8f5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 18 May 2023 11:11:16 -0400 Subject: [PATCH 461/464] Bryan's recs on the docs. --- .../src/main/java/edu/cmu/tetrad/search/IcaLingam.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java index 4994074523..7632127d44 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java @@ -80,10 +80,9 @@ *
      14. Estimate W using LiNG-D or using a user-provided W matrix.
      15. *
      16. Find the strongest diagonal for W using a linear assignment process.
      17. *
      18. Permute the matrix for this strongest diagonal and scele the matrix to produce B Hat
      19. - *
      20. Set a threshold on the absolute value of the coefficients in B Hat.
      21. - *
      22. Find edges in B Hat.
      23. - *
      24. Set small coefficients to zero until an acyclic model is achieved, if - * acyclicity is guaranteed.
      25. + *
      26. Set entries in BHat less than the treshold in absolute value to zero.
      27. + *
      28. If acyclicity is guaranteed, set small coefficients to zero until an acyclic + * model is achieved.
      29. *
      * *

      We are using the Hungarian Algorithm to find the best diagonal for W to solve From 711542560f2c4dcfd9bb7fe41ae663952643140d Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 18 May 2023 13:49:08 -0400 Subject: [PATCH 462/464] Bryan's recs on the docs. --- .../main/java/edu/cmu/tetrad/search/IcaLingD.java | 14 ++++++-------- .../main/java/edu/cmu/tetrad/search/IcaLingam.java | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java index cbd158407c..723c41d3a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java @@ -73,14 +73,12 @@ * *

      We use the N Rooks algorithm to find alternative diagonals for * permutations of the W matrix. The parameter that N Rooks requires is a - * threshold for entries in W to be included in possible diagonals, which is - * the lowest number in absolute value that a W matrix entry can take to be part - * of a diagonal; the implied permutation is the permutation that permutes rows - * so that this combination lies along the diagonal of W, which is then scaled, - * and the separate satisfactory B Hat matrices reported.

      - * - *

      The W Hat matrices are further thresholded, setting values below - * this threshold in absolute value to zero.

      + * threshold for entries in W to be included in possible diagonals, which + * is the lowest number in absolute value that a W matrix entry can take + * to be part of a diagonal; the implied permutations is the permutations + * that permutes rows so that these combination lies along the their + * respective diagonals in W, which are then scaled, and the separate + * satisfactory B Hat matrices reported.

      * *

      ICA-LiNG-D, which takes this W as an imput, is a method for estimating * a directed graph (DG) from a dataset. The graph is estimated by finding a diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java index 7632127d44..6f0208d4ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingam.java @@ -85,8 +85,8 @@ * model is achieved. * * - *

      We are using the Hungarian Algorithm to find the best diagonal for W to solve - * the linear assignment problem.

      + *

      We are using the Hungarian Algorithm to solve the linear assignment problem + * for finding the best diagonal for W.

      * *

      This class is not configured to respect knowledge of forbidden and required * edges.

      From f4ccd0c1ca9af725443f1b74439576b98fd44fa2 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 18 May 2023 14:55:16 -0400 Subject: [PATCH 463/464] Bryan's recs on the docs. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java index 723c41d3a3..c930f11b09 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java @@ -69,7 +69,7 @@ * X is the data matrix, e is a matrix of noise, and W is a matrix of coefficients. * The matrix W is then used to estimate a matrix B Hat, where B Hat is the matrix * of coefficients in the linear model that generated the data. The graph is then - * estimated by finding edges in B Hat.

      * + * estimated by finding edges in B Hat.

      * *

      We use the N Rooks algorithm to find alternative diagonals for * permutations of the W matrix. The parameter that N Rooks requires is a From ea019eb892373111164fb300ce9503d0cf98ad62 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 18 May 2023 17:24:31 -0400 Subject: [PATCH 464/464] Updated version to 7.4.0. --- data-reader/pom.xml | 2 +- pom.xml | 2 +- tetrad-gui/pom.xml | 2 +- tetrad-lib/pom.xml | 2 +- .../main/java/edu/cmu/tetrad/search/Boss.java | 76 +++++++++++-------- 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/data-reader/pom.xml b/data-reader/pom.xml index a103056b6b..76e0bb7096 100644 --- a/data-reader/pom.xml +++ b/data-reader/pom.xml @@ -5,7 +5,7 @@ io.github.cmu-phil tetrad - 7.3.4 + 7.4.0 data-reader diff --git a/pom.xml b/pom.xml index 15eb76fa46..7c8d2d75fd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.cmu-phil tetrad - 7.3.4 + 7.4.0 pom Tetrad Project diff --git a/tetrad-gui/pom.xml b/tetrad-gui/pom.xml index 5aa47c8e9f..5166a3e152 100644 --- a/tetrad-gui/pom.xml +++ b/tetrad-gui/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.3.4 + 7.4.0 tetrad-gui diff --git a/tetrad-lib/pom.xml b/tetrad-lib/pom.xml index 33165e33b0..1662a972bd 100644 --- a/tetrad-lib/pom.xml +++ b/tetrad-lib/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.3.4 + 7.4.0 tetrad-lib 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 541fe764f3..00eb2aaba6 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 @@ -12,51 +12,67 @@ import static edu.cmu.tetrad.util.RandomUtil.shuffle; /** - *

      Implements an algorithm called BOSS (Best Order Score Search). This - * follows up on work by Raskutti and Uhler on the SP (Sparsest Permutation) - * algorithm and work by Lam, Andrews, and Ramsey on the GRaSP algorithm is - * currently under development.

      + *

      Implements Best Order Score Search (BOSS). The following references + * are relevant:

      * - *

      This algorithm is based on the intuition that the permutation search is - * more effective when the variables are ordered in a way that is close to the - * true causal ordering. The permutation search is a greedy algorithm that - * starts with an arbitrary ordering and then tries to improve the ordering - * by swapping adjacent variables. The permutation search is not guaranteed - * to find the optimal ordering, but it is guaranteed to find an ordering that - * implies a DAG. The permutation search is also very fast, so it can be - * called many times in order to find the best ordering. This algorithm - * intercalates calls to the permutation search with calls to BES, which - * finds a DAG for a given ordering. The algorithm then keeps track of the - * best DAG found so far and the ordering that implies that DAG.

      + *

      Lam, W. Y., Andrews, B., & Ramsey, J. (2022, August). Greedy relaxations + * of the sparsest permutation algorithm. In Uncertainty in Artificial Intelligence + * (pp. 1052-1062). PMLR.

      + * + *

      Teyssier, M., & Koller, D. (2012). Ordering-based search: A simple and effective + * algorithm for learning Bayesian networks. arXiv preprint arXiv:1207.1429.

      + * + *

      Solus, L., Wang, Y., & Uhler, C. (2021). Consistency guarantees for greedy + * permutation-based causal inference algorithms. Biometrika, 108(4), 795-814.

      + * + *

      The BOSS algorithm is based on the idea that implied DAGs for permutations + * are most optimal in their BIC scores when the variables in the permutations + * are ordered causally--that is, so that that causes in the models come + * before effects in a topological order.

      + * + *

      This algorithm is implemented as a "plugin-in" algorithm to a + * PermutationSearch object (see), which deals with certain details of knowledge + * handling that are common to different permutation searches.

      + * + *

      BOSS, like GRaSP (see), is characterized by high adjacency and + * oreintation precision (especially) and recall for moderate sample + * sizes. BOSS scales up currently further than GRaSP to larger variable + * sets and denser graphs and so is currently preferable from a practical + * standpoint, though performance is essentially identical.

      * *

      The algorithm works as follows:

      * *
        *
      1. Start with an arbitrary ordering.
      2. *
      3. Run the permutation search to find a better ordering.
      4. - *
      5. Run BES on the new ordering to find a DAG.
      6. - *
      7. Repeat steps 2 and 3 until the model score can no longer be improved..
      8. - *
      9. Return the CPDAG of the best DAG found.
      10. + *
      11. Project this ordering to a CPDAG.
      12. + *
      13. Optionally, Run BES this CPDAG. + *
      14. Return this CPDAG.
      15. *
      * - * The BES step is needed for correctness, though with large models is has very - * little effect on the output, since nearly all edges are alreayy oriented, so - * a parameter is included to turn that step off. + * The optional BES step is needed for correctness, though with large + * models is has very little effect on the output, since nearly all edges + * are already oriented, so a parameter is included to turn that step off. * - *

      The permutation search step uses an repeated insert operation.

      + *

      Knowledge can be used with this search. If tiered knowledge is used, + * then the procedure is carried out for each tier separately, given the v + * ariables preceding that tier, which allows the Boss algorithm to address + * tiered (e.g., time series) problems with larger numbers of variables. + * However, knowledge of required and forbidden edges is correctly implemented + * for arbitrary such knowledge.

      * - *

      Knowledge can be used with this search. If tiered knowledge is used, then the procedure - * is carried out for each tier separately, given the variable preceding that tier, which - * allows the Boss algorithm to address tiered (e.g., time series) problems with larger numbers of - * variables.

      + *

      A paremeter is included to restart the search a certain number of time. + * The idea is that the goal is to optimize a BIC score, so if several runs + * are done of the algorithm for the same data, the model with the highest + * BIC score should be returned and the others ignored.

      * - *

      This class is meant to be used in the context of the PermutationSearch class (see). + *

      This class is meant to be used in the context of the PermutationSearch + * class (see). * * @author bryanandrews * @author josephramsey - * @see Sp - * @see Grasp * @see PermutationSearch + * @see Grasp * @see Knowledge */ public class Boss implements SuborderSearch { @@ -69,7 +85,7 @@ public class Boss implements SuborderSearch { private int numStarts = 1; /** - * This algorithm will work with an arbitrary score. + * This algorithm will work with an arbitrary BIC score. * * @param score The Score to use. */