/** * Creates an instance. * * @param mean the mean * @param sigma the sigma */ public NormalRandomNumberGenerator(double mean, double sigma) { ArgChecker.notNegativeOrZero(sigma, "standard deviation"); this.normal = new NormalDistribution(mean, sigma); }
private double getFraserApproxCDF(double x) { double s = Math.sqrt(_lambdaOverTwo * 2.0); double mu = Math.sqrt(x); double z; if (Double.doubleToLongBits(mu) == Double.doubleToLongBits(s)) { z = (1 - _dofOverTwo * 2.0) / 2 / s; } else { z = mu - s - (_dofOverTwo * 2.0 - 1) / 2 * (Math.log(mu) - Math.log(s)) / (mu - s); } return (new NormalDistribution(0, 1)).getCDF(z); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullEngine() { new NormalDistribution(0, 1, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeSigmaDistribution() { new NormalDistribution(1, -0.4); }
/** * Creates an instance. * * @param mean the mean * @param sigma the sigma * @param engine the random number engine */ public NormalRandomNumberGenerator(double mean, double sigma, RandomEngine engine) { ArgChecker.notNegativeOrZero(sigma, "standard deviation"); ArgChecker.notNull(engine, "engine"); this.normal = new NormalDistribution(mean, sigma, engine); }
public void testObject() { NormalDistribution other = new NormalDistribution(0, 1, ENGINE); assertEquals(NORMAL, other); assertEquals(NORMAL.hashCode(), other.hashCode()); other = new NormalDistribution(0, 1); assertEquals(NORMAL, other); assertEquals(NORMAL.hashCode(), other.hashCode()); other = new NormalDistribution(0.1, 1, ENGINE); assertFalse(NORMAL.equals(other)); other = new NormalDistribution(0, 1.1, ENGINE); assertFalse(NORMAL.equals(other)); } }
@Test public void testNormal() { final ProbabilityDistribution<Double> highDOF = new StudentTDistribution(1000000, ENGINE); final ProbabilityDistribution<Double> normal = new NormalDistribution(0, 1, ENGINE); final double eps = 1e-4; double x; for (int i = 0; i < 100; i++) { x = RANDOM.nextDouble(); assertEquals(highDOF.getCDF(x), normal.getCDF(x), eps); assertEquals(highDOF.getPDF(x), normal.getPDF(x), eps); assertEquals(highDOF.getInverseCDF(x), normal.getInverseCDF(x), eps); } }