本文整理匯總了Golang中github.com/dukejeffrie/htm/data.NewBitset函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewBitset函數的具體用法?Golang NewBitset怎麽用?Golang NewBitset使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewBitset函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRegionFeedBack
func TestRegionFeedBack(t *testing.T) {
l := NewRegion(RegionParameters{
Name: "Single Region",
Learning: true,
Height: 4,
Width: 500,
InputLength: 64,
MaximumFiringColumns: 5,
MinimumInputOverlap: 2,
})
l.RandomizeColumns(32)
inputA := data.NewBitset(64).Set(1, 5)
inputB := data.NewBitset(64).Set(2, 10)
maxAttempts := 77
for !l.SensedInput().Equals(*inputB) && maxAttempts > 0 {
maxAttempts--
l.ConsumeInput(*inputA)
l.ConsumeInput(*inputB)
}
oB := l.Output().Clone()
l.ConsumeInput(*inputA)
oA := l.Output().Clone()
fA := l.FeedBack(*oA)
if !fA.Equals(*inputA) {
t.Errorf("Feedback for A=%v does not match: %v", *inputA, *fA)
}
fB := l.FeedBack(*oB)
if !fB.Equals(*inputB) {
t.Errorf("Feedback for B=%v does not match: %v", *inputB, *fB)
}
}
示例2: TestTp_AAxB
func TestTp_AAxB(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
test := NewTpTest(t)
test.Verify = false
random := data.NewBitset(test.layer0.InputLength)
for i := 0; i < 8000; i++ {
test.Step(*test.inputA)
test.Step(*test.inputA)
random.Reset().Set(rand.Intn(test.layer0.InputLength))
test.Step(*random)
test.Step(*test.inputB)
}
aOrB := data.NewBitset(test.layer0.InputLength)
aOrB.ResetTo(*test.inputA)
aOrB.Or(*test.inputB)
// After ...,B comes A.
test.checkPredictedInput(*test.inputA)
// After ...,A comes A.
test.Step(*test.inputA)
test.checkPredictedInput(*test.inputA)
// After ...,A,A comes anything.
test.Step(*test.inputA)
test.Log("Predict anything:", test.layer0.PredictedInput())
// Then comes B.
random.Reset().Set(rand.Intn(test.layer0.InputLength))
test.Step(*random)
test.checkPredictedInput(*test.inputB)
}
示例3: TestFindBestSegment
func TestFindBestSegment(t *testing.T) {
c := NewColumn(64, 4)
active1 := data.NewBitset(64).Set(2, 20, 22)
active2 := data.NewBitset(64).Set(11, 31)
update := c.distal[1].CreateUpdate(-1, *active1, 2)
c.distal[1].Apply(update, true)
update = c.distal[2].CreateUpdate(-1, *active2, 2)
c.distal[2].Apply(update, true)
state := data.NewBitset(64).Set(2)
cell, s, overlap := c.FindBestSegment(*state, 1, false)
if cell != 1 || s != 0 || overlap != 1 {
t.Errorf("FindBestSegment(%v,minOverlap=%d): %d, %v, %d", *state, 1, cell, s, overlap)
}
cell, s, overlap = c.FindBestSegment(*state, 2, false)
if cell != -1 || s != -1 {
t.Errorf("FindBestSegment(%v,minOverlap=%d): %d, %v, %d", *state, 2, cell, s, overlap)
}
state.Set(22)
cell, s, overlap = c.FindBestSegment(*state, 2, false)
if cell != 1 || s != 0 || overlap != 2 {
t.Errorf("FindBestSegment(%v,minOverlap=%d): %d, %v, %d", *state, 2, cell, s, overlap)
}
state.Reset().Set(2, 20, 11, 31)
}
示例4: TestPredict
func TestPredict(t *testing.T) {
c := NewColumn(64, 4)
active1 := data.NewBitset(64).Set(2, 20)
active2 := data.NewBitset(64).Set(11, 31)
update := c.distal[1].CreateUpdate(-1, *active1, 2)
c.distal[1].Apply(update, true)
update = c.distal[2].CreateUpdate(-1, *active2, 2)
c.distal[2].Apply(update, true)
state := data.NewBitset(64).Set(2)
c.Predict(*state, 1)
pred := c.Predictive()
if !pred.AllSet(1) || pred.NumSetBits() != 1 {
t.Errorf("Should have predicted only cell 1, but got %v", pred)
t.Log(*c.distal[1])
}
state.Set(11)
c.Predict(*state, 1)
pred = c.Predictive()
if !pred.AllSet(1, 2) || pred.NumSetBits() != 2 {
t.Errorf("Should have predicted cells 1 and 2, but got %v", pred)
t.Log(*c.distal[1])
t.Log(*c.distal[2])
}
}
示例5: NewPermanenceMap
func NewPermanenceMap(numBits int) *PermanenceMap {
result := &PermanenceMap{
config: DefaultPermanenceConfig,
permanence: make(map[int]float32),
synapses: data.NewBitset(numBits),
receptiveField: data.NewBitset(numBits),
}
return result
}
示例6: BenchmarkColumnOverlap
func BenchmarkColumnOverlap(b *testing.B) {
c := NewColumn(64, 1)
connections := []int{1, 3, 5, 8, 11}
c.ResetConnections(connections)
input := data.NewBitset(64).Set(1, 5, 22)
result := data.NewBitset(64).Set(1, 5, 22, 60)
b.ResetTimer()
for i := 0; i < b.N; i++ {
result.Overlap(*input)
}
}
示例7: NewColumn
func NewColumn(inputSize, height int) *Column {
result := &Column{
active: data.NewBitset(height),
predictive: data.NewBitset(height),
proximal: segment.NewDendriteSegment(inputSize),
learning: -1,
learningTarget: 0,
distal: make([]*segment.DistalSegmentGroup, height),
}
for i := 0; i < height; i++ {
result.distal[i] = segment.NewDistalSegmentGroup()
}
return result
}
示例8: TestLearn64PatternAB_5
func TestLearn64PatternAB_5(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
rand.Seed(1979)
ds := segment.NewDendriteSegment(64)
ds.Reset(1, 3, 5, 8, 13, 21)
patternA := data.NewBitset(64)
patternA.Set(2, 4, 22, 24, 42, 44, 62)
patternB := data.NewBitset(64)
patternB.Set(22, 23, 24, 25, 26)
TryToLearn(t, 90, ds, 5, *patternA, *patternB)
t.Log(ds.Connected())
}
示例9: InitializeNetwork
func (d *Drop) InitializeNetwork() {
params := htm.RegionParameters{
Name: "0-drop",
Width: 640,
Height: 8,
MinimumInputOverlap: 1,
InputLength: 64,
Learning: true,
}
params.MaximumFiringColumns = params.Width / 50
d.step = 0
d.region0 = htm.NewRegion(params)
d.region0.RandomizeColumns(params.InputLength / 2)
params.Name = "1-drop"
params.Width = 2000
params.Height = 5
params.InputLength = d.region0.Output().Len()
params.MaximumFiringColumns = params.Width / 100
d.region1 = htm.NewRegion(params)
d.region1.RandomizeColumns(params.InputLength / 2)
params.Name = "final"
params.Width = 200
params.Height = 3
params.InputLength = d.region1.Output().Len()
params.MaximumFiringColumns = 1
d.region3 = htm.NewRegion(params)
d.region3.RandomizeColumns(params.InputLength / 2)
d.predicted = data.NewBitset(d.region3.PredictiveState().Len())
d.patterns = make(map[string]string)
}
示例10: TestBroadenSynapses
func TestBroadenSynapses(t *testing.T) {
ds := NewDendriteSegment(64)
ds.Reset(1, 3, 5, 8, 13)
input := data.NewBitset(64)
input.Set(1, 5, 22)
for i := 0; i < 1000 && ds.permanence[3] >= ds.Config().Minimum; i++ {
ds.narrow(*input)
}
if ds.permanence[22] != 0 {
t.Errorf("Permanence for non-connected should be zero: %v", ds.permanence)
}
input.Reset()
input.Set(1, 8, 22)
overlap := ds.broaden(*input, 0)
if overlap != 1 {
t.Errorf("Only bit 1 should overlap, not %d: %v", overlap, *ds)
}
if ds.permanence[1] <= ds.permanence[3] {
t.Errorf("Permanence scores did not improve: %v", ds.permanence)
}
if ds.permanence[1] != ds.permanence[5] {
t.Errorf("Permanence scores must be uniform: %v", ds.permanence)
}
if ds.permanence[8] != ds.Config().Minimum || ds.permanence[22] != ds.Config().Minimum {
t.Errorf("Permanence for broadened synapse should be %f: %v", ds.Config().Minimum, ds.permanence)
}
}
示例11: TryToLearn
func TryToLearn(t *testing.T, maxTries int, ds *segment.DendriteSegment,
minOverlap int, inputs ...data.Bitset) int {
result := 0
overlap := data.NewBitset(inputs[0].Len())
for !ds.Connected().Equals(inputs[0]) {
input := inputs[result%len(inputs)]
overlap.ResetTo(input)
overlap.And(ds.Connected())
active := overlap.NumSetBits() >= minOverlap || rand.Float32()+ds.Boost > 3.0
ds.Learn(input, active, minOverlap)
result++
if active {
fmt.Print("N")
} else {
fmt.Print("B")
}
if result > maxTries {
t.Error(fmt.Sprintf("Failed after %d rounds.", maxTries))
return result
}
}
fmt.Println()
t.Log(fmt.Sprintf("Learned in %d rounds.", result))
return result
}
示例12: TestMinOverlap
func TestMinOverlap(t *testing.T) {
l := NewRegion(RegionParameters{
Name: "Single Region",
Learning: true,
Height: 4,
Width: 100,
InputLength: 2048,
MaximumFiringColumns: 40,
MinimumInputOverlap: 1,
})
columnRand.Seed(0)
l.RandomizeColumns(20)
input := data.NewBitset(2048)
input.SetRange(0, 20)
l.ConsumeInput(*input)
output := l.Output()
if output.IsZero() {
t.Errorf("Output is empty: %v", output)
}
t.Log(output)
l.MinimumInputOverlap = 4
l.ConsumeInput(*input)
output = l.Output()
if !output.IsZero() {
t.Errorf("Output should be empty: %v", output)
}
}
示例13: TestCategoryEncoder
func TestCategoryEncoder(t *testing.T) {
s, err := NewCategorySensor(64, 4, "A", "B", "C")
if err != nil {
t.Fatal(err)
}
if err = s.Encode("A"); err != nil {
t.Error(err)
}
b := data.NewBitset(64).SetRange(0, 4)
if !s.Get().Equals(*b) {
t.Errorf("Encode failed. Expected: %v, but got: %v", *b, s.Get())
}
if v := s.Decode(*b); v != "A" {
t.Errorf("Decode failed. Expected: %v, but got: %v (%v)", "A", v, *s)
}
if err = s.Encode("B"); err != nil {
t.Error(err)
}
b.Reset().SetRange(4, 8)
if !s.Get().Equals(*b) {
t.Errorf("Encode failed. Expected: %v, but got: %v", *b, s.Get())
}
if v := s.Decode(*b); v != "B" {
t.Errorf("Decode failed. Expected: %v, but got: %v (%v)", "B", v, *s)
}
err = s.Encode("Other")
if err == nil {
t.Error("Should have failed to encode unknown category \"Other\":", *s)
}
}
示例14: TestTp_LearnAAB
func TestTp_LearnAAB(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
test := NewTpTest(t)
test.Verify = false
for i := 0; i < 100; i++ {
test.Step(*test.inputA)
test.Step(*test.inputA)
test.Step(*test.inputB)
}
aOrB := data.NewBitset(test.layer0.InputLength)
aOrB.ResetTo(*test.inputA)
aOrB.Or(*test.inputB)
// After ...,B comes A.
test.checkPredictedInput(*test.inputA)
// After ...,A comes A.
test.Step(*test.inputA)
test.checkPredictedInput(*test.inputA)
// After ...,A,A comes A or B.
test.Step(*test.inputA)
test.checkPredictedInput(*aOrB)
}
示例15: AddNoise
func (d *Drop) AddNoise() {
noise := data.NewBitset(d.region0.InputLength)
noise.Set(rand.Intn(noise.Len()), rand.Intn(noise.Len()))
d.region0.ConsumeInput(*noise)
d.region1.ConsumeInput(d.region0.Output())
d.region3.ConsumeInput(d.region1.Output())
}