List of usage examples for org.apache.commons.math3.random EmpiricalDistribution EmpiricalDistribution
public EmpiricalDistribution()
From source file:org.apache.solr.client.solrj.io.eval.EmpiricalDistributionEvaluator.java
@Override public Object doWork(Object value) throws IOException { if (!(value instanceof List<?>)) { throw new StreamEvaluatorException("List value expected but found type %s for value %s", value.getClass().getName(), value.toString()); }// w ww . ja v a 2 s. c om EmpiricalDistribution empiricalDistribution = new EmpiricalDistribution(); double[] backingValues = ((List<?>) value).stream() .mapToDouble(innerValue -> ((BigDecimal) innerValue).doubleValue()).sorted().toArray(); empiricalDistribution.load(backingValues); return empiricalDistribution; }
From source file:org.apache.solr.client.solrj.io.stream.eval.EmpiricalDistributionEvaluatorTest.java
@Test public void test() throws IOException { double[] l1 = new double[] { 3.4, 4.5, 6.7 }; double[] l2 = new double[] { 1.2, 3.2, 3 }; values.clear();/*from w w w. j a va 2 s. co m*/ values.put("l1", l1); values.put("l2", l2); EmpiricalDistribution dist = new EmpiricalDistribution(); dist.load(l1); Assert.assertEquals(dist.getNumericalMean(), ((EmpiricalDistribution) factory.constructEvaluator("emp(l1)").evaluate(new Tuple(values))) .getNumericalMean()); }