use of edu.cmu.tetrad.util.TetradVector in project tetrad by cmu-phil.
the class TestGeneralizedSem method test5.
@Test
public void test5() {
RandomUtil.getInstance().setSeed(29999483L);
List<Node> nodes = new ArrayList<>();
for (int i1 = 0; i1 < 5; i1++) {
nodes.add(new ContinuousVariable("X" + (i1 + 1)));
}
Graph graph = new Dag(GraphUtils.randomGraph(nodes, 0, 5, 30, 15, 15, false));
SemPm semPm = new SemPm(graph);
SemIm semIm = new SemIm(semPm);
semIm.simulateDataReducedForm(1000, false);
GeneralizedSemPm pm = new GeneralizedSemPm(semPm);
GeneralizedSemIm im = new GeneralizedSemIm(pm, semIm);
TetradVector e = new TetradVector(5);
for (int i = 0; i < e.size(); i++) {
e.set(i, RandomUtil.getInstance().nextNormal(0, 1));
}
TetradVector record1 = semIm.simulateOneRecord(e);
TetradVector record2 = im.simulateOneRecord(e);
print("XXX1" + e);
print("XXX2" + record1);
print("XXX3" + record2);
for (int i = 0; i < record1.size(); i++) {
assertEquals(record1.get(i), record2.get(i), 1e-10);
}
}
use of edu.cmu.tetrad.util.TetradVector in project tetrad by cmu-phil.
the class TestStandardizedSem method test1.
// Test the code that standardizes a data set.
@Test
public void test1() {
List<Node> nodes = new ArrayList<>();
for (int i = 0; i < 5; i++) {
nodes.add(new ContinuousVariable("X" + (i + 1)));
}
SemGraph graph = new SemGraph(new Dag(GraphUtils.randomGraph(nodes, 0, 5, 30, 15, 15, false)));
SemPm pm = new SemPm(graph);
SemIm im = new SemIm(pm);
DataSet dataSet = im.simulateData(1000, false);
TetradMatrix _dataSet = dataSet.getDoubleData();
_dataSet = DataUtils.standardizeData(_dataSet);
DataSet dataSetStandardized = ColtDataSet.makeData(dataSet.getVariables(), _dataSet);
DataUtils.cov(_dataSet);
DataUtils.mean(_dataSet);
SemEstimator estimator = new SemEstimator(dataSetStandardized, pm);
SemIm imStandardized = estimator.estimate();
imStandardized.getEdgeCoef();
imStandardized.getErrCovar();
new TetradVector(imStandardized.getMeans());
imStandardized.getEdgeCoef();
imStandardized.getErrCovar();
StandardizedSemIm sem = new StandardizedSemIm(im);
imStandardized.getEdgeCoef();
imStandardized.getErrCovar();
assertTrue(isStandardized(sem));
}
use of edu.cmu.tetrad.util.TetradVector in project tetrad by cmu-phil.
the class IndTestDirichletScore method determines.
/**
* If <code>isDeterminismAllowed()</code>, deters to IndTestFisherZD; otherwise throws
* UnsupportedOperationException.
*/
public boolean determines(List<Node> z, Node x) throws UnsupportedOperationException {
int[] parents = new int[z.size()];
for (int j = 0; j < parents.length; j++) {
parents[j] = covMatrix.getVariables().indexOf(z.get(j));
}
int i = covMatrix.getVariables().indexOf(x);
double variance = covMatrix.getValue(i, i);
if (parents.length > 0) {
// Regress z onto i, yielding regression coefficients b.
TetradMatrix Czz = covMatrix.getSelection(parents, parents);
TetradMatrix inverse;
try {
inverse = Czz.inverse();
} catch (Exception e) {
return true;
}
TetradVector Cyz = covMatrix.getSelection(parents, new int[] { i }).getColumn(0);
TetradVector b = inverse.times(Cyz);
variance -= Cyz.dotProduct(b);
}
return variance < 1e-20;
}
use of edu.cmu.tetrad.util.TetradVector in project tetrad by cmu-phil.
the class TestBoxDataSet method testPermuteRows.
@Test
public void testPermuteRows() {
ContinuousVariable x1 = new ContinuousVariable("X1");
ContinuousVariable x2 = new ContinuousVariable("X2");
List<Node> nodes = new ArrayList<>();
nodes.add(x1);
nodes.add(x2);
DataSet dataSet = new BoxDataSet(new DoubleDataBox(3, nodes.size()), nodes);
RandomUtil randomUtil = RandomUtil.getInstance();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
dataSet.setDouble(i, j, randomUtil.nextDouble());
}
}
BoxDataSet _dataSet = new BoxDataSet((BoxDataSet) dataSet);
dataSet.permuteRows();
I: for (int i = 0; i < dataSet.getNumRows(); i++) {
TetradVector v = _dataSet.getDoubleData().getRow(i);
for (int j = 0; j < dataSet.getNumRows(); j++) {
TetradVector w = dataSet.getDoubleData().getRow(j);
if (v.equals(w)) {
continue I;
}
}
fail("Missing row in permutation.");
}
}
Aggregations