Example #1
0
/*
 The primary method in charge of learning. Adapts the permanence values of
the synapses based on the input vector, and the chosen columns after
inhibition round. Permanence values are increased for synapses connected to
input bits that are turned on, and decreased for synapses connected to
inputs bits that are turned off.

Parameters:
----------------------------
inputVector: a numpy array of 0's and 1's thata comprises the input to
the spatial pooler. There exists an entry in the array
for every input bit.
activeColumns: an array containing the indices of the columns that
survived inhibition.
*/
func (sp *SpatialPooler) adaptSynapses(inputVector []bool, activeColumns []int) {
	var inputIndices []int
	for i, val := range inputVector {
		if val {
			inputIndices = append(inputIndices, i)
		}
	}

	permChanges := make([]float64, sp.numInputs)
	utils.FillSliceFloat64(permChanges, -1*sp.SynPermInactiveDec)
	for _, val := range inputIndices {
		permChanges[val] = sp.SynPermActiveInc
	}

	for _, ac := range activeColumns {
		perm := make([]float64, sp.numInputs)
		mask := sp.potentialPools.GetRowIndices(ac)
		for j := 0; j < sp.numInputs; j++ {
			if utils.ContainsInt(j, mask) {
				perm[j] = permChanges[j] + sp.permanences.Get(ac, j)
			} else {
				perm[j] = sp.permanences.Get(ac, j)
			}

		}
		sp.updatePermanencesForColumn(perm, ac, true)
	}

}
Example #2
0
func (tp *TrivialPredictor) reset() {

	for _, method := range tp.Methods {

		utils.FillSliceBool(tp.State[method].ActiveState, false)
		utils.FillSliceBool(tp.State[method].ActiveStateLast, false)
		utils.FillSliceBool(tp.State[method].PredictedState, false)
		utils.FillSliceBool(tp.State[method].PredictedStateLast, false)
		utils.FillSliceFloat64(tp.State[method].Confidence, 0.0)
		utils.FillSliceFloat64(tp.State[method].ConfidenceLast, 0.0)

		stats := tp.InternalStats[method]
		stats.NInfersSinceReset = 0
		stats.CurPredictionScore = 0.0
		stats.CurPredictionScore2 = 0.0
		stats.FalseNegativeScoreTotal = 0.0
		stats.FalsePositiveScoreTotal = 0.0
		stats.CurExtra = 0.0
		stats.CurMissing = 0.0
		tp.InternalStats[method] = stats
	}

}
Example #3
0
/*
Updates the minimum duty cycles in a global fashion. Sets the minimum duty
cycles for the overlap and activation of all columns to be a percent of the
maximum in the region, specified by minPctOverlapDutyCycle and
minPctActiveDutyCycle respectively. Functionaly it is equivalent to
updateMinDutyCyclesLocal, but this function exploits the globalilty of the
compuation to perform it in a straightforward, and more efficient manner.
*/
func (sp *SpatialPooler) updateMinDutyCyclesGlobal() {
	minOverlap := sp.MinPctOverlapDutyCycles * utils.MaxSliceFloat64(sp.overlapDutyCycles)
	utils.FillSliceFloat64(sp.minOverlapDutyCycles, minOverlap)
	minActive := sp.MinPctActiveDutyCycles * utils.MaxSliceFloat64(sp.activeDutyCycles)
	utils.FillSliceFloat64(sp.minActiveDutyCycles, minActive)
}
Example #4
0
func (tp *TrivialPredictor) infer(activeColumns []int) {

	numColsToPredict := int(0.5 + tp.AverageDensity*float64(tp.NumOfCols))

	//for method in self.methods:
	for _, method := range tp.Methods {
		// Copy t-1 into t
		copy(tp.State[method].ActiveStateLast, tp.State[method].ActiveState)
		copy(tp.State[method].PredictedStateLast, tp.State[method].PredictedState)
		copy(tp.State[method].ConfidenceLast, tp.State[method].Confidence)

		utils.FillSliceBool(tp.State[method].ActiveState, false)
		utils.FillSliceBool(tp.State[method].PredictedState, false)
		utils.FillSliceFloat64(tp.State[method].Confidence, 0.0)

		for _, val := range activeColumns {
			tp.State[method].ActiveState[val] = true
		}

		var predictedCols []int

		switch method {
		case Random:
			// Randomly predict N columns
			//predictedCols = RandomInts(numColsToPredict, tp.NumOfCols)
			break
		case Zeroth:
			// Always predict the top N most frequent columns
			var inds []int
			ints.Argsort(tp.ColumnCount, inds)
			predictedCols = inds[len(inds)-numColsToPredict:]
			break
		case Last:
			// Always predict the last input
			for idx, val := range tp.State[method].ActiveState {
				if val {
					predictedCols = append(predictedCols, idx)
				}
			}
			break
		case All:
			// Always predict all columns
			for i := 0; i < tp.NumOfCols; i++ {
				predictedCols = append(predictedCols, i)
			}
			break
		case Lots:
			// Always predict 2 * the top N most frequent columns
			numColsToPredict := mathutil.Min(2*numColsToPredict, tp.NumOfCols)
			var inds []int
			ints.Argsort(tp.ColumnCount, inds)
			predictedCols = inds[len(inds)-numColsToPredict:]

			break
		default:
			panic("prediction method not implemented")
		}

		for _, val := range predictedCols {
			tp.State[method].PredictedState[val] = true
			tp.State[method].Confidence[val] = 1.0
		}

		if tp.Verbosity > 1 {
			fmt.Println("Random prediction:", method)
			fmt.Println(" numColsToPredict:", numColsToPredict)
			fmt.Println(predictedCols)
		}

	}

}