org.apache.commons.math3.exception.OutOfRangeException Java Examples

The following examples show how to use org.apache.commons.math3.exception.OutOfRangeException. 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: 1_ElitisticListPopulation.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Creates a new ElitisticListPopulation instance.
     *
     * @param chromosomes list of chromosomes in the population
     * @param populationLimit maximal size of the population
     * @param elitismRate how many best chromosomes will be directly transferred to the
     *                    next generation [in %]
     * @throws OutOfRangeException if the elitism rate is outside the [0, 1] range
     */
    public ElitisticListPopulation(final List<Chromosome> chromosomes,
                                   final int populationLimit,
                                   final double elitismRate) {
// start of generated patch
super(chromosomes,populationLimit);
if(elitismRate<0||elitismRate>1){
throw new OutOfRangeException(LocalizedFormats.ELITISM_RATE,elitismRate,0,1);
}
this.elitismRate=elitismRate;
// end of generated patch
/* start of original code
        super(chromosomes, populationLimit);
        this.elitismRate = elitismRate;
 end of original code*/
    }
 
Example #2
Source File: Math_6_CMAESOptimizer_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] > uB[i] - lB[i]) {
                throw new OutOfRangeException(inputSigma[i], 0, uB[i] - lB[i]);
            }
        }
    }
}
 
Example #3
Source File: 1_ElitisticListPopulation.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Creates a new ElitisticListPopulation instance.
     *
     * @param chromosomes list of chromosomes in the population
     * @param populationLimit maximal size of the population
     * @param elitismRate how many best chromosomes will be directly transferred to the
     *                    next generation [in %]
     * @throws OutOfRangeException if the elitism rate is outside the [0, 1] range
     */
    public ElitisticListPopulation(final List<Chromosome> chromosomes,
                                   final int populationLimit,
                                   final double elitismRate) {
// start of generated patch
super(chromosomes,populationLimit);
if(elitismRate<0||elitismRate>1){
throw new OutOfRangeException(LocalizedFormats.ELITISM_RATE,elitismRate,0,1);
}
this.elitismRate=elitismRate;
// end of generated patch
/* start of original code
        super(chromosomes, populationLimit);
        this.elitismRate = elitismRate;
 end of original code*/
    }
 
Example #4
Source File: Math_6_CMAESOptimizer_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] > uB[i] - lB[i]) {
                throw new OutOfRangeException(inputSigma[i], 0, uB[i] - lB[i]);
            }
        }
    }
}
 
Example #5
Source File: PseudoSpectrumDataSet.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void addDP(int series, double x, double y, String ann) {
  if (series >= getSeriesCount())
    throw new OutOfRangeException(series, 0, getSeriesCount());

  XYDataItem dp = new XYDataItem(x, y);
  getSeries(series).add(dp);
  if (ann != null) {
    addAnnotation(dp, ann);
  }
}
 
Example #6
Source File: Cardumen_00256_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if ((java.lang.Double.isInfinite(p)) || (java.lang.Double.isNaN(p))) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #7
Source File: Cardumen_00105_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;

            // Abort early if the normalization will overflow (cf. "encode" method).
            for (int i = 0; i < lB.length; i++) {
                if (Double.isInfinite(boundaries[1][i] - boundaries[0][i])) {
                    final double max = Double.MAX_VALUE + boundaries[0][i];
                    final NumberIsTooLargeException e
                        = new NumberIsTooLargeException(boundaries[1][i],
                                                        max,
                                                        true);
                    e.getContext().addMessage(LocalizedFormats.OVERFLOW);
                    e.getContext().addMessage(LocalizedFormats.INDEX, i);

                    throw e;
                }
            }
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #8
Source File: jMutRepair_008_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp == upper) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #9
Source File: Elixir_0021_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #10
Source File: Cardumen_0037_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #11
Source File: JGenProg2017_00130_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #12
Source File: Cardumen_00213_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #13
Source File: JGenProg2017_0089_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #14
Source File: jMutRepair_0041_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #15
Source File: JGenProg2017_00130_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (java.lang.Double.isInfinite(p)) {
throw new org.apache.commons.math3.exception.NotFiniteNumberException(p);
}
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #16
Source File: JGenProg2017_0020_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #17
Source File: Nopol2017_0063_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            if (tmp == -1) {
                upper = ((int) Math.ceil(tmp)) - 1;
            }
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #18
Source File: Cardumen_00105_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;

            // Abort early if the normalization will overflow (cf. "encode" method).
            for (int i = 0; i < lB.length; i++) {
                if (Double.isInfinite(boundaries[1][i] - boundaries[0][i])) {
                    final double max = Double.MAX_VALUE + boundaries[0][i];
                    final NumberIsTooLargeException e
                        = new NumberIsTooLargeException(boundaries[1][i],
                                                        max,
                                                        true);
                    e.getContext().addMessage(LocalizedFormats.OVERFLOW);
                    e.getContext().addMessage(LocalizedFormats.INDEX, i);

                    throw e;
                }
            }
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #19
Source File: Cardumen_0035_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;

            // Abort early if the normalization will overflow (cf. "encode" method).
            for (int i = 0; i < lB.length; i++) {
                if (Double.isInfinite(boundaries[1][i] - boundaries[0][i])) {
                    final double max = Double.MAX_VALUE + boundaries[0][i];
                    final NumberIsTooLargeException e
                        = new NumberIsTooLargeException(boundaries[1][i],
                                                        max,
                                                        true);
                    e.getContext().addMessage(LocalizedFormats.OVERFLOW);
                    e.getContext().addMessage(LocalizedFormats.INDEX, i);

                    throw e;
                }
            }
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #20
Source File: Math_19_CMAESOptimizer_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;

            // Abort early if the normalization will overflow (cf. "encode" method).
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #21
Source File: JGenProg2017_0058_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #22
Source File: Cardumen_00107_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #23
Source File: jMutRepair_0033_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #24
Source File: jMutRepair_0024_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #25
Source File: Math_19_CMAESOptimizer_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;

            // Abort early if the normalization will overflow (cf. "encode" method).
            for (int i = 0; i < lB.length; i++) {
                if (Double.isInfinite(boundaries[1][i] - boundaries[0][i])) {
                    final double max = Double.MAX_VALUE + boundaries[0][i];
                    final NumberIsTooLargeException e
                        = new NumberIsTooLargeException(boundaries[1][i],
                                                        max,
                                                        true);
                    e.getContext().addMessage(LocalizedFormats.OVERFLOW);
                    e.getContext().addMessage(LocalizedFormats.INDEX, i);

                    throw e;
                }
            }
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #26
Source File: Arja_00104_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #27
Source File: Arja_0055_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}
 
Example #28
Source File: Arja_0078_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            upper = ((int) Math.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #29
Source File: Arja_0027_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) Math.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
        	lower-=1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
Example #30
Source File: JGenProg2017_0059_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Checks dimensions and values of boundaries and inputSigma if defined.
 */
private void checkParameters() {
    final double[] init = getStartPoint();
    final double[] lB = getLowerBound();
    final double[] uB = getUpperBound();

    // Checks whether there is at least one finite bound value.
    boolean hasFiniteBounds = false;
    for (int i = 0; i < lB.length; i++) {
        if (!Double.isInfinite(lB[i]) ||
            !Double.isInfinite(uB[i])) {
            hasFiniteBounds = true;
            break;
        }
    }
    // Checks whether there is at least one infinite bound value.
    boolean hasInfiniteBounds = false;
    if (hasFiniteBounds) {
        for (int i = 0; i < lB.length; i++) {
            if (Double.isInfinite(lB[i]) ||
                Double.isInfinite(uB[i])) {
                hasInfiniteBounds = true;
                break;
            }
        }

        if (hasInfiniteBounds) {
            // If there is at least one finite bound, none can be infinite,
            // because mixed cases are not supported by the current code.
            throw new MathUnsupportedOperationException();
        } else {
            // Convert API to internal handling of boundaries.
            boundaries = new double[2][];
            boundaries[0] = lB;
            boundaries[1] = uB;
        }
    } else {
        // Convert API to internal handling of boundaries.
        boundaries = null;
    }

    if (inputSigma != null) {
        if (inputSigma.length != init.length) {
            throw new DimensionMismatchException(inputSigma.length, init.length);
        }
        for (int i = 0; i < init.length; i++) {
            if (inputSigma[i] < 0) {
                throw new NotPositiveException(inputSigma[i]);
            }
            if (boundaries != null) {
                if (inputSigma[i] > boundaries[1][i] - boundaries[0][i]) {
                    throw new OutOfRangeException(inputSigma[i], 0, boundaries[1][i] - boundaries[0][i]);
                }
            }
        }
    }
}