Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ghc issue with hmatrix

Tags:

haskell

gsl

I'm trying to use hmatrix, and hmatrix-gsl-stats. But I am getting absolutely bizarre results. Can anybody reproduce what I'm seeing?

import Numeric.LinearAlgebra
import Numeric.GSL.Fitting.Linear

main :: IO ()
main = do
  let y = fromList [1,2,3,4,5]
  let x = trans $ fromLists [[1,2,3,4,5], [1,1,1,1,1]]
  let x3 = fromLists [[1,1], [2,1], [3,1], [4,1], [5,1]]
  print $ x == x3
  print $ multifit x y
  print $ multifit x3 y

So I just compile this and run it, and I get:

True
(fromList [0.6121951219512196,0.39756097560975645],(2><2)
 [   0.5100317271465397, -0.46568114217727535
 , -0.46568114217727535,     0.82048582193139 ],27.27560975609756)
(fromList [1.0000000000000002,-8.881784197001252e-16],(2><2)
 [ 2.1364982849735737e-32, -6.40949485492072e-32
 ,  -6.40949485492072e-32, 2.350148113470931e-31 ],6.409494854920721e-31)

Am I missing something totally obvious?

like image 905
Victor Avatar asked Oct 03 '22 16:10

Victor


1 Answers

I think this is a problem with how matrix transposition is handled internally. When you call trans, it's just a flipped bit in the metadata... that is apparently not being inspected when passing the matrix through the FFI.

If you try this, multifit (reshape (cols x) $ flatten x) y, on your penultimate line, you can force the transposition.

like image 143
Anthony Avatar answered Oct 13 '22 11:10

Anthony