Example #1
0
// helper for compute().
//Returns new state
func (tm *TemporalMemory) computeFn(activeColumns []int,
	prevPredictiveCells []int,
	prevActiveSegments []int,
	prevActiveSynapsesForSegment map[int][]int,
	prevWinnerCells []int,
	connections *TemporalMemoryConnections,
	learn bool) (activeCells []int,
	winnerCells []int,
	activeSynapsesForSegment map[int][]int,
	activeSegments []int,
	predictiveCells []int) {

	var predictedColumns []int

	activeCells, winnerCells, predictedColumns = tm.activateCorrectlyPredictiveCells(
		prevPredictiveCells,
		activeColumns,
		connections)

	_activeCells, _winnerCells, learningSegments := tm.burstColumns(activeColumns,
		predictedColumns,
		prevActiveSynapsesForSegment,
		connections)

	utils.Add(activeCells, _activeCells)
	utils.Add(winnerCells, _winnerCells)

	if learn {
		tm.learnOnSegments(prevActiveSegments,
			learningSegments,
			prevActiveSynapsesForSegment,
			winnerCells,
			prevWinnerCells,
			connections)
	}

	activeSynapsesForSegment = tm.computeActiveSynapses(activeCells, connections)

	activeSegments, predictiveCells = tm.computePredictiveCells(activeSynapsesForSegment,
		connections)

	return activeCells,
		winnerCells,
		activeSynapsesForSegment,
		activeSegments,
		predictiveCells

}
Example #2
0
/*
Phase 2: Burst unpredicted columns.
Pseudocode:
- for each unpredicted active column
- mark all cells as active
- mark the best matching cell as winner cell
- (learning)
- if it has no matching segment
- (optimization) if there are prev winner cells
- add a segment to it
- mark the segment as learning
*/
func (tm *TemporalMemory) burstColumns(activeColumns []int,
	predictedColumns []int,
	prevActiveSynapsesForSegment map[int][]int,
	connections *TemporalMemoryConnections) (activeCells []int,
	winnerCells []int,
	learningSegments []int) {

	unpredictedColumns := utils.Complement(activeColumns, predictedColumns)

	for _, column := range unpredictedColumns {
		cells := connections.CellsForColumn(column)
		activeCells = utils.Add(activeCells, cells)

		bestCell, bestSegment := tm.getBestMatchingCell(column,
			prevActiveSynapsesForSegment,
			connections)

		winnerCells = append(winnerCells, bestCell)

		if bestSegment == -1 {
			//TODO: (optimization) Only do this if there are prev winner cells
			bestSegment = connections.CreateSegment(bestCell)
		}
		//TODO: change to set data structure
		if !utils.ContainsInt(bestSegment, learningSegments) {
			learningSegments = append(learningSegments, bestSegment)
		}
	}

	return activeCells, winnerCells, learningSegments
}