Search in sources :

Example 96 with Parameters

use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.

the class GlassoSearchEditor method getIndTestParamBox.

private JComponent getIndTestParamBox() {
    final Parameters params = getAlgorithmRunner().getParams();
    IntTextField maxItField = new IntTextField((int) params.get("maxit", 10000), 6);
    maxItField.setFilter(new IntTextField.Filter() {

        public int filter(int value, int oldValue) {
            try {
                params.set("maxit", value);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    DoubleTextField thrField = new DoubleTextField(params.getDouble("thr", 1e-4), 8, new DecimalFormat("0.0########"), new DecimalFormat("0.00E00"), 1e-4);
    thrField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("thr", value);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    JCheckBox iaCheckBox = new JCheckBox("Meinhausen-Buhlman");
    iaCheckBox.setSelected(params.getBoolean("ia", false));
    iaCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("is", checkBox.isSelected());
        }
    });
    JCheckBox isCheckBox = new JCheckBox("Warm start");
    isCheckBox.setSelected(params.getBoolean("ia", false));
    isCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("is", checkBox.isSelected());
        }
    });
    JCheckBox itrCheckBox = new JCheckBox("Log trace");
    itrCheckBox.setSelected(params.getBoolean("ia", false));
    itrCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("itr", checkBox.isSelected());
        }
    });
    JCheckBox ipenCheckBox = new JCheckBox("Penalize diagonal");
    ipenCheckBox.setSelected(params.getBoolean("ipen", false));
    ipenCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("ipen", checkBox.isSelected());
        }
    });
    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Max iterations"));
    b1.add(Box.createHorizontalGlue());
    b1.add(maxItField);
    b.add(b1);
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Threshold"));
    b2.add(Box.createHorizontalGlue());
    b2.add(thrField);
    b.add(b2);
    Box b3 = Box.createHorizontalBox();
    b3.add(iaCheckBox);
    b3.add(Box.createHorizontalGlue());
    b.add(b3);
    Box b4 = Box.createHorizontalBox();
    b4.add(isCheckBox);
    b4.add(Box.createHorizontalGlue());
    b.add(b4);
    Box b5 = Box.createHorizontalBox();
    b5.add(itrCheckBox);
    b5.add(Box.createHorizontalGlue());
    b.add(b5);
    Box b6 = Box.createHorizontalBox();
    b6.add(ipenCheckBox);
    b6.add(Box.createHorizontalGlue());
    b.add(b6);
    return b;
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) ActionEvent(java.awt.event.ActionEvent) DecimalFormat(java.text.DecimalFormat) ActionListener(java.awt.event.ActionListener) IntTextField(edu.cmu.tetradapp.util.IntTextField)

Example 97 with Parameters

use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.

the class TsFciRunner method execute.

// =================PUBLIC METHODS OVERRIDING ABSTRACT=================//
/**
 * Executes the algorithm, producing (at least) a result workbench. Must be
 * implemented in the extending class.
 */
public void execute() {
    if (this.knowledge == null) {
        knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    }
    /*else {knowledge = this.knowledge;}*/
    Parameters searchParams = getParams();
    Parameters params = searchParams;
    // Cfci fciSearch =
    // new Cfci(getIndependenceTest(), knowledge);
    // fciSearch.setMaxIndegree(params.depth());
    // Graph graph = fciSearch.search();
    // 
    // if (knowledge.isDefaultToKnowledgeLayout()) {
    // SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    // }
    // 
    // setResultGraph(graph);
    Graph graph;
    if (params.getBoolean("rfciUsed", false)) {
        System.out.println("WARNING: there is no RFCI option for tsFCI! Just using tsFCI.");
        // Rfci fci = new Rfci(getIndependenceTest());
        TsFci fci = new TsFci(getIndependenceTest());
        fci.setKnowledge(knowledge);
        fci.setCompleteRuleSetUsed(true);
        fci.setMaxPathLength(params.getInt("maxReachablePathLength", -1));
        fci.setDepth(params.getInt("depth", -1));
        graph = fci.search();
    } else {
        TsFci fci = new TsFci(getIndependenceTest());
        fci.setKnowledge(knowledge);
        fci.setCompleteRuleSetUsed(true);
        fci.setPossibleDsepSearchDone(params.getBoolean("possibleDsepDone", true));
        fci.setMaxPathLength(params.getInt("maxReachablePathLength", -1));
        fci.setDepth(params.getInt("depth", -1));
        graph = fci.search();
    }
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (knowledge.isDefaultToKnowledgeLayout()) {
        SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) TsFci(edu.cmu.tetrad.search.TsFci) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 98 with Parameters

use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.

the class TsImagesRunner method execute.

// ============================PUBLIC METHODS==========================//
/**
 * Executes the algorithm, producing (at least) a result workbench. Must be
 * implemented in the extending class.
 */
public void execute() {
    Object model = getDataModel();
    if (model == null && getSourceGraph() != null) {
        model = getSourceGraph();
    }
    if (model == null) {
        throw new RuntimeException("Data source is unspecified. You may need to double click all your data boxes, \n" + "then click Save, and then right click on them and select Propagate Downstream. \n" + "The issue is that we use a seed to simulate from IM's, so your data is not saved to \n" + "file when you save the session. It can, however, be recreated from the saved seed.");
    }
    double penaltyDiscount = getParams().getDouble("penaltyDiscount", 4);
    if (model instanceof Graph) {
        GraphScore gesScore = new GraphScore((Graph) model);
        IndependenceTest test = new IndTestScore(gesScore);
        fges = new TsGFci(test, gesScore);
    } else if (model instanceof DataSet) {
        DataSet dataSet = (DataSet) model;
        if (dataSet.isContinuous()) {
            SemBicScore gesScore = new SemBicScore(new CovarianceMatrixOnTheFly((DataSet) model));
            gesScore.setPenaltyDiscount(penaltyDiscount);
            IndependenceTest test = new IndTestScore(gesScore);
            fges = new TsGFci(test, gesScore);
        } else if (dataSet.isDiscrete()) {
            double samplePrior = getParams().getDouble("samplePrior", 1);
            double structurePrior = getParams().getDouble("structurePrior", 1);
            BDeuScore score = new BDeuScore(dataSet);
            score.setSamplePrior(samplePrior);
            score.setStructurePrior(structurePrior);
            IndependenceTest test = new IndTestScore(score);
            fges = new TsGFci(test, score);
        } else {
            throw new IllegalStateException("Data set must either be continuous or discrete.");
        }
    } else if (model instanceof ICovarianceMatrix) {
        SemBicScore gesScore = new SemBicScore((ICovarianceMatrix) model);
        gesScore.setPenaltyDiscount(penaltyDiscount);
        IndependenceTest test = new IndTestScore(gesScore);
        fges = new TsGFci(test, gesScore);
    } else if (model instanceof DataModelList) {
        DataModelList list = (DataModelList) model;
        for (DataModel dataModel : list) {
            if (!(dataModel instanceof DataSet || dataModel instanceof ICovarianceMatrix)) {
                throw new IllegalArgumentException("Need a combination of all continuous data sets or " + "covariance matrices, or else all discrete data sets, or else a single graph.");
            }
        }
        // if (list.size() != 1) {
        // throw new IllegalArgumentException("FGES takes exactly one data set, covariance matrix, or graph " +
        // "as input. For multiple data sets as input, use IMaGES.");
        // }
        Parameters Parameters = getParams();
        if (allContinuous(list)) {
            double penalty = penaltyDiscount;
            SemBicScoreImages fgesScore = new SemBicScoreImages(list);
            fgesScore.setPenaltyDiscount(penalty);
            IndependenceTest test = new IndTestScore(fgesScore);
            fges = new TsGFci(test, fgesScore);
        } else if (allDiscrete(list)) {
            double structurePrior = getParams().getDouble("structurePrior", 1);
            double samplePrior = getParams().getDouble("samplePrior", 1);
            BdeuScoreImages fgesScore = new BdeuScoreImages(list);
            fgesScore.setSamplePrior(samplePrior);
            fgesScore.setStructurePrior(structurePrior);
            IndependenceTest test = new IndTestScore(fgesScore);
            fges = new TsGFci(test, fgesScore);
        } else {
            throw new IllegalArgumentException("Data must be either all discrete or all continuous.");
        }
    } else {
        System.out.println("No viable input.");
    }
    fges.setKnowledge((IKnowledge) getParams().get("knowledge", new Knowledge2()));
    // fges.setNumPatternsToStore(params.getNumPatternsToSave()); // removed for TsGFci
    // fges.setHeuristicSpeedup(((Parameters) params.getIndTestParams()).isFaithfulnessAssumed()); // removed for TsGFci
    fges.setVerbose(true);
    Graph graph = fges.search();
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (((IKnowledge) getParams().get("knowledge", new Knowledge2())).isDefaultToKnowledgeLayout()) {
        SearchGraphUtils.arrangeByKnowledgeTiers(graph, (IKnowledge) getParams().get("knowledge", new Knowledge2()));
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
    this.topGraphs = new ArrayList<>(getTopGraphs());
    if (topGraphs.isEmpty()) {
        topGraphs.add(new ScoredGraph(getResultGraph(), Double.NaN));
    }
    this.topGraphs = new ArrayList<>(getTopGraphs());
    if (this.topGraphs.isEmpty()) {
        this.topGraphs.add(new ScoredGraph(getResultGraph(), Double.NaN));
    }
    setIndex(topGraphs.size() - 1);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Graph(edu.cmu.tetrad.graph.Graph)

Example 99 with Parameters

use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.

the class LingRunner 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.");
// }
// 
// Ling ling = new Ling(data);
// Parameters searchParams = (Parameters) getParameters();
// ling.setThreshold(searchParams.getThreshold());
// Ling.StoredGraphs graphs = ling.search();
// Graph graph = null;
// 
// for (int i = 0; i < graphs.getNumGraphs(); i++) {
// System.out.println(graphs.getGraph(i));
// System.out.println(graphs.isStable(i));
// }
// 
// for (int i = 0; i < graphs.getNumGraphs(); i++) {
// if (graphs.isStable(i)) {
// graph = graphs.getGraph(i);
// break;
// }
// }
// 
// if (graph == null) {
// graph = new EdgeListGraph();
// }
// 
// setResultGraph(graph);
// setStoredGraphs(graphs);
// 
// if (getSourceGraph() != null) {
// DataGraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
// }
// else {
// DataGraphUtils.circleLayout(graph, 200, 200, 150);
// }
// 
// }
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.");
    }
    Ling ling = new Ling(data);
    Parameters searchParams = getParams();
    ling.setThreshold(searchParams.getDouble("threshold", 0.5));
    Ling.StoredGraphs graphs = ling.search();
    Graph graph = null;
    for (int i = 0; i < graphs.getNumGraphs(); i++) {
        System.out.println(graphs.getGraph(i));
        System.out.println(graphs.isStable(i));
    }
    for (int i = 0; i < graphs.getNumGraphs(); i++) {
        if (graphs.isStable(i)) {
            graph = graphs.getGraph(i);
            break;
        }
    }
    if (graph == null) {
        graph = new EdgeListGraph();
    }
    setResultGraph(graph);
    setStoredGraphs(graphs);
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
}
Also used : Ling(edu.cmu.tetrad.search.Ling) Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel)

Example 100 with Parameters

use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.

the class LogisticRegressionRunner method serializableInstance.

/**
 * Generates a simple exemplar of this class to test serialization.
 *
 * @see TetradSerializableUtils
 */
public static LogisticRegressionRunner serializableInstance() {
    List<Node> variables = new LinkedList<>();
    ContinuousVariable var1 = new ContinuousVariable("X");
    ContinuousVariable var2 = new ContinuousVariable("Y");
    variables.add(var1);
    variables.add(var2);
    DataSet dataSet = new ColtDataSet(3, variables);
    double[] col1data = new double[] { 0.0, 1.0, 2.0 };
    double[] col2data = new double[] { 2.3, 4.3, 2.5 };
    for (int i = 0; i < 3; i++) {
        dataSet.setDouble(i, 0, col1data[i]);
        dataSet.setDouble(i, 1, col2data[i]);
    }
    DataWrapper dataWrapper = new DataWrapper(dataSet);
    return new LogisticRegressionRunner(dataWrapper, new Parameters());
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Parameters(edu.cmu.tetrad.util.Parameters) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList)

Aggregations

Parameters (edu.cmu.tetrad.util.Parameters)134 Comparison (edu.cmu.tetrad.algcomparison.Comparison)30 Graph (edu.cmu.tetrad.graph.Graph)26 Algorithms (edu.cmu.tetrad.algcomparison.algorithm.Algorithms)25 DataSet (edu.cmu.tetrad.data.DataSet)22 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)20 IKnowledge (edu.cmu.tetrad.data.IKnowledge)18 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)17 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)14 ArrayList (java.util.ArrayList)14 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)13 Test (org.junit.Test)13 Node (edu.cmu.tetrad.graph.Node)11 ActionEvent (java.awt.event.ActionEvent)10 ActionListener (java.awt.event.ActionListener)10 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)8 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)8 DataModel (edu.cmu.tetrad.data.DataModel)8 TitledBorder (javax.swing.border.TitledBorder)8 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)7