use of edu.cmu.tetrad.graph.TimeLagGraph in project tetrad by cmu-phil.
the class BooleanGlassSimulation method createData.
@Override
public void createData(Parameters parameters) {
this.graph = randomGraph.createGraph(parameters);
LagGraphParams params = new LagGraphParams(parameters);
params.setIndegree(2);
params.setMlag(1);
RandomActiveLagGraph _graph = new RandomActiveLagGraph(params);
BooleanGlassGenePm pm = new BooleanGlassGenePm(_graph);
BooleanGlassGeneIm im = new BooleanGlassGeneIm(pm, parameters);
DataModelList data = im.simulateData();
List<DataSet> dataSets = new ArrayList<>();
for (DataModel model : data) {
dataSets.add((DataSet) model);
}
this.dataSets = dataSets;
List<String> factors = new ArrayList<>(_graph.getFactors());
Map<String, Node> nodes = new HashMap<>();
for (String factor : factors) {
nodes.put(factor, new ContinuousVariable(factor));
}
TimeLagGraph graph = new TimeLagGraph();
graph.setMaxLag(_graph.getMaxLag());
for (String factor : factors) {
graph.addNode(nodes.get(factor));
}
for (String factor : factors) {
for (Object o : _graph.getParents(factor)) {
LaggedFactor laggedFactor = (LaggedFactor) o;
String _factor = laggedFactor.getFactor();
int lag = laggedFactor.getLag();
Node node1 = graph.getNode(_factor + ":" + lag);
Node node2 = graph.getNode(factor);
graph.addDirectedEdge(node1, node2);
}
}
topToBottomLayout(graph);
this.graph = graph;
}
use of edu.cmu.tetrad.graph.TimeLagGraph in project tetrad by cmu-phil.
the class TimeSeriesSemSimulation method topToBottomLayout.
public static void topToBottomLayout(TimeLagGraph graph) {
int xStart = 65;
int yStart = 50;
int xSpace = 100;
int ySpace = 100;
List<Node> lag0Nodes = graph.getLag0Nodes();
Collections.sort(lag0Nodes, new Comparator<Node>() {
public int compare(Node o1, Node o2) {
return o1.getCenterX() - o2.getCenterX();
}
});
int x = xStart - xSpace;
for (Node node : lag0Nodes) {
x += xSpace;
int y = yStart - ySpace;
TimeLagGraph.NodeId id = graph.getNodeId(node);
for (int lag = graph.getMaxLag(); lag >= 0; lag--) {
y += ySpace;
Node _node = graph.getNode(id.getName(), lag);
if (_node == null) {
System.out.println("Couldn't find " + _node);
continue;
}
_node.setCenterX(x);
_node.setCenterY(y);
}
}
}
use of edu.cmu.tetrad.graph.TimeLagGraph in project tetrad by cmu-phil.
the class BooleanGlassSimulation method topToBottomLayout.
public static void topToBottomLayout(TimeLagGraph graph) {
int xStart = 65;
int yStart = 50;
int xSpace = 100;
int ySpace = 100;
List<Node> lag0Nodes = graph.getLag0Nodes();
Collections.sort(lag0Nodes, new Comparator<Node>() {
public int compare(Node o1, Node o2) {
return o1.getCenterX() - o2.getCenterX();
}
});
int x = xStart - xSpace;
for (Node node : lag0Nodes) {
x += xSpace;
int y = yStart - ySpace;
TimeLagGraph.NodeId id = graph.getNodeId(node);
for (int lag = graph.getMaxLag(); lag >= 0; lag--) {
y += ySpace;
Node _node = graph.getNode(id.getName(), lag);
if (_node == null) {
System.out.println("Couldn't find " + _node);
continue;
}
_node.setCenterX(x);
_node.setCenterY(y);
}
}
}
use of edu.cmu.tetrad.graph.TimeLagGraph in project tetrad by cmu-phil.
the class TimeSeriesSemSimulation method createData.
@Override
public void createData(Parameters parameters) {
dataSets = new ArrayList<>();
graphs = new ArrayList<>();
Graph graph = randomGraph.createGraph(parameters);
graph = TimeSeriesUtils.graphToLagGraph(graph, parameters.getInt("numLags"));
topToBottomLayout((TimeLagGraph) graph);
this.knowledge = TimeSeriesUtils.getKnowledge(graph);
for (int i = 0; i < parameters.getInt("numRuns"); i++) {
if (parameters.getBoolean("differentGraphs") && i > 0) {
graph = randomGraph.createGraph(parameters);
graph = TimeSeriesUtils.graphToLagGraph(graph, 2);
topToBottomLayout((TimeLagGraph) graph);
}
graphs.add(graph);
SemPm pm = new SemPm(graph);
SemIm im = new SemIm(pm, parameters);
final int sampleSize = parameters.getInt("sampleSize");
boolean saveLatentVars = parameters.getBoolean("saveLatentVars");
DataSet dataSet = im.simulateData(sampleSize, saveLatentVars);
int numLags = ((TimeLagGraph) graph).getMaxLag();
dataSet = TimeSeriesUtils.createLagData(dataSet, numLags);
dataSet.setName("" + (i + 1));
dataSet.setKnowledge(knowledge.copy());
dataSets.add(dataSet);
// LargeScaleSimulation sim = new LargeScaleSimulation(graph);
// if (parameters.getDouble("coefHigh") > 0.80) {
// System.out.println("Coefficients have been set (perhaps by default) too " +
// "high for stationary time series.");
// System.out.println("Setting coefficient range to [0.20,0.60].");
// sim.setCoefRange(0.20, 0.60);
// } else sim.setCoefRange(parameters.getDouble("coefLow"), parameters.getDouble("coefHigh"));
// boolean isStableTetradMatrix;
// int attempt = 1;
// int tierSize = parameters.getInt("numMeasures") + parameters.getInt("numLatents"); //params.getNumVars();
// int[] sub = new int[tierSize];
// int[] sub2 = new int[tierSize];
// for (int j = 0; j < tierSize; j++) {
// sub[j] = j;
// sub2[j] = tierSize + j;
// }
// DataSet dataSet;
// do {
// dataSet = sim.simulateDataFisher(parameters.getInt("sampleSize")); //params.getSampleSize());
//
// TetradMatrix coefMat = new TetradMatrix(sim.getCoefficientMatrix());
// TetradMatrix B = coefMat.getSelection(sub, sub);
// TetradMatrix Gamma1 = coefMat.getSelection(sub2, sub);
// TetradMatrix Gamma0 = TetradMatrix.identity(tierSize).minus(B);
// TetradMatrix A1 = Gamma0.inverse().times(Gamma1);
//
// isStableTetradMatrix = TimeSeriesUtils.allEigenvaluesAreSmallerThanOneInModulus(A1);
// attempt++;
// } while ((!isStableTetradMatrix) && attempt <= 5);
// if (!isStableTetradMatrix) {
// System.out.println("%%%%%%%%%% WARNING %%%%%%%% not a stable coefficient matrix, forcing coefs to [0.15,0.3]");
// System.out.println("Made " + (attempt - 1) + " attempts to get stable matrix.");
// sim.setCoefRange(0.15, 0.3);
// dataSet = sim.simulateDataFisher(parameters.getInt("sampleSize"));//params.getSampleSize());
// } //else System.out.println("Coefficient matrix is stable.");
// dataSet.setName("" + (i + 1));
// dataSet.setKnowledge(knowledge.copy());
// dataSets.add(dataSet);
}
}
use of edu.cmu.tetrad.graph.TimeLagGraph in project tetrad by cmu-phil.
the class TestTimeLagGraph method test1.
@Test
public void test1() {
TimeLagGraph graph = new TimeLagGraph();
Node x0 = new GraphNode("X");
Node y0 = new GraphNode("Y");
assertTrue(graph.addNode(x0));
assertTrue(graph.addNode(y0));
assertFalse(graph.setMaxLag(2));
Node x1 = graph.getNode("X", 1);
assertTrue(graph.addDirectedEdge(x1, y0));
assertTrue(graph.setMaxLag(4));
assertTrue(graph.setNumInitialLags(2));
assertFalse(graph.setMaxLag(3));
assertTrue(graph.setMaxLag(5));
Node y1 = graph.getNode("Y", 1);
assertTrue(graph.addDirectedEdge(y1, x0));
assertTrue(graph.setMaxLag(1));
assertFalse(graph.setMaxLag(0));
assertFalse(graph.removeHighLagEdges(0));
assertTrue(graph.addDirectedEdge(x0, y0));
}
Aggregations