當前位置: 首頁>>代碼示例>>Golang>>正文


Golang data.Bitset類代碼示例

本文整理匯總了Golang中github.com/dukejeffrie/htm/data.Bitset的典型用法代碼示例。如果您正苦於以下問題:Golang Bitset類的具體用法?Golang Bitset怎麽用?Golang Bitset使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Bitset類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Decode

func (s ScalarSensor) Decode(bits data.Bitset) interface{} {
	found := bits.Any(func(int) bool {
		return true
	})

	return (0.5+float64(found))*s.BucketSize + s.MinValue
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:7,代碼來源:sensor.go

示例2: LearnSequence

func (c *Column) LearnSequence(learnState data.Bitset) {
	logEnabled := log.HtmLogger.Enabled()
	if learnState.IsZero() {
		// Select the learning cell, but don't increment the target.
		c.learning = c.learningTarget
		if logEnabled {
			log.HtmLogger.Printf("\t(%d, %d)=%04d: skip learning empty sequence",
				c.Index, c.learning, c.CellId(c.learning))
		}
		return
	}
	cell, sIndex, _ := c.FindBestSegment(learnState, 1, true)
	if sIndex >= 0 {
		if logEnabled {
			log.HtmLogger.Printf("\t(%d, %d)=%04d: Will reinforce segment: %v",
				c.Index, cell, c.CellId(cell), c.distal[cell].Segment(sIndex))
		}
	} else {
		if logEnabled {
			log.HtmLogger.Printf("\t(%d, %d)=%04d: Will learn a new segment.",
				c.Index, c.learningTarget, c.CellId(c.learningTarget))
		}
		cell = c.learningTarget
		c.learningTarget = (c.learningTarget + 1) % c.Height()
		sIndex = -1
	}
	c.learning = cell
	update := c.distal[cell].CreateUpdate(sIndex, learnState, 1)
	if logEnabled {
		log.HtmLogger.Printf("\tLearning sequence %v => (%d, %d)=%04d",
			update, c.Index, cell, c.CellId(cell))
	}
	c.distal[cell].Apply(update, true)
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:34,代碼來源:column.go

示例3: FindBestSegment

func (c Column) FindBestSegment(state data.Bitset, minOverlap int, weak bool) (bestCell, bestSegment, bestOverlap int) {
	bestCell = -1
	bestSegment = -1
	bestOverlap = minOverlap - 1
	maxOverlap := state.NumSetBits()
	for i := 0; i < c.Height(); i++ {
		sIndex, sOverlap := c.distal[i].ComputeActive(state, minOverlap, weak)
		if sOverlap > bestOverlap {
			bestCell = i
			bestSegment = sIndex
			bestOverlap = sOverlap
			if bestOverlap == maxOverlap {
				break
			}
		}
	}
	if log.HtmLogger.Enabled() {
		if bestSegment >= 0 {
			s := c.distal[bestCell].Segment(bestSegment)
			log.HtmLogger.Printf("\t\tFind best segment for column=%d, state=%v, minOverlap=%d, weak=%t: (%d, %d)=%04d <= %v (overlap=%d)",
				c.Index, state, minOverlap, weak, c.Index, bestCell, c.CellId(bestCell),
				s.Connected(), bestOverlap)
		}
	}
	return
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:26,代碼來源:column.go

示例4: weaken

func (pm *PermanenceMap) weaken(input data.Bitset) {
	for k, v := range pm.permanence {
		if input.IsSet(k) {
			v -= pm.config.Decrement
		}
		pm.Set(k, v)
	}
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:8,代碼來源:permanence_map.go

示例5: PermanenceMapFromBits

func PermanenceMapFromBits(bits data.Bitset) (pm *PermanenceMap) {
	pm = NewPermanenceMap(bits.Len())
	bits.Foreach(func(k int) {
		pm.permanence[k] = pm.config.Initial
	})
	if pm.config.Initial > pm.config.Threshold {
		pm.synapses.Or(bits)
	}
	return pm
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:10,代碼來源:permanence_map.go

示例6: narrow

func (pm *PermanenceMap) narrow(input data.Bitset) {
	for k, v := range pm.permanence {
		if input.IsSet(k) {
			v += pm.config.Increment
		} else {
			v -= pm.config.Decrement
		}
		pm.Set(k, v)
	}
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:10,代碼來源:permanence_map.go

示例7: ConfirmPrediction

func (c *Column) ConfirmPrediction(state data.Bitset) bool {
	if c.learning >= 0 && state.IsSet(c.CellId(c.learning)) {
		if log.HtmLogger.Enabled() {
			log.HtmLogger.Printf("\t(%d, %d)=%04d: Confirmed prediction.",
				c.Index, c.learning, c.CellId(c.learning))
		}
		return true
	}
	return false
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:10,代碼來源:column.go

示例8: FeedBack

func (l *Region) FeedBack(output data.Bitset) *data.Bitset {
	dest := data.NewBitset(l.InputLength)
	output.Foreach(func(cellId int) {
		col := l.columns[cellId/l.Height()]
		cell := cellId % l.Height()
		if !col.Distal(cell).HasActiveSegment(output, l.MinimumInputOverlap) {
			// Not a predicted cell, must be active from fast-forward.
			dest.Or(col.Connected())
		}
	})
	return dest
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:12,代碼來源:region.go

示例9: CreateUpdate

func (g *DistalSegmentGroup) CreateUpdate(sIndex int, activeState data.Bitset, minSynapses int) *SegmentUpdate {
	state := data.NewBitset(activeState.Len())
	if sIndex >= 0 {
		s := g.segments[sIndex]
		state.ResetTo(s.Connected())
	}
	state.Or(activeState)
	for num := state.NumSetBits(); num < minSynapses; num = state.NumSetBits() {
		// TODO(tms): optimize.
		indices := segmentRand.Perm(state.Len())[num:minSynapses]
		state.Set(indices...)
	}
	return NewSegmentUpdate(sIndex, state)
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:14,代碼來源:segment.go

示例10: broaden

func (ds *DendriteSegment) broaden(input data.Bitset, minOverlap int) (overlapCount int) {
	overlapCount = input.Overlap(ds.Connected())
	threshold := ds.Config().Threshold
	newPermanence := ds.Config().Minimum + ds.Boost
	if newPermanence > threshold {
		newPermanence = threshold
	}
	newSynapses := input.Clone()
	newSynapses.AndNot(ds.ReceptiveField())
	newSynapses.Foreach(func(k int) {
		v := ds.Get(k)
		if v < newPermanence {
			ds.Set(k, newPermanence)
		}
	})
	ds.overlapHistory.Record(overlapCount >= minOverlap)
	if avg, ok := ds.overlapHistory.Average(); ok && avg < ds.MinActivityRatio {
		for k, v := range ds.permanence {
			ds.Set(k, v*1.01)
		}
	}
	return
}
開發者ID:postfix,項目名稱:htm-1,代碼行數:23,代碼來源:segment.go


注:本文中的github.com/dukejeffrie/htm/data.Bitset類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。