Fork me on GitHub

(ev! a w v nil) works, but (ev! a nil v nil) doesn't. (I'm guessing w is used to calculate v, right?)


No. w is eigenvalues, v are eigenvectors. You always want eigenvalues, so it cannot be nil...


Ok, I reached this point:

(let-release [rows       (mrows mat)
                  cols       (ncols mat)
                  covariance (cov (center mat))
                  evecs      (copy covariance)
                  qr         (ev! evecs w
                                  evecs nil)
                  top        (submatrix evecs rows n-components)]
      (mm! 1.0 covariance top 0.0 result))))
I create w and result previously, I'm not really sure what's the benefit of (view-ge evecs) when I can happily use the same object with the same binding, and I'm not really sure how to get rid of that (copy covariance) since I need it untouched for mm! at the end. Oh and of course also the starting matrix should be untouched (because this is what happens with Numpy)


First of all, you're not even using sy matrices in that pca code... Second, most of those lets should be in with-release, not let-release. Third, if covariance was sy, you could call ev! on it without messing up with its contents. Fourth, you should reuse memory more in that code.


And, of course, if you don't need all eigenvectors/values (I guess that's what top does) don't compute them. Instruct ev! itself to compute only the first n-components...


I'm not using sy right now to make results comparable with PCA (to check that I didn't mess anything up, and because I would like to have a working implementation at the end of the process)


Is it possible? Couldn't find anything in the docs


Ah and by the way I saw the post about broadcasting, that's really interesting!! Are you going to follow up on the matter?


Ok, found it, I guess this is it For symmetric matrices, computes the first k eigenvalues (k <= m)


Are there uncomplicate.commons docs somewhere?


yes. clojure.repl/doc function gives you the doc of any function that has it.


I meant something more thorough, I'm trying

(def mat (fge 300 300 (range)))

(defn pca-ev
  [mat n-components]
  (let-release [w   (fge m 2)
                result (fge m n-components)]
    (with-release [rows       (mrows mat)
                    cols       (ncols mat)
                    covariance (cov (center mat))
                     evecs (fge m 2)
                     qr         (ev! (view-sy covariance) (fge 2 1)
                                  evecs nil)]
      (mm! 1.0 covariance evecs 0.0 result))))

(pca-ev 300 2)
And it fails badly, shouldn't let-release release only if there are errors? And anyway only after body is evaluated?