use of edu.cmu.tetrad.sem.GeneralizedSemPm in project tetrad by cmu-phil.
the class SpecialDataClark method simulate.
private DataSet simulate(Graph graph, Parameters parameters) {
int N = parameters.getInt("sampleSize");
try {
GeneralizedSemPm pm = new GeneralizedSemPm(graph);
Graph g = pm.getGraph();
for (String p : pm.getParameters()) {
double coef = RandomUtil.getInstance().nextUniform(0.3, 0.6);
if (RandomUtil.getInstance().nextDouble() < 0.5) {
coef *= -1;
}
pm.setParameterExpression(p, "" + coef);
}
for (Node x : g.getNodes()) {
if (!(x.getNodeType() == NodeType.ERROR)) {
String error;
double s = RandomUtil.getInstance().nextUniform(.1, .4);
double f = getF(s, N);
if (s > 0) {
error = "pow(Uniform(0, 1), " + (1.0 + f) + ")";
} else {
error = "-pow(Uniform(0, 1), " + (1.0 + f) + ")";
}
pm.setNodeExpression(pm.getErrorNode(x), error);
}
}
GeneralizedSemIm im = new GeneralizedSemIm(pm);
return im.simulateData(N, false);
} catch (Exception e) {
throw new IllegalArgumentException("Sorry, I couldn't simulate from that Bayes IM; perhaps not all of\n" + "the parameters have been specified.");
}
}
Aggregations