Hi Steven
Yes, there are two different ways to do that: Either you sum up the variances of all the points, or you sum up the eigenvalues of the KL basis. Both should give you the same results (as the eigenvalue associated to the i-th basis function in the KL-Expansion is the amount of variance represented by this basis function).
Here is the corresponding code:
def computeTotalVarianceFromPoints(ssm : StatisticalMeshModel) : Double = {
val variances = for (pId <- ssm.referenceMesh.pointSet.pointIds) yield {
// variances (x,y,z) for point with id pId
breeze.linalg.sum(breeze.linalg.diag(ssm.gp.cov(pId, pId)))
}
variances.sum
}
def computeTotalVarianceFromKLBasis(ssm : StatisticalMeshModel) : Double = {
ssm.gp.klBasis.map(basis => basis.eigenvalue).sum
}
Best regards,
Marcel