Search in sources :

Example 1 with Node

use of edu.cmu.tetrad.graph.Node 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();
    }
}
Also used : ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) StringTokenizer(java.util.StringTokenizer) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) TimeSeriesData(edu.cmu.tetrad.data.TimeSeriesData)

Example 2 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class ScatterPlot method getRegressionResult.

private RegressionResult getRegressionResult() {
    List<Node> regressors = new ArrayList<>();
    regressors.add(dataSet.getVariable(x));
    Node target = dataSet.getVariable(y);
    Regression regression = new RegressionDataset(dataSet);
    RegressionResult result = regression.regress(target, regressors);
    System.out.println(result);
    return result;
}
Also used : RegressionDataset(edu.cmu.tetrad.regression.RegressionDataset) Node(edu.cmu.tetrad.graph.Node) Regression(edu.cmu.tetrad.regression.Regression) RegressionResult(edu.cmu.tetrad.regression.RegressionResult)

Example 3 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class ScatterPlot method removeConditioningVariable.

/**
 * Removes a conditioning variable.
 *
 * @param variable The name of the conditioning variable to remove.
 */
public void removeConditioningVariable(String variable) {
    Node node = dataSet.getVariable(variable);
    if (!(continuousIntervals.containsKey(node))) {
        throw new IllegalArgumentException("Not a conditioning node: " + variable);
    }
    continuousIntervals.remove(node);
}
Also used : Node(edu.cmu.tetrad.graph.Node)

Example 4 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class PcSearchParamEditor method setup.

public void setup() {
    /*
      The variable names from the object being searched over (usually data).
     */
    List<String> varNames = (List<String>) params.get("varNames", null);
    DataModel dataModel1 = null;
    Graph graph = null;
    for (Object parentModel1 : this.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<Node> it = graph.getNodes().iterator();
        varNames = new ArrayList();
        Node temp;
        while (it.hasNext()) {
            temp = 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).");
    }
    this.params.set("varNames", varNames);
    IntTextField depthField = new IntTextField(this.params.getInt("depth", -1), 4);
    depthField.setFilter(new IntTextField.Filter() {

        public int filter(int value, int oldValue) {
            try {
                PcSearchParamEditor.this.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 {
                    PcSearchParamEditor.this.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 b2 = Box.createHorizontalBox();
        b2.add(new JLabel("Alpha Value:"));
        b2.add(Box.createGlue());
        b2.add(alphaField);
        add(b2);
        add(Box.createVerticalStrut(10));
    }
    Box b3 = Box.createHorizontalBox();
    b3.add(new JLabel("Search Depth:"));
    b3.add(Box.createGlue());
    b3.add(depthField);
    add(b3);
    add(Box.createVerticalStrut(10));
}
Also used : Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DagWrapper(edu.cmu.tetradapp.model.DagWrapper) MatteBorder(javax.swing.border.MatteBorder) IntTextField(edu.cmu.tetradapp.util.IntTextField) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper) DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper) GraphWrapper(edu.cmu.tetradapp.model.GraphWrapper) Graph(edu.cmu.tetrad.graph.Graph) DataModel(edu.cmu.tetrad.data.DataModel)

Example 5 with Node

use of edu.cmu.tetrad.graph.Node in project tetrad by cmu-phil.

the class ScoredGraphsDisplay method pasteSubsession.

public void pasteSubsession(List sessionElements, Point upperLeft) {
    getWorkbench().pasteSubgraph(sessionElements, upperLeft);
    getWorkbench().deselectAll();
    for (int i = 0; i < sessionElements.size(); i++) {
        Object o = sessionElements.get(i);
        if (o instanceof GraphNode) {
            Node modelNode = (Node) o;
            getWorkbench().selectNode(modelNode);
        }
    }
    getWorkbench().selectConnectingEdges();
}
Also used : GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) DisplayNode(edu.cmu.tetradapp.workbench.DisplayNode) GraphNode(edu.cmu.tetrad.graph.GraphNode)

Aggregations

Node (edu.cmu.tetrad.graph.Node)674 ArrayList (java.util.ArrayList)129 Graph (edu.cmu.tetrad.graph.Graph)106 GraphNode (edu.cmu.tetrad.graph.GraphNode)64 DataSet (edu.cmu.tetrad.data.DataSet)59 LinkedList (java.util.LinkedList)55 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)48 Test (org.junit.Test)48 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)46 List (java.util.List)45 Dag (edu.cmu.tetrad.graph.Dag)41 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)41 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)40 ChoiceGenerator (edu.cmu.tetrad.util.ChoiceGenerator)37 Endpoint (edu.cmu.tetrad.graph.Endpoint)29 DisplayNode (edu.cmu.tetradapp.workbench.DisplayNode)26 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)25 Edge (edu.cmu.tetrad.graph.Edge)23 SemIm (edu.cmu.tetrad.sem.SemIm)19 DepthChoiceGenerator (edu.cmu.tetrad.util.DepthChoiceGenerator)19