Search in sources :

Example 36 with ContinuousVariable

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

the class TestMatrixUtils method testImpiedCovar.

@Test
public void testImpiedCovar() {
    List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        nodes.add(new ContinuousVariable("X" + (i + 1)));
    }
    Graph graph = new Dag(GraphUtils.randomGraph(nodes, 0, 10, 30, 15, 15, false));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    TetradMatrix err = im.getErrCovar();
    TetradMatrix coef = im.getEdgeCoef();
    TetradMatrix implied = MatrixUtils.impliedCovar(coef, err);
    assertTrue(MatrixUtils.isPositiveDefinite(implied));
    TetradMatrix corr = MatrixUtils.convertCovToCorr(new TetradMatrix(implied));
    assertTrue(MatrixUtils.isPositiveDefinite(corr));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) SemPm(edu.cmu.tetrad.sem.SemPm) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) Dag(edu.cmu.tetrad.graph.Dag) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test)

Example 37 with ContinuousVariable

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

the class TabularComparison method newExecution.

private void newExecution() {
    statistics = new ArrayList<>();
    statistics.add(new AdjacencyPrecision());
    statistics.add(new AdjacencyRecall());
    statistics.add(new ArrowheadPrecision());
    statistics.add(new ArrowheadRecall());
    statistics.add(new TwoCyclePrecision());
    statistics.add(new TwoCycleRecall());
    statistics.add(new TwoCycleFalsePositive());
    // statistics.add(new ElapsedTime());
    // statistics.add(new F1Adj());
    // statistics.add(new F1Arrow());
    // statistics.add(new MathewsCorrAdj());
    // statistics.add(new MathewsCorrArrow());
    // statistics.add(new SHD());
    List<Node> variables = new ArrayList<>();
    for (Statistic statistic : statistics) {
        variables.add(new ContinuousVariable(statistic.getAbbreviation()));
    }
    dataSet = new ColtDataSet(0, variables);
    dataSet.setNumberFormat(new DecimalFormat("0.00"));
}
Also used : Node(edu.cmu.tetrad.graph.Node) DecimalFormat(java.text.DecimalFormat) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet)

Example 38 with ContinuousVariable

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

the class TabularDataTable method pasteIntoColumn.

/**
 * The row and column indices are JTable indices.
 */
private void pasteIntoColumn(int row, int col, Object value) {
    int dataRow = row - getNumLeadingRows();
    int dataCol = col - getNumLeadingCols();
    Node variable = dataSet.getVariable(dataCol);
    if (variable instanceof ContinuousVariable && value instanceof Number) {
        dataSet.setObject(dataRow, dataCol, value);
        // dataSet.setDouble(dataRow, dataCol, (Double) value);
        return;
    }
    if ("".equals(value) || value == null) {
        return;
    }
    String valueTrimmed = ((String) value).trim();
    boolean quoted = false;
    if (valueTrimmed.startsWith("\"") && valueTrimmed.endsWith("\"")) {
        value = valueTrimmed.substring(1, valueTrimmed.length() - 1);
        quoted = true;
    }
    if (!(variable instanceof DiscreteVariable) && isEmpty(dataSet, dataCol) && (quoted || !isNumber((String) value))) {
        variable = swapDiscreteColumnForContinuous(col);
    }
    if (value instanceof String && ((String) value).trim().equals("*")) {
        value = ((Variable) variable).getMissingValueMarker();
    }
    dataSet.setObject(dataRow, dataCol, value);
    pcs.firePropertyChange("modelChanged", null, null);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) Node(edu.cmu.tetrad.graph.Node)

Example 39 with ContinuousVariable

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

the class GraphComparisonParams method newExecution.

// ==========================PUBLIC METHODS===========================//
public final void newExecution() {
    ContinuousVariable adjCorrect = new ContinuousVariable("ADJ_COR");
    ContinuousVariable adjFn = new ContinuousVariable("ADJ_FN");
    ContinuousVariable adjFp = new ContinuousVariable("ADJ_FP");
    ContinuousVariable arrowptCorrect = new ContinuousVariable("AHD_COR");
    ContinuousVariable arrowptFn = new ContinuousVariable("AHD_FN");
    ContinuousVariable arrowptFp = new ContinuousVariable("AHD_FP");
    ContinuousVariable adjPrec = new ContinuousVariable("ADJ_PREC");
    ContinuousVariable adjRec = new ContinuousVariable("ADJ_REC");
    ContinuousVariable arrowptPrec = new ContinuousVariable("ARROWPT_PREC");
    ContinuousVariable arrowptRec = new ContinuousVariable("ARROWPT_REC");
    ContinuousVariable shd = new ContinuousVariable("SHD");
    // ContinuousVariable twoCycleCorrect = new ContinuousVariable("TC_COR");
    // ContinuousVariable twoCycleFn = new ContinuousVariable("TC_FN");
    // ContinuousVariable twoCycleFp = new ContinuousVariable("TC_FP");
    List<Node> variables = new LinkedList<>();
    variables.add(adjCorrect);
    variables.add(adjFn);
    variables.add(adjFp);
    variables.add(arrowptCorrect);
    variables.add(arrowptFn);
    variables.add(arrowptFp);
    variables.add(adjPrec);
    variables.add(adjRec);
    variables.add(arrowptPrec);
    variables.add(arrowptRec);
    variables.add(shd);
    // variables.add(twoCycleCorrect);
    // variables.add(twoCycleFn);
    // variables.add(twoCycleFp);
    dataSet = new ColtDataSet(0, variables);
    dataSet.setNumberFormat(new DecimalFormat("0"));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Node(edu.cmu.tetrad.graph.Node) DecimalFormat(java.text.DecimalFormat) LinkedList(java.util.LinkedList)

Example 40 with ContinuousVariable

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

the class MNLRLikelihood method getDoF.

public double getDoF(int child_index, int[] parents) {
    double dof = 0;
    Node c = variables.get(child_index);
    List<ContinuousVariable> continuous_parents = new ArrayList<>();
    List<DiscreteVariable> discrete_parents = new ArrayList<>();
    for (int p : parents) {
        Node parent = variables.get(p);
        if (parent instanceof ContinuousVariable) {
            continuous_parents.add((ContinuousVariable) parent);
        } else {
            discrete_parents.add((DiscreteVariable) parent);
        }
    }
    int p = continuous_parents.size();
    List<List<Integer>> cells = adTree.getCellLeaves(discrete_parents);
    // List<List<Integer>> cells = partition(discrete_parents, 0).cells;
    int[] continuousCols = new int[p];
    for (int j = 0; j < p; j++) continuousCols[j] = nodesHash.get(continuous_parents.get(j));
    for (List<Integer> cell : cells) {
        int r = cell.size();
        if (r > 0) {
            int degree = fDegree;
            if (fDegree < 1) {
                degree = (int) Math.floor(Math.log(r));
            }
            if (c instanceof ContinuousVariable) {
                dof += degree * continuous_parents.size() + 1;
            } else {
                dof += ((degree * continuous_parents.size()) + 1) * (((DiscreteVariable) c).getNumCategories() - 1);
            }
        }
    }
    return dof;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable)

Aggregations

ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)91 DataSet (edu.cmu.tetrad.data.DataSet)48 Node (edu.cmu.tetrad.graph.Node)46 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)28 Graph (edu.cmu.tetrad.graph.Graph)22 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)19 SemPm (edu.cmu.tetrad.sem.SemPm)18 SemIm (edu.cmu.tetrad.sem.SemIm)16 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)15 LinkedList (java.util.LinkedList)13 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)12 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)8 DMSearch (edu.cmu.tetrad.search.DMSearch)7 Dag (edu.cmu.tetrad.graph.Dag)6 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)5 RandomUtil (edu.cmu.tetrad.util.RandomUtil)5 ParseException (java.text.ParseException)4 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)3 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)3