Example usage for org.apache.commons.math3.distribution RealDistribution density

List of usage examples for org.apache.commons.math3.distribution RealDistribution density

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution RealDistribution density.

Prototype

double density(double x);

Source Link

Document

Returns the probability density function (PDF) of this distribution evaluated at the specified point x .

Usage

From source file:edu.cmu.tetrad.test.TestGeneralizedSem.java

public void testEmpiricalDistribution() {
    NumberFormat nf = new DecimalFormat("0.0000");

    try {//from  w  ww  .  j a  v a2s .c o m
        Graph g = new EdgeListGraphSingleConnections();
        Node x = new GraphNode("X");
        g.addNode(x);
        GeneralizedSemPm pm = new GeneralizedSemPm(g);
        pm.setNodeExpression(x, "E_X");
        Node error = pm.getErrorNode(x);
        pm.setNodeExpression(error, "N(0, 1)");

        GeneralizedSemEstimator.MyContext context = new GeneralizedSemEstimator.MyContext();

        Expression expression = pm.getNodeExpression(error);
        RealDistribution dist1 = expression.getRealDistribution(context);
        RealDistribution dist2 = new EmpiricalDistributionForExpression(pm, error, context).getDist();

        for (double z = -2; z <= 2.01; z += 0.1) {
            System.out.println(nf.format(z) + " " + (nf.format(dist1.density(z) - dist2.density(z))));
            //                System.out.println(nf.format(z) + " " + (nf.format(dist1.density(z) -
            //                        dist2.density(z))));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}