-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RMSE implementation in terms of fast vectors
- Loading branch information
1 parent
ee5ebdb
commit 802533e
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |