himamo v0.1.0 Himamo.Training

Defines the required functions to train a new model by optimizing a given model on the given observation sequences.

Example

iex> # Specifying a model
...> a = fn -> # State transition probabilities
...>   import Himamo.Model.A, only: [new: 1, put: 3]
...>   new(2)
...>   |> put({0, 0}, 0.6) |> put({0, 1}, 0.4)
...>   |> put({1, 0}, 0.9) |> put({1, 1}, 0.1)
...> end.()
...> b = fn -> # Symbol emission probabilities
...>   import Himamo.Model.B, only: [new: 1, put: 3]
...>   new(n: 2, m: 3)
...>   |> put({0, 0}, 0.3) |> put({0, 1}, 0.3) |> put({0, 2}, 0.4)
...>   |> put({1, 0}, 0.8) |> put({1, 1}, 0.1) |> put({1, 2}, 0.1)
...> end.()
...> model = %Himamo.Model{
...>   n: 2, m: 3,
...>   a: a, b: b,
...>   pi: Himamo.Model.Pi.new([0.7, 0.3]), # Initial state probabilities
...> }
...>
...> # Two observation sequences, 3 symbols each (they must have equal
...> # lengths).
...> observation_sequences = [[0, 1, 0], [0, 2, 0]]
...>
...> # Stop training when probability difference between two models is
...> # smaller than this value.
...> delta = 1.0e-3
...>
...> # Training a model based on observation sequences
...> {new_model, _stats, _prob} = Himamo.Training.train(model, observation_sequences, delta)
...> new_model
%Himamo.Model{
  m: 3, n: 2,
  a: %Himamo.Matrix{ size: {2, 2},
    map: %{
      {0, 0} => 3.8825474955088077e-4, {0, 1} => 0.9996117452504493,
      {1, 0} => 0.9999999978716732, {1, 1} => 2.1283266130382603e-9,
    },
  },
  b: %Himamo.Matrix{ size: {2, 3},
    map: %{
      {0, 0} => 2.238512492599514e-9, {0, 1} => 0.42857142761206607, {0, 2} => 0.5714285701494215,
      {1, 0} => 0.9999999956546239, {1, 1} => 2.1726880663668223e-9, {1, 2} => 2.1726880663668223e-9,
    },
  },
  pi: %Himamo.Model.Pi{n: 2, probs: {2.6080207784738667e-9, 0.9999999973919793}},
}

Summary

Functions

train(model, observation_sequences, epsilon)

Train a new model.

Train a new model by iteratively improving the initial model on the given observation_sequences. Stop iterating when proability difference between two successive models is smaller than epsilon.