def initialize(self, inputs, outputs):
    """
    Initialize the self._tm if not already initialized. We need to figure out
    the constructor parameters for each class, and send it to that constructor.
    """
    if self._tm is None:
      # Create dict of arguments we will pass to the temporal memory class
      args = copy.deepcopy(self.__dict__)
      args["columnDimensions"] = (self.columnCount,)

      # Create the TM instance
      if self.monitor:
        self._tm = createModel("extendedMixin", **args)
      elif self.implementation == "cpp":
        del args["columnCount"]
        del args["formInternalConnections"]
        del args["monitor"]
        del args["implementation"]
        del args["learningMode"]
        del args["inferenceMode"]
        del args["defaultOutputType"]
        del args["_tm"]
        self._tm = createModel("reversedExtendedCPP", **args)
      else:
        self._tm = createModel("extended", **args)

      # numpy arrays we will use for some of the outputs
      self.activeState = numpy.zeros(self._tm.numberOfCells())
      self.previouslyPredictedCells = numpy.zeros(self._tm.numberOfCells())
示例#2
0
 def initialize(self):
   """
   Initialize the self._tm if not already initialized. We need to figure out
   the constructor parameters for each class, and send it to that constructor.
   """
   if self._tm is None:
     params = {
       "columnDimensions": (self.columnCount,),
       "basalInputDimensions": (self.basalInputWidth,),
       "apicalInputDimensions": (self.apicalInputWidth,),
       "cellsPerColumn": self.cellsPerColumn,
       "activationThreshold": self.activationThreshold,
       "initialPermanence": self.initialPermanence,
       "connectedPermanence": self.connectedPermanence,
       "minThreshold": self.minThreshold,
       "maxNewSynapseCount": self.maxNewSynapseCount,
       "permanenceIncrement": self.permanenceIncrement,
       "permanenceDecrement": self.permanenceDecrement,
       "predictedSegmentDecrement": self.predictedSegmentDecrement,
       "formInternalBasalConnections": self.formInternalBasalConnections,
       "learnOnOneCell": self.learnOnOneCell,
       "maxSegmentsPerCell": self.maxSegmentsPerCell,
       "maxSynapsesPerSegment": self.maxSynapsesPerSegment,
       "seed": self.seed,
       "checkInputs": self.checkInputs,
     }
     self._tm = createModel(self.implementation, **params)
示例#3
0
    def initialize(self, inputs, outputs):
        """
    Initialize the self._tm if not already initialized. We need to figure out
    the constructor parameters for each class, and send it to that constructor.
    """
        if self._tm is None:
            # Create dict of arguments we will pass to the temporal memory class
            args = copy.deepcopy(self.__dict__)
            args["columnDimensions"] = (self.columnCount, )

            # Ensure we only pass in those args that are expected by this
            # implementation. This is important for SWIG'ified classes, such as
            # TemporalMemoryCPP, which don't take kwargs.
            expectedArgs = getConstructorArguments(self.temporalImp)[0]
            for arg in args.keys():
                if not arg in expectedArgs:
                    args.pop(arg)

            # Create the TM instance
            self._tm = createModel(self.temporalImp, **args)

            # numpy arrays we will use for some of the outputs
            self.activeState = numpy.zeros(self._tm.numberOfCells())
            self.previouslyPredictedCells = numpy.zeros(
                self._tm.numberOfCells())
 def initialize(self, dims, splitterMaps):
   """
   Initialize the self._tm if not already initialized. We need to figure out
   the constructor parameters for each class, and send it to that constructor.
   """
   if self._tm is None:
     params = {
       "columnDimensions": (self.columnCount,),
       "basalInputDimensions": (self.basalInputWidth,),
       "apicalInputDimensions": (self.apicalInputWidth,),
       "cellsPerColumn": self.cellsPerColumn,
       "activationThreshold": self.activationThreshold,
       "initialPermanence": self.initialPermanence,
       "connectedPermanence": self.connectedPermanence,
       "minThreshold": self.minThreshold,
       "maxNewSynapseCount": self.maxNewSynapseCount,
       "permanenceIncrement": self.permanenceIncrement,
       "permanenceDecrement": self.permanenceDecrement,
       "predictedSegmentDecrement": self.predictedSegmentDecrement,
       "formInternalBasalConnections": self.formInternalBasalConnections,
       "learnOnOneCell": self.learnOnOneCell,
       "maxSegmentsPerCell": self.maxSegmentsPerCell,
       "maxSynapsesPerSegment": self.maxSynapsesPerSegment,
       "seed": self.seed,
       "checkInputs": self.checkInputs,
     }
     self._tm = createModel(self.implementation, **params)
示例#5
0
 def initialize(self, inputs, outputs):
     """
 Initialize the self._tm if not already initialized. We need to figure out
 the constructor parameters for each class, and send it to that constructor.
 """
     if self._tm is None:
         # Create dict of arguments we will pass to the temporal memory class
         args = copy.deepcopy(self.__dict__)
         args["columnDimensions"] = (self.columnCount, )
         self._tm = createModel(self.temporalImp, **args)
 def initialize(self, inputs, outputs):
   """
   Initialize the self._tm if not already initialized. We need to figure out
   the constructor parameters for each class, and send it to that constructor.
   """
   if self._tm is None:
     # Create dict of arguments we will pass to the temporal memory class
     args = copy.deepcopy(self.__dict__)
     args["columnDimensions"] = (self.columnCount,)
     self._tm = createModel(self.temporalImp, **args)
示例#7
0
  def initialize(self, inputs, outputs):
    """
    Initialize the self._tm if not already initialized. We need to figure out
    the constructor parameters for each class, and send it to that constructor.
    """
    if self._tm is None:
      # Create dict of arguments we will pass to the temporal memory class
      args = copy.deepcopy(self.__dict__)
      args["columnDimensions"] = (self.columnCount,)

      # Create the TM instance
      self._tm = createModel("extended", **args)

      # numpy arrays we will use for some of the outputs
      self.activeState = numpy.zeros(self._tm.numberOfCells())
      self.previouslyPredictedCells = numpy.zeros(self._tm.numberOfCells())
示例#8
0
    def initialize(self):
        """
    Initialize the self._tm if not already initialized. We need to figure out
    the constructor parameters for each class, and send it to that constructor.
    """
        if self._tm is None:
            args = {
                "columnDimensions": (self.columnCount, ),
                "cellsPerColumn": self.cellsPerColumn,
                "activationThreshold": self.activationThreshold,
                "initialPermanence": self.initialPermanence,
                "connectedPermanence": self.connectedPermanence,
                "minThreshold": self.minThreshold,
                "maxNewSynapseCount": self.maxNewSynapseCount,
                "permanenceIncrement": self.permanenceIncrement,
                "permanenceDecrement": self.permanenceDecrement,
                "predictedSegmentDecrement": self.predictedSegmentDecrement,
                "formInternalBasalConnections":
                self.formInternalBasalConnections,
                "learnOnOneCell": self.learnOnOneCell,
                "maxSegmentsPerCell": self.maxSegmentsPerCell,
                "maxSynapsesPerSegment": self.maxSynapsesPerSegment,
                "seed": self.seed,
                "checkInputs": self.checkInputs,
            }

            # Ensure we only pass in those args that are expected by this
            # implementation. This is important for SWIG'ified classes, such as
            # TemporalMemoryCPP, which don't take kwargs.
            expectedArgs = getConstructorArguments(self.temporalImp)[0]
            for arg in args.keys():
                if not arg in expectedArgs:
                    args.pop(arg)

            # Create the TM instance.
            self._tm = createModel(self.implementation, **args)

            # Carry some information to the next time step.
            self.prevPredictiveCells = ()
            self.prevActiveExternalCells = ()
            self.prevActiveApicalCells = ()
示例#9
0
    def initialize(self, inputs, outputs):
        """
    Initialize the self._tm if not already initialized. We need to figure out
    the constructor parameters for each class, and send it to that constructor.
    """
        if self._tm is None:
            args = {
                "columnDimensions": (self.columnCount,),
                "cellsPerColumn": self.cellsPerColumn,
                "activationThreshold": self.activationThreshold,
                "initialPermanence": self.initialPermanence,
                "connectedPermanence": self.connectedPermanence,
                "minThreshold": self.minThreshold,
                "maxNewSynapseCount": self.maxNewSynapseCount,
                "permanenceIncrement": self.permanenceIncrement,
                "permanenceDecrement": self.permanenceDecrement,
                "predictedSegmentDecrement": self.predictedSegmentDecrement,
                "formInternalBasalConnections": self.formInternalBasalConnections,
                "learnOnOneCell": self.learnOnOneCell,
                "maxSegmentsPerCell": self.maxSegmentsPerCell,
                "maxSynapsesPerSegment": self.maxSynapsesPerSegment,
                "seed": self.seed,
                "checkInputs": self.checkInputs,
            }

            # Ensure we only pass in those args that are expected by this
            # implementation. This is important for SWIG'ified classes, such as
            # TemporalMemoryCPP, which don't take kwargs.
            expectedArgs = getConstructorArguments(self.temporalImp)[0]
            for arg in args.keys():
                if not arg in expectedArgs:
                    args.pop(arg)

            # Create the TM instance.
            self._tm = createModel(self.implementation, **args)

            # Carry some information to the next time step.
            self.prevPredictiveCells = ()
            self.prevActiveExternalCells = ()
            self.prevActiveApicalCells = ()
示例#10
0
  def initialize(self, inputs, outputs):
    """
    Initialize the self._tm if not already initialized. We need to figure out
    the constructor parameters for each class, and send it to that constructor.
    """
    if self._tm is None:
      # Create dict of arguments we will pass to the temporal memory class
      args = copy.deepcopy(self.__dict__)
      args["columnDimensions"] = (self.columnCount,)

      # Ensure we only pass in those args that are expected by this
      # implementation. This is important for SWIG'ified classes, such as
      # TemporalMemoryCPP, which don't take kwargs.
      expectedArgs = getConstructorArguments(self.temporalImp)[0]
      for arg in args.keys():
        if not arg in expectedArgs:
          args.pop(arg)

      # Create the TM instance
      self._tm = createModel(self.temporalImp, **args)

      # numpy arrays we will use for some of the outputs
      self.activeState = numpy.zeros(self._tm.numberOfCells())
      self.previouslyPredictedCells = numpy.zeros(self._tm.numberOfCells())
示例#11
0
  def __init__(self,
               inputWidth,
               numActiveColumnsPerInhArea=40,
               synPermProximalInc=0.1,
               synPermProximalDec=0.001,
               initialProximalPermanence=0.6,
               columnDimensions=(2048,),
               activationThreshold=13,
               minThreshold=10,
               initialPermanence=0.41,
               connectedPermanence=0.50,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               maxSegmentsPerCell=255,
               maxSynapsesPerSegment=255,
               seed=42):
    """
    This classes uses an ExtendedTemporalMemory internally to keep track of
    distal segments. Please see ExtendedTemporalMemory for descriptions of
    constructor parameters not defined below.

    Parameters:
    ----------------------------
    @param  inputWidth (int)
            The number of proximal inputs into this layer

    @param  numActiveColumnsPerInhArea (int)
            Target number of active cells

    @param  synPermProximalInc (float)
            Permanence increment for proximal synapses

    @param  synPermProximalDec (float)
            Permanence decrement for proximal synapses

    @param  initialProximalPermanence (float)
            Initial permanence value for proximal segments

    """

    self.inputWidth = inputWidth
    self.numActiveColumnsPerInhArea = numActiveColumnsPerInhArea
    self.synPermProximalInc = synPermProximalInc
    self.synPermProximalDec = synPermProximalDec
    self.initialProximalPermanence = initialProximalPermanence
    self.connectedPermanence = connectedPermanence
    self.maxNewSynapseCount = maxNewSynapseCount
    self.minThreshold = minThreshold
    self.activeCells = set()
    self._random = Random(seed)

    # Create our own instance of extended temporal memory to handle distal
    # segments.
    self.tm = createModel(
                      modelName="extendedCPP",
                      columnDimensions=columnDimensions,
                      cellsPerColumn=1,
                      activationThreshold=activationThreshold,
                      initialPermanence=initialPermanence,
                      connectedPermanence=connectedPermanence,
                      minThreshold=minThreshold,
                      maxNewSynapseCount=maxNewSynapseCount,
                      permanenceIncrement=permanenceIncrement,
                      permanenceDecrement=permanenceDecrement,
                      predictedSegmentDecrement=predictedSegmentDecrement,
                      maxSegmentsPerCell=maxSegmentsPerCell,
                      maxSynapsesPerSegment=maxSynapsesPerSegment,
                      seed=seed,
                      learnOnOneCell=False,
    )

    # These sparse matrices will hold the synapses for each proximal segment.
    #
    # proximalPermanences - SparseMatrix with permanence values
    # proximalConnections - SparseBinaryMatrix of connected synapses

    self.proximalPermanences = SparseMatrix(self.numberOfColumns(),
                                               inputWidth)
    self.proximalConnections = SparseBinaryMatrix(inputWidth)
    self.proximalConnections.resize(self.numberOfColumns(), inputWidth)
示例#12
0
  def __init__(self,
               inputWidth,
               lateralInputWidth,
               numActiveColumnsPerInhArea=40,
               synPermProximalInc=0.1,
               synPermProximalDec=0.001,
               initialProximalPermanence=0.6,
               columnDimensions=(2048,),
               minThresholdProximal=10,
               activationThresholdDistal=13,
               minThresholdDistal=10,
               initialPermanence=0.41,
               connectedPermanence=0.50,
               maxNewProximalSynapseCount=20,
               maxNewDistalSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               maxSegmentsPerCell=255,
               maxSynapsesPerProximalSegment=255,
               maxSynapsesPerDistalSegment=255,
               seed=42):
    """
    This classes uses an ExtendedTemporalMemory internally to keep track of
    distal segments. Please see ExtendedTemporalMemory for descriptions of
    constructor parameters not defined below.

    Parameters:
    ----------------------------
    @param  inputWidth (int)
            The number of proximal inputs into this layer

    @param  lateralInputWidth (int)
            The number of lateral inputs into this layer

    @param  numActiveColumnsPerInhArea (int)
            Target number of active cells

    @param  synPermProximalInc (float)
            Permanence increment for proximal synapses

    @param  synPermProximalDec (float)
            Permanence decrement for proximal synapses

    @param  initialProximalPermanence (float)
            Initial permanence value for proximal segments

    """

    self.inputWidth = inputWidth
    self.lateralInputWidth = lateralInputWidth
    self.numActiveColumnsPerInhArea = numActiveColumnsPerInhArea
    self.synPermProximalInc = synPermProximalInc
    self.synPermProximalDec = synPermProximalDec
    self.initialProximalPermanence = initialProximalPermanence
    self.connectedPermanence = connectedPermanence
    self.maxNewProximalSynapseCount = maxNewProximalSynapseCount
    self.maxNewDistalSynapseCount = maxNewDistalSynapseCount
    self.minThresholdProximal = minThresholdProximal
    self.minThresholdDistal = minThresholdDistal
    self.maxSynapsesPerProximalSegment = maxSynapsesPerProximalSegment
    self.activeCells = set()
    self._random = Random(seed)

    # Create our own instance of extended temporal memory to handle distal
    # segments.
    self.tm = createModel(
                      modelName="etm_cpp",
                      columnDimensions=columnDimensions,
                      basalInputDimensions=(lateralInputWidth,),
                      apicalInputDimensions=(),
                      cellsPerColumn=1,
                      activationThreshold=activationThresholdDistal,
                      initialPermanence=initialPermanence,
                      connectedPermanence=connectedPermanence,
                      minThreshold=minThresholdDistal,
                      maxNewSynapseCount=maxNewDistalSynapseCount,
                      permanenceIncrement=permanenceIncrement,
                      permanenceDecrement=permanenceDecrement,
                      predictedSegmentDecrement=predictedSegmentDecrement,
                      formInternalBasalConnections=False,
                      learnOnOneCell=False,
                      maxSegmentsPerCell=maxSegmentsPerCell,
                      maxSynapsesPerSegment=maxSynapsesPerDistalSegment,
                      seed=seed,
    )

    # These sparse matrices will hold the synapses for each proximal segment.
    #
    # proximalPermanences - SparseMatrix with permanence values
    # proximalConnections - SparseBinaryMatrix of connected synapses

    self.proximalPermanences = SparseMatrix(self.numberOfColumns(),
                                               inputWidth)
    self.proximalConnections = SparseBinaryMatrix(inputWidth)
    self.proximalConnections.resize(self.numberOfColumns(), inputWidth)