예제 #1
0
파일: mom.go 프로젝트: jlund3/modelt
func (m *MoM) conditional(d int) []float64 {
	lcounts := make([]float64, m.T)
	for z := range lcounts {
		prob := math.Log(m.Alpha + float64(m.Topics[z]))
		for v, c := range m.DocWords[d] {
			base := m.Beta + float64(m.TopicWords[z][v])
			prob += util.Lgamma(base + float64(c))
			prob -= util.Lgamma(base)
		}
		base := float64(m.V)*m.Beta + float64(m.TopicsByWord[z])
		prob += util.Lgamma(base)
		prob -= util.Lgamma(base + float64(m.N[d]))
		lcounts[z] = prob
	}
	return lcounts
}
예제 #2
0
파일: dpmom.go 프로젝트: jlund3/modelt
func (m *DPMoM) conditional(d int) (lcounts []float64, mapping []int) {
	lcounts = make([]float64, m.T+1)
	mapping = make([]int, m.T+1)

	i := 0
	for z, used := range m.Used {
		if !used {
			continue
		}

		prob := math.Log(float64(m.Topics[z]))
		for v, c := range m.DocWords[d] {
			base := m.Beta + float64(m.TopicWords[z][v])
			prob += util.Lgamma(base + float64(c))
			prob -= util.Lgamma(base)
		}
		base := float64(m.V)*m.Beta + float64(m.TopicsByWord[z])
		prob += util.Lgamma(base)
		prob -= util.Lgamma(base + float64(m.N[d]))

		lcounts[i] = prob
		mapping[i] = z
		i++
	}

	prob := math.Log(m.Alpha)
	for _, c := range m.DocWords[d] {
		prob += util.Lgamma(m.Beta + float64(c))
		prob -= util.Lgamma(m.Beta)
	}
	prob += util.Lgamma(float64(m.V) * m.Beta)
	prob -= util.Lgamma(float64(m.N[d]) + float64(m.V)*m.Beta)
	lcounts[i] = prob
	mapping[i] = newCluster

	return
}