List of usage examples for org.apache.commons.math3.distribution PoissonDistribution PoissonDistribution
public PoissonDistribution(double p) throws NotStrictlyPositiveException
From source file:ml.shifu.shifu.core.dtrain.dt.DTWorker.java
private float[] sampleWeights(float label) { float[] sampleWeights = null; // sample negative or kFoldCV, sample rate is 1d double sampleRate = (modelConfig.getTrain().getSampleNegOnly() || this.isKFoldCV) ? 1d : modelConfig.getTrain().getBaggingSampleRate(); int classValue = (int) (label + 0.01f); if (this.treeNum == 1 || (this.isGBDT && !this.gbdtSampleWithReplacement)) { // if tree == 1 or GBDT, don't use with replacement sampling; for GBDT, every time is one tree sampleWeights = new float[1]; Random random = null;//from w ww.j ava 2s . c o m if (this.isStratifiedSampling) { random = baggingRandomMap.get(classValue); if (random == null) { random = DTrainUtils.generateRandomBySampleSeed(modelConfig.getTrain().getBaggingSampleSeed(), CommonConstants.NOT_CONFIGURED_BAGGING_SEED); baggingRandomMap.put(classValue, random); } } else { random = baggingRandomMap.get(0); if (random == null) { random = DTrainUtils.generateRandomBySampleSeed(modelConfig.getTrain().getBaggingSampleSeed(), CommonConstants.NOT_CONFIGURED_BAGGING_SEED); baggingRandomMap.put(0, random); } } if (random.nextDouble() <= sampleRate) { sampleWeights[0] = 1f; } else { sampleWeights[0] = 0f; } } else { // if gbdt and gbdtSampleWithReplacement = true, still sampling with replacement sampleWeights = new float[this.treeNum]; if (this.isStratifiedSampling) { PoissonDistribution[] rng = this.baggingRngMap.get(classValue); if (rng == null) { rng = new PoissonDistribution[treeNum]; for (int i = 0; i < treeNum; i++) { rng[i] = new PoissonDistribution(sampleRate); } this.baggingRngMap.put(classValue, rng); } for (int i = 0; i < sampleWeights.length; i++) { sampleWeights[i] = rng[i].sample(); } } else { PoissonDistribution[] rng = this.baggingRngMap.get(0); if (rng == null) { rng = new PoissonDistribution[treeNum]; for (int i = 0; i < treeNum; i++) { rng[i] = new PoissonDistribution(sampleRate); } this.baggingRngMap.put(0, rng); } for (int i = 0; i < sampleWeights.length; i++) { sampleWeights[i] = rng[i].sample(); } } } return sampleWeights; }
From source file:org.apache.flink.api.java.sampling.PoissonSampler.java
/** * Create a poisson sampler which can sample elements with replacement. * * @param fraction The expected count of each element. * @param seed Random number generator seed for internal PoissonDistribution. *//* w w w. j av a 2s . c om*/ public PoissonSampler(double fraction, long seed) { Preconditions.checkArgument(fraction >= 0, "fraction should be positive."); this.fraction = fraction; if (this.fraction > 0) { this.poissonDistribution = new PoissonDistribution(fraction); this.poissonDistribution.reseedRandomGenerator(seed); } this.random = new XORShiftRandom(seed); }
From source file:org.apache.flink.api.java.sampling.PoissonSampler.java
/** * Create a poisson sampler which can sample elements with replacement. * * @param fraction The expected count of each element. *//* www. j av a 2 s . c o m*/ public PoissonSampler(double fraction) { Preconditions.checkArgument(fraction >= 0, "fraction should be non-negative."); this.fraction = fraction; if (this.fraction > 0) { this.poissonDistribution = new PoissonDistribution(fraction); } this.random = new XORShiftRandom(); }
From source file:org.apache.reef.poison.context.PoissonPoisonedContextStartHandler.java
@Inject PoissonPoisonedContextStartHandler(@Parameter(CrashProbability.class) final double lambda, final Clock clock) { this.clock = clock; this.timeToCrash = new PoissonDistribution(lambda * 1000).sample(); LOG.log(Level.INFO, "Created Poisson poison injector with prescribed dose: {0}. Crash in {1} msec.", new Object[] { lambda, this.timeToCrash }); }
From source file:org.apache.reef.poison.task.PoissonPoisonedTaskStartHandler.java
@Inject PoissonPoisonedTaskStartHandler(@Parameter(CrashProbability.class) final double lambda, final Clock clock) { this.clock = clock; this.timeToCrash = new PoissonDistribution(lambda * 1000).sample(); LOG.log(Level.INFO, "Created Poisson poison injector with prescribed dose: {0}. Crash in {1} msec.", new Object[] { lambda, this.timeToCrash }); }
From source file:org.apache.solr.client.solrj.io.eval.PoissonDistributionEvaluator.java
@Override public Object doWork(Object first) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }/*from w w w. j av a2s.c o m*/ Number mean = (Number) first; return new PoissonDistribution(mean.intValue()); }
From source file:org.deidentifier.arx.criteria.KMap.java
/** * Calculates k, based on Poisson distribution. * @param lambda/*from w w w . j av a2s .c om*/ * @return */ private int calculateKPoisson(double lambda) { final double threshold = 1d - this.significanceLevel; final PoissonDistribution distribution = new PoissonDistribution(lambda); int counter = 0; double value = 0; while (value < threshold) { // value += (Math.pow(lambda, counter) * Math.exp(-lambda)) / ArithmeticUtils.factorial(counter); value = distribution.cumulativeProbability(counter); counter++; // Break if the estimated k is equal or greater than the given k, as this makes no sense. if (counter >= this.k) { // We are 100% sure that the dataset fulfills k-map value = 1d; break; } } this.type1Error = 1d - value; return counter + 1; }
From source file:org.deidentifier.arx.criteria.KMap.java
/** * Calculates k, based on Zero-truncated Poisson distribution. * https://en.wikipedia.org/wiki/Zero-truncated_Poisson_distribution * /*from ww w .j ava2 s .co m*/ * @param lambda * @return */ private int calculateKZeroPoisson(double lambda) { final double threshold = 1d - this.significanceLevel; final PoissonDistribution distribution = new PoissonDistribution(lambda); final double v2 = 1d - distribution.probability(0); int counter = 1; double value = 0d; while (value < threshold) { // value2 += ((Math.pow(lambda, counter)) / (Math.exp(lambda) - 1)) * ArithmeticUtils.factorial(counter); value += distribution.probability(counter) / v2; counter++; // Break if the estimated k is equal or greater than the given k, as this makes no sense. if (counter >= this.k) { // We are 100% sure that the dataset fulfills k-map value = 1d; break; } } this.type1Error = 1d - value; return counter; }
From source file:org.gitools.analysis.stats.test.BinomialTest.java
private static CommonResult resultWithPoisson(int observed, int n, double p, double expectedMean, double expectedStdev) { double leftPvalue; double rightPvalue; double twoTailPvalue; try {/*from www .ja va 2s.co m*/ PoissonDistribution poisson = new PoissonDistribution(expectedMean); leftPvalue = poisson.cumulativeProbability(observed); rightPvalue = observed > 0 ? poisson.cumulativeProbability(observed - 1, n) : 1.0; twoTailPvalue = (observed <= expectedMean ? leftPvalue : rightPvalue) * 2; //FIXME: Review twoTailPvalue = twoTailPvalue > 1.0 ? 1.0 : twoTailPvalue; } catch (ArithmeticException e) { leftPvalue = rightPvalue = twoTailPvalue = Double.NaN; } return new BinomialResult(BinomialResult.Distribution.POISSON, n, leftPvalue, rightPvalue, twoTailPvalue, observed, expectedMean, expectedStdev, p); }
From source file:org.talend.dataquality.duplicating.DistributionFactory.java
public static AbstractIntegerDistribution createDistribution(String name, double expectation) { AbstractIntegerDistribution distro = null; if (expectation < 2) { throw new IllegalArgumentException("The expectation value must be greater than or equals to 2"); //$NON-NLS-1$ }//from w w w. j a v a 2s. c o m if (name.equals("BERNOULLI")) { //$NON-NLS-1$ distro = new BinomialDistribution((int) ((expectation - 2) * 2), 0.5); } else if (name.equals("GEOMETRIC")) { //$NON-NLS-1$ distro = new GeometricDistribution(1 / (expectation - 1)); } else if (name.equals("POISSON")) { //$NON-NLS-1$ distro = new PoissonDistribution(expectation - 2 + java.lang.Double.MIN_VALUE); } return distro; }