Fork me on GitHub
#uncomplicate
<
2018-07-29
>
alan07:07:30

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

blueberry07:07:21

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

alan08:07:15

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)

blueberry08:07:10

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.

blueberry08:07:53

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

alan08:07:53

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)

alan08:07:34

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

alan08:07:22

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

alan08:07:00

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

alan09:07:03

Are there uncomplicate.commons docs somewhere?

blueberry09:07:35

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

alan09:07:25

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?