mikeizbicki / HLearn

Homomorphic machine learning
Other
1.63k stars 138 forks source link

Gaussian distribution? #31

Closed gliptak closed 10 years ago

gliptak commented 10 years ago

https://github.com/mikeizbicki/HLearn/tree/master/HLearn-distributions/src/HLearn/Models/Distributions/Univariate

contains a Gaussian.lhs, but not a Gaussian.hs, so Gaussian distribution is no longer available. Please add Gaussian.hs.

Thanks

mikeizbicki commented 10 years ago

The Gaussian distribution has been renamed to the Normal distribution. Use that and you should be good. I thought I removed Gaussian.lhs from the repo, but apparently not :)

gliptak commented 10 years ago

Thanks. From http://izbicki.me/blog/gausian-distributions-are-monoids

,bench "HLearn-Gaussian" $
 whnf (train :: VU.Vector Double -> Normal Double Double)
 (VU.enumFromN (0 ::Double) size)

gives compile error:

hlearn1.hs:46:12:
No instance for (Data.Foldable.Foldable VU.Vector)
  arising from a use of `train'
Possible fix:
  add an instance declaration for (Data.Foldable.Foldable VU.Vector)
In the first argument of `whnf', namely
  `(train :: VU.Vector Double -> Normal Double Double)'
In the second argument of `($)', namely
  `whnf
     (train :: VU.Vector Double -> Normal Double Double)
     (VU.enumFromN (0 :: Double) size)'
In the expression:
  bench "HLearn-Gaussian"
  $ whnf
      (train :: VU.Vector Double -> Normal Double Double)
      (VU.enumFromN (0 :: Double) size)

which can be corrected by

import qualified Data.Vector as V
,bench "HLearn-Gaussian" $
 whnf (train :: V.Vector Double -> Normal Double Double)
 (V.enumFromN (0 ::Double) size)

but now the benchmarks are no longer comparable ...

Could you suggest a different way to correct?

mikeizbicki commented 10 years ago

The interface has been updated to include a function called trainck. (This simplifies the type signature for the train function considerably, and in practice I've found that the performance benefit of unboxed vectors isn't super important.) This function uses the version of Foldable found in the ConstraintKinds package, also on gihub and hackage. This package uses the ConstraintKinds extension to allow us to make Unboxed Vectors instances of Foldable.