From a16f0c951a0a08e7579d305819ccd6d2c199cfea Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 21 Mar 2023 17:42:48 -0400 Subject: [PATCH 01/58] Updating to 7.3.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7eb3e0902..1228d325ce 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ All of our code is public and we welcome suggestions, especially suggestions tha ## Tetrad GUI Application To download the current jar you can use to launch the Tetrad GUI, -click [here](https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.2.2/tetrad-gui-7.2.2-launch.jar). +click [here](https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.3.0/tetrad-gui-7.3.0-launch.jar). Please delete any old ones you're not using. The application will work on all major platforms once a recent version of the Java JRE/JCK is installed, certainly * From 4bf609c6b9a19471dac97940518d74690f3e7fcb Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 21 Mar 2023 18:09:44 -0400 Subject: [PATCH 02/58] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1228d325ce..b81870782e 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ 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/) + ## Install All artifacts are published in From 1cc686a3656a8eb5502f2cfcd5570eac9f6a89d1 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 21 Mar 2023 18:10:07 -0400 Subject: [PATCH 03/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b81870782e..6bfe6b7e21 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,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.0/lib/) ## Install From 20dfa23ec4ae6fd8d41bd237992d653b3dfa31e8 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 21 Mar 2023 18:10:26 -0400 Subject: [PATCH 04/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bfe6b7e21..27ca8a7bed 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,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.0/lib/). ## Install From df6c1b0956256fc3c6a21bd404a09c8652f9da31 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 21 Mar 2023 20:43:45 -0400 Subject: [PATCH 05/58] Update README.md Made the download link bigger. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 27ca8a7bed..928910dc10 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ All of our code is public and we welcome suggestions, especially suggestions tha ## Tetrad GUI Application -To download the current jar you can use to launch the Tetrad GUI, -click [here](https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.3.0/tetrad-gui-7.3.0-launch.jar). -Please delete any old ones you're not using. +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.0/tetrad-gui-7.3.0-launch.jar. The application will work on all major platforms once a recent version of the Java JRE/JCK is installed, certainly * *_greater than version 1.8 (version 8)_**. We find that the most From 9fdee7fa9636570dabf6654824814184b396643b Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Tue, 21 Mar 2023 21:35:29 -0500 Subject: [PATCH 06/58] Update Boss.java update boss --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java index d079d59a76..2a0b5811ef 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 @@ -93,7 +93,7 @@ public void searchSuborder(List prefix, List suborder, Map Z = new ArrayList<>(prefix); Z.addAll(suborder); - Graph graph = PermutationSearch.getGraph(Z, parents, true); + Graph graph = PermutationSearch.getGraph(Z, parents, this.knowledge, true); this.bes.bes(graph, Z); graph.paths().makeValidOrder(suborder); s1 = update(prefix, suborder); From 1aa49685078badb061f5b3fd4f442fce825ffa99 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 21 Mar 2023 23:58:56 -0400 Subject: [PATCH 07/58] Added option to SEM Estimator editor to not display means. --- .../tetradapp/editor/SemEstimatorEditor.java | 193 ++++++++++-------- 1 file changed, 113 insertions(+), 80 deletions(-) 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 95e13893ec..9d23b00e5d 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 @@ -396,13 +396,14 @@ private class OneEditor extends JPanel implements LayoutEditable { /** * True iff covariance parameters are edited as correlations. */ - private boolean editIntercepts; + private int editIntercepts = 1; private JTabbedPane tabbedPane; private String graphicalEditorTitle = "Graphical Editor"; private String tabularEditorTitle = "Tabular Editor"; private boolean editable = true; private JCheckBoxMenuItem meansItem; private JCheckBoxMenuItem interceptsItem; + private JCheckBoxMenuItem noMeansOrIntercepts; private JMenuItem errorTerms; public OneEditor(SemEstimatorWrapper wrapper, String graphicalEditorTitle, String tabularEditorTitle, @@ -515,21 +516,29 @@ private void displaySemIm(String graphicalEditorTitle, String tabularEditorTitle this.meansItem = new JCheckBoxMenuItem("Show means"); this.interceptsItem = new JCheckBoxMenuItem("Show intercepts"); + this.noMeansOrIntercepts = new JCheckBoxMenuItem("Don't show means or intercepts"); ButtonGroup meansGroup = new ButtonGroup(); meansGroup.add(this.meansItem); meansGroup.add(this.interceptsItem); + meansGroup.add(this.noMeansOrIntercepts); this.meansItem.setSelected(true); this.meansItem.addActionListener((e) -> { if (this.meansItem.isSelected()) { - setEditIntercepts(false); + setEditIntercepts(1); } }); this.interceptsItem.addActionListener((e) -> { if (this.interceptsItem.isSelected()) { - setEditIntercepts(true); + setEditIntercepts(2); + } + }); + + this.noMeansOrIntercepts.addActionListener((e) -> { + if (this.noMeansOrIntercepts.isSelected()) { + setEditIntercepts(3); } }); @@ -543,6 +552,7 @@ private void displaySemIm(String graphicalEditorTitle, String tabularEditorTitle if (!SemEstimatorEditor.this.wrapper.getEstimatedSemIm().isCyclic()) { params.add(this.meansItem); params.add(this.interceptsItem); + params.add(this.noMeansOrIntercepts); } menuBar.add(params); @@ -710,17 +720,28 @@ private void setEditCovariancesAsCorrelations( tabularEditor().getTableModel().fireTableDataChanged(); } - public boolean isEditIntercepts() { + public int isEditIntercepts() { return this.editIntercepts; } - private void setEditIntercepts(boolean editIntercepts) { + private void setEditIntercepts(int editIntercepts) { this.editIntercepts = editIntercepts; graphicalEditor().resetLabels(); tabularEditor().getTableModel().fireTableDataChanged(); - this.meansItem.setSelected(!editIntercepts); - this.interceptsItem.setSelected(editIntercepts); + if (this.editIntercepts == 1) { + this.meansItem.setSelected(true); + this.interceptsItem.setSelected(false); + this.noMeansOrIntercepts.setSelected(false); + } else if (this.editIntercepts == 2) { + this.meansItem.setSelected(false); + this.interceptsItem.setSelected(true); + this.noMeansOrIntercepts.setSelected(false); + } else { + this.meansItem.setSelected(false); + this.interceptsItem.setSelected(false); + this.noMeansOrIntercepts.setSelected(true); + } } private String getGraphicalEditorTitle() { @@ -1044,16 +1065,19 @@ public Object getValueAt(int row, int column) { case 1: return nodes.get(index); case 2: - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { return "Intercept"; - } else { + } else if (this.editor.isEditIntercepts() == 1) { return "Mean"; + } else { + return "Don't display means or intercepts"; } case 3: - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { double intercept = semIm().getIntercept(node); return asString(intercept); - } else { + } + if (this.editor.isEditIntercepts() == 1) { return asString(mean); } case 4: @@ -1127,7 +1151,7 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { double intercept = semIm().getIntercept(y); - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { semIm().setIntercept(y, intercept); } } @@ -1139,9 +1163,9 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { Node node = semIm().getVariableNodes().get(index); if (semIm().getMean(semIm().getVariableNodes().get(index)) != value) { - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { semIm().setIntercept(node, value); - } else { + } else if (this.editor.isEditIntercepts() == 1) { semIm().setMean(node, value); } this.editor.firePropertyChange("modelChanged", 0, 0); @@ -1397,15 +1421,15 @@ private void beginNodeEdit(Node node) { return; } - double d; + double d = Double.NaN; String prefix; String postfix = ""; if (parameter.getType() == ParamType.MEAN) { - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { d = semIm().getIntercept(node); prefix = "B0_" + node.getName() + " = "; - } else { + } else if (this.editor.isEditIntercepts() == 1) { d = semIm().getMean(node); prefix = "Mean(" + node.getName() + ") = "; } @@ -1415,61 +1439,62 @@ private void beginNodeEdit(Node node) { postfix = ")"; } - DoubleTextField field = new DoubleTextField(d, 10, NumberFormatUtil.getInstance().getNumberFormat()); - field.setFilter((value, oldValue) -> { - try { - setNodeValue(node, "" + value); - return value; - } catch (IllegalArgumentException e) { - return oldValue; - } - }); + if (!Double.isNaN(d)) { + DoubleTextField field = new DoubleTextField(d, 10, NumberFormatUtil.getInstance().getNumberFormat()); + field.setFilter((value, oldValue) -> { + try { + setNodeValue(node, "" + value); + return value; + } catch (IllegalArgumentException e) { + return oldValue; + } + }); - Box box = Box.createHorizontalBox(); - box.add(Box.createHorizontalGlue()); - box.add(new JLabel("New value: ")); - box.add(field); - box.add(Box.createHorizontalGlue()); + Box box = Box.createHorizontalBox(); + box.add(Box.createHorizontalGlue()); + box.add(new JLabel("New value: ")); + box.add(field); + box.add(Box.createHorizontalGlue()); - field.addAncestorListener(new AncestorListener() { - @Override - public void ancestorMoved(AncestorEvent ancestorEvent) { - } + field.addAncestorListener(new AncestorListener() { + @Override + public void ancestorMoved(AncestorEvent ancestorEvent) { + } - @Override - public void ancestorRemoved(AncestorEvent ancestorEvent) { - } + @Override + public void ancestorRemoved(AncestorEvent ancestorEvent) { + } - @Override - public void ancestorAdded(AncestorEvent ancestorEvent) { - Container ancestor = ancestorEvent.getAncestor(); + @Override + public void ancestorAdded(AncestorEvent ancestorEvent) { + Container ancestor = ancestorEvent.getAncestor(); - if (ancestor instanceof JDialog) { - SemImGraphicalEditor.this.dialog = ancestor; + if (ancestor instanceof JDialog) { + SemImGraphicalEditor.this.dialog = ancestor; + } } - } - }); + }); - field.addActionListener((e) -> { - if (this.dialog != null) { - this.dialog.setVisible(false); - } - }); + field.addActionListener((e) -> { + if (this.dialog != null) { + this.dialog.setVisible(false); + } + }); - String s; + String s; - if (parameter.getType() == ParamType.MEAN) { - if (this.editor.isEditIntercepts()) { - s = "Intercept for " + node; + if (parameter.getType() == ParamType.MEAN) { + if (this.editor.isEditIntercepts() == 2) { + s = "Intercept for " + node; + } else if (this.editor.isEditIntercepts() == 1) { + s = "Mean for " + node; + } else { + s = ""; + } } else { - s = "Mean for " + node; + s = "Standard Deviation for " + node; } - } else { - s = "Standard Deviation for " + node; } - - JOptionPane.showMessageDialog(this.workbench.getComponent(node), box, s, JOptionPane.PLAIN_MESSAGE); - } private void finishEdit() { @@ -1612,10 +1637,10 @@ private void resetNodeLabel(Node node, Matrix implCovar) { String tooltip = ""; NodeType nodeType = node.getNodeType(); - if (nodeType == NodeType.MEASURED || nodeType == NodeType.LATENT) { - if (this.editor.isEditIntercepts()) { + if (nodeType != NodeType.ERROR) { + if (this.editor.isEditIntercepts() == 2) { meanOrIntercept = semIm().getIntercept(node); - } else { + } else if (this.editor.isEditIntercepts() == 1) { meanOrIntercept = semIm().getMean(node); } } @@ -1638,18 +1663,18 @@ private void resetNodeLabel(Node node, Matrix implCovar) { + asString(tValue) + ", P=" + asString(pValue); } - if (!Double.isNaN(meanOrIntercept)) { + if (nodeType != NodeType.ERROR && !Double.isNaN(meanOrIntercept)) { label.setForeground(Color.GREEN.darker()); label.setText(asString(meanOrIntercept)); - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { tooltip = "" + "B0_" + node.getName() + " = " + asString(meanOrIntercept) + ""; - } else { + } else if (this.editor.isEditIntercepts() == 1) { tooltip = "" + "Mean(" + node.getName() + ") = " + asString(meanOrIntercept) + ""; } - } else if (!this.editor.isEditCovariancesAsCorrelations() + } else if (nodeType == NodeType.ERROR && !this.editor.isEditCovariancesAsCorrelations() && !Double.isNaN(stdDev)) { label.setForeground(Color.BLUE); label.setText(asString(stdDev)); @@ -1657,25 +1682,33 @@ private void resetNodeLabel(Node node, Matrix implCovar) { tooltip = "" + node.getName() + " ~ N(0," + asString(stdDev) + ")" + "

" + tooltip + ""; - } else if (this.editor.isEditCovariancesAsCorrelations()) { + } else if (nodeType == NodeType.ERROR && this.editor.isEditCovariancesAsCorrelations()) { label.setForeground(Color.GRAY); label.setText(asString(stdDev)); + } else { + label = null; } - if (parameter != null && parameter.isFixed()) { - label.setForeground(Color.RED); - } + if (label != null) { + if (parameter != null && parameter.isFixed()) { + label.setForeground(Color.RED); + } - label.setToolTipText(tooltip); + label.setToolTipText(tooltip); + } // Offset the nodes slightly differently depending on whether // they're error nodes or not. - if (nodeType == NodeType.ERROR) { - label.setOpaque(false); - workbench().setNodeLabel(node, label, -10, -10); + if (label != null) { + if (nodeType == NodeType.ERROR) { + label.setOpaque(false); + workbench().setNodeLabel(node, label, -10, -10); + } else { + label.setOpaque(false); + workbench().setNodeLabel(node, label, 0, 0); + } } else { - label.setOpaque(false); - workbench().setNodeLabel(node, label, 0, 0); + workbench.setNodeLabel(node, null, 0, 0); } } @@ -1738,7 +1771,7 @@ private void setEdgeValue(Edge edge, String text) { semIm().setEdgeCoef(x, y, d); - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { double intercept = semIm().getIntercept(y); semIm().setIntercept(y, intercept); } @@ -1763,9 +1796,9 @@ private void setNodeValue(Node node, String text) { semIm().setParamValue(node, node, d * d); this.firePropertyChange("modelChanged", null, null); } else if (parameter.getType() == ParamType.MEAN) { - if (this.editor.isEditIntercepts()) { + if (this.editor.isEditIntercepts() == 2) { semIm().setIntercept(node, d); - } else { + } else if (this.editor.isEditIntercepts() == 1) { semIm().setMean(node, d); } From f5cfc7cfa416d973f3aa7654e4a3c6ff38560cd8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 22 Mar 2023 00:19:32 -0400 Subject: [PATCH 08/58] Added option to SEM Estimator editor to not display means. --- .../tetradapp/editor/SemEstimatorEditor.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) 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 9d23b00e5d..0b3f74d355 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 @@ -720,7 +720,7 @@ private void setEditCovariancesAsCorrelations( tabularEditor().getTableModel().fireTableDataChanged(); } - public int isEditIntercepts() { + public int nodeParamDisplay() { return this.editIntercepts; } @@ -1065,19 +1065,20 @@ public Object getValueAt(int row, int column) { case 1: return nodes.get(index); case 2: - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { return "Intercept"; - } else if (this.editor.isEditIntercepts() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { return "Mean"; + } else { return "Don't display means or intercepts"; } case 3: - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { double intercept = semIm().getIntercept(node); return asString(intercept); } - if (this.editor.isEditIntercepts() == 1) { + if (this.editor.nodeParamDisplay() == 1) { return asString(mean); } case 4: @@ -1151,7 +1152,7 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { double intercept = semIm().getIntercept(y); - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { semIm().setIntercept(y, intercept); } } @@ -1163,9 +1164,9 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { Node node = semIm().getVariableNodes().get(index); if (semIm().getMean(semIm().getVariableNodes().get(index)) != value) { - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { semIm().setIntercept(node, value); - } else if (this.editor.isEditIntercepts() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { semIm().setMean(node, value); } this.editor.firePropertyChange("modelChanged", 0, 0); @@ -1426,10 +1427,10 @@ private void beginNodeEdit(Node node) { String postfix = ""; if (parameter.getType() == ParamType.MEAN) { - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { d = semIm().getIntercept(node); prefix = "B0_" + node.getName() + " = "; - } else if (this.editor.isEditIntercepts() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { d = semIm().getMean(node); prefix = "Mean(" + node.getName() + ") = "; } @@ -1484,9 +1485,9 @@ public void ancestorAdded(AncestorEvent ancestorEvent) { String s; if (parameter.getType() == ParamType.MEAN) { - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { s = "Intercept for " + node; - } else if (this.editor.isEditIntercepts() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { s = "Mean for " + node; } else { s = ""; @@ -1638,9 +1639,9 @@ private void resetNodeLabel(Node node, Matrix implCovar) { NodeType nodeType = node.getNodeType(); if (nodeType != NodeType.ERROR) { - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { meanOrIntercept = semIm().getIntercept(node); - } else if (this.editor.isEditIntercepts() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { meanOrIntercept = semIm().getMean(node); } } @@ -1667,10 +1668,10 @@ private void resetNodeLabel(Node node, Matrix implCovar) { label.setForeground(Color.GREEN.darker()); label.setText(asString(meanOrIntercept)); - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { tooltip = "" + "B0_" + node.getName() + " = " + asString(meanOrIntercept) + ""; - } else if (this.editor.isEditIntercepts() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { tooltip = "" + "Mean(" + node.getName() + ") = " + asString(meanOrIntercept) + ""; } @@ -1771,7 +1772,7 @@ private void setEdgeValue(Edge edge, String text) { semIm().setEdgeCoef(x, y, d); - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { double intercept = semIm().getIntercept(y); semIm().setIntercept(y, intercept); } @@ -1796,9 +1797,9 @@ private void setNodeValue(Node node, String text) { semIm().setParamValue(node, node, d * d); this.firePropertyChange("modelChanged", null, null); } else if (parameter.getType() == ParamType.MEAN) { - if (this.editor.isEditIntercepts() == 2) { + if (this.editor.nodeParamDisplay() == 2) { semIm().setIntercept(node, d); - } else if (this.editor.isEditIntercepts() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { semIm().setMean(node, d); } From bd1711f6b55fa3ecf10c62c12697e858abeaba42 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 22 Mar 2023 00:25:11 -0400 Subject: [PATCH 09/58] Added option to SEM Estimator editor to not display means. --- .../main/java/edu/cmu/tetradapp/editor/SemEstimatorEditor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 0b3f74d355..4b2860e076 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 @@ -1077,8 +1077,7 @@ public Object getValueAt(int row, int column) { if (this.editor.nodeParamDisplay() == 2) { double intercept = semIm().getIntercept(node); return asString(intercept); - } - if (this.editor.nodeParamDisplay() == 1) { + } else if (this.editor.nodeParamDisplay() == 1) { return asString(mean); } case 4: From f8e01993ab229e27d3f04edcb73f352f4c1102f9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 22 Mar 2023 09:37:51 -0400 Subject: [PATCH 10/58] Changed version to 7.3.1-SNAPSHOT. --- data-reader/pom.xml | 2 +- pom.xml | 2 +- tetrad-gui/pom.xml | 2 +- tetrad-lib/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data-reader/pom.xml b/data-reader/pom.xml index 8ae79287a9..de18b973ed 100644 --- a/data-reader/pom.xml +++ b/data-reader/pom.xml @@ -5,7 +5,7 @@ io.github.cmu-phil tetrad - 7.3.0 + 7.3.1-SNAPSHOT data-reader diff --git a/pom.xml b/pom.xml index 64c8b71a50..5cda6ed2c8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.cmu-phil tetrad - 7.3.0 + 7.3.1-SNAPSHOT pom Tetrad Project diff --git a/tetrad-gui/pom.xml b/tetrad-gui/pom.xml index c73ecbeb9a..5b8a82b59f 100644 --- a/tetrad-gui/pom.xml +++ b/tetrad-gui/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.3.0 + 7.3.1-SNAPSHOT tetrad-gui diff --git a/tetrad-lib/pom.xml b/tetrad-lib/pom.xml index afa9cf1a23..0be68b7c74 100644 --- a/tetrad-lib/pom.xml +++ b/tetrad-lib/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.3.0 + 7.3.1-SNAPSHOT tetrad-lib From 5805da21cdd000d0f7390a1cbd23f81fb44e9fb9 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Thu, 23 Mar 2023 12:55:35 -0400 Subject: [PATCH 11/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 928910dc10..1c6e5a4180 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ To download the current jar you can use to launch the Tetrad GUI, click this lin https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.3.0/tetrad-gui-7.3.0-launch.jar. The application will work on all major platforms once a recent version of the Java JRE/JCK is installed, certainly * -*_greater than version 1.8 (version 8)_**. We find that the most +*greater than version 1.8 (version 8)*. We find that the most recent [Corretto JRE/JDK](https://aws.amazon.com/corretto/?filtered-posts.sort-by=item.additionalFields.createdDate&filtered-posts.sort-order=desc) with long term support (LTS) works well cross-platform. From 32ba9f78fff5959a8130668e97eede74c4dc1a9d Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Thu, 23 Mar 2023 12:57:14 -0400 Subject: [PATCH 12/58] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c6e5a4180..94fdfb2843 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ To download the current jar you can use to launch the Tetrad GUI, click this lin https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.3.0/tetrad-gui-7.3.0-launch.jar. -The application will work on all major platforms once a recent version of the Java JRE/JCK is installed, certainly * -*greater than version 1.8 (version 8)*. We find that the most +The application will work on all major platforms once a recent version of the Java JRE/JCK is installed, certainly +__greater than version 1.8 (version 8)__. We find that the most recent [Corretto JRE/JDK](https://aws.amazon.com/corretto/?filtered-posts.sort-by=item.additionalFields.createdDate&filtered-posts.sort-order=desc) with long term support (LTS) works well cross-platform. From 2443086a52a7eb7c90ab9baf6ef387c78dd50d83 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 23 Mar 2023 14:21:30 -0400 Subject: [PATCH 13/58] Set up BOSS and SP again for boostrapping.Also, fixed the structure prior method for DiscreteBicScore. --- .../algorithm/oracle/cpdag/BOSS.java | 51 ++++++++++++++----- .../algorithm/oracle/cpdag/SP.java | 41 +++++++++++---- .../cmu/tetrad/search/DiscreteBicScore.java | 21 ++++++-- 3 files changed, 86 insertions(+), 27 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java index f982d44a4c..340a1f13de 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 @@ -8,15 +8,15 @@ import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.annotation.Experimental; import edu.cmu.tetrad.data.DataModel; +import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.Boss; -import edu.cmu.tetrad.search.PermutationSearch; -import edu.cmu.tetrad.search.Score; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; +import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import java.util.ArrayList; import java.util.List; @@ -50,17 +50,40 @@ public BOSS(ScoreWrapper score) { @Override public Graph search(DataModel dataModel, Parameters parameters) { - Score score = this.score.getScore(dataModel, parameters); - - Boss boss = new Boss(score); - boss.setDepth(parameters.getInt(Params.DEPTH)); - boss.setNumStarts(parameters.getInt(Params.NUM_STARTS)); - PermutationSearch permutationSearch = new PermutationSearch(boss); - permutationSearch.setKnowledge(this.knowledge); - - permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE)); - - return permutationSearch.search(); + if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { + if (parameters.getInt(Params.TIME_LAG) > 0) { + DataSet dataSet = (DataSet) dataModel; + DataSet timeSeries = TimeSeriesUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); + if (dataSet.getName() != null) { + timeSeries.setName(dataSet.getName()); + } + dataModel = timeSeries; + knowledge = timeSeries.getKnowledge(); + } + + Score score = this.score.getScore(dataModel, parameters); + + Boss boss = new Boss(score); + boss.setDepth(parameters.getInt(Params.DEPTH)); + boss.setNumStarts(parameters.getInt(Params.NUM_STARTS)); + PermutationSearch permutationSearch = new PermutationSearch(boss); + permutationSearch.setKnowledge(this.knowledge); + + permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE)); + + return permutationSearch.search(); + } else { + BOSS algorithm = new BOSS(this.score); + + DataSet data = (DataSet) dataModel; + GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); + search.setKnowledge(this.knowledge); + + + search.setParameters(parameters); + search.setVerbose(parameters.getBoolean(Params.VERBOSE)); + return search.search(); + } } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java index 17714b7e91..cfcdb44d49 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 @@ -8,15 +8,15 @@ import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.annotation.Experimental; import edu.cmu.tetrad.data.DataModel; +import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.PermutationSearch; -import edu.cmu.tetrad.search.Score; -import edu.cmu.tetrad.search.Sp; +import edu.cmu.tetrad.search.*; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; +import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import java.util.ArrayList; import java.util.List; @@ -50,12 +50,35 @@ public SP(ScoreWrapper score) { @Override public Graph search(DataModel dataModel, Parameters parameters) { - Score score = this.score.getScore(dataModel, parameters); - PermutationSearch permutationSearch = new PermutationSearch(new Sp(score)); - permutationSearch.setKnowledge(this.knowledge); - permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE)); - - return permutationSearch.search(); + if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { + if (parameters.getInt(Params.TIME_LAG) > 0) { + DataSet dataSet = (DataSet) dataModel; + DataSet timeSeries = TimeSeriesUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); + if (dataSet.getName() != null) { + timeSeries.setName(dataSet.getName()); + } + dataModel = timeSeries; + knowledge = timeSeries.getKnowledge(); + } + + Score score = this.score.getScore(dataModel, parameters); + PermutationSearch permutationSearch = new PermutationSearch(new Sp(score)); + permutationSearch.setKnowledge(this.knowledge); + permutationSearch.setVerbose(parameters.getBoolean(Params.VERBOSE)); + + return permutationSearch.search(); + } else { + BOSS algorithm = new BOSS(this.score); + + DataSet data = (DataSet) dataModel; + GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); + search.setKnowledge(this.knowledge); + + + search.setParameters(parameters); + search.setVerbose(parameters.getBoolean(Params.VERBOSE)); + return search.search(); + } } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java index 77c299a0ee..c279362b66 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/DiscreteBicScore.java @@ -27,6 +27,9 @@ import java.util.List; +import static org.apache.commons.math3.util.FastMath.abs; +import static org.apache.commons.math3.util.FastMath.log; + /** * Calculates the discrete BIC score. */ @@ -167,10 +170,19 @@ public double localScore(int node, int[] parents) { } } - private double getPriorForStructure(int numParents) { - double e = getStructurePrior(); - int vm = this.data.length - 1; - return numParents * FastMath.log(e / (vm)) + (vm - numParents) * FastMath.log(1.0 - (e / (vm))); +// private double getPriorForStructure(int numParents) { +// double e = getStructurePrior(); +// int vm = this.data.length - 1; +// return numParents * FastMath.log(e / (vm)) + (vm - numParents) * FastMath.log(1.0 - (e / (vm))); +// } + + private double getPriorForStructure(int parents) { + if (abs(getStructurePrior()) <= 0) { + return 0; + } else { + double p = (getStructurePrior()) / (this.variables.size()); + return -((parents) * log(p) + (this.variables.size() - (parents)) * log(1.0 - p)); + } } @Override @@ -214,6 +226,7 @@ public double getStructurePrior() { return this.structurePrior; } + @Override public double getSamplePrior() { throw new UnsupportedOperationException(); From 0b5585fda16f1941e4830b70c749bb4fd3d64dd0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 23 Mar 2023 15:23:55 -0400 Subject: [PATCH 14/58] Set up BOSS and SP again for boostrapping.Also, fixed the structure prior method for DiscreteBicScore. --- .../edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cfcdb44d49..a62947f15b 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 @@ -68,7 +68,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return permutationSearch.search(); } else { - BOSS algorithm = new BOSS(this.score); + SP algorithm = new SP(this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); From 6c2a2582ac76991775a93780f66cb542a411535a Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Thu, 23 Mar 2023 18:08:55 -0400 Subject: [PATCH 15/58] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 94fdfb2843..8391689dfb 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,16 @@ try to the extent possible to resolve all reported issues before [releasing new versions of Tetrad](https://github.com/cmu-phil/tetrad/releases). This may involve moving items to our [Wish List ](https://github.com/cmu-phil/tetrad/wiki/Current-Wish-List). + +## Citation + +Please cite as: + +-- +@inproceedings{ramsey2018tetrad, + title={TETRAD—A toolbox for causal discovery}, + author={Ramsey, Joseph D and Zhang, Kun and Glymour, Madelyn and Romero, Ruben Sanchez and Huang, Biwei and Ebert-Uphoff, Imme and Samarasinghe, Savini and Barnes, Elizabeth A and Glymour, Clark}, + booktitle={8th international workshop on climate informatics}, + year={2018} +} +-- From 46b9382e8fcdea2ef38973658e01e01055300f6b Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Thu, 23 Mar 2023 18:09:47 -0400 Subject: [PATCH 16/58] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8391689dfb..6c2f5783c4 100644 --- a/README.md +++ b/README.md @@ -90,11 +90,11 @@ our [Wish List Please cite as: --- +``` @inproceedings{ramsey2018tetrad, title={TETRAD—A toolbox for causal discovery}, author={Ramsey, Joseph D and Zhang, Kun and Glymour, Madelyn and Romero, Ruben Sanchez and Huang, Biwei and Ebert-Uphoff, Imme and Samarasinghe, Savini and Barnes, Elizabeth A and Glymour, Clark}, booktitle={8th international workshop on climate informatics}, year={2018} } --- +``` From 6aff5defc11ab118e662c3337702642dfbc06757 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Fri, 24 Mar 2023 19:08:10 -0500 Subject: [PATCH 17/58] added graphToLavaan --- .../cmu/tetrad/graph/GraphPersistence.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java index b8ee725352..6a38388de7 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 @@ -708,6 +708,59 @@ public static String graphToXml(Graph graph) { return out.toString(); } + public static String graphToLavaan(Graph g) { + boolean includeIntercepts = true; + boolean includeErrors = true; + + Map> parents = new HashMap<>(); + Map> siblings = new HashMap<>(); + + StringBuilder lavaan = new StringBuilder(); + for (Node a : g.getNodes()) { + if (includeIntercepts) lavaan.append(a.getName()).append(" ~ 1\n"); + parents.put(a, new ArrayList<>()); + siblings.put(a, new ArrayList<>()); + for (Edge e : g.getEdges(a)) { + Node b = e.getDistalNode(a); + if (e.getProximalEndpoint(a) != Endpoint.ARROW) continue; + if (e.getProximalEndpoint(b) == Endpoint.TAIL) parents.get(a).add(b); + if (siblings.containsKey(b)) continue; + if (e.getProximalEndpoint(b) == Endpoint.ARROW) parents.get(a).add(b); + } + } + + if (includeIntercepts) lavaan.append("\n"); + boolean hasDirected = false; + for (Node a : g.getNodes()) { + Iterator itr = parents.get(a).iterator(); + if (itr.hasNext()) { + hasDirected = true; + lavaan.append(a.getName()).append(" ~ ").append(itr.next().getName()); + } else continue; + while (itr.hasNext()) lavaan.append(" + ").append(itr.next().getName()); + lavaan.append("\n"); + } + + if (hasDirected) lavaan.append("\n"); + boolean hasBidirected = false; + for (Node a : g.getNodes()) { + Iterator itr = siblings.get(a).iterator(); + if (itr.hasNext()) { + hasBidirected = true; + lavaan.append(a.getName()).append(" ~~ ").append(itr.next().getName()); + } else continue; + while (itr.hasNext()) lavaan.append(" + ").append(itr.next().getName()); + lavaan.append("\n"); + } + + if (hasBidirected) lavaan.append("\n"); + for (Node a : g.getNodes()) { + if (includeErrors) lavaan.append(a.getName()).append(" ~~ ").append(a.getName()).append("\n"); + } + + return lavaan.toString(); + } + public static String graphToPcalg(Graph g) { Map mark2Int = new HashMap(); mark2Int.put(Endpoint.NULL, 0); From c4484f5f5082d99e5e3141283a996c944d0f2838 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 24 Mar 2023 20:20:00 -0400 Subject: [PATCH 18/58] Added Bryan's lavaan graph save option. --- .../cmu/tetradapp/editor/GraphFileMenu.java | 1 + .../edu/cmu/tetradapp/editor/SaveGraph.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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 20db235b52..13f3790f7f 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 @@ -57,6 +57,7 @@ public GraphFileMenu(GraphEditable editable, JComponent comp, boolean saveOnly) save.add(new SaveGraph(editable, "R...", SaveGraph.Type.r)); save.add(new SaveGraph(editable, "Dot...", SaveGraph.Type.dot)); save.add(new SaveGraph(editable, "PCALG...", SaveGraph.Type.pcalg)); + save.add(new SaveGraph(editable, "lavaan...", SaveGraph.Type.lavaan)); addSeparator(); add(new SaveComponentImage(comp, "Save Graph Image...")); 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 5a0ae5e304..7db920803d 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 @@ -57,7 +57,7 @@ public class SaveGraph extends AbstractAction { */ private final Type type; - public enum Type {text, xml, json, r, dot, pcalg} + public enum Type {text, xml, json, r, dot, pcalg, lavaan} public SaveGraph(GraphEditable graphEditable, String title, Type type) { super(title); @@ -147,6 +147,23 @@ public void actionPerformed(ActionEvent e) { try { String text = GraphPersistence.graphToPcalg(graph); + PrintWriter out = new PrintWriter(file); + out.println(text); + Preferences.userRoot().put("fileSaveLocation", file.getParent()); + out.close(); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + throw new RuntimeException("Not a directed graph.", e1); + } catch (IllegalArgumentException e1) { + + // Probably not a directed graph. + JOptionPane.showMessageDialog(getGraphEditable().getWorkbench(), e1.getMessage()); + } + } else if (this.type == Type.lavaan) { + File file = EditorUtils.getSaveFile("graph", "lavaan.txt", parent, false, this.title); + try { + String text = GraphPersistence.graphToLavaan(graph); + PrintWriter out = new PrintWriter(file); out.println(text); Preferences.userRoot().put("fileSaveLocation", file.getParent()); From c08da7ada3216112775ff7ec39ff6ec96ac17eb7 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 25 Mar 2023 04:52:26 -0400 Subject: [PATCH 19/58] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6c2f5783c4..6d28ff8eab 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,10 @@ before [releasing new versions of Tetrad](https://github.com/cmu-phil/tetrad/rel our [Wish List ](https://github.com/cmu-phil/tetrad/wiki/Current-Wish-List). +## Towards More Openness + +If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), we love you. We don't know you, but we love you. Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can. + ## Citation Please cite as: From e5c8ee29117fb756e4146740a68506f92d5636e0 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 25 Mar 2023 05:23:18 -0400 Subject: [PATCH 20/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d28ff8eab..97c0cb0f1f 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ our [Wish List ## Towards More Openness -If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), we love you. We don't know you, but we love you. Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can. +If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), thank you! Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can. ## Citation From ed348458a939247446f44d28dd2c095d0738737c Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 25 Mar 2023 05:24:04 -0400 Subject: [PATCH 21/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 97c0cb0f1f..e48400db8f 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ before [releasing new versions of Tetrad](https://github.com/cmu-phil/tetrad/rel our [Wish List ](https://github.com/cmu-phil/tetrad/wiki/Current-Wish-List). -## Towards More Openness +## Open Code If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), thank you! Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can. From e7775247e5fc289f15832d74e7aa8dd5114883c6 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 25 Mar 2023 05:31:08 -0400 Subject: [PATCH 22/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e48400db8f..0c1173c126 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ our [Wish List ## Open Code -If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), thank you! Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can. +If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), thank you! Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can (with our small team). ## Citation From 84a15679d97d0b7aa14c90b3c54c65c852a12737 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 25 Mar 2023 05:31:40 -0400 Subject: [PATCH 23/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c1173c126..e48400db8f 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ our [Wish List ## Open Code -If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), thank you! Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can (with our small team). +If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), thank you! Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can. ## Citation From ea1f67a0970f9dd54abaf0b2a88a9321410a1297 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 25 Mar 2023 12:24:57 -0400 Subject: [PATCH 24/58] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e48400db8f..ccc6b0d10a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ version of Tetrad and Causal Command. All of our code is public and we welcome suggestions, especially suggestions that improve clarity or performance of our code. +## Setting up Java + +For setting up Java, see our [Wiki article on the topic](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java:-Tutorial-for-Newbies-and-Experts-Alike). + ## Tetrad GUI Application To download the current jar you can use to launch the Tetrad GUI, click this link: From 0fc4a40cae3c9ff5174d4d37ff02d1965341fafa Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sat, 25 Mar 2023 12:25:50 -0400 Subject: [PATCH 25/58] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ccc6b0d10a..492363fd9e 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ of contributors, and a bit of history. Here is the web page for the [Center for Causal Discovery](https://www.ccd.pitt.edu/), which also supports the latest version of Tetrad and Causal Command. -All of our code is public and we welcome suggestions, especially suggestions that improve clarity or performance of our code. - ## Setting up Java For setting up Java, see our [Wiki article on the topic](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java:-Tutorial-for-Newbies-and-Experts-Alike). @@ -92,6 +90,8 @@ our [Wish List ## Open Code +All of our code is public and we welcome suggestions, especially suggestions that improve clarity or performance of our code. + If you're writing code using (or for!) Tetrad in either [Java](https://github.com/cmu-phil/tetrad) or [Python](https://github.com/cmu-phil/py-tetrad) (or R, which we're working toward!), thank you! Please contribute if you are doing amazing work, or publish and send us links to your papers. Please keep us abreast of how Tetrad could be improved for your applications; we will do what we can. ## Citation From 9724b128f89f6bad5effa70c08cc33e50460f556 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Sat, 25 Mar 2023 13:18:53 -0500 Subject: [PATCH 26/58] some light refactoring of GST and TS --- .../algorithm/oracle/cpdag/GRaSP.java | 2 - .../algorithm/oracle/cpdag/GRaSPTol.java | 1 - .../algorithm/oracle/pag/GRASP_FCI.java | 2 - .../algcomparison/examples/TestBoss.java | 15 +- .../java/edu/cmu/tetrad/search/BfciFoo.java | 22 +- .../java/edu/cmu/tetrad/search/BossOrig.java | 6 - .../java/edu/cmu/tetrad/search/Grasp.java | 301 ++----- .../java/edu/cmu/tetrad/search/GraspFci.java | 7 - .../java/edu/cmu/tetrad/search/GraspTol.java | 7 - .../edu/cmu/tetrad/search/GrowShrinkTree.java | 27 +- .../edu/cmu/tetrad/search/OtherPermAlgs.java | 7 - .../cmu/tetrad/search/PermutationSearch.java | 81 +- .../edu/cmu/tetrad/search/TeyssierScorer.java | 755 +++--------------- .../java/edu/cmu/tetrad/test/TestGrasp.java | 3 - 14 files changed, 273 insertions(+), 963 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 fb9d17ad67..7beca2fa93 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 @@ -79,7 +79,6 @@ public Graph search(DataModel dataModel, Parameters parameters) { grasp.setUseRaskuttiUhler(parameters.getBoolean(Params.GRASP_USE_RASKUTTI_UHLER)); grasp.setUseDataOrder(parameters.getBoolean(Params.GRASP_USE_DATA_ORDER)); grasp.setVerbose(parameters.getBoolean(Params.VERBOSE)); - grasp.setCacheScores(parameters.getBoolean(Params.CACHE_SCORES)); grasp.setNumStarts(parameters.getInt(Params.NUM_STARTS)); grasp.setKnowledge(this.knowledge); @@ -126,7 +125,6 @@ public List getParameters() { params.add(Params.GRASP_ORDERED_ALG); params.add(Params.GRASP_USE_RASKUTTI_UHLER); params.add(Params.GRASP_USE_DATA_ORDER); - params.add(Params.CACHE_SCORES); params.add(Params.TIME_LAG); params.add(Params.VERBOSE); 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 index 6070e35441..17b5f95aa3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java @@ -83,7 +83,6 @@ public Graph search(DataModel dataModel, Parameters parameters) { grasp.setToleranceDepth(parameters.getInt(Params.GRASP_TOLERANCE_DEPTH)); grasp.setAllowRandomnessInsideAlgorithm(parameters.getBoolean(Params.GRASP_ALLOW_RANDOMNESS_INSIDE_ALGORITHM)); grasp.setVerbose(parameters.getBoolean(Params.VERBOSE)); - grasp.setCacheScores(parameters.getBoolean(Params.CACHE_SCORES)); grasp.setNumStarts(parameters.getInt(Params.NUM_STARTS)); grasp.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java index 6b25c232c8..a8157a7f65 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java @@ -88,7 +88,6 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setUseScore(parameters.getBoolean(Params.GRASP_USE_SCORE)); search.setUseRaskuttiUhler(parameters.getBoolean(Params.GRASP_USE_RASKUTTI_UHLER)); search.setUseDataOrder(parameters.getBoolean(Params.GRASP_USE_DATA_ORDER)); - search.setCacheScores(parameters.getBoolean(Params.CACHE_SCORES)); search.setNumStarts(parameters.getInt(Params.NUM_STARTS)); // FCI @@ -149,7 +148,6 @@ public List getParameters() { params.add(Params.GRASP_ORDERED_ALG); params.add(Params.GRASP_USE_RASKUTTI_UHLER); params.add(Params.GRASP_USE_DATA_ORDER); - params.add(Params.CACHE_SCORES); params.add(Params.NUM_STARTS); // FCI diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java index 930fd7fb4b..faa079d99f 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 @@ -25,8 +25,10 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.BOSS; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.GRaSP; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.SP; import edu.cmu.tetrad.algcomparison.graph.RandomForward; +import edu.cmu.tetrad.algcomparison.independence.FisherZ; import edu.cmu.tetrad.algcomparison.score.SemBicScore; import edu.cmu.tetrad.algcomparison.simulation.SemSimulation; import edu.cmu.tetrad.algcomparison.simulation.Simulations; @@ -42,21 +44,21 @@ public class TestBoss { public static void main(String... args) { Parameters parameters = new Parameters(); - parameters.set(Params.NUM_RUNS, 1); + parameters.set(Params.NUM_RUNS, 10); parameters.set(Params.DIFFERENT_GRAPHS, true); - parameters.set(Params.NUM_MEASURES, 10); - parameters.set(Params.AVG_DEGREE, 5); + parameters.set(Params.NUM_MEASURES, 60); + parameters.set(Params.AVG_DEGREE, 6); parameters.set(Params.SAMPLE_SIZE, 1000); parameters.set(Params.COEF_LOW, 0); parameters.set(Params.COEF_HIGH, 1); - parameters.set(Params.BOSS_ALG, 1); +// parameters.set(Params.BOSS_ALG, 1); parameters.set(Params.PENALTY_DISCOUNT, 2); parameters.set(Params.SEM_BIC_STRUCTURE_PRIOR, 0); parameters.set(Params.ALPHA, 1e-2); - parameters.set(Params.VERBOSE, true); + parameters.set(Params.VERBOSE, false); Statistics statistics = new Statistics(); statistics.add(new AdjacencyPrecision()); @@ -68,7 +70,8 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); algorithms.add(new Fges(new SemBicScore())); algorithms.add(new BOSS(new SemBicScore())); - algorithms.add(new SP(new SemBicScore())); + algorithms.add(new GRaSP(new SemBicScore(), new FisherZ())); +// algorithms.add(new SP(new SemBicScore())); Simulations simulations = new Simulations(); simulations.add(new SemSimulation(new RandomForward())); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java index a422ef51fc..579c91a384 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BfciFoo.java @@ -188,17 +188,17 @@ private static void triangleReduce1(Graph graph, TeyssierScorer scorer, Knowledg } } - private static void triangleReduce2(Graph graph, TeyssierScorer scorer0, Knowledge knowledge) { - TeyssierScorer scorer = new TeyssierScorer(scorer0); - Graph origGaph = new EdgeListGraph(graph); - - for (Edge edge : graph.getEdges()) { - Node a = edge.getNode1(); - Node b = edge.getNode2(); - t2visit(origGaph, graph, scorer0, knowledge, scorer, a, b); - t2visit(origGaph, graph, scorer0, knowledge, scorer, b, a); - } - } +// private static void triangleReduce2(Graph graph, TeyssierScorer scorer0, Knowledge knowledge) { +// TeyssierScorer scorer = new TeyssierScorer(scorer0); +// Graph origGaph = new EdgeListGraph(graph); +// +// for (Edge edge : graph.getEdges()) { +// Node a = edge.getNode1(); +// Node b = edge.getNode2(); +// t2visit(origGaph, graph, scorer0, knowledge, scorer, a, b); +// t2visit(origGaph, graph, scorer0, knowledge, scorer, b, a); +// } +// } private static boolean t2visit(Graph origGraph, Graph graph, TeyssierScorer scorer0, Knowledge knowledge, TeyssierScorer scorer, Node a, Node b) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java index 77b7f455fa..98abe1c5cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BossOrig.java @@ -37,7 +37,6 @@ public class BossOrig { private int depth = -1; private int numStarts = 1; private AlgType algType = AlgType.BOSS1; - private boolean caching = true; private double epsilon = 1e-10; public BossOrig(@NotNull IndependenceTest test, Score score) { @@ -64,7 +63,6 @@ public BossOrig(TeyssierScorer scorer) { public List bestOrder(@NotNull List order) { - scorer.setCachingScores(caching); scorer.setKnowledge(knowledge); List bestPerm; @@ -598,9 +596,5 @@ public void setAlgType(AlgType algType) { this.algType = algType; } - public void setCaching(boolean caching) { - this.caching = caching; - } - public enum AlgType {BOSS1, BOSS2, BOSS3} } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java index 797a90c18e..88e8eced5f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Grasp.java @@ -35,13 +35,12 @@ public class Grasp { private boolean useRaskuttiUhler; private boolean ordered; private boolean verbose; - private boolean cachingScores = true; private int uncoveredDepth = 1; private int nonSingularDepth = 1; private boolean useDataOrder = true; // other params - private int depth = 4; + private int depth = 3; private int numStarts = 1; public Grasp(@NotNull Score score) { @@ -79,8 +78,6 @@ public List bestOrder(@NotNull List order) { this.scorer.clearBookmarks(); - this.scorer.setCachingScores(this.cachingScores); - List bestPerm = null; double best = NEGATIVE_INFINITY; @@ -125,47 +122,61 @@ public int getNumEdges() { return this.scorer.getNumEdges(); } + private void makeValidKnowledgeOrder(List order) { if (!this.knowledge.isEmpty()) { - order.sort((o1, o2) -> { - if (o1.getName().equals(o2.getName())) { - return 0; - } else if (this.knowledge.isRequired(o1.getName(), o2.getName())) { - return -1; - } else if (this.knowledge.isRequired(o2.getName(), o1.getName())) { - return 1; - } else if (this.knowledge.isForbidden(o1.getName(), o2.getName())) { - return 1; - } else if (this.knowledge.isForbidden(o2.getName(), o1.getName())) { - return -1; - } else { - return 0; - } + order.sort((a, b) -> { + if (a.getName().equals(b.getName())) return 0; + else if (this.knowledge.isRequired(a.getName(), b.getName())) return -1; + else if (this.knowledge.isRequired(b.getName(), a.getName())) return 1; + else return 0; }); } + } - System.out.println("Initial knowledge sort order = " + order); - - if (violatesKnowledge(order)) { - Edge edge = violatesForbiddenKnowledge(order); - if (edge != null) { - JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), - "The initial sorting procedure could not find a permutation consistent with that \n" + - "knowledge; this edge was in the DAG: " + edge + " in the initial sort,\n" + - "but this edge was forbidden."); - } +// private void makeValidKnowledgeOrder(List order) { +// if (!this.knowledge.isEmpty()) { +// order.sort((o1, o2) -> { +// if (o1.getName().equals(o2.getName())) { +// return 0; +// } else if (this.knowledge.isRequired(o1.getName(), o2.getName())) { +// return -1; +// } else if (this.knowledge.isRequired(o2.getName(), o1.getName())) { +// return 1; +// } else if (this.knowledge.isForbidden(o1.getName(), o2.getName())) { +// return 1; +// } else if (this.knowledge.isForbidden(o2.getName(), o1.getName())) { +// return -1; +// } else { +// return 0; +// } +// }); +// } +// +// System.out.println("Initial knowledge sort order = " + order); +// +// if (violatesKnowledge(order)) { +// Edge edge = violatesForbiddenKnowledge(order); +// +// if (edge != null) { +// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), +// "The initial sorting procedure could not find a permutation consistent with that \n" + +// "knowledge; this edge was in the DAG: " + edge + " in the initial sort,\n" + +// "but this edge was forbidden."); +// } +// +// Edge edge2 = violatesRequiredKnowledge(order); +// +// if (edge2 != null) { +// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), +// "The initial sorting procedure could not find a permutation consistent with that \n" + +// "knowledge; this edge was not in the DAG: " + edge2 + " in the initial sorted," + +// "but this edge was required."); +// } +// } +// } - Edge edge2 = violatesRequiredKnowledge(order); - - if (edge2 != null) { - JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), - "The initial sorting procedure could not find a permutation consistent with that \n" + - "knowledge; this edge was not in the DAG: " + edge2 + " in the initial sorted," + - "but this edge was required."); - } - } - } public List grasp(@NotNull TeyssierScorer scorer) { scorer.clearBookmarks(); @@ -249,7 +260,6 @@ private void graspDfs(@NotNull TeyssierScorer scorer, double sOld, int[] depth, } while (zItr.hasNext()); // scorer.updateScores(idcs[0], idcs[1]); - if (currentDepth > depth[2] && !singular) { scorer.goToBookmark(currentDepth); continue; @@ -299,10 +309,6 @@ public Graph getGraph(boolean cpDag) { return graph; } - public void setCacheScores(boolean cachingScores) { - this.cachingScores = cachingScores; - } - public void setNumStarts(int numStarts) { this.numStarts = numStarts; } @@ -346,18 +352,12 @@ public void setUseScore(boolean useScore) { } private boolean violatesKnowledge(List order) { - if (!this.knowledge.isEmpty()) { - scorer.score(order); + if (this.knowledge.isEmpty()) return false; - for (int i = 0; i < order.size(); i++) { - for (int j = i + 1; j < order.size(); j++) { - if (this.knowledge.isForbidden(order.get(i).getName(), order.get(j).getName()) && scorer.parent(order.get(i), order.get(j))) { - return true; - } - - if (this.knowledge.isRequired(order.get(j).getName(), order.get(i).getName()) && !scorer.parent(order.get(i), order.get(j))) { - return true; - } + for (int i = 0; i < order.size(); i++) { + for (int j = 0; j < i; j++) { + if (this.knowledge.isRequired(order.get(i).getName(), order.get(j).getName())) { + return true; } } } @@ -365,37 +365,37 @@ private boolean violatesKnowledge(List order) { return false; } - private Edge violatesForbiddenKnowledge(List order) { - if (!this.knowledge.isEmpty()) { - scorer.score(order); - - for (int i = 0; i < order.size(); i++) { - for (int j = i + 1; j < order.size(); j++) { - if (this.knowledge.isForbidden(order.get(i).getName(), order.get(j).getName()) && scorer.parent(order.get(i), order.get(j))) { - return Edges.directedEdge(order.get(i), order.get(j)); - } - } - } - } - - return null; - } - - private Edge violatesRequiredKnowledge(List order) { - if (!this.knowledge.isEmpty()) { - scorer.score(order); - - for (int i = 0; i < order.size(); i++) { - for (int j = i + 1; j < order.size(); j++) { - if (this.knowledge.isRequired(order.get(j).getName(), order.get(i).getName()) && !scorer.parent(order.get(i), order.get(j))) { - return Edges.directedEdge(order.get(j), order.get(i)); - } - } - } - } - - return null; - } +// private Edge violatesForbiddenKnowledge(List order) { +// if (!this.knowledge.isEmpty()) { +// scorer.score(order); +// +// for (int i = 0; i < order.size(); i++) { +// for (int j = i + 1; j < order.size(); j++) { +// if (this.knowledge.isForbidden(order.get(i).getName(), order.get(j).getName()) && scorer.parent(order.get(i), order.get(j))) { +// return Edges.directedEdge(order.get(i), order.get(j)); +// } +// } +// } +// } +// +// return null; +// } + +// private Edge violatesRequiredKnowledge(List order) { +// if (!this.knowledge.isEmpty()) { +// scorer.score(order); +// +// for (int i = 0; i < order.size(); i++) { +// for (int j = i + 1; j < order.size(); j++) { +// if (this.knowledge.isRequired(order.get(j).getName(), order.get(i).getName()) && !scorer.parent(order.get(i), order.get(j))) { +// return Edges.directedEdge(order.get(j), order.get(i)); +// } +// } +// } +// } +// +// return null; +// } public void setOrdered(boolean ordered) { this.ordered = ordered; @@ -413,135 +413,4 @@ public void setUseDataOrder(boolean useDataOrder) { this.useDataOrder = useDataOrder; } - public void orientbk(Knowledge bk, Graph graph, List variables) { - for (Iterator it = bk.forbiddenEdgesIterator(); it.hasNext(); ) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - KnowledgeEdge edge = it.next(); - - //match strings to variables in the graph. - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); - - if (from == null || to == null) { - continue; - } - - if (graph.getEdge(from, to) == null) { - continue; - } - - // Orient to*->from - graph.setEndpoint(to, from, Endpoint.ARROW); -// graph.setEndpoint(from, to, Endpoint.CIRCLE); -// this.changeFlag = true; -// this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); - } - - for (Iterator it = bk.requiredEdgesIterator(); it.hasNext(); ) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - KnowledgeEdge edge = it.next(); - - //match strings to variables in the graph. - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); - - if (from == null || to == null) { - continue; - } - - if (graph.getEdge(from, to) == null) { - continue; - } - - // Orient to*->from - graph.setEndpoint(from, to, Endpoint.ARROW); -// graph.setEndpoint(from, to, Endpoint.CIRCLE); -// this.changeFlag = true; -// this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); - } - } - - private void addRequiredEdges(Graph graph) { - for (Iterator it = knowledge.requiredEdgesIterator(); it.hasNext() && !Thread.currentThread().isInterrupted(); ) { - KnowledgeEdge next = it.next(); - - Node nodeA = graph.getNode(next.getFrom()); - Node nodeB = graph.getNode(next.getTo()); - - if (!graph.paths().isAncestorOf(nodeB, nodeA)) { - graph.removeEdges(nodeA, nodeB); - graph.addDirectedEdge(nodeA, nodeB); - - if (verbose) { - TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeA, nodeB)); - } - } - } - for (Edge edge : graph.getEdges()) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - final String A = edge.getNode1().getName(); - final String B = edge.getNode2().getName(); - - if (knowledge.isForbidden(A, B)) { - Node nodeA = edge.getNode1(); - Node nodeB = edge.getNode2(); - - if (graph.isAdjacentTo(nodeA, nodeB) && !graph.isChildOf(nodeA, nodeB)) { - if (!graph.paths().isAncestorOf(nodeA, nodeB)) { - graph.removeEdges(nodeA, nodeB); - graph.addDirectedEdge(nodeB, nodeA); - - if (verbose) { - TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA)); - } - } - } - - if (!graph.isChildOf(nodeA, nodeB) && knowledge.isForbidden(nodeA.getName(), nodeB.getName())) { - if (!graph.paths().isAncestorOf(nodeA, nodeB)) { - graph.removeEdges(nodeA, nodeB); - graph.addDirectedEdge(nodeB, nodeA); - - if (verbose) { - TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA)); - } - } - } - } else if (knowledge.isForbidden(B, A)) { - Node nodeA = edge.getNode2(); - Node nodeB = edge.getNode1(); - - if (graph.isAdjacentTo(nodeA, nodeB) && !graph.isChildOf(nodeA, nodeB)) { - if (!graph.paths().isAncestorOf(nodeA, nodeB)) { - graph.removeEdges(nodeA, nodeB); - graph.addDirectedEdge(nodeB, nodeA); - - if (verbose) { - TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA)); - } - } - } - if (!graph.isChildOf(nodeA, nodeB) && knowledge.isForbidden(nodeA.getName(), nodeB.getName())) { - if (!graph.paths().isAncestorOf(nodeA, nodeB)) { - graph.removeEdges(nodeA, nodeB); - graph.addDirectedEdge(nodeB, nodeA); - - if (verbose) { - TetradLogger.getInstance().forceLogMessage("Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA)); - } - } - } - } - } - } - } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java index 9d514d8822..ccca654a03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java @@ -87,7 +87,6 @@ public final class GraspFci implements GraphSearch { private boolean possibleDsepSearchDone = true; private boolean ordered = false; - private boolean cachingScores = true; private int graspDepth = 3; private int uncoveredDepth = 1; private int nonSingularDepth = 1; @@ -127,7 +126,6 @@ public Graph search() { alg.setSingularDepth(uncoveredDepth); alg.setNonSingularDepth(nonSingularDepth); alg.setNumStarts(numStarts); - alg.setCacheScores(cachingScores); alg.setVerbose(verbose); List variables = this.score.getVariables(); @@ -422,9 +420,4 @@ public void setOrdered(boolean ordered) { this.ordered = ordered; } - - public void setCacheScores(boolean cachingScores) { - this.cachingScores = cachingScores; - } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java index 19b7d15473..15d1ca4ce9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspTol.java @@ -33,7 +33,6 @@ public class GraspTol { private boolean usePearl; private boolean ordered; private boolean verbose; - private boolean cachingScores = true; private int uncoveredDepth = 1; private int nonSingularDepth = 1; private int toleranceDepth; @@ -82,8 +81,6 @@ public List bestOrder(@NotNull List order) { this.scorer.setKnowledge(this.knowledge); this.scorer.clearBookmarks(); - this.scorer.setCachingScores(this.cachingScores); - List bestPerm = null; double best = NEGATIVE_INFINITY; @@ -388,10 +385,6 @@ public Graph getGraph(boolean cpDag) { return graph; } - public void setCacheScores(boolean cachingScores) { - this.cachingScores = cachingScores; - } - public void setNumStarts(int numStarts) { this.numStarts = numStarts; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java index d490823f66..1ac1d93b64 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GrowShrinkTree.java @@ -1,5 +1,6 @@ package edu.cmu.tetrad.search; +import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Node; import org.jetbrains.annotations.NotNull; @@ -10,22 +11,18 @@ public class GrowShrinkTree { private final Map index; private final Node node; private final int nodeIndex; - private final List required; - private final List forbidden; - private final GSTNode root; + private List required; + private List forbidden; + private GSTNode root; - public GrowShrinkTree(Score score, Map index, Node node, List required, List forbidden) { + public GrowShrinkTree(Score score, Map index, Node node) { this.score = score; this.index = index; this.node = node; this.nodeIndex = index.get(node); this.root = new GSTNode(this); - this.required = required; - this.forbidden = forbidden; - } - - public GrowShrinkTree(Score score, Map index, Node node) { - this(score, index, node, new ArrayList<>(), new ArrayList<>()); + this.required = new ArrayList<>(); + this.forbidden = new ArrayList<>(); } public double trace(Set prefix, Set parents) { @@ -60,6 +57,16 @@ public List getVariables() { return this.score.getVariables(); } + public List getRequired() { return this.required; } + + public List getForbidden() { return this.forbidden; } + + public void setKnowledge(List required, List forbidden) { + this.root = new GSTNode(this); + this.required = required; + this.forbidden = forbidden; + } + private static class GSTNode implements Comparable { private final GrowShrinkTree tree; private final Node add; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java index dbcceda433..7e403d8f8d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/OtherPermAlgs.java @@ -40,7 +40,6 @@ public class OtherPermAlgs { private boolean useScore = true; private boolean usePearl = false; private boolean verbose = false; - private boolean cachingScores = true; private boolean useDataOrder = false; private int numVars; @@ -84,8 +83,6 @@ public List bestOrder(@NotNull List _order) { scorer.setKnowledge(knowledge); scorer.clearBookmarks(); - scorer.setCachingScores(cachingScores); - List bestPerm = new ArrayList<>(order); double best = Float.NEGATIVE_INFINITY; @@ -437,10 +434,6 @@ public Graph getGraph(boolean cpDag) { return graph; } - public void setCacheScores(boolean cachingScores) { - this.cachingScores = cachingScores; - } - public void setNumStarts(int numStarts) { this.numStarts = numStarts; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationSearch.java index 50705717f0..c1f5071e76 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,48 +13,32 @@ * @author bryanandrews */ public class PermutationSearch { - private final Score score; - private final List order; - private final Map nodeMap; - private final Map index; private final SuborderSearch suborderSearch; - private Knowledge knowledge = new Knowledge(); private final List variables; + private final List order; private final Map gsts; - private boolean verbose = true; + private final Map nodeMap; + private Knowledge knowledge = new Knowledge(); + private boolean verbose = false; public PermutationSearch(SuborderSearch suborderSearch) { this.suborderSearch = suborderSearch; this.variables = suborderSearch.getVariables(); - this.score = suborderSearch.getScore(); - this.nodeMap = new HashMap<>(); this.order = new ArrayList<>(); + this.gsts = new HashMap<>(); + this.nodeMap = new HashMap<>(); int i = 0; - this.index = new HashMap<>(); - this.gsts = new HashMap<>(); + Score score = suborderSearch.getScore(); + Map index = new HashMap<>(); for (Node node : this.variables) { - this.index.put(node, i++); + index.put(node, i++); + this.gsts.put(node, new GrowShrinkTree(score, index, node)); this.nodeMap.put(node.getName(), node); } } public Graph search() { - this.gsts.clear(); - for (Node node : this.variables) { - if (this.knowledge.isEmpty()) { - this.gsts.put(node, new GrowShrinkTree(this.score, this.index, node)); - } else { - List required = new ArrayList<>(); - List forbidden = new ArrayList<>(); - for (Node parent : this.variables) { - if (this.knowledge.isRequired(parent.getName(), node.getName())) required.add(parent); - if (this.knowledge.isForbidden(parent.getName(), node.getName())) forbidden.add(parent); - } - this.gsts.put(node, new GrowShrinkTree(this.score, this.index, node, required, forbidden)); - } - } - List tasks = new ArrayList<>(); if (!this.knowledge.isEmpty() && this.knowledge.getVariablesNotInTiers().isEmpty()) { int start, end = 0; @@ -76,31 +60,18 @@ public Graph search() { for (int[] task : tasks) { List prefix = new ArrayList<>(this.order.subList(0, task[0])); List suborder = this.order.subList(task[0], task[1]); -// makeValidKnowledgeOrder(suborder); this.suborderSearch.searchSuborder(prefix, suborder, this.gsts); } return getGraph(this.variables, this.suborderSearch.getParents(), this.knowledge, true); } - // This would have to be moved to a better place like GraphUtils maybe... + // TO DO: moved to a better place like GraphUtils public static Graph getGraph(List nodes, Map> parents, boolean cpDag) { - Graph graph = new EdgeListGraph(nodes); - - for (Node a : nodes) { - for (Node b : parents.get(a)) { - graph.addDirectedEdge(b, a); - } - } - - if (cpDag) { - MeekRules rules = new MeekRules(); - rules.orientImplied(graph); - } - - return graph; + return getGraph(nodes, parents, null, cpDag); } + // TO DO: moved to a better place like GraphUtils public static Graph getGraph(List nodes, Map> parents, Knowledge knowledge, boolean cpDag) { Graph graph = new EdgeListGraph(nodes); @@ -112,24 +83,13 @@ public static Graph getGraph(List nodes, Map> parents, Kno if (cpDag) { MeekRules rules = new MeekRules(); - rules.setKnowledge(knowledge); + if (knowledge != null) rules.setKnowledge(knowledge); rules.orientImplied(graph); } return graph; } -// 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; -// }); -// } -// } - public List getVariables() { return new ArrayList<>(this.variables); } @@ -142,8 +102,21 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } + public Knowledge getKnowledge() { return this.knowledge; } + public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; this.suborderSearch.setKnowledge(knowledge); + + for (Node node : this.variables) { + List required = new ArrayList<>(); + List forbidden = new ArrayList<>(); + for (Node parent : this.variables) { + if (knowledge.isRequired(parent.getName(), node.getName())) required.add(parent); + if (knowledge.isForbidden(parent.getName(), node.getName())) forbidden.add(parent); + } + if (required.isEmpty() && forbidden.isEmpty()) continue; + this.gsts.get(node).setKnowledge(required, forbidden); + } } } \ No newline at end of file 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 a52430eef3..c84557f435 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 @@ -25,150 +25,84 @@ */ public class TeyssierScorer { private final List variables; - private final Map variablesHash; - private final Score score; - private final IndependenceTest test; - private int maxIndegree; - private Map> bookmarkedOrders = new HashMap<>(); - private Map> bookmarkedScores = new HashMap<>(); - private Map> bookmarkedOrderHashes = new HashMap<>(); - private Map bookmarkedRunningScores = new HashMap<>(); - private Map, Double>> cache = new HashMap<>(); - private Map orderHash; private ArrayList pi; // The current permutation. + private final Map variablesHash = new HashMap<>(); + 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<>(); + private final Map> bookmarkedScores = new HashMap<>(); + private final Map> bookmarkedOrderHashes = new HashMap<>(); + private final Map bookmarkedRunningScores = new HashMap<>(); + private final Map trees = new HashMap<>(); private Knowledge knowledge = new Knowledge(); - private ArrayList> prefixes; - private boolean useScore = true; - private boolean useRaskuttiUhler; - private boolean useBackwardScoring; - private boolean cachingScores = true; + private boolean useScore; + private boolean useRaskuttiUhler = false; private double runningScore = 0f; - private Graph mag = null; -// private GrowShrinkTree GST; public TeyssierScorer(IndependenceTest test, Score score) { + if (test == null && score == null) throw new IllegalArgumentException("Required: test or score"); NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.OBJECT); - this.score = score; - this.test = test; - -// this.GST = new GrowShrinkTree(score); - - if (score != null) { - this.variables = score.getVariables(); - this.pi = new ArrayList<>(this.variables); - } else if (test != null) { - this.variables = test.getVariables(); - this.pi = new ArrayList<>(this.variables); - } else { - throw new IllegalArgumentException("Need both a score and a test,"); - } - - this.orderHash = new HashMap<>(); - nodesHash(this.orderHash, this.pi); - - this.variablesHash = new HashMap<>(); + this.variables = score.getVariables(); + this.pi = new ArrayList<>(this.variables); nodesHash(this.variablesHash, this.variables); + nodesHash(this.orderHash, this.pi); - if (score instanceof GraphScore) { - this.useScore = false; - } - } - - public TeyssierScorer(TeyssierScorer 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.test = scorer.test; - - 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<>(); + this.test = test; + this.score = score; - for (Object key : scorer.bookmarkedOrderHashes.keySet()) { - this.bookmarkedOrderHashes.put(key, new HashMap<>(scorer.bookmarkedOrderHashes.get(key))); + setUseScore(true); + if (this.useScore) { + for (Node node : this.variables) { + this.trees.put(node, new GrowShrinkTree(score, this.variablesHash, node)); + } } - - 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; - - this.prefixes = new ArrayList<>(scorer.prefixes); } - public void moveToEnd(Node z) { - moveTo(z, size() - 1); - } /** * @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; - } + this.useScore = useScore && !(this.score instanceof GraphScore); + if (this.useScore) this.useRaskuttiUhler = false; } - /** - * @param cachingScores True if scores should be cached (potentially expensive for memory); - * false if not (potentially expensive for time). - */ - public void setCachingScores(boolean cachingScores) { - this.cachingScores = cachingScores; - } /** * @param knowledge Knowledge of forbidden edges. */ public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; + + for (Node node : this.variables) { + List required = new ArrayList<>(); + List forbidden = new ArrayList<>(); + for (Node parent : this.variables) { + if (knowledge.isRequired(parent.getName(), node.getName())) required.add(parent); + if (knowledge.isForbidden(parent.getName(), node.getName())) forbidden.add(parent); + } + if (required.isEmpty() && forbidden.isEmpty()) continue; + this.trees.get(node).setKnowledge(required, forbidden); + } } + /** * @param useRaskuttiUhler True if Pearl's method for building a DAG should be used. */ public void setUseRaskuttiUhler(boolean useRaskuttiUhler) { this.useRaskuttiUhler = useRaskuttiUhler; - this.useScore = false; + if (useRaskuttiUhler) this.useScore = false; } - public void setUseBackwardScoring(boolean useBackwardScoring) { - this.useBackwardScoring = useBackwardScoring; - } - - public double score(List order, Graph mag) { - this.mag = mag; - return score(order); - } /** * Scores the given permutation. This needs to be done initially before any move or tuck @@ -191,14 +125,15 @@ public double score(List order) { return score(); } + /** * @return The score of the current permutation. */ public double score() { return sum(); -// return runningScore; } + private double sum() { double score = 0; @@ -213,30 +148,12 @@ private double sum() { return score; } + /** * Performs a tuck operation. */ - public boolean swaptuck(Node x, Node y, Node z, boolean doZ) { - boolean moved = false; - - if (index(y) < index(x)) { - moveTo(x, index(y)); - moved = true; - } - - if (doZ) { - if (index(y) < index(z)) { - moveTo(z, index(y)); - moved = true; - } - } - - return moved; - } - public boolean swaptuck(Node x, Node y) { if (index(x) < index(y)) { -// moveTo(y, index(x)); return false; } else if (index(y) < index(x)) { moveTo(x, index(y)); @@ -246,19 +163,14 @@ public boolean swaptuck(Node x, Node y) { return false; } - public void tuckWithoutMovingAncestors(Node x, Node y) { - if (index(x) > index(y)) { - moveTo(x, index(y)); - } - } 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 (scorer.coveredEdge(k, scorer.get(j))) return false; if (j >= index(k)) return false; Set ancestors = getAncestors(k); @@ -271,6 +183,7 @@ public boolean tuck(Node k, int j) { return true; } + /** * Moves v to a new index. * @@ -292,6 +205,7 @@ public void moveTo(Node v, int toIndex) { } } + /** * Swaps m and n in the permutation. * @@ -321,6 +235,7 @@ 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} @@ -330,7 +245,7 @@ public boolean swap(Node m, Node n) { * @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; + if (!adjacent(x, y)) return false; Set px = getParents(x); Set py = getParents(y); px.remove(y); @@ -338,6 +253,7 @@ public boolean coveredEdge(Node x, Node y) { return px.equals(py); } + /** * @return A copy of the current permutation. */ @@ -345,6 +261,7 @@ public List getPi() { return new ArrayList<>(this.pi); } + /** * Returns the current permutation without making a copy. Could be dangerous! * @@ -354,6 +271,7 @@ public List getOrderShallow() { return this.pi; } + /** * Return the index of v in the current permutation. * @@ -370,6 +288,7 @@ public int index(Node v) { return integer; } + /** * Returns the parents of the node at index p. * @@ -381,12 +300,14 @@ public Set getParents(int p) { return new HashSet<>(this.scores.get(p).getParents()); } + public Set getChildren(int p) { Set adj = getAdjacentNodes(get(p)); adj.removeAll(getParents(p)); return adj; } + /** * Returns the parents of a node v. * @@ -397,10 +318,12 @@ public Set getParents(Node v) { return getParents(index(v)); } + public Set getChildren(Node v) { return getChildren(index(v)); } + /** * Returns the nodes adjacent to v. * @@ -419,17 +342,6 @@ public Set getAdjacentNodes(Node v) { return adj; } - public Set getAncestralNodes(Node v) { - Set adj = new HashSet<>(); - - for (Node w : this.pi) { - if (getAncestors(v).contains(w) || getAncestors(w).contains(v)) { - adj.add(w); - } - } - - return adj; - } /** * Returns the DAG build for the current permutation, or its CPDAG. @@ -438,209 +350,23 @@ public Set getAncestralNodes(Node v) { * @return This graph. */ public Graph getGraph(boolean cpDag) { - if (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)); - } + Graph graph = new EdgeListGraph(this.variables); + for (Node a : this.variables) { + for (Node b : getParents(a)) { + graph.addDirectedEdge(b, a); } - - GraphUtils.replaceNodes(G1, this.variables); - - MeekRules rules = new MeekRules(); - rules.setKnowledge(knowledge); - rules.orientImplied(G1); - - return G1; - -// return findCompelled(); - } else { - 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); - - return G1; } - } - public void orientbk(Knowledge bk, Graph graph, List variables) { - for (Iterator it = bk.forbiddenEdgesIterator(); it.hasNext(); ) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - KnowledgeEdge edge = it.next(); - - //match strings to variables in the graph. - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); - - if (from == null || to == null) { - continue; - } - - if (graph.getEdge(from, to) == null) { - continue; - } - - // Orient to*->from - graph.setEndpoint(to, from, Endpoint.ARROW); -// graph.setEndpoint(from, to, Endpoint.CIRCLE); -// this.changeFlag = true; -// this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); + if (cpDag) { + MeekRules rules = new MeekRules(); + rules.setKnowledge(this.knowledge); + rules.orientImplied(graph); } - for (Iterator it = bk.requiredEdgesIterator(); it.hasNext(); ) { - if (Thread.currentThread().isInterrupted()) { - break; - } - - KnowledgeEdge edge = it.next(); - - //match strings to variables in the graph. - Node from = SearchGraphUtils.translate(edge.getFrom(), variables); - Node to = SearchGraphUtils.translate(edge.getTo(), variables); - - if (from == null || to == null) { - continue; - } - - if (graph.getEdge(from, to) == null) { - continue; - } - - // Orient to*->from - graph.setEndpoint(from, to, Endpoint.ARROW); -// graph.setEndpoint(from, to, Endpoint.CIRCLE); -// this.changeFlag = true; -// this.logger.forceLogMessage(SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to))); - } + return graph; } -// public Graph getGraph(boolean cpDag) { -// -// if(cpDag) { -// return findCompelled(); -// } -// -// 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; -// } -// } - - private List orderEdges() { - - List orderedEdges = new ArrayList<>(); - - for (int i = this.pi.size(); i-- > 0; ) { - Node y = this.pi.get(i); - Set pa = this.getParents(i); - for (int j = 0; j < i; j++) { - Node x = this.pi.get(j); - if (pa.contains(x)) { - Edge e = new Edge(x, y, Endpoint.TAIL, Endpoint.ARROW); - orderedEdges.add(e); - pa.remove(x); - if (pa.isEmpty()) { - break; - } - } - } - } - return orderedEdges; - } - - public Graph findCompelled() { - - Graph G = new EdgeListGraph(this.variables); - - List orderedEdges = orderEdges(); - - Node remainderCompelled = null; - Node remainderReversible = null; - - EDGES: - while (!orderedEdges.isEmpty()) { - - Edge e = orderedEdges.remove(0); - Node x = e.getNode1(); - Node y = e.getNode2(); - - if (remainderCompelled != null) { - if (remainderCompelled == y) { - G.addEdge(e); - continue; - } else { - remainderCompelled = null; - } - } - - if (remainderReversible != null) { - if (remainderReversible == y) { - G.addUndirectedEdge(x, y); - continue; - } else { - remainderReversible = null; - } - } - - if (G.isParentOf(x, y)) { - continue; - } - - List compelled = G.getParents(x); - Set xPa = getParents(x); - Set yPa = getParents(y); - - for (Node w : compelled) { - if (yPa.contains(w)) { - G.addEdge(e); - continue EDGES; - } else { - G.addDirectedEdge(w, y); - } - } - - yPa.remove(x); - for (Node z : yPa) { - if (!xPa.contains(z)) { - G.addEdge(e); - remainderCompelled = y; - continue EDGES; - } - } - - G.addUndirectedEdge(x, y); - remainderReversible = y; - } - - return G; - } - /** * Returns a list of adjacent node pairs in the current graph. * @@ -664,36 +390,6 @@ public List getAdjacencies() { return new ArrayList<>(pairs); } - public Map> getAdjMap() { - Map> adjMap = new HashMap<>(); - for (Node node1 : getPi()) { - if (!adjMap.containsKey(node1)) { - adjMap.put(node1, new HashSet<>()); - } - for (Node node2 : getParents(node1)) { - if (!adjMap.containsKey(node2)) { - adjMap.put(node2, new HashSet<>()); - } - adjMap.get(node1).add(node2); - adjMap.get(node2).add(node1); - } - } - return adjMap; - } - - - public Map> getChildMap() { - Map> childMap = new HashMap<>(); - for (Node node1 : getPi()) { - for (Node node2 : getParents(node1)) { - if (!childMap.containsKey(node2)) { - childMap.put(node2, new HashSet<>()); - } - childMap.get(node2).add(node1); - } - } - return childMap; - } public Set getAncestors(Node node) { Set ancestors = new HashSet<>(); @@ -702,11 +398,6 @@ public Set getAncestors(Node node) { return ancestors; } - public Set getDescendants(Node node) { - Set descendants = new HashSet<>(); - collectDescendantVisit(node, descendants); - return descendants; - } private void collectAncestorsVisit(Node node, Set ancestors) { if (ancestors.contains(node)) { @@ -723,20 +414,6 @@ private void collectAncestorsVisit(Node node, Set ancestors) { } } - private void collectDescendantVisit(Node node, Set ancestors) { - if (ancestors.contains(node)) { - return; - } - - ancestors.add(node); - Set children = getChildren(node); - - if (!children.isEmpty()) { - for (Node parent : children) { - collectDescendantVisit(parent, ancestors); - } - } - } /** * Returns a list of edges for the current graph as a list of ordered pairs. @@ -756,6 +433,7 @@ public List> getEdges() { return edges; } + /** * @return The number of edges in the current graph. */ @@ -769,6 +447,7 @@ public int getNumEdges() { return numEdges; } + /** * Returns the node at index j in pi. * @@ -779,6 +458,7 @@ public Node get(int j) { return this.pi.get(j); } + /** * Bookmarks the current pi as index key. * @@ -796,6 +476,7 @@ public void bookmark(int key) { } } + /** * Bookmarks the current pi with index Integer.MIN_VALUE. */ @@ -803,6 +484,7 @@ public void bookmark() { bookmark(Integer.MIN_VALUE); } + /** * Retrieves the bookmarked state for index 'key' and removes that bookmark. * @@ -810,8 +492,6 @@ public void bookmark() { */ public void goToBookmark(int key) { if (!this.bookmarkedOrders.containsKey(key)) { -// bookmark(key); -// return; throw new IllegalArgumentException("That key was not bookmarked: " + key); } @@ -819,9 +499,9 @@ public void goToBookmark(int key) { this.scores = new ArrayList<>(this.bookmarkedScores.get(key)); this.orderHash = new HashMap<>(this.bookmarkedOrderHashes.get(key)); this.runningScore = this.bookmarkedRunningScores.get(key); - } + /** * Retries the bookmark with key = Integer.MIN_VALUE and removes the bookmark. */ @@ -829,6 +509,7 @@ public void goToBookmark() { goToBookmark(Integer.MIN_VALUE); } + /** * Clears all bookmarks. */ @@ -839,6 +520,7 @@ public void clearBookmarks() { this.bookmarkedRunningScores.clear(); } + /** * @return The size of pi, the current permutation. */ @@ -846,14 +528,6 @@ public int size() { return this.pi.size(); } - /** - * Shuffles the current permutation and rescores it. - */ - public void shuffleVariables() { - this.pi = new ArrayList<>(this.pi); - shuffle(this.pi); - score(this.pi); - } public List getShuffledVariables() { List variables = getPi(); @@ -861,6 +535,7 @@ public List getShuffledVariables() { return variables; } + /** * Returns True iff a is adjacent to b in the current graph. * @@ -873,10 +548,6 @@ public boolean adjacent(Node a, Node b) { return getParents(a).contains(b) || getParents(b).contains(a); } - public boolean ancestorAdjacent(Node a, Node b) { - if (a == b) return false; - return getAncestors(a).contains(b) || getAncestors(b).contains(a); - } /** * Returns true iff [a, b, c] is a collider. @@ -890,9 +561,6 @@ public boolean collider(Node a, Node b, Node c) { return getParents(b).contains(a) && getParents(b).contains(c); } - public boolean ancestralCollider(Node a, Node b, Node c) { - return getAncestors(b).contains(a) && getAncestors(b).contains(c); - } /** * Returns true iff [a, b, c] is a triangle. @@ -906,6 +574,7 @@ 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. * @@ -924,28 +593,14 @@ public boolean clique(List W) { return true; } -// /** -// * A convenience method to reset the score cache if it becomes larger than a certain -// * size. -// * -// * @param maxSize The maximum size of the score cache; it the if the score cache is -// * larger than this it will be cleared. -// */ -// public void resetCacheIfTooBig(int maxSize) { -// if (this.cache.size() > maxSize) { -// this.cache = new HashMap<>(); -// System.out.println("Clearing cacche..."); -// System.gc(); -// } -// } 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; - } + 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; } } } @@ -953,11 +608,13 @@ 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); @@ -985,37 +642,6 @@ private void updateScores(int i1, int i2) { // return chunk; // } - private double score(Node n, Set pi) { - if (this.cachingScores) { - this.cache.computeIfAbsent(n, w -> new HashMap<>()); - Double 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); - } - - if (mag != null) { - ((edu.cmu.tetrad.search.MagSemBicScore) score).setMag(mag); - } - - double v = (double) this.score.localScore(this.variablesHash.get(n), parentIndices); - - if (this.cachingScores) { - this.cache.computeIfAbsent(n, w -> new HashMap<>()); - this.cache.get(n).put(new HashSet<>(pi), v); - } - - return v; - } public Set getPrefix(int i) { Set prefix = new HashSet<>(); @@ -1027,42 +653,46 @@ 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); - } +// 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; +// } +// } - return true; - } - } private void recalculate(int p) { if (this.prefixes.get(p) == null || !this.prefixes.get(p).containsAll(getPrefix(p))) { @@ -1076,12 +706,14 @@ 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); @@ -1102,154 +734,34 @@ private boolean lastMoveSame(int i1, int i2) { return true; } + @NotNull 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); - Set parents = new HashSet<>(); - boolean changed = true; - - double sMax = score(n, new HashSet<>()); - List prefix = new ArrayList<>(getPrefix(p)); - -// Set prefix = new HashSet<>(getPrefix(p)); -// LinkedHashSet parents = new LinkedHashSet<>(); -// double sMax = GST.growShrink(n, prefix, parents); -// -// return new Pair(parents, Double.isNaN(sMax) ? Double.NEGATIVE_INFINITY : sMax); - - - // 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); - - if (!knowledge.isEmpty() && knowledge.isRequired(z0.getName(), n.getName())) continue; - - double 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)) { - if (!knowledge.isEmpty() && knowledge.isRequired(z0.getName(), n.getName())) continue; - - parents.remove(z0); - - double s2 = score(n, parents); - - if (s2 > sMax) { - sMax = s2; - w = z0; - } - - parents.add(z0); - } - - if (w != null) { - parents.remove(w); - changed2 = true; - } - } - -// while (changed2) { -// changed2 = false; -// -// List aaa = null; -// -// List pp = new ArrayList<>(parents); -// -// SublistGenerator gen = new SublistGenerator(parents.size(), 2); -// int[] choice; -// -// while ((choice = gen.next()) != null) { -// List aa = GraphUtils.asList(choice, pp); -// -//// for (Node z0 : new HashSet<>(parents)) { -//// if (!knowledge.isEmpty() && knowledge.isRequired(z0.getName(), n.getName())) continue; -//// -// aa.forEach(parents::remove); -// -// double s2 = score(n, parents); -// -// if (s2 > sMax) { -// sMax = s2; -// aaa = aa; -// } -// -// parents.addAll(aa); -// } -// -// if (aaa != null) { -// aaa.forEach(parents::remove); -// changed2 = true; -// } -// -// } - - if (this.useScore) { - return new Pair(parents, Double.isNaN(sMax) ? Double.NEGATIVE_INFINITY : sMax); - } else { - return new Pair(parents, -parents.size()); - } + 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<>(); - Set prefix = getPrefix(p); boolean changed1 = true; - while (changed1) { changed1 = false; for (Node z0 : prefix) { if (parents.contains(z0)) continue; if (!knowledge.isEmpty() && this.knowledge.isForbidden(z0.getName(), n.getName())) continue; - if (!knowledge.isEmpty() && this.knowledge.isRequired(z0.getName(), n.getName())) { parents.add(z0); continue; } - if (this.test.checkIndependence(n, z0, new ArrayList<>(parents)).dependent()) { parents.add(z0); changed1 = true; @@ -1260,9 +772,7 @@ private Pair getGrowShrinkIndependent(int p) { if (!knowledge.isEmpty() && this.knowledge.isRequired(z1.getName(), n.getName())) { continue; } - parents.remove(z1); - if (this.test.checkIndependence(n, z1, new ArrayList<>(parents)).dependent()) { parents.add(z1); } else { @@ -1274,6 +784,7 @@ private Pair getGrowShrinkIndependent(int p) { return new Pair(parents, -parents.size()); } + private Pair getParentsInternal(int p) { if (this.useRaskuttiUhler) { return getRaskuttiUhlerParents(p); @@ -1312,6 +823,7 @@ private Pair getRaskuttiUhlerParents(int p) { return new Pair(parents, -parents.size()); } + public Set> getSkeleton() { List order = getPi(); Set> skeleton = new HashSet<>(); @@ -1329,30 +841,11 @@ public Set> getSkeleton() { } -// public void moveToNoUpdate(Node v, int toIndex) { -// bookmark(-55); -// -// 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 (violatesKnowledge(this.pi)) { -// goToBookmark(-55); -// } -// -// } - 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/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index eda81e20ae..07688b6c5c 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 @@ -210,7 +210,6 @@ private static void runTestLoop(Graph g, List order, Score score, Independ Grasp grasp = getGrasp(score, test); - grasp.setCacheScores(true); grasp.setNumStarts(1); grasp.setVerbose(true); List perm = grasp.bestOrder(order); @@ -1541,7 +1540,6 @@ public void bryanCheckDensityClaims() { grasp.setUseRaskuttiUhler(usePearl); grasp.setOrdered(true); grasp.setVerbose(false); - grasp.setCacheScores(false); int count = 0; @@ -2096,7 +2094,6 @@ public void testRaskutti() { IndTestDSep test = new IndTestDSep(facts.getFacts()); OtherPermAlgs otherPermAlgs = new OtherPermAlgs(test); - otherPermAlgs.setCacheScores(true); otherPermAlgs.setMethod(SP); otherPermAlgs.setNumStarts(1); From 6cb9dc5b79cdfad56b334935f246f745b1ad91e5 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 25 Mar 2023 20:06:38 -0400 Subject: [PATCH 27/58] Blocking .DS_STOREs in .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index dd5611b7d6..44d3334adc 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,8 @@ tetrad-gui.log /testboostrap/CalibrationConstraintBased/RFCI/RandomGraph-Vars20-Edges80-Cases1000-BS5-H0.1-a0.001/PAG_v20_e80_c1000_b5_-1.txt /testboostrap/CalibrationConstraintBased/RFCI/RandomGraph-Vars20-Edges80-Cases1000-BS5-H0.1-a0.001/probs_v20_e80_c1000_b5_-1.txt /target/ + +.DS_Store +._.DS_Store +**/.DS_Store +**/._.DS_Store From a40f855bf0fbb50919fda246cd5e617df20efa95 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sun, 26 Mar 2023 09:53:02 -0400 Subject: [PATCH 28/58] Update README.md --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 492363fd9e..84f2f341ec 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,6 @@ To download the current jar you can use to launch the Tetrad GUI, click this lin https://s01.oss.sonatype.org/content/repositories/releases/io/github/cmu-phil/tetrad-gui/7.3.0/tetrad-gui-7.3.0-launch.jar. -The application will work on all major platforms once a recent version of the Java JRE/JCK is installed, certainly -__greater than version 1.8 (version 8)__. We find that the most -recent [Corretto JRE/JDK](https://aws.amazon.com/corretto/?filtered-posts.sort-by=item.additionalFields.createdDate&filtered-posts.sort-order=desc) -with long term support (LTS) works well cross-platform. - 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 any case, on all platforms, the jar may be launched at the command line (with a specification of the amount of RAM you From 50811d964074376c728954396b449655b19a768c Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Sun, 26 Mar 2023 11:17:57 -0400 Subject: [PATCH 29/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84f2f341ec..4de53ebe3b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ version of Tetrad and Causal Command. ## Setting up Java -For setting up Java, see our [Wiki article on the topic](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java:-Tutorial-for-Newbies-and-Experts-Alike). +You will need to set up Java on your machine. For setting up Java, see our [Wiki article on the topic](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java:-Tutorial-for-Newbies-and-Experts-Alike). ## Tetrad GUI Application From c1625668d654c223e440a1e1fd46a0f2b9da1017 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Mon, 27 Mar 2023 14:14:29 -0500 Subject: [PATCH 30/58] fixed issue in graphToLavaan --- .../src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6a38388de7..eac2cd9469 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 @@ -725,7 +725,7 @@ public static String graphToLavaan(Graph g) { if (e.getProximalEndpoint(a) != Endpoint.ARROW) continue; if (e.getProximalEndpoint(b) == Endpoint.TAIL) parents.get(a).add(b); if (siblings.containsKey(b)) continue; - if (e.getProximalEndpoint(b) == Endpoint.ARROW) parents.get(a).add(b); + if (e.getProximalEndpoint(b) == Endpoint.ARROW) siblings.get(a).add(b); } } From 3f5f61afd7192eb284cf68e3186a3fc0ff70d7d3 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Wed, 29 Mar 2023 15:33:52 -0400 Subject: [PATCH 31/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4de53ebe3b..c0403e46be 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 article on the topic](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java:-Tutorial-for-Newbies-and-Experts-Alike). +You will need to set up Java on your machine. For setting up Java, see our [Wiki article on the topic](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java-for-Tetrad). ## Tetrad GUI Application From cb02e07d9c1bff93ee07441f6fa06db2435f41ac Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Wed, 29 Mar 2023 15:34:38 -0400 Subject: [PATCH 32/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c0403e46be..a2c505a4b0 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 article on the topic](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 artible, [Setting up Java for Tetrad](https://github.com/cmu-phil/tetrad/wiki/Setting-up-Java-for-Tetrad). ## Tetrad GUI Application From 0a0ddfc61b2dea6c8fea73a8f7e9a08b2c58d9b9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Fri, 31 Mar 2023 23:03:24 -0400 Subject: [PATCH 33/58] Blocking .DS_STOREs in .gitignore --- data-reader/pom.xml | 2 +- tetrad-lib/pom.xml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data-reader/pom.xml b/data-reader/pom.xml index de18b973ed..a1142682df 100644 --- a/data-reader/pom.xml +++ b/data-reader/pom.xml @@ -35,7 +35,7 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4.1 + 2.14.2 diff --git a/tetrad-lib/pom.xml b/tetrad-lib/pom.xml index 0be68b7c74..21ed1a6583 100644 --- a/tetrad-lib/pom.xml +++ b/tetrad-lib/pom.xml @@ -115,7 +115,7 @@ org.json json - 20220924 + 20230227 @@ -130,7 +130,7 @@ org.jsoup jsoup - 1.15.3 + 1.15.4 @@ -142,7 +142,7 @@ org.jetbrains annotations - 23.1.0 + 24.0.1 compile From 7e879cb7281efd869248087a4f2fc713317164aa Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 2 Apr 2023 11:16:54 -0400 Subject: [PATCH 34/58] Cleaning up code for SvarFci and SvarGfci. --- .../java/edu/cmu/tetrad/search/SvarFci.java | 92 +++------------- .../java/edu/cmu/tetrad/search/SvarGFci.java | 101 ++++-------------- 2 files changed, 35 insertions(+), 158 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 ee63dc65d3..ca23b446e9 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 @@ -31,11 +31,7 @@ import org.apache.commons.math3.util.FastMath; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - /** * Extends Erin Korber's implementation of the Fast Causal Inference algorithm (found in FCI.java) with Jiji Zhang's @@ -69,15 +65,10 @@ public final class SvarFci implements GraphSearch { */ private Knowledge knowledge = new Knowledge(); - /** - * The variables to search over (optional) - */ - private final List variables = new ArrayList<>(); - 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; @@ -114,37 +105,6 @@ public SvarFci(IndependenceTest independenceTest) { } this.independenceTest = independenceTest; - this.variables.addAll(independenceTest.getVariables()); - buildIndexing(independenceTest.getVariables()); - - } - - /** - * Constructs a new FCI search for the given independence test and background knowledge and a list of variables to - * search over. - */ - public SvarFci(IndependenceTest independenceTest, List searchVars) { - if (independenceTest == null) { - throw new NullPointerException(); - } - - this.independenceTest = independenceTest; - this.variables.addAll(independenceTest.getVariables()); - - Set remVars = new HashSet<>(); - for (Node node1 : this.variables) { - boolean search = false; - for (Node node2 : searchVars) { - if (node1.getName().equals(node2.getName())) { - search = true; - } - } - if (!search) { - remVars.add(node1); - } - } - this.variables.removeAll(remVars); - } //========================PUBLIC METHODS==========================// @@ -176,7 +136,6 @@ public Graph search(IFas fas) { fas.setKnowledge(getKnowledge()); fas.setDepth(this.depth); fas.setVerbose(this.verbose); - //fas.setExternalGraph(externalGraph); this.graph = fas.search(); this.sepsets = fas.getSepsets(); @@ -185,14 +144,10 @@ public Graph search(IFas fas) { SepsetProducer sp = new SepsetsPossibleDsep(this.graph, this.independenceTest, this.knowledge, this.depth, this.maxPathLength); sp.setVerbose(this.verbose); - // The original FCI, with or without JiJi Zhang's orientation rules - // // Optional step: Possible Dsep. (Needed for correctness but very time consuming.) if (isPossibleDsepSearchDone()) { -// long time1 =edu.cmu.tetrad.util.Timer.currentThreadCpuTimeMilliseconds(); SvarFciOrient svarFciOrient = new SvarFciOrient(new SepsetsSet(this.sepsets, this.independenceTest), this.independenceTest); svarFciOrient.setKnowledge(this.knowledge); svarFciOrient.ruleR0(this.graph); -// new SvarFciOrient(new SepsetsSet(this.sepsets, independenceTest), independenceTest).ruleR0(graph); for (Edge edge : new ArrayList<>(this.graph.getEdges())) { Node x = edge.getNode1(); @@ -212,23 +167,6 @@ public Graph search(IFas fas) { } } - -// long time2 =edu.cmu.tetrad.util.Timer.currentThreadCpuTimeMilliseconds(); -// logger.log("info", "Step C: " + (time2 - time1) / 1000. + "s"); -// -// // Step FCI D. -// long time3 =edu.cmu.tetrad.util.Timer.currentThreadCpuTimeMilliseconds(); -// -// System.out.println("Starting possible dsep search"); -// PossibleDsepFci possibleDSep = new PossibleDsepFci(graph, independenceTest); -// possibleDSep.setMaxDegree(getPossibleDsepDepth()); -// possibleDSep.setKnowledge(getKnowledge()); -// possibleDSep.setMaxPathLength(maxPathLength); -// this.sepsets.addAll(possibleDSep.search()); -// long time4 =edu.cmu.tetrad.util.Timer.currentThreadCpuTimeMilliseconds(); -// logger.log("info", "Step D: " + (time4 - time3) / 1000. + "s"); -// System.out.println("Starting possible dsep search"); - // Reorient all edges as o-o. this.graph.reorientAllWith(Endpoint.CIRCLE); } @@ -333,28 +271,24 @@ public void setPenaltyDiscount(double penaltyDiscount) { //===========================PRIVATE METHODS=========================// - private void buildIndexing(List nodes) { - ConcurrentHashMap hashIndices = new ConcurrentHashMap<>(); - for (Node node : nodes) { - hashIndices.put(node, this.variables.indexOf(node)); - } - } - // removeSimilarPairs based on orientSimilarPairs in SvarFciOrient.java by Entner and Hoyer // this version removes edges from graph instead of list of adjacencies private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List condSet) { System.out.println("Entering removeSimilarPairs method..."); System.out.println("original independence: " + x + " and " + y + " conditional on " + condSet); + if (x.getName().equals("time") || y.getName().equals("time")) { System.out.println("Not removing similar pairs b/c variable pair includes time."); return; } + for (Node tempNode : condSet) { if (tempNode.getName().equals("time")) { System.out.println("Not removing similar pairs b/c conditioning set includes time."); return; } } + int ntiers = this.knowledge.getNumTiers(); int indx_tier = this.knowledge.isInWhichTier(x); int indy_tier = this.knowledge.isInWhichTier(y); @@ -362,9 +296,7 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List tier_x = this.knowledge.getTier(indx_tier); -// Collections.sort(tier_x); List tier_y = this.knowledge.getTier(indy_tier); -// Collections.sort(tier_y); int i; for (i = 0; i < tier_x.size(); ++i) { @@ -389,15 +321,15 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List= 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 = tmp_tier1.get(indx_comp); B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; @@ -415,8 +347,8 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List temptier = this.knowledge.getTier(ind_temptier); -// Collections.sort(temptier); int ind_temp = -1; + for (int j = 0; j < temptier.size(); ++j) { if (Thread.currentThread().isInterrupted()) { break; @@ -427,8 +359,10 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List (ntiers - 1) || this.knowledge.getTier(condAB_tier).size() == 1) { // added condition for time tier 05.29.2016 System.out.println("Warning: For nodes " + x1 + "," + y1 + " the conditioning variable is outside " @@ -436,7 +370,6 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List new_tier = this.knowledge.getTier(condAB_tier); -// Collections.sort(new_tier); String tempNode1 = new_tier.get(ind_temp); System.out.println("adding variable " + tempNode1 + " to SepSet"); condSetAB.add(test.getVariable(tempNode1)); @@ -445,9 +378,7 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, 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 = tmp_tier1.get(indx_comp); B = tmp_tier2.get(indy_comp); if (A.equals(B)) continue; @@ -465,8 +396,8 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List temptier = this.knowledge.getTier(ind_temptier); -// Collections.sort(temptier); int ind_temp = -1; + for (int j = 0; j < temptier.size(); ++j) { if (getNameNoLag(tempNode.getName()).equals(getNameNoLag(temptier.get(j)))) { ind_temp = j; @@ -476,14 +407,15 @@ private void removeSimilarPairs(IndependenceTest test, Node x, Node y, List (ntiers - 1) || this.knowledge.getTier(condAB_tier).size() == 1) { // added condition for time tier 05.29.2016 System.out.println("Warning: For nodes " + x1 + "," + y1 + " the conditioning variable is outside " + "of window, so not added to SepSet"); continue; } + List new_tier = this.knowledge.getTier(condAB_tier); -// Collections.sort(new_tier); String tempNode1 = new_tier.get(ind_temp); System.out.println("adding variable " + tempNode1 + " to SepSet"); condSetAB.add(test.getVariable(tempNode1)); 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 e1fdbc2ab6..6b090a3542 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 @@ -24,14 +24,11 @@ import edu.cmu.tetrad.data.*; 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.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; /** @@ -58,9 +55,6 @@ */ public final class SvarGFci implements GraphSearch { - // If a graph is provided. - private final Graph dag = null; - // The PAG being constructed. private Graph graph; @@ -68,7 +62,6 @@ public final class SvarGFci implements GraphSearch { private Knowledge knowledge = new Knowledge(); // The variables to search over (optional) - private final List variables = new ArrayList<>(); // The conditional independence test. private IndependenceTest independenceTest; @@ -117,8 +110,6 @@ public final class SvarGFci implements GraphSearch { private SepsetProducer sepsets; - private final int depth = -1; - //============================CONSTRUCTORS============================// /** @@ -137,14 +128,12 @@ public SvarGFci(IndependenceTest test, Score score) { public Graph search() { - long time1 = MillisecondTimes.timeMillis(); - List nodes = getIndependenceTest().getVariables(); this.logger.log("info", "Starting svarGFCI algorithm."); this.logger.log("info", "Independence test = " + getIndependenceTest() + "."); - this.graph = new EdgeListGraph(nodes); + this.graph = new EdgeListGraph(independenceTest.getVariables()); if (this.score == null) { setScore(); @@ -158,11 +147,9 @@ public Graph search() { this.graph = fges.search(); Graph fgesGraph = new EdgeListGraph(this.graph); -// System.out.println("GFCI: FGES done"); - this.sepsets = new SepsetsGreedy(fgesGraph, this.independenceTest, null, this.maxIndegree); - for (Node b : nodes) { + for (Node b : independenceTest.getVariables()) { List adjacentNodes = fgesGraph.getAdjacentNodes(b); if (adjacentNodes.size() < 2) { @@ -213,7 +200,7 @@ private void setScore() { Score score; if (this.independenceTest instanceof IndTestDSep) { - score = new GraphScore(this.dag); + score = new GraphScore(((IndTestDSep) independenceTest).getGraph()); } else if (cov != null) { this.covarianceMatrix = cov; SemBicScore score0 = new SemBicScore(cov); @@ -396,17 +383,6 @@ public void setFaithfulnessAssumed(boolean faithfulnessAssumed) { //===========================================PRIVATE METHODS=======================================// - private void buildIndexing(List nodes) { - // Map from variables to their column indices in the data set. - ConcurrentMap hashIndices = new ConcurrentHashMap<>(); - - int i = 0; - - for (Node node : nodes) { - hashIndices.put(node, i++); - } - } - /** * Orients according to background knowledge */ @@ -466,25 +442,6 @@ public void setStructurePrior(double structurePrior) { this.structurePrior = structurePrior; } - private int freeDegree(List nodes, Graph graph) { - int max = 0; - - for (Node x : nodes) { - List opposites = graph.getAdjacentNodes(x); - - for (Node y : opposites) { - Set adjx = new HashSet<>(opposites); - adjx.remove(y); - - if (adjx.size() > max) { - max = adjx.size(); - } - } - } - - return max; - } - private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y) { if (x.getName().equals("time") || y.getName().equals("time")) { return; @@ -496,10 +453,8 @@ 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); -// Collections.sort(tier_x); - List tier_y = knowledge.getTier(indy_tier); -// Collections.sort(tier_y); + List tier_x = knowledge.getTier(indx_tier); + List tier_y = knowledge.getTier(indy_tier); int i; for (i = 0; i < tier_x.size(); ++i) { @@ -526,12 +481,10 @@ 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); -// Collections.sort(tmp_tier1); - List tmp_tier2 = knowledge.getTier(i); -// Collections.sort(tmp_tier2); - A = (String) tmp_tier1.get(indx_comp); - B = (String) tmp_tier2.get(indy_comp); + List tmp_tier1 = knowledge.getTier(i + tier_diff); + List tmp_tier2 = knowledge.getTier(i); + 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; @@ -543,8 +496,6 @@ private void orientSimilarPairs(Graph graph, Knowledge knowledge, Node x, Node y graph.setEndpoint(x1, y1, Endpoint.ARROW); 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); } } @@ -570,10 +521,8 @@ private List> returnSimilarPairs(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 = 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) { @@ -606,19 +555,15 @@ private List> returnSimilarPairs(Node x, Node y) { 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; @@ -641,11 +586,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 1d2a312be6372f25d3a38b64a038f37c5935a0ec Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 2 Apr 2023 11:18:29 -0400 Subject: [PATCH 35/58] Cleaning up code for SvarFci and SvarGfci. --- .../algorithm/oracle/pag/{SvarFci.java => SVAR_FCI.java} | 8 ++++---- .../oracle/pag/{SvarGfci.java => SVAR_GFCI.java} | 8 ++++---- .../examples/ExampleCompareSimulationTimeSeries.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{SvarFci.java => SVAR_FCI.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{SvarGfci.java => SVAR_GFCI.java} (94%) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java index b96ceed770..9b3c958dc2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java @@ -35,16 +35,16 @@ ) @TimeSeries @Bootstrapping -public class SvarFci implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class SVAR_FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge; - public SvarFci() { + public SVAR_FCI() { } - public SvarFci(IndependenceWrapper test) { + public SVAR_FCI(IndependenceWrapper test) { this.test = test; } @@ -71,7 +71,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return search.search(); } else { - SvarFci svarFci = new SvarFci(this.test); + SVAR_FCI svarFci = new SVAR_FCI(this.test); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, svarFci, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java index af4071c333..d48a5c2be3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java @@ -37,17 +37,17 @@ ) @TimeSeries @Bootstrapping -public class SvarGfci implements Algorithm, HasKnowledge, TakesIndependenceWrapper, UsesScoreWrapper { +public class SVAR_GFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper, UsesScoreWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge; - public SvarGfci() { + public SVAR_GFCI() { } - public SvarGfci(IndependenceWrapper type, ScoreWrapper score) { + public SVAR_GFCI(IndependenceWrapper type, ScoreWrapper score) { this.test = type; this.score = score; } @@ -77,7 +77,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return search.search(); } else { - SvarGfci algorithm = new SvarGfci(this.test, this.score); + SVAR_GFCI algorithm = new SVAR_GFCI(this.test, this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java index 91bf2a369d..2fabfb7e5d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulationTimeSeries.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SvarFci; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SvarGfci; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SVAR_FCI; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.SVAR_GFCI; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.independence.FisherZ; import edu.cmu.tetrad.algcomparison.score.SemBicScore; @@ -66,8 +66,8 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new SvarFci(new FisherZ())); - algorithms.add(new SvarGfci(new FisherZ(), new SemBicScore())); + algorithms.add(new SVAR_FCI(new FisherZ())); + algorithms.add(new SVAR_GFCI(new FisherZ(), new SemBicScore())); Simulations simulations = new Simulations(); From 6fe13462e42decc85c70bd42585ea1be9848afd9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sun, 2 Apr 2023 11:33:23 -0400 Subject: [PATCH 36/58] Capitalized algorithm wrapper names and deleted some deprecated ones. --- .../editor/AlgorithmParameterPanel.java | 12 +- .../editor/search/AlgorithmCard.java | 4 +- .../model/GeneralAlgorithmRunner.java | 4 +- .../edu/cmu/tetradapp/test/FgsApiExample.java | 4 +- .../algorithm/AlgorithmFactory.java | 6 +- .../algcomparison/algorithm/cluster/BPC.java | 2 +- ...rAlgorithm.java => CLUSTER_ALGORITHM.java} | 2 +- .../algcomparison/algorithm/cluster/FOFC.java | 2 +- .../algcomparison/algorithm/cluster/FTFC.java | 2 +- .../continuous/dag/{Ling.java => LING.java} | 4 +- .../dag/{Lingam.java => LINGAM.java} | 4 +- .../algorithm/mixed/{Mgm.java => MGM.java} | 9 +- ...ixedFgesDiscretingContinuousVariables.java | 106 ----------- ...MixedFgesTreatingDiscreteAsContinuous.java | 95 ---------- ...tenated.java => CCD_MAX_CONCATENATED.java} | 8 +- ...ncatenated.java => FASK_CONCATENATED.java} | 10 +- ...nated.java => FASK_LOFS_CONCATENATED.java} | 8 +- .../multi/{FaskVote.java => FASK_VOTE.java} | 12 +- .../multi/{FasLofs.java => FAS_LOFS.java} | 6 +- ...oncatenated.java => FGES_CONCATENTED.java} | 12 +- .../multi/{Images.java => IMAGES.java} | 12 +- .../algorithm/multi/ImagesBDeu.java | 147 -------------- .../algorithm/multi/ImagesPcStableMax.java | 150 --------------- .../algorithm/multi/ImagesSemBic.java | 179 ------------------ .../algorithm/multi/MultiFaskV1.java | 161 ---------------- .../multi/PcStableMaxConcatenated.java | 164 ---------------- .../oracle/cpdag/{Fges.java => FGES.java} | 8 +- .../cpdag/{FgesMb.java => FGES_MB.java} | 8 +- ...Measurement.java => FGES_MEASUREMENT.java} | 6 +- .../oracle/cpdag/{GesMe.java => GES_ME.java} | 8 +- .../cpdag/{GRaSPTol.java => GRASP_TOL.java} | 8 +- .../oracle/cpdag/{Pcd.java => PCD.java} | 6 +- .../cpdag/{PcStable.java => PC_STABLE.java} | 8 +- .../algorithm/oracle/cpdag/PcAll.java | 171 ----------------- ...gleGraphAlg.java => SINGLE_GRAPH_ALG.java} | 4 +- .../oracle/pag/{CcdMax.java => CCD_MAX.java} | 6 +- .../oracle/pag/{Cfci.java => CFCI.java} | 6 +- .../oracle/pag/{Fci.java => FCI.java} | 8 +- .../oracle/pag/{FciMax.java => FCI_MAX.java} | 8 +- ...mplingRfci.java => PAG_SAMPLING_RFCI.java} | 2 +- .../oracle/pag/{Rfci.java => RFCI.java} | 8 +- .../pag/{RfciBsc.java => RFCI_BSC.java} | 2 +- .../oracle/pattern/{CStaR.java => CSTAR.java} | 4 +- ...ctorAnalysis.java => FACTOR_ANALYSIS.java} | 4 +- .../other/{Glasso.java => GLASSO.java} | 4 +- .../pairwise/{FaskPW.java => FASK_PW.java} | 8 +- .../pairwise/{RSkew.java => RSKEW.java} | 8 +- .../pairwise/{RSkewE.java => RSKEW_E.java} | 8 +- .../pairwise/{Skew.java => SKEW.java} | 8 +- .../pairwise/{SkewE.java => SKEW_E.java} | 8 +- .../pairwise/{Tanh.java => TAHN.java} | 6 +- .../examples/ExampleCompareSimulation2.java | 4 +- .../examples/MVPCompareFromFiles.java | 4 +- .../algcomparison/examples/TestBoss.java | 5 +- .../examples/TestDegenerateGaussian.java | 10 +- .../java/edu/cmu/tetrad/search/FaskVote.java | 4 +- .../tetrad/study/Conditions/Condition1.java | 4 +- .../study/ExampleCompareSimulation.java | 4 +- .../ExampleCompareSimulationDiscrete.java | 15 +- .../tetrad/study/ExampleFirstInflection.java | 4 +- .../edu/cmu/tetrad/study/ExampleStARS.java | 8 +- .../edu/cmu/tetrad/study/LingamStudy.java | 8 +- .../TestConditionalGaussianSimulation.java | 4 +- .../java/edu/cmu/tetrad/test/TestFges.java | 5 +- .../java/edu/cmu/tetrad/test/TestFgesFa.java | 4 +- .../test/TestGeneralResamplingTest.java | 12 +- .../java/edu/cmu/tetrad/test/TestGrasp.java | 26 +-- .../cmu/tetrad/test/TestImagesSimulation.java | 6 +- .../tetrad/test/TestKunMeasurementError.java | 8 +- .../cmu/tetrad/test/TestSimulatedFmr3.java | 4 +- .../cmu/tetrad/test/TestSimulatedFmri.java | 8 +- 71 files changed, 210 insertions(+), 1387 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/{ClusterAlgorithm.java => CLUSTER_ALGORITHM.java} (78%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/{Ling.java => LING.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/{Lingam.java => LINGAM.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/{Mgm.java => MGM.java} (96%) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/cpdag/MixedFgesDiscretingContinuousVariables.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/cpdag/MixedFgesTreatingDiscreteAsContinuous.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/{CcdMaxConcatenated.java => CCD_MAX_CONCATENATED.java} (94%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/{FaskConcatenated.java => FASK_CONCATENATED.java} (93%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/{FasLofsConcatenated.java => FASK_LOFS_CONCATENATED.java} (94%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/{FaskVote.java => FASK_VOTE.java} (93%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/{FasLofs.java => FAS_LOFS.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/{FgesConcatenated.java => FGES_CONCATENTED.java} (93%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/{Images.java => IMAGES.java} (96%) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesBDeu.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesPcStableMax.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesSemBic.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/MultiFaskV1.java delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/PcStableMaxConcatenated.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{Fges.java => FGES.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{FgesMb.java => FGES_MB.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{FgesMeasurement.java => FGES_MEASUREMENT.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{GesMe.java => GES_ME.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{GRaSPTol.java => GRASP_TOL.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{Pcd.java => PCD.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{PcStable.java => PC_STABLE.java} (94%) delete mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcAll.java rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{SingleGraphAlg.java => SINGLE_GRAPH_ALG.java} (92%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{CcdMax.java => CCD_MAX.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{Cfci.java => CFCI.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{Fci.java => FCI.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{FciMax.java => FCI_MAX.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{PagSamplingRfci.java => PAG_SAMPLING_RFCI.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{Rfci.java => RFCI.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{RfciBsc.java => RFCI_BSC.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/{CStaR.java => CSTAR.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/{FactorAnalysis.java => FACTOR_ANALYSIS.java} (98%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/{Glasso.java => GLASSO.java} (97%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/{FaskPW.java => FASK_PW.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/{RSkew.java => RSKEW.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/{RSkewE.java => RSKEW_E.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/{Skew.java => SKEW.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/{SkewE.java => SKEW_E.java} (95%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/{Tanh.java => TAHN.java} (95%) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AlgorithmParameterPanel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AlgorithmParameterPanel.java index a0eecf53eb..e586f08431 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AlgorithmParameterPanel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/AlgorithmParameterPanel.java @@ -19,8 +19,8 @@ package edu.cmu.tetradapp.editor; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.PagSamplingRfci; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.RfciBsc; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.PAG_SAMPLING_RFCI; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.RFCI_BSC; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; import edu.cmu.tetrad.annotation.Score; @@ -74,7 +74,7 @@ public void addToPanel(GeneralAlgorithmRunner algorithmRunner) { Parameters parameters = algorithmRunner.getParameters(); // Hard-coded parameter groups for Rfci-Bsc - if (algorithm instanceof RfciBsc) { + if (algorithm instanceof RFCI_BSC) { // Phase one: PAG and constraints candidates Searching String title = algorithm .getClass().getAnnotation(edu.cmu.tetrad.annotation.Algorithm.class).name(); @@ -107,7 +107,7 @@ public void addToPanel(GeneralAlgorithmRunner algorithmRunner) { this.mainPanel.add(createSubPanel(title, params, parameters)); this.mainPanel.add(Box.createVerticalStrut(10)); - } else if (algorithm instanceof PagSamplingRfci) { + } else if (algorithm instanceof PAG_SAMPLING_RFCI) { String title = algorithm.getClass().getAnnotation(edu.cmu.tetrad.annotation.Algorithm.class).name(); Set params = new LinkedHashSet<>(); @@ -118,13 +118,13 @@ public void addToPanel(GeneralAlgorithmRunner algorithmRunner) { title = "RFCI Parameters"; params.clear(); - params.addAll(PagSamplingRfci.RFCI_PARAMETERS); + params.addAll(PAG_SAMPLING_RFCI.RFCI_PARAMETERS); this.mainPanel.add(createSubPanel(title, params, parameters)); this.mainPanel.add(Box.createVerticalStrut(10)); title = "Probabilistic Test Parameters"; params.clear(); - params.addAll(PagSamplingRfci.PROBABILISTIC_TEST_PARAMETERS); + params.addAll(PAG_SAMPLING_RFCI.PROBABILISTIC_TEST_PARAMETERS); this.mainPanel.add(createSubPanel(title, params, parameters)); this.mainPanel.add(Box.createVerticalStrut(10)); } else { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/search/AlgorithmCard.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/search/AlgorithmCard.java index e10df9398d..3313665a67 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/search/AlgorithmCard.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/search/AlgorithmCard.java @@ -20,7 +20,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.AlgorithmFactory; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.SingleGraphAlg; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.SINGLE_GRAPH_ALG; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesExternalGraph; import edu.cmu.tetrad.annotation.*; @@ -391,7 +391,7 @@ public Algorithm getAlgorithmFromInterface(AlgorithmModel algoModel, Independenc // Those pairwise algos (R3, RShew, Skew..) require source graph to initialize - Zhou if (algorithm != null && algorithm instanceof TakesExternalGraph && this.algorithmRunner.getSourceGraph() != null && !this.algorithmRunner.getDataModelList().isEmpty()) { - Algorithm externalGraph = new SingleGraphAlg(this.algorithmRunner.getSourceGraph()); + Algorithm externalGraph = new SINGLE_GRAPH_ALG(this.algorithmRunner.getSourceGraph()); ((TakesExternalGraph) algorithm).setExternalGraph(externalGraph); } 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..7422958561 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 @@ -22,7 +22,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; -import edu.cmu.tetrad.algcomparison.algorithm.cluster.ClusterAlgorithm; +import edu.cmu.tetrad.algcomparison.algorithm.cluster.CLUSTER_ALGORITHM; import edu.cmu.tetrad.algcomparison.independence.DSeparationTest; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.independence.TakesGraph; @@ -316,7 +316,7 @@ public void execute() { graphList.add(((MultiDataSetAlgorithm) algo).search(sub, this.parameters)); } - } else if (getAlgorithm() instanceof ClusterAlgorithm) { + } else if (getAlgorithm() instanceof CLUSTER_ALGORITHM) { for (int k = 0; k < this.parameters.getInt("numRuns"); k++) { getDataModelList().forEach(dataModel -> { if (dataModel instanceof ICovarianceMatrix) { diff --git a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/FgsApiExample.java b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/FgsApiExample.java index c53712d252..892f71e7db 100644 --- a/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/FgsApiExample.java +++ b/tetrad-gui/src/test/java/edu/cmu/tetradapp/test/FgsApiExample.java @@ -2,7 +2,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.AlgorithmFactory; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.score.ConditionalGaussianBicScore; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; @@ -71,7 +71,7 @@ public static void main(String[] args) throws Exception { //Algorithm fges = AlgorithmFactory.create(Fges.class, null, BdeuScore.class); // for mixed data can use Conditional Gaussian - Algorithm fges = AlgorithmFactory.create(Fges.class, null, ConditionalGaussianBicScore.class); + Algorithm fges = AlgorithmFactory.create(FGES.class, null, ConditionalGaussianBicScore.class); // Set algorithm parameters diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/AlgorithmFactory.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/AlgorithmFactory.java index d608af095b..910164312d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/AlgorithmFactory.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/AlgorithmFactory.java @@ -18,7 +18,7 @@ */ package edu.cmu.tetrad.algcomparison.algorithm; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.SingleGraphAlg; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.SINGLE_GRAPH_ALG; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.TakesExternalGraph; @@ -69,7 +69,7 @@ public static Algorithm create(Class algoClass, Independenc throws IllegalAccessException, InstantiationException { Algorithm algorithm = AlgorithmFactory.create(algoClass, test, score); if (externalGraph != null && algorithm instanceof TakesExternalGraph) { - ((TakesExternalGraph) algorithm).setExternalGraph(new SingleGraphAlg(externalGraph)); + ((TakesExternalGraph) algorithm).setExternalGraph(new SINGLE_GRAPH_ALG(externalGraph)); } return algorithm; @@ -91,7 +91,7 @@ public static Algorithm create(Class algoClass, Class nodes = dataSet.getVariables(); - - for (Node node : nodes) { - if (node instanceof ContinuousVariable) { - discretizer.equalIntervals(node, parameters.getInt(Params.NUM_CATEGORIES)); - } - } - - dataSet = discretizer.discretize(); - DataSet _dataSet = SimpleDataLoader.getDiscreteDataSet(dataSet); - Fges fges = new Fges(this.score.getScore(_dataSet, parameters)); - fges.setVerbose(parameters.getBoolean(Params.VERBOSE)); - Graph p = fges.search(); - return convertBack(_dataSet, p); - } else { - MixedFgesDiscretingContinuousVariables algorithm = new MixedFgesDiscretingContinuousVariables(this.score); - - 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 SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); - } - - @Override - public String getDescription() { - return "FGES after discretizing the continuous variables in the data set using " + this.score.getDescription(); - } - - private Graph convertBack(DataSet Dk, Graph p) { - Graph p2 = new EdgeListGraph(Dk.getVariables()); - - for (int i = 0; i < p.getNodes().size(); i++) { - for (int j = i + 1; j < p.getNodes().size(); j++) { - Node v1 = p.getNodes().get(i); - Node v2 = p.getNodes().get(j); - - Edge e = p.getEdge(v1, v2); - - if (e != null) { - Node w1 = Dk.getVariable(e.getNode1().getName()); - Node w2 = Dk.getVariable(e.getNode2().getName()); - - Edge e2 = new Edge(w1, w2, e.getEndpoint1(), e.getEndpoint2()); - - p2.addEdge(e2); - } - } - } - return p2; - } - - @Override - public DataType getDataType() { - return DataType.Mixed; - } - - @Override - public List getParameters() { - List parameters = this.score.getParameters(); - parameters.add(Params.NUM_CATEGORIES); - parameters.add(Params.VERBOSE); - return parameters; - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/cpdag/MixedFgesTreatingDiscreteAsContinuous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/cpdag/MixedFgesTreatingDiscreteAsContinuous.java deleted file mode 100644 index 2684586dc4..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/cpdag/MixedFgesTreatingDiscreteAsContinuous.java +++ /dev/null @@ -1,95 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.mixed.cpdag; - -import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.search.SemBicScore; -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; - -/** - * @author jdramsey - */ -@Bootstrapping -public class MixedFgesTreatingDiscreteAsContinuous implements Algorithm { - static final long serialVersionUID = 23L; - - public Graph search(DataModel Dk, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - DataSet mixedDataSet = SimpleDataLoader.getMixedDataSet(Dk); - mixedDataSet = DataUtils.convertNumericalDiscreteToContinuous(mixedDataSet); - SemBicScore score = new SemBicScore(new CovarianceMatrix(mixedDataSet)); - score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - Fges fges = new Fges(score); - fges.setVerbose(parameters.getBoolean(Params.VERBOSE)); - Graph p = fges.search(); - return convertBack(mixedDataSet, p); - } else { - MixedFgesTreatingDiscreteAsContinuous algorithm = new MixedFgesTreatingDiscreteAsContinuous(); - - DataSet data = (DataSet) Dk; - 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(); - } - } - - private Graph convertBack(DataSet Dk, Graph p) { - Graph p2 = new EdgeListGraph(Dk.getVariables()); - - for (int i = 0; i < p.getNodes().size(); i++) { - for (int j = i + 1; j < p.getNodes().size(); j++) { - Node v1 = p.getNodes().get(i); - Node v2 = p.getNodes().get(j); - - Edge e = p.getEdge(v1, v2); - - if (e != null) { - Node w1 = Dk.getVariable(e.getNode1().getName()); - Node w2 = Dk.getVariable(e.getNode2().getName()); - - Edge e2 = new Edge(w1, w2, e.getEndpoint1(), e.getEndpoint2()); - - p2.addEdge(e2); - } - } - } - return p2; - } - - public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); - } - - public String getDescription() { - return "FGES2, using the SEM BIC score, treating all discrete variables as " + - "continuous"; - } - - @Override - public DataType getDataType() { - return DataType.Mixed; - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.PENALTY_DISCOUNT); - parameters.add(Params.VERBOSE); - return parameters; - } -} - - 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/CCD_MAX_CONCATENATED.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/CcdMaxConcatenated.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/CCD_MAX_CONCATENATED.java index 09a7513dba..85995f2794 100644 --- 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/CCD_MAX_CONCATENATED.java @@ -25,12 +25,12 @@ * @author jdramsey */ @Bootstrapping -public class CcdMaxConcatenated implements MultiDataSetAlgorithm, HasKnowledge { +public class CCD_MAX_CONCATENATED implements MultiDataSetAlgorithm, HasKnowledge { static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); private final IndependenceWrapper test; - public CcdMaxConcatenated(IndependenceWrapper test) { + public CCD_MAX_CONCATENATED(IndependenceWrapper test) { this.test = test; } @@ -56,7 +56,7 @@ public Graph search(List dataModels, Parameters parameters) { search.setUseOrientTowardDConnections(parameters.getBoolean(Params.ORIENT_TOWARD_DCONNECTIONS)); return search.search(); } else { - CcdMaxConcatenated algorithm = new CcdMaxConcatenated(this.test); + CCD_MAX_CONCATENATED algorithm = new CCD_MAX_CONCATENATED(this.test); List dataSets = new ArrayList<>(); @@ -88,7 +88,7 @@ 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); + CCD_MAX_CONCATENATED algorithm = new CCD_MAX_CONCATENATED(this.test); List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); GeneralResamplingTest search = new GeneralResamplingTest(dataSets, 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/FASK_CONCATENATED.java similarity index 93% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FASK_CONCATENATED.java index bd64a5a58a..aa5ec58dba 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/FASK_CONCATENATED.java @@ -34,18 +34,18 @@ // algoType = AlgType.forbid_latent_common_causes //) @Bootstrapping -public class FaskConcatenated implements MultiDataSetAlgorithm, HasKnowledge, TakesIndependenceWrapper { +public class FASK_CONCATENATED implements MultiDataSetAlgorithm, HasKnowledge, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); - public FaskConcatenated() { + public FASK_CONCATENATED() { } - public FaskConcatenated(ScoreWrapper score, IndependenceWrapper test) { + public FASK_CONCATENATED(ScoreWrapper score, IndependenceWrapper test) { this.score = score; this.test = test; } @@ -72,7 +72,7 @@ public Graph search(List dataSets, Parameters parameters) { return search.search(); } else { - FaskConcatenated algorithm = new FaskConcatenated(this.score, this.test); + FASK_CONCATENATED algorithm = new FASK_CONCATENATED(this.score, this.test); List datasets = new ArrayList<>(); @@ -104,7 +104,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); } else { - FaskConcatenated algorithm = new FaskConcatenated(this.score, this.test); + FASK_CONCATENATED algorithm = new FASK_CONCATENATED(this.score, this.test); List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); GeneralResamplingTest search = new GeneralResamplingTest(dataSets, diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofsConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FASK_LOFS_CONCATENATED.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofsConcatenated.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FASK_LOFS_CONCATENATED.java index 26e71722ff..6c62bb0936 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofsConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FASK_LOFS_CONCATENATED.java @@ -27,12 +27,12 @@ * @author jdramsey */ @Bootstrapping -public class FasLofsConcatenated implements MultiDataSetAlgorithm, HasKnowledge { +public class FASK_LOFS_CONCATENATED implements MultiDataSetAlgorithm, HasKnowledge { static final long serialVersionUID = 23L; private final Lofs2.Rule rule; private Knowledge knowledge = new Knowledge(); - public FasLofsConcatenated(Lofs2.Rule rule) { + public FASK_LOFS_CONCATENATED(Lofs2.Rule rule) { this.rule = rule; } @@ -53,7 +53,7 @@ public Graph search(List dataModels, Parameters parameters) { search.setKnowledge(this.knowledge); return getGraph(search); } else { - FasLofsConcatenated algorithm = new FasLofsConcatenated(this.rule); + FASK_LOFS_CONCATENATED algorithm = new FASK_LOFS_CONCATENATED(this.rule); List datasets = new ArrayList<>(); @@ -89,7 +89,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); } else { - FasLofsConcatenated algorithm = new FasLofsConcatenated(this.rule); + FASK_LOFS_CONCATENATED algorithm = new FASK_LOFS_CONCATENATED(this.rule); List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); GeneralResamplingTest search = new GeneralResamplingTest(dataSets, 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/FASK_VOTE.java similarity index 93% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FASK_VOTE.java index ce0d13d38c..032f3719b7 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/FASK_VOTE.java @@ -36,18 +36,18 @@ dataType = DataType.Continuous ) @Bootstrapping -public class FaskVote implements MultiDataSetAlgorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper { +public class FASK_VOTE implements MultiDataSetAlgorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); private ScoreWrapper score; private IndependenceWrapper test; - public FaskVote() { + public FASK_VOTE() { } - public FaskVote(IndependenceWrapper test, ScoreWrapper score) { + public FASK_VOTE(IndependenceWrapper test, ScoreWrapper score) { this.test = test; this.score = score; } @@ -71,7 +71,7 @@ public Graph search(List dataSets, Parameters parameters) { search.setKnowledge(this.knowledge); return search.search(parameters); } else { - FaskVote imagesSemBic = new FaskVote(this.test, this.score); + FASK_VOTE imagesSemBic = new FASK_VOTE(this.test, this.score); List datasets = new ArrayList<>(); @@ -97,7 +97,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); } else { - FaskVote imagesSemBic = new FaskVote(); + FASK_VOTE imagesSemBic = new FASK_VOTE(); List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); GeneralResamplingTest search = new GeneralResamplingTest( @@ -133,7 +133,7 @@ public DataType getDataType() { @Override public List getParameters() { - List parameters = new ImagesSemBic().getParameters(); + List parameters = new IMAGES().getParameters(); parameters.addAll(new FASK().getParameters()); return parameters; 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/FAS_LOFS.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FAS_LOFS.java index 09de8ce56a..c46f55a820 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/FAS_LOFS.java @@ -24,12 +24,12 @@ * * @author jdramsey */ -public class FasLofs implements Algorithm, HasKnowledge { +public class FAS_LOFS implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final Lofs2.Rule rule; private Knowledge knowledge = new Knowledge(); - public FasLofs(Lofs2.Rule rule) { + public FAS_LOFS(Lofs2.Rule rule) { this.rule = rule; } @@ -46,7 +46,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setKnowledge(this.knowledge); return getGraph(search); } else { - FasLofs fasLofs = new FasLofs(this.rule); + FAS_LOFS fasLofs = new FAS_LOFS(this.rule); //fasLofs.setKnowledge(knowledge); DataSet data = (DataSet) dataSet; 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/FGES_CONCATENTED.java similarity index 93% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FGES_CONCATENTED.java index d67ccb29de..ba402b2d13 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/FGES_CONCATENTED.java @@ -26,23 +26,23 @@ * @author jdramsey */ @Bootstrapping -public class FgesConcatenated implements MultiDataSetAlgorithm, HasKnowledge { +public class FGES_CONCATENTED implements MultiDataSetAlgorithm, HasKnowledge { static final long serialVersionUID = 23L; private final ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private Algorithm externalGraph; private boolean compareToTrue; - public FgesConcatenated(ScoreWrapper score) { + public FGES_CONCATENTED(ScoreWrapper score) { this.score = score; } - public FgesConcatenated(ScoreWrapper score, boolean compareToTrue) { + public FGES_CONCATENTED(ScoreWrapper score, boolean compareToTrue) { this.score = score; this.compareToTrue = compareToTrue; } - public FgesConcatenated(ScoreWrapper score, Algorithm externalGraph) { + public FGES_CONCATENTED(ScoreWrapper score, Algorithm externalGraph) { this.score = score; this.externalGraph = externalGraph; } @@ -80,7 +80,7 @@ public Graph search(List dataModels, Parameters parameters) { return search.search(); } else { - FgesConcatenated fgesConcatenated = new FgesConcatenated(this.score, this.externalGraph); + FGES_CONCATENTED fgesConcatenated = new FGES_CONCATENTED(this.score, this.externalGraph); fgesConcatenated.setCompareToTrue(this.compareToTrue); List datasets = new ArrayList<>(); @@ -112,7 +112,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); } else { - FgesConcatenated fgesConcatenated = new FgesConcatenated(this.score, this.externalGraph); + FGES_CONCATENTED fgesConcatenated = new FGES_CONCATENTED(this.score, this.externalGraph); fgesConcatenated.setCompareToTrue(this.compareToTrue); List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); 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 similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Images.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/IMAGES.java index aa93dfd30b..eece0ff8c7 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 @@ -1,7 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.multi; import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.score.SemBicScore; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -37,14 +37,14 @@ dataType = DataType.All ) @Bootstrapping -public class Images implements MultiDataSetAlgorithm, HasKnowledge, UsesScoreWrapper { +public class IMAGES implements MultiDataSetAlgorithm, HasKnowledge, UsesScoreWrapper { static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); private ScoreWrapper score; - public Images() { + public IMAGES() { } @Override @@ -114,7 +114,7 @@ else if (meta == 3) { throw new IllegalArgumentException("Unrecognized meta option: " + meta); } } else { - Images imagesSemBic = new Images(); + IMAGES imagesSemBic = new IMAGES(); List dataSets2 = new ArrayList<>(); @@ -155,7 +155,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { return search(Collections.singletonList(SimpleDataLoader.getMixedDataSet(dataSet)), parameters); } else { - Images images = new Images(); + IMAGES images = new IMAGES(); List dataSets = Collections.singletonList(SimpleDataLoader.getMixedDataSet(dataSet)); GeneralResamplingTest search = new GeneralResamplingTest(dataSets, @@ -196,7 +196,7 @@ public List getParameters() { List parameters = new LinkedList<>(); parameters.addAll(new SemBicScore().getParameters()); - parameters.addAll((new Fges()).getParameters()); + parameters.addAll((new FGES()).getParameters()); parameters.add(Params.RANDOM_SELECTION_SIZE); parameters.add(Params.TIME_LAG); parameters.add(Params.IMAGES_META_ALG); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesBDeu.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesBDeu.java deleted file mode 100644 index 66e36ca0d4..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesBDeu.java +++ /dev/null @@ -1,147 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.multi; - -import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; -import edu.cmu.tetrad.algcomparison.score.BdeuScore; -import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; -import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.annotation.Experimental; -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.BdeuScoreImages; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; -import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * Wraps the IMaGES algorithm for discrete variables. - *

- * Requires that the parameter 'randomSelectionSize' be set to indicate how many - * datasets should be taken at a time (randomly). This cannot given multiple - * values. - * - * @author jdramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "IMaGES Discrete", -// command = "imgs_disc", -// algoType = AlgType.forbid_latent_common_causes, -// dataType = DataType.Discrete -//) -@Bootstrapping -@Experimental -public class ImagesBDeu implements MultiDataSetAlgorithm, HasKnowledge { - - static final long serialVersionUID = 23L; - private Knowledge knowledge = new Knowledge(); - - public ImagesBDeu() { - } - - @Override - public Graph search(List dataSets, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - BdeuScoreImages score = new BdeuScoreImages(dataSets); - score.setSamplePrior(parameters.getDouble(Params.PRIOR_EQUIVALENT_SAMPLE_SIZE)); - score.setStructurePrior(parameters.getDouble(Params.STRUCTURE_PRIOR)); - edu.cmu.tetrad.search.Fges search = new edu.cmu.tetrad.search.Fges(score); - search.setFaithfulnessAssumed(true); - search.setKnowledge(this.knowledge); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - - return search.search(); - } else { - ImagesBDeu imagesBDeu = new ImagesBDeu(); - - List datasets = new ArrayList<>(); - - for (DataModel dataModel : dataSets) { - datasets.add((DataSet) dataModel); - } - GeneralResamplingTest search = new GeneralResamplingTest( - datasets, - imagesBDeu, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public void setScoreWrapper(ScoreWrapper score) { - - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - return search(Collections.singletonList(SimpleDataLoader.getDiscreteDataSet(dataSet)), parameters); - } else { - ImagesBDeu imagesBDeu = new ImagesBDeu(); - - List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); - GeneralResamplingTest search = new GeneralResamplingTest(dataSets, - imagesBDeu, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); - } - - @Override - public String getDescription() { - return "IMaGES for discrete variables (using the BDeu score)"; - } - - @Override - public DataType getDataType() { - return DataType.Discrete; - } - - @Override - public List getParameters() { - List parameters = new LinkedList<>(); - parameters.addAll((new Fges()).getParameters()); - parameters.addAll((new BdeuScore()).getParameters()); - parameters.add(Params.NUM_RUNS); - parameters.add(Params.RANDOM_SELECTION_SIZE); - parameters.add(Params.VERBOSE); - - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesPcStableMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesPcStableMax.java deleted file mode 100644 index bcfe2287b8..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesPcStableMax.java +++ /dev/null @@ -1,150 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.multi; - -import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; -import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; -import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.IndTestScore; -import edu.cmu.tetrad.search.IndependenceTest; -import edu.cmu.tetrad.search.PcStableMax; -import edu.cmu.tetrad.search.SemBicScoreImages; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; -import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Wraps the IMaGES algorithm for continuous variables. - *

- * Requires that the parameter 'randomSelectionSize' be set to indicate how many - * datasets should be taken at a time (randomly). This cannot given multiple values. - * - * @author jdramsey - */ -@Bootstrapping -public class ImagesPcStableMax implements MultiDataSetAlgorithm, HasKnowledge { - static final long serialVersionUID = 23L; - private Knowledge knowledge = new Knowledge(); - - public ImagesPcStableMax() { - } - - @Override - public Graph search(List dataModels, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - List dataSets = new ArrayList<>(); - - for (DataModel dataModel : dataModels) { - dataSets.add(dataModel); - } - - SemBicScoreImages score = new SemBicScoreImages(dataSets); - score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - IndependenceTest test = new IndTestScore(score); - PcStableMax search = new PcStableMax(test); - search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); - search.setMaxPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); - search.setKnowledge(this.knowledge); - search.setDepth(parameters.getInt(Params.DEPTH)); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } else { - ImagesPcStableMax imagesPcStableMax = new ImagesPcStableMax(); - - List datasets = new ArrayList<>(); - - for (DataModel dataModel : dataModels) { - datasets.add((DataSet) dataModel); - } - GeneralResamplingTest search = new GeneralResamplingTest(datasets, - imagesPcStableMax, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public void setScoreWrapper(ScoreWrapper score) { - - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); - } else { - ImagesPcStableMax imagesPcStableMax = new ImagesPcStableMax(); - - List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); - GeneralResamplingTest search = new GeneralResamplingTest(dataSets, - imagesPcStableMax, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "PC-Max using the IMaGES score for continuous variables"; - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.PENALTY_DISCOUNT); - - parameters.add(Params.DEPTH); - parameters.add(Params.ORIENT_VISIBLE_FEEDBACK_LOOPS); - parameters.add(Params.USE_MAX_P_ORIENTATION_HEURISTIC); - parameters.add(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH); - parameters.add(Params.APPLY_R1); - parameters.add(Params.ORIENT_TOWARD_DCONNECTIONS); - - parameters.add(Params.NUM_RUNS); - parameters.add(Params.RANDOM_SELECTION_SIZE); - - parameters.add(Params.VERBOSE); - - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesSemBic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesSemBic.java deleted file mode 100644 index d2c4485805..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/ImagesSemBic.java +++ /dev/null @@ -1,179 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.multi; - -import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; -import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; -import edu.cmu.tetrad.algcomparison.score.SemBicScore; -import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.annotation.Experimental; -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SemBicScoreImages; -import edu.cmu.tetrad.search.TimeSeriesUtils; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; -import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * Wraps the IMaGES algorithm for continuous variables. - *

- * Requires that the parameter 'randomSelectionSize' be set to indicate how many - * datasets should be taken at a time (randomly). This cannot given multiple - * values. - * - * @author jdramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "IMaGES Continuous", -// command = "imgs_cont", -// algoType = AlgType.forbid_latent_common_causes, -// dataType = DataType.Continuous -//) -@Bootstrapping -@Experimental -public class ImagesSemBic implements MultiDataSetAlgorithm, HasKnowledge { - - static final long serialVersionUID = 23L; - private Knowledge knowledge = new Knowledge(); - - public ImagesSemBic() { - } - - @Override - public Graph search(List dataSets, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - List _dataSets = new ArrayList<>(); - - if (parameters.getInt(Params.TIME_LAG) > 0) { - for (DataModel dataSet : dataSets) { - DataSet timeSeries = TimeSeriesUtils.createLagData((DataSet) dataSet, parameters.getInt(Params.TIME_LAG)); - if (dataSet.getName() != null) { - timeSeries.setName(dataSet.getName()); - } - _dataSets.add(timeSeries); - } - - dataSets = _dataSets; - this.knowledge = _dataSets.get(0).getKnowledge(); - } - - SemBicScoreImages score = new SemBicScoreImages(dataSets); - score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - edu.cmu.tetrad.search.Fges search = new edu.cmu.tetrad.search.Fges(score); - search.setKnowledge(this.knowledge); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } else { - ImagesSemBic imagesSemBic = new ImagesSemBic(); - - List dataSets2 = new ArrayList<>(); - - for (DataModel dataModel : dataSets) { - dataSets2.add((DataSet) dataModel); - } - - List _dataSets = new ArrayList<>(); - - if (parameters.getInt(Params.TIME_LAG) > 0) { - for (DataModel dataSet : dataSets2) { - DataSet timeSeries = TimeSeriesUtils.createLagData((DataSet) dataSet, parameters.getInt(Params.TIME_LAG)); - if (dataSet.getName() != null) { - timeSeries.setName(dataSet.getName()); - } - _dataSets.add(timeSeries); - } - - dataSets2 = _dataSets; - this.knowledge = _dataSets.get(0).getKnowledge(); - } - - GeneralResamplingTest search = new GeneralResamplingTest( - dataSets2, - imagesSemBic, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setKnowledge(knowledge); - return search.search(); - } - } - - @Override - public void setScoreWrapper(ScoreWrapper score) { - - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); - } else { - ImagesSemBic imagesSemBic = new ImagesSemBic(); - - List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); - GeneralResamplingTest search = new GeneralResamplingTest(dataSets, - imagesSemBic, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "IMaGES for continuous variables (using the SEM BIC score)"; - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - List parameters = new LinkedList<>(); - parameters.addAll(new SemBicScore().getParameters()); - - parameters.addAll((new Fges()).getParameters()); - parameters.add(Params.PENALTY_DISCOUNT); - parameters.add(Params.RANDOM_SELECTION_SIZE); - parameters.add(Params.TIME_LAG); - - parameters.add(Params.VERBOSE); - - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/MultiFaskV1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/MultiFaskV1.java deleted file mode 100644 index f3a5ba0888..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/MultiFaskV1.java +++ /dev/null @@ -1,161 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.multi; - -import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; -import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; -import edu.cmu.tetrad.algcomparison.score.SemBicScore; -import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SemBicScoreMultiFas; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; -import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * Wraps the MultiFask algorithm for continuous variables. - *

- * Requires that the parameter 'randomSelectionSize' be set to indicate how many - * datasets should be taken at a time (randomly). This cannot given multiple - * values. - * - * @author jdramsey - */ - -// Using FaskVote now in place of MultiFask. Keeping the name "MultiFask" in the interface. -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "MultiFask", -// command = "multi-fask", -// algoType = AlgType.forbid_latent_common_causes, -// dataType = DataType.Continuous -//) -@Bootstrapping -public class MultiFaskV1 implements MultiDataSetAlgorithm, HasKnowledge { - - static final long serialVersionUID = 23L; - private Knowledge knowledge = new Knowledge(); - - public MultiFaskV1() { - - } - - @Override - public Graph search(List dataSets, Parameters parameters) { - for (DataModel d : dataSets) { - DataSet _data = (DataSet) d; - - for (int j = 0; j < _data.getNumColumns(); j++) { - for (int i = 0; i < _data.getNumRows(); i++) { - if (Double.isNaN(_data.getDouble(i, j))) { - throw new IllegalArgumentException("Please remove or impute missing values."); - } - } - } - } - - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - List _dataSets = new ArrayList<>(); - for (DataModel d : dataSets) { - _dataSets.add((DataSet) d); - } - SemBicScoreMultiFas score = new SemBicScoreMultiFas(dataSets); - score.setPenaltyDiscount(parameters.getDouble(Params.PENALTY_DISCOUNT)); - edu.cmu.tetrad.search.MultiFaskV1 search = new edu.cmu.tetrad.search.MultiFaskV1(_dataSets, score); - search.setKnowledge(this.knowledge); - return search.search(); - } else { - MultiFaskV1 imagesSemBic = new MultiFaskV1(); - - List datasets = new ArrayList<>(); - - for (DataModel dataModel : dataSets) { - datasets.add((DataSet) dataModel); - } - GeneralResamplingTest search = new GeneralResamplingTest( - datasets, - imagesSemBic, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public void setScoreWrapper(ScoreWrapper score) { - - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); - } else { - MultiFaskV1 imagesSemBic = new MultiFaskV1(); - - List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); - GeneralResamplingTest search = new GeneralResamplingTest(dataSets, - imagesSemBic, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return new EdgeListGraph(graph); - } - - @Override - public String getDescription() { - return "IMaGES for continuous variables (using the SEM BIC score)"; - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - // MultiFask uses SemBicScore internally, so we'll need to add the score parameters too - Zhou - List parameters = new LinkedList<>(); - parameters.addAll((new Fges()).getParameters()); - parameters.addAll((new SemBicScore()).getParameters()); - parameters.add(Params.NUM_RUNS); - parameters.add(Params.RANDOM_SELECTION_SIZE); - - parameters.add(Params.VERBOSE); - - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/PcStableMaxConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/PcStableMaxConcatenated.java deleted file mode 100644 index b1f5c9c24e..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/PcStableMaxConcatenated.java +++ /dev/null @@ -1,164 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.multi; - -import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; -import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; -import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; -import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.PcStableMax; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; -import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * Requires that the parameter 'randomSelectionSize' be set to indicate how many - * datasets should be taken at a time (randomly). This cannot given multiple - * values. - * - * @author jdramsey - */ -@Bootstrapping -public class PcStableMaxConcatenated implements MultiDataSetAlgorithm, HasKnowledge { - - static final long serialVersionUID = 23L; - private boolean compareToTrue; - private final IndependenceWrapper test; - private final Algorithm externalGraph = null; - private Knowledge knowledge = new Knowledge(); - - public PcStableMaxConcatenated(IndependenceWrapper test, boolean compareToTrue) { - this.test = test; - this.compareToTrue = compareToTrue; - } - - public PcStableMaxConcatenated(IndependenceWrapper test) { - this.test = test; - } - - @Override - public Graph search(List dataModels, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - List dataSets = new ArrayList<>(); - - for (DataModel dataModel : dataModels) { - dataSets.add((DataSet) dataModel); - } - - DataSet dataSet = DataUtils.concatenate(dataSets); - PcStableMax search = new PcStableMax( - this.test.getTest(dataSet, parameters)); - search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); - search.setMaxPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); - search.setKnowledge(this.knowledge); - search.setDepth(parameters.getInt(Params.DEPTH)); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } else { - PcStableMaxConcatenated pcStableMaxConcatenated = new PcStableMaxConcatenated(this.test, this.compareToTrue); - - List datasets = new ArrayList<>(); - - for (DataModel dataModel : dataModels) { - datasets.add((DataSet) dataModel); - } - GeneralResamplingTest search = new GeneralResamplingTest( - datasets, - pcStableMaxConcatenated, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public void setScoreWrapper(ScoreWrapper score) { - - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - return search(Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)), parameters); - } else { - PcStableMaxConcatenated pcStableMaxConcatenated = new PcStableMaxConcatenated(this.test, this.compareToTrue); - - List dataSets = Collections.singletonList(SimpleDataLoader.getContinuousDataSet(dataSet)); - GeneralResamplingTest search = new GeneralResamplingTest(dataSets, - pcStableMaxConcatenated, - parameters.getInt(Params.NUMBER_RESAMPLING), - parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), - parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - search.setScoreWrapper(null); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - if (this.compareToTrue) { - return new EdgeListGraph(graph); - } else { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); - } - } - - @Override - public String getDescription() { - return "PC-Max (\"Peter and Clark\") on concatenating datasets using " + this.test.getDescription() - + ""; - } - - @Override - public DataType getDataType() { - return DataType.Continuous; - } - - @Override - public List getParameters() { - List parameters = new LinkedList<>(); - if (this.test != null) { - parameters.addAll(this.test.getParameters()); - } - parameters.add(Params.DEPTH); - parameters.add(Params.USE_MAX_P_ORIENTATION_HEURISTIC); - parameters.add(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH); - - parameters.add(Params.NUM_RUNS); - parameters.add(Params.RANDOM_SELECTION_SIZE); - - parameters.add(Params.VERBOSE); - - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - -} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Fges.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java index d0d1829513..d079a0ba9d 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 @@ -34,7 +34,7 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -public class Fges implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExternalGraph { +public class FGES implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExternalGraph { static final long serialVersionUID = 23L; @@ -45,11 +45,11 @@ public class Fges implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExt private Algorithm algorithm = null; - public Fges() { + public FGES() { } - public Fges(ScoreWrapper score) { + public FGES(ScoreWrapper score) { this.score = score; } @@ -98,7 +98,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return graph; } else { - Fges fges = new Fges(this.score); + FGES fges = new FGES(this.score); if (this.algorithm != null) { fges.setExternalGraph(this.algorithm); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java index bed3584b83..15e63bc882 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java @@ -35,17 +35,17 @@ algoType = AlgType.search_for_Markov_blankets ) @Bootstrapping -public class FgesMb implements Algorithm, HasKnowledge, UsesScoreWrapper { +public class FGES_MB implements Algorithm, HasKnowledge, UsesScoreWrapper { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private String targetName; - public FgesMb() { + public FGES_MB() { } - public FgesMb(ScoreWrapper score) { + public FGES_MB(ScoreWrapper score) { this.score = score; } @@ -69,7 +69,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { return search.search(Collections.singletonList(target)); } else { - FgesMb fgesMb = new FgesMb(this.score); + FGES_MB fgesMb = new FGES_MB(this.score); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, fgesMb, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java index 2fff224afb..c889a508aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java @@ -25,13 +25,13 @@ * @author jdramsey */ @Bootstrapping -public class FgesMeasurement implements Algorithm, HasKnowledge { +public class FGES_MEASUREMENT implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final ScoreWrapper score; private Knowledge knowledge = new Knowledge(); - public FgesMeasurement(ScoreWrapper score) { + public FGES_MEASUREMENT(ScoreWrapper score) { this.score = score; } @@ -66,7 +66,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return search.search(); } else { - FgesMeasurement fgesMeasurement = new FgesMeasurement(this.score); + FGES_MEASUREMENT fgesMeasurement = new FGES_MEASUREMENT(this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, fgesMeasurement, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java index 75e8662fdc..30f2b3321c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java @@ -30,17 +30,17 @@ */ @Bootstrapping @Experimental -public class GesMe implements Algorithm { +public class GES_ME implements Algorithm { static final long serialVersionUID = 23L; private boolean compareToTrue; private final ScoreWrapper score = new SemBicScoreDeterministic(); - public GesMe() { + public GES_ME() { setCompareToTrue(false); } - public GesMe(boolean compareToTrueGraph) { + public GES_ME(boolean compareToTrueGraph) { setCompareToTrue(compareToTrueGraph); } @@ -170,7 +170,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { return search.search(); } else { - GesMe algorithm = new GesMe(this.compareToTrue); + GES_ME algorithm = new GES_ME(this.compareToTrue); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java index 17b5f95aa3..696401ae71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSPTol.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java @@ -39,17 +39,17 @@ ) @Bootstrapping @Experimental -public class GRaSPTol implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class GRASP_TOL implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { static final long serialVersionUID = 23L; private ScoreWrapper score; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public GRaSPTol() { + public GRASP_TOL() { // Used in reflection; do not delete. } - public GRaSPTol(ScoreWrapper score, IndependenceWrapper test) { + public GRASP_TOL(ScoreWrapper score, IndependenceWrapper test) { this.score = score; this.test = test; } @@ -89,7 +89,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { grasp.bestOrder(score.getVariables()); return grasp.getGraph(parameters.getBoolean(Params.OUTPUT_CPDAG)); } else { - GRaSPTol algorithm = new GRaSPTol(this.score, this.test); + GRASP_TOL algorithm = new GRASP_TOL(this.score, this.test); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java index 8abc4cd458..a96d674bbe 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 @@ -21,11 +21,11 @@ * @author jdramsey */ @Bootstrapping -public class Pcd implements Algorithm, HasKnowledge { +public class PCD implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); - public Pcd() { + public PCD() { } @Override @@ -53,7 +53,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setVerbose(parameters.getBoolean(Params.VERBOSE)); return search.search(); } else { - Pcd algorithm = new Pcd(); + PCD algorithm = new PCD(); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java index 47415da71b..0a5b8ab09c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcStable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java @@ -26,16 +26,16 @@ * @author jdramsey */ @Bootstrapping -public class PcStable implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class PC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public PcStable() { + public PC_STABLE() { } - public PcStable(IndependenceWrapper test) { + public PC_STABLE(IndependenceWrapper test) { this.test = test; } @@ -52,7 +52,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setVerbose(parameters.getBoolean(Params.VERBOSE)); return search.search(); } else { - PcStable pcStable = new PcStable(this.test); + PC_STABLE pcStable = new PC_STABLE(this.test); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, pcStable, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcAll.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcAll.java deleted file mode 100644 index f349b7fa31..0000000000 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcAll.java +++ /dev/null @@ -1,171 +0,0 @@ -package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; - -import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; -import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; -import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; -import edu.cmu.tetrad.annotation.Bootstrapping; -import edu.cmu.tetrad.annotation.Experimental; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.Knowledge; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.SearchGraphUtils; -import edu.cmu.tetrad.util.Parameters; -import edu.cmu.tetrad.util.Params; -import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; - -import java.util.ArrayList; -import java.util.List; - -/** - * CPC. - * - * @author jdramsey - */ -//@edu.cmu.tetrad.annotation.Algorithm( -// name = "PC Variants", -// command = "pc-all", -// algoType = AlgType.forbid_latent_common_causes -//) -@Experimental -@Bootstrapping -public class PcAll implements Algorithm, HasKnowledge, TakesIndependenceWrapper { - - static final long serialVersionUID = 23L; - private IndependenceWrapper test; - private Knowledge knowledge = new Knowledge(); - - public PcAll() { - } - - public PcAll(IndependenceWrapper test) { - this.test = test; - } - - @Override - public Graph search(DataModel dataSet, Parameters parameters) { - if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - edu.cmu.tetrad.search.PcAll.ColliderDiscovery colliderDiscovery; - - switch (parameters.getInt(Params.COLLIDER_DISCOVERY_RULE)) { - case 1: - colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.FAS_SEPSETS; - break; - case 2: - colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.CONSERVATIVE; - break; - case 3: - colliderDiscovery = edu.cmu.tetrad.search.PcAll.ColliderDiscovery.MAX_P; - break; - default: - throw new IllegalArgumentException("Not a choice."); - } - - edu.cmu.tetrad.search.PcAll.ConflictRule conflictRule; - - switch (parameters.getInt(Params.CONFLICT_RULE)) { - case 1: - conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.OVERWRITE; - break; - case 2: - conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.BIDIRECTED; - break; - case 3: - conflictRule = edu.cmu.tetrad.search.PcAll.ConflictRule.PRIORITY; - break; - default: - throw new IllegalArgumentException("Not a choice."); - } - - edu.cmu.tetrad.search.PcAll search = new edu.cmu.tetrad.search.PcAll(this.test.getTest(dataSet, parameters)); - search.setDepth(parameters.getInt(Params.DEPTH)); - search.setHeuristic(parameters.getInt(Params.FAS_HEURISTIC)); - search.setKnowledge(this.knowledge); - - if (parameters.getBoolean(Params.STABLE_FAS)) { - search.setFasType(edu.cmu.tetrad.search.PcAll.FasType.STABLE); - } else { - search.setFasType(edu.cmu.tetrad.search.PcAll.FasType.REGULAR); - } - - if (parameters.getBoolean(Params.CONCURRENT_FAS)) { - search.setConcurrent(edu.cmu.tetrad.search.PcAll.Concurrent.YES); - } else { - search.setConcurrent(edu.cmu.tetrad.search.PcAll.Concurrent.NO); - } - - search.setColliderDiscovery(colliderDiscovery); - search.setConflictRule(conflictRule); - search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); - search.setMaxPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - - return search.search(); - } else { - PcAll pcAll = new PcAll(this.test); - - DataSet data = (DataSet) dataSet; - GeneralResamplingTest search = new GeneralResamplingTest(data, pcAll, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(this.knowledge); - - search.setParameters(parameters); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); - } - } - - @Override - public Graph getComparisonGraph(Graph graph) { - return SearchGraphUtils.cpdagForDag(new EdgeListGraph(graph)); - } - - @Override - public String getDescription() { - return "PC using " + this.test.getDescription(); - } - - @Override - public DataType getDataType() { - return this.test.getDataType(); - } - - @Override - public List getParameters() { - List parameters = new ArrayList<>(); - parameters.add(Params.STABLE_FAS); - parameters.add(Params.CONCURRENT_FAS); - parameters.add(Params.COLLIDER_DISCOVERY_RULE); - parameters.add(Params.CONFLICT_RULE); - parameters.add(Params.DEPTH); - parameters.add(Params.FAS_HEURISTIC); - parameters.add(Params.USE_MAX_P_ORIENTATION_HEURISTIC); - parameters.add(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH); - - parameters.add(Params.VERBOSE); - return parameters; - } - - @Override - public Knowledge getKnowledge() { - return this.knowledge; - } - - @Override - public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); - } - - @Override - public IndependenceWrapper getIndependenceWrapper() { - return this.test; - } - - @Override - public void setIndependenceWrapper(IndependenceWrapper test) { - this.test = test; - } - -} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SINGLE_GRAPH_ALG.java similarity index 92% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SINGLE_GRAPH_ALG.java index 9993219c6a..14340cb72c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SINGLE_GRAPH_ALG.java @@ -17,12 +17,12 @@ * * @author jdramsey */ -public class SingleGraphAlg implements Algorithm, HasKnowledge { +public class SINGLE_GRAPH_ALG implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final Graph graph; - public SingleGraphAlg(Graph graph) { + public SINGLE_GRAPH_ALG(Graph graph) { this.graph = graph; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java index f47f0d8221..f69a754ee6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CcdMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java @@ -29,13 +29,13 @@ oracleType = OracleType.Test )*/ @Bootstrapping -public class CcdMax implements Algorithm, HasKnowledge { +public class CCD_MAX implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public CcdMax(IndependenceWrapper test) { + public CCD_MAX(IndependenceWrapper test) { this.test = test; } @@ -53,7 +53,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setUseOrientTowardDConnections(parameters.getBoolean(Params.ORIENT_TOWARD_DCONNECTIONS)); return search.search(); } else { - CcdMax algorithm = new CcdMax(this.test); + CCD_MAX algorithm = new CCD_MAX(this.test); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Cfci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java index ace07f86e1..1b5d252dbc 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 @@ -25,13 +25,13 @@ * @author jdramsey */ @Bootstrapping -public class Cfci implements Algorithm, HasKnowledge { +public class CFCI implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public Cfci(IndependenceWrapper test) { + public CFCI(IndependenceWrapper test) { this.test = test; } @@ -46,7 +46,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setDoDiscriminatingPathRule(parameters.getBoolean(Params.DO_DISCRIMINATING_PATH_RULE)); return search.search(); } else { - Cfci algorithm = new Cfci(this.test); + CFCI algorithm = new CFCI(this.test); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Fci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Fci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java index a9ea4e9e97..a2dceaf2c6 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 @@ -33,16 +33,16 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class Fci implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public Fci() { + public FCI() { } - public Fci(IndependenceWrapper test) { + public FCI(IndependenceWrapper test) { this.test = test; } @@ -72,7 +72,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return search.search(); } else { - Fci algorithm = new Fci(this.test); + FCI algorithm = new FCI(this.test); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java index c7fc7a0602..fd5ebc3d58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java @@ -33,16 +33,16 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class FciMax implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class FCI_MAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public FciMax() { + public FCI_MAX() { } - public FciMax(IndependenceWrapper test) { + public FCI_MAX(IndependenceWrapper test) { this.test = test; } @@ -70,7 +70,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return search.search(); } else { - FciMax algorithm = new FciMax(this.test); + FCI_MAX algorithm = new FCI_MAX(this.test); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSamplingRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSamplingRfci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java index 5d9cd41e2f..efc62fd94b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSamplingRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java @@ -30,7 +30,7 @@ algoType = AlgType.allow_latent_common_causes ) //@Experimental -public class PagSamplingRfci implements Algorithm, HasKnowledge { +public class PAG_SAMPLING_RFCI implements Algorithm, HasKnowledge { public static final List PAG_SAMPLING_RFCI_PARAMETERS = new LinkedList<>(); public static final List RFCI_PARAMETERS = new LinkedList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Rfci.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java index 9dab978c3c..a055753023 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 @@ -33,16 +33,16 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class Rfci implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class RFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public Rfci() { + public RFCI() { } - public Rfci(IndependenceWrapper test) { + public RFCI(IndependenceWrapper test) { this.test = test; } @@ -66,7 +66,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setVerbose(parameters.getBoolean(Params.VERBOSE)); return search.search(); } else { - Rfci algorithm = new Rfci(this.test); + RFCI algorithm = new RFCI(this.test); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); search.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java index 83ef2a3a94..003f0a5825 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java @@ -31,7 +31,7 @@ dataType = DataType.Discrete ) @Experimental -public class RfciBsc implements Algorithm, HasKnowledge { +public class RFCI_BSC implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final IndependenceWrapper test = new ProbabilisticTest(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CStaR.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CSTAR.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CStaR.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CSTAR.java index 5306829bf1..6b90b526bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CStaR.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/CSTAR.java @@ -26,12 +26,12 @@ command = "cstar", algoType = AlgType.forbid_latent_common_causes ) -public class CStaR implements Algorithm, TakesIndependenceWrapper { +public class CSTAR implements Algorithm, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private LinkedList records; - public CStaR() { + public CSTAR() { } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FACTOR_ANALYSIS.java similarity index 98% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FACTOR_ANALYSIS.java index 5f13cd9133..080bfdcf48 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FACTOR_ANALYSIS.java @@ -20,7 +20,7 @@ * @author jdramsey */ @Bootstrapping -public class FactorAnalysis implements Algorithm { +public class FACTOR_ANALYSIS implements Algorithm { static final long serialVersionUID = 23L; public Graph search(DataModel ds, Parameters parameters) { @@ -102,7 +102,7 @@ public Graph search(DataModel ds, Parameters parameters) { return graph; } else { - FactorAnalysis algorithm = new FactorAnalysis(); + FACTOR_ANALYSIS algorithm = new FACTOR_ANALYSIS(); DataSet data = (DataSet) ds; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/GLASSO.java similarity index 97% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/GLASSO.java index 5530be2377..8bc7500bc2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/GLASSO.java @@ -33,7 +33,7 @@ ) @Bootstrapping @Experimental -public class Glasso implements Algorithm { +public class GLASSO implements Algorithm { static final long serialVersionUID = 23L; @@ -77,7 +77,7 @@ public Graph search(DataModel ds, Parameters parameters) { return resultGraph; } else { - Glasso algorithm = new Glasso(); + GLASSO algorithm = new GLASSO(); DataSet data = (DataSet) ds; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPW.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FASK_PW.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPW.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FASK_PW.java index 75185b33bf..921e3a97dd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPW.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FASK_PW.java @@ -32,16 +32,16 @@ dataType = DataType.Continuous ) @Bootstrapping -public class FaskPW implements Algorithm, TakesExternalGraph { +public class FASK_PW implements Algorithm, TakesExternalGraph { static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; - public FaskPW() { + public FASK_PW() { } - public FaskPW(Algorithm algorithm) { + public FASK_PW(Algorithm algorithm) { this.algorithm = algorithm; } @@ -67,7 +67,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return fask.search(); } else { - FaskPW rSkew = new FaskPW(this.algorithm); + FASK_PW rSkew = new FASK_PW(this.algorithm); if (this.externalGraph != null) { rSkew.setExternalGraph(this.algorithm); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkew.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkew.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW.java index 75db35741b..b4929bd146 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkew.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW.java @@ -30,16 +30,16 @@ dataType = DataType.Continuous ) @Bootstrapping -public class RSkew implements Algorithm, TakesExternalGraph { +public class RSKEW implements Algorithm, TakesExternalGraph { static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; - public RSkew() { + public RSKEW() { } - public RSkew(Algorithm algorithm) { + public RSKEW(Algorithm algorithm) { this.algorithm = algorithm; } @@ -63,7 +63,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { return lofs.orient(); } else { - RSkew rSkew = new RSkew(this.algorithm); + RSKEW rSkew = new RSKEW(this.algorithm); if (this.externalGraph != null) { rSkew.setExternalGraph(this.algorithm); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkewE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW_E.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkewE.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW_E.java index d28ebdf0c9..29d7819bee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSkewE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RSKEW_E.java @@ -30,18 +30,18 @@ // algoType = AlgType.orient_pairwise //) @Bootstrapping -public class RSkewE implements Algorithm, TakesExternalGraph { +public class RSKEW_E implements Algorithm, TakesExternalGraph { static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; - public RSkewE() { + public RSKEW_E() { } - public RSkewE(Algorithm algorithm) { + public RSKEW_E(Algorithm algorithm) { this.algorithm = algorithm; } @@ -65,7 +65,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { return lofs.orient(); } else { - RSkewE rSkewE = new RSkewE(this.algorithm); + RSKEW_E rSkewE = new RSKEW_E(this.algorithm); if (this.externalGraph != null) { rSkewE.setExternalGraph(this.algorithm); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW.java index 2c9871e465..1d954eec89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW.java @@ -31,16 +31,16 @@ ) @Bootstrapping -public class Skew implements Algorithm, TakesExternalGraph { +public class SKEW implements Algorithm, TakesExternalGraph { static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; - public Skew() { + public SKEW() { } - public Skew(Algorithm algorithm) { + public SKEW(Algorithm algorithm) { this.algorithm = algorithm; } @@ -64,7 +64,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { return lofs.orient(); } else { - Skew skew = new Skew(this.algorithm); + SKEW skew = new SKEW(this.algorithm); if (this.externalGraph != null) { skew.setExternalGraph(this.algorithm); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW_E.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW_E.java index f3642b96da..33cfe5ec75 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SKEW_E.java @@ -30,16 +30,16 @@ // algoType = AlgType.orient_pairwise //) @Bootstrapping -public class SkewE implements Algorithm, TakesExternalGraph { +public class SKEW_E implements Algorithm, TakesExternalGraph { static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; - public SkewE() { + public SKEW_E() { } - public SkewE(Algorithm algorithm) { + public SKEW_E(Algorithm algorithm) { this.algorithm = algorithm; } @@ -63,7 +63,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { return lofs.orient(); } else { - SkewE skewE = new SkewE(this.algorithm); + SKEW_E skewE = new SKEW_E(this.algorithm); if (this.externalGraph != null) { skewE.setExternalGraph(this.algorithm); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/TAHN.java similarity index 95% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/TAHN.java index 6e84ae7447..1f0bdcb36a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/TAHN.java @@ -24,14 +24,14 @@ * @author jdramsey */ @Bootstrapping -public class Tanh implements Algorithm, TakesExternalGraph { +public class TAHN implements Algorithm, TakesExternalGraph { static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; - public Tanh(Algorithm algorithm) { + public TAHN(Algorithm algorithm) { this.algorithm = algorithm; } @@ -55,7 +55,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { return lofs.orient(); } else { - Tanh tanh = new Tanh(this.algorithm); + TAHN tanh = new TAHN(this.algorithm); if (this.externalGraph != null) { tanh.setExternalGraph(this.algorithm); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java index b653456b7e..3196942e1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/ExampleCompareSimulation2.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.score.ConditionalGaussianBicScore; import edu.cmu.tetrad.algcomparison.simulation.BayesNetSimulation; @@ -57,7 +57,7 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new Fges(new ConditionalGaussianBicScore())); + algorithms.add(new FGES(new ConditionalGaussianBicScore())); Simulations simulations = new Simulations(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java index 82dfcad89a..4250fe537e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/MVPCompareFromFiles.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.score.MVPBicScore; import edu.cmu.tetrad.algcomparison.statistic.*; import edu.cmu.tetrad.util.Parameters; @@ -72,7 +72,7 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new Fges(new MVPBicScore())); + algorithms.add(new FGES(new MVPBicScore())); Comparison comparison = new Comparison(); comparison.setShowAlgorithmIndices(true); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java index faa079d99f..9d410f7042 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java @@ -24,9 +24,8 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.BOSS; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.GRaSP; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.SP; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.independence.FisherZ; import edu.cmu.tetrad.algcomparison.score.SemBicScore; @@ -68,7 +67,7 @@ public static void main(String... args) { statistics.add(new ElapsedCpuTime()); Algorithms algorithms = new Algorithms(); - algorithms.add(new Fges(new SemBicScore())); + algorithms.add(new FGES(new SemBicScore())); algorithms.add(new BOSS(new SemBicScore())); algorithms.add(new GRaSP(new SemBicScore(), new FisherZ())); // algorithms.add(new SP(new SemBicScore())); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java index 4bc86b99e1..ed8d64ecf1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestDegenerateGaussian.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PcStable; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC_STABLE; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.independence.DegenerateGaussianLRT; import edu.cmu.tetrad.algcomparison.score.ConditionalGaussianBicScore; @@ -77,9 +77,9 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new Fges(new ConditionalGaussianBicScore())); - algorithms.add(new Fges(new DegenerateGaussianBicScore())); - algorithms.add(new PcStable(new DegenerateGaussianLRT())); + algorithms.add(new FGES(new ConditionalGaussianBicScore())); + algorithms.add(new FGES(new DegenerateGaussianBicScore())); + algorithms.add(new PC_STABLE(new DegenerateGaussianLRT())); Simulations simulations = new Simulations(); simulations.add(new ConditionalGaussianSimulation(new RandomForward())); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java index 96826cc463..2d0995d566 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FaskVote.java @@ -1,6 +1,6 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.algcomparison.algorithm.multi.ImagesSemBic; +import edu.cmu.tetrad.algcomparison.algorithm.multi.IMAGES; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.data.DataModel; @@ -43,7 +43,7 @@ public Graph search(Parameters parameters) { _dataSets.add(DataUtils.standardizeData(dataSet)); } - ImagesSemBic imagesSemBic = new ImagesSemBic(); + IMAGES imagesSemBic = new IMAGES(); imagesSemBic.setKnowledge(this.knowledge); Graph G0 = imagesSemBic.search(_dataSets, parameters); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition1.java index 41318cb385..6863b3dafe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/Conditions/Condition1.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.external.ExternalAlgorithmPcalgGes; import edu.cmu.tetrad.algcomparison.algorithm.external.ExternalAlgorithmTetrad; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.score.SemBicScore; import edu.cmu.tetrad.algcomparison.statistic.*; import edu.cmu.tetrad.util.Parameters; @@ -78,7 +78,7 @@ public void generateTetradResults() { parameters.set("penaltyDiscount", 4); // - algorithms.add(new Fges(new SemBicScore())); + algorithms.add(new FGES(new SemBicScore())); comparison.compareFromFiles("/Users/user/comparison-data/condition_1", "/Users/user/causal-comparisons/condition_1", diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulation.java index 0393d63ebc..bff6db24c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulation.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.score.SemBicScore; import edu.cmu.tetrad.algcomparison.simulation.SemSimulation; @@ -116,7 +116,7 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); // algorithms.add(new PcAll(new FisherZ())); - algorithms.add(new Fges(new SemBicScore())); + algorithms.add(new FGES(new SemBicScore())); // algorithms.add(new Gfci(new FisherZ(), new SemBicScore())); Simulations simulations = new Simulations(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulationDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulationDiscrete.java index c981c0b54a..7d8dc685cb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulationDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleCompareSimulationDiscrete.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PcAll; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.independence.ChiSquare; import edu.cmu.tetrad.algcomparison.independence.GSquare; @@ -55,7 +55,6 @@ public static void main(String... args) { parameters.set("differentGraphs", true); parameters.set("alpha", 0.05, 0.01, 0.001); - parameters.set("colliderDiscoveryRule", 1, 2, 3); parameters.set("conflictRule", 3); parameters.set("maxDegree", 100); @@ -88,12 +87,12 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new PcAll(new ChiSquare())); - algorithms.add(new PcAll(new GSquare())); + algorithms.add(new PC(new ChiSquare())); + algorithms.add(new PC(new GSquare())); // - algorithms.add(new Fges(new BdeuScore())); - algorithms.add(new Fges(new DiscreteBicScore())); - algorithms.add(new Fges(new ConditionalGaussianBicScore())); + algorithms.add(new FGES(new BdeuScore())); + algorithms.add(new FGES(new DiscreteBicScore())); + algorithms.add(new FGES(new ConditionalGaussianBicScore())); Simulations simulations = new Simulations(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleFirstInflection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleFirstInflection.java index f10daf85a5..dff8337be2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleFirstInflection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleFirstInflection.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.FirstInflection; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.score.SemBicScore; import edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel; @@ -108,7 +108,7 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - Algorithm fges = new Fges(new SemBicScore()); + Algorithm fges = new FGES(new SemBicScore()); // algorithms.add(new FirstInflection(fges, "alpha", -7, -2, -.5)); algorithms.add(new FirstInflection(fges, "penaltyDiscount", 0.7, 5, 1)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleStARS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleStARS.java index 1e1b8d0ff8..250b8f77a5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleStARS.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/ExampleStARS.java @@ -26,7 +26,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.FirstInflection; import edu.cmu.tetrad.algcomparison.algorithm.StARS; import edu.cmu.tetrad.algcomparison.algorithm.StabilitySelection; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.score.SemBicScore; import edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel; @@ -113,9 +113,9 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); parameters.set("logScale", false); - algorithms.add(new StabilitySelection(new Fges(new SemBicScore()))); - algorithms.add(new StARS(new Fges(new SemBicScore()), "penaltyDiscount", 1, 5)); - algorithms.add(new FirstInflection(new Fges(new SemBicScore()), "penaltyDiscount", 1, 5, .1)); + algorithms.add(new StabilitySelection(new FGES(new SemBicScore()))); + algorithms.add(new StARS(new FGES(new SemBicScore()), "penaltyDiscount", 1, 5)); + algorithms.add(new FirstInflection(new FGES(new SemBicScore()), "penaltyDiscount", 1, 5, .1)); Simulations simulations = new Simulations(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/LingamStudy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/LingamStudy.java index fec2603e53..52b4a2ea0b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/LingamStudy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/LingamStudy.java @@ -23,11 +23,11 @@ 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.LINGAM; 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; -import edu.cmu.tetrad.algcomparison.algorithm.pairwise.RSkew; +import edu.cmu.tetrad.algcomparison.algorithm.pairwise.RSKEW; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.independence.FisherZ; import edu.cmu.tetrad.algcomparison.score.SemBicScore; @@ -63,9 +63,9 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new Lingam()); + algorithms.add(new LINGAM()); algorithms.add(new R3(new FAS(new FisherZ()))); - algorithms.add(new RSkew(new FAS(new FisherZ()))); + algorithms.add(new RSKEW(new FAS(new FisherZ()))); algorithms.add(new FASK(new FisherZ(), new SemBicScore())); Comparison comparison = new Comparison(); 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..b602b0be9d 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 @@ -23,7 +23,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.score.ConditionalGaussianBicScore; import edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation; @@ -74,7 +74,7 @@ public void testBryan(String... args) { Algorithms algorithms = new Algorithms(); - algorithms.add(new Fges(new ConditionalGaussianBicScore())); + algorithms.add(new FGES(new ConditionalGaussianBicScore())); Simulations simulations = new Simulations(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index 84a8794dac..eabcf27219 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 @@ -23,6 +23,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.CPC; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.graph.RandomGraph; import edu.cmu.tetrad.algcomparison.independence.FisherZ; @@ -399,7 +400,7 @@ public void clarkTest() { ScoreWrapper score = new edu.cmu.tetrad.algcomparison.score.SemBicScore(); IndependenceWrapper test = new FisherZ(); - Algorithm fges = new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges(score); + Algorithm fges = new FGES(score); Graph fgesGraph = fges.search(dataSet, parameters); @@ -1676,7 +1677,7 @@ public static void main(String... args) { LinearFisherModel sim = new LinearFisherModel(graph); sim.createData(parameters, false); ScoreWrapper score = new edu.cmu.tetrad.algcomparison.score.SemBicScore(); - Algorithm alg = new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges(score); + Algorithm alg = new FGES(score); parameters.set(Params.ALPHA, 1e-8); 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..7519747752 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 @@ -21,7 +21,7 @@ package edu.cmu.tetrad.test; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.GesMe; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.GES_ME; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.RandomGraph; @@ -58,7 +58,7 @@ public void test1() { parameters.set(Params.DETERMINISM_THRESHOLD, 1); - GesMe alg = new GesMe(); + GES_ME alg = new GES_ME(); Graph CPDAG = alg.search(dataSet, parameters); System.out.println(CPDAG); 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 97942128e3..c0f255576d 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 @@ -19,8 +19,8 @@ package edu.cmu.tetrad.test; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Fci; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.FCI; import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.GFCI; import edu.cmu.tetrad.algcomparison.independence.BDeuTest; import edu.cmu.tetrad.algcomparison.independence.ChiSquare; @@ -92,7 +92,7 @@ public void testFGESc() { parameters.set(Params.VERBOSE, verbose); ScoreWrapper score = new BdeuScore(); - Algorithm algorithm = new Fges(score); + Algorithm algorithm = new FGES(score); GeneralResamplingTest bootstrapTest = new GeneralResamplingTest( data, algorithm, numBootstrapSamples, 100.0, @@ -148,7 +148,7 @@ public void testFGESd() { parameters.set(Params.VERBOSE, verbose); ScoreWrapper score = new BdeuScore(); - Algorithm algorithm = new Fges(score); + Algorithm algorithm = new FGES(score); GeneralResamplingTest bootstrapTest = new GeneralResamplingTest(data, algorithm, numBootstrapSamples, 100.0, @@ -331,7 +331,7 @@ public void testFCIc() { parameters.set(Params.VERBOSE, verbose); IndependenceWrapper test = new FisherZ(); - Fci algorithm = new Fci(test); + FCI algorithm = new FCI(test); GeneralResamplingTest bootstrapTest = new GeneralResamplingTest(data, algorithm, numBootstrapSamples, 100.0, @@ -393,7 +393,7 @@ public void testFCId() { parameters.set(Params.VERBOSE, verbose); IndependenceWrapper test = new ChiSquare(); - Algorithm algorithm = new Fci(test); + Algorithm algorithm = new FCI(test); GeneralResamplingTest bootstrapTest = new GeneralResamplingTest(data, algorithm, numBootstrapSamples, 100.0, 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 07688b6c5c..efc460267c 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,8 +25,9 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.*; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Fci; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.FCI; import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.GFCI; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.RFCI; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.graph.SingleGraph; import edu.cmu.tetrad.algcomparison.independence.DSeparationTest; @@ -393,7 +394,7 @@ public void doPaperRun(Parameters params, String dataPath, String resultsPath, b algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); if (doPcFges) { - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges( + algorithms.add(new FGES( new edu.cmu.tetrad.algcomparison.score.SemBicScore())); algorithms.add(new PC(new FisherZ())); } @@ -705,7 +706,7 @@ public void testGraspForClark() { Algorithms algorithms = new Algorithms(); algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges( + algorithms.add(new FGES( new edu.cmu.tetrad.algcomparison.score.SemBicScore())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); @@ -933,7 +934,7 @@ public void testGrasp2() { Algorithms algorithms = new Algorithms(); // algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC( // new edu.cmu.tetrad.algcomparison.independence.FisherZ())); - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges( + algorithms.add(new FGES( new edu.cmu.tetrad.algcomparison.score.SemBicScore())); // algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); // algorithms.add(new BRIDGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); @@ -1003,7 +1004,7 @@ public void testLuFigure3() { Algorithms algorithms = new Algorithms(); algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); + algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); Simulations simulations = new Simulations(); simulations.add(new SemSimulation(new RandomForward())); @@ -1063,7 +1064,7 @@ public void testLuFigure6() { Algorithms algorithms = new Algorithms(); algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); + algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); Simulations simulations = new Simulations(); simulations.add(new SemSimulation(new RandomForward())); @@ -1131,7 +1132,7 @@ public void testPaperSimulations() { Algorithms algorithms = new Algorithms(); algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); + algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); Simulations simulations = new Simulations(); simulations.add(new SemSimulation(new RandomForward())); @@ -2022,9 +2023,8 @@ public void testClark() { algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score. EbicScore(), new FisherZ())); algorithms.add(new edu.cmu.tetrad.algcomparison - .algorithm.oracle.cpdag.PcAll(new FisherZ())); - algorithms.add(new edu.cmu.tetrad.algcomparison - .algorithm.oracle.cpdag.Fges(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); + .algorithm.oracle.cpdag.CPC(new FisherZ())); + algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); Node x1 = new ContinuousVariable("X1"); Node x2 = new ContinuousVariable("X2"); @@ -2585,9 +2585,9 @@ public void testFciAlgs() { List algorithms = new ArrayList<>(); - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Fci(test)); + algorithms.add(new FCI(test)); // algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.FciMax(test)); - algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Rfci(test)); + algorithms.add(new RFCI(test)); // for (ScoreWrapper score : scores) { algorithms.add(new GFCI(test, score)); @@ -2756,7 +2756,7 @@ public void testFcoAlgsFromDsep() { Algorithms algorithms = new Algorithms(); - algorithms.add(new Fci(test)); + algorithms.add(new FCI(test)); // algorithms.add(new FciMax(test)); // algorithms.add(new Rfci(test)); // algorithms.add(new GFCI(test, score)); 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 c6b5a4d7d1..731c2c1a70 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 @@ -23,8 +23,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.multi.ImagesPcStableMax; -import edu.cmu.tetrad.algcomparison.algorithm.multi.ImagesSemBic; +import edu.cmu.tetrad.algcomparison.algorithm.multi.IMAGES; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel; import edu.cmu.tetrad.algcomparison.simulation.Simulations; @@ -75,8 +74,7 @@ public void test1() { Algorithms algorithms = new Algorithms(); - algorithms.add(new ImagesSemBic()); - algorithms.add(new ImagesPcStableMax()); + algorithms.add(new IMAGES()); Simulations simulations = new Simulations(); 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 bb9e235883..973f2922b0 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 @@ -23,9 +23,9 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Pcd; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PCD; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.independence.SemBicTest; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; @@ -81,8 +81,8 @@ public void TestCycles_Data_fMRI_FASK() { ScoreWrapper score = new SemBicScore(); algorithms.add(new PC(test)); - algorithms.add(new Fges(score)); - algorithms.add(new Pcd()); + algorithms.add(new FGES(score)); + algorithms.add(new PCD()); Comparison comparison = new Comparison(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmr3.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmr3.java index 445d610ae2..c916780286 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmr3.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestSimulatedFmr3.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.multi.FASK; -import edu.cmu.tetrad.algcomparison.algorithm.multi.FaskConcatenated; +import edu.cmu.tetrad.algcomparison.algorithm.multi.FASK_CONCATENATED; import edu.cmu.tetrad.algcomparison.simulation.Simulations; import edu.cmu.tetrad.algcomparison.statistic.*; import edu.cmu.tetrad.util.Parameters; @@ -215,7 +215,7 @@ public void TestMadelynDAta() { Algorithms algorithms = new Algorithms(); - algorithms.add(new FaskConcatenated()); + algorithms.add(new FASK_CONCATENATED()); Comparison comparison = new Comparison(); 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..1ea24a9239 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 @@ -23,7 +23,7 @@ import edu.cmu.tetrad.algcomparison.Comparison; import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; -import edu.cmu.tetrad.algcomparison.algorithm.multi.FaskConcatenated; +import edu.cmu.tetrad.algcomparison.algorithm.multi.FASK_CONCATENATED; import edu.cmu.tetrad.algcomparison.independence.FisherZ; import edu.cmu.tetrad.algcomparison.score.SemBicScore; import edu.cmu.tetrad.algcomparison.simulation.Simulations; @@ -176,7 +176,7 @@ private void task() { Algorithms algorithms = new Algorithms(); - algorithms.add(new FaskConcatenated(new SemBicScore(), new FisherZ())); + algorithms.add(new FASK_CONCATENATED(new SemBicScore(), new FisherZ())); Comparison comparison = new Comparison(); @@ -239,7 +239,7 @@ public void task2() { simulations.add(new LoadContinuousDataSmithSim("/Users/user/Downloads/smithsim/", i)); } - algorithms.add(new FaskConcatenated( + algorithms.add(new FASK_CONCATENATED( new SemBicScore(), new FisherZ() { })); @@ -305,7 +305,7 @@ public void testTough() { Algorithms algorithms = new Algorithms(); - algorithms.add(new FaskConcatenated( + algorithms.add(new FASK_CONCATENATED( new SemBicScore(), new FisherZ())); From 65e62b02b0b7b04b96f41c1cb651492bad2fe81b Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Sun, 2 Apr 2023 13:28:23 -0500 Subject: [PATCH 37/58] Boss w/ tiered knowledge maybe fixed? --- .../main/java/edu/cmu/tetrad/search/Boss.java | 6 +- .../edu/cmu/tetrad/search/PermutationBes.java | 545 ++++++++++++++++++ 2 files changed, 548 insertions(+), 3 deletions(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java 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 2a0b5811ef..8582a96f75 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Boss.java @@ -28,7 +28,7 @@ * @see PermutationSearch */ public class Boss implements SuborderSearch { - private final Bes bes; + private final PermutationBes bes; private final Score score; private final List variables; private final Map> parents; @@ -52,7 +52,7 @@ public Boss(Score score) { this.parents.put(x, new HashSet<>()); } - this.bes = new Bes(score); + this.bes = new PermutationBes(score); this.bes.setVerbose(false); this.numStarts = 1; } @@ -94,7 +94,7 @@ public void searchSuborder(List prefix, List suborder, Map Z = new ArrayList<>(prefix); Z.addAll(suborder); Graph graph = PermutationSearch.getGraph(Z, parents, this.knowledge, true); - this.bes.bes(graph, Z); + this.bes.bes(graph, Z, suborder); graph.paths().makeValidOrder(suborder); s1 = update(prefix, suborder); } while (s1 > s3); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java new file mode 100644 index 0000000000..35a9a8137a --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PermutationBes.java @@ -0,0 +1,545 @@ +package edu.cmu.tetrad.search; + +import edu.cmu.tetrad.data.Knowledge; +import edu.cmu.tetrad.graph.*; +import edu.cmu.tetrad.util.SublistGenerator; +import edu.cmu.tetrad.util.TetradLogger; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.RecursiveTask; + +import static edu.cmu.tetrad.graph.Edges.directedEdge; +import static org.apache.commons.math3.util.FastMath.min; + + +/** + * Implements the backward equivalence search of FGES. + * + * @author bryanandrews + * @author josephramsey + */ +public class PermutationBes { + private final List variables; + private final Score score; + private Knowledge knowledge = new Knowledge(); + private boolean verbose = true; + private int depth = 4; + + public PermutationBes(@NotNull Score score) { + this.score = score; + this.variables = score.getVariables(); + } + + @NotNull + public List getVariables() { + return this.variables; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge((Knowledge) knowledge); + } + + public void setDepth(int depth) { + if (depth < -1) throw new IllegalArgumentException("Depth should be >= -1."); + this.depth = depth; + } + + private void buildIndexing(List nodes, Map hashIndices) { + + int i = -1; + + for (Node n : nodes) { + hashIndices.put(n, ++i); + } + } + + public void bes(Graph graph, List order, List suborder) { + Map hashIndices = new HashMap<>(); + SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>(); + Map arrowsMapBackward = new ConcurrentHashMap<>(); + int[] arrowIndex = new int[1]; + + buildIndexing(order, hashIndices); + + reevaluateBackward(new HashSet<>(order), graph, hashIndices, arrowIndex, sortedArrowsBack, arrowsMapBackward); + + while (!sortedArrowsBack.isEmpty()) { + Arrow arrow = sortedArrowsBack.first(); + sortedArrowsBack.remove(arrow); + + Node x = arrow.getA(); + Node y = arrow.getB(); + + if (!graph.isAdjacentTo(x, y)) { + continue; + } + + Edge edge = graph.getEdge(x, y); + + if (edge.pointsTowards(x)) { + continue; + } + + if (!getNaYX(x, y, graph).equals(arrow.getNaYX())) { + continue; + } + + if (!new HashSet<>(graph.getParents(y)).equals(new HashSet<>(arrow.getParents()))) { + continue; + } + + if (!validDelete(x, y, arrow.getHOrT(), arrow.getNaYX(), graph, suborder)) { + continue; + } + + Set complement = new HashSet<>(arrow.getNaYX()); + complement.removeAll(arrow.getHOrT()); + + double _bump = deleteEval(x, y, complement, arrow.parents, hashIndices); + + delete(x, y, arrow.getHOrT(), _bump, arrow.getNaYX(), graph); + + Set process = revertToCPDAG(graph); + process.add(x); + process.add(y); + process.addAll(graph.getAdjacentNodes(x)); + process.addAll(graph.getAdjacentNodes(y)); + + reevaluateBackward(new HashSet<>(process), graph, hashIndices, arrowIndex, sortedArrowsBack, arrowsMapBackward); + } + } + + private void delete(Node x, Node y, Set H, double bump, Set naYX, Graph graph) { + Edge oldxy = graph.getEdge(x, y); + + Set diff = new HashSet<>(naYX); + diff.removeAll(H); + + graph.removeEdge(oldxy); + + int numEdges = graph.getNumEdges(); + if (numEdges % 1000 == 0 && numEdges > 0) { + System.out.println("Num edges (backwards) = " + numEdges); + } + + if (verbose) { + int cond = diff.size() + graph.getParents(y).size(); + + String message = (graph.getNumEdges()) + ". DELETE " + x + " --> " + y + " H = " + H + " NaYX = " + naYX + " degree = " + GraphUtils.getDegree(graph) + " indegree = " + GraphUtils.getIndegree(graph) + " diff = " + diff + " (" + bump + ") " + " cond = " + cond; + TetradLogger.getInstance().forceLogMessage(message); + } + + for (Node h : H) { + if (graph.isParentOf(h, y) || graph.isParentOf(h, x)) { + continue; + } + + Edge oldyh = graph.getEdge(y, h); + + graph.removeEdge(oldyh); + + graph.addEdge(directedEdge(y, h)); + + if (verbose) { + TetradLogger.getInstance().forceLogMessage("--- Directing " + oldyh + " to " + graph.getEdge(y, h)); + } + + Edge oldxh = graph.getEdge(x, h); + + if (Edges.isUndirectedEdge(oldxh)) { + graph.removeEdge(oldxh); + + graph.addEdge(directedEdge(x, h)); + + if (verbose) { + TetradLogger.getInstance().forceLogMessage("--- Directing " + oldxh + " to " + graph.getEdge(x, h)); + } + } + } + } + + private double deleteEval(Node x, Node + y, Set complement, Set parents, Map hashIndices) { + Set set = new HashSet<>(complement); + set.addAll(parents); + set.remove(x); + + return -scoreGraphChange(x, y, set, hashIndices); + } + + private double scoreGraphChange(Node x, Node y, Set parents, Map hashIndices) { + int xIndex = hashIndices.get(x); + int yIndex = hashIndices.get(y); + + if (x == y) { + throw new IllegalArgumentException(); + } + + if (parents.contains(y)) { + throw new IllegalArgumentException(); + } + + int[] parentIndices = new int[parents.size()]; + + int count = 0; + for (Node parent : parents) { + parentIndices[count++] = hashIndices.get(parent); + } + + return score.localScoreDiff(xIndex, yIndex, parentIndices); + } + + public Knowledge getKnowledge() { + return knowledge; + } + + private Set revertToCPDAG(Graph graph) { + MeekRules rules = new MeekRules(); + rules.setKnowledge(getKnowledge()); + rules.setAggressivelyPreventCycles(true); + boolean meekVerbose = false; + rules.setVerbose(meekVerbose); + return rules.orientImplied(graph); + } + + private boolean validDelete(Node x, Node y, Set H, Set naYX, Graph graph, List suborder) { + if (existsKnowledge()) { + for (Node h : H) { + if (knowledge.isForbidden(x.getName(), h.getName())) return false; + if (knowledge.isForbidden(y.getName(), h.getName())) return false; + } + } + + Set diff = new HashSet<>(naYX); + diff.removeAll(H); + if (!isClique(diff, graph)) return false; + + graph = new EdgeListGraph(graph); + if (existsKnowledge()) { + for (Node h : H) { + if (graph.isParentOf(h, y) || graph.isParentOf(h, x)) continue; + Edge oldyh = graph.getEdge(y, h); + graph.removeEdge(oldyh); + graph.addEdge(directedEdge(y, h)); + + Edge oldxh = graph.getEdge(x, h); + if (!Edges.isUndirectedEdge(oldxh)) continue; + graph.removeEdge(oldxh); + graph.addEdge(directedEdge(x, h)); + } + } + + List initialOrder = new ArrayList<>(suborder); + Collections.reverse(initialOrder); + + while (!initialOrder.isEmpty()) { + Iterator itr = initialOrder.iterator(); + Node b; + do { + if (itr.hasNext()) b = itr.next(); + else return false; + } while (invalidSink(b, graph)); + graph.removeNode(b); + itr.remove(); + } + + return true; + } + + private boolean invalidSink(Node x, Graph graph) { + LinkedList neighbors = new LinkedList<>(); + + for (Edge edge : graph.getEdges(x)) { + if (edge.getDistalEndpoint(x) == Endpoint.ARROW) return true; + if (edge.getProximalEndpoint(x) == Endpoint.TAIL) neighbors.add(edge.getDistalNode(x)); + } + + while (!neighbors.isEmpty()) { + Node y = neighbors.pop(); + for (Node z : neighbors) if (!graph.isAdjacentTo(y, z)) return true; + } + + return false; + } + + private boolean existsKnowledge() { + return !knowledge.isEmpty(); + } + + private boolean isClique(Set nodes, Graph graph) { + List _nodes = new ArrayList<>(nodes); + for (int i = 0; i < _nodes.size(); i++) { + for (int j = i + 1; j < _nodes.size(); j++) { + if (!graph.isAdjacentTo(_nodes.get(i), _nodes.get(j))) { + return false; + } + } + } + + return true; + } + + private Set getNaYX(Node x, Node y, Graph graph) { + List adj = graph.getAdjacentNodes(y); + Set nayx = new HashSet<>(); + + for (Node z : adj) { + if (z == x) { + continue; + } + Edge yz = graph.getEdge(y, z); + if (!Edges.isUndirectedEdge(yz)) { + continue; + } + if (!graph.isAdjacentTo(z, x)) { + continue; + } + nayx.add(z); + } + + return nayx; + } + + private void reevaluateBackward(Set toProcess, Graph graph, Map hashIndices, + int[] arrowIndex, SortedSet sortedArrowsBack, Map arrowsMapBackward) { + + class BackwardTask extends RecursiveTask { + private final Node r; + private final List adj; + private final Map hashIndices; + private final int chunk; + private final int from; + private final int to; + private final SortedSet sortedArrowsBack; + final Map arrowsMapBackward; + + private BackwardTask(Node r, List 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) { + if (e.pointsTowards(r)) { + calculateArrowsBackward(w, r, graph, arrowsMapBackward, hashIndices, arrowIndex, sortedArrowsBack); + } else if (e.pointsTowards(w)) { + calculateArrowsBackward(r, w, graph, arrowsMapBackward, hashIndices, arrowIndex, sortedArrowsBack); + } else { + calculateArrowsBackward(w, r, graph, arrowsMapBackward, hashIndices, arrowIndex, sortedArrowsBack); + calculateArrowsBackward(r, w, graph, arrowsMapBackward, 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) { + int chunk = n / Runtime.getRuntime().availableProcessors(); + if (chunk < 100) chunk = 100; + return chunk; + } + + private void calculateArrowsBackward(Node a, Node b, Graph + graph, Map arrowsMapBackward, Map hashIndices, + int[] arrowIndex, SortedSet sortedArrowsBack) { + if (existsKnowledge()) { + if (!getKnowledge().noEdgeRequired(a.getName(), b.getName())) { + return; + } + } + + Set naYX = getNaYX(a, b, graph); + 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, 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 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); + } + } + + + 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; + } + } +} \ No newline at end of file From 22f63734d27e277c84b6bda2e604d4173a9ed6f1 Mon Sep 17 00:00:00 2001 From: Bryan Andrews Date: Sun, 2 Apr 2023 18:06:11 -0500 Subject: [PATCH 38/58] Boss w/ tiered knowledge maybe fixed? --- .../edu/cmu/tetrad/search/PermutationBes.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 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 35a9a8137a..05e5034006 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 @@ -222,8 +222,11 @@ private boolean validDelete(Node x, Node y, Set H, Set naYX, Graph g diff.removeAll(H); if (!isClique(diff, graph)) return false; - graph = new EdgeListGraph(graph); if (existsKnowledge()) { + graph = new EdgeListGraph(graph); + Edge oldxy = graph.getEdge(x, y); + graph.removeEdge(oldxy); + for (Node h : H) { if (graph.isParentOf(h, y) || graph.isParentOf(h, x)) continue; Edge oldyh = graph.getEdge(y, h); @@ -235,20 +238,22 @@ private boolean validDelete(Node x, Node y, Set H, Set naYX, Graph g graph.removeEdge(oldxh); graph.addEdge(directedEdge(x, h)); } - } - List initialOrder = new ArrayList<>(suborder); - Collections.reverse(initialOrder); + revertToCPDAG(graph); + List initialOrder = new ArrayList<>(suborder); + Collections.reverse(initialOrder); + + while (!initialOrder.isEmpty()) { + Iterator itr = initialOrder.iterator(); + Node b; + do { + if (itr.hasNext()) b = itr.next(); + else return false; + } while (invalidSink(b, graph)); + graph.removeNode(b); + itr.remove(); + } - while (!initialOrder.isEmpty()) { - Iterator itr = initialOrder.iterator(); - Node b; - do { - if (itr.hasNext()) b = itr.next(); - else return false; - } while (invalidSink(b, graph)); - graph.removeNode(b); - itr.remove(); } return true; From 0d961d89fbe30a172cedc0c14b40ea7ce13fa058 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 4 Apr 2023 11:41:47 -0400 Subject: [PATCH 39/58] Re-adding CCD as non-experimental per user requests. --- .../edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java index c31da6d72f..81e5aaa9e2 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 @@ -28,7 +28,7 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -@Experimental +//@Experimental public class CCD implements Algorithm, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; From 47ff8f0bd35148951d2ec4fb475428625f35bfeb Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 4 Apr 2023 13:20:00 -0400 Subject: [PATCH 40/58] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2c505a4b0..a5f3aa90d4 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,16 @@ where [g] is the maximum number of Gigabytes you wish to allocate to the process We have a tool, [Causal Command](https://github.com/bd2kccd/causal-cmd), that lets you run Tetrad algorithms at the command line. -## Python Integration +## Python and R Integration For Python integration, please see our (still new) [py-tetrad Python project](https://github.com/cmu-phil/py-tetrad), which shows how to integrate arbitrary Java code in the Tetrad project into a Python workflow using the [JPype Python project](https://jpype.readthedocs.io/en/latest/). Also, please see the [causal-learn Python package](https://causal-learn.readthedocs.io/en/latest/), translating some -Tetrad algorithms into Python and adding some algorithms not in Tetrad, now part of the [py-why space](https://github.com/py-why). +Tetrad algorithms into Python and adding some algorithms not in Tetrad, now part of the [py-why space](https://github.com/py-why) + +We added [a method to use Tetrad algorithms in R via Py-Tetrad](https://github.com/cmu-phil/py-tetrad/blob/main/pytetrad/R/REAMDE.md). This is work in progress. ## Documentation From f62710eb4f5c309e9fd9f5764dfaf2749df65b72 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 4 Apr 2023 13:20:50 -0400 Subject: [PATCH 41/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5f3aa90d4..040af3a4ab 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ the [JPype Python project](https://jpype.readthedocs.io/en/latest/). Also, please see the [causal-learn Python package](https://causal-learn.readthedocs.io/en/latest/), translating some Tetrad algorithms into Python and adding some algorithms not in Tetrad, now part of the [py-why space](https://github.com/py-why) -We added [a method to use Tetrad algorithms in R via Py-Tetrad](https://github.com/cmu-phil/py-tetrad/blob/main/pytetrad/R/REAMDE.md). This is work in progress. +We added [a method to use Tetrad algorithms in R via py-tetrad](https://github.com/cmu-phil/py-tetrad/blob/main/pytetrad/R/REAMDE.md). This is work in progress. ## Documentation From 9192d6e3e6c36aa578ea91b8430483eee9f2fdf0 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 4 Apr 2023 17:26:35 -0400 Subject: [PATCH 42/58] Re-adding CCD as non-experimental per user requests. --- tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java index 01507d16e8..3fe43781bb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ccd.java @@ -47,7 +47,7 @@ public final class Ccd implements GraphSearch { private boolean applyR1; public Ccd(IndependenceTest test) { - if (test == null) throw new NullPointerException(); + if (test == null) throw new NullPointerException("Test is not provided"); this.independenceTest = test; this.nodes = test.getVariables(); } From 40799a90da8d878c3f67305b84d78dde94934fb9 Mon Sep 17 00:00:00 2001 From: Joseph Ramsey Date: Tue, 4 Apr 2023 18:04:51 -0400 Subject: [PATCH 43/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 040af3a4ab..7b6bbaec9e 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ the [JPype Python project](https://jpype.readthedocs.io/en/latest/). Also, please see the [causal-learn Python package](https://causal-learn.readthedocs.io/en/latest/), translating some Tetrad algorithms into Python and adding some algorithms not in Tetrad, now part of the [py-why space](https://github.com/py-why) -We added [a method to use Tetrad algorithms in R via py-tetrad](https://github.com/cmu-phil/py-tetrad/blob/main/pytetrad/R/REAMDE.md). This is work in progress. +We added [a method to use Tetrad algorithms in R via py-tetrad](https://github.com/cmu-phil/py-tetrad/blob/main/pytetrad/R/). This is work in progress. ## Documentation From 8fa5fd6976bde03aa659b413ba0622c285db91c7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 6 Apr 2023 10:56:47 -0400 Subject: [PATCH 44/58] Removing FAS concurrent option because of instability. --- .../algorithm/oracle/cpdag/CPC.java | 4 +-- .../algorithm/oracle/cpdag/CpcStable.java | 2 +- .../algorithm/oracle/cpdag/PC.java | 4 +-- .../algorithm/oracle/cpdag/PCMAX.java | 4 +-- .../algorithm/oracle/cpdag/PC_STABLE.java | 2 +- .../java/edu/cmu/tetrad/data/CellTable.java | 8 ++--- .../java/edu/cmu/tetrad/search/CcdMax.java | 2 +- .../edu/cmu/tetrad/search/ChiSquareTest.java | 2 +- .../main/java/edu/cmu/tetrad/search/Cpc.java | 18 +++++------ .../java/edu/cmu/tetrad/search/CpcStable.java | 2 +- .../edu/cmu/tetrad/search/FasConcurrent.java | 1 + .../edu/cmu/tetrad/search/GSquareTest.java | 2 +- .../main/java/edu/cmu/tetrad/search/Pc.java | 18 +++++------ .../java/edu/cmu/tetrad/search/PcAll.java | 30 +++++++++---------- .../java/edu/cmu/tetrad/search/PcMax.java | 18 +++++------ 15 files changed, 59 insertions(+), 58 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 48d8b72b2a..e15573e2e7 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 @@ -63,7 +63,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); +// search.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(); @@ -99,7 +99,7 @@ public DataType getDataType() { public List getParameters() { List parameters = new ArrayList<>(); parameters.add(Params.STABLE_FAS); - parameters.add(Params.CONCURRENT_FAS); +// parameters.add(Params.CONCURRENT_FAS); // parameters.add(Params.COLLIDER_DISCOVERY_RULE); parameters.add(Params.CONFLICT_RULE); parameters.add(Params.DEPTH); 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 index 6f8c3ea910..636ef6dc1e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java @@ -53,7 +53,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setKnowledge(this.knowledge); search.setFasType(PcAll.FasType.STABLE); - search.setConcurrent(PcAll.Concurrent.NO); +// search.setConcurrent(PcAll.Concurrent.NO); search.setColliderDiscovery(PcAll.ColliderDiscovery.CONSERVATIVE); search.setConflictRule(PcAll.ConflictRule.PRIORITY); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java index 06ce9f26a8..cba4e51a29 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 @@ -65,7 +65,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); +// search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); search.setUseMaxP(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); return search.search(); @@ -101,7 +101,7 @@ public DataType getDataType() { public List getParameters() { List parameters = new ArrayList<>(); parameters.add(Params.STABLE_FAS); - parameters.add(Params.CONCURRENT_FAS); +// parameters.add(Params.CONCURRENT_FAS); // parameters.add(Params.COLLIDER_DISCOVERY_RULE); parameters.add(Params.CONFLICT_RULE); parameters.add(Params.DEPTH); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java index d7d64eb97b..f84d48a840 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 @@ -65,7 +65,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); +// search.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(); @@ -101,7 +101,7 @@ public DataType getDataType() { public List getParameters() { List parameters = new ArrayList<>(); parameters.add(Params.STABLE_FAS); - parameters.add(Params.CONCURRENT_FAS); +// parameters.add(Params.CONCURRENT_FAS); // parameters.add(Params.COLLIDER_DISCOVERY_RULE); parameters.add(Params.CONFLICT_RULE); parameters.add(Params.DEPTH); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java index 0a5b8ab09c..0081c191a7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java @@ -46,7 +46,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setKnowledge(this.knowledge); search.setFasType(PcAll.FasType.STABLE); - search.setConcurrent(PcAll.Concurrent.NO); +// search.setConcurrent(PcAll.Concurrent.NO); search.setColliderDiscovery(PcAll.ColliderDiscovery.FAS_SEPSETS); search.setConflictRule(PcAll.ConflictRule.PRIORITY); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java index 1a1d6cf7e2..40ecb0f416 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 @@ -56,7 +56,7 @@ public CellTable(int[] dims) { this.table = new MultiDimIntTable(dims); } - public synchronized void addToTable(DataSet dataSet, int[] indices) { + public void addToTable(DataSet dataSet, int[] indices) { int[] dims = new int[indices.length]; for (int i = 0; i < indices.length; i++) { @@ -107,7 +107,7 @@ public int getNumValues(int varIndex) { * @param coords an array of the sort described above. * @return the marginal sum specified. */ - public synchronized long calcMargin(int[] coords) { + public long calcMargin(int[] coords) { internalCoordCopy(coords); int sum = 0; @@ -140,7 +140,7 @@ public synchronized long calcMargin(int[] coords) { * @param marginVars an int[] value * @return an int value */ - public synchronized long calcMargin(int[] coords, int[] marginVars) { + public long calcMargin(int[] coords, int[] marginVars) { internalCoordCopy(coords); for (int marginVar : marginVars) { @@ -154,7 +154,7 @@ public synchronized long calcMargin(int[] coords, int[] marginVars) { * Makes a copy of the coordinate array so that the original is not messed * up. */ - private synchronized void internalCoordCopy(int[] coords) { + private void internalCoordCopy(int[] coords) { if ((this.coordCopy == null) || (this.coordCopy.length != coords.length)) { this.coordCopy = new int[coords.length]; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java index ad78ec4abf..ea73280c5b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CcdMax.java @@ -200,7 +200,7 @@ public void setApplyOrientAwayFromCollider(boolean applyOrientAwayFromCollider) private Graph fastAdjacencySearch() { long start = MillisecondTimes.timeMillis(); - FasConcurrent fas = new FasConcurrent(this.independenceTest); + Fas fas = new Fas(this.independenceTest); fas.setStable(true); fas.setDepth(getDepth()); fas.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java index f1e6371d5e..e0292b5f78 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/ChiSquareTest.java @@ -91,7 +91,7 @@ public ChiSquareTest(DataSet dataSet, double alpha) { * by summing up chi square and degrees of freedom for each conditional table in turn, where rows or columns that * consist entirely of zeros have been removed. */ - public synchronized Result calcChiSquare(int[] testIndices) { + public Result calcChiSquare(int[] testIndices) { // Reset the cell table for the columns referred to in // 'testIndices.' Do cell coefs for those columns. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java index ac146e9b08..c5817ce05d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cpc.java @@ -101,7 +101,7 @@ public final class Cpc implements GraphSearch { private boolean verbose; private boolean stable; - private boolean concurrent; +// private boolean concurrent; private boolean useHeuristic = false; private int maxPPathLength = -1; private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; @@ -261,11 +261,11 @@ public Graph search() { search.setFasType(PcAll.FasType.REGULAR); } - if (concurrent) { - search.setConcurrent(PcAll.Concurrent.YES); - } else { - search.setConcurrent(PcAll.Concurrent.NO); - } +// if (concurrent) { +// search.setConcurrent(PcAll.Concurrent.YES); +// } else { +// search.setConcurrent(PcAll.Concurrent.NO); +// } search.setColliderDiscovery(PcAll.ColliderDiscovery.CONSERVATIVE); search.setConflictRule(conflictRule); @@ -358,9 +358,9 @@ public void setStable(boolean stable) { this.stable = stable; } - public void setConcurrent(boolean concurrent) { - this.concurrent = concurrent; - } +// public void setConcurrent(boolean concurrent) { +// this.concurrent = concurrent; +// } public void setUseHeuristic(boolean useHeuristic) { this.useHeuristic = useHeuristic; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java index 6dbef27fb0..3de5fe6b38 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/CpcStable.java @@ -195,7 +195,7 @@ public Graph search(List nodes) { this.graph = new EdgeListGraph(nodes); - FasConcurrent fas = new FasConcurrent(getIndependenceTest()); + Fas fas = new Fas(getIndependenceTest()); fas.setStable(true); fas.setOut(this.out); return search(fas, nodes); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java index ccf60b91bd..9d448c1c24 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FasConcurrent.java @@ -43,6 +43,7 @@ * It uses a slightly different algorithm from FasStableConcurrent, probably better. * * @author Joseph Ramsey. + * @deprecated Use Fas instead; this is non-deterministic and gives problems with GSquare and ChiSquare. */ public class FasConcurrent implements IFas { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java index dbaf66689c..e4fb759359 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 @@ -49,7 +49,7 @@ public GSquareTest(DataSet dataSet, double alpha) { * summing up g square and degrees of freedom for each conditional table in turn, where rows or columns that consist * entirely of zeros have been removed. */ - public synchronized Result calcGSquare(int[] testIndices) { + public Result calcGSquare(int[] testIndices) { // Reset the cell table for the columns referred to in // 'testIndices.' Do cell coefs for those columns. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java index 40aaacebcd..752439ec5c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Pc.java @@ -91,7 +91,7 @@ public class Pc implements GraphSearch { private boolean verbose; private boolean stable; - private boolean concurrent; +// private boolean concurrent; private boolean useMaxP = false; private int maxPPathLength = -1; private PcAll.ConflictRule conflictRule = PcAll.ConflictRule.OVERWRITE; @@ -244,11 +244,11 @@ public Graph search(IFas fas, List nodes) { search.setFasType(PcAll.FasType.REGULAR); } - if (concurrent) { - search.setConcurrent(PcAll.Concurrent.YES); - } else { - search.setConcurrent(PcAll.Concurrent.NO); - } +// if (concurrent) { +// search.setConcurrent(PcAll.Concurrent.YES); +// } else { +// search.setConcurrent(PcAll.Concurrent.NO); +// } search.setColliderDiscovery(PcAll.ColliderDiscovery.FAS_SEPSETS); search.setConflictRule(conflictRule); @@ -315,9 +315,9 @@ public void setStable(boolean stable) { this.stable = stable; } - public void setConcurrent(boolean concurrent) { - this.concurrent = concurrent; - } +// public void setConcurrent(boolean concurrent) { +// this.concurrent = concurrent; +// } public void setUseMaxP(boolean useMaxP) { this.useMaxP = useMaxP; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java index 2a32f02b52..02adbffd28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcAll.java @@ -92,7 +92,7 @@ public final class PcAll implements GraphSearch { private boolean useHeuristic; private int maxPathLength; private FasType fasType = FasType.REGULAR; - private Concurrent concurrent = Concurrent.YES; +// private Concurrent concurrent = Concurrent.YES; private ColliderDiscovery colliderDiscovery = ColliderDiscovery.FAS_SEPSETS; private ConflictRule conflictRule = ConflictRule.OVERWRITE; private Graph externalGraph = null; @@ -169,9 +169,9 @@ public void setFasType(FasType fasType) { this.fasType = fasType; } - public void setConcurrent(Concurrent concurrent) { - this.concurrent = concurrent; - } +// public void setConcurrent(Concurrent concurrent) { +// this.concurrent = concurrent; +// } public void setHeuristic(int heuristic) { this.heuristic = heuristic; @@ -320,21 +320,21 @@ public Graph search(List nodes) { IFas fas; if (this.fasType == FasType.REGULAR) { - if (this.concurrent == Concurrent.NO) { +// if (this.concurrent == Concurrent.NO) { fas = new Fas(getIndependenceTest()); ((Fas) fas).setHeuristic(this.heuristic); - } else { - fas = new FasConcurrent(getIndependenceTest()); - ((FasConcurrent) fas).setStable(false); - } +// } else { +// fas = new FasConcurrent(getIndependenceTest()); +// ((FasConcurrent) fas).setStable(false); +// } } else { - if (this.concurrent == Concurrent.NO) { +// if (this.concurrent == Concurrent.NO) { fas = new Fas(getIndependenceTest()); ((Fas) fas).setStable(true); - } else { - fas = new FasConcurrent(getIndependenceTest()); - ((FasConcurrent) fas).setStable(true); - } +// } else { +// fas = new FasConcurrent(getIndependenceTest()); +// ((FasConcurrent) fas).setStable(true); +// } } fas.setKnowledge(getKnowledge()); @@ -605,7 +605,7 @@ public void setExternalGraph(Graph externalGraph) { public enum FasType {REGULAR, STABLE} - public enum Concurrent {YES, NO} + public enum Concurrent {NO};//, NO} public enum ColliderDiscovery {FAS_SEPSETS, CONSERVATIVE, MAX_P} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java index 5e05bb77d9..7752f00a06 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMax.java @@ -244,12 +244,12 @@ public Graph search(IFas fas, List nodes) { search.setFasType(PcAll.FasType.REGULAR); } - if (concurrent) { - search.setConcurrent(PcAll.Concurrent.YES); - } else { - search.setConcurrent(PcAll.Concurrent.NO); - } - +// if (concurrent) { +// search.setConcurrent(PcAll.Concurrent.YES); +// } else { +// search.setConcurrent(PcAll.Concurrent.NO); +// } +// search.setColliderDiscovery(PcAll.ColliderDiscovery.MAX_P); search.setConflictRule(conflictRule); search.setUseHeuristic(useHeuristic); @@ -311,9 +311,9 @@ public void setStable(boolean stable) { this.stable = stable; } - public void setConcurrent(boolean concurrent) { - this.concurrent = concurrent; - } +// public void setConcurrent(boolean concurrent) { +// this.concurrent = concurrent; +// } public void setUseHeuristic(boolean useHeuristic) { this.useHeuristic = useHeuristic; From 9d529d410b56017341b79ba184025fa3a70cf969 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 6 Apr 2023 11:21:23 -0400 Subject: [PATCH 45/58] Removing FAS concurrent option because of instability. --- .../edu/cmu/tetrad/search/GSquareTest.java | 141 +++++++++++++++++- 1 file changed, 139 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 e4fb759359..78b323e1a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java @@ -21,7 +21,9 @@ package edu.cmu.tetrad.search; +import edu.cmu.tetrad.data.CellTable; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.util.CombinationIterator; import edu.cmu.tetrad.util.ProbUtils; @@ -38,12 +40,53 @@ * @author Frank Wimberly original version * @author Joseph Ramsey revision 10/01 */ -public final class GSquareTest extends ChiSquareTest { +public final class GSquareTest { + + /** + * The data set this test uses. + */ + private final DataSet dataSet; + + /** + * The number of values for each variable in the data. + */ + private final int[] dims; + + /** + * Stores the data in the form of a cell table. + */ + private final CellTable cellTable; + + /** + * The significance level of the test. + */ + private double alpha; + public GSquareTest(DataSet dataSet, double alpha) { - super(dataSet, alpha); + if (alpha < 0.0 || alpha > 1.0) { + throw new IllegalArgumentException("Significance level must be in " + + "[0, 1]: " + alpha); + } + + this.dims = new int[dataSet.getNumColumns()]; + + for (int i = 0; i < getDims().length; i++) { + DiscreteVariable variable = + (DiscreteVariable) dataSet.getVariable(i); + this.getDims()[i] = variable.getNumCategories(); + } + + this.dataSet = dataSet; + this.alpha = alpha; + this.cellTable = new CellTable(null); + this.getCellTable().setMissingValue(DiscreteVariable.MISSING_VALUE); } +// public GSquareTest(DataSet dataSet, double alpha) { +// super(dataSet, alpha); +// } + /** * Calculates g square for a conditional crosstabulation table for independence question 0 _||_ 1 | 2, 3, ...max by * summing up g square and degrees of freedom for each conditional table in turn, where rows or columns that consist @@ -222,6 +265,100 @@ public boolean isIndep() { return this.isIndep; } } + + + public int[] getDims() { + return this.dims; + } + + public CellTable getCellTable() { + return this.cellTable; + } + + /** + * @return the getModel significance level being used for tests. + */ + public double getAlpha() { + return this.alpha; + } + + /** + * Sets the significance level to be used for tests. + */ + public void setAlpha(double alpha) { + if (alpha < 0.0 || alpha > 1.0) { + throw new IllegalArgumentException("Significance level must be in " + + "[0, 1]: " + alpha); + } + + this.alpha = alpha; + } + + public int[] selectFromArray(int[] arr, int[] indices) { + int[] retArr = new int[indices.length]; + + for (int i = 0; i < indices.length; i++) { + retArr[i] = arr[indices[i]]; + } + + return retArr; + } + + public DataSet getDataSet() { + return this.dataSet; + } + + public boolean isDetermined(int[] testIndices, double p) { + + // Reset the cell table for the columns referred to in + // 'testIndices.' Do cell coefs for those columns. + this.getCellTable().addToTable(getDataSet(), testIndices); + + // Indicator arrays to tell the cell table which margins + // to calculate. For x _||_ y | z1, z2, ..., we want to + // calculate the margin for x, the margin for y, and the + // margin for x and y. (These will be used later.) + int[] firstVar = {0}; + + int[] condDims = new int[testIndices.length - 1]; + System.arraycopy(selectFromArray(getDims(), testIndices), 1, condDims, 0, + condDims.length); + + int[] coords = new int[testIndices.length]; + int numValues = this.getCellTable().getNumValues(0); + + CombinationIterator combinationIterator = + new CombinationIterator(condDims); + + while (combinationIterator.hasNext()) { + int[] combination = combinationIterator.next(); + System.arraycopy(combination, 0, coords, 1, combination.length); + + long total = this.getCellTable().calcMargin(coords, firstVar); + + if (total == 0) { + continue; + } + + boolean dominates = false; + + for (int i = 0; i < numValues; i++) { + coords[0] = i; + + long numi = this.getCellTable().getValue(coords); + + if ((double) numi / total >= p) { + dominates = true; + } + } + + if (!dominates) { + return false; + } + } + + return true; + } } From 1c4d4d758876208f435f52c954fc2647f72f1643 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 6 Apr 2023 12:10:13 -0400 Subject: [PATCH 46/58] Removing FAS concurrent option because of instability. --- .../java/edu/cmu/tetrad/data/CellTable.java | 46 +++++++++++-------- .../edu/cmu/tetrad/util/MultiDimIntTable.java | 22 ++++----- 2 files changed, 37 insertions(+), 31 deletions(-) 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 40ecb0f416..e32a9e05c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CellTable.java @@ -23,6 +23,8 @@ import edu.cmu.tetrad.util.MultiDimIntTable; +import java.util.Arrays; + /** * Stores a cell count table of arbitrary dimension. Provides methods for @@ -34,10 +36,10 @@ public final class CellTable { - /** - * Stores a copy of coordinates for temporary use. (Reused.) - */ - private int[] coordCopy; +// /** +// * Stores a copy of coordinates for temporary use. (Reused.) +// */ +// private int[] coordCopy; /** * The value used in the data for missing values. @@ -108,24 +110,24 @@ public int getNumValues(int varIndex) { * @return the marginal sum specified. */ public long calcMargin(int[] coords) { - internalCoordCopy(coords); + int[] coordCopy = internalCoordCopy(coords); int sum = 0; int i = -1; - while (++i < this.coordCopy.length) { - if (this.coordCopy[i] == -1) { + while (++i < coordCopy.length) { + if (coordCopy[i] == -1) { for (int j = 0; j < this.table.getDimension(i); j++) { - this.coordCopy[i] = j; - sum += calcMargin(this.coordCopy); + coordCopy[i] = j; + sum += calcMargin(coordCopy); } - this.coordCopy[i] = -1; + coordCopy[i] = -1; return sum; } } - return this.table.getValue(this.coordCopy); + return this.table.getValue(coordCopy); } /** @@ -141,26 +143,30 @@ public long calcMargin(int[] coords) { * @return an int value */ public long calcMargin(int[] coords, int[] marginVars) { - internalCoordCopy(coords); + int[] coordCopy = internalCoordCopy(coords); for (int marginVar : marginVars) { - this.coordCopy[marginVar] = -1; + coordCopy[marginVar] = -1; } - return calcMargin(this.coordCopy); + return calcMargin(coordCopy); } /** * Makes a copy of the coordinate array so that the original is not messed * up. */ - private void internalCoordCopy(int[] coords) { - if ((this.coordCopy == null) || - (this.coordCopy.length != coords.length)) { - this.coordCopy = new int[coords.length]; - } + private int[] internalCoordCopy(int[] coords) { + int[] coordCopy = Arrays.copyOf(coords, coords.length); + +// if ((this.coordCopy == null) || +// (this.coordCopy.length != coords.length)) { +// this.coordCopy = new int[coords.length]; +// } +// +// System.arraycopy(coords, 0, this.coordCopy, 0, coords.length); - System.arraycopy(coords, 0, this.coordCopy, 0, coords.length); + return coordCopy; } private int getMissingValue() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MultiDimIntTable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/MultiDimIntTable.java index b70d529994..602640e43e 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 @@ -76,7 +76,7 @@ public MultiDimIntTable(int[] dims) { * @return the row in the table for the given node and combination of parent * values. */ - public synchronized int getCellIndex(int[] coords) { + public int getCellIndex(int[] coords) { int cellIndex = 0; for (int i = 0; i < this.dims.length; i++) { @@ -93,7 +93,7 @@ public synchronized int getCellIndex(int[] coords) { * row. */ @SuppressWarnings("SameParameterValue") - public synchronized int[] getCoordinates(int cellIndex) { + public int[] getCoordinates(int cellIndex) { int[] coords = new int[this.dims.length]; for (int i = this.dims.length - 1; i >= 0; i--) { @@ -113,7 +113,7 @@ public synchronized int[] getCoordinates(int cellIndex) { * should be incremented (an integer). * @return the new value at that table cell. */ - public synchronized long increment(int[] coords, int value) { + public long increment(int[] coords, int value) { int cellIndex = getCellIndex(coords); if (!this.cells.containsKey(cellIndex)) { @@ -134,7 +134,7 @@ public synchronized long increment(int[] coords, int value) { * @return the new value at that table cell. */ @SuppressWarnings("UnusedDeclaration") - public synchronized long setValue(int[] coords, int value) { + public long setValue(int[] coords, int value) { int cellIndex = getCellIndex(coords); this.cells.put(cellIndex, (long) value); return this.cells.get(cellIndex); @@ -144,7 +144,7 @@ public synchronized long setValue(int[] coords, int value) { * @param coords The coordinates of the table cell to update. * @return the new value at that table cell. */ - public synchronized long getValue(int[] coords) { + public long getValue(int[] coords) { int cellIndex = getCellIndex(coords); if (this.cells == null || !this.cells.containsKey(cellIndex)) { @@ -157,7 +157,7 @@ public synchronized long getValue(int[] coords) { /** * @return this number. */ - public synchronized int getNumCells() { + public int getNumCells() { return this.numCells; } @@ -165,7 +165,7 @@ public synchronized int getNumCells() { * @return this number. */ @SuppressWarnings("UnusedDeclaration") - public synchronized int[] getDimensions() { + public int[] getDimensions() { return this.dims; } @@ -175,14 +175,14 @@ public synchronized int[] getDimensions() { * @param var an int value * @return an int value */ - public synchronized int getDimension(int var) { + public int getDimension(int var) { return this.dims[var]; } /** * @return an int value */ - public synchronized int getNumDimensions() { + public int getNumDimensions() { return this.dims.length; } @@ -192,7 +192,7 @@ public synchronized int getNumDimensions() { * * @param dims an int[] value */ - public final synchronized void reset(int[] dims) { + public final void reset(int[] dims) { if (dims == null) { this.cells = null; } else { @@ -225,7 +225,7 @@ public final synchronized void reset(int[] dims) { } } - public synchronized int getDims(int varIndex) { + public int getDims(int varIndex) { return this.dims[varIndex]; } } From 14c4884b8402f77329e8856dd790449fbc271cae Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 6 Apr 2023 12:43:11 -0400 Subject: [PATCH 47/58] Turned bootstrapping back on for bootstrapping --- .../edu/pitt/dbmi/algo/resampling/GeneralResamplingSearch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingSearch.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingSearch.java index 233c47edc1..05810283bb 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingSearch.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingSearch.java @@ -216,7 +216,7 @@ public List search() { int numNoGraph = 0; - if (false) {//this.runParallel) { + if (this.runParallel) { List> futures = this.pool.invokeAll(tasks); for (Future future : futures) { Graph graph; From 72dd46d85b4bcca20af2a50409739991e4c5bfb7 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 6 Apr 2023 13:17:52 -0400 Subject: [PATCH 48/58] Using FastMath.log for GSquareTest --- .../src/main/java/edu/cmu/tetrad/search/GSquareTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 78b323e1a3..c75923a27d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GSquareTest.java @@ -26,6 +26,7 @@ import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.util.CombinationIterator; import edu.cmu.tetrad.util.ProbUtils; +import org.apache.commons.math3.util.FastMath; import java.util.ArrayList; import java.util.Arrays; @@ -171,7 +172,7 @@ public Result calcGSquare(int[] testIndices) { double expected = e.get(i) / (double) total; if (o.get(i) != 0) { - _gSquare += 2.0 * o.get(i) * log(o.get(i) / expected); + _gSquare += 2.0 * o.get(i) * FastMath.log(o.get(i) / expected); } } From 9cb7cf20365448260791d6a14f913ff64d8090dc Mon Sep 17 00:00:00 2001 From: jdramsey Date: Thu, 6 Apr 2023 13:21:11 -0400 Subject: [PATCH 49/58] Using FastMath.log for GSquareTest --- .../src/main/java/edu/cmu/tetradapp/editor/ScatterPlot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 222afb4e3f..73cb2ce291 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 @@ -119,7 +119,7 @@ public double getCorrelationPValue() { } private double fisherz(double r) { - return 0.5 * FastMath.sqrt(getSampleSize() - 3.0) * (log(1.0 + r) - log(1.0 - r)); + return 0.5 * FastMath.sqrt(getSampleSize() - 3.0) * (FastMath.log(1.0 + r) - FastMath.log(1.0 - r)); } /** From 501ef2307fdabf8541908014fc2a5b5892f67135 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 8 Apr 2023 18:14:13 -0400 Subject: [PATCH 50/58] Added a unit test to make sure knowledge is passed into all the basic algcomparison wrappers. --- .../algorithm/oracle/cpdag/CPC.java | 1 + .../cpdag/{CpcStable.java => CPC_STABLE.java} | 11 +-- .../oracle/cpdag/{GRaSP.java => GRASP.java} | 8 +- .../algorithm/oracle/cpdag/PC.java | 1 + .../algorithm/oracle/cpdag/PCMAX.java | 1 + .../oracle/pag/{SPFCI.java => SP_FCI.java} | 8 +- .../algcomparison/examples/TestBoss.java | 4 +- .../java/edu/cmu/tetrad/data/DataWriter.java | 2 +- .../java/edu/cmu/tetrad/search/MeekRules.java | 7 +- .../tetrad/algcomparison/TestKnowledge.java | 78 +++++++++++++++++++ .../java/edu/cmu/tetrad/test/TestGrasp.java | 26 +++---- 11 files changed, 112 insertions(+), 35 deletions(-) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{CpcStable.java => CPC_STABLE.java} (91%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/{GRaSP.java => GRASP.java} (96%) rename tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/{SPFCI.java => SP_FCI.java} (94%) create mode 100644 tetrad-lib/src/test/java/edu/cmu/tetrad/algcomparison/TestKnowledge.java 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 e15573e2e7..5fe1a5fe6c 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 @@ -63,6 +63,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); 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)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java similarity index 91% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java index 636ef6dc1e..dc1a459f16 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CpcStable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java @@ -26,21 +26,21 @@ * @author jdramsey */ @Bootstrapping -public class CpcStable implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class CPC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Algorithm algorithm; private Knowledge knowledge = new Knowledge(); - public CpcStable() { + public CPC_STABLE() { } - public CpcStable(IndependenceWrapper test) { + public CPC_STABLE(IndependenceWrapper test) { this.test = test; } - public CpcStable(IndependenceWrapper test, Algorithm algorithm) { + public CPC_STABLE(IndependenceWrapper test, Algorithm algorithm) { this.test = test; this.algorithm = algorithm; } @@ -53,13 +53,14 @@ public Graph search(DataModel dataSet, Parameters 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); + CPC_STABLE cpcStable = new CPC_STABLE(this.test, this.algorithm); DataSet data = (DataSet) dataSet; GeneralResamplingTest search = new GeneralResamplingTest(data, cpcStable, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java similarity index 96% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRaSP.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java index 7beca2fa93..e04b5dab9a 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 @@ -37,17 +37,17 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -public class GRaSP implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class GRASP implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { static final long serialVersionUID = 23L; private ScoreWrapper score; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); - public GRaSP() { + public GRASP() { // Used in reflection; do not delete. } - public GRaSP(ScoreWrapper score, IndependenceWrapper test) { + public GRASP(IndependenceWrapper test, ScoreWrapper score) { this.score = score; this.test = test; } @@ -85,7 +85,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { grasp.bestOrder(score.getVariables()); return grasp.getGraph(parameters.getBoolean(Params.OUTPUT_CPDAG)); } else { - GRaSP algorithm = new GRaSP(this.score, this.test); + GRASP algorithm = new GRASP(this.test, this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); 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 cba4e51a29..49a0741cce 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 @@ -65,6 +65,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); + search.setKnowledge(knowledge); // search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); search.setUseMaxP(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); 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 f84d48a840..a8e7cf933b 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 @@ -65,6 +65,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); 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)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SPFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java similarity index 94% rename from tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SPFCI.java rename to tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java index 08c9cbe01e..139ce99aec 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SPFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java @@ -42,18 +42,18 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class SPFCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class SP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); - public SPFCI() { + public SP_FCI() { // Used for reflection; do not delete. } - public SPFCI(ScoreWrapper score, IndependenceWrapper test) { + public SP_FCI(IndependenceWrapper test, ScoreWrapper score) { this.test = test; this.score = score; } @@ -76,7 +76,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { return search.search(); } else { - SPFCI algorithm = new SPFCI(this.score, this.test); + SP_FCI algorithm = new SP_FCI(this.test, this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); search.setKnowledge(data.getKnowledge()); 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 9d410f7042..c312835186 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/examples/TestBoss.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithms; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.BOSS; import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.FGES; -import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.GRaSP; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.GRASP; import edu.cmu.tetrad.algcomparison.graph.RandomForward; import edu.cmu.tetrad.algcomparison.independence.FisherZ; import edu.cmu.tetrad.algcomparison.score.SemBicScore; @@ -69,7 +69,7 @@ public static void main(String... args) { Algorithms algorithms = new Algorithms(); algorithms.add(new FGES(new SemBicScore())); algorithms.add(new BOSS(new SemBicScore())); - algorithms.add(new GRaSP(new SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new SemBicScore())); // algorithms.add(new SP(new SemBicScore())); Simulations simulations = new Simulations(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java index 60f25dd40e..4ad8c4f7d1 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataWriter.java @@ -156,7 +156,7 @@ public static void saveKnowledge(Knowledge knowledge, Writer out) throws IOExcep String forbiddenWithin = knowledge.isTierForbiddenWithin(i) ? "*" : ""; String onlyCanCauseNextTier = knowledge.isOnlyCanCauseNextTier(i) ? "-" : ""; - buf.append("\n").append(i + 1).append(forbiddenWithin).append(onlyCanCauseNextTier).append(" "); + buf.append("\n").append(i).append(forbiddenWithin).append(onlyCanCauseNextTier).append(" "); List tier = knowledge.getTier(i); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MeekRules.java index ea3d241096..69f2133708 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 @@ -126,7 +126,7 @@ public void revertToUnshieldedColliders(List nodes, Graph graph, Set } public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); } @@ -276,11 +276,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; 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 new file mode 100644 index 0000000000..5440400318 --- /dev/null +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/algcomparison/TestKnowledge.java @@ -0,0 +1,78 @@ +package edu.cmu.tetrad.algcomparison; + +import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.*; +import edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.*; +import edu.cmu.tetrad.algcomparison.independence.FisherZ; +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.algcomparison.utils.HasKnowledge; +import edu.cmu.tetrad.data.DataSet; +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.graph.RandomGraph; +import edu.cmu.tetrad.sem.SemIm; +import edu.cmu.tetrad.sem.SemPm; +import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetrad.util.RandomUtil; +import org.junit.Test; + +import java.util.List; + +import static junit.framework.TestCase.assertTrue; + +public class TestKnowledge { + + // Tests to make sure knowledge gets passed into the algcomparison wrappers for + // all methods that take knowledge. + @Test + public void test1() { + RandomUtil.getInstance().setSeed(3848283L); + + Graph graph = RandomGraph.randomGraph(10, 0, 10, 100, 1090, 100, false); + SemPm pm = new SemPm(graph); + SemIm im = new SemIm(pm); + DataSet dataSet = im.simulateData(100, false); + + Knowledge knowledge = new Knowledge(); + knowledge.addToTier(1, "X1"); + for (int i = 2; i <= 10; i++) knowledge.addToTier(0, "X" + i); + + System.out.println(knowledge); + + IndependenceWrapper test = new FisherZ(); + ScoreWrapper score = new SemBicScore(); + Parameters parameters = new Parameters(); + + testKnowledge(dataSet, knowledge, parameters, new BOSS(score)); + testKnowledge(dataSet, knowledge, parameters, new CPC(test)); + testKnowledge(dataSet, knowledge, parameters, new CPC_STABLE(test)); + testKnowledge(dataSet, knowledge, parameters, new FGES(score)); + testKnowledge(dataSet, knowledge, parameters, new GRASP(test, score)); + testKnowledge(dataSet, knowledge, parameters, new PC_STABLE(test)); + testKnowledge(dataSet, knowledge, parameters, new PC(test)); + testKnowledge(dataSet, knowledge, parameters, new PCMAX(test)); + testKnowledge(dataSet, knowledge, parameters, new SP(score)); + + testKnowledge(dataSet, knowledge, parameters, new BFCI(test, score)); + testKnowledge(dataSet, knowledge, parameters, new CFCI(test)); + testKnowledge(dataSet, knowledge, parameters, new FCI(test)); + testKnowledge(dataSet, knowledge, parameters, new FCI_MAX(test)); + testKnowledge(dataSet, knowledge, parameters, new GFCI(test, score)); + testKnowledge(dataSet, knowledge, parameters, new SP(score)); + testKnowledge(dataSet, knowledge, parameters, new GRASP_FCI(test, score)); + testKnowledge(dataSet, knowledge, parameters, new RFCI(test)); + testKnowledge(dataSet, knowledge, parameters, new SP_FCI(test, score)); + } + + private static void testKnowledge(DataSet dataSet, Knowledge knowledge, Parameters parameters, HasKnowledge algorithm) { + algorithm.setKnowledge(knowledge); + Graph _graph = ((Algorithm) algorithm).search(dataSet, parameters); + Node x1 = _graph.getNode("X1"); + List innodes = _graph.getNodesOutTo(x1, Endpoint.ARROW); + assertTrue(innodes.isEmpty()); + } +} 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 efc460267c..0209dcd90e 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 @@ -391,7 +391,7 @@ public void allPaperRuns() { public void doPaperRun(Parameters params, String dataPath, String resultsPath, boolean doPcFges) { Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); if (doPcFges) { algorithms.add(new FGES( @@ -496,7 +496,7 @@ private void testPaperSimulationsVisit(Parameters params, String type) { Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); // algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Pc(new FisherZ())); // algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.Fges(new edu.cmu.tetrad.algcomparison.score.LinearGaussianBicScore())); @@ -705,7 +705,7 @@ public void testGraspForClark() { Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); algorithms.add(new FGES( new edu.cmu.tetrad.algcomparison.score.SemBicScore())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); @@ -771,7 +771,7 @@ public void testGrasp1Bryan() { Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.EbicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.EbicScore())); Simulations simulations = new Simulations(); simulations.add(new SemSimulation(new RandomForward())); @@ -825,7 +825,7 @@ public void testComparePearlGrowShrink() { Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); Simulations simulations = new Simulations(); simulations.add(new SemSimulation(new RandomForward())); @@ -873,7 +873,7 @@ public void testCompareGrasp1Grasp2() { Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); Simulations simulations = new Simulations(); simulations.add(new SemSimulation(new RandomForward())); @@ -1002,7 +1002,7 @@ public void testLuFigure3() { params.set(Params.CACHE_SCORES, true); Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); @@ -1062,7 +1062,7 @@ public void testLuFigure6() { params.set(Params.GRASP_USE_RASKUTTI_UHLER, false); Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); @@ -1130,7 +1130,7 @@ public void testPaperSimulations() { Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); algorithms.add(new edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag.PC(new FisherZ())); algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); @@ -1614,7 +1614,7 @@ private void testForWayne() { // GraphScore score = new GraphScore(graph); List order = list(x1, x2, x3, x4, x5); - GRaSP boss = new GRaSP(new DSeparationScore(graph), new DSeparationTest(graph)); + GRASP boss = new GRASP(new DSeparationTest(graph), new DSeparationScore(graph)); Parameters parameters = new Parameters(); parameters.set(Params.GRASP_USE_RASKUTTI_UHLER, true); @@ -2020,8 +2020,8 @@ public void testClark() { params.set(Params.GRASP_USE_DATA_ORDER, false); Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score. - EbicScore(), new FisherZ())); + algorithms.add(new GRASP(new FisherZ(), new edu.cmu.tetrad.algcomparison.score. + EbicScore())); algorithms.add(new edu.cmu.tetrad.algcomparison .algorithm.oracle.cpdag.CPC(new FisherZ())); algorithms.add(new FGES(new edu.cmu.tetrad.algcomparison.score.SemBicScore())); @@ -2144,7 +2144,7 @@ public void testManyVarManyDegreeTest() { // simulations.add(new SemSimulationTrueModel(new RandomForward())); Algorithms algorithms = new Algorithms(); - algorithms.add(new GRaSP(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), new DSeparationTest())); + algorithms.add(new GRASP(new DSeparationTest(), new edu.cmu.tetrad.algcomparison.score.SemBicScore())); Comparison comparison = new Comparison(); comparison.setShowAlgorithmIndices(true); From 815299437b57f14759b6dec64e34cbe98845adcb Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 8 Apr 2023 18:30:54 -0400 Subject: [PATCH 51/58] Added a unit test to make sure knowledge is passed into all the basic algcomparison wrappers. --- .../test/java/edu/cmu/tetrad/algcomparison/TestKnowledge.java | 1 - 1 file changed, 1 deletion(-) 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 5440400318..7a989031be 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 @@ -62,7 +62,6 @@ public void test1() { testKnowledge(dataSet, knowledge, parameters, new FCI(test)); testKnowledge(dataSet, knowledge, parameters, new FCI_MAX(test)); testKnowledge(dataSet, knowledge, parameters, new GFCI(test, score)); - testKnowledge(dataSet, knowledge, parameters, new SP(score)); testKnowledge(dataSet, knowledge, parameters, new GRASP_FCI(test, score)); testKnowledge(dataSet, knowledge, parameters, new RFCI(test)); testKnowledge(dataSet, knowledge, parameters, new SP_FCI(test, score)); From cd34113e9098e9236e2468620254bc899d359e6b Mon Sep 17 00:00:00 2001 From: jdramsey Date: Sat, 8 Apr 2023 18:57:09 -0400 Subject: [PATCH 52/58] Fixed unit tests. --- .../src/main/java/edu/cmu/tetrad/search/MeekRules.java | 7 ++++++- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java | 5 +++-- tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestPc.java | 2 ++ 3 files changed, 11 insertions(+), 3 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 69f2133708..ea3d241096 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 @@ -126,7 +126,7 @@ public void revertToUnshieldedColliders(List nodes, Graph graph, Set } public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge(knowledge); + this.knowledge = new Knowledge((Knowledge) knowledge); } @@ -276,6 +276,11 @@ 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; 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 eabcf27219..99d1720394 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 @@ -534,8 +534,8 @@ public void testSearch4() { @Test public void testSearch5() { Knowledge knowledge = new Knowledge(); - knowledge.setTier(1, Collections.singletonList("A")); - knowledge.setTier(2, Collections.singletonList("B")); + knowledge.setTier(0, Collections.singletonList("A")); + knowledge.setTier(1, Collections.singletonList("B")); checkWithKnowledge("A-->B", "A-->B", knowledge); } @@ -608,6 +608,7 @@ public void testCites() { * graph. */ private void checkSearch(String inputGraph, String outputGraph) { + NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.NAME); // Set up graph and node objects. Graph graph = GraphUtils.convert(inputGraph); 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 6dad5403d3..785fbb5a0f 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 @@ -182,6 +182,8 @@ private void checkSearch(String inputGraph, String outputGraph) { * graph. */ private void checkWithKnowledge(Knowledge knowledge) { + NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.NAME); + // Set up graph and node objects. Graph graph = GraphUtils.convert("A-->B,C-->B,B-->D"); From 083623f689902c412dff6e0e340d46b167e9f715 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 10 Apr 2023 15:28:41 -0400 Subject: [PATCH 53/58] Fixed unit tests. --- .../algcomparison/score/DegenerateGaussianBicScore.java | 5 +++-- .../java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java | 5 +++-- 2 files changed, 6 insertions(+), 4 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 2738fa19b8..a2fe62b423 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DegenerateGaussianBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DegenerateGaussianBicScore.java @@ -8,6 +8,7 @@ import edu.cmu.tetrad.search.DegenerateGaussianScore; import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetrad.util.Params; import java.util.ArrayList; import java.util.List; @@ -51,8 +52,8 @@ public DataType getDataType() { @Override public List getParameters() { List parameters = new ArrayList<>(); - parameters.add("penaltyDiscount"); - parameters.add("structurePrior"); + parameters.add(Params.PENALTY_DISCOUNT); + parameters.add(Params.STRUCTURE_PRIOR); return parameters; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java index 8fd844fc1d..d6dcca4c3d 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MVPBicScore.java @@ -8,6 +8,7 @@ import edu.cmu.tetrad.search.MVPScore; import edu.cmu.tetrad.search.Score; import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetrad.util.Params; import java.util.ArrayList; import java.util.List; @@ -48,9 +49,9 @@ public DataType getDataType() { @Override public List getParameters() { List parameters = new ArrayList<>(); - parameters.add("structurePrior"); + parameters.add(Params.STRUCTURE_PRIOR); parameters.add("fDegree"); - parameters.add("discretize"); + parameters.add(Params.DISCRETIZE); return parameters; } From 6cbc0be461aa858fe316c0c6feeace916a4e6115 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Mon, 10 Apr 2023 15:29:52 -0400 Subject: [PATCH 54/58] Fixed unit tests. --- .../cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e04b5dab9a..936b043ec6 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 @@ -32,7 +32,7 @@ * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( - name = "GRaSP", + name = "GRASP", command = "grasp", algoType = AlgType.forbid_latent_common_causes ) From d39850732ed8d775096b89e930a2aa060a8b80b9 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 11 Apr 2023 16:56:36 -0400 Subject: [PATCH 55/58] Added an interface, ReturnsBootstrapGraphs, and implemented in several algcomparison wrappers to return the graphs found by a bootstrapping operation. --- .../algorithm/ReturnsBootstrapGraphs.java | 12 +++++++ .../algorithm/oracle/cpdag/BDCE.java | 4 ++- .../algorithm/oracle/cpdag/BOSS.java | 16 ++++++++-- .../algorithm/oracle/cpdag/BOSS_MB.java | 14 ++++++-- .../algorithm/oracle/cpdag/BOSS_MB2.java | 14 ++++++-- .../algorithm/oracle/cpdag/BRIDGES.java | 14 ++++++-- .../algorithm/oracle/cpdag/BRIDGES2.java | 14 ++++++-- .../algorithm/oracle/cpdag/CPC.java | 14 ++++++-- .../algorithm/oracle/cpdag/CPC_STABLE.java | 15 +++++++-- .../algorithm/oracle/cpdag/FAS.java | 15 +++++++-- .../algorithm/oracle/cpdag/FGES.java | 14 ++++++-- .../algorithm/oracle/cpdag/FGES_MB.java | 14 ++++++-- .../oracle/cpdag/FGES_MEASUREMENT.java | 13 ++++++-- .../algorithm/oracle/cpdag/GES_ME.java | 13 ++++++-- .../algorithm/oracle/cpdag/GRASP.java | 15 +++++++-- .../algorithm/oracle/cpdag/GRASP_TOL.java | 15 +++++++-- .../algorithm/oracle/cpdag/PC.java | 15 +++++++-- .../algorithm/oracle/cpdag/PCD.java | 13 ++++++-- .../algorithm/oracle/cpdag/PCMAX.java | 15 +++++++-- .../algorithm/oracle/cpdag/PC_MB.java | 14 ++++++-- .../algorithm/oracle/cpdag/PC_STABLE.java | 15 +++++++-- .../algorithm/oracle/cpdag/SP.java | 14 ++++++-- .../algorithm/oracle/pag/BFCI.java | 14 ++++++-- .../algorithm/oracle/pag/BFCITR.java | 14 ++++++-- .../algorithm/oracle/pag/CCD.java | 15 +++++++-- .../algorithm/oracle/pag/CCD_MAX.java | 15 +++++++-- .../algorithm/oracle/pag/CFCI.java | 15 +++++++-- .../algorithm/oracle/pag/FCI.java | 14 ++++++-- .../algorithm/oracle/pag/FCI_MAX.java | 14 ++++++-- .../algorithm/oracle/pag/GFCI.java | 13 ++++++-- .../algorithm/oracle/pag/GRASP_FCI.java | 14 ++++++-- .../oracle/pag/PAG_SAMPLING_RFCI.java | 7 ++-- .../algorithm/oracle/pag/RFCI.java | 14 ++++++-- .../algorithm/oracle/pag/RFCI_BSC.java | 4 ++- .../algorithm/oracle/pag/SP_FCI.java | 14 ++++++-- .../algorithm/oracle/pag/SVAR_FCI.java | 15 +++++++-- .../algorithm/oracle/pag/SVAR_GFCI.java | 14 ++++++-- .../cmu/tetrad/graph/GraphPersistence.java | 32 +++++++++++++------ .../resampling/GeneralResamplingTest.java | 9 +++++- 39 files changed, 457 insertions(+), 82 deletions(-) create mode 100644 tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ReturnsBootstrapGraphs.java diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ReturnsBootstrapGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ReturnsBootstrapGraphs.java new file mode 100644 index 0000000000..f7375fad5c --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/ReturnsBootstrapGraphs.java @@ -0,0 +1,12 @@ +package edu.cmu.tetrad.algcomparison.algorithm; + +import edu.cmu.tetrad.graph.Graph; + +import java.util.List; + +public interface ReturnsBootstrapGraphs { + + List getBootstrapGraphs(); + +} + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java index 5b88cea39e..f44d6a766a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BDCE.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; import edu.cmu.tetrad.annotation.Bootstrapping; @@ -33,6 +34,8 @@ public class BDCE implements Algorithm, UsesScoreWrapper { static final long serialVersionUID = 23L; private ScoreWrapper score; + private List bootstrapGraphs = new ArrayList<>(); + public BDCE() { // Used in reflection; do not delete. @@ -93,5 +96,4 @@ public ScoreWrapper getScoreWrapper() { public void setScoreWrapper(ScoreWrapper score) { this.score = score; } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java index 340a1f13de..7cfb5930d5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; @@ -34,10 +35,13 @@ ) @Bootstrapping @Experimental -public class BOSS implements Algorithm, UsesScoreWrapper, HasKnowledge { +public class BOSS implements Algorithm, UsesScoreWrapper, HasKnowledge, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public BOSS() { // Used in reflection; do not delete. @@ -79,10 +83,11 @@ public Graph search(DataModel dataModel, Parameters parameters) { GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); search.setKnowledge(this.knowledge); - search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -134,4 +139,9 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java index f8ed8cb404..86e1a06273 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; @@ -35,12 +36,15 @@ //) @Bootstrapping @Experimental -public class BOSS_MB implements Algorithm, HasKnowledge, UsesScoreWrapper { +public class BOSS_MB implements Algorithm, HasKnowledge, UsesScoreWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private String targets; + private List bootstrapGraphs = new ArrayList<>(); + public BOSS_MB() { } @@ -85,7 +89,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -143,4 +149,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java index ef5e0bb134..1468be1959 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BOSS_MB2.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; @@ -31,11 +32,14 @@ //) //@Bootstrapping //@Experimental -public class BOSS_MB2 implements Algorithm, HasKnowledge, UsesScoreWrapper { +public class BOSS_MB2 implements Algorithm, HasKnowledge, UsesScoreWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public BOSS_MB2() { } @@ -65,7 +69,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -117,4 +123,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java index cf922aee8b..79b94c1fef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; @@ -33,12 +34,15 @@ //) //@Bootstrapping //@Experimental -public class BRIDGES implements Algorithm, HasKnowledge, UsesScoreWrapper { +public class BRIDGES implements Algorithm, HasKnowledge, UsesScoreWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public BRIDGES() { @@ -94,7 +98,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -149,4 +155,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java index f00a755db5..cfe1f18dbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/BRIDGES2.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; @@ -33,12 +34,15 @@ //) //@Bootstrapping //@Experimental -public class BRIDGES2 implements Algorithm, HasKnowledge, UsesScoreWrapper { +public class BRIDGES2 implements Algorithm, HasKnowledge, UsesScoreWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public BRIDGES2() { @@ -87,7 +91,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -142,4 +148,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java index 5fe1a5fe6c..d0d1c24f59 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -33,11 +34,14 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -public class CPC implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class CPC implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public CPC() { } @@ -77,7 +81,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -133,4 +139,8 @@ public void setIndependenceWrapper(IndependenceWrapper test) { this.test = test; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java index dc1a459f16..73c9ebbb5e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/CPC_STABLE.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -26,12 +27,15 @@ * @author jdramsey */ @Bootstrapping -public class CPC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class CPC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Algorithm algorithm; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public CPC_STABLE() { } @@ -68,7 +72,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -115,4 +121,9 @@ public void setIndependenceWrapper(IndependenceWrapper independenceWrapper) { public IndependenceWrapper getIndependenceWrapper() { return this.test; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java index 6364478975..fe4f7bcbe9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FAS.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -33,11 +34,14 @@ algoType = AlgType.produce_undirected_graphs ) @Bootstrapping -public class FAS implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class FAS implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public FAS() { } @@ -71,7 +75,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -119,4 +125,9 @@ public IndependenceWrapper getIndependenceWrapper() { public void setIndependenceWrapper(IndependenceWrapper test) { this.test = test; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java index d079a0ba9d..95ecf03b76 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesExternalGraph; @@ -34,7 +35,7 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -public class FGES implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExternalGraph { +public class FGES implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExternalGraph, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; @@ -44,6 +45,7 @@ public class FGES implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExt private Graph externalGraph = null; private Algorithm algorithm = null; + private List bootstrapGraphs = new ArrayList<>(); public FGES() { @@ -111,7 +113,10 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + this.bootstrapGraphs = search.getGraphs(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -169,4 +174,9 @@ public void setScoreWrapper(ScoreWrapper score) { public void setExternalGraph(Algorithm algorithm) { this.algorithm = algorithm; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java index 15e63bc882..5ba19bb41a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MB.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; @@ -35,12 +36,15 @@ algoType = AlgType.search_for_Markov_blankets ) @Bootstrapping -public class FGES_MB implements Algorithm, HasKnowledge, UsesScoreWrapper { +public class FGES_MB implements Algorithm, HasKnowledge, UsesScoreWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private String targetName; + private List bootstrapGraphs = new ArrayList<>(); + public FGES_MB() { } @@ -76,7 +80,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -127,4 +133,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java index c889a508aa..0b25e9b308 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FGES_MEASUREMENT.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.annotation.Bootstrapping; @@ -25,11 +26,13 @@ * @author jdramsey */ @Bootstrapping -public class FGES_MEASUREMENT implements Algorithm, HasKnowledge { +public class FGES_MEASUREMENT implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private final ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public FGES_MEASUREMENT(ScoreWrapper score) { this.score = score; @@ -74,7 +77,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -114,4 +119,8 @@ public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java index 30f2b3321c..45367e8ea8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GES_ME.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.score.SemBicScoreDeterministic; import edu.cmu.tetrad.annotation.Bootstrapping; @@ -30,11 +31,13 @@ */ @Bootstrapping @Experimental -public class GES_ME implements Algorithm { +public class GES_ME implements Algorithm, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private boolean compareToTrue; private final ScoreWrapper score = new SemBicScoreDeterministic(); + private List bootstrapGraphs = new ArrayList<>(); + public GES_ME() { setCompareToTrue(false); @@ -177,7 +180,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -244,4 +249,8 @@ private String tableString(Matrix matrix, NumberFormat nf, double threshold) { } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java index 936b043ec6..ec27882df1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -37,11 +38,14 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -public class GRASP implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class GRASP implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, + HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public GRASP() { // Used in reflection; do not delete. @@ -94,7 +98,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -163,4 +169,9 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java index 696401ae71..25c1664216 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GRASP_TOL.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -39,11 +40,14 @@ ) @Bootstrapping @Experimental -public class GRASP_TOL implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class GRASP_TOL implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, + HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public GRASP_TOL() { // Used in reflection; do not delete. @@ -98,7 +102,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -171,4 +177,9 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java index 49a0741cce..b3643e2ee6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -33,13 +34,16 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -public class PC implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class PC implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private Graph externalGraph = null; + private List bootstrapGraphs = new ArrayList<>(); + public PC() { } @@ -79,7 +83,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -138,4 +144,9 @@ public void setIndependenceWrapper(IndependenceWrapper test) { public void setExternalGraph(Graph externalGraph) { this.externalGraph = externalGraph; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java index a96d674bbe..d46df5b6ae 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCD.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.*; @@ -21,9 +22,10 @@ * @author jdramsey */ @Bootstrapping -public class PCD implements Algorithm, HasKnowledge { +public class PCD implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); public PCD() { } @@ -61,7 +63,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -101,4 +105,9 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java index a8e7cf933b..80a0845068 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -33,13 +34,16 @@ algoType = AlgType.forbid_latent_common_causes ) @Bootstrapping -public class PCMAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class PCMAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private Graph externalGraph = null; + private List bootstrapGraphs = new ArrayList<>(); + public PCMAX() { } @@ -79,7 +83,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -138,4 +144,9 @@ public void setIndependenceWrapper(IndependenceWrapper test) { public void setExternalGraph(Graph externalGraph) { this.externalGraph = externalGraph; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java index 2d08574a10..bc05498271 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_MB.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -35,12 +36,14 @@ algoType = AlgType.search_for_Markov_blankets ) @Bootstrapping -public class PC_MB implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class PC_MB implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List targets; + private List bootstrapGraphs = new ArrayList<>(); public PC_MB() { } @@ -69,7 +72,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -130,4 +135,9 @@ public void setIndependenceWrapper(IndependenceWrapper test) { public IndependenceWrapper getIndependenceWrapper() { return this.test; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java index 0081c191a7..6013c46198 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC_STABLE.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -26,11 +27,14 @@ * @author jdramsey */ @Bootstrapping -public class PC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class PC_STABLE implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public PC_STABLE() { } @@ -60,7 +64,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -108,4 +114,9 @@ public void setIndependenceWrapper(IndependenceWrapper independenceWrapper) { public IndependenceWrapper getIndependenceWrapper() { return this.test; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java index a62947f15b..391a340df4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SP.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; @@ -34,10 +35,12 @@ ) @Bootstrapping @Experimental -public class SP implements Algorithm, UsesScoreWrapper, HasKnowledge { +public class SP implements Algorithm, UsesScoreWrapper, HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public SP() { // Used in reflection; do not delete. @@ -77,7 +80,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -126,4 +131,9 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java index 08ad58d539..5491c9d891 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -45,12 +46,15 @@ ) @Bootstrapping @Experimental -public class BFCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class BFCI implements Algorithm, UsesScoreWrapper, + TakesIndependenceWrapper, HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public BFCI() { // Used for reflection; do not delete. @@ -100,7 +104,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setKnowledge(data.getKnowledge()); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -168,4 +174,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java index 30b0852d49..9d373b7fbc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -42,12 +43,15 @@ //) //@Bootstrapping //@Experimental -public class BFCITR implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class BFCITR implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, + HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public BFCITR() { // Used for reflection; do not delete. @@ -92,7 +96,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setKnowledge(data.getKnowledge()); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -165,4 +171,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java index 81e5aaa9e2..9b893df318 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; import edu.cmu.tetrad.annotation.AlgType; @@ -15,6 +16,7 @@ import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; +import java.util.ArrayList; import java.util.List; /** @@ -29,9 +31,11 @@ ) @Bootstrapping //@Experimental -public class CCD implements Algorithm, TakesIndependenceWrapper { +public class CCD implements Algorithm, TakesIndependenceWrapper, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; + private List bootstrapGraphs = new ArrayList<>(); + public CCD() { // Used in reflection; do not delete. @@ -58,7 +62,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -97,4 +103,9 @@ public IndependenceWrapper getIndependenceWrapper() { public void setIndependenceWrapper(IndependenceWrapper independenceWrapper) { this.test = independenceWrapper; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java index f69a754ee6..99c94ad1b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CCD_MAX.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.annotation.Bootstrapping; @@ -15,6 +16,7 @@ import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -29,11 +31,13 @@ oracleType = OracleType.Test )*/ @Bootstrapping -public class CCD_MAX implements Algorithm, HasKnowledge { +public class CCD_MAX implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private final IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public CCD_MAX(IndependenceWrapper test) { this.test = test; @@ -61,7 +65,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -107,4 +113,9 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java index 1b5d252dbc..924b881e88 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/CFCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.annotation.Bootstrapping; @@ -14,6 +15,7 @@ import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -25,11 +27,13 @@ * @author jdramsey */ @Bootstrapping -public class CFCI implements Algorithm, HasKnowledge { +public class CFCI implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private final IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public CFCI(IndependenceWrapper test) { this.test = test; @@ -54,7 +58,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -96,4 +102,9 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = new Knowledge((Knowledge) knowledge); } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java index a2dceaf2c6..ca47ca337d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -33,11 +34,14 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public FCI() { } @@ -80,7 +84,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -135,4 +141,8 @@ public void setIndependenceWrapper(IndependenceWrapper test) { this.test = test; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java index fd5ebc3d58..d12c2069aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FCI_MAX.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -33,11 +34,14 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class FCI_MAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class FCI_MAX implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public FCI_MAX() { } @@ -78,7 +82,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -131,4 +137,8 @@ public void setIndependenceWrapper(IndependenceWrapper test) { this.test = test; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java index 9d130c6925..f138cf04ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GFCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -37,12 +38,14 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class GFCI implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper { +public class GFCI implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); public GFCI() { } @@ -91,7 +94,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -157,4 +162,8 @@ public IndependenceWrapper getIndependenceWrapper() { return this.test; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java index a8157a7f65..ee36aa6715 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -45,12 +46,15 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class GRASP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class GRASP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, + HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public GRASP_FCI() { // Used for reflection; do not delete. @@ -117,7 +121,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -195,4 +201,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java index efc62fd94b..06dbdcbf13 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PAG_SAMPLING_RFCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.independence.ProbabilisticTest; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -14,6 +15,7 @@ import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -30,7 +32,7 @@ algoType = AlgType.allow_latent_common_causes ) //@Experimental -public class PAG_SAMPLING_RFCI implements Algorithm, HasKnowledge { +public class PAG_SAMPLING_RFCI implements Algorithm, HasKnowledge{ public static final List PAG_SAMPLING_RFCI_PARAMETERS = new LinkedList<>(); public static final List RFCI_PARAMETERS = new LinkedList<>(); @@ -54,6 +56,8 @@ public class PAG_SAMPLING_RFCI implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final IndependenceWrapper test = new ProbabilisticTest(); private Knowledge knowledge; + private List bootstrapGraphs = new ArrayList<>(); + @Override public Graph search(DataModel dataSet, Parameters parameters) { @@ -111,5 +115,4 @@ public Knowledge getKnowledge() { public void setKnowledge(Knowledge knowledge) { this.knowledge = knowledge; } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java index a055753023..c000d8bfc0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -33,11 +34,13 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class RFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class RFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public RFCI() { } @@ -73,7 +76,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -122,4 +127,9 @@ public IndependenceWrapper getIndependenceWrapper() { public void setIndependenceWrapper(IndependenceWrapper test) { this.test = test; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java index 003f0a5825..e9edeefa15 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RFCI_BSC.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.independence.ProbabilisticTest; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -36,6 +37,8 @@ public class RFCI_BSC implements Algorithm, HasKnowledge { static final long serialVersionUID = 23L; private final IndependenceWrapper test = new ProbabilisticTest(); private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + @Override public Knowledge getKnowledge() { @@ -108,5 +111,4 @@ public List getParameters() { return parameters; } - } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java index 139ce99aec..3b572d0425 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -42,12 +43,15 @@ algoType = AlgType.allow_latent_common_causes ) @Bootstrapping -public class SP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge { +public class SP_FCI implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, + HasKnowledge, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + public SP_FCI() { // Used for reflection; do not delete. @@ -82,7 +86,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setKnowledge(data.getKnowledge()); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -150,4 +156,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java index 9b3c958dc2..4ad43892e6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; @@ -35,11 +36,14 @@ ) @TimeSeries @Bootstrapping -public class SVAR_FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper { +public class SVAR_FCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge; + private List bootstrapGraphs = new ArrayList<>(); + public SVAR_FCI() { } @@ -79,7 +83,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -125,4 +131,9 @@ public IndependenceWrapper getIndependenceWrapper() { public void setIndependenceWrapper(IndependenceWrapper test) { this.test = test; } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java index d48a5c2be3..44187e2a11 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java @@ -1,6 +1,7 @@ package edu.cmu.tetrad.algcomparison.algorithm.oracle.pag; import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; @@ -37,12 +38,15 @@ ) @TimeSeries @Bootstrapping -public class SVAR_GFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper, UsesScoreWrapper { +public class SVAR_GFCI implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + UsesScoreWrapper, ReturnsBootstrapGraphs { static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge; + private List bootstrapGraphs = new ArrayList<>(); + public SVAR_GFCI() { } @@ -85,7 +89,9 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - return search.search(); + Graph graph = search.search(); + this.bootstrapGraphs = search.getGraphs(); + return graph; } } @@ -146,4 +152,8 @@ public void setScoreWrapper(ScoreWrapper score) { this.score = score; } + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java index eac2cd9469..7296b9b7c5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java @@ -9,6 +9,8 @@ import nu.xom.*; import java.io.*; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -518,15 +520,19 @@ public static String graphToDot(Graph graph) { Endpoint end1 = edge.getEndpoint1(); Endpoint end2 = edge.getEndpoint2(); - if (n1.compareTo(n2) > 0) { - String temp = n1; - n1 = n2; - n2 = temp; - - Endpoint tmp = end1; - end1 = end2; - end2 = tmp; - } + // These may be in the graph but they represent edges not in the ensemble for which + // bootstrap information is available. + if (end1 == Endpoint.NULL || end2 == Endpoint.NULL) continue; + +// if (n1.compareTo(n2) > 0) { +// String temp = n1; +// n1 = n2; +// n2 = temp; +// +// Endpoint tmp = end1; +// end1 = end2; +// end2 = tmp; +// } builder.append(" \"").append(n1).append("\" -> \"").append(n2).append("\" ["); if (end1 != Endpoint.TAIL) { @@ -540,6 +546,8 @@ public static String graphToDot(Graph graph) { builder.append("none"); } else if (end1 == Endpoint.CIRCLE) { builder.append("odot"); + } else { + builder.append("xdot"); } builder.append(", arrowhead="); if (end2 == Endpoint.ARROW) { @@ -548,6 +556,8 @@ public static String graphToDot(Graph graph) { builder.append("none"); } else if (end2 == Endpoint.CIRCLE) { builder.append("odot"); + } else { + builder.append("xdot"); } // Bootstrapping @@ -593,7 +603,9 @@ public static String graphToDot(Graph graph) { } } - label.append("\\n[").append(edgeTypeString).append("]:").append(edgeTypeProbability.getProbability()); + NumberFormat nf = new DecimalFormat("0.000"); + + label.append("\\n[").append(edgeTypeString).append("]:").append(nf.format(edgeTypeProbability.getProbability())); } } builder.append(", label=\"").append(label).append("\", fontname=courier"); diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java index 6e2fdc2013..fbf530e9bf 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java @@ -26,7 +26,7 @@ public class GeneralResamplingTest { private Parameters parameters; private Algorithm algorithm; private MultiDataSetAlgorithm multiDataSetAlgorithm; - private List graphs; + private List graphs = new ArrayList<>(); private boolean verbose; /** * Specification of forbidden and required edges. @@ -328,4 +328,11 @@ public void setScoreWrapper(ScoreWrapper scoreWrapper) { this.scoreWrapper = scoreWrapper; } + /** + * Returns the individual bootstrap result graphs. + * @return A list of these Graphs. + */ + public List getGraphs() { + return graphs == null ? new ArrayList<>() : this.graphs; + } } From 355250738a51e2f7e6259c147f30f62cf0389cfe Mon Sep 17 00:00:00 2001 From: jdramsey Date: Tue, 11 Apr 2023 23:51:27 -0400 Subject: [PATCH 56/58] Typo. --- .../edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java index fbf530e9bf..7ca421aebe 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/resampling/GeneralResamplingTest.java @@ -301,7 +301,7 @@ public Graph search() { int numNoGraphs = this.resamplingSearch.getNumNograph(); TetradLogger.getInstance().forceLogMessage( - "Bootstrappiung: Number of searches that didn't return a graph = " + numNoGraphs); + "Bootstrapping: Number of searches that didn't return a graph = " + numNoGraphs); if (this.verbose) { this.out.println("Resampling number is : " + this.graphs.size()); @@ -333,6 +333,6 @@ public void setScoreWrapper(ScoreWrapper scoreWrapper) { * @return A list of these Graphs. */ public List getGraphs() { - return graphs == null ? new ArrayList<>() : this.graphs; + return graphs == null ? new ArrayList<>() : new ArrayList<>(this.graphs); } } From 99c2e335799e2fcb3ac213fcd3d10c8015a92622 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 12 Apr 2023 18:02:48 -0400 Subject: [PATCH 57/58] Fixing a bootstrapping for GRaSP-FCI. --- .../algcomparison/algorithm/multi/IMAGES.java | 34 +++++-------------- .../algorithm/oracle/cpdag/PC.java | 2 +- .../algorithm/oracle/cpdag/PCMAX.java | 2 +- .../algorithm/oracle/pag/BFCI.java | 2 +- .../algorithm/oracle/pag/BFCITR.java | 4 +-- .../algorithm/oracle/pag/GRASP_FCI.java | 2 +- .../algorithm/oracle/pag/SP_FCI.java | 3 +- .../algorithm/oracle/pag/SVAR_FCI.java | 4 +-- .../algorithm/oracle/pag/SVAR_GFCI.java | 4 +-- .../cmu/tetrad/graph/GraphPersistence.java | 5 ++- 10 files changed, 21 insertions(+), 41 deletions(-) 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 eece0ff8c7..cfe48ddbb5 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 @@ -79,33 +79,14 @@ public Graph search(List dataSets, Parameters parameters) { if (meta == 1) { edu.cmu.tetrad.search.Fges search = new edu.cmu.tetrad.search.Fges(score); - search.setKnowledge(new Knowledge((Knowledge) knowledge)); + search.setKnowledge(this.knowledge); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); return search.search(); - } -// else if (meta == 2) { -// Grasp search = new edu.cmu.tetrad.search.Grasp(score); -// search.setKnowledge(this.knowledge); -// search.setVerbose(parameters.getBoolean(Params.VERBOSE)); -// search.bestOrder(score.getVariables()); -// search.setDepth(6); -// search.setSingularDepth(1); -// search.setNonSingularDepth(1); -// return search.getGraph(true); -// } - else if (meta == 2) { + } else if (meta == 2) { PermutationSearch search = new PermutationSearch(new Boss(score)); - search.setKnowledge(new Knowledge((Knowledge) knowledge)); + search.setKnowledge(this.knowledge); return search.search(); - } -// else if (meta == 4) { -// Boss search = new edu.cmu.tetrad.search.Boss(score); -// search.setKnowledge(this.knowledge); -// search.setVerbose(parameters.getBoolean(Params.VERBOSE)); -// search.bestOrder(score.getVariables()); -// return search.getGraph(); -// } - else if (meta == 3) { + } else if (meta == 3) { BridgesOld search = new edu.cmu.tetrad.search.BridgesOld(score); search.setKnowledge(this.knowledge); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); @@ -144,7 +125,7 @@ else if (meta == 3) { 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)); - search.setKnowledge(dataSets.get(0).getKnowledge()); + search.setKnowledge(this.knowledge); search.setScoreWrapper(score); return search.search(); } @@ -162,8 +143,9 @@ public Graph search(DataModel dataSet, Parameters parameters) { images, 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); + parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), + parameters.getInt(Params.RESAMPLING_ENSEMBLE), + parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); if (score == null) { System.out.println(); 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 b3643e2ee6..a5638cc26c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PC.java @@ -69,7 +69,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setKnowledge(knowledge); + dataModel.setKnowledge(this.knowledge); // search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); search.setUseMaxP(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); 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 80a0845068..d04bcd95ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PCMAX.java @@ -69,7 +69,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setDepth(parameters.getInt(Params.DEPTH)); search.setAggressivelyPreventCycles(true); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setKnowledge(knowledge); + dataModel.setKnowledge(this.knowledge); // search.setConcurrent(parameters.getBoolean(Params.CONCURRENT_FAS)); search.setUseHeuristic(parameters.getBoolean(Params.USE_MAX_P_ORIENTATION_HEURISTIC)); search.setMaxPPathLength(parameters.getInt(Params.MAX_P_ORIENTATION_MAX_PATH_LENGTH)); 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 5491c9d891..226fe914f9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCI.java @@ -101,7 +101,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { BFCI algorithm = new BFCI(this.test, this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(data.getKnowledge()); + search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); Graph graph = search.search(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java index 9d373b7fbc..79f79d590a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/BFCITR.java @@ -80,7 +80,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setMaxPathLength(parameters.getInt(Params.MAX_PATH_LENGTH)); search.setCompleteRuleSetUsed(parameters.getBoolean(Params.COMPLETE_RULE_SET_USED)); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setKnowledge(knowledge); + dataModel.setKnowledge(this.knowledge); Object obj = parameters.get(Params.PRINT_STREAM); @@ -93,7 +93,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { BFCITR algorithm = new BFCITR(this.test, this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(data.getKnowledge()); + search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); Graph graph = search.search(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java index ee36aa6715..774e3dea67 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GRASP_FCI.java @@ -117,7 +117,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(data.getKnowledge()); + search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java index 3b572d0425..9d2b2d9e05 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SP_FCI.java @@ -70,7 +70,6 @@ public Graph search(DataModel dataModel, Parameters parameters) { search.setMaxPathLength(parameters.getInt(Params.MAX_PATH_LENGTH)); search.setCompleteRuleSetUsed(parameters.getBoolean(Params.COMPLETE_RULE_SET_USED)); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); - search.setKnowledge(search.getKnowledge()); Object obj = parameters.get(Params.PRINT_STREAM); @@ -83,7 +82,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { SP_FCI algorithm = new SP_FCI(this.test, this.score); DataSet data = (DataSet) dataModel; GeneralResamplingTest search = new GeneralResamplingTest(data, algorithm, parameters.getInt(Params.NUMBER_RESAMPLING), parameters.getDouble(Params.PERCENT_RESAMPLE_SIZE), parameters.getBoolean(Params.RESAMPLING_WITH_REPLACEMENT), parameters.getInt(Params.RESAMPLING_ENSEMBLE), parameters.getBoolean(Params.ADD_ORIGINAL_DATASET)); - search.setKnowledge(data.getKnowledge()); + search.setKnowledge(this.knowledge); search.setParameters(parameters); search.setVerbose(parameters.getBoolean(Params.VERBOSE)); Graph graph = search.search(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java index 4ad43892e6..442772741b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_FCI.java @@ -65,9 +65,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { knowledge = timeSeries.getKnowledge(); } - if (this.knowledge != null) { - dataModel.setKnowledge(this.knowledge); - } + dataModel.setKnowledge(this.knowledge); edu.cmu.tetrad.search.SvarFci search = new edu.cmu.tetrad.search.SvarFci(this.test.getTest(dataModel, parameters)); search.setDepth(parameters.getInt(Params.DEPTH)); search.setKnowledge(this.knowledge); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java index 44187e2a11..3e836986ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SVAR_GFCI.java @@ -70,9 +70,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { knowledge = timeSeries.getKnowledge(); } - if (this.knowledge != null) { - dataModel.setKnowledge(this.knowledge); - } + dataModel.setKnowledge(this.knowledge); edu.cmu.tetrad.search.SvarGFci search = new edu.cmu.tetrad.search.SvarGFci(this.test.getTest(dataModel, parameters), this.score.getScore(dataModel, parameters)); search.setKnowledge(this.knowledge); 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 7296b9b7c5..c3f636839e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphPersistence.java @@ -513,7 +513,10 @@ public static Graph readerToGraphJson(Reader reader) throws IOException { public static String graphToDot(Graph graph) { StringBuilder builder = new StringBuilder(); builder.append("digraph g {\n"); - for (Edge edge : graph.getEdges()) { + List edges = new ArrayList<>(graph.getEdges()); + Collections.sort(edges); + + for (Edge edge : edges) { String n1 = edge.getNode1().getName(); String n2 = edge.getNode2().getName(); From 49e199fc675faf2c6a85d77c633dca52f0d622f8 Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 12 Apr 2023 18:12:15 -0400 Subject: [PATCH 58/58] Setting version to 7.3.2. --- data-reader/pom.xml | 2 +- pom.xml | 2 +- tetrad-gui/pom.xml | 2 +- tetrad-lib/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data-reader/pom.xml b/data-reader/pom.xml index a1142682df..77f8eb6ec9 100644 --- a/data-reader/pom.xml +++ b/data-reader/pom.xml @@ -5,7 +5,7 @@ io.github.cmu-phil tetrad - 7.3.1-SNAPSHOT + 7.3.2 data-reader diff --git a/pom.xml b/pom.xml index 5cda6ed2c8..9d3ccd4389 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.cmu-phil tetrad - 7.3.1-SNAPSHOT + 7.3.2 pom Tetrad Project diff --git a/tetrad-gui/pom.xml b/tetrad-gui/pom.xml index 5b8a82b59f..efe9da2cd6 100644 --- a/tetrad-gui/pom.xml +++ b/tetrad-gui/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.3.1-SNAPSHOT + 7.3.2 tetrad-gui diff --git a/tetrad-lib/pom.xml b/tetrad-lib/pom.xml index 21ed1a6583..1d6765cb77 100644 --- a/tetrad-lib/pom.xml +++ b/tetrad-lib/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.3.1-SNAPSHOT + 7.3.2 tetrad-lib