uncomplicate

alan 2018-07-29T07:23:30.000001Z

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

2018-07-29T07:31:21.000013Z

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

alan 2018-07-29T08:13:15.000024Z

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)

2018-07-29T08:18:10.000001Z

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.

2018-07-29T08:19:53.000015Z

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...

alan 2018-07-29T08:23:53.000020Z

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)

alan 2018-07-29T08:24:34.000008Z

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

alan 2018-07-29T08:25:22.000005Z

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

alan 2018-07-29T08:37:00.000021Z

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

alan 2018-07-29T09:06:03.000017Z

Are there uncomplicate.commons docs somewhere?

2018-07-29T09:16:35.000029Z

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

alan 2018-07-29T09:18:25.000014Z

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?