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


Java DoubleMatrix.mmul方法代码示例

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


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

示例1: JBLASExample

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public void JBLASExample() {
    DoubleMatrix A = new DoubleMatrix(new double[][]{
        {0.1950, 0.0311},
        {0.3588, 0.2203},
        {0.1716, 0.5931},
        {0.2105, 0.3242}});

    DoubleMatrix B = new DoubleMatrix(new double[][]{
        {0.0502, 0.9823, 0.9472},
        {0.5732, 0.2694, 0.916}});
    DoubleMatrix C;

    C = A.mmul(B);

    for (int i = 0; i < C.getRows(); i++) {
        out.println(C.getRow(i));
    }
}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:19,代码来源:MathExamples.java

示例2: run

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public int[] run()
{
    int hash_idx = -1;
    for(DoubleMatrix projection : m_projection_matrix)
    {
        assert(projection.columns == m_query.rows);
        DoubleMatrix dotProduct = projection.mmul(m_query);

        int signature = 0;
        for(int idx = 0; idx < dotProduct.length; ++idx)
        {
            signature |= sign(dotProduct.get(idx));
            signature <<= 1;
        }
        m_hashes[++hash_idx] = signature;
    }
    return m_hashes;
}
 
开发者ID:rdspring1,项目名称:LSH_DeepLearning,代码行数:19,代码来源:RandomProjection.java

示例3: testSimpleMatrix

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testSimpleMatrix() {
    // Setting elements
    DoubleMatrix mat = new DoubleMatrix(2, 2);
    mat.put(0, 0, 2.3);
    mat.put(1, 0, 42.42);
    mat.put(0, 1, 3.14);
    mat.put(1, 1, 3.91992);
    Assert.assertEquals(mat.get(0, 0), 2.3, Math.ulp(2.3));
    Assert.assertEquals(mat.get(1, 0), 42.42, Math.ulp(42.42));
    Assert.assertEquals(mat.get(0, 1), 3.14, Math.ulp(3.14));
    Assert.assertEquals(mat.get(1, 1), 3.91992, Math.ulp(3.91992));

    // Matrix multiplied with its transpose should be symmetric.
    DoubleMatrix symMat = mat.mmul(mat.transpose());
    for (int i = 0; i < symMat.rows; i++) {
        for (int j = 0; j < symMat.columns; j++) {
            Assert.assertEquals(symMat.get(i, j), symMat.get(j, i), Math.ulp(symMat.get(i, j)));
        }
    }
}
 
开发者ID:vmware,项目名称:hillview,代码行数:22,代码来源:MatrixTest.java

示例4: testProjection

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testProjection() {
    int cols = 20;
    int rows = 2000;
    int numProjections = 8;
    Random.seed(42);
    DoubleMatrix matrix = DoubleMatrix.rand(rows, cols);
    DoubleMatrix projectionMatrix = DoubleMatrix.rand(numProjections, cols);
    ITable table = BlasConversions.toTable(matrix);
    LinearProjectionMap lpm = new LinearProjectionMap(
            table.getSchema().getColumnNames(), projectionMatrix,
            "LP");
    ITable result = lpm.apply(table);

    String[] newColNames = new String[numProjections];
    for (int i = 0; i < numProjections; i++) {
        newColNames[i] = String.format("LP%d", i);
    }

    DoubleMatrix projectedData = BlasConversions.toDoubleMatrix(result, newColNames);
    DoubleMatrix projectedDataCheck = matrix.mmul(projectionMatrix.transpose());
    Assert.assertEquals(rows * numProjections, projectedData.eq(projectedDataCheck).sum(), Math.ulp(rows * cols));
}
 
开发者ID:vmware,项目名称:hillview,代码行数:24,代码来源:LinearProjectionTest.java

示例5: learnWhiteningMatrix

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public void learnWhiteningMatrix(ArrayList<T> data) {
	this.means = getMeans(data);
	DoubleMatrix X = new DoubleMatrix(data.size(), this.dimension);
	// Center observations w.r.t. their means
	int row = 0;
	for(T t : data) {
		DoubleMatrix x_i = this.getOutput(t);
		X.putRow(row++, x_i.subi(means, x_i).transpose());
	}
	// Sphericize data
	DoubleMatrix M = X.transpose().mmul(X);
	M.divi(data.size(), M);
	DoubleMatrix[] ED = Eigen.symmetricEigenvectors(M);
	DoubleMatrix E = ED[0];
	DoubleMatrix D = ED[1];

	//DoubleMatrix D_invrt = Solve.pinv(sqrt(D));
	DoubleMatrix D_invrt = diagPow(D, -0.5);
	
	this.whitener = E.mmul(D_invrt);
	this.wasWhitened = true;
	
	checkSampleCovariance(X.mmul(this.whitener));
	
	//DoubleMatrix X_std = X.mmul(E).mmul(D_invrt);
}
 
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:27,代码来源:InputLayer.java

示例6: computeMapping

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

示例7: apply

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
public ITable apply(ITable table) {
    IColumn[] columns = new IColumn[this.newColNames.length];
    // Compute the projection with BLAS
    DoubleMatrix mat = BlasConversions.toDoubleMatrix(table, this.colNames);
    DoubleMatrix resultMat = mat.mmul(this.projectionMatrix.transpose());

    // Copy the result to new columns with the same membershipSet size. (Can't use
    // BlasConversions here.)
    for (int j = 0; j < this.numProjections; j++) {
        ColumnDescription colDesc = new ColumnDescription(
                this.newColNames[j], ContentsKind.Double, true);
        IMembershipSet set = table.getMembershipSet();
        int colSize = table.getMembershipSet().getMax();
        IMutableColumn column;
        if (set.useSparseColumn(set.getSize()))
            column = new SparseColumn(colDesc, colSize);
        else
            column = new DoubleArrayColumn(colDesc, colSize);
        IRowIterator it = table.getMembershipSet().getIterator();
        int row = it.getNextRow();
        int i = 0;
        while (row >= 0) {
            if (Double.isNaN(resultMat.get(i, j))) {
                column.setMissing(row);
            } else {
                column.set(row, resultMat.get(i, j));
            }
            row = it.getNextRow();
            i++;
        }
        columns[j] = column;
    }

    return table.append(columns);
}
 
开发者ID:vmware,项目名称:hillview,代码行数:37,代码来源:LinearProjectionMap.java

示例8: testDatasetProjection

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testDatasetProjection() {
    int rows = 10000;
    int cols = 20;
    int numProjections = 2;
    DoubleMatrix dataMatrix = DoubleMatrix.rand(rows, cols);
    DoubleMatrix projectionMatrix = DoubleMatrix.rand(numProjections, cols);
    DoubleMatrix projectionCheck = dataMatrix.mmul(projectionMatrix.transpose());

    ITable bigTable = BlasConversions.toTable(dataMatrix);
    String[] colNames = bigTable.getSchema().getColumnNames();
    // Convert it to an IDataset
    IDataSet<ITable> all = TestTables.makeParallel(bigTable, rows / 10);

    LinearProjectionMap lpm = new LinearProjectionMap(colNames, projectionMatrix, "LP");
    IDataSet<ITable> result = all.blockingMap(lpm);

    for (int i = 0; i < numProjections; i++) {
        BasicColStatSketch b = new BasicColStatSketch(
                new ColumnAndConverterDescription(String.format("LP%d", i)), 1, 1, 0);
        BasicColStats bcs = result.blockingSketch(b);
        double expectedMean = projectionCheck.get(new AllRange(), i).mean();
        double actualMean = bcs.getMoment(1);
        double eps = actualMean * 1e-6;
        Assert.assertTrue("Mean is too far from actual mean", Math.abs(actualMean - expectedMean) < eps);

        double expectedMin = projectionCheck.get(new AllRange(), i).min();
        double actualMin = bcs.getMin();
        eps = actualMin * 1e-6;
        Assert.assertTrue("Min is too far from actual min", Math.abs(actualMin - expectedMin) < eps);

        double expectedMax = projectionCheck.get(new AllRange(), i).max();
        double actualMax = bcs.getMax();
        eps = actualMax* 1e-6;
        Assert.assertTrue("Max is too far from actual min", Math.abs(actualMax - expectedMax) < eps);
    }
}
 
开发者ID:vmware,项目名称:hillview,代码行数:38,代码来源:LinearProjectionTest.java

示例9: pca

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

示例10: coalesceDown

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
private void coalesceDown(int currTreeInterval) {
		List<Node> parentLines = mascotInput.get().treeIntervalsInput.get().getLineagesAdded(currTreeInterval);
		if (parentLines.size()!=1){
			System.err.println("to many lineages, while coalescening down");
			System.exit(0);
		}
		Node parentNode = parentLines.get(0);
		
		if (!parentNode.isRoot()){
			DoubleMatrix start = stateProbabilities[parentNode.getNr() - nrSamples];
			DoubleMatrix end = stateProbabilitiesDown[parentNode.getParent().getNr() - nrSamples];
			DoubleMatrix flow = TransitionProbabilities[parentNode.getNr()];
			DoubleMatrix otherSideInfo = end.div(start.transpose().mmul(flow));
			// get rid of NaN from division by 0
			for (int i = 0; i < otherSideInfo.length; i++)
				if (Double.isNaN(otherSideInfo.get(i)))
					otherSideInfo.put(i, 0.0);
				
				
				
			DoubleMatrix conditional = flow.mmul(otherSideInfo);
			conditional = conditional.mul(start);
			stateProbabilitiesDown[parentNode.getNr() - nrSamples] = conditional.div(conditional.sum());
//			if (!(conditional.get(0) >= 0.0 && conditional.get(0)<=1.0))
//				conditional.print();
		}else{
//			DoubleMatrix d1 = stateProbabilities[parentNode.getLeft().getNr() - nrSamples];
//			DoubleMatrix d2 = stateProbabilities[parentNode.getRight().getNr() - nrSamples];
//			DoubleMatrix f1 = TransitionProbabilities[parentNode.getLeft().getNr()];
//			DoubleMatrix f2 = TransitionProbabilities[parentNode.getLeft().getNr()];
//			d1.transpose().mmul(f1).print();
//			d2.transpose().mmul(f2).print();
//			d1.print();
//			d2.print();
//			System.out.println();
//			f1.print();
//			f2.print();
//			System.out.println();
//			stateProbabilities[parentNode.getNr() - nrSamples].print();
//			
//			System.out.println();
//			System.exit(0);
			stateProbabilitiesDown[parentNode.getNr() - nrSamples] = stateProbabilities[parentNode.getNr() - nrSamples];
    	}
	}
 
开发者ID:nicfel,项目名称:Mascot,代码行数:46,代码来源:StructuredTreeLogger.java

示例11: computeDerivatives

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
public void computeDerivatives(double h, double[] ql, double[] dql)
		throws MaxCountExceededException, DimensionMismatchException {
	
	int tsPointCurrent = ts.getTimePoint(tsTimes0-h, tsPointLast);
	
	tsPointLast = tsPointCurrent;
	DoubleMatrix Y = ts.getYs()[tsPointCurrent];
	DoubleMatrix F = ts.getFs()[tsPointCurrent];
	DoubleMatrix G = ts.getGs()[tsPointCurrent];
	
	if (forgiveY) Y.maxi(1.0); else Y.maxi(MIN_Y);
			
	int i;
	for(i=0; i < numStatesSQ; i++) qdata[i] = ql[i];
	DoubleMatrix Q =  new DoubleMatrix(numStates,numStates,qdata);		
	DoubleMatrix Qnorm = Q.dup();
	Qnorm.diviRowVector(Q.columnSums());
	
	DoubleMatrix A = Qnorm.mmul(A0);
	A.divi(A.sum());  // normalised
	A.muli(sumA0);    // sum of A = sum(A0)
	//A = A.mul(sumA0).div(A.sum());
	DoubleMatrix a = A.div(Y);  // column vector 

	// DoubleMatrix dQ = new DoubleMatrix(numStates,numStates,dql);
	double dL = 0;
	DoubleMatrix FG = F.add(G);
	double accum;
	int k,l,z;
	i=0;
    for (z = 0; z < numStates; z++){
    	for (k = 0; k < numStates; k++){
        	accum = 0;
        	for(l=0; l < numStates; l++) {
        		if (k != l) {
        			if (Q.get(l,z) > 0) {
        				accum += FG.get(k,l) *  Q.get(l,z)/ Math.max(Q.get(l,z), Y.get(l));
        			}
        			if (Q.get(k,z) > 0) {
        				accum -= FG.get(l,k) *  Q.get(k,z)/  Math.max(Q.get(k,z), Y.get(k));
        			}
        		}
        		if (Q.get(k,z) > 0) {
        			accum -= F.get(k,l) * a.get(l) * Q.get(k,z)/  Math.max(Q.get(k,z), Y.get(k));
        		}
        	}
        	//dQ.put(k,z,accum);
        	dql[i++] = accum;
        }
    }	
    for (k= 0; k < numStates; k++){
    	for (l =0 ; l < numStates; l++){			
    		if (k == l && A.get(k) >= 1. ){
    			dL += (A.get(k) / Y.get(k)) * ((A.get(k)-1.) / Y.get(k)) * F.get(k,l) ; 
      		} else {
      			dL += a.get(k) * a.get(l) * F.get(k,l);
      		}
    	}
    }
    dL = Math.max(dL, 0.);   
    dql[numStatesSQ] = dL;					

}
 
开发者ID:mrc-ide,项目名称:PhyDyn,代码行数:65,代码来源:SolverQL.java


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