本文整理汇总了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();
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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();
}
}