/** * Throws IllegalStateException if n > 0. * @throws MathIllegalStateException if data has been added */ private void checkEmpty() throws MathIllegalStateException { if (n > 0) { throw new MathIllegalStateException( LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, n); } }
/** {@inheritDoc} */ public BSPTree<S> fixNode(BSPTree<S> node) { // the cut should not be null throw new MathIllegalStateException(LocalizedFormats.NULL_NOT_ALLOWED); } });
/** * Throws MathIllegalStateException if the statistic is not empty. * @throws MathIllegalStateException if n > 0. */ private void checkEmpty() throws MathIllegalStateException { if (n > 0) { throw new MathIllegalStateException( LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, n); } }
/** * Returns {@code true} if {@link #computeRoots(int)} was called with a * positive value of its argument {@code n}. If {@code true}, then * counter-clockwise ordering of the roots of unity should be used. * * @return {@code true} if the roots of unity are stored in * counter-clockwise order * @throws MathIllegalStateException if no roots of unity have been computed * yet */ public synchronized boolean isCounterClockWise() throws MathIllegalStateException { if (omegaCount == 0) { throw new MathIllegalStateException( LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET); } return isCounterClockWise; }
/** * Substitutes <code>value</code> for the most recently added value. * Returns the value that has been replaced. If the array is empty (i.e. * if {@link #numElements} is zero), an IllegalStateException is thrown. * * @param value New value to substitute for the most recently added value * @return the value that has been replaced in the array. * @throws MathIllegalStateException if the array is empty * @since 2.0 */ public synchronized double substituteMostRecentElement(double value) throws MathIllegalStateException { if (numElements < 1) { throw new MathIllegalStateException( LocalizedFormats.CANNOT_SUBSTITUTE_ELEMENT_FROM_EMPTY_ARRAY); } final int substIndex = startIndex + (numElements - 1); final double discarded = internalArray[substIndex]; internalArray[substIndex] = value; return discarded; }
/** * Removes the most recent value from the dataset. * * @throws MathIllegalStateException if there are no elements stored */ public void removeMostRecentValue() throws MathIllegalStateException { try { eDA.discardMostRecentElements(1); } catch (MathIllegalArgumentException ex) { throw new MathIllegalStateException(LocalizedFormats.NO_DATA); } }
/** * Generates a random value from this distribution. * <strong>Preconditions:</strong><ul> * <li>the distribution must be loaded before invoking this method</li></ul> * @return the random value. * @throws MathIllegalStateException if the distribution has not been loaded */ public double getNextValue() throws MathIllegalStateException { if (!loaded) { throw new MathIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED); } return sample(); }
/** * Returns the {@code nxk} membership matrix, where {@code n} is the number * of data points and {@code k} the number of clusters. * <p> * The element U<sub>i,j</sub> represents the membership value for data point {@code i} * to cluster {@code j}. * * @return the membership matrix * @throws MathIllegalStateException if {@link #cluster(Collection)} has not been called before */ public RealMatrix getMembershipMatrix() { if (membershipMatrix == null) { throw new MathIllegalStateException(); } return MatrixUtils.createRealMatrix(membershipMatrix); }
/** * Get the real part of the {@code k}-th {@code n}-th root of unity. * * @param k index of the {@code n}-th root of unity * @return real part of the {@code k}-th {@code n}-th root of unity * @throws MathIllegalStateException if no roots of unity have been * computed yet * @throws MathIllegalArgumentException if {@code k} is out of range */ public synchronized double getReal(int k) throws MathIllegalStateException, MathIllegalArgumentException { if (omegaCount == 0) { throw new MathIllegalStateException( LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET); } if ((k < 0) || (k >= omegaCount)) { throw new OutOfRangeException( LocalizedFormats.OUT_OF_RANGE_ROOT_OF_UNITY_INDEX, Integer.valueOf(k), Integer.valueOf(0), Integer.valueOf(omegaCount - 1)); } return omegaReal[k]; }
/** * Get the imaginary part of the {@code k}-th {@code n}-th root of unity. * * @param k index of the {@code n}-th root of unity * @return imaginary part of the {@code k}-th {@code n}-th root of unity * @throws MathIllegalStateException if no roots of unity have been * computed yet * @throws OutOfRangeException if {@code k} is out of range */ public synchronized double getImaginary(int k) throws MathIllegalStateException, OutOfRangeException { if (omegaCount == 0) { throw new MathIllegalStateException( LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET); } if ((k < 0) || (k >= omegaCount)) { throw new OutOfRangeException( LocalizedFormats.OUT_OF_RANGE_ROOT_OF_UNITY_INDEX, Integer.valueOf(k), Integer.valueOf(0), Integer.valueOf(omegaCount - 1)); } return isCounterClockWise ? omegaImaginaryCounterClockwise[k] : omegaImaginaryClockwise[k]; }
/** * Gets all the optima found during the last call to {@code optimize}. * The optimizer stores all the optima found during a set of * restarts. The {@code 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 {@code optimize} method. * <br/> * 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 {@code null} elements * corresponding to the runs that did not converge. This means all * elements will be {@code null} if the {@code optimize} method did throw * an exception. * This also means that if the first element is not {@code null}, it is * the best point found across all starts. * * @return an array containing the optima. * @throws MathIllegalStateException if {@link #optimize(OptimizationData[]) * optimize} has not been called. */ public UnivariatePointValuePair[] getOptima() { if (optima == null) { throw new MathIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET); } return optima.clone(); }
throw new MathIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET);
throw new MathIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET);
/** * Throws MathIllegalStateException if n > 0. * @throws MathIllegalStateException if data has been added to this statistic */ private void checkEmpty() throws MathIllegalStateException { if (getN() > 0) { throw new MathIllegalStateException( LocalizedFormats.VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC, getN()); } }
throw new MathIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET);
/** * 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 * @throws MathIllegalStateException if digest has not been initialized */ private double getNextDigest() throws MathIllegalStateException { if ((empiricalDistribution == null) || (empiricalDistribution.getBinStats().size() == 0)) { throw new MathIllegalStateException(LocalizedFormats.DIGEST_NOT_INITIALIZED); } return empiricalDistribution.getNextValue(); }
/** * Find the upper bound b ensuring bracketing of a root between a and b. * * @param f function whose root must be bracketed. * @param a lower bound of the interval. * @param h initial step to try. * @return b such that f(a) and f(b) have opposite signs. * @throws MathIllegalStateException if no bracket can be found. */ private double findUpperBound(final UnivariateFunction f, final double a, final double h) { final double yA = f.value(a); double yB = yA; for (double step = h; step < Double.MAX_VALUE; step *= FastMath.max(2, yA / yB)) { final double b = a + step; yB = f.value(b); if (yA * yB <= 0) { return b; } } throw new MathIllegalStateException(LocalizedFormats.UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH); }
/** * Get the value of the objective function. * @return the objective function evaluation as double value * @throws MathIllegalStateException if {@link #cluster(Collection)} has not been called before */ public double getObjectiveFunctionValue() { if (points == null || clusters == null) { throw new MathIllegalStateException(); } int i = 0; double objFunction = 0.0; for (final T point : points) { int j = 0; for (final CentroidCluster<T> cluster : clusters) { final double dist = distance(point, cluster.getCenter()); objFunction += (dist * dist) * FastMath.pow(membershipMatrix[i][j], fuzziness); j++; } i++; } return objFunction; }
/** * Builds a finder to retrieve the locations of neurons that * belong to the given {@code map}. * * @param map Map. * * @throws MathIllegalStateException if the network contains non-unique * identifiers. This indicates an inconsistent state due to a bug in * the construction code of the underlying * {@link org.apache.commons.math3.ml.neuralnet.Network network}. */ public LocationFinder(NeuronSquareMesh2D map) { final int nR = map.getNumberOfRows(); final int nC = map.getNumberOfColumns(); for (int r = 0; r < nR; r++) { for (int c = 0; c < nC; c++) { final Long id = map.getNeuron(r, c).getIdentifier(); if (locations.get(id) != null) { throw new MathIllegalStateException(); } locations.put(id, new Location(r, c)); } } }
/** * Returns the next generated value, generated according * to the mode value (see MODE constants). * * @return generated value * @throws IOException in REPLAY_MODE if a file I/O error occurs * @throws MathIllegalStateException if mode is not recognized * @throws MathIllegalArgumentException if the underlying random generator thwrows one */ public double getNext() throws IOException, MathIllegalStateException, MathIllegalArgumentException { switch (mode) { case DIGEST_MODE: return getNextDigest(); case REPLAY_MODE: return getNextReplay(); case UNIFORM_MODE: return getNextUniform(); case EXPONENTIAL_MODE: return getNextExponential(); case GAUSSIAN_MODE: return getNextGaussian(); case CONSTANT_MODE: return mu; default: throw new MathIllegalStateException( LocalizedFormats.UNKNOWN_MODE, mode, "DIGEST_MODE", DIGEST_MODE, "REPLAY_MODE", REPLAY_MODE, "UNIFORM_MODE", UNIFORM_MODE, "EXPONENTIAL_MODE", EXPONENTIAL_MODE, "GAUSSIAN_MODE", GAUSSIAN_MODE, "CONSTANT_MODE", CONSTANT_MODE); } }