Search in sources :

Example 61 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class IndTestFisherZConcatenateResiduals method residuals.

private double[] residuals(Node node, List<Node> parents) {
    List<Double> _residuals = new ArrayList<>();
    Node target = dataSets.get(0).getVariable(node.getName());
    List<Node> regressors = new ArrayList<>();
    for (Node _regressor : parents) {
        Node variable = dataSets.get(0).getVariable(_regressor.getName());
        regressors.add(variable);
    }
    for (int m = 0; m < dataSets.size(); m++) {
        RegressionResult result = regressions.get(m).regress(target, regressors);
        double[] residualsSingleDataset = result.getResiduals().toArray();
        double mean = StatUtils.mean(residualsSingleDataset);
        for (int i2 = 0; i2 < residualsSingleDataset.length; i2++) {
            residualsSingleDataset[i2] = residualsSingleDataset[i2] - mean;
        }
        for (double d : residualsSingleDataset) {
            _residuals.add(d);
        }
    }
    double[] _f = new double[_residuals.size()];
    for (int k = 0; k < _residuals.size(); k++) {
        _f[k] = _residuals.get(k);
    }
    return _f;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) RegressionResult(edu.cmu.tetrad.regression.RegressionResult)

Example 62 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class IndTestFisherZFisherPValue method getVariableNames.

/**
 * @return the list of variable varNames.
 */
public List<String> getVariableNames() {
    List<Node> variables = getVariables();
    List<String> variableNames = new ArrayList<>();
    for (Node variable1 : variables) {
        variableNames.add(variable1.getName());
    }
    return variableNames;
}
Also used : Node(edu.cmu.tetrad.graph.Node)

Example 63 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class IndTestFisherZFisherPValue method getAvailablePValues.

private static List<Double> getAvailablePValues(List<IndependenceTest> independenceTests, Node x, Node y, List<Node> condSet) {
    List<Double> allPValues = new ArrayList<>();
    for (IndependenceTest test : independenceTests) {
        // if (missingVariable(x, y, condSet, test)) continue;
        List<Node> localCondSet = new ArrayList<>();
        for (Node node : condSet) {
            localCondSet.add(test.getVariable(node.getName()));
        }
        try {
            test.isIndependent(test.getVariable(x.getName()), test.getVariable(y.getName()), localCondSet);
            allPValues.add(test.getPValue());
        } catch (Exception e) {
        // Skip that test.
        }
    }
    return allPValues;
}
Also used : Node(edu.cmu.tetrad.graph.Node)

Example 64 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class IndTestFisherZRecursive method indTestSubset.

// ==========================PUBLIC METHODS=============================//
/**
 * Creates a new independence test instance for a subset of the variables.
 */
public IndependenceTest indTestSubset(List<Node> vars) {
    if (vars.isEmpty()) {
        throw new IllegalArgumentException("Subset may not be empty.");
    }
    for (Node var : vars) {
        if (!variables.contains(var)) {
            throw new IllegalArgumentException("All vars must be original vars");
        }
    }
    int[] indices = new int[vars.size()];
    for (int i = 0; i < indices.length; i++) {
        indices[i] = indexMap.get(vars.get(i));
    }
    ICovarianceMatrix newCovMatrix = covMatrix.getSubmatrix(indices);
    double alphaNew = getAlpha();
    return new IndTestFisherZRecursive(newCovMatrix, alphaNew);
}
Also used : Node(edu.cmu.tetrad.graph.Node)

Example 65 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class IndTestHsic method getVariableNames.

/**
 * @return the list of variable varNames.
 */
public List<String> getVariableNames() {
    List<Node> variables = getVariables();
    List<String> variableNames = new ArrayList<>();
    for (Node variable1 : variables) {
        variableNames.add(variable1.getName());
    }
    return variableNames;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList)

Aggregations

Node (edu.cmu.tetrad.graph.Node)674 ArrayList (java.util.ArrayList)129 Graph (edu.cmu.tetrad.graph.Graph)106 GraphNode (edu.cmu.tetrad.graph.GraphNode)64 DataSet (edu.cmu.tetrad.data.DataSet)59 LinkedList (java.util.LinkedList)55 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)48 Test (org.junit.Test)48 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)46 List (java.util.List)45 Dag (edu.cmu.tetrad.graph.Dag)41 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)41 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)40 ChoiceGenerator (edu.cmu.tetrad.util.ChoiceGenerator)37 Endpoint (edu.cmu.tetrad.graph.Endpoint)29 DisplayNode (edu.cmu.tetradapp.workbench.DisplayNode)26 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)25 Edge (edu.cmu.tetrad.graph.Edge)23 SemIm (edu.cmu.tetrad.sem.SemIm)19 DepthChoiceGenerator (edu.cmu.tetrad.util.DepthChoiceGenerator)19