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


Java RealVector.subtract方法代码示例

本文整理汇总了Java中org.apache.commons.math3.linear.RealVector.subtract方法的典型用法代码示例。如果您正苦于以下问题:Java RealVector.subtract方法的具体用法?Java RealVector.subtract怎么用?Java RealVector.subtract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.linear.RealVector的用法示例。


在下文中一共展示了RealVector.subtract方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeBeta

import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
 *
 * @param y     the response vector
 * @param x     the design matrix
 */
private RealMatrix computeBeta(RealVector y, RealMatrix x) {
    if (solver == Solver.QR) {
        return computeBetaQR(y, x);
    } else {
        final int n = x.getRowDimension();
        final int p = x.getColumnDimension();
        final int offset = hasIntercept() ? 1 : 0;
        final RealMatrix xT = x.transpose();
        final RealMatrix xTxInv = new LUDecomposition(xT.multiply(x)).getSolver().getInverse();
        final RealVector betaVector = xTxInv.multiply(xT).operate(y);
        final RealVector residuals = y.subtract(x.operate(betaVector));
        this.rss = residuals.dotProduct(residuals);
        this.errorVariance = rss / (n - p);
        this.stdError = Math.sqrt(errorVariance);
        this.residuals = createResidualsFrame(residuals);
        final RealMatrix covMatrix = xTxInv.scalarMultiply(errorVariance);
        final RealMatrix result = new Array2DRowRealMatrix(p, 2);
        if (hasIntercept()) {
            result.setEntry(0, 0, betaVector.getEntry(0));      //Intercept coefficient
            result.setEntry(0, 1, covMatrix.getEntry(0, 0));    //Intercept variance
        }
        for (int i = 0; i < getRegressors().size(); i++) {
            final int index = i + offset;
            final double variance = covMatrix.getEntry(index, index);
            result.setEntry(index, 1, variance);
            result.setEntry(index, 0, betaVector.getEntry(index));
        }
        return result;
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:36,代码来源:XDataFrameLeastSquares.java

示例2: computeBetaQR

import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
 * Computes model parameters and parameter variance using a QR decomposition of the X matrix
 * @param y     the response vector
 * @param x     the design matrix
 */
private RealMatrix computeBetaQR(RealVector y, RealMatrix x) {
    final int n = x.getRowDimension();
    final int p = x.getColumnDimension();
    final int offset = hasIntercept() ? 1 : 0;
    final QRDecomposition decomposition = new QRDecomposition(x, threshold);
    final RealVector betaVector = decomposition.getSolver().solve(y);
    final RealVector residuals = y.subtract(x.operate(betaVector));
    this.rss = residuals.dotProduct(residuals);
    this.errorVariance = rss / (n - p);
    this.stdError = Math.sqrt(errorVariance);
    this.residuals = createResidualsFrame(residuals);
    final RealMatrix rAug = decomposition.getR().getSubMatrix(0, p - 1, 0, p - 1);
    final RealMatrix rInv = new LUDecomposition(rAug).getSolver().getInverse();
    final RealMatrix covMatrix = rInv.multiply(rInv.transpose()).scalarMultiply(errorVariance);
    final RealMatrix result = new Array2DRowRealMatrix(p, 2);
    if (hasIntercept()) {
        result.setEntry(0, 0, betaVector.getEntry(0));      //Intercept coefficient
        result.setEntry(0, 1, covMatrix.getEntry(0, 0));    //Intercept variance
    }
    for (int i = 0; i < getRegressors().size(); i++) {
        final int index = i + offset;
        final double variance = covMatrix.getEntry(index, index);
        result.setEntry(index, 1, variance);
        result.setEntry(index, 0, betaVector.getEntry(index));
    }
    return result;
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:33,代码来源:XDataFrameLeastSquares.java

示例3: correct

import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
 * Correct the current state estimate with an actual measurement.
 *
 * @param z
 *            the measurement vector
 * @throws NullArgumentException
 *             if the measurement vector is {@code null}
 * @throws DimensionMismatchException
 *             if the dimension of the measurement vector does not fit
 * @throws SingularMatrixException
 *             if the covariance matrix could not be inverted
 */
public void correct(final RealVector z) throws NullArgumentException,
           DimensionMismatchException, SingularMatrixException
{

	// sanity checks
	MathUtils.checkNotNull(z);
	if (z.getDimension() != measurementMatrix.getRowDimension())
	{
		throw new DimensionMismatchException(z.getDimension(),
				measurementMatrix.getRowDimension());
	}

	// S = H * P(k) * H' + R
	RealMatrix s = measurementMatrix.multiply(errorCovariance)
			.multiply(measurementMatrixT)
			.add(measurementModel.getMeasurementNoise());

	// Inn = z(k) - H * xHat(k)-
	RealVector innovation = z.subtract(measurementMatrix
			.operate(stateEstimation));

	// calculate gain matrix
	// K(k) = P(k)- * H' * (H * P(k)- * H' + R)^-1
	// K(k) = P(k)- * H' * S^-1

	// instead of calculating the inverse of S we can rearrange the formula,
	// and then solve the linear equation A x X = B with A = S', X = K' and
	// B = (H * P)'

	// K(k) * S = P(k)- * H'
	// S' * K(k)' = H * P(k)-'
	RealMatrix kalmanGain = new CholeskyDecomposition(s).getSolver()
			.solve(measurementMatrix.multiply(errorCovariance.transpose()))
			.transpose();

	// update estimate with measurement z(k)
	// xHat(k) = xHat(k)- + K * Inn
	stateEstimation = stateEstimation.add(kalmanGain.operate(innovation));

	// update covariance of prediction error
	// P(k) = (I - K * H) * P(k)-
	RealMatrix identity = MatrixUtils.createRealIdentityMatrix(kalmanGain
			.getRowDimension());
	errorCovariance = identity.subtract(
			kalmanGain.multiply(measurementMatrix)).multiply(
			errorCovariance);
}
 
开发者ID:KalebKE,项目名称:FSensor,代码行数:60,代码来源:RotationKalmanFilter.java


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