Search in sources :

Example 1 with TimeLagGraph

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;
}
Also used : LagGraphParams(edu.cmu.tetrad.gene.tetrad.gene.graph.LagGraphParams) BooleanGlassGenePm(edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGenePm) Node(edu.cmu.tetrad.graph.Node) BooleanGlassGeneIm(edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGeneIm) RandomActiveLagGraph(edu.cmu.tetrad.gene.tetrad.gene.graph.RandomActiveLagGraph) TimeLagGraph(edu.cmu.tetrad.graph.TimeLagGraph) LaggedFactor(edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor)

Example 2 with TimeLagGraph

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);
        }
    }
}
Also used : Node(edu.cmu.tetrad.graph.Node) TimeLagGraph(edu.cmu.tetrad.graph.TimeLagGraph)

Example 3 with TimeLagGraph

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);
        }
    }
}
Also used : Node(edu.cmu.tetrad.graph.Node) TimeLagGraph(edu.cmu.tetrad.graph.TimeLagGraph)

Example 4 with TimeLagGraph

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);
    }
}
Also used : TimeLagGraph(edu.cmu.tetrad.graph.TimeLagGraph) Graph(edu.cmu.tetrad.graph.Graph) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SingleGraph(edu.cmu.tetrad.algcomparison.graph.SingleGraph) SemPm(edu.cmu.tetrad.sem.SemPm) TimeLagGraph(edu.cmu.tetrad.graph.TimeLagGraph) SemIm(edu.cmu.tetrad.sem.SemIm)

Example 5 with TimeLagGraph

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));
}
Also used : GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) TimeLagGraph(edu.cmu.tetrad.graph.TimeLagGraph) GraphNode(edu.cmu.tetrad.graph.GraphNode) Test(org.junit.Test)

Aggregations

TimeLagGraph (edu.cmu.tetrad.graph.TimeLagGraph)6 Node (edu.cmu.tetrad.graph.Node)5 Graph (edu.cmu.tetrad.graph.Graph)2 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)1 SingleGraph (edu.cmu.tetrad.algcomparison.graph.SingleGraph)1 LagGraphParams (edu.cmu.tetrad.gene.tetrad.gene.graph.LagGraphParams)1 RandomActiveLagGraph (edu.cmu.tetrad.gene.tetrad.gene.graph.RandomActiveLagGraph)1 LaggedFactor (edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor)1 BooleanGlassGeneIm (edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGeneIm)1 BooleanGlassGenePm (edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGenePm)1 GraphNode (edu.cmu.tetrad.graph.GraphNode)1 SemIm (edu.cmu.tetrad.sem.SemIm)1 SemPm (edu.cmu.tetrad.sem.SemPm)1 Test (org.junit.Test)1