Example #1
0
func phase3(t *testing.T, bt *boostTest) {
	//Do two more training batches through the input patterns
	y := make([]bool, bt.sp.numColumns)

	for i := 0; i < 2; 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 that just won should be at 1.
	for idx, val := range y {
		if val {
			if bt.sp.boostFactors[idx] != 1 {
				assert.Fail(t, "Boost factors of winning columns not 1")
			}
		}
	}

	// By now, every column should have been sufficiently boosted to win at least
	// once. The number of columns that have never won should now be 0
	for _, val := range bt.winningIteration {
		if val == 0 {
			assert.Fail(t, "Expected all columns to have won atleast once.")
		}
	}

	// Because of the artificially induced thrashing, even the first two patterns
	// should have low overlap. Verify that the first two SDR's now have little
	// overlap
	overlap := computeOverlap(bt.lastSDR[0], bt.lastSDR[1])
	assert.True(t, overlap < 7, "First two SDR's overlap significantly when they should not")
}
Example #2
0
func verifySDRProps(t *testing.T, bt *boostTest) {
	/*
		 Verify that all SDRs have the properties desired for this test.
		The bounds for checking overlap are set fairly loosely here since there is
		some variance due to randomness and the artificial parameters used in this
		test.
	*/

	// Verify that all SDR's are unique
	for i := 0; i <= 4; i++ {
		for j := 1; j <= 4; j++ {
			eq := 0
			for k := 0; k < len(bt.lastSDR[i]); k++ {
				if bt.lastSDR[i][k] == bt.lastSDR[j][k] {
					eq++
				}
			}
			if eq == len(bt.lastSDR[i]) {
				//equal
				assert.Fail(t, "All SDR's are not unique")
			}
		}
	}

	//Verify that the first two SDR's have some overlap.
	expected := computeOverlap(bt.lastSDR[0], bt.lastSDR[1]) > 9
	assert.True(t, expected, "First two SDR's don't overlap much")

	// Verify the last three SDR's have low overlap with everyone else.
	for i := 2; i <= 4; i++ {
		for j := 0; j <= 4; j++ {
			if i != j {
				overlap := computeOverlap(bt.lastSDR[i], bt.lastSDR[j])
				expected := overlap < 18
				assert.True(t, expected, "One of the last three SDRs has high overlap")
			}
		}
	}

}