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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations