use of edu.cmu.tetrad.graph.SemGraph in project tetrad by cmu-phil.
the class DiscreteTetradTest method piHat2.
/**
* For two factor models.
*/
private double piHat2(int[] indices, int[] v, SemIm semIm) {
SemGraph graph = semIm.getSemPm().getGraph();
graph.setShowErrorTerms(true);
Node etaNode1 = graph.getNode("eta1");
double varEta1 = semIm.getParamValue(etaNode1, etaNode1);
double stdEta1 = Math.sqrt(semIm.getParamValue(etaNode1, etaNode1));
Node etaNode2 = graph.getNode("eta2");
double coeffEta = semIm.getParamValue(etaNode1, etaNode2);
Node errorEta2;
if (graph.getParents(etaNode2).get(0) == etaNode1) {
errorEta2 = graph.getParents(etaNode2).get(1);
} else {
errorEta2 = graph.getParents(etaNode2).get(0);
}
double varEta2 = coeffEta * coeffEta * varEta1 + semIm.getParamValue(errorEta2, errorEta2);
double stdEtaError2 = Math.sqrt(semIm.getParamValue(errorEta2, errorEta2));
double[] stdE = new double[indices.length];
double[] varEta = new double[indices.length];
double[] stdU = new double[indices.length];
double[] coeff = new double[indices.length];
for (int i = 0; i < indices.length; i++) {
Node uNode = graph.getNode("xi" + i);
Node uParent = null, uError = null;
for (Node node : graph.getParents(uNode)) {
Node parent = node;
if (parent.getNodeType() == NodeType.LATENT) {
uParent = parent;
} else {
uError = parent;
}
}
if (i == 0 || (i == 2 && indices.length == 4) || (i == 3 && indices.length > 4)) {
coeff[i] = 1.;
} else {
coeff[i] = semIm.getParamValue(uParent, uNode);
}
if (uParent == etaNode1) {
varEta[i] = varEta1;
} else {
varEta[i] = varEta2;
}
stdE[i] = Math.sqrt(semIm.getParamValue(uError, uError));
stdU[i] = Math.sqrt(coeff[i] * coeff[i] * varEta[i] + semIm.getParamValue(uError, uError));
}
double l = 0.;
for (int t1 = 0; t1 < GHY.length; t1++) {
for (int t2 = 0; t2 < GHY.length; t2++) {
double tValue = GHW[t1] * GHW[t2];
double eta1 = GHY[t1] * stdEta1;
double eta2 = eta1 * coeffEta + GHY[t2] * stdEtaError2;
for (int i = 0; i < indices.length; i++) {
double eta;
if (indices.length == 4) {
if (i < 2) {
eta = eta1;
} else {
eta = eta2;
}
} else {
if (i < 3) {
eta = eta1;
} else {
eta = eta2;
}
}
int numValues = this.values[indices[i]].length;
if (v[i] == 0) {
tValue *= ProbUtils.normalCdf((this.thresholds[indices[i]][0] * stdU[i] - coeff[i] * eta) / stdE[i]);
} else if (v[i] == numValues - 1) {
tValue *= (1. - ProbUtils.normalCdf((this.thresholds[indices[i]][numValues - 2] * stdU[i] - coeff[i] * eta) / stdE[i]));
} else {
tValue *= ProbUtils.normalCdf((this.thresholds[indices[i]][v[i]] * stdU[i] - coeff[i] * eta) / stdE[i]) - ProbUtils.normalCdf((this.thresholds[indices[i]][v[i] - 1] * stdU[i] - coeff[i] * eta) / stdE[i]);
}
}
l += tValue;
}
}
return l;
}
use of edu.cmu.tetrad.graph.SemGraph in project tetrad by cmu-phil.
the class StandardizedSemImImpliedMatricesPanel method layoutByKnowledge.
/**
* Lays the workbench graph out using knowledge tiers.
*/
public void layoutByKnowledge() {
SemGraph _graph = (SemGraph) standardizedSemImGraphicalEditor.getWorkbench().getGraph();
_graph.setShowErrorTerms(false);
standardizedSemImGraphicalEditor.getWorkbench().layoutByKnowledge();
_graph.resetErrorPositions();
standardizedSemImGraphicalEditor.getWorkbench().setGraph(_graph);
errorTerms.setText("Show Error Terms");
}
use of edu.cmu.tetrad.graph.SemGraph in project tetrad by cmu-phil.
the class StandardizedSemImImpliedMatricesPanel method layoutByGraph.
/**
* Lays out the graph in the workbench.
* @param graph The graph whose layout is to be mimicked.
*/
public void layoutByGraph(Graph graph) {
SemGraph _graph = (SemGraph) standardizedSemImGraphicalEditor.getWorkbench().getGraph();
_graph.setShowErrorTerms(false);
standardizedSemImGraphicalEditor.getWorkbench().layoutByGraph(graph);
_graph.resetErrorPositions();
// standardizedSemImGraphicalEditor.getWorkbench().setGraph(_graph);
errorTerms.setText("Show Error Terms");
}
use of edu.cmu.tetrad.graph.SemGraph in project tetrad by cmu-phil.
the class SemUpdater method createManipulatedGraph.
/**
* Alters the graph by removing edges from parents to manipulated variables.
*/
private SemGraph createManipulatedGraph(Graph graph) {
SemGraph updatedGraph = new SemGraph(graph);
for (int i = 0; i < evidence.getNumNodes(); ++i) {
if (evidence.isManipulated(i)) {
Node node = evidence.getNode(i);
List<Node> parents = updatedGraph.getParents(node);
for (Node parent : parents) {
if (parent.getNodeType() == NodeType.ERROR) {
continue;
}
updatedGraph.removeEdge(node, parent);
}
}
}
return updatedGraph;
}
use of edu.cmu.tetrad.graph.SemGraph in project tetrad by cmu-phil.
the class SemUpdater method getManipulatedSemIm.
public SemIm getManipulatedSemIm() {
SemGraph graph = getSemIm().getSemPm().getGraph();
SemGraph manipulatedGraph = createManipulatedGraph(graph);
return SemIm.retainValues(getSemIm(), manipulatedGraph);
}
Aggregations