use of edu.cmu.tetrad.search.TestType in project tetrad by cmu-phil.
the class PurifyParamsEditor method setup.
public void setup() {
DoubleTextField alphaField = new DoubleTextField(params.getDouble("alpha", 0.001), 4, NumberFormatUtil.getInstance().getNumberFormat());
alphaField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
getParams().set("alpha", 0.001);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
final TestType[] descriptions = TestType.getTestDescriptions();
JComboBox testSelector = new JComboBox(descriptions);
testSelector.setSelectedItem(params.get("tetradTestType", TestType.TETRAD_WISHART));
testSelector.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
TestType testType = (TestType) combo.getSelectedItem();
getParams().set("tetradTestType", testType);
}
});
boolean discreteModel = setVarNames(parentModels, params);
editClusters = new JButton("Edit");
editClusters.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openClusterEditor();
}
});
Box b = Box.createVerticalBox();
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Alpha:"));
b1.add(Box.createHorizontalGlue());
b1.add(alphaField);
b.add(b1);
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("search_for_structure_over_latents Assignments:"));
b2.add(Box.createHorizontalGlue());
b2.add(editClusters);
b.add(b2);
if (!discreteModel) {
Box b3 = Box.createHorizontalBox();
b3.add(new JLabel("Statistical Test:"));
b3.add(Box.createHorizontalGlue());
b3.add(testSelector);
b.add(b3);
} else {
this.params.set("tetradTestType", TestType.DISCRETE_LRT);
}
setLayout(new BorderLayout());
add(b, BorderLayout.CENTER);
}
use of edu.cmu.tetrad.search.TestType in project tetrad by cmu-phil.
the class Bpc method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
ICovarianceMatrix cov = DataUtils.getCovMatrix(dataSet);
double alpha = parameters.getDouble("alpha");
boolean wishart = parameters.getBoolean("useWishart", true);
TestType testType;
if (wishart) {
testType = TestType.TETRAD_WISHART;
} else {
testType = TestType.TETRAD_DELTA;
}
TestType purifyType = TestType.TETRAD_BASED;
BuildPureClusters bpc = new BuildPureClusters(cov, alpha, testType, purifyType);
bpc.setVerbose(parameters.getBoolean("verbose"));
return bpc.search();
} else {
Bpc algorithm = new Bpc();
// algorithm.setKnowledge(knowledge);
// if (initialGraph != null) {
// algorithm.setInitialGraph(initialGraph);
// }
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
search.setKnowledge(knowledge);
BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
switch(parameters.getInt("bootstrapEnsemble", 1)) {
case 0:
edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
break;
case 1:
edgeEnsemble = BootstrapEdgeEnsemble.Highest;
break;
case 2:
edgeEnsemble = BootstrapEdgeEnsemble.Majority;
}
search.setEdgeEnsemble(edgeEnsemble);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
}
}
use of edu.cmu.tetrad.search.TestType in project tetrad by cmu-phil.
the class FofcRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
/**
* Executes the algorithm, producing (at least) a result workbench. Must be
* implemented in the extending class.
*/
public void execute() {
Graph searchGraph;
FindOneFactorClusters fofc;
Object source = getData();
TestType tetradTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART);
if (tetradTestType == null || (!(tetradTestType == TestType.TETRAD_DELTA || tetradTestType == TestType.TETRAD_WISHART))) {
tetradTestType = TestType.TETRAD_DELTA;
getParams().set("tetradTestType", tetradTestType);
}
FindOneFactorClusters.Algorithm algorithm = (FindOneFactorClusters.Algorithm) getParams().get("fofcAlgorithm", FindOneFactorClusters.Algorithm.GAP);
if (source instanceof DataSet) {
fofc = new FindOneFactorClusters((DataSet) source, tetradTestType, algorithm, getParams().getDouble("alpha", 0.001));
searchGraph = fofc.search();
} else if (source instanceof CovarianceMatrix) {
fofc = new FindOneFactorClusters((CovarianceMatrix) source, tetradTestType, algorithm, getParams().getDouble("alpha", 0.001));
searchGraph = fofc.search();
} else {
throw new IllegalArgumentException("Unrecognized data type.");
}
if (semIm != null) {
List<List<Node>> partition = MimUtils.convertToClusters2(searchGraph);
List<String> variableNames = ReidentifyVariables.reidentifyVariables2(partition, trueGraph, (DataSet) getData());
rename(searchGraph, partition, variableNames);
// searchGraph = reidentifyVariables2(searchGraph, semIm);
} else if (trueGraph != null) {
List<List<Node>> partition = MimUtils.convertToClusters2(searchGraph);
List<String> variableNames = ReidentifyVariables.reidentifyVariables1(partition, trueGraph);
rename(searchGraph, partition, variableNames);
// searchGraph = reidentifyVariables(searchGraph, trueGraph);
}
System.out.println("Search Graph " + searchGraph);
try {
Graph graph = new MarshalledObject<>(searchGraph).get();
GraphUtils.circleLayout(graph, 200, 200, 150);
GraphUtils.fruchtermanReingoldLayout(graph);
setResultGraph(graph);
setClusters(MimUtils.convertToClusters(graph, getData().getVariables()));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of edu.cmu.tetrad.search.TestType in project tetrad by cmu-phil.
the class FtfcRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
/**
* Executes the algorithm, producing (at least) a result workbench. Must be
* implemented in the extending class.
*/
public void execute() {
Graph searchGraph;
FindTwoFactorClusters ftfc;
Object source = getData();
TestType tetradTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART);
if (tetradTestType == null || (!(tetradTestType == TestType.TETRAD_DELTA || tetradTestType == TestType.TETRAD_WISHART))) {
tetradTestType = TestType.TETRAD_DELTA;
getParams().set("tetradTestType", tetradTestType);
}
FindTwoFactorClusters.Algorithm algorithm = (FindTwoFactorClusters.Algorithm) getParams().get("ftfcAlgorithm", FindTwoFactorClusters.Algorithm.GAP);
if (source instanceof DataSet) {
ftfc = new FindTwoFactorClusters((DataSet) source, algorithm, getParams().getDouble("alpha", 0.001));
ftfc.setVerbose(true);
searchGraph = ftfc.search();
} else if (source instanceof CovarianceMatrix) {
ftfc = new FindTwoFactorClusters((CovarianceMatrix) source, algorithm, getParams().getDouble("alpha", 0.001));
ftfc.setVerbose(true);
searchGraph = ftfc.search();
} else {
throw new IllegalArgumentException("Unrecognized data type.");
}
if (semIm != null) {
List<List<Node>> partition = MimUtils.convertToClusters2(searchGraph);
List<String> variableNames = ReidentifyVariables.reidentifyVariables2(partition, trueGraph, (DataSet) getData());
rename(searchGraph, partition, variableNames);
// searchGraph = reidentifyVariables2(searchGraph, semIm);
} else if (trueGraph != null) {
List<List<Node>> partition = MimUtils.convertToClusters2(searchGraph);
List<String> variableNames = ReidentifyVariables.reidentifyVariables1(partition, trueGraph);
rename(searchGraph, partition, variableNames);
// searchGraph = reidentifyVariables(searchGraph, trueGraph);
}
System.out.println("Search Graph " + searchGraph);
try {
Graph graph = new MarshalledObject<>(searchGraph).get();
GraphUtils.circleLayout(graph, 200, 200, 150);
GraphUtils.fruchtermanReingoldLayout(graph);
setResultGraph(graph);
setClusters(MimUtils.convertToClusters(graph, getData().getVariables()));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of edu.cmu.tetrad.search.TestType in project tetrad by cmu-phil.
the class BuildPureClustersParamsEditor method setup.
public void setup() {
DoubleTextField alphaField = new DoubleTextField(params.getDouble("alpha", 0.001), 4, NumberFormatUtil.getInstance().getNumberFormat());
alphaField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
getParams().set("alpha", 0.001);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
final TestType[] descriptions = TestType.getTestDescriptions();
JComboBox testSelector = new JComboBox(descriptions);
testSelector.setSelectedItem(getParams().get("tetradTestType", TestType.TETRAD_WISHART));
testSelector.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
TestType testType = (TestType) combo.getSelectedItem();
getParams().set("tetradTestType", testType);
}
});
final TestType[] purifyDescriptions = TestType.getPurifyTestDescriptions();
JComboBox purifySelector = new JComboBox(purifyDescriptions);
purifySelector.setSelectedItem(getParams().get("purifyTestType", TestType.NONE));
purifySelector.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
TestType testType = (TestType) combo.getSelectedItem();
getParams().set("purifyTestType", testType);
}
});
// Where is it setting the appropriate knowledge for the search?
DataModel dataModel = null;
for (Object parentModel : this.parentModels) {
if (parentModel instanceof DataWrapper) {
DataWrapper dataWrapper = (DataWrapper) parentModel;
dataModel = dataWrapper.getSelectedDataModel();
}
}
if (dataModel == null) {
throw new IllegalStateException("Null data model.");
}
List<String> varNames = new ArrayList<>(dataModel.getVariableNames());
boolean isDiscreteModel;
if (dataModel instanceof ICovarianceMatrix) {
isDiscreteModel = false;
} else {
DataSet dataSet = (DataSet) dataModel;
isDiscreteModel = dataSet.isDiscrete();
// try {
// new DataSet((DataSet) dataModel);
// isDiscreteModel = true;
// }
// catch (IllegalArgumentException e) {
// isDiscreteModel = false;
// }
}
params.set("varNames", varNames);
alphaField.setValue(params.getDouble("alpha", 0.001));
Box b = Box.createVerticalBox();
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Alpha:"));
b1.add(Box.createHorizontalGlue());
b1.add(alphaField);
b.add(b1);
if (!isDiscreteModel) {
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Statistical Test:"));
b2.add(Box.createHorizontalGlue());
b2.add(testSelector);
b.add(b2);
Box b3 = Box.createHorizontalBox();
b3.add(new JLabel("Purify Test:"));
b3.add(Box.createHorizontalGlue());
b3.add(purifySelector);
b.add(b3);
} else {
this.params.set("purifyTestType", TestType.DISCRETE_LRT);
this.params.set("tetradTestType", TestType.DISCRETE);
}
setLayout(new BorderLayout());
add(b, BorderLayout.CENTER);
}
Aggregations