当前位置: 首页>>代码示例>>Java>>正文


Java Solve类代码示例

本文整理汇总了Java中org.jblas.Solve的典型用法代码示例。如果您正苦于以下问题:Java Solve类的具体用法?Java Solve怎么用?Java Solve使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Solve类属于org.jblas包,在下文中一共展示了Solve类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: train

import org.jblas.Solve; //导入依赖的package包/类
public void train(float[][] xraw, float[][] yraw) {
	float[][] x = new float[xraw.length][];
	for (int i=0; i<xraw.length; ++i) {
		x[i] = a.append(1.0f, xraw[i]);
	}
	float[][] y = yraw;
	
	Matrix yMat = Matrix.build(y);
	Matrix xMat = Matrix.build(x);
	Matrix xTrMat = xMat.transpose();
	
	List<Matrix> A = new ArrayList<Matrix>();
	A.add(xTrMat.mmul(xMat).diagAdd(reg));
	List<Matrix> B = new ArrayList<Matrix>();
	B.add(xTrMat.mmul(yMat));
	
	this.weights = Matrix.build(Solve.solvePositive(new FloatMatrix(xTrMat.mmul(xMat).diagAdd(reg).toArray2()), new FloatMatrix(xTrMat.mmul(yMat).toArray2())).toArray2());
	this.weights.setDontFree(true);
	
	CublasUtil.freeAll();
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:22,代码来源:GPULinearRegressor.java

示例2: calc

import org.jblas.Solve; //导入依赖的package包/类
public Matrix calc(Matrix source) {
	final DoubleMatrix m1;
	if (source instanceof JBlasDenseDoubleMatrix2D) {
		m1 = ((JBlasDenseDoubleMatrix2D) source).getWrappedObject();
	} else if (source instanceof HasColumnMajorDoubleArray1D) {
		m1 = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(source.getRowCount()), MathUtil.longToInt(source
				.getColumnCount()), ((HasColumnMajorDoubleArray1D) source).getColumnMajorDoubleArray1D())
				.getWrappedObject();
	} else {
		m1 = new JBlasDenseDoubleMatrix2D(source).getWrappedObject();
	}

	final DoubleMatrix I = DoubleMatrix.eye(m1.getRows());
	final DoubleMatrix result = Solve.solve(m1, I);
	return new JBlasDenseDoubleMatrix2D(result);
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:17,代码来源:Inv.java

示例3: solve

import org.jblas.Solve; //导入依赖的package包/类
public Matrix solve(Matrix a, Matrix b) {
	final DoubleMatrix a2;
	final DoubleMatrix b2;
	if (a instanceof JBlasDenseDoubleMatrix2D) {
		a2 = ((JBlasDenseDoubleMatrix2D) a).getWrappedObject();
	} else if (a instanceof HasColumnMajorDoubleArray1D) {
		a2 = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(a.getRowCount()), MathUtil.longToInt(a
				.getColumnCount()), ((HasColumnMajorDoubleArray1D) a).getColumnMajorDoubleArray1D())
				.getWrappedObject();
	} else {
		a2 = new JBlasDenseDoubleMatrix2D(a).getWrappedObject();
	}
	if (b instanceof JBlasDenseDoubleMatrix2D) {
		b2 = ((JBlasDenseDoubleMatrix2D) b).getWrappedObject();
	} else if (b instanceof HasColumnMajorDoubleArray1D) {
		b2 = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(b.getRowCount()), MathUtil.longToInt(b
				.getColumnCount()), ((HasColumnMajorDoubleArray1D) b).getColumnMajorDoubleArray1D())
				.getWrappedObject();
	} else {
		b2 = new JBlasDenseDoubleMatrix2D(b).getWrappedObject();
	}

	final DoubleMatrix x = Solve.solvePositive(a2, b2);
	return new JBlasDenseDoubleMatrix2D(x);
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:26,代码来源:Chol.java

示例4: solve

import org.jblas.Solve; //导入依赖的package包/类
public Matrix solve(Matrix a, Matrix b) {
	final DoubleMatrix a2;
	final DoubleMatrix b2;
	if (a instanceof JBlasDenseDoubleMatrix2D) {
		a2 = ((JBlasDenseDoubleMatrix2D) a).getWrappedObject();
	} else if (a instanceof HasColumnMajorDoubleArray1D) {
		a2 = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(a.getRowCount()), MathUtil.longToInt(a
				.getColumnCount()), ((HasColumnMajorDoubleArray1D) a).getColumnMajorDoubleArray1D())
				.getWrappedObject();
	} else {
		a2 = new JBlasDenseDoubleMatrix2D(a).getWrappedObject();
	}
	if (b instanceof JBlasDenseDoubleMatrix2D) {
		b2 = ((JBlasDenseDoubleMatrix2D) b).getWrappedObject();
	} else if (b instanceof HasColumnMajorDoubleArray1D) {
		b2 = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(b.getRowCount()), MathUtil.longToInt(b
				.getColumnCount()), ((HasColumnMajorDoubleArray1D) b).getColumnMajorDoubleArray1D())
				.getWrappedObject();
	} else {
		b2 = new JBlasDenseDoubleMatrix2D(b).getWrappedObject();
	}

	final DoubleMatrix x = Solve.solve(a2, b2);
	return new JBlasDenseDoubleMatrix2D(x);
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:26,代码来源:LU.java

示例5: calc

import org.jblas.Solve; //导入依赖的package包/类
public Matrix calc(Matrix source) {
	final DoubleMatrix m1;
	if (source instanceof JBlasDenseDoubleMatrix2D) {
		m1 = ((JBlasDenseDoubleMatrix2D) source).getWrappedObject();
	} else if (source instanceof HasColumnMajorDoubleArray1D) {
		m1 = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(source.getRowCount()), MathUtil.longToInt(source
				.getColumnCount()), ((HasColumnMajorDoubleArray1D) source).getColumnMajorDoubleArray1D())
				.getWrappedObject();
	} else {
		m1 = new JBlasDenseDoubleMatrix2D(source).getWrappedObject();
	}

	final DoubleMatrix I = DoubleMatrix.eye(m1.getRows());
	final DoubleMatrix result = Solve.solvePositive(m1, I);
	return new JBlasDenseDoubleMatrix2D(result);
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:17,代码来源:InvSPD.java

示例6: train

import org.jblas.Solve; //导入依赖的package包/类
public void train(TfIdf tfidf, DoubleMatrix trainMatrix)
    {
        if (tfidf == null)
        {
            throw new TrainingException("LSA training corpus should have TF-IDF type.");
        }
        log.info("Start to train LSA algorithm.");
        long st = System.currentTimeMillis();
        log.info("Training LSA...");
//        trainMatrix = trainMatrix.getRange(0, 400, 0, 500);
        DoubleMatrix[] USV = svd(trainMatrix);
        
        DoubleMatrix U = USV[0];
        DoubleMatrix S = USV[1];
//        DoubleMatrix V = USV[2];
        Uk = U.getRange(0, U.rows, 0, K); //m*k
        DoubleMatrix Sk = S.getRange(0, K, 0, K); //k*k
//        DoubleMatrix Vk = V.getRange(0, K, 0, V.columns);//k*n

        inverseS = Solve.pinv(Sk);
        preMatrix = trainMatrix.transpose().mmul(Uk).mmul(inverseS); //n*k
        preNorm = MatrixHelper.sqrt(preMatrix.mul(preMatrix).rowSums());
        log.info("Complete to train LSA.preMatrix(" + preMatrix.rows + "," + preMatrix.columns + ") InvS:" 
                            + inverseS.rows + "," + inverseS.columns + ")");
        log.info("LSA training cost " + (System.currentTimeMillis() - st) + "ms");
    }
 
开发者ID:liulhdarks,项目名称:darks-learning,代码行数:27,代码来源:LatentSemanticAnalysis.java

示例7: map

import org.jblas.Solve; //导入依赖的package包/类
@Override
public Factors map(Tuple2<Integer, Pair[]> integerTuple2) throws Exception {
	xtx.fill(0.0f);
	vector.fill(0.0f);

	int n = integerTuple2.f1.length;

	for(Pair p: integerTuple2.f1){
		FloatMatrix v = matrix.get(p.f0);

		ALSUtils.outerProductInPlace(v, xtx, numFactors);
		SimpleBlas.axpy(p.f1, v, vector);
	}

	ALSUtils.generateFullMatrix(xtx, fullMatrix, numFactors);

	for(int i =0; i < numFactors; i++){
		fullMatrix.data[i*numFactors + i] += (float)(n * lambda);
	}

	return new Factors(integerTuple2.f0, Solve.solvePositive(fullMatrix, vector).data);
}
 
开发者ID:project-flink,项目名称:flink-perf,代码行数:23,代码来源:ALSBroadcastJava.java

示例8: calculateTranslationMatrix

import org.jblas.Solve; //导入依赖的package包/类
public DoubleMatrix calculateTranslationMatrix (WordVectors ves, WordVectors ven) throws IOException {
	FileReader reader = new FileReader(dictionaryFile);
	BufferedReader bufReader = new BufferedReader(reader);
	String line = bufReader.readLine();
	String[] pair = line.split(dicseparator);
	int count = 0;
	String[] source_training_set = new String[dictionaryLength];
	String[] target_training_set = new String[dictionaryLength];
	// Reading dictionary from a text file where each line has the format term_in_language_A:equivalent_term_in_language_B
	while (line != null && count < dictionaryLength) {
		String wes = pair[0];
		String wen = pair[1];
		// If word not in source or target vector, then do not include in the source and target training vectors
		if (ves.hasWord(wes) && ven.hasWord(wen)) {
			source_training_set[count] = wes;
			target_training_set[count] = wen;
			count++;	
		}
		line = bufReader.readLine();
		pair = line.split(dicseparator);
	}
	bufReader.close();           
	// Generate vector matrix for source and target training sets. For simplification, assuming dimension of target vectors is equal to the dimension of the source vectors. Some (minimal) changes may be required otherwise
	// WX=Z -> W=transpose(pinv(X)Z)
	DoubleMatrix matrix_train_source = createVectorMatrix(source_training_set, ves);
	DoubleMatrix matrix_train_target = createVectorMatrix(target_training_set, ven);
	DoubleMatrix pinverse_matrix = Solve.pinv(matrix_train_source);
	DoubleMatrix translationMatrix = pinverse_matrix.mmul(matrix_train_target).transpose();
	return translationMatrix;
}
 
开发者ID:josemanuelgp,项目名称:word2vec_vector-translation-java,代码行数:31,代码来源:VectorTranslation.java

示例9: train

import org.jblas.Solve; //导入依赖的package包/类
public void train(float[][] xraw, float[][] yraw) {
	float[][] x = new float[xraw.length][];
	for (int i=0; i<xraw.length; ++i) {
		x[i] = a.append(1.0f, xraw[i]);
	}
	float[][] y = yraw;
	
	FloatMatrix yMat = new FloatMatrix(y);
	FloatMatrix xMat = new FloatMatrix(x);
	FloatMatrix xTrMat = xMat.transpose();
	
	weights = Solve.solvePositive(xTrMat.mmul(xMat).add(FloatMatrix.eye(x[0].length).mmul(reg)), xTrMat.mmul(yMat));
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:14,代码来源:LinearRegressor.java

示例10: train

import org.jblas.Solve; //导入依赖的package包/类
public void train(float[][] x, float[][] y) {
	this.x = x;
	FloatMatrix K = new FloatMatrix(kernelBuilder.build(x, x));
	CublasUtil.freeAll();
	this.Kcolsum = K.rowSums();
	this.Ksum = Kcolsum.sum();
	K.addiColumnVector(Kcolsum.mul(-1.0f/x.length));
	K.addiRowVector(Kcolsum.transpose().mul(-1.0f/x.length));
	K.addi(Ksum/(x.length*x.length));
	
	K.addi(FloatMatrix.eye(x.length).muli(reg));
	alpha = Solve.solvePositive(K, new FloatMatrix(y)).transpose();
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:14,代码来源:KernelLinearRegressor.java

示例11: multivariateGaussian

import org.jblas.Solve; //导入依赖的package包/类
/**
 * 计算多元高斯分布概率
 * 
 * @return 多元高斯分布概率
 */
public FloatMatrix multivariateGaussian(FloatMatrix matrix) {

	int k = mu.length;
	FloatMatrix sigma2 = sigma.dup();
	if (sigma2.rows == 1 || sigma2.columns == 1)
		sigma2 = FloatMatrix.diag(sigma2);

	FloatMatrix x1 = matrix.subRowVector(mu);
	float v1 = (float) MatrixFunctions.pow(2 * Math.PI, (float) -k / 2);
	float v2 = MatrixFunctions.pow(MatrixUtil.det(sigma2), -0.5f);
	FloatMatrix v3 = MatrixFunctions.exp(x1.mmul(Solve.pinv(sigma2)).mul(x1).rowSums().mmul(-0.5f));

	return v3.mmul(v1 * v2);
}
 
开发者ID:XSoftlab,项目名称:ml4j,代码行数:20,代码来源:AnomalyDetection.java

示例12: call

import org.jblas.Solve; //导入依赖的package包/类
@Override
public byte[] call(final byte[] memento) throws Exception {

  LOG.log(Level.FINEST, "UnwhitenMasterTask started");

  final DoubleMatrix A = this.env.getA();     // k*k
  final DoubleMatrix W = this.env.getOmega(); // d*k
  final DoubleMatrix lambda = this.env.getLambda();

  LOG.log(Level.FINEST, "UnwhitenMasterTask: W = {0}", W);

  final DoubleMatrix alphaHat = DoubleMatrix.ones(this.dimK).divi(lambda).divi(lambda);
  final DoubleMatrix prior = alphaHat.div(alphaHat.sum());
  final DoubleMatrix alpha = prior.mul(this.alpha0);

  final DoubleMatrix F =
      W.mmul(Solve.solvePositive(W.transpose().mmul(W), A.mmul(DoubleMatrix.diag(lambda))));

  LOG.log(Level.FINEST, "UnwhitenMasterTask F = {0}", F);

  final DoubleMatrix z = DoubleMatrix.zeros(W.rows, A.columns);

  for (int i = 0; i < A.columns; ++i) {
    final DoubleMatrix col = F.getColumn(i);
    final DoubleMatrix v1 = unwhitenTopic(col);
    final DoubleMatrix v2 = unwhitenTopic(col.neg());
    z.putColumn(i, v1.sub(col).norm2() < v2.add(col).norm2() ? v1 : v2);
  }

  LOG.log(Level.FINEST, "UnwhitenMasterTask complete: z = {0}", z);

  this.hdfsIO.writeMatrix(alpha, this.outputPath + ".alpha");
  this.hdfsIO.writeMatrix(z, this.outputPath + ".beta");

  return null;
}
 
开发者ID:Microsoft-CISL,项目名称:TensorFactorization-LDA,代码行数:37,代码来源:UnwhitenMasterTask.java

示例13: testSVD

import org.jblas.Solve; //导入依赖的package包/类
@Test
public void testSVD()
{
	double[][] testData = { 
			{ 36, 49, 47, 11 }, 
			{ 2, 68, 27, 42 }, 
			{ 42, 25, 38, 3 } 
		};
	RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
	SingularValueDecomposition svd = new SingularValueDecomposition(matrix);
       System.out.println(svd.getU());
       System.out.println(svd.getS());
       System.out.println(svd.getV());
	
	DoubleMatrix[] usv = Singular.fullSVD(new DoubleMatrix(testData));
       System.out.println(usv[0]);
       System.out.println(usv[1]);
       System.out.println(usv[2]);

       DoubleMatrix U = usv[0];
       DoubleMatrix S = usv[1];
       DoubleMatrix V = usv[2];
       DoubleMatrix mt = new DoubleMatrix(3, 4);
       for (int i = 0; i < S.length; i++)
       {
           mt.put(i, i, S.get(i));
       }
       System.out.println(mt.toString().replace(";", "\n"));
       DoubleMatrix src = U.mmul(mt).mmul(V.transpose());
       System.out.println(src.toString().replace(";", "\n"));
       mt = Solve.pinv(mt);
       System.out.println(mt.toString().replace(";", "\n"));
}
 
开发者ID:liulhdarks,项目名称:darks-learning,代码行数:34,代码来源:MathTest.java

示例14: performBuild

import org.jblas.Solve; //导入依赖的package包/类
@Override
protected void performBuild() 
{
	this.colToAddCache = new MaxSizeHashMap<Integer, DoubleMatrix>(100000, 10000);
	this.rowToAddCache = new MaxSizeHashMap<Integer, DoubleMatrix>(100000, 10000);
	//initializing observable matrices
	hist = new DoubleMatrix(projDim+1, 1);
	th = new DoubleMatrix(projDim, projDim+1);
	estimateHistoryAndTHMatrices();
	//		th.muli(1.0/((double)resetCount));
	//		hist.muli(1.0/((double)resetCount));

	svdResults = computeTruncatedSVD(th, minSingularVal, maxDim);
	pseudoInverse = svdResults[2].mmul(Solve.pinv(svdResults[1]));
	trainData.resetData();
	aoMats = new HashMap<ActionObservation, DoubleMatrix>();
	for(ActionObservation actOb : trainData.getValidActionObservationSet())
	{
		aoMats.put(actOb, new DoubleMatrix(pseudoInverse.getColumns(), pseudoInverse.getColumns()));
	}
	constructAOMatrices();
	//		for(ActionObservation actOb : trainData.getValidActionObservationSet())
	//		{
	//			aoMats.put(actOb, aoMats.get(actOb).muli(1.0/((double)resetCount)));
	//		}
	resetCount=0;

	mInf = new Minf(((hist.transpose()).mmul(pseudoInverse)).transpose());
	pv = new PredictionVector(svdResults[1].mmul(svdResults[2].transpose()).getColumn(0));
}
 
开发者ID:williamleif,项目名称:PSRToolbox,代码行数:31,代码来源:MemEffCPSR.java

示例15: performBuild

import org.jblas.Solve; //导入依赖的package包/类
@Override
	protected void performBuild() 
	{
		//initializing observable matrices
		hist = new DoubleMatrix(hPhi.getColumns(), 1);
		th = new DoubleMatrix(tPhi.getRows(), hPhi.getColumns());
		estimateHistoryAndTHMatrices();
//		th.muli(1.0/((double)resetCount));
//		hist.muli(1.0/((double)resetCount));
		
		svdResults = computeTruncatedSVD(th, minSingularVal, maxDim);
		pseudoInverse = svdResults[2].mmul(Solve.pinv(svdResults[1]));
		trainData.resetData();
		aoMats = new HashMap<ActionObservation, DoubleMatrix>();
		for(ActionObservation actOb : trainData.getValidActionObservationSet())
		{
			aoMats.put(actOb, new DoubleMatrix(pseudoInverse.getColumns(), pseudoInverse.getColumns()));
		}
		aoColAddMat = (svdResults[0].mmul(tPhi));
		aoRowAddMat = (hPhi.mmul(pseudoInverse));
		constructAOMatrices();
//		for(ActionObservation actOb : trainData.getValidActionObservationSet())
//		{
//			aoMats.put(actOb, aoMats.get(actOb).muli(1.0/((double)resetCount)));
//		}
		resetCount=0;
	
		mInf = new Minf(((hist.transpose()).mmul(pseudoInverse)).transpose());
		pv = new PredictionVector(svdResults[0].mmul(th).mmul(e));
	}
 
开发者ID:williamleif,项目名称:PSRToolbox,代码行数:31,代码来源:CPSR.java


注:本文中的org.jblas.Solve类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。