use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class TestSimulatedFmri method testClark.
// @Test
public void testClark() {
double f = .1;
int N = 512;
double alpha = 1.0;
double penaltyDiscount = 1.0;
for (int i = 0; i < 100; i++) {
{
Node x = new ContinuousVariable("X");
Node y = new ContinuousVariable("Y");
Node z = new ContinuousVariable("Z");
Graph g = new EdgeListGraph();
g.addNode(x);
g.addNode(y);
g.addNode(z);
g.addDirectedEdge(x, y);
g.addDirectedEdge(z, x);
g.addDirectedEdge(z, y);
GeneralizedSemPm pm = new GeneralizedSemPm(g);
try {
pm.setNodeExpression(g.getNode("X"), "0.5 * Z + E_X");
pm.setNodeExpression(g.getNode("Y"), "0.5 * X + 0.5 * Z + E_Y");
pm.setNodeExpression(g.getNode("Z"), "E_Z");
String error = "pow(Uniform(0, 1), " + f + ")";
pm.setNodeExpression(pm.getErrorNode(g.getNode("X")), error);
pm.setNodeExpression(pm.getErrorNode(g.getNode("Y")), error);
pm.setNodeExpression(pm.getErrorNode(g.getNode("Z")), error);
} catch (ParseException e) {
System.out.println(e);
}
GeneralizedSemIm im = new GeneralizedSemIm(pm);
DataSet data = im.simulateData(N, false);
edu.cmu.tetrad.search.SemBicScore score = new edu.cmu.tetrad.search.SemBicScore(new CovarianceMatrixOnTheFly(data, false));
score.setPenaltyDiscount(penaltyDiscount);
Fask fask = new Fask(data, score);
fask.setPenaltyDiscount(penaltyDiscount);
fask.setAlpha(alpha);
Graph out = fask.search();
System.out.println(out);
}
{
Node x = new ContinuousVariable("X");
Node y = new ContinuousVariable("Y");
Node z = new ContinuousVariable("Z");
Graph g = new EdgeListGraph();
g.addNode(x);
g.addNode(y);
g.addNode(z);
g.addDirectedEdge(x, y);
g.addDirectedEdge(x, z);
g.addDirectedEdge(y, z);
GeneralizedSemPm pm = new GeneralizedSemPm(g);
try {
pm.setNodeExpression(g.getNode("X"), "E_X");
pm.setNodeExpression(g.getNode("Y"), "0.4 * X + E_Y");
pm.setNodeExpression(g.getNode("Z"), "0.4 * X + 0.4 * Y + E_Z");
String error = "pow(Uniform(0, 1), " + f + ")";
pm.setNodeExpression(pm.getErrorNode(g.getNode("X")), error);
pm.setNodeExpression(pm.getErrorNode(g.getNode("Y")), error);
pm.setNodeExpression(pm.getErrorNode(g.getNode("Z")), error);
} catch (ParseException e) {
System.out.println(e);
}
GeneralizedSemIm im = new GeneralizedSemIm(pm);
DataSet data = im.simulateData(N, false);
edu.cmu.tetrad.search.SemBicScore score = new edu.cmu.tetrad.search.SemBicScore(new CovarianceMatrixOnTheFly(data, false));
score.setPenaltyDiscount(penaltyDiscount);
Fask fask = new Fask(data, score);
fask.setPenaltyDiscount(penaltyDiscount);
fask.setAlpha(alpha);
Graph out = fask.search();
System.out.println(out);
}
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class TestIndTestGSquare method testIsIndependent.
@Test
public void testIsIndependent() {
try {
DataSet dataSet = getDataSet(1);
IndTestGSquare test = new IndTestGSquare(dataSet, 0.05);
List<Node> v = test.getVariables();
Node x = v.get(0);
Node y = v.get(1);
ArrayList<Node> z = new ArrayList<>();
z.add(v.get(2));
assertTrue(test.isIndependent(x, y, z));
test.setDeterminationP(0.99);
assertFalse(test.determines(z, x));
assertFalse(test.determines(z, y));
} catch (IOException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class TestIndTestGSquare method testDetermination.
@Test
public void testDetermination() {
try {
DataSet dataSet = getDataSet(1);
IndTestGSquare test = new IndTestGSquare(dataSet, 0.05);
Node x = dataSet.getVariable("X4");
ArrayList<Node> z = new ArrayList<>();
test.setDeterminationP(0.99);
assertFalse(test.determines(z, x));
} catch (IOException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class TestIndTestWaldLR method testIsIndependent.
@Test
public void testIsIndependent() {
RandomUtil.getInstance().setSeed(1450705713157L);
int numPassed = 0;
for (int i = 0; i < 10; i++) {
List<Node> nodes = new ArrayList<>();
for (int i1 = 0; i1 < 10; i1++) {
nodes.add(new ContinuousVariable("X" + (i1 + 1)));
}
Graph graph = GraphUtils.randomGraph(nodes, 0, 10, 3, 3, 3, false);
SemPm pm = new SemPm(graph);
SemIm im = new SemIm(pm);
DataSet data = im.simulateData(1000, false);
Discretizer discretizer = new Discretizer(data);
discretizer.setVariablesCopied(true);
discretizer.equalCounts(data.getVariable(0), 2);
discretizer.equalCounts(data.getVariable(3), 2);
data = discretizer.discretize();
Node x1 = data.getVariable("X1");
Node x2 = data.getVariable("X2");
Node x3 = data.getVariable("X3");
Node x4 = data.getVariable("X4");
Node x5 = data.getVariable("X5");
List<Node> cond = new ArrayList<>();
cond.add(x3);
cond.add(x4);
cond.add(x5);
Node x1Graph = graph.getNode(x1.getName());
Node x2Graph = graph.getNode(x2.getName());
List<Node> condGraph = new ArrayList<>();
for (Node node : cond) {
condGraph.add(graph.getNode(node.getName()));
}
// Using the Wald LR test since it's most up to date.
IndependenceTest test = new IndTestMultinomialLogisticRegressionWald(data, 0.05, false);
IndTestDSep dsep = new IndTestDSep(graph);
boolean correct = test.isIndependent(x2, x1, cond) == dsep.isIndependent(x2Graph, x1Graph, condGraph);
if (correct) {
numPassed++;
}
}
// System.out.println(RandomUtil.getInstance().getSeed());
// Do not always get all 10.
assertEquals(10, numPassed);
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class TestLargeSemSimulator method test1.
@Test
public void test1() {
List<Node> nodes = new ArrayList<>();
for (int i = 1; i <= 10; i++) nodes.add(new ContinuousVariable("X" + i));
Graph graph = GraphUtils.randomGraph(nodes, 0, 10, 5, 5, 5, false);
LargeScaleSimulation simulator = new LargeScaleSimulation(graph);
DataSet dataset = simulator.simulateDataFisher(1000);
assertEquals(1000, dataset.getNumRows());
}
Aggregations