Safe Haskell | None |
---|

Every model in the HLearn library is an instance of the `HomTrainer`

type class. This ensures that the batch trainer is a monoid homomorphism. This is a restrictive condition that not all learning models satisfy; however, it is useful for two reasons. First, this property lets us easily derive three important functions for machine learning algorithms: online trainers, parallel trainers, and fast cross-validation algorithms. Second, many popular algorithms (or variants on them) satisfy the condition and are implemented in the library.

For a full theoretical description of the `HomTrainer`

class, see the paper: HERE

Unfortunately, the class hierarchy here is slightly more complicated. In the paper, we assume that all parameters for a model can be included in the model's type. Currently, however, this is not possible in Haskell, so every model must also have a data type that describes it's parameters. This is the purpose of the `ModelParams`

class. Most models have either no parameters, or reasonable defaults, and so their parameters are instances of the `DefaultParams`

class.

- class Monoid model => HomTrainer model where
- type Datapoint model
- train1dp :: Datapoint model -> model
- train :: (Functor container, Foldable container) => container (Datapoint model) -> model
- add1dp :: model -> Datapoint model -> model
- addBatch :: (Functor container, Foldable container) => model -> container (Datapoint model) -> model
- trainCK :: (Functor container, FunctorConstraint container model, FunctorConstraint container (Datapoint model), Foldable container, FoldableConstraint container model, FoldableConstraint container (Datapoint model)) => container (Datapoint model) -> model
- addBatchCK :: (Functor container, FunctorConstraint container model, FunctorConstraint container (Datapoint model), Foldable container, FoldableConstraint container model, FoldableConstraint container (Datapoint model)) => model -> container (Datapoint model) -> model

- class (Module model, HomTrainer model) => WeightedHomTrainer model where
- train1dpW :: (Ring model, Datapoint model) -> model
- trainW :: (Foldable container, Functor container) => container (Ring model, Datapoint model) -> model
- add1dpW :: model -> WeightedDatapoint model -> model
- addBatchW :: (Foldable container, Functor container) => model -> container (WeightedDatapoint model) -> model

- class HasRing model => NumDP model where
- sub1dp :: (Group model, HomTrainer model) => model -> Datapoint model -> model
- subBatch :: (Group model, HomTrainer model, Foldable container, Functor container) => model -> container (Datapoint model) -> model
- sub1dpW :: (Group model, WeightedHomTrainer model) => model -> WeightedDatapoint model -> model
- subBatchW :: (Group model, WeightedHomTrainer model, Foldable container, Functor container) => model -> container (WeightedDatapoint model) -> model

# HomTrainer

class Monoid model => HomTrainer model whereSource

A minimal complete definition of the class is the singleton trainer 'train1dp\''

train1dp :: Datapoint model -> modelSource

The singleton trainer

train :: (Functor container, Foldable container) => container (Datapoint model) -> modelSource

The batch trainer

add1dp :: model -> Datapoint model -> modelSource

The online trainer

addBatch :: (Functor container, Foldable container) => model -> container (Datapoint model) -> modelSource

The batch online trainer; will be more efficient than simply calling `add1dp`

for each element being added

trainCK :: (Functor container, FunctorConstraint container model, FunctorConstraint container (Datapoint model), Foldable container, FoldableConstraint container model, FoldableConstraint container (Datapoint model)) => container (Datapoint model) -> modelSource

CK methods take advantage of the ContraintKinds extension to allow containers that require constraints. In particular, they allow the use of Unboxed Vectors, which can improve performance.

addBatchCK :: (Functor container, FunctorConstraint container model, FunctorConstraint container (Datapoint model), Foldable container, FoldableConstraint container model, FoldableConstraint container (Datapoint model)) => model -> container (Datapoint model) -> modelSource

(Num r, Ord a) => HomTrainer (FreeModule r a) | |

(HomTrainer model, SingI Nat n, SingI Nat seed, Hashable (Datapoint model)) => HomTrainer (Bagging' n seed model) | |

(Num ring, Ord model, LameTrainer model, Applicative container, Monoid (container model)) => HomTrainer (FreeHomTrainer' * container model) | |

(Num ring, Ord model, LameTrainer model) => HomTrainer (FreeHomTrainer' * (FreeModule ring) model) |

class (Module model, HomTrainer model) => WeightedHomTrainer model whereSource

train1dpW :: (Ring model, Datapoint model) -> modelSource

trainW :: (Foldable container, Functor container) => container (Ring model, Datapoint model) -> modelSource

add1dpW :: model -> WeightedDatapoint model -> modelSource

addBatchW :: (Foldable container, Functor container) => model -> container (WeightedDatapoint model) -> modelSource

(Module model, HomTrainer model) => WeightedHomTrainer model |

class HasRing model => NumDP model whereSource

numdp returns the number of data points that the model has been trained on

# useful functions

sub1dp :: (Group model, HomTrainer model) => model -> Datapoint model -> modelSource

subtracts a single data point from the model

subBatch :: (Group model, HomTrainer model, Foldable container, Functor container) => model -> container (Datapoint model) -> modelSource

subtracts a multiple data point from the model

sub1dpW :: (Group model, WeightedHomTrainer model) => model -> WeightedDatapoint model -> modelSource

subtracts a single weighted data point from the model