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


Java RealMatrix.add方法代碼示例

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


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

示例1: main

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public static void main(String[] args) {
  // test wishart
  double[][] s = {{2.0,1.0,0.0},{1.0,2.0,1.0},{0.0,1.0,2.0}};
  RealMatrix S = new Array2DRowRealMatrix(s);
  Cholesky C = new Cholesky(S);
  double df = 2.4;
  RealMatrix sum = new Array2DRowRealMatrix(3,3);
  for (int i=0; i<100000; i++) {
    RealMatrix sample = generator.nextWishart(df, C);
    sum = sum.add(sample);
  }
  sum = sum.scalarMultiply(1.0/100000.0);
  System.out.println(sum.getRowVector(0));
  System.out.println(sum.getRowVector(1));
  System.out.println(sum.getRowVector(2));
}
 
開發者ID:BigBayes,項目名稱:BNPMix.java,代碼行數:17,代碼來源:Generator.java

示例2: sample

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public void sample(Collection<? extends XHierarchy> data) {
  double df;
  RealMatrix is = precisionInvScaleInvScale;
  df = precisionInvScaleDegFreedom + precisionDegFreedom*data.size();
  for (XHierarchy d : data) {
    MVNormalNonConjugateHierarchySampled h = (MVNormalNonConjugateHierarchySampled)d;
    is = is.add(h.param.getPrecision());
  }
  setPrecisionInvScale(generator.nextWishart(df, new Cholesky(is)));
}
 
開發者ID:BigBayes,項目名稱:BNPMix.java,代碼行數:11,代碼來源:MVNormalWishartIndependent.java

示例3: updateReward

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public void updateReward(User user, Article a, boolean clicked) {
	String aId = a.getId();
	// Collect Variables
	RealMatrix xta = MatrixUtils.createColumnRealMatrix(a.getFeatures());
	RealMatrix zta = makeZta(
			MatrixUtils.createColumnRealMatrix(user.getFeatures()), xta);

	RealMatrix Aa = AMap.get(aId);
	RealMatrix ba = bMap.get(aId);
	RealMatrix Ba = BMap.get(aId);

	// Find common transpose/inverse to save computation
	RealMatrix AaInverse = MatrixUtils.inverse(Aa);
	RealMatrix BaTranspose = Ba.transpose();
	RealMatrix xtaTranspose = xta.transpose();
	RealMatrix ztaTranspose = zta.transpose();

	// Update
	A0 = A0.add(BaTranspose.multiply(AaInverse).multiply(Ba));
	b0 = b0.add(BaTranspose.multiply(AaInverse).multiply(ba));
	Aa = Aa.add(xta.multiply(xtaTranspose));
	AMap.put(aId, Aa);
	Ba = Ba.add(xta.multiply(ztaTranspose));
	BMap.put(aId, Ba);
	if (clicked) {
		ba = ba.add(xta);
		bMap.put(aId, ba);
	}

	// Update A0 and b0 with the new values
	A0 = A0.add(zta.multiply(ztaTranspose)).subtract(
			Ba.transpose().multiply(MatrixUtils.inverse(Aa).multiply(Ba)));
	b0 = b0.subtract(Ba.transpose().multiply(MatrixUtils.inverse(Aa))
			.multiply(ba));
	if (clicked) {
		b0 = b0.add(zta);
	}
}
 
開發者ID:tankle,項目名稱:Bandit4J,代碼行數:39,代碼來源:HybridLinUCB.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.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。