本文整理汇总了Java中org.apache.commons.math3.linear.RealMatrix.multiply方法的典型用法代码示例。如果您正苦于以下问题:Java RealMatrix.multiply方法的具体用法?Java RealMatrix.multiply怎么用?Java RealMatrix.multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.RealMatrix
的用法示例。
在下文中一共展示了RealMatrix.multiply方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apacheCommonsExample
import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
public void apacheCommonsExample() {
double[][] A = {
{0.1950, 0.0311},
{0.3588, 0.2203},
{0.1716, 0.5931},
{0.2105, 0.3242}};
double[][] B = {
{0.0502, 0.9823, 0.9472},
{0.5732, 0.2694, 0.916}};
RealMatrix aRealMatrix = new Array2DRowRealMatrix(A);
RealMatrix bRealMatrix = new Array2DRowRealMatrix(B);
RealMatrix cRealMatrix = aRealMatrix.multiply(bRealMatrix);
System.out.println();
for (int i = 0; i < cRealMatrix.getRowDimension(); i++) {
System.out.println(cRealMatrix.getRowVector(i));
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:21,代码来源:MathExamples.java
示例2: makeZta
import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
public RealMatrix makeZta(RealMatrix userFeature, RealMatrix articleFeature) {
RealMatrix product = userFeature.multiply(articleFeature.transpose());
double[][] productData = product.getData();
double[] productVector = new double[36];
int count = 0;
for (int row = 0; row < 6; row++) {
for (int col = 0; col < 6; col++) {
productVector[count] = productData[row][col];
count++;
}
}
return MatrixUtils.createColumnRealMatrix(productVector);
}
示例3: wtdAvCorr
import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
/**
*
* @param values
* @param varCov
* @return
*/
public static WtdAvCorrResults wtdAvCorr(double[] values, double[][] varCov) {
// assume varCov is variance-covariance matrix (i.e. SigRho = false)
WtdAvCorrResults results = new WtdAvCorrResults();
int n = varCov.length;
RealMatrix omegaInv = new BlockRealMatrix(varCov);
RealMatrix omega = MatrixUtils.inverse(omegaInv);
double numer = 0.0;
double denom = 0.0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
numer += (values[i] + values[j]) * omega.getEntry(i, j);
denom += omega.getEntry(i, j);
}
}
// test denom
if (denom > 0.0) {
double meanVal = numer / denom / 2.0;
double meanValSigma = Math.sqrt(1.0 / denom);
double[][] unwtdResidsArray = new double[n][1];
for (int i = 0; i < n; i++) {
unwtdResidsArray[i][0] = values[i] - meanVal;
}
RealMatrix unwtdResids = new BlockRealMatrix(unwtdResidsArray);
RealMatrix transUnwtdResids = unwtdResids.transpose();
RealMatrix product = transUnwtdResids.multiply(omega);
RealMatrix sumWtdResids = product.multiply(unwtdResids);
double mswd = 0.0;
double prob = 0.0;
if (n > 1) {
mswd = sumWtdResids.getEntry(0, 0) / (n - 1);
// http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/distribution/FDistribution.html
FDistribution fdist = new org.apache.commons.math3.distribution.FDistribution((n - 1), 1E9);
prob = 1.0 - fdist.cumulativeProbability(mswd);
}
results.setBad(false);
results.setMeanVal(meanVal);
results.setSigmaMeanVal(meanValSigma);
results.setMswd(mswd);
results.setProb(prob);
}
return results;
}
示例4: 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;
}