Skip to content

Commit

Permalink
Merge pull request #1318 from cmu-phil/joe-knowledge-fix
Browse files Browse the repository at this point in the history
Knowledge and some other fixes.
  • Loading branch information
jdramsey authored Jan 25, 2021
2 parents 6cb45f4 + b0129b4 commit ce4d3f3
Show file tree
Hide file tree
Showing 38 changed files with 775 additions and 605 deletions.
66 changes: 64 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 @@ -4789,6 +4793,40 @@ <h3 id="selfLoopCoef" class="parameter_description">selfLoopCoef</h3>
<li>Value Type: <span id="selfLoopCoef_value_type">Double</span></li>
</ul>

<h3 id="semBicRule" class="parameter_description">semBicRule</h3>
<ul class="parameter_description_list">
<li>Short Description: <span id="semBicRule_short_desc">1 = Chickering, 2 = Nandy, 3 = High Dimensional</span>
</li>
<li>Long Description: <span id="semBicRule_long_desc">The rule used for calculating a score.
The Chickering Rule is the local scoring consistency criterion in Chickering's formulation of
GES, though we allow a multiplier on the penalty term called "penalty discount".
The Nandy et al. rule is a reformultion of the Chickering rule using a single calculation
of a partial correlation in place of the likelihood difference. For the high-dimensional score
we use the formulation in Gao and Chen, described on the Wikipedia page for Bayesian Information
Criterion, which is a pseudo-BIC formulation. It has two parameters, gamma (> 0) and omega (>= 1).
We fix gamma at 0.25 and allow omega to be adjusted using the "penalty discount" parameter.
In all cases we include a structure prior, which amounts to a prior on the number of
parents in any scoring, a binomial formula.</span>
</li>
<li>Default Value: <span id="semBicRule_default_value">1</span></li>
<li>Lower Bound: <span id="semBicRule_lower_bound">1</span></li>
<li>Upper Bound: <span id="semBicRule_upper_bound">4</span></li>
<li>Value Type: <span id="semBicRule_value_type">Integer</span></li>
</ul>

<h3 id="semBicStructurePrior" class="parameter_description">semBicStructurePrior</h3>
<ul class="parameter_description_list">
<li>Short Description: <span id="semBicStructurePrior_short_desc">Structure Prior for SEM BIC (default 0)</span>
</li>
<li>Long Description: <span id="semBicStructurePrior_long_desc">Structure prior; default is 0 (turned off); may be
any positive number otherwise</span>
</li>
<li>Default Value: <span id="semBicStructurePrior_default_value">0</span></li>
<li>Lower Bound: <span id="semBicStructurePrior_lower_bound">0</span></li>
<li>Upper Bound: <span id="semBicStructurePrior_upper_bound">Infinity</span></li>
<li>Value Type: <span id="semBicStructurePrior_value_type">Double</span></li>
</ul>

<h3 id="skipNumRecords" class="parameter_description">skipNumRecords</h3>
<ul class="parameter_description_list">
<li>Short Description: <span id="skipNumRecords_short_desc">Number of records that should be skipped between recordings (min = 0)</span>
Expand Down Expand Up @@ -4858,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 @@ -4914,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
6 changes: 6 additions & 0 deletions tetrad-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
<artifactId>data-reader</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>


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 ce4d3f3

Please sign in to comment.