default DoubleColumn bin(int binCount) { double[] histogram = new double[binCount]; EmpiricalDistribution distribution = new EmpiricalDistribution(binCount); distribution.load(asDoubleArray()); int k = 0; for(SummaryStatistics stats: distribution.getBinStats()) { histogram[k++] = stats.getN(); } return DoubleColumn.create(name() + "[binned]", histogram); }
/** * Computes the empirical distribution using values from the file * in <code>valuesFileURL</code> and <code>binCount</code> bins. * <p> * <code>valuesFileURL</code> must exist and be readable by this process * at runtime.</p> * <p> * This method must be called before using <code>getNext()</code> * with <code>mode = DIGEST_MODE</code></p> * * @param binCount the number of bins used in computing the empirical * distribution * @throws NullArgumentException if the {@code valuesFileURL} has not been set * @throws IOException if an error occurs reading the input file * @throws ZeroException if URL contains no data */ public void computeDistribution(int binCount) throws NullArgumentException, IOException, ZeroException { empiricalDistribution = new EmpiricalDistribution(binCount, randomData.getRandomGenerator()); empiricalDistribution.load(valuesFileURL); mu = empiricalDistribution.getSampleStats().getMean(); sigma = empiricalDistribution.getSampleStats().getStandardDeviation(); }
final int BIN_COUNT = 20; double[] data = {1.2, 0.2, 0.333, 1.4, 1.5, 1.2, 1.3, 10.4, 1, 2.0}; long[] histogram = new long[BIN_COUNT]; org.apache.commons.math3.random.EmpiricalDistribution distribution = new org.apache.commons.math3.random.EmpiricalDistribution(BIN_COUNT); distribution.load(data); int k = 0; for(org.apache.commons.math3.stat.descriptive.SummaryStatistics stats: distribution.getBinStats()) { histogram[k++] = stats.getN(); }
@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()); } EmpiricalDistribution empiricalDistribution = new EmpiricalDistribution(); double[] backingValues = ((List<?>)value).stream().mapToDouble(innerValue -> ((Number)innerValue).doubleValue()).sorted().toArray(); empiricalDistribution.load(backingValues); return empiricalDistribution; } }
EmpiricalDistribution distribution = new EmpiricalDistribution(bins); distribution.load(((List<?>)sourceValues).stream().mapToDouble(value -> ((Number)value).doubleValue()).toArray());;
default DoubleColumn bin(int binCount) { double[] histogram = new double[binCount]; EmpiricalDistribution distribution = new EmpiricalDistribution(binCount); distribution.load(asDoubleArray()); int k = 0; for(SummaryStatistics stats: distribution.getBinStats()) { histogram[k++] = stats.getN(); } return DoubleColumn.create(name() + "[binned]", histogram); }
/** * Computes the empirical distribution using values from the file * in <code>valuesFileURL</code> and <code>binCount</code> bins. * <p> * <code>valuesFileURL</code> must exist and be readable by this process * at runtime.</p> * <p> * This method must be called before using <code>getNext()</code> * with <code>mode = DIGEST_MODE</code></p> * * @param binCount the number of bins used in computing the empirical * distribution * @throws NullArgumentException if the {@code valuesFileURL} has not been set * @throws IOException if an error occurs reading the input file * @throws ZeroException if URL contains no data */ public void computeDistribution(int binCount) throws NullArgumentException, IOException, ZeroException { empiricalDistribution = new EmpiricalDistribution(binCount, randomData.getRandomGenerator()); empiricalDistribution.load(valuesFileURL); mu = empiricalDistribution.getSampleStats().getMean(); sigma = empiricalDistribution.getSampleStats().getStandardDeviation(); }