Search in sources :

Example 1 with LaggedFactor

use of edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor in project tetrad by cmu-phil.

the class HandleyConvert method addEdges.

/**
 * Assumes that the line consists of a cause followed by a number of effects
 * of that cause, in whitespace delimited format; adds the appropriate genes
 * and lagged factors to the lagGraph.
 *
 * @param line the input line described above.
 */
private void addEdges(String line, LagGraph lagGraph) {
    StringTokenizer st = new StringTokenizer(line);
    String cause = st.nextToken();
    while (st.hasMoreTokens()) {
        String effect = st.nextToken();
        if (effect == "") {
            continue;
        }
        System.out.println(cause + " --> " + effect);
        lagGraph.addFactor(effect);
        lagGraph.addEdge(effect, new LaggedFactor(cause, 1));
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) LaggedFactor(edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor)

Example 2 with LaggedFactor

use of edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor 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 3 with LaggedFactor

use of edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor in project tetrad by cmu-phil.

the class ActiveLagGraph method removeFactor.

/**
 * Attempts to remove a factor from the graph. Will also search through and
 * remove any edges that involve this edge. </p> Will throw a propertyChange
 * event of ((String) factor_removed, null).
 */
public void removeFactor(String factor) {
    try {
        lagGraph.removeFactor(factor);
        getPropertyChangeManager().firePropertyChange("nodeRemoved", factor, null);
        // search through and find edges which were sourced by this factor
        // and remove them
        ArrayList toDelete = new ArrayList();
        SortedSet factors = getFactors();
        Iterator f = factors.iterator();
        // have to search through all destination factors to find edges to remove
        while (f.hasNext()) {
            String destFactor = (String) f.next();
            SortedSet parents = lagGraph.getParents(destFactor);
            Iterator p = parents.iterator();
            // find edges sourced by factor
            while (p.hasNext()) {
                LaggedFactor lf = (LaggedFactor) p.next();
                if (lf.getFactor().equals(factor)) {
                    toDelete.add(lf);
                }
            }
            // remove those edges
            Iterator d = toDelete.iterator();
            while (d.hasNext()) {
                removeEdge(destFactor, (LaggedFactor) d.next());
            }
            toDelete.clear();
        }
    } catch (Exception e) {
    // Ignore.
    }
}
Also used : LaggedFactor(edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor) IOException(java.io.IOException)

Aggregations

LaggedFactor (edu.cmu.tetrad.gene.tetrad.gene.history.LaggedFactor)3 LagGraphParams (edu.cmu.tetrad.gene.tetrad.gene.graph.LagGraphParams)1 RandomActiveLagGraph (edu.cmu.tetrad.gene.tetrad.gene.graph.RandomActiveLagGraph)1 BooleanGlassGeneIm (edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGeneIm)1 BooleanGlassGenePm (edu.cmu.tetrad.gene.tetradapp.model.BooleanGlassGenePm)1 Node (edu.cmu.tetrad.graph.Node)1 TimeLagGraph (edu.cmu.tetrad.graph.TimeLagGraph)1 IOException (java.io.IOException)1 StringTokenizer (java.util.StringTokenizer)1