What is the Haskell / hmatrix equivalent of the MATLAB pos function?

I am translating MATLAB code to Haskell using the hmatrix library. Everything is going well, but I stumble upon the pos function because I don’t know what it does or what is the Haskell equivalent.

The MATLAB code is as follows:

[U,S,V] = svd(Y,0);
diagS = diag(S);
...
A = U * diag(pos(diagS-tau)) * V';
E = sign(Y) .* pos( abs(Y) - lambda*tau );
M = D - A - E;

My translation of Haskell:

(u,s,v) = svd y
diagS = diag s
a = u `multiply` (diagS - tau) `multiply` v

Actually, this type of check is fine, but of course I miss the "pos" call and it gives an error:

inconsistent dimensions in matrix product (3,3) x (4,4)

So, I assume pos is doing something with matrix size? Googling "matlab pos function" didn’t bring anything useful, so any pointers are really appreciated! (Obviously, I know little MATLAB)

By the way, this is for the TILT algorithm for restoring low-rank textures from a noisy, distorted image. I am very excited about this, even if the math goes beyond me!

, pos MATLAB:

function P = pos(A)
P = A .* double( A > 0 );

, . , , "True" == 1.0 "False" == 0.0

?

+4
2

, pos . mapMatrix

pos :: (Storable a, Num a) => Matrix a -> Matrix a
pos = mapMatrix go where
  go x | x > 0     = x
       | otherwise = 0

Matlab Matrix Vector Haskell.

Matlab. Per http://www.mathworks.com/help/matlab/ref/svd.html " " "-" Y, .. ,

U * S * V = Y

, Y m x n, U m x n, S n x n , V - n x n. , U, V . Y "" .

S , , diag(S), tau, . , , , pos , 0. diag , A, Y.

, Haskell, svd ( thinSVD) 0'- .

(u, s, v) = thinSVD y

-- note the trans here, that was the ' in Matlab
a = u `multiply` diag (fmap (max 0) s) `multiply` trans v

fmap max 0 Vector S, diag ( Numeric.Container) Vector a Matrix multiply s. , max 0 pos .

+4

(A > 0) A, , , ,

A = [ -1 2 -3 4
       5 6 -7 -8 ]

B = (A > 0)

B = [ 0 1 0 1
      1 1 0 0]

, , A, , 0 .

, A A, .*, A, 1, . A .* B

[ -1*0   2*1   -3*0   4*1
   5*1   6*1   -7*0  -8*0 ]

,

[ 0 2 0 4
  5 6 0 0 ]

, , , .

, u v , Generall SVD, REDIAGONALIZE POS (DIAGS - Tau), u* diagnonalized_(diagS -tau) agrres v

+1

All Articles