HLearn-algebra 0.1.1.0 → 0.1.2.0
raw patch · 6 files changed
+78/−9 lines, 6 files
Files
- HLearn-algebra.cabal +3/−1
- src/HLearn/Algebra.hs +4/−0
- src/HLearn/Algebra/Models.hs +7/−7
- src/HLearn/Algebra/Models/Lame.hs +40/−0
- src/HLearn/Algebra/Structures/Free/RegSG2Group.hs +1/−1
- src/HLearn/Algebra/Structures/Triangles.hs +23/−0
HLearn-algebra.cabal view
@@ -1,5 +1,5 @@ Name: HLearn-algebra-Version: 0.1.1.0+Version: 0.1.2.0 Synopsis: Algebraic foundation for homomorphic learning Description: This module contains the algebraic basis for the HLearn library. It is separated out in it's own library because it contains routines that may be useful to others. In particular, it contains methods for automatically converting algorithms into online/parallel versions, and its structure is slightly more modular (although much less complete) than other algebra packages. Category: Data Mining, Machine Learning@@ -25,7 +25,9 @@ HLearn.Algebra HLearn.Algebra.Functions HLearn.Algebra.Models+ HLearn.Algebra.Models.Lame HLearn.Algebra.Morphism HLearn.Algebra.Structures.Groups HLearn.Algebra.Structures.Modules HLearn.Algebra.Structures.Free.RegSG2Group+ HLearn.Algebra.Structures.Triangles
src/HLearn/Algebra.hs view
@@ -3,16 +3,20 @@ module HLearn.Algebra ( module HLearn.Algebra.Functions , module HLearn.Algebra.Models+ , module HLearn.Algebra.Models.Lame , module HLearn.Algebra.Morphism , module HLearn.Algebra.Structures.Groups , module HLearn.Algebra.Structures.Modules , module HLearn.Algebra.Structures.Free.RegSG2Group+ , module HLearn.Algebra.Structures.Triangles ) where import HLearn.Algebra.Functions import HLearn.Algebra.Models+import HLearn.Algebra.Models.Lame import HLearn.Algebra.Morphism import HLearn.Algebra.Structures.Groups import HLearn.Algebra.Structures.Modules import HLearn.Algebra.Structures.Free.RegSG2Group+import HLearn.Algebra.Structures.Triangles
src/HLearn/Algebra/Models.hs view
@@ -45,7 +45,7 @@ -- Model -- | Every model has at least one data type that that fully describes its parameters. Many models do not actually *need* any parameters, in which case they will simply use an empty data type for modelparams.-class Model modelparams model | modelparams -> model{-, model -> modelparams-} where+class Model modelparams model | modelparams -> model, model -> modelparams where getparams :: model -> modelparams -- | For those algorithms that do not require parameters (or that have reasonable default parameters), this class lets us use a more convenient calling notation.@@ -57,7 +57,7 @@ ( Semigroup model , Monoid model , Model modelparams model- ) => HomTrainer modelparams datapoint model | model -> modelparams+ ) => HomTrainer modelparams datapoint model | model -> modelparams datapoint where -- | The singleton trainer@@ -115,11 +115,11 @@ ) => model -> container datapoint -> model subBatch model xs = model <> (inverse $ train xs) -instance - ( HomTrainer modelparams datapoint model- , LeftOperator r model- ) => HomTrainer modelparams (r,datapoint) model where- train1dp' modelparams (r,dp) = r .* (train1dp' modelparams dp)+-- instance +-- ( HomTrainer modelparams datapoint model+-- , LeftOperator r model+-- ) => HomTrainer modelparams (r,datapoint) model where+-- train1dp' modelparams (r,dp) = r .* (train1dp' modelparams dp) -- instance -- ( HomTrainer modelparams datapoint model
+ src/HLearn/Algebra/Models/Lame.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE ConstraintKinds #-}++-- | Lame trainers are trainers that are crippled---They are not instances of Semigroup/Monoid, and training their models is not a homomorphism. This means we can't do any of the cool manipulations automatically that we can do with the HomTrainer class.++module HLearn.Algebra.Models.Lame+ ( + -- * Classes+ LameTrainer (..)+ , LameTrainerOnline (..)+ , Sizable (..)+ )+ where+ +import qualified Control.ConstraintKinds as CK+import HLearn.Algebra.Models++class Sizable t where+ size :: t a -> Int+ +instance Sizable [] where+ size = length+ +class (Model modelparams model) => LameTrainer modelparams datapoint model where+ lame_train :: + ( CK.Functor container+ , CK.FunctorConstraint container model+ , CK.FunctorConstraint container datapoint+ , CK.Foldable container+ , CK.FoldableConstraint container model+ , Sizable container+ ) => modelparams -> container datapoint -> model+ +class (Model modelparams model) => LameTrainerOnline modelparams datapoint model where+ lame_add1dp :: model -> datapoint -> model
src/HLearn/Algebra/Structures/Free/RegSG2Group.hs view
@@ -15,7 +15,7 @@ import Control.DeepSeq -- | Convert any regular semigroup into a group (and thus also a monoid) by adding a unique identity element-data (RegularSemigroup sg) => RegSG2Group sg = SGNothing | SGJust sg+data RegSG2Group sg = SGNothing | SGJust sg deriving (Show,Read,Ord,Eq) instance (RegularSemigroup sg) => Semigroup (RegSG2Group sg) where
+ src/HLearn/Algebra/Structures/Triangles.hs view
@@ -0,0 +1,23 @@+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}++module HLearn.Algebra.Structures.Triangles+ ( Triangle (..)+-- , module Data.Sequence+ )+ where++import qualified Data.Sequence as S+import Data.Sequence hiding ((<|),(|>))++class Triangle f a where+ (<|) :: a -> f -> f+ (|>) :: f -> a -> f+ +instance Triangle [a] a where+ a <| xs = a:xs+ xs |> a = xs++[a]++instance Triangle (S.Seq a) a where+ (<|) = (S.<|)+ (|>) = (S.|>)