Portability | portable |
---|---|
Stability | experimental |
Maintainer | felipe.lessa@gmail.com |
Safe Haskell | Safe-Infered |
This module re-exports functions from Math.Statistics.Dirichlet.Mixture and Math.Statistics.Dirichlet.Options in a more digestable way. Since this library is under-documented, I recommend reading the documentation of the symbols re-exported here.
This module does not use Math.Statistics.Dirichlet.Density in any way. If you don't need mixtures then you should probably use that module directly since it's faster and more reliable (less magic happens there).
- data DirichletMixture = DM {
- dmWeights :: !(Vector Double)
- dmDensities :: !Matrix
- empty :: Int -> Int -> Double -> DirichletMixture
- type Component = (Double, [Double])
- fromList :: [Component] -> DirichletMixture
- toList :: DirichletMixture -> [Component]
- type TrainingVector = Vector Double
- type TrainingVectors = Vector TrainingVector
- newtype StepSize = Step Double
- type Delta = Double
- data Predicate = Pred {
- maxIter :: !Int
- minDelta :: !Delta
- deltaSteps :: !Int
- maxWeightIter :: !Int
- jumpDelta :: !Delta
- data Reason
- data Result a = Result {}
- data TrainingData
- prepareTraining :: TrainingVectors -> TrainingData
- derive :: DirichletMixture -> Predicate -> StepSize -> TrainingData -> Result DirichletMixture
- cost :: TrainingData -> DirichletMixture -> Double
Data types (re-exported)
data DirichletMixture Source
A Dirichlet mixture.
empty :: Int -> Int -> Double -> DirichletMixtureSource
empty q n x
is an "empty" Dirichlet mixture with q
components and n
parameters. Each component has size n
,
weight inversely proportional to its index and all alphas set
to x
.
fromList :: [Component] -> DirichletMixtureSource
fromList xs
constructs a Dirichlet mixture from a
non-empty list of components. Each component has a weight and
a list of alpha values. The weights sum to 1, all lists must
have the same number of values and every number must be
non-negative. None of these preconditions are verified.
toList :: DirichletMixture -> [Component]Source
toList dm
is the inverse of fromList
, constructs a list
of components from a Dirichlet mixture. There are no error
conditions and toList . fromList == id
.
Options (re-exported)
type TrainingVector = Vector DoubleSource
A vector used for deriving the parameters of a Dirichlet density or mixture.
type TrainingVectors = Vector TrainingVectorSource
A vector of training vectors. This is the only vector that is not unboxed (for obvious reasons).
Usually denoted by lowercase greek letter eta (η), size of each step in the gradient. Should be greater than zero and much less than one.
Predicate specifying when the training should be over.
Pred | |
|
Reason why the derivation was over.
Delta | The difference between applications of the cost function dropped below the minimum delta. In other words, it coverged. |
MaxIter | The maximum number of iterations was reached while the delta was still greater than the minimum delta. |
CG Result | CG_DESCENT returned this result, which brought the derivation process to a halt. |
Result of a deriviation.
Training data (re-exported)
data TrainingData Source
Pre-processed training vectors (see prepareTraining
).
prepareTraining :: TrainingVectors -> TrainingDataSource
Prepares training vectors to be used as training data. Anything that depends only on the training vectors is precalculated here.
We also try to find columns where all training vectors are zero. Those columns are removed from the derivation process and every component will have zero value on that column. Note that at least one column should have non-zero training vectors.
Functions (re-exported)
derive :: DirichletMixture -> Predicate -> StepSize -> TrainingData -> Result DirichletMixtureSource
Derive a Dirichlet mixture using a maximum likelihood method as described by Karplus et al (equation 25) using CG_DESCENT method by Hager and Zhang (see Numeric.Optimization.Algorithms.HagerZhang05). All training vectors should have the same length, however this is not verified.
cost :: TrainingData -> DirichletMixture -> DoubleSource
Cost function for deriving a Dirichlet mixture (equation
18). This function is minimized by derive
. Calculated
using (17) and (54).