Skip to content

Commit

Permalink
Merge pull request #1784 from cmu-phil/joe_work_2024_6_1
Browse files Browse the repository at this point in the history
Joe work 2024 6 1
  • Loading branch information
jdramsey authored Jun 13, 2024
2 parents ebaba1b + 7585c80 commit 6aa0340
Show file tree
Hide file tree
Showing 371 changed files with 5,951 additions and 2,455 deletions.
5 changes: 2 additions & 3 deletions tetrad-gui/src/main/java/edu/cmu/tetradapp/Tetrad.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
///////////////////////////////////////////////////////////////////////////////
package edu.cmu.tetradapp;

import edu.cmu.tetrad.search.work_in_progress.DMSearch;
import edu.cmu.tetrad.util.JOptionUtils;
import edu.cmu.tetrad.util.TetradLogger;
import edu.cmu.tetrad.util.Version;
Expand Down Expand Up @@ -122,7 +121,7 @@ private static void setLookAndFeel() {
UIManager.getSystemLookAndFeelClassName());
}
} catch (Exception e) {
TetradLogger.getInstance().forceLogMessage("Couldn't set look and feel.");
TetradLogger.getInstance().log("Couldn't set look and feel.");
}
}

Expand Down Expand Up @@ -271,7 +270,7 @@ public void componentMoved(ComponentEvent e) {
}
});
} catch (Exception e) {
TetradLogger.getInstance().forceLogMessage("Could not set quit handler on this platform..");
TetradLogger.getInstance().log("Could not set quit handler on this platform..");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void watch() {
throw e1;
} catch (Exception e2) {
e2.printStackTrace();
TetradLogger.getInstance().forceLogMessage("Exception: " + e2.getMessage());
TetradLogger.getInstance().log("Exception: " + e2.getMessage());
}
} else if (o instanceof SessionWrapper) {
sessionWrapper = (SessionWrapper) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public void setDisplayLogging(boolean displayLogging) {
try {
TetradLogger.getInstance().setNextOutputStream();
} catch (IllegalStateException e2) {
TetradLogger.getInstance().forceLogMessage(
TetradLogger.getInstance().log(
"Unable to setup logging, please restart Tetrad.");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ private void setup() {

area.setFont(font);

int position = area.getText().indexOf("True graph");

// If the word is found, scroll to it
if (position >= 0) {
area.setCaretPosition(position);
}

JScrollPane scrollTextPane = new JScrollPane(area);
scrollTextPane.setPreferredSize(new Dimension(500, 600));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void setAlgorithmResult(String jsonResult) {
this.algorithmRunner.getGraphs().clear();
this.algorithmRunner.getGraphs().add(graph);

TetradLogger.getInstance().forceLogMessage("Remote graph result assigned to algorithmRunner!");
TetradLogger.getInstance().log("Remote graph result assigned to algorithmRunner!");
firePropertyChange("modelChanged", null, null);

this.graphCard.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ private void setParseText(String text) {
expressionTextDoc.remove(0, expressionTextPane.getText().length());
expressionTextDoc.insertString(0, text, null);
} catch (BadLocationException e) {
TetradLogger.getInstance().forceLogMessage(e.getMessage());
TetradLogger.getInstance().log(e.getMessage());
throw new RuntimeException(e);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ private JMenu createGraphMenu() {
JMenuItem randomGraph = new JMenuItem("Random Graph");
graph.add(randomGraph);

randomGraph.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.META_DOWN_MASK));

graph.addSeparator();

graph.add(new GraphPropertiesAction(getWorkbench()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import edu.cmu.tetrad.algcomparison.score.ScoreWrapper;
import edu.cmu.tetrad.algcomparison.simulation.Simulation;
import edu.cmu.tetrad.algcomparison.simulation.Simulations;
import edu.cmu.tetrad.algcomparison.simulation.SingleDatasetSimulation;
import edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper;
import edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper;
import edu.cmu.tetrad.annotation.AnnotatedClass;
import edu.cmu.tetrad.annotation.Score;
import edu.cmu.tetrad.annotation.TestOfIndependence;
import edu.cmu.tetrad.data.DataSet;
import edu.cmu.tetrad.data.DataType;
import edu.cmu.tetrad.data.Knowledge;
import edu.cmu.tetrad.graph.Graph;
import edu.cmu.tetrad.util.*;
import edu.cmu.tetradapp.editor.simulation.ParameterTab;
import edu.cmu.tetradapp.model.GridSearchModel;
Expand All @@ -30,10 +34,7 @@
import javax.swing.table.TableRowSorter;
import javax.swing.text.BadLocationException;
import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -155,8 +156,6 @@ public GridSearchEditor(GridSearchModel model) {
model.getParameters().set("algcomparisonSaveGraphs", model.getParameters().getBoolean("algcomparisonSaveGraphs", true));
model.getParameters().set("algcomparisonSaveCPDAGs", model.getParameters().getBoolean("algcomparisonSaveCPDAGs", false));
model.getParameters().set("algcomparisonSavePAGs", model.getParameters().getBoolean("algcomparisonSavePAGs", false));
model.getParameters().set("algcomparisonShowAlgorithmIndices", model.getParameters().getBoolean("algcomparisonShowAlgorithmIndices", true));
model.getParameters().set("algcomparisonShowSimulationIndices", model.getParameters().getBoolean("algcomparisonShowSimulationIndices", true));
model.getParameters().set("algcomparisonSortByUtility", model.getParameters().getBoolean("algcomparisonSortByUtility", false));
model.getParameters().set("algcomparisonShowUtilities", model.getParameters().getBoolean("algcomparisonShowUtilities", false));
model.getParameters().set("algcomparisonSetAlgorithmKnowledge", model.getParameters().getBoolean("algcomparisonSetAlgorithmKnowledge", false));
Expand Down Expand Up @@ -1299,16 +1298,6 @@ private void addComparisonTab(JTabbedPane tabbedPane) {
horiz2c.add(Box.createHorizontalGlue());
horiz2c.add(getBooleanSelectionBox("algcomparisonSavePAGs", model.getParameters(), false));

Box horiz3 = Box.createHorizontalBox();
horiz3.add(new JLabel("Show Algorithm Indices:"));
horiz3.add(Box.createHorizontalGlue());
horiz3.add(getBooleanSelectionBox("algcomparisonShowAlgorithmIndices", model.getParameters(), false));

Box horiz4 = Box.createHorizontalBox();
horiz4.add(new JLabel("Show Simulation Indices:"));
horiz4.add(Box.createHorizontalGlue());
horiz4.add(getBooleanSelectionBox("algcomparisonShowSimulationIndices", model.getParameters(), false));

Box horiz4a = Box.createHorizontalBox();
horiz4a.add(new JLabel("Sort by Utility:"));
horiz4a.add(Box.createHorizontalGlue());
Expand Down Expand Up @@ -1354,8 +1343,6 @@ private void addComparisonTab(JTabbedPane tabbedPane) {
parameterBox.add(horiz2);
parameterBox.add(horiz2b);
parameterBox.add(horiz2c);
parameterBox.add(horiz3);
parameterBox.add(horiz4);
parameterBox.add(horiz4a);
parameterBox.add(horiz4b);
parameterBox.add(horiz4c);
Expand Down Expand Up @@ -1435,6 +1422,41 @@ public void watch() {

try {
model.runComparison(ps);

String resultsPath = model.getResultsPath();

if (resultsPath != null && simulationChoiceTextArea != null) {
// Write contents of simulation text area to a file at resultsPath + "/simulation.txt"
try (PrintWriter writer = new PrintWriter(resultsPath + "/simulation.txt")) {
writer.println(simulationChoiceTextArea.getText());
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}

// Write contents of algorithm text area to a file at resultsPath + "/algorithm.txt"
try (PrintWriter writer = new PrintWriter(resultsPath + "/algorithm.txt")) {
writer.println(algorithmChoiceTextArea.getText());
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}

// Write contents of table columns text area to a file at resultsPath + "/tableColumns.txt"
try (PrintWriter writer = new PrintWriter(resultsPath + "/tableColumns.txt")) {
writer.println(tableColumnsChoiceTextArea.getText());
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}

// Write contents of verbose output text area to a file at resultsPath + "/verboseOutput.txt"
try (PrintWriter writer = new PrintWriter(resultsPath + "/verboseOutput.txt")) {
writer.println(verboseOutputTextArea.getText());
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}


}

} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -2032,13 +2054,34 @@ private void setSimulationText() {
Simulations selectedSimulations = model.getSelectedSimulations();
List<Simulation> simulations = selectedSimulations.getSimulations();

DataSet dataSet = model.getSuppliedData();

if (dataSet != null) {
simulationChoiceTextArea.append("A data set has been supplied with " + dataSet.getNumColumns() + " variables and " + dataSet.getNumRows() + " rows.");
simulationChoiceTextArea.append("\n\nThe variables for the data are as follow: " + dataSet.getVariableNames() + "\n\n");
}

Graph graph = model.getSuppliedGraph();

if (graph != null) {
simulationChoiceTextArea.append("A graph has been supplied with " + graph.getNumNodes() + " nodes and " + graph.getNumEdges() + " edges.");
simulationChoiceTextArea.append("\n\nThe nodes for the graph are as follow: " + graph.getNodeNames() + "\n\n");
}

Knowledge knowledge = model.getKnowledge();

if (knowledge != null) {
simulationChoiceTextArea.append("Knowledge has been set, as follows:");
simulationChoiceTextArea.append("\n\n" + knowledge + "\n\n");
}

if (simulations.isEmpty()) {
simulationChoiceTextArea.append("""
** No simulations have been selected. Please select at least one simulation using the Add Simulation button below. **
""");
return;
} else if (simulations.size() == 1) {
simulationChoiceTextArea.setText("""
simulationChoiceTextArea.append("""
The following simulation has been selected. This simulations will be run with the selected algorithms.
""");
Expand All @@ -2049,7 +2092,7 @@ private void setSimulationText() {
simulationChoiceTextArea.append("Selected graph type = " + (randomGraphClass == null ? "None" : randomGraphClass.getSimpleName() + "\n"));
simulationChoiceTextArea.append("Selected simulation type = " + simulationClass.getSimpleName() + "\n");
} else {
simulationChoiceTextArea.setText("""
simulationChoiceTextArea.append("""
The following simulations have been selected. These simulations will be run with the selected algorithms.
""");
for (int i = 0; i < simulations.size(); i++) {
Expand All @@ -2075,7 +2118,7 @@ private void setAlgorithmText() {
""");
return;
} else if (selectedAlgorithms.size() == 1) {
algorithmChoiceTextArea.setText("""
algorithmChoiceTextArea.append("""
The following algorithm has been selected. This algorithm will be run with the selected simulations.
""");
Expand All @@ -2092,7 +2135,7 @@ private void setAlgorithmText() {
}

} else {
algorithmChoiceTextArea.setText("""
algorithmChoiceTextArea.append("""
The following algorithms have been selected. These algorithms will be run with the selected simulations.
""");
for (int i = 0; i < selectedAlgorithms.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public void actionPerformed(ActionEvent e) {
File file = chooser.getSelectedFile();

if (file == null) {
System.out.println("File was null.");
JOptionPane.showMessageDialog((Component) this.graphEditable,
"No file was selected.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public void actionPerformed(ActionEvent e) {
File file = chooser.getSelectedFile();

if (file == null) {
System.out.println("File was null.");
JOptionPane.showMessageDialog((Component) this.graphEditable,
"No file was selected.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void actionPerformed(ActionEvent e) {
File file = chooser.getSelectedFile();

if (file == null) {
System.out.println("File was null.");
JOptionPane.showMessageDialog((Component) this.graphEditable,
"No file was selected.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void actionPerformed(ActionEvent e) {
File file = chooser.getSelectedFile();

if (file == null) {
System.out.println("File was null.");
JOptionPane.showMessageDialog((Component) this.graphEditable,
"No file was selected.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public void actionPerformed(ActionEvent e) {
File file = chooser.getSelectedFile();

if (file == null) {
System.out.println("File was null.");
JOptionPane.showMessageDialog((Component) this.graphEditable,
"No file was selected.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public LogisticRegressionEditor(LogisticRegressionRunner regressionRunner) {
LayoutUtil.fruchtermanReingoldLayout(outGraph);
workbench.setGraph(outGraph);
String message = this.modelParameters.getText();
TetradLogger.getInstance().forceLogMessage(message);
TetradLogger.getInstance().log(message);
});
}

Expand Down
Loading

0 comments on commit 6aa0340

Please sign in to comment.