Search in sources :

Example 36 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class LingRunner 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.");
// }
// 
// Ling ling = new Ling(data);
// Parameters searchParams = (Parameters) getParameters();
// ling.setThreshold(searchParams.getThreshold());
// Ling.StoredGraphs graphs = ling.search();
// Graph graph = null;
// 
// for (int i = 0; i < graphs.getNumGraphs(); i++) {
// System.out.println(graphs.getGraph(i));
// System.out.println(graphs.isStable(i));
// }
// 
// for (int i = 0; i < graphs.getNumGraphs(); i++) {
// if (graphs.isStable(i)) {
// graph = graphs.getGraph(i);
// break;
// }
// }
// 
// if (graph == null) {
// graph = new EdgeListGraph();
// }
// 
// setResultGraph(graph);
// setStoredGraphs(graphs);
// 
// if (getSourceGraph() != null) {
// DataGraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
// }
// else {
// DataGraphUtils.circleLayout(graph, 200, 200, 150);
// }
// 
// }
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.");
    }
    Ling ling = new Ling(data);
    Parameters searchParams = getParams();
    ling.setThreshold(searchParams.getDouble("threshold", 0.5));
    Ling.StoredGraphs graphs = ling.search();
    Graph graph = null;
    for (int i = 0; i < graphs.getNumGraphs(); i++) {
        System.out.println(graphs.getGraph(i));
        System.out.println(graphs.isStable(i));
    }
    for (int i = 0; i < graphs.getNumGraphs(); i++) {
        if (graphs.isStable(i)) {
            graph = graphs.getGraph(i);
            break;
        }
    }
    if (graph == null) {
        graph = new EdgeListGraph();
    }
    setResultGraph(graph);
    setStoredGraphs(graphs);
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
}
Also used : Ling(edu.cmu.tetrad.search.Ling) Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel)

Example 37 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class LingamRunner 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);
    // 
    // double lingamPruningAlpha = Preferences.userRoot().getDouble("lingamPruningAlpha", 0.05);
    // 
    // lingam.setAlternativePenalty(lingamPruningAlpha);
    // Graph graph = lingam.lingam(data).getGraph();
    Lingam lingam = new Lingam();
    Graph graph = lingam.search(data);
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
    GraphUtils.arrangeBySourceGraph(getResultGraph(), getSourceGraph());
}
Also used : 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 38 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class SemEstimatorWrapper method setParams.

private boolean setParams(SemPmWrapper semPmWrapper, DataModelList dataModel) {
    for (DataModel model : dataModel) {
        if (model instanceof DataSet) {
            DataSet dataSet = (DataSet) model;
            SemPm semPm = semPmWrapper.getSemPm();
            this.semPm = semPm;
            SemEstimator estimator = new SemEstimator(dataSet, semPm, getOptimizer());
            estimator.setNumRestarts(getParams().getInt("numRestarts", 1));
            estimator.setScoreType((ScoreType) getParams().get("scoreType", ScoreType.Fgls));
            if (!degreesOfFreedomCheck(semPm)) {
                return true;
            }
            estimator.estimate();
            getMultipleResultList().add(estimator);
        } else if (model instanceof ICovarianceMatrix) {
            ICovarianceMatrix covMatrix = new CovarianceMatrix((ICovarianceMatrix) model);
            SemPm semPm = semPmWrapper.getSemPm();
            this.semPm = semPm;
            SemEstimator estimator = new SemEstimator(covMatrix, semPm, getOptimizer());
            estimator.setNumRestarts(getParams().getInt("numRestarts", 1));
            estimator.setScoreType((ScoreType) getParams().get("scoreType", ScoreType.Fgls));
            if (!degreesOfFreedomCheck(semPm)) {
                return true;
            }
            estimator.estimate();
            getMultipleResultList().add(estimator);
        } else {
            throw new IllegalArgumentException("Data must consist of continuous data sets or covariance matrices.");
        }
    }
    return false;
}
Also used : ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) ScoreType(edu.cmu.tetrad.sem.ScoreType) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix)

Example 39 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class CovMatrixAverageWrapper method calcAverage.

private void calcAverage(List<DataWrapper> wrappers) {
    List<TetradMatrix> cov = new ArrayList<>();
    for (int i = 0; i < wrappers.size(); i++) {
        DataModel selectedDataModel = wrappers.get(i).getSelectedDataModel();
        if (!(selectedDataModel instanceof ICovarianceMatrix)) {
            throw new IllegalArgumentException("Sorry, this is an average only over covariance matrices.");
        }
        cov.add(((ICovarianceMatrix) selectedDataModel).getMatrix());
    }
    TetradMatrix cov3 = new TetradMatrix(cov.get(0).rows(), cov.get(0).rows());
    for (int i = 0; i < cov.get(0).rows(); i++) {
        for (int j = 0; j < cov.get(0).rows(); j++) {
            double c = 0.0;
            for (int k = 0; k < cov.size(); k++) {
                c += cov.get(k).get(i, j);
            }
            c /= cov.size();
            cov3.set(i, j, c);
            cov3.set(j, i, c);
        }
    }
    DataModel m = wrappers.get(0).getSelectedDataModel();
    ICovarianceMatrix _cov = (ICovarianceMatrix) m;
    List<Node> nodes = _cov.getVariables();
    int n = _cov.getSampleSize();
    ICovarianceMatrix covWrapper = new CovarianceMatrix(nodes, cov3, n);
    setDataModel(covWrapper);
}
Also used : DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix)

Aggregations

DataModel (edu.cmu.tetrad.data.DataModel)39 DataSet (edu.cmu.tetrad.data.DataSet)22 ArrayList (java.util.ArrayList)15 DataWrapper (edu.cmu.tetradapp.model.DataWrapper)13 Graph (edu.cmu.tetrad.graph.Graph)9 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)8 Parameters (edu.cmu.tetrad.util.Parameters)8 DataModelList (edu.cmu.tetrad.data.DataModelList)7 Node (edu.cmu.tetrad.graph.Node)7 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 List (java.util.List)5 LayoutMenu (edu.cmu.tetradapp.workbench.LayoutMenu)4 DoubleTextField (edu.cmu.tetradapp.util.DoubleTextField)3 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)3 GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)3 IOException (java.io.IOException)3 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)2 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)2 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2