27 lines
822 B
Haskell
27 lines
822 B
Haskell
|
-- TestKDE.hs
|
||
|
module TestKDE (tests) where
|
||
|
|
||
|
import MUD (kde)
|
||
|
import RandomUtils (generateUniformPoints)
|
||
|
import Data.List (intercalate)
|
||
|
|
||
|
tests :: IO ()
|
||
|
tests = do
|
||
|
-- List of 21 equispaced points from -5 to 5
|
||
|
let grdpoints :: [Double]
|
||
|
grdpoints = [-5, -4.5 .. 5]
|
||
|
|
||
|
-- Generate 10 random points from a normal distribution
|
||
|
controlPoints <- generateUniformPoints 10 (-1.0, 1.0)
|
||
|
|
||
|
-- Fit the KDE to the random points with a specified bandwidth
|
||
|
let bandwidth = 0.5
|
||
|
let kdeEstimator = kde controlPoints bandwidth
|
||
|
|
||
|
-- Evaluate the KDE on the grid from -5 to 5
|
||
|
let evaluations = map kdeEstimator grdpoints
|
||
|
|
||
|
putStrLn "KDE evaluations at points from -5 to 5:"
|
||
|
putStrLn $ intercalate "\n" $ zipWith (\x y -> "x = " ++ show x ++ ", KDE = " ++ show y) grdpoints evaluations
|
||
|
|