当前位置: 首页>>代码示例>>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;未经允许,请勿转载。