def __init__(self, columnCount, inputWidth, historyLength,
               minHistory, poolerType, **kwargs):

    if columnCount <= 0 or inputWidth <=0:
      raise TypeError("Parameters columnCount and inputWidth must be > 0")
    # Pull out the pooler arguments automatically
    # These calls whittle down kwargs and create instance variables of TemporalPoolerRegion
    self._poolerType = poolerType
    self._poolerClass = _getPoolerClass(poolerType)
    pArgTuples = _buildArgs(self._poolerClass, self, kwargs)

    # include parent spatial pooler parameters
    if poolerType == "union" or poolerType == "unionMonitored":
      pArgTuplesSP = _buildArgs(_getParentSpatialPoolerClass(poolerType), self, kwargs)
      # Make a list of automatic pooler arg names for later use
      self._poolerArgNames = [t[0] for t in pArgTuples] + [t[0] for t in pArgTuplesSP]
    else:
      self._poolerArgNames = [t[0] for t in pArgTuples]

    PyRegion.__init__(self, **kwargs)

    # Defaults for all other parameters
    self.learningMode = True
    self.inferenceMode = True
    self._inputWidth = inputWidth
    self._columnCount = columnCount
    self._historyLength = historyLength
    self._minHistory = minHistory

    # pooler instance
    self._pooler = None
Exemplo n.º 2
0
  def __init__(self,
               columnCount,   # Number of columns in the SP, a required parameter
               inputWidth,    # Size of inputs to the SP, a required parameter
               spatialImp=getDefaultSPImp(),   #'py', 'cpp'
               **kwargs):

    if columnCount <= 0 or inputWidth <=0:
      raise TypeError("Parameters columnCount and inputWidth must be > 0")

    # Pull out the spatial arguments automatically
    # These calls whittle down kwargs and create instance variables of SPRegion
    self.SpatialClass = getSPClass(spatialImp)
    sArgTuples = _buildArgs(self.SpatialClass.__init__, self, kwargs)

    # Make a list of automatic spatial arg names for later use
    self._spatialArgNames = [t[0] for t in sArgTuples]

    # Learning and SP parameters.
    # By default we start out in stage learn with inference disabled
    self.learningMode   = True
    self.inferenceMode  = False
    self.anomalyMode    = False
    self.topDownMode    = False
    self.columnCount    = columnCount
    self.inputWidth     = inputWidth

    PyRegion.__init__(self, **kwargs)

    # Initialize all non-persistent base members, as well as give
    # derived class an opportunity to do the same.
    self._loaded = False
    self._initializeEphemeralMembers()

    # Debugging support, used in _conditionalBreak
    self.breakPdb = False
    self.breakKomodo = False

    # Defaults for all other parameters
    self.logPathInput = ''
    self.logPathOutput = ''
    self.logPathOutputDense = ''
    self._fpLogSPInput = None
    self._fpLogSP = None
    self._fpLogSPDense = None


    #
    # Variables set up in initInNetwork()
    #

    # Spatial instance
    self._sfdr                = None

    # Spatial pooler's bottom-up output value: hang on to this  output for
    # top-down inference and for debugging
    self._spatialPoolerOutput = None

    # Spatial pooler's bottom-up input: hang on to this for supporting the
    # spInputNonZeros parameter
    self._spatialPoolerInput  = None
  def __init__(self,
               moduleCount,
               cellsPerAxis,
               scale,
               orientation,
               anchorInputSize,
               activeFiringRate,
               bumpSigma,
               activationThreshold=10,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               learningThreshold=10,
               sampleSize=20,
               permanenceIncrement=0.1,
               permanenceDecrement=0.0,
               maxSynapsesPerSegment=-1,
               bumpOverlapMethod="probabilistic",
               learningMode=False,
               seed=42,
               dualPhase=True,
               dimensions=2,
               **kwargs):
    if moduleCount <= 0 or cellsPerAxis <= 0:
      raise TypeError("Parameters moduleCount and cellsPerAxis must be > 0")
    if moduleCount != len(scale) or moduleCount != len(orientation):
      raise TypeError("scale and orientation arrays len must match moduleCount")
    if dimensions < 2:
      raise TypeError("dimensions must be >= 2")

    self.moduleCount = moduleCount
    self.cellsPerAxis = cellsPerAxis
    self.cellCount = cellsPerAxis * cellsPerAxis
    self.scale = list(scale)
    self.orientation = list(orientation)
    self.anchorInputSize = anchorInputSize
    self.activeFiringRate = activeFiringRate
    self.bumpSigma = bumpSigma
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.learningThreshold = learningThreshold
    self.sampleSize = sampleSize
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.maxSynapsesPerSegment = maxSynapsesPerSegment
    self.bumpOverlapMethod = bumpOverlapMethod
    self.learningMode = learningMode
    self.dualPhase = dualPhase
    self.dimensions = dimensions
    self.seed = seed

    # This flag controls whether the region is processing sensation or movement
    # on dual phase configuration
    self._sensing = False

    self._modules = None

    self._projection = None

    PyRegion.__init__(self, **kwargs)
Exemplo n.º 4
0
  def __init__(self,

               columnCount,   # Number of columns in the SP, a required parameter
               inputWidth,    # Size of inputs to the SP, a required parameter
               cellsPerColumn, # Number of cells per column, required

               # Constructor arguments are picked up automatically. There is no
               # need to add them anywhere in TMRegion, unless you need to do
               # something special with them. See docstring above.

               orColumnOutputs=False,
               cellsSavePath='',
               temporalImp=gDefaultTemporalImp,
               anomalyMode=False,
               computePredictedActiveCellIndices=False,

               **kwargs):
    # Which Temporal implementation?
    TemporalClass = _getTPClass(temporalImp)

    # Make a list of automatic temporal arg names for later use
    # Pull out the temporal arguments automatically
    # These calls whittle down kwargs and create instance variables of TMRegion
    tArgTuples = _buildArgs(TemporalClass.__init__, self, kwargs)

    self._temporalArgNames = [t[0] for t in tArgTuples]

    self.learningMode   = True      # Start out with learning enabled
    self.inferenceMode  = False
    self.anomalyMode    = anomalyMode
    self.computePredictedActiveCellIndices = computePredictedActiveCellIndices
    self.topDownMode    = False
    self.columnCount    = columnCount
    self.inputWidth     = inputWidth
    self.outputWidth    = columnCount * cellsPerColumn
    self.cellsPerColumn = cellsPerColumn

    PyRegion.__init__(self, **kwargs)

    # Initialize all non-persistent base members, as well as give
    # derived class an opportunity to do the same.
    self._loaded = False
    self._initialize()

    # Debugging support, used in _conditionalBreak
    self.breakPdb = False
    self.breakKomodo = False

    # TMRegion only, or special handling
    self.orColumnOutputs = orColumnOutputs
    self.temporalImp = temporalImp

    # Various file names
    self.storeDenseOutput = False
    self.logPathOutput = ''
    self.cellsSavePath = cellsSavePath
    self._fpLogTPOutput = None

    # Variables set up in initInNetwork()
    self._tfdr = None  # FDRTemporal instance
Exemplo n.º 5
0
  def __init__(self,
               columnCount=2048,
               cellsPerColumn=16,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               seed=42,
               defaultOutputType = "active",
               **kwargs):
    # Defaults for all other parameters
    self.columnCount = columnCount
    self.cellsPerColumn = cellsPerColumn
    self.inputWidth = self.columnCount*self.cellsPerColumn
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.maxNewSynapseCount = maxNewSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    self.seed = seed
    self.learningMode = True
    self.inferenceMode = True
    self.defaultOutputType = defaultOutputType

    PyRegion.__init__(self, **kwargs)
  def __init__(self,

               # Input sizes
               columnCount,
               basalInputWidth,
               apicalInputWidth=0,

               # TM params
               cellsPerColumn=32,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               reducedBasalThreshold=13, # ApicalTiebreak and ApicalDependent only
               sampleSize=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               basalPredictedSegmentDecrement=0.0,
               apicalPredictedSegmentDecrement=0.0,
               learnOnOneCell=False, # ApicalTiebreakCPP only
               maxSegmentsPerCell=255,
               maxSynapsesPerSegment=255, # ApicalTiebreakCPP only
               seed=42,

               # Region params
               implementation="ApicalTiebreak",
               learn=True,
               **kwargs):

    # Input sizes (the network API doesn't provide these during initialize)
    self.columnCount = columnCount
    self.basalInputWidth = basalInputWidth
    self.apicalInputWidth = apicalInputWidth

    # TM params
    self.cellsPerColumn = cellsPerColumn
    self.activationThreshold = activationThreshold
    self.reducedBasalThreshold = reducedBasalThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.sampleSize = sampleSize
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.basalPredictedSegmentDecrement = basalPredictedSegmentDecrement
    self.apicalPredictedSegmentDecrement = apicalPredictedSegmentDecrement
    self.maxSynapsesPerSegment = maxSynapsesPerSegment
    self.maxSegmentsPerCell = maxSegmentsPerCell
    self.learnOnOneCell = learnOnOneCell
    self.seed = seed

    # Region params
    self.implementation = implementation
    self.learn = learn

    PyRegion.__init__(self, **kwargs)

    # TM instance
    self._tm = None
Exemplo n.º 7
0
  def setParameter(self, name, index, value):
    """Set the value of a parameter."""

    if name == "SVDSampleCount":
      self._SVDSampleCount = value
    elif name == "logPath":
      self._logPath = value
    else:
      PyRegion.setParameter(self, name, index, value)
Exemplo n.º 8
0
  def __init__(self,
               cellCount=4096,
               inputWidth=16384,
               numOtherCorticalColumns=0,
               sdrSize=40,

               # Proximal
               synPermProximalInc=0.1,
               synPermProximalDec=0.001,
               initialProximalPermanence=0.6,
               sampleSizeProximal=20,
               minThresholdProximal=1,
               connectedPermanenceProximal=0.50,

               # Distal
               synPermDistalInc=0.10,
               synPermDistalDec=0.10,
               initialDistalPermanence=0.21,
               sampleSizeDistal=20,
               activationThresholdDistal=13,
               connectedPermanenceDistal=0.50,
               distalSegmentInhibitionFactor=1.5,

               seed=42,
               defaultOutputType = "active",
               **kwargs):

    # Used to derive Column Pooler params
    self.numOtherCorticalColumns = numOtherCorticalColumns

    # Column Pooler params
    self.inputWidth = inputWidth
    self.cellCount = cellCount
    self.sdrSize = sdrSize
    self.synPermProximalInc = synPermProximalInc
    self.synPermProximalDec = synPermProximalDec
    self.initialProximalPermanence = initialProximalPermanence
    self.sampleSizeProximal = sampleSizeProximal
    self.minThresholdProximal = minThresholdProximal
    self.connectedPermanenceProximal = connectedPermanenceProximal
    self.synPermDistalInc = synPermDistalInc
    self.synPermDistalDec = synPermDistalDec
    self.initialDistalPermanence = initialDistalPermanence
    self.sampleSizeDistal = sampleSizeDistal
    self.activationThresholdDistal = activationThresholdDistal
    self.connectedPermanenceDistal = connectedPermanenceDistal
    self.distalSegmentInhibitionFactor = distalSegmentInhibitionFactor
    self.seed = seed

    # Region params
    self.learningMode = True
    self.defaultOutputType = defaultOutputType

    self._pooler = None

    PyRegion.__init__(self, **kwargs)
  def __init__(self,
               columnCount=2048,
               inputWidth=16384,
               lateralInputWidth=0,
               activationThresholdDistal=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThresholdProximal=1,
               minThresholdDistal=10,
               maxNewProximalSynapseCount=20,
               maxNewDistalSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               synPermProximalInc=0.1,
               synPermProximalDec=0.001,
               initialProximalPermanence = 0.6,
               seed=42,
               numActiveColumnsPerInhArea=40,
               defaultOutputType = "active",
               **kwargs):

    # Modified Column Pooler params
    self.columnCount = columnCount

    # Column Pooler params
    self.inputWidth = inputWidth
    self.lateralInputWidth = lateralInputWidth
    self.activationThresholdDistal = activationThresholdDistal
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThresholdProximal = minThresholdProximal
    self.minThresholdDistal = minThresholdDistal
    self.maxNewProximalSynapseCount = maxNewProximalSynapseCount
    self.maxNewDistalSynapseCount = maxNewDistalSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    self.synPermProximalInc = synPermProximalInc
    self.synPermProximalDec = synPermProximalDec
    self.initialProximalPermanence = initialProximalPermanence
    self.seed = seed
    self.numActiveColumnsPerInhArea = numActiveColumnsPerInhArea
    self.maxSynapsesPerSegment = inputWidth

    # Region params
    self.learningMode = True
    self.inferenceMode = True
    self.defaultOutputType = defaultOutputType

    self._pooler = None

    PyRegion.__init__(self, **kwargs)
Exemplo n.º 10
0
 def getParameter(self, parameterName, index=-1):
   """
     Get the value of a NodeSpec parameter. Most parameters are handled
     automatically by PyRegion's parameter get mechanism. The ones that need
     special treatment are explicitly handled here.
   """
   return PyRegion.getParameter(self, parameterName, index)
Exemplo n.º 11
0
    def getParameter(self, parameterName, index=-1):
        """
    Overrides :meth:`~nupic.bindings.regions.PyRegion.PyRegion.getParameter`.
      
    Most parameters are handled automatically by PyRegion's parameter get 
    mechanism. The ones that need special treatment are explicitly handled here.
    """

        if parameterName == 'activeOutputCount':
            return self.columnCount
        elif parameterName == 'spatialPoolerInput':
            return list(self._spatialPoolerInput.reshape(-1))
        elif parameterName == 'spatialPoolerOutput':
            return list(self._spatialPoolerOutput)
        elif parameterName == 'spNumActiveOutputs':
            return len(self._spatialPoolerOutput.nonzero()[0])
        elif parameterName == 'spOutputNonZeros':
            return [len(self._spatialPoolerOutput)] + \
                    list(self._spatialPoolerOutput.nonzero()[0])
        elif parameterName == 'spInputNonZeros':
            import pdb
            pdb.set_trace()
            return [len(self._spatialPoolerInput)] + \
                    list(self._spatialPoolerInput.nonzero()[0])
        elif parameterName == 'spLearningStatsStr':
            try:
                return str(self._sfdr.getLearningStats())
            except:
                return str(dict())
        else:
            return PyRegion.getParameter(self, parameterName, index)
Exemplo n.º 12
0
 def getParameter(self, parameterName, index=-1):
     """
   Get the value of a NodeSpec parameter. Most parameters are handled
   automatically by PyRegion's parameter get mechanism. The ones that need
   special treatment are explicitly handled here.
 """
     return PyRegion.getParameter(self, parameterName, index)
Exemplo n.º 13
0
 def setParameter(self, name, index, value):
   """
   Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.setParameter`.
   """
   if name == "learningMode":
     self.learningMode = bool(int(value))
     self._epoch = 0
   elif name == "inferenceMode":
     self._epoch = 0
     if int(value) and not self.inferenceMode:
       self._finishLearning()
     self.inferenceMode = bool(int(value))
   elif name == "distanceNorm":
     self._knn.distanceNorm = value
   elif name == "distanceMethod":
     self._knn.distanceMethod = value
   elif name == "keepAllDistances":
     self.keepAllDistances = bool(value)
     if not self.keepAllDistances:
       # Discard all distances except the latest
       if self._protoScores is not None and self._protoScores.shape[0] > 1:
         self._protoScores = self._protoScores[-1,:]
       if self._protoScores is not None:
         self._protoScoreCount = 1
       else:
         self._protoScoreCount = 0
   elif name == "verbosity":
     self.verbosity = value
     self._knn.verbosity = value
   else:
     return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 14
0
 def setParameter(self, name, index, value):
   """
   Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.setParameter`.
   """
   if name == "learningMode":
     self.learningMode = bool(int(value))
     self._epoch = 0
   elif name == "inferenceMode":
     self._epoch = 0
     if int(value) and not self.inferenceMode:
       self._finishLearning()
     self.inferenceMode = bool(int(value))
   elif name == "distanceNorm":
     self._knn.distanceNorm = value
   elif name == "distanceMethod":
     self._knn.distanceMethod = value
   elif name == "keepAllDistances":
     self.keepAllDistances = bool(value)
     if not self.keepAllDistances:
       # Discard all distances except the latest
       if self._protoScores is not None and self._protoScores.shape[0] > 1:
         self._protoScores = self._protoScores[-1,:]
       if self._protoScores is not None:
         self._protoScoreCount = 1
       else:
         self._protoScoreCount = 0
   elif name == "verbosity":
     self.verbosity = value
     self._knn.verbosity = value
   else:
     return PyRegion.setParameter(self, name, index, value)
 def getParameter(self, name, index=-1):
   """
   Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.getParameter`.
   """
   # If any spec parameter name is the same as an attribute, this call
   # will get it automatically, e.g. self.learningMode
   return PyRegion.getParameter(self, name, index)
Exemplo n.º 16
0
  def setParameter(self, name, index, value):
    """
    Set the value of the parameter.

    @param name -- the name of the parameter to update, as defined
            by the Node Spec.
    @param value -- the value to which the parameter is to be set.
    """
    if name == "learningMode":
      self.learningMode = bool(int(value))
      self._epoch = 0
    elif name == "inferenceMode":
      self._epoch = 0
      if int(value) and not self.inferenceMode:
        self._finishLearning()
      self.inferenceMode = bool(int(value))
    elif name == "distanceNorm":
      self._knn.distanceNorm = value
    elif name == "distanceMethod":
      self._knn.distanceMethod = value
    elif name == "keepAllDistances":
      self.keepAllDistances = bool(value)
      if not self.keepAllDistances:
        # Discard all distances except the latest
        if self._protoScores is not None and self._protoScores.shape[0] > 1:
          self._protoScores = self._protoScores[-1,:]
        if self._protoScores is not None:
          self._protoScoreCount = 1
        else:
          self._protoScoreCount = 0
    elif name == "clVerbosity":
      self.verbosity = value
      self._knn.verbosity = value
    else:
      return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 17
0
 def getParameter(self, name, index=-1):
   """
   Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.getParameter`.
   """
   # If any spec parameter name is the same as an attribute, this call
   # will get it automatically, e.g. self.learningMode
   return PyRegion.getParameter(self, name, index)
Exemplo n.º 18
0
  def getParameter(self, parameterName, index=-1):
    """
      Get the value of a NodeSpec parameter. Most parameters are handled
      automatically by PyRegion's parameter get mechanism. The ones that need
      special treatment are explicitly handled here.
    """

    if parameterName == 'activeOutputCount':
      return self.columnCount
    elif parameterName == 'spatialPoolerInput':
      return list(self._spatialPoolerInput.reshape(-1))
    elif parameterName == 'spatialPoolerOutput':
      return list(self._spatialPoolerOutput)
    elif parameterName == 'spNumActiveOutputs':
      return len(self._spatialPoolerOutput.nonzero()[0])
    elif parameterName == 'spOutputNonZeros':
      return [len(self._spatialPoolerOutput)] + \
              list(self._spatialPoolerOutput.nonzero()[0])
    elif parameterName == 'spInputNonZeros':
      import pdb; pdb.set_trace()
      return [len(self._spatialPoolerInput)] + \
              list(self._spatialPoolerInput.nonzero()[0])
    elif parameterName == 'spLearningStatsStr':
      try:
        return str(self._sfdr.getLearningStats())
      except:
        return str(dict())
    else:
      return PyRegion.getParameter(self, parameterName, index)
Exemplo n.º 19
0
  def __init__(self,
               columnCount=2048,
               cellsPerColumn=32,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               seed=42,
               learnOnOneCell=1,
               formInternalConnections=1,
               formInternalBasalConnections=1,
               defaultOutputType = "active",
               monitor=False,
               implementation="cpp",
               **kwargs):
    # Defaults for all other parameters

    self.columnCount = columnCount
    self.cellsPerColumn = cellsPerColumn
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.maxNewSynapseCount = maxNewSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    self.seed = seed
    self.learnOnOneCell = bool(learnOnOneCell)
    self.learningMode = True
    self.inferenceMode = True
    self.formInternalConnections = bool(formInternalConnections)
    self.formInternalBasalConnections = bool(formInternalBasalConnections)
    self.defaultOutputType = defaultOutputType
    self.monitor = monitor
    self.implementation = implementation

    PyRegion.__init__(self, **kwargs)

    # TM instance
    self._tm = None
Exemplo n.º 20
0
    def __init__(self,
                 verbosity=0,
                 colorOption=False,
                 colorDiscreteIntensity=5,
                 **kwargs):
        self._colorOption = colorOption
        self._colorDiscreteIntensity = colorDiscreteIntensity
        self.dataSource = None
        self.verbosity = verbosity
        self._inputWidth = 768 * 1024 * 3
        # fixed universe input
        self._dataWidth = 160 * 160 * 3 * 5 if colorOption else 160 * 160
        # output size dependent on color option

        # lastRecord is the last record returned. Used for debugging only
        self.lastRecord = None

        PyRegion.__init__(self, **kwargs)
Exemplo n.º 21
0
  def getParameter(self, name, index=-1):
    """
    Get the value of the parameter.

    @param name -- the name of the parameter to retrieve, as defined
            by the Node Spec.
    """
    if name == "patternCount":
      return self._knn._numPatterns
    elif name == "patternMatrix":
      return self._getPatternMatrix()
    elif name == "k":
      return self._knn.k
    elif name == "distanceNorm":
      return self._knn.distanceNorm
    elif name == "distanceMethod":
      return self._knn.distanceMethod
    elif name == "distThreshold":
      return self._knn.distThreshold
    elif name == "inputThresh":
      return self._knn.binarizationThreshold
    elif name == "doBinarization":
      return self._knn.doBinarization
    elif name == "useSparseMemory":
      return self._knn.useSparseMemory
    elif name == "sparseThreshold":
      return self._knn.sparseThreshold
    elif name == "winnerCount":
      return self._knn.numWinners
    elif name == "relativeThreshold":
      return self._knn.relativeThreshold
    elif name == "SVDSampleCount":
      v = self._knn.numSVDSamples
      return v if v is not None else 0
    elif name == "SVDDimCount":
      v = self._knn.numSVDDims
      return v if v is not None else 0
    elif name == "fractionOfMax":
      v = self._knn.fractionOfMax
      return v if v is not None else 0
    elif name == "useAuxiliary":
      return self._useAuxiliary
    elif name == "justUseAuxiliary":
      return self._justUseAuxiliary
    elif name == "doSphering":
      return self._doSphering
    elif name == "cellsPerCol":
      return self._knn.cellsPerCol
    elif name == "maxStoredPatterns":
      return self.maxStoredPatterns
    elif name == 'categoryRecencyList':
      return self._knn._categoryRecencyList
    else:
      # If any spec parameter name is the same as an attribute, this call
      # will get it automatically, e.g. self.learningMode
      return PyRegion.getParameter(self, name, index)
Exemplo n.º 22
0
  def getParameter(self, name, index=-1):
    """
    Get the value of the parameter.

    @param name -- the name of the parameter to retrieve, as defined
            by the Node Spec.
    """
    # If any spec parameter name is the same as an attribute, this call
    # will get it automatically, e.g. self.learningMode
    return PyRegion.getParameter(self, name, index)
Exemplo n.º 23
0
 def setParameter(self, name, index, value):
     """
 Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.setParameter`.
 """
     if name == "learningMode":
         self.learningMode = bool(int(value))
     elif name == "inferenceMode":
         self.inferenceMode = bool(int(value))
     else:
         return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 24
0
 def setParameter(self, name, index, value):
   """
   Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.setParameter`.
   """
   if name == "learningMode":
     self.learningMode = bool(int(value))
   elif name == "inferenceMode":
     self.inferenceMode = bool(int(value))
   else:
     return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 25
0
    def __init__(self,
                 columnDimensions=(2048, ),
                 cellsPerColumn=32,
                 activationThreshold=13,
                 initialPermanence=0.21,
                 connectedPermanence=0.50,
                 minThreshold=10,
                 maxNewSynapseCount=20,
                 permanenceIncrement=0.10,
                 permanenceDecrement=0.10,
                 predictedSegmentDecrement=0.0,
                 seed=42,
                 learnOnOneCell=False,
                 tmImp=getDefaultTMImp(),
                 **kwargs):

        # Pull out the tm arguments automatically
        # These calls whittle down kwargs and create instance variables of TMRegion
        self._tmClass = getTMClass(tmImp)
        tmArgTuples = _buildArgs(self._tmClass, self, kwargs)

        # Make a list of automatic tm arg names for later use
        self._tmArgNames = [t[0] for t in tmArgTuples]

        # Defaults for all other parameters
        self.columnDimensions = copy.deepcopy(columnDimensions)
        self.cellsPerColumn = cellsPerColumn
        self.activationThreshold = activationThreshold
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.minThreshold = minThreshold
        self.maxNewSynapseCount = maxNewSynapseCount
        self.permanenceIncrement = permanenceIncrement
        self.permanenceDecrement = permanenceDecrement
        self.predictedSegmentDecrement = predictedSegmentDecrement
        self.seed = seed
        self.learnOnOneCell = learnOnOneCell
        self.learningMode = True

        PyRegion.__init__(self, **kwargs)

        # TM instance
        self._tm = None
Exemplo n.º 26
0
  def __init__(self,
               columnDimensions=(2048,),
               cellsPerColumn=32,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               seed=42,
               learnOnOneCell=False,
               tmImp=getDefaultTMImp(),
               **kwargs):

    # Pull out the tm arguments automatically
    # These calls whittle down kwargs and create instance variables of TMRegion
    self._tmClass = getTMClass(tmImp)
    tmArgTuples = _buildArgs(self._tmClass, self, kwargs)

    # Make a list of automatic tm arg names for later use
    self._tmArgNames = [t[0] for t in tmArgTuples]

    # Defaults for all other parameters
    self.columnDimensions = copy.deepcopy(columnDimensions)
    self.cellsPerColumn = cellsPerColumn
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.maxNewSynapseCount = maxNewSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    self.seed = seed
    self.learnOnOneCell = learnOnOneCell
    self.learningMode = True

    PyRegion.__init__(self, **kwargs)

    # TM instance
    self._tm = None
Exemplo n.º 27
0
    def getParameter(self, parameterName, index=-1):
        """
      Get the value of a parameter. Most parameters are handled automatically by
      PyRegion's parameter get mechanism. The ones that need special treatment
      are explicitly handled here.
    """

        if parameterName in self._temporalArgNames:
            return getattr(self._tfdr, parameterName)
        else:
            return PyRegion.getParameter(self, parameterName, index)
Exemplo n.º 28
0
  def getParameter(self, parameterName, index=-1):
    """
      Get the value of a parameter. Most parameters are handled automatically by
      PyRegion's parameter get mechanism. The ones that need special treatment
      are explicitly handled here.
    """

    if parameterName in self._temporalArgNames:
      return getattr(self._tfdr, parameterName)
    else:
      return PyRegion.getParameter(self, parameterName, index)
Exemplo n.º 29
0
  def __init__(self,
               columnCount=2048,
               inputWidth=16384,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               synPermProximalInc=0.1,
               synPermProximalDec=0.001,
               initialProximalPermanence = 0.6,
               seed=42,
               numActiveColumnsPerInhArea=40,
               defaultOutputType = "active",
               **kwargs):
    # Defaults for all other parameters
    self.columnCount = columnCount
    self.inputWidth = inputWidth
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.maxNewSynapseCount = maxNewSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    self.synPermProximalInc = synPermProximalInc
    self.synPermProximalDec = synPermProximalDec
    self.initialProximalPermanence = initialProximalPermanence
    self.seed = seed
    self.learningMode = True
    self.inferenceMode = True
    self.defaultOutputType = defaultOutputType
    self.numActiveColumnsPerInhArea = numActiveColumnsPerInhArea

    self._pooler = None

    PyRegion.__init__(self, **kwargs)
Exemplo n.º 30
0
  def getParameter(self, parameterName, index=-1):
    """
    Overrides :meth:`~nupic.bindings.regions.PyRegion.PyRegion.getParameter`.

    Get the value of a parameter. Most parameters are handled automatically by
    :class:`~nupic.bindings.regions.PyRegion.PyRegion`'s parameter get mechanism. The 
    ones that need special treatment are explicitly handled here.
    """
    if parameterName in self._temporalArgNames:
      return getattr(self._tfdr, parameterName)
    else:
      return PyRegion.getParameter(self, parameterName, index)
Exemplo n.º 31
0
    def __init__(self,
                 columnCount=2048,
                 cellsPerColumn=32,
                 activationThreshold=13,
                 initialPermanence=0.21,
                 connectedPermanence=0.50,
                 minThreshold=10,
                 maxNewSynapseCount=20,
                 permanenceIncrement=0.10,
                 permanenceDecrement=0.10,
                 predictedSegmentDecrement=0.0,
                 seed=42,
                 learnOnOneCell=1,
                 temporalImp="tm",
                 formInternalConnections=1,
                 defaultOutputType="active",
                 **kwargs):
        # Defaults for all other parameters
        self.columnCount = columnCount
        self.cellsPerColumn = cellsPerColumn
        self.activationThreshold = activationThreshold
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.minThreshold = minThreshold
        self.maxNewSynapseCount = maxNewSynapseCount
        self.permanenceIncrement = permanenceIncrement
        self.permanenceDecrement = permanenceDecrement
        self.predictedSegmentDecrement = predictedSegmentDecrement
        self.seed = seed
        self.learnOnOneCell = bool(learnOnOneCell)
        self.learningMode = True
        self.inferenceMode = True
        self.temporalImp = temporalImp
        self.formInternalConnections = bool(formInternalConnections)
        self.defaultOutputType = defaultOutputType

        PyRegion.__init__(self, **kwargs)

        # TM instance
        self._tm = None
Exemplo n.º 32
0
  def __init__(self,
               columnCount=2048,
               cellsPerColumn=32,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               seed=42,
               learnOnOneCell=1,
               temporalImp="tm",
               formInternalConnections = 1,
               **kwargs):
    # Defaults for all other parameters
    self.columnCount = columnCount
    self.cellsPerColumn = cellsPerColumn
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.maxNewSynapseCount = maxNewSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    self.seed = seed
    self.learnOnOneCell = bool(learnOnOneCell)
    self.learningMode = True
    self.inferenceMode = True
    self.temporalImp = temporalImp
    self.formInternalConnections = bool(formInternalConnections)
    self.previouslyPredictedCells = set()

    PyRegion.__init__(self, **kwargs)

    # TM instance
    self._tm = None
Exemplo n.º 33
0
  def setParameter(self, name, index, value):
    """
    Set the value of the parameter.

    @param name -- the name of the parameter to update, as defined
            by the Node Spec.
    @param value -- the value to which the parameter is to be set.
    """
    if name == "learningMode":
      self.learningMode = bool(int(value))
    elif name == "inferenceMode":
      self.inferenceMode = bool(int(value))
    else:
      return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 34
0
 def getParameter(self, name, index=-1):
   """
   Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.getParameter`.
   """
   if name == "trainRecords":
     return self.trainRecords
   elif name == "anomalyThreshold":
     return self.anomalyThreshold
   elif name == "activeColumnCount":
     return self._activeColumnCount
   elif name == "classificationMaxDist":
     return self._classificationMaxDist
   else:
     # If any spec parameter name is the same as an attribute, this call
     # will get it automatically, e.g. self.learningMode
     return PyRegion.getParameter(self, name, index)
 def getParameter(self, name, index=-1):
   """
   Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.getParameter`.
   """
   if name == "trainRecords":
     return self.trainRecords
   elif name == "anomalyThreshold":
     return self.anomalyThreshold
   elif name == "activeColumnCount":
     return self._activeColumnCount
   elif name == "classificationMaxDist":
     return self._classificationMaxDist
   else:
     # If any spec parameter name is the same as an attribute, this call
     # will get it automatically, e.g. self.learningMode
     return PyRegion.getParameter(self, name, index)
Exemplo n.º 36
0
    def setParameter(self, name, index, value):
        """
    Set the value of the parameter.

    @param name -- the name of the parameter to update, as defined
            by the Node Spec.
    @param value -- the value to which the parameter is to be set.
    """
        if name == "trainRecords":
            # Ensure that the trainRecords can only be set to minimum of the ROWID in
            # the saved states
            if not (isinstance(value, float) or isinstance(value, int)):
                raise CLAModelInvalidArgument(
                    "Invalid argument type \'%s\'. threshold "
                    "must be a number." % (type(value)))

            if len(self._recordsCache
                   ) > 0 and value < self._recordsCache[0].ROWID:
                raise CLAModelInvalidArgument(
                    "Invalid value. autoDetectWaitRecord "
                    "value must be valid record within output stream. Current minimum "
                    " ROWID in output stream is %d." %
                    (self._recordsCache[0].ROWID))

            self.trainRecords = value
            # Remove any labels before the first cached record (wont be used anymore)
            self._deleteRangeFromKNN(0, self._recordsCache[0].ROWID)
            # Reclassify all states
            self.classifyStates()
        elif name == "anomalyThreshold":
            if not (isinstance(value, float) or isinstance(value, int)):
                raise CLAModelInvalidArgument(
                    "Invalid argument type \'%s\'. threshold "
                    "must be a number." % (type(value)))
            self.anomalyThreshold = value
            self.classifyStates()
        elif name == "classificationMaxDist":
            if not (isinstance(value, float) or isinstance(value, int)):
                raise CLAModelInvalidArgument(
                    "Invalid argument type \'%s\'. "
                    "classificationMaxDist must be a number." % (type(value)))
            self._classificationMaxDist = value
            self.classifyStates()
        elif name == "activeColumnCount":
            self._activeColumnCount = value
        else:
            return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 37
0
    def getParameter(self, name, index=-1):
        """
    Get the value of the parameter.

    @param name -- the name of the parameter to retrieve, as defined
            by the Node Spec.
    """
        if name == "trainRecords":
            return self.trainRecords
        elif name == "anomalyThreshold":
            return self.anomalyThreshold
        elif name == "activeColumnCount":
            return self._activeColumnCount
        elif name == "classificationMaxDist":
            return self._classificationMaxDist
        else:
            # If any spec parameter name is the same as an attribute, this call
            # will get it automatically, e.g. self.learningMode
            return PyRegion.getParameter(self, name, index)
Exemplo n.º 38
0
  def getParameter(self, name, index=-1):
    """
    Get the value of the parameter.

    @param name -- the name of the parameter to retrieve, as defined
            by the Node Spec.
    """
    if name == "trainRecords":
      return self.trainRecords
    elif name == "anomalyThreshold":
      return self.anomalyThreshold
    elif name == "activeColumnCount":
      return self._activeColumnCount
    elif name == "classificationMaxDist":
      return self._classificationMaxDist
    else:
      # If any spec parameter name is the same as an attribute, this call
      # will get it automatically, e.g. self.learningMode
      return PyRegion.getParameter(self, name, index)
Exemplo n.º 39
0
  def setParameter(self, name, index, value):
    """
    Set the value of the parameter.

    @param name -- the name of the parameter to update, as defined
            by the Node Spec.
    @param value -- the value to which the parameter is to be set.
    """
    if name == "trainRecords":
      # Ensure that the trainRecords can only be set to minimum of the ROWID in
      # the saved states
      if not (isinstance(value, float) or isinstance(value, int)):
        raise CLAModelInvalidArgument("Invalid argument type \'%s\'. threshold "
          "must be a number." % (type(value)))

      if len(self._recordsCache) > 0 and value < self._recordsCache[0].ROWID:
        raise CLAModelInvalidArgument("Invalid value. autoDetectWaitRecord "
          "value must be valid record within output stream. Current minimum "
          " ROWID in output stream is %d." % (self._recordsCache[0].ROWID))

      self.trainRecords = value
      # Remove any labels before the first cached record (wont be used anymore)
      self._deleteRangeFromKNN(0, self._recordsCache[0].ROWID)
      # Reclassify all states
      self.classifyStates()
    elif name == "anomalyThreshold":
      if not (isinstance(value, float) or isinstance(value, int)):
        raise CLAModelInvalidArgument("Invalid argument type \'%s\'. threshold "
          "must be a number." % (type(value)))
      self.anomalyThreshold = value
      self.classifyStates()
    elif name == "classificationMaxDist":
      if not (isinstance(value, float) or isinstance(value, int)):
        raise CLAModelInvalidArgument("Invalid argument type \'%s\'. "
          "classificationMaxDist must be a number." % (type(value)))
      self._classificationMaxDist = value
      self.classifyStates()
    elif name == "activeColumnCount":
      self._activeColumnCount = value
    else:
      return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 40
0
    def setParameter(self, name, index, value):
        """
    Set the value of the parameter.

    @param name -- the name of the parameter to update, as defined
            by the Node Spec.
    @param value -- the value to which the parameter is to be set.
    """
        if name == "learningMode":
            if int(value) and not self.learningMode:
                self._restartLearning()
            self.learningMode = bool(int(value))
            self._epoch = 0
        elif name == "inferenceMode":
            self._epoch = 0
            if int(value) and not self.inferenceMode:
                self._finishLearning()
            self.inferenceMode = bool(int(value))
        elif name == "distanceNorm":
            self._knn.distanceNorm = value
        elif name == "distanceMethod":
            self._knn.distanceMethod = value
        elif name == "keepAllDistances":
            self.keepAllDistances = bool(value)
            if not self.keepAllDistances:
                # Discard all distances except the latest
                if self._protoScores is not None and self._protoScores.shape[
                        0] > 1:
                    self._protoScores = self._protoScores[-1, :]
                if self._protoScores is not None:
                    self._protoScoreCount = 1
                else:
                    self._protoScoreCount = 0
        elif name == "clVerbosity":
            self.verbosity = value
            self._knn.verbosity = value
        elif name == "doSelfValidation":
            self.doSelfValidation = value
        else:
            return PyRegion.setParameter(self, name, index, value)
Exemplo n.º 41
0
  def getParameter(self, name, index=-1):
    """
    Get the value of a parameter.

    Note: this method may be overridden by derived classes, but if so, then
    the derived class should invoke this base method if 'name'
    is unknown to the derived class.

    @param name -- the name of the parameter to retrieve, as defined
            by the Node Spec.
    """
    if name == "SVDSampleCount":
      return self._SVDSampleCount
    elif name == "SVDDimCount":
      return self._SVDDimCount
    elif name == "fractionOfMax":
      return self._fractionOfMax
    elif name == "trainingSampleCount":
      return self.gettrainingSampleCount()
    else:
      # If any spec parameter name is the same as an attribute, this call
      # will get it automatically, e.g. self.learningMode
      return PyRegion.getParameter(self, name, index)
Exemplo n.º 42
0
    def getParameter(self, name, index=-1):
        """
    Get the value of a parameter.

    Note: this method may be overridden by derived classes, but if so, then
    the derived class should invoke this base method if 'name'
    is unknown to the derived class.

    @param name -- the name of the parameter to retrieve, as defined
            by the Node Spec.
    """
        if name == "SVDSampleCount":
            return self._SVDSampleCount
        elif name == "SVDDimCount":
            return self._SVDDimCount
        elif name == "fractionOfMax":
            return self._fractionOfMax
        elif name == "trainingSampleCount":
            return self.gettrainingSampleCount()
        else:
            # If any spec parameter name is the same as an attribute, this call
            # will get it automatically, e.g. self.learningMode
            return PyRegion.getParameter(self, name, index)
Exemplo n.º 43
0
    def __init__(
            self,

            # Modified ETM params
            columnCount=2048,
            basalInputWidth=0,
            apicalInputWidth=0,
            TDTraceDecay=0.0,
            TDDiscount=0.0,
            TDLearningRate=0.1,
            globalValueDecay=0.0,

            # ETM params
            cellsPerColumn=32,
            activationThreshold=13,
            initialPermanence=0.21,
            connectedPermanence=0.50,
            minThreshold=10,
            maxNewSynapseCount=20,
            permanenceIncrement=0.10,
            permanenceDecrement=0.10,
            predictedSegmentDecrement=0.0,
            formInternalBasalConnections=True,
            learnOnOneCell=False,
            maxSegmentsPerCell=255,
            maxSynapsesPerSegment=255,
            seed=42,
            checkInputs=True,

            # Region params
            implementation="etm",
            learn=True,
            **kwargs):

        # Input sizes (the network API doesn't provide these during initialize)
        self.columnCount = columnCount
        self.basalInputWidth = basalInputWidth
        self.apicalInputWidth = apicalInputWidth

        # TM params
        self.cellsPerColumn = cellsPerColumn
        self.activationThreshold = activationThreshold
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.minThreshold = minThreshold
        self.maxNewSynapseCount = maxNewSynapseCount
        self.permanenceIncrement = permanenceIncrement
        self.permanenceDecrement = permanenceDecrement
        self.predictedSegmentDecrement = predictedSegmentDecrement
        self.formInternalBasalConnections = formInternalBasalConnections
        self.learnOnOneCell = learnOnOneCell
        self.maxSegmentsPerCell = maxSegmentsPerCell
        self.maxSynapsesPerSegment = maxSynapsesPerSegment
        self.seed = seed
        self.checkInputs = checkInputs

        # Region params
        self.implementation = implementation
        self.learn = learn

        PyRegion.__init__(self, **kwargs)

        # TM instance
        self._tm = None

        # Reinforcement Learning variables (Eligability traces and values for each neuron)
        self.TDDiscount = TDDiscount
        self.TDLearningRate = TDLearningRate
        self.TDTraceDecay = TDTraceDecay
        self.globalValueDecay = globalValueDecay
        self.traces = np.zeros(columnCount * cellsPerColumn)
        self.values = np.zeros(columnCount * cellsPerColumn)
        self.stateValue = 0
        self.prevActiveCells = []
        # Save prev. distal input for calculation with L5(t-1) distal input
        self.prevActiveCellsExternalBasal = []
        # For Debug save errors
        self.TDError = 0
Exemplo n.º 44
0
    def __init__(
            self,

            # Modified ETM params
            columnCount=2048,
            basalInputWidth=0,
            apicalInputWidth=0,

            # ETM params
            cellsPerColumn=32,
            activationThreshold=13,
            initialPermanence=0.21,
            connectedPermanence=0.50,
            minThreshold=10,
            maxNewSynapseCount=20,
            permanenceIncrement=0.10,
            permanenceDecrement=0.10,
            predictedSegmentDecrement=0.0,
            formInternalBasalConnections=True,
            learnOnOneCell=False,
            maxSegmentsPerCell=255,
            maxSynapsesPerSegment=255,
            seed=42,
            checkInputs=True,

            # Region params
            implementation="etm",
            learn=True,
            **kwargs):

        # Input sizes (the network API doesn't provide these during initialize)
        self.columnCount = columnCount
        self.basalInputWidth = basalInputWidth
        self.apicalInputWidth = apicalInputWidth

        # TM params
        self.cellsPerColumn = cellsPerColumn
        self.activationThreshold = activationThreshold
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.minThreshold = minThreshold
        self.maxNewSynapseCount = maxNewSynapseCount
        self.permanenceIncrement = permanenceIncrement
        self.permanenceDecrement = permanenceDecrement
        self.predictedSegmentDecrement = predictedSegmentDecrement
        self.formInternalBasalConnections = formInternalBasalConnections
        self.learnOnOneCell = learnOnOneCell
        self.maxSegmentsPerCell = maxSegmentsPerCell
        self.maxSynapsesPerSegment = maxSynapsesPerSegment
        self.seed = seed
        self.checkInputs = checkInputs

        # Region params
        self.implementation = implementation
        self.learn = learn

        PyRegion.__init__(self, **kwargs)

        # TM instance
        self._tm = None

        # Custom use L2(t-1) and L4(t-1) input for basal
        self.prevBasalInput = ()
Exemplo n.º 45
0
  def __init__(self, maxActive, outputWidth, **kwargs):
    PyRegion.__init__(self, **kwargs)

    self.maxActive = maxActive
    self.outputWidth = outputWidth
Exemplo n.º 46
0
 def compute(self, inputs, outputs):
   if "dataIn" in inputs:
     PyRegion.setSparseOutput(outputs, "dataOut", inputs["dataIn"])
   else:
     PyRegion.setSparseOutput(outputs, "dataOut", self.data)
Exemplo n.º 47
0
 def compute(self, inputs, outputs):
     if "dataIn" in inputs:
         PyRegion.setSparseOutput(outputs, "dataOut", inputs["dataIn"])
     else:
         PyRegion.setSparseOutput(outputs, "dataOut", self.data)
  def __init__(self,
               cellCount=4096,
               inputWidth=16384,
               numOtherCorticalColumns=0,
               sdrSize=40,
               onlineLearning = False,
               maxSdrSize = None,
               minSdrSize = None,

               # Proximal
               synPermProximalInc=0.1,
               synPermProximalDec=0.001,
               initialProximalPermanence=0.6,
               sampleSizeProximal=20,
               minThresholdProximal=1,
               connectedPermanenceProximal=0.50,
               predictedInhibitionThreshold=20,

               # Distal
               synPermDistalInc=0.10,
               synPermDistalDec=0.10,
               initialDistalPermanence=0.21,
               sampleSizeDistal=20,
               activationThresholdDistal=13,
               connectedPermanenceDistal=0.50,
               inertiaFactor=1.,

               seed=42,
               defaultOutputType = "active",
               **kwargs):

    # Used to derive Column Pooler params
    self.numOtherCorticalColumns = numOtherCorticalColumns

    # Column Pooler params
    self.inputWidth = inputWidth
    self.cellCount = cellCount
    self.sdrSize = sdrSize
    self.onlineLearning = onlineLearning
    self.maxSdrSize = maxSdrSize
    self.minSdrSize = minSdrSize
    self.synPermProximalInc = synPermProximalInc
    self.synPermProximalDec = synPermProximalDec
    self.initialProximalPermanence = initialProximalPermanence
    self.sampleSizeProximal = sampleSizeProximal
    self.minThresholdProximal = minThresholdProximal
    self.connectedPermanenceProximal = connectedPermanenceProximal
    self.predictedInhibitionThreshold = predictedInhibitionThreshold
    self.synPermDistalInc = synPermDistalInc
    self.synPermDistalDec = synPermDistalDec
    self.initialDistalPermanence = initialDistalPermanence
    self.sampleSizeDistal = sampleSizeDistal
    self.activationThresholdDistal = activationThresholdDistal
    self.connectedPermanenceDistal = connectedPermanenceDistal
    self.inertiaFactor = inertiaFactor
    self.seed = seed

    # Region params
    self.learningMode = True
    self.defaultOutputType = defaultOutputType

    self._pooler = None

    PyRegion.__init__(self, **kwargs)
Exemplo n.º 49
0
  def __init__(self,

               columnCount,   # Number of columns in the SP, a required parameter
               inputWidth,    # Size of inputs to the SP, a required parameter
               cellsPerColumn, # Number of cells per column, required

               # Constructor arguments are picked up automatically. There is no
               # need to add them anywhere in TMRegion, unless you need to do
               # something special with them. See docstring above.

               orColumnOutputs=False,
               cellsSavePath='',
               temporalImp=gDefaultTemporalImp,
               anomalyMode=False,
               computePredictedActiveCellIndices=False,

               **kwargs):

    # Which Temporal implementation?
    TemporalClass = _getTPClass(temporalImp)

    # Make a list of automatic temporal arg names for later use
    # Pull out the temporal arguments automatically
    # These calls whittle down kwargs and create instance variables of TMRegion
    tArgTuples = _buildArgs(TemporalClass.__init__, self, kwargs)

    self._temporalArgNames = [t[0] for t in tArgTuples]

    self.learningMode   = True      # Start out with learning enabled
    self.inferenceMode  = False
    self.anomalyMode    = anomalyMode
    self.computePredictedActiveCellIndices = computePredictedActiveCellIndices
    self.topDownMode    = False
    self.columnCount    = columnCount
    self.inputWidth     = inputWidth
    self.outputWidth    = columnCount * cellsPerColumn
    self.cellsPerColumn = cellsPerColumn

    PyRegion.__init__(self, **kwargs)

    # Initialize all non-persistent base members, as well as give
    # derived class an opportunity to do the same.
    self._loaded = False
    self._initialize()

    # Debugging support, used in _conditionalBreak
    self.breakPdb = False
    self.breakKomodo = False

    # TMRegion only, or special handling
    self.orColumnOutputs = orColumnOutputs
    self.temporalImp = temporalImp

    # Various file names
    self.storeDenseOutput = False
    self.logPathOutput = ''
    self.cellsSavePath = cellsSavePath
    self._fpLogTPOutput = None

    # Variables set up in initInNetwork()
    self._tfdr                = None  # FDRTemporal instance
    def __init__(self,
                 moduleCount,
                 cellsPerAxis,
                 scale,
                 orientation,
                 anchorInputSize,
                 activeFiringRate,
                 bumpSigma,
                 activationThreshold=10,
                 initialPermanence=0.21,
                 connectedPermanence=0.50,
                 learningThreshold=10,
                 sampleSize=20,
                 permanenceIncrement=0.1,
                 permanenceDecrement=0.0,
                 maxSynapsesPerSegment=-1,
                 bumpOverlapMethod="probabilistic",
                 learningMode=False,
                 seed=42,
                 dualPhase=True,
                 dimensions=2,
                 **kwargs):
        if moduleCount <= 0 or cellsPerAxis <= 0:
            raise TypeError(
                "Parameters moduleCount and cellsPerAxis must be > 0")
        if moduleCount != len(scale) or moduleCount != len(orientation):
            raise TypeError(
                "scale and orientation arrays len must match moduleCount")
        if dimensions < 2:
            raise TypeError("dimensions must be >= 2")

        self.moduleCount = moduleCount
        self.cellsPerAxis = cellsPerAxis
        self.cellCount = cellsPerAxis * cellsPerAxis
        self.scale = list(scale)
        self.orientation = list(orientation)
        self.anchorInputSize = anchorInputSize
        self.activeFiringRate = activeFiringRate
        self.bumpSigma = bumpSigma
        self.activationThreshold = activationThreshold
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.learningThreshold = learningThreshold
        self.sampleSize = sampleSize
        self.permanenceIncrement = permanenceIncrement
        self.permanenceDecrement = permanenceDecrement
        self.maxSynapsesPerSegment = maxSynapsesPerSegment
        self.bumpOverlapMethod = bumpOverlapMethod
        self.learningMode = learningMode
        self.dualPhase = dualPhase
        self.dimensions = dimensions
        self.seed = seed

        # This flag controls whether the region is processing sensation or movement
        # on dual phase configuration
        self._sensing = False

        self._modules = None

        self._projection = None

        PyRegion.__init__(self, **kwargs)
Exemplo n.º 51
0
    def __init__(self, maxActive, outputWidth, **kwargs):
        PyRegion.__init__(self, **kwargs)

        self.maxActive = maxActive
        self.outputWidth = outputWidth
  def __init__(self,
               cellCount=4096,
               inputWidth=16384,
               numOtherCorticalColumns=0,
               sdrSize=40,
               maxSdrSize = None,
               minSdrSize = None,

               # Proximal
               sampleSizeProximal=20,

               # Distal
               sampleSizeDistal=20,
               inertiaFactor=1.,

               # Bayesian
               noise=0.01,  # lambda
               learningRate=0.1,  # alpha
               activationThreshold=0.5,  # probability such that a cell becomes active
               forgetting=0.1,
               initMovingAverages=0.0,
               useSupport=False,
               avoidWeightExplosion=True,
               resetProximalCounter=False,
               useProximalProbabilities=True,
               implementation="Bayesian",
               seed=42,
               defaultOutputType = "active",
               **kwargs):

    # Used to derive Column Pooler params
    self.numOtherCorticalColumns = numOtherCorticalColumns

    # Column Pooler params
    self.inputWidth = inputWidth
    self.cellCount = cellCount
    self.sdrSize = sdrSize
    self.maxSdrSize = maxSdrSize
    self.minSdrSize = minSdrSize
    self.sampleSizeProximal = sampleSizeProximal
    self.sampleSizeDistal = sampleSizeDistal
    self.inertiaFactor = inertiaFactor
    self.seed = seed

    self.activationThreshold = activationThreshold
    self.learningRate = learningRate
    self.noise = noise

    self.implementation = implementation

    self.forgetting = forgetting
    self.initMovingAverages = initMovingAverages
    self.useSupport = useSupport
    self.avoidWeightExplosion = avoidWeightExplosion
    self.resetProximalCounter = resetProximalCounter
    self.useProximalProbabilities = useProximalProbabilities
    # Region params
    self.learningMode = True
    self.defaultOutputType = defaultOutputType

    self._pooler = None

    PyRegion.__init__(self, **kwargs)
Exemplo n.º 53
0
    def __init__(
            self,

            # Modified TM params
            basalInputWidth=0,
            apicalInputWidth=0,
            apicalGlobalDecay=0.000001,
            TDLearningRate=0.5,
            winnerSize=4,
            motorCount=32,
            synPermActiveIncMotor=0.04,
            synPermInactiveDecMotor=0.008,

            # TM params
            columnCount=2048,
            cellsPerColumn=32,
            activationThreshold=13,
            initialPermanence=0.21,
            connectedPermanence=0.50,
            minThreshold=10,
            maxNewSynapseCount=20,
            punishPredDec=0.0,
            maxSynapsesPerSegment=255,
            seed=42,

            # Region params
            learn=True,
            **kwargs):

        # Input sizes (the network API doesn't provide these during initialize)
        self.columnCount = columnCount
        self.basalInputWidth = basalInputWidth
        self.apicalInputWidth = apicalInputWidth

        # TM params
        self.columnCount = columnCount
        self.cellsPerColumn = cellsPerColumn
        self.basalInputWidth = basalInputWidth
        self.apicalInputWidth = apicalInputWidth
        self.activationThreshold = activationThreshold
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.minThreshold = minThreshold
        self.maxSynapsesPerSegment = maxSynapsesPerSegment
        self.seed = seed

        # Motor specific
        self.TDLearningRate = TDLearningRate
        self.apicalGlobalDecay = apicalGlobalDecay
        self.winnerSize = winnerSize
        self.punishPredDec = punishPredDec
        self.motorCount = motorCount
        self.synPermActiveIncMotor = synPermActiveIncMotor
        self.synPermInactiveDecMotor = synPermInactiveDecMotor

        # Region params
        self.learn = learn

        PyRegion.__init__(self, **kwargs)

        # TM instance
        self._tm = None
Exemplo n.º 54
0
  def __init__(self,
               columnCount,   # Number of columns in the SP, a required parameter
               inputWidth,    # Size of inputs to the SP, a required parameter
               spatialImp=getDefaultSPImp(),   #'py', 'cpp'
               **kwargs):

    if columnCount <= 0 or inputWidth <=0:
      raise TypeError("Parameters columnCount and inputWidth must be > 0")

    # Pull out the spatial arguments automatically
    # These calls whittle down kwargs and create instance variables of SPRegion
    self.spatialImp = spatialImp
    self.SpatialClass = getSPClass(spatialImp)
    sArgTuples = _buildArgs(self.SpatialClass.__init__, self, kwargs)

    # Make a list of automatic spatial arg names for later use
    self._spatialArgNames = [t[0] for t in sArgTuples]

    # Learning and SP parameters.
    # By default we start out in stage learn with inference disabled
    self.learningMode   = True
    self.inferenceMode  = False
    self.anomalyMode    = False
    self.topDownMode    = False
    self.columnCount    = columnCount
    self.inputWidth     = inputWidth

    PyRegion.__init__(self, **kwargs)

    # Initialize all non-persistent base members, as well as give
    # derived class an opportunity to do the same.
    self._loaded = False
    self._initializeEphemeralMembers()

    # Debugging support, used in _conditionalBreak
    self.breakPdb = False
    self.breakKomodo = False

    # Defaults for all other parameters
    self.logPathInput = ''
    self.logPathOutput = ''
    self.logPathOutputDense = ''
    self._fpLogSPInput = None
    self._fpLogSP = None
    self._fpLogSPDense = None


    #
    # Variables set up in initInNetwork()
    #

    # Spatial instance
    self._sfdr                = None

    # Spatial pooler's bottom-up output value: hang on to this  output for
    # top-down inference and for debugging
    self._spatialPoolerOutput = None

    # Spatial pooler's bottom-up input: hang on to this for supporting the
    # spInputNonZeros parameter
    self._spatialPoolerInput  = None
Exemplo n.º 55
0
    def __init__(
            self,

            # Modified TM params
            columnCount=2048,
            basalInputWidth=0,
            apicalInputWidth=0,

            # ETM params
            cellsPerColumn=32,
            activationThreshold=13,
            initialPermanence=0.21,
            connectedPermanence=0.50,
            minThreshold=10,
            maxNewSynapseCount=20,
            permanenceIncrement=0.10,
            permanenceDecrement=0.10,
            predictedSegmentDecrement=0.0,
            formInternalBasalConnections=True,
            learnOnOneCell=False,
            maxSegmentsPerCell=255,
            maxSynapsesPerSegment=255,
            seed=42,
            checkInputs=True,

            # Region params
            defaultOutputType="active",
            implementation="etm",
            learningMode=True,
            inferenceMode=True,
            **kwargs):

        # Modified TM params
        self.columnCount = columnCount
        self.basalInputWidth = basalInputWidth
        self.apicalInputWidth = apicalInputWidth

        # TM params
        self.cellsPerColumn = cellsPerColumn
        self.activationThreshold = activationThreshold
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.minThreshold = minThreshold
        self.maxNewSynapseCount = maxNewSynapseCount
        self.permanenceIncrement = permanenceIncrement
        self.permanenceDecrement = permanenceDecrement
        self.predictedSegmentDecrement = predictedSegmentDecrement
        self.formInternalBasalConnections = formInternalBasalConnections
        self.learnOnOneCell = learnOnOneCell
        self.maxSegmentsPerCell = maxSegmentsPerCell
        self.maxSynapsesPerSegment = maxSynapsesPerSegment
        self.seed = seed
        self.checkInputs = checkInputs

        # Region params
        self.defaultOutputType = defaultOutputType
        self.implementation = implementation
        self.learningMode = learningMode
        self.inferenceMode = inferenceMode

        PyRegion.__init__(self, **kwargs)

        # TM instance
        self._tm = None
    def __init__(
            self,

            # Modified ETM params
            columnCount=2048,
            basalInputWidth=0,
            apicalInputWidth=0,

            # ETM params
            cellsPerColumn=32,
            initialPermanence=0.21,
            connectedPermanence=0.50,
            permanenceIncrement=0.10,
            permanenceDecrement=0.10,
            predictedSegmentDecrement=0.0,
            maxSynapsesPerSegment=255,
            seed=42,
            sampleSize=20,

            # apical, basal weighting
            activationThresholdBasal=13,
            activationThresholdApical=2,
            minThresholdBasal=10,
            minThresholdApical=1,
            basalPredictedSegmentDecrement=0.001,
            apicalPredictedSegmentDecrement=0.001,

            # Region params
            implementation="etm",
            learn=True,
            **kwargs):

        # Input sizes (the network API doesn't provide these during initialize)
        self.columnCount = columnCount
        self.basalInputWidth = basalInputWidth
        self.apicalInputWidth = apicalInputWidth

        # TM params
        self.cellsPerColumn = cellsPerColumn
        self.initialPermanence = initialPermanence
        self.connectedPermanence = connectedPermanence
        self.permanenceIncrement = permanenceIncrement
        self.permanenceDecrement = permanenceDecrement
        self.predictedSegmentDecrement = predictedSegmentDecrement
        self.maxSynapsesPerSegment = maxSynapsesPerSegment
        self.seed = seed
        self.sampleSize = sampleSize

        # TM weight distal and apical differently
        self.minThresholdBasal = minThresholdBasal
        self.minThresholdApical = minThresholdApical
        self.activationThresholdBasal = activationThresholdBasal
        self.activationThresholdApical = activationThresholdApical
        self.basalPredictedSegmentDecrement = basalPredictedSegmentDecrement
        self.apicalPredictedSegmentDecrement = apicalPredictedSegmentDecrement

        # Region params
        self.implementation = implementation
        self.learn = learn

        PyRegion.__init__(self, **kwargs)

        # TM instance
        self._tm = None

        # Custom use internal activation t-1 as basal input
        self.prevActivation = np.array([])