/** * Adds random jitter to {@code data} using deviates sampled from {@code dist}. * <p> * Note that jitter is applied in-place - i.e., the array * values are overwritten with the result of applying jitter.</p> * * @param data input/output data array - entries overwritten by the method * @param dist probability distribution to sample for jitter values * @throws NullPointerException if either of the parameters is null */ private static void jitter(double[] data, RealDistribution dist) { for (int i = 0; i < data.length; i++) { data[i] += dist.sample(); } }
/** * Mass of bin i under the within-bin kernel of the bin. * * @param i index of the bin * @return the difference in the within-bin kernel cdf between the * upper and lower endpoints of bin i */ @SuppressWarnings("deprecation") private double kB(int i) { final double[] binBounds = getUpperBounds(); final RealDistribution kernel = getKernel(binStats.get(i)); return i == 0 ? kernel.cumulativeProbability(min, binBounds[0]) : kernel.cumulativeProbability(binBounds[i - 1], binBounds[i]); }
final double[] binBounds = getUpperBounds(); final double lower = i == 0 ? min : binBounds[i - 1]; final double kBminus = kernel.cumulativeProbability(lower); final double pB = pB(i); final double pBminus = pBminus(i); return lower; return kernel.inverseCumulativeProbability(kBminus + pCrit * kB / pB);
final RealDistribution kernel = k(x); if (kernel instanceof ConstantRealDistribution) { if (x < kernel.getNumericalMean()) { return pBminus; } else { final double lower = binIndex == 0 ? min : binBounds[binIndex - 1]; final double withinBinCum = (kernel.cumulativeProbability(x) - kernel.cumulativeProbability(lower)) / kB; return pBminus + pB * withinBinCum;
@Override public double sample(long seed) { dist.reseedRandomGenerator(seed); return dist.sample(); }
/** * @param dist * real distribution * @param c * variable value */ protected void setFromRealDist(RealDistribution dist, GeoNumberValue c) { if (this.isCumulative == null || this.isCumulative.getBoolean()) { num.setValue(dist.cumulativeProbability(c.getDouble())); } else { num.setValue(dist.density(c.getDouble())); } }
/** * Generate a random deviate from the given distribution using the * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> inversion method.</a> * * @param distribution Continuous distribution to generate a random value from * @return a random value sampled from the given distribution * @throws MathIllegalArgumentException if the underlynig distribution throws one * @since 2.2 * @deprecated use the distribution's sample() method */ @Deprecated public double nextInversionDeviate(RealDistribution distribution) throws MathIllegalArgumentException { return distribution.inverseCumulativeProbability(nextUniform(0, 1)); }
/** * {@inheritDoc} * * <p>Returns the kernel density normalized so that its integral over each bin * equals the bin mass.</p> * * <p>Algorithm description: <ol> * <li>Find the bin B that x belongs to.</li> * <li>Compute K(B) = the mass of B with respect to the within-bin kernel (i.e., the * integral of the kernel density over B).</li> * <li>Return k(x) * P(B) / K(B), where k is the within-bin kernel density * and P(B) is the mass of B.</li></ol></p> * @since 3.1 */ public double density(double x) { if (x < min || x > max) { return 0d; } final int binIndex = findBin(x); final RealDistribution kernel = getKernel(binStats.get(binIndex)); return kernel.density(x) * pB(binIndex) / kB(binIndex); }
protected final void setSeed(long seed){ this.seed = seed; numGen.reseedRandomGenerator(seed); }
@Override public Double get(long seed) { distribution.reseedRandomGenerator(seed); return distribution.sample(); } }
final RealDistribution kernel = k(x); if (kernel instanceof ConstantRealDistribution) { if (x < kernel.getNumericalMean()) { return pBminus; } else { final double lower = binIndex == 0 ? min : binBounds[binIndex - 1]; final double withinBinCum = (kernel.cumulativeProbability(x) - kernel.cumulativeProbability(lower)) / kB; return pBminus + pB * withinBinCum;
@Override public Double getValue(double[] input) { if (index == -1) { throw new IllegalStateException("Cannot get value: ParameterSpace index has not been set"); } return distribution.inverseCumulativeProbability(input[index]); }
private double getLikelihood(List<Double> residuals, RealDistribution dist) { double sum = 0.0; for (double r : residuals) { try { double t = dist.density(r); sum += log(t + 1e-15); } catch (Exception e) { // } } return sum; }
@Override public ImmutableList<Double> generate(long seed) { distribution.reseedRandomGenerator(seed); return ImmutableList.copyOf(new TimeSeriesIterator( distribution, length)); } }
/** {@inheritDoc} */ public double value() { return orig.value() + random.sample(); } };
@Override public Double get(long seed) { distribution.reseedRandomGenerator(seed); double val = distribution.sample(); if (outOfBoundStrategy == OutOfBoundStrategy.REDRAW) { while (!isInBounds(val)) { val = distribution.sample(); } } else if (val < lowerBound) { val = lowerBound; } else if (val >= upperBound) { val = upperBound; } return val; }
public double [] pValues(){ double [] res = zValues(); RealDistribution rd = _dispersionEstimated?new TDistribution(_training_metrics.residual_degrees_of_freedom()):new NormalDistribution(); for(int i = 0; i < res.length; ++i) res[i] = 2*rd.cumulativeProbability(-Math.abs(res[i])); return res; } double[][] _global_beta_multinomial;
final double[] binBounds = getUpperBounds(); final double lower = i == 0 ? min : binBounds[i - 1]; final double kBminus = kernel.cumulativeProbability(lower); final double pB = pB(i); final double pBminus = pBminus(i); return lower; return kernel.inverseCumulativeProbability(kBminus + pCrit * kB / pB);
final RealDistribution kernel = k(x); if (kernel instanceof ConstantRealDistribution) { if (x < kernel.getNumericalMean()) { return pBminus; } else { final double lower = binIndex == 0 ? min : binBounds[binIndex - 1]; final double withinBinCum = (kernel.cumulativeProbability(x) - kernel.cumulativeProbability(lower)) / kB; return pBminus + pB * withinBinCum;
@Override public Double getValue(double[] input) { if (index == -1) { throw new IllegalStateException("Cannot get value: ParameterSpace index has not been set"); } return distribution.inverseCumulativeProbability(input[index]); }