e.g. (in Scala)
def pseudoSolve(m: Matrix, b: Vector) = {
val svd = SVD.factorize(m)
val ps = new BandMatrix(m.numRows(), 0, 0)
// calculate pseudo-inverse of sigma
svd.getS.zipWithIndex.foreach { case (v, i) =>
if (v > 0.001) ps.set(i, i, 1 / v)
}
val tmpA = new DenseVector(b.size())
svd.getU.transMult(b, tmpA)
val tmpB = new DenseVector(b.size())
ps.mult(tmpA, tmpB)
tmpA
svd.getVt.transMult(tmpB, tmpA)
}
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
e.g. (in Scala)
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.