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


Java RealMatrix.multiply方法代碼示例

本文整理匯總了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);
}
 
開發者ID:tankle,項目名稱:Bandit4J,代碼行數:14,代碼來源:HybridLinUCB.java

示例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;

}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:61,代碼來源:WeightedMeanCalculators.java

示例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;
}
 
開發者ID:tankle,項目名稱:Bandit4J,代碼行數:75,代碼來源:HybridLinUCB.java


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