module HasGP.Demos.RegressionDemo1 where
import Numeric.LinearAlgebra
import Numeric.GSL.Minimization
import HasGP.Data.BishopData
import HasGP.Types.MainTypes
import HasGP.Support.Linear
import HasGP.Support.Random
import HasGP.Regression.Regression
import HasGP.Covariance.SquaredExp
demo = do
putStrLn "Generating the training data..."
let (inputs, targets) = bishopData
saveMatrix "inputs.txt" "%g" inputs
fprintfVector "targets.txt" "%g" targets
putStrLn "Searching for best hyperparameters..."
let f = gpRLogHyperToEvidence (SquaredExponential 0 0) inputs targets
let ev = fst . f
let gev = snd . f
let (solution, path) =
minimizeVD ConjugatePR 0.0001 50 0.01 0.1 ev gev
(constant (log 0.1) 3)
putStrLn $ "Found: " ++ (show solution)
putStrLn $ "Path: "
putStrLn $ show path
putStrLn "Learning and predicting..."
let newPoints = fromColumns $ [linspace 100 (0.0,1.0)]
let (newOuts, var) =
gpRPredict' (SquaredExponential (solution @> 1) (solution @> 2))
(solution @> 0) inputs targets newPoints
fprintfVector "outputs.txt" "%g" newOuts
fprintfVector "variances.txt" "%g" var
putStrLn "Done"
return ()