Four new matrix decomposition function added in the new vectorz-clj release

36 views
Skip to first unread message

Prasant Chidella

unread,
Jun 28, 2014, 1:30:58 AM6/28/14
to numerica...@googlegroups.com
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

Mike Anderson

unread,
Jun 28, 2014, 4:03:22 AM6/28/14
to numerica...@googlegroups.com
Great stuff - Prasant! It's a big milestone to get these decompositions working.

One question about your demo: the "(let [inv (fn [a] (emap (fn [e] (if-not (equals 0.0 e epsilon) (/ 1 e) e)) a)) ..." looks a bit ugly. How could we improve that?


--
You received this message because you are subscribed to the Google Groups "Numerical Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numerical-cloj...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages