haskell-numerics / hmatrix

Linear algebra and numerical computation
381 stars 104 forks source link

norm_2 strangeness #113

Closed idontgetoutmuch closed 9 years ago

idontgetoutmuch commented 9 years ago

Perhaps this is just a lack of documentation.

*StochVol> (^2) $ norm_2 $ fromList [1..4::Double]
30.0

as expected but

*StochVol> (^2) $ norm_2 $ (2><2) [1..4::Double]
29.866068747318504

If this is correct, perhaps the definition of or reference to the norm could be given with the function?

albertoruiz commented 9 years ago

Sorry for the missing documentation, I will update it shortly.

The matrix norms follow the standard definitions found in other numeric software: norm_2 is the maximum singular value, norm_1 is the largest column sum of absolute values, etc.

Thanks for your comment!

idontgetoutmuch commented 9 years ago

Ah that makes sense thanks - so norm_2 should be the usual L2 norm on vectors?

albertoruiz commented 9 years ago

Yes, on vectors norm_1, norm_2, and norm_Inf are the usual L norms, and norm_0 is the number of nonzero elements. On matrices we have the same definitions as in GNU-Octave: norm_1, the largest column sum of the absolute values. norm_2: Largest singular value. norm_Inf: the largest row sum of the absolute values. norm_Frob = norm_2 . flatten (Frobenius norm) and also norm_nuclear = sumElements . singularValues (norm_0 also works on matrices.)