'x y M'=. 5 7 3                  NB. Parameters
   $&.>s=. (i.x,x);(i.x,y);i.y,y NB. Fake "s"
+---+---+---+
|5 5|5 7|7 7|
+---+---+---+
   2<\x,M,M,y NB. Shapes we want
+---+---+---+
|5 3|3 3|3 7|
+---+---+---+
   (2<\xx,M,M,yy){.&.>s
+--------+--------+--------------------+
| 0 1 2| 0 1 2| 0 1 2 3 4 5 6|
| 5 6 7| 7 8 9| 7 8 9 10 11 12 13|
|10 11 12|14 15 16|14 15 16 17 18 19 20|
|15 16 17| | |
|20 21 22| | |
+--------+--------+--------------------+
   $&.>(2<\xx,M,M,yy){.&.>s
+---+---+---+
|5 3|3 3|3 7|
+---+---+---+
   $>mp&.>/(2<\xx,M,M,yy){.&.>s  NB. End up with shape x,y
5 7

On 1/15/08, Yoel Jacobsen <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> I want to implement matrix approximation using SVD.
> The SVD algorithm returns three boxed  matrices of the shapes x x ; x y ;
> y y
> I want to chop and multiply back:
> Step 1: reshape as - x M; M M ; M y where M is a small value
> Step 2: Unbox and multiply (x M  * M M * M y => x y)
>
> My current implementation is:
>
> s =. dgesvd ...
> a =. M {. "1 (> 0 { s)
> b =. M {. "1 (M {. (> 1 { s))
> c =. M {. (> 2 { s)
>
> mp =: +/ . *
> approximated =. a mp b mp c
>
> Now this is 1) ugly (for me) and 2) slow as hell.
>
> Suggestions?
>
> Thanks,
>   Yoel
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to