当前位置: 首页>>代码示例>>Java>>正文


Java LocalizedFormats类代码示例

本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats类的具体用法?Java LocalizedFormats怎么用?Java LocalizedFormats使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LocalizedFormats类属于org.apache.commons.math3.exception.util包,在下文中一共展示了LocalizedFormats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setWindowSize

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * WindowSize controls the number of values that contribute to the
 * reported statistics.  For example, if windowSize is set to 3 and the
 * values {1,2,3,4,5} have been added <strong> in that order</strong> then
 * the <i>available values</i> are {3,4,5} and all reported statistics will
 * be based on these values. If {@code windowSize} is decreased as a result
 * of this call and there are more than the new value of elements in the
 * current dataset, values from the front of the array are discarded to
 * reduce the dataset to {@code windowSize} elements.
 *
 * @param windowSize sets the size of the window.
 * @throws MathIllegalArgumentException if window size is less than 1 but
 * not equal to {@link #INFINITE_WINDOW}
 */
public void setWindowSize(int windowSize) throws MathIllegalArgumentException {
    if (windowSize < 1 && windowSize != INFINITE_WINDOW) {
        throw new MathIllegalArgumentException(
                LocalizedFormats.NOT_POSITIVE_WINDOW_SIZE, windowSize);
    }

    this.windowSize = windowSize;

    // We need to check to see if we need to discard elements
    // from the front of the array.  If the windowSize is less than
    // the current number of elements.
    if (windowSize != INFINITE_WINDOW && windowSize < eDA.getNumElements()) {
        eDA.discardFrontElements(eDA.getNumElements() - windowSize);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:30,代码来源:DescriptiveStatistics.java

示例2: discardExtremeElements

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Discards the <code>i</code> first or last elements of the array,
 * depending on the value of <code>front</code>.
 * For example, if the array contains the elements 1,2,3,4, invoking
 * <code>discardExtremeElements(2,false)</code> will cause the last two elements
 * to be discarded, leaving 1,2 in the array.
 * For example, if the array contains the elements 1,2,3,4, invoking
 * <code>discardExtremeElements(2,true)</code> will cause the first two elements
 * to be discarded, leaving 3,4 in the array.
 * Throws illegalArgumentException
 * if i exceeds numElements.
 *
 * @param i  the number of elements to discard from the front/end of the array
 * @param front true if elements are to be discarded from the front
 * of the array, false if elements are to be discarded from the end
 * of the array
 * @throws MathIllegalArgumentException if i is greater than numElements.
 * @since 2.0
 */
private synchronized void discardExtremeElements(int i,
                                                 boolean front)
    throws MathIllegalArgumentException {
    if (i > numElements) {
        throw new MathIllegalArgumentException(
                LocalizedFormats.TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY,
                i, numElements);
   } else if (i < 0) {
       throw new MathIllegalArgumentException(
               LocalizedFormats.CANNOT_DISCARD_NEGATIVE_NUMBER_OF_ELEMENTS,
               i);
    } else {
        // "Subtract" this number of discarded from numElements
        numElements -= i;
        if (front) {
            startIndex += i;
        }
    }
    if (shouldContract()) {
        contract();
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:42,代码来源:ResizableDoubleArray.java

示例3: mutate

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Mutate the given chromosome. Randomly changes one gene.
 *
 * @param original the original chromosome.
 * @return the mutated chromosome.
 * @throws MathIllegalArgumentException if <code>original</code> is not an instance of {@link BinaryChromosome}.
 */
public Chromosome mutate(Chromosome original) throws MathIllegalArgumentException {
    if (!(original instanceof BinaryChromosome)) {
        throw new MathIllegalArgumentException(LocalizedFormats.INVALID_BINARY_CHROMOSOME);
    }

    BinaryChromosome origChrom = (BinaryChromosome) original;
    List<Integer> newRepr = new ArrayList<Integer>(origChrom.getRepresentation());

    // randomly select a gene
    int geneIndex = GeneticAlgorithm.getRandomGenerator().nextInt(origChrom.getLength());
    // and change it
    newRepr.set(geneIndex, origChrom.getRepresentation().get(geneIndex) == 0 ? 1 : 0);

    Chromosome newChrom = origChrom.newFixedLengthChromosome(newRepr);
    return newChrom;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:24,代码来源:BinaryMutation.java

示例4: GeneticAlgorithm

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Create a new genetic algorithm.
 * @param crossoverPolicy The {@link CrossoverPolicy}
 * @param crossoverRate The crossover rate as a percentage (0-1 inclusive)
 * @param mutationPolicy The {@link MutationPolicy}
 * @param mutationRate The mutation rate as a percentage (0-1 inclusive)
 * @param selectionPolicy The {@link SelectionPolicy}
 * @throws OutOfRangeException if the crossover or mutation rate is outside the [0, 1] range
 */
public GeneticAlgorithm(final CrossoverPolicy crossoverPolicy,
                        final double crossoverRate,
                        final MutationPolicy mutationPolicy,
                        final double mutationRate,
                        final SelectionPolicy selectionPolicy) throws OutOfRangeException {

    if (crossoverRate < 0 || crossoverRate > 1) {
        throw new OutOfRangeException(LocalizedFormats.CROSSOVER_RATE,
                                      crossoverRate, 0, 1);
    }
    if (mutationRate < 0 || mutationRate > 1) {
        throw new OutOfRangeException(LocalizedFormats.MUTATION_RATE,
                                      mutationRate, 0, 1);
    }
    this.crossoverPolicy = crossoverPolicy;
    this.crossoverRate = crossoverRate;
    this.mutationPolicy = mutationPolicy;
    this.mutationRate = mutationRate;
    this.selectionPolicy = selectionPolicy;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:30,代码来源:GeneticAlgorithm.java

示例5: ParameterGuesser

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Constructs instance with the specified observed points.
 *
 * @param observations Observed points from which to guess the
 * parameters of the Gaussian.
 * @throws NullArgumentException if {@code observations} is
 * {@code null}.
 * @throws NumberIsTooSmallException if there are less than 3
 * observations.
 */
public ParameterGuesser(WeightedObservedPoint[] observations) {
    if (observations == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }
    if (observations.length < 3) {
        throw new NumberIsTooSmallException(observations.length, 3, true);
    }

    final WeightedObservedPoint[] sorted = sortObservations(observations);
    final double[] params = basicGuess(sorted);

    norm = params[0];
    mean = params[1];
    sigma = params[2];
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:GaussianFitter.java

示例6: pow

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Raise an int to a long power.
 *
 * @param k Number to raise.
 * @param e Exponent (must be positive or zero).
 * @return k<sup>e</sup>
 * @throws NotPositiveException if {@code e < 0}.
 */
public static int pow(final int k, long e) {
    if (e < 0) {
        throw new NotPositiveException(LocalizedFormats.EXPONENT, e);
    }

    int result = 1;
    int k2p    = k;
    while (e != 0) {
        if ((e & 0x1) != 0) {
            result *= k2p;
        }
        k2p *= k2p;
        e = e >> 1;
    }

    return result;
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:26,代码来源:ArithmeticUtils.java

示例7: inducedPermutation

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Generates a representation of a permutation corresponding to a
 * permutation which yields <code>permutedData</code> when applied to
 * <code>originalData</code>.
 *
 * This method can be viewed as an inverse to {@link #decode(List)}.
 *
 * @param <S> type of the data
 * @param originalData the original, unpermuted data
 * @param permutedData the data, somehow permuted
 * @return representation of a permutation corresponding to the permutation
 *   <code>originalData -> permutedData</code>
 * @throws DimensionMismatchException iff the length of <code>originalData</code>
 *   and <code>permutedData</code> lists are not equal
 * @throws MathIllegalArgumentException iff the <code>permutedData</code> and
 *   <code>originalData</code> lists contain different data
 */
public static <S> List<Double> inducedPermutation(final List<S> originalData,
                                                  final List<S> permutedData)
    throws DimensionMismatchException, MathIllegalArgumentException {

    if (originalData.size() != permutedData.size()) {
        throw new DimensionMismatchException(permutedData.size(), originalData.size());
    }
    int l = originalData.size();

    List<S> origDataCopy = new ArrayList<S> (originalData);

    Double[] res = new Double[l];
    for (int i=0; i<l; i++) {
        int index = origDataCopy.indexOf(permutedData.get(i));
        if (index == -1) {
            throw new MathIllegalArgumentException(LocalizedFormats.DIFFERENT_ORIG_AND_PERMUTED_DATA);
        }
        res[index] = (double) i / l;
        origDataCopy.set(index, null);
    }
    return Arrays.asList(res);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:40,代码来源:RandomKey.java

示例8: angle

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/** Compute the angular separation between two vectors.
 * <p>This method computes the angular separation between two
 * vectors using the dot product for well separated vectors and the
 * cross product for almost aligned vectors. This allows to have a
 * good accuracy in all cases, even for vectors very close to each
 * other.</p>
 * @param v1 first vector
 * @param v2 second vector
 * @return angular separation between v1 and v2
 * @exception MathArithmeticException if either vector has a null norm
 */
public static double angle(Vector2D v1, Vector2D v2) throws MathArithmeticException {

    double normProduct = v1.getNorm() * v2.getNorm();
    if (normProduct == 0) {
        throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
    }

    double dot = v1.dotProduct(v2);
    double threshold = normProduct * 0.9999;
    if ((dot < -threshold) || (dot > threshold)) {
        // the vectors are almost aligned, compute using the sine
        final double n = FastMath.abs(MathArrays.linearCombination(v1.x, v2.y, -v1.y, v2.x));
        if (dot >= 0) {
            return FastMath.asin(n / normProduct);
        }
        return FastMath.PI - FastMath.asin(n / normProduct);
    }

    // the vectors are sufficiently separated to use the cosine
    return FastMath.acos(dot / normProduct);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:34,代码来源:Vector2D.java

示例9: differentiate

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Returns the coefficients of the derivative of the polynomial with the given coefficients.
 *
 * @param coefficients Coefficients of the polynomial to differentiate.
 * @return the coefficients of the derivative or {@code null} if coefficients has length 1.
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
protected static double[] differentiate(double[] coefficients)
    throws NullArgumentException, NoDataException {
    MathUtils.checkNotNull(coefficients);
    int n = coefficients.length;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
    }
    if (n == 1) {
        return new double[]{0};
    }
    double[] result = new double[n - 1];
    for (int i = n - 1; i > 0; i--) {
        result[i - 1] = i * coefficients[i];
    }
    return result;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:25,代码来源:PolynomialFunction.java

示例10: floorDiv

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/** Finds q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0.
 * <p>
 * This methods returns the same value as integer division when
 * a and b are same signs, but returns a different value when
 * they are opposite (i.e. q is negative).
 * </p>
 * @param a dividend
 * @param b divisor
 * @return q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0
 * @exception MathArithmeticException if b == 0
 * @see #floorMod(long, long)
 * @since 3.4
 */
public static long floorDiv(final long a, final long b) throws MathArithmeticException {

    if (b == 0l) {
        throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
    }

    final long m = a % b;
    if ((a ^ b) >= 0l || m == 0l) {
        // a an b have same sign, or division is exact
        return a / b;
    } else {
        // a and b have opposite signs and division is not exact
        return (a / b) - 1l;
    }

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:30,代码来源:FastMath.java

示例11: checkIndices

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Checks that the indices of a subvector are valid.
 *
 * @param start the index of the first entry of the subvector
 * @param end the index of the last entry of the subvector (inclusive)
 * @throws OutOfRangeException if {@code start} of {@code end} are not valid
 * @throws NumberIsTooSmallException if {@code end < start}
 * @since 3.1
 */
protected void checkIndices(final int start, final int end)
    throws NumberIsTooSmallException, OutOfRangeException {
    final int dim = getDimension();
    if ((start < 0) || (start >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, start, 0,
                                      dim - 1);
    }
    if ((end < 0) || (end >= dim)) {
        throw new OutOfRangeException(LocalizedFormats.INDEX, end, 0,
                                      dim - 1);
    }
    if (end < start) {
        // TODO Use more specific error message
        throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
                                            end, start, false);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:RealVector.java

示例12: sample

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Generate a random sample from the distribution.
 * <p>
 * If the requested samples fit in the specified array, it is returned
 * therein. Otherwise, a new array is allocated with the runtime type of
 * the specified array and the size of this collection.
 *
 * @param sampleSize the number of random values to generate.
 * @param array the array to populate.
 * @return an array representing the random sample.
 * @throws NotStrictlyPositiveException if {@code sampleSize} is not positive.
 * @throws NullArgumentException if {@code array} is null
 */
public T[] sample(int sampleSize, final T[] array) throws NotStrictlyPositiveException {
    if (sampleSize <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
    }

    if (array == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }

    T[] out;
    if (array.length < sampleSize) {
        @SuppressWarnings("unchecked") // safe as both are of type T
        final T[] unchecked = (T[]) Array.newInstance(array.getClass().getComponentType(), sampleSize);
        out = unchecked;
    } else {
        out = array;
    }

    for (int i = 0; i < sampleSize; i++) {
        out[i] = sample();
    }

    return out;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:39,代码来源:EnumeratedDistribution.java

示例13: LogNormalDistribution

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Creates a log-normal distribution.
 *
 * @param rng Random number generator.
 * @param scale Scale parameter of this distribution.
 * @param shape Shape parameter of this distribution.
 * @param inverseCumAccuracy Inverse cumulative probability accuracy.
 * @throws NotStrictlyPositiveException if {@code shape <= 0}.
 * @since 3.1
 */
public LogNormalDistribution(RandomGenerator rng,
                             double scale,
                             double shape,
                             double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (shape <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
    }

    this.scale = scale;
    this.shape = shape;
    this.logShapePlusHalfLog2Pi = FastMath.log(shape) + 0.5 * FastMath.log(2 * FastMath.PI);
    this.solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:LogNormalDistribution.java

示例14: ParetoDistribution

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/**
 * Creates a Pareto distribution.
 *
 * @param rng Random number generator.
 * @param scale Scale parameter of this distribution.
 * @param shape Shape parameter of this distribution.
 * @param inverseCumAccuracy Inverse cumulative probability accuracy.
 * @throws NotStrictlyPositiveException if {@code scale <= 0} or {@code shape <= 0}.
 */
public ParetoDistribution(RandomGenerator rng,
                          double scale,
                          double shape,
                          double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (scale <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
    }

    if (shape <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
    }

    this.scale = scale;
    this.shape = shape;
    this.solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:29,代码来源:ParetoDistribution.java

示例15: solveUpperTriangularSystem

import org.apache.commons.math3.exception.util.LocalizedFormats; //导入依赖的package包/类
/** Solver a  system composed  of an Upper Triangular Matrix
 * {@link RealMatrix}.
 * <p>
 * This method is called to solve systems of equations which are
 * of the lower triangular form. The matrix {@link RealMatrix}
 * is assumed, though not checked, to be in upper triangular form.
 * The vector {@link RealVector} is overwritten with the solution.
 * The matrix is checked that it is square and its dimensions match
 * the length of the vector.
 * </p>
 * @param rm RealMatrix which is upper triangular
 * @param b  RealVector this is overwritten
 * @exception IllegalArgumentException if the matrix and vector are not conformable
 * @exception ArithmeticException there is a zero or near zero on the diagonal of rm
 */
public static void solveUpperTriangularSystem( RealMatrix rm, RealVector b){
    if ((rm == null) || (b == null) || ( rm.getRowDimension() != b.getDimension())) {
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE,
                (rm == null) ? 0 : rm.getRowDimension(),
                (b == null) ? 0 : b.getDimension());
    }
    if( rm.getColumnDimension() != rm.getRowDimension() ){
        throw new MathIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH_2x2,
                rm.getRowDimension(),rm.getRowDimension(),
                rm.getRowDimension(),rm.getColumnDimension());
    }
    int rows = rm.getRowDimension();
    for( int i = rows-1 ; i >-1 ; i-- ){
        double diag = rm.getEntry(i, i);
        if( FastMath.abs(diag) < Precision.SAFE_MIN ){
            throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
        }
        double bi = b.getEntry(i)/diag;
        b.setEntry(i,  bi );
        for( int j = i-1; j>-1; j-- ){
            b.setEntry(j, b.getEntry(j)-bi*rm.getEntry(j,i)  );
        }
    }
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:40,代码来源:MatrixUtils.java


注:本文中的org.apache.commons.math3.exception.util.LocalizedFormats类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。