def testProximalLearning_SampleSize(self): """ During learning, cells should attempt to have sampleSizeProximal active proximal synapses. """ pooler = ColumnPooler( inputWidth=2048 * 8, initialProximalPermanence=0.60, connectedPermanenceProximal=0.50, sampleSizeProximal=10, synPermProximalDec=0, ) feedforwardInput1 = range(10) pooler.compute(feedforwardInput1, learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 10, "Should connect to every active input bit.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 10, "Each synapse should be marked as connected.") (presynapticCells, permanences) = pooler.proximalPermanences.rowNonZeros(cell) self.assertEqual(set(presynapticCells), set(feedforwardInput1), "Should connect to every active input bit.") for perm in permanences: self.assertAlmostEqual( perm, 0.60, msg="Should use 'initialProximalPermanence'.") pooler.compute(range(10, 20), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 20, "Should connect to every active input bit.") pooler.compute(range(15, 25), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 25, ("Should connect to every active input bit " "that it's not yet connected to.")) pooler.compute(range(0, 30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual( pooler.numberOfProximalSynapses([cell]), 25, "Should not grow more synapses if it had lots active.") pooler.compute(range(23, 30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 30, "Should grow as many as it can.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 30, "Each synapse should be marked as connected.")
def testProximalLearning_SampleSize(self): """ During learning, cells should attempt to have sampleSizeProximal active proximal synapses. """ pooler = ColumnPooler( inputWidth=2048 * 8, initialProximalPermanence=0.60, connectedPermanenceProximal=0.50, sampleSizeProximal=10, synPermProximalDec=0, ) feedforwardInput1 = range(10) pooler.compute(feedforwardInput1, learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 10, "Should connect to every active input bit.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 10, "Each synapse should be marked as connected.") (presynapticCells, permanences) = pooler.proximalPermanences.rowNonZeros(cell) self.assertEqual(set(presynapticCells), set(feedforwardInput1), "Should connect to every active input bit.") for perm in permanences: self.assertAlmostEqual(perm, 0.60, msg="Should use 'initialProximalPermanence'.") pooler.compute(range(10, 20), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 20, "Should connect to every active input bit.") pooler.compute(range(15, 25), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 25, ("Should connect to every active input bit " "that it's not yet connected to.")) pooler.compute(range(0, 30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 25, "Should not grow more synapses if it had lots active.") pooler.compute(range(23, 30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 30, "Should grow as many as it can.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 30, "Each synapse should be marked as connected.")
def testProximalLearning_NoSampling(self): """ With sampleSize -1, during learning each cell should connect to every active bit. """ pooler = ColumnPooler( inputWidth=2048 * 8, initialProximalPermanence=0.60, connectedPermanenceProximal=0.50, sampleSizeProximal=-1, synPermProximalDec=0, ) feedforwardInput1 = range(10) pooler.compute(feedforwardInput1, learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 10, "Should connect to every active input bit.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 10, "Each synapse should be marked as connected.") (presynapticCells, permanences) = pooler.proximalPermanences.rowNonZeros(cell) self.assertEqual(set(presynapticCells), set(feedforwardInput1), "Should connect to every active input bit.") for perm in permanences: self.assertAlmostEqual( perm, 0.60, msg="Should use 'initialProximalPermanence'.") pooler.compute(range(30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual( pooler.numberOfProximalSynapses([cell]), 30, "Should grow synapses to every unsynapsed active bit.") pooler.compute(range(25, 30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual( pooler.numberOfProximalSynapses([cell]), 30, "Every bit is synapsed so nothing else should grow.") pooler.compute(range(125, 130), learn=True) for cell in pooler.getActiveCells(): self.assertEqual( pooler.numberOfProximalSynapses([cell]), 35, "Should grow synapses to every unsynapsed active bit.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 35, "Each synapse should be marked as connected.")
def testProximalLearning_NoSampling(self): """ With sampleSize -1, during learning each cell should connect to every active bit. """ pooler = ColumnPooler( inputWidth=2048 * 8, initialProximalPermanence=0.60, connectedPermanenceProximal=0.50, sampleSizeProximal=-1, synPermProximalDec=0, ) feedforwardInput1 = range(10) pooler.compute(feedforwardInput1, learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 10, "Should connect to every active input bit.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 10, "Each synapse should be marked as connected.") (presynapticCells, permanences) = pooler.proximalPermanences.rowNonZeros(cell) self.assertEqual(set(presynapticCells), set(feedforwardInput1), "Should connect to every active input bit.") for perm in permanences: self.assertAlmostEqual(perm, 0.60, msg="Should use 'initialProximalPermanence'.") pooler.compute(range(30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 30, "Should grow synapses to every unsynapsed active bit.") pooler.compute(range(25, 30), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 30, "Every bit is synapsed so nothing else should grow.") pooler.compute(range(125, 130), learn=True) for cell in pooler.getActiveCells(): self.assertEqual(pooler.numberOfProximalSynapses([cell]), 35, "Should grow synapses to every unsynapsed active bit.") self.assertEqual(pooler.numberOfConnectedProximalSynapses([cell]), 35, "Each synapse should be marked as connected.")