MUD.hs/test/TestKDE.hs

27 lines
822 B
Haskell
Raw Permalink Normal View History

2024-05-18 01:47:18 +00:00
-- 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