Hello all,
I have been working on core.matrix, vectorz-clj and vectorz libraries since the last six weeks as part of my GSoC project. We have been adding matrix decompositions and some other functions to these libraries. There is a new vectorz-clj release that has working implementations of QR decomposition, LU decomposition, SVD and Cholesky decomposition.
The decompositions will be in the clojure.core.matrix.linear namespace
The API we have implemented is as follows,
The decomposition functions will take the input matrix with an optional hashmap (containing the :return symbol mapped to an array of symbols) to specify the desired matrices.
The intended use is:
(let [{:keys [X Y]} (decomposition-function M)] ....)
(let [{:keys [X]} (decomposition-function M {:return [:X]})] ....)
For instance, for QR decomposition, if a user requires only the R matrix,
they should use
(let [{:keys [R]} (qr M {:return [:R]})])
To get both Q and R,
(let [{:keys [Q R]} (qr M {:return [:Q :R]})])
or just
(let [{:keys [Q R]} (qr M)])
As a simple demo, to compute the pseudoinverse of a matrix using SVD,
; if A = USV*, A+ = VS+U*, where M+ is pseudoinverse of M
; For a diagonal matrix, we get the pseudo inverse by taking
; the reciprocal of each non-zero element on the diagonal,
; leaving the zeros in place.
(def m (matrix :vectorz [[1 2 3][4 5 6][7 8 9]]))
(def epsilon 0.00001)
(let [inv (fn [a] (emap (fn [e] (if-not (equals 0.0 e epsilon) (/ 1 e) e)) a))
{:keys [U S V*]} (svd m)
S_inv (inv S)]
(mmul (transpose V*) S_inv (transpose U)))
Please do give them a try and provide any feedback that you might have! About any bug you might encounter, or any suggestion you have regarding the API.
More releases coming soon! :)
Prasant