Esempio n. 1
0
File: itm.go Progetto: jlund3/modelt
// NewITM creates a new ITM from the given Corpus and parameters.
func NewITM(c *pipeline.Corpus, T int, alpha, beta, eta float64) *ITM {
	z := make([][]int, c.M)
	for d, n := range c.N {
		z[d] = make([]int, n)
	}

	l := make([]int, c.V)
	cv := make([]map[int]struct{}, c.V)
	for i := range l {
		l[i] = i
		cv[i] = map[int]struct{}{i: struct{}{}}
	}

	dt := util.New2DCounter(c.M, T)
	tl := util.New2DCounter(T, c.V)
	t := util.NewCounter(T)

	tlv := make([][]map[int]int, T)
	for z := range tlv {
		tlv[z] = make([]map[int]int, c.V)
		for i := range tlv[z] {
			tlv[z][i] = make(map[int]int)
		}
	}

	itm := &ITM{c, T, alpha, beta, eta, z, l, cv, dt, tl, t, tlv}

	for d := 0; d < c.M; d++ {
		for n := 0; n < c.N[d]; n++ {
			itm.setZ(d, n, rand.Intn(T))
		}
	}

	return itm
}
Esempio n. 2
0
func newBase(c *pipeline.Corpus, initT, maxT int) base {
	z := make([]int, c.M)

	tv := util.New2DCounter(maxT, c.V)
	dv := util.NewSparse2DCounter(c.M, c.V)
	t := util.NewCounter(maxT)
	tw := util.NewCounter(maxT)

	for d := 0; d < c.M; d++ {
		zd := rand.Intn(initT)
		z[d] = zd

		t[zd]++
		tw[zd] += c.N[d]
		for _, v := range c.W[d] {
			tv[zd][v]++
			dv[d][v]++
		}
	}

	return base{c, initT, z, tv, dv, t, tw}
}
Esempio n. 3
0
File: lda.go Progetto: jlund3/modelt
// NewLDA creates a new LDA from the given Corpus and parameters.
func NewLDA(c *pipeline.Corpus, T int, alpha, beta float64) *LDA {
	z := make([][]int, c.M)
	for d, n := range c.N {
		z[d] = make([]int, n)
	}

	dt := util.New2DCounter(c.M, T)
	tv := util.New2DCounter(T, c.V)
	t := util.NewCounter(T)

	lda := &LDA{c, T, alpha, beta, z, dt, tv, t}

	for d := 0; d < c.M; d++ {
		for n := 0; n < c.N[d]; n++ {
			lda.setZ(d, n, rand.Intn(T))
		}
	}

	return lda
}