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


Java Singular.fullSVD方法代码示例

本文整理汇总了Java中org.jblas.Singular.fullSVD方法的典型用法代码示例。如果您正苦于以下问题:Java Singular.fullSVD方法的具体用法?Java Singular.fullSVD怎么用?Java Singular.fullSVD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jblas.Singular的用法示例。


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

示例1: calc

import org.jblas.Singular; //导入方法依赖的package包/类
public Matrix[] calc(Matrix source) {
	final DoubleMatrix matrix;
	if (source instanceof JBlasDenseDoubleMatrix2D) {
		matrix = ((JBlasDenseDoubleMatrix2D) source).getWrappedObject();
	} else if (source instanceof HasColumnMajorDoubleArray1D) {
		matrix = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(source.getRowCount()), MathUtil.longToInt(source
				.getColumnCount()), ((HasColumnMajorDoubleArray1D) source).getColumnMajorDoubleArray1D())
				.getWrappedObject();
	} else {
		matrix = new JBlasDenseDoubleMatrix2D(source).getWrappedObject();
	}
	final DoubleMatrix[] svd = Singular.fullSVD(matrix);
	final Matrix u = new JBlasDenseDoubleMatrix2D(svd[0]);
	DoubleMatrix sVector = svd[1];
	final Matrix s = new JBlasDenseDoubleMatrix2D(MathUtil.longToInt(source.getRowCount()),
			MathUtil.longToInt(source.getColumnCount()));
	for (int i = 0; i < sVector.rows; i++) {
		s.setAsDouble(sVector.get(i), i, i);
	}
	final Matrix v = new JBlasDenseDoubleMatrix2D(svd[2]);
	return new Matrix[] { u, s, v };
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:23,代码来源:SVD.java

示例2: pca

import org.jblas.Singular; //导入方法依赖的package包/类
/**
 * 
 * 
 * @param A
 * @param dim
 * @return
 */
public DoubleMatrix pca(DoubleMatrix A, int dim) {
	
	logger.info("Type 'pca' started (target dimensions = "+dim+").");
	
	A = centerData(A);
	save("A", A);
	
	logger.info("Computing SVD...");
	DoubleMatrix[] usv = Singular.fullSVD(A);
	DoubleMatrix U = usv[0];
	DoubleMatrix S = usv[1];
	
	save("U", U);
	save("S", S);
	
	// 
	logger.info("Reducing U to Uk...");
	DoubleMatrix Uk = new DoubleMatrix(U.rows, dim);
	for(int i=0; i<dim; i++)
		Uk.putColumn(i, U.getColumn(i));
	save("Uk", Uk);
	
	// build S matrix
	logger.info("Reducing S to Sk...");
	DoubleMatrix Sk = new DoubleMatrix(dim, dim);
	for (int i = 0; i < dim; i++) {
		Sk.put(i, i, S.get(i));
	}
	save("Sk", Sk);
	
	// calculate principal component matrix...
	logger.info("Computing principal components...");
	DoubleMatrix B = Uk.mmul(Sk);
	save("B", B);
	
	return B;
	
}
 
开发者ID:AKSW,项目名称:Resource2Vec,代码行数:46,代码来源:JblasSVD.java

示例3: compress

import org.jblas.Singular; //导入方法依赖的package包/类
/**
 * @param A
 * @param k
 * @return
 */
public DoubleMatrix compress(DoubleMatrix A, int k) {
	
	logger.info("Type 'compress' started...");

	A = centerData(A);
	
	DoubleMatrix[] usv = Singular.fullSVD(A);
	// n x n
	DoubleMatrix U = usv[0];
	// n x p
	DoubleMatrix S = usv[1];
	// p x p (straight)
	DoubleMatrix V = usv[2];
			
	// k x k
	DoubleMatrix Sk = new DoubleMatrix(U.columns, V.columns);
	for (int i = 0; i < k; i++) {
		Sk.put(i, i, S.get(i));
	}
	
	// 
	DoubleMatrix Aapprox = U.mmul(Sk).mmul(V.transpose());
	save("Aapprox", Aapprox);
	
	return Aapprox;
	
}
 
开发者ID:AKSW,项目名称:Resource2Vec,代码行数:33,代码来源:JblasSVD.java

示例4: reconstruct2

import org.jblas.Singular; //导入方法依赖的package包/类
public DoubleMatrix reconstruct2(DoubleMatrix A, int k) {
		
		logger.info("Type 'reconstruct2' started...");

		A = centerData(A);
		save("A", A);
		
		DoubleMatrix[] usv = Singular.fullSVD(A);
		// n x n
		DoubleMatrix U = usv[0];
		// n x p
		DoubleMatrix S = usv[1];
		// p x p (straight)
		DoubleMatrix V = usv[2];
		
		save("U", U);
		save("S", S);
		save("V", V);
		
		for(int i = k; i < U.columns; i++)
			U.putColumn(i, DoubleMatrix.zeros(U.rows, 1));
		save("Uk", U);
		
		DoubleMatrix Sm = new DoubleMatrix(A.rows, A.columns);
		for (int i = 0; i < k; i++) {
			Sm.put(i, i, S.get(i));
		}
		save("Sk", Sm);
		
//		for (int i = k; i < V.rows; i++) {
//			V.putColumn(i, DoubleMatrix.zeros(1, V.columns));
//		}
//		visual("Vk", V);
 		
		// 
		DoubleMatrix Aapprox = U.mmul(Sm).mmul(V.transpose());
		save("Aapprox", Aapprox);
				
		return Aapprox;
	}
 
开发者ID:AKSW,项目名称:Resource2Vec,代码行数:41,代码来源:JblasSVD.java

示例5: PCA

import org.jblas.Singular; //导入方法依赖的package包/类
/**
 * 初始化PCA
 * 
 * @param x 特征矩阵
 */
public PCA(FloatMatrix x) {
	super();
	this.x = x;

	this.m = x.rows;
	FloatMatrix Sigma = x.transpose().mmul(x).div(m);
	FloatMatrix[] result = Singular.fullSVD(Sigma);

	this.u = result[0].neg();// 与matlab保持一致
	this.s = result[1];
}
 
开发者ID:XSoftlab,项目名称:ml4j,代码行数:17,代码来源:PCA.java

示例6: pinv

import org.jblas.Singular; //导入方法依赖的package包/类
public static DoubleMatrix pinv(final DoubleMatrix A) {
  final DoubleMatrix[] usv = Singular.fullSVD(A);
  final DoubleMatrix s_inv = new DoubleMatrix(usv[1].length);
  for (int i = 0; i < usv[1].length; i++) {
    s_inv.put(i, Math.abs(usv[1].get(i)) < TOLERANCE ? 0.0 : 1.0 / usv[1].get(i));
  }
  return usv[2].mmul(DoubleMatrix.diag(s_inv)).mmul(usv[0].transpose());
}
 
开发者ID:Microsoft-CISL,项目名称:TensorFactorization-LDA,代码行数:9,代码来源:TensorUtil.java

示例7: svd

import org.jblas.Singular; //导入方法依赖的package包/类
public static DoubleMatrix[] svd(DoubleMatrix src)
{
    DoubleMatrix[] usv = Singular.fullSVD(src);
       DoubleMatrix S = usv[1];
       usv[1] = convertDiagMatrix(S, src.rows, src.columns);
       return usv;
}
 
开发者ID:liulhdarks,项目名称:darks-learning,代码行数:8,代码来源:MatrixHelper.java

示例8: testSVD

import org.jblas.Singular; //导入方法依赖的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

示例9: reconstruct

import org.jblas.Singular; //导入方法依赖的package包/类
/**
 * @param A
 * @param k
 * @return
 */
public DoubleMatrix reconstruct(DoubleMatrix A, int k) {
	
	logger.info("Type 'reconstruct' started...");

	A = centerData(A);
	save("A", A);
	
	DoubleMatrix[] usv = Singular.fullSVD(A);
	// n x n
	DoubleMatrix U = usv[0];
	// n x p
	DoubleMatrix S = usv[1];
	// p x p (straight)
	DoubleMatrix V = usv[2];
	
	save("U", U);
	save("S", S);
	save("V", V);
	
	// n x k
	DoubleMatrix Uk = new DoubleMatrix(U.rows, k);
	for(int i=0; i<k; i++)
		Uk.putColumn(i, U.getColumn(i));
	save("Uk", Uk);
	
	// k x k
	DoubleMatrix Sk = new DoubleMatrix(k, k);
	for (int i = 0; i < k; i++) {
		Sk.put(i, i, S.get(i));
	}
	save("Sk", Sk);
	
	// p x k (straight)
	DoubleMatrix Vk = new DoubleMatrix(A.columns, k);
	for (int i = 0; i < k; i++) {
		Vk.putColumn(i, V.getColumn(i));
	}
	save("Vk", Vk);
		
	// 
	DoubleMatrix Aapprox = Uk.mmul(Sk).mmul(Vk.transpose());
	save("Aapprox", Aapprox);
	
	DoubleMatrix Areduced = new DoubleMatrix(A.rows, k);
	for(int i=0; i<k; i++)
		Areduced.putColumn(i, Aapprox.getColumn(i));
	save("C"+k, Areduced);
	
	return Areduced;
	
}
 
开发者ID:AKSW,项目名称:Resource2Vec,代码行数:57,代码来源:JblasSVD.java


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