Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#MEAN

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#MEAN . 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: PoissonDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param rng Random number generator.
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 3.1
 */
public PoissonDistribution(RandomGenerator rng,
                           double p,
                           double epsilon,
                           int maxIterations)
throws NotStrictlyPositiveException {
    super(rng);

    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;

    // Use the same RNG instance as the parent class.
    normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    exponential = new ExponentialDistribution(rng, 1,
                                              ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
 
Example 2
Source File: PoissonDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param rng Random number generator.
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 3.1
 */
public PoissonDistribution(RandomGenerator rng,
                           double p,
                           double epsilon,
                           int maxIterations)
throws NotStrictlyPositiveException {
    super(rng);

    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;

    // Use the same RNG instance as the parent class.
    normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    exponential = new ExponentialDistribution(rng, 1,
                                              ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
 
Example 3
Source File: PoissonDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param rng Random number generator.
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 3.1
 */
public PoissonDistribution(RandomGenerator rng,
                           double p,
                           double epsilon,
                           int maxIterations)
throws NotStrictlyPositiveException {
    super(rng);

    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;

    // Use the same RNG instance as the parent class.
    normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    exponential = new ExponentialDistribution(rng, 1,
                                              ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
 
Example 4
Source File: PoissonDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param rng Random number generator.
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 3.1
 */
public PoissonDistribution(RandomGenerator rng,
                           double p,
                           double epsilon,
                           int maxIterations)
throws NotStrictlyPositiveException {
    super(rng);

    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;

    // Use the same RNG instance as the parent class.
    normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    exponential = new ExponentialDistribution(rng, 1,
                                              ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
 
Example 5
Source File: PoissonDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param rng Random number generator.
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 3.1
 */
public PoissonDistribution(RandomGenerator rng,
                           double p,
                           double epsilon,
                           int maxIterations)
throws NotStrictlyPositiveException {
    super(rng);

    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;

    // Use the same RNG instance as the parent class.
    normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    exponential = new ExponentialDistribution(rng, 1,
                                              ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
 
Example 6
Source File: PoissonDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param rng Random number generator.
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 3.1
 */
public PoissonDistribution(RandomGenerator rng,
                           double p,
                           double epsilon,
                           int maxIterations)
throws NotStrictlyPositiveException {
    super(rng);

    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;

    // Use the same RNG instance as the parent class.
    normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    exponential = new ExponentialDistribution(rng, 1,
                                              ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
 
Example 7
Source File: PoissonDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param rng Random number generator.
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 3.1
 */
public PoissonDistribution(RandomGenerator rng,
                           double p,
                           double epsilon,
                           int maxIterations)
throws NotStrictlyPositiveException {
    super(rng);

    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;

    // Use the same RNG instance as the parent class.
    normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    exponential = new ExponentialDistribution(rng, 1,
                                              ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
 
Example 8
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an exponential distribution.
 *
 * @param rng Random number generator.
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 3.1
 */
public ExponentialDistribution(RandomGenerator rng,
                               double mean,
                               double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    logMean = FastMath.log(mean);
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 9
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an exponential distribution.
 *
 * @param rng Random number generator.
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 3.1
 */
public ExponentialDistribution(RandomGenerator rng,
                               double mean,
                               double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    logMean = FastMath.log(mean);
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 10
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an exponential distribution.
 *
 * @param rng Random number generator.
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 3.1
 */
public ExponentialDistribution(RandomGenerator rng,
                               double mean,
                               double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 11
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an exponential distribution.
 *
 * @param rng Random number generator.
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 3.1
 */
public ExponentialDistribution(RandomGenerator rng,
                               double mean,
                               double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 12
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an exponential distribution.
 *
 * @param rng Random number generator.
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 3.1
 */
public ExponentialDistribution(RandomGenerator rng,
                               double mean,
                               double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 13
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an exponential distribution.
 *
 * @param rng Random number generator.
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 3.1
 */
public ExponentialDistribution(RandomGenerator rng,
                               double mean,
                               double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 14
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an exponential distribution.
 *
 * @param rng Random number generator.
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 3.1
 */
public ExponentialDistribution(RandomGenerator rng,
                               double mean,
                               double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 15
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) {

    if (mean <= 0.0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }

    // Step 1:
    double a = 0;
    double u = this.nextUniform(0, 1);

    // Step 2 and 3:
    while (u < 0.5) {
        a += EXPONENTIAL_SA_QI[0];
        u *= 2;
    }

    // Step 4 (now u >= 0.5):
    u += u - 1;

    // Step 5:
    if (u <= EXPONENTIAL_SA_QI[0]) {
        return mean * (a + u);
    }

    // Step 6:
    int i = 0; // Should be 1, be we iterate before it in while using 0
    double u2 = this.nextUniform(0, 1);
    double umin = u2;

    // Step 7 and 8:
    do {
        ++i;
        u2 = this.nextUniform(0, 1);

        if (u2 < umin) {
            umin = u2;
        }

        // Step 8:
    } while (u > EXPONENTIAL_SA_QI[i]); // Ensured to exit since EXPONENTIAL_SA_QI[MAX] = 1

    return mean * (a + umin * EXPONENTIAL_SA_QI[0]);
}
 
Example 16
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>
 * <strong>Algorithm Description</strong>: Uses the Algorithm SA (Ahrens)
 * from p. 876 in:
 * [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for
 * sampling from the exponential and normal distributions.
 * Communications of the ACM, 15, 873-882.
 * </p>
 */
public double nextExponential(double mean) {

    if (mean <= 0.0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }

    // Step 1:
    double a = 0;
    double u = this.nextUniform(0, 1);

    // Step 2 and 3:
    while (u < 0.5) {
        a += EXPONENTIAL_SA_QI[0];
        u *= 2;
    }

    // Step 4 (now u >= 0.5):
    u += u - 1;

    // Step 5:
    if (u <= EXPONENTIAL_SA_QI[0]) {
        return mean * (a + u);
    }

    // Step 6:
    int i = 0; // Should be 1, be we iterate before it in while using 0
    double u2 = this.nextUniform(0, 1);
    double umin = u2;

    // Step 7 and 8:
    do {
        ++i;
        u2 = this.nextUniform(0, 1);

        if (u2 < umin) {
            umin = u2;
        }

        // Step 8:
    } while (u > EXPONENTIAL_SA_QI[i]); // Ensured to exit since EXPONENTIAL_SA_QI[MAX] = 1

    return mean * (a + umin * EXPONENTIAL_SA_QI[0]);
}
 
Example 17
Source File: ExponentialDistribution.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a exponential distribution with the given mean.
 *
 * @param mean Mean of this distribution.
 * @param inverseCumAccuracy Maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code mean <= 0}.
 * @since 2.1
 */
public ExponentialDistribution(double mean, double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    if (mean <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
    }
    this.mean = mean;
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
Example 18
Source File: PoissonDistribution.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new Poisson distribution with specified mean, convergence
 * criterion and maximum number of iterations.
 *
 * @param p Poisson mean.
 * @param epsilon Convergence criterion for cumulative probabilities.
 * @param maxIterations the maximum number of iterations for cumulative
 * probabilities.
 * @throws NotStrictlyPositiveException if {@code p <= 0}.
 * @since 2.1
 */
public PoissonDistribution(double p, double epsilon, int maxIterations)
throws NotStrictlyPositiveException {
    if (p <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, p);
    }
    mean = p;
    normal = new NormalDistribution(p, FastMath.sqrt(p));
    this.epsilon = epsilon;
    this.maxIterations = maxIterations;
}