Java Code Examples for org.apache.commons.math3.util.Pair#getValue()

The following examples show how to use org.apache.commons.math3.util.Pair#getValue() . 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: Arja_00127_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param samples definition of probability mass function in the format of
 * list of pairs.
 * @throws NotPositiveException if probability of at least one value is
 * negative.
 * @throws MathArithmeticException if the probabilities sum to zero.
 * @throws MathIllegalArgumentException if probability of at least one value
 * is infinite.
 */
public DiscreteDistribution(final RandomGenerator rng, final List<Pair<T, Double>> samples)
    throws NotPositiveException, MathArithmeticException, MathIllegalArgumentException {
    random = rng;

    singletons = new ArrayList<T>(samples.size());
    final double[] probs = new double[samples.size()];

    for (int i = 0; i < samples.size(); i++) {
        final Pair<T, Double> sample = samples.get(i);
        singletons.add(sample.getKey());
        if (sample.getValue() < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        probs[i] = sample.getValue();
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example 2
Source File: Arja_00108_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param samples definition of probability mass function in the format of
 * list of pairs.
 * @throws NotPositiveException if probability of at least one value is
 * negative.
 * @throws MathArithmeticException if the probabilities sum to zero.
 * @throws MathIllegalArgumentException if probability of at least one value
 * is infinite.
 */
public DiscreteDistribution(final RandomGenerator rng, final List<Pair<T, Double>> samples)
    throws NotPositiveException, MathArithmeticException, MathIllegalArgumentException {
    random = rng;

    singletons = new ArrayList<T>(samples.size());
    final double[] probs = new double[samples.size()];

    for (int i = 0; i < samples.size(); i++) {
        final Pair<T, Double> sample = samples.get(i);
        singletons.add(sample.getKey());
        if (sample.getValue() < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        probs[i] = sample.getValue();
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example 3
Source File: Cardumen_0060_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param samples definition of probability mass function in the format of
 * list of pairs.
 * @throws NotPositiveException if probability of at least one value is
 * negative.
 * @throws MathArithmeticException if the probabilities sum to zero.
 * @throws MathIllegalArgumentException if probability of at least one value
 * is infinite.
 */
public DiscreteDistribution(final RandomGenerator rng, final List<Pair<T, Double>> samples)
    throws NotPositiveException, MathArithmeticException, MathIllegalArgumentException {
    random = rng;

    singletons = new ArrayList<T>(samples.size());
    final double[] probs = new double[samples.size()];

    for (int i = 0; i < samples.size(); i++) {
        final Pair<T, Double> sample = samples.get(i);
        singletons.add(sample.getKey());
        if (sample.getValue() < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        probs[i] = sample.getValue();
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example 4
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    double probability = 0;
    double x = getSupportLowerBound();
    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getValue() == 0.0) {
            continue;
        }

        probability += sample.getValue();
        x = sample.getKey();

        if (probability >= p) {
            break;
        }
    }

    return x;
}
 
Example 5
Source File: JGenProg2017_0070_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param samples definition of probability mass function in the format of
 * list of pairs.
 * @throws NotPositiveException if probability of at least one value is
 * negative.
 * @throws MathArithmeticException if the probabilities sum to zero.
 * @throws MathIllegalArgumentException if probability of at least one value
 * is infinite.
 */
public DiscreteDistribution(final RandomGenerator rng, final List<Pair<T, Double>> samples)
    throws NotPositiveException, MathArithmeticException, MathIllegalArgumentException {
    random = rng;

    singletons = new ArrayList<T>(samples.size());
    final double[] probs = new double[samples.size()];

    for (int i = 0; i < samples.size(); i++) {
        final Pair<T, Double> sample = samples.get(i);
        singletons.add(sample.getKey());
        if (sample.getValue() < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        probs[i] = sample.getValue();
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example 6
Source File: Cardumen_00179_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param samples definition of probability mass function in the format of
 * list of pairs.
 * @throws NotPositiveException if probability of at least one value is
 * negative.
 * @throws MathArithmeticException if the probabilities sum to zero.
 * @throws MathIllegalArgumentException if probability of at least one value
 * is infinite.
 */
public DiscreteDistribution(final RandomGenerator rng, final List<Pair<T, Double>> samples)
    throws NotPositiveException, MathArithmeticException, MathIllegalArgumentException {
    random = rng;

    singletons = new ArrayList<T>(samples.size());
    final double[] probs = new double[samples.size()];

    for (int i = 0; i < samples.size(); i++) {
        final Pair<T, Double> sample = samples.get(i);
        singletons.add(sample.getKey());
        if (sample.getValue() < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        probs[i] = sample.getValue();
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example 7
Source File: Arja_00170_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param samples definition of probability mass function in the format of
 * list of pairs.
 * @throws NotPositiveException if probability of at least one value is
 * negative.
 * @throws MathArithmeticException if the probabilities sum to zero.
 * @throws MathIllegalArgumentException if probability of at least one value
 * is infinite.
 */
public DiscreteDistribution(final RandomGenerator rng, final List<Pair<T, Double>> samples)
    throws NotPositiveException, MathArithmeticException, MathIllegalArgumentException {
    random = rng;

    singletons = new ArrayList<T>(samples.size());
    final double[] probs = new double[samples.size()];

    for (int i = 0; i < samples.size(); i++) {
        final Pair<T, Double> sample = samples.get(i);
        singletons.add(sample.getKey());
        if (sample.getValue() < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        probs[i] = sample.getValue();
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example 8
Source File: Cardumen_00272_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Create a discrete distribution using the given random number generator
 * and probability mass function definition.
 *
 * @param rng random number generator.
 * @param samples definition of probability mass function in the format of
 * list of pairs.
 * @throws NotPositiveException if probability of at least one value is
 * negative.
 * @throws MathArithmeticException if the probabilities sum to zero.
 * @throws MathIllegalArgumentException if probability of at least one value
 * is infinite.
 */
public DiscreteDistribution(final RandomGenerator rng, final List<Pair<T, Double>> samples)
    throws NotPositiveException, MathArithmeticException, MathIllegalArgumentException {
    random = rng;

    singletons = new ArrayList<T>(samples.size());
    final double[] probs = new double[samples.size()];

    for (int i = 0; i < samples.size(); i++) {
        final Pair<T, Double> sample = samples.get(i);
        singletons.add(sample.getKey());
        if (sample.getValue() < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        probs[i] = sample.getValue();
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);
}
 
Example 9
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the highest value with non-zero probability.
 *
 * @return the highest value with non-zero probability.
 */
public int getSupportUpperBound() {
    int max = Integer.MIN_VALUE;
    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() > max && sample.getValue() > 0) {
            max = sample.getKey();
        }
    }

    return max;
}
 
Example 10
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum((singletons[i] - mean) ^ 2 * probabilities[i])}
 */
public double getNumericalVariance() {
    double mean = 0;
    double meanOfSquares = 0;

    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
        meanOfSquares += sample.getValue() * sample.getKey() * sample.getKey();
    }

    return meanOfSquares - mean * mean;
}
 
Example 11
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum((singletons[i] - mean) ^ 2 * probabilities[i])}
 */
public double getNumericalVariance() {
    double mean = 0;
    double meanOfSquares = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
        meanOfSquares += sample.getValue() * sample.getKey() * sample.getKey();
    }

    return meanOfSquares - mean * mean;
}
 
Example 12
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the highest value with non-zero probability.
 *
 * @return the highest value with non-zero probability.
 */
public int getSupportUpperBound() {
    int max = Integer.MIN_VALUE;
    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() > max && sample.getValue() > 0) {
            max = sample.getKey();
        }
    }

    return max;
}
 
Example 13
Source File: ParseGridsearchResults.java    From bluima with Apache License 2.0 5 votes vote down vote up
private static List<String> optionsValsFor(String optionName) {
    Pair<Type, Object[]> optionDefinition = StaticOption
            .getOptionDefinition(optionName);
    List<String> optionValues = newArrayList();
    for (Object optionValue : optionDefinition.getValue()) {
        optionValues.add(optionValue.toString());
    }
    return optionValues;
}
 
Example 14
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public double cumulativeProbability(final int x) {
    double probability = 0;

    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() <= x) {
            probability += sample.getValue();
        }
    }

    return probability;
}
 
Example 15
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the lowest value with non-zero probability.
 *
 * @return the lowest value with non-zero probability.
 */
public int getSupportLowerBound() {
    int min = Integer.MAX_VALUE;
    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() < min && sample.getValue() > 0) {
            min = sample.getKey();
        }
    }

    return min;
}
 
Example 16
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public double cumulativeProbability(final double x) {
    double probability = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() <= x) {
            probability += sample.getValue();
        }
    }

    return probability;
}
 
Example 17
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the lowest value with non-zero probability.
 *
 * @return the lowest value with non-zero probability.
 */
public double getSupportLowerBound() {
    double min = Double.POSITIVE_INFINITY;
    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() < min && sample.getValue() > 0) {
            min = sample.getKey();
        }
    }

    return min;
}
 
Example 18
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum(singletons[i] * probabilities[i])}
 */
public double getNumericalMean() {
    double mean = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
    }

    return mean;
}
 
Example 19
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum((singletons[i] - mean) ^ 2 * probabilities[i])}
 */
public double getNumericalVariance() {
    double mean = 0;
    double meanOfSquares = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
        meanOfSquares += sample.getValue() * sample.getKey() * sample.getKey();
    }

    return meanOfSquares - mean * mean;
}
 
Example 20
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public double cumulativeProbability(final double x) {
    double probability = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() <= x) {
            probability += sample.getValue();
        }
    }

    return probability;
}