@Setup public void setup() { randomValues = new int[numEvents]; Random r = ThreadLocalRandom.current(); for (int i = 0; i < numEvents; i++) { randomValues[i] = r.nextInt(UPPER_LIMIT); } fixedHistogramForAdds = new FixedBucketsHistogram( LOWER_LIMIT, UPPER_LIMIT, numBuckets, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW ); NormalDistribution normalDistribution = new NormalDistribution(50000, 10000); normalDistributionValues = new float[numEvents]; for (int i = 0; i < numEvents; i++) { normalDistributionValues[i] = (float) normalDistribution.sample(); } }
@Override public void initialize(Tensor t) { float[] elements = t.getElements(); t.forEach(i -> elements[i] = (float)normalDistribution.sample()); }
public Builder normal(double mean, double sd, long duration, TimeUnit units) { final NormalDistribution distribution = new NormalDistribution(mean, sd); return add("normal(" + mean + ")", () -> (long)distribution.sample(), duration, units); }
@Test public void testNormalDistribution() { NormalDistribution normalDistribution = new NormalDistribution( new JDKRandomGenerator(1000), 50000, 10000 ); FixedBucketsHistogram h = new FixedBucketsHistogram( 0, 100000, 1000, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW ); for (int i = 0; i < 100000; i++) { double val = normalDistribution.sample(); h.add(val); } float[] quantiles = h.percentilesFloat(new double[]{12.5f, 25.0f, 50.0f, 98f}); Assert.assertArrayEquals( new float[]{38565.324f, 43297.95f, 50091.902f, 70509.125f}, quantiles, 0.01f ); }
private double getChisqSample() { double z = normal.sample(); return z * z; }
@Override public double sample () { return Math.exp(normalSampler.sample()); } }
/** * @param mean The mean of the Normal. * @param sd The standard deviation of the Normal. * @return Ibid. */ public double nextNormal(double mean, double sd) { if (sd <= 0) { throw new IllegalArgumentException("Standard deviation must be non-negative: " + sd); } double sample = normal.sample(); return sample * sd + mean; // return new NormalDistribution(randomGenerator, mean, sd).sample(); }
@Override public double sample () { return Math.min(high, Math.max(low, normalSampler.sample())); } }
@Override public double value() { return distribution.sample(); } }, min, max);
@Override public int nextInt(int bound) { return (int) normalize(delegate.sample(), 0, bound); }
@Override public long nextLong(long lower, long upper) { return (int) normalize(delegate.sample(), lower, upper); }
@Override public double nextDouble(double lower, double upper) { return normalize(delegate.sample(), lower, upper); }
@Override public int nextInt(int bound) { return (int) normalize(delegate.sample(), 0, bound); }
@Override public int nextInt(int lower, int upper) { return (int) normalize(delegate.sample(), lower, upper); }
private void walkCoefficients (double[] s0, double[] s1) { double[] ran = normal01.sample(2); // two samples double[] coef = getCoefficientArray(); s1[0] = s0[0] + ran[0] * rwaSigma * coef[0] + (coef[0] - s0[0]) * rwaOffset; s1[1] = s0[1]; s1[2] = s0[2] + ran[1] * rwcSigma * coef[2] + (coef[2] - s0[2]) * rwcOffset; }
@Override public double nextDouble(double lower, double upper) { return normalize(delegate.sample(), lower, upper); }
public double[][] getUncorrelatedGaussianShocks(int sampleSize) { NormalDistribution normal = new NormalDistribution(new Well1024a(++seed), 0, 1); int numVars = variableNodes.size(); setupModel(numVars); double[][] shocks = new double[sampleSize][numVars]; for (int i = 0; i < sampleSize; i++) { for (int j = 0; j < numVars; j++) { shocks[i][j] = normal.sample() * sqrt(errorVars[j]); } } return shocks; }
public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); double e1 = getExpressions().get(0).evaluate(context); double e2 = getExpressions().get(1).evaluate(context); final NormalDistribution distribution = new NormalDistribution(randomGenerator, e1, e2); return distribution.sample(); // faster // return RandomUtil.getInstance().nextNormal(e1, e2); }
public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); double e1 = getExpressions().get(0).evaluate(context); double e2 = getExpressions().get(1).evaluate(context); return new NormalDistribution(randomGenerator, e1, e2).sample(); }
private RealMatrix randomStart(int ncol){ NormalDistribution norm = new NormalDistribution(0.0, 1.0); RealMatrix T = new Array2DRowRealMatrix(ncol, ncol); for(int i=0;i<ncol;i++){ for(int j=0;j<ncol;j++){ T.setEntry(i,j,norm.sample()); } } QRDecomposition qr = new QRDecomposition(T); return qr.getQ(); }