use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class LoadTimeSeriesDataAction method loadTimeSeriesDataSet.
/**
* Method loadDataSet_TabDelim
*/
private void loadTimeSeriesDataSet() {
// select a file to load using the file chooser
JFileChooser chooser = getJFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showOpenDialog(this.editor);
// get the file
File file = chooser.getSelectedFile();
Preferences.userRoot().put("fileSaveLocation", file.getParent());
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
StringTokenizer st;
// read in variable name and set up DataSet.
List<Node> variables = new LinkedList<>();
st = new StringTokenizer(in.readLine());
while (st.hasMoreTokens()) {
String name = st.nextToken();
ContinuousVariable var = new ContinuousVariable(name);
variables.add(var);
}
DataSet dataSet = new ColtDataSet(0, variables);
int row = -1;
while ((line = in.readLine()) != null) {
int col = -1;
st = new StringTokenizer(line);
while (st.hasMoreTokens()) {
String literal = st.nextToken();
if (literal.length() == 0) {
continue;
}
dataSet.setObject(row, ++col, literal);
}
}
TimeSeriesData dataSet3 = new TimeSeriesData(dataSet.getDoubleData(), dataSet.getVariableNames());
editor.getDataWrapper().setDataModel(dataSet3);
firePropertyChange("modelChanged", null, null);
editor.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class SpecialGraphClark method createGraph.
@Override
public Graph createGraph(Parameters parameters) {
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);
g.addDirectedEdge(x, y);
g.addDirectedEdge(x, z);
g.addDirectedEdge(y, z);
//
return g;
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class TestColtDataSet method testMixed.
@Test
public void testMixed() {
List<Node> variables = new LinkedList<>();
DiscreteVariable x1 = new DiscreteVariable("X1");
variables.add(x1);
ContinuousVariable x2 = new ContinuousVariable("X2");
variables.add(x2);
DataSet dataSet = new ColtDataSet(5, variables);
assertTrue(dataSet.getVariables().get(0) instanceof DiscreteVariable);
assertTrue(dataSet.getVariables().get(1) instanceof ContinuousVariable);
assertTrue(dataSet.getInt(0, 0) == -99);
assertTrue(Double.isNaN(dataSet.getDouble(1, 0)));
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class TestDM method test2.
@Test
public void test2() {
// setting seed for debug.
RandomUtil.getInstance().setSeed(29483818483L);
Graph graph = emptyGraph(8);
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X2"));
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X2"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X7"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X7"));
graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X7"));
graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X7"));
SemPm pm = new SemPm(graph);
SemIm im = new SemIm(pm);
DataSet data = im.simulateData(100000, false);
DMSearch search = new DMSearch();
search.setInputs(new int[] { 0, 1, 4, 5 });
search.setOutputs(new int[] { 2, 3, 6, 7 });
search.setData(data);
search.setTrueInputs(search.getInputs());
Graph foundGraph = search.search();
print("Test Case 2");
Graph trueGraph = new EdgeListGraph();
trueGraph.addNode(new ContinuousVariable("X0"));
trueGraph.addNode(new ContinuousVariable("X1"));
trueGraph.addNode(new ContinuousVariable("X2"));
trueGraph.addNode(new ContinuousVariable("X3"));
trueGraph.addNode(new ContinuousVariable("X4"));
trueGraph.addNode(new ContinuousVariable("X5"));
trueGraph.addNode(new ContinuousVariable("X6"));
trueGraph.addNode(new ContinuousVariable("X7"));
trueGraph.addNode(new ContinuousVariable("L0"));
trueGraph.addNode(new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L0"));
trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L0"));
trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X2"));
trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X3"));
// trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X6"));
trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X7"));
assertTrue(foundGraph.equals(trueGraph));
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class TestDM method test10.
//
@Test
public void test10() {
// setting seed for debug.
RandomUtil.getInstance().setSeed(29483818483L);
Graph graph = emptyGraph(5);
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X2"));
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X4"));
SemPm pm = new SemPm(graph);
SemIm im = new SemIm(pm);
DataSet data = im.simulateData(100000, false);
DMSearch search = new DMSearch();
search.setUseFges(false);
search.setInputs(new int[] { 0, 1 });
search.setOutputs(new int[] { 2, 3, 4 });
search.setData(data);
search.setTrueInputs(search.getInputs());
search.search();
print("Test Case 10");
// Trying to quiet the output for unit tests.
if (false) {
System.out.println(search.getDmStructure());
}
assertTrue(true);
}
Aggregations