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


Java Singular.sparseSVD方法代码示例

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


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

示例1: computeTruncatedSVD

import org.jblas.Singular; //导入方法依赖的package包/类
protected DoubleMatrix[] computeTruncatedSVD(DoubleMatrix mat, Double singValTol, int maxSize)
{
	DoubleMatrix[] svdResult = Singular.sparseSVD(mat);
	
	notifyPSRObservers(svdResult[1].toArray());
	
	int singIter;
	for(singIter = 0; singIter < svdResult[1].getRows(); singIter++)
	{
		if(svdResult[1].get(singIter,0) < singValTol)
			break;
	}
	
	int numToKeep = Math.min(singIter, maxSize);
	maxDim = numToKeep;
			
	DoubleMatrix u = new DoubleMatrix(mat.getRows(),numToKeep);
	u = svdResult[0].getRange(0,svdResult[0].getRows(), 0, numToKeep);
	DoubleMatrix s = DoubleMatrix.diag(svdResult[1].getRange(0, numToKeep, 0, 1));
	DoubleMatrix v = new DoubleMatrix(mat.getColumns(), numToKeep);
	v = svdResult[2].getRange(0, svdResult[2].getRows(), 0, numToKeep);
	
	DoubleMatrix[] truncatedSVDResult = {u.transpose(),s,v};
	return truncatedSVDResult;
}
 
开发者ID:williamleif,项目名称:PSRToolbox,代码行数:26,代码来源:TPSR.java

示例2: computeMapping

import org.jblas.Singular; //导入方法依赖的package包/类
private DoubleMatrix computeMapping(DoubleMatrix x) {
    DoubleMatrix alphas = MatrixFunctions.pow(
            MatrixFunctions.pow(
                    this.highDimControlPoints.subRowVector(x),
                    2
            ).rowSums(),
            -1
    );
    double alpha = alphas.sum();

    DoubleMatrix xTilde = this.highDimControlPoints.mulColumnVector(alphas).columnSums().div(alpha);
    DoubleMatrix yTilde = this.lowDimControlPoints.mulColumnVector(alphas).columnSums().div(alpha);
    DoubleMatrix xHats = this.highDimControlPoints.subRowVector(xTilde);
    @SuppressWarnings("SuspiciousNameCombination")
    DoubleMatrix yHats = this.lowDimControlPoints.subRowVector(yTilde);

    DoubleMatrix sqrtAlphas = MatrixFunctions.sqrt(alphas);
    DoubleMatrix A = xHats.mulColumnVector(sqrtAlphas);
    DoubleMatrix B = yHats.mulColumnVector(sqrtAlphas);

    DoubleMatrix[] svdComposition = Singular.sparseSVD(A.transpose().mmul(B));
    DoubleMatrix U = svdComposition[0];
    DoubleMatrix V = svdComposition[2];

    DoubleMatrix M = U.mmul(V);

    return x.sub(xTilde).mmul(M).add(yTilde);
}
 
开发者ID:vmware,项目名称:hillview,代码行数:29,代码来源:LAMPMap.java

示例3: CPSR

import org.jblas.Singular; //导入方法依赖的package包/类
public CPSR(TrainingDataSet trainData, double minSingularVal, int maxSVDDim, int projDim, int maxHistLen, ProjType projType, boolean histCompress, boolean randStart)
{
	super(trainData, minSingularVal, maxSVDDim, maxHistLen);
	this.projType = projType;
	this.histCompress = histCompress;
	this.projDim = projDim;

	tPhi = constructRandomMatrix(projType, projDim, tests.size(), projDim);
	if(!histCompress)
	{
		hPhi = constructRandomMatrix(ProjType.Eye,histories.size()+1,histories.size()+1, 1.0);
	}
	else
	{
		hPhi = constructRandomMatrix(projType,histories.size()+1,projDim, projDim);
	}

	DoubleMatrix one = DoubleMatrix.zeros(histories.size()+1, 1);
	this.randStart = randStart;

	one.put(0,0, 1.0);
	if(randStart)
	{
		for(int i = 0; i < one.getRows(); i++)
			one.put(i,0,1.0);
	}

	if(histCompress)
	{
		DoubleMatrix[] hPhiSVD = Singular.sparseSVD(hPhi);
		DoubleMatrix sigma = DoubleMatrix.diag(hPhiSVD[1]);


		e = hPhiSVD[2].mmul(Solve.pinv(sigma)).mmul(hPhiSVD[0].transpose());
		
		e = e.mmul(one);
	}
	else
	{
		e = one;
	}
	
	
}
 
开发者ID:williamleif,项目名称:PSRToolbox,代码行数:45,代码来源:CPSR.java

示例4: updateSVD

import org.jblas.Singular; //导入方法依赖的package包/类
protected DoubleMatrix[] updateSVD(DoubleMatrix newTHData)
{
	DoubleMatrix biggerV = DoubleMatrix.concatVertically(svdResults[2],
			DoubleMatrix.zeros(newTHData.getColumns()-svdResults[2].getRows(), svdResults[2].getColumns()));
	
	DoubleMatrix m = svdResults[0].mmul(newTHData);
	DoubleMatrix p = newTHData.sub((svdResults[0].transpose()).mmul(m));
	
	DoubleMatrix pBase = Singular.sparseSVD(p)[0];
	pBase = DoubleMatrix.concatHorizontally(pBase, DoubleMatrix.zeros(pBase.getRows(), p.getColumns()-pBase.getColumns()));
	DoubleMatrix rA = (pBase.transpose()).mmul(p);
	
	DoubleMatrix n = (biggerV.transpose()).mmul(DoubleMatrix.eye(newTHData.getColumns()));
	DoubleMatrix q = DoubleMatrix.eye(newTHData.getColumns()).sub(biggerV.mmul(n));
	
	DoubleMatrix qBase = Singular.sparseSVD(q)[0];
	DoubleMatrix rB = (qBase.transpose()).mmul(q);
	
	DoubleMatrix z = DoubleMatrix.zeros(m.getRows(), m.getColumns());
	DoubleMatrix z2 = DoubleMatrix.zeros(m.getColumns(),m.getColumns());
	
	DoubleMatrix top = DoubleMatrix.concatHorizontally(svdResults[1],z);
	DoubleMatrix bottom = DoubleMatrix.concatHorizontally(z.transpose(),z2);
	DoubleMatrix comb = DoubleMatrix.concatVertically(top, bottom);
	
	DoubleMatrix mRA = DoubleMatrix.concatVertically(m, rA);
	DoubleMatrix nRB = DoubleMatrix.concatVertically(n, rB);

	DoubleMatrix mRANRB = mRA.mmul(nRB.transpose());
	DoubleMatrix k = comb.add(mRANRB);
	
	DoubleMatrix[] newBases = computeTruncatedSVD(k, Double.MIN_VALUE, maxDim);
			
	DoubleMatrix uP = (DoubleMatrix.concatHorizontally(svdResults[0].transpose(), p)).mmul(newBases[0].transpose());
	DoubleMatrix vP = (DoubleMatrix.concatHorizontally(biggerV,q)).mmul(newBases[2]);
	
	DoubleMatrix[] updatedSVDResults = new DoubleMatrix[3];
	
	updatedSVDResults[0] = uP.transpose();
	updatedSVDResults[1] = newBases[1];
	updatedSVDResults[2] = vP;
	
	double[] singVals = new double[updatedSVDResults[1].getRows()];
	for(int i = 0; i < updatedSVDResults[1].getRows(); i++)
		singVals[i] = updatedSVDResults[1].get(i,i);
			
	return updatedSVDResults;
}
 
开发者ID:williamleif,项目名称:PSRToolbox,代码行数:49,代码来源:TPSR.java


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