Search in sources :

Example 6 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class MimSearchEditor2 method getIndTestParamBox.

/**
 * Factory to return the correct param editor for independence test params.
 * This will go in a little box in the search editor.
 */
private JComponent getIndTestParamBox(Parameters params) {
    if (params == null) {
        throw new NullPointerException();
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        DataModel dataModel = runner.getData();
        if (dataModel instanceof DataSet) {
            DataSet data = (DataSet) runner.getData();
            boolean discrete = data.isDiscrete();
            return new BuildPureClustersIndTestParamsEditor2(params, discrete);
        } else if (dataModel instanceof ICovarianceMatrix) {
            return new BuildPureClustersIndTestParamsEditor2(params, false);
        }
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        boolean discreteData = false;
        if (runner.getData() instanceof DataSet) {
            discreteData = ((DataSet) runner.getData()).isDiscrete();
        }
        return new PurifyIndTestParamsEditor(params, discreteData);
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        return new MimBuildIndTestParamsEditor(params);
    }
    throw new IllegalArgumentException("Unrecognized Parameters: " + params.getClass());
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) MimRunner(edu.cmu.tetradapp.model.MimRunner)

Example 7 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class MbSearchEditor method addSpecialMenus.

protected void addSpecialMenus(JMenuBar menuBar) {
    JMenu test = new JMenu("Independence");
    menuBar.add(test);
    IndTestMenuItems.addIndependenceTestChoices(test, this);
    if (getAlgorithmRunner() instanceof MbfsRunner) {
        JMenu graph = new JMenu("Graph");
        JMenuItem showDags = new JMenuItem("Show DAG's Consistent with forbid_latent_common_causes");
        // JMenuItem meekOrient = new JMenuItem("Meek Orientation");
        JMenuItem gesOrient = new JMenuItem("Global Score-based Reorientation");
        JMenuItem nextGraph = new JMenuItem("Next Graph");
        JMenuItem previousGraph = new JMenuItem("Previous Graph");
        graph.add(new GraphPropertiesAction(getWorkbench()));
        graph.add(new PathsAction(getWorkbench()));
        // graph.add(new DirectedPathsAction(getWorkbench()));
        // graph.add(new TreksAction(getWorkbench()));
        // graph.add(new AllPathsAction(getWorkbench()));
        // graph.add(new NeighborhoodsAction(getWorkbench()));
        graph.addSeparator();
        // graph.add(meekOrient);
        graph.add(gesOrient);
        graph.addSeparator();
        graph.add(previousGraph);
        graph.add(nextGraph);
        graph.addSeparator();
        graph.add(showDags);
        menuBar.add(graph);
        showDags.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                AlgorithmRunner runner = getAlgorithmRunner();
                if (!(runner instanceof MbfsRunner)) {
                    return;
                }
                MbfsRunner mbRunner = (MbfsRunner) runner;
                final Mbfs search = mbRunner.getMbFanSearch();
                if (search == null) {
                    JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "The search was not stored.");
                    return;
                }
                MbPatternDisplay display = new MbPatternDisplay(search);
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), display, "MB DAG's Consistent with forbid_latent_common_causes", JOptionPane.PLAIN_MESSAGE);
            }
        });
        // meekOrient.addActionListener(new ActionListener() {
        // public void actionPerformed(ActionEvent e) {
        // ImpliedOrientation rules = getAlgorithmRunner().getMeekRules();
        // rules.setKnowledge((IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2()));
        // rules.orientImplied(getGraph());
        // getWorkbench().setGraph(getGraph());
        // }
        // });
        gesOrient.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                DataModel dataModel = getAlgorithmRunner().getDataModel();
                final Graph graph = SearchGraphUtils.reorient(getGraph(), dataModel, getKnowledge());
                getGraphHistory().add(graph);
                getWorkbench().setGraph(graph);
                firePropertyChange("modelChanged", null, null);
            }
        });
    }
    // if (getAlgorithmRunner().supportsKnowledge()) {
    // menuBar.add(new Knowledge2Menu(this));
    // }
    menuBar.add(new LayoutMenu(this));
}
Also used : LayoutMenu(edu.cmu.tetradapp.workbench.LayoutMenu) ActionEvent(java.awt.event.ActionEvent) Mbfs(edu.cmu.tetrad.search.Mbfs) Graph(edu.cmu.tetrad.graph.Graph) ActionListener(java.awt.event.ActionListener) DataModel(edu.cmu.tetrad.data.DataModel)

Example 8 with DataModel

use of edu.cmu.tetrad.data.DataModel 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 9 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class TsImages method search.

@Override
public Graph search(List<DataModel> dataSets, Parameters parameters) {
    List<DataModel> dataModels = new ArrayList<>();
    for (DataModel dataSet : dataSets) {
        dataModels.add(dataSet);
    }
    TsGFci search;
    if (score instanceof SemBicScore) {
        SemBicScoreImages gesScore = new SemBicScoreImages(dataModels);
        gesScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
        IndependenceTest test = new IndTestScore(gesScore);
        search = new TsGFci(test, gesScore);
    } else if (score instanceof BdeuScore) {
        double samplePrior = parameters.getDouble("samplePrior", 1);
        double structurePrior = parameters.getDouble("structurePrior", 1);
        BdeuScoreImages score = new BdeuScoreImages(dataModels);
        score.setSamplePrior(samplePrior);
        score.setStructurePrior(structurePrior);
        IndependenceTest test = new IndTestScore(score);
        search = new TsGFci(test, score);
    } else {
        throw new IllegalStateException("Sorry, data must either be all continuous or all discrete.");
    }
    IKnowledge knowledge = dataModels.get(0).getKnowledge();
    search.setKnowledge(knowledge);
    return search.search();
}
Also used : BdeuScoreImages(edu.cmu.tetrad.search.BdeuScoreImages) IKnowledge(edu.cmu.tetrad.data.IKnowledge) IndependenceTest(edu.cmu.tetrad.search.IndependenceTest) SemBicScoreImages(edu.cmu.tetrad.search.SemBicScoreImages) DataModel(edu.cmu.tetrad.data.DataModel) IndTestScore(edu.cmu.tetrad.search.IndTestScore) BdeuScore(edu.cmu.tetrad.algcomparison.score.BdeuScore) ArrayList(java.util.ArrayList) TsGFci(edu.cmu.tetrad.search.TsGFci) SemBicScore(edu.cmu.tetrad.algcomparison.score.SemBicScore)

Example 10 with DataModel

use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.

the class LingamStructureRunner method execute.

// ============================PUBLIC METHODS==========================//
/**
 * Executes the algorithm, producing (at least) a result workbench. Must be
 * implemented in the extending class.
 */
public void execute() {
    DataModel source = getDataModel();
    if (!(source instanceof DataSet)) {
        throw new IllegalArgumentException("Expecting a rectangular data set.");
    }
    DataSet data = (DataSet) source;
    if (!data.isContinuous()) {
        throw new IllegalArgumentException("Expecting a continuous data set.");
    }
    // Lingam_old lingam = new Lingam_old();
    // lingam.setAlternativePenalty(getParameters().getAlternativePenalty());
    // lingam.setPruningDone(true);
    // lingam.setAlternativePenalty(getParameters().getAlternativePenalty());
    // GraphWithParameters result = lingam.lingam(data);
    // Graph graph = result.getGraph();
    Lingam lingam = new Lingam();
    Parameters params = getParams();
    Graph graph = lingam.search(data);
    setResultGraph(graph);
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) Lingam(edu.cmu.tetrad.search.Lingam)

Aggregations

DataModel (edu.cmu.tetrad.data.DataModel)39 DataSet (edu.cmu.tetrad.data.DataSet)22 ArrayList (java.util.ArrayList)15 DataWrapper (edu.cmu.tetradapp.model.DataWrapper)13 Graph (edu.cmu.tetrad.graph.Graph)9 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)8 Parameters (edu.cmu.tetrad.util.Parameters)8 DataModelList (edu.cmu.tetrad.data.DataModelList)7 Node (edu.cmu.tetrad.graph.Node)7 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 List (java.util.List)5 LayoutMenu (edu.cmu.tetradapp.workbench.LayoutMenu)4 DoubleTextField (edu.cmu.tetradapp.util.DoubleTextField)3 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)3 GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)3 IOException (java.io.IOException)3 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)2 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)2 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2