``````

In [2]:

from sympy import *
init_printing()
from IPython.display import display

%matplotlib inline

import matplotlib.pyplot as plt

``````

# Equation for Neuron Paper

``  A dendritic segment can robustly classify a pattern by subsampling a small number of cells from a larger population.  Assuming a random distribution of patterns, the exact probability of a false match is given by the following equation:``
``````

In [3]:

oxp = Symbol("Omega_x'")
b = Symbol("b")
n = Symbol("n")
theta = Symbol("theta")
s = Symbol("s")
a = Symbol("a")

subsampledOmega = (binomial(s, b) * binomial(n - s, a - b)) / binomial(n, a)
subsampledFpF = Sum(subsampledOmega, (b, theta, s))
subsampledOmegaSlow = (binomial(s, b) * binomial(n - s, a - b))
subsampledFpFSlow = Sum(subsampledOmegaSlow, (b, theta, s))/ binomial(n, a)

display(subsampledFpF)
display(subsampledFpFSlow)

``````
``````

Sum(binomial(s, b)*binomial(n - s, a - b)/binomial(n, a), (b, theta, s))

Sum(binomial(s, b)*binomial(n - s, a - b), (b, theta, s))/binomial(n, a)

``````

where n refers to the size of the population of cells, a is the number of active cells at any instance in time, s is the number of actual synapses on a dendritic segment, and θ is the threshold for NMDA spikes. Following (Ahmad & Hawkins, 2015), the numerator counts the number of possible ways θ or more cells can match a fixed set of s synapses. The denominator counts the number of ways a cells out of n can be active.

## Example usage

``````

In [4]:

display("n=10000, a=64, s=24, theta=12", subsampledFpF.subs(s,24).subs(n, 10000).subs(a, 64).subs(theta, 12).evalf())

``````
``````

'n=10000, a=64, s=24, theta=12'

0

``````
``````

In [5]:

display("n=10000, a=300, s=24, theta=12", subsampledFpFSlow.subs(theta, 12).subs(s, 24).subs(n, 10000).subs(a, 300).evalf())

``````
``````

'n=10000, a=300, s=24, theta=12'

8.37584522709849e-13

``````
``````

In [6]:

display("n=2048, a=400, s=40, theta=20", subsampledFpF.subs(theta, 15).subs(s, 30).subs(n, 10000).subs(a, 300).evalf())

``````
``````

'n=2048, a=400, s=40, theta=20'

1.04849765783378e-15

``````

## Table 1B

``````

In [7]:

T1B = subsampledFpFSlow.subs(n, 100000).subs(a, 2000).subs(theta,s).evalf()
print "n=100000, a=2000, theta=s"
display("s=6",T1B.subs(s,6).evalf())
display("s=8",T1B.subs(s,8).evalf())
display("s=10",T1B.subs(s,10).evalf())

``````
``````

n=100000, a=2000, theta=s

's=6'

6.35308872941916e-11

's=8'

2.52507239284961e-14

's=10'

1.00163216178113e-17

``````

## Table 1C

``````

In [8]:

T1C = subsampledFpFSlow.subs(n, 100000).subs(a, 2000).subs(s,2*theta).evalf()
print "n=10000, a=300, s=2*theta"
display("theta=6",T1C.subs(theta,6).evalf())
display("theta=8",T1C.subs(theta,8).evalf())
display("theta=10",T1C.subs(theta,10).evalf())
display("theta=12",T1C.subs(theta,12).evalf())

``````
``````

n=10000, a=300, s=2*theta

'theta=6'

5.29386836275369e-8

'theta=8'

2.81724528327272e-10

'theta=10'

1.54192767258720e-12

'theta=12'

8.58694100276592e-15

``````

## Table 1D

``````

In [9]:

m = Symbol("m")
T1D = subsampledFpF.subs(n, 100000).subs(a, 2000).subs(s,2*m*theta).evalf()
print "n=100000, a=2000, s=2*m*theta"
display("theta=10, m=2",T1D.subs(theta,10).subs(m,2).evalf())
display("theta=10, m=4",T1D.subs(theta,10).subs(m,4).evalf())
display("theta=10, m=6",T1D.subs(theta,10).subs(m,6).evalf())
display("theta=20, m=6",T1D.subs(theta,20).subs(m,6).evalf())

``````
``````

n=100000, a=2000, s=2*m*theta

'theta=10, m=2'

4.91541864813209e-9

'theta=10, m=4'

4.62568448037595e-6

'theta=10, m=6'

0.000158799793094937

'theta=20, m=6'

1.07990763941591e-7

``````

# Charts for SDR Paper

``````  The following sections calculates the numbers for some of the SDR paper charts.

``````

## Importance of large n

``````

In [10]:

eq1 = subsampledFpFSlow.subs(s, 24).subs(theta, 12)
print "a=128 cells active, s=16 synapses on segment, dendritic threshold is theta=8\n"
errorList = []
nList = []
for n0 in range(300,20100,200):
error = eq1.subs(n, n0).subs(a,n0/2).evalf()
errorList += [error]
nList += [n0]
print "population n = %5d, sparsity = %5.2f%%, probability of false match = "%(n0, 100.0*32.0/n0), error

print errorList
print nList

``````
``````

a=128 cells active, s=16 synapses on segment, dendritic threshold is theta=8

population n =   300, sparsity = 10.67%, probability of false match =  0.584014929308308
population n =   500, sparsity =  6.40%, probability of false match =  0.582594747080399
population n =   700, sparsity =  4.57%, probability of false match =  0.582007206016863
population n =   900, sparsity =  3.56%, probability of false match =  0.581686021979051
population n =  1100, sparsity =  2.91%, probability of false match =  0.581483533877904
population n =  1300, sparsity =  2.46%, probability of false match =  0.581344204898149
population n =  1500, sparsity =  2.13%, probability of false match =  0.581242471033283
population n =  1700, sparsity =  1.88%, probability of false match =  0.581164924569868
population n =  1900, sparsity =  1.68%, probability of false match =  0.581103856001899
population n =  2100, sparsity =  1.52%, probability of false match =  0.581054517612207
population n =  2300, sparsity =  1.39%, probability of false match =  0.581013825794851
population n =  2500, sparsity =  1.28%, probability of false match =  0.580979690688467
population n =  2700, sparsity =  1.19%, probability of false match =  0.580950645707841
population n =  2900, sparsity =  1.10%, probability of false match =  0.580925631309445
population n =  3100, sparsity =  1.03%, probability of false match =  0.580903862938630
population n =  3300, sparsity =  0.97%, probability of false match =  0.580884747253428
population n =  3500, sparsity =  0.91%, probability of false match =  0.580867827216677
population n =  3700, sparsity =  0.86%, probability of false match =  0.580852745081144
population n =  3900, sparsity =  0.82%, probability of false match =  0.580839216815388
population n =  4100, sparsity =  0.78%, probability of false match =  0.580827014046966
population n =  4300, sparsity =  0.74%, probability of false match =  0.580815951065415
population n =  4500, sparsity =  0.71%, probability of false match =  0.580805875304680
population n =  4700, sparsity =  0.68%, probability of false match =  0.580796660264685
population n =  4900, sparsity =  0.65%, probability of false match =  0.580788200172619
population n =  5100, sparsity =  0.63%, probability of false match =  0.580780405904740
population n =  5300, sparsity =  0.60%, probability of false match =  0.580773201834607
population n =  5500, sparsity =  0.58%, probability of false match =  0.580766523371170
population n =  5700, sparsity =  0.56%, probability of false match =  0.580760315016762
population n =  5900, sparsity =  0.54%, probability of false match =  0.580754528821252
population n =  6100, sparsity =  0.52%, probability of false match =  0.580749123141178
population n =  6300, sparsity =  0.51%, probability of false match =  0.580744061635889
population n =  6500, sparsity =  0.49%, probability of false match =  0.580739312449527
population n =  6700, sparsity =  0.48%, probability of false match =  0.580734847539893
population n =  6900, sparsity =  0.46%, probability of false match =  0.580730642124341
population n =  7100, sparsity =  0.45%, probability of false match =  0.580726674219543
population n =  7300, sparsity =  0.44%, probability of false match =  0.580722924257102
population n =  7500, sparsity =  0.43%, probability of false match =  0.580719374760806
population n =  7700, sparsity =  0.42%, probability of false match =  0.580716010074293
population n =  7900, sparsity =  0.41%, probability of false match =  0.580712816130183
population n =  8100, sparsity =  0.40%, probability of false match =  0.580709780253477
population n =  8300, sparsity =  0.39%, probability of false match =  0.580706890993447
population n =  8500, sparsity =  0.38%, probability of false match =  0.580704137979309
population n =  8700, sparsity =  0.37%, probability of false match =  0.580701511795837
population n =  8900, sparsity =  0.36%, probability of false match =  0.580699003875787
population n =  9100, sparsity =  0.35%, probability of false match =  0.580696606406533
population n =  9300, sparsity =  0.34%, probability of false match =  0.580694312248771
population n =  9500, sparsity =  0.34%, probability of false match =  0.580692114865511
population n =  9700, sparsity =  0.33%, probability of false match =  0.580690008259874
population n =  9900, sparsity =  0.32%, probability of false match =  0.580687986920434
population n = 10100, sparsity =  0.32%, probability of false match =  0.580686045773074
population n = 10300, sparsity =  0.31%, probability of false match =  0.580684180138454
population n = 10500, sparsity =  0.30%, probability of false match =  0.580682385694351
population n = 10700, sparsity =  0.30%, probability of false match =  0.580680658442227
population n = 10900, sparsity =  0.29%, probability of false match =  0.580678994677491
population n = 11100, sparsity =  0.29%, probability of false match =  0.580677390962967
population n = 11300, sparsity =  0.28%, probability of false match =  0.580675844105201
population n = 11500, sparsity =  0.28%, probability of false match =  0.580674351133227
population n = 11700, sparsity =  0.27%, probability of false match =  0.580672909279530
population n = 11900, sparsity =  0.27%, probability of false match =  0.580671515962919
population n = 12100, sparsity =  0.26%, probability of false match =  0.580670168773108
population n = 12300, sparsity =  0.26%, probability of false match =  0.580668865456801
population n = 12500, sparsity =  0.26%, probability of false match =  0.580667603905115
population n = 12700, sparsity =  0.25%, probability of false match =  0.580666382142195
population n = 12900, sparsity =  0.25%, probability of false match =  0.580665198314884
population n = 13100, sparsity =  0.24%, probability of false match =  0.580664050683348
population n = 13300, sparsity =  0.24%, probability of false match =  0.580662937612542
population n = 13500, sparsity =  0.24%, probability of false match =  0.580661857564439
population n = 13700, sparsity =  0.23%, probability of false match =  0.580660809090938
population n = 13900, sparsity =  0.23%, probability of false match =  0.580659790827387
population n = 14100, sparsity =  0.23%, probability of false match =  0.580658801486658
population n = 14300, sparsity =  0.22%, probability of false match =  0.580657839853719
population n = 14500, sparsity =  0.22%, probability of false match =  0.580656904780654
population n = 14700, sparsity =  0.22%, probability of false match =  0.580655995182094
population n = 14900, sparsity =  0.21%, probability of false match =  0.580655110031012
population n = 15100, sparsity =  0.21%, probability of false match =  0.580654248354858
population n = 15300, sparsity =  0.21%, probability of false match =  0.580653409231992
population n = 15500, sparsity =  0.21%, probability of false match =  0.580652591788397
population n = 15700, sparsity =  0.20%, probability of false match =  0.580651795194639
population n = 15900, sparsity =  0.20%, probability of false match =  0.580651018663065
population n = 16100, sparsity =  0.20%, probability of false match =  0.580650261445202
population n = 16300, sparsity =  0.20%, probability of false match =  0.580649522829352
population n = 16500, sparsity =  0.19%, probability of false match =  0.580648802138360
population n = 16700, sparsity =  0.19%, probability of false match =  0.580648098727541
population n = 16900, sparsity =  0.19%, probability of false match =  0.580647411982763
population n = 17100, sparsity =  0.19%, probability of false match =  0.580646741318654
population n = 17300, sparsity =  0.18%, probability of false match =  0.580646086176936
population n = 17500, sparsity =  0.18%, probability of false match =  0.580645446024882
population n = 17700, sparsity =  0.18%, probability of false match =  0.580644820353863
population n = 17900, sparsity =  0.18%, probability of false match =  0.580644208678006
population n = 18100, sparsity =  0.18%, probability of false match =  0.580643610532935
population n = 18300, sparsity =  0.17%, probability of false match =  0.580643025474591
population n = 18500, sparsity =  0.17%, probability of false match =  0.580642453078140
population n = 18700, sparsity =  0.17%, probability of false match =  0.580641892936935
population n = 18900, sparsity =  0.17%, probability of false match =  0.580641344661561
population n = 19100, sparsity =  0.17%, probability of false match =  0.580640807878927
population n = 19300, sparsity =  0.17%, probability of false match =  0.580640282231422
population n = 19500, sparsity =  0.16%, probability of false match =  0.580639767376118
population n = 19700, sparsity =  0.16%, probability of false match =  0.580639262984026
population n = 19900, sparsity =  0.16%, probability of false match =  0.580638768739396
[0.584014929308308, 0.582594747080399, 0.582007206016863, 0.581686021979051, 0.581483533877904, 0.581344204898149, 0.581242471033283, 0.581164924569868, 0.581103856001899, 0.581054517612207, 0.581013825794851, 0.580979690688467, 0.580950645707841, 0.580925631309445, 0.580903862938630, 0.580884747253428, 0.580867827216677, 0.580852745081144, 0.580839216815388, 0.580827014046966, 0.580815951065415, 0.580805875304680, 0.580796660264685, 0.580788200172619, 0.580780405904740, 0.580773201834607, 0.580766523371170, 0.580760315016762, 0.580754528821252, 0.580749123141178, 0.580744061635889, 0.580739312449527, 0.580734847539893, 0.580730642124341, 0.580726674219543, 0.580722924257102, 0.580719374760806, 0.580716010074293, 0.580712816130183, 0.580709780253477, 0.580706890993447, 0.580704137979309, 0.580701511795837, 0.580699003875787, 0.580696606406533, 0.580694312248771, 0.580692114865511, 0.580690008259874, 0.580687986920434, 0.580686045773074, 0.580684180138454, 0.580682385694351, 0.580680658442227, 0.580678994677491, 0.580677390962967, 0.580675844105201, 0.580674351133227, 0.580672909279530, 0.580671515962919, 0.580670168773108, 0.580668865456801, 0.580667603905115, 0.580666382142195, 0.580665198314884, 0.580664050683348, 0.580662937612542, 0.580661857564439, 0.580660809090938, 0.580659790827387, 0.580658801486658, 0.580657839853719, 0.580656904780654, 0.580655995182094, 0.580655110031012, 0.580654248354858, 0.580653409231992, 0.580652591788397, 0.580651795194639, 0.580651018663065, 0.580650261445202, 0.580649522829352, 0.580648802138360, 0.580648098727541, 0.580647411982763, 0.580646741318654, 0.580646086176936, 0.580645446024882, 0.580644820353863, 0.580644208678006, 0.580643610532935, 0.580643025474591, 0.580642453078140, 0.580641892936935, 0.580641344661561, 0.580640807878927, 0.580640282231422, 0.580639767376118, 0.580639262984026, 0.580638768739396]
[300, 500, 700, 900, 1100, 1300, 1500, 1700, 1900, 2100, 2300, 2500, 2700, 2900, 3100, 3300, 3500, 3700, 3900, 4100, 4300, 4500, 4700, 4900, 5100, 5300, 5500, 5700, 5900, 6100, 6300, 6500, 6700, 6900, 7100, 7300, 7500, 7700, 7900, 8100, 8300, 8500, 8700, 8900, 9100, 9300, 9500, 9700, 9900, 10100, 10300, 10500, 10700, 10900, 11100, 11300, 11500, 11700, 11900, 12100, 12300, 12500, 12700, 12900, 13100, 13300, 13500, 13700, 13900, 14100, 14300, 14500, 14700, 14900, 15100, 15300, 15500, 15700, 15900, 16100, 16300, 16500, 16700, 16900, 17100, 17300, 17500, 17700, 17900, 18100, 18300, 18500, 18700, 18900, 19100, 19300, 19500, 19700, 19900]

``````

## Small sparsity is insufficient

``````

In [11]:

print ("2% sparsity with n=400")
print subsampledFpFSlow.subs(s, 4).subs(a, 8).subs(theta, 2).subs(n,400).evalf()
print ("2% sparsity with n=4000")
print subsampledFpFSlow.subs(s, 4).subs(a, 400).subs(theta, 2).subs(n,4000).evalf()

``````
``````

2% sparsity with n=400
0.00206314616966578
2% sparsity with n=4000
0.0522148720308419

``````

## A small subsample can be very reliable (but not too small)

``````

In [12]:

eq2 = subsampledFpFSlow.subs(n, 10000).subs(a, 300)
print "a=200 cells active out of population of n=10000 cells\n"
errorList = []
sList = []
for s0 in range(2,31,1):
print "synapses s = %3d, theta = s/2 = %3d, probability of false match = "%(s0,s0/2), eq2.subs(s, s0).subs(theta,s0/2).evalf()
errorList += [eq2.subs(s, s0).subs(theta,s0/2).evalf()]
sList += [s0]

print errorList
print sList

``````
``````

a=200 cells active out of population of n=10000 cells

synapses s =   2, theta = s/2 =   1, probability of false match =  0.0591029102910291
synapses s =   3, theta = s/2 =   1, probability of false match =  0.0873354694941389
synapses s =   4, theta = s/2 =   2, probability of false match =  0.00517101241148655
synapses s =   5, theta = s/2 =   2, probability of false match =  0.00844794620736664
synapses s =   6, theta = s/2 =   3, probability of false match =  0.000499865412306804
synapses s =   7, theta = s/2 =   3, probability of false match =  0.000855357919350205
synapses s =   8, theta = s/2 =   4, probability of false match =  5.05282906751424e-5
synapses s =   9, theta = s/2 =   4, probability of false match =  8.88044155296650e-5
synapses s =  10, theta = s/2 =   5, probability of false match =  5.23462085992797e-6
synapses s =  11, theta = s/2 =   5, probability of false match =  9.36152430040881e-6
synapses s =  12, theta = s/2 =   6, probability of false match =  5.50467708713271e-7
synapses s =  13, theta = s/2 =   6, probability of false match =  9.96590775459112e-7
synapses s =  14, theta = s/2 =   7, probability of false match =  5.84458284016591e-8
synapses s =  15, theta = s/2 =   7, probability of false match =  1.06781055245346e-7
synapses s =  16, theta = s/2 =   8, probability of false match =  6.24488987535941e-9
synapses s =  17, theta = s/2 =   8, probability of false match =  1.14900993578035e-8
synapses s =  18, theta = s/2 =   9, probability of false match =  6.70048689113995e-10
synapses s =  19, theta = s/2 =   9, probability of false match =  1.23977606153067e-9
synapses s =  20, theta = s/2 =  10, probability of false match =  7.20851539659221e-11
synapses s =  21, theta = s/2 =  10, probability of false match =  1.33990428897848e-10
synapses s =  22, theta = s/2 =  11, probability of false match =  7.76731651059463e-12
synapses s =  23, theta = s/2 =  11, probability of false match =  1.44929751014167e-11
synapses s =  24, theta = s/2 =  12, probability of false match =  8.37584522709849e-13
synapses s =  25, theta = s/2 =  12, probability of false match =  1.56790489972169e-12
synapses s =  26, theta = s/2 =  13, probability of false match =  9.03331595141546e-14
synapses s =  27, theta = s/2 =  13, probability of false match =  1.69568150423906e-13
synapses s =  28, theta = s/2 =  14, probability of false match =  9.73897092618566e-15
synapses s =  29, theta = s/2 =  14, probability of false match =  1.83255953842929e-14
synapses s =  30, theta = s/2 =  15, probability of false match =  1.04919182521237e-15
[0.0591029102910291, 0.0873354694941389, 0.00517101241148655, 0.00844794620736664, 0.000499865412306804, 0.000855357919350205, 5.05282906751424e-5, 8.88044155296650e-5, 5.23462085992797e-6, 9.36152430040881e-6, 5.50467708713271e-7, 9.96590775459112e-7, 5.84458284016591e-8, 1.06781055245346e-7, 6.24488987535941e-9, 1.14900993578035e-8, 6.70048689113995e-10, 1.23977606153067e-9, 7.20851539659221e-11, 1.33990428897848e-10, 7.76731651059463e-12, 1.44929751014167e-11, 8.37584522709849e-13, 1.56790489972169e-12, 9.03331595141546e-14, 1.69568150423906e-13, 9.73897092618566e-15, 1.83255953842929e-14, 1.04919182521237e-15]
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]

``````

## Impact of noise on false negatives

``````

In [22]:

b = Symbol("b")
v = Symbol("v")
theta = Symbol("theta")
s = Symbol("s")
a = Symbol("a")

overlapSetNoise = (binomial(s, b) * binomial(a - s, v - b)) / binomial(a, v)
noiseFN = Sum(overlapSetNoise, (b, s-theta+1, s))

``````
``````

In [23]:

eqn = noiseFN.subs(s, 30).subs(a, 128)
print "a=128 cells active with segment containing s=30 synapses (n doesn't matter here)\n"
for t in range(8,20,4):
print "theta = ",t
errorList = []
noiseList = []
noisePct = 0.05
while noisePct <= 0.85:
noise = int(round(noisePct*128,0))
errorList += [eqn.subs(v, noise).subs(theta,t).evalf()]
noiseList += [noise/128.0]
noisePct += 0.05
print errorList
print noiseList

``````
``````

a=128 cells active with segment containing s=30 synapses (n doesn't matter here)

theta =  8
[0, 0, 0, 3.11341516283240e-16, 2.23243424464799e-12, 7.90168637530306e-10, 1.20695707971664e-7, 3.45576265561118e-6, 8.08202472708491e-5, 0.000735429456875121, 0.00464043435771348, 0.0268657157114204, 0.0896352007201254, 0.263952754229579, 0.508714577385333, 0.770861966941236]
[0.046875, 0.1015625, 0.1484375, 0.203125, 0.25, 0.296875, 0.3515625, 0.3984375, 0.453125, 0.5, 0.546875, 0.6015625, 0.6484375, 0.703125, 0.75, 0.796875]
theta =  12
[0, 0, 2.48810797387309e-15, 7.92695349343630e-10, 2.16302525195240e-7, 1.09248135880715e-5, 0.000314435369055385, 0.00279559866084888, 0.0198782675563797, 0.0716985160403564, 0.190430462690358, 0.426525969583828, 0.664766152465367, 0.880922510721824, 0.970339402698393, 0.996376835285247]
[0.046875, 0.1015625, 0.1484375, 0.203125, 0.25, 0.296875, 0.3515625, 0.3984375, 0.453125, 0.5, 0.546875, 0.6015625, 0.6484375, 0.703125, 0.75, 0.796875]
theta =  16
[0, 0, 2.65549705827547e-8, 1.97277260559420e-5, 0.000590078912236923, 0.00627504390204146, 0.0434711883681422, 0.139067254386793, 0.351117043857492, 0.582501773030327, 0.788076297517739, 0.933878292787173, 0.983735005386502, 0.998319255844748, 0.999889798557155, 0.999997748076386]
[0.046875, 0.1015625, 0.1484375, 0.203125, 0.25, 0.296875, 0.3515625, 0.3984375, 0.453125, 0.5, 0.546875, 0.6015625, 0.6484375, 0.703125, 0.75, 0.796875]

``````
``````

In [ ]:

``````