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

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

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution MultivariateRealDistribution 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:org.apache.solr.client.solrj.io.eval.DensityEvaluator.java

@Override
public Object doWork(Object first, Object second) throws IOException {

    if (!(first instanceof MultivariateRealDistribution)) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the first value, expecting a MultiVariateRealDistribution for density",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }//from  w  ww . ja v a2s  .c om
    if (!(second instanceof List)) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the second value, expecting a numeric array.",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }

    MultivariateRealDistribution multivariateRealDistribution = (MultivariateRealDistribution) first;
    List<Number> nums = (List<Number>) second;

    double[] vec = new double[nums.size()];

    for (int i = 0; i < vec.length; i++) {
        vec[i] = nums.get(i).doubleValue();
    }

    return multivariateRealDistribution.density(vec);
}