當前位置: 首頁>>代碼示例>>Java>>正文


Java RealVector.dotProduct方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.linear.RealVector.dotProduct方法的典型用法代碼示例。如果您正苦於以下問題:Java RealVector.dotProduct方法的具體用法?Java RealVector.dotProduct怎麽用?Java RealVector.dotProduct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.linear.RealVector的用法示例。


在下文中一共展示了RealVector.dotProduct方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: logProbability

import org.apache.commons.math3.linear.RealVector; //導入方法依賴的package包/類
@Override public double logProbability(MVNormal datum) {
   int d = meanMean.getDimension();
	RealVector diff = datum.getMean().subtract(meanMean);
	return  -.5*diff.dotProduct(meanPrecision.operate(diff))
           -.5*traceDot(datum.getPrecision())
           +.5*(precisionDegFreedom-d-1)*datum.getPrecisionLogDeterminant()
					-logNormalizer();
}
 
開發者ID:BigBayes,項目名稱:BNPMix.java,代碼行數:9,代碼來源:MVNormalWishartIndependent.java

示例2: 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

示例3: 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

示例4: computeTSS

import org.apache.commons.math3.linear.RealVector; //導入方法依賴的package包/類
/**
 * Computes the Total Sum of Squares for regressand
 * @param y     the vector with dependent variable observations
 * @return      the Total Sum of Squares for regressand
 */
protected double computeTSS(RealVector y) {
    if (!hasIntercept()) {
        return y.dotProduct(y);
    } else {
        final double[] values = y.toArray();
        final double mean = DoubleStream.of(values).average().orElse(Double.NaN);
        final double[] demeaned = DoubleStream.of(values).map(v -> v - mean).toArray();
        final RealVector demeanedVector = new ArrayRealVector(demeaned);
        return demeanedVector.dotProduct(demeanedVector);
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:17,代碼來源:XDataFrameLeastSquares.java

示例5: computeTSS

import org.apache.commons.math3.linear.RealVector; //導入方法依賴的package包/類
@Override
protected double computeTSS(RealVector y) {
    if (!hasIntercept()) {
        return y.dotProduct(y);
    } else {
        final C regressand = getRegressand();
        final double sumOfWeights = weights.stats().sum().doubleValue();
        final Array<Double> yValues = Array.of(frame().col(regressand).toDoubleStream().toArray());
        final double weightedAvg = yValues.mapToDoubles(v -> v.getDouble() * weights.getDouble(v.index())).stats().sum().doubleValue() / sumOfWeights;
        final Array<Double> diffSquared = yValues.mapToDoubles(v -> weights.getDouble(v.index()) * Math.pow(v.getDouble() - weightedAvg, 2d));
        return diffSquared.stats().sum().doubleValue();
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:14,代碼來源:XDataFrame_WLS.java


注:本文中的org.apache.commons.math3.linear.RealVector.dotProduct方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。