示例#1
0
    def test_adjustInactiveSynapses(self):
        for (name, cells, inputs, adjustedSegments, activeInputs,
             initialPermanence, delta, connectedPermanence,
             expected) in (("Basic test", [1, 2, 3], [42, 43, 44], [0, 2],
                            [42, 44], 0.45, 0.1, 0.5, [1, 0, 1]),
                           ("Negative increment", [1, 2, 3], [42, 43, 44],
                            [0, 2], [42, 44], 0.55, -0.1, 0.5, [2, 3, 2]),
                           ("No segments", [1, 2,
                                            3], [42, 43,
                                                 44], [], [42,
                                                           44], 0.45, 0.1, 0.5,
                            [0,
                             0, 0]), ("No active synapses", [1, 2,
                                                             3], [42, 43, 44],
                                      [0, 2], [], 0.45, 0.1, 0.5, [3, 0, 3]),
                           ("Delta of zero", [1, 2, 3], [42, 43, 44], [0, 2],
                            [42, 44], 0.55, 0.0, 0.5, [3, 3, 3])):

            connections = SparseMatrixConnections(2048, 2048)

            segments = connections.createSegments(cells)

            connections.growSynapses(segments, inputs, initialPermanence)
            connections.adjustInactiveSynapses(segments[adjustedSegments],
                                               activeInputs, delta)

            overlaps = connections.computeActivity(inputs, connectedPermanence)

            np.testing.assert_equal(overlaps[segments], expected, name)
示例#2
0
  def test_adjustInactiveSynapses(self):
    for (name, cells, inputs,
         adjustedSegments, activeInputs,
         initialPermanence, delta, connectedPermanence,
         expected) in (("Basic test",
                        [1, 2, 3], [42, 43, 44],
                        [0, 2], [42, 44],
                        0.45, 0.1, 0.5,
                        [1, 0, 1]),
                       ("Negative increment",
                        [1, 2, 3], [42, 43, 44],
                        [0, 2], [42, 44],
                        0.55, -0.1, 0.5,
                        [2, 3, 2]),
                       ("No segments",
                        [1, 2, 3], [42, 43, 44],
                        [], [42, 44],
                        0.45, 0.1, 0.5,
                        [0, 0, 0]),
                       ("No active synapses",
                        [1, 2, 3], [42, 43, 44],
                        [0, 2], [],
                        0.45, 0.1, 0.5,
                        [3, 0, 3]),
                       ("Delta of zero",
                        [1, 2, 3], [42, 43, 44],
                        [0, 2], [42, 44],
                        0.55, 0.0, 0.5,
                        [3, 3, 3])
         ):

      connections = SparseMatrixConnections(2048, 2048)

      segments = connections.createSegments(cells)

      connections.growSynapses(segments, inputs, initialPermanence)
      connections.adjustInactiveSynapses(segments[adjustedSegments],
                                         activeInputs, delta)

      overlaps = connections.computeActivity(inputs, connectedPermanence)

      np.testing.assert_equal(overlaps[segments], expected, name)
示例#3
0
    def test_whenPermanenceFallsBelowZero(self):
        connections = SparseMatrixConnections(2048, 2048)

        segments = connections.createSegments([1, 2, 3])

        connections.growSynapses(segments, [42, 43], 0.05)
        connections.adjustSynapses(segments, [42, 43], -0.06, 0.0)
        np.testing.assert_equal(
            connections.mapSegmentsToSynapseCounts(segments), [0, 0, 0])

        connections.growSynapses(segments, [42, 43], 0.05)
        connections.adjustSynapses(segments, [], 0.0, -0.06)
        np.testing.assert_equal(
            connections.mapSegmentsToSynapseCounts(segments), [0, 0, 0])

        connections.growSynapses(segments, [42, 43], 0.05)
        connections.adjustActiveSynapses(segments, [42, 43], -0.06)
        np.testing.assert_equal(
            connections.mapSegmentsToSynapseCounts(segments), [0, 0, 0])

        connections.growSynapses(segments, [42, 43], 0.05)
        connections.adjustInactiveSynapses(segments, [], -0.06)
        np.testing.assert_equal(
            connections.mapSegmentsToSynapseCounts(segments), [0, 0, 0])
示例#4
0
  def test_whenPermanenceFallsBelowZero(self):
    connections = SparseMatrixConnections(2048, 2048)

    segments = connections.createSegments([1, 2, 3])

    connections.growSynapses(segments, [42, 43], 0.05)
    connections.adjustSynapses(segments, [42, 43], -0.06, 0.0)
    np.testing.assert_equal(connections.mapSegmentsToSynapseCounts(segments),
                            [0, 0, 0])

    connections.growSynapses(segments, [42, 43], 0.05)
    connections.adjustSynapses(segments, [], 0.0, -0.06)
    np.testing.assert_equal(connections.mapSegmentsToSynapseCounts(segments),
                            [0, 0, 0])

    connections.growSynapses(segments, [42, 43], 0.05)
    connections.adjustActiveSynapses(segments, [42, 43], -0.06)
    np.testing.assert_equal(connections.mapSegmentsToSynapseCounts(segments),
                            [0, 0, 0])

    connections.growSynapses(segments, [42, 43], 0.05)
    connections.adjustInactiveSynapses(segments, [], -0.06)
    np.testing.assert_equal(connections.mapSegmentsToSynapseCounts(segments),
                            [0, 0, 0])
示例#5
0
    def test_clipPermanences(self):
        connections = SparseMatrixConnections(2048, 2048)

        # Destroy synapses with permanences <= 0.0
        segments = connections.createSegments([1, 2, 3])
        connections.growSynapses(segments, [42, 43, 44], 0.05)
        connections.growSynapses(segments, [45, 46], 0.1)
        connections.adjustInactiveSynapses(segments, [], -0.1)
        connections.clipPermanences(segments)
        np.testing.assert_equal(
            connections.mapSegmentsToSynapseCounts(segments), [0, 0, 0])

        # Clip permanences to 1.0
        connections.growSynapses(segments, [42, 43, 44], 0.95)
        connections.adjustInactiveSynapses(segments, [], 0.50)
        connections.clipPermanences(segments)
        np.testing.assert_equal(
            connections.mapSegmentsToSynapseCounts(segments), [3, 3, 3])
        connections.adjustInactiveSynapses(segments, [], -0.5)
        overlaps1 = connections.computeActivity([42, 43, 44], 0.49)
        overlaps2 = connections.computeActivity([42, 43, 44], 0.51)
        np.testing.assert_equal(overlaps1, [3, 3, 3])
        np.testing.assert_equal(overlaps2, [0, 0, 0])
示例#6
0
  def test_clipPermanences(self):
    connections = SparseMatrixConnections(2048, 2048)

    # Destroy synapses with permanences <= 0.0
    segments = connections.createSegments([1, 2, 3])
    connections.growSynapses(segments, [42, 43, 44], 0.05)
    connections.growSynapses(segments, [45, 46], 0.1)
    connections.adjustInactiveSynapses(segments, [], -0.1)
    connections.clipPermanences(segments)
    np.testing.assert_equal(connections.mapSegmentsToSynapseCounts(segments),
                            [0, 0, 0])

    # Clip permanences to 1.0
    connections.growSynapses(segments, [42, 43, 44], 0.95)
    connections.adjustInactiveSynapses(segments, [], 0.50)
    connections.clipPermanences(segments)
    np.testing.assert_equal(connections.mapSegmentsToSynapseCounts(segments),
                            [3, 3, 3])
    connections.adjustInactiveSynapses(segments, [], -0.5)
    overlaps1 = connections.computeActivity([42, 43, 44], 0.49)
    overlaps2 = connections.computeActivity([42, 43, 44], 0.51)
    np.testing.assert_equal(overlaps1, [3, 3, 3])
    np.testing.assert_equal(overlaps2, [0, 0, 0])