Calculation of projection matrices in J

I am trying to calculate the projection matrix in J. That is, given the matrix A, I want to calculate A(A'A)^(-1)A'where A'the transpose is A.

I think the right way to do this is to note that I am doing three operations before Aand multiplying the results. I am looking for something like (f x) * (g x) * (h x)if f, gand h- these are verbs. (Accounting +/ . *is matrix multiplication.) Is there a construct or idiom J to do this briefly? Or is there a better way to do this in J?

My rough work so far:

mp =: +/ . *
ATA =: |: mp ]
right_proj =: (%.@ATA) mp |: NB. (A'A)^(-1)A factor in product.
proj_mat =: ] mp right_proj
+4
source share
1 answer

I think your solution is pretty good. My immediate approach would be very similar:

mp=: +/ .*        NB. matrix multiplication
XtY=: mp~ |:      NB. sum of cross products (monadic is XtX)
proj_mat=: mp %.@XtY mp |:

%., . , y %. X X'X^(-1)X'y. , %., - X.

I=: =@i.@#                 NB. identity matrix
proj_mat=: mp I %. ]       NB. projection matrix

, , LAPACK.

+3

Source: https://habr.com/ru/post/1687342/


All Articles