htm

package module
v0.0.0-...-061a763 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 12 Imported by: 4

README

htm

Hierarchical Temporal Memory Implementation in Golang

GoDoc Build Status

This is a direct port of the spatial & temporal poolers, temporal memory, and encoders as they currently exist in Numenta's Nupic Project. This project was done as a learning exercise, no effort has been made to optimize this implementation and it was not designed for production use.

The Nupic project basically demonstrates the CLA, a single stage of the cortical hierarchy. Eventually this same code can be extended to form a full HTM hierarchy. https://github.com/numenta/nupic

##Changes From Numentas Implementation

  • Temporal pooler ephemeral state is stored in strongly typed struct rather than a hashmap. t-1 vars have "last" appended to their names.
  • Temporal pooler params stored in "params" sub struct
  • Binary data structures are used rather than ints
  • No C++ dependency everything is written in Go

##Current State of Project

  • Temporal and Spatial poolers pass basic tests
  • Temporal memory passes basic unit tests
  • Basic scaler encoder implemented

##Todo * Finish temporal unit tests

  • Implement a better sparse binary matrix structure with versions optimized for col or row heavy access.
  • Implement better binary datastructure
  • Refactor to be more idiomatic Go. It is basically a line for line port of the python implementation, it could be refactored to make better use of Go's type system.
  • Implement some of the common encoders

##Examples

###Temporal Pooler

package main

import (
	"fmt"
	"github.com/zacg/htm"
	"github.com/nupic-community/htmutils"
)

func main() {
	tps := htm.NewTemporalPoolerParams()
	tps.Verbosity = 0
	tps.NumberOfCols = 50
	tps.CellsPerColumn = 2
	tps.ActivationThreshold = 8
	tps.MinThreshold = 10
	tps.InitialPerm = 0.5
	tps.ConnectedPerm = 0.5
	tps.NewSynapseCount = 10
	tps.PermanenceDec = 0.0
	tps.PermanenceInc = 0.1
	tps.GlobalDecay = 0
	tps.BurnIn = 1
	tps.PamLength = 10
	tps.CollectStats = true
	tp := htm.NewTemporalPooler(*tps)

	//Mock encoding of ABCDE
	inputs := make([][]bool, 5)
	inputs[0] = boolRange(0, 9, 50)   //bits 0-9 are "on"
	inputs[1] = boolRange(10, 19, 50) //bits 10-19 are "on"
	inputs[2] = boolRange(20, 29, 50) //bits 20-29 are "on"
	inputs[3] = boolRange(30, 39, 50) //bits 30-39 are "on"
	inputs[4] = boolRange(40, 49, 50) //bits 40-49 are "on"

	//Learn 5 sequences above
	for i := 0; i < 10; i++ {
		for p := 0; p < 5; p++ {
			tp.Compute(inputs[p], true, false)
		}
		tp.Reset()
	}

	//Predict sequences
	for i := 0; i < 4; i++ {
		tp.Compute(inputs[i], false, true)
		p := tp.DynamicState.InfPredictedState

		fmt.Printf("Predicted: %v From input: %v \n", p.NonZeroRows(), utils.OnIndices(inputs[i]))

	}

}

//helper method for creating boolean sequences
func boolRange(start int, end int, length int) []bool {
	result := make([]bool, length)
	for i := start; i <= end; i++ {
		result[i] = true
	}
	return result
}


###Spatial Pooler

package main

import (
	"fmt"
	"github.com/davecheney/profile"
	"github.com/zacg/htm"
	"github.com/nupic-community/htmutils"
	"math/rand"
)

func main() {
	
	ssp := htm.NewSpParams()
	ssp.ColumnDimensions = []int{64, 64}
	ssp.InputDimensions = []int{32, 32}
	ssp.PotentialRadius = ssp.NumInputs()
	ssp.NumActiveColumnsPerInhArea = int(0.02 * float64(ssp.NumColumns()))
	ssp.GlobalInhibition = true
	ssp.SynPermActiveInc = 0.01
	ssp.SpVerbosity = 10
	sp := htm.NewSpatialPooler(ssp)
	

	activeArray := make([]bool, sp.NumColumns())
	inputVector := make([]bool, sp.NumInputs())

	for idx, _ := range inputVector {
		inputVector[idx] = rand.Intn(5) >= 2
	}

	sp.Compute(inputVector, true, activeArray, sp.InhibitColumns)

	fmt.Println("Active Indices:", utils.OnIndices(activeArray))

}

###Temporal Memory


	tmp := NewTemporalMemoryParams()
	tmp.MaxNewSynapseCount = 1000

	tm := NewTemporalMemory(tmp)

###Encoding


	//Create new scaler encoder
	p := NewScalerEncoderParams(3, 1, 8)
	p.Radius = 1.5
	p.Periodic = true
	p.Verbosity = 5
	e := NewScalerEncoder(p)

	//Encode "1"
	encoded := e.Encode(1, false)

	//Print results
	fmt.Printfn("1 Encoded as: %v", utils.Bool2Int(encoded))


	//Create new date encoder
	p := NewDateEncoderParams()
	p.SeasonWidth = 3
	p.DayOfWeekWidth = 1
	p.WeekendWidth = 3
	p.TimeOfDayWidth = 5
	p.Verbosity = 5
	de := NewDateEncoder(p)
	
	d := time.Date(2010, 11, 4, 14, 55, 0, 0, time.UTC)
	encoded := de.Encode(d)

	//Print results
	fmt.Printfn("%v Encoded as: %v", d, utils.Bool2Int(encoded))

Documentation

Overview

htm contains ports of Numenta's spatial and temporal poolers as they are currently implemented in the Nupic framework.

Index

Constants

This section is empty.

Variables

View Source
var SegmentDutyCycleAlphas = []float64{0, 0.0032, 0.0010, 0.00032,
	0.00010, 0.000032, 0.00001, 0.0000032,
	0.0000010}
View Source
var SegmentDutyCycleTiers = []int{0, 100, 320, 1000,
	3200, 10000, 32000, 100000, 320000}

Functions

This section is empty.

Types

type DenseBinaryMatrix

type DenseBinaryMatrix struct {
	Width  int
	Height int
	// contains filtered or unexported fields
}

Sparse binary matrix stores indexes of non-zero entries in matrix to conserve space

func NewDenseBinaryMatrix

func NewDenseBinaryMatrix(height, width int) *DenseBinaryMatrix

Create new sparse binary matrix of specified size

func NewDenseBinaryMatrixFromDense

func NewDenseBinaryMatrixFromDense(values [][]bool) *DenseBinaryMatrix

Create sparse binary matrix from specified dense matrix

func NewDenseBinaryMatrixFromDense1D

func NewDenseBinaryMatrixFromDense1D(values []bool, rows, cols int) *DenseBinaryMatrix

Create sparse binary matrix from specified dense matrix

func NewDenseBinaryMatrixFromInts

func NewDenseBinaryMatrixFromInts(values [][]int) *DenseBinaryMatrix

Creates a sparse binary matrix from specified integer array (any values greater than 0 are true)

func (*DenseBinaryMatrix) Clear

func (sm *DenseBinaryMatrix) Clear()

Clears all entries

func (*DenseBinaryMatrix) Copy

Copys a matrix

func (*DenseBinaryMatrix) Entries

func (sm *DenseBinaryMatrix) Entries() []SparseEntry

Returns all true/on indices

func (*DenseBinaryMatrix) FillRow

func (sm *DenseBinaryMatrix) FillRow(row int, val bool)

Fills specified row with specified value

func (*DenseBinaryMatrix) Flatten

func (sm *DenseBinaryMatrix) Flatten() []bool

Returns flattend dense represenation

func (*DenseBinaryMatrix) Get

func (sm *DenseBinaryMatrix) Get(row int, col int) bool

Get value at col,row position

func (*DenseBinaryMatrix) GetDenseRow

func (sm *DenseBinaryMatrix) GetDenseRow(row int) []bool

Returns dense row

func (*DenseBinaryMatrix) GetRowIndices

func (sm *DenseBinaryMatrix) GetRowIndices(row int) []int

Returns a rows "on" indices

func (*DenseBinaryMatrix) NonZeroRows

func (sm *DenseBinaryMatrix) NonZeroRows() []int

Returns row indexes with at least 1 true column

func (*DenseBinaryMatrix) Or

Ors 2 matrices

func (*DenseBinaryMatrix) ReplaceRow

func (sm *DenseBinaryMatrix) ReplaceRow(row int, values []bool)

Replaces specified row with values, assumes values is ordered correctly

func (*DenseBinaryMatrix) ReplaceRowByIndices

func (sm *DenseBinaryMatrix) ReplaceRowByIndices(row int, indices []int)

Replaces row with true values at specified indices

func (*DenseBinaryMatrix) RowAndSum

func (sm *DenseBinaryMatrix) RowAndSum(row []bool) []int

In a normal matrix this would be multiplication in binary terms we just and then sum the true entries

func (*DenseBinaryMatrix) Set

func (sm *DenseBinaryMatrix) Set(row int, col int, value bool)

Set value at row,col position

func (*DenseBinaryMatrix) SetRowFromDense

func (sm *DenseBinaryMatrix) SetRowFromDense(row int, denseRow []bool)

Sets a sparse row from dense representation

func (*DenseBinaryMatrix) ToString

func (sm *DenseBinaryMatrix) ToString() string

func (*DenseBinaryMatrix) TotalNonZeroCount

func (sm *DenseBinaryMatrix) TotalNonZeroCount() int

Returns total true entries

func (*DenseBinaryMatrix) TotalTrueRows

func (sm *DenseBinaryMatrix) TotalTrueRows() int

Returns # of rows with at least 1 true value

type DynamicState

type DynamicState struct {
	//orginally dynamic vars
	LrnActiveState     *SparseBinaryMatrix // t
	LrnActiveStateLast *SparseBinaryMatrix // t-1

	LrnPredictedState     *SparseBinaryMatrix
	LrnPredictedStateLast *SparseBinaryMatrix

	InfActiveState          *SparseBinaryMatrix
	InfActiveStateLast      *SparseBinaryMatrix
	InfActiveStateBackup    *SparseBinaryMatrix
	InfActiveStateCandidate *SparseBinaryMatrix

	InfPredictedState          *SparseBinaryMatrix
	InfPredictedStateLast      *SparseBinaryMatrix
	InfPredictedStateBackup    *SparseBinaryMatrix
	InfPredictedStateCandidate *SparseBinaryMatrix

	CellConfidence          *matrix.DenseMatrix
	CellConfidenceLast      *matrix.DenseMatrix
	CellConfidenceCandidate *matrix.DenseMatrix

	ColConfidence          []float64
	ColConfidenceLast      []float64
	ColConfidenceCandidate []float64
}

func (*DynamicState) Copy

func (ds *DynamicState) Copy() *DynamicState

type PredictorMethod

type PredictorMethod int
const (
	Random PredictorMethod = 1
	Zeroth PredictorMethod = 2
	Last   PredictorMethod = 3
	All    PredictorMethod = 4
	Lots   PredictorMethod = 5
)

type ProcessAction

type ProcessAction int
const (
	Update ProcessAction = 0
	Keep   ProcessAction = 1
	Remove ProcessAction = 2
)

type Segment

type Segment struct {
	// contains filtered or unexported fields
}

The Segment struct is a container for all of the segment variables and the synapses it owns.

func NewSegment

func NewSegment(tp *TemporalPooler, isSequenceSeg bool) *Segment

Creates a new segment

func (*Segment) AddSynapse

func (s *Segment) AddSynapse(srcCellCol, srcCellIdx int, perm float64)

Adds a new synapse

func (*Segment) Equals

func (s *Segment) Equals(seg *Segment) bool

Determines segment equality

func (*Segment) ToString

func (s *Segment) ToString() string

Print segment information for verbose messaging and debugging. This uses the following format:

ID:54413 True 0.64801 (24/36) 101 [9,1]0.75 [10,1]0.75 [11,1]0.75

where: 54413 - is the unique segment id True - is sequence segment 0.64801 - moving average duty cycle (24/36) - (numPositiveActivations / numTotalActivations) 101 - age, number of iterations since last activated [9,1]0.75 - synapse from column 9, cell #1, strength 0.75 [10,1]0.75 - synapse from column 10, cell #1, strength 0.75 [11,1]0.75 - synapse from column 11, cell #1, strength 0.75

type SegmentStats

type SegmentStats struct {
	NumSegments        int
	NumSynapses        int
	NumActiveSynapses  int
	DistSegSizes       float64
	DistNumSegsPerCell float64
	DistPermValues     float64
	DistAges           float64
}

type SegmentUpdate

type SegmentUpdate struct {
	// contains filtered or unexported fields
}

type SpParams

type SpParams struct {
	InputDimensions            []int
	ColumnDimensions           []int
	PotentialRadius            int
	PotentialPct               float64
	GlobalInhibition           bool
	LocalAreaDensity           float64
	NumActiveColumnsPerInhArea int
	StimulusThreshold          int
	SynPermInactiveDec         float64
	SynPermActiveInc           float64
	SynPermConnected           float64
	MinPctOverlapDutyCycle     float64
	MinPctActiveDutyCycle      float64
	DutyCyclePeriod            int
	MaxBoost                   float64
	Seed                       int
	SpVerbosity                int
}

func NewSpParams

func NewSpParams() SpParams

Initializes default spatial pooler params

func (*SpParams) NumColumns

func (ssp *SpParams) NumColumns() int

Returns number of columns

func (*SpParams) NumInputs

func (ssp *SpParams) NumInputs() int

Returns number of inputs

type SparseBinaryMatrix

type SparseBinaryMatrix struct {
	Width  int
	Height int
	// contains filtered or unexported fields
}

Sparse binary matrix stores indexes of non-zero entries in matrix to conserve space

func NewSparseBinaryMatrix

func NewSparseBinaryMatrix(height, width int) *SparseBinaryMatrix

Create new sparse binary matrix of specified size

func NewSparseBinaryMatrixFromDense

func NewSparseBinaryMatrixFromDense(values [][]bool) *SparseBinaryMatrix

Create sparse binary matrix from specified dense matrix

func NewSparseBinaryMatrixFromDense1D

func NewSparseBinaryMatrixFromDense1D(values []bool, rows, cols int) *SparseBinaryMatrix

Create sparse binary matrix from specified dense matrix

func NewSparseBinaryMatrixFromInts

func NewSparseBinaryMatrixFromInts(values [][]int) *SparseBinaryMatrix

Creates a sparse binary matrix from specified integer array (any values greater than 0 are true)

func (*SparseBinaryMatrix) Clear

func (sm *SparseBinaryMatrix) Clear()

Clears all entries

func (*SparseBinaryMatrix) Copy

Copys a matrix

func (*SparseBinaryMatrix) Entries

func (sm *SparseBinaryMatrix) Entries() []SparseEntry

Returns all true/on indices

func (*SparseBinaryMatrix) FillRow

func (sm *SparseBinaryMatrix) FillRow(row int, val bool)

Fills specified row with specified value

func (*SparseBinaryMatrix) Flatten

func (sm *SparseBinaryMatrix) Flatten() []bool

Returns flattend dense represenation

func (*SparseBinaryMatrix) Get

func (sm *SparseBinaryMatrix) Get(row int, col int) bool

Get value at col,row position

func (*SparseBinaryMatrix) GetDenseRow

func (sm *SparseBinaryMatrix) GetDenseRow(row int) []bool

Returns dense row

func (*SparseBinaryMatrix) GetRowIndices

func (sm *SparseBinaryMatrix) GetRowIndices(row int) []int

Returns a rows "on" indices

func (*SparseBinaryMatrix) NonZeroRows

func (sm *SparseBinaryMatrix) NonZeroRows() []int

Returns row indexes with at least 1 true column

func (*SparseBinaryMatrix) Or

Ors 2 matrices

func (*SparseBinaryMatrix) ReplaceRow

func (sm *SparseBinaryMatrix) ReplaceRow(row int, values []bool)

Replaces specified row with values, assumes values is ordered correctly

func (*SparseBinaryMatrix) ReplaceRowByIndices

func (sm *SparseBinaryMatrix) ReplaceRowByIndices(row int, indices []int)

Replaces row with true values at specified indices

func (*SparseBinaryMatrix) RowAndSum

func (sm *SparseBinaryMatrix) RowAndSum(row []bool) []int

In a normal matrix this would be multiplication in binary terms we just and then sum the true entries

func (*SparseBinaryMatrix) Set

func (sm *SparseBinaryMatrix) Set(row int, col int, value bool)

Set value at row,col position

func (*SparseBinaryMatrix) SetRowFromDense

func (sm *SparseBinaryMatrix) SetRowFromDense(row int, denseRow []bool)

Sets a sparse row from dense representation

func (*SparseBinaryMatrix) ToString

func (sm *SparseBinaryMatrix) ToString() string

func (*SparseBinaryMatrix) TotalNonZeroCount

func (sm *SparseBinaryMatrix) TotalNonZeroCount() int

Returns total true entries

func (*SparseBinaryMatrix) TotalTrueCols

func (sm *SparseBinaryMatrix) TotalTrueCols() int

Returns # of cols with at least 1 true value

func (*SparseBinaryMatrix) TotalTrueRows

func (sm *SparseBinaryMatrix) TotalTrueRows() int

Returns # of rows with at least 1 true value

type SparseEntry

type SparseEntry struct {
	Row int
	Col int
}

entries are positions of non-zero values

type SpatialPooler

type SpatialPooler struct {
	ColumnDimensions           []int
	InputDimensions            []int
	PotentialRadius            int
	PotentialPct               float64
	GlobalInhibition           bool
	NumActiveColumnsPerInhArea int
	LocalAreaDensity           float64
	StimulusThreshold          int
	SynPermInactiveDec         float64
	SynPermActiveInc           float64
	SynPermBelowStimulusInc    float64
	SynPermConnected           float64
	MinPctOverlapDutyCycles    float64
	MinPctActiveDutyCycles     float64
	DutyCyclePeriod            int
	MaxBoost                   float64
	SpVerbosity                int

	// Extra parameter settings
	SynPermMin           float64
	SynPermMax           float64
	SynPermTrimThreshold float64
	UpdatePeriod         int
	InitConnectedPct     float64

	// Internal state
	Version           float64
	IterationNum      int
	IterationLearnNum int

	//random seed
	Seed int
	// contains filtered or unexported fields
}

func NewSpatialPooler

func NewSpatialPooler(spParams SpParams) *SpatialPooler

Creates a new spatial pooler

func (*SpatialPooler) Compute

func (sp *SpatialPooler) Compute(inputVector []bool, learn bool, activeArray []bool, inhibitColumns inhibitColFunc)
This is the primary public method of the SpatialPooler class. This
function takes a input vector and outputs the indices of the active columns.
If 'learn' is set to True, this method also updates the permanences of the
columns.

Parameters: ---------------------------- inputVector: a numpy array of 0's and 1's thata comprises the input to

 the spatial pooler. The array will be treated as a one
 dimensional array, therefore the dimensions of the array
 do not have to much the exact dimensions specified in the
 class constructor. In fact, even a list would suffice.
The number of input bits in the vector must, however,
match the number of bits specified by the call to the
constructor. Therefore there must be a '0' or '1' in the
array for every input bit.

learn: a boolean value indicating whether learning should be

performed. Learning entails updating the permanence
values of the synapses, and hence modifying the 'state'
of the model. Setting learning to 'off' freezes the SP
and has many uses. For example, you might want to feed in
various inputs and examine the resulting SDR's.

activeArray: an array whose size is equal to the number of columns.

	   Before the function returns this array will be populated
       with 1's at the indices of the active columns, and 0's
	   everywhere else.

func (*SpatialPooler) InhibitColumns

func (sp *SpatialPooler) InhibitColumns(overlaps []float64, inhibitColumnsGlobal, inhibitColumnsLocal inhibitColumnsFunc) []int

func (*SpatialPooler) NumColumns

func (sp *SpatialPooler) NumColumns() int

Returns number of columns

func (*SpatialPooler) NumInputs

func (sp *SpatialPooler) NumInputs() int

Returns number of inputs

type Synapse

type Synapse struct {
	SrcCellCol int
	SrcCellIdx int
	Permanence float64
}

type SynapseUpdateState

type SynapseUpdateState struct {
	New       bool
	Index     int
	CellIndex int //only set when new
}

type TemporalMemory

type TemporalMemory struct {
	ActiveCells              []int
	PredictiveCells          []int
	ActiveSegments           []int
	ActiveSynapsesForSegment map[int][]int
	WinnerCells              []int
	Connections              *TemporalMemoryConnections
	// contains filtered or unexported fields
}

Temporal memory

func NewTemporalMemory

func NewTemporalMemory(params *TemporalMemoryParams) *TemporalMemory

Create new temporal memory

func (*TemporalMemory) Compute

func (tm *TemporalMemory) Compute(activeColumns []int, learn bool)

Feeds input record through TM, performing inference and learning. Updates member variables with new state.

func (*TemporalMemory) Reset

func (tm *TemporalMemory) Reset()

Indicates the start of a new sequence. Resets sequence state of the TM.

type TemporalMemoryConnections

type TemporalMemoryConnections struct {
	ColumnDimensions []int
	CellsPerColumn   int
	// contains filtered or unexported fields
}
Structure holds data representing the connectivity of a layer of cells,

that the TM operates on.

func NewTemporalMemoryConnections

func NewTemporalMemoryConnections(maxSynCount int, cellsPerColumn int, colDimensions []int) *TemporalMemoryConnections

Create a new temporal memory

func (*TemporalMemoryConnections) CellForSegment

func (tmc *TemporalMemoryConnections) CellForSegment(segment int) int

Returns the cell that a segment belongs to.

func (*TemporalMemoryConnections) CellsForColumn

func (tmc *TemporalMemoryConnections) CellsForColumn(column int) []int

Returns the indices of cells that belong to a column.

func (*TemporalMemoryConnections) ColumnForCell

func (tmc *TemporalMemoryConnections) ColumnForCell(cell int) int

Returns the index of the column that a cell belongs to.

func (*TemporalMemoryConnections) CreateSegment

func (tmc *TemporalMemoryConnections) CreateSegment(cell int) int

Creates a new segment on specified cell, returns segment index

func (*TemporalMemoryConnections) CreateSynapse

func (tmc *TemporalMemoryConnections) CreateSynapse(segment int, sourceCell int, permanence float64) *TmSynapse

func (*TemporalMemoryConnections) DataForSynapse

func (tmc *TemporalMemoryConnections) DataForSynapse(synapse int) *TmSynapse

Returns synapse data for specified index

func (*TemporalMemoryConnections) NumberOfColumns

func (tmc *TemporalMemoryConnections) NumberOfColumns() int

Returns the number of columns in this layer.

func (*TemporalMemoryConnections) NumberOfcells

func (tmc *TemporalMemoryConnections) NumberOfcells() int

Returns the number of cells in this layer.

func (*TemporalMemoryConnections) SegmentsForCell

func (tmc *TemporalMemoryConnections) SegmentsForCell(cell int) []int

Returns the segments that belong to a cell.

func (*TemporalMemoryConnections) SynapsesForSegment

func (tmc *TemporalMemoryConnections) SynapsesForSegment(segment int) []int

Returns the synapses on a segment.

func (*TemporalMemoryConnections) SynapsesForSourceCell

func (tmc *TemporalMemoryConnections) SynapsesForSourceCell(sourceCell int) []int

Returns the synapses for the source cell that they synapse on.

func (*TemporalMemoryConnections) UpdateSynapsePermanence

func (tmc *TemporalMemoryConnections) UpdateSynapsePermanence(synapse int, permanence float64)

Updates the permanence for a synapse.

type TemporalMemoryParams

type TemporalMemoryParams struct {
	//Column dimensions
	ColumnDimensions []int
	CellsPerColumn   int
	//If the number of active connected synapses on a segment is at least
	//this threshold, the segment is said to be active.
	ActivationThreshold int
	//Radius around cell from which it can sample to form distal dendrite
	//connections.
	LearningRadius    int
	InitialPermanence float64
	//If the permanence value for a synapse is greater than this value, it is said
	//to be connected.
	ConnectedPermanence float64
	//If the number of synapses active on a segment is at least this threshold,
	//it is selected as the best matching cell in a bursing column.
	MinThreshold int
	//The maximum number of synapses added to a segment during learning.
	MaxNewSynapseCount  int
	PermanenceIncrement float64
	PermanenceDecrement float64
	//rand seed
	Seed int
}

Params for intializing temporal memory

func NewTemporalMemoryParams

func NewTemporalMemoryParams() *TemporalMemoryParams

Create default temporal memory params

type TemporalPooler

type TemporalPooler struct {
	CurrentOutput *SparseBinaryMatrix

	DynamicState *DynamicState
	// contains filtered or unexported fields
}

func NewTemporalPooler

func NewTemporalPooler(tParams TemporalPoolerParams) *TemporalPooler

Initializes a new temporal pooler

func (*TemporalPooler) Compute

func (tp *TemporalPooler) Compute(bottomUpInput []bool, enableLearn bool, computeInfOutput bool) []bool
Handle one compute, possibly learning.

param bottomUpInput The bottom-up input, typically from a spatial pooler param enableLearn If true, perform learning param computeInfOutput If None, default behavior is to disable the inference output when enableLearn is on. If true, compute the inference output If false, do not compute the inference output

It is an error to have both enableLearn and computeInfOutput set to False

By default, we don't compute the inference output when learning because it slows things down, but you can override this by passing in True for computeInfOutput

func (*TemporalPooler) GetSegId

func (tp *TemporalPooler) GetSegId() int

Returns new unique segment id

func (*TemporalPooler) Predict

func (tp *TemporalPooler) Predict(nSteps int) *matrix.DenseMatrix
This function gives the future predictions for <nSteps> timesteps starting

from the current TP state. The TP is returned to its original state at the end before returning.

- We save the TP state. - Loop for nSteps - Turn-on with lateral support from the current active cells - Set the predicted cells as the next step's active cells. This step in learn and infer methods use input here to correct the predictions. We don't use any input here. - Revert back the TP state to the time before prediction

param nSteps The number of future time steps to be predicted returns all the future predictions - floating point matrix and shape (nSteps, numberOfCols). The ith row gives the tp prediction for each column at a future timestep (t+i+1).

func (*TemporalPooler) Reset

func (tp *TemporalPooler) Reset()
Reset the state of all cells.

This is normally used between sequences while training. All internal states are reset to 0.

type TemporalPoolerParams

type TemporalPoolerParams struct {
	NumberOfCols           int
	CellsPerColumn         int
	InitialPerm            float64
	ConnectedPerm          float64
	MinThreshold           int
	NewSynapseCount        int
	PermanenceInc          float64
	PermanenceDec          float64
	PermanenceMax          float64
	GlobalDecay            float64
	ActivationThreshold    int
	DoPooling              bool
	SegUpdateValidDuration int
	BurnIn                 int
	CollectStats           bool
	//Seed                   int
	Verbosity int
	//checkSynapseConsistency=False, # for cpp only -- ignored
	TrivialPredictionMethods []PredictorMethod
	PamLength                int
	MaxInfBacktrack          int
	MaxLrnBacktrack          int
	MaxAge                   int
	MaxSeqLength             int
	MaxSegmentsPerCell       int
	MaxSynapsesPerSegment    int
	// contains filtered or unexported fields
}

func NewTemporalPoolerParams

func NewTemporalPoolerParams() *TemporalPoolerParams

Initializes tp params with default values

type TmSynapse

type TmSynapse struct {
	Segment    int
	SourceCell int
	Permanence float64
}

type TpOutputType

type TpOutputType int
const (
	Normal                 TpOutputType = 0
	ActiveState            TpOutputType = 1
	ActiveState1CellPerCol TpOutputType = 2
)

type TpStats

type TpStats struct {
	NInfersSinceReset       int
	NPredictions            int
	PredictionScoreTotal    float64
	PredictionScoreTotal2   float64
	FalseNegativeScoreTotal float64
	FalsePositiveScoreTotal float64
	PctExtraTotal           float64
	PctMissingTotal         float64
	TotalMissing            float64
	TotalExtra              float64

	CurPredictionScore    float64
	CurPredictionScore2   float64
	CurFalseNegativeScore float64
	CurFalsePositiveScore float64
	CurMissing            float64
	CurExtra              float64
	ConfHistogram         matrix.DenseMatrix
}

func (*TpStats) ToString

func (s *TpStats) ToString() string

type TrivialPredictor

type TrivialPredictor struct {
	NumOfCols      int
	Methods        []PredictorMethod
	Verbosity      int
	InternalStats  map[PredictorMethod]*TpStats
	State          map[PredictorMethod]TrivialPredictorState
	ColumnCount    []int
	AverageDensity float64
}

func MakeTrivialPredictor

func MakeTrivialPredictor(numberOfCols int, methods []PredictorMethod) *TrivialPredictor

type TrivialPredictorState

type TrivialPredictorState struct {
	ActiveState        []bool
	ActiveStateLast    []bool
	PredictedState     []bool
	PredictedStateLast []bool
	Confidence         []float64
	ConfidenceLast     []float64
}

type UpdateState

type UpdateState struct {
	//creationdate refers to iteration idx
	CreationDate int
	Update       *SegmentUpdate
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL