Hi, I'm Michela. I need a help, I'm having problems in calculating the eigenvectors on a model obtained with the PCA.
I'm using ScalismoLab and I generated the model in this way:
val PCAmodel = StatisticalMeshModel.createUsingPCA (dc) .get
Later I found the basis Matrix:
val X = PCAmodel.gp.basisMatrix
And finally to get the eigenvectors I tried to calculate the covariance matrix using different methods, but none of them worked:
METHOD 1)
val G = X.t * X
val n = X.cols
val svd.SVD (u, s, _) = breeze.linalg.svd (G * (1.0 / (n-1)))
error: could not find implicit value for parameter op: breeze.linalg.operators.OpMulMatrix.Impl2 [breeze.linalg.DenseMatrix [Float], Double, That]
METHOD 2)
In the second method I have used this function:
def decomposeCovarianceMatrix (
X: DenseMatrix [Double],
threshold: Double = 1.0e-8
): (DenseMatrix [Double], DenseVector [Double]) = {
val n = X.cols
val Cov = X * X.t * (1.0 / (n-1))
val svd.SVD (u, s, _) = breeze.linalg.svd (Cov)
val rank = s.toArray.count (_> threshold)
(u (::, 0 until rank), s (0 until rank))
}
val Covariance = decomposeCovarianceMatrix (X)
error: type mismatch;
found: breeze.linalg.DenseMatrix [Float]
required: breeze.linalg.DenseMatrix [Double]
Is there a way to solve these problems or another way to find the eigenvectors of the covariance matrix of the model created using PCA?
Best regards
Michela