module HasGP.Demos.ClassificationDemo2 where
import Numeric.LinearAlgebra
import Numeric.GSL.Minimization
import HasGP.Types.MainTypes
import HasGP.Support.Linear
import HasGP.Classification.EP.ClassificationEP
import HasGP.Covariance.SquaredExpARD
import HasGP.Covariance.Basic
stopEP::EPConvergenceTest
stopEP s1 s2 = ((count s2) == 100) ||
((eValue s1) > (eValue s2)) ||
(abs ((eValue s1) (eValue s2)) < 0.001)
demo = do
putStrLn "Loading the training data..."
inputs <- loadMatrix "gpml-classifier-x.txt"
targets <- fscanfVector "gpml-classifier-y.txt" 120
points <- loadMatrix "gpml-classifier-test.txt"
putStrLn "Learning and predicting: EP + hyperparameter optimization..."
let cov = SquaredExponentialARD (log 1.0) (constant (log 1.0) 2)
let c = covarianceMatrix cov inputs
let f = (\v -> gpClassifierEPLogEvidenceVec inputs targets cov
generateRandomSiteOrder stopEP v)
let ev = fst . f
let gev = snd . f
let (solution, path) =
minimizeVD ConjugatePR 0.0001 50 1 0.0001 ev gev
(constant (log 1) 3)
putStrLn $ "Solution: " ++ (show $ mapVector exp solution)
putStrLn $ "Path: "
putStrLn $ show path
let cov' = SquaredExponentialARD (solution @> 0)
(fromList [(solution @> 1), (solution @> 2)])
let c' = covarianceMatrix cov' inputs
let (epValue, epState) =
gpClassifierEPLearn c' targets generateRandomSiteOrder stopEP
let classify =
gpClassifierEPPredict (siteState epValue) inputs targets c' cov'
let newOuts = classify points
fprintfVector "gpml-hasgp-outputs.txt" "%g" newOuts
putStrLn $ "Done"
return ()