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


Java DenseMatrix类代码示例

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


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

示例1: ignoredTimedTransMult

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
public void ignoredTimedTransMult() {
    Stopwatch watch = Stopwatch.createUnstarted();
    DenseMatrix dense = new DenseMatrix(1000, 1000);
    int[][] nz = Utilities.getRowPattern(dense.numRows(),
            dense.numColumns(), 100);
    Utilities.rowPopulate(dense, nz);
    log.info("created matrices");
    Matrix sparse = new LinkedSparseMatrix(dense.numRows(),
            dense.numColumns());
    sparse.set(dense);

    for (Matrix m : Lists.newArrayList(dense, sparse)) {
        log.info("starting " + m.getClass());
        Matrix t = new DenseMatrix(m);
        Matrix o = new DenseMatrix(dense.numRows(), dense.numColumns());
        log.info("warming up " + m.getClass() + " " + o.getClass());
        for (int i = 0; i < 10; i++)
            m.transAmult(t, o);
        log.info("starting " + m.getClass() + " " + o.getClass());
        watch.start();
        for (int i = 0; i < 100; i++)
            m.transAmult(t, o);
        watch.stop();
        log.info(m.getClass() + " " + o.getClass() + " " + watch);
    }
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:27,代码来源:LinkedSparseMatrixTest.java

示例2: testWriteRead

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
@Test
public void testWriteRead() throws Exception {
    DenseMatrix mat = new DenseMatrix(
            new double[][]{{1.1, 1.2}, {1.3, 1.4}});
    File matrixFile = new File("TestMatrixFile");
    BufferedWriter out = new BufferedWriter(new FileWriter(matrixFile));
    MatrixVectorWriter writer = new MatrixVectorWriter(out);
    MatrixInfo mi = new MatrixInfo(false, MatrixInfo.MatrixField.Real,
            MatrixInfo.MatrixSymmetry.General);
    writer.printMatrixInfo(mi);
    writer.printMatrixSize(new MatrixSize(mat.numRows(), mat.numColumns(),
            mat.numColumns() * mat.numRows()), mi);
    writer.printArray(mat.getData());
    writer.close();
    Matrix newMat = new DenseMatrix(new MatrixVectorReader(new FileReader(
            matrixFile)));

    MatrixTestAbstract.assertMatrixEquals(mat, newMat);
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:20,代码来源:MatrixVectorIoTest.java

示例3: testSample

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
public void testSample ()
  {
    Variable v1 = new Variable (Variable.CONTINUOUS);
    Variable v2 = new Variable (Variable.CONTINUOUS);
    Randoms r = new Randoms (2343);

    Vector mu = new DenseVector (new double[] { 1.0, 2.0 });
    Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 0, 1 }});
//    Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 2.0, 0.75 }});

    VarSet vars = new HashVarSet (new Variable[] { v1, v2 });
    Factor f = new NormalFactor (vars, mu, var);

    TDoubleArrayList v1lst = new TDoubleArrayList ();
    TDoubleArrayList v2lst = new TDoubleArrayList ();
    for (int i = 0; i < 100000; i++) {
      Assignment assn = f.sample (r);
      v1lst.add (assn.getDouble (v1));
      v2lst.add (assn.getDouble (v2));
    }

    checkMeanStd (v1lst, 1.0, Math.sqrt (1/0.5));
    checkMeanStd (v2lst, 2.0, Math.sqrt (1/0.75));
  }
 
开发者ID:mimno,项目名称:GRMM,代码行数:25,代码来源:TestNormalFactor.java

示例4: testMultiply

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
@Test
public void testMultiply() {
  double[][] tmpMatrix = { { 1, 2, 3 }, { 4, 5, 6 } };
  double[] tmpVector = { 1, 2, 3 };
  double[] resultExpected = { 14, 32 };
  DenseMatrix denseMatrix = new DenseMatrix(tmpMatrix);
  DenseVector denseVector = new DenseVector(tmpVector);
  AbstractMatrix abstractMatrix = new MtjMatrix(denseMatrix);
  AbstractVector abstractVector = new MtjVector(denseVector);

  AbstractVector resultActual = abstractMatrix.multiply(abstractVector);
  assertEquals(resultExpected.length, resultActual.getDimension());
  for (int i = 0; i < resultActual.getDimension(); i++) {
    assertEquals(resultExpected[i], resultActual.getEntry(i), Helper.TOLERANCE);
  }

}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:18,代码来源:MtjMatrixTest.java

示例5: testGetSubMatrixDense

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
@Test
public void testGetSubMatrixDense() {
  double[][] tmpMatrix = { { 1, 2, 3 }, { 4, 5, 6 } };
  double[][] expteced = { { 5, 6 } };
  DenseMatrix denseMatrix = new DenseMatrix(tmpMatrix);
  AbstractMatrix abstractMatrix = new MtjMatrix(denseMatrix);

  AbstractMatrix resultActual = abstractMatrix.getSubMatrix(1, 1, 1, 2);
  assertEquals(1, resultActual.getRowDimension());
  assertEquals(2, resultActual.getColumnDimension());
  for (int i = 0; i < resultActual.getRowDimension(); i++) {
    for (int j = 0; j < resultActual.getColumnDimension(); j++) {
      assertEquals(expteced[i][j], resultActual.getEntry(i, j), Helper.TOLERANCE);
    }
  }
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:17,代码来源:MtjMatrixTest.java

示例6: testGetPermutationMatrix

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
/**
 * Checks to see if a matrix can be permuted correctly given a permutation vector. The
 * permutation is done both on rows and columns
 */
@Test
public void testGetPermutationMatrix() {
    Matrix M = new DenseMatrix(new double[][] {
        new double[] { 1, 5, 9,  13 },
        new double[] { 2, 6, 10, 14 },
        new double[] { 3, 7, 11, 15 },
        new double[] { 4, 8, 12, 16 },
    });
    int[] permutations = new int[] { 3, 2, 1, 0 };
    Matrix R = GraphPartition.getPermutedMatrix(M, permutations);
    Matrix R_e = new DenseMatrix(new double[][] {
        new double[] { 16, 12, 8, 4 },
        new double[] { 15, 11, 7, 3 },
        new double[] { 14, 10, 6, 2 },
        new double[] { 13, 9,  5, 1 },
    });

    assertArrayEquals(Matrices.getArray(R_e), Matrices.getArray(R));
}
 
开发者ID:OpenChatAlytics,项目名称:OpenChatAlytics,代码行数:24,代码来源:GraphPartitionTest.java

示例7: getSortedEigenVectors

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
/**
 * The Eigenvector for the absolutely smallest Eigenvalue
 * is sorted to the back. The two other vectors are sorted
 * such that their Eigenvalues are ascending
 * @param evd
 * @return
 */
public static double[][] getSortedEigenVectors(EVD evd){
	double[] eigVal = evd.getRealEigenvalues();
	DenseMatrix eigVec = evd.getRightEigenvectors();
	double[][] eigVecArr = new double[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			eigVecArr[i][j]= eigVec.get(j,i);
		}
	}
	//get minimal magnitude
	int i3 = getIndexOfMinMagnitude(eigVal);
	int i1 = (i3 + 1) % 3;
	int i2 = (i3 + 2) % 3;
	double k1 = eigVal[i1];
	double k2 = eigVal[i2];
	double[][] r = new double[3][];
	r[0] = k1 < k2 ? eigVecArr[i1] : eigVecArr[i2];
	r[1] = k1 < k2 ? eigVecArr[i2] : eigVecArr[i1];
	r[2] = eigVecArr[i3];
	return r;
}
 
开发者ID:sechel,项目名称:jtem-halfedgetools,代码行数:29,代码来源:CurvatureUtility.java

示例8: calc

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
public Matrix[] calc(Matrix source) {
	try {
		DenseMatrix m = null;
		if (source instanceof MTJDenseDoubleMatrix2D) {
			m = ((MTJDenseDoubleMatrix2D) source).getWrappedObject();
		} else {
			m = new MTJDenseDoubleMatrix2D(source).getWrappedObject();
		}
		no.uib.cipr.matrix.SVD svd = no.uib.cipr.matrix.SVD.factorize(m);
		Matrix u = new MTJDenseDoubleMatrix2D(svd.getU());
		Matrix v = new MTJDenseDoubleMatrix2D(svd.getVt()).transpose();
		double[] svs = svd.getS();
		Matrix s = SparseDoubleMatrix2D.Factory.zeros(source.getSize());
		for (int i = (int) Math.min(s.getRowCount(), s.getColumnCount()); --i >= 0;) {
			s.setAsDouble(svs[i], i, i);
		}
		return new Matrix[] { u, s, v };
	} catch (Exception e) {
		throw new RuntimeException(e);
	}

}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:23,代码来源:SVD.java

示例9: mtimes

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
public Matrix mtimes(Matrix m2) {
	if (m2 instanceof MTJDenseDoubleMatrix2D) {
		DenseMatrix a = matrix;
		DenseMatrix b = ((MTJDenseDoubleMatrix2D) m2).getWrappedObject();
		DenseMatrix c = new DenseMatrix(a.numRows(), b.numColumns());
		// try {
		a.mult(b, c);
		return new MTJDenseDoubleMatrix2D(c);
		// } catch (Exception e) {
		// // sometimes BLAS cannot be found. Don't know why. Use direct
		// // method instead.
		// double[] Bd = ((DenseMatrix) b).getData(), Cd = ((DenseMatrix)
		// c).getData();
		// org.netlib.blas.Dgemm.dgemm("N", "N", c.numRows(),
		// c.numColumns(), a.numColumns(), 1, a.getData(), 0,
		// Math.max(1, a.numRows()), Bd, 0, Math.max(1, b.numRows()), 1, Cd,
		// 0, Math.max(1, c.numRows()));
		// return new MTJDenseDoubleMatrix2D(c);
		// }
	}
	return super.mtimes(m2);
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:23,代码来源:MTJDenseDoubleMatrix2D.java

示例10: multBLASAdd

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
public static DenseMatrix multBLASAdd(double alpha, DenseMatrix B, DenseMatrix C) {

        double[] Bd = B.getData(), Cd = C.getData();
        int CRows = C.numRows();
        int cCols = C.numColumns();
        int BRows = B.numRows();
        int bCols = B.numColumns();


        BLAS.getInstance().dgemm("N", "N",
                C.numRows(), C.numColumns(),
                B.numColumns(), alpha,
                Bd,
                Math.max(1, B.numRows()), Bd, Math.max(1, B.numRows()), 0.0, Cd,
                Math.max(1, C.numRows()));

        return C;
    }
 
开发者ID:scalalab,项目名称:scalalab,代码行数:19,代码来源:MTJLAPACK.java

示例11: factor

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
/**
 * Computes the eigenvalue decomposition of the given matrix
 *
 * @param A Matrix to factorize. Overwritten on return
 * @return The current decomposition
 * @throws NotConvergedException
 */
public NativeEVD factor(DenseMatrix A) throws NotConvergedException {
    if (!A.isSquare())
        throw new IllegalArgumentException("!A.isSquare()");
    else if (A.numRows() != n)
        throw new IllegalArgumentException("A.numRows() != n");

    intW info = new intW(0);
    //NativeBlas.dgeev(jobLeft.netlib(), jobRight.netlib(), n, A.getData(),
    //      LAPACKUtils.ld(n), Wr, Wi, jobLeft == JobEigEnum.All ? Vl.getData() : new double[0],
    //    LAPACKUtils.ld(n), jobRight == JobEigEnum.All ? Vr.getData() : new double[0], LAPACKUtils.ld(n),
    //  work, work.length, info);

    if (info.val > 0)
        throw new NotConvergedException(
                NotConvergedException.Reason.Iterations);
    else if (info.val < 0)
        throw new IllegalArgumentException();

    return this;
}
 
开发者ID:scalalab,项目名称:scalalab,代码行数:28,代码来源:NativeEVD.java

示例12: testSample

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
public void testSample ()
  {
    Variable v1 = new Variable (Variable.CONTINUOUS);
    Variable v2 = new Variable (Variable.CONTINUOUS);
    Randoms r = new Randoms (2343);

    Vector mu = new DenseVector (new double[] { 1.0, 2.0 });
    Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 0, 1 }});
//    Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 2.0, 0.75 }});

    VarSet vars = new HashVarSet (new Variable[] { v1, v2 });
    Factor f = new NormalFactor (vars, mu, var);

    TDoubleArrayList v1lst = new TDoubleArrayList();
    TDoubleArrayList v2lst = new TDoubleArrayList ();
    for (int i = 0; i < 100000; i++) {
      Assignment assn = f.sample (r);
      v1lst.add (assn.getDouble (v1));
      v2lst.add (assn.getDouble (v2));
    }

    checkMeanStd (v1lst, 1.0, Math.sqrt (1/0.5));
    checkMeanStd (v2lst, 2.0, Math.sqrt (1/0.75));
  }
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:25,代码来源:TestNormalFactor.java

示例13: sumLogFactorial

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
private double sumLogFactorial(DenseMatrix fv) {
	double sum = 0;
	final double[] data = fv.getData();
	for (int i = 0; i < fv.numColumns(); i++) {
		final int fvi = (int) data[i];
		if (logFacCache.contains(fvi))
		{
			sum += logFacCache.get(fvi);
		}
		else {
			for (int j = 1; j < fvi + 1; j++) {
				sum += Math.log(j);
			}
		}
	}
	return sum;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:18,代码来源:LanguageDetector.java

示例14: symmetricGeneralisedEigenvectors

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
/**
 * Solve the general problem A x = L B x. 
 * The returned eigenvalues are not ordered.
 *
 * @param A symmetric matrix A
 * @param B symmetric matrix B
 * @return The eigenvectors x and eigenvalues L.
 */
public static IndependentPair<Matrix, double[]> symmetricGeneralisedEigenvectors(Matrix A, Matrix B) {
	if ((A.getRowDimension() != A.getColumnDimension()) || (B.getRowDimension() != B.getColumnDimension())) 
    	throw new IllegalArgumentException("Input matrices must be square");
	
	int dim = A.getRowDimension();
	DenseMatrix vecs = new DenseMatrix(A.getArray());
	DenseVector W = new DenseVector(dim);
    
	sygvd(1, "V", "U", vecs, new DenseMatrix(B.getArray()), W);
    
	Matrix evecs = new Matrix(dim, dim);
	final double[][] evecsData = evecs.getArray();
	final double[] vecsData = vecs.getData();
	for (int r=0; r<dim; r++)
		for (int c=0; c<dim; c++)
			evecsData[r][c] = vecsData[r + c * dim];
	
    return new IndependentPair<Matrix, double[]>(evecs, W.getData());
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:28,代码来源:GeneralisedEigenvalueProblem.java

示例15: symmetricGeneralisedEigenvectorsSorted

import no.uib.cipr.matrix.DenseMatrix; //导入依赖的package包/类
/**
 * Solve the general problem A x = L B x. 
 * The returned eigenvalues ordered in a decreasing manner.
 *
 * @param A symmetric matrix A
 * @param B symmetric matrix B
 * @return The eigenvectors x and eigenvalues L.
 */
public static IndependentPair<Matrix, double[]> symmetricGeneralisedEigenvectorsSorted(Matrix A, Matrix B) {
	if ((A.getRowDimension() != A.getColumnDimension()) || (B.getRowDimension() != B.getColumnDimension())) 
    	throw new IllegalArgumentException("Input matrices must be square");
	
	int dim = A.getRowDimension();
	DenseMatrix vecs = new DenseMatrix(A.getArray());
	DenseVector W = new DenseVector(dim);
    
	sygvd(1, "V", "U", vecs, new DenseMatrix(B.getArray()), W);
    
	Matrix evecs = new Matrix(dim, dim);
	final double[][] evecsData = evecs.getArray();
	final double[] vecsData = vecs.getData();
	final double[] valsData = W.getData();
	
	int [] indices = ArrayUtils.range(0, valsData.length-1);
	ArrayUtils.parallelQuicksortDescending(valsData, indices);
	
	for (int r=0; r<dim; r++)
		for (int c=0; c<dim; c++)
			evecsData[r][c] = vecsData[r + indices[c] * dim];
	
    return new IndependentPair<Matrix, double[]>(evecs, valsData);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:33,代码来源:GeneralisedEigenvalueProblem.java


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