本文整理汇总了Java中org.ejml.factory.DecompositionFactory.svd方法的典型用法代码示例。如果您正苦于以下问题:Java DecompositionFactory.svd方法的具体用法?Java DecompositionFactory.svd怎么用?Java DecompositionFactory.svd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ejml.factory.DecompositionFactory
的用法示例。
在下文中一共展示了DecompositionFactory.svd方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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 };
}
示例3: 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;
}
示例4: 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);
}
示例5: 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));
}
示例6: 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);
}
示例7: 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);
}
示例8: 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
}
示例9: TrifocalLinearPoint7
import org.ejml.factory.DecompositionFactory; //导入方法依赖的package包/类
public TrifocalLinearPoint7() {
svdNull = DecompositionFactory.svd(24, 27, false, true, false);
svdNull = new SafeSvd(svdNull);
}
示例10: TrifocalExtractEpipoles
import org.ejml.factory.DecompositionFactory; //导入方法依赖的package包/类
public TrifocalExtractEpipoles() {
svd = DecompositionFactory.svd(3, 3, true, true, true);
svd = new SafeSvd(svd);
}
示例11: 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);
}
示例12: SolvePseudoInverseSvd
import org.ejml.factory.DecompositionFactory; //导入方法依赖的package包/类
/**
* Creates a new solver targeted at the specified matrix size.
*
* @param maxRows The expected largest matrix it might have to process. Can be larger.
* @param maxCols The expected largest matrix it might have to process. Can be larger.
*/
public SolvePseudoInverseSvd(int maxRows, int maxCols) {
svd = DecompositionFactory.svd(maxRows,maxCols,true,true,true);
}