Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add AnyModel for working with collections of inhomogenous models

  • Loading branch information...
commit e8d69dff3a3a944920786a1db62524f40e64722e 1 parent 2168b56
@batterseapower authored
Showing with 11 additions and 2 deletions.
  1. +7 −2 Algorithms/MachineLearning/Framework.hs
  2. +4 −0 machine-learning.cabal
View
9 Algorithms/MachineLearning/Framework.hs
@@ -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
4 machine-learning.cabal
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.