Beispiel #1
0
  def testRaisePermanenceThreshold(self):
    sp = SpatialPooler(inputDimensions=[5],
                       columnDimensions=[5],
                       synPermConnected=0.1,
                       stimulusThreshold=3)
    sp._synPermBelowStimulusInc = 0.01
    sp._permanences = SparseMatrix(
        [[0.0, 0.11, 0.095, 0.092, 0.01],
         [0.12, 0.15, 0.02, 0.12, 0.09],
         [0.51, 0.081, 0.025, 0.089, 0.31],
         [0.18, 0.0601, 0.11, 0.011, 0.03],
         [0.011, 0.011, 0.011, 0.011, 0.011]])

    sp._connectedSynapses = SparseBinaryMatrix(
        [[0, 1, 0, 0, 0],
         [1, 1, 0, 1, 0],
         [1, 0, 0, 0, 1],
         [1, 0, 1, 0, 0],
         [0, 0, 0, 0, 0]])

    sp._connectedCounts = numpy.array([1, 3, 2, 2, 0])

    truePermanences = [
        [0.0, 0.12, 0.105, 0.102, 0.0],  # incremented once
        [0.12, 0.15, 0.02, 0.12, 0.09],  # no change
        [0.53, 0.101, 0.0, 0.109, 0.33],  # increment twice
        [0.22, 0.1001, 0.15, 0.051, 0.07],  # increment four times
        [0.101, 0.101, 0.101, 0.101, 0.101]]  #increment 9 times

    trueConnectedSynapses = [
        [0, 1, 1, 1, 0],
        [1, 1, 0, 1, 0],
        [1, 1, 0, 1, 1],
        [1, 1, 1, 0, 0],
        [1, 1, 1, 1, 1]]

    trueConnectedCounts = [3, 3, 4, 3, 5]
    sp._raisePermanenceToThreshold()
    for i in xrange(sp._numColumns):
      perm = list(sp._permanences.getRow(i))
      for j in xrange(sp._numInputs):
        self.assertAlmostEqual(truePermanences[i][j],perm[j])
      self.assertListEqual(
        trueConnectedSynapses[i],
        list(sp._connectedSynapses.getRow(i))
      )
      self.assertEqual(trueConnectedCounts[i], sp._connectedCounts[i])
Beispiel #2
0
  def testBumpUpWeakColumns(self):
    sp = SpatialPooler(inputDimensions=[8],
                      columnDimensions=[5])

    sp._synPermBelowStimulusInc = 0.01
    sp._synPermTrimThreshold = 0.05
    sp._overlapDutyCycles = numpy.array([0, 0.009, 0.1, 0.001, 0.002])
    sp._minOverlapDutyCycles = numpy.array(5*[0.01])

    sp._potentialPools = SparseBinaryMatrix(
       [[1, 1, 1, 1, 0, 0, 0, 0],
        [1, 0, 0, 0, 1, 1, 0, 1],
        [0, 0, 1, 0, 1, 1, 1, 0],
        [1, 1, 1, 0, 0, 0, 1, 0],
        [1, 1, 1, 1, 1, 1, 1, 1]])

    sp._permanences = SparseMatrix(
      [[0.200, 0.120, 0.090, 0.040, 0.000, 0.000, 0.000, 0.000],
       [0.150, 0.000, 0.000, 0.000, 0.180, 0.120, 0.000, 0.450],
       [0.000, 0.000, 0.014, 0.000, 0.032, 0.044, 0.110, 0.000],
       [0.041, 0.000, 0.000, 0.000, 0.000, 0.000, 0.178, 0.000],
       [0.100, 0.738, 0.045, 0.002, 0.050, 0.008, 0.208, 0.034]])

    truePermanences = [
      [0.210, 0.130, 0.100, 0.000, 0.000, 0.000, 0.000, 0.000],
  #    Inc    Inc    Inc    Trim    -     -     -    -
      [0.160, 0.000, 0.000, 0.000, 0.190, 0.130, 0.000, 0.460],
  #    Inc   -     -    -     Inc   Inc    -     Inc
      [0.000, 0.000, 0.014, 0.000, 0.032, 0.044, 0.110, 0.000], #unchanged
  #    -    -     -    -     -    -     -    -
      [0.051, 0.000, 0.000, 0.000, 0.000, 0.000, 0.188, 0.000],
  #    Inc   Trim    Trim    -     -    -    Inc     -
      [0.110, 0.748, 0.055, 0.000, 0.060, 0.000, 0.218, 0.000]]

    sp._bumpUpWeakColumns()
    for i in xrange(sp._numColumns):
      perm = list(sp._permanences.getRow(i))
      for j in xrange(sp._numInputs):
        self.assertAlmostEqual(truePermanences[i][j], perm[j])