本文整理匯總了Java中org.apache.commons.math3.linear.RealMatrix.subtract方法的典型用法代碼示例。如果您正苦於以下問題:Java RealMatrix.subtract方法的具體用法?Java RealMatrix.subtract怎麽用?Java RealMatrix.subtract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.linear.RealMatrix
的用法示例。
在下文中一共展示了RealMatrix.subtract方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: score
import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
private NoveltyScores score(final RealMatrix kernelMatrix) {
// projected test samples:
final RealMatrix projectionVectors =
kernelMatrix.transpose().multiply(m_projection);
// differences to the target value:
final RealMatrix diff = projectionVectors.subtract(
MatrixFunctions.ones(kernelMatrix.getColumnDimension(), 1)
.scalarMultiply(m_targetPoints.getEntry(0, 0)));
// distances to the target value:
final RealVector scoresVector = MatrixFunctions.sqrt(MatrixFunctions
.rowSums(MatrixFunctions.multiplyElementWise(diff, diff)));
return new NoveltyScores(scoresVector.toArray(), projectionVectors);
}
示例2: chooseArm
import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public Article chooseArm(User user, List<Article> articles) {
Article bestA = null;
double bestArmP = Double.MIN_VALUE;
RealMatrix Aa;
RealMatrix Ba;
RealMatrix ba;
for (Article a : articles) {
String aId = a.getId();
if (!AMap.containsKey(aId)) {
Aa = MatrixUtils.createRealIdentityMatrix(6);
AMap.put(aId, Aa); // set as identity for now and we will update
// in reward
double[] zeros = { 0, 0, 0, 0, 0, 0 };
ba = MatrixUtils.createColumnRealMatrix(zeros);
bMap.put(aId, ba);
double[][] BMapZeros = new double[6][36];
for (double[] row : BMapZeros) {
Arrays.fill(row, 0.0);
}
Ba = MatrixUtils.createRealMatrix(BMapZeros);
BMap.put(aId, Ba);
} else {
Aa = AMap.get(aId);
ba = bMap.get(aId);
Ba = BMap.get(aId);
}
// Make column vector out of features
RealMatrix xta = MatrixUtils
.createColumnRealMatrix(a.getFeatures());
RealMatrix zta = makeZta(
MatrixUtils.createColumnRealMatrix(user.getFeatures()), xta);
// Set up common variables
RealMatrix A0Inverse = MatrixUtils.inverse(A0);
RealMatrix AaInverse = MatrixUtils.inverse(Aa);
RealMatrix ztaTranspose = zta.transpose();
RealMatrix BaTranspose = Ba.transpose();
RealMatrix xtaTranspose = xta.transpose();
// Find theta
RealMatrix theta = AaInverse.multiply(ba.subtract(Ba
.multiply(BetaHat)));
// Find sta
RealMatrix staMatrix = ztaTranspose.multiply(A0Inverse).multiply(
zta);
staMatrix = staMatrix.subtract(ztaTranspose.multiply(A0Inverse)
.multiply(BaTranspose).multiply(AaInverse).multiply(xta)
.scalarMultiply(2));
staMatrix = staMatrix.add(xtaTranspose.multiply(AaInverse)
.multiply(xta));
staMatrix = staMatrix.add(xtaTranspose.multiply(AaInverse)
.multiply(Ba).multiply(A0Inverse).multiply(BaTranspose)
.multiply(AaInverse).multiply(xta));
// Find pta for arm
RealMatrix ptaMatrix = ztaTranspose.multiply(BetaHat);
ptaMatrix = ptaMatrix.add(xtaTranspose.multiply(theta));
double ptaVal = ptaMatrix.getData()[0][0];
double staVal = staMatrix.getData()[0][0];
ptaVal = ptaVal + alpha * Math.sqrt(staVal);
// Update argmax
if (ptaVal > bestArmP) {
bestArmP = ptaVal;
bestA = a;
}
}
return bestA;
}