Search in sources :

Example 6 with GraphWrapper

use of edu.cmu.tetradapp.model.GraphWrapper in project tetrad by cmu-phil.

the class RegressionParamsPanel method getVarsFromGraph.

private List<String> getVarsFromGraph(Object[] parentModels) {
    Object graphWrapper = null;
    for (Object parentModel : parentModels) {
        if (parentModel instanceof GraphWrapper) {
            graphWrapper = parentModel;
        } else if (parentModel instanceof DagWrapper) {
            graphWrapper = parentModel;
        }
    }
    if (graphWrapper == null) {
        return null;
    } else {
        Graph graph = null;
        if (graphWrapper instanceof GraphWrapper) {
            graph = ((GraphWrapper) graphWrapper).getGraph();
        } else if (graphWrapper instanceof DagWrapper) {
            graph = ((DagWrapper) graphWrapper).getDag();
        }
        List<Node> nodes = graph.getNodes();
        List<String> nodeNames = new LinkedList<>();
        for (Node node : nodes) {
            nodeNames.add(node.getName());
        }
        return nodeNames;
    }
}
Also used : DagWrapper(edu.cmu.tetradapp.model.DagWrapper) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) GraphWrapper(edu.cmu.tetradapp.model.GraphWrapper) LinkedList(java.util.LinkedList)

Example 7 with GraphWrapper

use of edu.cmu.tetradapp.model.GraphWrapper in project tetrad by cmu-phil.

the class TabularComparisonEditor method setup.

private void setup() {
    java.util.List<Graph> referenceGraphs = comparison.getReferenceGraphs();
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP);
    pane.addTab("Comparison", getTableDisplay());
    JTabbedPane pane2 = new JTabbedPane(JTabbedPane.LEFT);
    for (int i = 0; i < referenceGraphs.size(); i++) {
        JTabbedPane pane3 = new JTabbedPane(JTabbedPane.TOP);
        pane3.add("Target Graph", new GraphEditor(new GraphWrapper(comparison.getTargetGraphs().get(i))).getWorkbench());
        pane3.add("True Graph", new GraphEditor(new GraphWrapper(comparison.getReferenceGraphs().get(i))).getWorkbench());
        pane2.add("" + (i + 1), pane3);
    }
    pane.addTab("Graphs", pane2);
    add(pane);
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) GraphWrapper(edu.cmu.tetradapp.model.GraphWrapper)

Example 8 with GraphWrapper

use of edu.cmu.tetradapp.model.GraphWrapper in project tetrad by cmu-phil.

the class SearchParamEditor method setup.

public void setup() {
    /*
      The variable names from the object being searched over (usually data).
     */
    List varNames = (List<String>) params.get("varNames", null);
    DataModel dataModel1 = null;
    Graph graph = null;
    for (Object parentModel1 : parentModels) {
        if (parentModel1 instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel1;
            dataModel1 = dataWrapper.getSelectedDataModel();
        }
        if (parentModel1 instanceof GraphWrapper) {
            GraphWrapper graphWrapper = (GraphWrapper) parentModel1;
            graph = graphWrapper.getGraph();
        }
        if (parentModel1 instanceof DagWrapper) {
            DagWrapper dagWrapper = (DagWrapper) parentModel1;
            graph = dagWrapper.getDag();
        }
        if (parentModel1 instanceof SemGraphWrapper) {
            SemGraphWrapper semGraphWrapper = (SemGraphWrapper) parentModel1;
            graph = semGraphWrapper.getGraph();
        }
    }
    if (dataModel1 != null) {
        varNames = new ArrayList(dataModel1.getVariableNames());
    } else if (graph != null) {
        Iterator it = graph.getNodes().iterator();
        varNames = new ArrayList();
        Node temp;
        while (it.hasNext()) {
            temp = (Node) it.next();
            if (temp.getNodeType() == NodeType.MEASURED) {
                varNames.add(temp.getName());
            }
        }
    } else {
        throw new NullPointerException("Null model (no graph or data model " + "passed to the search).");
    }
    params.set("varNames", varNames);
    IntTextField depthField = new IntTextField(params.getInt("depth", -1), 4);
    depthField.setFilter(new IntTextField.Filter() {

        public int filter(int value, int oldValue) {
            try {
                params.set("depth", value);
                Preferences.userRoot().putInt("depth", value);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    double alpha = params.getDouble("alpha", 0.001);
    if (!Double.isNaN(alpha)) {
        alphaField = new DoubleTextField(alpha, 4, NumberFormatUtil.getInstance().getNumberFormat());
        alphaField.setFilter(new DoubleTextField.Filter() {

            public double filter(double value, double oldValue) {
                try {
                    params.set("alpha", 0.001);
                    Preferences.userRoot().putDouble("alpha", value);
                    return value;
                } catch (Exception e) {
                    return oldValue;
                }
            }
        });
    }
    setBorder(new MatteBorder(10, 10, 10, 10, super.getBackground()));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    if (!Double.isNaN(alpha)) {
        Box b0 = Box.createHorizontalBox();
        b0.add(new JLabel("Alpha Value:"));
        b0.add(Box.createGlue());
        b0.add(alphaField);
        add(b0);
        add(Box.createVerticalStrut(10));
    }
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Search Depth:"));
    b1.add(Box.createGlue());
    b1.add(depthField);
    add(b1);
    add(Box.createVerticalStrut(10));
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) Node(edu.cmu.tetrad.graph.Node) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper) GraphWrapper(edu.cmu.tetradapp.model.GraphWrapper) ArrayList(java.util.ArrayList) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DagWrapper(edu.cmu.tetradapp.model.DagWrapper) MatteBorder(javax.swing.border.MatteBorder) Graph(edu.cmu.tetrad.graph.Graph) DataModel(edu.cmu.tetrad.data.DataModel) IntTextField(edu.cmu.tetradapp.util.IntTextField) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper)

Aggregations

Graph (edu.cmu.tetrad.graph.Graph)8 GraphWrapper (edu.cmu.tetradapp.model.GraphWrapper)8 Node (edu.cmu.tetrad.graph.Node)5 DagWrapper (edu.cmu.tetradapp.model.DagWrapper)5 DataModel (edu.cmu.tetrad.data.DataModel)3 DataWrapper (edu.cmu.tetradapp.model.DataWrapper)3 SemGraphWrapper (edu.cmu.tetradapp.model.SemGraphWrapper)3 DoubleTextField (edu.cmu.tetradapp.util.DoubleTextField)3 IntTextField (edu.cmu.tetradapp.util.IntTextField)3 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 List (java.util.List)3 MatteBorder (javax.swing.border.MatteBorder)3 LinkedList (java.util.LinkedList)2