diff --git a/data-reader/pom.xml b/data-reader/pom.xml index a8de779f7f..1c486fb130 100644 --- a/data-reader/pom.xml +++ b/data-reader/pom.xml @@ -5,7 +5,7 @@ io.github.cmu-phil tetrad - 7.5.0 + 7.5.1-SNAPSHOT data-reader diff --git a/pom.xml b/pom.xml index 1a97a9a344..7a8587268d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.cmu-phil tetrad - 7.5.0 + 7.5.1-SNAPSHOT pom Tetrad Project @@ -116,7 +116,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.6.0 /usr/bin/javadoc diff --git a/tetrad-gui/pom.xml b/tetrad-gui/pom.xml index 2c23929000..d865a82df7 100644 --- a/tetrad-gui/pom.xml +++ b/tetrad-gui/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.5.0 + 7.5.1-SNAPSHOT tetrad-gui diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java index 2c21a50ebe..bade4439ef 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/CPDAGDisplay.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.JOptionUtils; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.workbench.DisplayEdge; @@ -49,7 +49,7 @@ public class CPDAGDisplay extends JPanel implements GraphEditable { private GraphWorkbench workbench; public CPDAGDisplay(Graph graph) { - List dags = GraphSearchUtils.generateCpdagDags(graph, false); + List dags = GraphTransforms.generateCpdagDags(graph, false); if (dags.size() == 0) { JOptionPane.showMessageDialog( @@ -81,7 +81,7 @@ public CPDAGDisplay(Graph graph) { String option = (String) box.getSelectedItem(); if ("Orient --- only".equals(option)) { - List _dags = GraphSearchUtils.generateCpdagDags(graph, false); + List _dags = GraphTransforms.generateCpdagDags(graph, false); dags.clear(); dags.addAll(_dags); SpinnerNumberModel model1 = @@ -97,7 +97,7 @@ public CPDAGDisplay(Graph graph) { totalLabel.setText(" of " + dags.size()); CPDAGDisplay.this.workbench.setGraph(dags.get(0)); } else if ("Orient ---, <->".equals(option)) { - List _dags = GraphSearchUtils.generateCpdagDags(graph, true); + List _dags = GraphTransforms.generateCpdagDags(graph, true); dags.clear(); dags.addAll(_dags); SpinnerNumberModel model1 = diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStats.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStats.java index 5187a63dad..60a03da317 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStats.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStats.java @@ -100,7 +100,7 @@ public static String generateDescriptiveStats(DataSet dataSet, Node variable, table.setToken(rowindex, 0, "Skewness:"); table.setToken(rowindex++, 1, nf.format(StatUtils.skewness(data))); - table.setToken(rowindex, 0, "Kurtosis:"); + table.setToken(rowindex, 0, "" + "Kurtosis:"); table.setToken(rowindex++, 1, nf.format(StatUtils.kurtosis(data))); if (continuous) { @@ -120,7 +120,7 @@ public static String generateDescriptiveStats(DataSet dataSet, Node variable, } table.setToken(rowindex, 0, "Constant Columns:"); - List constantColumns = DataUtils.getConstantColumns(dataSet); + List constantColumns = DataTransforms.getConstantColumns(dataSet); table.setToken(rowindex++, 1, constantColumns.isEmpty() ? "None" : constantColumns.toString()); table.setToken(rowindex, 0, "Example Nonsingular (2 - 3 vars):"); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsAction.java index 2944d34e36..31d34c3f1a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsAction.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetradapp.util.DesktopController; @@ -87,13 +88,16 @@ private Box createDescriptiveStatsDialog() { String coonstantColumnsString = "Constant Columns: "; assert dataSet != null; - java.util.List constantColumns = DataUtils.getConstantColumns(dataSet); + java.util.List constantColumns = DataTransforms.getConstantColumns(dataSet); coonstantColumnsString += constantColumns.isEmpty() ? "None" : constantColumns.toString(); + String nonsingularString = null; - String nonsingularString = "Example Nonsingular (2 vars): "; - CovarianceMatrix covarianceMatrix = new CovarianceMatrix(dataSet); - List exampleNonsingular = DataUtils.getExampleNonsingular(covarianceMatrix, 2); - nonsingularString += exampleNonsingular == null ? "None" : exampleNonsingular.toString(); + if (dataSet.isContinuous()) { + nonsingularString = "Example Nonsingular (2 vars): "; + CovarianceMatrix covarianceMatrix = new CovarianceMatrix(dataSet); + List exampleNonsingular = DataUtils.getExampleNonsingular(covarianceMatrix, 2); + nonsingularString += exampleNonsingular == null ? "None" : exampleNonsingular.toString(); + } Box box = Box.createVerticalBox(); @@ -128,7 +132,11 @@ private Box createDescriptiveStatsDialog() { box.add(b1); Box b2 = Box.createHorizontalBox(); - b2.add(new JLabel(nonsingularString)); + if (nonsingularString != null) { + b2.add(new JLabel(nonsingularString)); + } + +// b2.add(new JLabel(nonsingularString)); b2.add(Box.createHorizontalGlue()); box.add(b2); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsModel.java index 2c24894216..eec539d94c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/DescriptiveStatsModel.java @@ -108,9 +108,6 @@ public static Ret generateDescriptiveStats(DataSet dataSet, Node variable) { names.add("Kurtosis"); stats.add(StatUtils.kurtosis(data)); - names.add("Skewness"); - stats.add(StatUtils.skewness(data)); - if (continuous) { double[] median = DescriptiveStats.median(data); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisAction.java index b1e172a819..3ae769c4c6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisAction.java @@ -160,7 +160,7 @@ private JPanel createDialog(FactorAnalysis analysis) { } } - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); LayoutUtil.fruchtermanReingoldLayout(graph); GraphWorkbench workbench = new GraphWorkbench(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisEditor.java index 2df4093deb..690b09a30a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/FactorAnalysisEditor.java @@ -75,7 +75,7 @@ protected void setup(String resultLabel) { display.setEditable(false); display.setFont(new Font("Monospaced", Font.PLAIN, 12)); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); LayoutUtil.fruchtermanReingoldLayout(graph); GraphWorkbench workbench = new GraphWorkbench(graph); @@ -132,7 +132,7 @@ protected void doDefaultArrangement(Graph resultGraph) { LayoutUtil.arrangeBySourceGraph(resultGraph, getLatestWorkbenchGraph()); } else { - LayoutUtil.circleLayout(resultGraph); + LayoutUtil.defaultLayout(resultGraph); } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java index 7df5e69274..0df4cc9f87 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GraphAdjacencyIntersectionWrapper.java @@ -39,7 +39,7 @@ * @author josephramsey */ public class GraphAdjacencyIntersectionWrapper implements SessionModel, DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private List graphs; private String name = ""; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXmlAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXmlAction.java index 99704b0f48..5bec3bb649 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXmlAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXmlAction.java @@ -108,7 +108,7 @@ public void actionPerformed(ActionEvent e) { } if (!allSpecified) { - LayoutUtil.circleLayout(bayesIm.getBayesPm().getDag()); + LayoutUtil.defaultLayout(bayesIm.getBayesPm().getDag()); } this.bayesImWrapper.setBayesIm(bayesIm); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java index 048af03705..b5da644a78 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadBayesImXsdlXmlAction.java @@ -108,7 +108,7 @@ public void actionPerformed(ActionEvent e) { } if (!allSpecified) { - LayoutUtil.circleLayout(bayesIm.getBayesPm().getDag()); + LayoutUtil.defaultLayout(bayesIm.getBayesPm().getDag()); } this.bayesImWrapper.setBayesIm(bayesIm); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java index a16acd7b61..878c7fd170 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraph.java @@ -81,7 +81,7 @@ public void actionPerformed(ActionEvent e) { Preferences.userRoot().put("fileSaveLocation", file.getParent()); Graph graph = GraphSaveLoadUtils.loadGraph(file); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); this.graphEditable.setGraph(graph); } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java index c625a67643..0c6d0d5fbe 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphPcalg.java @@ -79,7 +79,7 @@ public void actionPerformed(ActionEvent e) { Preferences.userRoot().put("fileSaveLocation", file.getParent()); Graph graph = GraphSaveLoadUtils.loadGraphPcalg(file); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); this.graphEditable.setGraph(graph); } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java index 36f99a7bd5..518447d3bb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LoadGraphTxt.java @@ -81,7 +81,7 @@ public void actionPerformed(ActionEvent e) { Preferences.userRoot().put("fileSaveLocation", file.getParent()); Graph graph = GraphSaveLoadUtils.loadGraphTxt(file); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); this.graphEditable.setGraph(graph); } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java index 01e6520f13..0ef7e0a910 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/LogisticRegressionEditor.java @@ -135,7 +135,7 @@ public LogisticRegressionEditor(LogisticRegressionRunner regressionRunner) { // modelParameters.setText(regRunner.getReport()); print(regressionRunner.getResult(), regressionRunner.getAlpha()); Graph outGraph = regressionRunner.getOutGraph(); - LayoutUtil.circleLayout(outGraph); + LayoutUtil.defaultLayout(outGraph); LayoutUtil.fruchtermanReingoldLayout(outGraph); workbench.setGraph(outGraph); TetradLogger.getInstance().log("result", this.modelParameters.getText()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java index 38056de311..20da5dae5e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/MarkovCheckEditor.java @@ -830,6 +830,7 @@ private Box createHistogramPanel(boolean indep) { return Box.createVerticalBox(); } + DataSet dataSet = new BoxDataSet(new VerticalDoubleDataBox(results.size(), 1), Collections.singletonList(new ContinuousVariable("P-Value or Bump"))); @@ -837,7 +838,7 @@ private Box createHistogramPanel(boolean indep) { dataSet.setDouble(i, 0, results.get(i).getPValue()); } - Histogram histogram = new Histogram(dataSet, "P-Value or Bump"); + Histogram histogram = new Histogram(dataSet, "P-Value or Bump", false); // histogram.setTarget("P-Value or Bump"); HistogramPanel view = new HistogramPanel(histogram, true); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PlotMatrix.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PlotMatrix.java index a21d8e58a4..d167c8a059 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PlotMatrix.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/PlotMatrix.java @@ -30,7 +30,10 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -48,6 +51,7 @@ public class PlotMatrix extends JPanel { private JList colSelector; private int numBins = 9; private boolean addRegressionLines = false; + private boolean removeZeroPointsPerPlot = false; private int[] lastRows = new int[]{0}; private int[] lastCols = new int[]{0}; private Map conditioningPanelMap = new HashMap<>(); @@ -72,11 +76,11 @@ public PlotMatrix(DataSet dataSet) { charts = new JPanel(); this.rowSelector.addListSelectionListener(e -> - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector)); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot())); this.colSelector.addListSelectionListener(e -> - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector)); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot())); - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); JMenuBar menuBar = new JMenuBar(); JMenu settings = new JMenu("Settings"); @@ -87,9 +91,19 @@ public PlotMatrix(DataSet dataSet) { addTrendLines.setSelected(false); settings.add(addTrendLines); + JMenuItem removeZeroPointsPerPlot = new JCheckBoxMenuItem("Remove Zero Points Per Plot"); + removeZeroPointsPerPlot.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK)); + removeZeroPointsPerPlot.setSelected(false); + settings.add(removeZeroPointsPerPlot); + + removeZeroPointsPerPlot.addActionListener(e -> { + setRemoveMinPointsPerPlot(!isRemoveTrendLinesPerPlot()); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); + }); + addTrendLines.addActionListener(e -> { setAddRegressionLines(!isAddRegressionLines()); - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); }); JMenuItem numBins = new JMenu("Set number of Bins for Histograms"); @@ -104,7 +118,7 @@ public PlotMatrix(DataSet dataSet) { comp.addActionListener(e -> { setNumBins(_i); - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); }); } @@ -133,17 +147,17 @@ public PlotMatrix(DataSet dataSet) { menuItem1.addActionListener(e -> { this.jitterStyle = ScatterPlot.JitterStyle.Gaussian; - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); }); menuItem2.addActionListener(e -> { this.jitterStyle = ScatterPlot.JitterStyle.Uniform; - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); }); menuItem3.addActionListener(e -> { this.jitterStyle = ScatterPlot.JitterStyle.None; - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); }); settings.add(jitterDiscrete); @@ -151,15 +165,13 @@ public PlotMatrix(DataSet dataSet) { JMenuItem editConditioning = new JMenuItem("Edit Conditioning Variables..."); editConditioning.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK)); - editConditioning.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - VariableConditioningEditor conditioningEditor - = new VariableConditioningEditor(dataSet, conditioningPanelMap); - conditioningEditor.setPreferredSize(new Dimension(300, 300)); - JOptionPane.showMessageDialog(PlotMatrix.this, new JScrollPane(conditioningEditor)); - conditioningPanelMap = conditioningEditor.getConditioningPanelMap(); - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); - } + editConditioning.addActionListener(e -> { + VariableConditioningEditor conditioningEditor + = new VariableConditioningEditor(dataSet, conditioningPanelMap); + conditioningEditor.setPreferredSize(new Dimension(300, 300)); + JOptionPane.showMessageDialog(PlotMatrix.this, new JScrollPane(conditioningEditor)); + conditioningPanelMap = conditioningEditor.getConditioningPanelMap(); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); }); settings.add(editConditioning); @@ -186,7 +198,12 @@ public void actionPerformed(ActionEvent e) { setPreferredSize(new Dimension(750, 450)); } - private void constructPlotMatrix(JPanel charts, DataSet dataSet, List nodes, JList rowSelector, JList colSelector) { + private void setRemoveMinPointsPerPlot(boolean removeZeroPointsPerPlot) { + this.removeZeroPointsPerPlot = removeZeroPointsPerPlot; + } + + private void constructPlotMatrix(JPanel charts, DataSet dataSet, List nodes, JList rowSelector, + JList colSelector, boolean removeZeroPointsPerPlot) { int[] rowIndices = rowSelector.getSelectedIndices(); int[] colIndices = colSelector.getSelectedIndices(); charts.removeAll(); @@ -196,7 +213,7 @@ private void constructPlotMatrix(JPanel charts, DataSet dataSet, List node for (int rowIndex : rowIndices) { for (int colIndex : colIndices) { if (rowIndex == colIndex) { - Histogram histogram = new Histogram(dataSet, nodes.get(rowIndex).getName()); + Histogram histogram = new Histogram(dataSet, nodes.get(rowIndex).getName(), removeZeroPointsPerPlot); // histogram.setTarget(nodes.get(rowIndex).getName()); for (Node node : conditioningPanelMap.keySet()) { @@ -228,7 +245,7 @@ private void constructPlotMatrix(JPanel charts, DataSet dataSet, List node charts.add(panel); } else { ScatterPlot scatterPlot = new ScatterPlot(dataSet, addRegressionLines, nodes.get(colIndex).getName(), - nodes.get(rowIndex).getName()); + nodes.get(rowIndex).getName(), removeZeroPointsPerPlot); for (Node node : conditioningPanelMap.keySet()) { if (node instanceof ContinuousVariable) { @@ -248,7 +265,7 @@ private void constructPlotMatrix(JPanel charts, DataSet dataSet, List node scatterPlot.setJitterStyle(jitterStyle); - ScatterplotPanel panel = new ScatterplotPanel(scatterPlot); + ScatterplotPanel panel = new ScatterplotPanel(scatterPlot, removeZeroPointsPerPlot); panel.setDrawAxes(rowIndices.length == 1 && colIndices.length == 1); panel.setMinimumSize(new Dimension(10, 10)); @@ -272,22 +289,22 @@ private void addPanelListener(JPanel charts, DataSet dataSet, List nodes, panel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2) { - if (rowSelector.getSelectedIndices().length == 1 - && colSelector.getSelectedIndices().length == 1) { - rowSelector.setSelectedIndices(lastRows); - colSelector.setSelectedIndices(lastCols); - lastRows = new int[]{rowIndex}; - lastCols = new int[]{colIndex}; - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); - } else { - lastRows = rowSelector.getSelectedIndices(); - lastCols = colSelector.getSelectedIndices(); - rowSelector.setSelectedIndex(rowIndex); - colSelector.setSelectedIndex(colIndex); - constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector); - } +// if (e.getClickCount() == 1) { + if (rowSelector.getSelectedIndices().length == 1 + && colSelector.getSelectedIndices().length == 1) { + rowSelector.setSelectedIndices(lastRows); + colSelector.setSelectedIndices(lastCols); + lastRows = new int[]{rowIndex}; + lastCols = new int[]{colIndex}; + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); + } else { + lastRows = rowSelector.getSelectedIndices(); + lastCols = colSelector.getSelectedIndices(); + rowSelector.setSelectedIndex(rowIndex); + colSelector.setSelectedIndex(colIndex); + constructPlotMatrix(charts, dataSet, nodes, rowSelector, colSelector, isRemoveTrendLinesPerPlot()); } +// } } }); } @@ -307,6 +324,10 @@ public boolean isAddRegressionLines() { public void setAddRegressionLines(boolean addRegressionLines) { this.addRegressionLines = addRegressionLines; } + + public boolean isRemoveTrendLinesPerPlot() { + return removeZeroPointsPerPlot; + } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java index 824b93e43c..da60a8c81a 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/RegressionEditor.java @@ -191,7 +191,7 @@ private void runRegression() { this.runner.execute(); Graph graph = this.runner.getOutGraph(); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); LayoutUtil.fruchtermanReingoldLayout(graph); this.workbench.setGraph(graph); RegressionResult report = this.runner.getResult(); 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 42e3d75d01..c6d7ddf75d 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 @@ -53,16 +53,18 @@ public class ScatterPlot { private final Map discreteValues; private final Node _x; private final Node _y; + private boolean removeZeroPointsPerPlot; private JitterStyle jitterStyle = JitterStyle.None; /** * Constructor. * - * @param includeLine whether to include the regression line in the plot. - * @param x y-axis variable name. - * @param y x-axis variable name. + * @param includeLine whether to include the regression line in the plot. + * @param x y-axis variable name. + * @param y x-axis variable name. + * @param removeZeroPointsPerPlot whether to remove zero points per plot. */ - public ScatterPlot(DataSet dataSet, boolean includeLine, String x, String y) { + public ScatterPlot(DataSet dataSet, boolean includeLine, String x, String y, boolean removeZeroPointsPerPlot) { this.dataSet = dataSet; this.x = x; this.y = y; @@ -71,6 +73,7 @@ public ScatterPlot(DataSet dataSet, boolean includeLine, String x, String y) { this.includeLine = includeLine; this.continuousIntervals = new HashMap<>(); this.discreteValues = new HashMap<>(); + this.removeZeroPointsPerPlot = removeZeroPointsPerPlot; } public void setJitterStyle(JitterStyle jitterStyle) { @@ -97,6 +100,9 @@ public double getCorrelationCoeff() { double[] xdata = data.getColumn(_x).toArray(); double[] ydata = data.getColumn(_y).toArray(); + Result result = new Result(xdata, ydata, removeZeroPointsPerPlot); + xdata = result.xdata; + ydata = result.ydata; double correlation = StatUtils.correlation(xdata, ydata); @@ -106,6 +112,33 @@ public double getCorrelationCoeff() { return correlation; } + private static class Result { + public double[] xdata; + public double[] ydata; + + public Result(double[] xdata, double[] ydata, boolean removeZeroPointsPerPlot) { + this.xdata = xdata; + this.ydata = ydata; + + if (removeZeroPointsPerPlot) { + List x = new ArrayList<>(); + List y = new ArrayList<>(); + for (int i = 0; i < xdata.length; i++) { + if (xdata[i] != 0 && ydata[i] != 0) { + x.add(xdata[i]); + y.add(ydata[i]); + } + } + this.xdata = new double[x.size()]; + this.ydata = new double[y.size()]; + for (int i = 0; i < x.size(); i++) { + this.xdata[i] = x.get(i); + this.ydata[i] = y.get(i); + } + } + } + } + /** * @return the p-value of the correlation coefficient statistics. */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterplotPanel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterplotPanel.java index 4d5070fb6d..39a84de8e9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterplotPanel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScatterplotPanel.java @@ -18,15 +18,21 @@ */ class ScatterplotPanel extends JPanel { private final NumberFormat nf; + private final boolean removeZeroPointsPerPlot; private ScatterPlot scatterPlot; private boolean drawAxes = false; private int pointSize = 5; + public ScatterplotPanel(ScatterPlot ScatterPlot) { + this(ScatterPlot, false); + } + /** * Constructor. */ - public ScatterplotPanel(ScatterPlot ScatterPlot) { + public ScatterplotPanel(ScatterPlot ScatterPlot, boolean removeZeroPointsPerPlot) { this.scatterPlot = ScatterPlot; + this.removeZeroPointsPerPlot = removeZeroPointsPerPlot; setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); @@ -41,10 +47,10 @@ public ScatterplotPanel(ScatterPlot ScatterPlot) { * Renders the view. */ public void paintComponent(Graphics graphics) { - double xmin = this.scatterPlot.getXmin() - 0.000001; - double xmax = this.scatterPlot.getXmax() + 0.000001; - double ymin = this.scatterPlot.getYmin() - 0.000001; - double ymax = this.scatterPlot.getYmax() + 0.000001; + double xmin = this.scatterPlot.getXmin();// - 0.000001; + double xmax = this.scatterPlot.getXmax();// + 0.000001; + double ymin = this.scatterPlot.getYmin();// - 0.000001; + double ymax = this.scatterPlot.getYmax();// + 0.000001; Graphics2D g = (Graphics2D) graphics; @@ -93,6 +99,12 @@ public void paintComponent(Graphics graphics) { g.setColor(Color.RED.darker()); for (Point2D.Double _pt : pts) { + if (Double.isNaN(_pt.getX()) || Double.isNaN(_pt.getY())) continue; + + if (removeZeroPointsPerPlot) { + if (_pt.getX() == 0 || _pt.getY() == 0) continue; + } + x = (int) (((_pt.getX() - xmin) / _xRange) * xRange + xMin); y = (int) (((ymax - _pt.getY()) / _yRange) * yRange + yMin); g.fillOval(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java index c23c19750e..d56051e6eb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/ScoredGraphsDisplay.java @@ -23,9 +23,9 @@ import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.utils.DagScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.NumberFormatUtil; import edu.cmu.tetrad.util.TetradSerializable; import edu.cmu.tetradapp.model.ScoredGraphsWrapper; @@ -72,7 +72,7 @@ public ScoredGraphsDisplay(ScoredGraphsWrapper scoredGraphsWrapper) { } public ScoredGraphsDisplay(Graph graph, DagScorer scorer) { - List _dags = GraphSearchUtils.generateCpdagDags(graph, true); + List _dags = GraphTransforms.generateCpdagDags(graph, true); for (Graph _graph : _dags) { double score = Double.NaN; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java index cb4a25972f..85c1390a36 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImEditor.java @@ -42,7 +42,7 @@ */ public final class StandardizedSemImEditor extends JPanel implements LayoutEditable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The SemIm being edited. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImGraphicalEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImGraphicalEditor.java index 1933b95b61..2f18d8110a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImGraphicalEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/StandardizedSemImGraphicalEditor.java @@ -42,7 +42,7 @@ */ final class StandardizedSemImGraphicalEditor extends JPanel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Font size for parameter values in the graph. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeBoxEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeBoxEditor.java index 0d704b9bd4..9a46c98a9e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeBoxEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeBoxEditor.java @@ -691,7 +691,7 @@ private void resetEdgeDisplay(JCheckBox checkBox) { this.edgeWorkbench.getGraph()); if (!arrangedAll) { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } this.edgeWorkbench.setGraph(graph); @@ -726,7 +726,6 @@ private void setShowForbiddenExplicitly(boolean showForbiddenExplicitly) { private void setShowRequired(boolean showRequired) { this.showRequired = showRequired; } - private void setShowForbiddenByTiers(boolean showForbiddenByTiers) { this.showForbiddenByTiers = showForbiddenByTiers; } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java index 554ec30951..f2a4ed27e4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeGraph.java @@ -37,7 +37,7 @@ * @author josephramsey */ public class KnowledgeGraph implements Graph, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java index badcf0d87a..caff2ae04c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelEdge.java @@ -42,7 +42,7 @@ public class KnowledgeModelEdge extends Edge public static final int REQUIRED = 2; public static final int FORBIDDEN_BY_GROUPS = 3; public static final int REQUIRED_BY_GROUPS = 4; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The type of the node, FORBIDDEN or REQUIRED. * diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java index e970f42f7e..1c56940eef 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/knowledge_editor/KnowledgeModelNode.java @@ -38,7 +38,7 @@ */ public class KnowledgeModelNode implements Node, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Map attributes = new HashMap<>(); /** * @serial @@ -134,30 +134,30 @@ public String toString() { return getName(); } - @Override - public int compareTo(Node node) { - String name = getName(); - String[] tokens1 = name.split(":"); - String _name = node.getName(); - String[] tokens2 = _name.split(":"); - - if (tokens1.length == 1) { - tokens1 = new String[]{tokens1[0], "0"}; - } - - if (tokens2.length == 1) { - tokens2 = new String[]{tokens2[0], "0"}; - } - - int i1 = tokens1[1].compareTo(tokens2[1]); - int i2 = tokens1[0].compareTo(tokens2[0]); - - if (i1 == 0) { - return i2; - } else { - return i1; - } - } +// @Override +// public int compareTo(Node node) { +// String name = getName(); +// String[] tokens1 = name.split(":"); +// String _name = node.getName(); +// String[] tokens2 = _name.split(":"); +// +// if (tokens1.length == 1) { +// tokens1 = new String[]{tokens1[0], "0"}; +// } +// +// if (tokens2.length == 1) { +// tokens2 = new String[]{tokens2[0], "0"}; +// } +// +// int i1 = tokens1[1].compareTo(tokens2[1]); +// int i2 = tokens1[0].compareTo(tokens2[0]); +// +// if (i1 == 0) { +// return i2; +// } else { +// return i1; +// } +// } @Override public NodeVariableType getNodeVariableType() { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java index 03748eb57d..397c075340 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractAlgorithmRunner.java @@ -43,7 +43,7 @@ */ public abstract class AbstractAlgorithmRunner implements AlgorithmRunner, ParamsResettable, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; final Map paramSettings = new LinkedHashMap<>(); private DataWrapper dataWrapper; /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java index 0a01a57610..b8ebf4dd11 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMBSearchRunner.java @@ -47,7 +47,7 @@ * @author Tyler Gibson */ public abstract class AbstractMBSearchRunner extends DataWrapper implements MarkovBlanketSearchRunner { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The source data model. * diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java index 73ac184605..723cc1ad5c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AbstractMimRunner.java @@ -35,7 +35,7 @@ * @author josephramsey */ public abstract class AbstractMimRunner implements MimRunner, ParamsResettable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Keeps a reference to the dataModel source that has been provided (hopefully either a dataModel model or a * graph). diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AllEdgesUndirectedWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AllEdgesUndirectedWrapper.java index 6cf7e107d6..4e85b94cc1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AllEdgesUndirectedWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/AllEdgesUndirectedWrapper.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class AllEdgesUndirectedWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public AllEdgesUndirectedWrapper(GraphSource source, Parameters parameters) { @@ -43,7 +43,7 @@ public AllEdgesUndirectedWrapper(GraphSource source, Parameters parameters) { public AllEdgesUndirectedWrapper(Graph graph) { - super(AllEdgesUndirectedWrapper.pickDagFromCPDAG(graph), "Make Bidirected Edges Undirected"); + super(GraphUtils.undirectedGraph(graph), "Make Bidirected Edges Undirected"); TetradLogger.getInstance().log("graph", getGraph() + ""); } @@ -56,10 +56,6 @@ public static AllEdgesUndirectedWrapper serializableInstance() { //======================== Private Methods ================================// - private static Graph pickDagFromCPDAG(Graph graph) { - return GraphUtils.undirectedGraph(graph); - } - @Override public boolean allowRandomGraph() { return false; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ApproximateUpdaterWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ApproximateUpdaterWrapper.java index 0a7a46da9f..5e24fb9cd0 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ApproximateUpdaterWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ApproximateUpdaterWrapper.java @@ -37,7 +37,7 @@ * @author William Taysom -- 2003/06/14 */ public class ApproximateUpdaterWrapper implements SessionModel, UpdaterWrapper, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java index e13139b3d1..db69b372ae 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesEstimatorWrapper.java @@ -46,7 +46,7 @@ */ public class BayesEstimatorWrapper implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final DataWrapper dataWrapper; private final List bayesIms = new ArrayList<>(); /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java index 942b94640e..46c8c6a83c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapper.java @@ -43,7 +43,7 @@ */ public class BayesImWrapper implements SessionModel, Memorable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numModels = 1; private int modelIndex; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java index e41a83c2e1..e7a090ad6e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesImWrapperObs.java @@ -44,7 +44,7 @@ /////////////////////////////////////////////////////////// public class BayesImWrapperObs implements SessionModel, Memorable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java index d2f4243005..cb309e8f0c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesPmWrapper.java @@ -47,7 +47,7 @@ * @author josephramsey */ public class BayesPmWrapper implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numModels = 1; private int modelIndex; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java index 7a1d7661ac..67a21222c0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BayesUpdaterClassifierWrapper.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class BayesUpdaterClassifierWrapper implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BidirectedToUndirectedWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BidirectedToUndirectedWrapper.java index 704e684760..a1888bd09f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BidirectedToUndirectedWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BidirectedToUndirectedWrapper.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class BidirectedToUndirectedWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public BidirectedToUndirectedWrapper(GraphSource source, Parameters parameters) { @@ -43,7 +43,7 @@ public BidirectedToUndirectedWrapper(GraphSource source, Parameters parameters) public BidirectedToUndirectedWrapper(Graph graph) { - super(BidirectedToUndirectedWrapper.pickDagFromCPDAG(graph), "Make Bidirected Edges Undirected"); + super(GraphUtils.bidirectedToUndirected(graph), "Make Bidirected Edges Undirected"); TetradLogger.getInstance().log("graph", getGraph() + ""); } @@ -56,10 +56,6 @@ public static BidirectedToUndirectedWrapper serializableInstance() { //======================== Private Methods ================================// - private static Graph pickDagFromCPDAG(Graph graph) { - return GraphUtils.bidirectedToUndirected(graph); - } - @Override public boolean allowRandomGraph() { return false; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java index 2ec0ee0970..a7be1d5918 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BootstrapSamplerWrapper.java @@ -34,7 +34,7 @@ * @author josephramsey */ public class BootstrapSamplerWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java index 2555b16b3a..902994de2f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/BuildPureClustersRunner.java @@ -51,7 +51,7 @@ */ public class BuildPureClustersRunner extends AbstractMimRunner implements GraphSource, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * To reidentify variables. @@ -244,7 +244,7 @@ public void execute() { try { Graph graph = new MarshalledObject<>(searchGraph).get(); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); LayoutUtil.fruchtermanReingoldLayout(graph); setResultGraph(graph); setClusters(MimUtils.convertToClusters(graph, getData().getVariables())); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java index 23f45f18d9..d8118a2dd3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFitModel.java @@ -27,11 +27,7 @@ import edu.cmu.tetrad.data.DataModelList; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.graph.NodeType; -import edu.cmu.tetrad.graph.SemGraph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -50,7 +46,7 @@ * @author Erin Korber (added remove latents functionality July 2004) */ public final class CPDAGFitModel implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Parameters parameters; private final DataModelList dataModelList; private String name; @@ -88,7 +84,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn for (int i = 0; i < dataModels.size(); i++) { DataSet dataSet = (DataSet) dataModels.get(0); - Graph dag = GraphSearchUtils.dagFromCPDAG(graphs.get(0)); + Graph dag = GraphTransforms.dagFromCPDAG(graphs.get(0), null); BayesPm pm = new BayesPmWrapper(dag, new DataWrapper(dataSet)).getBayesPm(); this.bayesPms.add(pm); this.bayesIms.add(estimate(dataSet, pm)); @@ -99,7 +95,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn for (int i = 0; i < dataModels.size(); i++) { DataSet dataSet = (DataSet) dataModels.get(0); - Graph dag = GraphSearchUtils.dagFromCPDAG(graphs.get(0)); + Graph dag = GraphTransforms.dagFromCPDAG(graphs.get(0), null); try { SemPm pm = new SemPm(dag); @@ -108,7 +104,7 @@ public CPDAGFitModel(Simulation simulation, GeneralAlgorithmRunner algorithmRunn } catch (Exception e) { e.printStackTrace(); - Graph mag = GraphSearchUtils.pagToMag(graphs.get(0)); + Graph mag = GraphTransforms.pagToMag(graphs.get(0)); // Ricf.RicfResult result = estimatePag(dataSet, mag); SemGraph graph = new SemGraph(mag); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java index f45791a9a7..ed1bf832f8 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CPDAGFromDagGraphWrapper.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.graph.Dag; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class CPDAGFromDagGraphWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CPDAGFromDagGraphWrapper(GraphSource source, Parameters parameters) { @@ -66,7 +66,7 @@ public static CPDAGFromDagGraphWrapper serializableInstance() { private static Graph getCPDAG(Graph graph) { - return GraphSearchUtils.cpdagFromDag(graph); + return GraphTransforms.cpdagForDag(graph); } @Override diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CalculatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CalculatorWrapper.java index b940b5cea9..d89ea8bfcb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CalculatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CalculatorWrapper.java @@ -37,7 +37,7 @@ * @author Tyler */ public class CalculatorWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java index a65b54a5e9..521c504142 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ConvertToPositiveSkew.java @@ -37,7 +37,7 @@ * @author josephramsey */ public class ConvertToPositiveSkew extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //=============================CONSTRUCTORS==============================// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java index fa6e71333e..61b10abfeb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CorrMatrixConverter.java @@ -34,7 +34,7 @@ * @author josephramsey */ public class CorrMatrixConverter extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //=============================CONSTRUCTORS==============================// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CptInvariantUpdaterWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CptInvariantUpdaterWrapper.java index 56b3643943..2946ddbcd3 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CptInvariantUpdaterWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/CptInvariantUpdaterWrapper.java @@ -38,7 +38,7 @@ * @author William Taysom -- 2003/06/14 */ public class CptInvariantUpdaterWrapper implements SessionModel, UpdaterWrapper, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagFromCPDAGWrapper.java similarity index 78% rename from tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java rename to tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagFromCPDAGWrapper.java index a663bcf815..a948a06a0e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagInCPDAGWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagFromCPDAGWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -33,26 +33,26 @@ * * @author Tyler Gibson */ -public class DagInCPDAGWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; +public class DagFromCPDAGWrapper extends GraphWrapper implements DoNotAddOldModel { + private static final long serialVersionUID = 23L; - public DagInCPDAGWrapper(GraphSource source, Parameters parameters) { + public DagFromCPDAGWrapper(GraphSource source, Parameters parameters) { this(source.getGraph()); } - public DagInCPDAGWrapper(Graph graph) { - super(DagInCPDAGWrapper.getGraph(graph), "Choose DAG in CPDAG."); + public DagFromCPDAGWrapper(Graph graph) { + super(DagFromCPDAGWrapper.getGraph(graph), "Choose DAG in CPDAG."); TetradLogger.getInstance().log("graph", getGraph() + ""); } private static Graph getGraph(Graph graph) { - return GraphSearchUtils.dagFromCPDAG(graph); + return GraphTransforms.dagFromCPDAG(graph, null); } - public static DagInCPDAGWrapper serializableInstance() { - return new DagInCPDAGWrapper(EdgeListGraph.serializableInstance()); + public static DagFromCPDAGWrapper serializableInstance() { + return new DagFromCPDAGWrapper(EdgeListGraph.serializableInstance()); } @Override diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java index 15340282ec..a2e649a833 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DagWrapper.java @@ -44,7 +44,7 @@ public class DagWrapper implements GraphSource, KnowledgeBoxInput, IndTestProducer, SimulationParamsSource, MultipleGraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numModels = 1; private int modelIndex; private String modelSourceName; @@ -128,7 +128,7 @@ public DagWrapper(DataWrapper wrapper) { setGraph(new EdgeListGraph(wrapper.getVariables())); } - LayoutUtil.circleLayout(getGraph()); + LayoutUtil.defaultLayout(getGraph()); } public DagWrapper(BayesPmWrapper wrapper) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java index 4496cb3106..dd0a368330 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataCenterer.java @@ -35,7 +35,7 @@ */ public class DataCenterer extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //=============================CONSTRUCTORS==============================// private DataCenterer(DataWrapper wrapper, Parameters params) { @@ -49,7 +49,7 @@ private DataCenterer(DataWrapper wrapper, Parameters params) { DataSet dataSet = (DataSet) model; - Matrix data2 = DataUtils.centerData(dataSet.getDoubleData()); + Matrix data2 = DataTransforms.centerData(dataSet.getDoubleData()); List list = dataSet.getVariables(); DataSet dataSet2 = new BoxDataSet(new VerticalDoubleDataBox(data2.transpose().toArray()), list); dataSet2.setName(model.getName()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java index 35abc35089..6b4dec3ccf 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataStandardizer.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class DataStandardizer extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //=============================CONSTRUCTORS==============================// @@ -54,7 +54,7 @@ public DataStandardizer(DataWrapper wrapper, Parameters params) { throw new IllegalArgumentException("Not a continuous data set: " + dataSet.getName()); } - Matrix data2 = DataUtils.standardizeData(dataSet.getDoubleData()); + Matrix data2 = DataTransforms.standardizeData(dataSet.getDoubleData()); List list = dataSet.getVariables(); DataSet dataSet2 = new BoxDataSet(new VerticalDoubleDataBox(data2.transpose().toArray()), list); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java index df69845a82..892fbef860 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DataWrapper.java @@ -43,7 +43,7 @@ public class DataWrapper implements KnowledgeEditable, KnowledgeBoxInput, DoNotAddOldModel, SimulationParamsSource, MultipleDataSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Maps columns to discretization specs so that user's work is not forgotten from one editing of the same data set * to the next. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java index 980b4e7ee2..e13f12d84e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletBayesImWrapper.java @@ -40,7 +40,7 @@ */ public class DirichletBayesImWrapper implements KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java index 6f32e219de..0e6b80956c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/DirichletEstimatorWrapper.java @@ -40,7 +40,7 @@ */ public class DirichletEstimatorWrapper implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java index d7ac62dba3..0d5e4f29e6 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgeWeightComparison.java @@ -34,7 +34,7 @@ * @author Michael Freenor */ public class EdgeWeightComparison implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final SemIm reference; private final SemIm target; private String name; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java index cb5d572621..8cb0fa8664 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EdgewiseComparisonModel.java @@ -24,6 +24,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; @@ -33,8 +34,6 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Compares a target workbench with a reference workbench by counting errors of omission and commission. (for edge @@ -44,7 +43,7 @@ * @author Erin Korber (added remove latents functionality July 2004) */ public final class EdgewiseComparisonModel implements SessionModel, DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph targetGraph; private final Graph referenceGraph; private final Parameters params; @@ -97,10 +96,10 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return GraphSearchUtils.cpdagForDag(graph); + return GraphTransforms.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); - return dagToPag(graph); + return GraphTransforms.dagToPag(graph); } else { params.set("graphComparisonType", "DAG"); return new EdgeListGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java index 9d7b6f083f..be285fa554 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/EmBayesEstimatorWrapper.java @@ -41,7 +41,7 @@ * @author Frank Wimberly adapted for EM Bayes estimator and structural EM Bayes estimator */ public class EmBayesEstimatorWrapper implements SessionModel, GraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java index 3031fb25f4..ff81f6fc15 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtraCategoryInterpolatorWrapper.java @@ -34,7 +34,7 @@ * @author josephramsey */ public class ExtraCategoryInterpolatorWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ExtraCategoryInterpolatorWrapper(DataWrapper wrapper, Parameters params) { DataFilter interpolator = new ExtraCategoryInterpolator(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java index 0883519ea3..5143056e5b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ExtractStructureModelWrapper.java @@ -22,7 +22,6 @@ package edu.cmu.tetradapp.model; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -35,7 +34,7 @@ * @author Tyler Gibson */ public class ExtractStructureModelWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ExtractStructureModelWrapper(GraphSource source, Parameters parameters) { @@ -80,7 +79,7 @@ public static ExtractStructureModelWrapper serializableInstance() { private static Graph getCPDAG(Dag dag) { - return GraphSearchUtils.cpdagFromDag(dag); + return GraphTransforms.cpdagForDag(dag); } @Override diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java index 5e5212f43f..53f4cdeb31 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FactorAnalysisRunner.java @@ -37,7 +37,7 @@ * @author Michael Freenor */ public class FactorAnalysisRunner extends AbstractAlgorithmRunner { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private String output; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java index dcee4e2cff..f2e47435a4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FasRunner.java @@ -41,7 +41,7 @@ */ public class FasRunner extends AbstractAlgorithmRunner implements IndTestProducer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph externalGraph; //============================CONSTRUCTORS============================// @@ -150,7 +150,7 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } setResultGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java index b5a8401e12..312f001f81 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/FciRunner.java @@ -43,7 +43,7 @@ */ public class FciRunner extends AbstractAlgorithmRunner implements IndTestProducer, IonInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //=========================CONSTRUCTORS================================// @@ -132,7 +132,7 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } setResultGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ForbiddenGraphModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ForbiddenGraphModel.java index ee779cda4e..0b6ac85df4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ForbiddenGraphModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ForbiddenGraphModel.java @@ -41,7 +41,7 @@ */ public class ForbiddenGraphModel extends KnowledgeBoxModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph resultGraph = new EdgeListGraph(); 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 e3917b841c..3e26cfcf32 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 @@ -61,7 +61,7 @@ public class GeneralAlgorithmRunner implements AlgorithmRunner, ParamsResettable Unmarshallable, IndTestProducer, KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Map userAlgoSelections = new HashMap<>(); private DataWrapper dataWrapper; private String name; @@ -282,7 +282,7 @@ public void execute() { Graph graph = algo.search(null, this.parameters); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); graphList.add(graph); } else { @@ -332,7 +332,7 @@ public void execute() { Graph graph = this.algorithm.search(dataSet, this.parameters); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); graphList.add(graph); } else if (dataModel instanceof DataSet) { @@ -351,7 +351,7 @@ public void execute() { } Graph graph = this.algorithm.search(dataSet, this.parameters); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); graphList.add(graph); } @@ -385,15 +385,15 @@ public void execute() { if (data.isContinuous() && (algDataType == DataType.Continuous || algDataType == DataType.Mixed)) { Graph graph = algo.search(data, this.parameters); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); graphList.add(graph); } else if (data.isDiscrete() && (algDataType == DataType.Discrete || algDataType == DataType.Mixed)) { Graph graph = algo.search(data, this.parameters); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); graphList.add(graph); } else if (data.isMixed() && algDataType == DataType.Mixed) { Graph graph = algo.search(data, this.parameters); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); graphList.add(graph); } else { throw new IllegalArgumentException("The algorithm was not expecting that type of data."); @@ -409,7 +409,7 @@ public void execute() { } } else { for (Graph graph : graphList) { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java index c6e8a24b45..971c1add53 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemEstimatorWrapper.java @@ -42,7 +42,7 @@ * @author josephramsey */ public class GeneralizedSemEstimatorWrapper implements SessionModel, GraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final DataSet data; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java index 8263526e28..7f5447ae5d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemImWrapper.java @@ -41,7 +41,7 @@ */ public class GeneralizedSemImWrapper implements KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java index 8a6e021c57..31d1f30c76 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GeneralizedSemPmWrapper.java @@ -44,7 +44,7 @@ */ public class GeneralizedSemPmWrapper implements KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The wrapped SemPm. * diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GenerateCompleteGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GenerateCompleteGraphWrapper.java index ea29f4170f..f72eb08278 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GenerateCompleteGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GenerateCompleteGraphWrapper.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class GenerateCompleteGraphWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public GenerateCompleteGraphWrapper(GraphSource source, Parameters parameters) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java index afe9bfc748..5a688aee3e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphComparisonParams.java @@ -43,7 +43,7 @@ */ public class GraphComparisonParams extends SessionAdapter implements ExecutionRestarter { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The data set to which records are appended. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java index ae475e59bc..2720362f31 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphSelectionWrapper.java @@ -41,7 +41,7 @@ * @author josephramsey */ public class GraphSelectionWrapper implements GraphSource, KnowledgeBoxInput, IonInput, IndTestProducer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Parameters params; private List selectedNodes; private List graphs = new ArrayList<>(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java index e5199aa173..5087b6a1b4 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GraphWrapper.java @@ -50,7 +50,7 @@ */ public class GraphWrapper implements KnowledgeBoxInput, IonInput, IndTestProducer, SimulationParamsSource, GraphSettable, MultipleGraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numModels = 1; private int modelIndex; private String modelSourceName; @@ -133,7 +133,7 @@ public GraphWrapper(DataWrapper wrapper) { setGraph(new EdgeListGraph(wrapper.getVariables())); } - LayoutUtil.circleLayout(getGraph()); + LayoutUtil.defaultLayout(getGraph()); } public GraphWrapper(GeneralizedSemImWrapper wrapper) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java index 96b3e2f901..b3f8378d9c 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IdentifiabilityWrapper.java @@ -43,7 +43,7 @@ /////////////////////////////////////// public class IdentifiabilityWrapper implements SessionModel, UpdaterWrapper, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java index c0aff91edf..67e8b43d80 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataAllWrapper.java @@ -40,7 +40,7 @@ * @author josephramsey */ public class ImpliedCovarianceDataAllWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private SemIm semIm; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java index 29f6b2e0d4..56331f9e48 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ImpliedCovarianceDataWrapper.java @@ -40,7 +40,7 @@ * @author josephramsey */ public class ImpliedCovarianceDataWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private SemIm semIm; //==============================CONSTRUCTORS=============================// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java index 9b21018a77..d7117f1178 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndTestModel.java @@ -37,7 +37,7 @@ * @author josephramsey */ public class IndTestModel implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final List indTestProducers; private String name = ""; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java index b454809e6a..25c3dbe95d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceFactsModel.java @@ -40,7 +40,7 @@ * @author josephramsey */ public class IndependenceFactsModel implements KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceFacts facts = new IndependenceFacts(); private String name = ""; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceResultIndFacts.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceResultIndFacts.java index 15107c8311..6c99a77b16 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceResultIndFacts.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IndependenceResultIndFacts.java @@ -31,7 +31,7 @@ * Stores the result of an independence test. */ public final class IndependenceResultIndFacts implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat(); private final int index; private final String fact; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java index d584b32f9b..949fae587f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/IonRunner.java @@ -46,7 +46,7 @@ */ public class IonRunner extends AbstractAlgorithmRunner implements IndTestProducer, DoNotAddOldModel, IonInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private List graphs; //=========================CONSTRUCTORS================================// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/JunctionTreeWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/JunctionTreeWrapper.java index 144f2146c5..5f08321e3e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/JunctionTreeWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/JunctionTreeWrapper.java @@ -36,7 +36,7 @@ */ public class JunctionTreeWrapper implements SessionModel, UpdaterWrapper, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private JunctionTreeUpdater bayesUpdater; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeBoxModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeBoxModel.java index 40fd7291ef..4408d02043 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeBoxModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/KnowledgeBoxModel.java @@ -40,7 +40,7 @@ */ public class KnowledgeBoxModel implements SessionModel, ParamsResettable, KnowledgeEditable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph sourceGraph = new EdgeListGraph(); private String name; private Parameters params; @@ -49,14 +49,6 @@ public class KnowledgeBoxModel implements SessionModel, ParamsResettable, Knowle private List variableNames = new ArrayList<>(); private int numTiers = 3; - public KnowledgeBoxModel() { - this.knowledge = new Knowledge(); - this.numTiers = 3; - this.variables = new ArrayList<>(); - this.params = new Parameters(); -// this.params.set("__myKnowledge", this.knowledge); - } - public KnowledgeBoxModel(Parameters params) { this.knowledge = new Knowledge(); this.numTiers = 3; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogData.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogData.java index 5197f3cbc2..f0832b3830 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogData.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogData.java @@ -31,7 +31,7 @@ * @author Jeremy Espino */ public class LogData extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //=============================CONSTRUCTORS==============================// @@ -50,7 +50,7 @@ public LogData(DataWrapper wrapper, Parameters params) { boolean isUnlog = params.getBoolean("unlog"); int base = params.getInt("base"); - DataSet dataSet2 = DataUtils.logData(dataSet, a, isUnlog, base); + DataSet dataSet2 = DataTransforms.logData(dataSet, a, isUnlog, base); outList.add(dataSet2); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java index 6e9424e56b..3ab00c7c65 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/LogisticRegressionRunner.java @@ -42,7 +42,7 @@ */ public class LogisticRegressionRunner implements AlgorithmRunner, RegressionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Parameters params; private final List variableNames; private String name; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java index 976655e2cd..72ef30ddae 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MagInPagWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class MagInPagWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public MagInPagWrapper(GraphSource source, Parameters parameters) { this(source.getGraph()); @@ -47,7 +47,7 @@ public MagInPagWrapper(Graph graph) { } private static Graph getGraph(Graph graph) { - return GraphSearchUtils.pagToMag(graph); + return GraphTransforms.pagToMag(graph); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java index 2c53cd749c..05ed27b7aa 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MarkovCheckIndTestModel.java @@ -40,7 +40,7 @@ * @author josephramsey */ public class MarkovCheckIndTestModel implements SessionModel, GraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final DataModel dataModel; private final Parameters parameters; private final Graph graph; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java index ed96856d93..587355c0f2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MeasurementModelWrapper.java @@ -44,7 +44,7 @@ */ public final class MeasurementModelWrapper implements ParamsResettable, KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Clusters resulting from the last run of the algorithm. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MergeDatasetsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MergeDatasetsWrapper.java index c2c4ee6c05..1a6d3c6036 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MergeDatasetsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MergeDatasetsWrapper.java @@ -32,7 +32,7 @@ * @author Tyler Gibson */ public class MergeDatasetsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public MergeDatasetsWrapper(DataWrapper[] data, Parameters params) { construct(data); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java index b94229851c..267de2635a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildRunner.java @@ -45,7 +45,7 @@ * @author Ricardo Silva */ public class MimBuildRunner extends AbstractMimRunner implements GraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final DataSet dataSet; private Graph fullGraph; private ICovarianceMatrix covMatrix; @@ -121,7 +121,7 @@ public void execute() throws Exception { CovarianceMatrix cov = new CovarianceMatrix(data); Graph structureGraph = mimbuild.search(partition, latentNames, cov); - LayoutUtil.circleLayout(structureGraph); + LayoutUtil.defaultLayout(structureGraph); LayoutUtil.fruchtermanReingoldLayout(structureGraph); ICovarianceMatrix latentsCov = mimbuild.getLatentsCov(); @@ -129,7 +129,7 @@ public void execute() throws Exception { TetradLogger.getInstance().log("details", "Latent covs = \n" + latentsCov); Graph fullGraph = mimbuild.getFullGraph(); - LayoutUtil.circleLayout(fullGraph); + LayoutUtil.defaultLayout(fullGraph); LayoutUtil.fruchtermanReingoldLayout(fullGraph); setResultGraph(fullGraph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java index e8efb41721..54c635d8be 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MimBuildTrekRunner.java @@ -44,7 +44,7 @@ * @author Ricardo Silva */ public class MimBuildTrekRunner extends AbstractMimRunner implements GraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final DataSet dataSet; private Graph fullGraph; private ICovarianceMatrix covMatrix; @@ -145,7 +145,7 @@ public void execute() throws Exception { CovarianceMatrix cov = new CovarianceMatrix(data); Graph structureGraph = mimbuild.search(partition, latentNames, cov); - LayoutUtil.circleLayout(structureGraph); + LayoutUtil.defaultLayout(structureGraph); LayoutUtil.fruchtermanReingoldLayout(structureGraph); ICovarianceMatrix latentsCov = mimbuild.getLatentsCov(); @@ -153,7 +153,7 @@ public void execute() throws Exception { TetradLogger.getInstance().log("details", "Latent covs = \n" + latentsCov); Graph fullGraph = mimbuild.getFullGraph(); - LayoutUtil.circleLayout(fullGraph); + LayoutUtil.defaultLayout(fullGraph); LayoutUtil.fruchtermanReingoldLayout(fullGraph); setResultGraph(fullGraph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java index a4c38c8618..8a1d9b3e00 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Misclassifications.java @@ -25,7 +25,7 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -34,8 +34,6 @@ import java.io.IOException; import java.io.ObjectInputStream; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Compares a target workbench with a reference workbench by counting errors of omission and commission. (for edge @@ -45,7 +43,7 @@ * @author Erin Korber (added remove latents functionality July 2004) */ public final class Misclassifications implements SessionModel, DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph targetGraph; private final Graph referenceGraph; @@ -101,10 +99,10 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return GraphSearchUtils.cpdagForDag(graph); + return GraphTransforms.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); - return dagToPag(graph); + return GraphTransforms.dagToPag(graph); } else { params.set("graphComparisonType", "DAG"); return new EdgeListGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java index c453bcae0a..64d027e637 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/MissingDataInjectorWrapper.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.data.LogDataUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -38,7 +38,7 @@ * @author Frank Wimberly based on similar class by Ramsey */ public class MissingDataInjectorWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. @@ -59,7 +59,7 @@ public MissingDataInjectorWrapper(DataWrapper wrapper, Arrays.fill(probs, prob); - this.outputDataSet = DataUtils.addMissingData(dataSet, probs); + this.outputDataSet = DataTransforms.addMissingData(dataSet, probs); setDataModel(this.outputDataSet); setSourceGraph(wrapper.getSourceGraph()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java index 770741e07f..080d21a91b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ModeInterpolatorWrapper.java @@ -34,7 +34,7 @@ * @author josephramsey */ public class ModeInterpolatorWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ModeInterpolatorWrapper(DataWrapper wrapper, Parameters params) { DataFilter interpolator = new ModeInterpolator(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java index e677543a3d..2fec0c328d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NonparanormalTransform.java @@ -31,7 +31,7 @@ */ public class NonparanormalTransform extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //=============================CONSTRUCTORS==============================// public NonparanormalTransform(DataWrapper wrapper, Parameters params) { @@ -41,7 +41,7 @@ public NonparanormalTransform(DataWrapper wrapper, Parameters params) { throw new IllegalArgumentException("Data model must be a tabular continuous data set, not a covariance matrix."); } - DataSet nonparanormalTransformed = DataUtils.getNonparanormalTransformed((DataSet) dataModel); + DataSet nonparanormalTransformed = DataTransforms.getNonparanormalTransformed((DataSet) dataModel); nonparanormalTransformed.setKnowledge(dataModel.getKnowledge().copy()); setDataModel(nonparanormalTransformed); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java index c201ae3337..fa3e488f4b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/NoteModel.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class NoteModel implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private StyledDocument note = new DefaultStyledDocument(); private String name; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java index b7b4bc1b11..27faa11081 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PValueImproverWrapper.java @@ -45,7 +45,7 @@ * @author Ricardo Silva */ public class PValueImproverWrapper extends AbstractAlgorithmRunner { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final DataWrapper dataWrapper; private final Parameters params = new Parameters(); /** @@ -249,10 +249,10 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(this.graph, knowledge); } else { - LayoutUtil.circleLayout(this.graph); + LayoutUtil.defaultLayout(this.graph); } - setResultGraph(GraphSearchUtils.cpdagForDag(this.graph)); + setResultGraph(GraphTransforms.cpdagForDag(this.graph)); } public boolean supportsKnowledge() { @@ -368,7 +368,7 @@ public DataSet simulateDataCholesky(int sampleSize, Matrix covar, List var } } - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java index 9725bb2986..05bd9f32ba 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PagFromDagGraphWrapper.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.TetradLogger; @@ -32,7 +32,7 @@ * @author Tyler Gibson */ public class PagFromDagGraphWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public PagFromDagGraphWrapper(GraphSource source, Parameters parameters) { @@ -47,7 +47,7 @@ public PagFromDagGraphWrapper(Graph graph) { throw new IllegalArgumentException("The source graph is not a DAG."); } - Graph pag = GraphSearchUtils.dagToPag(graph); + Graph pag = GraphTransforms.dagToPag(graph); setGraph(pag); TetradLogger.getInstance().log("info", "\nGenerating allow_latent_common_causes from DAG."); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java index e300d48145..6ae198ba15 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PcRunner.java @@ -40,7 +40,7 @@ */ public class PcRunner extends AbstractAlgorithmRunner implements IndTestProducer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph externalGraph; private Set pcAdjacent; private Set pcNonadjacent; @@ -147,7 +147,7 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } setResultGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java index ec41681199..9dda500f0a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/PurifyRunner.java @@ -39,7 +39,7 @@ * @author Ricardo Silva */ public class PurifyRunner extends AbstractMimRunner implements GraphSource, KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; //============================CONSTRUCTORS============================// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java index a76976acaa..657a7ab04e 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RegressionRunner.java @@ -45,7 +45,7 @@ * @author Frank Wimberly after Joe Ramsey's PcRunner */ public class RegressionRunner implements AlgorithmRunner, RegressionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Parameters params; private final DataModelList dataModels; private final List variableNames; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNonSkeletonEdgesModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNonSkeletonEdgesModel.java index d73d97c4fb..4c9c7ab3b3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNonSkeletonEdgesModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNonSkeletonEdgesModel.java @@ -39,7 +39,7 @@ */ public class RemoveNonSkeletonEdgesModel extends KnowledgeBoxModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph resultGraph = new EdgeListGraph(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNullEdgesGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNullEdgesGraphWrapper.java index 6fe69f44b6..301f7263d2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNullEdgesGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RemoveNullEdgesGraphWrapper.java @@ -39,7 +39,7 @@ * @author josephramsey */ public class RemoveNullEdgesGraphWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public RemoveNullEdgesGraphWrapper(GraphSource source, Parameters parameters) { this(source.getGraph()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java index 441ed33e79..8c5f7c5d81 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ReplaceMissingWithRandomWrapper.java @@ -22,7 +22,7 @@ package edu.cmu.tetradapp.model; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.data.LogDataUtils; import edu.cmu.tetrad.util.TetradSerializableUtils; @@ -36,7 +36,7 @@ * @author Frank Wimberly based on similar class by Ramsey */ public class ReplaceMissingWithRandomWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. @@ -49,7 +49,7 @@ public ReplaceMissingWithRandomWrapper(DataWrapper wrapper) { DataSet dataSet = (DataSet) wrapper.getSelectedDataModel(); - this.outputDataSet = DataUtils.replaceMissingWithRandom(dataSet); + this.outputDataSet = DataTransforms.replaceMissingWithRandom(dataSet); setDataModel(this.outputDataSet); setSourceGraph(wrapper.getSourceGraph()); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RequiredGraphModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RequiredGraphModel.java index 8bb65c7a86..d40d672507 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RequiredGraphModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RequiredGraphModel.java @@ -37,7 +37,7 @@ */ public class RequiredGraphModel extends KnowledgeBoxModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph resultGraph; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java index 4d75064a66..6b04546dc3 100755 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/RowSummingExactWrapper.java @@ -37,7 +37,7 @@ * @author josephramsey */ public class RowSummingExactWrapper implements SessionModel, UpdaterWrapper, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java index 6296c74e6a..b36d4a1459 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcFastRunner.java @@ -43,7 +43,7 @@ */ public class SampleVcpcFastRunner extends AbstractAlgorithmRunner implements IndTestProducer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private SemIm semIm; private Set sfVcpcAdjacent; @@ -162,7 +162,7 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } setResultGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java index 4e88c0696a..5718bf7535 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SampleVcpcRunner.java @@ -45,7 +45,7 @@ */ public class SampleVcpcRunner extends AbstractAlgorithmRunner implements IndTestProducer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceFactsModel independenceFactsModel; private Graph trueGraph; private SemPm semPm; @@ -196,7 +196,7 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } setResultGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java index f13b57d9dc..4cf3e98965 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/ScoredGraphsWrapper.java @@ -23,8 +23,8 @@ import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.utils.DagScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.session.DoNotAddOldModel; import edu.cmu.tetrad.session.SessionModel; import edu.cmu.tetrad.util.Parameters; @@ -46,7 +46,7 @@ * @author josephramsey */ public class ScoredGraphsWrapper implements SessionModel, GraphSource, Unmarshallable, DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Map graphsToScores; /** * Transient graph scorer, null if non exists (or needs to be refreshed). @@ -69,7 +69,7 @@ private ScoredGraphsWrapper() { } public ScoredGraphsWrapper(Graph graph, DagScorer scorer) { - List dags = GraphSearchUtils.generateCpdagDags(graph, true); + List dags = GraphTransforms.generateCpdagDags(graph, true); this.graphsToScores = new HashMap<>(); this.graphScorer = scorer; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java index f8c0c52818..8f6641861b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemEstimatorWrapper.java @@ -43,7 +43,7 @@ public class SemEstimatorWrapper implements SessionModel { ;//}, Unmarshallable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Parameters params; private final SemPm semPm; /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java index a22c9825bc..19d5a63fdc 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemGraphWrapper.java @@ -43,7 +43,7 @@ public class SemGraphWrapper implements GraphSource, KnowledgeBoxInput, SimulationParamsSource, DoNotAddOldModel, MultipleGraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numModels = 1; private int modelIndex; private String modelSourceName; @@ -176,7 +176,7 @@ public SemGraphWrapper(DataWrapper wrapper) { setGraph(new EdgeListGraph(wrapper.getVariables())); } - LayoutUtil.circleLayout(getGraph()); + LayoutUtil.defaultLayout(getGraph()); } public SemGraphWrapper(BayesPmWrapper wrapper) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java index 7e99a6b6c5..dc59f4fc09 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemImWrapper.java @@ -43,7 +43,7 @@ */ public class SemImWrapper implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private List semIms; /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java index 766f7ef78d..3afdab82fb 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemPmWrapper.java @@ -44,7 +44,7 @@ */ public class SemPmWrapper implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numModels = 1; private int modelIndex; private String modelSourceName; @@ -167,7 +167,7 @@ public SemPmWrapper(AlgorithmRunner wrapper) { this(new EdgeListGraph(wrapper.getGraph())); } - public SemPmWrapper(DagInCPDAGWrapper wrapper) { + public SemPmWrapper(DagFromCPDAGWrapper wrapper) { this(new EdgeListGraph(wrapper.getGraph())); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java index 141eb6af12..935d301575 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SemUpdaterWrapper.java @@ -34,7 +34,7 @@ * @author josephramsey */ public class SemUpdaterWrapper implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java index 01149a70c8..9d10bd1240 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionNodeWrapper.java @@ -38,7 +38,7 @@ * @see SessionWrapper */ public class SessionNodeWrapper extends GraphNode { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The SessionNode being wrapped. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java index 59c4e8e22a..6834248c10 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/SessionWrapper.java @@ -47,7 +47,7 @@ * @see edu.cmu.tetrad.graph.Graph */ public class SessionWrapper extends EdgeListGraph implements SessionWrapperIndirectRef { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The session being wrapped. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java index 19f28cea11..977548b778 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/Simulation.java @@ -43,7 +43,7 @@ public class Simulation extends DataWrapper implements GraphSource, MultipleGraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private edu.cmu.tetrad.algcomparison.simulation.Simulation simulation; private Parameters parameters; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java index ce3d2afebe..37129ba7aa 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StandardizedSemImWrapper.java @@ -40,7 +40,7 @@ */ public class StandardizedSemImWrapper implements KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. */ diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java index 77299a6e48..1ae007e11c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/StructEmBayesSearchRunner.java @@ -41,7 +41,7 @@ * @author Frank Wimberly adapted for EM Bayes estimator and structural EM Bayes search */ public class StructEmBayesSearchRunner implements SessionModel, GraphSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java index f59876c64a..97790ac162 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TabularComparison.java @@ -46,7 +46,7 @@ public final class TabularComparison implements SessionModel, SimulationParamsSource, DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph targetGraph; private final Graph referenceGraph; private final Parameters params; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java index 5c248ba0e7..0e4c69a12e 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TetradMetadata.java @@ -39,7 +39,7 @@ */ public class TetradMetadata implements TetradSerializable, TetradMetadataIndirectRef { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The version of Tetrad that saved this session out. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java index 5cbf563d07..e0ebd19f05 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TimeLagGraphWrapper.java @@ -41,7 +41,7 @@ * @author josephramsey */ public class TimeLagGraphWrapper implements GraphSource, KnowledgeBoxInput { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java index abed21dbbe..3c4499c8e0 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/TsPagFromDagGraphWrapper.java @@ -34,7 +34,7 @@ * @author danielmalinsky */ public class TsPagFromDagGraphWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TsPagFromDagGraphWrapper(GraphSource source, Parameters parameters) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UndirectedToBidirectedWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UndirectedToBidirectedWrapper.java index 55a6d9159b..5801c0bacc 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UndirectedToBidirectedWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/UndirectedToBidirectedWrapper.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class UndirectedToBidirectedWrapper extends GraphWrapper implements DoNotAddOldModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public UndirectedToBidirectedWrapper(GraphSource source, Parameters parameters) { @@ -43,7 +43,7 @@ public UndirectedToBidirectedWrapper(GraphSource source, Parameters parameters) public UndirectedToBidirectedWrapper(Graph graph) { - super(UndirectedToBidirectedWrapper.pickDagFromCPDAG(graph), "Make Bidirected Edges Undirected"); + super(GraphUtils.undirectedToBidirected(graph), "Make Bidirected Edges Undirected"); TetradLogger.getInstance().log("graph", getGraph() + ""); } @@ -56,10 +56,6 @@ public static UndirectedToBidirectedWrapper serializableInstance() { //======================== Private Methods ================================// - private static Graph pickDagFromCPDAG(Graph graph) { - return GraphUtils.undirectedToBidirected(graph); - } - @Override public boolean allowRandomGraph() { return false; diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java index eafe334bc9..4e92909c05 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcFastRunner.java @@ -44,7 +44,7 @@ */ public class VcpcFastRunner extends AbstractAlgorithmRunner implements IndTestProducer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph dag; private IndependenceFactsModel independenceFactsModel; private Graph trueGraph; @@ -187,7 +187,7 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } setResultGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java index 60b62cd620..920d9bc407 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/VcpcRunner.java @@ -44,7 +44,7 @@ */ public class VcpcRunner extends AbstractAlgorithmRunner implements IndTestProducer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph dag; private IndependenceFactsModel independenceFactsModel; private Graph trueGraph; @@ -187,7 +187,7 @@ public void execute() { } else if (knowledge.isDefaultToKnowledgeLayout()) { GraphSearchUtils.arrangeByKnowledgeTiers(graph, knowledge); } else { - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); } setResultGraph(graph); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java index 30756a7bdc..23eef49aab 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/YeastPcCcdSearchWrapper.java @@ -70,7 +70,7 @@ public static void main(String[] args) { try { cds = SimpleDataLoader.loadContinuousData(new File(args[0]), "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); } catch (IOException e) { e.printStackTrace(); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java index 5f809f435b..a254c9c92b 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ArResidualsWrapper.java @@ -35,7 +35,7 @@ * @author Tyler */ public class ArResidualsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs a new time series dataset. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/BoxCoxWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/BoxCoxWrapper.java index d8d22c5ba7..486ac3861d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/BoxCoxWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/BoxCoxWrapper.java @@ -32,7 +32,7 @@ * @author Tyler */ public class BoxCoxWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs a new time series dataset. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConcatenateDatasetsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConcatenateDatasetsWrapper.java index 3c288524df..1c37399add 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConcatenateDatasetsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConcatenateDatasetsWrapper.java @@ -39,7 +39,7 @@ */ public class ConcatenateDatasetsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ConcatenateDatasetsWrapper(DataWrapper[] data, Parameters params) { construct(data); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConvertNumericalDiscreteToContinuousWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConvertNumericalDiscreteToContinuousWrapper.java index 6744e76194..fa230892be 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConvertNumericalDiscreteToContinuousWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ConvertNumericalDiscreteToContinuousWrapper.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class ConvertNumericalDiscreteToContinuousWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ConvertNumericalDiscreteToContinuousWrapper(DataWrapper data, Parameters params) { if (data == null) { @@ -52,7 +52,7 @@ public ConvertNumericalDiscreteToContinuousWrapper(DataWrapper data, Parameters DataSet convertedData; try { - convertedData = DataUtils.convertNumericalDiscreteToContinuous(originalData); + convertedData = DataTransforms.convertNumericalDiscreteToContinuous(originalData); } catch (NumberFormatException e) { throw new RuntimeException("There were some non-numeric values in that dataset."); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopyAllDatasetsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopyAllDatasetsWrapper.java index bde9585731..21810dd377 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopyAllDatasetsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopyAllDatasetsWrapper.java @@ -36,7 +36,7 @@ * @author Tyler Gibson */ public class CopyAllDatasetsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CopyAllDatasetsWrapper(DataWrapper wrapper, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopySelectedDatasetWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopySelectedDatasetWrapper.java index f610367384..87d3fa4b88 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopySelectedDatasetWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CopySelectedDatasetWrapper.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class CopySelectedDatasetWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CopySelectedDatasetWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java index 0c45dfa648..7ded0457c3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixAverageWrapper.java @@ -41,7 +41,7 @@ * @author Tyler Gibson */ public class CovMatrixAverageWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CovMatrixAverageWrapper(DataWrapper[] covs, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java index a916bcb0ac..c189618ef3 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixDifferenceWrapper.java @@ -38,7 +38,7 @@ * @author Tyler Gibson */ public class CovMatrixDifferenceWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Splits the given data set by collinear columns. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java index 62dda160a3..3edfbc01f2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixSumWrapper.java @@ -36,7 +36,7 @@ * @author Tyler Gibson */ public class CovMatrixSumWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Splits the given data set by collinear columns. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixWrapper.java index ca3dfff2c5..2ff108632d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/CovMatrixWrapper.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class CovMatrixWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Splits the given data set by collinear columns. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/DiscretizationWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/DiscretizationWrapper.java index 99f752fb0a..0f1e014413 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/DiscretizationWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/DiscretizationWrapper.java @@ -41,7 +41,7 @@ * @author Tyler */ public class DiscretizationWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ExpandCaseMultipliersWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ExpandCaseMultipliersWrapper.java index b3a4df8801..781a02cbfa 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ExpandCaseMultipliersWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ExpandCaseMultipliersWrapper.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class ExpandCaseMultipliersWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ExpandCaseMultipliersWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/FirstDifferencesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/FirstDifferencesWrapper.java index d266b5d7c7..f448eeddee 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/FirstDifferencesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/FirstDifferencesWrapper.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class FirstDifferencesWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs the wrapper given some data and the params. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InverseMatrixWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InverseMatrixWrapper.java index 7e07f71eba..78e8d6e07c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InverseMatrixWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InverseMatrixWrapper.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class InverseMatrixWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Splits the given data set by collinear columns. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InvertCovMatrixWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InvertCovMatrixWrapper.java index 8ae0fe8648..b49dfbb3c1 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InvertCovMatrixWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/InvertCovMatrixWrapper.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class InvertCovMatrixWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Splits the given data set by collinear columns. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/MeanInterpolatorWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/MeanInterpolatorWrapper.java index 957d0af37a..bd70c1f171 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/MeanInterpolatorWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/MeanInterpolatorWrapper.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class MeanInterpolatorWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public MeanInterpolatorWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/PermuteRowsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/PermuteRowsWrapper.java index 5bf77bd7c1..52b0c9f0dd 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/PermuteRowsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/PermuteRowsWrapper.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ public class PermuteRowsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs the wrapper given some data and the params. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsDataFilter.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsDataFilter.java index 2363dce45b..4bd26731a7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsDataFilter.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsDataFilter.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.DataFilter; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.graph.Node; import java.util.ArrayList; @@ -53,7 +53,7 @@ public static List getNodes(List wrappers) { * @return - new dataset with constant columns removed. */ public DataSet filter(DataSet dataSet) { - return DataUtils.removeConstantColumns(dataSet); + return DataTransforms.removeConstantColumns(dataSet); } //================================ Inner classes ===============================// diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsWrapper.java index 778a3fa4a5..897ff7b85d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveConstantColumnsWrapper.java @@ -36,7 +36,7 @@ * @author Tyler Gibson */ public class RemoveConstantColumnsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public RemoveConstantColumnsWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveMissingValueCasesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveMissingValueCasesWrapper.java index 895fdad03d..2b10384cb2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveMissingValueCasesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveMissingValueCasesWrapper.java @@ -35,7 +35,7 @@ * @author Tyler Gibson */ public class RemoveMissingValueCasesWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs the missing value cases wrapper. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveSelectedVariablesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveSelectedVariablesWrapper.java index 868cfe20bf..a8b997c4ba 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveSelectedVariablesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/RemoveSelectedVariablesWrapper.java @@ -35,7 +35,7 @@ * @author Tyler Gibson */ public class RemoveSelectedVariablesWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public RemoveSelectedVariablesWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ReorderColumnsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ReorderColumnsWrapper.java index 85b810e63d..04de81447f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ReorderColumnsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ReorderColumnsWrapper.java @@ -38,7 +38,7 @@ * @author Tyler Gibson */ public class ReorderColumnsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ReorderColumnsWrapper(DataWrapper data, Parameters params) { @@ -59,7 +59,7 @@ public ReorderColumnsWrapper(DataWrapper data, Parameters params) { for (DataModel dataModel : dataModelList) { dataSets.add((DataSet) dataModel); } - newData.addAll((DataUtils.shuffleColumns2(dataSets))); + newData.addAll((DataTransforms.shuffleColumns2(dataSets))); } else { for (DataModel dataModel : dataModelList) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ResidualsWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ResidualsWrapper.java index f07cb0c863..d2586badf2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ResidualsWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ResidualsWrapper.java @@ -35,7 +35,7 @@ * @author Tyler */ public class ResidualsWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs a new time series dataset. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java index a7cc902fbd..cc343681af 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/ShiftDataWrapper.java @@ -42,7 +42,7 @@ * @author Tyler Gibson */ public class ShiftDataWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs the wrapper given some data and the params. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SimulateFromCovWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SimulateFromCovWrapper.java index 300d0dd6ca..6f3de07b4a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SimulateFromCovWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SimulateFromCovWrapper.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class SimulateFromCovWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Splits the given data set by collinear columns. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SplitCasesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SplitCasesWrapper.java index 21e35e5a9a..e0807e838d 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SplitCasesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SplitCasesWrapper.java @@ -37,7 +37,7 @@ * @author Tyler Gibson */ public class SplitCasesWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs the wrapper given some data and the params. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetContinuousVariablesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetContinuousVariablesWrapper.java index 67c57cfc55..8e9d0841d9 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetContinuousVariablesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetContinuousVariablesWrapper.java @@ -37,7 +37,7 @@ * @author Tyler Gibson */ public class SubsetContinuousVariablesWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SubsetContinuousVariablesWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetDiscreteVariablesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetDiscreteVariablesWrapper.java index d32f65e8d5..36cc1b11ce 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetDiscreteVariablesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetDiscreteVariablesWrapper.java @@ -37,7 +37,7 @@ * @author Tyler Gibson */ public class SubsetDiscreteVariablesWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SubsetDiscreteVariablesWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java index 4fbfd95e62..b1a8732f4c 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/SubsetSelectedVariablesWrapper.java @@ -35,7 +35,7 @@ * @author Tyler Gibson */ public class SubsetSelectedVariablesWrapper extends DataWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SubsetSelectedVariablesWrapper(DataWrapper data, Parameters params) { diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java index 161fdf2160..5ea930d55f 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper.java @@ -32,7 +32,7 @@ * @author Tyler */ public class TimeSeriesWrapper extends DataWrapper implements KnowledgeTransferable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @SuppressWarnings("FieldCanBeLocal") private Knowledge knowledge = new Knowledge(); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java index 35b715984e..cf63ee3253 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/datamanip/TimeSeriesWrapper2.java @@ -32,7 +32,7 @@ * @author Tyler */ public class TimeSeriesWrapper2 extends DataWrapper implements KnowledgeTransferable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs a new time series dataset. diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java index d9100cbc26..3b38986a4a 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/util/IndTestType.java @@ -60,7 +60,7 @@ public final class IndTestType implements TetradSerializable { new IndTestType("Fisher Z Pooled Residuals", DataType.Continuous); public static final IndTestType FISHER = new IndTestType("Fisher (Fisher Z)", DataType.Continuous); public static final IndTestType TIPPETT = new IndTestType("Tippett (Fisher Z)", DataType.Continuous); - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final IndTestType[] TYPES = {IndTestType.DEFAULT, IndTestType.CORRELATION_T, IndTestType.FISHER_Z, IndTestType.LINEAR_REGRESSION, IndTestType.CONDITIONAL_CORRELATION, IndTestType.SEM_BIC, IndTestType.LOGISTIC_REGRESSION, IndTestType.MIXED_MLR, IndTestType.FISHER_ZD, diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java index 67a4d9ef40..9e14f2dce7 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutMenu.java @@ -22,6 +22,7 @@ package edu.cmu.tetradapp.workbench; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.search.utils.GraphSearchUtils; @@ -171,18 +172,7 @@ public LayoutMenu(LayoutEditable layoutEditable) { causalOrder.addActionListener(e -> { LayoutEditable layoutEditable13 = LayoutMenu.this.getLayoutEditable(); - Graph graph = layoutEditable13.getGraph(); - - for (Node node : new ArrayList<>(graph.getNodes())) { - if (node.getNodeType() == NodeType.ERROR) { - graph.removeNode(node); - } - } - - CausalOrder layout1 = new CausalOrder(layoutEditable13); - layout1.doLayout(); - layoutEditable13.layoutByGraph(graph); - LayoutUtils.layout = LayoutUtils.Layout.distanceFromSelected; + LayoutUtils.layoutByCausalOrder(layoutEditable13); // Copy the laid out graph to the clipboard. getCopyLayoutAction().actionPerformed(null); diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java index 93e434c2a9..59f6984a47 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/workbench/LayoutUtils.java @@ -446,7 +446,7 @@ public static void layeredDrawingLayout(LayoutEditable layoutEditable) { } } - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); layoutEditable.layoutByGraph(graph); LayoutUtils.layout = Layout.layered; } @@ -492,19 +492,14 @@ public static void circleLayout(LayoutEditable layoutEditable) { for (Node node : new ArrayList<>(graph.getNodes())) { if (node.getNodeType() == NodeType.ERROR) { ((SemGraph) graph).setShowErrorTerms(false); -// graph.removeNode(node); } } Rectangle r = layoutEditable.getVisibleRect(); int m = FastMath.min(r.width, r.height) / 2; - int radius = m - 50; - int centerx = r.x + m; - int centery = r.y + m; -// DataGraphUtils.circleLayout(graph, 200, 200, 150); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); layoutEditable.layoutByGraph(graph); LayoutUtils.layout = Layout.circle; } @@ -515,13 +510,11 @@ public static void squareLayout(LayoutEditable layoutEditable) { for (Node node : new ArrayList<>(graph.getNodes())) { if (node.getNodeType() == NodeType.ERROR) { ((SemGraph) graph).setShowErrorTerms(false); -// graph.removeNode(node); } } Rectangle r = layoutEditable.getVisibleRect(); -// LayoutUtil.circleLayout(graph); LayoutUtil.squareLayout(graph); layoutEditable.layoutByGraph(graph); LayoutUtils.layout = Layout.circle; @@ -641,6 +634,19 @@ public static void lastLayout(LayoutEditable layoutEditable) { } } + public static void layoutByCausalOrder(LayoutEditable layoutEditable) { + Graph graph = layoutEditable.getGraph(); + + for (Node node : new ArrayList<>(graph.getNodes())) { + if (node.getNodeType() == NodeType.ERROR) { + graph.removeNode(node); + } + } + + LayoutUtil.layoutByCausalOrder(graph); + layoutEditable.layoutByGraph(graph); + LayoutUtils.layout = Layout.layered; + } public enum Layout { diff --git a/tetrad-gui/src/main/resources/config/devConfig.xml b/tetrad-gui/src/main/resources/config/devConfig.xml index 8346097168..14bff1cbeb 100644 --- a/tetrad-gui/src/main/resources/config/devConfig.xml +++ b/tetrad-gui/src/main/resources/config/devConfig.xml @@ -78,7 +78,7 @@ - edu.cmu.tetradapp.model.DagInCPDAGWrapper + edu.cmu.tetradapp.model.DagFromCPDAGWrapper edu.cmu.tetradapp.editor.GraphEditor diff --git a/tetrad-gui/src/main/resources/config/prodConfig.xml b/tetrad-gui/src/main/resources/config/prodConfig.xml index e5a3cbc3e3..f3494d414d 100644 --- a/tetrad-gui/src/main/resources/config/prodConfig.xml +++ b/tetrad-gui/src/main/resources/config/prodConfig.xml @@ -78,7 +78,7 @@ - edu.cmu.tetradapp.model.DagInCPDAGWrapper + edu.cmu.tetradapp.model.DagFromCPDAGWrapper edu.cmu.tetradapp.editor.GraphEditor diff --git a/tetrad-lib/pom.xml b/tetrad-lib/pom.xml index e8ae9022b3..4febc9080d 100644 --- a/tetrad-lib/pom.xml +++ b/tetrad-lib/pom.xml @@ -6,7 +6,7 @@ io.github.cmu-phil tetrad - 7.5.0 + 7.5.1-SNAPSHOT tetrad-lib diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/CompareTwoGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/CompareTwoGraphs.java index 28439e005a..c32f6e5f8c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/CompareTwoGraphs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/CompareTwoGraphs.java @@ -85,11 +85,11 @@ public static String getEdgewiseComparisonString(Graph trueGraph, Graph targetGr if (printStars) { boolean directedInGraph1 = false; - if (Edges.isDirectedEdge(edge) && trueGraph.paths().existsSemidirectedPath(node1, node2)) { + if (Edges.isDirectedEdge(edge) && trueGraph.paths().existsSemiDirectedPath(node1, node2)) { directedInGraph1 = true; } else if ((Edges.isUndirectedEdge(edge) || Edges.isBidirectedEdge(edge)) - && (trueGraph.paths().existsSemidirectedPath(node1, node2) - || trueGraph.paths().existsSemidirectedPath(node2, node1))) { + && (trueGraph.paths().existsSemiDirectedPath(node1, node2) + || trueGraph.paths().existsSemiDirectedPath(node2, node1))) { directedInGraph1 = true; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java index 2e7a3d0c95..c6cb199910 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/Comparison.java @@ -41,7 +41,6 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; @@ -555,12 +554,12 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param if (isSaveCPDAGs()) { File file3 = new File(dir3, "cpdag." + (j + 1) + ".txt"); - GraphSaveLoadUtils.saveGraph(GraphSearchUtils.cpdagForDag(graph), file3, false); + GraphSaveLoadUtils.saveGraph(GraphTransforms.cpdagForDag(graph), file3, false); } if (isSavePags()) { File file4 = new File(dir4, "pag." + (j + 1) + ".txt"); - GraphSaveLoadUtils.saveGraph(GraphSearchUtils.dagToPag(graph), file4, false); + GraphSaveLoadUtils.saveGraph(GraphTransforms.dagToPag(graph), file4, false); } } @@ -641,12 +640,12 @@ public void saveToFilesSingleSimulation(String dataPath, Simulation simulation, if (isSaveCPDAGs()) { File file3 = new File(dir3, "cpdag." + (j + 1) + ".txt"); - GraphSaveLoadUtils.saveGraph(GraphSearchUtils.cpdagForDag(graph), file3, false); + GraphSaveLoadUtils.saveGraph(GraphTransforms.cpdagForDag(graph), file3, false); } if (isSavePags()) { File file4 = new File(dir4, "pag." + (j + 1) + ".txt"); - GraphSaveLoadUtils.saveGraph(GraphSearchUtils.dagToPag(graph), file4, false); + GraphSaveLoadUtils.saveGraph(GraphTransforms.dagToPag(graph), file4, false); } } } catch (IOException e) { @@ -1191,9 +1190,10 @@ private void doRun(List algorithmSimulationWrappers, if (this.comparisonGraph == ComparisonGraph.true_DAG) { comparisonGraph = new EdgeListGraph(trueGraph); } else if (this.comparisonGraph == ComparisonGraph.CPDAG_of_the_true_DAG) { - comparisonGraph = GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueGraph)); + Graph dag = new EdgeListGraph(trueGraph); + comparisonGraph = GraphTransforms.cpdagForDag(dag); } else if (this.comparisonGraph == ComparisonGraph.PAG_of_the_true_DAG) { - comparisonGraph = GraphSearchUtils.dagToPag(trueGraph); + comparisonGraph = GraphTransforms.dagToPag(trueGraph); } else { throw new IllegalArgumentException("Unrecognized graph type."); } @@ -1643,7 +1643,7 @@ private enum Mode { private static class AlgorithmWrapper implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Algorithm algorithm; private final Parameters parameters; private final List overriddenParameters = new ArrayList<>(); @@ -1707,7 +1707,7 @@ public Parameters getAlgorithmSpecificParameters() { private static class AlgorithmSimulationWrapper implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final SimulationWrapper simulationWrapper; private final AlgorithmWrapper algorithmWrapper; @@ -1753,7 +1753,7 @@ public AlgorithmWrapper getAlgorithmWrapper() { } private static class SimulationWrapper implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Simulation simulation; private List graphs; private List dataModels; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java index eb98cff67c..1f48973d1a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/TimeoutComparison.java @@ -39,7 +39,6 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.data.simulation.LoadDataAndGraphs; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.*; import org.apache.commons.math3.util.FastMath; import org.reflections.Reflections; @@ -54,8 +53,6 @@ import java.util.*; import java.util.concurrent.*; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Nov 14, 2017 12:00:31 PM * @@ -499,12 +496,12 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param if (isSaveCPDAGs()) { File file3 = new File(dir3, "pattern." + (j + 1) + ".txt"); - GraphSaveLoadUtils.saveGraph(GraphSearchUtils.cpdagForDag(graph), file3, false); + GraphSaveLoadUtils.saveGraph(GraphTransforms.cpdagForDag(graph), file3, false); } if (isSavePags()) { File file4 = new File(dir4, "pag." + (j + 1) + ".txt"); - GraphSaveLoadUtils.saveGraph(dagToPag(graph), file4, false); + GraphSaveLoadUtils.saveGraph(GraphTransforms.dagToPag(graph), file4, false); } } @@ -1104,9 +1101,11 @@ private void doRun(List algorithmSimulationWrappers, if (this.comparisonGraph == ComparisonGraph.true_DAG) { comparisonGraph = new EdgeListGraph(trueGraph); } else if (this.comparisonGraph == ComparisonGraph.CPDAG_of_the_true_DAG) { - comparisonGraph = GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueGraph)); + Graph dag = new EdgeListGraph(trueGraph); + comparisonGraph = GraphTransforms.cpdagForDag(dag); } else if (this.comparisonGraph == ComparisonGraph.PAG_of_the_true_DAG) { - comparisonGraph = dagToPag(new EdgeListGraph(trueGraph)); + Graph trueGraph1 = new EdgeListGraph(trueGraph); + comparisonGraph = GraphTransforms.dagToPag(trueGraph1); } else { throw new IllegalArgumentException("Unrecognized graph type."); } @@ -1536,7 +1535,7 @@ private enum Mode { private static class AlgorithmWrapper implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Algorithm algorithm; private final Parameters parameters; private final List overriddenParameters = new ArrayList<>(); @@ -1600,7 +1599,7 @@ public Parameters getAlgorithmSpecificParameters() { private static class AlgorithmSimulationWrapper implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final SimulationWrapper simulationWrapper; private final AlgorithmWrapper algorithmWrapper; List parameters = new ArrayList<>(); @@ -1650,7 +1649,7 @@ public AlgorithmWrapper getAlgorithmWrapper() { private static class SimulationWrapper implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Simulation simulation; private List graphs; private List dataModels; 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..f5b3491d6a 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 @@ -37,6 +37,16 @@ public class AlgorithmFactory { private AlgorithmFactory() { } + /** + * Creates an algorithm. + * + * @param algoClass algorithm class + * @param test independence test + * @param score score + * @return algorithm + * @throws IllegalAccessException Reflection exception + * @throws InstantiationException Reflection exception + */ public static Algorithm create(Class algoClass, IndependenceWrapper test, ScoreWrapper score) throws IllegalAccessException, InstantiationException { if (algoClass == null) { @@ -65,6 +75,16 @@ public static Algorithm create(Class algoClass, Independenc return algorithm; } + /** + * Creates an algorithm. + * @param algoClass algorithm class + * @param test independence test + * @param score score + * @param externalGraph external graph + * @return algorithm + * @throws IllegalAccessException Reflection exception + * @throws InstantiationException Reflection exception + */ public static Algorithm create(Class algoClass, IndependenceWrapper test, ScoreWrapper score, Graph externalGraph) throws IllegalAccessException, InstantiationException { Algorithm algorithm = AlgorithmFactory.create(algoClass, test, score); @@ -75,6 +95,16 @@ public static Algorithm create(Class algoClass, Independenc return algorithm; } + /** + * Creates an algorithm. + * + * @param algoClass algorithm class + * @param indTestClass independence test class + * @param scoreClass score class + * @return algorithm + * @throws IllegalAccessException Reflection exception + * @throws InstantiationException Reflection exception + */ public static Algorithm create(Class algoClass, Class indTestClass, Class scoreClass) throws IllegalAccessException, InstantiationException { if (algoClass == null) { @@ -87,6 +117,16 @@ public static Algorithm create(Class algoClass, Class algoClass, Class indTestClass, Class scoreClass, Graph externalGraph) throws IllegalAccessException, InstantiationException { Algorithm algorithm = AlgorithmFactory.create(algoClass, indTestClass, scoreClass); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java index 82b4564980..df08c3ea63 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/Algorithms.java @@ -11,6 +11,9 @@ public class Algorithms { private final List algorithms = new ArrayList<>(); + /** + * Constructs an empty list of algorithms. + */ public Algorithms() { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java index b83dc96a92..9c01364626 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/FirstInflection.java @@ -18,7 +18,7 @@ */ public class FirstInflection implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double low; private final double high; private final double increment; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java index d9e185c2fe..ee68842960 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StARS.java @@ -23,7 +23,7 @@ */ public class StARS implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double low; private final double high; private final String parameter; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java index f70ead92c9..1c5067c5b3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/StabilitySelection.java @@ -24,7 +24,7 @@ */ public class StabilitySelection implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Algorithm algorithm; public StabilitySelection(Algorithm algorithm) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java index 548e7bb8a5..e78b2d4983 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Bpc.java @@ -4,15 +4,11 @@ import edu.cmu.tetrad.annotation.AlgType; 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.graph.LayoutUtil; -import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Mimbuild; import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.utils.ClusterSignificance; import edu.cmu.tetrad.search.utils.ClusterUtils; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; @@ -34,7 +30,7 @@ @Bootstrapping public class Bpc implements Algorithm, ClusterAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Bpc() { } @@ -94,7 +90,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { } Graph structureGraph = mimbuild.search(partition, latentNames, cov); - LayoutUtil.circleLayout(structureGraph); + LayoutUtil.defaultLayout(structureGraph); LayoutUtil.fruchtermanReingoldLayout(structureGraph); ICovarianceMatrix latentsCov = mimbuild.getLatentsCov(); @@ -102,7 +98,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { TetradLogger.getInstance().log("details", "Latent covs = \n" + latentsCov); Graph fullGraph = mimbuild.getFullGraph(); - LayoutUtil.circleLayout(fullGraph); + LayoutUtil.defaultLayout(fullGraph); LayoutUtil.fruchtermanReingoldLayout(fullGraph); return fullGraph; @@ -123,7 +119,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java index 7829309678..9dab552ba2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Fofc.java @@ -6,13 +6,13 @@ import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.LayoutUtil; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.Mimbuild; import edu.cmu.tetrad.search.utils.BpcTestType; import edu.cmu.tetrad.search.utils.ClusterSignificance; import edu.cmu.tetrad.search.utils.ClusterUtils; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.TetradLogger; @@ -34,7 +34,7 @@ @Bootstrapping public class Fofc implements Algorithm, HasKnowledge, ClusterAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); public Fofc() { @@ -108,7 +108,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { } Graph structureGraph = mimbuild.search(partition, latentNames, cov); - LayoutUtil.circleLayout(structureGraph); + LayoutUtil.defaultLayout(structureGraph); LayoutUtil.fruchtermanReingoldLayout(structureGraph); ICovarianceMatrix latentsCov = mimbuild.getLatentsCov(); @@ -116,7 +116,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { TetradLogger.getInstance().log("details", "Latent covs = \n" + latentsCov); Graph fullGraph = mimbuild.getFullGraph(); - LayoutUtil.circleLayout(fullGraph); + LayoutUtil.defaultLayout(fullGraph); LayoutUtil.fruchtermanReingoldLayout(fullGraph); return fullGraph; @@ -137,7 +137,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(graph); + return GraphTransforms.cpdagForDag(graph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java index a9ab94824f..7cad8fb209 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/cluster/Ftfc.java @@ -7,7 +7,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -28,7 +28,7 @@ @Bootstrapping public class Ftfc implements Algorithm, HasKnowledge, ClusterAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); public Ftfc() { @@ -79,7 +79,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Dagma.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Dagma.java index b9d41ed17e..a47570bffd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Dagma.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/Dagma.java @@ -35,7 +35,7 @@ @Bootstrapping public class Dagma implements Algorithm, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private List bootstrapGraphs = new ArrayList<>(); public Dagma() {} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/DirectLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/DirectLingam.java index 84645c2e63..42cefbfbe8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/DirectLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/DirectLingam.java @@ -35,7 +35,7 @@ @Bootstrapping public class DirectLingam implements Algorithm, UsesScoreWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private ScoreWrapper score; private List bootstrapGraphs = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingD.java index 74c717c964..00bdae5ccc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingD.java @@ -33,7 +33,7 @@ @Bootstrapping public class IcaLingD implements Algorithm, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private List bootstrapGraphs = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingam.java index 0471c220bd..c97e7a0614 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/continuous/dag/IcaLingam.java @@ -34,7 +34,7 @@ @Bootstrapping public class IcaLingam implements Algorithm, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private List bootstrapGraphs = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java index 000c3d0a15..b9bae9e305 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBNTPc.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class ExternalAlgorithmBNTPc extends ExternalAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String extDir; private final String shortDescription; @@ -62,11 +62,11 @@ public Graph search(DataModel dataSet, Parameters parameters) { try { DataSet dataSet2 = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); System.out.println("Loading graph from " + file.getAbsolutePath()); Graph graph = GraphSaveLoadUtils.loadGraphBNTPcMatrix(dataSet.getVariables(), dataSet2); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); return graph; } catch (IOException e) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java index 3d4443eeb9..94984c3d6f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmBnlearnMmhc.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class ExternalAlgorithmBnlearnMmhc extends ExternalAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String extDir; private final String shortDescription; @@ -87,7 +87,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { } } - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); return graph; } catch (IOException e) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java index 51fda663fa..9a315cda90 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmIntersection.java @@ -29,7 +29,7 @@ * @author josephramsey */ public class ExternalAlgorithmIntersection extends ExternalAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final ExternalAlgorithm[] algorithms; private final String shortDescription; private long elapsed = -99; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java index d00edb0193..9c91f45b83 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgGes.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class ExternalAlgorithmPcalgGes extends ExternalAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String extDir; private final String shortDescription; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java index 05b546b6a4..5a8c228022 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmPcalgPc.java @@ -37,7 +37,7 @@ * @author josephramsey */ public class ExternalAlgorithmPcalgPc extends ExternalAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String extDir; private final String shortDescription; @@ -86,11 +86,11 @@ public Graph search(DataModel dataSet, Parameters parameters) { try { DataSet dataSet2 = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); System.out.println("Loading graph from " + file.getAbsolutePath()); Graph graph = ExternalAlgorithmPcalgPc.loadGraphPcAlgMatrix(dataSet2); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); return graph; } catch (IOException e) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java index 5d99e87525..7aa6c2c4a2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/external/ExternalAlgorithmTetrad.java @@ -33,7 +33,7 @@ * @author josephramsey */ public class ExternalAlgorithmTetrad extends ExternalAlgorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String extDir; private final String shortDescription; @@ -56,7 +56,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { File file = new File(this.path, "/results/" + this.extDir + "/" + (this.simIndex + 1) + "/graph." + index + ".txt"); System.out.println(file.getAbsolutePath()); Graph graph = GraphSaveLoadUtils.loadGraphTxt(file); - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); return graph; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java index f86023a935..4bbb0491b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/mixed/Mgm.java @@ -15,6 +15,8 @@ import java.util.List; /** + * MGM. + * * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( @@ -25,7 +27,7 @@ @Bootstrapping public class Mgm implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Mgm() { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java index 2d12a13e3f..7ce9b95d94 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FasLofs.java @@ -25,7 +25,7 @@ * @author josephramsey */ public class FasLofs implements Algorithm, HasKnowledge { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Lofs.Rule rule; private Knowledge knowledge = new Knowledge(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java index dfdbb59cd0..1656d42d19 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/Fask.java @@ -40,7 +40,7 @@ dataType = DataType.Continuous ) public class Fask implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java index a2ed68b9db..5a69402e55 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskConcatenated.java @@ -35,7 +35,7 @@ @Bootstrapping public class FaskConcatenated implements MultiDataSetAlgorithm, HasKnowledge, TakesIndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); @@ -55,10 +55,10 @@ public Graph search(List dataSets, Parameters parameters) { List centered = new ArrayList<>(); for (DataModel dataSet : dataSets) { - centered.add(DataUtils.standardizeData((DataSet) dataSet)); + centered.add(DataTransforms.standardizeData((DataSet) dataSet)); } - DataSet dataSet = DataUtils.concatenate(centered); + DataSet dataSet = DataTransforms.concatenate(centered); dataSet.setNumberFormat(new DecimalFormat("0.000000000000000000")); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java index 4d4f3cb43d..c582032801 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskLofsConcatenated.java @@ -28,7 +28,7 @@ */ @Bootstrapping public class FaskLofsConcatenated implements MultiDataSetAlgorithm, HasKnowledge { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Lofs.Rule rule; private Knowledge knowledge = new Knowledge(); @@ -45,7 +45,7 @@ public Graph search(List dataModels, Parameters parameters) { dataSets.add((DataSet) dataModel); } - DataSet dataSet = DataUtils.concatenate(dataSets); + DataSet dataSet = DataTransforms.concatenate(dataSets); FasLofs search = new FasLofs(dataSet, this.rule); search.setDepth(parameters.getInt(Params.DEPTH)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java index d2db4ba91f..abd3627ffd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FaskVote.java @@ -39,7 +39,7 @@ @Experimental public class FaskVote implements MultiDataSetAlgorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); private ScoreWrapper score; private IndependenceWrapper test; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FciIod.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FciIod.java index 055b6446fd..6417db6bc3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FciIod.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FciIod.java @@ -24,7 +24,7 @@ /** *

Runs FCI on multiple datasets using the IOD pooled dataset independence test. The reference is here:

* - *

Tillman, R., & Spirtes, P. (2011, June). Learning equivalence classes of acyclic models with latent and selection + *

Tillman, R., & Spirtes, P. (2011, June). Learning equivalence classes of acyclic models with latent and selection * variables from multiple datasets with overlapping variables. In Proceedings of the Fourteenth International * Conference on Artificial Intelligence and Statistics (pp. 3-15). JMLR Workshop and Conference Proceedings.

* @@ -41,7 +41,7 @@ // in principle, so we've removed the bootstrapping annotation from it and deleted the bootstrapping code. public class FciIod implements MultiDataSetAlgorithm, HasKnowledge, TakesIndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); private IndependenceWrapper test; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java index 3c83c95d9c..ccf347cbc2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/multi/FgesConcatenated.java @@ -9,7 +9,7 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -27,7 +27,7 @@ */ @Bootstrapping public class FgesConcatenated implements MultiDataSetAlgorithm, HasKnowledge { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private Algorithm externalGraph; @@ -56,7 +56,7 @@ public Graph search(List dataModels, Parameters parameters) { dataSets.add((DataSet) dataModel); } - DataSet dataSet = DataUtils.concatenate(dataSets); + DataSet dataSet = DataTransforms.concatenate(dataSets); Graph initial = null; if (this.externalGraph != null) { @@ -140,7 +140,8 @@ public Graph getComparisonGraph(Graph graph) { if (this.compareToTrue) { return new EdgeListGraph(graph); } else { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } } 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 15b51ae31f..5ea008c074 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 @@ -43,7 +43,7 @@ @Bootstrapping public class Images implements MultiDataSetAlgorithm, HasKnowledge, UsesScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); private ScoreWrapper score = new SemBicScore(); 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 564843f29a..ec75e01630 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 @@ -37,7 +37,7 @@ @Bootstrapping public class Boss implements Algorithm, UsesScoreWrapper, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); 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 12ab8c57e8..8430b3b623 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Cpc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Cpc.java @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; @@ -37,7 +37,7 @@ public class Cpc implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -125,7 +125,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } @Override @@ -144,7 +145,6 @@ public List getParameters() { parameters.add(Params.STABLE_FAS); parameters.add(Params.CONFLICT_RULE); parameters.add(Params.MEEK_PREVENT_CYCLES); -// parameters.add(Params.PC_HEURISTIC); parameters.add(Params.DEPTH); parameters.add(Params.TIME_LAG); 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 563e6b7cad..bd8df26b75 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Fas.java @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -36,7 +36,7 @@ public class Fas implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -101,7 +101,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } @Override 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 43c421201e..ca9d0460f3 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 @@ -37,7 +37,7 @@ @Bootstrapping public class Fges implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesExternalGraph, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java index 190a484a20..5446c2c237 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMb.java @@ -38,7 +38,7 @@ public class FgesMb implements Algorithm, HasKnowledge, UsesScoreWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private String targetName; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java index 93831b2ef4..010fcf852c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/FgesMeasurement.java @@ -8,8 +8,8 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.RandomUtil; @@ -28,7 +28,7 @@ @Bootstrapping public class FgesMeasurement implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -44,7 +44,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { DataSet dataSet = SimpleDataLoader.getContinuousDataSet(dataModel); dataSet = dataSet.copy(); - dataSet = DataUtils.standardizeData(dataSet); + dataSet = DataTransforms.standardizeData(dataSet); double variance = parameters.getDouble(Params.MEASUREMENT_VARIANCE); if (variance > 0) { @@ -85,7 +85,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java index bfcd15c7b1..8e96910c9f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/GesMe.java @@ -9,9 +9,9 @@ import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.*; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import org.apache.commons.math3.util.FastMath; @@ -33,7 +33,7 @@ @Experimental public class GesMe implements Algorithm, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final ScoreWrapper score = new SemBicScoreDeterministic(); private boolean compareToTrue; private List bootstrapGraphs = new ArrayList<>(); @@ -191,7 +191,8 @@ public Graph getComparisonGraph(Graph graph) { if (this.compareToTrue) { return new EdgeListGraph(graph); } else { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } } 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 ab0897c94a..174d70ed85 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 @@ -39,7 +39,7 @@ @Bootstrapping public class Grasp implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private ScoreWrapper score; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); 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 07ac5b2f54..f836722598 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pc.java @@ -13,7 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.utils.PcCommon; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; @@ -36,7 +36,7 @@ @Bootstrapping public class Pc implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -124,7 +124,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(new EdgeListGraph(graph)); + Graph dag = new EdgeListGraph(graph); + return GraphTransforms.cpdagForDag(dag); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcLingam.java new file mode 100644 index 0000000000..04e2a4b0eb --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcLingam.java @@ -0,0 +1,141 @@ +package edu.cmu.tetrad.algcomparison.algorithm.oracle.cpdag; + +import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; +import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; +import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; +import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; +import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper; +import edu.cmu.tetrad.annotation.AlgType; +import edu.cmu.tetrad.annotation.Bootstrapping; +import edu.cmu.tetrad.data.DataModel; +import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataType; +import edu.cmu.tetrad.data.Knowledge; +import edu.cmu.tetrad.graph.EdgeListGraph; +import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.search.PermutationSearch; +import edu.cmu.tetrad.search.score.Score; +import edu.cmu.tetrad.search.utils.TsUtils; +import edu.cmu.tetrad.util.Parameters; +import edu.cmu.tetrad.util.Params; +import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; + +import java.util.ArrayList; +import java.util.List; + +/** + * Peter/Clark algorithm (PC). + * + * @author josephramsey + */ +@edu.cmu.tetrad.annotation.Algorithm(name = "PC-LiNGAM", command = "pc-lingam", algoType = AlgType.forbid_latent_common_causes) +@Bootstrapping +public class PcLingam implements Algorithm, HasKnowledge, UsesScoreWrapper, ReturnsBootstrapGraphs { + private static final long serialVersionUID = 23L; + private ScoreWrapper score; + private Knowledge knowledge = new Knowledge(); + private List bootstrapGraphs = new ArrayList<>(); + + public PcLingam() { + } + + public PcLingam(ScoreWrapper scoreWrapper) { + this.score = scoreWrapper; + } + + @Override + public Graph search(DataModel dataModel, Parameters parameters) { + if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { + if (parameters.getInt(Params.TIME_LAG) > 0) { + DataSet dataSet = (DataSet) dataModel; + DataSet timeSeries = TsUtils.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); + + edu.cmu.tetrad.search.Boss boss = new edu.cmu.tetrad.search.Boss(score); + boss.setUseBes(parameters.getBoolean(Params.USE_BES)); + boss.setNumStarts(parameters.getInt(Params.NUM_STARTS)); + boss.setNumThreads(parameters.getInt(Params.NUM_THREADS)); + boss.setUseDataOrder(parameters.getBoolean(Params.USE_DATA_ORDER)); + boss.setVerbose(parameters.getBoolean(Params.VERBOSE)); + PermutationSearch permutationSearch = new PermutationSearch(boss); + permutationSearch.setKnowledge(this.knowledge); + + Graph cpdag = permutationSearch.search(); + + edu.cmu.tetrad.search.PcLingam pcLingam = new edu.cmu.tetrad.search.PcLingam(cpdag, (DataSet) dataModel); + + return pcLingam.search(); + } else { + PcLingam pcAll = new PcLingam(this.score); + + DataSet data = (DataSet) dataModel; + 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)); + Graph graph = search.search(); + if (parameters.getBoolean(Params.SAVE_BOOTSTRAP_GRAPHS)) this.bootstrapGraphs = search.getGraphs(); + return graph; + } + } + + @Override + public Graph getComparisonGraph(Graph graph) { + return new EdgeListGraph(graph); + } + + @Override + public String getDescription() { + return "PC-LiNGAM using " + this.score.getDescription(); + } + + @Override + public DataType getDataType() { + return this.score.getDataType(); + } + + @Override + public List getParameters() { + List parameters = new ArrayList<>(); + parameters.add(Params.USE_BES); + parameters.add(Params.NUM_STARTS); + parameters.add(Params.TIME_LAG); + parameters.add(Params.NUM_THREADS); + parameters.add(Params.USE_DATA_ORDER); + parameters.add(Params.VERBOSE); + return parameters; + } + + @Override + public Knowledge getKnowledge() { + return this.knowledge; + } + + @Override + public void setKnowledge(Knowledge knowledge) { + this.knowledge = new Knowledge(knowledge); + } + + @Override + public ScoreWrapper getScoreWrapper() { + return this.score; + } + + @Override + public void setScoreWrapper(ScoreWrapper score) { + this.score = score; + } + + @Override + public List getBootstrapGraphs() { + return this.bootstrapGraphs; + } +} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java index 2cca6c6ea4..cf60e4995d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/PcMb.java @@ -38,7 +38,7 @@ public class PcMb implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List targets; 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 ef9b665870..f74f3d8730 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Pcd.java @@ -6,8 +6,8 @@ import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.test.ScoreIndTest; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.work_in_progress.SemBicScoreDeterministic; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -23,7 +23,7 @@ */ @Bootstrapping public class Pcd implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -71,7 +71,7 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return GraphSearchUtils.cpdagForDag(graph); + return GraphTransforms.cpdagForDag(graph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/RestrictedBoss.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/RestrictedBoss.java index 40e9abc0f0..50f0ca4e39 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/RestrictedBoss.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/RestrictedBoss.java @@ -36,7 +36,7 @@ @Bootstrapping public class RestrictedBoss implements Algorithm, UsesScoreWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private ScoreWrapper score; private List bootstrapGraphs = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java index 92b8d14e42..b0b7c1f562 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/SingleGraphAlg.java @@ -19,7 +19,7 @@ */ public class SingleGraphAlg implements Algorithm, HasKnowledge { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph graph; public SingleGraphAlg(Graph graph) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Sp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/cpdag/Sp.java index 11e2349061..d0813c6b81 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 @@ -38,7 +38,7 @@ @Bootstrapping @Experimental public class Sp implements Algorithm, UsesScoreWrapper, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); 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 fcf5b72ea7..53a25cc689 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 @@ -15,6 +15,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.BFci; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; @@ -24,8 +25,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Adjusts GFCI to use a permutation algorithm (such as BOSS-Tuck) to do the initial steps of finding adjacencies and @@ -47,13 +46,15 @@ public class Bfci implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); - + /** + * No-arg constructor. Used for reflection; do not delete. + */ public Bfci() { // Used for reflection; do not delete. } @@ -105,7 +106,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(graph); + return GraphTransforms.dagToPag(graph); } @Override 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 624e65aed6..9accc6e7e6 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 @@ -31,7 +31,7 @@ @Bootstrapping //@Experimental public class Ccd implements Algorithm, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private List bootstrapGraphs = new ArrayList<>(); 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 c35e9493a1..21af3edfba 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 @@ -4,6 +4,8 @@ import edu.cmu.tetrad.algcomparison.algorithm.ReturnsBootstrapGraphs; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.utils.HasKnowledge; +import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper; +import edu.cmu.tetrad.annotation.AlgType; import edu.cmu.tetrad.annotation.Bootstrapping; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; @@ -11,48 +13,68 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; +import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** - * Conserative FCI. + * FCI. * * @author josephramsey */ +@edu.cmu.tetrad.annotation.Algorithm( + name = "CFCI", + command = "cfci", + algoType = AlgType.allow_latent_common_causes +) @Bootstrapping -public class Cfci implements Algorithm, HasKnowledge, ReturnsBootstrapGraphs { +public class Cfci implements Algorithm, HasKnowledge, TakesIndependenceWrapper, + ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; - private final IndependenceWrapper test; + private static final long serialVersionUID = 23L; + private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); + public Cfci() { + } + public Cfci(IndependenceWrapper test) { this.test = test; } @Override - public Graph search(DataModel dataSet, Parameters parameters) { + public Graph search(DataModel dataModel, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { - edu.cmu.tetrad.search.Cfci search = new edu.cmu.tetrad.search.Cfci(this.test.getTest(dataSet, parameters)); + if (parameters.getInt(Params.TIME_LAG) > 0) { + DataSet dataSet = (DataSet) dataModel; + DataSet timeSeries = TsUtils.createLagData(dataSet, parameters.getInt(Params.TIME_LAG)); + if (dataSet.getName() != null) { + timeSeries.setName(dataSet.getName()); + } + dataModel = timeSeries; + knowledge = timeSeries.getKnowledge(); + } + + edu.cmu.tetrad.search.Cfci search = new edu.cmu.tetrad.search.Cfci(this.test.getTest(dataModel, parameters)); + search.setDepth(parameters.getInt(Params.DEPTH)); search.setKnowledge(this.knowledge); search.setCompleteRuleSetUsed(parameters.getBoolean(Params.COMPLETE_RULE_SET_USED)); - search.setDepth(parameters.getInt(Params.DEPTH)); - search.setVerbose(parameters.getBoolean(Params.VERBOSE)); + search.setPossibleMsepSearchDone(parameters.getBoolean(Params.POSSIBLE_MSEP_DONE)); search.setDoDiscriminatingPathRule(parameters.getBoolean(Params.DO_DISCRIMINATING_PATH_RULE)); + search.setVerbose(parameters.getBoolean(Params.VERBOSE)); + return search.search(); } else { Cfci algorithm = new Cfci(this.test); - DataSet data = (DataSet) dataSet; + 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); @@ -66,12 +88,12 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(new EdgeListGraph(graph)); + Graph trueGraph = new EdgeListGraph(graph); + return GraphTransforms.dagToPag(trueGraph); } - @Override public String getDescription() { - return "CFCI (Conservative Fast Causal Inference), using " + this.test.getDescription(); + return "FCI (Fast Causal Inference) using " + this.test.getDescription(); } @Override @@ -81,15 +103,15 @@ public DataType getDataType() { @Override public List getParameters() { - List parameters = new LinkedList<>(); - if (this.test != null) { - parameters.addAll(this.test.getParameters()); - } + List parameters = new ArrayList<>(); parameters.add(Params.DEPTH); - parameters.add(Params.COMPLETE_RULE_SET_USED); + parameters.add(Params.POSSIBLE_MSEP_DONE); parameters.add(Params.DO_DISCRIMINATING_PATH_RULE); + parameters.add(Params.COMPLETE_RULE_SET_USED); + parameters.add(Params.TIME_LAG); parameters.add(Params.VERBOSE); + return parameters; } @@ -100,7 +122,17 @@ public Knowledge getKnowledge() { @Override public void setKnowledge(Knowledge knowledge) { - this.knowledge = new Knowledge((Knowledge) knowledge); + this.knowledge = new Knowledge(knowledge); + } + + @Override + public IndependenceWrapper getIndependenceWrapper() { + return this.test; + } + + @Override + public void setIndependenceWrapper(IndependenceWrapper test) { + this.test = test; } @Override 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 b909386f6f..752d387009 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Fci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Fci.java @@ -13,6 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -21,8 +22,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * FCI. * @@ -37,7 +36,7 @@ public class Fci implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -111,7 +110,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(new EdgeListGraph(graph)); + Graph trueGraph = new EdgeListGraph(graph); + return GraphTransforms.dagToPag(trueGraph); } public String getDescription() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java index 79144d8e72..4eb8e3c8f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/FciMax.java @@ -13,6 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -21,8 +22,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * FCI. * @@ -37,7 +36,7 @@ public class FciMax implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -109,7 +108,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(new EdgeListGraph(graph)); + Graph trueGraph = new EdgeListGraph(graph); + return GraphTransforms.dagToPag(trueGraph); } public String getDescription() { 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 85c48a47a1..c4404a117c 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 @@ -14,6 +14,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.GFci; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; @@ -24,8 +25,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * GFCI. @@ -41,7 +40,7 @@ public class Gfci implements Algorithm, HasKnowledge, UsesScoreWrapper, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); @@ -102,7 +101,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(graph); + return GraphTransforms.dagToPag(graph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java index 69ba496aad..1475820bbb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/GraspFci.java @@ -14,6 +14,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.score.Score; import edu.cmu.tetrad.search.utils.TsUtils; @@ -24,8 +25,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Adjusts GFCI to use a permutation algorithm (such as BOSS-Tuck) to do the initial steps of finding adjacencies and @@ -46,7 +45,7 @@ public class GraspFci implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); @@ -119,7 +118,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(graph); + return GraphTransforms.dagToPag(graph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java index 10a92ba8f3..ff39e0d06f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/PagSampleRfci.java @@ -11,6 +11,7 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -18,8 +19,6 @@ import java.util.LinkedList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Jan 29, 2023 3:45:09 PM * @@ -36,7 +35,7 @@ public class PagSampleRfci implements Algorithm, HasKnowledge { public static final List PAG_SAMPLING_RFCI_PARAMETERS = new LinkedList<>(); public static final List RFCI_PARAMETERS = new LinkedList<>(); public static final List PROBABILISTIC_TEST_PARAMETERS = new LinkedList<>(); - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; static { // algorithm parameters @@ -81,7 +80,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(new EdgeListGraph(graph)); + Graph trueGraph = new EdgeListGraph(graph); + return GraphTransforms.dagToPag(trueGraph); } @Override 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 ffd2dccb40..3fbf1d0834 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/Rfci.java @@ -13,6 +13,7 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.utils.TsUtils; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -21,8 +22,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * RFCI. * @@ -36,7 +35,7 @@ @Bootstrapping public class Rfci implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -84,7 +83,8 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(new EdgeListGraph(graph)); + Graph trueGraph = new EdgeListGraph(graph); + return GraphTransforms.dagToPag(trueGraph); } public String getDescription() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java index 50434f273a..70901c090e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/RfciBsc.java @@ -11,14 +11,13 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Jan 4, 2019 4:32:05 PM * @@ -33,7 +32,7 @@ @Experimental public class RfciBsc implements Algorithm, HasKnowledge { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final IndependenceWrapper test = new ProbabilisticTest(); private Knowledge knowledge = new Knowledge(); private List bootstrapGraphs = new ArrayList<>(); @@ -75,7 +74,8 @@ public Graph search(DataModel dataSet, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(new EdgeListGraph(graph)); + Graph trueGraph = new EdgeListGraph(graph); + return GraphTransforms.dagToPag(trueGraph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SpFci.java index 61385467f8..9d28f8a164 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SpFci.java @@ -14,6 +14,7 @@ import edu.cmu.tetrad.data.DataType; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; import edu.pitt.dbmi.algo.resampling.GeneralResamplingTest; @@ -22,8 +23,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Adjusts GFCI to use a permutation algorithm (in this case SP) to do the initial steps of finding adjacencies and @@ -44,7 +43,7 @@ public class SpFci implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper, HasKnowledge, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge = new Knowledge(); @@ -91,7 +90,7 @@ public Graph search(DataModel dataModel, Parameters parameters) { @Override public Graph getComparisonGraph(Graph graph) { - return dagToPag(graph); + return GraphTransforms.dagToPag(graph); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java index e2f9b1393b..40c66a4e1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarFci.java @@ -39,7 +39,7 @@ public class SvarFci implements Algorithm, HasKnowledge, TakesIndependenceWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private Knowledge knowledge; private List bootstrapGraphs = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java index d45120c34f..2d9d31d9bf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pag/SvarGfci.java @@ -41,7 +41,7 @@ public class SvarGfci implements Algorithm, HasKnowledge, TakesIndependenceWrapper, UsesScoreWrapper, ReturnsBootstrapGraphs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private Knowledge knowledge; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/oracle/pattern/Cstar.java index 86b780e4a9..8d8c1ddea4 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 @@ -31,7 +31,7 @@ algoType = AlgType.forbid_latent_common_causes ) public class Cstar implements Algorithm, UsesScoreWrapper, TakesIndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private IndependenceWrapper test; private ScoreWrapper score; private LinkedList records; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java index 6d0e7a49c5..3fa5343b08 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/FactorAnalysis.java @@ -17,11 +17,13 @@ import java.util.Vector; /** + * Factor analysis. + * * @author josephramsey */ @Bootstrapping public class FactorAnalysis implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Graph search(DataModel ds, Parameters parameters) { if (parameters.getInt(Params.NUMBER_RESAMPLING) < 1) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java index bad9c9fefc..4be9e56f4b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/other/Glasso.java @@ -21,6 +21,8 @@ import java.util.List; /** + * GLASSO. + * * @author josephramsey */ @edu.cmu.tetrad.annotation.Algorithm( @@ -33,7 +35,7 @@ @Experimental public class Glasso implements Algorithm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Graph search(DataModel ds, Parameters parameters) { DataSet _data = (DataSet) ds; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java index 350f892725..87de56deb8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Eb.java @@ -32,7 +32,7 @@ @Bootstrapping public class Eb implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPw.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPw.java index 15ac158d66..6f2ab2bdb6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPw.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/FaskPw.java @@ -34,7 +34,7 @@ @Bootstrapping public class FaskPw implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java index d63298ce79..cd35b9d354 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R1.java @@ -32,7 +32,7 @@ @Bootstrapping public class R1 implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java index b3f50a5db3..d5c73f8492 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R2.java @@ -32,7 +32,7 @@ @Bootstrapping public class R2 implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java index 1f5bf8e03d..c4c9e5e1c4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/R3.java @@ -33,7 +33,7 @@ @Bootstrapping public class R3 implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Rskew.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Rskew.java index 29a78f263e..b4b94d41b1 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 @@ -32,7 +32,7 @@ @Bootstrapping public class Rskew implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RskewE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RskewE.java index 85d132b92b..d806e60f62 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RskewE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/RskewE.java @@ -32,7 +32,7 @@ @Bootstrapping public class RskewE implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Skew.java index ce404c2b04..42a1138dbc 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 @@ -33,7 +33,7 @@ @Bootstrapping public class Skew implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java index b90084b60a..e0802a23cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/SkewE.java @@ -32,7 +32,7 @@ @Bootstrapping public class SkewE implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java index 9e81e1cf5f..c37292d9ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/algorithm/pairwise/Tanh.java @@ -26,7 +26,7 @@ @Bootstrapping public class Tanh implements Algorithm, TakesExternalGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Algorithm algorithm; private Graph externalGraph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java index 75b36da608..35b1aae61e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/Cyclic.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class Cyclic implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public Graph createGraph(Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java index e394d1e783..c3a100b491 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ErdosRenyi.java @@ -13,7 +13,7 @@ * @author josephramsey */ public class ErdosRenyi implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public Graph createGraph(Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java index fa1c7f5a3b..7355ebf7d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomForward.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class RandomForward implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public Graph createGraph(Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java index 59e3c1ef44..b4f722d05f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomSingleFactorMim.java @@ -13,7 +13,7 @@ * @author josephramsey */ public class RandomSingleFactorMim implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public Graph createGraph(Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java index 327c5a99f5..028f2b842b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/RandomTwoFactorMim.java @@ -13,7 +13,7 @@ * @author josephramsey */ public class RandomTwoFactorMim implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public Graph createGraph(Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java index f088762d8b..02782c2796 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/ScaleFree.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class ScaleFree implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public edu.cmu.tetrad.graph.Graph createGraph(Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java index 1ca56b4db5..410d4c1334 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/graph/SingleGraph.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class SingleGraph implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph graph; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java index 74c3d84b6b..5784395b9c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/BdeuTest.java @@ -27,8 +27,14 @@ @Experimental public class BdeuTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Returns the test. + * @param dataSet The data set to test independence against. + * @param parameters The paramters of the test. + * @return Ibid. + */ @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { BdeuScore score = new BdeuScore(SimpleDataLoader.getDiscreteDataSet(dataSet)); @@ -37,16 +43,28 @@ public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { return new ScoreIndTest(score); } + /** + * Returns the description of the test. + * @return Ibid. + */ @Override public String getDescription() { return "BDeu Test"; } + /** + * Returns the data type of the test. + * @return Ibid. + */ @Override public DataType getDataType() { return DataType.Discrete; } + /** + * Returns the parameters of the test. + * @return Ibid. + */ @Override public List getParameters() { List parameters = new ArrayList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java index 6f86748c62..1c65102761 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/CciTest.java @@ -29,7 +29,7 @@ @General public class CciTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java index 3ad303bcd1..d78c8c1147 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ChiSquare.java @@ -24,7 +24,7 @@ ) public class ChiSquare implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java index 843f86aa82..6af96c0ba3 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/ConditionalGaussianLRT.java @@ -26,7 +26,7 @@ @Mixed public class ConditionalGaussianLRT implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java index 4013dc29b6..eb0832257a 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DegenerateGaussianLRT.java @@ -26,7 +26,7 @@ @Mixed public class DegenerateGaussianLRT implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java index 3a7b2585e0..541c279281 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/DiscreteBicTest.java @@ -27,7 +27,7 @@ @Experimental public class DiscreteBicTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java index 2bdc70e6d8..48c0ab7fc3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/FisherZ.java @@ -27,7 +27,7 @@ @LinearGaussian public class FisherZ implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/GICScoreTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/GICScoreTests.java index cc2ff14066..bd02f7529f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/GICScoreTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/GICScoreTests.java @@ -28,7 +28,7 @@ @LinearGaussian public class GICScoreTests implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java index f5e7fb16fd..e1574d1c92 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Gsquare.java @@ -24,7 +24,7 @@ ) public class Gsquare implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java index 7569b58a48..82436d94b0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Kci.java @@ -27,7 +27,7 @@ @General public class Kci implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MSeparationTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MSeparationTest.java index 5c6e47b8ab..3cdee103b6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MSeparationTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MSeparationTest.java @@ -23,7 +23,7 @@ ) public class MSeparationTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph graph; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java index 1d214be873..8cba14f86d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MagSemBicTest.java @@ -28,7 +28,7 @@ @LinearGaussian public class MagSemBicTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java index e9ddb95d1b..ede3ce3b84 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mnlrlrt.java @@ -25,7 +25,7 @@ ) public class Mnlrlrt implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java index 527e82552b..ee1c4e4021 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/MultinomialLogisticRegressionWald.java @@ -22,7 +22,7 @@ //) public class MultinomialLogisticRegressionWald implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java index e093ddacdb..01832f89b8 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/Mvplrt.java @@ -25,7 +25,7 @@ ) public class Mvplrt implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PoissonScoreTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PoissonScoreTest.java index 281e33880d..7133f58047 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PoissonScoreTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PoissonScoreTest.java @@ -28,7 +28,7 @@ @LinearGaussian public class PoissonScoreTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java index 2b3fb51671..55fc7f772f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/PositiveCorr.java @@ -16,7 +16,7 @@ * @author josephramsey */ public class PositiveCorr implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double alpha = 0.001; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java index 3bb971e0ab..dad5a4c6a9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicDTest.java @@ -19,7 +19,7 @@ */ public class SemBicDTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java index e90167ead7..1bd5bd099f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/SemBicTest.java @@ -28,7 +28,7 @@ @LinearGaussian public class SemBicTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/UniformScatterTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/UniformScatterTest.java index f0c6a1501d..1642dc5e4f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/UniformScatterTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/independence/UniformScatterTest.java @@ -26,7 +26,7 @@ @LinearGaussian public class UniformScatterTest implements IndependenceWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public IndependenceTest getTest(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java index 1b94eca0e3..29f8bb3c46 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/BdeuScore.java @@ -23,7 +23,7 @@ ) public class BdeuScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java index 6279c60b0a..77bb987a2c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/CciScore.java @@ -24,7 +24,7 @@ //@Experimental public class CciScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java index 435e70bf81..5d7685eb88 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ConditionalGaussianBicScore.java @@ -26,7 +26,7 @@ @Mixed public class ConditionalGaussianBicScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override 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 f4bde290c6..75ebea601d 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 @@ -47,7 +47,7 @@ @Mixed public class DegenerateGaussianBicScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java index 8042a40496..48247b7016 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/DiscreteBicScore.java @@ -23,7 +23,7 @@ ) public class DiscreteBicScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java index 9586b2631a..3b9e10c94f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/EbicScore.java @@ -26,7 +26,7 @@ @LinearGaussian public class EbicScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java index ce8ddf2e9e..a29d419338 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/FisherZScore.java @@ -25,7 +25,7 @@ //) public class FisherZScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; double alpha = 0.001; private DataModel dataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/GicScores.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/GicScores.java index 73c40283ca..aa169a1ad9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/GicScores.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/GicScores.java @@ -26,7 +26,7 @@ @LinearGaussian public class GicScores implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MSeparationScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MSeparationScore.java index 4f04bb152c..ee4843e24e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MSeparationScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MSeparationScore.java @@ -23,7 +23,7 @@ ) public class MSeparationScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Graph graph; private DataModel dataSet; 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 65a945c942..7684201c5c 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 @@ -26,7 +26,7 @@ ) public class MVPBicScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public Score getScore(DataModel dataSet, Parameters parameters) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java index 8f7291388b..6b04877a2a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/MagSemBicScore.java @@ -24,7 +24,7 @@ ) public class MagSemBicScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java index b11c242321..124039dd0c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PoissonPriorScore.java @@ -26,7 +26,7 @@ @LinearGaussian public class PoissonPriorScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java index 3f57131fd6..86878cf8ef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/PositiveCorrScore.java @@ -18,7 +18,7 @@ * @author josephramsey */ public class PositiveCorrScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; double alpha = 0.001; private DataModel dataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java index 424ae85e72..686dad09ea 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ScoreWrapper.java @@ -50,7 +50,8 @@ public interface ScoreWrapper extends HasParameters, TetradSerializable { /** * Returns the variable with the given name. + * @param name the name. */ Node getVariable(String name); -} +} \ No newline at end of file diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java index 68238561c4..be60ded960 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScore.java @@ -26,7 +26,7 @@ @LinearGaussian public class SemBicScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java index 79c9245c22..83dff20772 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/SemBicScoreDeterministic.java @@ -22,7 +22,7 @@ //) public class SemBicScoreDeterministic implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java index c2f86afd6e..9f6649fa03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/score/ZhangShenBoundScore.java @@ -27,7 +27,7 @@ @LinearGaussian public class ZhangShenBoundScore implements ScoreWrapper { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private DataModel dataSet; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java index fe0f975e02..8347eceea0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BayesNetSimulation.java @@ -7,8 +7,8 @@ import edu.cmu.tetrad.bayes.MlBayesIm; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.util.Parameters; @@ -19,11 +19,13 @@ import java.util.List; /** + * Bayes net simulation. + * * @author josephramsey */ public class BayesNetSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private BayesPm pm; private BayesIm im; @@ -31,15 +33,30 @@ public class BayesNetSimulation implements Simulation { private List graphs = new ArrayList<>(); private List ims = new ArrayList<>(); + /** + * Constructs a new BayesNetSimulation. + * + * @param graph The graph. + */ public BayesNetSimulation(RandomGraph graph) { this.randomGraph = graph; } + /** + * Constructs a new BayesNetSimulation. + * + * @param pm The Bayes PM. + */ public BayesNetSimulation(BayesPm pm) { this.randomGraph = new SingleGraph(pm.getDag()); this.pm = pm; } + /** + * Constructs a new BayesNetSimulation. + * + * @param im The Bayes IM. + */ public BayesNetSimulation(BayesIm im) { this.randomGraph = new SingleGraph(im.getDag()); this.im = im; @@ -48,6 +65,12 @@ public BayesNetSimulation(BayesIm im) { this.ims.add(im); } + /** + * Creates the data. + * + * @param parameters The parameters to use in the simulation. + * @param newModel If true, a new model is created. If false, the model is reused. + */ @Override public void createData(Parameters parameters, boolean newModel) { if (parameters.getLong(Params.SEED) != -1L) { @@ -72,11 +95,12 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = simulate(graph, parameters); if (parameters.getBoolean(Params.RANDOMIZE_COLUMNS)) { - dataSet = DataUtils.shuffleColumns(dataSet); + dataSet = DataTransforms.shuffleColumns(dataSet); } if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); @@ -84,11 +108,23 @@ public void createData(Parameters parameters, boolean newModel) { } } + /** + * Returns the simulated data set. + * + * @param index The index of the desired simulated data set. + * @return Ibid. + */ @Override public DataModel getDataModel(int index) { return this.dataSets.get(index); } + /** + * Returns the true graph. + * + * @param index The index of the desired true graph. + * @return Ibid. + */ @Override public Graph getTrueGraph(int index) { if (this.graphs.isEmpty()) { @@ -98,11 +134,21 @@ public Graph getTrueGraph(int index) { } } + /** + * Returns the description. + * + * @return Ibid. + */ @Override public String getDescription() { return "Bayes net simulation using " + this.randomGraph.getDescription(); } + /** + * Returns the parameters. + * + * @return Ibid. + */ @Override public List getParameters() { List parameters = new ArrayList<>(); @@ -130,16 +176,33 @@ public List getParameters() { return parameters; } + /** + * Returns the number of data sets. + * + * @return Ibid. + */ @Override public int getNumDataModels() { return this.dataSets.size(); } + /** + * Returns the data type. + * + * @return Ibid. + */ @Override public DataType getDataType() { return DataType.Discrete; } + /** + * Simulates a dataset. + * + * @param graph The graph. + * @param parameters The parameters. + * @return Ibid. + */ private DataSet simulate(Graph graph, Parameters parameters) { boolean saveLatentVars = parameters.getBoolean(Params.SAVE_LATENT_VARS); @@ -168,6 +231,10 @@ private DataSet simulate(Graph graph, Parameters parameters) { } } + /** + * Returns the list of Bayes IMs. + * @return Ibid. + */ public List getBayesIms() { return this.ims; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java index 044737fb4e..6524f67bcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/BooleanGlassSimulation.java @@ -25,7 +25,7 @@ */ @Experimental public class BooleanGlassSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List dataSets = new ArrayList<>(); private Graph graph = new EdgeListGraph(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java index e488dffc24..6f1ec1107d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/ConditionalGaussianSimulation.java @@ -22,7 +22,7 @@ */ public class ConditionalGaussianSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List dataSets = new ArrayList<>(); private List graphs = new ArrayList<>(); @@ -120,11 +120,12 @@ public void createData(Parameters parameters, boolean newModel) { dataSet.setName("" + (i + 1)); if (parameters.getBoolean(Params.RANDOMIZE_COLUMNS)) { - dataSet = DataUtils.shuffleColumns(dataSet); + dataSet = DataTransforms.shuffleColumns(dataSet); } if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } this.dataSets.add(dataSet); @@ -368,7 +369,7 @@ private DataSet simulate(Graph G, Parameters parameters) { } boolean saveLatentVars = parameters.getBoolean(Params.SAVE_LATENT_VARS); - return saveLatentVars ? mixedData : DataUtils.restrictToMeasured(mixedData); + return saveLatentVars ? mixedData : DataTransforms.restrictToMeasured(mixedData); } private double[] getBreakpoints(DataSet mixedData, DiscreteVariable _parent, int mixedParentColumn) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java index 4d7be5585c..c33bd2d0ff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulation.java @@ -2,10 +2,7 @@ import edu.cmu.tetrad.algcomparison.graph.RandomGraph; import edu.cmu.tetrad.algcomparison.graph.SingleGraph; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.SemGraph; @@ -22,10 +19,12 @@ import java.util.List; /** + * General SEM simulation. + * * @author josephramsey */ public class GeneralSemSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private GeneralizedSemPm pm; private GeneralizedSemIm im; @@ -78,7 +77,7 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = simulate(graph, parameters); if (parameters.getBoolean(Params.STANDARDIZE)) { - dataSet = DataUtils.standardizeData(dataSet); + dataSet = DataTransforms.standardizeData(dataSet); } double variance = parameters.getDouble(Params.MEASUREMENT_VARIANCE); @@ -94,15 +93,16 @@ public void createData(Parameters parameters, boolean newModel) { } if (parameters.getBoolean(Params.RANDOMIZE_COLUMNS)) { - dataSet = DataUtils.shuffleColumns(dataSet); + dataSet = DataTransforms.shuffleColumns(dataSet); } if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); - this.dataSets.add(DataUtils.restrictToMeasured(dataSet)); + this.dataSets.add(DataTransforms.restrictToMeasured(dataSet)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java index d7bf74fe50..b2801cc127 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/GeneralSemSimulationSpecial1.java @@ -1,10 +1,7 @@ package edu.cmu.tetrad.algcomparison.simulation; import edu.cmu.tetrad.algcomparison.graph.RandomGraph; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.NodeType; @@ -26,7 +23,7 @@ * @author josephramsey */ public class GeneralSemSimulationSpecial1 implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List graphs = new ArrayList<>(); private List dataSets = new ArrayList<>(); @@ -59,7 +56,8 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = simulate(graph, parameters); if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java index 87672a093e..d20aaf89c1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LeeHastieSimulation.java @@ -1,10 +1,7 @@ package edu.cmu.tetrad.algcomparison.simulation; import edu.cmu.tetrad.algcomparison.graph.RandomGraph; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.sem.GeneralizedSemIm; @@ -25,7 +22,7 @@ */ public class LeeHastieSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List dataSets = new ArrayList<>(); private List graphs = new ArrayList<>(); @@ -80,11 +77,12 @@ public void createData(Parameters parameters, boolean newModel) { dataSet.setName("" + (i + 1)); if (parameters.getBoolean(Params.RANDOMIZE_COLUMNS)) { - dataSet = DataUtils.shuffleColumns(dataSet); + dataSet = DataTransforms.shuffleColumns(dataSet); } if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } this.dataSets.add(dataSet); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java index 4426b8b1e5..f896c17611 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearFisherModel.java @@ -2,10 +2,7 @@ import edu.cmu.tetrad.algcomparison.graph.RandomGraph; import edu.cmu.tetrad.algcomparison.utils.TakesData; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; @@ -20,11 +17,13 @@ import java.util.List; /** + * Linear Fisher Model. + * * @author josephramsey */ public class LinearFisherModel implements Simulation, TakesData { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private final List shocks; private List dataSets = new ArrayList<>(); @@ -144,18 +143,19 @@ public void createData(Parameters parameters, boolean newModel) { dataSet.setName("" + (i + 1)); if (parameters.getBoolean(Params.STANDARDIZE)) { - dataSet = DataUtils.standardizeData(dataSet); + dataSet = DataTransforms.standardizeData(dataSet); } if (parameters.getBoolean(Params.RANDOMIZE_COLUMNS)) { - dataSet = DataUtils.shuffleColumns(dataSet); + dataSet = DataTransforms.shuffleColumns(dataSet); } if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } - this.dataSets.add(saveLatentVars ? dataSet : DataUtils.restrictToMeasured(dataSet)); + this.dataSets.add(saveLatentVars ? dataSet : DataTransforms.restrictToMeasured(dataSet)); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearSineSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearSineSimulation.java index 2bcb1e94c9..b0cf5836d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearSineSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/LinearSineSimulation.java @@ -21,7 +21,7 @@ */ @Experimental public class LinearSineSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List dataSets = new ArrayList<>(); private List graphs = new ArrayList<>(); @@ -106,7 +106,8 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = simulate(graph, parameters); if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/NLSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/NLSemSimulation.java index 6367b7cd6e..ae8e1a97f8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/NLSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/NLSemSimulation.java @@ -22,11 +22,13 @@ import static org.apache.commons.math3.util.FastMath.*; /** + * NL SEM simulation. + * * @author bryanandrews */ public class NLSemSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List dataSets = new ArrayList<>(); private List graphs = new ArrayList<>(); @@ -160,7 +162,7 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = new BoxDataSet(new DoubleDataBox(data.getData()), continuousVars); if (parameters.getBoolean(Params.RANDOMIZE_COLUMNS)) { - dataSet = DataUtils.shuffleColumns(dataSet); + dataSet = DataTransforms.shuffleColumns(dataSet); } dataSet.setName(String.valueOf(i + 1)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java index 86ebe5cdb5..989dfd72f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemSimulation.java @@ -2,10 +2,7 @@ import edu.cmu.tetrad.algcomparison.graph.RandomGraph; import edu.cmu.tetrad.algcomparison.graph.SingleGraph; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.SemGraph; @@ -20,17 +17,20 @@ import java.util.List; /** + * SEM simulation. + * * @author josephramsey */ public class SemSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private SemPm pm; private SemIm im; private List dataSets = new ArrayList<>(); private List graphs = new ArrayList<>(); private List ims = new ArrayList<>(); + private long seed = -1L; public SemSimulation(RandomGraph graph) { this.randomGraph = graph; @@ -78,7 +78,7 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = simulate(graph, parameters); if (parameters.getBoolean(Params.STANDARDIZE)) { - dataSet = DataUtils.standardizeData(dataSet); + dataSet = DataTransforms.standardizeData(dataSet); } double variance = parameters.getDouble(Params.MEASUREMENT_VARIANCE); @@ -94,11 +94,12 @@ public void createData(Parameters parameters, boolean newModel) { } if (parameters.getBoolean(Params.RANDOMIZE_COLUMNS)) { - dataSet = DataUtils.shuffleColumns(dataSet); + dataSet = DataTransforms.shuffleColumns(dataSet); } if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); @@ -163,25 +164,37 @@ private DataSet simulate(Graph graph, Parameters parameters) { boolean saveLatentVars = parameters.getBoolean(Params.SAVE_LATENT_VARS); SemPm pm = this.pm; + SemIm im = this.im; if (pm == null) { pm = new SemPm(graph); + this.pm = pm; } - // Aargh, need to go through the motions of initializing the SEM IM each time so that if a - // random seed is set, the random number methods on RandomUtil will have been called the - // same number of times in the deterministic pseudorandom sequence. But we only want - // to keep the first one of these, because we want the IM for this SemSimulation object - // to be constant. Grr. And we have to do it this way because the parameters are needed to - // initialize the SEM IM but are only passed in this method and not available in the - // constructor. :-( So don't change this code!!! Please!!! -JR 2023/02/04 - SemIm im = new SemIm(pm, parameters); + // If an im is already available, then we should use that im without creating new + // random parameter values.-JR 20231005 + long seed = parameters.getLong(Params.SEED); - // Not setting this im messes up algcomparison. -JR 20230206 + if (im != null) { -// if (this.im == null) { - this.im = im; -// } + // If the seed is set and has not changed, then we should call RandomUtil + // methods the same number of times as we would have if we had created a new im. + if (seed != -1 && seed == this.seed) { + for (int i = 0; i < this.im.getNumRandomCalls(); i++) { + RandomUtil.getInstance().nextNormal(0, 1); + } + } + + this.im = im; + } else { + + // Otherwise, we should create a new im with new random parameter values. + // -JR 20231005 + im = new SemIm(pm, parameters); + this.im = im; + } + + this.seed = seed; // Need this in case the SEM IM is given externally. this.im.setParams(parameters); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java index 518fb5a041..e2bf648fbe 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/SemThenDiscretize.java @@ -14,10 +14,12 @@ import java.util.List; /** + * SEM the discretize. + * * @author josephramsey */ public class SemThenDiscretize implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List graphs = new ArrayList<>(); private List dataSets = new ArrayList<>(); @@ -74,7 +76,8 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = simulate(graph, parameters); if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java index 70b9633214..e668d5595f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulation.java @@ -19,37 +19,46 @@ public interface Simulation extends HasParameters, TetradSerializable { /** * Creates a data set and simulates data. + * + * @param parameters The parameters to use in the simulation. + * @param newModel If true, a new model is created. If false, the model is reused. */ void createData(Parameters parameters, boolean newModel); /** + * Returns the number of data models. * @return The number of data sets to simulate. */ int getNumDataModels(); /** + * Returns the true graph at the given index. * @param index The index of the desired true graph. * @return That graph. */ Graph getTrueGraph(int index); /** + * Returns the number of data sets to simulate. * @param index The index of the desired simulated data set. * @return That data set. */ DataModel getDataModel(int index); /** + * Returns the data type of the data. * @return Returns the type of the data, continuous, discrete or mixed. */ DataType getDataType(); /** + * Returns the description of the simulation. * @return Returns a one-line description of the simulation, to be printed at the beginning of the report. */ String getDescription(); /** + * Returns the list of parameters used in the simulation. * @return Returns the parameters used in the simulation. These are the parameters whose values can be varied. */ List getParameters(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java index 55d55fef28..69d7eb5270 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/Simulations.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class Simulations { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final List simulations = new ArrayList<>(); public Simulations() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java index 1b3f7e414c..dcf2f7f114 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/StandardizedSemSimulation.java @@ -2,10 +2,7 @@ import edu.cmu.tetrad.algcomparison.graph.RandomGraph; import edu.cmu.tetrad.algcomparison.graph.SingleGraph; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataType; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.SemGraph; import edu.cmu.tetrad.sem.SemIm; @@ -19,10 +16,12 @@ import java.util.List; /** + * Standardized SEM simulation. + * * @author josephramsey */ public class StandardizedSemSimulation implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private SemPm pm; private StandardizedSemIm standardizedIm; @@ -69,7 +68,8 @@ public void createData(Parameters parameters, boolean newModel) { DataSet dataSet = simulate(graph, parameters); if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java index fb96555583..9c3fb1f515 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/simulation/TimeSeriesSemSimulation.java @@ -18,12 +18,14 @@ import java.util.List; /** + * Time series SEM simulation. + * * @author josephramsey * @author danielmalinsky */ public class TimeSeriesSemSimulation implements Simulation, HasKnowledge { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private List graphs = new ArrayList<>(); private List dataSets = new ArrayList<>(); @@ -104,7 +106,8 @@ public void createData(Parameters parameters, boolean newModel) { dataSet = TsUtils.createLagData(dataSet, numLags); if (parameters.getDouble(Params.PROB_REMOVE_COLUMN) > 0) { - dataSet = DataUtils.removeRandomColumns(dataSet, parameters.getDouble(Params.PROB_REMOVE_COLUMN)); + double aDouble = parameters.getDouble(Params.PROB_REMOVE_COLUMN); + dataSet = DataTransforms.removeRandomColumns(dataSet, aDouble); } dataSet.setName("" + (i + 1)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java index 0cdd77a993..4e7c3534f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFn.java @@ -10,24 +10,56 @@ * @author josephramsey */ public class AdjacencyFn implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AdjacencyFn() { + } + + /** + * Returns the name of the statistic. + * + * @return The name. + */ @Override public String getAbbreviation() { return "AFN"; } + /** + * Returns the description of the statistic. + * + * @return The description. + */ @Override public String getDescription() { return "Adjacency False Negatives"; } + /** + * Returns the value of the statistic, given the true graph and the estimated graph. + * + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return The value of the statistic. + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { AdjacencyConfusion adjConfusion = new AdjacencyConfusion(trueGraph, estGraph); return adjConfusion.getFn(); } + /** + * Returns a mapping of the statistic to the interval [0, 1], with higher being better. This is used for a + * calculation of a utility for an algorithm.If the statistic is already between 0 and 1, you can just return the + * statistic. + * + * @param value The value of the statistic. + * @return The weight of the statistic, 0 to 1, higher is better. + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java index 5add8a4a7e..10b0b31743 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFp.java @@ -10,7 +10,13 @@ * @author josephramsey */ public class AdjacencyFp implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public AdjacencyFp() { + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java index dbca534bee..3eff148582 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyFpr.java @@ -11,18 +11,40 @@ * @author josephramsey */ public class AdjacencyFpr implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AdjacencyFpr() { + + } + + /** + * Returns the name of the statistic. + * @return The name. + */ @Override public String getAbbreviation() { return "AFPR"; } + /** + * Returns the description of the statistic. + * @return The description. + */ @Override public String getDescription() { return "Adjacency False Positive Rate"; } + /** + * Returns the value of the statistic, given the true graph and the estimated graph. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return The value of the statistic. + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { AdjacencyConfusion adjConfusion = new AdjacencyConfusion(trueGraph, estGraph); @@ -31,6 +53,11 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { return adjFp / (double) (adjFp + adjTn); } + /** + * Returns a mapping of the statistic to the interval [0, 1], with higher being better. This is used for a + * @param value The value of the statistic. + * @return The normalized value. + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java index 3fd5fc7081..c023bb5262 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyPrecision.java @@ -10,7 +10,15 @@ * @author josephramsey */ public class AdjacencyPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public AdjacencyPrecision() { + + } + @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java index 5e31c4f62f..19814ecd89 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyRecall.java @@ -10,7 +10,14 @@ * @author josephramsey */ public class AdjacencyRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public AdjacencyRecall() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java index b56a262042..14482c4b0f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTn.java @@ -10,24 +10,51 @@ * @author josephramsey */ public class AdjacencyTn implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AdjacencyTn() { + + } + + /** + * Returns the name of the statistic. + * @return The name. + */ @Override public String getAbbreviation() { return "ATN"; } + /** + * Returns the description of the statistic. + * @return The description. + */ @Override public String getDescription() { return "Adjacency True Negatives"; } + /** + * Returns the value of the statistic, given the true graph and the estimated graph. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return The value of the statistic. + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { AdjacencyConfusion adjConfusion = new AdjacencyConfusion(trueGraph, estGraph); return adjConfusion.getTn(); } + /** + * Returns a mapping of the statistic to the interval [0, 1], with higher being better. This is used for a + * @param value The value of the statistic. + * @return The normalized value. + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java index 62bdea4406..f91cd5aaa8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTp.java @@ -10,24 +10,51 @@ * @author josephramsey */ public class AdjacencyTp implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AdjacencyTp() { + + } + + /** + * Returns the name of the statistic. + * @return The name. + */ @Override public String getAbbreviation() { return "ATP"; } + /** + * Returns the description of the statistic. + * @return The description. + */ @Override public String getDescription() { return "Adjacency True Positives"; } + /** + * Returns the value of the statistic, given the true graph and the estimated graph. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return The value of the statistic. + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { AdjacencyConfusion adjConfusion = new AdjacencyConfusion(trueGraph, estGraph); return adjConfusion.getTp(); } + /** + * Returns a mapping of the statistic to the interval [0, 1], with higher being better. This is used for a + * @param value The value of the statistic. + * @return The normalized value. + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java index e395aa6d8b..01daf84a61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AdjacencyTpr.java @@ -11,18 +11,40 @@ * @author josephramsey */ public class AdjacencyTpr implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AdjacencyTpr() { + + } + + /** + * Returns the name of the statistic. + * @return The name. + */ @Override public String getAbbreviation() { return "ATPR"; } + /** + * Returns the description of the statistic. + * @return The description. + */ @Override public String getDescription() { return "Adjacency True Positive Rate"; } + /** + * Returns the value of the statistic, given the true graph and the estimated graph. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return The value of the statistic. + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { AdjacencyConfusion adjConfusion = new AdjacencyConfusion(trueGraph, estGraph); @@ -32,6 +54,11 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { return adjTp / (double) (adjTp + adjFn); } + /** + * Returns a mapping of the statistic to the interval [0, 1], with higher being better. This is used for a + * @param value The value of the statistic. + * @return The normalized value. + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorF1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorF1.java index 70dfe4112e..74f8f640f0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorF1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorF1.java @@ -13,18 +13,40 @@ * @author Joseh Ramsey */ public class AncestorF1 implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AncestorF1() { + + } + + /** + * Returns the name of the statistic. + * @return the name of the statistic + */ @Override public String getAbbreviation() { return "Ancestor-F1"; } + /** + * Returns the name of the statistic. + * @return the name of the statistic + */ @Override public String getDescription() { return "F1 statistic for ancestry comparing the estimated graph to the true graph"; } + /** + * Calculates the F1 statistic for adjacencies. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return the F1 statistic for adjacencies + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { double precision = new AncestorPrecision().getValue(trueGraph, estGraph, dataModel); @@ -32,6 +54,11 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { return 2 * (precision * recall) / (precision + recall); } + /** + * Returns the norm value of the statistic. + * @param value The value of the statistic. + * @return the value of the statistic + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java index 3c1f4f39a7..1c5e024e31 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorPrecision.java @@ -7,21 +7,45 @@ import java.util.List; /** + * Ancestor precision. + * * @author josephramsey */ public class AncestorPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AncestorPrecision() { + + } + + /** + * Returns the name of the statistic. + * @return the name of the statistic + */ @Override public String getAbbreviation() { return "Anc-Prec"; } + /** + * Returns the description of the statistic. + * @return the description of the statistic + */ @Override public String getDescription() { return "Proportion of X~~>Y in the estimated graph for which also X~~>Y in true graph"; } + /** + * Calculates the statistic. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return the statistic + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0; @@ -45,6 +69,11 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { return tp / (double) (tp + fp); } + /** + * Returns the norm value of the statistic. + * @param value The norm value of the statistic. + * @return the norm value of the statistic + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java index 2e1c9d7554..1e44168657 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestorRecall.java @@ -7,21 +7,45 @@ import java.util.List; /** + * Ancestor recall. + * * @author josephramsey */ public class AncestorRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AncestorRecall() { + + } + + /** + * Returns the name of the statistic. + * @return the name of the statistic + */ @Override public String getAbbreviation() { return "Anc-Rec"; } + /** + * Returns the description of the statistic. + * @return the description of the statistic + */ @Override public String getDescription() { return "Proportion of X~~>Y in the true graph for which also X~~>Y in estimated graph"; } + /** + * Calculates the statistic. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return the statistic + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0; @@ -45,6 +69,11 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { return tp / (double) (tp + fn); } + /** + * Returns the norm value of the statistic. + * @param value The value of the statistic. + * @return the value of the statistic + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java index 1a29a936c3..a5847ecec2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralPrecision.java @@ -12,18 +12,40 @@ * @author josephramsey */ public class AncestralPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AncestralPrecision() { + + } + + /** + * Returns the name of the statistic. + * @return the name of the statistic + */ @Override public String getAbbreviation() { return "AncP"; } + /** + * Returns the description of the statistic. + * @return the description of the statistic + */ @Override public String getDescription() { return "Proportion of X~~>Y for which X~~>Y in true"; } + /** + * Calculates the statistic. + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return the statistic + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fp = 0; @@ -47,6 +69,11 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { return tp / (double) (tp + fp); } + /** + * Returns the norm value of the statistic. + * @param value The value of the statistic. + * @return the value of the statistic + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java index bd5361c5a8..7647f891cd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AncestralRecall.java @@ -12,18 +12,43 @@ * @author josephramsey */ public class AncestralRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * Constructs the statistic. + */ + public AncestralRecall() { + + } + + /** + * Returns the name of the statistic. + * + * @return the name of the statistic + */ @Override public String getAbbreviation() { return "AncR"; } + /** + * Returns the description of the statistic. + * + * @return the description of the statistic + */ @Override public String getDescription() { return "Proportion of X~~>Y in true for which X~~>Y in est"; } + /** + * Calculates the statistic. + * + * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). + * @param estGraph The estimated graph (same type). + * @param dataModel The data model. + * @return the statistic + */ @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fn = 0; @@ -47,6 +72,12 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { return tp / (double) (tp + fn); } + /** + * Returns the norm value of the statistic. + * + * @param value The value of the statistic. + * @return the norm value. + */ @Override public double getNormValue(double value) { return value; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java index a4915d8ae3..1f3349c978 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFn.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadFn implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadFn() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java index 4808918736..1c369ab90f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFp.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadFp implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadFp() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java index 3c5fc2a5a2..b4655de155 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadFpr.java @@ -11,7 +11,14 @@ * @author josephramsey */ public class ArrowheadFpr implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadFpr() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java index c13a75f6e0..006b969ef6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecision.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadPrecision() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java index 7e867b996b..9cbf2c7a93 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadPrecisionCommonEdges.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadPrecisionCommonEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadPrecisionCommonEdges() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java index 0783c6adeb..25c3004c0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecall.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadRecall() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java index 65a0ddcd41..f2a7ca80fd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadRecallCommonEdges.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadRecallCommonEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadRecallCommonEdges() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java index d8d8b96632..805f4069bc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTn.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadTn implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadTn() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java index 3e56ae318e..49519c7153 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ArrowheadTp.java @@ -13,7 +13,14 @@ * @author josephramsey */ public class ArrowheadTp implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public ArrowheadTp() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java index 473a51f937..d78c0ed8a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeEst.java @@ -9,7 +9,14 @@ * @author josephramsey */ public class AverageDegreeEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public AverageDegreeEst() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java index e7174c7eb2..0c23655dcc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/AverageDegreeTrue.java @@ -9,7 +9,14 @@ * @author josephramsey */ public class AverageDegreeTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + + /** + * Constructs the statistic. + */ + public AverageDegreeTrue() { + + } @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java index ce10c5a589..83241bb266 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiff.java @@ -2,8 +2,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.score.SemBicScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static org.apache.commons.math3.util.FastMath.tanh; @@ -13,7 +13,7 @@ * @author josephramsey */ public class BicDiff implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private boolean precomputeCovariances = true; @Override @@ -28,8 +28,8 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - double _true = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(trueGraph), dataModel, precomputeCovariances); - double est = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(estGraph), dataModel, precomputeCovariances); + double _true = SemBicScorer.scoreDag(GraphTransforms.dagFromCPDAG(trueGraph, null), dataModel, precomputeCovariances); + double est = SemBicScorer.scoreDag(GraphTransforms.dagFromCPDAG(estGraph, null), dataModel, precomputeCovariances); return (_true - est); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java index 8228879a73..c98412966e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicDiffPerRecord.java @@ -3,8 +3,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.score.SemBicScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static org.apache.commons.math3.util.FastMath.abs; import static org.apache.commons.math3.util.FastMath.tanh; @@ -15,7 +15,7 @@ * @author josephramsey */ public class BicDiffPerRecord implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private boolean precomputeCovariances = true; @Override @@ -31,8 +31,8 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - double _true = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(trueGraph), dataModel, precomputeCovariances); - double est = SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(estGraph), dataModel, precomputeCovariances); + double _true = SemBicScorer.scoreDag(GraphTransforms.dagFromCPDAG(trueGraph, null), dataModel, precomputeCovariances); + double est = SemBicScorer.scoreDag(GraphTransforms.dagFromCPDAG(estGraph, null), dataModel, precomputeCovariances); if (abs(_true) < 0.0001) _true = 0.0; if (abs(est) < 0.0001) est = 0.0; return (_true - est) / ((DataSet) dataModel).getNumRows(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java index 139a32ff8f..2fc7024067 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicEst.java @@ -2,8 +2,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.score.SemBicScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static org.apache.commons.math3.util.FastMath.tanh; @@ -13,7 +13,7 @@ * @author josephramsey */ public class BicEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double penaltyDiscount = 1.0; private boolean precomputeCovariances = true; @@ -38,7 +38,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { // double _true = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(trueGraph), dataModel); - return SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(estGraph), dataModel, precomputeCovariances); + return SemBicScorer.scoreDag(GraphTransforms.dagFromCPDAG(estGraph, null), dataModel, precomputeCovariances); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java index 9310641b5d..c41e272e5e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BicTrue.java @@ -2,8 +2,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.score.SemBicScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static org.apache.commons.math3.util.FastMath.tanh; @@ -13,7 +13,7 @@ * @author josephramsey */ public class BicTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private boolean precomputeCovariances = true; @Override @@ -29,7 +29,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { // double est = SemBicScorer.scoreDag(SearchGraphUtils.dagFromCPDAG(estGraph), dataModel); - return SemBicScorer.scoreDag(GraphSearchUtils.dagFromCPDAG(trueGraph), dataModel, precomputeCovariances); + return SemBicScorer.scoreDag(GraphTransforms.dagFromCPDAG(trueGraph, null), dataModel, precomputeCovariances); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java index d80d173ec6..32af4ed267 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedEst.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class BidirectedEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java index 45f7fada34..9708d7d548 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedFP.java @@ -3,8 +3,7 @@ import edu.cmu.tetrad.algcomparison.statistic.utils.BidirectedConfusion; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; - -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; +import edu.cmu.tetrad.graph.GraphTransforms; /** * The bidirected false negatives. @@ -12,7 +11,7 @@ * @author josephramsey */ public class BidirectedFP implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -26,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); BidirectedConfusion confusion = new BidirectedConfusion(pag, estGraph); return confusion.getFp(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java index c540c1b23a..d33216e411 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedLatentPrecision.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class BidirectedLatentPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java index 4ce4d4789f..2623357dd8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedPrecision.java @@ -4,8 +4,7 @@ import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; - -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; +import edu.cmu.tetrad.graph.GraphTransforms; /** * The bidirected edge precision. @@ -13,7 +12,7 @@ * @author josephramsey */ public class BidirectedPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -27,7 +26,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java index e551513687..1a65c95947 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedRecall.java @@ -4,8 +4,7 @@ import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; - -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; +import edu.cmu.tetrad.graph.GraphTransforms; /** * The bidirected edge precision. @@ -13,7 +12,7 @@ * @author josephramsey */ public class BidirectedRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -27,7 +26,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fn = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java index 7c0bc14b6b..c02ebe47e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTP.java @@ -3,8 +3,7 @@ import edu.cmu.tetrad.algcomparison.statistic.utils.BidirectedConfusion; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; - -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; +import edu.cmu.tetrad.graph.GraphTransforms; /** * The bidirected true positives. @@ -12,7 +11,7 @@ * @author josephramsey */ public class BidirectedTP implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -26,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); BidirectedConfusion confusion = new BidirectedConfusion(pag, estGraph); return confusion.getTp(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java index d4e2a1cc44..4e8012997b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/BidirectedTrue.java @@ -4,8 +4,7 @@ import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Edges; import edu.cmu.tetrad.graph.Graph; - -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; +import edu.cmu.tetrad.graph.GraphTransforms; /** * The bidirected true positives. @@ -13,7 +12,7 @@ * @author josephramsey */ public class BidirectedTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -27,7 +26,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int t = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java index 4bc51d0e5f..7b1b1caa2b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,6 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.CommonAncestorTruePositiveBidirected.existsCommonAncestor; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected true positives. @@ -14,7 +13,7 @@ * @author josephramsey */ public class CommonAncestorFalseNegativeBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -28,7 +27,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int fn = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java index e64f36df59..caf5082547 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorFalsePositiveBidirected.java @@ -13,7 +13,7 @@ * @author josephramsey */ public class CommonAncestorFalsePositiveBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java index a94a6aee4e..e9c5e15941 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonAncestorTruePositiveBidirected.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class CommonAncestorTruePositiveBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public static boolean existsCommonAncestor(Graph trueGraph, Edge edge) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java index 00b423678b..add6f73dd8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CommonMeasuredAncestorRecallBidirected.java @@ -17,7 +17,7 @@ * @author josephramsey */ public class CommonMeasuredAncestorRecallBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java index 5608b676cc..f9afb5cdcf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/CorrectSkeleton.java @@ -10,7 +10,7 @@ * @author josephramsey */ public class CorrectSkeleton implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java index bd3f9d20ad..08821f37c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathPrecision.java @@ -1,11 +1,7 @@ package edu.cmu.tetrad.algcomparison.statistic; import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.*; import java.util.List; @@ -15,7 +11,7 @@ * @author josephramsey */ public class DefiniteDirectedPathPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -32,7 +28,7 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fp = 0; List nodes = trueGraph.getNodes(); - Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphTransforms.cpdagForDag(trueGraph); GraphUtils.addPagColoring(estGraph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java index 44e5db0301..da95bd1663 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DefiniteDirectedPathRecall.java @@ -2,8 +2,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -13,7 +13,7 @@ * @author josephramsey */ public class DefiniteDirectedPathRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -30,7 +30,7 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fn = 0; List nodes = trueGraph.getNodes(); - Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphTransforms.cpdagForDag(trueGraph); for (Node x : nodes) { for (Node y : nodes) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java index 20a16cb437..b2b62fe595 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityEst.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class DensityEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java index 0a5736186d..809e1a01e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/DensityTrue.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class DensityTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java index bfa8ac753b..07b70b2511 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ElapsedCpuTime.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class ElapsedCpuTime implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Adj.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Adj.java index 186b2169ce..96545c8a9f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Adj.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Adj.java @@ -14,7 +14,7 @@ * @author Joseh Ramsey */ public class F1Adj implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1All.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1All.java index 6e640e7a82..1ea8fbc5a4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1All.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1All.java @@ -15,7 +15,7 @@ * @author Joseh Ramsey */ public class F1All implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Arrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Arrow.java index 90970180e2..02c37f55d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Arrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/F1Arrow.java @@ -16,7 +16,7 @@ * @author Joseh Ramsey */ public class F1Arrow implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java index f6c9e0b2b9..1a147e7434 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalseNegativesAdjacencies.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class FalseNegativesAdjacencies implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java index e6204327d9..26c268e357 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FalsePositiveAdjacencies.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class FalsePositiveAdjacencies implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderAlternative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderAlternative.java index e101f93fef..176e4b0201 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderAlternative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderAlternative.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class FractionDependentUnderAlternative implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double alpha = 0.01; public FractionDependentUnderAlternative() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderNull.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderNull.java index 52be1e03a1..70f9299e1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderNull.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/FractionDependentUnderNull.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class FractionDependentUnderNull implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double alpha = 0.01; public FractionDependentUnderNull() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java index 83d74ec393..f601dcdead 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/GraphExactlyRight.java @@ -10,7 +10,7 @@ * @author josephramsey */ public class GraphExactlyRight implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java index 5e0ced6ef6..c17ec93be5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalseNegativeBidirected.java @@ -6,7 +6,6 @@ import java.util.List; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; /** * The bidirected true positives. @@ -14,7 +13,7 @@ * @author josephramsey */ public class LatentCommonAncestorFalseNegativeBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -28,7 +27,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int fn = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java index 2c178a3e85..919413b771 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorFalsePositiveBidirected.java @@ -13,7 +13,7 @@ * @author josephramsey */ public class LatentCommonAncestorFalsePositiveBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java index f9cc5aa0d1..1ad5467c1a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorRecallBidirected.java @@ -16,7 +16,7 @@ * @author josephramseyHow */ public class LatentCommonAncestorRecallBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java index 178450e7de..4f1b6d4ea3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LatentCommonAncestorTruePositiveBidirected.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class LatentCommonAncestorTruePositiveBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public static boolean existsLatentCommonAncestor(Graph trueGraph, Edge edge) { List nodes = trueGraph.paths().getAncestors(Collections.singletonList(edge.getNode1())); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java index 3394b87327..cb169eb8f7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/LegalPag.java @@ -10,7 +10,7 @@ * @author josephramsey */ public class LegalPag implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MarkovAdequacyScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MarkovAdequacyScore.java index 660ad3ad60..6833b6f6e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MarkovAdequacyScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MarkovAdequacyScore.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class MarkovAdequacyScore implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double alpha = 0.05; @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java index 8f3478fd3a..28555b4b3b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrAdj.java @@ -15,7 +15,7 @@ * @author josephramsey */ public class MathewsCorrAdj implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java index 583cf1b710..2b1af94c4f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MathewsCorrArrow.java @@ -18,7 +18,7 @@ * @author josephramsey */ public class MathewsCorrArrow implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java index d294c17b4a..70ff7e7fdc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/MaximalityCondition.java @@ -2,16 +2,18 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; /** + * MaximalMag statistic. + * * @author josephramsey */ public class MaximalityCondition implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -27,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { Graph pag = estGraph; - Graph mag = GraphSearchUtils.pagToMag(estGraph); + Graph mag = GraphTransforms.pagToMag(estGraph); List nodes = pag.getNodes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java index c527f0a55e..2b06f225ed 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsCondition.java @@ -7,10 +7,12 @@ import edu.cmu.tetrad.graph.Node; /** + * No almost cyclic paths condition. + * * @author josephramsey */ public class NoAlmostCyclicPathsCondition implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java index 30bc869919..26796214a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoAlmostCyclicPathsInMagCondition.java @@ -1,17 +1,15 @@ package edu.cmu.tetrad.algcomparison.statistic; import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.Edges; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.*; /** + * No almost cyclic paths condition in MAG. + * * @author josephramsey */ public class NoAlmostCyclicPathsInMagCondition implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -25,7 +23,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph mag = GraphSearchUtils.pagToMag(estGraph); + Graph mag = GraphTransforms.pagToMag(estGraph); for (Edge e : mag.getEdges()) { Node x = e.getNode1(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java index 635e89c9aa..b5d4abcc8f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsCondition.java @@ -5,10 +5,12 @@ import edu.cmu.tetrad.graph.Node; /** + * No cyclic paths condition. + * * @author josephramsey */ public class NoCyclicPathsCondition implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java index 086956faae..4ee4ee7335 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoCyclicPathsInMagCondition.java @@ -2,14 +2,16 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** + * No cyclic paths condition. + * * @author josephramsey */ public class NoCyclicPathsInMagCondition implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -23,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph mag = GraphSearchUtils.pagToMag(estGraph); + Graph mag = GraphTransforms.pagToMag(estGraph); for (Node n : mag.getNodes()) { if (mag.paths().existsDirectedPathFromTo(n, n)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedF1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedF1.java index 7d4df2bed3..df2b4102bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedF1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedF1.java @@ -13,7 +13,7 @@ * @author Joseh Ramsey */ public class NoSemidirectedF1 implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java index 511701e73f..e2a92db0b0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedPrecision.java @@ -2,8 +2,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -13,7 +13,7 @@ * @author josephramsey */ public class NoSemidirectedPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fp = 0; - Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphTransforms.cpdagForDag(trueGraph); List nodes = estGraph.getNodes(); @@ -37,8 +37,8 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { for (Node y : nodes) { if (x == y) continue; - if (!estGraph.paths().existsSemiDirectedPathFromTo(x, y)) { - if (!cpdag.paths().existsSemiDirectedPathFromTo(x, y)) { + if (!estGraph.paths().existsSemiDirectedPath(x, y)) { + if (!cpdag.paths().existsSemiDirectedPath(x, y)) { tp++; } else { fp++; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java index 5d79af132d..7f1ae718d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NoSemidirectedRecall.java @@ -2,8 +2,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.List; @@ -13,7 +13,7 @@ * @author josephramsey */ public class NoSemidirectedRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -29,7 +29,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0, fn = 0; - Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphTransforms.cpdagForDag(trueGraph); List nodes = trueGraph.getNodes(); @@ -37,8 +37,8 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { for (Node y : nodes) { if (x == y) continue; - if (!cpdag.paths().existsSemiDirectedPathFromTo(x, y)) { - if (!estGraph.paths().existsSemiDirectedPathFromTo(x, y)) { + if (!cpdag.paths().existsSemiDirectedPath(x, y)) { + if (!estGraph.paths().existsSemiDirectedPath(x, y)) { tp++; } else { fn++; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java index a96b055155..9faad43d13 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesPrecision.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class NodesInCyclesPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java index 88c2407b85..03b05bc50c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NodesInCyclesRecall.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class NodesInCyclesRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java index ac8f9f7c93..46e8c85b26 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorPrecision.java @@ -7,10 +7,12 @@ import java.util.List; /** + * Number of NOT X~~>Y in true graph for which also NOT X~~>Y in estimated graph. + * * @author josephramsey */ public class NonancestorPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java index 5ed3f7920f..956b3a8eb5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NonancestorRecall.java @@ -7,10 +7,12 @@ import java.util.List; /** + * Number of NOT X~~>Y in true graph for which also NOT X~~>Y in estimated graph. + * * @author josephramsey */ public class NonancestorRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java index 07e481b89f..04030e3b31 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumAmbiguousTriples.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class NumAmbiguousTriples implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java index 83035bdbc7..e3a3d94a29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedBothNonancestorAncestor.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumBidirectedBothNonancestorAncestor implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java index 755df2b67c..42c479677b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesEst.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class NumBidirectedEdgesEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java index 6836b6bf73..76412771cf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumBidirectedEdgesTrue.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class NumBidirectedEdgesTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java index 0b328cf48e..3c49a57edc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredDD.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumColoredDD implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java index ecceefef46..f4d77855e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredNL.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumColoredNL implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java index 7bf8e8d5eb..ce53df0bfc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPD.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumColoredPD implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java index 948a2fe7fe..2d695e3305 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumColoredPL.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumColoredPL implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java index 7074eb8abf..36fd11631c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCommonMeasuredAncestorBidirected.java @@ -17,7 +17,7 @@ * @author josephramsey */ public class NumCommonMeasuredAncestorBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public static boolean existsCommonAncestor(Graph trueGraph, Edge edge) { List nodes = trueGraph.paths().getAncestors(Collections.singletonList(edge.getNode1())); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java index e882b793a5..e549c0722e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDefiniteDirectedEdgeAncestors.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -12,7 +11,7 @@ * @author josephramsey */ public class NumCompatibleDefiniteDirectedEdgeAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -28,7 +27,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java index dff8657a12..bd5004e6a3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeConfounded.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.algcomparison.statistic.LatentCommonAncestorTruePositiveBidirected.existsLatentCommonAncestor; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -13,7 +12,7 @@ * @author josephramsey */ public class NumCompatibleDirectedEdgeConfounded implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -29,7 +28,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java index a89c8e27f4..1c597b6dcb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleDirectedEdgeNonAncestors.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class NumCompatibleDirectedEdgeNonAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java index caaa289d6c..93edd07325 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleEdges.java @@ -3,8 +3,8 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -14,7 +14,7 @@ * @author josephramsey */ public class NumCompatibleEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -30,7 +30,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java index 35b0d77c8e..53f6c05db5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeAncestors.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -12,7 +11,7 @@ * @author josephramsey */ public class NumCompatiblePossiblyDirectedEdgeAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -28,7 +27,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java index 757094026e..2062f850c6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatiblePossiblyDirectedEdgeNonAncestors.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -12,7 +11,7 @@ * @author josephramsey */ public class NumCompatiblePossiblyDirectedEdgeNonAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -28,7 +27,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java index f07c83e18c..36ae9fa8dc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleAncestors.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -12,7 +11,7 @@ * @author josephramsey */ public class NumCompatibleVisibleAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -28,7 +27,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { GraphUtils.addPagColoring(estGraph); - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java index c0cd6b2d69..ecc1dffc80 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCompatibleVisibleNonancestors.java @@ -1,11 +1,7 @@ package edu.cmu.tetrad.algcomparison.statistic; import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.Edges; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.*; import static edu.cmu.tetrad.graph.GraphUtils.compatible; @@ -15,7 +11,7 @@ * @author josephramsey */ public class NumCompatibleVisibleNonancestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -29,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); int tp = 0; int fp = 0; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java index 62778571be..b3849eab94 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectDDAncestors.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class NumCorrectDDAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java index 6722f99f94..e8f55d1ce8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectPDAncestors.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class NumCorrectPDAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java index 462431fbee..0f64dea0de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumCorrectVisibleAncestors.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class NumCorrectVisibleAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java index 18c30bf881..2d7047ec73 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyDirected.java @@ -1,11 +1,7 @@ package edu.cmu.tetrad.algcomparison.statistic; import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.graph.Edge; -import edu.cmu.tetrad.graph.Edges; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.*; /** * The bidirected true positives. @@ -13,7 +9,7 @@ * @author josephramsey */ public class NumDefinitelyDirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -29,7 +25,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphTransforms.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java index d90dd0c772..811fdae615 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDefinitelyNotDirectedPaths.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * The bidirected true positives. @@ -10,7 +9,7 @@ * @author josephramsey */ public class NumDefinitelyNotDirectedPaths implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -26,7 +25,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphTransforms.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java index b922269dea..7b806636c8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeAncestors.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumDirectedEdgeAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java index 22dbdb45c9..571546d787 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeBnaMeasuredCounfounded.java @@ -15,7 +15,7 @@ * @author josephramsey */ public class NumDirectedEdgeBnaMeasuredCounfounded implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java index ee48bfc69c..16fb106c22 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNoMeasureAncestors.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class NumDirectedEdgeNoMeasureAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java index 71f44dd1bd..aa575478e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeNotAncNotRev.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumDirectedEdgeNotAncNotRev implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java index aa95b60422..3930c61320 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeReversed.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumDirectedEdgeReversed implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java index f653202e56..82626805c2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdgeVisible.java @@ -3,13 +3,15 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Edge; import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; +import edu.cmu.tetrad.graph.GraphTransforms; /** + * Number of X-->Y for which X-->Y visible in true PAG. + * * @author josephramsey */ public class NumDirectedEdgeVisible implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -25,7 +27,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int tp = 0; - Graph pag = GraphSearchUtils.dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); for (Edge edge : pag.getEdges()) { if (pag.paths().defVisible(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java index 5551988c54..84da8532c2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedEdges.java @@ -6,10 +6,12 @@ import edu.cmu.tetrad.graph.Graph; /** + * Number of X-->Y in est. + * * @author josephramsey */ public class NumDirectedEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java index bca1ea9b5d..313ed944c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsEst.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumDirectedPathsEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java index 218aa463a8..22ff3072aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedPathsTrue.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class NumDirectedPathsTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java index 010133c651..cef32e2cce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumDirectedShouldBePartiallyDirected.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class NumDirectedShouldBePartiallyDirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java index 8eb31fd41f..5f514c47c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectDDAncestors.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class NumIncorrectDDAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java index caf9e3aa97..9df698dc57 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectPDAncestors.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class NumIncorrectPDAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java index 75510db7dd..766d097982 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumIncorrectVisibleAncestors.java @@ -9,7 +9,7 @@ * @author josephramsey */ public class NumIncorrectVisibleAncestors implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java index 6a9198ea4c..14382fff06 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumLatentCommonAncestorBidirected.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class NumLatentCommonAncestorBidirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java index 62d132233d..e40d415ac0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumNondirectedEdges.java @@ -6,10 +6,12 @@ import edu.cmu.tetrad.graph.Graph; /** + * Number of X---Y in est. + * * @author josephramsey */ public class NumNondirectedEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java index 63780c07b2..84b8d1beca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPartiallyOrientedEdges.java @@ -6,10 +6,12 @@ import edu.cmu.tetrad.graph.Graph; /** + * Number of Xo->Y in est. + * * @author josephramsey */ public class NumPartiallyOrientedEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java index 7f302e2eb6..4de8297265 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumPossiblyDirected.java @@ -2,7 +2,6 @@ import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; /** * The bidirected true positives. @@ -10,7 +9,7 @@ * @author josephramsey */ public class NumPossiblyDirected implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -26,7 +25,7 @@ public String getDescription() { public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { int count = 0; - Graph cpdag = GraphSearchUtils.cpdagForDag(trueGraph); + Graph cpdag = GraphTransforms.cpdagForDag(trueGraph); for (Edge edge : estGraph.getEdges()) { if (Edges.isDirectedEdge(edge)) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java index fb1f668f9f..2467a8b2e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumUndirectedEdges.java @@ -6,10 +6,12 @@ import edu.cmu.tetrad.graph.Graph; /** + * Number of X---Y in est. + * * @author josephramsey */ public class NumUndirectedEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java index fc23324264..17cb0b8376 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumVisibleEst.java @@ -6,10 +6,12 @@ import edu.cmu.tetrad.graph.Graph; /** + * Number of X-->Y visible in est. + * * @author josephramsey */ public class NumVisibleEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java index e64f42b76b..f641f7cfc6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesEst.java @@ -10,7 +10,7 @@ * @author josephramsey */ public class NumberOfEdgesEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java index 668f2bdc0c..34de9ccb1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/NumberOfEdgesTrue.java @@ -10,7 +10,7 @@ * @author josephramsey */ public class NumberOfEdgesTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java index 856fc06ff2..d099d9ca3f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationPrecision.java @@ -10,7 +10,7 @@ * @author bryanandrews, osephramsey */ public class OrientationPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java index b65504aa9a..7065ac60ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/OrientationRecall.java @@ -10,7 +10,7 @@ * @author bryanandrews, josephramsey */ public class OrientationRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java index 9f4dd05ead..fa26169033 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyPrecision.java @@ -3,8 +3,7 @@ import edu.cmu.tetrad.algcomparison.statistic.utils.AdjacencyConfusion; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; - -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; +import edu.cmu.tetrad.graph.GraphTransforms; /** * The adjacency precision. The true positives are the number of adjacencies in both the true and estimated graphs. @@ -12,7 +11,7 @@ * @author josephramsey */ public class PagAdjacencyPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -26,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); AdjacencyConfusion adjConfusion = new AdjacencyConfusion(pag, estGraph); int adjTp = adjConfusion.getTp(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java index e858319066..8546ca7628 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PagAdjacencyRecall.java @@ -3,8 +3,7 @@ import edu.cmu.tetrad.algcomparison.statistic.utils.AdjacencyConfusion; import edu.cmu.tetrad.data.DataModel; import edu.cmu.tetrad.graph.Graph; - -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; +import edu.cmu.tetrad.graph.GraphTransforms; /** * The adjacency recall. The true positives are the number of adjacencies in both the true and estimated graphs. @@ -12,7 +11,7 @@ * @author josephramsey */ public class PagAdjacencyRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -26,7 +25,7 @@ public String getDescription() { @Override public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { - Graph pag = dagToPag(trueGraph); + Graph pag = GraphTransforms.dagToPag(trueGraph); AdjacencyConfusion adjConfusion = new AdjacencyConfusion(pag, estGraph); int adjTp = adjConfusion.getTp(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java index ea023a76a7..60fe462c45 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ParameterColumn.java @@ -10,7 +10,7 @@ * @author josephramsey */ public class ParameterColumn implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String parameter; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java index 14a91438eb..a1ca55af43 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentAmbiguous.java @@ -15,7 +15,7 @@ * @author josephramsey */ public class PercentAmbiguous implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java index 0d69fce9b8..bd546ff057 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PercentBidirectedEdges.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class PercentBidirectedEdges implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java index 2170cd5fa3..ad12c9d59f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedEst.java @@ -8,10 +8,12 @@ import java.util.List; /** + * Proportion of semi(X, Y) in estimated graph for which there is no semi(Y, X) in true graph. + * * @author josephramsey */ public class ProportionSemidirectedPathsNotReversedEst implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -35,8 +37,8 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { for (Node y : nodes) { if (x == y) continue; - if (estGraph.paths().existsSemiDirectedPathFromTo(x, y)) { - if (!trueGraph.paths().existsSemiDirectedPathFromTo(y, x)) { + if (estGraph.paths().existsSemiDirectedPath(x, y)) { + if (!trueGraph.paths().existsSemiDirectedPath(y, x)) { tp++; } else { fp++; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java index d8b8787fd5..4875ba5191 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/ProportionSemidirectedPathsNotReversedTrue.java @@ -8,10 +8,12 @@ import java.util.List; /** + * Proportion of semi(X, Y) in true graph for which there is no semi(Y, Z) in estimated graph. + * * @author josephramsey */ public class ProportionSemidirectedPathsNotReversedTrue implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -35,8 +37,8 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { for (Node y : nodes) { if (x == y) continue; - if (trueGraph.paths().existsSemiDirectedPathFromTo(x, y)) { - if (!estGraph.paths().existsSemiDirectedPathFromTo(y, x)) { + if (trueGraph.paths().existsSemiDirectedPath(x, y)) { + if (!estGraph.paths().existsSemiDirectedPath(y, x)) { tp++; } else { fn++; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueDistanceToAlpha.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueDistanceToAlpha.java index 41570b0f0a..8fef3f87ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueDistanceToAlpha.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueDistanceToAlpha.java @@ -16,7 +16,7 @@ * @author josephramsey */ public class PvalueDistanceToAlpha implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double alpha = 0.01; public PvalueDistanceToAlpha(double alpha) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueUniformityUnderNull.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueUniformityUnderNull.java index c913c7351a..1a23b18e6f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueUniformityUnderNull.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/PvalueUniformityUnderNull.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class PvalueUniformityUnderNull implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double alpha = 0.01; public PvalueUniformityUnderNull(double alpha) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPathF1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPathF1.java index 683f7d4290..161c5a1a06 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPathF1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPathF1.java @@ -13,7 +13,7 @@ * @author Joseh Ramsey */ public class SemidirectedPathF1 implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java index 7bbecf35cc..fea01ed1aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedPrecision.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class SemidirectedPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -38,8 +38,8 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { for (Node y : nodes) { if (x == y) continue; - if (estGraph.paths().existsSemiDirectedPathFromTo(x, Collections.singleton(y))) { - if (trueGraph.paths().existsSemiDirectedPathFromTo(x, Collections.singleton(y))) { + if (estGraph.paths().existsSemiDirectedPath(x, Collections.singleton(y))) { + if (trueGraph.paths().existsSemiDirectedPath(x, Collections.singleton(y))) { tp++; } else { fp++; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java index a57c881253..86c91aeb03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/SemidirectedRecall.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class SemidirectedRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { @@ -38,8 +38,8 @@ public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) { for (Node y : nodes) { if (x == y) continue; - if (trueGraph.paths().existsSemiDirectedPathFromTo(x, Collections.singleton(y))) { - if (estGraph.paths().existsSemiDirectedPathFromTo(x, Collections.singleton(y))) { + if (trueGraph.paths().existsSemiDirectedPath(x, Collections.singleton(y))) { + if (estGraph.paths().existsSemiDirectedPath(x, Collections.singleton(y))) { tp++; } else { fn++; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java index 132cf36004..ca79dbfb3c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/Statistic.java @@ -32,6 +32,7 @@ public interface Statistic extends Serializable { * * @param trueGraph The true graph (DAG, CPDAG, PAG_of_the_true_DAG). * @param estGraph The estimated graph (same type). + * @param dataModel The data model. * @return The value of the statistic. */ double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/StructuralHammingDistance.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/StructuralHammingDistance.java index 29dd119ea2..3a22767caa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/StructuralHammingDistance.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/StructuralHammingDistance.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class StructuralHammingDistance implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java index 26dccf598f..e072b1bdb5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailPrecision.java @@ -13,7 +13,7 @@ * @author josephramsey */ public class TailPrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java index 3671e75e12..c365f087d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TailRecall.java @@ -13,7 +13,7 @@ * @author josephramsey */ public class TailRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java index 84a63e7dcf..28229a198f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesArrows.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class TrueDagFalseNegativesArrows implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java index e7dd509e7a..f0bdbae4a4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalseNegativesTails.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class TrueDagFalseNegativesTails implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java index 3604306810..9409c853b4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveArrow.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class TrueDagFalsePositiveArrow implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java index 07bf4e60e6..fe75064d65 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagFalsePositiveTails.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class TrueDagFalsePositiveTails implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java index ce161ffd78..fee6534567 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionArrow.java @@ -8,10 +8,12 @@ import java.util.List; /** + * The proportion of X*->Y in the estimated graph for which there is no path Y~~>X in the true graph. + * * @author josephramsey */ public class TrueDagPrecisionArrow implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java index e33b034f45..b88dda878c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagPrecisionTails.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class TrueDagPrecisionTails implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java index 5067ed945b..b7cc3c3955 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallArrows.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class TrueDagRecallArrows implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java index 143d17646a..5e75a3ea87 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagRecallTails.java @@ -14,7 +14,7 @@ * @author josephramsey */ public class TrueDagRecallTails implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java index 3fc37c0359..1367b2bf0b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveArrow.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class TrueDagTruePositiveArrow implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java index 78639caae4..45b2426f61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveDirectedPathNonancestor.java @@ -12,7 +12,7 @@ * @author josephramsey */ public class TrueDagTruePositiveDirectedPathNonancestor implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java index a4ed824e13..20b75ee93f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TrueDagTruePositiveTails.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class TrueDagTruePositiveTails implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java index b2b0b85bc2..757d3528be 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalseNegative.java @@ -12,7 +12,7 @@ * @author josephramsey, rubens (November 2016) */ public class TwoCycleFalseNegative implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java index 7f2e33a3c2..2160872e21 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleFalsePositive.java @@ -13,7 +13,7 @@ * @author josephramsey, rubens (November 2016) */ public class TwoCycleFalsePositive implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java index 1dfafb1753..3fa16d163e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCyclePrecision.java @@ -12,7 +12,7 @@ * @author josephramsey, rubens (November 2016) */ public class TwoCyclePrecision implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java index 6d1076d40f..3d2691770b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleRecall.java @@ -12,7 +12,7 @@ * @author josephramsey, rubens (November 2016) */ public class TwoCycleRecall implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java index 00b41ed995..43c1d34792 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/TwoCycleTruePositive.java @@ -12,7 +12,7 @@ * @author josephramsey, rubens (November 2016) */ public class TwoCycleTruePositive implements Statistic { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public String getAbbreviation() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java index d42a819424..d2833de749 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/AdjacencyConfusion.java @@ -18,6 +18,11 @@ public class AdjacencyConfusion { private int fp; private int fn; + /** + * Constructs a new AdjacencyConfusion object from the given graphs. + * @param truth The true graph. + * @param est The estimated graph. + */ public AdjacencyConfusion(Graph truth, Graph est) { this.tp = 0; this.fp = 0; @@ -54,18 +59,34 @@ public AdjacencyConfusion(Graph truth, Graph est) { this.tn = allEdges - this.fn - this.fp - this.fn; } + /** + * Returns the true positive count. + * @return the true positive count. + */ public int getTp() { return this.tp; } + /** + * Returns the false positive count. + * @return the false positive count. + */ public int getFp() { return this.fp; } + /** + * Returns the false negative count. + * @return the false negative count. + */ public int getFn() { return this.fn; } + /** + * Returns the true negative count. + * @return the true negative count. + */ public int getTn() { return this.tn; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java index 32eff0bedc..d09b997733 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/ArrowConfusion.java @@ -30,10 +30,21 @@ public class ArrowConfusion { private int TCfn; private int TCfp; + /** + * Constructs a new ArrowConfusion object. + * @param truth the true graph + * @param est the estimated graph + */ public ArrowConfusion(Graph truth, Graph est) { this(truth, est, false); } + /** + * Constructs a new ArrowConfusion object. + * @param truth the true graph + * @param est the estimated graph + * @param truthAdj if true, use the true graph to determine adjacency for arrowhead FP's + */ public ArrowConfusion(Graph truth, Graph est, boolean truthAdj) { Graph truth1 = truth; Graph est1 = est; @@ -259,37 +270,65 @@ public ArrowConfusion(Graph truth, Graph est, boolean truthAdj) { } - + /** + * True positives. + * @return the number of true positives + */ public int getTp() { return this.tp; } + /** + * False positives. + * @return the number of false positives + */ public int getFp() { return this.fp; } + /** + * False negatives. + * @return the number of false negatives + */ public int getFn() { return this.fn; } + /** + * True negatives. + * @return the number of true negatives + */ public int getTn() { return this.tn; } + /** + * Two positives for two-cycles. + * @return the number of true positives for two-cycles. + */ public int getTwoCycleTp() { return this.TCtp; } + /** + * False positives for two-cycles. + * @return the number of false positives for two-cycles. + */ public int getTwoCycleFp() { return this.TCfp; } + /** + * False negatives for two-cycles. + * @return the number of false negatives for two-cycles. + */ public int getTwoCycleFn() { return this.TCfn; } /** - * Two positives for common edges. + * True positives for common edges. + * @return the number of true positives for common edges */ public int getTpc() { return this.tpc; @@ -297,6 +336,7 @@ public int getTpc() { /** * False positives for common edges. + * @return the number of false positives for common edges */ public int getFpc() { return this.fpc; @@ -304,6 +344,7 @@ public int getFpc() { /** * False negatives for common edges. + * @return the number of false negatives for common edges */ public int getFnc() { return this.fnc; @@ -311,11 +352,16 @@ public int getFnc() { /** * True Negatives for common edges. + * @return the number of true negatives for common edges */ public int getTnc() { return this.tnc; } + /** + * Returns true if the truth graph is used to determine adjacency for arrowhead FP's. + * @return true if the truth graph is used to determine adjacency for arrowhead FP's + */ public boolean isTruthAdj() { return this.truthAdj; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java index 2e4f2d2dd9..fd81b6baa1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/statistic/utils/OrientationConfusion.java @@ -7,12 +7,6 @@ /** * A confusion matrix for orientations: - *

- * True | Estimated | Orientation -------------------------------- a <- b | a <- b | tp, tn | a -> b | - * fp, fn | a −− b | fn | a .. b | fn -------------------------------- a .. b | a <- b | fp | a -> - * b | fp | a −− b | | a .. b | - *

- * The true graph should be a DAG! * * @author bryanandrews, josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasKnowledge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasKnowledge.java index c6c6f139a8..3c91c06df1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasKnowledge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasKnowledge.java @@ -10,12 +10,14 @@ public interface HasKnowledge { /** + * Returns a knowledge object. * @return a knowledge object. */ Knowledge getKnowledge(); /** * Sets a knowledge object. + * @param knowledge a knowledge object. */ void setKnowledge(Knowledge knowledge); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasParameters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasParameters.java index 6e8ec78863..e12cdf9a6c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasParameters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/algcomparison/utils/HasParameters.java @@ -8,6 +8,7 @@ public interface HasParameters { /** + * Returns the list of parameter names that are used. These are looked up in ParamMap, so if they're not * @return Returns the list of parameter names that are used. These are looked up in ParamMap, so if they're not * already defined they'll need to be defined there. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AbstractAnnotations.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AbstractAnnotations.java index c88491f25a..2ff0a40347 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AbstractAnnotations.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AbstractAnnotations.java @@ -27,6 +27,8 @@ import java.util.stream.Collectors; /** + * Abstract class for annotations. + * * Sep 20, 2017 10:59:43 AM * * @param annotation type @@ -34,8 +36,16 @@ */ public abstract class AbstractAnnotations { + /** + * Annotated classes. + */ protected final List> annotatedClasses; + /** + * Constructor. + * @param packageName package name + * @param type annotation type + */ public AbstractAnnotations(String packageName, Class type) { Reflections reflections = new Reflections(packageName); Set> classes = reflections.getTypesAnnotatedWith(type); @@ -45,10 +55,20 @@ public AbstractAnnotations(String packageName, Class type) { .collect(Collectors.toList()); } + /** + * Get annotated classes. + * @return annotated classes + */ public List> getAnnotatedClasses() { return Collections.unmodifiableList(this.annotatedClasses); } + /** + * Filter annotated classes by annotation type. + * @param annoClasses annotated classes + * @param type annotation type + * @return filtered annotated classes + */ public List> filterByAnnotation(List> annoClasses, Class type) { if (annoClasses == null || type == null) { return Collections.EMPTY_LIST; @@ -61,6 +81,12 @@ public List> filterByAnnotation(List> annoCl return Collections.unmodifiableList(list); } + /** + * Filter out annotated classes by annotation type. + * @param annoClasses annotated classes + * @param type annotation type + * @return filtered annotated classes + */ public List> filterOutByAnnotation(List> annoClasses, Class type) { if (annoClasses == null || type == null) { return Collections.EMPTY_LIST; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgType.java index ff89f7a970..7c71fdcce6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgType.java @@ -4,11 +4,34 @@ * Author : Jeremy Espino MD Created 6/30/17 10:36 AM */ public enum AlgType { + + /** + * If an algorithm forbids latent common causes. + */ forbid_latent_common_causes, // PC_All, PcStableMax, FGES, IMaGES_Discrete, IMaGES_Continuous, FANG, EFANG + + /** + * If an algorithm allows latent common causes. + */ allow_latent_common_causes, // FCI, RFCI, GFCI, SVARFCI, SvarGFCI - /*DAG, */ + + /** + * If an algorithm searches for Markov blanekts. + */ search_for_Markov_blankets, // FGES-MB, PC-MB + + /** + * If an algorithm produces undirected graphs. + */ produce_undirected_graphs, // FAS, MGM, GLASSO + + /** + * If algorithm orients edges pairwise. + */ orient_pairwise, // R3, RSkew, Skew + + /** + * If an algorithm searches for structure over latents. + */ search_for_structure_over_latents // BPC, FOFC, FTFC } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/Algorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/Algorithm.java index 51c797f31b..adc299d00a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/Algorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/Algorithm.java @@ -32,12 +32,28 @@ @Documented public @interface Algorithm { + /** + * Name of the algorithm. + * @return name of the algorithm + */ String name(); + /** + * Command of the algorithm. + * @return command of the algorithm + */ String command(); + /** + * Description of the algorithm. + * @return description of the algorithm + */ AlgType algoType(); + /** + * Description of the algorithm. + * @return description of the algorithm + */ DataType[] dataType() default DataType.All; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgorithmAnnotations.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgorithmAnnotations.java index 1c9c7fb83b..dc8cabac6a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgorithmAnnotations.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AlgorithmAnnotations.java @@ -27,6 +27,8 @@ import java.util.List; /** + * Annotations for algorithms. + * * Sep 26, 2017 12:19:41 AM * * @author Kevin V. Bui (kvb2@pitt.edu) @@ -39,34 +41,74 @@ private AlgorithmAnnotations() { super("edu.cmu.tetrad.algcomparison.algorithm", Algorithm.class); } + /** + * Gets the instance of this class. + * @return instance of this class + */ public static AlgorithmAnnotations getInstance() { return AlgorithmAnnotations.INSTANCE; } + /** + * Filters out algorithms that are not for the given data type. + * @param list list of algorithms + * @return list of algorithms that are not for the given data type + */ public List> filterOutExperimental(List> list) { return filterOutByAnnotation(list, Experimental.class); } + /** + * Checks if the algorithm takes multiple data sets. + * @param clazz algorithm class + * @return true if the algorithm takes multiple data sets + */ public boolean takesMultipleDataset(Class clazz) { return clazz != null && MultiDataSetAlgorithm.class.isAssignableFrom(clazz); } + /** + * Checks if the algorithm takes knowledge. + * @param clazz algorithm class + * @return true if the algorithm takes knowledge + */ public boolean takesKnowledge(Class clazz) { return clazz != null && HasKnowledge.class.isAssignableFrom(clazz); } + /** + * Checks if the algorithm takes an external graph. + * @param clazz algorithm class + * @return true if the algorithm takes an external graph + */ public boolean takesExternalGraph(Class clazz) { return clazz != null && TakesExternalGraph.class.isAssignableFrom(clazz); } + /** + * Checks if the algorithm requires independence test. + * @param clazz algorithm class + * @return true if the algorithm requires independence test + */ public boolean requiresIndependenceTest(Class clazz) { return clazz != null && TakesIndependenceWrapper.class.isAssignableFrom(clazz); } + /** + * Checks if the algorithm requires a score. + * @param clazz algorithm class + * @return true if the algorithm requires a score + */ public boolean requiresScore(Class clazz) { return clazz != null && UsesScoreWrapper.class.isAssignableFrom(clazz); } + /** + * Checks if the algorithm handles unmeasured confounders. + * + * @param clazz algorithm class + * @return true if the algorithm handles unmeasured confounders + */ public boolean handlesUnmeasuredConfounder(Class clazz) { return clazz != null && clazz.isAnnotationPresent(UnmeasuredConfounder.class); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClass.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClass.java index 0a3bb1d043..a56a602075 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClass.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClass.java @@ -35,15 +35,28 @@ public class AnnotatedClass implements Serializable { private final T annotation; + /** + * Creates an annotated class. + * @param clazz class + * @param annotation annotation + */ public AnnotatedClass(Class clazz, T annotation) { this.clazz = clazz; this.annotation = annotation; } + /** + * Gets the class. + * @return class + */ public Class getClazz() { return this.clazz; } + /** + * Gets the annotation. + * @return annotation + */ public T getAnnotation() { return this.annotation; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClassUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClassUtils.java index de6bbc5d8f..ca4a8180d2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClassUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/annotation/AnnotatedClassUtils.java @@ -36,6 +36,13 @@ public class AnnotatedClassUtils { private AnnotatedClassUtils() { } + /** + * Gets a list of annotated classes in the given package. + * @param packageName package name + * @param type annotation type + * @return list of annotated classes + * @param annotation type. + */ public static List> getAnnotatedClasses(String packageName, Class type) { Reflections reflections = new Reflections(packageName); Set> classes = reflections.getTypesAnnotatedWith(type); @@ -45,6 +52,13 @@ public static List> getAnnotatedClasses .collect(Collectors.toList()); } + /** + * Filters a list of annotated classes by the given annotation. + * @param annotation annotation + * @param annotatedClasses list of annotated classes + * @return list of annotated classes + * @param annotation type. + */ public static List> filterByAnnotations(Class annotation, List> annotatedClasses) { List> list = new LinkedList<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java index 60a9835256..41578750a2 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ApproximateUpdater.java @@ -40,7 +40,7 @@ * @author josephramsey */ public final class ApproximateUpdater implements ManipulatingBayesUpdater { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The IM which this updater modifies. @@ -72,6 +72,10 @@ public final class ApproximateUpdater implements ManipulatingBayesUpdater { //==============================CONSTRUCTORS===========================// + /** + * Constructs a new updater for the given Bayes net. + * @param bayesIm the Bayes net to be updated. + */ public ApproximateUpdater(BayesIm bayesIm) { if (bayesIm == null) { throw new NullPointerException(); @@ -83,6 +87,8 @@ public ApproximateUpdater(BayesIm bayesIm) { /** * Constructs a new updater for the given Bayes net. + * @param bayesIm the Bayes net to be updated. + * @param evidence the evidence for the update. */ public ApproximateUpdater(BayesIm bayesIm, Evidence evidence) { if (bayesIm == null) { @@ -94,6 +100,7 @@ public ApproximateUpdater(BayesIm bayesIm, Evidence evidence) { } /** + * Returns a simple exemplar of this class to test serialization. * @return a simple exemplar of this class to test serialization. */ public static ApproximateUpdater serializableInstance() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java index a08ab7bd04..3a44dcdf56 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesIm.java @@ -52,53 +52,75 @@ public interface BayesIm extends VariableSource, Im, Simulator { /** + * Returns the underlying Bayes PM. + * * @return the underlying Bayes PM. */ BayesPm getBayesPm(); /** + * $Description + * * @return the underlying DAG. */ Graph getDag(); /** + * Returns the name of the given node. + * * @return the number of nodes in the model. */ int getNumNodes(); /** + * Returns the name of the given node. + * + * @param nodeIndex the index of the node. * @return the node corresponding to the given node index. */ Node getNode(int nodeIndex); /** + * Returns the name of the given node. + * * @param name the name of the node. * @return the node with the given name in the associated graph. */ Node getNode(String name); /** + * Returns the index of the given node. + * * @param node the given node. * @return the index for that node, or -1 if the node is not in the BayesIm. */ int getNodeIndex(Node node); /** + * Returns the list of variables. + * * @return the list of variable for this Bayes net. */ List getVariables(); /** + * Returns the list of variable names. + * * @return the list of variable names for this Bayes net. */ List getVariableNames(); /** + * Returns the list of measured variables. + * * @return the list of measured variableNodes. */ List getMeasuredNodes(); /** + * Returns the number of columns. + * + * @param nodeIndex the index of the node. * @return the number of columns in the table of the given node N with index 'nodeIndex'--that is, the number of * possible values that N can take on. That is, if P(N=v0 | P1=v1, P2=v2, ... Pn=vn) is a conditional probability * stored in 'probs', then the maximum number of rows in the table for N is #vals(N). @@ -107,6 +129,9 @@ public interface BayesIm extends VariableSource, Im, Simulator { int getNumColumns(int nodeIndex); /** + * Returns the number of rows. + * + * @param nodeIndex the index of the node. * @return the number of rows in the table of the given node, which would be the total number of possible * combinations of parent values for a given node. That is, if P(N=v0 | P1=v1, P2=v2, ... Pn=vn) is a conditional * probability stored in 'probs', then the maximum number of rows in the table for N is #vals(P1) x #vals(P2) x ... @@ -117,22 +142,35 @@ public interface BayesIm extends VariableSource, Im, Simulator { int getNumRows(int nodeIndex); /** + * Returns the number of parents for the given node. + * * @param nodeIndex the given node. * @return the number of parents of the given node. */ int getNumParents(int nodeIndex); /** + * Returns the ith parent of the givne node. + * + * @param nodeIndex the index of the node. + * @param parentIndex the index of the parent. * @return the given parent of the given node. */ int getParent(int nodeIndex, int parentIndex); /** + * Returns the dimension of the given parent for the given node. + * + * @param nodeIndex the index of the node. + * @param parentIndex the index of the parent. * @return the dimension of the given parent for the given node. */ int getParentDim(int nodeIndex, int parentIndex); /** + * Returns the dimensions of the pararents of the given node. + * + * @param nodeIndex the index of the node. * @return (a defensive copy of) the array representing the dimensionality of each parent of a node, that is, the * number of values which that node can take on. The order of entries in this array is the same as the order of * entries of nodes returned by getParents() for that node. @@ -141,6 +179,9 @@ public interface BayesIm extends VariableSource, Im, Simulator { int[] getParentDims(int nodeIndex); /** + * Returns the parents of the given node. + * + * @param nodeIndex the index of the node. * @return (a defensive copy of) the array containing all of the parents of a given node in the order in which they * are stored internally. * @see #getParentDims @@ -148,6 +189,8 @@ public interface BayesIm extends VariableSource, Im, Simulator { int[] getParents(int nodeIndex); /** + * Returns the parents values of the given node. + * * @param nodeIndex the index of the node. * @param rowIndex the index of the row in question. * @return an array containing the combination of parent values for a given node and given row in the probability @@ -164,11 +207,18 @@ public interface BayesIm extends VariableSource, Im, Simulator { int[] getParentValues(int nodeIndex, int rowIndex); /** + * Returns the given parent value. + * + * @param nodeIndex the index of the node. + * @param rowIndex the index of the row in question. + * @param colIndex the index of the column in question. * @return the value in the probability table for the given node, at the given row and column. */ int getParentValue(int nodeIndex, int rowIndex, int colIndex); /** + * Returns the probability for the given cell in the given CPT. + * * @param nodeIndex the index of the node in question. * @param rowIndex the row in the table for this for node which represents the combination of parent values in * question. @@ -184,6 +234,8 @@ public interface BayesIm extends VariableSource, Im, Simulator { double getProbability(int nodeIndex, int rowIndex, int colIndex); /** + * Returns a row index. + * * @return the row in the table at which the given combination of parent values is represented for the given node. * The row is calculated as a variable-base place-value number. For instance, if the array of parent dimensions is * [3, 5, 7] and the parent value combination is [2, 4, 5], then the row number is (7 * (5 * (3 * 0 + 2) + 4)) + 5 = @@ -191,6 +243,8 @@ public interface BayesIm extends VariableSource, Im, Simulator { *

* Note: If the node has n values, the length of 'values' must be >= the number of parents. Only the first n * values are used. + * @param nodeIndex the index of the node in question. + * @param values the combination of parent values in question. * @see #getParentValues */ int getRowIndex(int nodeIndex, int[] values); @@ -202,11 +256,16 @@ public interface BayesIm extends VariableSource, Im, Simulator { /** * Normalizes all rows in the table associated with a given node. + * + * @param nodeIndex the index of the node in question. */ void normalizeNode(int nodeIndex); /** * Normalizes the given row. + * + * @param nodeIndex the index of the node in question. + * @param rowIndex the index of the row in question. */ void normalizeRow(int nodeIndex, int rowIndex); @@ -224,8 +283,7 @@ public interface BayesIm extends VariableSource, Im, Simulator { * @param value the desired probability to be set. * @see #getProbability */ - void setProbability(int nodeIndex, int rowIndex, int colIndex, - double value); + void setProbability(int nodeIndex, int rowIndex, int colIndex, double value); /** * Sets the probability for the given node. The matrix row represent row index, the row in the table for this for @@ -238,6 +296,10 @@ void setProbability(int nodeIndex, int rowIndex, int colIndex, void setProbability(int nodeIndex, double[][] probMatrix); /** + * Returns the index of the given node in the given BayesIm. + * + * @param otherBayesIm the BayesIm in which the node is to be found. + * @param nodeIndex the index of the node in this BayesIm. * @return the index of the node with the given name in the specified BayesIm. */ int getCorrespondingNodeIndex(int nodeIndex, BayesIm otherBayesIm); @@ -280,11 +342,18 @@ void setProbability(int nodeIndex, int rowIndex, int colIndex, void clearTable(int nodeIndex); /** + * Returns true iff the given row in the given node has a Double.NaN value in it. + * + * @param nodeIndex the node for the table whose incomplete rows are to be checked. + * @param rowIndex the index of the row in question. * @return true iff one of the values in the given row is Double.NaN. */ boolean isIncomplete(int nodeIndex, int rowIndex); /** + * Returns true iff the given node has a Double.NaN value in it. + * + * @param nodeIndex the node for the table whose incomplete rows are to be checked. * @return true iff any value in the table for the given node is Double.NaN. */ boolean isIncomplete(int nodeIndex); @@ -293,33 +362,34 @@ void setProbability(int nodeIndex, int rowIndex, int colIndex, * Simulates a sample with the given sample size. * * @param sampleSize the sample size. + * @param latentDataSaved true iff the latent data is to be saved. * @return the simulated sample as a DataSet. */ DataSet simulateData(int sampleSize, boolean latentDataSaved); -// /** -// * Simulates a sample with the given sample size. -// * -// * @param sampleSize the sample size. -// * @return the simulated sample as a DataSet. -// */ -// DataSet simulateData(int sampleSize, long seed, boolean latentDataSaved); - /** * Overwrites the given dataSet with a new simulated dataSet, to avoid allocating memory. The given dataSet must * have the necessary number of columns. * + * @param dataSet the dataSet to be overwritten. + * @param latentDataSaved true iff the latent data is to be saved. * @return the simulated sample as a DataSet. */ DataSet simulateData(DataSet dataSet, boolean latentDataSaved); /** + * Returns true iff this Bayes net is equal to the given Bayes net. The sense of equality may vary depending on the + * type of Bayes net. + * + * @param o the Bayes net to be compared to this Bayes net. * @return true iff this bayes net is equal to the given Bayes net. The sense of equality may vary depending on the * type of Bayes net. */ boolean equals(Object o); /** + * Returns a string representation for this Bayes net. + * * @return a string representation for this Bayes net. */ String toString(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java index f9458d46db..fc82053648 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesImProbs.java @@ -38,7 +38,7 @@ * @author josephramsey */ public final class BayesImProbs implements DiscreteProbs, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. @@ -52,6 +52,10 @@ public final class BayesImProbs implements DiscreteProbs, TetradSerializable { //===========================CONSTRUCTORS==========================// + /** + * Constructs a BayesImProbs object from the given BayesIm. + * @param bayesIm Ibid. + */ public BayesImProbs(BayesIm bayesIm) { if (bayesIm == null) { throw new NullPointerException(); @@ -80,6 +84,8 @@ public BayesImProbs(BayesIm bayesIm) { /** * Generates a simple exemplar of this class to test serialization. + * + * @return a simple exemplar of this class to test serialization. */ public static BayesImProbs serializableInstance() { return new BayesImProbs(MlBayesIm.serializableInstance()); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java index 5aa5e791e1..58e48f7815 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesPm.java @@ -44,7 +44,7 @@ * @see BayesIm */ public final class BayesPm implements Pm, VariableSource { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The underlying graph that's being parameterized. @@ -65,6 +65,8 @@ public final class BayesPm implements Pm, VariableSource { /** * Construct a new BayesPm using the given DAG, assigning each variable two values named "value1" and "value2" * unless nodes are discrete variables with categories already defined. + * + * @param graph Ibid. */ public BayesPm(Graph graph) { if (graph == null) { @@ -92,6 +94,9 @@ public BayesPm(Graph graph) { /** * Constructs a new BayesPm using a given DAG, using as much information from the old BayesPm as possible. + * + * @param graph Ibid. + * @param oldBayesPm Ibid. */ public BayesPm(Graph graph, BayesPm oldBayesPm) { this(graph, oldBayesPm, 2, 2); @@ -102,6 +107,10 @@ public BayesPm(Graph graph, BayesPm oldBayesPm) { * lowerBound and * upperBound. Uses a fixed number of values if lowerBound == * upperBound. The values are named "value1" ... "valuen". + * + * @param graph Ibid. + * @param lowerBound Ibid. + * @param upperBound Ibid. */ public BayesPm(Graph graph, int lowerBound, int upperBound) { if (graph == null) { @@ -118,6 +127,11 @@ public BayesPm(Graph graph, int lowerBound, int upperBound) { * variables not in the old BayesPm, assigns each variable a random number of values between * lowerBound and upperBound. Uses a fixed number * of values if lowerBound == upperBound. The values are named "value1" ... "valuen". + * + * @param graph Ibid. + * @param oldBayesPm Ibid. + * @param lowerBound Ibid. + * @param upperBound Ibid. */ public BayesPm(Graph graph, BayesPm oldBayesPm, int lowerBound, int upperBound) { @@ -145,6 +159,8 @@ public BayesPm(Graph graph, BayesPm oldBayesPm, int lowerBound, /** * Copy constructor. + * + * @param bayesPm Ibid. */ public BayesPm(BayesPm bayesPm) { this.dag = bayesPm.dag; @@ -162,6 +178,8 @@ public BayesPm(BayesPm bayesPm) { /** * Generates a simple exemplar of this class to test serialization. + * + * @return Ibid. */ public static BayesPm serializableInstance() { return new BayesPm(Dag.serializableInstance()); @@ -170,6 +188,11 @@ public static BayesPm serializableInstance() { //=========================PUBLIC METHODS=============================// + /** + * Returns the parameter names. + * + * @return Ibid. + */ public static List getParameterNames() { List parameters = new ArrayList<>(); parameters.add("minCategories"); @@ -194,6 +217,8 @@ private static int pickNumVals(int lowerBound, int upperBound) { } /** + * Returns the DAG. + * * @return the DAG as a Graph. */ public Graph getDag() { @@ -201,6 +226,9 @@ public Graph getDag() { } /** + * Returns the number of values for the given node. + * + * @param node Ibid. * @return the number of values for the given node. */ public int getNumCategories(Node node) { @@ -214,6 +242,10 @@ public int getNumCategories(Node node) { } /** + * Returns the index'th value for the given node. + * + * @param node Ibid. + * @param index Ibid. * @return the index'th value for the given node. */ public String getCategory(Node node, int index) { @@ -237,6 +269,10 @@ public String getCategory(Node node, int index) { } /** + * Returns the index of the given category for the given node. + * + * @param node Ibid. + * @param category Ibid. * @return the index of the given category for the given node. */ public int getCategoryIndex(Node node, String category) { @@ -246,6 +282,9 @@ public int getCategoryIndex(Node node, String category) { /** * Sets the number of values for the given node to the given number. + * + * @param node Ibid. + * @param numCategories Ibid. */ public void setNumCategories(Node node, int numCategories) { if (!this.nodesToVariables.containsKey(node)) { @@ -283,6 +322,8 @@ public void setNumCategories(Node node, int numCategories) { /** * Will return true if the argument is a BayesPm with the same graph and variables. + * + * @param o Ibid. */ public boolean equals(Object o) { if (o == null) { @@ -299,6 +340,12 @@ public boolean equals(Object o) { } + /** + * Sets the number of values for the given node to the given number. + * + * @param node Ibid. + * @param categories Ibid. + */ public void setCategories(Node node, List categories) { mapNodeToVariable(node, categories); } @@ -313,6 +360,11 @@ public List getVariables() { return variables; } + /** + * Returns the variable names. + * + * @return Ibid. + */ public List getVariableNames() { List variables = getVariables(); List names = new ArrayList<>(); @@ -325,11 +377,19 @@ public List getVariableNames() { return names; } + /** + * Returns the variable for the given node. + * + * @param node Ibid. + * @return Ibid. + */ public Node getVariable(Node node) { return this.nodesToVariables.get(node); } /** + * Returns the measured nodes. + * * @return the list of measured variableNodes. */ public List getMeasuredNodes() { @@ -346,6 +406,7 @@ public List getMeasuredNodes() { /** * Prints out the list of values for each node. + * @return Ibid. */ public String toString() { StringBuilder buf = new StringBuilder(); @@ -368,24 +429,42 @@ public String toString() { return buf.toString(); } + /** + * Returns the node by the given name. + * @param nodeName Ibid. + * @return Ibid. + */ public Node getNode(String nodeName) { return this.dag.getNode(nodeName); } + /** + * Returns the node at the given index. + * @param index Ibid. + * @return Ibid. + */ public Node getNode(int index) { return getVariables().get(index); } + /** + * Returns the node index. + * @return -1. + */ public int getNodeIndex() { return -1; } - //=========================PRIVATE METHODS=============================// - + /** + * Returns the number of nodes. + * @return Ibid. + */ public int getNumNodes() { return this.dag.getNumNodes(); } + //=========================PRIVATE METHODS=============================// + private void copyAvailableInformationFromOldBayesPm(BayesPm oldbayesPm, int lowerBound, int upperBound) { Graph newGraph = getDag(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java index b57a007d69..37a811b5ff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesProperties.java @@ -101,6 +101,8 @@ private static int getRowIndex(int[] dim, int[] values) { /** * Calculates the p-value of the graph with respect to the given data. + * + * @param graph The graph. */ public LikelihoodRet getLikelihoodRatioP(Graph graph) { @@ -154,6 +156,8 @@ public LikelihoodRet getLikelihoodRatioP(Graph graph) { /** * Call after calling getLikelihoodP(). + * + * @return The chi-squared statistic. */ public double getChisq() { return this.chisq; @@ -161,6 +165,8 @@ public double getChisq() { /** * Call after calling getLikelihoodP(). + * + * @return The degrees of freedom. */ public double getDof() { return this.dof; @@ -168,6 +174,8 @@ public double getDof() { /** * Call after calling getLikelihoodP(). + * + * @return The BIC. */ public double getBic() { return this.bic; @@ -175,6 +183,8 @@ public double getBic() { /** * Call after calling getLikelihoodP(). + * + * @return The likelihood. */ public double getLikelihood() { return this.likelihood; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java index 606afb1368..4dbfa13c2f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/BayesUpdater.java @@ -39,32 +39,58 @@ public interface BayesUpdater extends TetradSerializable { long serialVersionUID = 23L; /** + * Returns the marginal probability of the given variable taking the given value, given the evidence. + * + * @param variable variable index + * @param category category index * @return P(variable = value | evidence), where evidence is getEvidence(). */ double getMarginal(int variable, int category); /** + * Returns the joint marginal probability of the given variables taking the given values, given the evidence. + * * @return true if the getJointMarginal() method is supported. */ boolean isJointMarginalSupported(); /** + * Returns the joint marginal probability of the given variables taking the given values, given the evidence. + * + * @param variables variable indices + * @param values category indices * @return P(variables[i] = values[i] | evidence), where evidence is getEvidence(). */ double getJointMarginal(int[] variables, int[] values); /** * Sets new evidence for the updater. Once this is called, old updating results should not longer be available. + * + * @param evidence evidence */ void setEvidence(Evidence evidence); /** + * Returns the evidence for the updater. + * * @return the Bayes instantiated model that is being updated. */ BayesIm getBayesIm(); + /** + * Calculates the prior marginal probabilities of the given node. + * + * @param nodeIndex node index + * @return P(node = value), where value is the value of the node in the Bayes net. + */ double[] calculatePriorMarginals(int nodeIndex); + /** + * Calculates the updated marginal probabilities of the given node, given the evidence. + * + * @param nodeIndex node index + * @return P(node = value | evidence), where value is the value of the node in the Bayes net. + */ double[] calculateUpdatedMarginals(int nodeIndex); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java index 08ea5531e9..f273fd1638 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantMarginalCalculator.java @@ -35,7 +35,7 @@ */ public final class CptInvariantMarginalCalculator implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java index d33a8f0ab4..da910e533f 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/CptInvariantUpdater.java @@ -37,7 +37,7 @@ * @author josephramsey */ public final class CptInvariantUpdater implements ManipulatingBayesUpdater { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The IM which this updater modifies. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java index a7bd84ab85..3ce6c9d218 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DataSetProbs.java @@ -36,7 +36,7 @@ * @author josephramsey */ public final class DataSetProbs implements DiscreteProbs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The data set that this is a cell count table for. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java index 7b6716e24a..007a3e390e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/DirichletBayesIm.java @@ -67,7 +67,7 @@ */ public final class DirichletBayesIm implements BayesIm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final double ALLOWABLE_DIFFERENCE = 1.0e-10; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java index 1d83f30c2b..081e6581a1 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Evidence.java @@ -38,7 +38,7 @@ * @author josephramsey */ public final class Evidence implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * A proposition stating what we know for each variable. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Identifiability.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Identifiability.java index d731f9dd45..e1098bc4c3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Identifiability.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Identifiability.java @@ -38,7 +38,7 @@ * @author Choh Man Teng */ public final class Identifiability implements ManipulatingBayesUpdater { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The BayesIm which this updater modifies. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeAlgorithm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeAlgorithm.java index ccb80213af..c92d831d61 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeAlgorithm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeAlgorithm.java @@ -39,7 +39,7 @@ * href="https://raw.githubusercontent.com/Waikato/weka-3.8/master/weka/src/main/java/weka/classifiers/bayes/net/MarginCalculator.java">MarginCalculator.java */ public class JunctionTreeAlgorithm implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final TreeNode root; @@ -546,7 +546,7 @@ public String toString() { private class TreeSeparator implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double[] parentPotentials; private final double[] childPotentials; @@ -600,7 +600,7 @@ public void updateFromChild() { private class TreeNode implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Distribution over this junction node according to its potentials. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeUpdater.java index 29e1eb13c1..0dfed40047 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/JunctionTreeUpdater.java @@ -32,7 +32,7 @@ * @author Kevin V. Bui (kvb2@pitt.edu) */ public class JunctionTreeUpdater implements ManipulatingBayesUpdater { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The BayesIm which this updater modifies. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java index f3163c24e4..6b2afed2fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/ManipulatingBayesUpdater.java @@ -33,32 +33,46 @@ public interface ManipulatingBayesUpdater extends BayesUpdater { long serialVersionUID = 23L; /** + * Returns the manipulated Bayes IM. This is the Bayes IM in which the variables in the manipulation have been + * removed from the graph. + * * @return the Bayes instantiated model after manipulations have been applied. */ BayesIm getManipulatedBayesIm(); /** + * Returns the manipulated graph. This is the graph in which the variables in the manipulation have been removed + * from the graph. + * * @return the graph for the manipulated BayesIm. */ Graph getManipulatedGraph(); /** + * Returns the manipulation that was used to manipulate the Bayes IM. + * * @return a defensive copy of the evidence. */ Evidence getEvidence(); /** * Sets new evidence for the updater. Once this is called, old updating results should not longer be available. + * + * @param evidence the new evidence. */ void setEvidence(Evidence evidence); /** + * Returns the updated Bayes IM. This is the Bayes IM in which all probabilities of variables conditional on their + * parents have been updated. * @return the updated Bayes IM--that is, the Bayes IM in which all probabilities of variables conditional on their * parents have been updated. */ BayesIm getUpdatedBayesIm(); /** + * Returns the updated graph. This is the graph in which all probabilities of variables conditional on their + * parents have been updated. * @return P(variable = category | evidence) where evidence is getEvidence(). */ double getMarginal(int variable, int category); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java index a39ec6d88a..b7f86d02de 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Manipulation.java @@ -35,7 +35,7 @@ * @author josephramsey */ public final class Manipulation implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final VariableSource variableSource; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java index b538aa8a3b..77003ff05c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesIm.java @@ -76,7 +76,7 @@ public final class MlBayesIm implements BayesIm { * Indicates that new rows in this BayesIm should be initialized randomly. */ public static final int RANDOM = 1; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final double ALLOWABLE_DIFFERENCE = 1.0e-3; /** @@ -944,7 +944,7 @@ private DataSet simulateDataHelper(int sampleSize, boolean latentDataSaved, int[ constructSample(sampleSize, dataSet, map, tiers); if (!latentDataSaved) { - dataSet = DataUtils.restrictToMeasured(dataSet); + dataSet = DataTransforms.restrictToMeasured(dataSet); } return dataSet; @@ -994,7 +994,7 @@ private DataSet simulateDataHelper(DataSet dataSet, boolean latentDataSaved, int if (latentDataSaved) { return dataSet; } else { - return DataUtils.restrictToMeasured(dataSet); + return DataTransforms.restrictToMeasured(dataSet); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java index d22f9e4ddc..9fff8d6ca5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/MlBayesImObs.java @@ -65,7 +65,7 @@ */ public final class MlBayesImObs implements BayesIm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final double ALLOWABLE_DIFFERENCE = 1.0e-10; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java index 10d591f614..2a1782731b 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/Proposition.java @@ -42,7 +42,7 @@ * @author josephramsey */ public final class Proposition implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java index b2bf4e2d87..fd4a16398f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/RowSummingExactUpdater.java @@ -37,7 +37,7 @@ * @author josephramsey */ public final class RowSummingExactUpdater implements ManipulatingBayesUpdater { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The BayesIm which this updater modifies. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java index a311cbed4c..36c3e6225f 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbs.java @@ -38,7 +38,7 @@ * @author josephramsey */ public final class StoredCellProbs implements TetradSerializable, DiscreteProbs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final List variables; private final int[] parentDims; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java index 7b4086ed9a..b077d7b218 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/StoredCellProbsObs.java @@ -42,7 +42,7 @@ ////////////////////////////////////////////////////////////////////// public final class StoredCellProbsObs implements TetradSerializable, DiscreteProbs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final List variables; private final int[] parentDims; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java index 3496d9aba7..b4730e1fef 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/bayes/UpdatedBayesIm.java @@ -41,7 +41,7 @@ */ public final class UpdatedBayesIm implements BayesIm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final double ALLOWABLE_DIFFERENCE = 1.0e-10; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpression.java index 030229d3c3..198b8d93a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpression.java @@ -34,7 +34,7 @@ * @author Tyler Gibson */ abstract class AbstractExpression implements Expression { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The sub expressionts diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpressionDescriptor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpressionDescriptor.java index 09caaf05b2..3ad1dc3ffc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpressionDescriptor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/AbstractExpressionDescriptor.java @@ -27,7 +27,7 @@ * @author Tyler Gibson */ abstract class AbstractExpressionDescriptor implements ExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The human-readable name for the descriptor. @@ -111,7 +111,7 @@ public boolean isDisplay() { * Basic implementation of expression signature. */ public static class Signature implements ExpressionSignature { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String[] arguments; private String signature; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ConstantExpression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ConstantExpression.java index 709aae9f38..0e5a181321 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ConstantExpression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ConstantExpression.java @@ -42,7 +42,7 @@ public class ConstantExpression implements Expression { * Constant expression for e. */ public static final ConstantExpression E = new ConstantExpression(FastMath.E, "E");// "e"); - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * THe value of the expression. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/EvaluationExpression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/EvaluationExpression.java index 716300dac9..71399412f8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/EvaluationExpression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/EvaluationExpression.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class EvaluationExpression implements Expression { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The variable part of the expression. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionDescriptor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionDescriptor.java index 532a605ad0..cb6c18ef9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionDescriptor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionDescriptor.java @@ -63,7 +63,7 @@ enum Position implements TetradSerializable { PREFIX, BOTH; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public static Position serializableInstance() { return Position.NEITHER; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionManager.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionManager.java index 0ac9b15a97..0510fefd43 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionManager.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/ExpressionManager.java @@ -193,7 +193,7 @@ public ExpressionDescriptor getDescriptorFromToken(String token) { * Addition */ private static class AdditionExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public AdditionExpressionDescriptor() { @@ -204,7 +204,7 @@ public AdditionExpressionDescriptor() { public Expression createExpression(Expression... expressions) throws ExpressionInitializationException { if (expressions.length > 0) { return new AbstractExpression("+", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double value = 0.0; @@ -233,7 +233,7 @@ public double evaluate(Context context) { * Addition */ private static class SubtractionExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SubtractionExpressionDescriptor() { @@ -244,7 +244,7 @@ public SubtractionExpressionDescriptor() { public Expression createExpression(Expression... expressions) throws ExpressionInitializationException { if (expressions.length == 1) { return new AbstractExpression("-", Position.INFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return -getExpressions().get(0).evaluate(context); @@ -252,7 +252,7 @@ public double evaluate(Context context) { }; } else if (expressions.length == 2) { return new AbstractExpression("-", Position.INFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return getExpressions().get(0).evaluate(context) - getExpressions().get(1).evaluate(context); @@ -269,7 +269,7 @@ public double evaluate(Context context) { * Ceil */ private static class CeilExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CeilExpressionDescriptor() { @@ -283,7 +283,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("ceil", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.ceil(getExpressions().get(0).evaluate(context)); @@ -293,7 +293,7 @@ public double evaluate(Context context) { } private static class SignumExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SignumExpressionDescriptor() { @@ -307,7 +307,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("signum", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.signum(getExpressions().get(0).evaluate(context)); @@ -320,7 +320,7 @@ public double evaluate(Context context) { * Cosine */ private static class CosExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CosExpressionDescriptor() { @@ -334,7 +334,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("cos", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.cos(getExpressions().get(0).evaluate(context)); @@ -344,7 +344,7 @@ public double evaluate(Context context) { } private static class CoshExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CoshExpressionDescriptor() { @@ -358,7 +358,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("cosh", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.cosh(getExpressions().get(0).evaluate(context)); @@ -368,7 +368,7 @@ public double evaluate(Context context) { } private static class AcosExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public AcosExpressionDescriptor() { @@ -382,7 +382,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("acos", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.acos(getExpressions().get(0).evaluate(context)); @@ -396,7 +396,7 @@ public double evaluate(Context context) { * Flooor. */ private static class FloorExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public FloorExpressionDescriptor() { @@ -410,7 +410,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("floor", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.floor(getExpressions().get(0).evaluate(context)); @@ -423,7 +423,7 @@ public double evaluate(Context context) { * Flooor. */ private static class AbsoluteValueExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public AbsoluteValueExpressionDescriptor() { @@ -437,7 +437,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("abs", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.abs(getExpressions().get(0).evaluate(context)); @@ -447,7 +447,7 @@ public double evaluate(Context context) { } private static class Log10ExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Log10ExpressionDescriptor() { @@ -461,7 +461,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("log10", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.log10(getExpressions().get(0).evaluate(context)); @@ -475,7 +475,7 @@ public double evaluate(Context context) { * Multiplication. */ private static class MultiplicationExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public MultiplicationExpressionDescriptor() { @@ -488,7 +488,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("Must have at least two arguments."); } return new AbstractExpression("*", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double value = 1.0; @@ -506,7 +506,7 @@ public double evaluate(Context context) { * Multiplication. */ private static class DivisionExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public DivisionExpressionDescriptor() { @@ -519,7 +519,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("Must have two arguments."); } return new AbstractExpression("/", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return getExpressions().get(0).evaluate(context) @@ -534,7 +534,7 @@ public double evaluate(Context context) { * Natural log. */ private static class NaturalLogExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public NaturalLogExpressionDescriptor() { @@ -548,7 +548,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("ln", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.log(getExpressions().get(0).evaluate(context)); @@ -561,7 +561,7 @@ public double evaluate(Context context) { * Random value. */ private static class RandomExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public RandomExpressionDescriptor() { @@ -574,7 +574,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("Random must have no arguments."); } return new AbstractExpression("random", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.random(); @@ -587,7 +587,7 @@ public double evaluate(Context context) { * Round expression. */ private static class RoundExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public RoundExpressionDescriptor() { @@ -601,7 +601,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("round", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.round(getExpressions().get(0).evaluate(context)); @@ -615,7 +615,7 @@ public double evaluate(Context context) { * Tangent expression. */ private static class TanExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TanExpressionDescriptor() { @@ -629,7 +629,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("tan", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.tan(getExpressions().get(0).evaluate(context)); @@ -639,7 +639,7 @@ public double evaluate(Context context) { } private static class TanhExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TanhExpressionDescriptor() { @@ -653,7 +653,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("tanh", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.tanh(getExpressions().get(0).evaluate(context)); @@ -663,7 +663,7 @@ public double evaluate(Context context) { } private static class AtanExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public AtanExpressionDescriptor() { @@ -677,7 +677,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("atan", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.atan(getExpressions().get(0).evaluate(context)); @@ -687,7 +687,7 @@ public double evaluate(Context context) { } private static class LogisticExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public LogisticExpressionDescriptor() { @@ -701,7 +701,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("logistic", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double t = getExpressions().get(0).evaluate(context); @@ -715,7 +715,7 @@ public double evaluate(Context context) { * Square Root. */ private static class SquareRootExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SquareRootExpressionDescriptor() { @@ -729,7 +729,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("sqrt", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.sqrt(getExpressions().get(0).evaluate(context)); @@ -742,7 +742,7 @@ public double evaluate(Context context) { * Sine expression. */ private static class SinExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SinExpressionDescriptor() { @@ -756,7 +756,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("sin", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.sin(getExpressions().get(0).evaluate(context)); @@ -766,7 +766,7 @@ public double evaluate(Context context) { } private static class SinhExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SinhExpressionDescriptor() { @@ -780,7 +780,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("sinh", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.sinh(getExpressions().get(0).evaluate(context)); @@ -790,7 +790,7 @@ public double evaluate(Context context) { } private static class AsinExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public AsinExpressionDescriptor() { @@ -804,7 +804,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI " argument."); } return new AbstractExpression("asin", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return FastMath.asin(getExpressions().get(0).evaluate(context)); @@ -819,7 +819,7 @@ public double evaluate(Context context) { * @author Tyler Gibson */ private static class PowExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public PowExpressionDescriptor() { @@ -834,7 +834,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("pow", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { Expression exp1 = getExpressions().get(0); @@ -847,7 +847,7 @@ public double evaluate(Context context) { } private static class PowExpressionDescriptor2 extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public PowExpressionDescriptor2() { @@ -862,7 +862,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("^", Position.INFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { Expression exp1 = getExpressions().get(0); @@ -875,7 +875,7 @@ public double evaluate(Context context) { } private static class ExpExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ExpExpressionDescriptor() { super("Exponential", "exp", Position.PREFIX, false); @@ -889,7 +889,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("exp", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { Expression exp1 = getExpressions().get(0); @@ -900,7 +900,7 @@ public double evaluate(Context context) { } private static class MaxExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public MaxExpressionDescriptor() { @@ -913,7 +913,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("max must have two or more arguments."); } return new AbstractExpression("max", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double max = getExpressions().get(0).evaluate(context); @@ -930,7 +930,7 @@ public double evaluate(Context context) { } private static class MinExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public MinExpressionDescriptor() { @@ -943,7 +943,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("min must have two or more arguments."); } return new AbstractExpression("min", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double min = getExpressions().get(0).evaluate(context); @@ -960,7 +960,7 @@ public double evaluate(Context context) { } private static class ChiSquareExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ChiSquareExpressionDescriptor() { super("Chi Square", "ChiSquare", Position.PREFIX, false); @@ -974,7 +974,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("ChiSquare", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -993,7 +993,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class GammaExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public GammaExpressionDescriptor() { super("Gamma", "Gamma", Position.PREFIX, false); @@ -1007,7 +1007,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Gamma", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1028,7 +1028,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class BetaExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public BetaExpressionDescriptor() { super("Beta", "Beta", Position.PREFIX, false); @@ -1042,7 +1042,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Beta", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1062,7 +1062,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class CauchyExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public CauchyExpressionDescriptor() { super("Cauchy", "Cauchy", Position.PREFIX, false); @@ -1076,7 +1076,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Cauchy", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1097,7 +1097,7 @@ public RealDistribution getRealDistribution(Context context) { private static class FExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public FExpressionDescriptor() { super("FDist", "FDist", Position.PREFIX, false); @@ -1111,7 +1111,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("FDist", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1131,7 +1131,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class GumbelExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public GumbelExpressionDescriptor() { super("Gumbel", "Gumbel", Position.PREFIX, false); @@ -1145,7 +1145,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Gumbel", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1165,7 +1165,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class LaplaceExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public LaplaceExpressionDescriptor() { super("Laplace", "Laplace", Position.PREFIX, false); @@ -1179,7 +1179,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Laplace", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1199,7 +1199,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class LevyExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public LevyExpressionDescriptor() { super("Levy", "Levy", Position.PREFIX, false); @@ -1213,7 +1213,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Levy", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1233,7 +1233,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class NakagamiExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public NakagamiExpressionDescriptor() { super("Nakagami", "Nakagami", Position.PREFIX, false); @@ -1247,7 +1247,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Nakagami", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1267,7 +1267,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class ParetoExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ParetoExpressionDescriptor() { super("Pareto", "Pareto", Position.PREFIX, false); @@ -1281,7 +1281,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Pareto", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1301,7 +1301,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class TriangularExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TriangularExpressionDescriptor() { super("Triangular", "Triangular", Position.PREFIX, false); @@ -1315,7 +1315,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Triangular", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1337,7 +1337,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class UniformExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public UniformExpressionDescriptor() { super("Uniform", "Uniform", Position.PREFIX, false); @@ -1351,7 +1351,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Uniform", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1371,7 +1371,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class UExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public UExpressionDescriptor() { super("Uniform", "U", Position.PREFIX, false); @@ -1385,7 +1385,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Uniform", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1405,7 +1405,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class WeibullExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public WeibullExpressionDescriptor() { super("Weibull", "Weibull", Position.PREFIX, false); @@ -1419,7 +1419,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Weibull", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1439,7 +1439,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class PoissonExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public PoissonExpressionDescriptor() { super("Poisson", "Poisson", Position.PREFIX, false); @@ -1453,7 +1453,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Poisson", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1477,7 +1477,7 @@ public IntegerDistribution getIntegerDistribution(Context context) { } private static class IndicatorExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public IndicatorExpressionDescriptor() { super("Indicator", "Indicator", Position.PREFIX, false); @@ -1491,7 +1491,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Indicator", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { Expression exp1 = getExpressions().get(0); @@ -1506,7 +1506,7 @@ public double evaluate(Context context) { } private static class ExponentialExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public ExponentialExpressionDescriptor() { super("ExponentialDist", "ExponentialDist", Position.PREFIX, false); @@ -1520,7 +1520,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("ExponentialDist", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1548,7 +1548,7 @@ public RealDistribution getRealDistribution(Context context) { // // "exp(Normal(0, 1))" private static class LogNormalExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public LogNormalExpressionDescriptor() { super("LogNormal", "LogNormal", Position.PREFIX, false); @@ -1562,7 +1562,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("LogNormal", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1598,7 +1598,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class NormalExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public NormalExpressionDescriptor() { super("Normal", "Normal", Position.PREFIX, false); @@ -1612,7 +1612,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Normal", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1632,7 +1632,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class TruncNormalExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TruncNormalExpressionDescriptor() { super("TruncNormal", "TruncNormal", Position.PREFIX, false); @@ -1646,7 +1646,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("TruncNormal", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { Expression exp1 = getExpressions().get(0); @@ -1673,7 +1673,7 @@ public double evaluate(Context context) { } private static class NExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public NExpressionDescriptor() { super("Normal", "N", Position.PREFIX, false); @@ -1687,7 +1687,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("N", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1710,7 +1710,7 @@ public RealDistribution getRealDistribution(Context context) { } private static class DiscreteExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public DiscreteExpressionDescriptor() { super("Discrete", "Discrete", Position.PREFIX, false); @@ -1724,7 +1724,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Discrete", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double[] p = new double[getExpressions().size()]; @@ -1772,7 +1772,7 @@ private double[] convert(double... p) { // "0.3 * Normal(-2, 0.5) + 0.7 * Normal(2, 0.5) private static class MixtureDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public MixtureDescriptor() { super("Mixture", "Mixture", Position.PREFIX, false); @@ -1786,7 +1786,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Mixture", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List exp = getExpressions(); @@ -1827,7 +1827,7 @@ public double evaluate(Context context) { } private static class StudentTExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public StudentTExpressionDescriptor() { super("StudentT", "StudentT", Position.PREFIX, false); @@ -1841,7 +1841,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("StudentT", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); @@ -1865,7 +1865,7 @@ public RealDistribution getRealDistribution(Context context) { * Draws from the U(a1, b2) U U(a3, a4)... */ private static class SplitExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SplitExpressionDescriptor() { super("Split", "Split", Position.PREFIX, false); @@ -1879,7 +1879,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Split", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { if (getExpressions().size() < 2) { @@ -1930,7 +1930,7 @@ public double evaluate(Context context) { * For boolean "and". Will return true if all sub-expressions evaluate to a non-zero value and false otherwise. */ private static class AndExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public AndExpressionDescriptor() { @@ -1943,7 +1943,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("Must have at least two arguments."); } return new AbstractExpression("AND", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { boolean allOnes = true; @@ -1965,7 +1965,7 @@ public double evaluate(Context context) { * For boolean "Or". Will return 1.0 if at least one of the sub-expressions is non-zero. */ private static class OrExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public OrExpressionDescriptor() { super("Or", "OR", Position.PREFIX, true); @@ -1976,7 +1976,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("Must have at least two arguments."); } return new AbstractExpression("OR", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { for (Expression exp : getExpressions()) { @@ -1994,7 +1994,7 @@ public double evaluate(Context context) { * For boolean "Or". Will return 1.0 if at least one of the sub-expressions is non-zero. */ private static class XOrExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public XOrExpressionDescriptor() { super("Exclusive or", "XOR", Position.PREFIX, false); @@ -2005,7 +2005,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI throw new ExpressionInitializationException("Must have two arguments."); } return new AbstractExpression("XOR", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double first = getExpressions().get(0).evaluate(context); @@ -2020,7 +2020,7 @@ public double evaluate(Context context) { } private static class LessThanExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public LessThanExpressionDescriptor() { super("Less Than", "<", Position.BOTH, true); @@ -2032,7 +2032,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("<", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List expressions = getExpressions(); @@ -2045,7 +2045,7 @@ public double evaluate(Context context) { } private static class LessThanOrEqualExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public LessThanOrEqualExpressionDescriptor() { super("Less Than Or Equals", "<=", Position.BOTH, true); @@ -2057,7 +2057,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("<=", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List expressions = getExpressions(); @@ -2070,7 +2070,7 @@ public double evaluate(Context context) { } private static class EqualsExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public EqualsExpressionDescriptor() { super("Equals", "=", Position.BOTH, true); @@ -2082,7 +2082,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("=", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List expressions = getExpressions(); @@ -2095,7 +2095,7 @@ public double evaluate(Context context) { } private static class GreaterThanExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public GreaterThanExpressionDescriptor() { super("Greater Than", ">", Position.BOTH, true); @@ -2107,7 +2107,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("<", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List expressions = getExpressions(); @@ -2120,7 +2120,7 @@ public double evaluate(Context context) { } private static class GreaterThanOrEqualExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public GreaterThanOrEqualExpressionDescriptor() { super("Greater Than Or Equals", ">=", Position.BOTH, true); @@ -2132,7 +2132,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("<", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List expressions = getExpressions(); @@ -2145,7 +2145,7 @@ public double evaluate(Context context) { } private static class IfExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public IfExpressionDescriptor() { super("If", "IF", Position.PREFIX, true); @@ -2157,7 +2157,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("IF", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List expressions = getExpressions(); @@ -2171,7 +2171,7 @@ public double evaluate(Context context) { } private static class NewExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public NewExpressionDescriptor() { super("New Parameter", "NEW", Position.PREFIX, true); @@ -2187,7 +2187,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("NEW", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return Double.NaN; @@ -2197,7 +2197,7 @@ public double evaluate(Context context) { } private static class NewExpressionDescriptor2 extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public NewExpressionDescriptor2() { super("New Parameter", "new", Position.PREFIX, true); @@ -2213,7 +2213,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("new", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return Double.NaN; @@ -2223,7 +2223,7 @@ public double evaluate(Context context) { } private static class TSumExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TSumExpressionDescriptor() { super("Template Sum", "TSUM", Position.PREFIX, true); @@ -2235,7 +2235,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("TSUM", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return Double.NaN; @@ -2245,7 +2245,7 @@ public double evaluate(Context context) { } private static class TSumExpressionDescriptor2 extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TSumExpressionDescriptor2() { super("Template Sum", "tsum", Position.PREFIX, true); @@ -2257,7 +2257,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("tsum", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return Double.NaN; @@ -2267,7 +2267,7 @@ public double evaluate(Context context) { } private static class TProductExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TProductExpressionDescriptor() { super("Template Product", "TPROD", Position.PREFIX, true); @@ -2279,7 +2279,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("TPROD", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return Double.NaN; @@ -2289,7 +2289,7 @@ public double evaluate(Context context) { } private static class TProductExpressionDescriptor2 extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public TProductExpressionDescriptor2() { super("Template Product", "tprod", Position.PREFIX, true); @@ -2301,7 +2301,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("tprod", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { return Double.NaN; @@ -2314,7 +2314,7 @@ public double evaluate(Context context) { //First term should be a random draw that will be used to select a category index based on the (un-normalized) //weights given in the rest of the terms private static class DiscErrorExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public DiscErrorExpressionDescriptor() { super("DiscError", "DiscError", Position.PREFIX, false); @@ -2328,7 +2328,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("DiscError", Position.PREFIX, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { double[] p = new double[getExpressions().size() - 1]; @@ -2380,7 +2380,7 @@ private double[] convert(double... p) { //the first term is an index (non-negative integer) that tells the expression which of the rest of the terms to //return private static class SwitchExpressionDescriptor extends AbstractExpressionDescriptor { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public SwitchExpressionDescriptor() { super("Switch", "Switch", Position.PREFIX, true); @@ -2393,7 +2393,7 @@ public Expression createExpression(Expression... expressions) throws ExpressionI } return new AbstractExpression("Switch", Position.BOTH, expressions) { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public double evaluate(Context context) { List expressions = getExpressions(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/VariableExpression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/VariableExpression.java index 7c123fbe74..4f8fae696e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/VariableExpression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calculator/expression/VariableExpression.java @@ -33,7 +33,7 @@ * @author Tyler Gibson */ public class VariableExpression implements Expression { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The variable that is being evaluated. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java index 5f45f46990..b5e4916a5c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/calibration/DataForCalibrationRfci.java @@ -2,13 +2,12 @@ import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.BFci; import edu.cmu.tetrad.search.Rfci; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestFisherZ; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.MillisecondTimes; import org.apache.commons.math3.util.FastMath; @@ -111,7 +110,7 @@ public static void main(String[] args) throws IOException { // // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); System.out.println("true PAG construction Done!"); @@ -123,7 +122,7 @@ public static void main(String[] args) throws IOException { DataSet data = simulator.simulateDataReducedForm(numCases); // To remove the columns related to latent variables from dataset - data = DataUtils.restrictToMeasured(data); + data = DataTransforms.restrictToMeasured(data); System.out.println("Data simulation done"); System.out.println("Covariance matrix done"); @@ -350,7 +349,7 @@ public Graph makeDAG(int numVars, double edgesPerNode, int numLatentConfounders) } public DataSet bootStrapSampling(DataSet data, int bootsrapSampleSize) { - return DataUtils.getBootstrapSample(data, bootsrapSampleSize); + return DataTransforms.getBootstrapSample(data, bootsrapSampleSize); } public Graph learnBNRFCI(DataSet bootstrapSample, int depth, Graph truePag) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierBayesUpdaterDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierBayesUpdaterDiscrete.java index 8f77ee97b2..bd4c5d2870 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierBayesUpdaterDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierBayesUpdaterDiscrete.java @@ -47,7 +47,7 @@ */ public final class ClassifierBayesUpdaterDiscrete implements ClassifierDiscrete, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The BayesIm instance used to create an updater. Supplied as an argument to the constructor. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierMbDiscrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierMbDiscrete.java index da923d4659..2cfee5c690 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierMbDiscrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/classify/ClassifierMbDiscrete.java @@ -80,9 +80,9 @@ public ClassifierMbDiscrete(String trainPath, String testPath, String targetStri TetradLogger.getInstance().log("info", s); DataSet train = SimpleDataLoader.loadContinuousData(new File(trainPath), "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); DataSet test = SimpleDataLoader.loadContinuousData(new File(testPath), "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); double alpha = Double.parseDouble(alphaString); int depth = Integer.parseInt(depthString); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java index fd7a7ddd34..34789947ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AbstractVariable.java @@ -34,8 +34,11 @@ */ public abstract class AbstractVariable implements Variable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; + /** + * The last ID assigned to a variable. + */ public static int LAST_ID; /** @@ -94,20 +97,20 @@ public final void setName(String name) { /** * Checks to see whether the passed value is an acceptable value for - * this variable. For AbstractVariable, this method always - * returns true. Subclasses should override - * checkValue() in order to provide for subclass-specific value + * this variable. For AbstractVariable, this method always + * returns true. Subclasses should override + * checkValue() in order to provide for subclass-specific value * checking. The value should pass the test if it can be converted into an equivalent object of the correct class * type (see - * getValueClass()) for this variable; otherwise, it should fail. In - * general, checkValue() should not fail a value for simply not being an instance of a particular class. + * getValueClass()) for this variable; otherwise, it should fail. In + * general, checkValue() should not fail a value for simply not being an instance of a particular class. * Since this method is not - * static, subclasses may (but need not) provide for + * static, subclasses may (but need not) provide for * instance-specific value checking. * * @param value a value - * @return true if the value is an acceptable value for - * this variable, and false otherwise + * @return true if the value is an acceptable value for + * this variable, and false otherwise */ public boolean checkValue(Object value) { return true; @@ -122,57 +125,57 @@ public String toString() { public abstract Node like(String name); - @Override - public int compareTo(Node node) { - String node1 = getName(); - String node2 = node.getName(); - - boolean isAlpha1 = Node.ALPHA.matcher(node1).matches(); - boolean isAlpha2 = Node.ALPHA.matcher(node2).matches(); - boolean isAlphaNum1 = Node.ALPHA_NUM.matcher(node1).matches(); - boolean isAlphaNum2 = Node.ALPHA_NUM.matcher(node2).matches(); - boolean isLag1 = Node.LAG.matcher(node1).matches(); - boolean isLag2 = Node.LAG.matcher(node2).matches(); - - if (isAlpha1) { - if (isLag2) { - return -1; - } - } else if (isAlphaNum1) { - if (isAlphaNum2) { - String s1 = node1.replaceAll("\\d+", ""); - String s2 = node2.replaceAll("\\d+", ""); - if (s1.equals(s2)) { - String n1 = node1.replaceAll("\\D+", ""); - String n2 = node2.replaceAll("\\D+", ""); - - return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); - } else { - return s1.compareTo(s2); - } - } else if (isLag2) { - return -1; - } - } else if (isLag1) { - if (isAlpha2 || isAlphaNum2) { - return 1; - } else if (isLag2) { - String l1 = node1.replaceAll(":", ""); - String l2 = node2.replaceAll(":", ""); - String s1 = l1.replaceAll("\\d+", ""); - String s2 = l2.replaceAll("\\d+", ""); - if (s1.equals(s2)) { - String n1 = l1.replaceAll("\\D+", ""); - String n2 = l2.replaceAll("\\D+", ""); - - return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); - } else { - return s1.compareTo(s2); - } - } - } - - return node1.compareTo(node2); - } +// @Override +// public int compareTo(Node node) { +// String node1 = getName(); +// String node2 = node.getName(); +// +// boolean isAlpha1 = Node.ALPHA.matcher(node1).matches(); +// boolean isAlpha2 = Node.ALPHA.matcher(node2).matches(); +// boolean isAlphaNum1 = Node.ALPHA_NUM.matcher(node1).matches(); +// boolean isAlphaNum2 = Node.ALPHA_NUM.matcher(node2).matches(); +// boolean isLag1 = Node.LAG.matcher(node1).matches(); +// boolean isLag2 = Node.LAG.matcher(node2).matches(); +// +// if (isAlpha1) { +// if (isLag2) { +// return -1; +// } +// } else if (isAlphaNum1) { +// if (isAlphaNum2) { +// String s1 = node1.replaceAll("\\d+", ""); +// String s2 = node2.replaceAll("\\d+", ""); +// if (s1.equals(s2)) { +// String n1 = node1.replaceAll("\\D+", ""); +// String n2 = node2.replaceAll("\\D+", ""); +// +// return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); +// } else { +// return s1.compareTo(s2); +// } +// } else if (isLag2) { +// return -1; +// } +// } else if (isLag1) { +// if (isAlpha2 || isAlphaNum2) { +// return 1; +// } else if (isLag2) { +// String l1 = node1.replaceAll(":", ""); +// String l2 = node2.replaceAll(":", ""); +// String s1 = l1.replaceAll("\\d+", ""); +// String s2 = l2.replaceAll("\\d+", ""); +// if (s1.equals(s2)) { +// String n1 = l1.replaceAll("\\D+", ""); +// String n2 = l2.replaceAll("\\D+", ""); +// +// return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); +// } else { +// return s1.compareTo(s2); +// } +// } +// } +// +// return node1.compareTo(node2); +// } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java index ed493930e1..3d58112c66 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/AndersonDarlingTest.java @@ -61,6 +61,8 @@ public class AndersonDarlingTest { /** * Constructs an Anderson-Darling test for the given column of data. + * + * @param data the column of data to be analyzed. */ public AndersonDarlingTest(double[] data) { this.data = data; @@ -68,6 +70,8 @@ public AndersonDarlingTest(double[] data) { } /** + * Constructs an Anderson-Darling test for the given column of data. + * * @return the A^2 statistic. */ public double getASquared() { @@ -75,6 +79,8 @@ public double getASquared() { } /** + * Constructs an Anderson-Darling test for the given column of data. + * * @return the A^2* statistic, which is the A^2 statistic adjusted heuristically for sample size. */ public double getASquaredStar() { @@ -82,6 +88,8 @@ public double getASquaredStar() { } /** + * Constructs an Anderson-Darling test for the given column of data. + * * @return the p value of the A^2* statistic, which is interpolated using exponential functions. */ public double getP() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java index 786568026a..450149b03c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/BoxDataSet.java @@ -55,7 +55,7 @@ * Knowledge may be associated with the data set, using the * setKnowledge method. This knowledge is not used internally to * the data set, but it may be retrieved by algorithms and used. - *

+ *

* * @author josephramsey * @see edu.cmu.tetrad.data.Variable @@ -63,7 +63,7 @@ */ public final class BoxDataSet implements DataSet { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Case ID's. These are strings associated with some or all of the cases of the dataset. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ByteDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ByteDataBox.java index 85314063c8..3e777c5990 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ByteDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ByteDataBox.java @@ -30,7 +30,7 @@ * Stores a 2D array of byte data. Note that the missing value marker for this box is -99. */ public class ByteDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored byte data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java index 67b6d108c3..4d262cbba2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Clusters.java @@ -35,7 +35,7 @@ * @author Ricardo Silva */ public final class Clusters implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * This is used to store information on pure measurement models (when the graph is a measurement/structural model). diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java index e40ed1bbd5..26ef62bc60 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousDiscretizationSpec.java @@ -43,7 +43,7 @@ public final class ContinuousDiscretizationSpec implements TetradSerializable, D public static final int EVENLY_DISTRIBUTED_VALUES = 1; public static final int EVENLY_DISTRIBUTED_INTERVALS = 2; public static final int NONE = 3; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Breakpoints, for continuous data. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java index b1ed8371ca..24ab2aa194 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ContinuousVariable.java @@ -37,11 +37,11 @@ * @author Willie Wheeler 07/99 * @author josephramsey modifications 12/00 */ -public final class ContinuousVariable extends AbstractVariable { +public final class ContinuousVariable extends AbstractVariable implements Variable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; - /** +/** * This is the value which represents missing data in data columns for this variable. */ private static final double MISSING_VALUE = Double.NaN; @@ -90,7 +90,7 @@ public ContinuousVariable(ContinuousVariable variable) { this.nodeType = variable.nodeType; this.centerX = variable.centerX; this.centerY = variable.centerY; - this.nodeVariableType = getNodeVariableType(); + this.nodeVariableType = variable.nodeVariableType; } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java index 25ce7291aa..1035d5f6a8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrix.java @@ -37,7 +37,7 @@ * @author josephramsey */ public final class CorrelationMatrix extends CovarianceMatrix { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Constructs a new correlation matrix using the covariances in the given covariance matrix. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java index 6bb72ab86d..5224dff3e9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CorrelationMatrixOnTheFly.java @@ -43,7 +43,7 @@ * @see CorrelationMatrix */ public class CorrelationMatrixOnTheFly implements ICovarianceMatrix { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final ICovarianceMatrix cov; private boolean verbose; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java index 5579f363f1..81a3374627 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrix.java @@ -40,7 +40,7 @@ * @see edu.cmu.tetrad.data.CorrelationMatrix */ public class CovarianceMatrix implements ICovarianceMatrix { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The wrapped covariance matrix data. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java index 044cc81ec4..735eb7ca4e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovarianceMatrixOnTheFly.java @@ -45,7 +45,7 @@ * @see CorrelationMatrix */ public class CovarianceMatrixOnTheFly implements ICovarianceMatrix { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double[] variances; private boolean verbose = false; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovariancesDoubleForkJoin.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovariancesDoubleForkJoin.java index 9bada02fdb..570ba61505 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovariancesDoubleForkJoin.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/CovariancesDoubleForkJoin.java @@ -27,7 +27,7 @@ * @author Joseph D. Ramsey */ public class CovariancesDoubleForkJoin { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final int numOfCols; private final double[][] covariances; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataGraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataGraphUtils.java index af5844a17a..973a738f67 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataGraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataGraphUtils.java @@ -219,7 +219,7 @@ public static Graph randomMim(Graph graph, int numMeasurementsPerLatent, } if (arrangeGraph) { - LayoutUtil.circleLayout(graph1); + LayoutUtil.defaultLayout(graph1); LayoutUtil.fruchtermanReingoldLayout(graph1); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java index 983562ebfc..f6d94141aa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataModelList.java @@ -38,7 +38,7 @@ public final class DataModelList extends AbstractList implements DataModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The list of models. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataTransforms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataTransforms.java new file mode 100644 index 0000000000..2462a1d3df --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataTransforms.java @@ -0,0 +1,1035 @@ +package edu.cmu.tetrad.data; + + +import cern.colt.list.DoubleArrayList; +import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.graph.NodeType; +import edu.cmu.tetrad.util.Matrix; +import edu.cmu.tetrad.util.RandomUtil; +import edu.cmu.tetrad.util.StatUtils; +import edu.cmu.tetrad.util.Vector; +import org.apache.commons.math3.distribution.NormalDistribution; +import org.apache.commons.math3.exception.OutOfRangeException; +import org.apache.commons.math3.random.RandomGenerator; +import org.apache.commons.math3.util.FastMath; + +import java.rmi.MarshalledObject; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +public class DataTransforms { + + + /** + * Log or unlog data + */ + public static DataSet logData(DataSet dataSet, double a, boolean isUnlog, int base) { + Matrix data = dataSet.getDoubleData(); + Matrix X = data.like(); + + for (int j = 0; j < data.getNumColumns(); j++) { + double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); + double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); + + if (dataSet.getVariable(j) instanceof DiscreteVariable) { + X.assignColumn(j, new Vector(x1)); + continue; + } + + for (int i = 0; i < x1.length; i++) { + if (isUnlog) { + if (base == 0) { + x1[i] = FastMath.exp(x1Orig[i]) - a; + } else { + x1[i] = FastMath.pow(base, (x1Orig[i])) - a; + } + } else { + double log = FastMath.log(a + x1Orig[i]); + if (base == 0) { + x1[i] = log; + } else { + x1[i] = log / FastMath.log(base); + } + } + } + + X.assignColumn(j, new Vector(x1)); + } + + return new BoxDataSet(new VerticalDoubleDataBox(X.transpose().toArray()), dataSet.getVariables()); + } + + public static List standardizeData(List dataSets) { + List outList = new ArrayList<>(); + + for (DataSet dataSet : dataSets) { + if (!(dataSet.isContinuous())) { + throw new IllegalArgumentException("Not a continuous data set: " + dataSet.getName()); + } + + Matrix data2 = standardizeData(dataSet.getDoubleData()); + + DataSet dataSet2 = new BoxDataSet(new VerticalDoubleDataBox(data2.transpose().toArray()), dataSet.getVariables()); + outList.add(dataSet2); + } + + return outList; + } + + public static DataSet standardizeData(DataSet dataSet) { + List dataSets = Collections.singletonList(dataSet); + List outList = standardizeData(dataSets); + return outList.get(0); + } + + public static List center(List dataList) { + List dataSets = new ArrayList<>(dataList); + List outList = new ArrayList<>(); + + for (DataSet model : dataSets) { + if (model == null) { + throw new NullPointerException("Missing dataset."); + } + + if (!(model.isContinuous())) { + throw new IllegalArgumentException("Not a continuous data set: " + model.getName()); + } + + Matrix data2 = centerData(model.getDoubleData()); + List list = model.getVariables(); + List list2 = new ArrayList<>(list); + + DataSet dataSet2 = new BoxDataSet(new VerticalDoubleDataBox(data2.transpose().toArray()), list2); + outList.add(dataSet2); + } + + return outList; + } + + public static DataSet discretize(DataSet dataSet, int numCategories, boolean variablesCopied) { + Discretizer discretizer = new Discretizer(dataSet); + discretizer.setVariablesCopied(variablesCopied); + + for (Node node : dataSet.getVariables()) { +// if (dataSet.getVariable(node.getNode()) instanceof ContinuousVariable) { + discretizer.equalIntervals(node, numCategories); +// } + } + + return discretizer.discretize(); + } + + public static DataSet convertNumericalDiscreteToContinuous( + DataSet dataSet) throws NumberFormatException { + List variables = new ArrayList<>(); + + for (Node variable : dataSet.getVariables()) { + if (variable instanceof ContinuousVariable) { + variables.add(variable); + } else { + variables.add(new ContinuousVariable(variable.getName())); + } + } + + DataSet continuousData = new BoxDataSet(new VerticalDoubleDataBox(dataSet.getNumRows(), variables.size()), variables); + + for (int j = 0; j < dataSet.getNumColumns(); j++) { + Node variable = dataSet.getVariable(j); + + if (variable instanceof ContinuousVariable) { + for (int i = 0; i < dataSet.getNumRows(); i++) { + continuousData.setDouble(i, j, dataSet.getDouble(i, j)); + } + } else { + DiscreteVariable discreteVariable = (DiscreteVariable) variable; + + boolean allNumerical = true; + + for (String cat : discreteVariable.getCategories()) { + try { + Double.parseDouble(cat); + } catch (NumberFormatException e) { + allNumerical = false; + break; + } + } + + + for (int i = 0; i < dataSet.getNumRows(); i++) { + int index = dataSet.getInt(i, j); + String catName = discreteVariable.getCategory(index); + double value; + + if (catName.equals("*")) { + value = Double.NaN; + } else { + if (allNumerical) { + value = Double.parseDouble(catName); + } else { + value = index; + } + } + + continuousData.setDouble(i, j, value); + } + } + } + + return continuousData; + } + + public static DataSet concatenate(DataSet dataSet1, DataSet dataSet2) { + List vars1 = dataSet1.getVariables(); + List vars2 = dataSet2.getVariables(); + Map varMap2 = new HashMap<>(); + for (int i = 0; i < vars2.size(); i++) { + varMap2.put(vars2.get(i).getName(), i); + } + int rows1 = dataSet1.getNumRows(); + int rows2 = dataSet2.getNumRows(); + int cols1 = dataSet1.getNumColumns(); + + Matrix concatMatrix = new Matrix(rows1 + rows2, cols1); + Matrix matrix1 = dataSet1.getDoubleData(); + Matrix matrix2 = dataSet2.getDoubleData(); + + for (int i = 0; i < vars1.size(); i++) { + int var2 = varMap2.get(vars1.get(i).getName()); + for (int j = 0; j < rows1; j++) { + concatMatrix.set(j, i, matrix1.get(j, i)); + } + for (int j = 0; j < rows2; j++) { + concatMatrix.set(j + rows1, i, matrix2.get(j, var2)); + } + } + + return new BoxDataSet(new VerticalDoubleDataBox(concatMatrix.transpose().toArray()), vars1); + } + + public static DataSet concatenate(DataSet... dataSets) { + List _dataSets = new ArrayList<>(); + + Collections.addAll(_dataSets, dataSets); + + return concatenate(_dataSets); + } + + // Trying to optimize some. + public static DataSet concatenate(List dataSets) { + int totalSampleSize = 0; + + for (DataSet dataSet : dataSets) { + totalSampleSize += dataSet.getNumRows(); + } + + int numColumns = dataSets.get(0).getNumColumns(); + Matrix allData = new Matrix(totalSampleSize, numColumns); + int q = 0; + int r; + + for (DataSet dataSet : dataSets) { + Matrix _data = dataSet.getDoubleData(); + r = _data.getNumRows(); + + for (int i = 0; i < r; i++) { + for (int j = 0; j < numColumns; j++) { + allData.set(q + i, j, _data.get(i, j)); + } + } + + q += r; + } + + return new BoxDataSet(new VerticalDoubleDataBox(allData.transpose().toArray()), dataSets.get(0).getVariables()); + } + + public static DataSet restrictToMeasured(DataSet fullDataSet) { + List measuredVars = new ArrayList<>(); + List latentVars = new ArrayList<>(); + + for (Node node : fullDataSet.getVariables()) { + if (node.getNodeType() == NodeType.MEASURED) { + measuredVars.add(node); + } else { + latentVars.add(node); + } + } + + return latentVars.isEmpty() ? fullDataSet : fullDataSet.subsetColumns(measuredVars); + } + + /** + * @return a sample without replacement with the given sample size from the given dataset. + */ + public static DataSet getResamplingDataset(DataSet data, int sampleSize) { + int actualSampleSize = data.getNumRows(); + int _size = sampleSize; + if (actualSampleSize < _size) { + _size = actualSampleSize; + } + + List availRows = new ArrayList<>(); + for (int i = 0; i < actualSampleSize; i++) { + availRows.add(i); + } + + RandomUtil.shuffle(availRows); + + List addedRows = new ArrayList<>(); + int[] rows = new int[_size]; + for (int i = 0; i < _size; i++) { + int row = -1; + int index = -1; + while (row == -1 || addedRows.contains(row)) { + index = RandomUtil.getInstance().nextInt(availRows.size()); + row = availRows.get(index); + } + rows[i] = row; + addedRows.add(row); + availRows.remove(index); + } + + int[] cols = new int[data.getNumColumns()]; + for (int i = 0; i < cols.length; i++) cols[i] = i; + + return new BoxDataSet(new VerticalDoubleDataBox(data.getDoubleData().getSelection(rows, cols).transpose().toArray()), data.getVariables()); + } + + /** + * Get dataset sampled without replacement. + * + * @param data original dataset + * @param sampleSize number of data (row) + * @param randomGenerator random number generator + * @return dataset + */ + public static DataSet getResamplingDataset(DataSet data, int sampleSize, RandomGenerator randomGenerator) { + int actualSampleSize = data.getNumRows(); + int _size = sampleSize; + if (actualSampleSize < _size) { + _size = actualSampleSize; + } + + List availRows = new ArrayList<>(); + for (int i = 0; i < actualSampleSize; i++) { + availRows.add(i); + } + + RandomUtil.shuffle(availRows); + + List addedRows = new ArrayList<>(); + int[] rows = new int[_size]; + for (int i = 0; i < _size; i++) { + int row = -1; + int index = -1; + while (row == -1 || addedRows.contains(row)) { + index = randomGenerator.nextInt(availRows.size()); + row = availRows.get(index); + } + rows[i] = row; + addedRows.add(row); + availRows.remove(index); + } + + int[] cols = new int[data.getNumColumns()]; + for (int i = 0; i < cols.length; i++) { + cols[i] = i; + } + + return new BoxDataSet(new VerticalDoubleDataBox(data.getDoubleData().getSelection(rows, cols).transpose().toArray()), data.getVariables()); + } + + /** + * @return a sample with replacement with the given sample size from the given dataset. + */ + public static DataSet getBootstrapSample(DataSet data, int sampleSize) { + int actualSampleSize = data.getNumRows(); + + int[] rows = new int[sampleSize]; + + for (int i = 0; i < rows.length; i++) { + rows[i] = RandomUtil.getInstance().nextInt(actualSampleSize); + } + + int[] cols = new int[data.getNumColumns()]; + for (int i = 0; i < cols.length; i++) cols[i] = i; + + BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox(data.getDoubleData().getSelection(rows, cols).transpose().toArray()), + data.getVariables()); + boxDataSet.setKnowledge(data.getKnowledge()); + return boxDataSet; + } + + /** + * Get dataset sampled with replacement. + * + * @param data original dataset + * @param sampleSize number of data (row) + * @param randomGenerator random number generator + * @return dataset + */ + public static DataSet getBootstrapSample(DataSet data, int sampleSize, RandomGenerator randomGenerator) { + int actualSampleSize = data.getNumRows(); + int[] rows = new int[sampleSize]; + for (int i = 0; i < rows.length; i++) { + rows[i] = randomGenerator.nextInt(actualSampleSize); + } + + int[] cols = new int[data.getNumColumns()]; + for (int i = 0; i < cols.length; i++) { + cols[i] = i; + } + + BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox( + data.getDoubleData().getSelection(rows, cols).transpose().toArray()), + data.getVariables()); + boxDataSet.setKnowledge(data.getKnowledge()); + + return boxDataSet; + } + + public static List split(DataSet data, double percentTest) { + if (percentTest <= 0 || percentTest >= 1) throw new IllegalArgumentException(); + + List rows = new ArrayList<>(); + for (int i = 0; i < data.getNumRows(); i++) rows.add(i); + + RandomUtil.shuffle(rows); + + int split = (int) (rows.size() * percentTest); + + List rows1 = new ArrayList<>(); + List rows2 = new ArrayList<>(); + + for (int i = 0; i < split; i++) { + rows1.add(rows.get(i)); + } + + for (int i = split; i < rows.size(); i++) { + rows2.add(rows.get(i)); + } + + int[] _rows1 = new int[rows1.size()]; + int[] _rows2 = new int[rows2.size()]; + + for (int i = 0; i < rows1.size(); i++) _rows1[i] = rows1.get(i); + for (int i = 0; i < rows2.size(); i++) _rows2[i] = rows2.get(i); + + int[] cols = new int[data.getNumColumns()]; + for (int i = 0; i < cols.length; i++) cols[i] = i; + + BoxDataSet boxDataSet1 = new BoxDataSet(new VerticalDoubleDataBox( + data.getDoubleData().getSelection(_rows1, cols).transpose().toArray()), + data.getVariables()); + + BoxDataSet boxDataSet2 = new BoxDataSet(new VerticalDoubleDataBox( + data.getDoubleData().getSelection(_rows2, cols).transpose().toArray()), + data.getVariables()); + + List ret = new ArrayList<>(); + + ret.add(boxDataSet1); + ret.add(boxDataSet2); + + return ret; + } + + /** + * Subtracts the mean of each column from each datum that column. + */ + public static DataSet center(DataSet data) { + DataSet _data = data.copy(); + + for (int j = 0; j < _data.getNumColumns(); j++) { + double sum = 0.0; + int n = 0; + + for (int i = 0; i < _data.getNumRows(); i++) { + double v = _data.getDouble(i, j); + + if (!Double.isNaN(v)) { + sum += v; + n++; + } + } + + double avg = sum / n; + + for (int i = 0; i < _data.getNumRows(); i++) { + _data.setDouble(i, j, _data.getDouble(i, j) - avg); + } + } + + return _data; + } + + public static DataSet shuffleColumns(DataSet dataModel) { + String name = dataModel.getName(); + int numVariables = dataModel.getNumColumns(); + + List indicesList = new ArrayList<>(); + for (int i = 0; i < numVariables; i++) indicesList.add(i); + RandomUtil.shuffle(indicesList); + + int[] indices = new int[numVariables]; + + for (int i = 0; i < numVariables; i++) { + indices[i] = indicesList.get(i); + } + + DataSet dataSet = dataModel.subsetColumns(indices); + dataSet.setName(name); + return dataSet; + } + + public static List shuffleColumns2(List dataSets) { + List vars = new ArrayList<>(); + + List variables = dataSets.get(0).getVariables(); + RandomUtil.shuffle(variables); + + for (Node node : variables) { + Node _node = dataSets.get(0).getVariable(node.getName()); + + if (_node != null) { + vars.add(_node); + } + } + + List ret = new ArrayList<>(); + + for (DataSet m : dataSets) { + DataSet data = m.subsetColumns(vars); + data.setName(m.getName() + ".reordered"); + ret.add(data); + } + + return ret; + } + + public static ICovarianceMatrix covarianceNonparanormalDrton(DataSet dataSet) { + CovarianceMatrix covMatrix = new CovarianceMatrix(dataSet); + Matrix data = dataSet.getDoubleData(); + int NTHREDS = Runtime.getRuntime().availableProcessors() * 10; + final int EPOCH_COUNT = 100000; + + ExecutorService executor = Executors.newFixedThreadPool(NTHREDS); + int runnableCount = 0; + + for (int _i = 0; _i < dataSet.getNumColumns(); _i++) { + for (int _j = _i; _j < dataSet.getNumColumns(); _j++) { + int i = _i; + int j = _j; + + Runnable worker = () -> { + double tau = StatUtils.kendallsTau(data.getColumn(i).toArray(), data.getColumn(j).toArray()); + covMatrix.setValue(i, j, tau); + covMatrix.setValue(j, i, tau); + }; + + executor.execute(worker); + + if (runnableCount < EPOCH_COUNT) { + runnableCount++; +// System.out.println(runnableCount); + } else { + executor.shutdown(); + try { + // Wait until all threads are finish + boolean b = executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + + if (b) { + System.out.println("Finished all threads"); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + + executor = Executors.newFixedThreadPool(NTHREDS); + runnableCount = 0; + } + } + } + + executor.shutdown(); + + try { + // Wait until all threads are finish + boolean b = executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + + if (b) { + System.out.println("Finished all threads"); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return covMatrix; + } + + public static DataSet getNonparanormalTransformed(DataSet dataSet) { + try { + Matrix data = dataSet.getDoubleData(); + Matrix X = data.like(); + double n = dataSet.getNumRows(); +// delta = 1.0 / (4.0 * FastMath.pow(n, 0.25) * FastMath.sqrt(FastMath.PI * FastMath.log(n))); + + NormalDistribution normalDistribution = new NormalDistribution(); + + double std = Double.NaN; + + for (int j = 0; j < data.getNumColumns(); j++) { + double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); + double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); + + double a2Orig = new AndersonDarlingTest(x1).getASquaredStar(); + + if (dataSet.getVariable(j) instanceof DiscreteVariable) { + X.assignColumn(j, new Vector(x1)); + continue; + } + + double std1 = StatUtils.sd(x1); + double mu1 = StatUtils.mean(x1); + double[] xTransformed = DataUtils.ranks(x1); + + for (int i = 0; i < xTransformed.length; i++) { + xTransformed[i] /= n; + xTransformed[i] = normalDistribution.inverseCumulativeProbability(xTransformed[i]); + } + + if (Double.isNaN(std)) { + std = StatUtils.sd(x1Orig); + } + + for (int i = 0; i < xTransformed.length; i++) { + xTransformed[i] *= std1; + xTransformed[i] += mu1; + } + + double a2Transformed = new AndersonDarlingTest(xTransformed).getASquaredStar(); + + double min = Double.POSITIVE_INFINITY; + double max = Double.NEGATIVE_INFINITY; + + for (double v : xTransformed) { + if (v > max && !Double.isInfinite(v)) { + max = v; + } + + if (v < min && !Double.isInfinite(v)) { + min = v; + } + } + + for (int i = 0; i < xTransformed.length; i++) { + if (xTransformed[i] == Double.POSITIVE_INFINITY) { + xTransformed[i] = max; + } + + if (xTransformed[i] < Double.NEGATIVE_INFINITY) { + xTransformed[i] = min; + } + } + + System.out.println(dataSet.getVariable(j) + ": A^2* = " + a2Orig + " transformed A^2* = " + a2Transformed); + +// if (a2Transformed < a2Orig) { + X.assignColumn(j, new Vector(xTransformed)); +// } else { +// X.assignColumn(j, new Vector(x1Orig)); +// } + } + + return new BoxDataSet(new VerticalDoubleDataBox(X.transpose().toArray()), dataSet.getVariables()); + } catch (OutOfRangeException e) { + e.printStackTrace(); + return dataSet; + } + } + + public static DataSet removeConstantColumns(DataSet dataSet) { + int columns = dataSet.getNumColumns(); + int rows = dataSet.getNumRows(); + if (rows == 0) { + return dataSet; + } + + List keepCols = new ArrayList<>(); + + for (int j = 0; j < columns; j++) { + Object previous = dataSet.getObject(0, j); + boolean constant = true; + for (int row = 1; row < rows; row++) { + Object current = dataSet.getObject(row, j); + if (!previous.equals(current)) { + constant = false; + break; + } + + if (previous instanceof Double && current instanceof Double) { + double _previouw = (Double) previous; + double _current = (Double) current; + + if (Double.isNaN(_previouw) && Double.isNaN(_current)) { + constant = false; + break; + } + } + } + + if (!constant) keepCols.add(j); + } + + int[] newCols = new int[keepCols.size()]; + for (int j = 0; j < keepCols.size(); j++) newCols[j] = keepCols.get(j); + + return dataSet.subsetColumns(newCols); + } + + public static List getConstantColumns(DataSet dataSet) { + List constantColumns = new ArrayList<>(); + int rows = dataSet.getNumRows(); + + for (int j = 0; j < dataSet.getNumColumns(); j++) { + Object first = dataSet.getObject(0, j); + boolean constant = true; + + for (int row = 1; row < rows; row++) { + Object current = dataSet.getObject(row, j); + if (!first.equals(current)) { + constant = false; + break; + } + } + + if (constant) { + constantColumns.add(dataSet.getVariable(j)); + } + } + + return constantColumns; + } + + public static DataSet removeRandomColumns(DataSet dataSet, double aDouble) { + int columns = dataSet.getNumColumns(); + int rows = dataSet.getNumRows(); + if (rows == 0) { + return dataSet; + } + + List keepCols = new ArrayList<>(); + + for (int j = 0; j < columns; j++) { + if (RandomUtil.getInstance().nextDouble() > aDouble) { + keepCols.add(j); + } + } + + int[] newCols = new int[keepCols.size()]; + for (int j = 0; j < keepCols.size(); j++) newCols[j] = keepCols.get(j); + + return dataSet.subsetColumns(newCols); + } + + public static Matrix standardizeData(Matrix data) { + Matrix data2 = data.copy(); + + for (int j = 0; j < data2.getNumColumns(); j++) { + double sum = 0.0; + + for (int i = 0; i < data2.getNumRows(); i++) { + sum += data2.get(i, j); + } + + double mean = sum / data.getNumRows(); + + for (int i = 0; i < data.getNumRows(); i++) { + data2.set(i, j, data.get(i, j) - mean); + } + + double norm = 0.0; + + for (int i = 0; i < data.getNumRows(); i++) { + double v = data2.get(i, j); + norm += v * v; + } + + norm = FastMath.sqrt(norm / (data.getNumRows() - 1)); + + for (int i = 0; i < data.getNumRows(); i++) { + data2.set(i, j, data2.get(i, j) / norm); + } + } + + return data2; + } + + public static double[] standardizeData(double[] data) { + double[] data2 = new double[data.length]; + + double sum = 0.0; + + for (double d : data) { + sum += d; + } + + double mean = sum / data.length; + + for (int i = 0; i < data.length; i++) { + data2[i] = data[i] - mean; + } + + double norm = 0.0; + + for (double v : data2) { + norm += v * v; + } + + norm = FastMath.sqrt(norm / (data2.length - 1)); + + for (int i = 0; i < data2.length; i++) { + data2[i] = data2[i] / norm; + } + + return data2; + } + + public static DoubleArrayList standardizeData(DoubleArrayList data) { + DoubleArrayList data2 = new DoubleArrayList(data.size()); + + double sum = 0.0; + + for (int i = 0; i < data.size(); i++) { + sum += data.get(i); + } + + double mean = sum / data.size(); + + for (int i = 0; i < data.size(); i++) { + data2.add(data.get(i) - mean); + } + + double norm = 0.0; + + for (int i = 0; i < data2.size(); i++) { + double v = data2.get(i); + norm += v * v; + } + + norm = FastMath.sqrt(norm / (data2.size() - 1)); + + for (int i = 0; i < data2.size(); i++) { + data2.set(i, data2.get(i) / norm); + } + + return data2; + } + + public static double[] center(double[] d) { + double sum = 0.0; + + for (double v : d) { + sum += v; + } + + double mean = sum / d.length; + double[] d2 = new double[d.length]; + + for (int i = 0; i < d.length; i++) { + d2[i] = d[i] - mean; + } + + return d2; + } + + public static Matrix centerData(Matrix data) { + Matrix data2 = data.copy(); + + for (int j = 0; j < data2.getNumColumns(); j++) { + double sum = 0.0; + + for (int i = 0; i < data2.getNumRows(); i++) { + sum += data2.get(i, j); + } + + double mean = sum / data.getNumRows(); + + for (int i = 0; i < data.getNumRows(); i++) { + data2.set(i, j, data.get(i, j) - mean); + } + } + + return data2; + } + + public static Matrix concatenate(Matrix... dataSets) { + int totalSampleSize = 0; + + for (Matrix dataSet : dataSets) { + totalSampleSize += dataSet.getNumRows(); + } + + int numColumns = dataSets[0].getNumColumns(); + Matrix allData = new Matrix(totalSampleSize, numColumns); + int q = 0; + int r; + + for (Matrix dataSet : dataSets) { + r = dataSet.getNumRows(); + + for (int i = 0; i < r; i++) { + for (int j = 0; j < numColumns; j++) { + allData.set(q + i, j, dataSet.get(i, j)); + } + } + + q += r; + } + + return allData; + } + + /** + * @return a sample with replacement with the given sample size from the given dataset. + */ + public static Matrix getBootstrapSample(Matrix data, int sampleSize) { + int actualSampleSize = data.getNumRows(); + + int[] rows = new int[sampleSize]; + + for (int i = 0; i < rows.length; i++) { + rows[i] = RandomUtil.getInstance().nextInt(actualSampleSize); + } + + int[] cols = new int[data.getNumColumns()]; + for (int i = 0; i < cols.length; i++) cols[i] = i; + + return data.getSelection(rows, cols); + } + + public static void copyColumn(Node node, DataSet source, DataSet dest) { + int sourceColumn = source.getColumn(node); + int destColumn = dest.getColumn(node); + if (sourceColumn < 0) { + throw new NullPointerException("The given node was not in the source dataset"); + } + if (destColumn < 0) { + throw new NullPointerException("The given node was not in the destination dataset"); + } + int sourceRows = source.getNumRows(); + int destRows = dest.getNumRows(); + if (node instanceof ContinuousVariable) { + for (int i = 0; i < destRows && i < sourceRows; i++) { + dest.setDouble(i, destColumn, source.getDouble(i, sourceColumn)); + } + } else if (node instanceof DiscreteVariable) { + for (int i = 0; i < destRows && i < sourceRows; i++) { + dest.setInt(i, destColumn, source.getInt(i, sourceColumn)); + } + } else { + throw new IllegalArgumentException("The given variable most be discrete or continuous"); + } + } + + /** + * Adds missing data values to cases in accordance with probabilities specified in a double array which has as many + * elements as there are columns in the input dataset. Hence, if the first element of the array of probabilities is + * alpha, then the first column will contain a -99 (or other missing value code) in a given case with probability + * alpha. This method will be useful in generating datasets which can be used to test algorithm that handle missing + * data and/or latent variables. Author: Frank Wimberly + * + * @param inData The data to which random missing data is to be added. + * @param probs The probability of adding missing data to each column. + * @return The new data sets with missing data added. + */ + public static DataSet addMissingData( + DataSet inData, double[] probs) { + DataSet outData; + + outData = inData.copy(); + + if (probs.length != outData.getNumColumns()) { + throw new IllegalArgumentException( + "Wrong number of elements in prob array"); + } + + for (double prob : probs) { + if (prob < 0.0 || prob > 1.0) { + throw new IllegalArgumentException("Probability out of range"); + } + } + + for (int j = 0; j < outData.getNumColumns(); j++) { + Node node = outData.getVariable(j); + + if (node instanceof ContinuousVariable) { + for (int i = 0; i < outData.getNumRows(); i++) { + if (RandomUtil.getInstance().nextDouble() < probs[j]) { + outData.setDouble(i, j, Double.NaN); + } + } + } else if (node instanceof DiscreteVariable) { + for (int i = 0; i < outData.getNumRows(); i++) { + if (RandomUtil.getInstance().nextDouble() < probs[j]) { + outData.setInt(i, j, -99); + } + } + } + } + + return outData; + } + + public static DataSet replaceMissingWithRandom(DataSet inData) { + DataSet outData; + + try { + outData = new MarshalledObject<>(inData).get(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + for (int j = 0; j < outData.getNumColumns(); j++) { + Node variable = outData.getVariable(j); + + if (variable instanceof DiscreteVariable) { + List values = new ArrayList<>(); + + for (int i = 0; i < outData.getNumRows(); i++) { + int value = outData.getInt(i, j); + if (value == -99) continue; + values.add(value); + } + + Collections.sort(values); + + for (int i = 0; i < outData.getNumRows(); i++) { + if (outData.getInt(i, j) == -99) { + int value = RandomUtil.getInstance().nextInt(values.size()); + outData.setInt(i, j, values.get(value)); + } + } + } else { + double min = Double.POSITIVE_INFINITY; + double max = Double.NEGATIVE_INFINITY; + + for (int i = 0; i < outData.getNumRows(); i++) { + double value = outData.getDouble(i, j); + if (value < min) min = value; + if (value > max) max = value; + } + + for (int i = 0; i < outData.getNumRows(); i++) { + double random = RandomUtil.getInstance().nextDouble(); + outData.setDouble(i, j, min + random * (max - min)); + } + } + } + + return outData; + } +} + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java index 27660ba7da..e82d7ad975 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DataUtils.java @@ -21,25 +21,16 @@ package edu.cmu.tetrad.data; -import cern.colt.list.DoubleArrayList; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.graph.NodeType; import edu.cmu.tetrad.util.Vector; import edu.cmu.tetrad.util.*; -import org.apache.commons.math3.distribution.NormalDistribution; -import org.apache.commons.math3.exception.OutOfRangeException; import org.apache.commons.math3.linear.BlockRealMatrix; import org.apache.commons.math3.linear.RealMatrix; -import org.apache.commons.math3.random.RandomGenerator; import org.apache.commons.math3.util.FastMath; -import java.rmi.MarshalledObject; import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.TimeUnit; /** * Some static utility methods for dealing with data sets. @@ -48,32 +39,12 @@ */ public final class DataUtils { - - public static void copyColumn(Node node, DataSet source, DataSet dest) { - int sourceColumn = source.getColumn(node); - int destColumn = dest.getColumn(node); - if (sourceColumn < 0) { - throw new NullPointerException("The given node was not in the source dataset"); - } - if (destColumn < 0) { - throw new NullPointerException("The given node was not in the destination dataset"); - } - int sourceRows = source.getNumRows(); - int destRows = dest.getNumRows(); - if (node instanceof ContinuousVariable) { - for (int i = 0; i < destRows && i < sourceRows; i++) { - dest.setDouble(i, destColumn, source.getDouble(i, sourceColumn)); - } - } else if (node instanceof DiscreteVariable) { - for (int i = 0; i < destRows && i < sourceRows; i++) { - dest.setInt(i, destColumn, source.getInt(i, sourceColumn)); - } - } else { - throw new IllegalArgumentException("The given variable most be discrete or continuous"); - } + /** + * Private constructor to prevent instantiation. + */ + private DataUtils() { } - /** * States whether the given column of the given data set is binary. * @@ -113,104 +84,6 @@ public static String defaultCategory(int index) { return Integer.toString(index); } - /** - * Adds missing data values to cases in accordance with probabilities specified in a double array which has as many - * elements as there are columns in the input dataset. Hence, if the first element of the array of probabilities is - * alpha, then the first column will contain a -99 (or other missing value code) in a given case with probability - * alpha. This method will be useful in generating datasets which can be used to test algorithm that handle missing - * data and/or latent variables. Author: Frank Wimberly - * - * @param inData The data to which random missing data is to be added. - * @param probs The probability of adding missing data to each column. - * @return The new data sets with missing data added. - */ - public static DataSet addMissingData( - DataSet inData, double[] probs) { - DataSet outData; - - outData = inData.copy(); - - if (probs.length != outData.getNumColumns()) { - throw new IllegalArgumentException( - "Wrong number of elements in prob array"); - } - - for (double prob : probs) { - if (prob < 0.0 || prob > 1.0) { - throw new IllegalArgumentException("Probability out of range"); - } - } - - for (int j = 0; j < outData.getNumColumns(); j++) { - Node node = outData.getVariable(j); - - if (node instanceof ContinuousVariable) { - for (int i = 0; i < outData.getNumRows(); i++) { - if (RandomUtil.getInstance().nextDouble() < probs[j]) { - outData.setDouble(i, j, Double.NaN); - } - } - } else if (node instanceof DiscreteVariable) { - for (int i = 0; i < outData.getNumRows(); i++) { - if (RandomUtil.getInstance().nextDouble() < probs[j]) { - outData.setInt(i, j, -99); - } - } - } - } - - return outData; - } - - public static DataSet replaceMissingWithRandom(DataSet inData) { - DataSet outData; - - try { - outData = new MarshalledObject<>(inData).get(); - } catch (Exception e) { - throw new RuntimeException(e); - } - - for (int j = 0; j < outData.getNumColumns(); j++) { - Node variable = outData.getVariable(j); - - if (variable instanceof DiscreteVariable) { - List values = new ArrayList<>(); - - for (int i = 0; i < outData.getNumRows(); i++) { - int value = outData.getInt(i, j); - if (value == -99) continue; - values.add(value); - } - - Collections.sort(values); - - for (int i = 0; i < outData.getNumRows(); i++) { - if (outData.getInt(i, j) == -99) { - int value = RandomUtil.getInstance().nextInt(values.size()); - outData.setInt(i, j, values.get(value)); - } - } - } else { - double min = Double.POSITIVE_INFINITY; - double max = Double.NEGATIVE_INFINITY; - - for (int i = 0; i < outData.getNumRows(); i++) { - double value = outData.getDouble(i, j); - if (value < min) min = value; - if (value > max) max = value; - } - - for (int i = 0; i < outData.getNumRows(); i++) { - double random = RandomUtil.getInstance().nextDouble(); - outData.setDouble(i, j, min + random * (max - min)); - } - } - } - - return outData; - } - /** * A discrete data set used to construct some other serializable instances. */ @@ -263,237 +136,6 @@ public static boolean containsMissingValue(DataSet data) { return false; } - /** - * Log or unlog data - */ - public static DataSet logData(DataSet dataSet, double a, boolean isUnlog, int base) { - Matrix data = dataSet.getDoubleData(); - Matrix X = data.like(); - - for (int j = 0; j < data.getNumColumns(); j++) { - double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); - double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); - - if (dataSet.getVariable(j) instanceof DiscreteVariable) { - X.assignColumn(j, new Vector(x1)); - continue; - } - - for (int i = 0; i < x1.length; i++) { - if (isUnlog) { - if (base == 0) { - x1[i] = FastMath.exp(x1Orig[i]) - a; - } else { - x1[i] = FastMath.pow(base, (x1Orig[i])) - a; - } - } else { - double log = FastMath.log(a + x1Orig[i]); - if (base == 0) { - x1[i] = log; - } else { - x1[i] = log / FastMath.log(base); - } - } - } - - X.assignColumn(j, new Vector(x1)); - } - - return new BoxDataSet(new VerticalDoubleDataBox(X.transpose().toArray()), dataSet.getVariables()); - } - - - public static Matrix standardizeData(Matrix data) { - Matrix data2 = data.copy(); - - for (int j = 0; j < data2.getNumColumns(); j++) { - double sum = 0.0; - - for (int i = 0; i < data2.getNumRows(); i++) { - sum += data2.get(i, j); - } - - double mean = sum / data.getNumRows(); - - for (int i = 0; i < data.getNumRows(); i++) { - data2.set(i, j, data.get(i, j) - mean); - } - - double norm = 0.0; - - for (int i = 0; i < data.getNumRows(); i++) { - double v = data2.get(i, j); - norm += v * v; - } - - norm = FastMath.sqrt(norm / (data.getNumRows() - 1)); - - for (int i = 0; i < data.getNumRows(); i++) { - data2.set(i, j, data2.get(i, j) / norm); - } - } - - return data2; - } - - public static double[] standardizeData(double[] data) { - double[] data2 = new double[data.length]; - - double sum = 0.0; - - for (double d : data) { - sum += d; - } - - double mean = sum / data.length; - - for (int i = 0; i < data.length; i++) { - data2[i] = data[i] - mean; - } - - double norm = 0.0; - - for (double v : data2) { - norm += v * v; - } - - norm = FastMath.sqrt(norm / (data2.length - 1)); - - for (int i = 0; i < data2.length; i++) { - data2[i] = data2[i] / norm; - } - - return data2; - } - - public static DoubleArrayList standardizeData(DoubleArrayList data) { - DoubleArrayList data2 = new DoubleArrayList(data.size()); - - double sum = 0.0; - - for (int i = 0; i < data.size(); i++) { - sum += data.get(i); - } - - double mean = sum / data.size(); - - for (int i = 0; i < data.size(); i++) { - data2.add(data.get(i) - mean); - } - - double norm = 0.0; - - for (int i = 0; i < data2.size(); i++) { - double v = data2.get(i); - norm += v * v; - } - - norm = FastMath.sqrt(norm / (data2.size() - 1)); - - for (int i = 0; i < data2.size(); i++) { - data2.set(i, data2.get(i) / norm); - } - - return data2; - } - - public static List standardizeData(List dataSets) { - List outList = new ArrayList<>(); - - for (DataSet dataSet : dataSets) { - if (!(dataSet.isContinuous())) { - throw new IllegalArgumentException("Not a continuous data set: " + dataSet.getName()); - } - - Matrix data2 = DataUtils.standardizeData(dataSet.getDoubleData()); - - DataSet dataSet2 = new BoxDataSet(new VerticalDoubleDataBox(data2.transpose().toArray()), dataSet.getVariables()); - outList.add(dataSet2); - } - - return outList; - } - - public static DataSet standardizeData(DataSet dataSet) { - List dataSets = Collections.singletonList(dataSet); - List outList = DataUtils.standardizeData(dataSets); - return outList.get(0); - } - - public static double[] center(double[] d) { - double sum = 0.0; - - for (double v : d) { - sum += v; - } - - double mean = sum / d.length; - double[] d2 = new double[d.length]; - - for (int i = 0; i < d.length; i++) { - d2[i] = d[i] - mean; - } - - return d2; - } - - public static Matrix centerData(Matrix data) { - Matrix data2 = data.copy(); - - for (int j = 0; j < data2.getNumColumns(); j++) { - double sum = 0.0; - - for (int i = 0; i < data2.getNumRows(); i++) { - sum += data2.get(i, j); - } - - double mean = sum / data.getNumRows(); - - for (int i = 0; i < data.getNumRows(); i++) { - data2.set(i, j, data.get(i, j) - mean); - } - } - - return data2; - } - - public static List center(List dataList) { - List dataSets = new ArrayList<>(dataList); - List outList = new ArrayList<>(); - - for (DataSet model : dataSets) { - if (model == null) { - throw new NullPointerException("Missing dataset."); - } - - if (!(model.isContinuous())) { - throw new IllegalArgumentException("Not a continuous data set: " + model.getName()); - } - - Matrix data2 = DataUtils.centerData(model.getDoubleData()); - List list = model.getVariables(); - List list2 = new ArrayList<>(list); - - DataSet dataSet2 = new BoxDataSet(new VerticalDoubleDataBox(data2.transpose().toArray()), list2); - outList.add(dataSet2); - } - - return outList; - } - - - public static DataSet discretize(DataSet dataSet, int numCategories, boolean variablesCopied) { - Discretizer discretizer = new Discretizer(dataSet); - discretizer.setVariablesCopied(variablesCopied); - - for (Node node : dataSet.getVariables()) { -// if (dataSet.getVariable(node.getNode()) instanceof ContinuousVariable) { - discretizer.equalIntervals(node, numCategories); -// } - } - - return discretizer.discretize(); - } public static List createContinuousVariables(String[] varNames) { List variables = new LinkedList<>(); @@ -640,173 +282,6 @@ public static Matrix subMatrix(ICovarianceMatrix m, Map indexMap, return m.getSelection(indices, indices); } - public static DataSet convertNumericalDiscreteToContinuous( - DataSet dataSet) throws NumberFormatException { - List variables = new ArrayList<>(); - - for (Node variable : dataSet.getVariables()) { - if (variable instanceof ContinuousVariable) { - variables.add(variable); - } else { - variables.add(new ContinuousVariable(variable.getName())); - } - } - - DataSet continuousData = new BoxDataSet(new VerticalDoubleDataBox(dataSet.getNumRows(), variables.size()), variables); - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - Node variable = dataSet.getVariable(j); - - if (variable instanceof ContinuousVariable) { - for (int i = 0; i < dataSet.getNumRows(); i++) { - continuousData.setDouble(i, j, dataSet.getDouble(i, j)); - } - } else { - DiscreteVariable discreteVariable = (DiscreteVariable) variable; - - boolean allNumerical = true; - - for (String cat : discreteVariable.getCategories()) { - try { - Double.parseDouble(cat); - } catch (NumberFormatException e) { - allNumerical = false; - break; - } - } - - - for (int i = 0; i < dataSet.getNumRows(); i++) { - int index = dataSet.getInt(i, j); - String catName = discreteVariable.getCategory(index); - double value; - - if (catName.equals("*")) { - value = Double.NaN; - } else { - if (allNumerical) { - value = Double.parseDouble(catName); - } else { - value = index; - } - } - - continuousData.setDouble(i, j, value); - } - } - } - - return continuousData; - } - - public static DataSet concatenate(DataSet dataSet1, DataSet dataSet2) { - List vars1 = dataSet1.getVariables(); - List vars2 = dataSet2.getVariables(); - Map varMap2 = new HashMap<>(); - for (int i = 0; i < vars2.size(); i++) { - varMap2.put(vars2.get(i).getName(), i); - } - int rows1 = dataSet1.getNumRows(); - int rows2 = dataSet2.getNumRows(); - int cols1 = dataSet1.getNumColumns(); - - Matrix concatMatrix = new Matrix(rows1 + rows2, cols1); - Matrix matrix1 = dataSet1.getDoubleData(); - Matrix matrix2 = dataSet2.getDoubleData(); - - for (int i = 0; i < vars1.size(); i++) { - int var2 = varMap2.get(vars1.get(i).getName()); - for (int j = 0; j < rows1; j++) { - concatMatrix.set(j, i, matrix1.get(j, i)); - } - for (int j = 0; j < rows2; j++) { - concatMatrix.set(j + rows1, i, matrix2.get(j, var2)); - } - } - - return new BoxDataSet(new VerticalDoubleDataBox(concatMatrix.transpose().toArray()), vars1); - } - - - public static DataSet concatenate(DataSet... dataSets) { - List _dataSets = new ArrayList<>(); - - Collections.addAll(_dataSets, dataSets); - - return DataUtils.concatenate(_dataSets); - } - - public static Matrix concatenate(Matrix... dataSets) { - int totalSampleSize = 0; - - for (Matrix dataSet : dataSets) { - totalSampleSize += dataSet.getNumRows(); - } - - int numColumns = dataSets[0].getNumColumns(); - Matrix allData = new Matrix(totalSampleSize, numColumns); - int q = 0; - int r; - - for (Matrix dataSet : dataSets) { - r = dataSet.getNumRows(); - - for (int i = 0; i < r; i++) { - for (int j = 0; j < numColumns; j++) { - allData.set(q + i, j, dataSet.get(i, j)); - } - } - - q += r; - } - - return allData; - } - - // Trying to optimize some. - public static DataSet concatenate(List dataSets) { - int totalSampleSize = 0; - - for (DataSet dataSet : dataSets) { - totalSampleSize += dataSet.getNumRows(); - } - - int numColumns = dataSets.get(0).getNumColumns(); - Matrix allData = new Matrix(totalSampleSize, numColumns); - int q = 0; - int r; - - for (DataSet dataSet : dataSets) { - Matrix _data = dataSet.getDoubleData(); - r = _data.getNumRows(); - - for (int i = 0; i < r; i++) { - for (int j = 0; j < numColumns; j++) { - allData.set(q + i, j, _data.get(i, j)); - } - } - - q += r; - } - - return new BoxDataSet(new VerticalDoubleDataBox(allData.transpose().toArray()), dataSets.get(0).getVariables()); - } - - public static DataSet restrictToMeasured(DataSet fullDataSet) { - List measuredVars = new ArrayList<>(); - List latentVars = new ArrayList<>(); - - for (Node node : fullDataSet.getVariables()) { - if (node.getNodeType() == NodeType.MEASURED) { - measuredVars.add(node); - } else { - latentVars.add(node); - } - } - - return latentVars.isEmpty() ? fullDataSet : fullDataSet.subsetColumns(measuredVars); - } - public static Vector means(Matrix data) { Vector means = new Vector(data.getNumColumns()); @@ -1002,463 +477,6 @@ public static DataSet choleskySimulation(CovarianceMatrix cov) { return dataSet; } - /** - * @return a sample with replacement with the given sample size from the given dataset. - */ - public static Matrix getBootstrapSample(Matrix data, int sampleSize) { - int actualSampleSize = data.getNumRows(); - - int[] rows = new int[sampleSize]; - - for (int i = 0; i < rows.length; i++) { - rows[i] = RandomUtil.getInstance().nextInt(actualSampleSize); - } - - int[] cols = new int[data.getNumColumns()]; - for (int i = 0; i < cols.length; i++) cols[i] = i; - - return data.getSelection(rows, cols); - } - - /** - * @return a sample without replacement with the given sample size from the given dataset. - */ - public static DataSet getResamplingDataset(DataSet data, int sampleSize) { - int actualSampleSize = data.getNumRows(); - int _size = sampleSize; - if (actualSampleSize < _size) { - _size = actualSampleSize; - } - - List availRows = new ArrayList<>(); - for (int i = 0; i < actualSampleSize; i++) { - availRows.add(i); - } - - RandomUtil.shuffle(availRows); - - List addedRows = new ArrayList<>(); - int[] rows = new int[_size]; - for (int i = 0; i < _size; i++) { - int row = -1; - int index = -1; - while (row == -1 || addedRows.contains(row)) { - index = RandomUtil.getInstance().nextInt(availRows.size()); - row = availRows.get(index); - } - rows[i] = row; - addedRows.add(row); - availRows.remove(index); - } - - int[] cols = new int[data.getNumColumns()]; - for (int i = 0; i < cols.length; i++) cols[i] = i; - - return new BoxDataSet(new VerticalDoubleDataBox(data.getDoubleData().getSelection(rows, cols).transpose().toArray()), data.getVariables()); - } - - /** - * Get dataset sampled without replacement. - * - * @param data original dataset - * @param sampleSize number of data (row) - * @param randomGenerator random number generator - * @return dataset - */ - public static DataSet getResamplingDataset(DataSet data, int sampleSize, RandomGenerator randomGenerator) { - int actualSampleSize = data.getNumRows(); - int _size = sampleSize; - if (actualSampleSize < _size) { - _size = actualSampleSize; - } - - List availRows = new ArrayList<>(); - for (int i = 0; i < actualSampleSize; i++) { - availRows.add(i); - } - - RandomUtil.shuffle(availRows); - - List addedRows = new ArrayList<>(); - int[] rows = new int[_size]; - for (int i = 0; i < _size; i++) { - int row = -1; - int index = -1; - while (row == -1 || addedRows.contains(row)) { - index = randomGenerator.nextInt(availRows.size()); - row = availRows.get(index); - } - rows[i] = row; - addedRows.add(row); - availRows.remove(index); - } - - int[] cols = new int[data.getNumColumns()]; - for (int i = 0; i < cols.length; i++) { - cols[i] = i; - } - - return new BoxDataSet(new VerticalDoubleDataBox(data.getDoubleData().getSelection(rows, cols).transpose().toArray()), data.getVariables()); - } - - /** - * @return a sample with replacement with the given sample size from the given dataset. - */ - public static DataSet getBootstrapSample(DataSet data, int sampleSize) { - int actualSampleSize = data.getNumRows(); - - int[] rows = new int[sampleSize]; - - for (int i = 0; i < rows.length; i++) { - rows[i] = RandomUtil.getInstance().nextInt(actualSampleSize); - } - - int[] cols = new int[data.getNumColumns()]; - for (int i = 0; i < cols.length; i++) cols[i] = i; - - BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox(data.getDoubleData().getSelection(rows, cols).transpose().toArray()), - data.getVariables()); - boxDataSet.setKnowledge(data.getKnowledge()); - return boxDataSet; - } - - /** - * Get dataset sampled with replacement. - * - * @param data original dataset - * @param sampleSize number of data (row) - * @param randomGenerator random number generator - * @return dataset - */ - public static DataSet getBootstrapSample(DataSet data, int sampleSize, RandomGenerator randomGenerator) { - int actualSampleSize = data.getNumRows(); - int[] rows = new int[sampleSize]; - for (int i = 0; i < rows.length; i++) { - rows[i] = randomGenerator.nextInt(actualSampleSize); - } - - int[] cols = new int[data.getNumColumns()]; - for (int i = 0; i < cols.length; i++) { - cols[i] = i; - } - - BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox( - data.getDoubleData().getSelection(rows, cols).transpose().toArray()), - data.getVariables()); - boxDataSet.setKnowledge(data.getKnowledge()); - - return boxDataSet; - } - - public static List split(DataSet data, double percentTest) { - if (percentTest <= 0 || percentTest >= 1) throw new IllegalArgumentException(); - - List rows = new ArrayList<>(); - for (int i = 0; i < data.getNumRows(); i++) rows.add(i); - - RandomUtil.shuffle(rows); - - int split = (int) (rows.size() * percentTest); - - List rows1 = new ArrayList<>(); - List rows2 = new ArrayList<>(); - - for (int i = 0; i < split; i++) { - rows1.add(rows.get(i)); - } - - for (int i = split; i < rows.size(); i++) { - rows2.add(rows.get(i)); - } - - int[] _rows1 = new int[rows1.size()]; - int[] _rows2 = new int[rows2.size()]; - - for (int i = 0; i < rows1.size(); i++) _rows1[i] = rows1.get(i); - for (int i = 0; i < rows2.size(); i++) _rows2[i] = rows2.get(i); - - int[] cols = new int[data.getNumColumns()]; - for (int i = 0; i < cols.length; i++) cols[i] = i; - - BoxDataSet boxDataSet1 = new BoxDataSet(new VerticalDoubleDataBox( - data.getDoubleData().getSelection(_rows1, cols).transpose().toArray()), - data.getVariables()); - - BoxDataSet boxDataSet2 = new BoxDataSet(new VerticalDoubleDataBox( - data.getDoubleData().getSelection(_rows2, cols).transpose().toArray()), - data.getVariables()); - - List ret = new ArrayList<>(); - - ret.add(boxDataSet1); - ret.add(boxDataSet2); - - return ret; - } - - /** - * Subtracts the mean of each column from each datum that column. - */ - public static DataSet center(DataSet data) { - DataSet _data = data.copy(); - - for (int j = 0; j < _data.getNumColumns(); j++) { - double sum = 0.0; - int n = 0; - - for (int i = 0; i < _data.getNumRows(); i++) { - double v = _data.getDouble(i, j); - - if (!Double.isNaN(v)) { - sum += v; - n++; - } - } - - double avg = sum / n; - - for (int i = 0; i < _data.getNumRows(); i++) { - _data.setDouble(i, j, _data.getDouble(i, j) - avg); - } - } - - return _data; - } - - public static DataSet shuffleColumns(DataSet dataModel) { - String name = dataModel.getName(); - int numVariables = dataModel.getNumColumns(); - - List indicesList = new ArrayList<>(); - for (int i = 0; i < numVariables; i++) indicesList.add(i); - RandomUtil.shuffle(indicesList); - - int[] indices = new int[numVariables]; - - for (int i = 0; i < numVariables; i++) { - indices[i] = indicesList.get(i); - } - - DataSet dataSet = dataModel.subsetColumns(indices); - dataSet.setName(name); - return dataSet; - } - - public static List shuffleColumns2(List dataSets) { - List vars = new ArrayList<>(); - - List variables = dataSets.get(0).getVariables(); - RandomUtil.shuffle(variables); - - for (Node node : variables) { - Node _node = dataSets.get(0).getVariable(node.getName()); - - if (_node != null) { - vars.add(_node); - } - } - - List ret = new ArrayList<>(); - - for (DataSet m : dataSets) { - DataSet data = m.subsetColumns(vars); - data.setName(m.getName() + ".reordered"); - ret.add(data); - } - - return ret; - } - - - public static ICovarianceMatrix covarianceNonparanormalDrton(DataSet dataSet) { - CovarianceMatrix covMatrix = new CovarianceMatrix(dataSet); - Matrix data = dataSet.getDoubleData(); - int NTHREDS = Runtime.getRuntime().availableProcessors() * 10; - final int EPOCH_COUNT = 100000; - - ExecutorService executor = Executors.newFixedThreadPool(NTHREDS); - int runnableCount = 0; - - for (int _i = 0; _i < dataSet.getNumColumns(); _i++) { - for (int _j = _i; _j < dataSet.getNumColumns(); _j++) { - int i = _i; - int j = _j; - - Runnable worker = () -> { - double tau = StatUtils.kendallsTau(data.getColumn(i).toArray(), data.getColumn(j).toArray()); - covMatrix.setValue(i, j, tau); - covMatrix.setValue(j, i, tau); - }; - - executor.execute(worker); - - if (runnableCount < EPOCH_COUNT) { - runnableCount++; -// System.out.println(runnableCount); - } else { - executor.shutdown(); - try { - // Wait until all threads are finish - boolean b = executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); - - if (b) { - System.out.println("Finished all threads"); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - - executor = Executors.newFixedThreadPool(NTHREDS); - runnableCount = 0; - } - } - } - - executor.shutdown(); - - try { - // Wait until all threads are finish - boolean b = executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); - - if (b) { - System.out.println("Finished all threads"); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return covMatrix; - } - -// function (x, npn.func = "shrinkage", npn.thresh = NULL, verbose = TRUE) -// { -// gcinfo(FALSE) -// n = nrow(x) -// d = ncol(x) -// x.col = colnames(x) -// x.row = rownames(x) -// if (npn.func == "shrinkage") { -// if (verbose) -// cat("Conducting the nonparanormal (npn) transformation via shrunkun ECDF....") -// x = qnorm(apply(x, 2, rank)/(n + 1)) -// x = x/sd(x[, 1]) -// if (verbose) -// cat("done.\n") -// rm(n, d, verbose) -// gc() -// colnames(x) = x.col -// rownames(x) = x.row -// } -// if (npn.func == "truncation") { -// if (verbose) -// cat("Conducting nonparanormal (npn) transformation via truncated ECDF....") -// if (is.null(npn.thresh)) -// npn.thresh = 1/(4 * (n^0.25) * sqrt(pi * log(n))) -// x = qnorm(pmin(pmax(apply(x, 2, rank)/n, npn.thresh), -// 1 - npn.thresh)) -// x = x/sd(x[, 1]) -// if (verbose) -// cat("done.\n") -// rm(n, d, npn.thresh, verbose) -// gc() -// colnames(x) = x.col -// rownames(x) = x.row -// } -// if (npn.func == "skeptic") { -// if (verbose) -// cat("Conducting nonparanormal (npn) transformation via skeptic....") -// x = 2 * sin(pi/6 * cor(x, method = "spearman")) -// if (verbose) -// cat("done.\n") -// rm(n, d, verbose) -// gc() -// colnames(x) = x.col -// rownames(x) = x.col -// } -// return(x) -// } - - public static DataSet getNonparanormalTransformed(DataSet dataSet) { - try { - Matrix data = dataSet.getDoubleData(); - Matrix X = data.like(); - double n = dataSet.getNumRows(); -// delta = 1.0 / (4.0 * FastMath.pow(n, 0.25) * FastMath.sqrt(FastMath.PI * FastMath.log(n))); - - NormalDistribution normalDistribution = new NormalDistribution(); - - double std = Double.NaN; - - for (int j = 0; j < data.getNumColumns(); j++) { - double[] x1Orig = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); - double[] x1 = Arrays.copyOf(data.getColumn(j).toArray(), data.getNumRows()); - - double a2Orig = new AndersonDarlingTest(x1).getASquaredStar(); - - if (dataSet.getVariable(j) instanceof DiscreteVariable) { - X.assignColumn(j, new Vector(x1)); - continue; - } - - double std1 = StatUtils.sd(x1); - double mu1 = StatUtils.mean(x1); - double[] xTransformed = DataUtils.ranks(x1); - - for (int i = 0; i < xTransformed.length; i++) { - xTransformed[i] /= n; - xTransformed[i] = normalDistribution.inverseCumulativeProbability(xTransformed[i]); - } - - if (Double.isNaN(std)) { - std = StatUtils.sd(x1Orig); - } - - for (int i = 0; i < xTransformed.length; i++) { - xTransformed[i] *= std1; - xTransformed[i] += mu1; - } - - double a2Transformed = new AndersonDarlingTest(xTransformed).getASquaredStar(); - - double min = Double.POSITIVE_INFINITY; - double max = Double.NEGATIVE_INFINITY; - - for (double v : xTransformed) { - if (v > max && !Double.isInfinite(v)) { - max = v; - } - - if (v < min && !Double.isInfinite(v)) { - min = v; - } - } - - for (int i = 0; i < xTransformed.length; i++) { - if (xTransformed[i] == Double.POSITIVE_INFINITY) { - xTransformed[i] = max; - } - - if (xTransformed[i] < Double.NEGATIVE_INFINITY) { - xTransformed[i] = min; - } - } - - System.out.println(dataSet.getVariable(j) + ": A^2* = " + a2Orig + " transformed A^2* = " + a2Transformed); - -// if (a2Transformed < a2Orig) { - X.assignColumn(j, new Vector(xTransformed)); -// } else { -// X.assignColumn(j, new Vector(x1Orig)); -// } - } - - return new BoxDataSet(new VerticalDoubleDataBox(X.transpose().toArray()), dataSet.getVariables()); - } catch (OutOfRangeException e) { - e.printStackTrace(); - return dataSet; - } - } - public static double[] ranks(double[] x) { int numRows = x.length; double[] ranks = new double[numRows]; @@ -1479,69 +497,6 @@ public static double[] ranks(double[] x) { return ranks; } - public static DataSet removeConstantColumns(DataSet dataSet) { - int columns = dataSet.getNumColumns(); - int rows = dataSet.getNumRows(); - if (rows == 0) { - return dataSet; - } - - List keepCols = new ArrayList<>(); - - for (int j = 0; j < columns; j++) { - Object previous = dataSet.getObject(0, j); - boolean constant = true; - for (int row = 1; row < rows; row++) { - Object current = dataSet.getObject(row, j); - if (!previous.equals(current)) { - constant = false; - break; - } - - if (previous instanceof Double && current instanceof Double) { - double _previouw = (Double) previous; - double _current = (Double) current; - - if (Double.isNaN(_previouw) && Double.isNaN(_current)) { - constant = false; - break; - } - } - } - - if (!constant) keepCols.add(j); - } - - int[] newCols = new int[keepCols.size()]; - for (int j = 0; j < keepCols.size(); j++) newCols[j] = keepCols.get(j); - - return dataSet.subsetColumns(newCols); - } - - public static List getConstantColumns(DataSet dataSet) { - List constantColumns = new ArrayList<>(); - int rows = dataSet.getNumRows(); - - for (int j = 0; j < dataSet.getNumColumns(); j++) { - Object first = dataSet.getObject(0, j); - boolean constant = true; - - for (int row = 1; row < rows; row++) { - Object current = dataSet.getObject(row, j); - if (!first.equals(current)) { - constant = false; - break; - } - } - - if (constant) { - constantColumns.add(dataSet.getVariable(j)); - } - } - - return constantColumns; - } - public static List getExampleNonsingular(ICovarianceMatrix covarianceMatrix, int depth) { List variables = covarianceMatrix.getVariables(); @@ -1588,27 +543,6 @@ public static double getEss(ICovarianceMatrix covariances) { double rho = (n * sum - n * m) / (m * (n * n - n)); return n / (1. + (n - 1.) * rho); } - - public static DataSet removeRandomColumns(DataSet dataSet, double aDouble) { - int columns = dataSet.getNumColumns(); - int rows = dataSet.getNumRows(); - if (rows == 0) { - return dataSet; - } - - List keepCols = new ArrayList<>(); - - for (int j = 0; j < columns; j++) { - if (RandomUtil.getInstance().nextDouble() > aDouble) { - keepCols.add(j); - } - } - - int[] newCols = new int[keepCols.size()]; - for (int j = 0; j < keepCols.size(); j++) newCols[j] = keepCols.get(j); - - return dataSet.subsetColumns(newCols); - } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java index 31f42bad36..dc1f5c9fe4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DelimiterType.java @@ -42,7 +42,7 @@ public final class DelimiterType implements TetradSerializable { = new DelimiterType("Comma", ","); public static final DelimiterType COLON = new DelimiterType("Colon", ":"); - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final DelimiterType[] TYPES = {DelimiterType.WHITESPACE, DelimiterType.TAB, DelimiterType.COMMA}; // Declarations required for serialization. private static int nextOrdinal; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java index 1db4eb0f8b..3ff0cfea26 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteDiscretizationSpec.java @@ -37,7 +37,7 @@ * @author josephramsey */ public final class DiscreteDiscretizationSpec implements TetradSerializable, DiscretizationSpec { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Discrete remapping of categories, for discrete data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java index 13494aa7cd..2c12305bfa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariable.java @@ -47,13 +47,13 @@ * * @author josephramsey */ -public final class DiscreteVariable extends AbstractVariable { +public final class DiscreteVariable extends AbstractVariable implements Node { /** * This is the index in the data which represents missing data internally for this variable. */ public static final int MISSING_VALUE = -99; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The string displayed for missing values. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java index dc73db0fc9..95d12e989b 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DiscreteVariableType.java @@ -35,7 +35,7 @@ public final class DiscreteVariableType implements TetradSerializable { public static final DiscreteVariableType NOMINAL = new DiscreteVariableType("Nominal"); - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final DiscreteVariableType ORDINAL = new DiscreteVariableType("Ordinal"); private static final DiscreteVariableType[] TYPES = {DiscreteVariableType.NOMINAL, DiscreteVariableType.ORDINAL}; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java index 4afb5663d4..3dff3dd8a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Discretizer.java @@ -312,7 +312,7 @@ public DataSet discretize() { } } else { - DataUtils.copyColumn(variable, this.sourceDataSet, newDataSet); + DataTransforms.copyColumn(variable, this.sourceDataSet, newDataSet); } } return newDataSet; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DoubleDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DoubleDataBox.java index b4cdb41dd1..43caebc8b9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DoubleDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/DoubleDataBox.java @@ -30,7 +30,7 @@ * Stores a 2D array of double data. Note that the missing value marker for this box is -99. */ public class DoubleDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored double data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/FloatDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/FloatDataBox.java index 12ef0bcbcb..0abaf0faa4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/FloatDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/FloatDataBox.java @@ -30,7 +30,7 @@ * Stores a 2D array of float data. Note that the missing value marker for this box is Float.NaN. */ public class FloatDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored float data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java index 79f5cdc7a3..a09d506c88 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Histogram.java @@ -36,6 +36,7 @@ */ public class Histogram { private final DataSet dataSet; + private final boolean removeZeroPointsPerPlot; private Node target; private int numBins = 10; private Map continuousIntervals; @@ -44,12 +45,13 @@ public class Histogram { /** * This histogram is for variables in a particular data set. These may be continuous or discrete. */ - public Histogram(DataSet dataSet, String target) { + public Histogram(DataSet dataSet, String target, boolean removeZeroPointsPerPlot) { if (dataSet.getVariables().size() < 1) { throw new IllegalArgumentException("Can't do histograms for an empty data sets."); } this.dataSet = dataSet; + this.removeZeroPointsPerPlot = removeZeroPointsPerPlot; setTarget(target); } @@ -118,6 +120,7 @@ public void setNumBins(int numBins) { public int[] getFrequencies() { if (this.target instanceof ContinuousVariable) { List _data = getConditionedDataContinuous(); + _data = removeZeroPointsPerPlot(_data); double[] breakpoints = getBreakpoints(_data, this.numBins); int[] counts = new int[this.numBins]; @@ -157,6 +160,18 @@ public int[] getFrequencies() { } } + private List removeZeroPointsPerPlot(List data) { + List _data = new ArrayList<>(); + + for (double d : data) { + if (!removeZeroPointsPerPlot || d != 0) { + _data.add(d); + } + } + + return _data; + } + /** * For a continuous target, returns the maximum value of the values histogrammed, for the unconditioned data. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java index d6f5398c10..38f66cc916 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IDataReader.java @@ -1,6 +1,8 @@ package edu.cmu.tetrad.data; /** + * Identifies a class that can read data from a file. + * * @author josephramsey */ public interface IDataReader { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java index 0b24c6592b..b68b46ffc9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IndependenceFacts.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class IndependenceFacts implements DataModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private List nodes = new ArrayList<>(); private Set unsortedFacts = new LinkedHashSet<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IntDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IntDataBox.java index 7856efa976..4b6c6e5c6e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IntDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/IntDataBox.java @@ -30,7 +30,7 @@ */ public class IntDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored short data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java index 5592ce7f6a..d023bd4dc4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Knowledge.java @@ -51,12 +51,12 @@ public final class Knowledge implements TetradSerializable { private static final long serialVersionUID = 23L; -// private static final Pattern VARNAME_PATTERN = Pattern.compile("[A-Za-z0-9:_\\-.]+"); + // private static final Pattern VARNAME_PATTERN = Pattern.compile("[A-Za-z0-9:_\\-.]+"); // private static final Pattern SPEC_PATTERN = Pattern.compile("[A-Za-z0-9:-_,\\-.*]+"); private static final Pattern COMMAN_DELIM = Pattern.compile(","); private final Set variables; - private final List>> forbiddenRulesSpecs; - private final List>> requiredRulesSpecs; + private final Set>> forbiddenRulesSpecs; + private final Set>> requiredRulesSpecs; private final List> tierSpecs; // Legacy. private final List knowledgeGroups; @@ -65,8 +65,8 @@ public final class Knowledge implements TetradSerializable { public Knowledge() { this.variables = new HashSet<>(); - this.forbiddenRulesSpecs = new ArrayList<>(); - this.requiredRulesSpecs = new ArrayList<>(); + this.forbiddenRulesSpecs = new HashSet<>(); + this.requiredRulesSpecs = new HashSet<>(); this.tierSpecs = new ArrayList<>(); this.knowledgeGroups = new LinkedList<>(); this.knowledgeGroupRules = new HashMap<>(); @@ -160,10 +160,6 @@ private Set split(String spec) { private void ensureTiers(int tier) { for (int i = this.tierSpecs.size(); i <= tier; i++) { this.tierSpecs.add(new HashSet<>()); - -// for (int j = 0; j < i; j++) { -// this.forbiddenRulesSpecs.add(new OrderedPair<>(this.tierSpecs.get(i), this.tierSpecs.get(j))); -// } } } @@ -212,6 +208,7 @@ public void addToTier(int tier, String spec) { if (tier < 0) { throw new IllegalArgumentException(); } + if (spec == null) { throw new NullPointerException(); } @@ -222,15 +219,15 @@ public void addToTier(int tier, String spec) { Set extent = getExtent(spec); - for (String var : extent) { - for (int i = 0; i < tierSpecs.size(); i++) { - if (i == tier) { - this.tierSpecs.get(i).add(var); - } else { - this.tierSpecs.get(i).remove(var); - } + for (Set tierSpec : tierSpecs) { + for (String var : extent) { + tierSpec.remove(var); } } + + for (String var : extent) { + tierSpecs.get(tier).add(var); + } } /** @@ -260,6 +257,8 @@ public void addToTiersByVarNames(List varNames) { * interface. */ public void addKnowledgeGroup(KnowledgeGroup group) { + if (group == null) throw new NullPointerException("Knowledge group is null."); + this.knowledgeGroups.add(group); OrderedPair> o = getGroupRule(group); @@ -290,15 +289,8 @@ public void clear() { * Iterator over the KnowledgeEdge's representing forbidden edges. */ public Iterator forbiddenEdgesIterator() { - Set edges = new HashSet<>(); - - this.forbiddenRulesSpecs.forEach(o -> o.getFirst().forEach(s1 -> o.getSecond().forEach(s2 -> { - if (!s1.equals(s2)) { - edges.add(new KnowledgeEdge(s1, s2)); - } - }))); - - return edges.iterator(); + List forbiddenEdges = getListOfForbiddenEdges(); + return forbiddenEdges.iterator(); } /** @@ -377,10 +369,6 @@ private boolean isForbiddenByRules(String var1, String var2) { * Determines whether the edge var1 --> var2 is forbidden. */ public boolean isForbidden(String var1, String var2) { - if (isRequired(var1, var2)) { - return false; - } - return isForbiddenByRules(var1, var2) || isForbiddenByTiers(var1, var2); } @@ -546,7 +534,9 @@ public void setForbidden(String var1, String var2) { Set f1 = getExtent(var1); Set f2 = getExtent(var2); - this.forbiddenRulesSpecs.add(new OrderedPair<>(f1, f2)); + OrderedPair> o = new OrderedPair<>(f1, f2); + + this.forbiddenRulesSpecs.add(o); } /** @@ -566,6 +556,8 @@ public void removeForbidden(String var1, String var2) { * Marks the edge var1 --> var2 as required. */ public void setRequired(String var1, String var2) { + if (isRequired(var1, var1)) return; + addVariable(var1); addVariable(var2); @@ -586,7 +578,9 @@ public void setRequired(String var1, String var2) { } }); - this.requiredRulesSpecs.add(new OrderedPair<>(f1, f2)); + OrderedPair> o = new OrderedPair<>(f1, f2); + + this.requiredRulesSpecs.add(o); } /** @@ -612,6 +606,8 @@ public void setKnowledgeGroup(int index, KnowledgeGroup group) { this.forbiddenRulesSpecs.remove(old); this.requiredRulesSpecs.remove(old); + knowledgeGroupRules.put(group, o); + if (group.getType() == KnowledgeGroup.FORBIDDEN) { this.forbiddenRulesSpecs.add(o); } else if (group.getType() == KnowledgeGroup.REQUIRED) { @@ -641,10 +637,12 @@ public void setTierForbiddenWithin(int tier, boolean forbidden) { ensureTiers(tier); Set varsInTier = this.tierSpecs.get(tier); + OrderedPair> o = new OrderedPair<>(varsInTier, varsInTier); + if (forbidden) { - this.forbiddenRulesSpecs.add(new OrderedPair<>(varsInTier, varsInTier)); + this.forbiddenRulesSpecs.add(o); } else { - this.forbiddenRulesSpecs.remove(new OrderedPair<>(varsInTier, varsInTier)); + this.forbiddenRulesSpecs.remove(o); } } @@ -705,9 +703,35 @@ public List getListOfExplicitlyRequiredEdges() { public List getListOfForbiddenEdges() { Set edges = new HashSet<>(); - this.forbiddenRulesSpecs.forEach(e -> e.getFirst().forEach(e1 -> e.getSecond().forEach(e2 -> { - if (!e1.equals(e2)) { - edges.add(new KnowledgeEdge(e1, e2)); + for (int i = 0; i < tierSpecs.size(); i++) { + if (isTierForbiddenWithin(i)) { + Set tier = tierSpecs.get(i); + for (String x : tier) { + for (String y : tier) { + if (!x.equals(y)) { + edges.add(new KnowledgeEdge(x, y)); + } + } + } + } + } + + for (int i = this.tierSpecs.size() - 1; i >= 0; i--) { + for (int j = i; j >= 0; j--) { + Set tieri = this.tierSpecs.get(i); + Set tierj = this.tierSpecs.get(j); + + for (String x : tieri) { + for (String y : tierj) { + edges.add(new KnowledgeEdge(x, y)); + } + } + } + } + + this.forbiddenRulesSpecs.forEach(o -> o.getFirst().forEach(s1 -> o.getSecond().forEach(s2 -> { + if (!s1.equals(s2)) { + edges.add(new KnowledgeEdge(s1, s2)); } }))); @@ -759,10 +783,12 @@ public void setOnlyCanCauseNextTier(int tier, boolean onlyCausesNext) { for (int tierN = tier + 2; tierN < this.tierSpecs.size(); tierN++) { Set varsInTierN = this.tierSpecs.get(tierN); + OrderedPair> o = new OrderedPair<>(varsInTier, varsInTierN); + if (onlyCausesNext) { - this.forbiddenRulesSpecs.add(new OrderedPair<>(varsInTier, varsInTierN)); + this.forbiddenRulesSpecs.add(o); } else { - this.forbiddenRulesSpecs.remove(new OrderedPair<>(varsInTier, varsInTierN)); + this.forbiddenRulesSpecs.remove(o); } } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java index 478422c254..d5601da556 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeEdge.java @@ -32,7 +32,7 @@ * @author josephramsey */ public final class KnowledgeEdge implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeGroup.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeGroup.java index b9df89d1eb..e3c9e32c2f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeGroup.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/KnowledgeGroup.java @@ -41,7 +41,7 @@ public final class KnowledgeGroup implements TetradSerializable { */ public static final int REQUIRED = 1; public static final int FORBIDDEN = 2; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The left group of variables. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/LongDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/LongDataBox.java index 07e52f9ec4..a0eb9d2e3c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/LongDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/LongDataBox.java @@ -30,7 +30,7 @@ * Stores a 2D array of long data. Note that the missing value marker for this box is -99. */ public class LongDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored long data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java index 5f9b67f7c3..57707a47d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/NumberObjectDataSet.java @@ -54,7 +54,7 @@ * the data set, but it may be retrieved by algorithm and used. *

* This data set replaces an earlier Minitab-style DataSet class. The reasons for replacement are as follows. - *

+ *

*
  • COLT marices are optimized for double 2D matrix calculations in ways * that Java-style double[][] matrices are not.
  • The COLT library comes with * a wide range of linear algebra library methods that are better tested and @@ -73,7 +73,7 @@ */ public final class NumberObjectDataSet implements DataSet { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Map columnToTooltip = new HashMap<>(); /** * The name of the data model. This is not used internally; it is only here in case an external class wants this diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ShortDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ShortDataBox.java index 5dddc39977..643ebee730 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ShortDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/ShortDataBox.java @@ -30,7 +30,7 @@ * Stores a 2D array of short data. Note that the missing value marker for this box is -99. */ public class ShortDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored short data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SimpleDataLoader.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SimpleDataLoader.java index 6a1a31155a..c220488334 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SimpleDataLoader.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SimpleDataLoader.java @@ -1,5 +1,6 @@ package edu.cmu.tetrad.data; +import com.google.gson.Gson; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; @@ -28,21 +29,34 @@ public class SimpleDataLoader { * @param missingValueMarker The missing value marker as a string--e.g., "NA". * @param hasHeader True if the first row of the data contains variable names. * @param delimiter One of the options in the Delimiter enum--e.g., Delimiter.TAB. + * @param excludeFirstColumn If the first column should be excluded from the data. * @return The loaded DataSet. * @throws IOException If an error occurred in reading the file. */ + // From SimpleDataLoader @NotNull public static DataSet loadContinuousData(File file, String commentMarker, char quoteCharacter, - String missingValueMarker, boolean hasHeader, Delimiter delimiter) + String missingValueMarker, boolean hasHeader, Delimiter delimiter, + boolean excludeFirstColumn) throws IOException { - ContinuousTabularDatasetFileReader dataReader - = new ContinuousTabularDatasetFileReader(file.toPath(), delimiter); + TabularColumnReader columnReader = new TabularColumnFileReader(file.toPath(), delimiter); + DataColumn[] dataColumns = columnReader.readInDataColumns(excludeFirstColumn ? + new int[]{1} : new int[]{}, false); + + columnReader.setCommentMarker(commentMarker); + + TabularDataReader dataReader = new TabularDataFileReader(file.toPath(), delimiter); + + // Need to specify commentMarker, .... again to the TabularDataFileReader dataReader.setCommentMarker(commentMarker); - dataReader.setQuoteCharacter(quoteCharacter); dataReader.setMissingDataMarker(missingValueMarker); - dataReader.setHasHeader(hasHeader); - ContinuousData data = (ContinuousData) dataReader.readInData(); - return (DataSet) DataConvertUtils.toContinuousDataModel(data); + dataReader.setQuoteCharacter(quoteCharacter); + + Data data = dataReader.read(dataColumns, hasHeader); + DataModel dataModel = DataConvertUtils.toDataModel(data); + dataModel.setName(file.getName()); + + return (DataSet) dataModel; } /** @@ -54,15 +68,19 @@ public static DataSet loadContinuousData(File file, String commentMarker, char q * @param missingValueMarker The missing value marker as a string--e.g., "NA". * @param hasHeader True if the first row of the data contains variable names. * @param delimiter One of the options in the Delimiter enum--e.g., Delimiter.TAB. + * @param excludeFirstColumn If the first columns should be excluded from the data. * @return The loaded DataSet. * @throws IOException If an error occurred in reading the file. */ + // From SimpleDataLoader @NotNull public static DataSet loadDiscreteData(File file, String commentMarker, char quoteCharacter, - String missingValueMarker, boolean hasHeader, Delimiter delimiter) + String missingValueMarker, boolean hasHeader, Delimiter delimiter, + boolean excludeFirstColumn) throws IOException { TabularColumnReader columnReader = new TabularColumnFileReader(file.toPath(), delimiter); - DataColumn[] dataColumns = columnReader.readInDataColumns(new int[]{1}, true); + DataColumn[] dataColumns = columnReader.readInDataColumns(excludeFirstColumn ? + new int[]{1} : new int[]{}, true); columnReader.setCommentMarker(commentMarker); @@ -75,6 +93,7 @@ public static DataSet loadDiscreteData(File file, String commentMarker, char quo Data data = dataReader.read(dataColumns, hasHeader); DataModel dataModel = DataConvertUtils.toDataModel(data); + dataModel.setName(file.getName()); return (DataSet) dataModel; } @@ -87,18 +106,22 @@ public static DataSet loadDiscreteData(File file, String commentMarker, char quo * @param quoteCharacter The quote character, e.g., '\"'. * @param missingValueMarker The missing value marker as a string--e.g., "NA". * @param hasHeader True if the first row of the data contains variable names. - * @param delimiter One of the options in the Delimiter enum--e.g., Delimiter.TAB. * @param maxNumCategories The maximum number of distinct entries in a columns alloed in order for the column to * be parsed as discrete. + * @param delimiter One of the options in the Delimiter enum--e.g., Delimiter.TAB. + * @param excludeFirstColumn If the first columns should be excluded from the data set. * @return The loaded DataSet. * @throws IOException If an error occurred in reading the file. */ + // From SimpleDataLoader @NotNull public static DataSet loadMixedData(File file, String commentMarker, char quoteCharacter, - String missingValueMarker, boolean hasHeader, int maxNumCategories, Delimiter delimiter) + String missingValueMarker, boolean hasHeader, int maxNumCategories, + Delimiter delimiter, boolean excludeFirstColumn) throws IOException { TabularColumnReader columnReader = new TabularColumnFileReader(file.toPath(), delimiter); - DataColumn[] dataColumns = columnReader.readInDataColumns(new int[]{1}, false); + DataColumn[] dataColumns = columnReader.readInDataColumns(excludeFirstColumn ? + new int[]{1} : new int[]{}, false); columnReader.setCommentMarker(commentMarker); @@ -111,9 +134,14 @@ public static DataSet loadMixedData(File file, String commentMarker, char quoteC dataReader.determineDiscreteDataColumns(dataColumns, maxNumCategories, hasHeader); Data data = dataReader.read(dataColumns, hasHeader); - DataModel dataModel = DataConvertUtils.toDataModel(data); - return (DataSet) dataModel; + if (data != null){ + DataModel dataModel = DataConvertUtils.toDataModel(data); + dataModel.setName(file.getName()); + return (DataSet) dataModel; + } + + return null; } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Simulator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Simulator.java index 8d96b89472..cde705ca08 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Simulator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Simulator.java @@ -8,5 +8,11 @@ public interface Simulator extends TetradSerializable { long serialVersionUID = 23L; + /** + * Simulates data from the model associated with this object. + * @param sampleSize the number of rows to simulate. + * @param latentDataSaved if true, latent variables are saved in the data set. + * @return the simulated data set. + */ DataSet simulateData(int sampleSize, boolean latentDataSaved); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java index 9e4466a771..250e3fa890 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/SplitCasesSpec.java @@ -37,7 +37,7 @@ * @author josephramsey */ public final class SplitCasesSpec implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Breakpoints, for continuous data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java index c32b2a1877..d8bce2813d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/TimeSeriesData.java @@ -36,7 +36,7 @@ * @author josephramsey */ public final class TimeSeriesData implements DataModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java index 5f338c109c..db9724cc28 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/Variable.java @@ -40,6 +40,8 @@ public interface Variable extends Node { long serialVersionUID = 23L; /** + * Returns the name of the variable. + * * @return the missing value marker as an object--i.e. a double if continuous, an Integer if discrete, etc. */ Object getMissingValueMarker(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java index 3fed877997..6164086975 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VariableSource.java @@ -37,11 +37,13 @@ public interface VariableSource extends TetradSerializable { long serialVersionUID = 23L; /** + * Returns the list of variables associated with this object. * @return the list of variables associated with this object. */ List getVariables(); /** + * Returns the variable names associated with this getVariableNames. * @return the variable names associated with this getVariableNames. */ List getVariableNames(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java index 532a701c42..791d4a81af 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalDoubleDataBox.java @@ -32,7 +32,7 @@ * @author josephramsey */ public class VerticalDoubleDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored double data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalIntDataBox.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalIntDataBox.java index 90e88dcad4..24de12e8d8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalIntDataBox.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/VerticalIntDataBox.java @@ -30,7 +30,7 @@ * Stores a 2D array of int data. Note that the missing value marker for this box is -99. */ public class VerticalIntDataBox implements DataBox { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored int data. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java index 2c7dc2b740..5300450846 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndGraphs.java @@ -21,10 +21,12 @@ import java.util.Objects; /** + * Load data sets and graphs from a directory. + * * @author josephramsey */ public class LoadContinuousDataAndGraphs implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String path; private final List graphs = new ArrayList<>(); private final List usedParameters = new ArrayList<>(); @@ -49,13 +51,13 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading graph from " + file2.getAbsolutePath()); this.graphs.add(GraphSaveLoadUtils.loadGraphTxt(file2)); - LayoutUtil.circleLayout(this.graphs.get(i)); + LayoutUtil.defaultLayout(this.graphs.get(i)); File file1 = new File(this.path + "/data/data." + (i + 1) + ".txt"); System.out.println("Loading data from " + file1.getAbsolutePath()); DataSet data = SimpleDataLoader.loadContinuousData(file1, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.dataSets.add(data); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java index 2ac3a5e980..1b535faa56 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataAndSingleGraph.java @@ -19,11 +19,13 @@ import java.util.List; /** + * Load data sets and graphs from a directory. + * * @author josephramsey */ @Experimental public class LoadContinuousDataAndSingleGraph implements Simulation, HasParameterValues { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String path; private final List usedParameters = new ArrayList<>(); private final Parameters parametersValues = new Parameters(); @@ -51,7 +53,7 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading data from " + file.getAbsolutePath()); try { DataSet data = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.dataSets.add(data); } catch (Exception e) { System.out.println("Couldn't parse " + file.getAbsolutePath()); @@ -74,7 +76,7 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading graph from " + file.getAbsolutePath()); this.graph = GraphSaveLoadUtils.loadGraphTxt(file); - LayoutUtil.circleLayout(this.graph); + LayoutUtil.defaultLayout(this.graph); } if (parameters.get(Params.NUM_RUNS) != null) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java index 8490b6e3dc..ab93766d64 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadContinuousDataSmithSim.java @@ -21,11 +21,13 @@ import java.util.List; /** + * Load data sets and graphs from a directory. + * * @author josephramsey */ @Experimental public class LoadContinuousDataSmithSim implements Simulation, HasParameterValues { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String path; private final List usedParameters = new ArrayList<>(); private final Parameters parametersValues = new Parameters(); @@ -55,7 +57,7 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading data from " + file.getAbsolutePath()); try { DataSet dataSet = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.dataSets.add(dataSet); } catch (Exception e) { System.out.println("Couldn't parse " + file.getAbsolutePath()); @@ -75,7 +77,7 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading graph from " + file.getAbsolutePath()); this.graph = readGraph(file); - LayoutUtil.circleLayout(this.graph); + LayoutUtil.defaultLayout(this.graph); break; } @@ -132,7 +134,7 @@ public Parameters getParameterValues() { public Graph readGraph(File file) { try { DataSet data = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); List variables = data.getVariables(); Graph graph = new EdgeListGraph(variables); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java index 889983d764..2b3d2b6c71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataAndGraphs.java @@ -18,11 +18,13 @@ import java.util.Objects; /** + * Load data sets and graphs from a directory. + * * @author josephramsey */ public class LoadDataAndGraphs implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String path; private final List graphs = new ArrayList<>(); private final List usedParameters = new ArrayList<>(); @@ -57,14 +59,14 @@ public void createData(Parameters parameters, boolean newModel) { this.graphs.add(null); } - LayoutUtil.circleLayout(this.graphs.get(i)); + LayoutUtil.defaultLayout(this.graphs.get(i)); File file1 = new File(path + "/data/data." + (i + 1) + ".txt"); this.stdout.println("Loading data from " + file1.getAbsolutePath()); DataSet ds = SimpleDataLoader.loadContinuousData(file1, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.dataSets.add(ds); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java index 0cded1f256..206be8cc07 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/data/simulation/LoadDataFromFileWithoutGraph.java @@ -19,10 +19,12 @@ import java.util.Map; /** + * Load data sets and graphs from a directory. + * * @author josephramsey */ public class LoadDataFromFileWithoutGraph implements Simulation, SimulationPath, ParameterValues { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String path; private final Map parameterValues = new HashMap<>(); private DataSet dataSet; @@ -38,7 +40,7 @@ public void createData(Parameters parameters, boolean newModel) { File file = new File(this.path); System.out.println("Loading data from " + file.getAbsolutePath()); this.dataSet = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); } catch (IOException e) { e.printStackTrace(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java index 396a559367..0521db460c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Dag.java @@ -33,7 +33,7 @@ * @author josephramsey */ public final class Dag implements Graph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph graph; private final Set underLineTriples = new HashSet<>(); private final Set dottedUnderLineTriples = new HashSet<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java index f27e157f02..374b74cac7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Edge.java @@ -40,7 +40,7 @@ * @author josephramsey */ public class Edge implements TetradSerializable, Comparable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Node node1; private final Node node2; private Endpoint endpoint1; @@ -317,10 +317,6 @@ public final String toString() { } public final int hashCode() { - - // Equality of nodes can only dependent on the object identity of the - // nodes, not on their name. Otherwise, the identity of an edge could be - // changed by changing the name of one of its nodes. return 1; } @@ -338,12 +334,6 @@ public final boolean equals(Object o) { // Equality of nodes can only dependent on the object identity of the // nodes, not on their name. Otherwise, the identity of an edge could be // changed by changing the name of one of its nodes. - -// String name1 = getNode1().getName(); -// String name2 = getNode2().getName(); -// String name1b = edge.getNode1().getName(); -// String name2b = edge.getNode2().getName(); - Node node1 = getNode1(); Node node2 = getNode2(); Node node1b = edge.getNode1(); @@ -354,19 +344,10 @@ public final boolean equals(Object o) { Endpoint end1b = edge.getEndpoint1(); Endpoint end2b = edge.getEndpoint2(); -// if (name1.hashCode() == name1b.hashCode() && name2.hashCode() == name2b.hashCode() -// && name1.equals(name1b) && name2.equals(name2b)) { -// return end1 == end1b && end2 == end2b; -// } else { -// return name1.hashCode() == name2b.hashCode() && name2.hashCode() == name1b.hashCode() -// && name1.equals(name2b) && name2.equals(name1b) && end1 == end2b && end2 == end1b; -// } + boolean equals1 = node1 == node1b && node2 == node2b && end1 == end1b && end2 == end2b; + boolean equals2 = node1 == node2b && node2 == node1b && end1 == end2b && end2 == end1b; - if (node1 == node1b && node2 == node2b) { - return end1 == end1b && end2 == end2b; - } else { - return node1 == node2b && node2 == node1b && end1 == end2b && end2 == end1b; - } + return equals1 || equals2; } public int compareTo(Edge _edge) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java index 88e7ca4bc9..cca46a120e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/EdgeListGraph.java @@ -42,7 +42,7 @@ */ public class EdgeListGraph implements Graph, TripleClassifier { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The edges in the graph. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java index e4132a9391..db93cecf2a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Endpoint.java @@ -31,7 +31,7 @@ */ public enum Endpoint implements TetradSerializable { TAIL, ARROW, CIRCLE, STAR, NULL; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java index c78fc7c593..0cc5622164 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphNode.java @@ -35,7 +35,7 @@ */ public class GraphNode implements Node { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Map attributes = new HashMap<>(); /** * The name of the node. @@ -240,58 +240,58 @@ private void readObject(ObjectInputStream s) } } - @Override - public int compareTo(Node node) { - String node1 = getName(); - String node2 = node.getName(); - - boolean isAlpha1 = Node.ALPHA.matcher(node1).matches(); - boolean isAlpha2 = Node.ALPHA.matcher(node2).matches(); - boolean isAlphaNum1 = Node.ALPHA_NUM.matcher(node1).matches(); - boolean isAlphaNum2 = Node.ALPHA_NUM.matcher(node2).matches(); - boolean isLag1 = Node.LAG.matcher(node1).matches(); - boolean isLag2 = Node.LAG.matcher(node2).matches(); - - if (isAlpha1) { - if (isLag2) { - return -1; - } - } else if (isAlphaNum1) { - if (isAlphaNum2) { - String s1 = node1.replaceAll("\\d+", ""); - String s2 = node2.replaceAll("\\d+", ""); - if (s1.equals(s2)) { - String n1 = node1.replaceAll("\\D+", ""); - String n2 = node2.replaceAll("\\D+", ""); - - return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); - } else { - return s1.compareTo(s2); - } - } else if (isLag2) { - return -1; - } - } else if (isLag1) { - if (isAlpha2 || isAlphaNum2) { - return 1; - } else if (isLag2) { - String l1 = node1.replaceAll(":", ""); - String l2 = node2.replaceAll(":", ""); - String s1 = l1.replaceAll("\\d+", ""); - String s2 = l2.replaceAll("\\d+", ""); - if (s1.equals(s2)) { - String n1 = l1.replaceAll("\\D+", ""); - String n2 = l2.replaceAll("\\D+", ""); - - return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); - } else { - return s1.compareTo(s2); - } - } - } - - return node1.compareTo(node2); - } +// @Override +// public int compareTo(Node node) { +// String node1 = getName(); +// String node2 = node.getName(); +// +// boolean isAlpha1 = Node.ALPHA.matcher(node1).matches(); +// boolean isAlpha2 = Node.ALPHA.matcher(node2).matches(); +// boolean isAlphaNum1 = Node.ALPHA_NUM.matcher(node1).matches(); +// boolean isAlphaNum2 = Node.ALPHA_NUM.matcher(node2).matches(); +// boolean isLag1 = Node.LAG.matcher(node1).matches(); +// boolean isLag2 = Node.LAG.matcher(node2).matches(); +// +// if (isAlpha1) { +// if (isLag2) { +// return -1; +// } +// } else if (isAlphaNum1) { +// if (isAlphaNum2) { +// String s1 = node1.replaceAll("\\d+", ""); +// String s2 = node2.replaceAll("\\d+", ""); +// if (s1.equals(s2)) { +// String n1 = node1.replaceAll("\\D+", ""); +// String n2 = node2.replaceAll("\\D+", ""); +// +// return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); +// } else { +// return s1.compareTo(s2); +// } +// } else if (isLag2) { +// return -1; +// } +// } else if (isLag1) { +// if (isAlpha2 || isAlphaNum2) { +// return 1; +// } else if (isLag2) { +// String l1 = node1.replaceAll(":", ""); +// String l2 = node2.replaceAll(":", ""); +// String s1 = l1.replaceAll("\\d+", ""); +// String s2 = l2.replaceAll("\\d+", ""); +// if (s1.equals(s2)) { +// String n1 = l1.replaceAll("\\D+", ""); +// String n2 = l2.replaceAll("\\D+", ""); +// +// return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); +// } else { +// return s1.compareTo(s2); +// } +// } +// } +// +// return node1.compareTo(node2); +// } @Override public NodeVariableType getNodeVariableType() { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphSaveLoadUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphSaveLoadUtils.java index 660cbc43f6..96042eef40 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphSaveLoadUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphSaveLoadUtils.java @@ -58,7 +58,8 @@ public static Graph loadGraphRuben(File file) { final String missingValueMarker = "*"; final boolean hasHeader = false; - DataSet dataSet = SimpleDataLoader.loadContinuousData(file, commentMarker, quoteCharacter, missingValueMarker, hasHeader, Delimiter.COMMA); + DataSet dataSet = SimpleDataLoader.loadContinuousData(file, commentMarker, quoteCharacter, missingValueMarker, + hasHeader, Delimiter.COMMA, false); List nodes = dataSet.getVariables(); Graph graph = new EdgeListGraph(nodes); @@ -202,7 +203,7 @@ public static Graph loadRSpecial(File file) { public static Graph loadGraphPcalg(File file) { try { DataSet dataSet = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.COMMA); + "*", true, Delimiter.COMMA, false); List nodes = dataSet.getVariables(); Graph graph = new EdgeListGraph(nodes); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphTransforms.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphTransforms.java new file mode 100644 index 0000000000..012a9b4663 --- /dev/null +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphTransforms.java @@ -0,0 +1,223 @@ +package edu.cmu.tetrad.graph; + +import edu.cmu.tetrad.data.Knowledge; +import edu.cmu.tetrad.search.utils.DagInCpcagIterator; +import edu.cmu.tetrad.search.utils.DagToPag; +import edu.cmu.tetrad.search.utils.MeekRules; +import edu.cmu.tetrad.util.CombinationGenerator; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * Transformations that transform one graph into another. + * + * @author josephramsey + */ +public class GraphTransforms { + public static Graph dagFromCPDAG(Graph graph) { + return dagFromCPDAG(graph, null); + } + + public static Graph dagFromCPDAG(Graph graph, Knowledge knowledge) { + Graph dag = new EdgeListGraph(graph); + + for (Edge edge : dag.getEdges()) { + if (Edges.isBidirectedEdge(edge)) { + throw new IllegalArgumentException("That 'cpdag' contains a bidirected edge."); + } + } + + MeekRules rules = new MeekRules(); + + if (knowledge != null) { + rules.setKnowledge(knowledge); + } + + rules.setRevertToUnshieldedColliders(false); + + NEXT: + while (true) { + for (Edge edge : dag.getEdges()) { + Node x = edge.getNode1(); + Node y = edge.getNode2(); + + if (Edges.isUndirectedEdge(edge) && !graph.paths().isAncestorOf(y, x)) { + direct(x, y, dag); + rules.orientImplied(dag); + continue NEXT; + } + } + + break; + } + + return dag; + } + + // Zhang 2008 Theorem 2 + public static Graph pagToMag(Graph pag) { + Graph mag = new EdgeListGraph(pag.getNodes()); + for (Edge e : pag.getEdges()) mag.addEdge(new Edge(e)); + + List nodes = mag.getNodes(); + + Graph pcafci = new EdgeListGraph(nodes); + + for (int i = 0; i < nodes.size(); i++) { + for (int j = 0; j < nodes.size(); j++) { + if (i == j) continue; + + Node x = nodes.get(i); + Node y = nodes.get(j); + + if (mag.getEndpoint(y, x) == Endpoint.CIRCLE && mag.getEndpoint(x, y) == Endpoint.ARROW) { + mag.setEndpoint(y, x, Endpoint.TAIL); + } + + if (mag.getEndpoint(y, x) == Endpoint.TAIL && mag.getEndpoint(x, y) == Endpoint.CIRCLE) { + mag.setEndpoint(x, y, Endpoint.ARROW); + } + + if (mag.getEndpoint(y, x) == Endpoint.CIRCLE && mag.getEndpoint(x, y) == Endpoint.CIRCLE) { + pcafci.addEdge(mag.getEdge(x, y)); + } + } + } + + for (Edge e : pcafci.getEdges()) { + e.setEndpoint1(Endpoint.TAIL); + e.setEndpoint2(Endpoint.TAIL); + } + + W: + while (true) { + for (Edge e : pcafci.getEdges()) { + if (Edges.isUndirectedEdge(e)) { + Node x = e.getNode1(); + Node y = e.getNode2(); + + pcafci.setEndpoint(y, x, Endpoint.TAIL); + pcafci.setEndpoint(x, y, Endpoint.ARROW); + + MeekRules meekRules = new MeekRules(); + meekRules.setRevertToUnshieldedColliders(false); + meekRules.orientImplied(pcafci); + + continue W; + } + } + + break; + } + + for (Edge e : pcafci.getEdges()) { + mag.removeEdge(e.getNode1(), e.getNode2()); + mag.addEdge(e); + } + + return mag; + } + + /** + * Generates the list of DAGs in the given cpdag. + */ + public static List generateCpdagDags(Graph cpdag, boolean orientBidirectedEdges) { + if (orientBidirectedEdges) { + cpdag = GraphUtils.removeBidirectedOrientations(cpdag); + } + + return getDagsInCpdagMeek(cpdag, new Knowledge()); + } + + public static List getDagsInCpdagMeek(Graph cpdag, Knowledge knowledge) { + DagInCpcagIterator iterator = new DagInCpcagIterator(cpdag, knowledge); + List dags = new ArrayList<>(); + + while (iterator.hasNext()) { + Graph graph = iterator.next(); + + try { + if (knowledge.isViolatedBy(graph)) { + continue; + } + + dags.add(graph); + } catch (IllegalArgumentException e) { + System.out.println("Found a non-DAG: " + graph); + } + } + + return dags; + } + + public static List getAllGraphsByDirectingUndirectedEdges(Graph skeleton) { + List graphs = new ArrayList<>(); + List edges = new ArrayList<>(skeleton.getEdges()); + + List undirectedIndices = new ArrayList<>(); + + for (int i = 0; i < edges.size(); i++) { + if (Edges.isUndirectedEdge(edges.get(i))) { + undirectedIndices.add(i); + } + } + + int[] dims = new int[undirectedIndices.size()]; + + for (int i = 0; i < undirectedIndices.size(); i++) { + dims[i] = 2; + } + + CombinationGenerator gen = new CombinationGenerator(dims); + int[] comb; + + while ((comb = gen.next()) != null) { + Graph graph = new EdgeListGraph(skeleton.getNodes()); + + for (Edge edge : edges) { + if (!Edges.isUndirectedEdge(edge)) { + graph.addEdge(edge); + } + } + + for (int i = 0; i < undirectedIndices.size(); i++) { + Edge edge = edges.get(undirectedIndices.get(i)); + Node node1 = edge.getNode1(); + Node node2 = edge.getNode2(); + + if (comb[i] == 1) { + graph.addEdge(Edges.directedEdge(node1, node2)); + } else { + graph.addEdge(Edges.directedEdge(node2, node1)); + } + } + + graphs.add(graph); + } + + return graphs; + } + + public static Graph cpdagForDag(Graph dag) { + Graph cpdag = new EdgeListGraph(dag); + MeekRules rules = new MeekRules(); + rules.setRevertToUnshieldedColliders(true); + rules.orientImplied(cpdag); + return cpdag; + } + + @NotNull + public static Graph dagToPag(Graph trueGraph) { + return new DagToPag(trueGraph).convert(); + } + + + private static void direct(Node a, Node c, Graph graph) { + Edge before = graph.getEdge(a, c); + Edge after = Edges.directedEdge(a, c); + graph.removeEdge(before); + graph.addEdge(after); + } +} diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java index 82f8bed834..fbabe43554 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java @@ -36,8 +36,6 @@ import java.util.*; import java.util.concurrent.RecursiveTask; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Basic graph utilities. * @@ -665,7 +663,10 @@ public static Set asSet(int[] indices, List nodes) { Set set = new HashSet<>(); for (int i : indices) { - set.add(nodes.get(i)); + if (i >= 0 && i < nodes.size()) { + set.add(nodes.get(i)); + } +// set.add(nodes.get(i)); } return set; @@ -1511,10 +1512,10 @@ public static Graph getComparisonGraph(Graph graph, Parameters params) { return new EdgeListGraph(graph); } else if ("CPDAG".equals(type)) { params.set("graphComparisonType", "CPDAG"); - return GraphSearchUtils.cpdagForDag(graph); + return GraphTransforms.cpdagForDag(graph); } else if ("PAG".equals(type)) { params.set("graphComparisonType", "PAG"); - return dagToPag(graph); + return GraphTransforms.dagToPag(graph); } else { params.set("graphComparisonType", "DAG"); return new EdgeListGraph(graph); @@ -1788,6 +1789,7 @@ public static Graph convert(String spec) { // Due to Spirtes. public static void gfciR0(Graph graph, Graph referenceCpdag, SepsetProducer sepsets, Knowledge knowledge) { graph.reorientAllWith(Endpoint.CIRCLE); + fciOrientbk(knowledge, graph, graph.getNodes()); List nodes = graph.getNodes(); @@ -1942,7 +1944,7 @@ private static Graph trimSemidirected(List targets, Graph graph) { for (Node m : graph.getNodes()) { if (!targets.contains(m)) { for (Node n : targets) { - if (graph.paths().existsSemidirectedPath(m, n)) { + if (graph.paths().existsSemiDirectedPath(m, n)) { continue M; } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java index 6aff92b49a..76dc7b8e9b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/IndependenceFact.java @@ -35,7 +35,7 @@ */ public final class IndependenceFact implements Comparable, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Node x; private final Node y; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java index 28c99d37e7..43ff9b5f0a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LagGraph.java @@ -31,7 +31,7 @@ * @author josephramsey */ public class LagGraph implements Graph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final List variables = new ArrayList<>(); private final Map> laggedVariables = new HashMap<>(); private final Map attributes = new HashMap<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java index ad0c08461d..c5bd1ac995 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/LayoutUtil.java @@ -5,10 +5,7 @@ import javax.swing.*; import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; public class LayoutUtil { public static void kamadaKawaiLayout(Graph graph, boolean randomlyInitialized, double naturalEdgeLength, double springConstant, double stopEnergy) { @@ -32,10 +29,23 @@ public static void arrangeByLayout(Graph graph, HashMap layout) } } + /** + * Arranges the nodes in the graph in a circle if there are 20 or fewer nodes, otherwise arranges them in a square. + * @param graph the graph to be arranged. + */ + public static void defaultLayout(Graph graph) { + if (graph.getNumNodes() <= 20) { + circleLayout(graph); + } else { + squareLayout(graph); + } + } + /** * Arranges the nodes in the graph in a circle. + * @param graph the graph to be arranged. */ - public static void circleLayout(Graph graph) { + private static void circleLayout(Graph graph) { if (graph == null) { return; } @@ -44,7 +54,7 @@ public static void circleLayout(Graph graph) { int centery = 120 + 7 * graph.getNumNodes(); int radius = centerx - 50; - List nodes = new ArrayList<>(graph.getNodes()); + List nodes = graph.getNodes(); Collections.sort(nodes); double rad = 6.28 / nodes.size(); @@ -114,6 +124,86 @@ public static void squareLayout(Graph graph) { } } + public static void layoutByCausalOrder(Graph graph) { + List> tiers = getTiers(graph); + + int y = 0; + + for (List tier : tiers) { + y += 60; + + if (tier.isEmpty()) continue; + + Node node = tier.get(0); + + int width = 80; + + int x = width / 2 + 10; + + node.setCenterX(x); + node.setCenterY(y); + + int lastHalf = width / 2; + + for (int i = 1; i < tier.size(); i++) { + node = tier.get(i); + int thisHalf = width / 2; + x += lastHalf + thisHalf + 5; + node.setCenterX(x); + node.setCenterY(y); + lastHalf = thisHalf; + } + } + } + + /** + * Finds the set of nodes which have no children, followed by the set of their parents, then the set of the parents' + * parents, and so on. The result is returned as a List of Lists. + * + * @return the tiers of this digraph. + */ + /** + * Finds the set of nodes which have no children, followed by the set of their parents, then the set of the parents' + * parents, and so on. The result is returned as a List of Lists. + * + * @return the tiers of this digraph. + */ + private static List> getTiers(Graph graph) { + Set found = new HashSet<>(); + List> tiers = new LinkedList<>(); + + // first copy all the nodes into 'notFound'. + Set notFound = new HashSet<>(graph.getNodes()); + + // repeatedly run through the nodes left in 'notFound'. If any node + // has all of its parents already in 'found', then add it to the + // getModel tier. + while (!notFound.isEmpty()) { + List thisTier = new LinkedList<>(); + + for (Node node : notFound) { + if (found.containsAll(graph.getParents(node))) { + thisTier.add(node); + } + } + + if (thisTier.isEmpty()) { + tiers.add(new ArrayList<>(notFound)); + break; + } + + // shift all the nodes in this tier from 'notFound' to 'found'. + thisTier.forEach(notFound::remove); + found.addAll(thisTier); + + // add the getModel tier to the list of tiers. + tiers.add(thisTier); + } + + return tiers; + } + + /** * Arranges the nodes in the result graph according to their positions in the source graph. * @@ -125,7 +215,7 @@ public static boolean arrangeBySourceGraph(Graph resultGraph, Graph sourceGraph) } if (sourceGraph == null) { - circleLayout(resultGraph); + defaultLayout(resultGraph); return true; } @@ -225,7 +315,7 @@ public KamadaKawaiLayout(Graph graph) { //============================PUBLIC METHODS==========================// public void doLayout() { - circleLayout(this.graph); + defaultLayout(this.graph); this.monitor = new ProgressMonitor(null, "Energy settling...", "Energy = ?", 0, 100); @@ -686,7 +776,7 @@ public FruchtermanReingoldLayout(Graph graph) { //============================PUBLIC METHODS==========================// public void doLayout() { - circleLayout(this.graph); + defaultLayout(this.graph); List> components = this.graph.paths().connectedComponents(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java index 34a1d46673..8f983fd76b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Node.java @@ -21,7 +21,6 @@ package edu.cmu.tetrad.graph; import edu.cmu.tetrad.util.TetradSerializable; -import org.jetbrains.annotations.NotNull; import java.beans.PropertyChangeListener; import java.util.Map; @@ -42,89 +41,176 @@ public interface Node extends TetradSerializable, Comparable { long serialVersionUID = 23L; /** + * Returns the name of this node. + * * @return the name of the node. */ String getName(); /** * Sets the name of this node. + * + * @param name the name of this node. */ void setName(String name); /** + * Returns the node type for this node. + * * @return the node type for this node. */ NodeType getNodeType(); /** * Sets the node type for this node. + * + * @param nodeType the node type for this node. */ void setNodeType(NodeType nodeType); /** + * Returns the node shape for this node. + * * @return the intervention type */ NodeVariableType getNodeVariableType(); /** * Sets the type (domain, interventional status, interventional value..) for this node variable + * + * @param nodeVariableType the type (domain, interventional status, interventional value..) for this node variable */ void setNodeVariableType(NodeVariableType nodeVariableType); /** + * Returns the intervention type for this node. + * * @return a string representation of the node. */ String toString(); /** + * Returns the x coordinate of the center of this node. + * * @return the x coordinate of the center of the node. */ int getCenterX(); /** * Sets the x coordinate of the center of this node. + * + * @param centerX This coordinate. */ void setCenterX(int centerX); /** + * Returns the y coordinate of the center of this node. + * * @return the y coordinate of the center of the node. */ int getCenterY(); /** * Sets the y coordinate of the center of this node. + * + * @param centerY This coordinate. */ void setCenterY(int centerY); /** * Sets the (x, y) coordinates of the center of this node. + * + * @param centerX The x coordinate. + * @param centerY The y coordinate. */ void setCenter(int centerX, int centerY); /** * Adds a property change listener. + * + * @param l This listener. */ void addPropertyChangeListener(PropertyChangeListener l); /** + * Removes a property change listener. + * * @return a hashcode for this variable. */ int hashCode(); /** + * Tests whether this variable is equal to the given variable. + * * @return true iff this variable is equal to the given variable. */ boolean equals(Object o); /** * Creates a new node of the same type as this one with the given name. + * + * @param name the name of the new node. + * @return the new node. */ Node like(String name); /** - * Alphabetical order. - */ - int compareTo(@NotNull Node node); + * Returns the hashcode for this node. + * + * @param node the object to be compared. + * @return the hashcode for this node. + */ + default int compareTo(Node node) { + String node1 = getName(); + String node2 = node.getName(); + + boolean isAlpha1 = Node.ALPHA.matcher(node1).matches(); + boolean isAlpha2 = Node.ALPHA.matcher(node2).matches(); + boolean isAlphaNum1 = Node.ALPHA_NUM.matcher(node1).matches(); + boolean isAlphaNum2 = Node.ALPHA_NUM.matcher(node2).matches(); + boolean isLag1 = Node.LAG.matcher(node1).matches(); + boolean isLag2 = Node.LAG.matcher(node2).matches(); + + if (isAlpha1) { + if (isLag2) { + return -1; + } + } else if (isAlphaNum1) { + if (isAlphaNum2) { + String s1 = node1.replaceAll("\\d+", ""); + String s2 = node2.replaceAll("\\d+", ""); + if (s1.equals(s2)) { + String n1 = node1.replaceAll("\\D+", ""); + String n2 = node2.replaceAll("\\D+", ""); + + return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); + } else { + return s1.compareTo(s2); + } + } else if (isLag2) { + return -1; + } + } else if (isLag1) { + if (isAlpha2 || isAlphaNum2) { + return 1; + } else if (isLag2) { + String l1 = node1.replaceAll(":", ""); + String l2 = node2.replaceAll(":", ""); + String s1 = l1.replaceAll("\\d+", ""); + String s2 = l2.replaceAll("\\d+", ""); + if (s1.equals(s2)) { + String n1 = l1.replaceAll("\\D+", ""); + String n2 = l2.replaceAll("\\D+", ""); + + return Integer.valueOf(n1).compareTo(Integer.valueOf(n2)); + } else { + return s1.compareTo(s2); + } + } + } + + return node1.compareTo(node2); + } Map getAllAttributes(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java index d221e6bcd1..586fb6f3d7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeType.java @@ -39,7 +39,7 @@ public final class NodeType implements TetradSerializable { public static final NodeType LOCK = new NodeType("Lock"); public static final NodeType NO_TYPE = new NodeType("No type"); public static final NodeType[] TYPES = {NodeType.MEASURED, NodeType.LATENT, NodeType.ERROR, NodeType.NO_TYPE, NodeType.RANDOMIZE, NodeType.LOCK}; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; // Declarations required for serialization. private static int nextOrdinal; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeVariableType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeVariableType.java index 2f7ec10f00..15f6301cbf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeVariableType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/NodeVariableType.java @@ -6,6 +6,8 @@ package edu.cmu.tetrad.graph; /** + * Node variable type. + * * @author Zhou Yuan zhy19@pitt.edu */ public enum NodeVariableType { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/OrderedPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/OrderedPair.java index e4df42c432..7308c8eef3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/OrderedPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/OrderedPair.java @@ -28,9 +28,10 @@ * An ordered pair of objects. This does not serialize well, unfortunately. * * @author Tyler Gibson + * @param The type of the objects in the pair. */ public class OrderedPair implements TetradSerializable, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The "First" node. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java index cbde1eee8c..266b4b1022 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Paths.java @@ -10,7 +10,7 @@ import java.util.concurrent.ConcurrentSkipListSet; public class Paths implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph graph; @@ -1184,7 +1184,7 @@ private boolean existOnePathWithPossibleParents(Map> previous, N continue; } - if ((existsSemidirectedPath(r, x)) || existsSemidirectedPath(r, b)) { + if ((existsSemiDirectedPath(r, x)) || existsSemiDirectedPath(r, b)) { return true; } } @@ -1192,48 +1192,6 @@ private boolean existOnePathWithPossibleParents(Map> previous, N return false; } - public boolean existsSemidirectedPath(Node from, Node to) { - Queue Q = new LinkedList<>(); - Set V = new HashSet<>(); - - for (Node u : graph.getAdjacentNodes(from)) { - Edge edge = graph.getEdge(from, u); - Node c = GraphUtils.traverseSemiDirected(from, edge); - - if (c == null) { - continue; - } - - if (!V.contains(c)) { - V.add(c); - Q.offer(c); - } - } - - while (!Q.isEmpty()) { - Node t = Q.remove(); - - if (t == to) { - return true; - } - - for (Node u : graph.getAdjacentNodes(t)) { - Edge edge = graph.getEdge(t, u); - Node c = GraphUtils.traverseSemiDirected(t, edge); - - if (c == null) { - continue; - } - - if (!V.contains(c)) { - V.add(c); - Q.offer(c); - } - } - } - - return false; - } /** * Check to see if a set of variables Z satisfies the back-door criterion relative to node x and node y. @@ -1661,13 +1619,8 @@ public boolean existsDirectedPathFromTo(Node node1, Node node2) { return false; } - public boolean existsSemiDirectedPathFromTo(Node node1, Node node2) { - return existsSemiDirectedPathFromTo(node1, Collections.singleton(node2)); - } - - public boolean existsSemiDirectedPathFromTo(Node node1, Set nodes) { - return existsSemiDirectedPathVisit(node1, nodes, - new LinkedList<>()); + public boolean existsSemiDirectedPath(Node node1, Set nodes) { + return existsSemiDirectedPathVisit(node1, nodes, new LinkedList<>()); } /** @@ -1732,7 +1685,7 @@ public boolean isDescendentOf(Node node1, Node node2) { * * @return true iff node2 is a definite nondecendent of node1 */ - public boolean defNonDescendent(Node node1, Node node2) { + public boolean definiteNonDescendent(Node node1, Node node2) { return !(possibleAncestor(node1, node2)); } @@ -1756,8 +1709,7 @@ public boolean isMSeparatedFrom(Node node1, Node node2, Set z) { /** * @return true iff there is a semi-directed path from node1 to node2 */ - private boolean existsSemiDirectedPathVisit(Node node1, Set nodes2, - LinkedList path) { + private boolean existsSemiDirectedPathVisit(Node node1, Set nodes2, LinkedList path) { path.addLast(node1); for (Edge edge : graph.getEdges(node1)) { @@ -1799,8 +1751,7 @@ public boolean isUndirectedFromTo(Node node1, Node node2) { } public boolean possibleAncestor(Node node1, Node node2) { - return existsSemiDirectedPathFromTo(node1, - Collections.singleton(node2)); + return existsSemiDirectedPath(node1, Collections.singleton(node2)); } public static class AllCliquesAlgorithm { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java index a12ab4073a..d373a041df 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/RandomGraph.java @@ -80,7 +80,7 @@ public static Graph randomGraphUniform(List nodes, int numLatentConfounder // dag. Arrange the nodes in a circle. fixLatents1(numLatentConfounders, dag); - LayoutUtil.circleLayout(dag); + LayoutUtil.defaultLayout(dag); return dag; } @@ -180,7 +180,7 @@ public static Graph randomGraphRandomForwardEdges(List nodes, int numLaten fixLatents4(numLatentConfounders, dag); if (layoutAsCircle) { - LayoutUtil.circleLayout(dag); + LayoutUtil.defaultLayout(dag); } return dag; @@ -274,7 +274,7 @@ private static Graph randomScaleFreeGraph(List _nodes, int numLatentConfou fixLatents1(numLatentConfounders, G); - LayoutUtil.circleLayout(G); + LayoutUtil.defaultLayout(G); return G; } @@ -474,7 +474,7 @@ public static Graph randomCyclicGraph2(int numNodes, int numEdges, int maxDegree } } - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); return graph; } @@ -578,7 +578,7 @@ public static Graph randomCyclicGraph3(int numNodes, int numEdges, int maxDegree } } - LayoutUtil.circleLayout(graph); + LayoutUtil.defaultLayout(graph); return graph; } @@ -864,7 +864,7 @@ public Graph getDag(List nodes) { } // System.out.println("Arranging in circle."); - LayoutUtil.circleLayout(dag); + LayoutUtil.defaultLayout(dag); //System.out.println("DAG conversion completed."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java index 476ced5fd3..a73e4181c0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/SemGraph.java @@ -45,7 +45,7 @@ * @author josephramsey */ public final class SemGraph implements Graph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The underlying graph that stores all the information. This needs to be an EdgeListGraph or something at least diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java index d1d7c6c777..806f1c5652 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/TimeLagGraph.java @@ -32,7 +32,7 @@ * @author josephramsey */ public class TimeLagGraph implements Graph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Map attributes = new HashMap<>(); /** * Fires property change events. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java index bffabb783d..fa64c9bbbf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Triple.java @@ -32,7 +32,7 @@ * @author josephramsey, after Frank Wimberly. */ public final class Triple implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; // Note: Switching all uses of Underline to Triple, since they did the // same thing, and this allows for some useful generalizations, especially diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java index dbf722ec82..8a5bfc2d29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/Underlines.java @@ -10,7 +10,7 @@ // This used ot be a field in the graph classes but that led to a circular dependency // between the graph and the graph reader/writer. So now it's a separate class. public class Underlines implements TripleClassifier, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph graph; private Set underLineTriples; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/LogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/LogisticRegression.java index 042eecddf2..2b5491eca1 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/LogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/LogisticRegression.java @@ -48,7 +48,7 @@ * @author Frank Wimberly */ public class LogisticRegression implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The data set that was supplied. @@ -387,7 +387,7 @@ private void readObject(ObjectInputStream s) //================================== Public Methods =======================================// public static class Result implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double chiSq; private final double alpha; private final List regressorNames; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java index d7162c6420..f49ccdcd97 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/regression/RegressionResult.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class RegressionResult implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * True iff this model assumes a zero intercept. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java index 96a28734d6..e001129de8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/BFci.java @@ -123,7 +123,6 @@ public Graph search() { Graph graph = alg.search(); - Knowledge knowledge2 = new Knowledge(knowledge); Graph referenceDag = new EdgeListGraph(graph); // GFCI extra edge removal step... @@ -137,7 +136,7 @@ public Graph search() { fciOrient.setDoDiscriminatingPathColliderRule(this.doDiscriminatingPathRule); fciOrient.setDoDiscriminatingPathTailRule(this.doDiscriminatingPathRule); fciOrient.setVerbose(verbose); - fciOrient.setKnowledge(knowledge2); + fciOrient.setKnowledge(knowledge); fciOrient.doFinalOrientation(graph); 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 f9851780c7..d2ca4feeb0 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 @@ -15,13 +15,13 @@ /** *

    Implements Best Order Score Search (BOSS). The following references are relevant:

    * - *

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

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

    * - *

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

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

    * - *

    Solus, L., Wang, Y., & Uhler, C. (2021). Consistency guarantees for greedy permutation-based causal inference + *

    Solus, L., Wang, Y., & Uhler, C. (2021). Consistency guarantees for greedy permutation-based causal inference * algorithms. Biometrika, 108(4), 795-814.

    * *

    The BOSS algorithm is based on the idea that implied DAGs for permutations are most optimal in their BIC scores @@ -45,9 +45,9 @@ *

  • Return this CPDAG.
  • * * - * The optional BES step is needed for correctness, though with large + *

    The optional BES step is needed for correctness, though with large * models is has very little effect on the output, since nearly all edges - * are already oriented, so a parameter is included to turn that step off. + * are already oriented, so a parameter is included to turn that step off.

    * *

    Knowledge can be used with this search. If tiered knowledge is used, * then the procedure is carried out for each tier separately, given the 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 1f182286dc..4c98673ad6 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 @@ -38,9 +38,9 @@ *

    Richardson, T. S. (2013). A discovery algorithm for directed cyclic graphs. arXiv * preprint arXiv:1302.3599.

    * - *

    See also Chapter 7 of:

    + *

    See also Chapter 7 of:

    * - *

    Glymour, C. N., & Cooper, G. F. (Eds.). (1999). Computation, causation, and + *

    Glymour, C. N., & Cooper, G. F. (Eds.). (1999). Computation, causation, and * discovery. Aaai Press.

    * *

    The graph takes continuous data from a cyclic model as input and returns a cyclic diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java index 090f56229d..69e575f82f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cfci.java @@ -318,8 +318,8 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { Set sepset = sepsets.get(x, z); if (type == TripleType.COLLIDER || (sepset != null && !sepset.contains(y))) { - if (isArrowheadAllowed(x, y) && - isArrowheadAllowed(z, y)) { + if (FciOrient.isArrowheadAllowed(x, y, graph, knowledge) && + FciOrient.isArrowheadAllowed(z, y, graph, knowledge)) { getGraph().setEndpoint(x, y, Endpoint.ARROW); getGraph().setEndpoint(z, y, Endpoint.ARROW); @@ -344,33 +344,6 @@ private void ruleR0(IndependenceTest test, int depth, SepsetMap sepsets) { } } - /** - * Helper method. Appears to check if an arrowhead is permitted by background knowledge. - * - * @param x The possible other node. - * @param y The possible point node. - * @return Whether the arrowhead is allowed. - */ - private boolean isArrowheadAllowed(Node x, Node y) { - if (this.graph.getEndpoint(x, y) == Endpoint.ARROW) { - return true; - } - - if (this.graph.getEndpoint(x, y) == Endpoint.TAIL) { - return false; - } - - if (this.graph.getEndpoint(y, x) == Endpoint.ARROW) { - if (!this.knowledge.isForbidden(x.getName(), y.getName())) return true; - } - - if (this.graph.getEndpoint(y, x) == Endpoint.TAIL) { - if (!this.knowledge.isForbidden(x.getName(), y.getName())) return true; - } - - return this.graph.getEndpoint(y, x) == Endpoint.CIRCLE; - } - private TripleType getTripleType(Node x, Node y, Node z, IndependenceTest test, int depth) { boolean existsSepsetContainingY = false; 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 fc37c8bf5f..a5db19f91e 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 @@ -41,8 +41,8 @@ *

    Ramsey, J., Zhang, J., & Spirtes, P. L. (2012). Adjacency-faithfulness and conservative causal inference. * arXiv preprint arXiv:1206.6843.

    * - *

    Conservative triple orientation is a method for orienting unshielded triples X*=-*Y*-*Z as one of the following: - * (a) Collider, X->Y<-Z, (b) Noncollider, X-->Y-->Z, or X<-Y<-Z, or X<-Y->Z, (c) ambiguous between (a) or (b). One does + *

    Conservative triple orientation is a method for orienting unshielded triples X*-*Y*-*Z as one of the following: + * (a) Collider, X->Y<-Z, (b) Noncollider, X-->Y-->Z, or X<-Y<-Z, or X<-Y->Z, (c) ambiguous between (a) or (b). One does * this by conditioning on subsets of adj(X) or adj(Z). One first checks conditional independence of X and Z conditional * on each of these subsets, then lists all of these subsets conditional on which X and Z are *independent*, then looks * thoough this list to see if Y is in them. If Y is in all of these subset, the triple is judged to be a noncollider; @@ -283,7 +283,7 @@ public void setVerbose(boolean verbose) { *

    Sets whether the stable adjacency search should be used. Default is false. Default is false. See the * following reference for this:

    * - *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. + *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. * Learn. Res., 15(1), 3741-3782.

    * * @param stable True iff the case. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java index 309f56e0a4..df608c89e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Cstar.java @@ -200,7 +200,8 @@ public LinkedList> getRecords(DataSet dataSet, List pos if (new File(origDir, "data.txt").exists()) { try { - dataSet = SimpleDataLoader.loadContinuousData(new File(origDir, "data.txt"), "//", '\"', "*", true, Delimiter.TAB); + dataSet = SimpleDataLoader.loadContinuousData(new File(origDir, "data.txt"), "//", + '\"', "*", true, Delimiter.TAB, false); } catch (Exception e) { throw new IllegalArgumentException("Could not load data from " + new File(origDir, "data.txt").getAbsolutePath()); } @@ -626,7 +627,8 @@ private void saveMatrix(double[][] effects, File file) { private double[][] loadMatrix(File file) { try { - DataSet dataSet = SimpleDataLoader.loadContinuousData(file, "//", '\"', "*", true, Delimiter.TAB); + DataSet dataSet = SimpleDataLoader.loadContinuousData(file, "//", + '\"', "*", true, Delimiter.TAB, false); return dataSet.getDoubleData().toArray(); } catch (IOException e) { throw new RuntimeException(e); @@ -677,7 +679,7 @@ public enum SampleStyle {BOOTSTRAP, SUBSAMPLE} * Represents a single record in the returned table for CSTaR. */ public static class Record implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Node causeNode; private final Node target; private final double pi; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java index aa8e73e3a1..8942219381 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fas.java @@ -324,7 +324,7 @@ public void setPcHeuristicType(PcCommon.PcHeuristicType pcHeuristic) { *

    Sets whether the stable adjacency search should be used. Default is false. Default is false. See the * following reference for this:

    * - *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. + *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. * Learn. Res., 15(1), 3741-3782.

    * * @param stable True iff the case. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java index e57be01a02..3abc85bf77 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fask.java @@ -22,7 +22,7 @@ package edu.cmu.tetrad.search; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.RegressionDataset; @@ -250,7 +250,7 @@ public Graph search() { long start = MillisecondTimes.timeMillis(); NumberFormat nf = new DecimalFormat("0.000"); - DataSet dataSet = DataUtils.standardizeData(this.dataSet); + DataSet dataSet = DataTransforms.standardizeData(this.dataSet); List variables = dataSet.getVariables(); double[][] lrs = getLrScores(); // Sets D. @@ -377,7 +377,7 @@ public Graph search() { continue; } - if (this.twoCycleScreeningCutoff > 0 && abs(faskLeftRightV2(x, y)) < this.twoCycleScreeningCutoff) { + if (this.twoCycleScreeningCutoff > 0 && abs(faskLeftRightV2(x, y, empirical, delta)) < this.twoCycleScreeningCutoff) { TetradLogger.getInstance().forceLogMessage(X + "\t" + Y + "\t2-cycle Prescreen" + "\t" + nf.format(lr) + "\t" + X + "...TC?..." + Y @@ -476,7 +476,7 @@ public double[][] getB() { */ public double[][] getLrScores() { List variables = this.dataSet.getVariables(); - double[][] D = DataUtils.standardizeData(this.dataSet).getDoubleData().transpose().toArray(); + double[][] D = DataTransforms.standardizeData(this.dataSet).getDoubleData().transpose().toArray(); double[][] lr = new double[variables.size()][variables.size()]; @@ -617,38 +617,38 @@ public void setEmpirical(boolean empirical) { */ public double leftRight(double[] x, double[] y) { if (this.leftRight == LeftRight.FASK1) { - return faskLeftRightV1(x, y); + return faskLeftRightV1(x, y, empirical, delta); } else if (this.leftRight == LeftRight.FASK2) { - return faskLeftRightV2(x, y); + return faskLeftRightV2(x, y, empirical, delta); } else if (this.leftRight == LeftRight.RSKEW) { - return robustSkew(x, y); + return robustSkew(x, y, empirical); } else if (this.leftRight == LeftRight.SKEW) { - return skew(x, y); + return skew(x, y, empirical); } else if (this.leftRight == LeftRight.TANH) { - return tanh(x, y); + return tanh(x, y, empirical); } throw new IllegalStateException("Left right rule not configured: " + this.leftRight); } - private double faskLeftRightV2(double[] x, double[] y) { + public static double faskLeftRightV2(double[] x, double[] y, boolean empirical, double delta) { double sx = skewness(x); double sy = skewness(y); double r = correlation(x, y); double lr = Fask.correxp(x, y, x) - Fask.correxp(x, y, y); - if (this.empirical) { + if (empirical) { lr *= signum(sx) * signum(sy); } - if (r < this.delta) { + if (r < delta) { lr *= -1; } return lr; } - private double faskLeftRightV1(double[] x, double[] y) { + public static double faskLeftRightV1(double[] x, double[] y, boolean empirical, double delta) { double left = Fask.cu(x, y, x) / (sqrt(Fask.cu(x, x, x) * Fask.cu(y, y, x))); double right = Fask.cu(x, y, y) / (sqrt(Fask.cu(x, x, y) * Fask.cu(y, y, y))); double lr = left - right; @@ -657,19 +657,19 @@ private double faskLeftRightV1(double[] x, double[] y) { double sx = skewness(x); double sy = skewness(y); - if (this.empirical) { + if (empirical) { r *= signum(sx) * signum(sy); } lr *= signum(r); - if (r < this.delta) lr *= -1; + if (r < delta) lr *= -1; return lr; } - private double robustSkew(double[] x, double[] y) { + public static double robustSkew(double[] x, double[] y, boolean empirical) { - if (this.empirical) { + if (empirical) { x = correctSkewness(x, skewness(x)); y = correctSkewness(y, skewness(y)); } @@ -683,9 +683,9 @@ private double robustSkew(double[] x, double[] y) { return correlation(x, y) * mean(lr); } - private double skew(double[] x, double[] y) { + public static double skew(double[] x, double[] y, boolean empirical) { - if (this.empirical) { + if (empirical) { x = correctSkewness(x, skewness(x)); y = correctSkewness(y, skewness(y)); } @@ -699,9 +699,9 @@ private double skew(double[] x, double[] y) { return correlation(x, y) * mean(lr); } - private double tanh(double[] x, double[] y) { + private double tanh(double[] x, double[] y, boolean empirical) { - if (this.empirical) { + if (empirical) { x = correctSkewness(x, skewness(x)); y = correctSkewness(y, skewness(y)); } @@ -715,7 +715,7 @@ private double tanh(double[] x, double[] y) { return correlation(x, y) * mean(lr); } - private double g(double x) { + public static double g(double x) { return log(cosh(FastMath.max(x, 0))); } @@ -727,7 +727,7 @@ private boolean edgeForbiddenByKnowledge(Node X, Node Y) { return this.knowledge.isForbidden(Y.getName(), X.getName()) && this.knowledge.isForbidden(X.getName(), Y.getName()); } - private double[] correctSkewness(double[] data, double sk) { + public static double[] correctSkewness(double[] data, double sk) { double[] data2 = new double[data.length]; for (int i = 0; i < data.length; i++) data2[i] = data[i] * signum(sk); return data2; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java index ab18389a4b..7692028629 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FastIca.java @@ -120,7 +120,7 @@ *

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

    + *

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java index f1a6f58355..362d9906b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FciMax.java @@ -46,7 +46,7 @@ * models. Thorax, 74(7), 643-649.

    * *

    Max-P triple orientation is a method for orienting unshielded triples - * X*=-*Y*-*Z as one of the following: (a) Collider, X->Y<-Z, or (b) Noncollider, X-->Y-->Z, or X<-Y<-Z, or X<-Y->Z. One + * X*=-*Y*-*Z as one of the following: (a) Collider, X->Y<-Z, or (b) Noncollider, X-->Y-->Z, or X<-Y<-Z, or X<-Y->Z. One * does this by conditioning on subsets of adj(X) or adj(Z). One first checks conditional independence of X and Z * conditional on each of these subsets, and lists the p-values for each test. Then, one chooses the conditioning set * out of all of these that maximizes the p-value. If this conditioning set contains Y, then the triple is judged to be diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java index dcd7783562..094758eeb9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Fges.java @@ -28,7 +28,6 @@ import edu.cmu.tetrad.search.score.ScoredGraph; import edu.cmu.tetrad.search.utils.Bes; import edu.cmu.tetrad.search.utils.DagScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.SublistGenerator; @@ -241,7 +240,7 @@ public Graph search() { this.logger.forceLogMessage("Elapsed time = " + (elapsedTime) / 1000. + " s"); } - this.modelScore = scoreDag(GraphSearchUtils.dagFromCPDAG(graph), true); + this.modelScore = scoreDag(GraphTransforms.dagFromCPDAG(graph, null), true); return graph; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java index 6c328f25af..b78b44f668 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/FgesMb.java @@ -28,10 +28,8 @@ import edu.cmu.tetrad.search.score.ScoredGraph; import edu.cmu.tetrad.search.utils.Bes; import edu.cmu.tetrad.search.utils.DagScorer; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.MillisecondTimes; -import edu.cmu.tetrad.util.Params; import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.jetbrains.annotations.NotNull; @@ -232,7 +230,7 @@ public Graph search(List targets) { this.logger.forceLogMessage("Elapsed time = " + (elapsedTime) / 1000. + " s"); } - this.modelScore = scoreDag(GraphSearchUtils.dagFromCPDAG(graph), true); + this.modelScore = scoreDag(GraphTransforms.dagFromCPDAG(graph, null), true); graph = GraphUtils.trimGraph(targets, graph, trimmingStyle); return graph; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/GraspFci.java index 009d4f1449..c5b5405fc4 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 @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // +// For information as to what this class does, see the Javadoc, below. //i // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // // 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // // Scheines, Joseph Ramsey, and Clark Glymour. // @@ -131,7 +131,7 @@ public Graph search() { alg.bestOrder(variables); Graph graph = alg.getGraph(true); // Get the DAG - Knowledge knowledge2 = new Knowledge(knowledge); +// Knowledge knowledge2 = new Knowledge(knowledge); Graph referenceDag = new EdgeListGraph(graph); // GFCI extra edge removal step... @@ -145,7 +145,7 @@ public Graph search() { fciOrient.setDoDiscriminatingPathColliderRule(this.doDiscriminatingPathRule); fciOrient.setDoDiscriminatingPathTailRule(this.doDiscriminatingPathRule); fciOrient.setVerbose(verbose); - fciOrient.setKnowledge(knowledge2); + fciOrient.setKnowledge(knowledge); fciOrient.doFinalOrientation(graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java index ce7bf74955..39c5ec9db1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IcaLingD.java @@ -23,7 +23,7 @@ import edu.cmu.tetrad.data.AndersonDarlingTest; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.graph.EdgeListGraph; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphNode; @@ -148,7 +148,7 @@ public static Matrix estimateW(DataSet data, int fastIcaMaxIter, double fastIcaT TetradLogger.getInstance().forceLogMessage(""); Matrix X = data.getDoubleData(); - X = DataUtils.centerData(X).transpose(); + X = DataTransforms.centerData(X).transpose(); FastIca fastIca = new FastIca(X, X.getNumRows()); fastIca.setVerbose(false); fastIca.setMaxIterations(fastIcaMaxIter); @@ -244,7 +244,7 @@ public static Matrix scale(Matrix M) { * Thresholds the given matrix, sending any small entries in absolute value to zero. * * @param M The matrix to threshold. - * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. Should be non-negative. + * @param threshold The value such that M(i, j) is set to zero if |M(i, j)| < threshold. Should be non-negative. * @return The thresholded matrix. */ public static Matrix threshold(Matrix M, double threshold) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java index 2b1d776d51..586627ef7a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Ida.java @@ -1,9 +1,6 @@ package edu.cmu.tetrad.search; -import edu.cmu.tetrad.data.CovarianceMatrix; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.ICovarianceMatrix; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.graph.Node; @@ -48,7 +45,7 @@ public class Ida { * @param possibleCauses The possible causes to be considered. */ public Ida(DataSet dataSet, Graph cpdag, List possibleCauses) { - this.dataSet = DataUtils.convertNumericalDiscreteToContinuous(dataSet); + this.dataSet = DataTransforms.convertNumericalDiscreteToContinuous(dataSet); this.pattern = cpdag; possibleCauses = GraphUtils.replaceNodes(possibleCauses, dataSet.getVariables()); this.possibleCauses = possibleCauses; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIod.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIod.java index 648ef09fc7..bd5cd3e3e0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIod.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/IndTestIod.java @@ -36,7 +36,7 @@ *

    Checks independence result by listing all tests with those variables, testing each one, and returning the * resolution of these test results. The reference is here:

    * - *

    Tillman, R., & Spirtes, P. (2011, June). Learning equivalence classes of acyclic models with latent and selection + *

    Tillman, R., & Spirtes, P. (2011, June). Learning equivalence classes of acyclic models with latent and selection * variables from multiple datasets with overlapping variables. In Proceedings of the Fourteenth International * Conference on Artificial Intelligence and Statistics (pp. 3-15). JMLR Workshop and Conference Proceedings.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java index 4bf13b2d51..7cee5b015a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Lofs.java @@ -48,7 +48,7 @@ * literature and can be googled, though we should certainly give this reference for several of them, to which we are * indebted:

    * - *

    Hyvärinen, A., & Smith, S. M. (2013). Pairwise likelihood ratios for estimation + *

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

    * *

    This class is configured to respect knowledge of forbidden and required @@ -364,7 +364,7 @@ private void ruleR1TimeLag(Graph skeleton, Graph graph) { } private void ruleR1(Graph skeleton, Graph graph, List nodes) { - List centeredData = DataUtils.center(this.dataSets); + List centeredData = DataTransforms.center(this.dataSets); setDataSets(centeredData); for (Node node : nodes) { @@ -442,7 +442,7 @@ private void ruleR1(Graph skeleton, Graph graph, List nodes) { } private void ruleR2(Graph skeleton, Graph graph) { - List standardized = DataUtils.standardizeData(this.dataSets); + List standardized = DataTransforms.standardizeData(this.dataSets); setDataSets(standardized); Set edgeList1 = skeleton.getEdges(); @@ -693,7 +693,7 @@ private void resolveOneEdgeMax2(Graph graph, Node x, Node y, boolean strong) { } private void ruleR3(Graph graph) { - List standardized = DataUtils.standardizeData(this.dataSets); + List standardized = DataTransforms.standardizeData(this.dataSets); setDataSets(standardized); Set edgeList1 = graph.getEdges(); @@ -789,8 +789,8 @@ public double scoreRow(int rowIndex, Matrix data, List> rows, List } private Graph entropyBased(Graph graph) { - DataSet dataSet = DataUtils.concatenate(this.dataSets); - dataSet = DataUtils.standardizeData(dataSet); + DataSet dataSet = DataTransforms.concatenate(this.dataSets); + dataSet = DataTransforms.standardizeData(dataSet); Graph _graph = new EdgeListGraph(graph.getNodes()); for (Edge edge : graph.getEdges()) { @@ -833,9 +833,9 @@ private Graph entropyBased(Graph graph) { } private Graph tanhGraph(Graph graph) { - DataSet dataSet = DataUtils.concatenate(this.dataSets); + DataSet dataSet = DataTransforms.concatenate(this.dataSets); graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); - dataSet = DataUtils.standardizeData(dataSet); + dataSet = DataTransforms.standardizeData(dataSet); double[][] data = dataSet.getDoubleData().transpose().toArray(); Graph _graph = new EdgeListGraph(graph.getNodes()); List nodes = dataSet.getVariables(); @@ -895,9 +895,9 @@ private Graph tanhGraph(Graph graph) { // @param empirical True if the skew signs are estimated empirically. private Graph skewGraph(Graph graph, boolean empirical) { - DataSet dataSet = DataUtils.concatenate(this.dataSets); + DataSet dataSet = DataTransforms.concatenate(this.dataSets); graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); - dataSet = DataUtils.standardizeData(dataSet); + dataSet = DataTransforms.standardizeData(dataSet); double[][] data = dataSet.getDoubleData().transpose().toArray(); Graph _graph = new EdgeListGraph(graph.getNodes()); List nodes = dataSet.getVariables(); @@ -964,9 +964,9 @@ private Graph skewGraph(Graph graph, boolean empirical) { private Graph robustSkewGraph(Graph graph, boolean empirical) { // DataUtils.standardizeData(dataSet)); List _dataSets = new ArrayList<>(this.dataSets); - DataSet dataSet = DataUtils.concatenate(_dataSets); + DataSet dataSet = DataTransforms.concatenate(_dataSets); graph = GraphUtils.replaceNodes(graph, dataSet.getVariables()); - dataSet = DataUtils.standardizeData(dataSet); + dataSet = DataTransforms.standardizeData(dataSet); double[][] data = dataSet.getDoubleData().transpose().toArray(); List nodes = dataSet.getVariables(); Map nodesHash = new HashMap<>(); @@ -1032,9 +1032,9 @@ private double g(double x) { // cutoff is NaN if no thresholding is to be done, otherwise a threshold between 0 and 1. private Graph patelTauOrientation(Graph graph, double cutoff) { - List centered = DataUtils.center(this.dataSets); - DataSet concat = DataUtils.concatenate(centered); - DataSet dataSet = DataUtils.standardizeData(concat); + List centered = DataTransforms.center(this.dataSets); + DataSet concat = DataTransforms.concatenate(centered); + DataSet dataSet = DataTransforms.standardizeData(concat); Graph _graph = new EdgeListGraph(graph.getNodes()); @@ -1464,7 +1464,7 @@ private double score(double[] col) { } else if (this.score == Lofs.Score.entropy) { return maxEntApprox(col); } else if (this.score == Lofs.Score.kurtosis) { - col = DataUtils.standardizeData(col); + col = DataTransforms.standardizeData(col); return -abs(kurtosis(col)); } else if (this.score == Lofs.Score.skew) { return abs(skewness(col)); @@ -1577,7 +1577,7 @@ private double[] residuals(Node node, List parents, boolean standardize) { } if (standardize) { - _f = DataUtils.standardizeData(_f); + _f = DataTransforms.standardizeData(_f); } return _f; @@ -1696,7 +1696,7 @@ private Graph resolveEdgeConditional(Graph graph) { private void resolveEdgeConditional(Graph graph, Node x, Node y) { if (this._data == null) { - this._data = DataUtils.centerData(this.matrices.get(0)); + this._data = DataTransforms.centerData(this.matrices.get(0)); } int xIndex = this.dataSets.get(0).getColumn(this.dataSets.get(0).getVariable(x.getName())); int yIndex = this.dataSets.get(0).getColumn(this.dataSets.get(0).getVariable(y.getName())); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java index e3ad8b9a29..fef052901c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java @@ -9,6 +9,7 @@ import edu.cmu.tetrad.util.SublistGenerator; import edu.cmu.tetrad.util.UniformityTest; import org.apache.commons.math3.util.FastMath; +import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.concurrent.Callable; @@ -74,39 +75,9 @@ public void generateResults() { resultsDep.clear(); if (setType == ConditioningSetType.ALL_SUBSETS) { - List variables = independenceTest.getVariables(); - List nodes = new ArrayList<>(variables); - Collections.sort(nodes); - - for (Node x : nodes) { - List other = new ArrayList<>(graph.getNodes()); - Collections.sort(other); - other.remove(x); - - List msep = new ArrayList<>(); - List mconn = new ArrayList<>(); - - for (Node y : other) { - List _other = new ArrayList<>(other); - _other.remove(y); - - SublistGenerator generator = new SublistGenerator(_other.size(), _other.size()); - int[] list; - - while ((list = generator.next()) != null) { - Set z = GraphUtils.asSet(list, _other); - - if (this.msep.isMSeparated(x, y, z)) { - msep.add(new IndependenceFact(x, y, z)); - } else { - mconn.add(new IndependenceFact(x, y, z)); - } - } - } - - generateResultsAllSubsets(true, msep, mconn); - generateResultsAllSubsets(false, msep, mconn); - } + AllSubsetsIndependenceFacts result = getAllSubsetsIndependenceFacts(graph); + generateResultsAllSubsets(true, result.msep, result.mconn); + generateResultsAllSubsets(false, result.msep, result.mconn); } else { List variables = independenceTest.getVariables(); List nodes = new ArrayList<>(variables); @@ -152,6 +123,74 @@ public void generateResults() { calcStats(false); } + @NotNull + public static AllSubsetsIndependenceFacts getAllSubsetsIndependenceFacts(Graph graph) { + List variables = new ArrayList<>(graph.getNodes()); + MsepTest msepTest = new MsepTest(graph); + + List nodes = new ArrayList<>(variables); + Collections.sort(nodes); + + List msep = new ArrayList<>(); + List mconn = new ArrayList<>(); + + for (Node x : nodes) { + List other = new ArrayList<>(variables); + Collections.sort(other); + other.remove(x); + + for (Node y : other) { + List _other = new ArrayList<>(other); + _other.remove(y); + + SublistGenerator generator = new SublistGenerator(_other.size(), _other.size()); + int[] list; + + while ((list = generator.next()) != null) { + Set z = GraphUtils.asSet(list, _other); + + if (msepTest.isMSeparated(x, y, z)) { + msep.add(new IndependenceFact(x, y, z)); + } else { + mconn.add(new IndependenceFact(x, y, z)); + } + } + } + } + return new AllSubsetsIndependenceFacts(msep, mconn); + } + + public static class AllSubsetsIndependenceFacts { + public final List msep; + public final List mconn; + + public AllSubsetsIndependenceFacts(List msep, List mconn) { + this.msep = msep; + this.mconn = mconn; + } + + public String toStringIndep() { + StringBuilder builder = new StringBuilder("All subsets independence facts:\n"); + + for (IndependenceFact fact : msep) { + builder.append(fact).append("\n"); + } + + return builder.toString(); + } + + + public String toStringDep() { + StringBuilder builder = new StringBuilder("All subsets independence facts:\n"); + + for (IndependenceFact fact : mconn) { + builder.append(fact).append("\n"); + } + + return builder.toString(); + } + } + /** * Returns type of conditioning sets to use in the Markov check. * 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 b19ea6dbec..e1f143d1d9 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 @@ -328,7 +328,7 @@ public void setVerbose(boolean verbose) { *

    Sets whether the stable adjacency search should be used. Default is false. Default is false. See the * following reference for this:

    * - *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. + *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. * Learn. Res., 15(1), 3741-3782.

    * * @param stable True iff the case. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java index 3047155025..e5792a7fcb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcLingam.java @@ -25,11 +25,11 @@ import cern.jet.stat.Descriptive; import edu.cmu.tetrad.data.AndersonDarlingTest; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionDataset; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.TetradLogger; @@ -100,96 +100,36 @@ public PcLingam(Graph cpdag, DataSet dataSet) * @return This graph. */ public Graph search() { + Graph toOrient = new EdgeListGraph(cpdag); - Graph _cpdag = GraphUtils.bidirectedToUndirected(getCpdag()); + DataSet standardized = DataTransforms.standardizeData(this.dataSet); + double[][] _data = standardized.getDoubleData().transpose().toArray(); + GraphUtils.replaceNodes(toOrient, standardized.getVariables()); - TetradLogger.getInstance().log("info", "Making list of all dags in CPDAG..."); + List nodes = standardized.getVariables(); - List dags = GraphSearchUtils.getAllGraphsByDirectingUndirectedEdges(_cpdag); + for (Edge edge : cpdag.getEdges()) { + if (Edges.isUndirectedEdge(edge)) { + Node X = edge.getNode1(); + Node Y = edge.getNode2(); - TetradLogger.getInstance().log("normalityTests", "Anderson Darling P value for Variables\n"); - NumberFormat nf = new DecimalFormat("0.0000"); + int i = nodes.indexOf(X); + int j = nodes.indexOf(Y); - if (dags.isEmpty()) { - return null; - } - - Matrix data = getDataSet().getDoubleData(); - List variables = getDataSet().getVariables(); - - if (dags.size() == 0) { - throw new IllegalArgumentException("The data set is empty."); - } - - // Check that all the dags and the data contain the same variables. - - List scores = new ArrayList<>(); - - for (Graph dag : dags) { - scores.add(getScore(dag, data, variables)); - } - - double maxScore = 0.0; - int maxj = -1; - - for (int j = 0; j < dags.size(); j++) { - double _score = scores.get(j).score; - - if (_score > maxScore) { - maxScore = _score; - maxj = j; - } - } - - Graph dag = dags.get(maxj); - this.pValues = scores.get(maxj).pvals; - - TetradLogger.getInstance().log("graph", "winning dag = " + dag); + double lr = Fask.faskLeftRightV2(_data[i], _data[j], true, 0); - TetradLogger.getInstance().log("normalityTests", "Anderson Darling P value for Residuals\n"); - - for (int j = 0; j < getDataSet().getNumColumns(); j++) { - TetradLogger.getInstance().log("normalityTests", getDataSet().getVariable(j) + ": " + nf.format(scores.get(maxj).pvals[j])); - } - - Graph ngDagCPDAG = GraphSearchUtils.cpdagFromDag(dag); - - List nodes = ngDagCPDAG.getNodes(); - - for (Edge edge : ngDagCPDAG.getEdges()) { - Node node1 = edge.getNode1(); - Node node2 = edge.getNode2(); - - double p1 = getPValues()[nodes.indexOf(node1)]; - double p2 = getPValues()[nodes.indexOf(node2)]; - - boolean node1Nongaussian = p1 < this.alpha; - boolean node2Nongaussian = p2 < this.alpha; - - if (node1Nongaussian || node2Nongaussian) { - if (!Edges.isUndirectedEdge(edge)) { - continue; + if (lr > 0.0) { + toOrient.removeEdge(edge); + toOrient.addDirectedEdge(X, Y); + } else { + toOrient.removeEdge(edge); + toOrient.addDirectedEdge(Y, X); } - - ngDagCPDAG.removeEdge(edge); - ngDagCPDAG.addEdge(dag.getEdge(node1, node2)); - - if (node1Nongaussian) { - TetradLogger.getInstance().log("edgeOrientations", node1 + " nongaussian "); - } - - if (node2Nongaussian) { - TetradLogger.getInstance().log("edgeOrientations", node2 + " nongaussian "); - } - - TetradLogger.getInstance().log("nongaussianOrientations", "Nongaussian orientation: " + dag.getEdge(node1, node2)); } } - new MeekRules().orientImplied(ngDagCPDAG); - - TetradLogger.getInstance().log("graph", "Returning: " + ngDagCPDAG); - return ngDagCPDAG; + TetradLogger.getInstance().log("graph", "Returning: " + toOrient); + return toOrient; } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java index 26013f1c4c..bd29fbeb07 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/PcMb.java @@ -37,7 +37,7 @@ * Markov blankets. Note that this code has been converted to be consistent with the CPC algorithm. The reference is * here:

    * - *

    Bai, X., Padman, R., Ramsey, J., & Spirtes, P. (2008). Tabu search-enhanced graphical models + *

    Bai, X., Padman, R., Ramsey, J., & Spirtes, P. (2008). Tabu search-enhanced graphical models * for classification in high dimensions. INFORMS Journal on Computing, 20(3), 423-437.

    * *

    This class is configured to respect knowledge of forbidden and required diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java index aca9f4abf7..de529b3972 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/Rfci.java @@ -40,7 +40,7 @@ * the FCI algorithm. The goal of of the algorithm is to avoid certain expensive steps in the FCI procedure in a correct * way. This was introduced here:

    * - *

    Colombo, D., Maathuis, M. H., Kalisch, M., & Richardson, T. S. (2012). Learning + *

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

    * *

    This class is configured to respect knowledge of forbidden and required diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java index 4c96a50307..fd33a5e157 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SpFci.java @@ -134,7 +134,7 @@ public Graph search() { } Knowledge knowledge2 = new Knowledge(knowledge); - addForbiddenReverseEdgesForDirectedEdges(GraphSearchUtils.cpdagForDag(graph), knowledge2); + addForbiddenReverseEdgesForDirectedEdges(GraphTransforms.cpdagForDag(graph), knowledge2); // Keep a copy of this CPDAG. Graph referenceDag = new EdgeListGraph(this.graph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java index 21db9961dc..ca60755df1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SuborderSearch.java @@ -11,7 +11,7 @@ /** * An interface for suborder searches for various types of permutation algorithms. A "suborder search" is a search for - * permutation <x1a,...x1n, x2a,...,x2m, x3a,...,x3l>> that searches for a good permutation of x2a,...,x2m with + * permutation <x1a,...x1n, x2a,...,x2m, x3a,...,x3l>> that searches for a good permutation of x2a,...,x2m with * x1a,...,x1n as a prefix. This is used by PermutationSearch to form a complete permutation search algorithm, where * PermutationSearch handles an optimization for tiered knowledge where each tier can be searched separately in order. * (See the documentation for that class.) diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java index 4dbe2b4c1f..dd862c6469 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFas.java @@ -47,7 +47,7 @@ * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD workshop on causal discovery * (pp. 23-47). PMLR.

    * - *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic * graphical models, 121-128.

    * *

    This class is configured to respect knowledge of forbidden and required 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 57319df9e4..7e46fa7170 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 @@ -52,7 +52,7 @@ * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD workshop on causal discovery * (pp. 23-47). PMLR.

    * - *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic * graphical models, 121-128.

    * *

    This class is configured to respect knowledge of forbidden and required diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java index 092f6e5d3a..092342ba34 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarFges.java @@ -50,7 +50,7 @@ * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD workshop on causal discovery * (pp. 23-47). PMLR.

    * - *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic * graphical models, 121-128.

    * *

    This class is configured to respect knowledge of forbidden and required 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 5f43fd780b..50cccb97f3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/SvarGfci.java @@ -51,7 +51,7 @@ * time series in settings with unmeasured confounding. In Proceedings of 2018 ACM SIGKDD workshop on causal discovery * (pp. 23-47). PMLR.

    * - *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic + *

    Entner, D., & Hoyer, P. O. (2010). On causal discovery from time series data using FCI. Probabilistic * graphical models, 121-128.

    * *

    This class is configured to respect knowledge of forbidden and required diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java index 49d2b2b7d8..e62624bc15 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianLikelihood.java @@ -43,7 +43,7 @@ * maximal only if the continuous variables are jointly Gaussian conditional on the discrete variables; in all other * cases, it will be less than maximal. The reference is here:

    * - *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of mixed variables. + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of mixed variables. * International journal of data science and analytics, 6, 3-18.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java index 950ade509c..18c5cd6ac6 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ConditionalGaussianScore.java @@ -39,7 +39,7 @@ * score for mixed discrete/Gaussian data using the conditional Gaussian likelihood function (see). The reference is * here:

    * - *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of mixed variables. + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of mixed variables. * International journal of data science and analytics, 6, 3-18.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java index 52e041e670..b29e125155 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DegenerateGaussianScore.java @@ -41,7 +41,7 @@ * used to help determine conditional independence for the mixed continuous/discrete case from this information. The * references is as follows:

    * - *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2019, July). Learning high-dimensional + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2019, July). Learning high-dimensional * directed acyclic graphs with mixed data-types. In The 2019 ACM SIGKDD Workshop on Causal Discovery (pp. 4-21). * PMLR.

    * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java index 629eba9a57..9199dce89e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/DiscreteScore.java @@ -29,10 +29,24 @@ * @author josephramsey */ public interface DiscreteScore extends Score { + + /** + * Sets the structure prior. + * @param structurePrior Ibid. + * + */ void setStructurePrior(double structurePrior); + /** + * Sets the sample prior. + * @param samplePrior Ibid. + */ void setSamplePrior(double samplePrior); + /** + * Returns the dataset. + * @return Ibid. + */ DataSet getDataSet(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java index 4436692c46..6d618b12e1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/EbicScore.java @@ -38,7 +38,7 @@ /** *

    Implements the extended BIC (EBIC) score. The reference is here:

    * - *

    Chen, J., & Chen, Z. (2008). Extended Bayesian information criteria for + *

    Chen, J., & Chen, Z. (2008). Extended Bayesian information criteria for * model selection with large model spaces. Biometrika, 95(3), 759-771.

    * *

    As for all scores in Tetrad, higher scores mean more dependence, and negative @@ -49,7 +49,6 @@ public class EbicScore implements Score { private final List variables; private final int sampleSize; - private DataSet dataSet; private ICovarianceMatrix covariances; private double N; private Matrix data; @@ -82,12 +81,10 @@ public EbicScore(DataSet dataSet, boolean precomputeCovariances) { throw new NullPointerException(); } - this.dataSet = dataSet; - this.variables = dataSet.getVariables(); this.sampleSize = dataSet.getNumRows(); - DataSet _dataSet = DataUtils.center(dataSet); + DataSet _dataSet = DataTransforms.center(dataSet); this.data = _dataSet.getDoubleData(); if (!dataSet.existsMissingValue()) { @@ -206,29 +203,7 @@ public void setGamma(double gamma) { } private void setCovariances(ICovarianceMatrix covariances) { -// CorrelationMatrix correlations = new CorrelationMatrix(covariances); this.covariances = covariances; - -// boolean exists = false; -// -// double correlationThreshold = 1.0; -// for (int i = 0; i < correlations.getSize(); i++) { -// for (int j = 0; j < correlations.getSize(); j++) { -// if (i == j) continue; -// double r = correlations.getValue(i, j); -// if (abs(r) > correlationThreshold) { -// System.out.println("Absolute correlation too high: " + r); -// exists = true; -// } -// } -// } -// -// if (exists) { -// throw new IllegalArgumentException("Some correlations are too high (> " + correlationThreshold -// + ") in absolute value."); -// } - - this.N = covariances.getSampleSize(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java index 22208a6324..b5a300cfc6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/IndTestScore.java @@ -41,7 +41,6 @@ * * @author josephramsey * @see IndependenceTest - * @see IndependenceTest#getScore() */ public class IndTestScore implements Score { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java index fb3bf6e981..c03360e8fb 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpLikelihood.java @@ -40,7 +40,7 @@ /** *

    Calculates Mixed Variables Polynomial likelihood. The reference is here:

    * - *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of * mixed variables. International journal of data science and analytics, 6, 3-18.

    * * @author Bryan Andrews diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java index ed96b492d6..49c406a812 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/MvpScore.java @@ -30,7 +30,7 @@ /** *

    Implements a mixed variable polynomial BIC score. The reference is here:

    * - *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of * mixed variables. International journal of data science and analytics, 6, 3-18.

    * * @author Bryan Andrews diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java index 304c14169e..99617ec475 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/PoissonPriorScore.java @@ -97,7 +97,7 @@ public PoissonPriorScore(DataSet dataSet, boolean precomputeCovariances) { this.variables = dataSet.getVariables(); this.sampleSize = dataSet.getNumRows(); - DataSet _dataSet = DataUtils.center(dataSet); + DataSet _dataSet = DataTransforms.center(dataSet); this.data = _dataSet.getDoubleData(); if (!dataSet.existsMissingValue()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java index 580e465768..3f5da0b718 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/Score.java @@ -64,10 +64,25 @@ public interface Score { String toString(); + /** + * Returns the score difference of the graph. + * + * @param x A node. + * @param y TAhe node. + * @param z A set of nodes. + * @return The score difference. + */ default double localScoreDiff(int x, int y, int[] z) { return localScore(y, append(z, x)) - localScore(y, z); } + /** + * Appends an extra int to a list of ints. + * + * @param parents The list of ints. + * @param extra The extra int. + * @return The new list of ints. + */ default int[] append(int[] parents, int extra) { int[] all = new int[parents.length + 1]; System.arraycopy(parents, 0, all, 0, parents.length); @@ -75,18 +90,43 @@ default int[] append(int[] parents, int extra) { return all; } + /** + * Returns the local score difference of the graph. + * + * @param x A node. + * @param y The node. + * @return The local score difference. + */ default double localScoreDiff(int x, int y) { return localScore(y, x) - localScore(y); } + /** + * Returns the local score of the graph. + * + * @param node A node. + * @param parent A parent. + * @return The local score. + */ default double localScore(int node, int parent) { return localScore(node, new int[]{parent}); } + /** + * Returns the local score of the gien node in the graph. + * + * @param node A node. + * @return The local score. + */ default double localScore(int node) { return localScore(node, new int[0]); } + /** + * Returns the variable with the given name. + * @param targetName The name. + * @return The variable. + */ default Node getVariable(String targetName) { for (Node node : getVariables()) { if (node.getName().equals(targetName)) { @@ -97,14 +137,32 @@ default Node getVariable(String targetName) { return null; } + /** + * Returns true iff the edge between x and y is an effect edge. + * + * @param bump The bump. + * @return True iff the edge between x and y is an effect edge. + */ default boolean isEffectEdge(double bump) { return false; } + /** + * Returns the max degree, by default 1000. + * + * @return The max degree. + */ default int getMaxDegree() { return 1000; } + /** + * Returns true iff the score determines the edge between x and y. + * + * @param z The set of nodes. + * @param y The node. + * @return True iff the score determines the edge between x and y. + */ default boolean determines(List z, Node y) { throw new UnsupportedOperationException("Method determines() is not implemented for this score."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java index ad290fd6b8..e8e9f2260f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/ScoredGraph.java @@ -33,7 +33,7 @@ * @author josephramsey */ public class ScoredGraph implements Comparable, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Graph graph; private final Double score; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java index 4d3b0bda60..7b069f6634 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/score/SemBicScore.java @@ -55,7 +55,7 @@ * *

    The version of the score due to Nandy et al. is given in this reference:

    * - *

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

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

    * *

    This score may be used anywhere though where a linear, Gaussian score is needed. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java index 3d210e724b..7b230e59f5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/GSquareTest.java @@ -37,7 +37,7 @@ * Degrees of freedom are calculated as in Fienberg (2007), this reference:

    * *

    Fienberg, S. E. (2007). The analysis of cross-classified categorical data. - * Springer Science & Business Media.

    + * Springer Science & Business Media.

    * * @author Frank Wimberly original version * @author josephramsey revision 10/01 diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java index 991f04cdf6..0b5cb3c307 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalCorrelation.java @@ -113,6 +113,12 @@ public IndependenceResult checkIndependence(Node x, Node y, Set z) { double score = this.cci.isIndependent(x, y, z); this.score = score; double p = this.cci.getPValue(score); + + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered for test: " + LogUtilsSearch.independenceFact(x, y, z)); + + } + boolean independent = p > this.alpha; if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java index fc17cd3533..363ba09130 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestConditionalGaussianLrt.java @@ -35,7 +35,6 @@ import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.*; -import java.util.concurrent.ConcurrentSkipListMap; /** * Performs a test of conditional independence X _||_ Y | Z1...Zn where all searchVariables are either continuous or @@ -65,7 +64,7 @@ public IndTestConditionalGaussianLrt(DataSet data, double alpha, boolean discret this.data = data; this.likelihood = new ConditionalGaussianLikelihood(data); this.likelihood.setDiscretize(discretize); - this.nodesHash = new ConcurrentSkipListMap<>(); + this.nodesHash = new HashMap<>(); List variables = data.getVariables(); @@ -132,7 +131,7 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { double pValue; if (Double.isNaN(lik0)) { - pValue = Double.NaN; + throw new RuntimeException("Undefined likelihood encountered for test: " + LogUtilsSearch.independenceFact(x, y, _z)); } else { pValue = 1.0 - new ChiSquaredDistribution(dof0).cumulativeProbability(2.0 * lik0); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java index a1eb6496f0..b8eace3243 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestDegenerateGaussianLrt.java @@ -44,7 +44,7 @@ /** *

    Implements a degenerate Gaussian score as a LRT. The reference is here:

    * - *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2019, July). Learning high-dimensional + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2019, July). Learning high-dimensional * directed acyclic graphs with mixed data-types. In The 2019 ACM SIGKDD Workshop on Causal Discovery (pp. 4-21). * PMLR.

    * @@ -222,7 +222,7 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { double pValue; if (Double.isNaN(lik0)) { - pValue = NaN; + throw new RuntimeException("Undefined likelihood encountered for test: " + LogUtilsSearch.independenceFact(x, y, _z)); } else { pValue = 1.0 - new ChiSquaredDistribution(dof0).cumulativeProbability(2.0 * lik0); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java index 3f97130db2..729eda85e7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZ.java @@ -25,6 +25,7 @@ import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceTest; +import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.util.Matrix; import edu.cmu.tetrad.util.MatrixUtils; @@ -54,7 +55,7 @@ public final class IndTestFisherZ implements IndependenceTest { private final Map nameMap; private final NormalDistribution normal = new NormalDistribution(0, 1, 1e-15); private final Map nodesHash; - private final ICovarianceMatrix cor; + private ICovarianceMatrix cor = null; private List variables; private double alpha; private DataSet dataSet; @@ -92,7 +93,7 @@ public IndTestFisherZ(DataSet dataSet, double alpha) { this.nodesHash = nodesHash; } else { - this.cor = new CorrelationMatrix(dataSet); +// this.cor = new CorrelationMatrix(dataSet); if (!(alpha >= 0 && alpha <= 1)) { throw new IllegalArgumentException("Alpha mut be in [0, 1]"); @@ -201,14 +202,12 @@ public IndependenceTest indTestSubset(List vars) { * @see IndependenceResult */ public IndependenceResult checkIndependence(Node x, Node y, Set z) { - double p = 0.0; + double p = Double.NaN; + try { p = getPValue(x, y, z); } catch (SingularMatrixException e) { - throw new RuntimeException("Singularity encountered when testing " + - LogUtilsSearch.independenceFact(x, y, z)); -// return new IndependenceResult(new IndependenceFact(x, y, z), -// false, p, alpha - p); + throw new RuntimeException("Singular matrix encountered for test: " + LogUtilsSearch.independenceFact(x, y, z)); } boolean independent = p > this.alpha; @@ -221,23 +220,13 @@ public IndependenceResult checkIndependence(Node x, Node y, Set z) { } if (Double.isNaN(p)) { - return new IndependenceResult(new IndependenceFact(x, y, z), - false, p, alpha - p); + throw new RuntimeException("Undefined p-value encountered in for test: " + LogUtilsSearch.independenceFact(x, y, z)); } else { return new IndependenceResult(new IndependenceFact(x, y, z), independent, p, alpha - p); } } -// /** -// * Returns the probability associated with the most recently computed independence test. -// * -// * @return This probability. -// */ -// public double getPValue() { -// return this.p; -// } - /** * Returns the p-value for x _||_ y | z. * @@ -264,10 +253,8 @@ private double getPValue(Node x, Node y, Set z) throws SingularMatrixExcep this.r = r; double q = .5 * (log(1.0 + abs(r)) - log(1.0 - abs(r))); double fisherZ = sqrt(n - 3. - z.size()) * q; - double p = 2 * (1.0 - this.normal.cumulativeProbability(fisherZ)); -// this.p = p; - return p; + return 2 * (1.0 - this.normal.cumulativeProbability(fisherZ)); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java index 8e823aab1f..b422a41d22 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZConcatenateResiduals.java @@ -164,6 +164,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { } double pValue = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, FastMath.abs(fisherZ))); + + if (Double.isNaN(pValue)) { + throw new RuntimeException("Undefined p-value encountered for test: " + LogUtilsSearch.independenceFact(x, y, _z)); + } + this.pValue = pValue; boolean independent = pValue > this.alpha; @@ -219,7 +224,7 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep * @return This data */ public DataSet getData() { - return DataUtils.concatenate(this.dataSets); + return DataTransforms.concatenate(this.dataSets); } /** @@ -232,10 +237,10 @@ public ICovarianceMatrix getCov() { List _dataSets = new ArrayList<>(); for (DataSet d : this.dataSets) { - _dataSets.add(DataUtils.standardizeData(d)); + _dataSets.add(DataTransforms.standardizeData(d)); } - return new CovarianceMatrix(DataUtils.concatenate(_dataSets)); + return new CovarianceMatrix(DataTransforms.concatenate(_dataSets)); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java index cdea8b3bcb..59381346e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestFisherZFisherPValue.java @@ -21,10 +21,7 @@ package edu.cmu.tetrad.search.test; -import edu.cmu.tetrad.data.CovarianceMatrix; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.ICovarianceMatrix; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceTest; @@ -43,7 +40,7 @@ *

    Calculates independence from multiple datasets from using the Fisher method * of pooling independence results. See this paper for details:

    * - *

    Tillman, R. E., & Eberhardt, F. (2014). Learning causal structure from + *

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

    * * @author robertillman @@ -150,6 +147,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { "For the Fisher method, all component p values in the calculation may not be zero, " + "\nsince not all p values can be ignored. Maybe try calculating AR residuals."); double p = 1.0 - ProbUtils.chisqCdf(tf, 2 * n); + + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered for test: " + LogUtilsSearch.independenceFact(x, y, _z)); + } + this.pValue = p; boolean independent = p > this.alpha; @@ -215,7 +217,7 @@ public boolean determines(List z, Node x) throws UnsupportedOperationExcep * @return This data */ public DataSet getData() { - return DataUtils.concatenate(this.dataSets); + return DataTransforms.concatenate(this.dataSets); } /** @@ -227,10 +229,10 @@ public ICovarianceMatrix getCov() { List _dataSets = new ArrayList<>(); for (DataSet d : this.dataSets) { - _dataSets.add(DataUtils.standardizeData(d)); + _dataSets.add(DataTransforms.standardizeData(d)); } - return new CovarianceMatrix(DataUtils.concatenate(_dataSets)); + return new CovarianceMatrix(DataTransforms.concatenate(_dataSets)); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java index 132e1c9da6..0c847c44ce 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestGSquare.java @@ -192,6 +192,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { GSquareTest.Result result = this.gSquareTest.calcGSquare(testIndices); this.pValue = result.getPValue(); + if (Double.isNaN(this.pValue)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, _z)); + } + if (this.verbose) { if (result.isIndep()) { TetradLogger.getInstance().forceLogMessage( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java index cbdaaa2668..5f046e23c8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestHsic.java @@ -324,6 +324,11 @@ public IndependenceResult checkIndependence(Node y, Node x, Set _z) { evalCdf /= this.perms; this.pValue = 1.0 - evalCdf; + if (Double.isNaN(this.pValue)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, _z)); + } + // reject if pvalue <= alpha boolean independent = this.pValue <= this.alpha; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java index 269ab8660d..ba1e962108 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestMvpLrt.java @@ -39,7 +39,7 @@ * variables are either continuous or discrete. This test is valid for both ordinal and non-ordinal discrete * searchVariables.

    * - *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of + *

    Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of * mixed variables. International journal of data science and analytics, 6, 3-18.

    * * @author Bryan Andrews @@ -142,6 +142,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { double pValue = FastMath.min(p_0, p_1); + if (Double.isNaN(pValue)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, _z)); + } + boolean independent = pValue > this.alpha; if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java index 027e74fe97..64e7c64172 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestProbabilistic.java @@ -195,6 +195,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Node... z) { double p = pInd; + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, GraphUtils.asSet(z))); + } + posterior = p; boolean ind; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java index bafdc43e6c..ce6887a15c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndTestRegression.java @@ -142,6 +142,11 @@ public IndependenceResult checkIndependence(Node xVar, Node yVar, Set zLis double p = result.getP()[1]; + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(xVar, yVar, zList)); + } + boolean independent = p > this.alpha; if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java index e3f664c278..8e1740369f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/IndependenceResult.java @@ -13,7 +13,7 @@ * @author josephramsey */ public final class IndependenceResult implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final IndependenceFact fact; private final boolean indep; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java index c3042126ff..47a333f4ee 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/Kci.java @@ -1,9 +1,6 @@ package edu.cmu.tetrad.search.test; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.ICovarianceMatrix; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceTest; @@ -82,7 +79,7 @@ public class Kci implements IndependenceTest { * @param alpha The alpha value of the test. */ public Kci(DataSet data, double alpha) { - this.data = DataUtils.standardizeData(data); + this.data = DataTransforms.standardizeData(data); // _data = data.getDoubleData().transpose().toArray(); this.variables = data.getVariables(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/MsepTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/MsepTest.java index a921aa1c2d..bfc2da94a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/MsepTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/MsepTest.java @@ -228,6 +228,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set z) { pValue = 0.0; } + if (Double.isNaN(pvalue)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + this.pvalue = pValue; return new IndependenceResult(new IndependenceFact(x, y, z), mSeparated, pValue, pvalue == 1 ? -1 : 1); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java index 2ad971b9ca..de7e21e1f7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/test/ScoreIndTest.java @@ -85,6 +85,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set z) { double v = this.score.localScoreDiff(this.variables.indexOf(x), this.variables.indexOf(y), varIndices(z1)); + + if (Double.isNaN(v)) { + throw new RuntimeException("Undefined score bump encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } this.bump = v; int N = score.getSampleSize(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java index 0ce4a14030..a4c96872b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/AdLeafTree.java @@ -100,6 +100,7 @@ public List> getCellLeaves(List A) { * sets. * * @param A A list of discrete variables. + * @param B A discrete variable. * @return The list of index sets of the first variable varied by the second variable, and so on, to the last * variable. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java index d9ef93e052..605a6ba104 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BayesImParser.java @@ -45,6 +45,9 @@ public class BayesImParser { private boolean useDisplayNames; + /** + * Creates a new BayesImParser. + */ public BayesImParser() { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java index 3f21ba7aa3..0242ddaa16 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BesPermutation.java @@ -86,6 +86,12 @@ private void buildIndexing(List nodes, Map hashIndices) { // this.depth = depth; // } + /** + * Runs BES. + * @param graph The graph. + * @param order The order. + * @param suborder The suborder. + */ public void bes(Graph graph, List order, List suborder) { Map hashIndices = new HashMap<>(); SortedSet sortedArrowsBack = new ConcurrentSkipListSet<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java index d1465106a9..a130741bb5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcAlgorithmType.java @@ -35,7 +35,7 @@ public enum BpcAlgorithmType implements TetradSerializable { FIND_ONE_FACTOR_CLUSTERS, FIND_TWO_FACTOR_CLUSTERS; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public static BpcAlgorithmType serializableInstance() { return BpcAlgorithmType.BUILD_PURE_CLUSTERS; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java index f0eb6a50fb..a5cf29545a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/BpcTestType.java @@ -54,7 +54,7 @@ public enum BpcTestType implements TetradSerializable { SAG, GAP; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public static BpcTestType serializableInstance() { return BpcTestType.GAUSSIAN_PVALUE; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java index 8875ebbe81..aed83a956a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaSextadTest.java @@ -39,7 +39,7 @@ * @author josephramsey */ public class DeltaSextadTest { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final int N; private final ICovarianceMatrix cov; private final List variables; @@ -69,7 +69,7 @@ public DeltaSextadTest(DataSet dataSet) { this.cov = new CovarianceMatrix(dataSet); - Matrix centered = DataUtils.centerData(dataSet.getDoubleData()); + Matrix centered = DataTransforms.centerData(dataSet.getDoubleData()); this.data = centered.transpose().toArray(); this.N = dataSet.getNumRows(); this.variables = dataSet.getVariables(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java index cf253f61c8..c19644473c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/DeltaTetradTest.java @@ -71,7 +71,7 @@ public DeltaTetradTest(DataSet dataSet) { List data1 = new ArrayList<>(); data1.add(dataSet); - List data2 = DataUtils.center(data1); + List data2 = DataTransforms.center(data1); this.dataSet = data2.get(0); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java index 0de0723aa2..59d5f48a30 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/FciOrient.java @@ -501,7 +501,7 @@ public void ruleR2(Node a, Node b, Node c, Graph graph) { } /** - * Implements the double-triangle orientation rule, which states that if D*-oB, A*->B<-*C and A*-oDo-*C, and !adj(a, + * Implements the double-triangle orientation rule, which states that if D*-oB, A*->B<-*C and A*-oDo-*C, and !adj(a, * c), D*-oB, then D*->B. *

    * This is Zhang's rule R3. @@ -536,6 +536,10 @@ public void ruleR3(Graph graph) { if (graph.getEndpoint(a, d) == Endpoint.CIRCLE && graph.getEndpoint(c, d) == Endpoint.CIRCLE) { if (!graph.isAdjacentTo(a, c)) { if (graph.getEndpoint(d, b) == Endpoint.CIRCLE) { + if (!isArrowheadAllowed(d, b, graph, knowledge)) { + return; + } + graph.setEndpoint(d, b, Endpoint.ARROW); if (this.verbose) { @@ -975,7 +979,7 @@ public boolean ruleR8(Node a, Node c, Graph graph) { *

    * MAY HAVE WEIRD EFFECTS ON ARBITRARY NODE PAIRS. *

    - * R9: If Ao->C and there is an uncovered p.d. path u= such that C,B nonadjacent, then A-->C. + * R9: If Ao->C and there is an uncovered p.d. path u=<A,B,..,C> such that C,B nonadjacent, then A-->C. * * @param a The node A. * @param c The node C. @@ -1039,6 +1043,10 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { continue; } + if (!isArrowheadAllowed(to, from, graph, knowledge)) { + return; + } + // Orient to*->from graph.setEndpoint(to, from, Endpoint.ARROW); this.changeFlag = true; @@ -1065,6 +1073,10 @@ public void fciOrientbk(Knowledge bk, Graph graph, List variables) { continue; } + if (!isArrowheadAllowed(from, to, graph, knowledge)) { + return; + } + graph.setEndpoint(to, from, Endpoint.TAIL); graph.setEndpoint(from, to, Endpoint.ARROW); this.changeFlag = true; @@ -1158,8 +1170,8 @@ public void setDoDiscriminatingPathTailRule(boolean doDiscriminatingPathTailRule *

    * MAY HAVE WEIRD EFFECTS ON ARBITRARY NODE PAIRS. *

    - * R10: If Ao->C, B-->C<--D, there is an uncovered p.d. path u1= and an uncovered p.d. path u2= - * with M != N and M,N nonadjacent then A-->C. + * R10: If Ao->C, B-->C<--D, there is an uncovered p.d. path u1=<A,M,...,B> and an uncovered p.d. path u2= + * <A,N,...,D> with M != N and M,N nonadjacent then A-->C. * * @param a The node A. * @param c The node C. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphSearchUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphSearchUtils.java index 7a1ef3e56b..642cd9ade1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphSearchUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/GraphSearchUtils.java @@ -27,11 +27,9 @@ import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.util.ChoiceGenerator; -import edu.cmu.tetrad.util.CombinationGenerator; import edu.cmu.tetrad.util.TetradLogger; import org.apache.commons.collections4.map.MultiKeyMap; import org.apache.commons.math3.util.FastMath; -import org.jetbrains.annotations.NotNull; import java.io.PrintStream; import java.text.DecimalFormat; @@ -349,128 +347,6 @@ public static void basicCpdagRestricted2(Graph graph, Node node) { } } - /** - * @return the cpdag to which the given DAG belongs. - */ - public static Graph cpdagFromDag(Graph dag) { - Graph graph = new EdgeListGraph(dag); - GraphSearchUtils.basicCpdag(graph); - MeekRules rules = new MeekRules(); - rules.orientImplied(graph); - return graph; - } - - public static Graph dagFromCPDAG(Graph graph) { - return GraphSearchUtils.dagFromCPDAG(graph, null); - } - - public static Graph dagFromCPDAG(Graph graph, Knowledge knowledge) { - Graph dag = new EdgeListGraph(graph); - - for (Edge edge : dag.getEdges()) { - if (Edges.isBidirectedEdge(edge)) { - throw new IllegalArgumentException("That 'cpdag' contains a bidirected edge."); - } - } - - MeekRules rules = new MeekRules(); - - if (knowledge != null) { - rules.setKnowledge(knowledge); - } - - rules.setRevertToUnshieldedColliders(false); - - NEXT: - while (true) { - for (Edge edge : dag.getEdges()) { - Node x = edge.getNode1(); - Node y = edge.getNode2(); - - if (Edges.isUndirectedEdge(edge) && !graph.paths().isAncestorOf(y, x)) { - GraphSearchUtils.direct(x, y, dag); - rules.orientImplied(dag); - continue NEXT; - } - } - - break; - } - - return dag; - } - - private static void direct(Node a, Node c, Graph graph) { - Edge before = graph.getEdge(a, c); - Edge after = Edges.directedEdge(a, c); - graph.removeEdge(before); - graph.addEdge(after); - } - - // Zhang 2008 Theorem 2 - public static Graph pagToMag(Graph pag) { - Graph mag = new EdgeListGraph(pag.getNodes()); - for (Edge e : pag.getEdges()) mag.addEdge(new Edge(e)); - - List nodes = mag.getNodes(); - - Graph pcafci = new EdgeListGraph(nodes); - - for (int i = 0; i < nodes.size(); i++) { - for (int j = 0; j < nodes.size(); j++) { - if (i == j) continue; - - Node x = nodes.get(i); - Node y = nodes.get(j); - - if (mag.getEndpoint(y, x) == Endpoint.CIRCLE && mag.getEndpoint(x, y) == Endpoint.ARROW) { - mag.setEndpoint(y, x, Endpoint.TAIL); - } - - if (mag.getEndpoint(y, x) == Endpoint.TAIL && mag.getEndpoint(x, y) == Endpoint.CIRCLE) { - mag.setEndpoint(x, y, Endpoint.ARROW); - } - - if (mag.getEndpoint(y, x) == Endpoint.CIRCLE && mag.getEndpoint(x, y) == Endpoint.CIRCLE) { - pcafci.addEdge(mag.getEdge(x, y)); - } - } - } - - for (Edge e : pcafci.getEdges()) { - e.setEndpoint1(Endpoint.TAIL); - e.setEndpoint2(Endpoint.TAIL); - } - - W: - while (true) { - for (Edge e : pcafci.getEdges()) { - if (Edges.isUndirectedEdge(e)) { - Node x = e.getNode1(); - Node y = e.getNode2(); - - pcafci.setEndpoint(y, x, Endpoint.TAIL); - pcafci.setEndpoint(x, y, Endpoint.ARROW); - - MeekRules meekRules = new MeekRules(); - meekRules.setRevertToUnshieldedColliders(false); - meekRules.orientImplied(pcafci); - - continue W; - } - } - - break; - } - - for (Edge e : pcafci.getEdges()) { - mag.removeEdge(e.getNode1(), e.getNode2()); - mag.addEdge(e); - } - - return mag; - } - public static LegalPagRet isLegalPag(Graph pag) { for (Node n : pag.getNodes()) { @@ -480,7 +356,7 @@ public static LegalPagRet isLegalPag(Graph pag) { } } - Graph mag = pagToMag(pag); + Graph mag = GraphTransforms.pagToMag(pag); LegalMagRet legalMag = isLegalMag(mag); @@ -488,7 +364,7 @@ public static LegalPagRet isLegalPag(Graph pag) { return new LegalPagRet(false, legalMag.getReason() + " in a MAG implied by this graph"); } - Graph pag2 = GraphSearchUtils.dagToPag(mag); + Graph pag2 = GraphTransforms.dagToPag(mag); if (!pag.equals(pag2)) { String edgeMismatch = ""; @@ -825,86 +701,6 @@ public static List> powerSet(List nodes) { return subsets; } - /** - * Generates the list of DAGs in the given cpdag. - */ - public static List generateCpdagDags(Graph cpdag, boolean orientBidirectedEdges) { - if (orientBidirectedEdges) { - cpdag = GraphUtils.removeBidirectedOrientations(cpdag); - } - - return GraphSearchUtils.getDagsInCpdagMeek(cpdag, new Knowledge()); - } - - public static List getDagsInCpdagMeek(Graph cpdag, Knowledge knowledge) { - DagInCpcagIterator iterator = new DagInCpcagIterator(cpdag, knowledge); - List dags = new ArrayList<>(); - - while (iterator.hasNext()) { - Graph graph = iterator.next(); - - try { - if (knowledge.isViolatedBy(graph)) { - continue; - } - - dags.add(graph); - } catch (IllegalArgumentException e) { - System.out.println("Found a non-DAG: " + graph); - } - } - - return dags; - } - - public static List getAllGraphsByDirectingUndirectedEdges(Graph skeleton) { - List graphs = new ArrayList<>(); - List edges = new ArrayList<>(skeleton.getEdges()); - - List undirectedIndices = new ArrayList<>(); - - for (int i = 0; i < edges.size(); i++) { - if (Edges.isUndirectedEdge(edges.get(i))) { - undirectedIndices.add(i); - } - } - - int[] dims = new int[undirectedIndices.size()]; - - for (int i = 0; i < undirectedIndices.size(); i++) { - dims[i] = 2; - } - - CombinationGenerator gen = new CombinationGenerator(dims); - int[] comb; - - while ((comb = gen.next()) != null) { - Graph graph = new EdgeListGraph(skeleton.getNodes()); - - for (Edge edge : edges) { - if (!Edges.isUndirectedEdge(edge)) { - graph.addEdge(edge); - } - } - - for (int i = 0; i < undirectedIndices.size(); i++) { - Edge edge = edges.get(undirectedIndices.get(i)); - Node node1 = edge.getNode1(); - Node node2 = edge.getNode2(); - - if (comb[i] == 1) { - graph.addEdge(Edges.directedEdge(node1, node2)); - } else { - graph.addEdge(Edges.directedEdge(node2, node1)); - } - } - - graphs.add(graph); - } - - return graphs; - } - // The published version. public static CpcTripleType getCpcTripleType(Node x, Node y, Node z, IndependenceTest test, int depth, @@ -977,14 +773,6 @@ public static CpcTripleType getCpcTripleType(Node x, Node y, Node z, } } - public static Graph cpdagForDag(Graph dag) { - Graph cpdag = new EdgeListGraph(dag); - MeekRules rules = new MeekRules(); - rules.setRevertToUnshieldedColliders(true); - rules.orientImplied(cpdag); - return cpdag; - } - /** * Tsamardinos, I., Brown, L. E., and Aliferis, C. F. (2006). The max-min hill-climbing Bayesian network structure * learning algorithm. Machine learning, 65(1), 31-78. @@ -996,8 +784,8 @@ public static int structuralHammingDistance(Graph trueGraph, Graph estGraph) { try { estGraph = GraphUtils.replaceNodes(estGraph, trueGraph.getNodes()); - trueGraph = GraphSearchUtils.cpdagForDag(trueGraph); - estGraph = GraphSearchUtils.cpdagForDag(estGraph); + trueGraph = GraphTransforms.cpdagForDag(trueGraph); + estGraph = GraphTransforms.cpdagForDag(estGraph); // Will check mixedness later. if (trueGraph.paths().existsDirectedCycle()) { @@ -1275,11 +1063,6 @@ public static int[][] graphComparison(Graph trueCpdag, Graph estCpdag, PrintStre return counts; } - @NotNull - public static Graph dagToPag(Graph trueGraph) { - return new DagToPag(trueGraph).convert(); - } - /** * Gives the options for triple type for a conservative unshielded collider orientation, which may be "collider" or * "noncollider" or "ambiguous". diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java index ab9781c208..7d320a1bfc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MbUtils.java @@ -238,7 +238,7 @@ public static List generateMbDags(Graph mbCPDAG, * @return An example DAG in this CPDAG. */ public static Graph getOneMbDag(Graph mbCpdag) { - return GraphSearchUtils.dagFromCPDAG(mbCpdag); + return GraphTransforms.dagFromCPDAG(mbCpdag, null); } /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java index a5810616be..f329f72144 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/MeekRules.java @@ -135,8 +135,8 @@ public void setMeekPreventCycles(boolean meekPreventCycles) { /** * Returns a complete set of all the edges that were changed in the course of orientation, as a map from the - * previous edges in the graph to the new, changed edges for the same node pair. For example, if X->Y was changed to - * X<-Y, thie map will send X->Y to X<-Y. + * previous edges in the graph to the new, changed edges for the same node pair. For example, if X->Y was changed to + * X<-Y, thie map will send X->Y to X<-Y. * * @return This map. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java index 0e497a1789..be8d250df5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/PcCommon.java @@ -579,7 +579,7 @@ private void orientCollidersUsingSepsets(SepsetMap set, Knowledge knowledge, Gra *

    NONE = no heuristic, PC-1 = sort nodes alphabetically; PC-1 = sort edges by p-value; PC-3 = additionally sort * edges in reverse order using p-values of associated independence facts. See this reference:

    * - *

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

    + *

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

    */ public enum PcHeuristicType {NONE, HEURISTIC_1, HEURISTIC_2, HEURISTIC_3} @@ -596,7 +596,7 @@ public enum FasType {REGULAR, STABLE} *

    Give the options for the collider discovery algroithm to use--FAS with sepsets reasoning, FAS with * conservative reasoning, or FAS with Max P reasoning. See these respective references:

    * - *

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

    + *

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

    * *

    Ramsey, J., Zhang, J., & Spirtes, P. L. (2012). Adjacency-faithfulness and conservative causal inference. * arXiv preprint arXiv:1206.6843.

    diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java index 9bbb5ff5e6..f97404f1b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/ResolveSepsets.java @@ -38,7 +38,7 @@ * between sepsets learned for overlapping datasets. This occurs frequently when using the DCI and ION algorithm. A * reference is here:

    * - *

    Tillman, R. E., & Eberhardt, F. (2014). Learning causal structure from + *

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

    * * @author roberttillman diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java index 4f2b6154f0..389fa02d80 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/SepsetMap.java @@ -43,7 +43,7 @@ * @author josephramsey */ public final class SepsetMap implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Map> parents = new HashMap<>(); private Map, Set> sepsets = new ConcurrentHashMap<>(); private Map, Double> pValues = new ConcurrentHashMap<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Sextad.java index cd139e5660..fa991ab9b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/Sextad.java @@ -11,7 +11,7 @@ * @author josephramsey */ public class Sextad implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final int i; private final int j; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java index d0ef2dd916..a015a29f52 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/utils/TetradTestContinuous.java @@ -599,7 +599,7 @@ public boolean isSignificant() { } static class OneFactorEstimator extends SimpleFactorEstimator { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public OneFactorEstimator(ICovarianceMatrix sampleCov, double sig, int nvar) { @@ -623,7 +623,7 @@ protected SemPm buildSemPm(int[] values) { } static class TwoFactorsEstimator extends SimpleFactorEstimator { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; int nleft; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Fas3.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Fas3.java index 93fbfb3b45..d8801baf24 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Fas3.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Fas3.java @@ -330,7 +330,7 @@ public void setPcHeuristicType(PcCommon.PcHeuristicType pcHeuristic) { *

    Sets whether the stable adjacency search should be used. Default is false. Default is false. See the * following reference for this:

    * - *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. + *

    Colombo, D., & Maathuis, M. H. (2014). Order-independent constraint-based causal structure learning. J. Mach. * Learn. Res., 15(1), 3741-3782.

    * * @param stable True iff the case. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java index dd3123eaea..55584e6f7b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FasLofs.java @@ -44,7 +44,7 @@ * This was an early attempt at this. For PC-LiNGAM, see this paper:

    * *

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

    * * @author josephramsey diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java index 56026de4ad..b71fffdef0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/FaskVote.java @@ -3,10 +3,7 @@ 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; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.Knowledge; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fask; import edu.cmu.tetrad.util.Parameters; @@ -60,7 +57,7 @@ public Graph search(Parameters parameters) { List _dataSets = new ArrayList<>(); for (DataSet dataSet : this.dataSets) { - _dataSets.add(DataUtils.standardizeData(dataSet)); + _dataSets.add(DataTransforms.standardizeData(dataSet)); } Images imagesSemBic = new Images(score); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java index 41bbc64ee9..4cf15d1fe4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsBeam.java @@ -29,7 +29,6 @@ import edu.cmu.tetrad.regression.Regression; import edu.cmu.tetrad.regression.RegressionCovariance; import edu.cmu.tetrad.regression.RegressionResult; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.utils.MeekRules; import edu.cmu.tetrad.sem.*; import edu.cmu.tetrad.util.TetradLogger; @@ -84,7 +83,7 @@ public HbsmsBeam(Graph graph, CovarianceMatrix cov, Knowledge knowledge) { public Graph search() { EdgeListGraph _graph = new EdgeListGraph(this.externalGraph); addRequiredEdges(_graph); - Graph bestGraph = GraphSearchUtils.dagFromCPDAG(_graph); + Graph bestGraph = GraphTransforms.dagFromCPDAG(_graph, null); if (getGraph().getNumEdges() == 0) { System.out.println("Found one!"); @@ -106,7 +105,7 @@ public Graph search() { if (this.trueModel != null) { this.trueModel = GraphUtils.replaceNodes(this.trueModel, bestGraph.getNodes()); - this.trueModel = GraphSearchUtils.cpdagForDag(this.trueModel); + this.trueModel = GraphTransforms.cpdagForDag(this.trueModel); } System.out.println("Initial Score = " + this.nf.format(bestScore)); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java index 9c90c3d563..debf8bf9d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/HbsmsGes.java @@ -62,7 +62,7 @@ public HbsmsGes(Graph graph, DataSet data) { DagInCpcagIterator iterator = new DagInCpcagIterator(graph, getKnowledge(), allowArbitraryOrientations, allowNewColliders); graph = iterator.next(); - graph = GraphSearchUtils.cpdagForDag(graph); + graph = GraphTransforms.cpdagForDag(graph); if (GraphUtils.containsBidirectedEdge(graph)) { throw new IllegalArgumentException("Contains bidirected edge."); @@ -166,7 +166,7 @@ private void saveModelIfSignificant(Graph graph) { } public Score scoreGraph(Graph graph) { - Graph dag = GraphSearchUtils.dagFromCPDAG(graph, getKnowledge()); + Graph dag = GraphTransforms.dagFromCPDAG(graph, getKnowledge()); this.scorer.score(dag); return new Score(this.scorer); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java index 0534a5a5df..402155badc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestCramerT.java @@ -245,6 +245,10 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { boolean independent = isZero(this.storedR, size, getAlpha()); double pValue = getPValue(); + if (Double.isNaN(pValue)) { + throw new RuntimeException("Undefined p-value encountered for test: " + LogUtilsSearch.independenceFact(x, y, _z)); + } + if (this.verbose) { if (independent) { TetradLogger.getInstance().forceLogMessage( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java index eeeadc9ee8..f7dafb2aa7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZGeneralizedInverse.java @@ -27,7 +27,7 @@ import cern.colt.matrix.linalg.Algebra; import cern.jet.math.Functions; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceTest; @@ -95,7 +95,7 @@ public IndTestFisherZGeneralizedInverse(DataSet dataSet, double alpha) { this.dataSet = dataSet; - this.data = new DenseDoubleMatrix2D(DataUtils.center(this.dataSet).getDoubleData().toArray()); + this.data = new DenseDoubleMatrix2D(DataTransforms.center(this.dataSet).getDoubleData().toArray()); this.variables = Collections.unmodifiableList(this.dataSet.getVariables()); setAlpha(alpha); } @@ -205,6 +205,10 @@ public IndependenceResult checkIndependence(Node xVar, Node yVar, Set _z) TetradLogger.getInstance().log("independencies", LogUtilsSearch.independenceFactMsg(xVar, yVar, _z, getPValue())); } + if (Double.isNaN(getPValue())) { + throw new RuntimeException("Undefined p-value encountered for test: " + LogUtilsSearch.independenceFact(xVar, yVar, _z)); + } + if (this.verbose) { if (indFisher) { TetradLogger.getInstance().forceLogMessage( diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java index 3302b76048..462c8e492c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZPercentIndependent.java @@ -21,10 +21,7 @@ package edu.cmu.tetrad.search.work_in_progress; -import edu.cmu.tetrad.data.CovarianceMatrix; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.ICovarianceMatrix; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.IndependenceFact; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.search.IndependenceTest; @@ -70,7 +67,7 @@ public IndTestFisherZPercentIndependent(List dataSets, double alpha) { this.data = new ArrayList<>(); for (DataSet dataSet : dataSets) { - dataSet = DataUtils.center(dataSet); + dataSet = DataTransforms.center(dataSet); Matrix _data = dataSet.getDoubleData(); this.data.add(_data); } @@ -136,6 +133,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { int index = (int) round((1.0 - this.percent) * pValues.size()); double pValue = pValues.get(index); + if (Double.isNaN(pValue)) { + throw new RuntimeException("NaN p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, _z)); + } + boolean independent = pValue > _cutoff; if (this.verbose) { @@ -195,17 +197,17 @@ public boolean determines(List z, Node x) throws UnsupportedOperationException { * @throws UnsupportedOperationException */ public DataSet getData() { - return DataUtils.concatenate(this.dataSets); + return DataTransforms.concatenate(this.dataSets); } public ICovarianceMatrix getCov() { List _dataSets = new ArrayList<>(); for (DataSet d : this.dataSets) { - _dataSets.add(DataUtils.standardizeData(d)); + _dataSets.add(DataTransforms.standardizeData(d)); } - return new CovarianceMatrix(DataUtils.concatenate(this.dataSets)); + return new CovarianceMatrix(DataTransforms.concatenate(this.dataSets)); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java index ff85839b3e..9d019cf25c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestFisherZRecursive.java @@ -198,6 +198,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set z) { double fisherZ = sqrt(n - 3 - z.size()) * abs(q); this.fisherZ = fisherZ; + if (Double.isNaN(fisherZ)) { + throw new RuntimeException("NaN Fisher's Z encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + boolean independent = fisherZ < this.cutoff; if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMnlrLr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMnlrLr.java index 5eff479cec..49aa518902 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMnlrLr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMnlrLr.java @@ -129,6 +129,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { double pValue = FastMath.min(p_0, p_1); + if (Double.isNaN(pValue)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, _z)); + } + boolean independent = pValue > this.alpha; if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java index 57f22b5d5d..789e5e6269 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestMultinomialLogisticRegression.java @@ -194,6 +194,12 @@ private IndependenceResult isIndependentMultinomialLogisticRegression(Node x, No double chisq = (ll0 - ll1); int df = this.variablesPerNode.get(y).size(); double p = 1.0 - new ChiSquaredDistribution(df).cumulativeProbability(chisq); + + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + pValues.add(p); } @@ -264,6 +270,11 @@ private IndependenceResult isIndependentRegression(Node x, Node y, Set z) double p = result.getP()[1]; this.lastP = p; + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + boolean indep = p > this.alpha; if (this.verbose) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestPositiveCorr.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestPositiveCorr.java index a50bde2886..089b312b6d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestPositiveCorr.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestPositiveCorr.java @@ -177,6 +177,11 @@ public IndependenceResult checkIndependence(Node x0, Node y0, Set _z0) { double pValue = getPValue(); + if (Double.isNaN(pValue)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x0, y0, _z0)); + } + return new IndependenceResult(new IndependenceFact(x0, y0, _z0), !possibleEdge, pValue, alpha - pValue); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestSepsetDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestSepsetDci.java index ad5f443e0e..faf8b64e2a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestSepsetDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestSepsetDci.java @@ -145,6 +145,11 @@ public IndependenceResult checkIndependence(Node x, Node y, Set z) { } } + if (Double.isNaN(getPValue())) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + return new IndependenceResult(new IndependenceFact(x, y, z), independent, getPValue(), getAlpha() - getPValue()); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestUniformScatter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestUniformScatter.java index d2a69a4329..76081fd8a0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestUniformScatter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/IndTestUniformScatter.java @@ -5,6 +5,7 @@ import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.test.IndependenceResult; import edu.cmu.tetrad.search.test.MsepTest; +import edu.cmu.tetrad.search.utils.LogUtilsSearch; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.CombinationIterator; @@ -318,7 +319,13 @@ public IndependenceResult checkIndependence(Node x, Node y, Set z) { int m = (int) pow(numCellsPerTable, 0.5); double p = getConditionallyIndependentUniformPvalue(data, xIndex, yIndex, _z, m, numCondCategories); - return new IndependenceResult(new IndependenceFact(x, y, z), p > alpha, p, alpha - p); + + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + + return new IndependenceResult(new IndependenceFact(x, y, z), p > alpha, p, p); } @Override diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java index 2ebe598d84..8bc7b9a54a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Ion.java @@ -1551,13 +1551,13 @@ private Set checkPaths(Set pags) { Node node2 = pag.getNode(edge.getNode2().getName()); if (Edges.isDirectedEdge(edge)) { - if (!pag.paths().existsSemiDirectedPathFromTo(node1, Collections.singleton(node2))) { + if (!pag.paths().existsSemiDirectedPath(node1, Collections.singleton(node2))) { allAccountFor = false; break GRAPH; } } if (/*!pag.existsTrek(node1, node2) ||*/ Edges.isPartiallyOrientedEdge(edge)) { - if (pag.paths().existsSemiDirectedPathFromTo(node2, Collections.singleton(node1))) { + if (pag.paths().existsSemiDirectedPath(node2, Collections.singleton(node1))) { allAccountFor = false; break GRAPH; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java index bfad240b9e..983c23c537 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/ProbabilisticMapIndependence.java @@ -127,6 +127,12 @@ public IndependenceResult checkIndependence(Node x, Node y, Set _z) { public IndependenceResult checkIndependence(Node x, Node y, Node... z) { double pInd = probConstraint(BCInference.OP.independent, x, y, z); double p = this.probOp(pInd); + + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, GraphUtils.asSet(z))); + } + posterior = p; boolean independent = p > 0.5; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java index 81edba51cd..54f36eff63 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/SepsetMapDci.java @@ -44,7 +44,7 @@ * @author Robert Tillman */ public final class SepsetMapDci { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Map> parents = new HashMap<>(); /** * @serial diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java index 876fa07f28..3ec8b1782c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/work_in_progress/Sextad.java @@ -32,7 +32,7 @@ * Represents an ordered sextad of variables. */ public class Sextad implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Node i; private final Node j; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java index 4342c00f6c..961f2e7e2d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/DagScorer.java @@ -47,7 +47,7 @@ * @author josephramsey */ public final class DagScorer implements TetradSerializable, Scorer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final ICovarianceMatrix covMatrix; private final Matrix edgeCoef; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java index 6d38d7851e..2ddf29a889 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemIm.java @@ -53,7 +53,7 @@ * @author josephramsey */ public class GeneralizedSemIm implements Im, Simulator { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The wrapped PM, that holds all of the expressions and structure for the model. @@ -459,7 +459,7 @@ public DataSet simulateDataRecursive(int sampleSize, boolean latentDataSaved) { if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } @@ -591,7 +591,7 @@ public double value(double[] doubles) { if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } @@ -730,7 +730,7 @@ public DataSet simulateDataAvoidInfinity(int sampleSize, boolean latentDataSaved if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } @@ -875,7 +875,7 @@ public synchronized DataSet simulateDataFisher(int sampleSize, int intervalBetwe } BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox(all), continuousVars); - return DataUtils.restrictToMeasured(boxDataSet); + return DataTransforms.restrictToMeasured(boxDataSet); } @@ -1064,7 +1064,7 @@ public DataSet simulateDataNSteps(int sampleSize, boolean latentDataSaved) { if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java index b62cc113f2..6cb780e1de 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/GeneralizedSemPm.java @@ -40,7 +40,7 @@ * @author josephramsey */ public final class GeneralizedSemPm implements Pm, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The structural model graph that this sem parametric model is based on. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java index 8837fa69c8..d86ee5f347 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/LargeScaleSimulation.java @@ -51,7 +51,7 @@ */ public final class LargeScaleSimulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final List variableNodes; private final Graph graph; private int[][] parents; @@ -265,7 +265,7 @@ public DataSet simulateDataReducedForm(int sampleSize) { } BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox(all), continuousVars); - return DataUtils.restrictToMeasured(boxDataSet); + return DataTransforms.restrictToMeasured(boxDataSet); } /** @@ -357,7 +357,7 @@ public DataSet simulateDataFisher(double[][] shocks, int intervalBetweenShocks, } BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox(all), continuousVars); - return DataUtils.restrictToMeasured(boxDataSet); + return DataTransforms.restrictToMeasured(boxDataSet); } public DataSet simulateDataFisher(int intervalBetweenShocks, int intervalBetweenRecordings, int sampleSize, double epsilon, boolean saveLatentVars) { @@ -426,7 +426,7 @@ public DataSet simulateDataFisher(int intervalBetweenShocks, int intervalBetween BoxDataSet boxDataSet = new BoxDataSet(new VerticalDoubleDataBox(all), continuousVars); - return saveLatentVars ? boxDataSet : DataUtils.restrictToMeasured(boxDataSet); + return saveLatentVars ? boxDataSet : DataTransforms.restrictToMeasured(boxDataSet); } private void setupModel(int size) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Mapping.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Mapping.java index ff5ad617e7..7f8a35b66c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Mapping.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Mapping.java @@ -37,7 +37,7 @@ * @author Joe Ramsey */ public class Mapping implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The SemIm for which this is a mapping. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraint.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraint.java index d7bf597b82..cdf791c609 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraint.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraint.java @@ -32,7 +32,7 @@ * @author Frank Wimberly */ public class ParamConstraint implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double number; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraintType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraintType.java index 827d33fc50..c1e269da71 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraintType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamConstraintType.java @@ -50,7 +50,7 @@ public class ParamConstraintType implements TetradSerializable { */ public static final ParamConstraintType NONE = new ParamConstraintType("NONE"); - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final ParamConstraintType[] TYPES = {ParamConstraintType.LT, ParamConstraintType.GT, ParamConstraintType.EQ, ParamConstraintType.NONE}; // Declarations required for serialization. private static int NEXT_ORDINAL; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java index ca79734239..fb83d91e9b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParamType.java @@ -49,7 +49,7 @@ public class ParamType implements TetradSerializable { * A covariance parameter. (Does not include variance freeParameters; these are indicated using VAR.) */ public static final ParamType COVAR = new ParamType("Error Covariance"); - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * A parameter of a distribution. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java index 2a909acbef..e699f583bd 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/Parameter.java @@ -39,7 +39,7 @@ * @author josephramsey */ public final class Parameter implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The default distribution from which initial values are drawn for this distribution. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java index 24ac44a44b..6bae0d5b03 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/ParameterPair.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class ParameterPair implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The first element of the ordered pair. Can be null. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java index cbb2366371..f6cd16a7ff 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimator.java @@ -42,7 +42,7 @@ * @author josephramsey */ public final class SemEstimator implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The SemPm containing the graph and the freeParameters to be estimated. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java index 0213a1b707..9a24d61f1f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbs.java @@ -41,7 +41,7 @@ * @author Frank Wimberly */ public final class SemEstimatorGibbs { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final int numIterations; private final double stretch1; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbsParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbsParams.java index 962ea1f92b..8ecae988e5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbsParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEstimatorGibbsParams.java @@ -34,7 +34,7 @@ * @author Frank Wimberly */ public final class SemEstimatorGibbsParams implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double tolerance; private SemIm startIm; private boolean flatPrior; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java index cc8e335ba8..b177e4fee0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemEvidence.java @@ -36,7 +36,7 @@ * @author josephramsey */ public final class SemEvidence implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Bayes IM that this is evidence for. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java index 87b0c62142..6f0a62aca9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemIm.java @@ -65,7 +65,7 @@ */ public final class SemIm implements Im, ISemIm { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The Sem PM containing the graph and the freeParameters to be estimated. For now a defensive copy of this is not * being constructed, since it is not used anywhere in the code except in the the constructor and in its accessor @@ -209,6 +209,7 @@ public final class SemIm implements Im, ISemIm { private ScoreType scoreType = ScoreType.Fml; private double errorParam1; private double errorParam2 = 1.0; + private int numRandomCalls = 0; /** * Constructs a new SEM IM from a SEM PM. @@ -1151,7 +1152,7 @@ private DataSet simulateTimeSeries(int sampleSize, boolean latentDataSaved) { } Node child = semGraph.getChildren(parent).iterator().next(); double paramValue = getParamValue(child, child); - sum += RandomUtil.getInstance().nextNormal(0.0, paramValue); + sum += getNextNormal(0.0, paramValue); } else { TimeLagGraph.NodeId id = timeSeriesGraph.getNodeId(parent); int fromIndex = nodeIndices.get(timeSeriesGraph.getNode(id.getName(), 0)); @@ -1161,7 +1162,7 @@ private DataSet simulateTimeSeries(int sampleSize, boolean latentDataSaved) { double fromValue = fullData.getDouble(currentStep - lag, fromIndex); sum += coef * fromValue; } else { - sum += RandomUtil.getInstance().nextNormal(0.0, 0.5); + sum += getNextNormal(0.0, 0.5); } } } @@ -1173,7 +1174,12 @@ private DataSet simulateTimeSeries(int sampleSize, boolean latentDataSaved) { } } - return latentDataSaved ? fullData : DataUtils.restrictToMeasured(fullData); + return latentDataSaved ? fullData : DataTransforms.restrictToMeasured(fullData); + } + + private double getNextNormal(double mean, double stdDev) { + numRandomCalls++; + return RandomUtil.getInstance().nextNormal(mean, stdDev); } // /** @@ -1266,7 +1272,7 @@ public DataSet simulateDataCholesky(int sampleSize, boolean latentDataSaved) { if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } @@ -1336,18 +1342,16 @@ private DataSet simulateDataRecursive(int sampleSize, DataSet initialValues, for (int i = 0; i < exoData.length; i++) { if (errorType == 1) { - exoData[i] = RandomUtil.getInstance().nextNormal(0, + exoData[i] = getNextNormal(0, sqrt(this.errCovar.get(i, i))); } else if (errorType == 2) { - exoData[i] = RandomUtil.getInstance().nextUniform(this.errorParam1, this.errorParam2); + exoData[i] = getNextUniform(); } else if (errorType == 3) { - exoData[i] = RandomUtil.getInstance().nextExponential(this.errorParam1); + exoData[i] = getNextExponential(); } else if (errorType == 4) { - exoData[i] = RandomUtil.getInstance().nextGumbel(this.errorParam1, - this.errorParam2); + exoData[i] = getNextGumbel(); } else if (errorType == 5) { - exoData[i] = RandomUtil.getInstance().nextGamma(this.errorParam1, - this.errorParam2); + exoData[i] = getNextGamma(); } } @@ -1441,10 +1445,32 @@ private DataSet simulateDataRecursive(int sampleSize, DataSet initialValues, if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } + private double getNextGamma() { + numRandomCalls++; + return RandomUtil.getInstance().nextGamma(this.errorParam1, + this.errorParam2); + } + + private double getNextGumbel() { + numRandomCalls++; + return RandomUtil.getInstance().nextGumbel(this.errorParam1, + this.errorParam2); + } + + private double getNextExponential() { + numRandomCalls++; + return RandomUtil.getInstance().nextExponential(this.errorParam1); + } + + private double getNextUniform() { + numRandomCalls++; + return RandomUtil.getInstance().nextUniform(this.errorParam1, this.errorParam2); + } + public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) { int errorType = this.params.getInt(Params.SIMULATION_ERROR_TYPE); double errorParam1 = params.getDouble(Params.SIMULATION_PARAM1); @@ -1466,11 +1492,13 @@ public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) Vector e = new Vector(this.edgeCoef.getNumColumns()); for (int i = 0; i < e.size(); i++) { -// e.set(i, RandomUtil.getInstance().nextNormal(0, sqrt(errCovar.get(i, i)))); - if (errorType == 1) { - e.set(i, RandomUtil.getInstance().nextNormal(0, sqrt(this.errCovar.get(i, i)))); -// e.set(i, RandomUtil.getInstance().nextNormal(0, sqrt(errorParam2))); + double errCovar = this.errCovar.get(i, i); + if (errCovar == 0.0) { + e.set(i, 0.0); + } else { + e.set(i, RandomUtil.getInstance().nextNormal(0, sqrt(errCovar))); + } } else if (errorType == 2) { e.set(i, RandomUtil.getInstance().nextUniform(errorParam1, errorParam2)); } else if (errorType == 3) { @@ -1511,7 +1539,7 @@ public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } @@ -2155,4 +2183,8 @@ public Matrix getImplCovar(List nodes) { return implCovarMeas; } + + public int getNumRandomCalls() { + return numRandomCalls; + } } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java index bac11364ef..7331adde1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemManipulation.java @@ -36,7 +36,7 @@ * @author josephramsey */ public final class SemManipulation implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Bayes IM that this is evidence for. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java index df8a302da9..2b2c68ee3c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerEm.java @@ -41,7 +41,7 @@ * @author josephramsey Cleanup, modernization. */ public class SemOptimizerEm implements SemOptimizer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private static final double FUNC_TOLERANCE = 1.0e-6; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java index 67a2629336..bf990d2a98 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerPowell.java @@ -40,7 +40,7 @@ * @author josephramsey */ public class SemOptimizerPowell implements SemOptimizer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numRestarts; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRegression.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRegression.java index de93a602da..e40c1be2cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRegression.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRegression.java @@ -38,7 +38,7 @@ * @author josephramsey */ public class SemOptimizerRegression implements SemOptimizer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numRestarts = 1; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java index 555c21e6f9..a05c9aa093 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerRicf.java @@ -33,7 +33,7 @@ * @author josephramsey */ public class SemOptimizerRicf implements SemOptimizer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numRestarts = 1; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java index 09733ae19b..9f7c27542b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemOptimizerScattershot.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class SemOptimizerScattershot implements SemOptimizer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private int numRestarts; /** diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java index e5b8750e66..457b25cd29 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemPm.java @@ -43,7 +43,7 @@ * @author josephramsey */ public final class SemPm implements Pm, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The structural model graph that this sem parametric model is based on. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java index 137e5d883f..98103b741f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemProposition.java @@ -40,7 +40,7 @@ * @author josephramsey */ public final class SemProposition implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java index aa1703aef5..8ac7eac4a1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/SemUpdater.java @@ -45,7 +45,7 @@ */ public class SemUpdater implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final SemIm semIm; private SemEvidence evidence; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java index a9fabdd142..64c13c32ca 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/sem/StandardizedSemIm.java @@ -51,7 +51,7 @@ * Currently we are not allowing bidirected edges in the SEM graph. */ public class StandardizedSemIm implements Simulator { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final int sampleSize; /** * The SEM model. @@ -144,7 +144,7 @@ public StandardizedSemIm(SemIm im, Initialization initialization, Parameters par // This code estimates the new coefficients from simulated data from the old model. DataSet dataSet = im.simulateData(this.sampleSize, false); Matrix _dataSet = dataSet.getDoubleData(); - _dataSet = DataUtils.standardizeData(_dataSet); + _dataSet = DataTransforms.standardizeData(_dataSet); DataSet dataSetStandardized = new BoxDataSet(new VerticalDoubleDataBox(_dataSet.toArray()), dataSet.getVariables()); SemEstimator estimator = new SemEstimator(dataSetStandardized, im.getSemPm()); @@ -581,7 +581,7 @@ public DataSet simulateDataReducedForm(int sampleSize, boolean latentDataSaved) if (latentDataSaved) { return fullDataSet; } else { - return DataUtils.restrictToMeasured(fullDataSet); + return DataTransforms.restrictToMeasured(fullDataSet); } } @@ -824,7 +824,7 @@ public enum Initialization { * @author josephramsey */ public static final class ParameterRange implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Edge edge; private final double coef; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java index b1f7ed57d1..bdcdb8830a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Session.java @@ -66,7 +66,7 @@ * @see SessionEvent */ public final class Session implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The session nodes, stored as a Set of nodes. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java index e9a47c357f..1caaa8f13b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/SessionNode.java @@ -62,7 +62,7 @@ */ public class SessionNode implements Node { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * A map from model classes to parameter objects. * @@ -1508,14 +1508,16 @@ private void createModelUsingArguments(Class modelClass, List models) } } - if (arguments == null) { - arguments = assignParameters(constructorTypes, models); - } - if (constructorTypes.length == 0) { + JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "UI models shouldn't have blank constructors. " + + "This one did: " + modelClass.getName()); continue; } + if (arguments == null) { + arguments = assignParameters(constructorTypes, models); + } + if (arguments != null) { try { this.model = (SessionModel) constructor.newInstance(arguments); @@ -1529,10 +1531,10 @@ private void createModelUsingArguments(Class modelClass, List models) int begin = packagePath.lastIndexOf('.') + 1; String name = packagePath.substring(begin); - if (e.getTargetException() instanceof ThreadDeath) { - e.printStackTrace(); - return; - } +// if (e.getTargetException() instanceof ThreadDeath) { +// e.printStackTrace(); +// return; +// } e.printStackTrace(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type1.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type1.java index fc27111239..d3ceba0107 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type1.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type1.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type1 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * A sample constructor that takes Model 2 and Type3 as parent. The session node wrapping this should allow parent diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type10.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type10.java index 92cf3b512b..dbbc4fb000 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type10.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type10.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type10 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Type10(Type6 model1, Type6 model2, Parameters parameters) { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type11.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type11.java index e54243da53..9aca6b6608 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type11.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type11.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type11 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Type11(Parameters parameters) { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type12.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type12.java index eeefffc630..8b7e359e47 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type12.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type12.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type12 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Type12(Type11 a, Parameters parameters) { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type2.java index 48786849c0..67bfc2b5d0 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type2.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type2 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * A sample constructor that takes Model 2 and Type3 as parent. The session node wrapping this should allow parent diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type3.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type3.java index e9f3efe106..16694abd93 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type3.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type3.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type3 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * It should be possible to construct a Type3-model with a Type1-node as parent. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type4.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type4.java index d456641324..8ed3c1ab65 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type4.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type4.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type4 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * It should be possible to construct a Type4-model with a Type1-node as parent. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type5.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type5.java index 7cc6755e44..1f16fc63c7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type5.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type5.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type5 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * It should not be possible to constuct Type5, because it contains two arguments of the same type. There is in diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type6.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type6.java index 22b5d97867..3ed9c98e58 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type6.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type6.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type6 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Type6(Type7 model1, Type8 model2, Parameters parameters) { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type7.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type7.java index b96a295c2f..7b4522b777 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type7.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type7.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type7 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Type7(Parameters parameters) { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type8.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type8.java index 6408a31cb6..e4b98026cc 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type8.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type8.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type8 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Type8(Type7 model1, Parameters parameters) { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type9.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type9.java index ccec12920c..2140ff305f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type9.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/session/Type9.java @@ -29,7 +29,7 @@ * A sample class to be wrapped in a SessionNode as a model. */ public class Type9 implements SessionModel, TetradSerializableExcluded { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; public Type9(Type6 model1, Parameters parameters) { } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java index 63e19e16f0..77a8b897cf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/GdistanceRandom.java @@ -2,8 +2,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import java.util.ArrayList; import java.util.List; @@ -52,8 +52,8 @@ private List randomPairSimulation() { //convert those dags to CPDAGs if (this.verbose) System.out.println("converting dags to CPDAGs"); - Graph graph1 = GraphSearchUtils.cpdagFromDag(dag1); - Graph graph2 = GraphSearchUtils.cpdagFromDag(dag2); + Graph graph1 = GraphTransforms.cpdagForDag(dag1); + Graph graph2 = GraphTransforms.cpdagForDag(dag2); //run Gdistance on these two graphs if (this.verbose) System.out.println("running Gdistance on the CPDAGs"); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java index e0d931b43d..c01171c804 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoC.java @@ -4,13 +4,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataWriter; import edu.cmu.tetrad.data.ICovarianceMatrix; -import edu.cmu.tetrad.graph.Dag; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.GraphUtils; -import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.SemBicScore; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; import edu.cmu.tetrad.util.RandomUtil; @@ -75,7 +71,7 @@ public double[] run(int resimSize) { Graph estGraph = fges.search(); //if (verbose) System.out.println(estGraph); - Graph estGraphDAG = GraphSearchUtils.dagFromCPDAG(estGraph); + Graph estGraphDAG = GraphTransforms.dagFromCPDAG(estGraph, null); Dag estDAG = new Dag(estGraphDAG); //Dag estDAG = new Dag(estGraph); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java index 9bc0e3db32..9c37e02850 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimAutoRun.java @@ -7,7 +7,6 @@ import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.BdeuScore; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.DataConvertUtils; import edu.cmu.tetrad.util.DelimiterUtils; import edu.cmu.tetrad.util.RandomUtil; @@ -90,7 +89,7 @@ public double[] run(int resimSize) { //if (verbose) System.out.println(estGraph); Graph estCPDAG = new EdgeListGraph(estGraph); - Graph estGraphDAG = GraphSearchUtils.dagFromCPDAG(estCPDAG); + Graph estGraphDAG = GraphTransforms.dagFromCPDAG(estCPDAG, null); Dag estDAG = new Dag(estGraphDAG); //===========Identify the nodes to be resimulated=========== diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java index ce8d7940de..ca82e2e486 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimEvalFromData.java @@ -6,9 +6,9 @@ import edu.cmu.tetrad.graph.Dag; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphSaveLoadUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.SemBicScore; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.SemEstimator; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; @@ -89,7 +89,7 @@ public static void main(String[] args) { for (whichFrepeat = 0; whichFrepeat < fsimRepeat.size(); whichFrepeat++) { ArrayList errorsList = new ArrayList<>(); for (int r = 0; r < fsimRepeat.get(whichFrepeat); r++) { - Graph fgsDag = GraphSearchUtils.dagFromCPDAG(oFGSGraph); + Graph fgsDag = GraphTransforms.dagFromCPDAG(oFGSGraph, null); Dag fgsdag2 = new Dag(fgsDag); //then fit an IM to this dag and the data. GeneralizedSemEstimator seems to bug out diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java index 77417a7fb8..86f9911c9a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRobustCompare.java @@ -3,13 +3,9 @@ import edu.cmu.tetrad.bayes.*; import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.graph.Dag; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; -import edu.cmu.tetrad.graph.RandomGraph; +import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.BdeuScore; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; @@ -68,7 +64,7 @@ public static List run(int numVars, double edgesPerNode, int numCases, //create various simulated data sets ////let's do the full simulated data set first: a dag in the FGES CPDAG fit to the data set. - Graph fgesDag = GraphSearchUtils.dagFromCPDAG(oGraphOut); + Graph fgesDag = GraphTransforms.dagFromCPDAG(oGraphOut, null); Dag fgesdag2 = new Dag(fgesDag); BayesPm simBayesPm = new BayesPm(fgesdag2, bayesPm); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java index d86f00a98b..f4b9d720bb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/simulation/HsimRun.java @@ -3,10 +3,7 @@ import edu.cmu.tetrad.data.CovarianceMatrix; import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DataWriter; -import edu.cmu.tetrad.graph.Dag; -import edu.cmu.tetrad.graph.EdgeListGraph; -import edu.cmu.tetrad.graph.Graph; -import edu.cmu.tetrad.graph.Node; +import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.Fges; import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.utils.GraphSearchUtils; @@ -52,7 +49,7 @@ public static void run(String readfilename, String filenameOut, char delimiter, System.out.println(estGraph); Graph estCPDAG = new EdgeListGraph(estGraph); - Graph estGraphDAG = GraphSearchUtils.dagFromCPDAG(estCPDAG); + Graph estGraphDAG = GraphTransforms.dagFromCPDAG(estCPDAG, null); Dag estDAG = new Dag(estGraphDAG); //===========Identify the nodes to be resimulated=========== diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/stat/correlation/RealCovarianceMatrixForkJoin.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/stat/correlation/RealCovarianceMatrixForkJoin.java index f7e76f758e..f71bea211c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/stat/correlation/RealCovarianceMatrixForkJoin.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/stat/correlation/RealCovarianceMatrixForkJoin.java @@ -30,7 +30,7 @@ * @author Kevin V. Bui (kvb2@pitt.edu) */ public class RealCovarianceMatrixForkJoin implements RealCovariance { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double[][] data; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java index 3d681541f0..6828eefd88 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/RBExperiments.java @@ -156,11 +156,11 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo // simulate data from instantiated model DataSet fullData = im.simulateData(numCases, /*round * 1000000 + 71512,*/ true); refineData(fullData); - DataSet data = DataUtils.restrictToMeasured(fullData); + DataSet data = DataTransforms.restrictToMeasured(fullData); // get the true underlying PAG - Graph PAG_True = GraphSearchUtils.dagToPag(dag); + Graph PAG_True = GraphTransforms.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, data.getVariables()); @@ -187,7 +187,7 @@ public void experiment(String modelName, int numCases, int numModels, int numBoo // learn structure of constraints using empirical data Graph depCPDAG = runFGS(depData); - Graph estDepBN = GraphSearchUtils.dagFromCPDAG(depCPDAG); + Graph estDepBN = GraphTransforms.dagFromCPDAG(depCPDAG, null); System.out.println("estDepBN: " + estDepBN.getEdges()); out.println("DepGraph(nodes,edges):" + estDepBN.getNumNodes() + "," + estDepBN.getNumEdges()); System.out.println("Dependency graph done!"); @@ -369,7 +369,8 @@ private DataSet createDepDataFiltering(Map H, DataSet System.out.println("HCopy size: " + HCopy.size()); for (int b = 0; b < numBootstrapSamples; b++) { - DataSet bsData = DataUtils.getBootstrapSample(data, data.getNumRows()); + int sampleSize = data.getNumRows(); + DataSet bsData = DataTransforms.getBootstrapSample(data, sampleSize); IndTestProbabilistic bsTest = new IndTestProbabilistic(bsData); bsTest.setThreshold(threshold); for (IndependenceFact f : HCopy.keySet()) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java index 85a9a0c223..e5c2606894 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaDigraph.java @@ -27,7 +27,7 @@ import java.io.IOException; /** - * Implements a digraph to be used by the Biolingua algorithm.

    + *

    Implements a digraph to be used by the Biolingua algorithm.

    * * @author Raul Saavedra * (rsaavedr@ai.uwf.edu) @@ -37,6 +37,9 @@ public class BiolinguaDigraph extends Digraph implements OutputGraph { /** * Creates a BiolinguaDigraph with name gName and * n nodes + * + * @param gName the name of the graph + * @param n the number of nodes */ public BiolinguaDigraph(String gName, int n) { super(gName, n); @@ -44,14 +47,18 @@ public BiolinguaDigraph(String gName, int n) { /** * Creates a BiolinguaDigraph reading it from file fname. + * + * @param fname the name of the file to read the graph from. + * @throws IOException if an error occurs while reading the file. */ - public BiolinguaDigraph(String fname) - throws IOException { + public BiolinguaDigraph(String fname) throws IOException { super(fname); } /** * Copy constructor. + * + * @param digraph the graph to copy. */ public BiolinguaDigraph(BiolinguaDigraph digraph) { this("Clone_of_[" + digraph + "]", digraph.nNodes); @@ -65,6 +72,8 @@ public BiolinguaDigraph(BiolinguaDigraph digraph) { /** * Returns a clone of this graph + * + * @return a clone of this graph */ public Object clone() { BiolinguaDigraph g2 = new BiolinguaDigraph( @@ -79,7 +88,10 @@ public Object clone() { } /** - * Returns true if node p is parent of node c.

    + * Returns true if node p is parent of node c. + * + * @param p the parent node + * @param c the child node */ public boolean isParent(int p, int c) { return (this.getEdges().getDoubleValue(p, c) != 0.0); @@ -87,6 +99,7 @@ public boolean isParent(int p, int c) { /** * Returns a string with the indexes of all parents of node i separated by spaces (useful for printouts) + * @param i the node whose parents are requested */ public String strOfParents(int i) { int[] ap = this.getParents(i); @@ -101,6 +114,8 @@ public String strOfParents(int i) { /** * Returns null (no lag information is stored in a BiolinguaDigraph). + * @param i the node whose parents are requested + * @return null (no lag information is stored in a BiolinguaDigraph). */ public int[] getLags(int i) { return null; @@ -109,6 +124,7 @@ public int[] getLags(int i) { /** * Returns a specially formatted string with all the contents of this Graph. Actually this string is compliant with * the same format expected when reading the graph from a file. + * @return a specially formatted string with all the contents of this Graph. */ public String toString() { String s = this.getClass().getName() + " " + this.graphName + "\n" + diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java index ba42a9dbc0..95e101dc01 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/BiolinguaRunner.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.SymMatrixF; /** - * Client of the Biolingua class, can be used to easily run the algorithm with different inputs.

    + *

    Client of the Biolingua class, can be used to easily run the algorithm with different inputs.

    * * @author Raul Saavedra, rsaavedr@ai.uwf.edu */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Digraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Digraph.java index 07c7ed1b5e..94fb87fa9f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Digraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/Digraph.java @@ -50,6 +50,9 @@ public class Digraph extends BasicGraph { /** * Creates a OldDigraph with gName name, and n nodes. + * + * @param gName the name of the graph + * @param nNodes the number of nodes */ public Digraph(String gName, int nNodes) { super(gName, nNodes); @@ -57,6 +60,8 @@ public Digraph(String gName, int nNodes) { /** * Creates a OldDigraph reading it from file fname. + * + * @param fname the name of the file to read the graph from. */ public Digraph(String fname) throws IOException { super(fname); @@ -90,6 +95,9 @@ public Object clone() { return g2; } + /** + * Initializes the edges matrix + */ protected void initializeEdges() { this.edges = new MatrixF("EdgeMatrix_" + this.graphName, this.nNodes); this.nParents = new int[this.nNodes]; @@ -97,6 +105,9 @@ protected void initializeEdges() { /** * Sets a value of edge between nodes i and j + * @param i the first node + * @param j the second node + * @param value the value of the edge */ public void setEdge(int i, int j, double value) { double e = this.getEdges().getDoubleValue(i, j); @@ -114,6 +125,8 @@ public void setEdge(int i, int j, double value) { /** * Returns the value of edge between nodes i and j + * @param i the first node + * @param j the second node */ public double getEdge(int i, int j) { return this.getEdges().getDoubleValue(i, j); @@ -121,6 +134,7 @@ public double getEdge(int i, int j) { /** * Returns a string representation of the set of edges in this graph + * @return a string representation of the set of edges in this graph. */ public String EdgesToString() { String s = ""; @@ -139,7 +153,9 @@ public String EdgesToString() { } /** - * Returns the number of parents of node i + * Returns the number of parents of node i. + * @param i the node + * @return the number of parents of node i. */ public int getNumParents(int i) { if ((i < 0) || (i >= this.getSize())) { @@ -151,6 +167,7 @@ public int getNumParents(int i) { /** * Returns an array with the indexes of the parents of node i. If node i has no parents it returns an array of size * 0 (e.g. not null) + * @param j the index of the node */ public int[] getParents(int j) { if ((j < 0) || (j >= this.nNodes)) { @@ -167,6 +184,10 @@ public int[] getParents(int j) { return ap; } + /** + * Returns the edge matrix. + * @return the edge matrix. + */ public MatrixF getEdges() { return this.edges; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java index 2e21a46062..d12dc2afe4 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/biolingua/LTester.java @@ -24,9 +24,7 @@ import edu.cmu.tetrad.study.gene.tetrad.gene.algorithm.util.*; /** - * Class that makes some very simple tests on the classes LtMatrix, Graph, and Biolingua

    - *

    - * TODO: make it a junit testing class + *

    Class that makes some very simple tests on the classes LtMatrix, Graph, and Biolingua

    * * @author Raul Saavedra, rsaavedr@ai.uwf.edu */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java index 8990fa4eb6..35dcae5c48 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/AbstractNbComponent.java @@ -25,6 +25,8 @@ /** + * Abstract NB component. + * * @author Frank Wimberly */ public abstract class AbstractNbComponent implements NbComponent { @@ -39,6 +41,14 @@ public abstract class AbstractNbComponent implements NbComponent { private double sd; + /** + * Constructs a new component with the given factor, power, parents, and + * @param factor the factor + * @param power the power + * @param parents the parents + * @param inhibitExcite the inhibit/excite + * @param name the namew + */ public AbstractNbComponent(double factor, double power, NbComponent[] parents, int[] inhibitExcite, String name) { setFactor(factor); @@ -67,6 +77,10 @@ public String getName() { return this.name; } + /** + * Sets the name. + * @param name the name. + */ public void setName(String name) { if (!NamingProtocol.isLegalName(name)) { throw new IllegalArgumentException( @@ -100,6 +114,9 @@ public void addParent(NbComponent component, int ie) { } } + /** + * Displays the parents. + */ public void displayParents() { for (int i = 0; i < getNparents(); i++) { System.out.println(getParents()[i].getName() + " " + @@ -107,52 +124,103 @@ public void displayParents() { } } + /** + * Updates. + */ public abstract void update(); + /** + * Returns the parents. + * @return These parents. + */ public NbComponent[] getParents() { return this.parents; } + /** + * Sets the parents. + * @param parents the parents. + */ public void setParents(NbComponent[] parents) { this.parents = parents; } + /** + * Returns the inhibit/excite. + * @return the inhibit/excite. + */ public int[] getInhibitExcite() { return this.inhibitExcite; } + /** + * Sets the inhibit/excite. + * @param inhibitExcite the inhibit/excite. + */ public void setInhibitExcite(int[] inhibitExcite) { this.inhibitExcite = inhibitExcite; } + /** + * Sets the number of parents. + * @return the number of parents. + */ public int getNparents() { return this.nparents; } + /** + * Sets the number of parents. + * @param nparents the number of parents. + */ public void setNparents(int nparents) { this.nparents = nparents; } + /** + * Returns the factor. + * @return the factor. + */ public double getFactor() { return this.factor; } + /** + * Sets the factor. + * @param factor the factor. + */ public void setFactor(double factor) { this.factor = factor; } + /** + * Returns the power. + * @return the power. + */ public double getPower() { return this.power; } + /** + * Sets the power. + * @param power the power. + */ public void setPower(double power) { this.power = power; } + /** + * Returns the standard deviation. + * @return the standard deviation. + */ public double getSd() { return this.sd; } + /** + * Sets the standard deviation. + * @param sd the standard deviation. + */ public void setSd(double sd) { this.sd = sd; } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbComponent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbComponent.java index 5288225485..ee7df5bc8d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbComponent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/urchin/NbComponent.java @@ -23,14 +23,36 @@ public interface NbComponent { + + /** + * Returns the parents of this component. + * @return the parents of this component. + */ double getValue(); + /** + * Sets the parents of this component. + * @param v the value + */ void setValue(double v); + /** + * Updates. + */ void update(); + /** + * Returns the parents of this component. + * + * @param c the component + * @param i the index + */ void addParent(NbComponent c, int i); + /** + * Returns the name. + * @return the name. + */ String getName(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicGraph.java index 72b0a71630..edf250e753 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicGraph.java @@ -52,11 +52,17 @@ public abstract class BasicGraph { */ protected int nEdges; + /** + * Default constructor + */ protected BasicGraph() { } /** * Creates a graph with gName name, and n nodes. + * + * @param gName name of the graph + * @param n number of nodes */ public BasicGraph(String gName, int n) { if (n <= 0) { @@ -87,6 +93,9 @@ public BasicGraph(String gName, int n) { * (and also slash-star) style comments anywhere in the file. Tokens can be separated by any number of blank * delimiters: tabs, spaces, carriage returns. Support of int, long, floating point, or doubles as edge values will * depend on how a subclass of Graph implement the set of edges. + * + * @param fname name of the file to read the graph from + * @throws IOException if there is a problem reading the file */ public BasicGraph(String fname) throws IOException { // Create and prepare stream tokenizer @@ -148,6 +157,8 @@ public BasicGraph(String fname) throws IOException { /** * Returns the name of the graph + * + * @return the name of the graph */ public String getGraphName() { return this.graphName; @@ -155,6 +166,8 @@ public String getGraphName() { /** * Sets the name of the graph + * + * @param newName the new name of the graph */ public void setGraphName(String newName) { this.graphName = newName; @@ -162,6 +175,8 @@ public void setGraphName(String newName) { /** * Returns the # nodes in this graph + * + * @return the # nodes in this graph */ public int getSize() { return this.nNodes; @@ -169,6 +184,9 @@ public int getSize() { /** * Sets the name of node i in this graph + * + * @param i the index of the node + * @param nodeName the new name of the node */ public void setNodeName(int i, String nodeName) { if ((i < 0) || (i > this.nNodes - 1)) { @@ -179,6 +197,9 @@ public void setNodeName(int i, String nodeName) { /** * Returns the name of node i in this graph + * + * @param i the index of the node + * @return the name of node i in this graph */ public String getNodeName(int i) { if ((i < 0) || (i > this.nNodes - 1)) { @@ -189,6 +210,8 @@ public String getNodeName(int i) { /** * Returns the Total # of edges in this graph + * + * @return the Total # of edges in this graph */ public int getNumEdges() { return this.nEdges; @@ -197,6 +220,8 @@ public int getNumEdges() { /** * Returns a specially formatted string with all the contents of this Graph. Actually this string is exactly the * same format expected when reading the graph from a file. + * + * @return a specially formatted string with all the contents of this Graph */ public String toString() { StringBuilder s = new StringBuilder(this.getClass().getName() + " " + this.graphName + "\n" + @@ -209,6 +234,11 @@ public String toString() { return s.toString(); } + /** + * Returns a specially formatted string with all the contents of the set of edges in this Graph. + * + * @param i the index of the node + */ protected void badNodeIndex(int i) { throw new IllegalArgumentException("Bad node index " + i + " for Graph with " + this.nNodes + " nodes"); @@ -216,6 +246,8 @@ protected void badNodeIndex(int i) { /** * Returns a clone of this graph + * + * @return a clone of this graph */ public abstract Object clone(); @@ -226,16 +258,25 @@ protected void badNodeIndex(int i) { /** * Sets a value of edge between nodes i and j + * + * @param i the index of the node + * @param j the index of the node + * @param value the value of the edge */ public abstract void setEdge(int i, int j, double value); /** * Returns the value of edge between nodes i and j + * + * @param i the index of the node + * @param j the index of the node + * @return the value of the edge */ public abstract double getEdge(int i, int j); /** * Returns a string representation of the set of edges in this graph + * @return a string representation of the set of edges in this graph */ public abstract String EdgesToString(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java index 428c471fc7..881679a935 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicLTMatrix.java @@ -34,6 +34,9 @@ public abstract class BasicLTMatrix extends BasicMatrix { /** * Creates a lower triangular matrix with nrows rows. + * + * @param mname the name of the matrix + * @param nrows the number of rows in the matrix */ public BasicLTMatrix(String mname, int nrows) { super(mname, nrows); @@ -50,6 +53,9 @@ public BasicLTMatrix(String mname, int nrows) { * number of blank delimiters: tabs, spaces, carriage returns. In the examples above they appear in different lines * for more readability of the file. The file may have less elements than the total needed to fill the matrix. If * it has more elements an illegal argument exception will be generated. + * + * @param fname the name of the file to read the matrix from + * @throws IOException if there is an error reading the file */ public BasicLTMatrix(String fname) throws IOException { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicMatrix.java index 1c7a19dc31..3b9a232711 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/BasicMatrix.java @@ -55,7 +55,15 @@ public abstract class BasicMatrix { * Minimum float value */ public static final float MIN_FLOAT = -BasicMatrix.MAX_FLOAT; + + /** + * Name of the matrix + */ protected String name; + + /** + * Number of rows ( == # columns) of this matrix + */ protected int n; /** @@ -67,6 +75,9 @@ protected BasicMatrix() { /** * Creates a matrix with nrows rows, and with name * mname. + * + * @param mname name of the matrix + * @param nrows number of rows in the matrix */ public BasicMatrix(String mname, int nrows) { this.name = mname; @@ -89,6 +100,9 @@ public BasicMatrix(String mname, int nrows) { * examples above they appear in different lines for more readability of the file. The file may have less elements * than the total needed to fill the matrix. If it has more elements an illegal argument exception will be * generated. + * + * @param fname name of the file to read the matrix from + * @throws IOException if there is an error reading the file */ public BasicMatrix(String fname) throws IOException { // Create and prepare stream tokenizer @@ -153,6 +167,8 @@ public BasicMatrix(String fname) throws IOException { /** * Returns # rows ( == # columns) of this matrix + * + * @return # rows ( == # columns) of this matrix */ public int getSize() { return this.n; @@ -160,6 +176,8 @@ public int getSize() { /** * Returns name of this matrix + * + * @return name of this matrix */ public String getName() { return this.name; @@ -167,6 +185,8 @@ public String getName() { /** * Sets the name of this matrix + * + * @param newName new name of this matrix */ public void setName(String newName) { this.name = newName; @@ -174,6 +194,8 @@ public void setName(String newName) { /** * Returns a specially formatted string with all the contents of this matrix + * + * @return a specially formatted string with all the contents of this matrix */ public String toString() { StringBuilder s = new StringBuilder(this.getClass().getName() + " " + this.name + "\n" + this.n + @@ -188,6 +210,12 @@ public String toString() { return s.toString(); } + /** + * Throws a bad index exception. + * + * @param r row index + * @param c column index + */ protected void badIndexXcp(int r, int c) { throw new IllegalArgumentException( "Bad index (" + r + "," + c + ") for matrix of size " + this.n); @@ -200,12 +228,20 @@ protected void badIndexXcp(int r, int c) { /** * Returns the value stored at element (r,c) as a double + * + * @param r row index + * @param c column index + * @return the value stored at element (r,c) as a double */ public abstract double getDoubleValue(int r, int c); /** * Assigns double value x in matrix element (r, c). Notice the presence of this method does not really force the * implementing class to actually store doubles. + * + * @param r row index + * @param c column index + * @param x value to be assigned to element (r,c) */ public abstract void setDoubleValue(int r, int c, double x); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java index fd7fffef5f..89ee0b6d19 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/algorithm/util/OutputGraph.java @@ -31,6 +31,7 @@ public interface OutputGraph { /** * Returns the number of variables over which the graph is defined. + * @return the number of variables over which the graph is defined. */ int getSize(); @@ -38,6 +39,7 @@ public interface OutputGraph { * Returns the indices of the parent variables for the given variable. * * @param index the index of the variable whose parents are requested. + * @return the indices of the parent variables for the given variable. */ int[] getParents(int index); @@ -49,16 +51,23 @@ public interface OutputGraph { * position in getParents(i), for i = 0,..., getParents(i).length. * * @param index the lags of the variable whose parents are requested. + * @return the lags of the parent variables for the given variable, provided parents have associated time lags; + * otherwise, returns null. */ int[] getLags(int index); /** * Returns the name of the variable at the given index. + * + * @param index the index of the variable whose name is requested. + * @return the name of the variable at the given index. */ String getNodeName(int index); /** * Returns the name of the graph + * + * @return the name of the graph */ String getGraphName(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ActiveLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ActiveLagGraph.java index 1e93493ba1..0bfd9f0700 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ActiveLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ActiveLagGraph.java @@ -46,7 +46,7 @@ * @author Gregory Li */ public class ActiveLagGraph implements LagGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Underlying graph representing the update graph. @@ -70,6 +70,8 @@ public ActiveLagGraph() { /** * Generates a simple exemplar of this class to test serialization. + * + * @return a simple exemplar of this class to test serialization. */ public static ActiveLagGraph serializableInstance() { return new ActiveLagGraph(); @@ -79,13 +81,17 @@ public static ActiveLagGraph serializableInstance() { /** * Registers a listener to events concerning the lag graph. + * + * @param l the listener */ public void addPropertyChangeListener(PropertyChangeListener l) { getPropertyChangeManager().addPropertyChangeListener(l); } - /* + /** * Unregisters a listener for events concerning the lag graph. + * + * @param l the listener */ public void removePropertyChangeListener(PropertyChangeListener l) { getPropertyChangeManager().removePropertyChangeListener(l); @@ -106,8 +112,7 @@ public void addEdge(String factor, LaggedFactor laggedFactor) { } this.lagGraph.addEdge(factor, laggedFactor); - getPropertyChangeManager().firePropertyChange("edgeAdded", null, - new LaggedEdge(factor, laggedFactor)); + getPropertyChangeManager().firePropertyChange("edgeAdded", null, new LaggedEdge(factor, laggedFactor)); } catch (Exception ignored) { } } @@ -118,16 +123,14 @@ public void addEdge(String factor, LaggedFactor laggedFactor) { */ public void addFactor(String factor) { if (!NamingProtocol.isLegalName(factor)) { - throw new IllegalArgumentException( - NamingProtocol.getProtocolDescription()); + throw new IllegalArgumentException(NamingProtocol.getProtocolDescription()); } // no exception is thrown if the factor is already in the graph if (!existsFactor(factor)) { try { this.lagGraph.addFactor(factor); - getPropertyChangeManager().firePropertyChange("nodeAdded", null, - factor); + getPropertyChangeManager().firePropertyChange("nodeAdded", null, factor); } catch (Exception ignored) { } } @@ -141,8 +144,7 @@ public void removeEdge(String factor, LaggedFactor laggedFactor) { if (existsEdge(factor, laggedFactor)) { try { this.lagGraph.removeEdge(factor, laggedFactor); - getPropertyChangeManager().firePropertyChange("edgeRemoved", - new LaggedEdge(factor, laggedFactor), null); + getPropertyChangeManager().firePropertyChange("edgeRemoved", new LaggedEdge(factor, laggedFactor), null); } catch (Exception e) { // Igore. } @@ -156,8 +158,7 @@ public void removeEdge(String factor, LaggedFactor laggedFactor) { public void removeFactor(String factor) { try { this.lagGraph.removeFactor(factor); - getPropertyChangeManager().firePropertyChange("nodeRemoved", factor, - null); + getPropertyChangeManager().firePropertyChange("nodeRemoved", factor, null); // search through and find edges which were sourced by this factor // and remove them @@ -191,8 +192,7 @@ public void removeFactor(String factor) { public void renameFactor(String oldName, String newName) { try { this.lagGraph.renameFactor(oldName, newName); - getPropertyChangeManager().firePropertyChange("factorRenamed", - oldName, newName); + getPropertyChangeManager().firePropertyChange("factorRenamed", oldName, newName); } catch (IllegalArgumentException e) { // ignore } @@ -234,8 +234,7 @@ public void setMaxLagAllowable(int maxLagAllowable) { if (maxLagAllowable >= getMaxLag()) { this.lagGraph.setMaxLagAllowable(maxLagAllowable); this.lagGraph.setMaxLagAllowable(maxLagAllowable); - getPropertyChangeManager().firePropertyChange("maxLagAllowable", - null, getMaxLagAllowable()); + getPropertyChangeManager().firePropertyChange("maxLagAllowable", null, getMaxLagAllowable()); } } @@ -279,8 +278,7 @@ public Map getLocations() { * class that didn't include it. (That's what the "s.defaultReadObject();" is for. See J. Bloch, Effective Java, for * help. */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException { + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); if (this.lagGraph == null) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/LagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/LagGraphParams.java index af90ee88d6..6c213a3fdf 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/LagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/LagGraphParams.java @@ -9,7 +9,7 @@ public class LagGraphParams { public static final int CONSTANT = 0; public static final int MAX = 1; public static final int MEAN = 2; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Parameters parameters; private int indegreeType; private int varsPerInd = 5; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualActiveLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualActiveLagGraph.java index 6e51dbb0db..b24b09b682 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualActiveLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualActiveLagGraph.java @@ -28,7 +28,7 @@ * Constructs as a (manual) update graph. */ public class ManualActiveLagGraph extends ActiveLagGraph implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private String name; //=========================CONSTRUCTORS===========================// diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraph.java index 15fbc1268d..391d8c7a27 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraph.java @@ -37,7 +37,7 @@ * Constructs as a (manual) update graph. */ public final class ManualLagGraph implements LagGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java index 326a6f0767..831e97ec79 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/ManualLagGraphParams.java @@ -32,7 +32,7 @@ * @author josephramsey */ public class ManualLagGraphParams implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The number of variables per individual. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java index c05a01f4ae..b99be73b87 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/RandomActiveLagGraph.java @@ -31,7 +31,7 @@ */ public class RandomActiveLagGraph extends ActiveLagGraph implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private String name; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java index 001b3c7143..4da8ec9e3c 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/graph/StoredLagGraphParams.java @@ -29,7 +29,7 @@ * @author josephramsey */ public class StoredLagGraphParams implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The filename of the stored lag graph. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java index c6b0258eb0..730cd11b7c 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasalInitializer.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class BasalInitializer implements Initializer { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The update function this is initializing for. @@ -65,6 +65,11 @@ public class BasalInitializer implements Initializer { /** * Constructs a new history that will initialize genes using the given basal expression and initial standard * deviation. + * + * @param updateFunction the update function this is initializing for. + * @param basalExpression the average expression level that all unregulated genes are initialized to. + * @param initStDev the standard deviation of a normal distribution N(basalExpression, sem.D.) that random + * initial values for unregulated genes are set to. */ public BasalInitializer(UpdateFunction updateFunction, double basalExpression, double initStDev) { @@ -85,6 +90,7 @@ public BasalInitializer(UpdateFunction updateFunction, /** * Generates a simple exemplar of this class to test serialization. + * @return a simple exemplar of this class to test serialization. */ public static BasalInitializer serializableInstance() { return new BasalInitializer(BooleanGlassFunction.serializableInstance(), diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java index 44150c7caa..c25a56bad3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BasicLagGraph.java @@ -42,7 +42,7 @@ * @author josephramsey */ public final class BasicLagGraph implements LagGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * For each factor, stores the set of lagged factors which map into it. (Maps Strings to SortedSets of Strings.) @@ -77,6 +77,8 @@ public BasicLagGraph() { /** * Constructs a copy of the given lag graph. + * + * @param lagGraph the lag graph to copy. */ public BasicLagGraph(LagGraph lagGraph) { this.connectivity = lagGraph.getConnectivity(); @@ -85,6 +87,7 @@ public BasicLagGraph(LagGraph lagGraph) { /** * Generates a simple exemplar of this class to test serialization. + * @return a simple exemplar of this class to test serialization. */ public static BasicLagGraph serializableInstance() { BasicLagGraph lagGraph = new BasicLagGraph(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java index 655ffb6998..1c2db5b9e2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanFunction.java @@ -33,7 +33,7 @@ * @author josephramsey */ public class BooleanFunction implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The array of parents for the stored boolean function. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java index c7b17ecfd5..562dcfa3d1 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/BooleanGlassFunction.java @@ -56,7 +56,7 @@ * @author josephramsey */ public class BooleanGlassFunction implements UpdateFunction { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The indexed connectivity "snapshot" of the lag graph. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java index d230f41f49..932b9897b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/DishModel.java @@ -37,7 +37,7 @@ * @author josephramsey */ public class DishModel implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * An array of dish bumps for each dish. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java index 39a7cf8e45..931bee09fb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/GeneHistory.java @@ -32,7 +32,7 @@ * @author josephramsey */ public class GeneHistory implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The initializer for the history. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java index 005967863f..b76c1a95e3 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedConnectivity.java @@ -38,7 +38,7 @@ * @author josephramsey */ public class IndexedConnectivity implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The factors in the graph, in the order that they are used. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java index c7b6624bdd..bb21af3b2e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedLagGraph.java @@ -38,7 +38,7 @@ * @author josephramsey */ public class IndexedLagGraph implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The factors in the graph, in the order that they are used. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java index cae5d152cd..ba852a20e8 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/IndexedParent.java @@ -33,7 +33,7 @@ * @author josephramsey */ public final class IndexedParent implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The index of the parent. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Initializer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Initializer.java index 5ff2c68fa7..bf1ccd1169 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Initializer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Initializer.java @@ -31,6 +31,7 @@ public interface Initializer extends TetradSerializable { /** * Initializes a history array. + * @param historyArray the history array to initialize. */ void initialize(double[][] historyArray); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java index 7f071a13ff..e5d8b63592 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LagGraph.java @@ -29,6 +29,8 @@ import java.util.SortedSet; /** + * Lag graph. + * * @author josephramsey */ public interface LagGraph extends TetradSerializable { @@ -90,12 +92,15 @@ void addEdge(String factor, LaggedFactor laggedFactor) /** * Gets the maximum allowable lag. Edges may not be added with lags greated than this. + * @return the maximum allowable lag. */ int getMaxLagAllowable(); /** * Sets the maximum allowable lag. Edges may not be added with lags greater than this. This value must be >= the * getModel value of getMaxLag(). + * + * @param maxLagAllowable the maximum allowable lag. */ void setMaxLagAllowable(int maxLagAllowable); @@ -129,6 +134,9 @@ void addEdge(String factor, LaggedFactor laggedFactor) /** * Renames a factor, changing all occurances of the old name to the new one + * + * @param oldName the old name + * @param newName the new name */ void renameFactor(String oldName, String newName); @@ -153,12 +161,31 @@ void addEdge(String factor, LaggedFactor laggedFactor) */ String toString(); + /** + * Returns a string representation of the graph, indicating for each factor which lagged factors map into it. + * @param base the base name of the factors. + * @param numFactors the number of factors. + */ void addFactors(String base, int numFactors); + /** + * Sets the location. + * @param factor the factor. + * @param point the point. + */ void setLocation(String factor, PointXy point); + /** + * Gets the location. + * @param factor the factor. + * @return the location. + */ PointXy getLocation(String factor); + /** + * Gets the locations. + * @return the locations. + */ Map getLocations(); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedEdge.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedEdge.java index 65e0672969..585134cd20 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedEdge.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedEdge.java @@ -32,7 +32,7 @@ * @author gmli */ public class LaggedEdge implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java index e5f51777bb..88ace84324 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LaggedFactor.java @@ -32,7 +32,7 @@ * @author josephramsey */ public class LaggedFactor implements Comparable, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The number of time steps back for the lagged factor. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java index 8f8a807fb7..12e703ef21 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/LinearFunction.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class LinearFunction implements UpdateFunction { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The wrapped polynomial function that's doing all the work. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java index 2858a0870f..533cf3c21a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/Polynomial.java @@ -35,7 +35,7 @@ * @author josephramsey */ public final class Polynomial implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The terms of the polynomial. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java index d3d22b9595..d7ef0510b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialFunction.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class PolynomialFunction implements UpdateFunction { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The "snapshot" indexed connectivity of the initial lag graph. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java index 0cabdb1ac1..526c2352b7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/PolynomialTerm.java @@ -38,7 +38,7 @@ * @author josephramsey */ public class PolynomialTerm implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The variables of the term. * diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java index 0179885ca9..4978306a50 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/history/SimpleRandomizer.java @@ -52,7 +52,7 @@ public class SimpleRandomizer implements GraphInitializer { * Indicates mean indegree. */ public static final int MEAN = 2; - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The indegree type of this randomizer. */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java index 3d7a2bc3e2..4783f8eadf 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetrad/gene/simulation/MeasurementSimulator.java @@ -53,7 +53,7 @@ * @see TestMeasurementSimulator */ public class MeasurementSimulator implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final Parameters parameters; private final int numDishes = 1; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java index b0ce1f4b78..967cc89729 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGeneIm.java @@ -42,7 +42,7 @@ * @author josephramsey */ public class BooleanGlassGeneIm implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java index 5181930a79..8c40e17f8d 100755 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/BooleanGlassGenePm.java @@ -32,7 +32,7 @@ * @author josephramsey */ public class BooleanGlassGenePm extends GenePm implements SessionModel { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Can be null.n diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java index cea22d0ef4..2890c30944 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/GenePm.java @@ -33,7 +33,7 @@ * @author josephramsey */ public abstract class GenePm implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The wrapped lag workbench. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java index 83e324c6e1..e4d4d8222a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/gene/tetradapp/model/MeasurementSimulatorParams.java @@ -37,7 +37,7 @@ * @author josephramsey */ public class MeasurementSimulatorParams implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial Cannot be null. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java index 603a176c2a..96c6b80e5d 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison.java @@ -21,8 +21,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Does a comparison of algorithm results across algorithm type, sample sizes, etc. * @@ -189,34 +187,38 @@ public static ComparisonResult compare(ComparisonParameters params) { if (test == null) throw new IllegalArgumentException("Test not set."); Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { if (test == null) throw new IllegalArgumentException("Test not set."); Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) throw new IllegalArgumentException("Score not set."); Fges search = new Fges(score); search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES2) { if (score == null) throw new IllegalArgumentException("Score not set."); Fges search = new Fges(score); search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { if (test == null) throw new IllegalArgumentException("Test not set."); Fci search = new Fci(test); result.setResultGraph(search.search()); - result.setCorrectResult(dagToPag(trueDag)); + result.setCorrectResult(GraphTransforms.dagToPag(trueDag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.GFCI) { if (test == null) throw new IllegalArgumentException("Test not set."); GFci search = new GFci(test, score); result.setResultGraph(search.search()); - result.setCorrectResult(dagToPag(trueDag)); + result.setCorrectResult(GraphTransforms.dagToPag(trueDag)); } else { throw new IllegalArgumentException("Unrecognized algorithm."); } diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java index bed177f1f3..6d1d165f0e 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/Comparison2.java @@ -35,8 +35,6 @@ import java.util.Collections; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Does a comparison of algorithm results across algorithm type, sample sizes, etc. * @@ -142,24 +140,27 @@ public static ComparisonResult compare(ComparisonParameters params) { if (params.getAlgorithm() == ComparisonParameters.Algorithm.PC) { Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { Fges search = new Fges(score); //search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { Fci search = new Fci(test); result.setResultGraph(search.search()); - result.setCorrectResult(dagToPag(trueDag)); + result.setCorrectResult(GraphTransforms.dagToPag(trueDag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.GFCI) { GFci search = new GFci(test, score); result.setResultGraph(search.search()); - result.setCorrectResult(dagToPag(trueDag)); + result.setCorrectResult(GraphTransforms.dagToPag(trueDag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.SVARFCI) { SvarFci search = new SvarFci(test); Knowledge knowledge = getKnowledge(trueDag); @@ -377,14 +378,16 @@ public static ComparisonResult compare(ComparisonParameters params) { } Pc search = new Pc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.CPC) { if (test == null) { throw new IllegalArgumentException("Test not set."); } Cpc search = new Cpc(test); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FGES) { if (score == null) { throw new IllegalArgumentException("Score not set."); @@ -392,21 +395,22 @@ public static ComparisonResult compare(ComparisonParameters params) { Fges search = new Fges(score); //search.setFaithfulnessAssumed(params.isOneEdgeFaithfulnessAssumed()); result.setResultGraph(search.search()); - result.setCorrectResult(GraphSearchUtils.cpdagForDag(new EdgeListGraph(trueDag))); + Graph dag = new EdgeListGraph(trueDag); + result.setCorrectResult(GraphTransforms.cpdagForDag(dag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.FCI) { if (test == null) { throw new IllegalArgumentException("Test not set."); } Fci search = new Fci(test); result.setResultGraph(search.search()); - result.setCorrectResult(dagToPag(trueDag)); + result.setCorrectResult(GraphTransforms.dagToPag(trueDag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.GFCI) { if (test == null) { throw new IllegalArgumentException("Test not set."); } GFci search = new GFci(test, score); result.setResultGraph(search.search()); - result.setCorrectResult(dagToPag(trueDag)); + result.setCorrectResult(GraphTransforms.dagToPag(trueDag)); } else if (params.getAlgorithm() == ComparisonParameters.Algorithm.SVARFCI) { if (test == null) { throw new IllegalArgumentException("Test not set."); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java index 723eef0de9..2436b4d2d5 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTests.java @@ -45,8 +45,6 @@ import java.text.NumberFormat; import java.util.*; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Runs some basic performance tests of various algorithm. * @@ -290,7 +288,7 @@ public void testPc(int numVars, double edgeFactor, int numCases, double alpha) { this.out.println("Total elapsed (cov + PC-Stable) " + (time4 - time2) + " ms"); - GraphSearchUtils.graphComparison(GraphSearchUtils.cpdagForDag(graph), outGraph, this.out); + GraphSearchUtils.graphComparison(GraphTransforms.cpdagForDag(graph), outGraph, this.out); this.out.close(); } @@ -401,7 +399,7 @@ public void testPcStable(int numVars, double edgeFactor, int numCases, double al this.out.println("Total elapsed (cov + PC-Stable) " + (time4 - time2) + " ms"); - Graph trueCPDAG = GraphSearchUtils.cpdagForDag(dag); + Graph trueCPDAG = GraphTransforms.cpdagForDag(dag); System.out.println("# edges in true CPDAG = " + trueCPDAG.getNumEdges()); System.out.println("# edges in est CPDAG = " + estCPDAG.getNumEdges()); @@ -464,7 +462,7 @@ public void testFges(int numVars, double edgeFactor, int numCases, double penalt this.out.println("Total elapsed (cov + FGES) " + (time4 - time2) + " ms"); - Graph trueCPDAG = GraphSearchUtils.cpdagForDag(dag); + Graph trueCPDAG = GraphTransforms.cpdagForDag(dag); System.out.println("# edges in true CPDAG = " + trueCPDAG.getNumEdges()); System.out.println("# edges in est CPDAG = " + estCPDAG.getNumEdges()); @@ -552,7 +550,7 @@ public void testCpc(int numVars, double edgeFactor, int numCases) { this.out.println("Total elapsed (cov + PC-Stable) " + (time4 - time2) + " ms"); - GraphSearchUtils.graphComparison(GraphSearchUtils.cpdagForDag(graph), outGraph, this.out); + GraphSearchUtils.graphComparison(GraphTransforms.cpdagForDag(graph), outGraph, this.out); this.out.close(); } @@ -623,7 +621,7 @@ public void testCpcStable(int numVars, double edgeFactor, int numCases, double a this.out.println("Total elapsed (cov + CPC-Stable) " + (time4 - time2) + " ms"); - Graph trueCPDAG = GraphSearchUtils.cpdagForDag(graph); + Graph trueCPDAG = GraphTransforms.cpdagForDag(graph); GraphSearchUtils.graphComparison(trueCPDAG, outGraph, this.out); @@ -751,7 +749,7 @@ public void testGfci(int numVars, double edgeFactor) { DataSet data = simulator.simulateDataFisher(numCases); - data = DataUtils.restrictToMeasured(data); + data = DataTransforms.restrictToMeasured(data); System.out.println("Finishing simulation"); @@ -787,7 +785,7 @@ public void testGfci(int numVars, double edgeFactor) { this.out.println(outGraph); - System.out.println(MisclassificationUtils.edgeMisclassifications(outGraph, dagToPag(dag))); + System.out.println(MisclassificationUtils.edgeMisclassifications(outGraph, GraphTransforms.dagToPag(dag))); long time4 = MillisecondTimes.timeMillis(); @@ -861,7 +859,7 @@ private void testFges(int numVars, double edgeFactor, int numCases, int numRuns, System.out.println("Calculating CPDAG for DAG"); - Graph CPDAG = GraphSearchUtils.cpdagForDag(dag); + Graph CPDAG = GraphTransforms.cpdagForDag(dag); List vars = dag.getNodes(); @@ -1065,7 +1063,7 @@ private void testFgesMb(int numVars, double edgeFactor, int numCases, int numRun System.out.println("Calculating CPDAG for DAG"); - Graph CPDAG = GraphSearchUtils.cpdagForDag(dag); + Graph CPDAG = GraphTransforms.cpdagForDag(dag); int[] tiers = new int[dag.getNumNodes()]; @@ -1353,7 +1351,7 @@ public void testGFciComparison() { // dagToPag.setMaxPathLength(maxPathLength); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); System.out.println("True PAG_of_the_true_DAG done"); @@ -1366,7 +1364,7 @@ public void testGFciComparison() { DataSet data = simulator.simulateDataFisher(numCases); - data = DataUtils.restrictToMeasured(data); + data = DataTransforms.restrictToMeasured(data); System.out.println("Finishing simulation"); @@ -1484,7 +1482,7 @@ public void testCompareDagToCPDAG(int numLatents) { System.out.println("PC graph = " + left); - Graph top = GraphSearchUtils.cpdagForDag(dag); + Graph top = GraphTransforms.cpdagForDag(dag); System.out.println("DAG to CPDAG graph = " + top); @@ -1534,7 +1532,7 @@ public void testComparePcVersions(int numVars, double edgeFactor, int numLatents System.out.println("Graph done"); - Graph left = GraphSearchUtils.cpdagForDag(dag);// pc1.search(); + Graph left = GraphTransforms.cpdagForDag(dag);// pc1.search(); System.out.println("First FAS graph = " + left); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java index 72cf3d962f..fba5fce14a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/study/performance/PerformanceTestsDan.java @@ -21,10 +21,7 @@ package edu.cmu.tetrad.study.performance; -import edu.cmu.tetrad.data.CovarianceMatrix; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.ICovarianceMatrix; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.GFci; import edu.cmu.tetrad.search.Pc; @@ -41,8 +38,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; - /** * Contains some tests for Dan Malinsky, that might be of interest to others. * @@ -173,7 +168,7 @@ private void testIdaOutputForDan() { DataSet fullData = im.simulateData(numCases, false); - DataSet data = DataUtils.restrictToMeasured(fullData); + DataSet data = DataTransforms.restrictToMeasured(fullData); ICovarianceMatrix cov = new CovarianceMatrix(data); @@ -211,7 +206,7 @@ private void testIdaOutputForDan() { out10.println(data); out11.println("True PAG_of_the_true_DAG"); - Graph truePag = dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); out11.println(truePag); printDanMatrix(_vars, truePag, out12); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/AlgorithmDescriptions.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/AlgorithmDescriptions.java index 7d67562a0f..46fde7a468 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/AlgorithmDescriptions.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/AlgorithmDescriptions.java @@ -33,6 +33,8 @@ import java.util.stream.Collectors; /** + * Algorithm descriptions. + * * @author Zhou Yuan zhy19@pitt.edu * @author Kevin V. Bui (kvb2@pitt.edu) */ @@ -62,10 +64,19 @@ private AlgorithmDescriptions() { } } + /** + * Gets the instance of this class. + * @return instance of this class + */ public static AlgorithmDescriptions getInstance() { return AlgorithmDescriptions.INSTANCE; } + /** + * Gets the description of the algorithm. + * @param shortName short name of the algorithm + * @return description of the algorithm + */ public String get(String shortName) { String description = this.descriptions.get(shortName); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/DefaultTetradLoggerConfig.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/DefaultTetradLoggerConfig.java index 46145b4cde..a4e772a3c2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/DefaultTetradLoggerConfig.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/DefaultTetradLoggerConfig.java @@ -31,7 +31,7 @@ */ public class DefaultTetradLoggerConfig implements TetradLoggerConfig { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The events that are supported. @@ -136,7 +136,7 @@ private boolean contains(String id) { //================================= Inner class ==================================// public static class DefaultEvent implements TetradLoggerConfig.Event { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String id; private final String description; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java index 2b5fa38ca9..7360bcf912 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/IndexedMatrix.java @@ -23,6 +23,8 @@ /** + * Indexed matrix. + * * @author josephramsey Returns values of the given square matrix, where the indices are remapped via the given indices * array. If the supplied matrix is 6 x 6, for example, and the indices set are [5 4 2 1], then getValue(1, 2) will * return element [4][2] of the given matrix. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java index d3dc2ec792..f3968e8691 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class Matrix implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RealMatrix apacheData; private int m, n; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix2.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix2.java index 2f1b1cf1b7..34b4913007 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix2.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Matrix2.java @@ -36,7 +36,7 @@ * @author josephramsey */ public class Matrix2 implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RealMatrix apacheData; private int m, n; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java index f91606ab2d..24928448ba 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Parameters.java @@ -11,7 +11,7 @@ */ public class Parameters implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private Map parameters = new LinkedHashMap<>(); private Set usedParameters = new LinkedHashSet<>(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java index b7ef509894..9a5aea4b30 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PartialCorrelationPdf.java @@ -32,7 +32,7 @@ * @author josephramsey */ public class PartialCorrelationPdf implements Function, TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Number of data points in the sample. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java index e2bbfb75c8..a0f1b077fa 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/PointXy.java @@ -28,7 +28,7 @@ * @author josephramsey */ public class PointXy implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The x coordinate. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ProbUtils.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ProbUtils.java index 2170976ee5..2e3d7f8a45 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ProbUtils.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/ProbUtils.java @@ -1689,13 +1689,13 @@ public static double fRand(double ndf, double ddf) { } /** - * Bivariate normal CDF. Adapted from statlib, file general/gaut.c, by Ajay Shah. Adaptation for Java found in - * http://www.geocities.com/optionpage/utility.html --November 1st 2003, Ricardo Silva + * Bivariate normal CDF. Adapted from statlib, file general/gaut.c, by Ajay Shah. Adaptation for Java found + * here --November 1st 2003, Ricardo Silva * * @param ah upper bound 1 * @param ak upper bound 1 - * @param r correlation - * @return Prob(x1 & le ; ah, x2 & le ; ak) + * @param r correlatiohn + * @return Prob(x1 & le ; ah, x2 & le ; ak) */ public static double biNormalCdf(double ah, double ak, double r) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java index 7403d856a1..a7bbd2ed41 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradLogger.java @@ -619,7 +619,7 @@ public interface LogDisplayOutputStream { * A empty config, where no event is active. */ public static class EmptyConfig implements TetradLoggerConfig { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final boolean active; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java index ae729465c7..76cf00c4f2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/TetradSerializable.java @@ -40,8 +40,8 @@ * instance, binary serialization will load it in well under a second, whereas XML parsers that I've checked don't come * back in under 5 minutes.> 0

    The test class that checks the above conditions are TestSerialization, which in * turn uses methods in TetradSerializableUtils. More details can be find there.> 0 - *

    - *

    See TestSerialization and TestSerializiableUtils.> 0 + *

    + *

    See TestSerialization and TestSerializiableUtils.> 0

    * * @author josephramsey */ diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java index 89168e20b5..d2e5fd60a6 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Vector.java @@ -28,7 +28,7 @@ * Vector wrapping matrix library. */ public class Vector implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RealVector data; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java index 70cf705cb7..0ab2da56b2 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/Version.java @@ -35,7 +35,7 @@ */ @SuppressWarnings("RedundantIfStatement") public class Version implements TetradSerializable { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The major version number. In release a.b.c-d, a. At time of creating this class, it's 4, and the minor version is diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java index 8f75401bc7..2616863ea7 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Beta.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class Beta implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * Ibid. @@ -52,13 +52,17 @@ private Beta() { /** * Generates a simple exemplar of this class to test serialization. + * + * @return Ibid. */ public static Beta serializableInstance() { return new Beta(); } /** - * See interface. + * Returns the next random. + * + * @return Ibid. */ public double nextRandom() { return RandomUtil.getInstance().nextBeta(this.alpha, this.beta); @@ -66,6 +70,9 @@ public double nextRandom() { /** * The order of parameters is alpha = 0, beta = 1. + * + * @param index the index of the parameter. + * @param value the value. */ public void setParameter(int index, double value) { if (index == 0) { @@ -79,6 +86,7 @@ public void setParameter(int index, double value) { /** * The order of parameters is alpha = 0, beta = 1. + * @param index the index. */ public double getParameter(int index) { if (index == 0) { @@ -92,6 +100,7 @@ public double getParameter(int index) { /** * The order of parameters is alpha = 0, beta = 1. + * @param index the index. */ public String getParameterName(int index) { if (index == 0) { diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java index 8433c7ae55..2654893d12 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/ChiSquare.java @@ -33,7 +33,7 @@ * @author josephramsey */ public class ChiSquare implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The stored degees of freedom. Needed because the wrapped distribution does not provide getters for its diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java index bacb830f84..4610bb503b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Discrete.java @@ -33,7 +33,7 @@ * @author josephramsey */ public class Discrete implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double[] p; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java index d6d89a472a..fe118f4e85 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Distribution.java @@ -35,12 +35,14 @@ public interface Distribution extends TetradSerializable { long serialVersionUID = 23L; /** - * @return Ibid. + * Returns the number of parameters in the distribution. + * @return the number of parameters. */ int getNumParameters(); /** - * @return Ibid. + * Returns the name of the distribution. + * @return the name. */ String getName(); @@ -53,6 +55,7 @@ public interface Distribution extends TetradSerializable { void setParameter(int index, double value); /** + * Returns the index'th parameter. * @param index Ibid. Muist be <= 0 and < # parameters. * @return The Ibid. */ @@ -67,6 +70,7 @@ public interface Distribution extends TetradSerializable { String getParameterName(int index); /** + * Returns the next random number from the distribution. * @return Ibid. */ double nextRandom(); diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java index daed46c3dd..33a7c67aef 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Exponential.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class Exponential implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double lambda; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java index 9341be9d3e..b41fb75be4 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Gamma.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class Gamma implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double alpha; private double lambda; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/GaussianPower.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/GaussianPower.java index b985b08a04..e1cf11c434 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/GaussianPower.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/GaussianPower.java @@ -24,7 +24,7 @@ import edu.cmu.tetrad.util.RandomUtil; public class GaussianPower implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final double sd; private final String name; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Indicator.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Indicator.java index dca818fec6..cbda690716 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Indicator.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Indicator.java @@ -28,7 +28,7 @@ * Settings | File Templates. */ public class Indicator implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double p; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java index 0a33df5b9f..a497f376d9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/LogNormal.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class LogNormal implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double sd; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java index 14af08c4cf..74f25ab94f 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/MixtureOfGaussians.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class MixtureOfGaussians implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double a; private double mean1; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java index 25c2c25647..1f49d443eb 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Normal.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class Normal implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The mean of the distribution. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java index 5e9eb06c8f..6b48968182 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Poisson.java @@ -30,7 +30,7 @@ * @author josephramsey */ public class Poisson implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private double mean; diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java index 0ad9c505e6..a6092b557b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/SingleValue.java @@ -27,7 +27,7 @@ * @author josephramsey */ public class SingleValue implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java index 61cb239505..f995671459 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Split.java @@ -36,7 +36,7 @@ */ @SuppressWarnings("WeakerAccess") public class Split implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * @serial diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java index a60492ec25..287b6908e9 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/TruncatedNormal.java @@ -35,7 +35,7 @@ * @author josephramsey */ public class TruncatedNormal implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The mean of the distribution. diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java index 7c65b5560c..616a90a79a 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/util/dist/Uniform.java @@ -34,7 +34,7 @@ * @author josephramsey */ public class Uniform implements Distribution { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; /** * The lower bound of the range from which numbers are drawn uniformly. diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ConvexProximal.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ConvexProximal.java index 2ceae38138..9528f752ad 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ConvexProximal.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ConvexProximal.java @@ -28,9 +28,8 @@ * h(x) where g(x) is a differentiable convex function (i.e. smooth) and h(x) is a convex but not necessarily * differentiable (i.e. non-smooth) and has a proximal operator prox_t(x) = argmin_z 1/(2t) norm2(x-z)^2 + h(z) has a * solution for any t > 0. Typically g(x) will be a likelihood, and h(x) is a penalty term (as in l_1 in the lasso) - *

    - *

    - * Created by ajsedgewick on 8/4/15. + * + * @author asedgewick 8/4/15 */ public abstract class ConvexProximal { diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java index 0578795160..287c130d5b 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/ExploreIndepTests.java @@ -24,8 +24,8 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphSaveLoadUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.search.Pc; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.search.work_in_progress.IndTestMultinomialLogisticRegression; import edu.cmu.tetrad.util.MillisecondTimes; @@ -38,7 +38,8 @@ public class ExploreIndepTests { public static void main(String[] args) { try { String path = ExampleMixedSearch.class.getResource("test_data").getPath(); - Graph trueGraph = GraphSearchUtils.cpdagFromDag(GraphSaveLoadUtils.loadGraphTxt(new File(path, "DAG_0_graph.txt"))); + Graph dag3 = GraphSaveLoadUtils.loadGraphTxt(new File(path, "DAG_0_graph.txt")); + Graph trueGraph = GraphTransforms.cpdagForDag(dag3); DataSet ds = MixedUtils.loadDataSet(path, "DAG_0_data.txt"); IndTestMultinomialLogisticRegression indMix = new IndTestMultinomialLogisticRegression(ds, .05); @@ -54,15 +55,18 @@ public static void main(String[] args) { s3.setStable(true); long time = MillisecondTimes.timeMillis(); - Graph g1 = GraphSearchUtils.cpdagFromDag(s1.search()); + Graph dag2 = s1.search(); + Graph g1 = GraphTransforms.cpdagForDag(dag2); System.out.println("Mix Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); time = MillisecondTimes.timeMillis(); - Graph g2 = GraphSearchUtils.cpdagFromDag(s2.search()); + Graph dag1 = s2.search(); + Graph g2 = GraphTransforms.cpdagForDag(dag1); System.out.println("Wald lin Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); time = MillisecondTimes.timeMillis(); - Graph g3 = GraphSearchUtils.cpdagFromDag(s3.search()); + Graph dag = s3.search(); + Graph g3 = GraphTransforms.cpdagForDag(dag); System.out.println("Wald log Time " + ((MillisecondTimes.timeMillis() - time) / 1000.0)); System.out.println(MixedUtils.EdgeStatHeader); diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java index c2ff537e68..5b0844c36d 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/IndTestMultinomialLogisticRegressionWald.java @@ -244,6 +244,11 @@ private IndependenceResult isIndependentMultinomialLogisticRegression(Node x, No independent = p > this.alpha; + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + this.lastP = p; if (this.verbose) { @@ -332,6 +337,12 @@ private IndependenceResult isIndependentRegression(Node x, Node y, Set z) p = val; } } + + if (Double.isNaN(p)) { + throw new RuntimeException("Undefined p-value encountered when testing " + + LogUtilsSearch.independenceFact(x, y, z)); + } + this.lastP = p; boolean independent = p > this.alpha; diff --git a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java index e2d3d69c1c..08697a7323 100644 --- a/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java +++ b/tetrad-lib/src/main/java/edu/pitt/csb/mgm/MixedUtils.java @@ -790,13 +790,13 @@ public static String stringFrom2dArray(int[][] arr) { public static DataSet loadDataSet(String dir, String filename) throws IOException { File file = new File(dir, filename); return SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); } public static DataSet loadDelim(String dir, String filename) throws IOException { File file = new File(dir, filename); return SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", false, Delimiter.TAB); + "*", false, Delimiter.TAB, false); } //Gives a map of number of categories of DiscreteVariables in g. ContinuousVariables are mapped to 0 @@ -815,7 +815,7 @@ public static Map getNodeDists(Graph g) { public static DataSet loadData(String dir, String filename) throws IOException { File file = new File(dir, filename); return SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); } /** diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInference.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInference.java index 96b0e8dd69..937009d1b6 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInference.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInference.java @@ -43,6 +43,14 @@ public class BayesianConstraintInference { private static File casFile; /** + * Constructor. + */ + public BayesianConstraintInference() { + + } + + /** + * Main method. * @param args the command line arguments */ public static void main(String[] args) { diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInferenceTest.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInferenceTest.java index 2a75651b3e..dbd9f81274 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInferenceTest.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/inference/BayesianConstraintInferenceTest.java @@ -28,9 +28,16 @@ */ public class BayesianConstraintInferenceTest { + /** + * Constructor. + */ public BayesianConstraintInferenceTest() { } + /** + * Main method. + * @param args the command line arguments + */ public static void main(String[] args) { new BayesianConstraintInferenceTest().testMain(); } diff --git a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java index c24ea4dd67..534b63a0bc 100644 --- a/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java +++ b/tetrad-lib/src/main/java/edu/pitt/dbmi/algo/bayesian/constraint/search/RfciBsc.java @@ -13,7 +13,6 @@ import edu.cmu.tetrad.search.Rfci; import edu.cmu.tetrad.search.score.BdeuScore; import edu.cmu.tetrad.search.test.IndTestProbabilistic; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.TetradLogger; import edu.pitt.dbmi.algo.bayesian.constraint.inference.BCInference; @@ -342,7 +341,7 @@ class BootstrapDepDataTask implements Callable { public BootstrapDepDataTask(int row_index, int rows) { this.row_index = row_index; - DataSet bsData = DataUtils.getBootstrapSample(dataSet, rows); + DataSet bsData = DataTransforms.getBootstrapSample(dataSet, rows); this.bsTest = new IndTestProbabilistic(bsData); this.bsTest.setThreshold(RfciBsc.this.thresholdNoRandomConstrainSearch); if (RfciBsc.this.thresholdNoRandomConstrainSearch) { @@ -400,7 +399,7 @@ public Boolean call() throws Exception { Graph depPattern = fges.search(); depPattern = GraphUtils.replaceNodes(depPattern, depData.getVariables()); - Graph estDepBN = GraphSearchUtils.dagFromCPDAG(depPattern); + Graph estDepBN = GraphTransforms.dagFromCPDAG(depPattern, null); if (this.verbose) { this.out.println("estDepBN:"); 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 49d67df8ed..ec22cd56a9 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 @@ -3,10 +3,7 @@ import edu.cmu.tetrad.algcomparison.algorithm.Algorithm; import edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; -import edu.cmu.tetrad.data.DataModel; -import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; -import edu.cmu.tetrad.data.Knowledge; +import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -157,13 +154,21 @@ public List search() { DataSet dataSet; if (this.resamplingWithReplacement) { - dataSet = (randomGenerator == null) - ? DataUtils.getBootstrapSample(data, (int) (data.getNumRows() * this.percentResampleSize / 100.0)) - : DataUtils.getBootstrapSample(data, (int) (data.getNumRows() * this.percentResampleSize / 100.0), randomGenerator); + if ((randomGenerator == null)) { + int sampleSize = (int) (data.getNumRows() * this.percentResampleSize / 100.0); + dataSet = DataTransforms.getBootstrapSample(data, sampleSize); + } else { + int sampleSize = (int) (data.getNumRows() * this.percentResampleSize / 100.0); + dataSet = DataTransforms.getBootstrapSample(data, sampleSize, randomGenerator); + } } else { - dataSet = (randomGenerator == null) - ? DataUtils.getResamplingDataset(data, (int) (data.getNumRows() * this.percentResampleSize / 100.0)) - : DataUtils.getResamplingDataset(data, (int) (data.getNumRows() * this.percentResampleSize / 100.0), randomGenerator); + if ((randomGenerator == null)) { + int sampleSize = (int) (data.getNumRows() * this.percentResampleSize / 100.0); + dataSet = DataTransforms.getResamplingDataset(data, sampleSize); + } else { + int sampleSize = (int) (data.getNumRows() * this.percentResampleSize / 100.0); + dataSet = DataTransforms.getResamplingDataset(data, sampleSize, randomGenerator); + } } dataSet.setKnowledge(data.getKnowledge()); @@ -191,11 +196,13 @@ public List search() { for (DataSet data : this.dataSets) { if (this.resamplingWithReplacement) { - DataSet bootstrapSample = DataUtils.getBootstrapSample(data, (int) (data.getNumRows() * this.percentResampleSize / 100.0)); + int sampleSize = (int) (data.getNumRows() * this.percentResampleSize / 100.0); + DataSet bootstrapSample = DataTransforms.getBootstrapSample(data, sampleSize); bootstrapSample.setKnowledge(data.getKnowledge()); dataModels.add(bootstrapSample); } else { - DataSet resamplingDataset = DataUtils.getResamplingDataset(data, (int) (data.getNumRows() * this.percentResampleSize / 100.0)); + int sampleSize = (int) (data.getNumRows() * this.percentResampleSize / 100.0); + DataSet resamplingDataset = DataTransforms.getResamplingDataset(data, sampleSize); resamplingDataset.setKnowledge(data.getKnowledge()); dataModels.add(resamplingDataset); } diff --git a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTree.java b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTree.java index 0743f4d842..96e4bb5557 100644 --- a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTree.java +++ b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTree.java @@ -36,7 +36,9 @@ * Indexing of the variables works backwards: (a_i can't have children a_i ... a_m) ... not that that difference is * visible in the API. * - * @author user + * @param Attribute type + * @param Value type + * @author jdramsey */ public class AdTree extends AdTreeHelper { @@ -45,6 +47,10 @@ public class AdTree extends AdTreeHelper { private final List values; private final CountNode root; + /** + * Constructs an AD tree for the given data set. + * @param data The data set. + */ public AdTree(DataTable data) { super(data.columnCount()); @@ -100,12 +106,22 @@ public AdTree(DataTable data) { this.root = new CountNode(this.m, array); } + /** + * Returns the number of rows in the data set. + * @param attribute The attribute to count. + * @return The number of rows in the data set. + */ public List values(A attribute) { int index = Objects.requireNonNull(this.attributeLookup.get(attribute), "Attribute " + attribute.toString() + " not found."); return this.values.get(index).list; } + /** + * Returns the number of rows in the data set. + * @param assignment The assignment to count. + * @return The number of rows in the data set. + */ public int count(Map assignment) { int[] a = new int[this.m]; for (int i = 0; i < this.m; i++) { @@ -117,6 +133,12 @@ public int count(Map assignment) { return count(a, this.root); } + /** + * Returns the number of rows in the data set. + * @param attribute The attribute to count. + * @param assignment The assignment to count. + * @return The number of rows in the data set. + */ public Map counts(A attribute, Map assignment) { List vlist = this.values.get(this.attributeLookup.get(attribute)).list; @@ -130,10 +152,20 @@ public Map counts(A attribute, Map assignment) { return result; } + /** + * Converts to XML. + * @return The XML document. + * @throws ParserConfigurationException if something goes wrong + */ public Document toXML() throws ParserConfigurationException { return toXML(DocumentBuilderFactory.newInstance().newDocumentBuilder()); } + /** + * Converts to XML. + * @param builder The builder. + * @return The XML document. + */ public Document toXML(DocumentBuilder builder) { Document doc = builder.newDocument(); diff --git a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeHelper.java b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeHelper.java index e0ff3d4dcc..7ccf40b8aa 100644 --- a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeHelper.java +++ b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeHelper.java @@ -30,14 +30,33 @@ */ class AdTreeHelper implements Serializable { + /** + * The number of attributes. + */ protected final int m; // The number of attributes + + /** + * The airities of the attributes. The i-th element of this array is the airity of the i-th attribute. + */ protected final int[] airities; + /** + * Constructs an AD tree helper for the given data set. + * + * @param m The number of attributes. + */ protected AdTreeHelper(int m) { this.m = m; this.airities = new int[m]; } + /** + * Constructs an AD tree helper for the given data set. + * + * @param assignment The assignment of values to attributes. + * @param ptr The root of the AD tree. + * @return The number of instances in the data set that match the given assignment. + */ protected int count(int[] assignment, CountNode ptr) { if (null == ptr) return 0; @@ -63,6 +82,9 @@ protected int count(int[] assignment, CountNode ptr) { return null == ptr ? 0 : ptr.count; } + /** + * Constructs an AD tree helper for the given data set. + */ protected class CountNode implements Serializable { protected final int count; protected final VaryNode[] vary; @@ -77,6 +99,9 @@ protected CountNode(int attribute, int[][] array) { } } + /** + * Constructs an AD tree helper for the given data set. + */ protected class VaryNode implements Serializable { protected final CountNode[] values; protected int mcv = -1; @@ -118,6 +143,5 @@ private VaryNode(int attr, int[][] array) { } } } - } diff --git a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeTest.java b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeTest.java index 64157b3ba3..66208cdc4f 100644 --- a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeTest.java +++ b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/AdTreeTest.java @@ -36,10 +36,23 @@ import java.util.TreeMap; /** + *

    A test of the AD tree implementation.

    * Author : Jeremy Espino MD Created 6/24/15 3:32 PM */ public class AdTreeTest { + /** + * Creates a new AdTreeTest object. + */ + public AdTreeTest() { + } + + /** + * Test the AD tree + * + * @param args ignored + * @throws Exception if something goes wrong + */ public static void main(String[] args) throws Exception { final int columns = 40; final int numEdges = 40; diff --git a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTable.java b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTable.java index 6682db6b1f..dc30dac4f8 100644 --- a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTable.java +++ b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTable.java @@ -24,6 +24,10 @@ import java.util.List; /** + * Data table implementation. + * + * @param Type of variable names + * @param Type of variable values * @author YUS24 */ public interface DataTable extends Iterable> { diff --git a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTableImpl.java b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTableImpl.java index 75bc057630..3864c502df 100644 --- a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTableImpl.java +++ b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTableImpl.java @@ -27,7 +27,11 @@ import java.util.List; /** + * Data table implementation. + * * @author YUS24 + * @param Type of variable names + * @param Type of variable values */ public class DataTableImpl implements DataTable { diff --git a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTools.java b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTools.java index 967c6f17da..b02f6ab4d6 100644 --- a/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTools.java +++ b/tetrad-lib/src/main/java/edu/pitt/isp/sverchkov/data/DataTools.java @@ -27,6 +27,8 @@ import java.util.Scanner; /** + * Data tools. + * * @author YUS24 */ public class DataTools { 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 ffd15ec085..f10cfcf224 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 @@ -61,7 +61,6 @@ public void test1() { 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 FciMax(test)); testKnowledge(dataSet, knowledge, parameters, new Gfci(test, score)); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java index 973ac58ebd..552ec719dc 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/ExploreAutisticsNeurotypicals.java @@ -448,7 +448,7 @@ private List> loadData(String path, String... prefixes) { if (file.getName().startsWith(prefixes[i]) && !file.getName().endsWith(".graph.txt") && !file.getName().contains("tet")) { DataSet data = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); allDataSets.get(i).add(data); attested = true; @@ -506,7 +506,7 @@ public void makeDataSpecial() { final String path = "/Users/jdramsey/Documents/LAB_NOTEBOOK.2012.04.20/data/USM_Datasets"; File file = new File(path, "concat_usm_dataset_madelyn.txt"); DataSet data = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); ContinuousVariable avg = new ContinuousVariable("Avg"); data.addVariable(avg); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java index 73aa8c86a5..cb852f04cb 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/FaskGraphs.java @@ -106,7 +106,7 @@ private void loadFiles(String path, Parameters parameters, String... contains) { if (name.contains("autistic")) { this.types.add(true); DataSet dataSet = SimpleDataLoader.loadContinuousData(new File(path, name), "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.filenames.add(name); this.datasets.add(dataSet); Fask fask = new Fask(); @@ -115,7 +115,7 @@ private void loadFiles(String path, Parameters parameters, String... contains) { } else if (name.contains("typical")) { this.types.add(false); DataSet dataSet = SimpleDataLoader.loadContinuousData(new File(path, name), "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.filenames.add(name); this.datasets.add(dataSet); Fask fask = new Fask(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java index 7eae275f35..c9e4fa9e95 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraph.java @@ -20,7 +20,7 @@ * @author josephramsey */ public class LoadContinuousDataAndSingleGraph implements Simulation, HasParameterValues { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String path; private final String subdir; private final List usedParameters = new ArrayList<>(); @@ -53,7 +53,7 @@ public void createData(Parameters parameters, boolean newModel) { try { DataSet dataSet = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.dataSets.add(dataSet); if (!(dataSet.isContinuous())) { @@ -79,7 +79,7 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading graph from " + file.getAbsolutePath()); this.graph = GraphSaveLoadUtils.loadGraphTxt(file); - LayoutUtil.circleLayout(this.graph); + LayoutUtil.defaultLayout(this.graph); } if (parameters.get("numRuns") != null) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java index 5959e40d71..aed74c6c5b 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataAndSingleGraphKun.java @@ -16,7 +16,7 @@ * @author josephramsey */ public class LoadContinuousDataAndSingleGraphKun implements Simulation, HasParameterValues { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String path; private final String prefix; private final List usedParameters = new ArrayList<>(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java index 0b83cfe11d..84d6495819 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadContinuousDataSmithSim.java @@ -19,7 +19,7 @@ * @author josephramsey */ public class LoadContinuousDataSmithSim implements Simulation, HasParameterValues { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final int index; private final String path; private final List usedParameters = new ArrayList<>(); @@ -51,7 +51,7 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading graph from " + file.getAbsolutePath()); this.graph = readGraph(file); - LayoutUtil.circleLayout(this.graph); + LayoutUtil.defaultLayout(this.graph); break; } @@ -68,7 +68,7 @@ public void createData(Parameters parameters, boolean newModel) { System.out.println("Loading data from " + file.getAbsolutePath()); try { DataSet dataSet = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); if (dataSet.getVariables().size() > this.graph.getNumNodes()) { List nodes = new ArrayList<>(); @@ -138,7 +138,7 @@ public Parameters getParameterValues() { public Graph readGraph(File file) { try { DataSet data = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); List variables = data.getVariables(); List _variables = new ArrayList<>(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java index 6edee93c50..f958ae92ca 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/LoadMadelynData.java @@ -20,7 +20,7 @@ * @author josephramsey */ public class LoadMadelynData implements Simulation, HasParameterValues { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final String directory; private final String suffix; private final int structure; @@ -46,7 +46,7 @@ public void createData(Parameters parameters, boolean newModel) { try { DataSet dataSet = SimpleDataLoader.loadContinuousData(file, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); this.dataSets.add(dataSet); if (!(dataSet.isContinuous())) { @@ -62,7 +62,7 @@ public void createData(Parameters parameters, boolean newModel) { File file2 = new File(parent + "/structure_" + this.structure + "_graph.txt"); System.out.println("Loading graph from " + file2.getAbsolutePath()); this.graph = GraphSaveLoadUtils.loadGraphTxt(file2); - LayoutUtil.circleLayout(this.graph); + LayoutUtil.defaultLayout(this.graph); if (parameters.get("numRuns") != null) { parameters.set("numRuns", parameters.get("numRuns")); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java index 199bfa78b8..02fa4f19b2 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialDataClark.java @@ -29,7 +29,7 @@ * @author josephramsey */ public class SpecialDataClark implements Simulation { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; private final RandomGraph randomGraph; private final List ims = new ArrayList<>(); private BayesPm pm; diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java index a8e78a2b73..94ead33774 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/SpecialGraphClark.java @@ -16,7 +16,7 @@ * @author josephramsey */ public class SpecialGraphClark implements RandomGraph { - static final long serialVersionUID = 23L; + private static final long serialVersionUID = 23L; @Override public Graph createGraph(Parameters parameters) { diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java index 53c230d7a8..c939df41d3 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDM.java @@ -1185,7 +1185,7 @@ public DMSearch readAndSearchData(String fileLocation, int[] inputs, int[] outpu try { data = SimpleDataLoader.loadContinuousData(file, "//", '"', - "*", true, Delimiter.WHITESPACE); + "*", true, Delimiter.WHITESPACE, false); } catch (IOException e) { System.out.println("Failed to read in data."); e.printStackTrace(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java index b8280069a0..8f62d049f0 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDagInPatternIterator.java @@ -25,7 +25,6 @@ import edu.cmu.tetrad.data.Knowledge; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.utils.DagInCpcagIterator; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.RandomUtil; import java.util.ArrayList; @@ -55,7 +54,7 @@ public void test1() { Dag dag = new Dag(graph); - Graph CPDAG = GraphSearchUtils.cpdagFromDag(graph); + Graph CPDAG = GraphTransforms.cpdagForDag(graph); System.out.println(CPDAG); @@ -176,7 +175,7 @@ public void test5() { Dag dag1 = new Dag(RandomGraph.randomGraph(nodes1, 0, 3, 30, 15, 15, false)); - Graph CPDAG = GraphSearchUtils.cpdagForDag(dag1); + Graph CPDAG = GraphTransforms.cpdagForDag(dag1); List nodes = CPDAG.getNodes(); // Make random knowedge. diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java index 94dab7fa2a..1975d2ebc6 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestDeltaSextadTest.java @@ -118,7 +118,7 @@ public void testBollenExampleb() { try { final String name = "src/test/resources/dataLG.txt"; data = SimpleDataLoader.loadContinuousData(new File(name), "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); } catch (IOException e) { e.printStackTrace(); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java index 6d1a22cd5e..2a417bbb0c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFaskSimpleSimulaton.java @@ -21,7 +21,7 @@ package edu.cmu.tetrad.test; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.util.RandomUtil; import edu.cmu.tetrad.util.StatUtils; @@ -96,9 +96,9 @@ public void simulation() { } // Center variables. - x = DataUtils.center(x); - y = DataUtils.center(y); - z = DataUtils.center(z); + x = DataTransforms.center(x); + y = DataTransforms.center(y); + z = DataTransforms.center(z); // Swap x and y so y->x instead. double[] w = x; @@ -168,9 +168,9 @@ public void test2() { } // Center variables. - x = DataUtils.center(x); - y = DataUtils.center(y); - z = DataUtils.center(z); + x = DataTransforms.center(x); + y = DataTransforms.center(y); + z = DataTransforms.center(z); // Swap x and y so y->x instead. diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java index ee2a462afe..5141a62e56 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFci.java @@ -33,7 +33,6 @@ import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.MsepTest; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.ChoiceGenerator; @@ -162,7 +161,7 @@ public void testSearch11() { knowledge.addToTier(2, "X3"); checkSearch("Latent(L1),Latent(L2),L1-->X1,L1-->X2,L2-->X2,L2-->X3", - "X1o->X2,X2<-oX3", knowledge); + "X1<->X2,X2<->X3", knowledge); } @Test @@ -202,7 +201,7 @@ public void testSearch13() { // DagToPag dagToPag = new DagToPag(trueGraph); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(trueGraph); + Graph truePag = GraphTransforms.dagToPag(trueGraph); assertEquals(graph, truePag); } diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFges.java index 18c6f2ba69..c9e7477ca5 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 @@ -165,7 +165,7 @@ public void explore1() { alg.setFaithfulnessAssumed(true); Graph estCPDAG = alg.search(); - Graph trueCPDAG = GraphSearchUtils.cpdagForDag(dag); + Graph trueCPDAG = GraphTransforms.cpdagForDag(dag); estCPDAG = GraphUtils.replaceNodes(estCPDAG, vars); @@ -230,7 +230,7 @@ public void explore2() { Graph estCPDAG = ges.search(); - Graph trueCPDAG = GraphSearchUtils.cpdagForDag(dag); + Graph trueCPDAG = GraphTransforms.cpdagForDag(dag); int[][] counts = GraphSearchUtils.graphComparison(trueCPDAG, estCPDAG, null); @@ -252,7 +252,7 @@ public void testExplore3() { Graph graph = GraphUtils.convert("A-->B,A-->C,B-->D,C-->D"); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); Graph CPDAG = fges.search(); - assertEquals(GraphSearchUtils.cpdagForDag(graph), CPDAG); + assertEquals(GraphTransforms.cpdagForDag(graph), CPDAG); } @Test @@ -260,7 +260,7 @@ public void testExplore4() { Graph graph = GraphUtils.convert("A-->B,A-->C,A-->D,B-->E,C-->E,D-->E"); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); Graph CPDAG = fges.search(); - assertEquals(GraphSearchUtils.cpdagForDag(graph), CPDAG); + assertEquals(GraphTransforms.cpdagForDag(graph), CPDAG); } @Test @@ -269,7 +269,7 @@ public void testExplore5() { edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(new GraphScore(graph)); fges.setFaithfulnessAssumed(false); Graph CPDAG = fges.search(); - assertEquals(GraphSearchUtils.cpdagForDag(graph), CPDAG); + assertEquals(GraphTransforms.cpdagForDag(graph), CPDAG); } @Test @@ -725,7 +725,7 @@ public void testFromGraph() { fges.setVerbose(true); fges.setParallelized(true); Graph CPDAG1 = fges.search(); - Graph CPDAG2 = GraphSearchUtils.cpdagFromDag(dag); + Graph CPDAG2 = GraphTransforms.cpdagForDag(dag); assertEquals(CPDAG2, CPDAG1); } } @@ -919,7 +919,7 @@ private Graph getSubgraph(Graph graph, boolean discrete1, boolean discrete2, Dat } private Graph searchSemFges(DataSet Dk) { - Dk = DataUtils.convertNumericalDiscreteToContinuous(Dk); + Dk = DataTransforms.convertNumericalDiscreteToContinuous(Dk); SemBicScore score = new SemBicScore(new CovarianceMatrix(Dk)); score.setPenaltyDiscount(2.0); edu.cmu.tetrad.search.Fges fges = new edu.cmu.tetrad.search.Fges(score); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java index ff9e367827..4d9ded3e93 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestFruchtermanReingoldLayout.java @@ -64,7 +64,7 @@ public void testLayout() { Dag dag2 = new Dag(dag); - LayoutUtil.circleLayout(dag); + LayoutUtil.defaultLayout(dag); LayoutUtil.FruchtermanReingoldLayout layout = new LayoutUtil.FruchtermanReingoldLayout(dag); layout.doLayout(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java index 49409b6a5e..a28048e009 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGFci.java @@ -25,8 +25,6 @@ import edu.cmu.tetrad.bayes.MlBayesIm; import edu.cmu.tetrad.data.*; import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.BFci; -import edu.cmu.tetrad.search.Fci; import edu.cmu.tetrad.search.GFci; import edu.cmu.tetrad.search.IndependenceTest; import edu.cmu.tetrad.search.score.BdeuScore; @@ -89,7 +87,7 @@ public void test1() { simulator.setCoefRange(.5, 1.5); simulator.setVarRange(1, 3); data = simulator.simulateDataFisher(sampleSize); - data = DataUtils.restrictToMeasured(data); + data = DataTransforms.restrictToMeasured(data); ICovarianceMatrix cov = new CovarianceMatrix(data); @@ -112,7 +110,7 @@ public void test1() { // dagToPag.setMaxPathLength(maxPathLength); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); outGraph = GraphUtils.replaceNodes(outGraph, truePag.getNodes()); @@ -197,7 +195,7 @@ public void testFromGraph() { // dagToPag.setCompleteRuleSetUsed(false); // Graph pag2 = dagToPag.convert(); - Graph pag2 = GraphSearchUtils.dagToPag(dag); + Graph pag2 = GraphTransforms.dagToPag(dag); assertEquals(pag2, pag1); } @@ -223,7 +221,7 @@ public void testFromData() { DataSet data = im.simulateData(1000, false); - data = DataUtils.restrictToMeasured(data); + data = DataTransforms.restrictToMeasured(data); // System.out.println(data.getCorrelationMatrix()); 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 16d626f740..151d3947cc 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 @@ -35,9 +35,9 @@ import edu.cmu.tetrad.data.DataSet; import edu.cmu.tetrad.data.DiscreteVariable; import edu.cmu.tetrad.graph.Graph; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.Node; import edu.cmu.tetrad.graph.RandomGraph; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.LargeScaleSimulation; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -291,7 +291,7 @@ public void testGFCIc() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); int[] causalOrdering = new int[numVars]; @@ -353,7 +353,7 @@ public void testGFCId() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); BayesPm pm = new BayesPm(dag, 2, 3); BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM); @@ -413,7 +413,7 @@ public void testFCIc() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); int[] causalOrdering = new int[numVars]; @@ -477,7 +477,7 @@ public void testFCId() { // DagToPag dagToPag = new DagToPag(dag); // Graph truePag = dagToPag.convert(); - Graph truePag = GraphSearchUtils.dagToPag(dag); + Graph truePag = GraphTransforms.dagToPag(dag); BayesPm pm = new BayesPm(dag, 2, 3); BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestGrasp.java index cd9e7a7dfe..f05949230e 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 @@ -33,7 +33,6 @@ import edu.cmu.tetrad.algcomparison.independence.FisherZ; import edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper; import edu.cmu.tetrad.algcomparison.independence.MSeparationTest; -import edu.cmu.tetrad.algcomparison.independence.SemBicDTest; import edu.cmu.tetrad.algcomparison.score.GicScores; import edu.cmu.tetrad.algcomparison.score.MSeparationScore; import edu.cmu.tetrad.algcomparison.score.ScoreWrapper; @@ -2663,7 +2662,7 @@ public void testFcoAlgsFromMsep() { Graph trueGraph = RandomGraph.randomGraph(20, 8, 40, 100, 100, 100, false); - Graph truePag = GraphSearchUtils.dagToPag(trueGraph); + Graph truePag = GraphTransforms.dagToPag(trueGraph); trueGraphMap.put(i, new HashMap<>()); trueGraphs.add(trueGraph); @@ -3157,7 +3156,7 @@ public void testWayne2() { if (g1.equals(g2)) gsCount++; gsShd += GraphSearchUtils.structuralHammingDistance( - GraphSearchUtils.cpdagForDag(g1), GraphSearchUtils.cpdagForDag(g2)); + GraphTransforms.cpdagForDag(g1), GraphTransforms.cpdagForDag(g2)); for (int i = 0; i < alpha.length; i++) { // test.setAlpha(alpha[i]); @@ -3172,7 +3171,7 @@ public void testWayne2() { if (g1.equals(g3)) pearlCounts[i]++; pearlShd[i] += GraphSearchUtils.structuralHammingDistance( - GraphSearchUtils.cpdagForDag(g1), GraphSearchUtils.cpdagForDag(g3)); + GraphTransforms.cpdagForDag(g1), GraphTransforms.cpdagForDag(g3)); } } @@ -3387,7 +3386,7 @@ public void testJaime() { // String path = "/Users/josephramsey/Downloads/sample100genes.csv1.imputed.txt"; String path = "/Users/josephramsey/Downloads/Arabidopsis_dataset_Wdtf.csv1.impute.txt"; DataSet data = SimpleDataLoader.loadContinuousData(new File(path), "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); System.out.println(data.getNumColumns()); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java index dc4c614518..ee3403d4a5 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestHistogram.java @@ -66,7 +66,7 @@ public void testHistogram() { SemIm semIm = new SemIm(semPm); DataSet data = semIm.simulateData(sampleSize, false); - Histogram histogram = new Histogram(data, "X1"); + Histogram histogram = new Histogram(data, "X1", false); // histogram.setTarget("X1"); histogram.setNumBins(20); @@ -97,7 +97,7 @@ public void testHistogram() { // values when all of the unit tests are run are // once. TODO They produce stable values when // this particular test is run repeatedly. - Histogram histogram2 = new Histogram(data2, "X1"); + Histogram histogram2 = new Histogram(data2, "X1", false); // histogram2.setTarget("X1"); histogram2.getFrequencies(); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaIcaLingamPattern.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaIcaLingamPattern.java deleted file mode 100644 index a303e6e3db..0000000000 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIcaIcaLingamPattern.java +++ /dev/null @@ -1,174 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// For information as to what this class does, see the Javadoc, below. // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, // -// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard // -// Scheines, Joseph Ramsey, and Clark Glymour. // -// // -// This program is free software; you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation; either version 2 of the License, or // -// (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program; if not, write to the Free Software // -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -/////////////////////////////////////////////////////////////////////////////// - -package edu.cmu.tetrad.test; - -import edu.cmu.tetrad.data.*; -import edu.cmu.tetrad.graph.*; -import edu.cmu.tetrad.search.Fges; -import edu.cmu.tetrad.search.PcLingam; -import edu.cmu.tetrad.search.score.Score; -import edu.cmu.tetrad.search.score.SemBicScore; -import edu.cmu.tetrad.sem.SemIm; -import edu.cmu.tetrad.sem.SemPm; -import edu.cmu.tetrad.util.RandomUtil; -import edu.cmu.tetrad.util.dist.Distribution; -import edu.cmu.tetrad.util.dist.Normal; -import edu.cmu.tetrad.util.dist.Uniform; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - - -/** - * @author josephramsey - */ -public class TestIcaIcaLingamPattern { - - @Test - public void test1() { - RandomUtil.getInstance().setSeed(4938492L); - - final int sampleSize = 1000; - - List nodes = new ArrayList<>(); - - for (int i = 0; i < 6; i++) { - nodes.add(new ContinuousVariable("X" + (i + 1))); - } - - Graph graph = new Dag(RandomGraph.randomGraph(nodes, 0, 6, - 4, 4, 4, false)); - - List variableDistributions = new ArrayList<>(); - - variableDistributions.add(new Normal(0, 1)); - variableDistributions.add(new Normal(0, 1)); - variableDistributions.add(new Normal(0, 1)); - variableDistributions.add(new Uniform(-1, 1)); - variableDistributions.add(new Normal(0, 1)); - variableDistributions.add(new Normal(0, 1)); - - SemPm semPm = new SemPm(graph); - SemIm semIm = new SemIm(semPm); - - DataSet dataSet = simulateDataNonNormal(semIm, variableDistributions); - Score score = new SemBicScore(new CovarianceMatrix(dataSet)); - Graph estnumCPDAGsToStore = new Fges(score).search(); - - PcLingam lingam = new PcLingam(estnumCPDAGsToStore, dataSet); - lingam.search(); - - double[] pvals = lingam.getPValues(); - - double[] expectedPVals = {0.18, 0.29, 0.88, 0.00, 0.01, 0.57}; - - for (int i = 0; i < pvals.length; i++) { -// assertEquals(expectedPVals[i], pvals[i], 0.01); - } - } - - /** - * This simulates data by picking random values for the exogenous terms and percolating this information down - * through the SEM, assuming it is acyclic. Fast for large simulations but hangs for cyclic models. - * - * @return the simulated data set. - */ - private DataSet simulateDataNonNormal(SemIm semIm, - List distributions) { - List variables = new LinkedList<>(); - List variableNodes = semIm.getSemPm().getVariableNodes(); - - for (Node node : variableNodes) { - ContinuousVariable var = new ContinuousVariable(node.getName()); - variables.add(var); - } - - DataSet dataSet = new BoxDataSet(new DoubleDataBox(1000, variables.size()), variables); - - // Create some index arrays to hopefully speed up the simulation. - SemGraph graph = semIm.getSemPm().getGraph(); - - - List tierOrdering = graph.paths().getValidOrder(graph.getNodes(), true); - - System.out.println(graph); - - - int[] tierIndices = new int[variableNodes.size()]; - - for (int i = 0; i < tierIndices.length; i++) { - tierIndices[i] = variableNodes.indexOf(tierOrdering.get(i)); - } - - int[][] _parents = new int[variables.size()][]; - - for (int i = 0; i < variableNodes.size(); i++) { - Node node = variableNodes.get(i); - List parents = new ArrayList<>(graph.getParents(node)); - - for (Iterator j = parents.iterator(); j.hasNext(); ) { - Node _node = j.next(); - - if (_node.getNodeType() == NodeType.ERROR) { - j.remove(); - } - } - - _parents[i] = new int[parents.size()]; - - for (int j = 0; j < parents.size(); j++) { - Node _parent = parents.get(j); - _parents[i][j] = variableNodes.indexOf(_parent); - } - } - - // Do the simulation. - for (int row = 0; row < 1000; row++) { -// System.out.println(row); - - for (int i = 0; i < tierOrdering.size(); i++) { - int col = tierIndices[i]; - Distribution distribution = distributions.get(col); - -// System.out.println(distribution); - - double value = distribution.nextRandom(); - - for (int j = 0; j < _parents[col].length; j++) { - int parent = _parents[col][j]; - value += dataSet.getDouble(row, parent) * - semIm.getEdgeCoef().get(parent, col); - } - - value += semIm.getMeans()[col]; - dataSet.setDouble(row, col, value); - } - } - - return dataSet; - } -} - - diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java index b411945f3e..17611aec7c 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestIndTestGSquare.java @@ -91,7 +91,8 @@ private DataSet getDataSet() throws IOException { System.out.println("Loading " + filename); return SimpleDataLoader.loadDiscreteData(new File(filename), - "//", '\"', "-99", true, Delimiter.TAB); + "//", '\"', "-99", true, Delimiter.TAB, + false); } } 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 eed9b8c8b8..4b841cd7aa 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 @@ -28,7 +28,6 @@ import edu.cmu.tetrad.search.score.SemBicScore; import edu.cmu.tetrad.search.test.IndTestFisherZ; import edu.cmu.tetrad.search.test.MsepTest; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.sem.SemIm; import edu.cmu.tetrad.sem.SemPm; import edu.cmu.tetrad.util.MillisecondTimes; @@ -41,7 +40,6 @@ import java.util.ArrayList; import java.util.List; -import static edu.cmu.tetrad.search.utils.GraphSearchUtils.dagToPag; import static org.junit.Assert.assertEquals; /** @@ -128,9 +126,9 @@ public void testCites() { "\n" + "Graph Edges:\n" + "1. ABILITY --> CITES\n" + - "2. ABILITY --- GPQ\n" + - "3. ABILITY --- PREPROD\n" + - "4. GPQ --- QFJ\n" + + "2. ABILITY --> GPQ\n" + + "3. ABILITY --> PREPROD\n" + + "4. GPQ --> QFJ\n" + "5. PREPROD --> CITES\n" + "6. PUBS --> CITES\n" + "7. QFJ --> CITES\n" + @@ -219,7 +217,7 @@ public void checknumCPDAGsToStore() { MsepTest test = new MsepTest(graph); Pc pc = new Pc(test); Graph CPDAG = pc.search(); - Graph CPDAG2 = GraphSearchUtils.cpdagFromDag(graph); + Graph CPDAG2 = GraphTransforms.cpdagForDag(graph); assertEquals(CPDAG, CPDAG2); } } @@ -648,7 +646,7 @@ private double[] printStatsPcRegression(String[] algorithms, int t, SemPm pm = new SemPm(dag); SemIm im = new SemIm(pm); DataSet data = im.simulateData(10000, false); - Graph comparison = dagToPag(dag); + Graph comparison = GraphTransforms.dagToPag(dag); IndTestFisherZ test = new IndTestFisherZ(data, 0.1); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java index 4ef02d4ccb..70ba06d08a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRfciBsc.java @@ -4,11 +4,10 @@ import edu.cmu.tetrad.bayes.BayesPm; import edu.cmu.tetrad.bayes.MlBayesIm; import edu.cmu.tetrad.data.DataSet; -import edu.cmu.tetrad.data.DataUtils; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.search.test.IndTestProbabilistic; import edu.cmu.tetrad.search.utils.BayesImParser; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.RandomUtil; import nu.xom.Builder; @@ -89,14 +88,14 @@ public void testRandomDiscreteData() { // simulate data from instantiated model DataSet fullData = bayesIm.simulateData(sampleSize, true); TestRfciBsc.refineData(fullData); - DataSet dataSet = DataUtils.restrictToMeasured(fullData); + DataSet dataSet = DataTransforms.restrictToMeasured(fullData); // get the true underlying PAG // DagToPag dagToPag = new DagToPag(dag); // dagToPag.setCompleteRuleSetUsed(false); // Graph PAG_True = dagToPag.convert(); - Graph PAG_True = GraphSearchUtils.dagToPag(dag); + Graph PAG_True = GraphTransforms.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, dataSet.getVariables()); @@ -162,14 +161,14 @@ public void testDiscreteRealData() { DataSet fullData = im.simulateData(sampleSize, true); TestRfciBsc.refineData(fullData); - DataSet dataSet = DataUtils.restrictToMeasured(fullData); + DataSet dataSet = DataTransforms.restrictToMeasured(fullData); // get the true underlying PAG // DagToPag dagToPag = new DagToPag(dag); // dagToPag.setCompleteRuleSetUsed(false); // Graph PAG_True = dagToPag.convert(); - Graph PAG_True = GraphSearchUtils.dagToPag(dag); + Graph PAG_True = GraphTransforms.dagToPag(dag); PAG_True = GraphUtils.replaceNodes(PAG_True, dataSet.getVariables()); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java index d2099a9533..5e43540212 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRicf.java @@ -283,7 +283,7 @@ public void test3() { try { File datapath = new File("/Users/josephramsey/Downloads/data6.txt"); DataSet dataSet = SimpleDataLoader.loadContinuousData(datapath, "//", '\"', - "*", true, Delimiter.TAB); + "*", true, Delimiter.TAB, false); Graph mag = GraphSaveLoadUtils.loadGraphTxt(new File("/Users/josephramsey/Downloads/graph3.txt")); ICovarianceMatrix cov = new CovarianceMatrix(dataSet); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java index 5431e492b6..e1e816251a 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestRubenData.java @@ -11,11 +11,11 @@ import edu.cmu.tetrad.data.SimpleDataLoader; import edu.cmu.tetrad.graph.Graph; import edu.cmu.tetrad.graph.GraphSaveLoadUtils; +import edu.cmu.tetrad.graph.GraphTransforms; import edu.cmu.tetrad.graph.GraphUtils; import edu.cmu.tetrad.search.Boss; import edu.cmu.tetrad.search.PermutationSearch; import edu.cmu.tetrad.search.score.SemBicScore; -import edu.cmu.tetrad.search.utils.GraphSearchUtils; import edu.cmu.tetrad.util.MillisecondTimes; import edu.cmu.tetrad.util.Parameters; import edu.cmu.tetrad.util.Params; @@ -49,11 +49,11 @@ public void test1() { try { DataSet data = SimpleDataLoader.loadContinuousData(new File(path1), "//", - '\"', "*", true, Delimiter.COMMA); + '\"', "*", true, Delimiter.COMMA, false); Graph graph = GraphSaveLoadUtils.loadGraphTxt(new File(path2)); - graph = GraphSearchUtils.cpdagForDag(graph); + graph = GraphTransforms.cpdagForDag(graph); SemBicScore score = new SemBicScore(data, precomputeCovariances); score.setPenaltyDiscount(2); diff --git a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java index 12991a80e3..f70d5bfc31 100644 --- a/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java +++ b/tetrad-lib/src/test/java/edu/cmu/tetrad/test/TestStandardizedSem.java @@ -23,6 +23,7 @@ import edu.cmu.tetrad.data.ContinuousVariable; import edu.cmu.tetrad.data.DataSet; +import edu.cmu.tetrad.data.DataTransforms; import edu.cmu.tetrad.data.DataUtils; import edu.cmu.tetrad.graph.*; import edu.cmu.tetrad.sem.SemEstimator; @@ -65,7 +66,7 @@ public void test1() { SemIm im = new SemIm(pm); DataSet dataSet = im.simulateData(1000, false); - DataSet dataSetStandardized = DataUtils.standardizeData(dataSet); + DataSet dataSetStandardized = DataTransforms.standardizeData(dataSet); Matrix _dataSet = dataSet.getDoubleData(); DataUtils.cov(_dataSet);