コード例 #1
0
func basicComputeLoop(t *testing.T, spParams SpParams) {
	/*
		 Feed in some vectors and retrieve outputs. Ensure the right number of
		columns win, that we always get binary outputs, and that nothing crashes.
	*/

	sp := NewSpatialPooler(spParams)

	// Create a set of input vectors as well as various numpy vectors we will
	// need to retrieve data from the SP
	numRecords := 100

	inputMatrix := make([][]bool, numRecords)
	for i := range inputMatrix {
		inputMatrix[i] = make([]bool, sp.numInputs)
		for j := range inputMatrix[i] {
			inputMatrix[i][j] = rand.Float64() > 0.8
		}
	}

	// With learning off and no prior training we should get no winners
	y := make([]bool, sp.numColumns)
	for _, input := range inputMatrix {
		utils.FillSliceBool(y, false)
		sp.Compute(input, false, y, sp.InhibitColumns)
		assert.Equal(t, 0, utils.CountTrue(y))
	}

	// With learning on we should get the requested number of winners
	for _, input := range inputMatrix {
		utils.FillSliceBool(y, false)
		sp.Compute(input, true, y, sp.InhibitColumns)
		assert.Equal(t, sp.NumActiveColumnsPerInhArea, utils.CountTrue(y))

	}

	// With learning off and some prior training we should get the requested
	// number of winners
	for _, input := range inputMatrix {
		utils.FillSliceBool(y, false)
		sp.Compute(input, false, y, sp.InhibitColumns)
		assert.Equal(t, sp.NumActiveColumnsPerInhArea, utils.CountTrue(y))
	}

}
コード例 #2
0
ファイル: spatialPooler_test.go プロジェクト: Fardinak/htm
func TestMapPotential1D(t *testing.T) {
	sp := SpatialPooler{}
	sp.InputDimensions = []int{10}
	sp.numInputs = 10
	sp.ColumnDimensions = []int{4}
	sp.numColumns = 4
	sp.PotentialRadius = 2
	sp.PotentialPct = 1

	expectedMask := []bool{true, true, true, false, false, false, false, false, false, false}
	mask := sp.mapPotential(0, false)
	assert.Equal(t, expectedMask, mask)

	expectedMask = []bool{false, false, false, false, true, true, true, true, true, false}
	mask = sp.mapPotential(2, false)
	assert.Equal(t, expectedMask, mask)

	sp.PotentialPct = 1

	expectedMask = []bool{true, true, true, false, false, false, false, false, true, true}
	mask = sp.mapPotential(0, true)
	assert.Equal(t, expectedMask, mask)

	expectedMask = []bool{true, true, false, false, false, false, false, true, true, true}
	mask = sp.mapPotential(3, true)
	assert.Equal(t, expectedMask, mask)

	// Test with potentialPct < 1
	sp.PotentialPct = 0.5

	expectedMask = []bool{true, true, true, false, false, false, false, false, true, true}
	mask = sp.mapPotential(0, true)

	assert.Equal(t, 3, utils.CountTrue(mask))

	unionMask := utils.OrBool(expectedMask, mask)
	assert.Equal(t, expectedMask, unionMask)

}
コード例 #3
0
ファイル: temporalPoolerPrint.go プロジェクト: Fardinak/htm
/*
 Called at the end of inference to print out various diagnostic
information based on the current verbosity level.
*/
func (tp *TemporalPooler) printComputeEnd(output []bool, learn bool) {

	if tp.params.Verbosity < 3 {
		if tp.params.Verbosity >= 1 {
			fmt.Println("TP: learn:", learn)
			fmt.Printf("TP: active outputs(%v):\n", utils.CountTrue(output))
			fmt.Print(NewSparseBinaryMatrixFromDense1D(output,
				tp.params.NumberOfCols, tp.params.CellsPerColumn).ToString())
		}
		return
	}

	fmt.Println("----- computeEnd summary: ")
	fmt.Println("learn:", learn)
	bursting := 0
	counts := make([]int, tp.DynamicState.InfActiveState.Height)
	for _, val := range tp.DynamicState.InfActiveState.Entries() {
		counts[val.Row]++
		if counts[val.Row] == tp.DynamicState.InfActiveState.Width {
			bursting++
		}
	}
	fmt.Println("numBurstingCols:", bursting)
	fmt.Println("curPredScore2:", tp.internalStats.CurPredictionScore2)
	fmt.Println("curFalsePosScore", tp.internalStats.CurFalsePositiveScore)
	fmt.Println("1-curFalseNegScore", 1-tp.internalStats.CurFalseNegativeScore)
	fmt.Println("avgLearnedSeqLength", tp.avgLearnedSeqLength)

	stats := tp.calcSegmentStats(true)
	fmt.Println("numSegments", stats.NumSegments)

	fmt.Printf("----- InfActiveState (%v on) ------\n", tp.DynamicState.InfActiveState.TotalNonZeroCount())
	tp.printActiveIndices(tp.DynamicState.InfActiveState, false)

	if tp.params.Verbosity >= 6 {
		//tp.printState(tp.InfActiveState['t'])
		//fmt.Println(tp.DynamicState.InfActiveState.ToString())
	}

	fmt.Printf("----- InfPredictedState (%v on)-----\n", tp.DynamicState.InfPredictedState.TotalNonZeroCount())
	tp.printActiveIndices(tp.DynamicState.InfPredictedState, false)
	if tp.params.Verbosity >= 6 {
		//fmt.Println(tp.DynamicState.InfPredictedState.ToString())
	}

	fmt.Printf("----- LrnActiveState (%v on) ------\n", tp.DynamicState.LrnActiveState.TotalNonZeroCount())
	tp.printActiveIndices(tp.DynamicState.LrnActiveState, false)
	if tp.params.Verbosity >= 6 {
		//fmt.Println(tp.DynamicState.LrnActiveState.ToString())
	}

	fmt.Printf("----- LrnPredictedState (%v on)-----\n", tp.DynamicState.LrnPredictedState.TotalNonZeroCount())
	tp.printActiveIndices(tp.DynamicState.LrnPredictedState, false)
	if tp.params.Verbosity >= 6 {
		//fmt.Println(tp.DynamicState.LrnPredictedState.ToString())
	}

	fmt.Println("----- CellConfidence -----")
	//tp.printActiveIndices(tp.DynamicState.CellConfidence, true)

	if tp.params.Verbosity >= 6 {
		//TODO: this
		//tp.printConfidence(tp.DynamicState.CellConfidence)
		for r := 0; r < tp.DynamicState.CellConfidence.Rows(); r++ {
			for c := 0; c < tp.DynamicState.CellConfidenceLast.Cols(); c++ {
				if tp.DynamicState.CellConfidence.Get(r, c) != 0 {
					fmt.Printf("[%v,%v,%v]", r, c, tp.DynamicState.CellConfidence.Get(r, c))
				}
			}
		}

	}

	fmt.Println("----- ColConfidence -----")
	//tp.printActiveIndices(tp.DynamicState.ColConfidence, true)
	fmt.Println("----- CellConfidence[t-1] for currently active cells -----")
	//cc := matrix.ZerosSparse(tp.DynamicState.CellConfidence.Rows(), tp.DynamicState.CellConfidence.Cols())
	for _, val := range tp.DynamicState.InfActiveState.Entries() {
		//cc.Set(val.Row, val.Col, tp.DynamicState.CellConfidence.Get(val.Row, val.Col))
		fmt.Printf("[%v,%v,%v]", val.Row, val.Col, tp.DynamicState.CellConfidence.Get(val.Row, val.Col))

	}
	//fmt.Println(cc.String())

	if tp.params.Verbosity == 4 {
		fmt.Println("Cells, predicted segments only:")
		tp.printCells(true)
	} else if tp.params.Verbosity >= 5 {
		fmt.Println("Cells, all segments:")
		tp.printCells(true)
	}

}