Safe Haskell | None |
---|

This module contains "low-level higher order functions" for manipulating algebraic homomorphisms. You probably want to use the HomTrainer type-class rather than using these functions directly.

- class Function f domain range | f domain -> range where
- function :: f -> domain -> range

- parallel :: (Monoid model, NFData model, Partitionable container, PartitionableConstraint container datapoint) => (container datapoint -> model) -> container datapoint -> model
- online :: Monoid model => (datapoint -> model) -> model -> datapoint -> model
- offline :: Monoid model => (model -> datapoint -> model) -> datapoint -> model
- batch :: (Monoid model, Functor container, Foldable container) => (datapoint -> model) -> container datapoint -> model
- batchCK :: (Monoid model, Functor container, FunctorConstraint container model, FunctorConstraint container datapoint, Foldable container, FoldableConstraint container model) => (datapoint -> model) -> container datapoint -> model
- unbatch :: ([datapoint] -> model) -> datapoint -> model
- semigroup :: (model -> datapoint -> model) -> (model -> datapoint) -> model -> model -> model
- reduce :: (Monoid sg, Foldable container) => container sg -> sg

# Almost dependently typed function

class Function f domain range | f domain -> range whereSource

Every data type that implements this class has a corresponding function. We can use this data type as type level parameters to other data types. This gives us some of the benefit of dependently typed functions.

# Higher order functions

## Parallelism

:: (Monoid model, NFData model, Partitionable container, PartitionableConstraint container datapoint) | |

=> (container datapoint -> model) | sequential batch trainer |

-> container datapoint -> model | parallel batch trainer |

Parallelizes any batch trainer to run over multiple processors on a single machine. The function automatically detects the number of available processors and parallelizes the function accordingly. This requires the use of unsafePerformIO, however, the result should still be safe.

## Manipulating homomorphisms

:: Monoid model | |

=> (datapoint -> model) | singleton trainer |

-> model -> datapoint -> model | online trainer |

Converts a batch trainer into an online trainer. The input function should be a semigroup homomorphism.

:: Monoid model | |

=> (model -> datapoint -> model) | online singleton trainer |

-> datapoint -> model | singleton trainer |

The inverse of `online`

. Converts an online trainer into a batch trainer.

:: (Monoid model, Functor container, Foldable container) | |

=> (datapoint -> model) | singleton trainer |

-> container datapoint -> model | batch trainer |

Converts a singleton trainer into a batch trainer, which is also a semigroup homomorphism.

:: (Monoid model, Functor container, FunctorConstraint container model, FunctorConstraint container datapoint, Foldable container, FoldableConstraint container model) | |

=> (datapoint -> model) | singleton trainer |

-> container datapoint -> model | batch trainer |

:: ([datapoint] -> model) | batch trainer |

-> datapoint -> model | singleton trainer |

Inverse of `unbatch`

. Converts a semigroup homomorphism into a singleton trainer.

:: (model -> datapoint -> model) | online trainer |

-> (model -> datapoint) | pseudo inverse |

-> model -> model -> model | The semigroup operation |

Normally we would define our semigroup operation explicitly. However, it is possible to generate one from an online trainer and a pseudo inverse.

## Helper functions

reduce :: (Monoid sg, Foldable container) => container sg -> sgSource

Like fold, but (i) only for use on the semigroup operation (<>) and (ii) uses the fan-in reduction strategy which is more efficient when the semigroup operation takes nonconstant time depending on the size of the data structures being reduced.