func phase2(t *testing.T, bt *boostTest) { y := make([]bool, bt.sp.numColumns) // Do 9 training batch through the input patterns for i := 0; i < 9; i++ { for idx, input := range bt.x { utils.FillSliceBool(y, false) bt.sp.Compute(input, true, y, bt.sp.InhibitColumns) for j, winner := range y { if winner { bt.winningIteration[j] = bt.sp.IterationLearnNum } } bt.lastSDR[idx] = y } } // The boost factor for all columns should be at 1. assert.Equal(t, bt.sp.numColumns, utils.CountFloat64(bt.sp.boostFactors, 1), "Boost factors are not all 1") // Roughly half of the columns should have never been active. winners := utils.CountInt(bt.winningIteration, 0) assert.True(t, winners >= int(0.4*float64(bt.sp.numColumns)), "More than 60% of the columns have been active") // All the never-active columns should have duty cycle of 0 activeSum := 0.0 for idx, val := range bt.sp.activeDutyCycles { if bt.winningIteration[idx] == 0 { activeSum += val } } assert.Equal(t, 0, activeSum, "Inactive columns have positive duty cycle.") dutyAvg := 0.0 dutyCount := 0 for _, val := range bt.sp.activeDutyCycles { if val > 0 { dutyAvg += val dutyCount++ } } // The average at-least-once-active columns should have duty cycle >= 0.15 // and <= 0.25 dutyAvg = dutyAvg / float64(dutyCount) assert.True(t, dutyAvg >= 0.15, "Average on-columns duty cycle is too low.") assert.True(t, dutyAvg <= 0.30, "Average on-columns duty cycle is too high.") verifySDRProps(t, bt) }
func phase1(t *testing.T, bt *boostTest) { y := make([]bool, bt.sp.numColumns) // Do one training batch through the input patterns for idx, input := range bt.x { utils.FillSliceBool(y, false) bt.sp.Compute(input, true, y, bt.sp.InhibitColumns) for j, winner := range y { if winner { bt.winningIteration[j] = bt.sp.IterationLearnNum } } bt.lastSDR[idx] = y } //The boost factor for all columns should be at 1. assert.Equal(t, bt.sp.numColumns, utils.CountFloat64(bt.sp.boostFactors, 1), "Boost factors are not all 1") //At least half of the columns should have never been active. winners := utils.CountInt(bt.winningIteration, 0) assert.True(t, winners >= bt.sp.numColumns/2, "More than half of the columns have been active") //All the never-active columns should have duty cycle of 0 //All the at-least-once-active columns should have duty cycle >= 0.2 activeSum := 0.0 for idx, val := range bt.sp.activeDutyCycles { if bt.winningIteration[idx] == 0 { //assert.Equal(t, expected, actual, ...) activeSum += val } } assert.Equal(t, 0, activeSum, "Inactive columns have positive duty cycle.") winningMin := 100000.0 for idx, val := range bt.sp.activeDutyCycles { if bt.winningIteration[idx] > 0 { if val < winningMin { winningMin = val } } } assert.True(t, winningMin >= 0.2, "Active columns have duty cycle that is too low.") verifySDRProps(t, bt) }