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


Java DecompositionFactory类代码示例

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


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

示例1: getEigenvectors

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
/**
 * Calculates a List of eigenvalues and eigenvectors from the provided 3x3 (covariance) matrix.
 *
 * @param matrix 3x3 Matrix to derive the eigenvalues and eigenvectors from.
 * @return List of pairs containing both the eigenvalues and the eigenvectors. The entries are
 * sorted in ascending order of the eigenvalue.
 */
private static List<Pair<Float,Vector3f>> getEigenvectors(DenseMatrix64F matrix) {
    List<Pair<Float,Vector3f>> eigenvectors = new ArrayList<>();

    EigenDecomposition<DenseMatrix64F> eig = DecompositionFactory.eig(3, true);
    eig.decompose(matrix);

    int eigValNum = eig.getNumberOfEigenvalues();
    for(int i = 0; i < eigValNum; i++){
        DenseMatrix64F eigMat = eig.getEigenVector(i);
        if(eigMat != null){
            eigenvectors.add(new Pair<>((float)eig.getEigenvalue(i).getReal(), new Vector3f((float)eigMat.get(0,0), (float)eigMat.get(1,0), (float)eigMat.get(2,0))));
        }
    }

    eigenvectors.sort(Comparator.comparing(e -> e.first));

    return eigenvectors;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:26,代码来源:MeshTransformUtil.java

示例2: calc

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
public Matrix[] calc(Matrix source) {
	QRDecomposition<DenseMatrix64F> qr = DecompositionFactory.qr((int) source.getRowCount(),
			(int) source.getColumnCount());
	DenseMatrix64F matrix = null;
	if (source instanceof EJMLDenseDoubleMatrix2D) {
		matrix = ((EJMLDenseDoubleMatrix2D) source).getWrappedObject();
	} else {
		matrix = new EJMLDenseDoubleMatrix2D(source).getWrappedObject();
	}
	qr.decompose(matrix);
	DenseMatrix64F qm = qr.getQ(null, true);
	DenseMatrix64F rm = qr.getR(null, true);
	Matrix q = new EJMLDenseDoubleMatrix2D(qm);
	Matrix r = new EJMLDenseDoubleMatrix2D(rm);
	return new Matrix[] { q, r };
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:17,代码来源:QR.java

示例3: computeBasis

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
/**
 * Computes a basis (the principal components) from the most dominant eigenvectors.
 *
 * @param numComponents Number of vectors it will use to describe the data.  Typically much
 *                      smaller than the number of elements in the input vector.
 */
public void computeBasis(int numComponents) {
    Logger.getAnonymousLogger().log(Level.INFO, "Compute basis to get principal components.");

    validateData(numComponents);
    setNumPrincipalComponents(numComponents);
    computeNormalizedMean();

    // Compute SVD and save time by not computing U
    SingularValueDecomposition<DenseMatrix64F> svd =
            DecompositionFactory.svd(getDataMatrix().numRows, getDataMatrix().numCols, false, true, false);
    if (!svd.decompose(getDataMatrix())) {
        throw new IllegalStateException("SVD failure. Can't compute principal components!");
    }

    setPrincipalComponentSubspace(svd.getV(null, true));
    final DenseMatrix64F singularDiagonalMatrix = svd.getW(null);

    // Singular values are in an arbitrary order initially. We ask for principal components subspace to be transposed.
    SingularOps.descendingOrder(null, false, singularDiagonalMatrix, getPrincipalComponentSubspace(), true);

    // strip off unneeded components and find the basis
    getPrincipalComponentSubspace().reshape(numComponents, getMean().length, true);
}
 
开发者ID:LakkiB,项目名称:mlstorm,代码行数:30,代码来源:PrincipalComponentsBase.java

示例4: calc

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
public Matrix[] calc(Matrix source) {
	SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd((int) source.getRowCount(),
			(int) source.getColumnCount(), true, true, false);

	if (source instanceof EJMLDenseDoubleMatrix2D) {
		svd.decompose(((EJMLDenseDoubleMatrix2D) source).getWrappedObject());
	} else {
		svd.decompose(new EJMLDenseDoubleMatrix2D(source).getWrappedObject());
	}
	Matrix u = new EJMLDenseDoubleMatrix2D(svd.getU(null, false));
	Matrix v = new EJMLDenseDoubleMatrix2D(svd.getV(null, false));
	Matrix s = new EJMLDenseDoubleMatrix2D(svd.getW(null));
	return new Matrix[] { u, s, v };
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:15,代码来源:SVD.java

示例5: getSvd

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
/**
 * 获取svd相关计算结果的方法:
 * list.get(0)是svd值的double[],list中剩下的double[]是矩阵M*M的特征向量(V的列集合)
 *
 * @param data
 * @return
 */
public static List<double[]> getSvd(double data[][]) throws Exception {
    DenseMatrix64F matA = buildMatrix(data);
    DebugLog.i(matA.toString());
    double[] result;
    ArrayList<double[]> resultList = new ArrayList<double[]>();
    SingularValueDecomposition<DenseMatrix64F> svd =
            DecompositionFactory.svd(matA.numRows, matA.numCols, false, true, true);
    if (!DecompositionFactory.decomposeSafe(svd, matA)) {
        throw new Exception("Decomposition failed");
    }
    DenseMatrix64F S = svd.getW(null);
    DenseMatrix64F V = svd.getV(null, false);
    result = new double[S.numRows];
    for (int i = 0; i < S.numRows; i++) {
        result[i] = formatDouble(S.get(i, i));
    }
    resultList.add(result);
    for (int i = 0; i < V.numCols; i++) {
        result = new double[V.numRows];
        for (int j = 0; j < V.numRows; j++) {
            result[j] = formatDouble(V.get(j, i));
        }
        resultList.add(result);
    }
    return resultList;
}
 
开发者ID:Richard-Cao,项目名称:MatrixSvdDemo,代码行数:34,代码来源:Svd.java

示例6: main

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
public static void main(String[] args) {
    DenseMatrix64F y = new DenseMatrix64F(1, 2, true, new double[]{1.0, 2.0});
    DenseMatrix64F yT = CommonOps.transpose(y, null);
    DenseMatrix64F m = new DenseMatrix64F(2,2);
    CommonOps.mult(yT, y, m);

    SimpleMatrix m2 = new SimpleMatrix(2,2, true, new double[]{1,2,3,4});
    org.ejml.factory.SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd(2, 2, false, true, false);
    svd.decompose(m);
    m = svd.getV(null, true);

}
 
开发者ID:LakkiB,项目名称:mlstorm,代码行数:13,代码来源:IncrementalStormPca.java

示例7: decomposeCameraMatrix

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
/**
 * <p>
 * Decomposes a camera matrix P=A*[R|T], where A is an upper triangular camera calibration
 * matrix, R is a rotation matrix, and T is a translation vector.
 *
 * <ul>
 * <li> NOTE: There are multiple valid solutions to this problem and only one solution is returned.
 * <li> NOTE: The camera center will be on the plane at infinity.
 * </ul>
 * </p>
 *
 * @param P Input: Camera matrix, 3 by 4
 * @param K Output: Camera calibration matrix, 3 by 3.
 * @param pose Output: The rotation and translation.
 */
public static void decomposeCameraMatrix(DenseMatrix64F P, DenseMatrix64F K, Se3_F64 pose) {
	DenseMatrix64F KR = new DenseMatrix64F(3,3);
	CommonOps.extract(P, 0, 3, 0, 3, KR, 0, 0);

	QRDecomposition<DenseMatrix64F> qr = DecompositionFactory.qr(3, 3);

	if( !CommonOps.invert(KR) )
		throw new RuntimeException("Inverse failed!  Bad input?");

	if( !qr.decompose(KR) )
		throw new RuntimeException("QR decomposition failed!  Bad input?");

	DenseMatrix64F U = qr.getQ(null,false);
	DenseMatrix64F B = qr.getR(null, false);

	if( !CommonOps.invert(U,pose.getR()) )
		throw new RuntimeException("Inverse failed!  Bad input?");

	Point3D_F64 KT = new Point3D_F64(P.get(0,3),P.get(1,3),P.get(2,3));
	GeometryMath_F64.mult(B, KT, pose.getT());

	if( !CommonOps.invert(B,K) )
		throw new RuntimeException("Inverse failed!  Bad input?");

	CommonOps.scale(1.0/K.get(2,2),K);
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:42,代码来源:MultiViewOps.java

示例8: DecomposeHomography

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
public DecomposeHomography() {
	for( int i = 0; i < 4; i++ ) {
		solutionsN.add( new Vector3D_F64() );
		solutionsSE.add( new Se3_F64() );
	}

	// insure that the inputs are not modified
	svd = new SafeSvd(DecompositionFactory.svd(3, 3, false, true, false));
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:10,代码来源:DecomposeHomography.java

示例9: summarize

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
@Override
public Set<String> summarize(Map<String, Vector> vectors, int L) {
	
	int n = vectors.size();
	int themes = (int) Math.sqrt(n);
	
	DenseMatrix64F A = new DenseMatrix64F(n, n);

	Set<String> keys = vectors.keySet();
	List<String> ids = sortTimesliceIds(keys);
	for(int i = 0; i<n; i++) {
		for(int j = i; j<n; j++) {
			
			Vector v1 = vectors.get(ids.get(i));
			Vector v2 = vectors.get(ids.get(j));
			
			double w = .0;
			if(v1 != null && v2 != null) {
				w = v1.cosine(v2);
				if(w < similarityThreshold) {
					w = .0;
				}
			}
			
			A.set(i, j, w);
			A.set(j, i, w);				
			
		}	
	}
	
	System.out.println("Start Eigenvalue Decomposition.");
	EigenDecomposition<DenseMatrix64F> evdFactory = DecompositionFactory.eig(n, true);
	evdFactory.decompose(A);
	System.out.println(evdFactory.getNumberOfEigenvalues() + " eigenvalues, " + themes + " major themes");
	
	System.out.println("Start Event Segmentation");
	List<Event> events = segment(evdFactory, themes);
	
	System.out.println("#Events: " + events.size());
	
	Map<String, Double> scores = new HashMap<String, Double>();
	for(Event event : events) {
		System.out.println(event.toString());
		int index = event.maxAmplBlock;
		if(index >= 0) {
			String id = ids.get(index);
			Double score = scores.get(id);
			if(score == null || score < event.maxAmplitude) {
				scores.put(id, event.maxAmplitude);
			}
		}
	}
	
	// Sort by weight
	List<Entry<String, Double>> sortedWeights = Sorter.sort(scores);

	Set<String> summary = new HashSet<String>();
	for(int i = 0; i < Math.min(L, sortedWeights.size()); i++) {
		Entry<String, Double> entry = sortedWeights.get(i);
		summary.add(entry.getKey());
	}
	return summary;
}
 
开发者ID:MKLab-ITI,项目名称:mgraph-summarization,代码行数:64,代码来源:TScanSummarizer.java

示例10: computeBasis

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
/**
 * Computes a basis (the principal components) from the most dominant eigenvectors.
 *
 * @param numComponents Number of vectors it will use to describe the data.  Typically much
 * smaller than the number of elements in the input vector.
 */
public void computeBasis( int numComponents ) {
    if( numComponents > A.getNumCols() )
        throw new IllegalArgumentException("More components requested that the data's length.");
    if( sampleIndex != A.getNumRows() )
        throw new IllegalArgumentException("Not all the data has been added");
    if( numComponents > sampleIndex )
        throw new IllegalArgumentException("More data needed to compute the desired number of components");

    this.numComponents = numComponents;

    // compute the mean of all the samples
    for( int i = 0; i < A.getNumRows(); i++ ) {
        for( int j = 0; j < mean.length; j++ ) {
            mean[j] += A.get(i,j);
        }
    }
    for( int j = 0; j < mean.length; j++ ) {
        mean[j] /= A.getNumRows();
    }

    // subtract the mean from the original data
    for( int i = 0; i < A.getNumRows(); i++ ) {
        for( int j = 0; j < mean.length; j++ ) {
            A.set(i,j,A.get(i,j)-mean[j]);
        }
    }

    // Compute SVD and save time by not computing U
    SingularValueDecomposition<DenseMatrix64F> svd =
            DecompositionFactory.svd(A.numRows, A.numCols, false, true, false);
    if( !svd.decompose(A) )
        throw new RuntimeException("SVD failed");

    V_t = svd.getV(null,true);
    DenseMatrix64F W = svd.getW(null);

    // Singular values are in an arbitrary order initially
    SingularOps.descendingOrder(null,false,W,V_t,true);

    // strip off unneeded components and find the basis
    V_t.reshape(numComponents,mean.length,true);
}
 
开发者ID:droiddeveloper1,项目名称:android-wear-gestures-recognition,代码行数:49,代码来源:PCA.java

示例11: computeBasis

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
/**
 * Computes a basis (the principle components) from the most dominant eigenvectors.
 *
 * @param numComponents Number of vectors it will use to describe the data.  Typically much
 * smaller than the number of elements in the input vector.
 */
public void computeBasis( int numComponents ) {
   if( numComponents > A.getNumCols() )
      throw new IllegalArgumentException("More components requested that the data's length.");
   if( sampleIndex != A.getNumRows() )
      throw new IllegalArgumentException("Not all the data has been added");
   if( numComponents > sampleIndex )
      throw new IllegalArgumentException("More data needed to compute the desired number of components");

   this.numComponents = numComponents;

   // compute the mean of all the samples
   for( int i = 0; i < A.getNumRows(); i++ ) {
      for( int j = 0; j < mean.length; j++ ) {
         mean[j] += A.get(i,j);
      }
   }
   for( int j = 0; j < mean.length; j++ ) {
      mean[j] /= A.getNumRows();
   }

   // subtract the mean from the original data
   for( int i = 0; i < A.getNumRows(); i++ ) {
      for( int j = 0; j < mean.length; j++ ) {
         A.set(i,j,A.get(i,j)-mean[j]);
      }
   }

   // Compute SVD and save time by not computing U
   SingularValueDecomposition<DenseMatrix64F> svd =
          DecompositionFactory.svd(A.numRows, A.numCols, false, true, false);
   if( !svd.decompose(A) )
      throw new RuntimeException("SVD failed");

   V_t = svd.getV(null,true);
   DenseMatrix64F W = svd.getW(null);

   // Singular values are in an arbitrary order initially
   SingularOps.descendingOrder(null,false,W,V_t,true);

   // strip off unneeded components and find the basis
   V_t.reshape(numComponents,mean.length,true);
}
 
开发者ID:frank0631,项目名称:semantic-web-scraper,代码行数:49,代码来源:PrincipleComponentAnalysis.java

示例12: EnforceTrifocalGeometry

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
public EnforceTrifocalGeometry() {
	svdU = DecompositionFactory.svd(10,10,true,false,true);
	svdV = DecompositionFactory.svd(10,10,false,true,false);
	svdV = new SafeSvd(svdV); // can't modify the input in this case
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:6,代码来源:EnforceTrifocalGeometry.java

示例13: TrifocalLinearPoint7

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
public TrifocalLinearPoint7() {
	svdNull = DecompositionFactory.svd(24, 27, false, true, false);
	svdNull = new SafeSvd(svdNull);
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:5,代码来源:TrifocalLinearPoint7.java

示例14: TrifocalExtractEpipoles

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
public TrifocalExtractEpipoles() {
	svd = DecompositionFactory.svd(3, 3, true, true, true);
	svd = new SafeSvd(svd);
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:5,代码来源:TrifocalExtractEpipoles.java

示例15: computeBasis

import org.ejml.factory.DecompositionFactory; //导入依赖的package包/类
/**
 * Computes a basis (the principle components) from the most dominant eigenvectors.
 */
public void computeBasis() {
	if (sampleIndex != numSamples)
		throw new IllegalArgumentException("Not all the data has been added");
	if (numComponents > numSamples)
		throw new IllegalArgumentException(
				"More data needed to compute the desired number of components");

	means = new DenseMatrix64F(sampleSize, 1);
	// compute the mean of all the samples
	for (int i = 0; i < numSamples; i++) {
		for (int j = 0; j < sampleSize; j++) {
			double val = means.get(j);
			means.set(j, val + A.get(i, j));
		}
	}
	for (int j = 0; j < sampleSize; j++) {
		double avg = means.get(j) / numSamples;
		means.set(j, avg);
	}

	// subtract the mean from the original data
	for (int i = 0; i < numSamples; i++) {
		for (int j = 0; j < sampleSize; j++) {
			A.set(i, j, A.get(i, j) - means.get(j));
		}
	}

	// compute SVD and save time by not computing U
	SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd(numSamples, sampleSize,
			false, true, compact);
	if (!svd.decompose(A))
		throw new RuntimeException("SVD failed");

	V_t = svd.getV(null, true);
	W = svd.getW(null);

	// singular values are in an arbitrary order initially and need to be sorted in descending order
	SingularOps.descendingOrder(null, false, W, V_t, true);

	// strip off unneeded components and find the basis
	V_t.reshape(numComponents, sampleSize, true);

}
 
开发者ID:MKLab-ITI,项目名称:multimedia-indexing,代码行数:47,代码来源:PCA.java


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