use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class Skew method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
Graph graph = algorithm.search(dataSet, parameters);
if (graph != null) {
initialGraph = graph;
} else {
throw new IllegalArgumentException("This Skew algorithm needs both data and a graph source as inputs; it \n" + "will orient the edges in the input graph using the data");
}
List<DataSet> dataSets = new ArrayList<>();
dataSets.add(DataUtils.getContinuousDataSet(dataSet));
Lofs2 lofs = new Lofs2(initialGraph, dataSets);
lofs.setRule(Lofs2.Rule.Skew);
return lofs.orient();
} else {
Skew skew = new Skew(algorithm);
if (initialGraph != null) {
skew.setInitialGraph(initialGraph);
}
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, skew, parameters.getInt("bootstrapSampleSize"));
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.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class Tanh method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
Graph graph = algorithm.search(dataSet, parameters);
if (graph != null) {
initialGraph = graph;
} else {
throw new IllegalArgumentException("This Tanh algorithm needs both data and a graph source as inputs; it \n" + "will orient the edges in the input graph using the data");
}
List<DataSet> dataSets = new ArrayList<>();
dataSets.add(DataUtils.getContinuousDataSet(dataSet));
Lofs2 lofs = new Lofs2(initialGraph, dataSets);
lofs.setRule(Lofs2.Rule.Tanh);
return lofs.orient();
} else {
Tanh tanh = new Tanh(algorithm);
if (initialGraph != null) {
tanh.setInitialGraph(initialGraph);
}
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, tanh, parameters.getInt("bootstrapSampleSize"));
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.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class MBFS method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
IndependenceTest test = this.test.getTest(dataSet, parameters);
edu.cmu.tetrad.search.Mbfs search = new edu.cmu.tetrad.search.Mbfs(test, parameters.getInt("depth"));
search.setDepth(parameters.getInt("depth"));
search.setKnowledge(knowledge);
this.targetName = parameters.getString("targetName");
if (targetName.isEmpty()) {
throw new IllegalArgumentException("Target variable name needs to be provided.");
}
if (test.getVariable(targetName) == null) {
throw new IllegalArgumentException("Target variable name '" + targetName + "' not found in dataset.");
}
Node target = test.getVariable(targetName);
return search.search(target.getName());
} else {
MBFS algorithm = new MBFS(test);
// algorithm.setKnowledge(knowledge);
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.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class FactorAnalysis method search.
public Graph search(DataModel ds, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
DataSet selectedModel = (DataSet) ds;
if (selectedModel == null) {
throw new NullPointerException("Data not specified.");
}
edu.cmu.tetrad.search.FactorAnalysis analysis = new edu.cmu.tetrad.search.FactorAnalysis(selectedModel);
analysis.setThreshold(parameters.getDouble("convergenceThreshold"));
analysis.setNumFactors(parameters.getInt("numFactors"));
double threshold = parameters.getDouble("fa_threshold");
TetradMatrix unrotatedSolution = analysis.successiveResidual();
TetradMatrix rotatedSolution = analysis.successiveFactorVarimax(unrotatedSolution);
SemGraph graph = new SemGraph();
Vector<Node> observedVariables = new Vector<>();
for (Node a : selectedModel.getVariables()) {
graph.addNode(a);
observedVariables.add(a);
}
Vector<Node> factors = new Vector<>();
if (parameters.getBoolean("useVarimax")) {
for (int i = 0; i < rotatedSolution.columns(); i++) {
ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1));
factor.setNodeType(NodeType.LATENT);
graph.addNode(factor);
factors.add(factor);
}
for (int i = 0; i < rotatedSolution.rows(); i++) {
for (int j = 0; j < rotatedSolution.columns(); j++) {
if (Math.abs(rotatedSolution.get(i, j)) > threshold) {
graph.addDirectedEdge(factors.get(j), observedVariables.get(i));
}
}
}
} else {
for (int i = 0; i < unrotatedSolution.columns(); i++) {
ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1));
factor.setNodeType(NodeType.LATENT);
graph.addNode(factor);
factors.add(factor);
}
for (int i = 0; i < unrotatedSolution.rows(); i++) {
for (int j = 0; j < unrotatedSolution.columns(); j++) {
if (Math.abs(unrotatedSolution.get(i, j)) > threshold) {
graph.addDirectedEdge(factors.get(j), observedVariables.get(i));
}
}
}
}
if (parameters.getBoolean("verbose")) {
NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
String output = "Unrotated Factor Loading Matrix:\n";
output += tableString(unrotatedSolution, nf, Double.POSITIVE_INFINITY);
if (unrotatedSolution.columns() != 1) {
output += "\n\nRotated Matrix (using sequential varimax):\n";
output += tableString(rotatedSolution, nf, threshold);
}
System.out.println(output);
TetradLogger.getInstance().forceLogMessage(output);
}
return graph;
} else {
FactorAnalysis algorithm = new FactorAnalysis();
DataSet data = (DataSet) ds;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
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.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class R2 method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
Graph graph = algorithm.search(dataSet, parameters);
if (graph != null) {
initialGraph = graph;
} else {
throw new IllegalArgumentException("This R2 algorithm needs both data and a graph source as inputs; it \n" + "will orient the edges in the input graph using the data");
}
List<DataSet> dataSets = new ArrayList<>();
dataSets.add(DataUtils.getContinuousDataSet(dataSet));
Lofs2 lofs = new Lofs2(initialGraph, dataSets);
lofs.setRule(Lofs2.Rule.R2);
return lofs.orient();
} else {
R2 r2 = new R2(algorithm);
if (initialGraph != null) {
r2.setInitialGraph(initialGraph);
}
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, r2, parameters.getInt("bootstrapSampleSize"));
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();
}
}
Aggregations