Пример #1
0
func (sp *SpatialPooler) InhibitColumns(overlaps []float64, inhibitColumnsGlobal, inhibitColumnsLocal inhibitColumnsFunc) []int {
	/*
			 determine how many columns should be selected in the inhibition phase.
		     This can be specified by either setting the 'numActiveColumnsPerInhArea'
		     parameter of the 'localAreaDensity' parameter when initializing the class
	*/
	density := 0.0
	if sp.LocalAreaDensity > 0 {
		density = sp.LocalAreaDensity
	} else {
		inhibitionArea := math.Pow(float64(2*sp.inhibitionRadius+1), float64(len(sp.ColumnDimensions)))
		inhibitionArea = math.Min(float64(sp.numColumns), inhibitionArea)
		density = float64(sp.NumActiveColumnsPerInhArea) / inhibitionArea
		density = math.Min(density, 0.5)
	}

	// Add our fixed little bit of random noise to the scores to help break ties.
	//overlaps += sp.tieBreaker
	for i := 0; i < len(overlaps); i++ {
		overlaps[i] += sp.tieBreaker[i]
	}

	if sp.GlobalInhibition ||
		sp.inhibitionRadius > utils.MaxSliceInt(sp.ColumnDimensions) {
		return inhibitColumnsGlobal(overlaps, density)
	} else {
		return inhibitColumnsLocal(overlaps, density)
	}

}
Пример #2
0
/*
 Update the inhibition radius. The inhibition radius is a meausre of the
square (or hypersquare) of columns that each a column is "conencted to"
on average. Since columns are are not connected to each other directly, we
determine this quantity by first figuring out how many *inputs* a column is
connected to, and then multiplying it by the total number of columns that
exist for each input. For multiple dimension the aforementioned
calculations are averaged over all dimensions of inputs and columns. This
value is meaningless if global inhibition is enabled.
*/
func (sp *SpatialPooler) updateInhibitionRadius(avgConnectedSpanForColumnND avgConnectedSpanForColumnNDFunc,
	avgColumnsPerInput avgColumnsPerInputFunc) {

	if sp.GlobalInhibition {
		cmax := utils.MaxSliceInt(sp.ColumnDimensions)
		sp.inhibitionRadius = cmax
		return
	}

	avgConnectedSpan := 0.0
	for i := 0; i < sp.numColumns; i++ {
		avgConnectedSpan += avgConnectedSpanForColumnND(i)
	}
	avgConnectedSpan = avgConnectedSpan / float64(sp.numColumns)

	columnsPerInput := avgColumnsPerInput()
	diameter := avgConnectedSpan * columnsPerInput
	radius := (diameter - 1) / 2.0
	radius = math.Max(1.0, radius)

	sp.inhibitionRadius = int(utils.RoundPrec(radius, 0))
}