use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class MimSearchEditor2 method getIndTestParamBox.
/**
* Factory to return the correct param editor for independence test params.
* This will go in a little box in the search editor.
*/
private JComponent getIndTestParamBox(Parameters params) {
if (params == null) {
throw new NullPointerException();
}
if (params instanceof Parameters) {
MimRunner runner = getMimRunner();
params.set("varNames", runner.getParams().get("varNames", null));
DataModel dataModel = runner.getData();
if (dataModel instanceof DataSet) {
DataSet data = (DataSet) runner.getData();
boolean discrete = data.isDiscrete();
return new BuildPureClustersIndTestParamsEditor2(params, discrete);
} else if (dataModel instanceof ICovarianceMatrix) {
return new BuildPureClustersIndTestParamsEditor2(params, false);
}
}
if (params instanceof Parameters) {
MimRunner runner = getMimRunner();
params.set("varNames", runner.getParams().get("varNames", null));
boolean discreteData = false;
if (runner.getData() instanceof DataSet) {
discreteData = ((DataSet) runner.getData()).isDiscrete();
}
return new PurifyIndTestParamsEditor(params, discreteData);
}
if (params instanceof Parameters) {
MimRunner runner = getMimRunner();
params.set("varNames", runner.getParams().get("varNames", null));
return new MimBuildIndTestParamsEditor(params);
}
throw new IllegalArgumentException("Unrecognized Parameters: " + params.getClass());
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class MbSearchEditor method addSpecialMenus.
protected void addSpecialMenus(JMenuBar menuBar) {
JMenu test = new JMenu("Independence");
menuBar.add(test);
IndTestMenuItems.addIndependenceTestChoices(test, this);
if (getAlgorithmRunner() instanceof MbfsRunner) {
JMenu graph = new JMenu("Graph");
JMenuItem showDags = new JMenuItem("Show DAG's Consistent with forbid_latent_common_causes");
// JMenuItem meekOrient = new JMenuItem("Meek Orientation");
JMenuItem gesOrient = new JMenuItem("Global Score-based Reorientation");
JMenuItem nextGraph = new JMenuItem("Next Graph");
JMenuItem previousGraph = new JMenuItem("Previous Graph");
graph.add(new GraphPropertiesAction(getWorkbench()));
graph.add(new PathsAction(getWorkbench()));
// graph.add(new DirectedPathsAction(getWorkbench()));
// graph.add(new TreksAction(getWorkbench()));
// graph.add(new AllPathsAction(getWorkbench()));
// graph.add(new NeighborhoodsAction(getWorkbench()));
graph.addSeparator();
// graph.add(meekOrient);
graph.add(gesOrient);
graph.addSeparator();
graph.add(previousGraph);
graph.add(nextGraph);
graph.addSeparator();
graph.add(showDags);
menuBar.add(graph);
showDags.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AlgorithmRunner runner = getAlgorithmRunner();
if (!(runner instanceof MbfsRunner)) {
return;
}
MbfsRunner mbRunner = (MbfsRunner) runner;
final Mbfs search = mbRunner.getMbFanSearch();
if (search == null) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "The search was not stored.");
return;
}
MbPatternDisplay display = new MbPatternDisplay(search);
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), display, "MB DAG's Consistent with forbid_latent_common_causes", JOptionPane.PLAIN_MESSAGE);
}
});
// meekOrient.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// ImpliedOrientation rules = getAlgorithmRunner().getMeekRules();
// rules.setKnowledge((IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2()));
// rules.orientImplied(getGraph());
// getWorkbench().setGraph(getGraph());
// }
// });
gesOrient.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DataModel dataModel = getAlgorithmRunner().getDataModel();
final Graph graph = SearchGraphUtils.reorient(getGraph(), dataModel, getKnowledge());
getGraphHistory().add(graph);
getWorkbench().setGraph(graph);
firePropertyChange("modelChanged", null, null);
}
});
}
// if (getAlgorithmRunner().supportsKnowledge()) {
// menuBar.add(new Knowledge2Menu(this));
// }
menuBar.add(new LayoutMenu(this));
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class PcSearchParamEditor method setup.
public void setup() {
/*
The variable names from the object being searched over (usually data).
*/
List<String> varNames = (List<String>) params.get("varNames", null);
DataModel dataModel1 = null;
Graph graph = null;
for (Object parentModel1 : this.parentModels) {
if (parentModel1 instanceof DataWrapper) {
DataWrapper dataWrapper = (DataWrapper) parentModel1;
dataModel1 = dataWrapper.getSelectedDataModel();
}
if (parentModel1 instanceof GraphWrapper) {
GraphWrapper graphWrapper = (GraphWrapper) parentModel1;
graph = graphWrapper.getGraph();
}
if (parentModel1 instanceof DagWrapper) {
DagWrapper dagWrapper = (DagWrapper) parentModel1;
graph = dagWrapper.getDag();
}
if (parentModel1 instanceof SemGraphWrapper) {
SemGraphWrapper semGraphWrapper = (SemGraphWrapper) parentModel1;
graph = semGraphWrapper.getGraph();
}
}
if (dataModel1 != null) {
varNames = new ArrayList<>(dataModel1.getVariableNames());
} else if (graph != null) {
Iterator<Node> it = graph.getNodes().iterator();
varNames = new ArrayList();
Node temp;
while (it.hasNext()) {
temp = it.next();
if (temp.getNodeType() == NodeType.MEASURED) {
varNames.add(temp.getName());
}
}
} else {
throw new NullPointerException("Null model (no graph or data model " + "passed to the search).");
}
this.params.set("varNames", varNames);
IntTextField depthField = new IntTextField(this.params.getInt("depth", -1), 4);
depthField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
PcSearchParamEditor.this.params.set("depth", value);
Preferences.userRoot().putInt("depth", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
double alpha = params.getDouble("alpha", 0.001);
if (!Double.isNaN(alpha)) {
alphaField = new DoubleTextField(alpha, 4, NumberFormatUtil.getInstance().getNumberFormat());
alphaField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
PcSearchParamEditor.this.params.set("alpha", 0.001);
Preferences.userRoot().putDouble("alpha", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
}
setBorder(new MatteBorder(10, 10, 10, 10, super.getBackground()));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
if (!Double.isNaN(alpha)) {
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Alpha Value:"));
b2.add(Box.createGlue());
b2.add(alphaField);
add(b2);
add(Box.createVerticalStrut(10));
}
Box b3 = Box.createHorizontalBox();
b3.add(new JLabel("Search Depth:"));
b3.add(Box.createGlue());
b3.add(depthField);
add(b3);
add(Box.createVerticalStrut(10));
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class TsImages method search.
@Override
public Graph search(List<DataModel> dataSets, Parameters parameters) {
List<DataModel> dataModels = new ArrayList<>();
for (DataModel dataSet : dataSets) {
dataModels.add(dataSet);
}
TsGFci search;
if (score instanceof SemBicScore) {
SemBicScoreImages gesScore = new SemBicScoreImages(dataModels);
gesScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
IndependenceTest test = new IndTestScore(gesScore);
search = new TsGFci(test, gesScore);
} else if (score instanceof BdeuScore) {
double samplePrior = parameters.getDouble("samplePrior", 1);
double structurePrior = parameters.getDouble("structurePrior", 1);
BdeuScoreImages score = new BdeuScoreImages(dataModels);
score.setSamplePrior(samplePrior);
score.setStructurePrior(structurePrior);
IndependenceTest test = new IndTestScore(score);
search = new TsGFci(test, score);
} else {
throw new IllegalStateException("Sorry, data must either be all continuous or all discrete.");
}
IKnowledge knowledge = dataModels.get(0).getKnowledge();
search.setKnowledge(knowledge);
return search.search();
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class LingamStructureRunner method execute.
// ============================PUBLIC METHODS==========================//
/**
* Executes the algorithm, producing (at least) a result workbench. Must be
* implemented in the extending class.
*/
public void execute() {
DataModel source = getDataModel();
if (!(source instanceof DataSet)) {
throw new IllegalArgumentException("Expecting a rectangular data set.");
}
DataSet data = (DataSet) source;
if (!data.isContinuous()) {
throw new IllegalArgumentException("Expecting a continuous data set.");
}
// Lingam_old lingam = new Lingam_old();
// lingam.setAlternativePenalty(getParameters().getAlternativePenalty());
// lingam.setPruningDone(true);
// lingam.setAlternativePenalty(getParameters().getAlternativePenalty());
// GraphWithParameters result = lingam.lingam(data);
// Graph graph = result.getGraph();
Lingam lingam = new Lingam();
Parameters params = getParams();
Graph graph = lingam.search(data);
setResultGraph(graph);
if (getSourceGraph() != null) {
GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
} else {
GraphUtils.circleLayout(graph, 200, 200, 150);
}
}
Aggregations