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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations