def testRandomSPDoesNotLearn(self):
   
   sp = FlatSpatialPooler(inputShape=5,
                          coincidencesShape=10,
                          randomSP=True)
   inputArray = (numpy.random.rand(5) > 0.5).astype(uintType)
   activeArray = numpy.zeros(sp._numColumns).astype(realType)
   # Should start off at 0
   self.assertEqual(sp._iterationNum, 0)
   self.assertEqual(sp._iterationLearnNum, 0)
   
   # Store the initialized state
   initialPerms = copy(sp._permanences)
   
   sp.compute(inputArray, False, activeArray)
   # Should have incremented general counter but not learning counter
   self.assertEqual(sp._iterationNum, 1)
   self.assertEqual(sp._iterationLearnNum, 0)
   
   # Should not learn even if learning set to True
   sp.compute(inputArray, True, activeArray)
   self.assertEqual(sp._iterationNum, 2)
   self.assertEqual(sp._iterationLearnNum, 0)
   
   # Check the initial perm state was not modified either
   self.assertEqual(sp._permanences, initialPerms)
Esempio n. 2
0
 def setUp(self):
     self._sp = FlatSpatialPooler(
         numInputs=5,
         numColumns=5,
         localAreaDensity=0.1,
         numActiveColumnsPerInhArea=-1,
         stimulusThreshold=1,
         minDistance=0.0,
         seed=-1,
         spVerbosity=0,
     )
Esempio n. 3
0
 def testRandomSPDoesNotLearn(self):
   
   sp = FlatSpatialPooler(inputShape=5,
                          coincidencesShape=10,
                          randomSP=True)
   inputArray = (numpy.random.rand(5) > 0.5).astype(uintType)
   activeArray = numpy.zeros(sp._numColumns).astype(realType)
   # Should start off at 0
   self.assertEqual(sp._iterationNum, 0)
   self.assertEqual(sp._iterationLearnNum, 0)
   
   # Store the initialized state
   initialPerms = copy(sp._permanences)
   
   sp.compute(inputArray, False, activeArray)
   # Should have incremented general counter but not learning counter
   self.assertEqual(sp._iterationNum, 1)
   self.assertEqual(sp._iterationLearnNum, 0)
   
   # Should not learn even if learning set to True
   sp.compute(inputArray, True, activeArray)
   self.assertEqual(sp._iterationNum, 2)
   self.assertEqual(sp._iterationLearnNum, 0)
   
   # Check the initial perm state was not modified either
   self.assertEqual(sp._permanences, initialPerms)
Esempio n. 4
0
 def setUp(self):
   self._sp = FlatSpatialPooler(
       inputShape=(5,1),
       coincidencesShape=(10,1))
  def testActiveColumnsEqualNumActive(self):
    '''
    After feeding in a record the number of active columns should
    always be equal to numActivePerInhArea
    '''

    for i in [1, 10, 50]:
      numActive = i
      inputShape = 10
      sp = FlatSpatialPooler(inputShape=inputShape,
                             coincidencesShape=100,
                             numActivePerInhArea=numActive)
      inputArray = (numpy.random.rand(inputShape) > 0.5).astype(uintType)
      inputArray2 = (numpy.random.rand(inputShape) > 0.8).astype(uintType)
      activeArray = numpy.zeros(sp._numColumns).astype(realType)
  
      # Random SP
      sp._randomSP = True
      sp.compute(inputArray, False, activeArray)
      sp.compute(inputArray2, False, activeArray)
      self.assertEqual(sum(activeArray), numActive)
      
      # Default, learning on
      sp._randomSP = False
      sp.compute(inputArray, True, activeArray)
      sp.compute(inputArray2, True, activeArray)
      self.assertEqual(sum(activeArray), numActive)
Esempio n. 6
0
  def testActiveColumnsEqualNumActive(self):
    '''
    After feeding in a record the number of active columns should
    always be equal to numActivePerInhArea
    '''

    for i in [1, 10, 50]:
      numActive = i
      inputShape = 10
      sp = FlatSpatialPooler(inputShape=inputShape,
                             coincidencesShape=100,
                             numActivePerInhArea=numActive)
      inputArray = (numpy.random.rand(inputShape) > 0.5).astype(uintType)
      inputArray2 = (numpy.random.rand(inputShape) > 0.8).astype(uintType)
      activeArray = numpy.zeros(sp._numColumns).astype(realType)
  
      # Random SP
      sp._randomSP = True
      sp.compute(inputArray, False, activeArray)
      sp.compute(inputArray2, False, activeArray)
      self.assertEqual(sum(activeArray), numActive)
      
      # Default, learning on
      sp._randomSP = False
      sp.compute(inputArray, True, activeArray)
      sp.compute(inputArray2, True, activeArray)
      self.assertEqual(sum(activeArray), numActive)