Search in sources :

Example 1 with DenseDoubleSingularValueDecomposition

use of cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleSingularValueDecomposition in project clusterMaker2 by RBVI.

the class RunSCPS method getNegSqrRoot.

// Calculate negative square root of matrix using singular value decomposition
public DoubleMatrix2D getNegSqrRoot(DoubleMatrix2D A) {
    // A = USV, where S is Diagnol Matrix
    DenseDoubleSingularValueDecomposition decomp = new DenseDoubleSingularValueDecomposition(A, true, true);
    DoubleMatrix2D U = decomp.getU();
    DoubleMatrix2D S = decomp.getS();
    DoubleMatrix2D V = decomp.getV();
    // S^1/2 = Square root of every value in diangol matrix
    for (int i = 0; i < S.rows(); i++) S.set(i, i, Math.pow(S.get(i, i), .5));
    // A^1/2 = VS^1/2U
    DenseDoubleAlgebra alg = new DenseDoubleAlgebra();
    DoubleMatrix2D sqrtA = alg.mult(alg.mult(V, S), U);
    // return A^-1/2
    return alg.inverse(sqrtA);
}
Also used : DenseDoubleAlgebra(cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) DenseDoubleSingularValueDecomposition(cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleSingularValueDecomposition)

Aggregations

DoubleMatrix2D (cern.colt.matrix.tdouble.DoubleMatrix2D)1 DenseDoubleAlgebra (cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra)1 DenseDoubleSingularValueDecomposition (cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleSingularValueDecomposition)1