Permalink
Browse files

Add AnyModel for working with collections of inhomogenous models

  • Loading branch information...
1 parent 2168b56 commit e8d69dff3a3a944920786a1db62524f40e64722e @batterseapower committed Sep 12, 2008
Showing with 11 additions and 2 deletions.
  1. +7 −2 Algorithms/MachineLearning/Framework.hs
  2. +4 −0 machine-learning.cabal
@@ -133,10 +133,15 @@ instance MetricSpace (Vector Double) where
-- Models
--
-class (Vectorable input, Vectorable target) => Model model input target | model -> input target where
+class Model model input target | model -> input target where
predict :: model -> input -> target
-modelSumSquaredError :: (Model model input target, MetricSpace target) => model -> DataSet input target -> Double
+data AnyModel input output = forall model. Model model input output => AnyModel { theModel :: model }
+
+instance Model (AnyModel input output) input output where
+ predict (AnyModel model) = predict model
+
+modelSumSquaredError :: (Model model input target, MetricSpace target, Vectorable input, Vectorable target) => model -> DataSet input target -> Double
modelSumSquaredError model ds = sum [sample_error * sample_error | sample_error <- sample_errors]
where
sample_errors = zipWith (\x y -> x `distance` y) (dataSetTargets ds) (map (predict model) (dataSetInputs ds))
View
@@ -41,6 +41,8 @@ Library
TypeSynonymInstances
FlexibleInstances
FlexibleContexts
+ ExistentialQuantification
+ ScopedTypeVariables
Ghc-Options: -O2 -fvia-C -Wall
Executable machine-learning-tests
@@ -60,6 +62,8 @@ Executable machine-learning-tests
TypeSynonymInstances
FlexibleInstances
FlexibleContexts
+ ExistentialQuantification
+ ScopedTypeVariables
Ghc-Options: -O2 -fvia-C -Wall
if !flag(tests)

0 comments on commit e8d69df

Please sign in to comment.