-
Notifications
You must be signed in to change notification settings - Fork 0
/
emission.go
52 lines (46 loc) · 1.06 KB
/
emission.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package hmm
import(
"github.com/johnmcconnell/gologspace"
)
type Emission map[Tag]map[string]float64
func (e *Emission) P(tag Tag, val string) float64 {
return (*e)[tag][val]
}
func NewEmission(tags []Tag) Emission {
e := make(Emission)
for _, tag := range tags {
e[tag] = make(map[string]float64)
}
return e
}
func UniformE(emissions ECache, words []string, s gologspace.Space) Emission {
e := make(Emission)
one := s.Enter(1.0)
zero := s.Enter(0.0)
for tag, foundWs := range emissions {
e[tag] = make(map[string]float64)
// Zero initial values
for _, word := range words {
e[tag][word] = zero
}
length := float64(len(words))
size := s.Enter(length)
for word, _ := range foundWs {
e[tag][word] = one / size
}
}
return e
}
func UniformE2(tags []Tag, words []string, s gologspace.Space) Emission {
e := make(Emission)
one := s.Enter(1.0)
for _, tag := range tags {
e[tag] = make(map[string]float64)
length := float64(len(words))
size := s.Enter(length)
for _, word := range words {
e[tag][word] = one / size
}
}
return e
}