@Test public void testOffset() { OnlineSummarizer s = new OnlineSummarizer(); Sampler<Double> sampler = new Normal(2, 5); for (int i = 0; i < 10001; i++) { s.add(sampler.sample()); } assertEquals(String.format("m = %.3f, sd = %.3f", s.getMean(), s.getSD()), 2, s.getMean(), 0.04 * s.getSD()); assertEquals(5, s.getSD(), 0.12); }
@Override public Double sample() { return rand.nextGaussian() * sd + mean; }
Normal extends AbstractSamplerFunction { @Override public Double sample() { return rand.nextGaussian() * sd + mean; } }
Normal extends AbstractSamplerFunction { @Override public Double sample() { return rand.nextGaussian() * sd + mean; } Normal();  Normal(double mean, double sd); }
Normal extends AbstractSamplerFunction { @Override public Double sample() { return rand.nextGaussian() * sd + mean; } Normal();  Normal(double mean, double sd); @Override Double sample(); }
Normal extends AbstractSamplerFunction { @Override public Double sample() { return rand.nextGaussian() * sd + mean; } Normal();  Normal(double mean, double sd); @Override Double sample();  }