Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final merge for 7.1.3 #1443

Merged
merged 6 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7392,7 +7392,7 @@ <h3 class="parameter_description" id="ebicGamma">ebicGamma</h3>
class="parameter_description_list">
<li>Short Description: <span
id="percentResampleSize_short_desc">The percentage of resample size
(min = 0.1)</span></li>
(min = 10%)</span></li>
<li>Long Description: <span
id="percentResampleSize_long_desc"> This parameter specifies the
percentage of records in the bootstrap (as a percentage of the total
Expand All @@ -7401,9 +7401,9 @@ <h3 class="parameter_description" id="ebicGamma">ebicGamma</h3>
id="percentResampleSize_default_value">90</span></li>
<li>Lower
Bound: <span
id="percentResampleSize_lower_bound">-2147483648</span></li>
id="percentResampleSize_lower_bound">10</span></li>
<li>Upper Bound: <span
id="percentResampleSize_upper_bound">2147483647</span></li>
id="percentResampleSize_upper_bound">100</span></li>
<li>Value
Type: <span id="percentResampleSize_value_type">Integer</span></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public GraphFileMenu(GraphEditable editable, JComponent comp, boolean saveOnly)
load.add(new LoadGraph(editable, "XML..."));
load.add(new LoadGraphTxt(editable, "Text..."));
load.add(new LoadGraphJson(editable, "Json..."));
load.add(new LoadGraphPcalg(editable, "PCALG..."));
}

JMenu save = new JMenu("Save...");
Expand All @@ -55,6 +56,7 @@ public GraphFileMenu(GraphEditable editable, JComponent comp, boolean saveOnly)
save.add(new SaveGraph(editable, "Json...", SaveGraph.Type.json));
save.add(new SaveGraph(editable, "R...", SaveGraph.Type.r));
save.add(new SaveGraph(editable, "Dot...", SaveGraph.Type.dot));
save.add(new SaveGraph(editable, "PCALG...", SaveGraph.Type.pcalg));

addSeparator();
add(new SaveComponentImage(comp, "Save Graph Image..."));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
///////////////////////////////////////////////////////////////////////////////
// For information as to what this class does, see the Javadoc, below. //
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, //
// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard //
// Scheines, Joseph Ramsey, and Clark Glymour. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
///////////////////////////////////////////////////////////////////////////////

package edu.cmu.tetradapp.editor;

import edu.cmu.tetrad.graph.Graph;
import edu.cmu.tetrad.graph.GraphUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.prefs.Preferences;

/**
* @author Joseph Ramsey [email protected]
*/
class LoadGraphPcalg extends AbstractAction {

/**
* The component whose image is to be saved.
*/
private final GraphEditable graphEditable;

public LoadGraphPcalg(GraphEditable graphEditable, String title) {
super(title);

if (graphEditable == null) {
throw new NullPointerException("Component must not be null.");
}

this.graphEditable = graphEditable;
}

/**
* Performs the action of loading a session from a file.
*/
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = LoadGraphPcalg.getJFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showOpenDialog((Component) this.graphEditable);

File file = chooser.getSelectedFile();

if (file == null) {
System.out.println("File was null.");
return;
}

Preferences.userRoot().put("fileSaveLocation", file.getParent());

Graph graph = GraphUtils.loadGraphPcalg(file);
GraphUtils.circleLayout(graph, 200, 200, 150);
this.graphEditable.setGraph(graph);
}

private static JFileChooser getJFileChooser() {
JFileChooser chooser = new JFileChooser();
String sessionSaveLocation =
Preferences.userRoot().get("fileSaveLocation", "");
chooser.setCurrentDirectory(new File(sessionSaveLocation));
chooser.resetChoosableFileFilters();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
return chooser;
}
}



19 changes: 18 additions & 1 deletion tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/SaveGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class SaveGraph extends AbstractAction {
*/
private final Type type;

public enum Type {text, xml, json, r, dot}
public enum Type {text, xml, json, r, dot, pcalg}

public SaveGraph(GraphEditable graphEditable, String title, Type type) {
super(title);
Expand Down Expand Up @@ -130,6 +130,23 @@ public void actionPerformed(ActionEvent e) {
try {
String text = GraphUtils.graphToDot(graph);

PrintWriter out = new PrintWriter(file);
out.println(text);
Preferences.userRoot().put("fileSaveLocation", file.getParent());
out.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
throw new RuntimeException("Not a directed graph.", e1);
} catch (IllegalArgumentException e1) {

// Probably not a directed graph.
JOptionPane.showMessageDialog(getGraphEditable().getWorkbench(), e1.getMessage());
}
}else if (this.type == Type.pcalg) {
File file = EditorUtils.getSaveFile("graph", "pcalg.csv", parent, false, this.title);
try {
String text = GraphUtils.graphToPcalg(graph);

PrintWriter out = new PrintWriter(file);
out.println(text);
Preferences.userRoot().put("fileSaveLocation", file.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private Box getTableDisplay() {

private TextTable getTextTable(DataSet dataSet, NumberFormat nf) {
TextTable table = new TextTable(dataSet.getNumRows() + 2, dataSet.getNumColumns() + 1);
table.setTabDelimited(true);
table.setDelimiter(TextTable.Delimiter.TAB);
table.setToken(0, 0, "Run");

for (int j = 0; j < dataSet.getNumColumns(); j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,35 @@ public static IntTextField getIntTextField(String parameter, Parameters paramete
return field;
}

public static LongTextField getLongTextField(String parameter, Parameters parameters,
long defaultValue, double lowerBound, double upperBound) {
LongTextField field = new LongTextField(parameters.getLong(parameter, defaultValue), 10);

field.setFilter((value, oldValue) -> {
if (value == field.getValue()) {
return oldValue;
}

if (value < lowerBound) {
return oldValue;
}

if (value > upperBound) {
return oldValue;
}

try {
parameters.set(parameter, value);
} catch (Exception e) {
// Ignore.
}

return value;
});

return field;
}

public static Box getBooleanSelectionBox(String parameter, Parameters parameters, boolean defaultValue) {
Box selectionBox = Box.createHorizontalBox();

Expand Down Expand Up @@ -203,6 +232,10 @@ private static Box createParameterComponent(String parameter, Parameters paramet
int lowerBoundInt = paramDesc.getLowerBoundInt();
int upperBoundInt = paramDesc.getUpperBoundInt();
component = ParameterComponents.getIntTextField(parameter, parameters, (Integer) defaultValue, lowerBoundInt, upperBoundInt);
} else if (defaultValue instanceof Long) {
int lowerBoundInt = paramDesc.getLowerBoundInt();
int upperBoundInt = paramDesc.getUpperBoundInt();
component = ParameterComponents.getLongTextField(parameter, parameters, (Long) defaultValue, lowerBoundInt, upperBoundInt);
} else if (defaultValue instanceof Boolean) {
component = ParameterComponents.getBooleanSelectionBox(parameter, parameters, (Boolean) defaultValue);
} else if (defaultValue instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,10 @@ private void edgeClicked(Object source, MouseEvent e) {
graphEdge.setSelected(true);
}
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}
}

private void nodeClicked(Object source, MouseEvent e) {
Expand All @@ -1814,6 +1818,10 @@ private void nodeClicked(Object source, MouseEvent e) {
selectConnectingEdges();
fireNodeSelection();
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}
}

private void reorientEdge(Object source, MouseEvent e) {
Expand All @@ -1828,7 +1836,7 @@ private void reorientEdge(Object source, MouseEvent e) {
if (e.isShiftDown()) {
if (AbstractWorkbench.distance(point, pointA) < endpointRadius) {
toggleEndpoint(graphEdge, 1);
firePropertyChange("modelChanged", null, null);
fireModelChanged();
} else if (AbstractWorkbench.distance(point, pointB) < endpointRadius) {
toggleEndpoint(graphEdge, 2);
firePropertyChange("modelChanged", null, null);
Expand All @@ -1842,6 +1850,14 @@ private void reorientEdge(Object source, MouseEvent e) {
firePropertyChange("modelChanged", null, null);
}
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}
}

private void fireModelChanged() {
firePropertyChange("modelChanged", null, null);
}

private void handleMousePressed(MouseEvent e) {
Expand Down Expand Up @@ -1894,6 +1910,10 @@ private void handleMousePressed(MouseEvent e) {

break;
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}
}

private void launchPopup(MouseEvent e) {
Expand Down Expand Up @@ -1935,6 +1955,10 @@ private void handleMouseReleased(MouseEvent e) {
finishEdge();
break;
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}
}

private void handleMouseDragged(MouseEvent e) {
Expand All @@ -1960,6 +1984,10 @@ private void handleMouseDragged(MouseEvent e) {
dragNewEdge(source, newPoint);
break;
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}
}

private void handleMouseEntered(MouseEvent e) {
Expand Down Expand Up @@ -2245,17 +2273,28 @@ private void directEdge(IDisplayEdge graphEdge, int endpoint) {

try {
boolean added = getGraph().addEdge(newEdge);

if (!added) {
getGraph().addEdge(edge);
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
"Reorienting that edge would violate graph constraints.");
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}
} catch (IllegalArgumentException e) {
getGraph().addEdge(edge);

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}

JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
"Reorienting that edge would violate graph constraints.");
}

revalidate();
repaint();
}

Expand Down Expand Up @@ -2299,13 +2338,23 @@ private void toggleEndpoint(IDisplayEdge graphEdge, int endpointNumber) {
boolean added = getGraph().addEdge(newEdge);
if (!added) {
getGraph().addEdge(edge);

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}

return;
}
} catch (IllegalArgumentException e) {
getGraph().addEdge(edge);
return;
}

if (graph.getGraphType() == EdgeListGraph.GraphType.PAG) {
GraphUtils.addPagColoring(new EdgeListGraph(graph));
}

revalidate();
repaint();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*/
public class Comparison {

private boolean parallelized = true;
private boolean parallelized = false;

public void setParallelized(boolean parallelized) {
this.parallelized = parallelized;
Expand Down Expand Up @@ -1467,7 +1467,7 @@ private void printStats(double[][][] statTables, Statistics statistics, Mode mod
+ (isShowUtilities() ? 1 : 0);

TextTable table = new TextTable(rows, cols);
table.setTabDelimited(isTabDelimitedTables());
table.setDelimiter(isTabDelimitedTables() ? TextTable.Delimiter.TAB : TextTable.Delimiter.JUSTIFIED);

int initialColumn = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ private void printStats(double[][][] statTables, Statistics statistics, Mode mod
+ (isShowUtilities() ? 1 : 0);

TextTable table = new TextTable(rows, cols);
table.setTabDelimited(isTabDelimitedTables());
table.setDelimiter(isTabDelimitedTables() ? TextTable.Delimiter.TAB : TextTable.Delimiter.JUSTIFIED);

int initialColumn = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import java.util.ArrayList;
import java.util.List;

/**
* Wrapper for CCI Score.
*
* @author jdramsey
*/
@edu.cmu.tetrad.annotation.Score(name = "CCI-Score (Conditional Correlation Independence Score)", command = "cci-score", dataType = DataType.Continuous)
@General
@Experimental
///**
// * Wrapper for CCI Score.
// *
// * @author jdramsey
// */
//@edu.cmu.tetrad.annotation.Score(name = "CCI-Score (Conditional Correlation Independence Score)", command = "cci-score", dataType = DataType.Continuous)
//@General
//@Experimental
public class CciScore implements ScoreWrapper {

static final long serialVersionUID = 23L;
Expand Down
Loading