コード例 #1
0
ファイル: dateEncoder_test.go プロジェクト: Fardinak/htm
func TestSimpleDateEncoding(t *testing.T) {

	p := NewDateEncoderParams()
	p.SeasonWidth = 3
	p.DayOfWeekWidth = 1
	p.WeekendWidth = 3
	p.TimeOfDayWidth = 5
	de := NewDateEncoder(p)

	// season is aaabbbcccddd (1 bit/month)  TODO should be <<3?
	// should be 000000000111 (centered on month 11 - Nov)
	seasonExpected := utils.Make1DBool([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1})
	// week is SMTWTFS
	// differs from python implementation
	dayOfWeekExpected := utils.Make1DBool([]int{0, 0, 0, 0, 1, 0, 0})
	// not a weekend, so it should be "False"
	weekendExpected := utils.Make1DBool([]int{1, 1, 1, 0, 0, 0})
	// time of day has radius of 4 hours and w of 5 so each bit = 240/5 min = 48min
	// 14:55 is minute 14*60 + 55 = 895; 895/48 = bit 18.6
	// should be 30 bits total (30 * 48 minutes = 24 hours)
	timeOfDayExpected := utils.Make1DBool([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0})

	d := time.Date(2010, 11, 4, 14, 55, 0, 0, time.UTC)
	encoded := de.Encode(d)
	t.Log(utils.Bool2Int(encoded))

	expected := append(seasonExpected, dayOfWeekExpected...)
	expected = append(expected, weekendExpected...)
	expected = append(expected, timeOfDayExpected...)

	assert.Equal(t, utils.Bool2Int(expected), utils.Bool2Int(encoded))

}
コード例 #2
0
ファイル: scalerEncoder_test.go プロジェクト: Fardinak/htm
func TestSimpleEncoding(t *testing.T) {

	p := NewScalerEncoderParams(3, 1, 8)
	p.N = 14
	p.Periodic = true
	//p.Verbosity = 5

	e := NewScalerEncoder(p)

	encoded := e.Encode(1, false)
	t.Log(encoded)
	expected := utils.Make1DBool([]int{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
	assert.True(t, len(encoded) == 14)
	assert.Equal(t, expected, encoded)

	encoded = e.Encode(2, false)
	expected = utils.Make1DBool([]int{0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
	assert.True(t, len(encoded) == 14)
	assert.Equal(t, expected, encoded)

	encoded = e.Encode(3, false)
	expected = utils.Make1DBool([]int{0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0})
	assert.True(t, len(encoded) == 14)
	assert.Equal(t, expected, encoded)

}
コード例 #3
0
ファイル: spatialPooler_test.go プロジェクト: Fardinak/htm
func TestCompute1(t *testing.T) {
	/*
		Checks that feeding in the same input vector leads to polarized
		permanence values: either zeros or ones, but no fractions
	*/

	spParams := NewSpParams()
	spParams.InputDimensions = []int{9}
	spParams.ColumnDimensions = []int{5}
	spParams.PotentialRadius = 3
	spParams.PotentialPct = 0.5
	spParams.GlobalInhibition = false
	spParams.LocalAreaDensity = -1
	spParams.NumActiveColumnsPerInhArea = 3
	spParams.StimulusThreshold = 1
	spParams.SynPermInactiveDec = 0.01
	spParams.SynPermActiveInc = 0.1
	spParams.SynPermConnected = 0.10
	spParams.MinPctOverlapDutyCycle = 0.1
	spParams.MinPctActiveDutyCycle = 0.1
	spParams.DutyCyclePeriod = 10
	spParams.MaxBoost = 10.0
	sp := NewSpatialPooler(spParams)

	sp.potentialPools = NewDenseBinaryMatrix(sp.numColumns, sp.numInputs)
	for i := 0; i < sp.numColumns; i++ {
		for j := 0; j < sp.numInputs; j++ {
			sp.potentialPools.Set(i, j, true)
		}
	}

	inhibitColumnsMock := func(overlaps []float64, inhibitColumnsGlobal, inhibitColumnsLocal inhibitColumnsFunc) []int {
		return []int{0, 1, 2, 3, 4}
	}

	inputVector := utils.Make1DBool([]int{1, 0, 1, 0, 1, 0, 0, 1, 1})
	activeArray := make([]bool, 5)

	for i := 0; i < 20; i++ {
		sp.Compute(inputVector, true, activeArray, inhibitColumnsMock)
	}

	for i := 0; i < 20; i++ {
		perm := Float64SliceToInt(GetRowFromSM(sp.permanences, i))
		assert.Equal(t, inputVector, utils.Make1DBool(perm))
	}

}
コード例 #4
0
ファイル: spatialPooler_test.go プロジェクト: Fardinak/htm
func TestCompute2(t *testing.T) {
	/*
		Checks that columns only change the permanence values for
		inputs that are within their potential pool
	*/

	spParams := NewSpParams()
	spParams.InputDimensions = []int{10}
	spParams.ColumnDimensions = []int{5}
	spParams.PotentialRadius = 3
	spParams.PotentialPct = 0.5
	spParams.GlobalInhibition = false
	spParams.LocalAreaDensity = -1
	spParams.NumActiveColumnsPerInhArea = 3
	spParams.StimulusThreshold = 1
	spParams.SynPermInactiveDec = 0.01
	spParams.SynPermActiveInc = 0.1
	spParams.SynPermConnected = 0.10
	spParams.MinPctOverlapDutyCycle = 0.1
	spParams.MinPctActiveDutyCycle = 0.1
	spParams.DutyCyclePeriod = 10
	spParams.MaxBoost = 10.0
	sp := NewSpatialPooler(spParams)

	inhibitColumnsMock := func(overlaps []float64, inhibitColumnsGlobal, inhibitColumnsLocal inhibitColumnsFunc) []int {
		return []int{0, 1, 2, 3, 4}
	}

	inputVector := utils.Make1DBool([]int{1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
	activeArray := make([]bool, 5)

	for i := 0; i < 20; i++ {
		sp.Compute(inputVector, true, activeArray, inhibitColumnsMock)
	}

	for i := 0; i < sp.numColumns; i++ {
		perm := Float64SliceToInt(GetRowFromSM(sp.permanences, i))
		potential := sp.potentialPools.GetDenseRow(i)
		assert.Equal(t, potential, utils.Make1DBool(perm))
	}

}
コード例 #5
0
ファイル: scalerEncoder_test.go プロジェクト: Fardinak/htm
func TestSimpleDecoding(t *testing.T) {

	p := NewScalerEncoderParams(3, 1, 8)
	p.Radius = 1.5
	p.Periodic = true
	//p.Verbosity = 5

	e := NewScalerEncoder(p)

	// Test with a "hole"
	encoded := utils.Make1DBool([]int{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0})
	expected := []utils.TupleFloat{utils.TupleFloat{7.5, 7.5}}
	actual := e.Decode(encoded)
	assert.Equal(t, expected, actual)

	// Test with something wider than w, and with a hole, and wrapped
	encoded = utils.Make1DBool([]int{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0})
	expected = []utils.TupleFloat{utils.TupleFloat{7.5, 8}, utils.TupleFloat{1, 1}}
	actual = e.Decode(encoded)
	assert.Equal(t, expected, actual)

	// Test with something wider than w, no hole
	encoded = utils.Make1DBool([]int{1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0})
	expected = []utils.TupleFloat{utils.TupleFloat{1.5, 2.5}}
	actual = e.Decode(encoded)
	assert.Equal(t, expected, actual)

	// 1
	encoded = utils.Make1DBool([]int{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
	expected = []utils.TupleFloat{utils.TupleFloat{1, 1}}
	actual = e.Decode(encoded)
	assert.Equal(t, expected, actual)

	// 2
	encoded = utils.Make1DBool([]int{0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
	expected = []utils.TupleFloat{utils.TupleFloat{2, 2}}
	actual = e.Decode(encoded)
	assert.Equal(t, expected, actual)

}
コード例 #6
0
ファイル: scalerEncoder_test.go プロジェクト: Fardinak/htm
func TestWideEncoding(t *testing.T) {

	p := NewScalerEncoderParams(5, 0, 24)
	p.Periodic = true
	//p.Verbosity = 5
	p.Radius = 4
	e := NewScalerEncoder(p)

	encoded := e.Encode(14.916666666666666, false)
	t.Log(encoded)
	expected := utils.Make1DBool([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0})

	assert.True(t, len(encoded) == 30)
	assert.Equal(t, utils.Bool2Int(expected), utils.Bool2Int(encoded))

}
コード例 #7
0
ファイル: scalerEncoder_test.go プロジェクト: Fardinak/htm
func TestNarrowEncoding(t *testing.T) {

	p := NewScalerEncoderParams(3, 0, 1)
	p.Periodic = false
	//p.Verbosity = 5
	p.Radius = 1
	e := NewScalerEncoder(p)

	encoded := make([]bool, 6)
	e.EncodeToSlice(0, false, encoded)
	t.Log(encoded)
	expected := utils.Make1DBool([]int{1, 1, 1, 0, 0, 0})

	assert.True(t, len(encoded) == 6)
	assert.Equal(t, utils.Bool2Int(expected), utils.Bool2Int(encoded))

}