Beispiel #1
0
func (self *Strategy) consume(state *algorithm.State) {
	ni, no := self.ni, self.no
	np := uint(len(self.priority))
	na := uint(len(self.accuracy))
	nn := uint(len(state.Counts))

	self.priority = append(self.priority, make([]float64, nn)...)
	priority := self.priority[np:]

	self.accuracy = append(self.accuracy, make([]float64, nn*no)...)
	accuracy := self.accuracy[na:]

	levels := internal.Levelize(state.Lndices, ni)

	for i, o := uint(0), uint(0); i < nn; i++ {
		count := state.Counts[i]
		if levels[i] < uint64(self.lmin) {
			priority[i] = internal.Infinity
			internal.Set(accuracy[i*no:(i+1)*no], internal.Infinity)
		} else if levels[i] < uint64(self.lmax) {
			priority[i] = internal.Average(state.Scores[o:(o + count)])
			self.threshold.Compress(accuracy[i*no:(i+1)*no],
				state.Surpluses[o*no:(o+count)*no])
		}
		o += count
	}

	self.threshold.Update(state.Values)
}
Beispiel #2
0
func (self *Strategy) consume(state *algorithm.State) {
	ni, no := self.ni, self.no
	np := uint(len(self.priority))
	na := uint(len(self.accuracy))
	ns := uint(len(self.scores))
	nn := uint(len(state.Counts))

	self.priority = append(self.priority, make([]float64, nn)...)
	priority := self.priority[np:]

	self.accuracy = append(self.accuracy, make([]float64, nn*no)...)
	accuracy := self.accuracy[na:]

	self.scopes = append(self.scopes, make([][]uint, nn)...)
	scopes := self.scopes[np:]

	self.scores = append(self.scores, make([]float64, len(state.Scores))...)
	scores := self.scores[ns:]

	groups := state.Data.([][]uint64)
	levels := internal.Levelize(state.Lndices, ni)

	for i, o := uint(0), uint(0); i < nn; i++ {
		count := state.Counts[i]
		if levels[i] < uint64(self.lmin) {
			internal.Set(accuracy[i*no:(i+1)*no], internal.Infinity)
			internal.Set(scores[o:(o+count)], internal.Infinity)
		} else if levels[i] < uint64(self.lmax) {
			self.threshold.Compress(accuracy[i*no:(i+1)*no],
				state.Surpluses[o*no:(o+count)*no])
			copy(scores[o:(o+count)], state.Scores[o:(o+count)])
		}
		for j := uint(0); j < count; j++ {
			index := state.Indices[(o+j)*ni : (o+j+1)*ni]
			self.indexer[self.hash.Key(index)] = ns + o + j
		}
		o += count
	}

	for i := uint(0); i < nn; i++ {
		count := uint(len(groups[i])) / ni
		scope := make([]uint, count)
		for j := uint(0); j < count; j++ {
			index := groups[i][j*ni : (j+1)*ni]
			k, ok := self.indexer[self.hash.Key(index)]
			if !ok {
				panic("something went wrong")
			}
			scope[j] = k
		}
		scopes[i] = scope
		if levels[i] < uint64(self.lmin) {
			priority[i] = internal.Infinity
		} else if levels[i] < uint64(self.lmax) {
			for _, j := range scope {
				priority[i] += self.scores[j]
			}
			priority[i] /= float64(count)
		}
		lndex := state.Lndices[i*ni : (i+1)*ni]
		self.lndexer[self.hash.Key(lndex)] = np + i
	}

	self.threshold.Update(state.Values)
}