Search in sources :

Example 56 with DataSet

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);
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet)

Example 57 with DataSet

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);
    }
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D)

Example 58 with DataSet

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);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Parameters(edu.cmu.tetrad.util.Parameters) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) SemPm(edu.cmu.tetrad.sem.SemPm) Dag(edu.cmu.tetrad.graph.Dag) LinkedList(java.util.LinkedList)

Example 59 with DataSet

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);
    }
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) Lingam(edu.cmu.tetrad.search.Lingam)

Example 60 with DataSet

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);
    }
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) InverseCorrelation(edu.cmu.tetrad.search.InverseCorrelation)

Aggregations

DataSet (edu.cmu.tetrad.data.DataSet)216 Test (org.junit.Test)65 Graph (edu.cmu.tetrad.graph.Graph)64 Node (edu.cmu.tetrad.graph.Node)60 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)48 ArrayList (java.util.ArrayList)45 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)36 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)32 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)29 SemIm (edu.cmu.tetrad.sem.SemIm)28 SemPm (edu.cmu.tetrad.sem.SemPm)28 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)26 DataModel (edu.cmu.tetrad.data.DataModel)22 Parameters (edu.cmu.tetrad.util.Parameters)22 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)20 File (java.io.File)16 ParseException (java.text.ParseException)16 LinkedList (java.util.LinkedList)14 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)13 DMSearch (edu.cmu.tetrad.search.DMSearch)10