Search in sources :

Example 1 with Parameter

use of edu.cmu.tetrad.sem.Parameter in project tetrad by cmu-phil.

the class TestSemVarMeans method testMeansCholesky.

@Test
public void testMeansCholesky() {
    Graph graph = constructGraph1();
    SemPm semPm1 = new SemPm(graph);
    List<Parameter> parameters = semPm1.getParameters();
    for (Parameter p : parameters) {
        p.setInitializedRandomly(false);
    }
    SemIm semIm1 = new SemIm(semPm1);
    double[] means = { 5.0, 4.0, 3.0, 2.0, 1.0 };
    RandomUtil.getInstance().setSeed(-379467L);
    for (int i = 0; i < semIm1.getVariableNodes().size(); i++) {
        Node node = semIm1.getVariableNodes().get(i);
        semIm1.setMean(node, means[i]);
    }
    DataSet dataSet = semIm1.simulateDataCholesky(1000, false);
    SemEstimator semEst = new SemEstimator(dataSet, semPm1);
    semEst.estimate();
    SemIm estSemIm = semEst.getEstimatedSem();
    List<Node> nodes = semPm1.getVariableNodes();
    for (Node node : nodes) {
        double mean = semIm1.getMean(node);
        assertEquals(mean, estSemIm.getMean(node), 0.6);
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) SemPm(edu.cmu.tetrad.sem.SemPm) Parameter(edu.cmu.tetrad.sem.Parameter) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test)

Example 2 with Parameter

use of edu.cmu.tetrad.sem.Parameter in project tetrad by cmu-phil.

the class TestSemVarMeans method testMeansReducedForm.

@Test
public void testMeansReducedForm() {
    Graph graph = constructGraph1();
    SemPm semPm1 = new SemPm(graph);
    List<Parameter> parameters = semPm1.getParameters();
    for (Parameter p : parameters) {
        p.setInitializedRandomly(false);
    }
    SemIm semIm1 = new SemIm(semPm1);
    double[] means = { 5.0, 4.0, 3.0, 2.0, 1.0 };
    RandomUtil.getInstance().setSeed(-379467L);
    for (int i = 0; i < semIm1.getVariableNodes().size(); i++) {
        Node node = semIm1.getVariableNodes().get(i);
        semIm1.setMean(node, means[i]);
    }
    DataSet dataSet = semIm1.simulateDataReducedForm(1000, false);
    SemEstimator semEst = new SemEstimator(dataSet, semPm1);
    semEst.estimate();
    SemIm estSemIm = semEst.getEstimatedSem();
    List<Node> nodes = semPm1.getVariableNodes();
    for (Node node : nodes) {
        double mean = semIm1.getMean(node);
        assertEquals(mean, estSemIm.getMean(node), 0.5);
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) SemPm(edu.cmu.tetrad.sem.SemPm) Parameter(edu.cmu.tetrad.sem.Parameter) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test)

Example 3 with Parameter

use of edu.cmu.tetrad.sem.Parameter in project tetrad by cmu-phil.

the class TestSemVarMeans method testMeansRecursive.

@Test
public void testMeansRecursive() {
    Graph graph = constructGraph1();
    SemPm semPm1 = new SemPm(graph);
    List<Parameter> parameters = semPm1.getParameters();
    for (Parameter p : parameters) {
        p.setInitializedRandomly(false);
    }
    SemIm semIm1 = new SemIm(semPm1);
    double[] means = { 5.0, 4.0, 3.0, 2.0, 1.0 };
    RandomUtil.getInstance().setSeed(-379467L);
    for (int i = 0; i < semIm1.getVariableNodes().size(); i++) {
        Node node = semIm1.getVariableNodes().get(i);
        semIm1.setMean(node, means[i]);
    }
    DataSet dataSet = semIm1.simulateDataRecursive(1000, false);
    SemEstimator semEst = new SemEstimator(dataSet, semPm1);
    semEst.estimate();
    SemIm estSemIm = semEst.getEstimatedSem();
    List<Node> nodes = semPm1.getVariableNodes();
    for (Node node : nodes) {
        double mean = semIm1.getMean(node);
        assertEquals(mean, estSemIm.getMean(node), 0.5);
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) SemPm(edu.cmu.tetrad.sem.SemPm) Parameter(edu.cmu.tetrad.sem.Parameter) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test)

Example 4 with Parameter

use of edu.cmu.tetrad.sem.Parameter in project tetrad by cmu-phil.

the class SemPmGraphicalEditor method resetNodeLabel.

private void resetNodeLabel(Node node) {
    Parameter parameter = getNodeParameter(node);
    if (parameter == null) {
        workbench().setNodeLabel(node, null, 0, 0);
    } else {
        JLabel label = new JLabel();
        label.setForeground(Color.blue);
        label.setBackground(Color.white);
        label.setFont(SMALL_FONT);
        label.setText(parameter.getName());
        label.addMouseListener(new NodeMouseListener(node, this));
        if (parameter.isFixed()) {
            label.setForeground(Color.RED);
        }
        // they're error nodes or not.
        if (node.getNodeType() == NodeType.ERROR) {
            label.setOpaque(false);
            workbench().setNodeLabel(node, label, -10, -10);
        } else {
            label.setOpaque(false);
            workbench().setNodeLabel(node, label, 0, 0);
        }
    }
}
Also used : Parameter(edu.cmu.tetrad.sem.Parameter)

Example 5 with Parameter

use of edu.cmu.tetrad.sem.Parameter in project tetrad by cmu-phil.

the class SemPmGraphicalEditor method resetEdgeLabel.

private void resetEdgeLabel(Edge edge) {
    Parameter parameter = getEdgeParameter(edge);
    if (parameter != null) {
        JLabel label = new JLabel();
        if (parameter.getType() == ParamType.COVAR) {
            label.setForeground(Color.GREEN.darker().darker());
        }
        if (parameter.isFixed()) {
            label.setForeground(Color.RED);
        }
        label.setBackground(Color.white);
        label.setOpaque(true);
        label.setFont(SMALL_FONT);
        label.setText(parameter.getName());
        label.addMouseListener(new EdgeMouseListener(edge, this));
        workbench().setEdgeLabel(edge, label);
    } else {
        workbench().setEdgeLabel(edge, null);
    }
}
Also used : Parameter(edu.cmu.tetrad.sem.Parameter)

Aggregations

Parameter (edu.cmu.tetrad.sem.Parameter)11 DataSet (edu.cmu.tetrad.data.DataSet)3 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)3 Graph (edu.cmu.tetrad.graph.Graph)3 GraphNode (edu.cmu.tetrad.graph.GraphNode)3 Node (edu.cmu.tetrad.graph.Node)3 SemEstimator (edu.cmu.tetrad.sem.SemEstimator)3 SemIm (edu.cmu.tetrad.sem.SemIm)3 SemPm (edu.cmu.tetrad.sem.SemPm)3 Test (org.junit.Test)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 DisplayNode (edu.cmu.tetradapp.workbench.DisplayNode)1 List (java.util.List)1