http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/distribution/ZipfDistribution.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/distribution/ZipfDistribution.java b/src/main/java/org/apache/commons/math3/distribution/ZipfDistribution.java deleted file mode 100644 index 18cb2f4..0000000 --- a/src/main/java/org/apache/commons/math3/distribution/ZipfDistribution.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math3.distribution; - -import org.apache.commons.math3.exception.NotStrictlyPositiveException; -import org.apache.commons.math3.exception.util.LocalizedFormats; -import org.apache.commons.math3.random.RandomGenerator; -import org.apache.commons.math3.random.Well19937c; -import org.apache.commons.math3.util.FastMath; - -/** - * Implementation of the Zipf distribution. - * - * @see <a href="http://mathworld.wolfram.com/ZipfDistribution.html">Zipf distribution (MathWorld)</a> - */ -public class ZipfDistribution extends AbstractIntegerDistribution { - /** Serializable version identifier. */ - private static final long serialVersionUID = -140627372283420404L; - /** Number of elements. */ - private final int numberOfElements; - /** Exponent parameter of the distribution. */ - private final double exponent; - /** Cached numerical mean */ - private double numericalMean = Double.NaN; - /** Whether or not the numerical mean has been calculated */ - private boolean numericalMeanIsCalculated = false; - /** Cached numerical variance */ - private double numericalVariance = Double.NaN; - /** Whether or not the numerical variance has been calculated */ - private boolean numericalVarianceIsCalculated = false; - - /** - * Create a new Zipf distribution with the given number of elements and - * exponent. - * <p> - * <b>Note:</b> this constructor will implicitly create an instance of - * {@link Well19937c} as random generator to be used for sampling only (see - * {@link #sample()} and {@link #sample(int)}). In case no sampling is - * needed for the created distribution, it is advised to pass {@code null} - * as random generator via the appropriate constructors to avoid the - * additional initialisation overhead. - * - * @param numberOfElements Number of elements. - * @param exponent Exponent. - * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0} - * or {@code exponent <= 0}. - */ - public ZipfDistribution(final int numberOfElements, final double exponent) { - this(new Well19937c(), numberOfElements, exponent); - } - - /** - * Creates a Zipf distribution. - * - * @param rng Random number generator. - * @param numberOfElements Number of elements. - * @param exponent Exponent. - * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0} - * or {@code exponent <= 0}. - * @since 3.1 - */ - public ZipfDistribution(RandomGenerator rng, - int numberOfElements, - double exponent) - throws NotStrictlyPositiveException { - super(rng); - - if (numberOfElements <= 0) { - throw new NotStrictlyPositiveException(LocalizedFormats.DIMENSION, - numberOfElements); - } - if (exponent <= 0) { - throw new NotStrictlyPositiveException(LocalizedFormats.EXPONENT, - exponent); - } - - this.numberOfElements = numberOfElements; - this.exponent = exponent; - } - - /** - * Get the number of elements (e.g. corpus size) for the distribution. - * - * @return the number of elements - */ - public int getNumberOfElements() { - return numberOfElements; - } - - /** - * Get the exponent characterizing the distribution. - * - * @return the exponent - */ - public double getExponent() { - return exponent; - } - - /** {@inheritDoc} */ - public double probability(final int x) { - if (x <= 0 || x > numberOfElements) { - return 0.0; - } - - return (1.0 / FastMath.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent); - } - - /** {@inheritDoc} */ - @Override - public double logProbability(int x) { - if (x <= 0 || x > numberOfElements) { - return Double.NEGATIVE_INFINITY; - } - - return -FastMath.log(x) * exponent - FastMath.log(generalizedHarmonic(numberOfElements, exponent)); - } - - /** {@inheritDoc} */ - public double cumulativeProbability(final int x) { - if (x <= 0) { - return 0.0; - } else if (x >= numberOfElements) { - return 1.0; - } - - return generalizedHarmonic(x, exponent) / generalizedHarmonic(numberOfElements, exponent); - } - - /** - * {@inheritDoc} - * - * For number of elements {@code N} and exponent {@code s}, the mean is - * {@code Hs1 / Hs}, where - * <ul> - * <li>{@code Hs1 = generalizedHarmonic(N, s - 1)},</li> - * <li>{@code Hs = generalizedHarmonic(N, s)}.</li> - * </ul> - */ - public double getNumericalMean() { - if (!numericalMeanIsCalculated) { - numericalMean = calculateNumericalMean(); - numericalMeanIsCalculated = true; - } - return numericalMean; - } - - /** - * Used by {@link #getNumericalMean()}. - * - * @return the mean of this distribution - */ - protected double calculateNumericalMean() { - final int N = getNumberOfElements(); - final double s = getExponent(); - - final double Hs1 = generalizedHarmonic(N, s - 1); - final double Hs = generalizedHarmonic(N, s); - - return Hs1 / Hs; - } - - /** - * {@inheritDoc} - * - * For number of elements {@code N} and exponent {@code s}, the mean is - * {@code (Hs2 / Hs) - (Hs1^2 / Hs^2)}, where - * <ul> - * <li>{@code Hs2 = generalizedHarmonic(N, s - 2)},</li> - * <li>{@code Hs1 = generalizedHarmonic(N, s - 1)},</li> - * <li>{@code Hs = generalizedHarmonic(N, s)}.</li> - * </ul> - */ - public double getNumericalVariance() { - if (!numericalVarianceIsCalculated) { - numericalVariance = calculateNumericalVariance(); - numericalVarianceIsCalculated = true; - } - return numericalVariance; - } - - /** - * Used by {@link #getNumericalVariance()}. - * - * @return the variance of this distribution - */ - protected double calculateNumericalVariance() { - final int N = getNumberOfElements(); - final double s = getExponent(); - - final double Hs2 = generalizedHarmonic(N, s - 2); - final double Hs1 = generalizedHarmonic(N, s - 1); - final double Hs = generalizedHarmonic(N, s); - - return (Hs2 / Hs) - ((Hs1 * Hs1) / (Hs * Hs)); - } - - /** - * Calculates the Nth generalized harmonic number. See - * <a href="http://mathworld.wolfram.com/HarmonicSeries.html">Harmonic - * Series</a>. - * - * @param n Term in the series to calculate (must be larger than 1) - * @param m Exponent (special case {@code m = 1} is the harmonic series). - * @return the n<sup>th</sup> generalized harmonic number. - */ - private double generalizedHarmonic(final int n, final double m) { - double value = 0; - for (int k = n; k > 0; --k) { - value += 1.0 / FastMath.pow(k, m); - } - return value; - } - - /** - * {@inheritDoc} - * - * The lower bound of the support is always 1 no matter the parameters. - * - * @return lower bound of the support (always 1) - */ - public int getSupportLowerBound() { - return 1; - } - - /** - * {@inheritDoc} - * - * The upper bound of the support is the number of elements. - * - * @return upper bound of the support - */ - public int getSupportUpperBound() { - return getNumberOfElements(); - } - - /** - * {@inheritDoc} - * - * The support of this distribution is connected. - * - * @return {@code true} - */ - public boolean isSupportConnected() { - return true; - } -} -
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java b/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java deleted file mode 100644 index 0b4ac0d..0000000 --- a/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java +++ /dev/null @@ -1,454 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.distribution.fitting; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.math3.distribution.MultivariateNormalDistribution; -import org.apache.commons.math3.distribution.MixtureMultivariateNormalDistribution; -import org.apache.commons.math3.exception.ConvergenceException; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.exception.NotStrictlyPositiveException; -import org.apache.commons.math3.exception.NumberIsTooSmallException; -import org.apache.commons.math3.exception.NumberIsTooLargeException; -import org.apache.commons.math3.exception.util.LocalizedFormats; -import org.apache.commons.math3.linear.Array2DRowRealMatrix; -import org.apache.commons.math3.linear.RealMatrix; -import org.apache.commons.math3.linear.SingularMatrixException; -import org.apache.commons.math3.stat.correlation.Covariance; -import org.apache.commons.math3.util.FastMath; -import org.apache.commons.math3.util.MathArrays; -import org.apache.commons.math3.util.Pair; - -/** - * Expectation-Maximization</a> algorithm for fitting the parameters of - * multivariate normal mixture model distributions. - * - * This implementation is pure original code based on <a - * href="https://www.ee.washington.edu/techsite/papers/documents/UWEETR-2010-0002.pdf"> - * EM Demystified: An Expectation-Maximization Tutorial</a> by Yihua Chen and Maya R. Gupta, - * Department of Electrical Engineering, University of Washington, Seattle, WA 98195. - * It was verified using external tools like <a - * href="http://cran.r-project.org/web/packages/mixtools/index.html">CRAN Mixtools</a> - * (see the JUnit test cases) but it is <strong>not</strong> based on Mixtools code at all. - * The discussion of the origin of this class can be seen in the comments of the <a - * href="https://issues.apache.org/jira/browse/MATH-817">MATH-817</a> JIRA issue. - * @since 3.2 - */ -public class MultivariateNormalMixtureExpectationMaximization { - /** - * Default maximum number of iterations allowed per fitting process. - */ - private static final int DEFAULT_MAX_ITERATIONS = 1000; - /** - * Default convergence threshold for fitting. - */ - private static final double DEFAULT_THRESHOLD = 1E-5; - /** - * The data to fit. - */ - private final double[][] data; - /** - * The model fit against the data. - */ - private MixtureMultivariateNormalDistribution fittedModel; - /** - * The log likelihood of the data given the fitted model. - */ - private double logLikelihood = 0d; - - /** - * Creates an object to fit a multivariate normal mixture model to data. - * - * @param data Data to use in fitting procedure - * @throws NotStrictlyPositiveException if data has no rows - * @throws DimensionMismatchException if rows of data have different numbers - * of columns - * @throws NumberIsTooSmallException if the number of columns in the data is - * less than 2 - */ - public MultivariateNormalMixtureExpectationMaximization(double[][] data) - throws NotStrictlyPositiveException, - DimensionMismatchException, - NumberIsTooSmallException { - if (data.length < 1) { - throw new NotStrictlyPositiveException(data.length); - } - - this.data = new double[data.length][data[0].length]; - - for (int i = 0; i < data.length; i++) { - if (data[i].length != data[0].length) { - // Jagged arrays not allowed - throw new DimensionMismatchException(data[i].length, - data[0].length); - } - if (data[i].length < 2) { - throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_TOO_SMALL, - data[i].length, 2, true); - } - this.data[i] = MathArrays.copyOf(data[i], data[i].length); - } - } - - /** - * Fit a mixture model to the data supplied to the constructor. - * - * The quality of the fit depends on the concavity of the data provided to - * the constructor and the initial mixture provided to this function. If the - * data has many local optima, multiple runs of the fitting function with - * different initial mixtures may be required to find the optimal solution. - * If a SingularMatrixException is encountered, it is possible that another - * initialization would work. - * - * @param initialMixture Model containing initial values of weights and - * multivariate normals - * @param maxIterations Maximum iterations allowed for fit - * @param threshold Convergence threshold computed as difference in - * logLikelihoods between successive iterations - * @throws SingularMatrixException if any component's covariance matrix is - * singular during fitting - * @throws NotStrictlyPositiveException if numComponents is less than one - * or threshold is less than Double.MIN_VALUE - * @throws DimensionMismatchException if initialMixture mean vector and data - * number of columns are not equal - */ - public void fit(final MixtureMultivariateNormalDistribution initialMixture, - final int maxIterations, - final double threshold) - throws SingularMatrixException, - NotStrictlyPositiveException, - DimensionMismatchException { - if (maxIterations < 1) { - throw new NotStrictlyPositiveException(maxIterations); - } - - if (threshold < Double.MIN_VALUE) { - throw new NotStrictlyPositiveException(threshold); - } - - final int n = data.length; - - // Number of data columns. Jagged data already rejected in constructor, - // so we can assume the lengths of each row are equal. - final int numCols = data[0].length; - final int k = initialMixture.getComponents().size(); - - final int numMeanColumns - = initialMixture.getComponents().get(0).getSecond().getMeans().length; - - if (numMeanColumns != numCols) { - throw new DimensionMismatchException(numMeanColumns, numCols); - } - - int numIterations = 0; - double previousLogLikelihood = 0d; - - logLikelihood = Double.NEGATIVE_INFINITY; - - // Initialize model to fit to initial mixture. - fittedModel = new MixtureMultivariateNormalDistribution(initialMixture.getComponents()); - - while (numIterations++ <= maxIterations && - FastMath.abs(previousLogLikelihood - logLikelihood) > threshold) { - previousLogLikelihood = logLikelihood; - double sumLogLikelihood = 0d; - - // Mixture components - final List<Pair<Double, MultivariateNormalDistribution>> components - = fittedModel.getComponents(); - - // Weight and distribution of each component - final double[] weights = new double[k]; - - final MultivariateNormalDistribution[] mvns = new MultivariateNormalDistribution[k]; - - for (int j = 0; j < k; j++) { - weights[j] = components.get(j).getFirst(); - mvns[j] = components.get(j).getSecond(); - } - - // E-step: compute the data dependent parameters of the expectation - // function. - // The percentage of row's total density between a row and a - // component - final double[][] gamma = new double[n][k]; - - // Sum of gamma for each component - final double[] gammaSums = new double[k]; - - // Sum of gamma times its row for each each component - final double[][] gammaDataProdSums = new double[k][numCols]; - - for (int i = 0; i < n; i++) { - final double rowDensity = fittedModel.density(data[i]); - sumLogLikelihood += FastMath.log(rowDensity); - - for (int j = 0; j < k; j++) { - gamma[i][j] = weights[j] * mvns[j].density(data[i]) / rowDensity; - gammaSums[j] += gamma[i][j]; - - for (int col = 0; col < numCols; col++) { - gammaDataProdSums[j][col] += gamma[i][j] * data[i][col]; - } - } - } - - logLikelihood = sumLogLikelihood / n; - - // M-step: compute the new parameters based on the expectation - // function. - final double[] newWeights = new double[k]; - final double[][] newMeans = new double[k][numCols]; - - for (int j = 0; j < k; j++) { - newWeights[j] = gammaSums[j] / n; - for (int col = 0; col < numCols; col++) { - newMeans[j][col] = gammaDataProdSums[j][col] / gammaSums[j]; - } - } - - // Compute new covariance matrices - final RealMatrix[] newCovMats = new RealMatrix[k]; - for (int j = 0; j < k; j++) { - newCovMats[j] = new Array2DRowRealMatrix(numCols, numCols); - } - for (int i = 0; i < n; i++) { - for (int j = 0; j < k; j++) { - final RealMatrix vec - = new Array2DRowRealMatrix(MathArrays.ebeSubtract(data[i], newMeans[j])); - final RealMatrix dataCov - = vec.multiply(vec.transpose()).scalarMultiply(gamma[i][j]); - newCovMats[j] = newCovMats[j].add(dataCov); - } - } - - // Converting to arrays for use by fitted model - final double[][][] newCovMatArrays = new double[k][numCols][numCols]; - for (int j = 0; j < k; j++) { - newCovMats[j] = newCovMats[j].scalarMultiply(1d / gammaSums[j]); - newCovMatArrays[j] = newCovMats[j].getData(); - } - - // Update current model - fittedModel = new MixtureMultivariateNormalDistribution(newWeights, - newMeans, - newCovMatArrays); - } - - if (FastMath.abs(previousLogLikelihood - logLikelihood) > threshold) { - // Did not converge before the maximum number of iterations - throw new ConvergenceException(); - } - } - - /** - * Fit a mixture model to the data supplied to the constructor. - * - * The quality of the fit depends on the concavity of the data provided to - * the constructor and the initial mixture provided to this function. If the - * data has many local optima, multiple runs of the fitting function with - * different initial mixtures may be required to find the optimal solution. - * If a SingularMatrixException is encountered, it is possible that another - * initialization would work. - * - * @param initialMixture Model containing initial values of weights and - * multivariate normals - * @throws SingularMatrixException if any component's covariance matrix is - * singular during fitting - * @throws NotStrictlyPositiveException if numComponents is less than one or - * threshold is less than Double.MIN_VALUE - */ - public void fit(MixtureMultivariateNormalDistribution initialMixture) - throws SingularMatrixException, - NotStrictlyPositiveException { - fit(initialMixture, DEFAULT_MAX_ITERATIONS, DEFAULT_THRESHOLD); - } - - /** - * Helper method to create a multivariate normal mixture model which can be - * used to initialize {@link #fit(MixtureMultivariateNormalDistribution)}. - * - * This method uses the data supplied to the constructor to try to determine - * a good mixture model at which to start the fit, but it is not guaranteed - * to supply a model which will find the optimal solution or even converge. - * - * @param data Data to estimate distribution - * @param numComponents Number of components for estimated mixture - * @return Multivariate normal mixture model estimated from the data - * @throws NumberIsTooLargeException if {@code numComponents} is greater - * than the number of data rows. - * @throws NumberIsTooSmallException if {@code numComponents < 2}. - * @throws NotStrictlyPositiveException if data has less than 2 rows - * @throws DimensionMismatchException if rows of data have different numbers - * of columns - */ - public static MixtureMultivariateNormalDistribution estimate(final double[][] data, - final int numComponents) - throws NotStrictlyPositiveException, - DimensionMismatchException { - if (data.length < 2) { - throw new NotStrictlyPositiveException(data.length); - } - if (numComponents < 2) { - throw new NumberIsTooSmallException(numComponents, 2, true); - } - if (numComponents > data.length) { - throw new NumberIsTooLargeException(numComponents, data.length, true); - } - - final int numRows = data.length; - final int numCols = data[0].length; - - // sort the data - final DataRow[] sortedData = new DataRow[numRows]; - for (int i = 0; i < numRows; i++) { - sortedData[i] = new DataRow(data[i]); - } - Arrays.sort(sortedData); - - // uniform weight for each bin - final double weight = 1d / numComponents; - - // components of mixture model to be created - final List<Pair<Double, MultivariateNormalDistribution>> components = - new ArrayList<Pair<Double, MultivariateNormalDistribution>>(numComponents); - - // create a component based on data in each bin - for (int binIndex = 0; binIndex < numComponents; binIndex++) { - // minimum index (inclusive) from sorted data for this bin - final int minIndex = (binIndex * numRows) / numComponents; - - // maximum index (exclusive) from sorted data for this bin - final int maxIndex = ((binIndex + 1) * numRows) / numComponents; - - // number of data records that will be in this bin - final int numBinRows = maxIndex - minIndex; - - // data for this bin - final double[][] binData = new double[numBinRows][numCols]; - - // mean of each column for the data in the this bin - final double[] columnMeans = new double[numCols]; - - // populate bin and create component - for (int i = minIndex, iBin = 0; i < maxIndex; i++, iBin++) { - for (int j = 0; j < numCols; j++) { - final double val = sortedData[i].getRow()[j]; - columnMeans[j] += val; - binData[iBin][j] = val; - } - } - - MathArrays.scaleInPlace(1d / numBinRows, columnMeans); - - // covariance matrix for this bin - final double[][] covMat - = new Covariance(binData).getCovarianceMatrix().getData(); - final MultivariateNormalDistribution mvn - = new MultivariateNormalDistribution(columnMeans, covMat); - - components.add(new Pair<Double, MultivariateNormalDistribution>(weight, mvn)); - } - - return new MixtureMultivariateNormalDistribution(components); - } - - /** - * Gets the log likelihood of the data under the fitted model. - * - * @return Log likelihood of data or zero of no data has been fit - */ - public double getLogLikelihood() { - return logLikelihood; - } - - /** - * Gets the fitted model. - * - * @return fitted model or {@code null} if no fit has been performed yet. - */ - public MixtureMultivariateNormalDistribution getFittedModel() { - return new MixtureMultivariateNormalDistribution(fittedModel.getComponents()); - } - - /** - * Class used for sorting user-supplied data. - */ - private static class DataRow implements Comparable<DataRow> { - /** One data row. */ - private final double[] row; - /** Mean of the data row. */ - private Double mean; - - /** - * Create a data row. - * @param data Data to use for the row - */ - DataRow(final double[] data) { - // Store reference. - row = data; - // Compute mean. - mean = 0d; - for (int i = 0; i < data.length; i++) { - mean += data[i]; - } - mean /= data.length; - } - - /** - * Compare two data rows. - * @param other The other row - * @return int for sorting - */ - public int compareTo(final DataRow other) { - return mean.compareTo(other.mean); - } - - /** {@inheritDoc} */ - @Override - public boolean equals(Object other) { - - if (this == other) { - return true; - } - - if (other instanceof DataRow) { - return MathArrays.equals(row, ((DataRow) other).row); - } - - return false; - - } - - /** {@inheritDoc} */ - @Override - public int hashCode() { - return Arrays.hashCode(row); - } - /** - * Get a data row. - * @return data row array - */ - public double[] getRow() { - return row; - } - } -} - http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/distribution/fitting/package-info.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/distribution/fitting/package-info.java b/src/main/java/org/apache/commons/math3/distribution/fitting/package-info.java deleted file mode 100644 index aa95c6d..0000000 --- a/src/main/java/org/apache/commons/math3/distribution/fitting/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Fitting of parameters against distributions. - */ -package org.apache.commons.math3.distribution.fitting; http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/distribution/package-info.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/distribution/package-info.java b/src/main/java/org/apache/commons/math3/distribution/package-info.java deleted file mode 100644 index 4e11196..0000000 --- a/src/main/java/org/apache/commons/math3/distribution/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Implementations of common discrete and continuous distributions. - */ -package org.apache.commons.math3.distribution; http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/ConvergenceException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/ConvergenceException.java b/src/main/java/org/apache/commons/math3/exception/ConvergenceException.java deleted file mode 100644 index 3aecfc2..0000000 --- a/src/main/java/org/apache/commons/math3/exception/ConvergenceException.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Error thrown when a numerical computation can not be performed because the - * numerical result failed to converge to a finite value. - * - * @since 2.2 - */ -public class ConvergenceException extends MathIllegalStateException { - /** Serializable version Id. */ - private static final long serialVersionUID = 4330003017885151975L; - - /** - * Construct the exception. - */ - public ConvergenceException() { - this(LocalizedFormats.CONVERGENCE_FAILED); - } - - /** - * Construct the exception with a specific context and arguments. - * - * @param pattern Message pattern providing the specific context of - * the error. - * @param args Arguments. - */ - public ConvergenceException(Localizable pattern, - Object ... args) { - getContext().addMessage(pattern, args); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/DimensionMismatchException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/DimensionMismatchException.java b/src/main/java/org/apache/commons/math3/exception/DimensionMismatchException.java deleted file mode 100644 index 2bf84c8..0000000 --- a/src/main/java/org/apache/commons/math3/exception/DimensionMismatchException.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.LocalizedFormats; -import org.apache.commons.math3.exception.util.Localizable; - -/** - * Exception to be thrown when two dimensions differ. - * - * @since 2.2 - */ -public class DimensionMismatchException extends MathIllegalNumberException { - /** Serializable version Id. */ - private static final long serialVersionUID = -8415396756375798143L; - /** Correct dimension. */ - private final int dimension; - - /** - * Construct an exception from the mismatched dimensions. - * - * @param specific Specific context information pattern. - * @param wrong Wrong dimension. - * @param expected Expected dimension. - */ - public DimensionMismatchException(Localizable specific, - int wrong, - int expected) { - super(specific, Integer.valueOf(wrong), Integer.valueOf(expected)); - dimension = expected; - } - - /** - * Construct an exception from the mismatched dimensions. - * - * @param wrong Wrong dimension. - * @param expected Expected dimension. - */ - public DimensionMismatchException(int wrong, - int expected) { - this(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, wrong, expected); - } - - /** - * @return the expected dimension. - */ - public int getDimension() { - return dimension; - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/InsufficientDataException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/InsufficientDataException.java b/src/main/java/org/apache/commons/math3/exception/InsufficientDataException.java deleted file mode 100644 index ec61d4e..0000000 --- a/src/main/java/org/apache/commons/math3/exception/InsufficientDataException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when there is insufficient data to perform a computation. - * - * @since 3.3 - */ -public class InsufficientDataException - extends MathIllegalArgumentException { - - /** Serializable version Id. */ - private static final long serialVersionUID = -2629324471511903359L; - - /** - * Construct the exception. - */ - public InsufficientDataException() { - this(LocalizedFormats.INSUFFICIENT_DATA); - } - - /** - * Construct the exception with a specific context. - * - * @param pattern Message pattern providing the specific context of the error. - * @param arguments Values for replacing the placeholders in {@code pattern}. - */ - public InsufficientDataException(Localizable pattern, Object... arguments) { - super(pattern, arguments); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathArithmeticException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathArithmeticException.java b/src/main/java/org/apache/commons/math3/exception/MathArithmeticException.java deleted file mode 100644 index c3826e4..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathArithmeticException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; -import org.apache.commons.math3.exception.util.ExceptionContext; -import org.apache.commons.math3.exception.util.ExceptionContextProvider; - -/** - * Base class for arithmetic exceptions. - * It is used for all the exceptions that have the semantics of the standard - * {@link ArithmeticException}, but must also provide a localized - * message. - * - * @since 3.0 - */ -public class MathArithmeticException extends ArithmeticException - implements ExceptionContextProvider { - /** Serializable version Id. */ - private static final long serialVersionUID = -6024911025449780478L; - /** Context. */ - private final ExceptionContext context; - - /** - * Default constructor. - */ - public MathArithmeticException() { - context = new ExceptionContext(this); - context.addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION); - } - - /** - * Constructor with a specific message. - * - * @param pattern Message pattern providing the specific context of - * the error. - * @param args Arguments. - */ - public MathArithmeticException(Localizable pattern, - Object ... args) { - context = new ExceptionContext(this); - context.addMessage(pattern, args); - } - - /** {@inheritDoc} */ - public ExceptionContext getContext() { - return context; - } - - /** {@inheritDoc} */ - @Override - public String getMessage() { - return context.getMessage(); - } - - /** {@inheritDoc} */ - @Override - public String getLocalizedMessage() { - return context.getLocalizedMessage(); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathIllegalArgumentException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathIllegalArgumentException.java b/src/main/java/org/apache/commons/math3/exception/MathIllegalArgumentException.java deleted file mode 100644 index 89012f0..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathIllegalArgumentException.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.ExceptionContext; -import org.apache.commons.math3.exception.util.ExceptionContextProvider; - -/** - * Base class for all preconditions violation exceptions. - * In most cases, this class should not be instantiated directly: it should - * serve as a base class to create all the exceptions that have the semantics - * of the standard {@link IllegalArgumentException}. - * - * @since 2.2 - */ -public class MathIllegalArgumentException extends IllegalArgumentException - implements ExceptionContextProvider { - /** Serializable version Id. */ - private static final long serialVersionUID = -6024911025449780478L; - /** Context. */ - private final ExceptionContext context; - - /** - * @param pattern Message pattern explaining the cause of the error. - * @param args Arguments. - */ - public MathIllegalArgumentException(Localizable pattern, - Object ... args) { - context = new ExceptionContext(this); - context.addMessage(pattern, args); - } - - /** {@inheritDoc} */ - public ExceptionContext getContext() { - return context; - } - - /** {@inheritDoc} */ - @Override - public String getMessage() { - return context.getMessage(); - } - - /** {@inheritDoc} */ - @Override - public String getLocalizedMessage() { - return context.getLocalizedMessage(); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathIllegalNumberException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathIllegalNumberException.java b/src/main/java/org/apache/commons/math3/exception/MathIllegalNumberException.java deleted file mode 100644 index 8edb2cb..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathIllegalNumberException.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; - -/** - * Base class for exceptions raised by a wrong number. - * This class is not intended to be instantiated directly: it should serve - * as a base class to create all the exceptions that are raised because some - * precondition is violated by a number argument. - * - * @since 2.2 - */ -public class MathIllegalNumberException extends MathIllegalArgumentException { - - /** Helper to avoid boxing warnings. @since 3.3 */ - protected static final Integer INTEGER_ZERO = Integer.valueOf(0); - - /** Serializable version Id. */ - private static final long serialVersionUID = -7447085893598031110L; - - /** Requested. */ - private final Number argument; - - /** - * Construct an exception. - * - * @param pattern Localizable pattern. - * @param wrong Wrong number. - * @param arguments Arguments. - */ - protected MathIllegalNumberException(Localizable pattern, - Number wrong, - Object ... arguments) { - super(pattern, wrong, arguments); - argument = wrong; - } - - /** - * @return the requested value. - */ - public Number getArgument() { - return argument; - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathIllegalStateException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathIllegalStateException.java b/src/main/java/org/apache/commons/math3/exception/MathIllegalStateException.java deleted file mode 100644 index f516536..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathIllegalStateException.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; -import org.apache.commons.math3.exception.util.ExceptionContext; -import org.apache.commons.math3.exception.util.ExceptionContextProvider; - -/** - * Base class for all exceptions that signal that the process - * throwing the exception is in a state that does not comply with - * the set of states that it is designed to be in. - * - * @since 2.2 - */ -public class MathIllegalStateException extends IllegalStateException - implements ExceptionContextProvider { - /** Serializable version Id. */ - private static final long serialVersionUID = -6024911025449780478L; - /** Context. */ - private final ExceptionContext context; - - /** - * Simple constructor. - * - * @param pattern Message pattern explaining the cause of the error. - * @param args Arguments. - */ - public MathIllegalStateException(Localizable pattern, - Object ... args) { - context = new ExceptionContext(this); - context.addMessage(pattern, args); - } - - /** - * Simple constructor. - * - * @param cause Root cause. - * @param pattern Message pattern explaining the cause of the error. - * @param args Arguments. - */ - public MathIllegalStateException(Throwable cause, - Localizable pattern, - Object ... args) { - super(cause); - context = new ExceptionContext(this); - context.addMessage(pattern, args); - } - - /** - * Default constructor. - */ - public MathIllegalStateException() { - this(LocalizedFormats.ILLEGAL_STATE); - } - - /** {@inheritDoc} */ - public ExceptionContext getContext() { - return context; - } - - /** {@inheritDoc} */ - @Override - public String getMessage() { - return context.getMessage(); - } - - /** {@inheritDoc} */ - @Override - public String getLocalizedMessage() { - return context.getLocalizedMessage(); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathInternalError.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathInternalError.java b/src/main/java/org/apache/commons/math3/exception/MathInternalError.java deleted file mode 100644 index 5ca66c9..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathInternalError.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception triggered when something that shouldn't happen does happen. - * - * @since 2.2 - */ -public class MathInternalError extends MathIllegalStateException { - /** Serializable version Id. */ - private static final long serialVersionUID = -6276776513966934846L; - /** URL for reporting problems. */ - private static final String REPORT_URL = "https://issues.apache.org/jira/browse/MATH"; - - /** - * Simple constructor. - */ - public MathInternalError() { - getContext().addMessage(LocalizedFormats.INTERNAL_ERROR, REPORT_URL); - } - - /** - * Simple constructor. - * @param cause root cause - */ - public MathInternalError(final Throwable cause) { - super(cause, LocalizedFormats.INTERNAL_ERROR, REPORT_URL); - } - - /** - * Constructor accepting a localized message. - * - * @param pattern Message pattern explaining the cause of the error. - * @param args Arguments. - */ - public MathInternalError(Localizable pattern, Object ... args) { - super(pattern, args); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathParseException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathParseException.java b/src/main/java/org/apache/commons/math3/exception/MathParseException.java deleted file mode 100644 index 0c84767..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathParseException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.ExceptionContextProvider; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Class to signal parse failures. - * - * @since 2.2 - */ -public class MathParseException extends MathIllegalStateException - implements ExceptionContextProvider { - /** Serializable version Id. */ - private static final long serialVersionUID = -6024911025449780478L; - - /** - * @param wrong Bad string representation of the object. - * @param position Index, in the {@code wrong} string, that caused the - * parsing to fail. - * @param type Class of the object supposedly represented by the - * {@code wrong} string. - */ - public MathParseException(String wrong, - int position, - Class<?> type) { - getContext().addMessage(LocalizedFormats.CANNOT_PARSE_AS_TYPE, - wrong, Integer.valueOf(position), type.getName()); - } - - /** - * @param wrong Bad string representation of the object. - * @param position Index, in the {@code wrong} string, that caused the - * parsing to fail. - */ - public MathParseException(String wrong, - int position) { - getContext().addMessage(LocalizedFormats.CANNOT_PARSE, - wrong, Integer.valueOf(position)); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathRuntimeException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathRuntimeException.java b/src/main/java/org/apache/commons/math3/exception/MathRuntimeException.java deleted file mode 100644 index 9f04704..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathRuntimeException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.ExceptionContext; -import org.apache.commons.math3.exception.util.ExceptionContextProvider; - -/** - * As of release 4.0, all exceptions thrown by the Commons Math code (except - * {@link NullArgumentException}) inherit from this class. - * In most cases, this class should not be instantiated directly: it should - * serve as a base class for implementing exception classes that describe a - * specific "problem". - * - * @since 3.1 - */ -public class MathRuntimeException extends RuntimeException - implements ExceptionContextProvider { - /** Serializable version Id. */ - private static final long serialVersionUID = 20120926L; - /** Context. */ - private final ExceptionContext context; - - /** - * @param pattern Message pattern explaining the cause of the error. - * @param args Arguments. - */ - public MathRuntimeException(Localizable pattern, - Object ... args) { - context = new ExceptionContext(this); - context.addMessage(pattern, args); - } - - /** {@inheritDoc} */ - public ExceptionContext getContext() { - return context; - } - - /** {@inheritDoc} */ - @Override - public String getMessage() { - return context.getMessage(); - } - - /** {@inheritDoc} */ - @Override - public String getLocalizedMessage() { - return context.getLocalizedMessage(); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MathUnsupportedOperationException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MathUnsupportedOperationException.java b/src/main/java/org/apache/commons/math3/exception/MathUnsupportedOperationException.java deleted file mode 100644 index 4a829f0..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MathUnsupportedOperationException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; -import org.apache.commons.math3.exception.util.ExceptionContext; -import org.apache.commons.math3.exception.util.ExceptionContextProvider; - -/** - * Base class for all unsupported features. - * It is used for all the exceptions that have the semantics of the standard - * {@link UnsupportedOperationException}, but must also provide a localized - * message. - * - * @since 2.2 - */ -public class MathUnsupportedOperationException extends UnsupportedOperationException - implements ExceptionContextProvider { - /** Serializable version Id. */ - private static final long serialVersionUID = -6024911025449780478L; - /** Context. */ - private final ExceptionContext context; - - /** - * Default constructor. - */ - public MathUnsupportedOperationException() { - this(LocalizedFormats.UNSUPPORTED_OPERATION); - } - /** - * @param pattern Message pattern providing the specific context of - * the error. - * @param args Arguments. - */ - public MathUnsupportedOperationException(Localizable pattern, - Object ... args) { - context = new ExceptionContext(this); - context.addMessage(pattern, args); - } - - /** {@inheritDoc} */ - public ExceptionContext getContext() { - return context; - } - - /** {@inheritDoc} */ - @Override - public String getMessage() { - return context.getMessage(); - } - - /** {@inheritDoc} */ - @Override - public String getLocalizedMessage() { - return context.getLocalizedMessage(); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MaxCountExceededException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MaxCountExceededException.java b/src/main/java/org/apache/commons/math3/exception/MaxCountExceededException.java deleted file mode 100644 index e846ce9..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MaxCountExceededException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when some counter maximum value is exceeded. - * - * @since 3.0 - */ -public class MaxCountExceededException extends MathIllegalStateException { - /** Serializable version Id. */ - private static final long serialVersionUID = 4330003017885151975L; - /** - * Maximum number of evaluations. - */ - private final Number max; - - /** - * Construct the exception. - * - * @param max Maximum. - */ - public MaxCountExceededException(Number max) { - this(LocalizedFormats.MAX_COUNT_EXCEEDED, max); - } - /** - * Construct the exception with a specific context. - * - * @param specific Specific context pattern. - * @param max Maximum. - * @param args Additional arguments. - */ - public MaxCountExceededException(Localizable specific, - Number max, - Object ... args) { - getContext().addMessage(specific, max, args); - this.max = max; - } - - /** - * @return the maximum number of evaluations. - */ - public Number getMax() { - return max; - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/MultiDimensionMismatchException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/MultiDimensionMismatchException.java b/src/main/java/org/apache/commons/math3/exception/MultiDimensionMismatchException.java deleted file mode 100644 index 16b1fc9..0000000 --- a/src/main/java/org/apache/commons/math3/exception/MultiDimensionMismatchException.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when two sets of dimensions differ. - * - * @since 3.0 - */ -public class MultiDimensionMismatchException extends MathIllegalArgumentException { - /** Serializable version Id. */ - private static final long serialVersionUID = -8415396756375798143L; - - /** Wrong dimensions. */ - private final Integer[] wrong; - /** Correct dimensions. */ - private final Integer[] expected; - - /** - * Construct an exception from the mismatched dimensions. - * - * @param wrong Wrong dimensions. - * @param expected Expected dimensions. - */ - public MultiDimensionMismatchException(Integer[] wrong, - Integer[] expected) { - this(LocalizedFormats.DIMENSIONS_MISMATCH, wrong, expected); - } - - /** - * Construct an exception from the mismatched dimensions. - * - * @param specific Message pattern providing the specific context of - * the error. - * @param wrong Wrong dimensions. - * @param expected Expected dimensions. - */ - public MultiDimensionMismatchException(Localizable specific, - Integer[] wrong, - Integer[] expected) { - super(specific, wrong, expected); - this.wrong = wrong.clone(); - this.expected = expected.clone(); - } - - /** - * @return an array containing the wrong dimensions. - */ - public Integer[] getWrongDimensions() { - return wrong.clone(); - } - /** - * @return an array containing the expected dimensions. - */ - public Integer[] getExpectedDimensions() { - return expected.clone(); - } - - /** - * @param index Dimension index. - * @return the wrong dimension stored at {@code index}. - */ - public int getWrongDimension(int index) { - return wrong[index].intValue(); - } - /** - * @param index Dimension index. - * @return the expected dimension stored at {@code index}. - */ - public int getExpectedDimension(int index) { - return expected[index].intValue(); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/NoBracketingException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/NoBracketingException.java b/src/main/java/org/apache/commons/math3/exception/NoBracketingException.java deleted file mode 100644 index 50083e1..0000000 --- a/src/main/java/org/apache/commons/math3/exception/NoBracketingException.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when function values have the same sign at both - * ends of an interval. - * - * @since 3.0 - */ -public class NoBracketingException extends MathIllegalArgumentException { - /** Serializable version Id. */ - private static final long serialVersionUID = -3629324471511904459L; - /** Lower end of the interval. */ - private final double lo; - /** Higher end of the interval. */ - private final double hi; - /** Value at lower end of the interval. */ - private final double fLo; - /** Value at higher end of the interval. */ - private final double fHi; - - /** - * Construct the exception. - * - * @param lo Lower end of the interval. - * @param hi Higher end of the interval. - * @param fLo Value at lower end of the interval. - * @param fHi Value at higher end of the interval. - */ - public NoBracketingException(double lo, double hi, - double fLo, double fHi) { - this(LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, lo, hi, fLo, fHi); - } - - /** - * Construct the exception with a specific context. - * - * @param specific Contextual information on what caused the exception. - * @param lo Lower end of the interval. - * @param hi Higher end of the interval. - * @param fLo Value at lower end of the interval. - * @param fHi Value at higher end of the interval. - * @param args Additional arguments. - */ - public NoBracketingException(Localizable specific, - double lo, double hi, - double fLo, double fHi, - Object ... args) { - super(specific, Double.valueOf(lo), Double.valueOf(hi), Double.valueOf(fLo), Double.valueOf(fHi), args); - this.lo = lo; - this.hi = hi; - this.fLo = fLo; - this.fHi = fHi; - } - - /** - * Get the lower end of the interval. - * - * @return the lower end. - */ - public double getLo() { - return lo; - } - /** - * Get the higher end of the interval. - * - * @return the higher end. - */ - public double getHi() { - return hi; - } - /** - * Get the value at the lower end of the interval. - * - * @return the value at the lower end. - */ - public double getFLo() { - return fLo; - } - /** - * Get the value at the higher end of the interval. - * - * @return the value at the higher end. - */ - public double getFHi() { - return fHi; - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/NoDataException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/NoDataException.java b/src/main/java/org/apache/commons/math3/exception/NoDataException.java deleted file mode 100644 index 8a72c4a..0000000 --- a/src/main/java/org/apache/commons/math3/exception/NoDataException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when the required data is missing. - * - * @since 2.2 - */ -public class NoDataException extends MathIllegalArgumentException { - - /** Serializable version Id. */ - private static final long serialVersionUID = -3629324471511904459L; - - /** - * Construct the exception. - */ - public NoDataException() { - this(LocalizedFormats.NO_DATA); - } - /** - * Construct the exception with a specific context. - * - * @param specific Contextual information on what caused the exception. - */ - public NoDataException(Localizable specific) { - super(specific); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/NonMonotonicSequenceException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/NonMonotonicSequenceException.java b/src/main/java/org/apache/commons/math3/exception/NonMonotonicSequenceException.java deleted file mode 100644 index ab479ab..0000000 --- a/src/main/java/org/apache/commons/math3/exception/NonMonotonicSequenceException.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.util.MathArrays; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when the a sequence of values is not monotonically - * increasing or decreasing. - * - * @since 2.2 (name changed to "NonMonotonicSequenceException" in 3.0) - */ -public class NonMonotonicSequenceException extends MathIllegalNumberException { - /** Serializable version Id. */ - private static final long serialVersionUID = 3596849179428944575L; - /** - * Direction (positive for increasing, negative for decreasing). - */ - private final MathArrays.OrderDirection direction; - /** - * Whether the sequence must be strictly increasing or decreasing. - */ - private final boolean strict; - /** - * Index of the wrong value. - */ - private final int index; - /** - * Previous value. - */ - private final Number previous; - - /** - * Construct the exception. - * This constructor uses default values assuming that the sequence should - * have been strictly increasing. - * - * @param wrong Value that did not match the requirements. - * @param previous Previous value in the sequence. - * @param index Index of the value that did not match the requirements. - */ - public NonMonotonicSequenceException(Number wrong, - Number previous, - int index) { - this(wrong, previous, index, MathArrays.OrderDirection.INCREASING, true); - } - - /** - * Construct the exception. - * - * @param wrong Value that did not match the requirements. - * @param previous Previous value in the sequence. - * @param index Index of the value that did not match the requirements. - * @param direction Strictly positive for a sequence required to be - * increasing, negative (or zero) for a decreasing sequence. - * @param strict Whether the sequence must be strictly increasing or - * decreasing. - */ - public NonMonotonicSequenceException(Number wrong, - Number previous, - int index, - MathArrays.OrderDirection direction, - boolean strict) { - super(direction == MathArrays.OrderDirection.INCREASING ? - (strict ? - LocalizedFormats.NOT_STRICTLY_INCREASING_SEQUENCE : - LocalizedFormats.NOT_INCREASING_SEQUENCE) : - (strict ? - LocalizedFormats.NOT_STRICTLY_DECREASING_SEQUENCE : - LocalizedFormats.NOT_DECREASING_SEQUENCE), - wrong, previous, Integer.valueOf(index), Integer.valueOf(index - 1)); - - this.direction = direction; - this.strict = strict; - this.index = index; - this.previous = previous; - } - - /** - * @return the order direction. - **/ - public MathArrays.OrderDirection getDirection() { - return direction; - } - /** - * @return {@code true} is the sequence should be strictly monotonic. - **/ - public boolean getStrict() { - return strict; - } - /** - * Get the index of the wrong value. - * - * @return the current index. - */ - public int getIndex() { - return index; - } - /** - * @return the previous value. - */ - public Number getPrevious() { - return previous; - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/NotANumberException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/NotANumberException.java b/src/main/java/org/apache/commons/math3/exception/NotANumberException.java deleted file mode 100644 index f50d1e4..0000000 --- a/src/main/java/org/apache/commons/math3/exception/NotANumberException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when a number is not a number. - * - * @since 3.1 - */ -public class NotANumberException extends MathIllegalNumberException { - /** Serializable version Id. */ - private static final long serialVersionUID = 20120906L; - - /** - * Construct the exception. - */ - public NotANumberException() { - super(LocalizedFormats.NAN_NOT_ALLOWED, Double.valueOf(Double.NaN)); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/NotFiniteNumberException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/NotFiniteNumberException.java b/src/main/java/org/apache/commons/math3/exception/NotFiniteNumberException.java deleted file mode 100644 index d4dcece..0000000 --- a/src/main/java/org/apache/commons/math3/exception/NotFiniteNumberException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; -import org.apache.commons.math3.exception.util.LocalizedFormats; - -/** - * Exception to be thrown when a number is not finite. - * - * @since 3.0 - */ -public class NotFiniteNumberException extends MathIllegalNumberException { - /** Serializable version Id. */ - private static final long serialVersionUID = -6100997100383932834L; - - /** - * Construct the exception. - * - * @param wrong Value that is infinite or NaN. - * @param args Optional arguments. - */ - public NotFiniteNumberException(Number wrong, - Object ... args) { - this(LocalizedFormats.NOT_FINITE_NUMBER, wrong, args); - } - - /** - * Construct the exception with a specific context. - * - * @param specific Specific context pattern. - * @param wrong Value that is infinite or NaN. - * @param args Optional arguments. - */ - public NotFiniteNumberException(Localizable specific, - Number wrong, - Object ... args) { - super(specific, wrong, args); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/exception/NotPositiveException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/exception/NotPositiveException.java b/src/main/java/org/apache/commons/math3/exception/NotPositiveException.java deleted file mode 100644 index 936c996..0000000 --- a/src/main/java/org/apache/commons/math3/exception/NotPositiveException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.exception; - -import org.apache.commons.math3.exception.util.Localizable; - -/** - * Exception to be thrown when the argument is negative. - * - * @since 2.2 - */ -public class NotPositiveException extends NumberIsTooSmallException { - /** Serializable version Id. */ - private static final long serialVersionUID = -2250556892093726375L; - - /** - * Construct the exception. - * - * @param value Argument. - */ - public NotPositiveException(Number value) { - super(value, INTEGER_ZERO, true); - } - /** - * Construct the exception with a specific context. - * - * @param specific Specific context where the error occurred. - * @param value Argument. - */ - public NotPositiveException(Localizable specific, - Number value) { - super(specific, value, INTEGER_ZERO, true); - } -}