Skip to content

Commit

Permalink
Changed order of HMM arguments
Browse files Browse the repository at this point in the history
It made more sense for initial-prob to come before the other
probabilities, so now it does.
  • Loading branch information
dwysocki committed Mar 20, 2015
1 parent c8c830b commit eb73588
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/hidden_markov_music/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
(def song-model
(HMM. song-states
song-notes
{:beginning 1.0,
:middle 0.0,
:chorus 0.0,
:finale 0.0,
:end 0.0}
{:beginning {:beginning 0.8,
:middle 0.2,
:chorus 0.0,
Expand All @@ -47,12 +52,7 @@
:chorus 0.0,
:finale 0.0,
:end 1.0}}
(stats/random-row-stochastic-map song-states song-notes)
{:beginning 1.0,
:middle 0.0,
:chorus 0.0,
:finale 0.0,
:end 0.0}))
(stats/random-row-stochastic-map song-states song-notes)))

(def models
{"weather" random-weather-model,
Expand Down
12 changes: 6 additions & 6 deletions src/hidden_markov_music/hmm.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
(defrecord HMM
[states
observations
initial-prob
transition-prob
observation-prob
initial-prob])
observation-prob])

;; HMM has no docstring, but the functions it generates do.
;; attach some more descriptive text to those functions
Expand All @@ -24,9 +24,9 @@
(HMM.
states
observations
(stats/random-stochastic-map states)
(stats/random-row-stochastic-map states states)
(stats/random-row-stochastic-map states observations)
(stats/random-stochastic-map states)))
(stats/random-row-stochastic-map states observations)))

(defn forward-probability-initial
"Returns `α_1(i)`, for all states `i`.
Expand Down Expand Up @@ -476,9 +476,9 @@
new-model (HMM.
(:states model)
(:observations model)
new-initial-probs
new-transition-probs
new-observation-probs
new-initial-probs)
new-observation-probs)

new-likelihood (likelihood-forward new-model observations)]
(if (> (- new-likelihood likelihood)
Expand Down
28 changes: 14 additions & 14 deletions test/hidden_markov_music/test_models.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

[:good :bad :so-so]

{:sunny (/ 3.0),
:cloudy (/ 3.0),
:rainy (/ 3.0)}

{:sunny {:sunny 0.5,
:cloudy 0.3,
:rainy 0.2},
Expand All @@ -26,11 +30,7 @@
:so-so 0.5},
:rainy {:good 0.1,
:bad 0.6,
:so-so 0.3}}

{:sunny (/ 3.0)
:cloudy (/ 3.0),
:rainy (/ 3.0)}))
:so-so 0.3}}))

(def ibe-ex-11-observations
[:good :good :so-so :bad :bad])
Expand All @@ -48,6 +48,10 @@

[:a :b :c]

{:A 1.0,
:B 0.0,
:C 0.0}

{:A {:A 0.0,
:B 1.0,
:C 0.0},
Expand All @@ -66,11 +70,7 @@
:c 0.0},
:C {:a 0.0,
:b 0.0,
:c 1.0}}

{:A 1.0,
:B 0.0,
:C 0.0}))
:c 1.0}}))

(def deterministic-certain-observations
[:a :b :c :a :b :c])
Expand All @@ -87,6 +87,9 @@

[:a :b]

{:A 0.5,
:B 0.5}

{:A {:A 0.0,
:B 1.0},
:B {:A 1.0,
Expand All @@ -95,10 +98,7 @@
{:A {:a 1.0,
:b 0.0},
:B {:a 0.0,
:b 1.0}}

{:A 0.5,
:B 0.5}))
:b 1.0}}))

(def a-50-50-observations
[:a :b :a :b :a :b])
Expand Down

0 comments on commit eb73588

Please sign in to comment.