Search in sources :

Example 16 with BayesIm

use of edu.cmu.tetrad.bayes.BayesIm in project tetrad by cmu-phil.

the class TestProposition method sampleBayesIm2.

private BayesIm sampleBayesIm2() {
    Node a = new GraphNode("a");
    Node b = new GraphNode("b");
    Node c = new GraphNode("c");
    Dag graph;
    graph = new Dag();
    graph.addNode(a);
    graph.addNode(b);
    graph.addNode(c);
    graph.addDirectedEdge(a, b);
    graph.addDirectedEdge(a, c);
    graph.addDirectedEdge(b, c);
    BayesPm bayesPm = new BayesPm(graph);
    bayesPm.setNumCategories(b, 3);
    BayesIm bayesIm1 = new MlBayesIm(bayesPm);
    bayesIm1.setProbability(0, 0, 0, .3);
    bayesIm1.setProbability(0, 0, 1, .7);
    bayesIm1.setProbability(1, 0, 0, .3);
    bayesIm1.setProbability(1, 0, 1, .4);
    bayesIm1.setProbability(1, 0, 2, .3);
    bayesIm1.setProbability(1, 1, 0, .6);
    bayesIm1.setProbability(1, 1, 1, .1);
    bayesIm1.setProbability(1, 1, 2, .3);
    bayesIm1.setProbability(2, 0, 0, .9);
    bayesIm1.setProbability(2, 0, 1, .1);
    bayesIm1.setProbability(2, 1, 0, .1);
    bayesIm1.setProbability(2, 1, 1, .9);
    bayesIm1.setProbability(2, 2, 0, .5);
    bayesIm1.setProbability(2, 2, 1, .5);
    bayesIm1.setProbability(2, 3, 0, .2);
    bayesIm1.setProbability(2, 3, 1, .8);
    bayesIm1.setProbability(2, 4, 0, .6);
    bayesIm1.setProbability(2, 4, 1, .4);
    bayesIm1.setProbability(2, 5, 0, .7);
    bayesIm1.setProbability(2, 5, 1, .3);
    return bayesIm1;
}
Also used : MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) GraphNode(edu.cmu.tetrad.graph.GraphNode) Dag(edu.cmu.tetrad.graph.Dag) BayesPm(edu.cmu.tetrad.bayes.BayesPm)

Example 17 with BayesIm

use of edu.cmu.tetrad.bayes.BayesIm in project tetrad by cmu-phil.

the class UpdaterEditingTableModelObs method addListOfEvidence.

private void addListOfEvidence(Box verticalBox) {
    boolean foundACondition = false;
    for (int i = 0; i < evidence.getNumNodes(); i++) {
        if (evidence.hasNoEvidence(i)) {
            continue;
        }
        foundACondition = true;
        Node node = evidence.getNode(i);
        Box c = Box.createHorizontalBox();
        c.add(Box.createRigidArea(new Dimension(30, 1)));
        StringBuilder buf = new StringBuilder();
        buf.append("<html>").append(node.getName()).append(" = ");
        boolean listedOneAlready = false;
        for (int j = 0; j < evidence.getNumCategories(i); j++) {
            if (evidence.getProposition().isAllowed(i, j)) {
                if (listedOneAlready) {
                    buf.append(" <i>OR</i>  ");
                }
                BayesIm manipulatedBayesIm = updaterWrapper.getBayesUpdater().getManipulatedBayesIm();
                String valueName = manipulatedBayesIm.getBayesPm().getCategory(node, j);
                buf.append(valueName);
                listedOneAlready = true;
            }
        }
        buf.append("</html>");
        c.add(new JLabel(buf.toString()));
        c.add(Box.createHorizontalGlue());
        verticalBox.add(c);
    }
    if (!foundACondition) {
        Box e = Box.createHorizontalBox();
        e.add(Box.createRigidArea(new Dimension(30, 1)));
        e.add(new JLabel("--No Evidence--"));
        e.add(Box.createHorizontalGlue());
        verticalBox.add(e);
    }
}
Also used : BayesIm(edu.cmu.tetrad.bayes.BayesIm) Node(edu.cmu.tetrad.graph.Node) DisplayNode(edu.cmu.tetradapp.workbench.DisplayNode) SortingComboBox(edu.cmu.tetradapp.util.SortingComboBox)

Example 18 with BayesIm

use of edu.cmu.tetrad.bayes.BayesIm in project tetrad by cmu-phil.

the class UpdaterEditingTableModelObs method getNumParents.

private int getNumParents() {
    UpdaterEditingTableModelObs editingTableModel = (UpdaterEditingTableModelObs) getModel();
    BayesIm bayesIm = editingTableModel.getBayesIm();
    int nodeIndex = editingTableModel.getNodeIndex();
    return bayesIm.getNumParents(nodeIndex);
}
Also used : BayesIm(edu.cmu.tetrad.bayes.BayesIm)

Example 19 with BayesIm

use of edu.cmu.tetrad.bayes.BayesIm in project tetrad by cmu-phil.

the class UpdaterEditingTableModel method addListOfEvidence.

private void addListOfEvidence(Box verticalBox) {
    boolean foundACondition = false;
    for (int i = 0; i < evidence.getNumNodes(); i++) {
        if (evidence.hasNoEvidence(i)) {
            continue;
        }
        foundACondition = true;
        Node node = evidence.getNode(i);
        Box c = Box.createHorizontalBox();
        c.add(Box.createRigidArea(new Dimension(30, 1)));
        StringBuilder buf = new StringBuilder();
        buf.append("<html>").append(node.getName()).append(" = ");
        boolean listedOneAlready = false;
        for (int j = 0; j < evidence.getNumCategories(i); j++) {
            if (evidence.getProposition().isAllowed(i, j)) {
                if (listedOneAlready) {
                    buf.append(" <i>OR</i>  ");
                }
                BayesIm manipulatedBayesIm = updaterWrapper.getBayesUpdater().getManipulatedBayesIm();
                String valueName = manipulatedBayesIm.getBayesPm().getCategory(node, j);
                buf.append(valueName);
                listedOneAlready = true;
            }
        }
        buf.append("</html>");
        c.add(new JLabel(buf.toString()));
        c.add(Box.createHorizontalGlue());
        verticalBox.add(c);
    }
    if (!foundACondition) {
        Box e = Box.createHorizontalBox();
        e.add(Box.createRigidArea(new Dimension(30, 1)));
        e.add(new JLabel("--No Evidence--"));
        e.add(Box.createHorizontalGlue());
        verticalBox.add(e);
    }
}
Also used : BayesIm(edu.cmu.tetrad.bayes.BayesIm) Node(edu.cmu.tetrad.graph.Node) DisplayNode(edu.cmu.tetradapp.workbench.DisplayNode) SortingComboBox(edu.cmu.tetradapp.util.SortingComboBox)

Example 20 with BayesIm

use of edu.cmu.tetrad.bayes.BayesIm in project tetrad by cmu-phil.

the class UpdaterEditingTableModel method getNumParents.

private int getNumParents() {
    UpdaterEditingTableModel editingTableModel = (UpdaterEditingTableModel) getModel();
    BayesIm bayesIm = editingTableModel.getBayesIm();
    int nodeIndex = editingTableModel.getNodeIndex();
    return bayesIm.getNumParents(nodeIndex);
}
Also used : BayesIm(edu.cmu.tetrad.bayes.BayesIm)

Aggregations

BayesIm (edu.cmu.tetrad.bayes.BayesIm)36 MlBayesIm (edu.cmu.tetrad.bayes.MlBayesIm)21 BayesPm (edu.cmu.tetrad.bayes.BayesPm)18 Test (org.junit.Test)14 Graph (edu.cmu.tetrad.graph.Graph)7 Node (edu.cmu.tetrad.graph.Node)7 DataSet (edu.cmu.tetrad.data.DataSet)6 Dag (edu.cmu.tetrad.graph.Dag)5 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)3 GraphNode (edu.cmu.tetrad.graph.GraphNode)3 Parameters (edu.cmu.tetrad.util.Parameters)3 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Element (nu.xom.Element)3 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)2 ChiSquare (edu.cmu.tetrad.algcomparison.independence.ChiSquare)2 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)2 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2