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


Java MathArrays类代码示例

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


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

示例1: BilinearInterpolatingFunction

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
public BilinearInterpolatingFunction(double[] xval, double[] yval, double[][] fval)
throws DimensionMismatchException, NoDataException, NonMonotonicSequenceException {
	if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
		throw new NoDataException();
	}
	if (xval.length != fval.length) {
		throw new DimensionMismatchException(xval.length, fval.length);
	}
	if (yval.length != fval[0].length) {
		throw new DimensionMismatchException(yval.length, fval[0].length);
	}

	MathArrays.checkOrder(xval);
	MathArrays.checkOrder(yval);
	
	this.xval = xval;
	this.yval = yval;
	this.fval = fval;
}
 
开发者ID:sing-group,项目名称:la-images,代码行数:20,代码来源:BilinearInterpolatingFunction.java

示例2: interpolate

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
@Override
public BilinearInterpolatingFunction interpolate(double[] xval, double[] yval, double[][] fval)
throws NoDataException, DimensionMismatchException, NonMonotonicSequenceException {
	if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
           throw new NoDataException();
       }
       if (xval.length != fval.length) {
           throw new DimensionMismatchException(xval.length, fval.length);
       }
       if (yval.length != fval[0].length) {
       	throw new DimensionMismatchException(yval.length, fval[0].length);
       }

       MathArrays.checkOrder(xval);
       MathArrays.checkOrder(yval);
       
	return new BilinearInterpolatingFunction(xval, yval, fval);
}
 
开发者ID:sing-group,项目名称:la-images,代码行数:19,代码来源:BilinearInterpolator.java

示例3: addObservation

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/**
 * Adds an observation to the regression model.
 * @param x the array with regressor values
 * @param y  the value of dependent variable given these regressors
 * @exception ModelSpecificationException if the length of {@code x} does not equal
 * the number of independent variables in the model
 */
public void addObservation(final double[] x, final double y)
throws ModelSpecificationException {

    if ((!this.hasIntercept && x.length != nvars) ||
           (this.hasIntercept && x.length + 1 != nvars)) {
        throw new ModelSpecificationException(LocalizedFormats.INVALID_REGRESSION_OBSERVATION,
                x.length, nvars);
    }
    if (!this.hasIntercept) {
        include(MathArrays.copyOf(x, x.length), 1.0, y);
    } else {
        final double[] tmp = new double[x.length + 1];
        System.arraycopy(x, 0, tmp, 1, x.length);
        tmp[0] = 1.0;
        include(tmp, 1.0, y);
    }
    ++nobs;

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

示例4: operate

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** {@inheritDoc} */
public FieldVector<T> operate(final FieldVector<T> v)
    throws DimensionMismatchException {
    try {
        return new ArrayFieldVector<T>(field, operate(((ArrayFieldVector<T>) 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 T[] out = MathArrays.buildArray(field, nRows);
        for (int row = 0; row < nRows; ++row) {
            T sum = field.getZero();
            for (int i = 0; i < nCols; ++i) {
                sum = sum.add(getEntry(row, i).multiply(v.getEntry(i)));
            }
            out[row] = sum;
        }

        return new ArrayFieldVector<T>(field, out, false);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:25,代码来源:AbstractFieldMatrix.java

示例5: createBlocksLayout

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/**
 * Create a data array in blocks layout.
 * <p>
 * This method can be used to create the array argument of the {@link
 * #BlockFieldMatrix(int, int, FieldElement[][], boolean)}
 * constructor.
 * </p>
 * @param <T> Type of the field elements.
 * @param field Field to which the elements belong.
 * @param rows Number of rows in the new matrix.
 * @param columns Number of columns in the new matrix.
 * @return a new data array in blocks layout.
 * @see #toBlocksLayout(FieldElement[][])
 * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean)
 */
public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field,
                                                                   final int rows, final int columns) {
    final int blockRows    = (rows    + BLOCK_SIZE - 1) / BLOCK_SIZE;
    final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE;

    final T[][] blocks = MathArrays.buildArray(field, blockRows * blockColumns, -1);
    int blockIndex = 0;
    for (int iBlock = 0; iBlock < blockRows; ++iBlock) {
        final int pStart  = iBlock * BLOCK_SIZE;
        final int pEnd    = FastMath.min(pStart + BLOCK_SIZE, rows);
        final int iHeight = pEnd - pStart;
        for (int jBlock = 0; jBlock < blockColumns; ++jBlock) {
            final int qStart = jBlock * BLOCK_SIZE;
            final int qEnd   = FastMath.min(qStart + BLOCK_SIZE, columns);
            final int jWidth = qEnd - qStart;
            blocks[blockIndex] = MathArrays.buildArray(field, iHeight * jWidth);
            ++blockIndex;
        }
    }

    return blocks;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:38,代码来源:BlockFieldMatrix.java

示例6: linearCombination

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

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

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

    // 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,代码行数:25,代码来源:DerivativeStructure.java

示例7: linearCombination

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** {@inheritDoc} */
public SparseGradient linearCombination(final SparseGradient[] a,
                                          final SparseGradient[] b)
    throws DimensionMismatchException {

    // compute a simple value, with all partial derivatives
    SparseGradient out = a[0].getField().getZero();
    for (int i = 0; i < a.length; ++i) {
        out = out.add(a[i].multiply(b[i]));
    }

    // recompute an accurate value, taking care of cancellations
    final double[] aDouble = new double[a.length];
    for (int i = 0; i < a.length; ++i) {
        aDouble[i] = a[i].getValue();
    }
    final double[] bDouble = new double[b.length];
    for (int i = 0; i < b.length; ++i) {
        bDouble[i] = b[i].getValue();
    }
    out.value = MathArrays.linearCombination(aDouble, bDouble);

    return out;

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

示例8: getRow

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public T[] getRow(final int row) throws OutOfRangeException {
    checkRowIndex(row);
    final T[] out = MathArrays.buildArray(getField(), columns);

    // perform copy block-wise, to ensure good cache behavior
    final int iBlock  = row / BLOCK_SIZE;
    final int iRow    = row - iBlock * BLOCK_SIZE;
    int outIndex      = 0;
    for (int jBlock = 0; jBlock < blockColumns; ++jBlock) {
        final int jWidth     = blockWidth(jBlock);
        final T[] block = blocks[iBlock * blockColumns + jBlock];
        System.arraycopy(block, iRow * jWidth, out, outIndex, jWidth);
        outIndex += jWidth;
    }

    return out;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:20,代码来源:BlockFieldMatrix.java

示例9: illuminate

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/**
 * Illumination.
 *
 * @param sampleDirection Vector whose origin is at the interpolation
 * point and tail is at the sample location.
 * @param sampleValue Data value of the sample.
 * @param weight Weight.
 */
private void illuminate(double[] sampleDirection,
                        double sampleValue,
                        double weight) {
    for (int i = 0; i < size; i++) {
        final double[] n = microsphere.get(i).getNormal();
        final double cos = MathArrays.cosAngle(n, sampleDirection);

        if (cos > 0) {
            final double illumination = cos * weight;

            if (illumination > darkThreshold &&
                illumination > microsphereData.get(i).illumination()) {
                microsphereData.set(i, new FacetData(illumination, sampleValue));
            }
        }
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:InterpolatingMicrosphere.java

示例10: getA

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** {@inheritDoc} */
public T[][] getA() {

    final T two     = getField().getZero().add(2);
    final T sqrtTwo = two.sqrt();

    final T[][] a = MathArrays.buildArray(getField(), 3, -1);
    for (int i = 0; i < a.length; ++i) {
        a[i] = MathArrays.buildArray(getField(), i + 1);
    }
    a[0][0] = fraction(1, 2);
    a[1][0] = sqrtTwo.subtract(1).multiply(0.5);
    a[1][1] = sqrtTwo.subtract(2).multiply(-0.5);
    a[2][0] = getField().getZero();
    a[2][1] = sqrtTwo.multiply(-0.5);
    a[2][2] = sqrtTwo.add(2).multiply(0.5);
    return a;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:19,代码来源:GillFieldIntegrator.java

示例11: getC

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** {@inheritDoc} */
public T[] getC() {

    final T sqrt6 = getField().getOne().multiply(6).sqrt();

    final T[] c = MathArrays.buildArray(getField(), 15);
    c[ 0] = sqrt6.add(-6).divide(-67.5);
    c[ 1] = sqrt6.add(-6).divide(-45.0);
    c[ 2] = sqrt6.add(-6).divide(-30.0);
    c[ 3] = sqrt6.add( 6).divide( 30.0);
    c[ 4] = fraction(1, 3);
    c[ 5] = fraction(1, 4);
    c[ 6] = fraction(4, 13);
    c[ 7] = fraction(127, 195);
    c[ 8] = fraction(3, 5);
    c[ 9] = fraction(6, 7);
    c[10] = getField().getOne();
    c[11] = getField().getOne();
    c[12] = fraction(1.0, 10.0);
    c[13] = fraction(1.0, 5.0);
    c[14] = fraction(7.0, 9.0);

    return c;

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

示例12: operate

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public T[] operate(final T[] v) throws DimensionMismatchException {
    final int nRows = this.getRowDimension();
    final int nCols = this.getColumnDimension();
    if (v.length != nCols) {
        throw new DimensionMismatchException(v.length, nCols);
    }
    final T[] out = MathArrays.buildArray(getField(), nRows);
    for (int row = 0; row < nRows; row++) {
        final T[] dataRow = data[row];
        T sum = getField().getZero();
        for (int i = 0; i < nCols; i++) {
            sum = sum.add(dataRow[i].multiply(v[i]));
        }
        out[row] = sum;
    }
    return out;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:20,代码来源:Array2DRowFieldMatrix.java

示例13: HighamHall54FieldIntegrator

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** Simple constructor.
 * Build a fifth order Higham and Hall integrator with the given step bounds
 * @param field field to which the time and state vector elements belong
 * @param minStep minimal step (sign is irrelevant, regardless of
 * integration direction, forward or backward), the last step can
 * be smaller than this
 * @param maxStep maximal step (sign is irrelevant, regardless of
 * integration direction, forward or backward), the last step can
 * be smaller than this
 * @param scalAbsoluteTolerance allowed absolute error
 * @param scalRelativeTolerance allowed relative error
 */
public HighamHall54FieldIntegrator(final Field<T> field,
                                   final double minStep, final double maxStep,
                                   final double scalAbsoluteTolerance,
                                   final double scalRelativeTolerance) {
    super(field, METHOD_NAME, -1,
          minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
    e = MathArrays.buildArray(field, 7);
    e[0] = fraction(-1,  20);
    e[1] = field.getZero();
    e[2] = fraction(81, 160);
    e[3] = fraction(-6,   5);
    e[4] = fraction(25,  32);
    e[5] = fraction( 1,  16);
    e[6] = fraction(-1,  10);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:HighamHall54FieldIntegrator.java

示例14: computeDerivatives

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** Get the current time derivative of the complete state vector.
 * @param t current value of the independent <I>time</I> variable
 * @param y array containing the current value of the complete state vector
 * @return time derivative of the complete state vector
 * @exception MaxCountExceededException if the number of functions evaluations is exceeded
 * @exception DimensionMismatchException if arrays dimensions do not match equations settings
 */
public T[] computeDerivatives(final T t, final T[] y)
    throws MaxCountExceededException, DimensionMismatchException {

    final T[] yDot = MathArrays.buildArray(t.getField(), mapper.getTotalDimension());

    // compute derivatives of the primary equations
    int index = 0;
    final T[] primaryState    = mapper.extractEquationData(index, y);
    final T[] primaryStateDot = primary.computeDerivatives(t, primaryState);
    mapper.insertEquationData(index, primaryStateDot, yDot);

    // Add contribution for secondary equations
    while (++index < mapper.getNumberOfEquations()) {
        final T[] componentState    = mapper.extractEquationData(index, y);
        final T[] componentStateDot = components.get(index - 1).computeDerivatives(t, primaryState, primaryStateDot,
                                                                                   componentState);
        mapper.insertEquationData(index, componentStateDot, yDot);
    }

    return yDot;

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

示例15: copy

import org.apache.commons.math3.util.MathArrays; //导入依赖的package包/类
/** Copy a two-dimensions array.
 * @param field field to which elements belong
 * @param original original array (may be null)
 * @return copied array or null if original array was null
 */
protected T[][] copy(final Field<T> field, final T[][] original) {

    // special handling of null arrays
    if (original == null) {
        return null;
    }

    // allocate the array
    final T[][] copied = MathArrays.buildArray(field, original.length, -1);

    // copy content
    for (int i = 0; i < original.length; ++i) {
        copied[i] = original[i].clone();
    }

    return copied;

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


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