use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class IndTestGSquare method indTestSubset.
/**
* Creates a new IndTestGSquare for a subset of the variables.
*/
public IndependenceTest indTestSubset(List vars) {
if (vars.isEmpty()) {
throw new IllegalArgumentException("Subset may not be empty.");
}
int[] indices = new int[vars.size()];
int j = -1;
for (int i = 0; i < variables.size(); i++) {
if (!vars.contains(variables.get(i))) {
continue;
}
indices[++j] = i;
}
DataSet newDataSet = dataSet.subsetColumns(indices);
return new IndTestGSquare(newDataSet, alpha);
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class GlassoRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
Object dataModel = getDataModel();
Parameters params = getParams();
if (dataModel instanceof DataSet) {
DataSet dataSet = (DataSet) dataModel;
DoubleMatrix2D cov = new DenseDoubleMatrix2D(dataSet.getCovarianceMatrix().toArray());
Glasso glasso = new Glasso(cov);
glasso.setMaxit((int) params.get("maxit", 10000));
glasso.setIa(params.getBoolean("ia", false));
glasso.setIs(params.getBoolean("is", false));
glasso.setItr(params.getBoolean("itr", false));
glasso.setIpen(params.getBoolean("ipen", false));
glasso.setThr(params.getDouble("thr", 1e-4));
glasso.setRhoAllEqual(1.0);
Glasso.Result result = glasso.search();
TetradMatrix wwi = new TetradMatrix(result.getWwi().toArray());
List<Node> variables = dataSet.getVariables();
Graph resultGraph = new EdgeListGraph(variables);
for (int i = 0; i < variables.size(); i++) {
for (int j = i + 1; j < variables.size(); j++) {
if (wwi.get(i, j) != 0.0 && wwi.get(i, j) != 0.0) {
resultGraph.addUndirectedEdge(variables.get(i), variables.get(j));
}
}
}
setResultGraph(resultGraph);
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class SemEstimatorWrapper method serializableInstance.
// public SemEstimatorWrapper(DataWrapper dataWrapper,
// SemPmWrapper semPmWrapper,
// SemImWrapper semImWrapper,
// Parameters params) {
// if (dataWrapper == null) {
// throw new NullPointerException();
// }
//
// if (semPmWrapper == null) {
// throw new NullPointerException();
// }
//
// if (semImWrapper == null) {
// throw new NullPointerException();
// }
//
// DataSet dataSet =
// (DataSet) dataWrapper.getSelectedDataModel();
// SemPm semPm = semPmWrapper.getSemPm();
// SemIm semIm = semImWrapper.getSemIm();
//
// this.semEstimator = new SemEstimator(dataSet, semPm, getOptimizer());
// if (!degreesOfFreedomCheck(semPm)) return;
// this.semEstimator.setTrueSemIm(semIm);
// this.semEstimator.setNumRestarts(getParams().getInt("numRestarts", 1));
// this.semEstimator.estimate();
//
// this.params = params;
//
// log();
// }
/**
* Generates a simple exemplar of this class to test serialization.
*
* @see TetradSerializableUtils
*/
public static SemEstimatorWrapper serializableInstance() {
List<Node> variables = new LinkedList<>();
ContinuousVariable x = new ContinuousVariable("X");
variables.add(x);
DataSet dataSet = new ColtDataSet(10, variables);
for (int i = 0; i < dataSet.getNumRows(); i++) {
for (int j = 0; j < dataSet.getNumColumns(); j++) {
dataSet.setDouble(i, j, RandomUtil.getInstance().nextDouble());
}
}
Dag dag = new Dag();
dag.addNode(x);
SemPm pm = new SemPm(dag);
Parameters params1 = new Parameters();
return new SemEstimatorWrapper(dataSet, pm, params1);
}
use of edu.cmu.tetrad.data.DataSet 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);
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class InverseCorrelationRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
Object dataModel = getDataModel();
if (dataModel instanceof DataSet) {
DataSet dataSet = (DataSet) dataModel;
Parameters params = getParams();
InverseCorrelation search = new InverseCorrelation(dataSet, params.getDouble("thr", 1e-4));
Graph graph = search.search();
setResultGraph(graph);
}
}
Aggregations