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