Skip to content

Commit

Permalink
RMSE implementation in terms of fast vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephBond committed Sep 20, 2023
1 parent ee5ebdb commit 802533e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions example/Util/BMA.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Example.Util.BMA where

import Prelude

import Data.FastVect.FastVect (Vect)
import Data.Foldable (foldl)
import Data.Int (toNumber)
import Data.Number (pow)

product :: forall a len. Semiring a => Vect len a -> a
product v = foldl (*) one v

sum :: forall a len. Semiring a => Vect len a -> a
sum v = foldl (+) zero v

vlen :: forall a len. Vect len a -> Int
vlen xs = foldl (\count _x -> (+) 1 count) 0 xs

vlenN :: forall a len. Vect len a -> Number
vlenN = toNumber <<< vlen

mean :: forall len. Number -> Vect len Number -> Number
mean 0.0 xs = product xs `pow` (1.0 / vlenN xs)
mean p xs = (1.0 / vlenN xs * sum (map (pow p) xs)) `pow` (1.0/p)

0 comments on commit 802533e

Please sign in to comment.