Search in sources :

Example 11 with GeneralizedSemPm

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.");
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SingleGraph(edu.cmu.tetrad.algcomparison.graph.SingleGraph) Node(edu.cmu.tetrad.graph.Node) GeneralizedSemIm(edu.cmu.tetrad.sem.GeneralizedSemIm) GeneralizedSemPm(edu.cmu.tetrad.sem.GeneralizedSemPm)

Aggregations

GeneralizedSemPm (edu.cmu.tetrad.sem.GeneralizedSemPm)11 GeneralizedSemIm (edu.cmu.tetrad.sem.GeneralizedSemIm)7 Node (edu.cmu.tetrad.graph.Node)5 ParseException (java.text.ParseException)5 DataSet (edu.cmu.tetrad.data.DataSet)4 Graph (edu.cmu.tetrad.graph.Graph)4 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)3 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)2 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)2 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)2 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)2 Fask (edu.cmu.tetrad.search.Fask)2 SingleGraph (edu.cmu.tetrad.algcomparison.graph.SingleGraph)1 Expression (edu.cmu.tetrad.calculator.expression.Expression)1 VariableExpression (edu.cmu.tetrad.calculator.expression.VariableExpression)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1