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


Java DimensionMismatchException类代码示例

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


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

示例1: computeWeightedJacobian

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Computes the Jacobian matrix.
 *
 * @param params Model parameters at which to compute the Jacobian.
 * @return the weighted Jacobian: W<sup>1/2</sup> J.
 * @throws DimensionMismatchException if the Jacobian dimension does not
 * match problem dimension.
 * @since 3.1
 */
protected RealMatrix computeWeightedJacobian(double[] params) {
    ++jacobianEvaluations;

    final DerivativeStructure[] dsPoint = new DerivativeStructure[params.length];
    final int nC = params.length;
    for (int i = 0; i < nC; ++i) {
        dsPoint[i] = new DerivativeStructure(nC, 1, i, params[i]);
    }
    final DerivativeStructure[] dsValue = jF.value(dsPoint);
    final int nR = getTarget().length;
    if (dsValue.length != nR) {
        throw new DimensionMismatchException(dsValue.length, nR);
    }
    final double[][] jacobianData = new double[nR][nC];
    for (int i = 0; i < nR; ++i) {
        int[] orders = new int[nC];
        for (int j = 0; j < nC; ++j) {
            orders[j] = 1;
            jacobianData[i][j] = dsValue[i].getPartialDerivative(orders);
            orders[j] = 0;
        }
    }

    return weightMatrixSqrt.multiply(MatrixUtils.createRealMatrix(jacobianData));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:35,代码来源:AbstractLeastSquaresOptimizer.java

示例2: solveL

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Solves for L x = b
 * @param b
 * @return x
 */
public RealVector solveL(RealVector b) {
  final int m = lTData.length;
  if (b.getDimension() != m) {
    throw new DimensionMismatchException(b.getDimension(), m);
  }

  final double[] x = b.toArray();

  // Solve LY = b
  for (int j = 0; j < m; j++) {
    final double[] lJ = lTData[j];
    x[j] /= lJ[j];
    final double xJ = x[j];
    for (int i = j + 1; i < m; i++) {
      x[i] -= xJ * lJ[i];
    }
  }
  return new ArrayRealVector(x, false);
}
 
开发者ID:BigBayes,项目名称:BNPMix.java,代码行数:25,代码来源:Cholesky.java

示例3: solveLT

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Solves for L^T x = b
 * @param b
 * @return x
 */
public RealVector solveLT(RealVector b) {
  final int m = lTData.length;
  if (b.getDimension() != m) {
    throw new DimensionMismatchException(b.getDimension(), m);
  }

  final double[] x = b.toArray();

  // Solve LTX = b
  for (int j = m - 1; j >= 0; j--) {
    x[j] /= lTData[j][j];
    final double xJ = x[j];
    for (int i = 0; i < j; i++) {
      x[i] -= xJ * lTData[i][j];
    }
  }

  return new ArrayRealVector(x, false);
}
 
开发者ID:BigBayes,项目名称:BNPMix.java,代码行数:25,代码来源:Cholesky.java

示例4: computeDerivatives

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
@Override
public void computeDerivatives(double t, double[] y, double[] yDot)
		throws MaxCountExceededException, DimensionMismatchException {
	int i,j;
	
	DoubleMatrix demeYdot;
	
	updateMatrices(t,y);
	demeYdot = births.columnSums().transpose();
	demeYdot.addi(migrations.columnSums().transpose());
	demeYdot.subi(migrations.rowSums());
	demeYdot.subi(deaths);
	
	for(i=0; i<numDemes; i++) { yDot[i] = demeYdot.get(i,0); }
	for(j=0; i<numDemes+numNonDemes; i++,j++) { yDot[i] = nondemeYdot[j]; }
	
	/* -- previous code optimisation
	if (this.fixedStepSize) {
		timeseries.addFG(t, births, migrations);
	}
	*/
	
}
 
开发者ID:mrc-ide,项目名称:PhyDyn,代码行数:24,代码来源:PopModelODE.java

示例5: computeDerivatives

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
@Override
public void computeDerivatives(double t, double[] y, double[] yDot)
    throws MaxCountExceededException, DimensionMismatchException 
{
  
  if(Double.isNaN(t))
  {
    throw new MaxCountExceededException(t);
  }
  
  setCurrentTime(t);
  vectorWrapper.setValues(y);
  computeAssignmentRules();
  vectorWrapper.setRates(yDot);
  computeRates();
}
 
开发者ID:MyersResearchGroup,项目名称:iBioSim,代码行数:17,代码来源:HierarchicalODERKSimulator.java

示例6: PolynomialSplineFunction

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Construct a polynomial spline function with the given segment delimiters
 * and interpolating polynomials.
 * The constructor copies both arrays and assigns the copies to the knots
 * and polynomials properties, respectively.
 *
 * @param knots Spline segment interval delimiters.
 * @param polynomials Polynomial functions that make up the spline.
 * @throws NullArgumentException if either of the input arrays is {@code null}.
 * @throws NumberIsTooSmallException if knots has length less than 2.
 * @throws DimensionMismatchException if {@code polynomials.length != knots.length - 1}.
 * @throws NonMonotonicSequenceException if the {@code knots} array is not strictly increasing.
 *
 */
public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[])
    throws NullArgumentException, NumberIsTooSmallException,
           DimensionMismatchException, NonMonotonicSequenceException{
    if (knots == null ||
        polynomials == null) {
        throw new NullArgumentException();
    }
    if (knots.length < 2) {
        throw new NumberIsTooSmallException(LocalizedFormats.NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION,
                                            2, knots.length, false);
    }
    if (knots.length - 1 != polynomials.length) {
        throw new DimensionMismatchException(polynomials.length, knots.length);
    }
    MathArrays.checkOrder(knots);

    this.n = knots.length -1;
    this.knots = new double[n + 1];
    System.arraycopy(knots, 0, this.knots, 0, n + 1);
    this.polynomials = new PolynomialFunction[n];
    System.arraycopy(polynomials, 0, this.polynomials, 0, n);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:37,代码来源:PolynomialSplineFunction.java

示例7: build

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Build an initial simplex.
 *
 * @param startPoint First point of the simplex.
 * @throws DimensionMismatchException if the start point does not match
 * simplex dimension.
 */
public void build(final double[] startPoint) {
    if (dimension != startPoint.length) {
        throw new DimensionMismatchException(dimension, startPoint.length);
    }

    // Set first vertex.
    simplex = new PointValuePair[dimension + 1];
    simplex[0] = new PointValuePair(startPoint, Double.NaN);

    // Set remaining vertices.
    for (int i = 0; i < dimension; i++) {
        final double[] confI = startConfiguration[i];
        final double[] vertexI = new double[dimension];
        for (int k = 0; k < dimension; k++) {
            vertexI[k] = startPoint[k] + confI[k];
        }
        simplex[i + 1] = new PointValuePair(vertexI, Double.NaN);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:AbstractSimplex.java

示例8: Array2DRowFieldMatrix

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Create a new {@code FieldMatrix<T>} using the input array as the underlying
 * data array.
 * <p>If an array is built specially in order to be embedded in a
 * {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.</p>
 *
 * @param field Field to which the elements belong.
 * @param d Data for the new matrix.
 * @param copyArray Whether to copy or reference the input array.
 * @throws DimensionMismatchException if {@code d} is not rectangular.
 * @throws NoDataException if there are not at least one row and one column.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @see #Array2DRowFieldMatrix(FieldElement[][])
 */
public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray)
    throws DimensionMismatchException, NoDataException, NullArgumentException {
    super(field);
    if (copyArray) {
        copyIn(d);
    } else {
        MathUtils.checkNotNull(d);
        final int nRows = d.length;
        if (nRows == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
        }
        final int nCols = d[0].length;
        if (nCols == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
        }
        for (int r = 1; r < nRows; r++) {
            if (d[r].length != nCols) {
                throw new DimensionMismatchException(nCols, d[r].length);
            }
        }
        data = d;
    }
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:40,代码来源:Array2DRowFieldMatrix.java

示例9: getCount

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Convert to unidimensional counter.
 *
 * @param c Indices in multidimensional counter.
 * @return the index within the unidimensionl counter.
 * @throws DimensionMismatchException if the size of {@code c}
 * does not match the size of the array given in the constructor.
 * @throws OutOfRangeException if a value of {@code c} is not in
 * the range of the corresponding dimension, as defined in the
 * {@link MultidimensionalCounter#MultidimensionalCounter(int...) constructor}.
 */
public int getCount(int ... c)
    throws OutOfRangeException, DimensionMismatchException {
    if (c.length != dimension) {
        throw new DimensionMismatchException(c.length, dimension);
    }
    int count = 0;
    for (int i = 0; i < dimension; i++) {
        final int index = c[i];
        if (index < 0 ||
            index >= size[i]) {
            throw new OutOfRangeException(index, 0, size[i] - 1);
        }
        count += uniCounterOffset[i] * c[i];
    }
    return count + c[last];
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:MultidimensionalCounter.java

示例10: inducedPermutation

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

示例11: add

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/**
 * Optimized method to add sparse vectors.
 *
 * @param v Vector to add.
 * @return {@code this + v}.
 * @throws DimensionMismatchException if {@code v} is not the same size as
 * {@code this}.
 */
public FieldVector<T> add(SparseFieldVector<T> v)
    throws DimensionMismatchException {
    checkVectorDimensions(v.getDimension());
    SparseFieldVector<T> res = (SparseFieldVector<T>)copy();
    OpenIntToFieldHashMap<T>.Iterator iter = v.getEntries().iterator();
    while (iter.hasNext()) {
        iter.advance();
        int key = iter.key();
        T value = iter.value();
        if (entries.containsKey(key)) {
            res.setEntry(key, entries.get(key).add(value));
        } else {
            res.setEntry(key, value);
        }
    }
    return res;

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

示例12: sanityChecks

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void sanityChecks(final FieldODEState<T> eqn, final T t)
    throws DimensionMismatchException, NumberIsTooSmallException {

    super.sanityChecks(eqn, t);

    mainSetDimension = eqn.getStateDimension();

    if (vecAbsoluteTolerance != null && vecAbsoluteTolerance.length != mainSetDimension) {
        throw new DimensionMismatchException(mainSetDimension, vecAbsoluteTolerance.length);
    }

    if (vecRelativeTolerance != null && vecRelativeTolerance.length != mainSetDimension) {
        throw new DimensionMismatchException(mainSetDimension, vecRelativeTolerance.length);
    }

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

示例13: preMultiply

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/** {@inheritDoc} */
public RealVector preMultiply(final RealVector v) {
    try {
        return new ArrayRealVector(preMultiply(((ArrayRealVector) v).getDataRef()), false);
    } catch (ClassCastException cce) {

        final int nRows = getRowDimension();
        final int nCols = getColumnDimension();
        if (v.getDimension() != nRows) {
            throw new DimensionMismatchException(v.getDimension(), nRows);
        }

        final double[] out = new double[nCols];
        for (int col = 0; col < nCols; ++col) {
            double sum = 0;
            for (int i = 0; i < nRows; ++i) {
                sum += getEntry(i, col) * v.getEntry(i);
            }
            out[col] = sum;
        }

        return new ArrayRealVector(out, false);
    }
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:25,代码来源:AbstractRealMatrix.java

示例14: operate

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public RealVector operate(final RealVector v) {
    try {
        return new ArrayRealVector(operate(((ArrayRealVector) v).getDataRef()), false);
    } catch (ClassCastException cce) {
        final int nRows = getRowDimension();
        final int nCols = getColumnDimension();
        if (v.getDimension() != nCols) {
            throw new DimensionMismatchException(v.getDimension(), nCols);
        }

        final double[] out = new double[nRows];
        for (int row = 0; row < nRows; ++row) {
            double sum = 0;
            for (int i = 0; i < nCols; ++i) {
                sum += getEntry(row, i) * v.getEntry(i);
            }
            out[row] = sum;
        }

        return new ArrayRealVector(out, false);
    }
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:25,代码来源:AbstractRealMatrix.java

示例15: linearCombination

import org.apache.commons.math3.exception.DimensionMismatchException; //导入依赖的package包/类
/** {@inheritDoc}
 * @exception DimensionMismatchException if number of free parameters
 * or orders do not match
 * @since 3.2
 */
public DerivativeStructure linearCombination(final DerivativeStructure a1, final DerivativeStructure b1,
                                             final DerivativeStructure a2, final DerivativeStructure b2,
                                             final DerivativeStructure a3, final DerivativeStructure b3,
                                             final DerivativeStructure a4, final DerivativeStructure b4)
    throws DimensionMismatchException {

    // compute an accurate value, taking care of cancellations
    final double accurateValue = MathArrays.linearCombination(a1.getValue(), b1.getValue(),
                                                              a2.getValue(), b2.getValue(),
                                                              a3.getValue(), b3.getValue(),
                                                              a4.getValue(), b4.getValue());

    // compute a simple value, with all partial derivatives
    final DerivativeStructure simpleValue = a1.multiply(b1).add(a2.multiply(b2)).add(a3.multiply(b3)).add(a4.multiply(b4));

    // create a result with accurate value and all derivatives (not necessarily as accurate as the value)
    final double[] all = simpleValue.getAllDerivatives();
    all[0] = accurateValue;
    return new DerivativeStructure(getFreeParameters(), getOrder(), all);

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


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