org.apache.commons.math3.distribution.PascalDistribution Java Examples

The following examples show how to use org.apache.commons.math3.distribution.PascalDistribution. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #2
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #3
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #4
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #5
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() throws Exception {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #6
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #7
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #8
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextPascal() {
    PascalDistributionTest testInstance = new PascalDistributionTest();
    int[] densityPoints = testInstance.makeDensityTestPoints();
    double[] densityValues = testInstance.makeDensityTestValues();
    int sampleSize = 1000;
    int length = TestUtils.eliminateZeroMassPoints(densityPoints, densityValues);
    PascalDistribution distribution = (PascalDistribution) testInstance.makeDistribution();
    double[] expectedCounts = new double[length];
    long[] observedCounts = new long[length];
    for (int i = 0; i < length; i++) {
        expectedCounts[i] = sampleSize * densityValues[i];
    }
    randomData.reSeed(1000);
    for (int i = 0; i < sampleSize; i++) {
      int value = randomData.nextPascal(distribution.getNumberOfSuccesses(), distribution.getProbabilityOfSuccess());
      for (int j = 0; j < length; j++) {
          if (value == densityPoints[j]) {
              observedCounts[j]++;
          }
      }
    }
    TestUtils.assertChiSquareAccept(densityPoints, expectedCounts, observedCounts, .001);
}
 
Example #9
Source File: SamplingLongPrimitiveIterator.java    From elasticsearch-taste with Apache License 2.0 5 votes vote down vote up
public SamplingLongPrimitiveIterator(final RandomWrapper random,
        final LongPrimitiveIterator delegate, final double samplingRate) {
    Preconditions.checkNotNull(delegate);
    Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0,
            "Must be: 0.0 < samplingRate <= 1.0");
    // Geometric distribution is special case of negative binomial (aka Pascal) with r=1:
    geometricDistribution = new PascalDistribution(
            random.getRandomGenerator(), 1, samplingRate);
    this.delegate = delegate;
    hasNext = true;
    doNext();
}
 
Example #10
Source File: SamplingLongPrimitiveIterator.java    From myrrix-recommender with Apache License 2.0 5 votes vote down vote up
public SamplingLongPrimitiveIterator(RandomGenerator random, LongPrimitiveIterator delegate, double samplingRate) {
  Preconditions.checkNotNull(random);
  Preconditions.checkNotNull(delegate);
  Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0);
  // Geometric distribution is special case of negative binomial (aka Pascal) with r=1:
  geometricDistribution = new PascalDistribution(random, 1, samplingRate);
  this.delegate = delegate;
  this.hasNext = true;
  doNext();
}
 
Example #11
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @throws NotStrictlyPositiveException if the number of successes is not positive
 * @throws OutOfRangeException if the probability of success is not in the
 * range {@code [0, 1]}.
 */
public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException {
    return new PascalDistribution(getRandomGenerator(), r, p).sample();
}
 
Example #12
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 * This implementation uses {@link #nextInversionDeviate(IntegerDistribution) inversion}
 * to generate random values.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @since 2.2
 */
public int nextPascal(int r, double p) {
    return nextInversionDeviate(new PascalDistribution(r, p));
}
 
Example #13
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 * This implementation uses {@link #nextInversionDeviate(IntegerDistribution) inversion}
 * to generate random values.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @since 2.2
 */
public int nextPascal(int r, double p) {
    return nextInversionDeviate(new PascalDistribution(r, p));
}
 
Example #14
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @throws NotStrictlyPositiveException if the number of successes is not positive
 * @throws OutOfRangeException if the probability of success is not in the
 * range {@code [0, 1]}.
 */
public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException {
    return new PascalDistribution(getRandomGenerator(), r, p).sample();
}
 
Example #15
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @throws NotStrictlyPositiveException if the number of successes is not positive
 * @throws OutOfRangeException if the probability of success is not in the
 * range {@code [0, 1]}.
 */
public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException {
    return new PascalDistribution(getRandomGenerator(), r, p).sample();
}
 
Example #16
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @throws NotStrictlyPositiveException if the number of successes is not positive
 * @throws OutOfRangeException if the probability of success is not in the
 * range {@code [0, 1]}.
 */
public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException {
    return new PascalDistribution(getRan(), r, p).sample();
}
 
Example #17
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @throws NotStrictlyPositiveException if the number of successes is not positive
 * @throws OutOfRangeException if the probability of success is not in the
 * range {@code [0, 1]}.
 */
public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException {
    return new PascalDistribution(getRandomGenerator(), r, p).sample();
}
 
Example #18
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link PascalDistribution Pascal Distribution}.
 *
 * @param r the number of successes of the Pascal distribution
 * @param p the probability of success of the Pascal distribution
 * @return random value sampled from the Pascal(r, p) distribution
 * @throws NotStrictlyPositiveException if the number of successes is not positive
 * @throws OutOfRangeException if the probability of success is not in the
 * range {@code [0, 1]}.
 */
public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException {
    return new PascalDistribution(getRandomGenerator(), r, p).sample();
}