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


Java MathIllegalArgumentException类代码示例

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


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

示例1: crossover

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
@Override
public ChromosomePair crossover(Chromosome first, Chromosome second) throws MathIllegalArgumentException {

	XMPChromosome firstParent = (XMPChromosome) first;
	int x1 = firstParent.getXmp().getX();
	int y1 = firstParent.getXmp().getY();
	double firstChildRatio = Math.random();
			
	XMPChromosome secondParent = (XMPChromosome) second;
	int x2 = secondParent.getXmp().getX();
	int y2 = secondParent.getXmp().getY();
	double secondChildRatio = Math.random();
	
	// All XMP have the same level
	int xmpLevel = firstParent.getXmp().getLevel();


	XMPChromosome firstChild = new XMPChromosome(scene, new XMP(xmpLevel, (int)Math.round(x1+(x2-x1)*firstChildRatio), (int)Math.round(y1+(y2-y1)*firstChildRatio)));
	XMPChromosome secondChild = new XMPChromosome(scene, new XMP(xmpLevel, (int)Math.round(x1+(x2-x1)*secondChildRatio), (int)Math.round(y1+(y2-y1)*secondChildRatio)));
	
	
	return new ChromosomePair(firstChild, secondChild);
}
 
开发者ID:gDanix,项目名称:Genetic-Ingress-Attack-Optimizer,代码行数:24,代码来源:SMOTEXMPCrossover.java

示例2: mutate

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
@Override
public Chromosome mutate(Chromosome original) throws MathIllegalArgumentException {
	double jumpRatio = Math.random()/2;
	double jumpAngle = Math.random()*Math.PI*2;
	
	XMPChromosome originalXMPChromosome = (XMPChromosome) original;
	
	int xmpLevel = originalXMPChromosome.getXmp().getLevel();

	int oldX = originalXMPChromosome.getXmp().getX();
	int oldY = originalXMPChromosome.getXmp().getY();

	int newX = (int) Math.round(oldX+512*jumpRatio*Math.cos(jumpAngle));
	if(newX > 511) newX = 511;
	if(newX < 0) newX = 0;
	
	int newY = Math.min((int) Math.round(oldY+512*jumpRatio*Math.sin(jumpAngle)), 511);
	if(newY > 511) newY = 511;
	if(newY < 0) newY = 0;
	
	return new XMPChromosome(scene, new XMP(xmpLevel, newX, newY));
}
 
开发者ID:gDanix,项目名称:Genetic-Ingress-Attack-Optimizer,代码行数:23,代码来源:JumpXMPMutation.java

示例3: solveUpperTriangularSystem

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的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

示例4: ResizableDoubleArray

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * Creates an instance with the specified properties.
 * <br/>
 * Throws MathIllegalArgumentException if the following conditions are
 * not met:
 * <ul>
 *  <li>{@code initialCapacity > 0}</li>
 *  <li>{@code expansionFactor > 1}</li>
 *  <li>{@code contractionCriterion >= expansionFactor}</li>
 * </ul>
 *
 * @param initialCapacity Initial size of the internal storage array.
 * @param expansionFactor The array will be expanded based on this
 * parameter.
 * @param contractionCriterion Contraction criteria.
 * @param expansionMode Expansion mode.
 * @param data Initial contents of the array.
 * @throws MathIllegalArgumentException if the parameters are not valid.
 */
public ResizableDoubleArray(int initialCapacity,
                            double expansionFactor,
                            double contractionCriterion,
                            ExpansionMode expansionMode,
                            double ... data)
    throws MathIllegalArgumentException {
    if (initialCapacity <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.INITIAL_CAPACITY_NOT_POSITIVE,
                                               initialCapacity);
    }
    checkContractExpand(contractionCriterion, expansionFactor);

    this.expansionFactor = expansionFactor;
    this.contractionCriterion = contractionCriterion;
    this.expansionMode = expansionMode;
    internalArray = new double[initialCapacity];
    numElements = 0;
    startIndex = 0;

    if (data != null && data.length > 0) {
        addElements(data);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:43,代码来源:ResizableDoubleArray.java

示例5: mutate

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @throws MathIllegalArgumentException if <code>original</code> is not a {@link RandomKey} instance
 */
public Chromosome mutate(final Chromosome original) throws MathIllegalArgumentException {
    if (!(original instanceof RandomKey<?>)) {
        throw new MathIllegalArgumentException(LocalizedFormats.RANDOMKEY_MUTATION_WRONG_CLASS,
                                               original.getClass().getSimpleName());
    }

    RandomKey<?> originalRk = (RandomKey<?>) original;
    List<Double> repr = originalRk.getRepresentation();
    int rInd = GeneticAlgorithm.getRandomGenerator().nextInt(repr.size());

    List<Double> newRepr = new ArrayList<Double> (repr);
    newRepr.set(rInd, GeneticAlgorithm.getRandomGenerator().nextDouble());

    return originalRk.newFixedLengthChromosome(newRepr);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:21,代码来源:RandomKeyMutation.java

示例6: transform

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @throws MathIllegalArgumentException if the length of the data array is
 * not a power of two plus one
 */
public double[] transform(final double[] f, final TransformType type)
  throws MathIllegalArgumentException {
    if (type == TransformType.FORWARD) {
        if (normalization == DctNormalization.ORTHOGONAL_DCT_I) {
            final double s = FastMath.sqrt(2.0 / (f.length - 1));
            return TransformUtils.scaleArray(fct(f), s);
        }
        return fct(f);
    }
    final double s2 = 2.0 / (f.length - 1);
    final double s1;
    if (normalization == DctNormalization.ORTHOGONAL_DCT_I) {
        s1 = FastMath.sqrt(s2);
    } else {
        s1 = s2;
    }
    return TransformUtils.scaleArray(fct(f), s1);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:25,代码来源:FastCosineTransformer.java

示例7: transform

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * @param o  the object that gets transformed.
 * @return a double primitive representation of the Object o.
 * @throws NullArgumentException if Object <code>o</code> is {@code null}.
 * @throws MathIllegalArgumentException if Object <code>o</code>
 * cannot successfully be transformed
 * @see <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html">Commons Collections Transformer</a>
 */
public double transform(Object o)
    throws NullArgumentException, MathIllegalArgumentException {

    if (o == null) {
        throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION);
    }

    if (o instanceof Number) {
        return ((Number)o).doubleValue();
    }

    try {
        return Double.parseDouble(o.toString());
    } catch (NumberFormatException e) {
        throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE,
                                               o.toString());
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:DefaultTransformer.java

示例8: setData

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * Set the data array.  The input array is copied, not referenced.
 *
 * @param values data array to store
 * @param begin the index of the first element to include
 * @param length the number of elements to include
 * @throws MathIllegalArgumentException if values is null or the indices
 * are not valid
 * @see #evaluate()
 */
public void setData(final double[] values, final int begin, final int length)
throws MathIllegalArgumentException {
    if (values == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }

    if (begin < 0) {
        throw new NotPositiveException(LocalizedFormats.START_POSITION, begin);
    }

    if (length < 0) {
        throw new NotPositiveException(LocalizedFormats.LENGTH, length);
    }

    if (begin + length > values.length) {
        throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END,
                                            begin + length, values.length, true);
    }
    storedData = new double[length];
    System.arraycopy(values, begin, storedData, 0, length);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:AbstractUnivariateStatistic.java

示例9: format

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * Formats an object and appends the result to a StringBuffer. <code>obj</code> must be either a
 * {@link Fraction} object or a {@link Number} object.  Any other type of
 * object will result in an {@link IllegalArgumentException} being thrown.
 *
 * @param obj the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
 * @throws FractionConversionException if the number cannot be converted to a fraction
 * @throws MathIllegalArgumentException if <code>obj</code> is not a valid type.
 */
@Override
public StringBuffer format(final Object obj,
                           final StringBuffer toAppendTo, final FieldPosition pos)
    throws FractionConversionException, MathIllegalArgumentException {
    StringBuffer ret = null;

    if (obj instanceof Fraction) {
        ret = format((Fraction) obj, toAppendTo, pos);
    } else if (obj instanceof Number) {
        ret = format(new Fraction(((Number) obj).doubleValue()), toAppendTo, pos);
    } else {
        throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION);
    }

    return ret;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:FractionFormat.java

示例10: setNumElements

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * This function allows you to control the number of elements contained
 * in this array, and can be used to "throw out" the last n values in an
 * array. This function will also expand the internal array as needed.
 *
 * @param i a new number of elements
 * @throws MathIllegalArgumentException if <code>i</code> is negative.
 */
public synchronized void setNumElements(int i)
    throws MathIllegalArgumentException {
    // If index is negative thrown an error.
    if (i < 0) {
        throw new MathIllegalArgumentException(
                LocalizedFormats.INDEX_NOT_POSITIVE,
                i);
    }

    // Test the new num elements, check to see if the array needs to be
    // expanded to accommodate this new number of elements.
    final int newSize = startIndex + i;
    if (newSize > internalArray.length) {
        expandTo(newSize);
    }

    // Set the new number of elements to new value.
    numElements = i;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:ResizableDoubleArray.java

示例11: setup

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * Prepare for computation.
 * Subclasses must call this method if they override any of the
 * {@code solve} methods.
 *
 * @param maxEval Maximum number of evaluations.
 * @param f the integrand function
 * @param lower the min bound for the interval
 * @param upper the upper bound for the interval
 * @throws NullArgumentException if {@code f} is {@code null}.
 * @throws MathIllegalArgumentException if {@code min >= max}.
 */
protected void setup(final int maxEval,
                     final UnivariateFunction f,
                     final double lower, final double upper)
    throws NullArgumentException, MathIllegalArgumentException {

    // Checks.
    MathUtils.checkNotNull(f);
    UnivariateSolverUtils.verifyInterval(lower, upper);

    // Reset.
    min = lower;
    max = upper;
    function = f;
    evaluations = evaluations.withMaximalCount(maxEval).withStart(0);
    count       = count.withStart(0);

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

示例12: getReal

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * Get the real part of the {@code k}-th {@code n}-th root of unity.
 *
 * @param k index of the {@code n}-th root of unity
 * @return real part of the {@code k}-th {@code n}-th root of unity
 * @throws MathIllegalStateException if no roots of unity have been
 * computed yet
 * @throws MathIllegalArgumentException if {@code k} is out of range
 */
public synchronized double getReal(int k)
        throws MathIllegalStateException, MathIllegalArgumentException {

    if (omegaCount == 0) {
        throw new MathIllegalStateException(
                LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET);
    }
    if ((k < 0) || (k >= omegaCount)) {
        throw new OutOfRangeException(
                LocalizedFormats.OUT_OF_RANGE_ROOT_OF_UNITY_INDEX,
                Integer.valueOf(k),
                Integer.valueOf(0),
                Integer.valueOf(omegaCount - 1));
    }

    return omegaReal[k];
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:RootsOfUnity.java

示例13: setNumElements

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * This function allows you to control the number of elements contained
 * in this array, and can be used to "throw out" the last n values in an
 * array. This function will also expand the internal array as needed.
 *
 * @param i a new number of elements
 * @throws IllegalArgumentException if <code>i</code> is negative.
 */
public synchronized void setNumElements(int i) {

    // If index is negative thrown an error
    if (i < 0) {
        throw new MathIllegalArgumentException(
                LocalizedFormats.INDEX_NOT_POSITIVE,
                i);
    }

    // Test the new num elements, check to see if the array needs to be
    // expanded to accommodate this new number of elements
    if ((startIndex + i) > internalArray.length) {
        expandTo(startIndex + i);
    }

    // Set the new number of elements to new value
    numElements = i;
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:27,代码来源:ResizableDoubleArray.java

示例14: checkContractExpand

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * Checks the expansion factor and the contraction criteria and throws an
 * IllegalArgumentException if the contractionCriteria is less than the
 * expansionCriteria
 *
 * @param expansion factor to be checked
 * @param contraction criteria to be checked
 * @throws IllegalArgumentException if the contractionCriteria is less than
 *         the expansionCriteria.
 */
protected void checkContractExpand(float contraction, float expansion) {

    if (contraction < expansion) {
        throw new MathIllegalArgumentException(
                LocalizedFormats.CONTRACTION_CRITERIA_SMALLER_THAN_EXPANSION_FACTOR,
                contraction, expansion);
    }

    if (contraction <= 1.0) {
        throw new MathIllegalArgumentException(
                LocalizedFormats.CONTRACTION_CRITERIA_SMALLER_THAN_ONE,
                contraction);
    }

    if (expansion <= 1.0) {
        throw new MathIllegalArgumentException(
                LocalizedFormats.EXPANSION_FACTOR_SMALLER_THAN_ONE,
                expansion);
    }
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:31,代码来源:ResizableDoubleArray.java

示例15: correlation

import org.apache.commons.math3.exception.MathIllegalArgumentException; //导入依赖的package包/类
/**
 * Computes the Spearman's rank correlation coefficient between the two arrays.
 *
 * @param xArray first data array
 * @param yArray second data array
 * @return Returns Spearman's rank correlation coefficient for the two arrays
 * @throws DimensionMismatchException if the arrays lengths do not match
 * @throws MathIllegalArgumentException if the array length is less than 2
 */
public double correlation(final double[] xArray, final double[] yArray) {
    if (xArray.length != yArray.length) {
        throw new DimensionMismatchException(xArray.length, yArray.length);
    } else if (xArray.length < 2) {
        throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
                                               xArray.length, 2);
    } else {
        double[] x = xArray;
        double[] y = yArray;
        if (rankingAlgorithm instanceof NaturalRanking &&
            NaNStrategy.REMOVED == ((NaturalRanking) rankingAlgorithm).getNanStrategy()) {
            final Set<Integer> nanPositions = new HashSet<Integer>();

            nanPositions.addAll(getNaNPositions(xArray));
            nanPositions.addAll(getNaNPositions(yArray));

            x = removeValues(xArray, nanPositions);
            y = removeValues(yArray, nanPositions);
        }
        return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(x), rankingAlgorithm.rank(y));
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:SpearmansCorrelation.java


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