Java Code Examples for org.apache.commons.math.MathRuntimeException#createIllegalStateException()

The following examples show how to use org.apache.commons.math.MathRuntimeException#createIllegalStateException() . 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: EmpiricalDistributionImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates a random value from this distribution.
 *
 * @return the random value.
 * @throws IllegalStateException if the distribution has not been loaded
 */
public double getNextValue() throws IllegalStateException {

    if (!loaded) {
        throw MathRuntimeException.createIllegalStateException("distribution not loaded");
    }

    // Start with a uniformly distributed random number in (0,1)
    double x = Math.random();

    // Use this to select the bin and generate a Gaussian within the bin
    for (int i = 0; i < binCount; i++) {
       if (x <= upperBounds[i]) {
           SummaryStatistics stats = binStats.get(i);
           if (stats.getN() > 0) {
               if (stats.getStandardDeviation() > 0) {  // more than one obs
                    return randomData.nextGaussian
                        (stats.getMean(),stats.getStandardDeviation());
               } else {
                   return stats.getMean(); // only one obs in bin
               }
           }
       }
    }
    throw new MathRuntimeException("no bin selected");
}
 
Example 2
Source File: UnivariateRealIntegratorImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double getResult() throws IllegalStateException {
    if (resultComputed) {
        return result;
    } else {
        throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE);
    }
}
 
Example 3
Source File: FastFourierTransformer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the real part of the k<sup>th</sup> n<sup>th</sup> root of unity
 * @param k index of the n<sup>th</sup> root of unity
 * @return real part of the k<sup>th</sup> n<sup>th</sup> root of unity
 * @throws IllegalStateException if no roots of unity have been computed yet
 * @throws IllegalArgumentException if k is out of range
 */
public synchronized double getOmegaReal(int k)
  throws IllegalStateException, IllegalArgumentException {

  if (omegaCount == 0) {
      throw MathRuntimeException.createIllegalStateException(LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET);
  }
  if ((k < 0) || (k >= omegaCount)) {
      throw MathRuntimeException.createIllegalArgumentException(
              LocalizedFormats.OUT_OF_RANGE_ROOT_OF_UNITY_INDEX, k, 0, omegaCount - 1);
  }

  return omegaReal[k];

}
 
Example 4
Source File: SummaryStatistics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Throws IllegalStateException if n > 0.
 */
private void checkEmpty() {
    if (n > 0) {
        throw MathRuntimeException.createIllegalStateException(
                "{0} values have been added before statistic is configured",
                n);
    }
}
 
Example 5
Source File: Kurtosis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void clear() {
    if (incMoment) {
        moment.clear();
    } else  {
        throw MathRuntimeException.createIllegalStateException(
                "statistics constructed from external moments cannot be cleared");
    }
}
 
Example 6
Source File: GeometricMean.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Throws IllegalStateException if n > 0.
 */
private void checkEmpty() {
    if (getN() > 0) {
        throw MathRuntimeException.createIllegalStateException(
                LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC,
                getN());
    }
}
 
Example 7
Source File: SummaryStatistics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Throws IllegalStateException if n > 0.
 */
private void checkEmpty() {
    if (n > 0) {
        throw MathRuntimeException.createIllegalStateException(
                "{0} values have been added before statistic is configured",
                n);
    }
}
 
Example 8
Source File: Array2DRowFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setSubMatrix(final T[][] subMatrix, final int row, final int column)
throws MatrixIndexException {
    if (data == null) {
        if (row > 0) {
            throw MathRuntimeException.createIllegalStateException(
                    "first {0} rows are not initialized yet",
                    row);
        }
        if (column > 0) {
            throw MathRuntimeException.createIllegalStateException(
                    "first {0} columns are not initialized yet",
                    column);
        }
        final int nRows = subMatrix.length;
        if (nRows == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
        }

        final int nCols = subMatrix[0].length;
        if (nCols == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
        }
        data = buildArray(getField(), subMatrix.length, nCols);
        for (int i = 0; i < data.length; ++i) {
            if (subMatrix[i].length != nCols) {
                throw MathRuntimeException.createIllegalArgumentException(
                        "some rows have length {0} while others have length {1}",
                        nCols, subMatrix[i].length);
            }
            System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
        }
    } else {
        super.setSubMatrix(subMatrix, row, column);
    }

}
 
Example 9
Source File: RealMatrixImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
throws MatrixIndexException {
    if (data == null) {
        if (row > 0) {
            throw MathRuntimeException.createIllegalStateException(
                    "first {0} rows are not initialized yet",
                    row);
        }
        if (column > 0) {
            throw MathRuntimeException.createIllegalStateException(
                    "first {0} columns are not initialized yet",
                    column);
        }
        final int nRows = subMatrix.length;
        if (nRows == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
        }

        final int nCols = subMatrix[0].length;
        if (nCols == 0) {
            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
        }
        data = new double[subMatrix.length][nCols];
        for (int i = 0; i < data.length; ++i) {
            if (subMatrix[i].length != nCols) {
                throw MathRuntimeException.createIllegalArgumentException(
                        "some rows have length {0} while others have length {1}",
                        nCols, subMatrix[i].length);
            }
            System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
        }
    } else {
        super.setSubMatrix(subMatrix, row, column);
    }

}
 
Example 10
Source File: UnivariateRealIntegratorImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Access the last computed integral.
 *
 * @return the last computed integral
 * @throws IllegalStateException if no integral has been computed
 */
public double getResult() throws IllegalStateException {
    if (resultComputed) {
        return result;
    } else {
        throw MathRuntimeException.createIllegalStateException("no result available");
    }
}
 
Example 11
Source File: MultivariateSummaryStatistics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Throws IllegalStateException if n > 0.
 */
private void checkEmpty() {
    if (n > 0) {
        throw MathRuntimeException.createIllegalStateException(
                "{0} values have been added before statistic is configured",
                n);
    }
}
 
Example 12
Source File: Kurtosis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void clear() {
    if (incMoment) {
        moment.clear();
    } else  {
        throw MathRuntimeException.createIllegalStateException(
                LocalizedFormats.CANNOT_CLEAR_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS);
    }
}
 
Example 13
Source File: FastFourierTransformer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if computation has been done for forward or reverse transform.
 * @return true if computation has been done for forward transform
 * @throws IllegalStateException if no roots of unity have been computed yet
 */
public synchronized boolean isForward() throws IllegalStateException {

  if (omegaCount == 0) {
    throw MathRuntimeException.createIllegalStateException(
            MISSING_ROOTS_OF_UNITY_MESSAGE);
  }
  return isForward;

}
 
Example 14
Source File: FastFourierTransformer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check if computation has been done for forward or reverse transform.
 * @return true if computation has been done for forward transform
 * @throws IllegalStateException if no roots of unity have been computed yet
 */
public synchronized boolean isForward() throws IllegalStateException {

  if (omegaCount == 0) {
    throw MathRuntimeException.createIllegalStateException(
            MISSING_ROOTS_OF_UNITY_MESSAGE);
  }
  return isForward;

}
 
Example 15
Source File: Kurtosis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void increment(final double d) {
    if (incMoment) {
        moment.increment(d);
    }  else  {
        throw MathRuntimeException.createIllegalStateException(
                LocalizedFormats.CANNOT_INCREMENT_STATISTIC_CONSTRUCTED_FROM_EXTERNAL_MOMENTS);
    }
}
 
Example 16
Source File: BigMatrixImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Replace the submatrix starting at <code>row, column</code> using data in
 * the input <code>subMatrix</code> array. Indexes are 0-based.
 * <p>
 * Example:<br>
 * Starting with <pre>
 * 1  2  3  4
 * 5  6  7  8
 * 9  0  1  2
 * </pre>
 * and <code>subMatrix = {{3, 4} {5,6}}</code>, invoking
 * <code>setSubMatrix(subMatrix,1,1))</code> will result in <pre>
 * 1  2  3  4
 * 5  3  4  8
 * 9  5  6  2
 * </pre></p>
 *
 * @param subMatrix  array containing the submatrix replacement data
 * @param row  row coordinate of the top, left element to be replaced
 * @param column  column coordinate of the top, left element to be replaced
 * @throws MatrixIndexException  if subMatrix does not fit into this
 *    matrix from element in (row, column)
 * @throws IllegalArgumentException if <code>subMatrix</code> is not rectangular
 *  (not all rows have the same length) or empty
 * @throws NullPointerException if <code>subMatrix</code> is null
 * @since 1.1
 */
public void setSubMatrix(BigDecimal[][] subMatrix, int row, int column)
throws MatrixIndexException {

    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
    }

    for (int r = 1; r < nRows; r++) {
        if (subMatrix[r].length != nCols) {
            throw MathRuntimeException.createIllegalArgumentException(
                  "some rows have length {0} while others have length {1}",
                  nCols, subMatrix[r].length);
        }
    }

    if (data == null) {
        if (row > 0) {
            throw MathRuntimeException.createIllegalStateException(
                    "first {0} rows are not initialized yet",
                    row);
        }
        if (column > 0) {
            throw MathRuntimeException.createIllegalStateException(
                    "first {0} columns are not initialized yet",
                    column);
        }
        data = new BigDecimal[nRows][nCols];
        System.arraycopy(subMatrix, 0, data, 0, subMatrix.length);
    } else {
        MatrixUtils.checkRowIndex(this, row);
        MatrixUtils.checkColumnIndex(this, column);
        MatrixUtils.checkRowIndex(this, nRows + row - 1);
        MatrixUtils.checkColumnIndex(this, nCols + column - 1);
    }
    for (int i = 0; i < nRows; i++) {
        System.arraycopy(subMatrix[i], 0, data[row + i], column, nCols);
    }

    lu = null;

}
 
Example 17
Source File: MultiStartDifferentiableMultivariateVectorialOptimizer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Get all the optima found during the last call to {@link
 * #optimize(DifferentiableMultivariateVectorialFunction,
 * double[], double[], double[]) optimize}.
 * <p>The optimizer stores all the optima found during a set of
 * restarts. The {@link #optimize(DifferentiableMultivariateVectorialFunction,
 * double[], double[], double[]) optimize} method returns the
 * best point only. This method returns all the points found at the
 * end of each starts, including the best one already returned by the {@link
 * #optimize(DifferentiableMultivariateVectorialFunction, double[],
 * double[], double[]) optimize} method.
 * </p>
 * <p>
 * The returned array as one element for each start as specified
 * in the constructor. It is ordered with the results from the
 * runs that did converge first, sorted from best to worst
 * objective value (i.e in ascending order if minimizing and in
 * descending order if maximizing), followed by and null elements
 * corresponding to the runs that did not converge. This means all
 * elements will be null if the {@link #optimize(DifferentiableMultivariateVectorialFunction,
 * double[], double[], double[]) optimize} method did throw a {@link
 * ConvergenceException ConvergenceException}). This also means that
 * if the first element is non null, it is the best point found across
 * all starts.</p>
 * @return array containing the optima
 * @exception IllegalStateException if {@link #optimize(DifferentiableMultivariateVectorialFunction,
 * double[], double[], double[]) optimize} has not been called
 */
public VectorialPointValuePair[] getOptima() throws IllegalStateException {
    if (optima == null) {
        throw MathRuntimeException.createIllegalStateException("no optimum computed yet");
    }
    return optima.clone();
}
 
Example 18
Source File: ValueServer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets a random value in DIGEST_MODE.
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>Before this method is called, <code>computeDistribution()</code>
 * must have completed successfully; otherwise an
 * <code>IllegalStateException</code> will be thrown</li></ul></p>
 *
 * @return next random value from the empirical distribution digest
 */
private double getNextDigest() {
    if ((empiricalDistribution == null) ||
        (empiricalDistribution.getBinStats().size() == 0)) {
        throw MathRuntimeException.createIllegalStateException(LocalizedFormats.DIGEST_NOT_INITIALIZED);
    }
    return empiricalDistribution.getNextValue();
}
 
Example 19
Source File: MultiStartMultivariateRealOptimizer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Get all the optima found during the last call to {@link
 * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}.
 * <p>The optimizer stores all the optima found during a set of
 * restarts. The {@link #optimize(MultivariateRealFunction, GoalType,
 * double[]) optimize} method returns the best point only. This
 * method returns all the points found at the end of each starts,
 * including the best one already returned by the {@link
 * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}
 * method.
 * </p>
 * <p>
 * The returned array as one element for each start as specified
 * in the constructor. It is ordered with the results from the
 * runs that did converge first, sorted from best to worst
 * objective value (i.e in ascending order if minimizing and in
 * descending order if maximizing), followed by and null elements
 * corresponding to the runs that did not converge. This means all
 * elements will be null if the {@link #optimize(MultivariateRealFunction,
 * GoalType, double[]) optimize} method did throw a {@link
 * org.apache.commons.math.ConvergenceException ConvergenceException}).
 * This also means that if the first element is non null, it is the best
 * point found across all starts.</p>
 * @return array containing the optima
 * @exception IllegalStateException if {@link #optimize(MultivariateRealFunction,
 * GoalType, double[]) optimize} has not been called
 */
public RealPointValuePair[] getOptima() throws IllegalStateException {
    if (optima == null) {
        throw MathRuntimeException.createIllegalStateException("no optimum computed yet");
    }
    return optima.clone();
}
 
Example 20
Source File: MultiStartUnivariateRealOptimizer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Get all the optima found during the last call to {@link
 * #optimize(UnivariateRealFunction, GoalType, double, double) optimize}.
 * <p>The optimizer stores all the optima found during a set of
 * restarts. The {@link #optimize(UnivariateRealFunction, GoalType,
 * double, double) optimize} method returns the best point only. This
 * method returns all the points found at the end of each starts,
 * including the best one already returned by the {@link
 * #optimize(UnivariateRealFunction, GoalType, double, double) optimize}
 * method.
 * </p>
 * <p>
 * The returned array as one element for each start as specified
 * in the constructor. It is ordered with the results from the
 * runs that did converge first, sorted from best to worst
 * objective value (i.e in ascending order if minimizing and in
 * descending order if maximizing), followed by Double.NaN elements
 * corresponding to the runs that did not converge. This means all
 * elements will be NaN if the {@link #optimize(UnivariateRealFunction,
 * GoalType, double, double) optimize} method did throw a {@link
 * ConvergenceException ConvergenceException}). This also means that
 * if the first element is not NaN, it is the best point found across
 * all starts.</p>
 * @return array containing the optima
 * @exception IllegalStateException if {@link #optimize(UnivariateRealFunction,
 * GoalType, double, double) optimize} has not been called
 * @see #getOptimaValues()
 */
public double[] getOptima() throws IllegalStateException {
    if (optima == null) {
        throw MathRuntimeException.createIllegalStateException("no optimum computed yet");
    }
    return optima.clone();
}