Skip to content

Commit

Permalink
Also pulling over a fix for an annoying interface bug, in the simulat…
Browse files Browse the repository at this point in the history
…ion editor, where if you click the simulate bug twice you don't get a news simulation. You have to select a new model type. Fixed this. Affected several files.

For FGES, decided to add the turning and tdepth parameters. Adjusted the manual.
  • Loading branch information
jdramsey committed Jan 8, 2021
1 parent a9f4dde commit 1f2d1cd
Show file tree
Hide file tree
Showing 31 changed files with 250 additions and 121 deletions.
32 changes: 30 additions & 2 deletions docs/manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2253,8 +2253,12 @@ <h4>Output Format</h4>
<h4>Parameters</h4>

<p><a href="#samplePrior">samplePrior</a>, <a href="#structurePrior">structurePrior</a>, <a href="#penaltyDiscount">penaltyDiscount</a>,
<a href="#symmetricFirstStep">symmetricFirstStep</a>, <a href="#faithfulnessAssumed">faithfulnessAssumed</a>, <a
href="#maxDegree">maxDegree</a></p>
<a href="#symmetricFirstStep">symmetricFirstStep</a>,
<a href="#faithfulnessAssumed">faithfulnessAssumed</a>,
<a href="#maxDegree">maxDegree</a>
<a href="#tDepth">tDepth</a>
<a href="#turning">turning</a>
</p>


<h3>The IMaGES Discrete Algorithm (BDeu Score)</h3>
Expand Down Expand Up @@ -4892,6 +4896,19 @@ <h3 id="targetName" class="parameter_description">targetName</h3>
<li>Value Type: <span id="targetName_value_type">String</span></li>
</ul>

<h3 id="tDepth" class="parameter_description">tDepth</h3>
<ul class="parameter_description_list">
<li>Short Description: <span id="tDepth_short_desc">"T-Depth", the maximum number of neighbors considered in power set calculations</span>
</li>
<li>Long Description: <span id="tDepth_long_desc">For FGES, this is the maximum number of T-neighbors or H-complement-neights
that are considered in any scoring step. Default is -1 (unlimited).</span>
</li>
<li>Default Value: <span id="tDepth_default_value">-1</span></li>
<li>Lower Bound: <span id="tDepth_lower_bound">-1</span></li>
<li>Upper Bound: <span id="tDepth_upper_bound">2147483647</span></li>
<li>Value Type: <span id="tDepth_value_type">Integer</span></li>
</ul>

<h3 id="thr" class="parameter_description">thr</h3>
<ul class="parameter_description_list">
<li>Short Description: <span id="thr_short_desc">THR parameter (GLASSO) (min = 0.0)</span></li>
Expand Down Expand Up @@ -4948,6 +4965,17 @@ <h3 id="twoCycleAlpha" class="parameter_description">twoCycleAlpha</h3>
<li>Value Type: <span id="twoCycleAlpha_value_type">Double</span></li>
</ul>

<h3 id="turning" class="parameter_description">turning</h3>
<ul class="parameter_description_list">
<li>Short Description: <span id="turning_short_desc">Yes, if the turning step should be included</span>
</li>
<li>Long Description: <span id="turning_long_desc">Performs a turning step similar to (but not quite teh same as) that of PCALG's GES. The search in FGES repeats the sequence FES followed by BES, twice. The turning step is inserted between FGES and GES, if the user opts to use it. It is not used by default. The turning step is still somewhat experimental and may change in the future.</span></li>
<li>Default Value: <span id="turning_default_value">false</span></li>
<li>Lower Bound: <span id="turning_lower_bound"></span></li> g
<li>Upper Bound: <span id="turning_upper_bound"></span></li>
<li>Value Type: <span id="turning_value_type">Boolean</span></li>
</ul>

<h3 id="upperBound" class="parameter_description">upperBound</h3>
<ul class="parameter_description_list">
<li>Short Description: <span id="upperBound_short_desc">Upper bound cutoff threshold</span></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import edu.cmu.tetradapp.ui.PaddingPanel;
import edu.cmu.tetradapp.util.ParameterComponents;
import edu.cmu.tetradapp.util.WatchedProcess;
import org.jetbrains.annotations.NotNull;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
Expand All @@ -68,20 +70,20 @@ public class ParameterTab extends JPanel {
private static final long serialVersionUID = 7074205549192562786L;

private static final String[] GRAPH_ITEMS = new String[]{
GraphTypes.RANDOM_FOWARD_DAG,
GraphTypes.SCALE_FREE_DAG,
GraphTypes.CYCLIC_CONSTRUCTED_FROM_SMALL_LOOPS,
GraphTypes.RANDOM_ONE_FACTOR_MIM,
GraphTypes.RANDOM_TWO_FACTOR_MIM
GraphTypes.RANDOM_FOWARD_DAG,
GraphTypes.SCALE_FREE_DAG,
GraphTypes.CYCLIC_CONSTRUCTED_FROM_SMALL_LOOPS,
GraphTypes.RANDOM_ONE_FACTOR_MIM,
GraphTypes.RANDOM_TWO_FACTOR_MIM
};

private static final String[] SOURCE_GRAPH_ITEMS = {
SimulationTypes.BAYS_NET,
SimulationTypes.STRUCTURAL_EQUATION_MODEL,
SimulationTypes.LINEAR_FISHER_MODEL,
SimulationTypes.LEE_AND_HASTIE,
SimulationTypes.CONDITIONAL_GAUSSIAN,
SimulationTypes.TIME_SERIES
SimulationTypes.BAYS_NET,
SimulationTypes.STRUCTURAL_EQUATION_MODEL,
SimulationTypes.LINEAR_FISHER_MODEL,
SimulationTypes.LEE_AND_HASTIE,
SimulationTypes.CONDITIONAL_GAUSSIAN,
SimulationTypes.TIME_SERIES
};

private static final JLabel NO_PARAM_LBL = new JLabel("No parameters to edit");
Expand Down Expand Up @@ -123,6 +125,16 @@ private void initComponents() {
}

private void refreshParameters() {
RandomGraph randomGraph = newRandomGraph();
newSimulation(randomGraph);

showParameters();

firePropertyChange("refreshParameters", null, null);
}

@NotNull
private RandomGraph newRandomGraph() {
RandomGraph randomGraph = (simulation.getSourceGraph() == null)
? new SingleGraph(new EdgeListGraph())
: new SingleGraph(simulation.getSourceGraph());
Expand Down Expand Up @@ -151,7 +163,10 @@ private void refreshParameters() {
throw new IllegalArgumentException("Unrecognized simulation type: " + graphItem);
}
}
return randomGraph;
}

private void newSimulation(RandomGraph randomGraph) {
if (!simulation.isFixedSimulation()) {
String simulationItem = simulationsDropdown.getItemAt(simulationsDropdown.getSelectedIndex());
simulation.getParams().set("simulationsDropdownPreference", simulationItem);
Expand Down Expand Up @@ -209,10 +224,6 @@ private void refreshParameters() {
}
}
}

showParameters();

firePropertyChange("refreshParameters", null, null);
}

private void showParameters() {
Expand Down Expand Up @@ -289,7 +300,7 @@ private Box createSimulationOptionBox() {
simulation.getParams().getString("simulationsDropdownPreference", simulationItems[0]));
simulationsDropdown.addActionListener(e -> refreshParameters());

simOptBox.add(createLabeledComponent("For a New Simulation, Select (or re-select) Type: ", simulationsDropdown));
simOptBox.add(createLabeledComponent("Type of Simulation: ", simulationsDropdown));
simOptBox.add(Box.createVerticalStrut(20));

return simOptBox;
Expand All @@ -300,7 +311,9 @@ private void simulate() {
@Override
public void watch() {
try {
simulation.getSimulation().createData(simulation.getParams());
RandomGraph randomGraph = newRandomGraph();
newSimulation(randomGraph);
simulation.getSimulation().createData(simulation.getParams(), false);

firePropertyChange("modelChanged", null, null);
} catch (Exception exception) {
Expand Down Expand Up @@ -339,27 +352,27 @@ private String[] getSimulationItems(Simulation simulation) {
if (simulation.isFixedSimulation()) {
if (simulation.getSimulation() instanceof BayesNetSimulation) {
items = new String[]{
SimulationTypes.BAYS_NET
SimulationTypes.BAYS_NET
};
} else if (simulation.getSimulation() instanceof SemSimulation) {
items = new String[]{
SimulationTypes.STRUCTURAL_EQUATION_MODEL
SimulationTypes.STRUCTURAL_EQUATION_MODEL
};
} else if (simulation.getSimulation() instanceof LinearFisherModel) {
items = new String[]{
SimulationTypes.LINEAR_FISHER_MODEL
SimulationTypes.LINEAR_FISHER_MODEL
};
} else if (simulation.getSimulation() instanceof StandardizedSemSimulation) {
items = new String[]{
SimulationTypes.STANDARDIZED_STRUCTURAL_EQUATION_MODEL
SimulationTypes.STANDARDIZED_STRUCTURAL_EQUATION_MODEL
};
} else if (simulation.getSimulation() instanceof GeneralSemSimulation) {
items = new String[]{
SimulationTypes.GENERAL_STRUCTURAL_EQUATION_MODEL
SimulationTypes.GENERAL_STRUCTURAL_EQUATION_MODEL
};
} else if (simulation.getSimulation() instanceof LoadContinuousDataAndGraphs) {
items = new String[]{
SimulationTypes.LOADED_FROM_FILES
SimulationTypes.LOADED_FROM_FILES
};
} else {
throw new IllegalStateException("Not expecting that model type: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void createSimulation() {
// Every time the users click the Simulate button, new data needs to be created
// regardless of already created data - Zhou
//if (simulation.getNumDataModels() == 0) {
simulation.createData(parameters);
simulation.createData(parameters, false);
//}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public enum ComparisonGraph {
private String resultsPath = null;
private boolean parallelized = false;
private boolean savePatterns = false;
private boolean saveData = true;
private boolean savePags = false;
// private boolean saveTrueDags = false;
private ArrayList<String> dirs = null;
Expand Down Expand Up @@ -264,7 +265,7 @@ public void compareFromSimulations(String resultsPath, Simulations simulations,
List<SimulationWrapper> wrappers = getSimulationWrappers(simulation, parameters);

for (SimulationWrapper wrapper : wrappers) {
wrapper.createData(wrapper.getSimulationSpecificParameters());
wrapper.createData(wrapper.getSimulationSpecificParameters(), true);
simulationWrappers.add(wrapper);
}
}
Expand Down Expand Up @@ -543,7 +544,7 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param
parameters.set(param, simulationWrapper.getValue(param));
}

simulationWrapper.createData(simulationWrapper.getSimulationSpecificParameters());
simulationWrapper.createData(simulationWrapper.getSimulationSpecificParameters(), false);

File subdir = dir;
if (simulationWrappers.size() > 1) {
Expand Down Expand Up @@ -585,11 +586,13 @@ public void saveToFiles(String dataPath, Simulation simulation, Parameters param

GraphUtils.saveGraph(graph, file2, false);

File file = new File(dir2, "data." + (j + 1) + ".txt");
Writer out = new FileWriter(file);
DataModel dataModel = (DataModel) simulationWrapper.getDataModel(j);
DataWriter.writeRectangularData((DataSet) dataModel, out, '\t');
out.close();
if (isSaveData()) {
File file = new File(dir2, "data." + (j + 1) + ".txt");
Writer out = new FileWriter(file);
DataModel dataModel = (DataModel) simulationWrapper.getDataModel(j);
DataWriter.writeRectangularData((DataSet) dataModel, out, '\t');
out.close();
}

if (isSavePatterns()) {
File file3 = new File(dir3, "pattern." + (j + 1) + ".txt");
Expand Down Expand Up @@ -1148,6 +1151,20 @@ public void setSavePags(boolean savePags) {
// this.saveTrueDags = saveTrueDags;
// }

/**
* @return True if patterns should be saved out.
*/
public boolean isSaveData() {
return this.saveData;
}

/**
* @return True if patterns should be saved out.
*/
public void setSaveData(boolean saveData) {
this.saveData = saveData;
}

/**
* @return True iff tables should be tab delimited (e.g. for easy pasting
* into Excel).
Expand Down Expand Up @@ -1939,7 +1956,6 @@ public AlgorithmWrapper getAlgorithmWrapper() {
}

private class SimulationWrapper implements Simulation {

static final long serialVersionUID = 23L;
private Simulation simulation;
private List<Graph> graphs;
Expand All @@ -1955,12 +1971,12 @@ public SimulationWrapper(Simulation simulation, Parameters parameters) {
}

@Override
public void createData(Parameters parameters) {
simulation.createData(parameters);
public void createData(Parameters parameters, boolean newModel) {
simulation.createData(parameters, newModel);
this.graphs = new ArrayList<>();
this.dataModels = new ArrayList<>();
for (int i = 0; i < simulation.getNumDataModels(); i++) {
this.graphs.add(new EdgeListGraph(simulation.getTrueGraph(i)));
this.graphs.add(simulation.getTrueGraph(i));
this.dataModels.add(simulation.getDataModel(i));
}
}
Expand Down
Loading

0 comments on commit 1f2d1cd

Please sign in to comment.