In [107]:
from sympy import *
init_printing()
from IPython.display import display
%matplotlib inline
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['pdf.fonttype'] = 42
In [25]:
nColL4 = Symbol("nColL4", positive=True)
nCellPerColL4 = Symbol("nCellPerColL4", positive=True)
n = Symbol("n", positive=True)
m = Symbol("m", positive=True)
# number of active bits
w = Symbol("w", positive=True)
b = Symbol("b", positive=True)
# match thresh
theta = Symbol("theta", positive=True)
nCw = factorial(n) / (factorial(w) * factorial(n - w))
overlapSet = binomial(w, b) * binomial(n - w, w - b)
numFeatures = factorial(n) / (factorial(w) * factorial(n - w))/(binomial(w, b) * binomial(n - w, w - b))
display(Eq(binomial(n, w), nCw))
In [57]:
nColL4Val = 2048
wVal = 40
bVal = 20
mVal = 32
numPts = nCw.subs(n, nColL4Val).subs(w, wVal)
print numPts.evalf()
sizeOverlapSet = 0
for bVal in range(20, 40):
sizeOverlapSet += overlapSet.subs(w, wVal).subs(n, nColL4Val).subs(b, bVal)
print sizeOverlapSet.evalf()
numFeatures = numPts / sizeOverlapSet
#numFeature = numFeatures.subs(n, nColL4Val).subs(w, wVal).subs(b, bVal)
print numFeatures.evalf()
In [64]:
mtow = pow(m, w)
numPts = mtow.subs(m, mVal).subs(w, wVal)
sizeInexactMatch = 0
for bVal in range(20, 40):
sizeInexactMatch += nCw.subs(n, wVal).subs(w, bVal) * pow(mVal, wVal-bVal)
numLocations = numPts / sizeInexactMatch
print numPts.evalf()
print numLocations.evalf()
In [56]:
print numFeatures.evalf()
numPts = nCw.subs(n, nColL4Val-1).subs(w, wVal-1)
print numPts.evalf()
In [99]:
p = Symbol("p", positive=True)
k = Symbol("k", positive=True)
pValCell = float(wVal)/(nColL4Val*mVal)
pValCol = float(wVal)/(nColL4Val)
pActive = 1-pow(1-p, k)
print pActive.subs(p, pVal).subs(k, 1).evalf()
numCellsVsK = []
numColsVsK = []
numCellPerColumnVsK = []
for kVal in range(200):
numCellsVsK.append(nColL4Val*mVal*pActive.subs(p, pVal).subs(k, kVal).evalf())
numColsVsK.append(nColL4Val*1*pActive.subs(p, pValCol).subs(k, kVal).evalf())
numCellPerColumnVsK.append(numCellsVsK[-1]/numColsVsK[-1])
In [108]:
fig, ax = plt.subplots(1, 2)
ax[0].plot(numCellsVsK)
ax[0].plot(numColsVsK,'r')
ax[0].set_xlabel("# (feature, object) pair")
ax[0].set_ylabel("# active bits in union")
ax[0].legend(['Cell', 'Column'])
ax[1].plot(numCellPerColumnVsK)
ax[1].set_xlabel("# (feature, object) pair")
ax[1].set_ylabel("# cell per column")
plt.savefig('UnionSizeVsK.pdf')
In [ ]:
n = Symbol("n", positive=True)
m = Symbol("m", positive=True)
# number of active bits
w = Symbol("w", positive=True)
b = Symbol("b", positive=True)
theta = Symbol("theta", positive=True)
nColL4Val = 2048
wVal = 40
mVal = 32
kVal = 200
thetaVal = 20
numCellsInUnion = n*m*(1-pow(1-w/(n*m), k))
numColsInUnion = n*(1-pow(1-w/n, k))
numCellsPerColumn = numCellsInUnion / numColsInUnion
print "numColsInUnion: ", numColsInUnion.subs(n, nColL4Val).subs(w, wVal).subs(k,kVal).evalf()
print "numCellsPerColumn: ", numCellsPerColumn.subs(n, nColL4Val).subs(w, wVal).subs(k,kVal).subs(m, mVal).evalf()
overlapSet = binomial(w, b) * binomial(n - w, w - b)
numFeatureInexactMatch = 0
for bVal in range(20, 40):
numFeatureInexactMatch += overlapSet.subs(w, wVal).subs(n, nColL4Val).subs(b, bVal)
numFeaturePts = nCw.subs(n, nColL4Val).subs(w, wVal)
numFeatureCapacity = numFeaturePts / numFeatureInexactMatch
mtow = pow(m, w)
numLocationPts = mtow.subs(m, mVal).subs(w, wVal)
numLocationInexactMatch = 0
for bVal in range(20, 40):
numLocationInexactMatch += nCw.subs(n, wVal).subs(w, bVal) * pow(mVal, wVal-bVal)
numLocationCapacity = numLocationPts / numLocationInexactMatch
numMatchCounts = binomial(numColsInUnion, theta) * binomial(n - numColsInUnion, w - theta) * pow(theta, numCellsPerColumn) * pow(w - theta, m)
numMatchCountsVal = numMatchCounts.subs(n, nColL4Val).subs(w, wVal).subs(m, mVal).subs(k, kVal).subs(theta, thetaVal)
falseMatch = numMatchCountsVal / (numFeaturePts * numLocationPts)
falseMatch.evalf()
In [ ]:
n = Symbol("n", positive=True)
m = Symbol("m", positive=True)
# number of active bits
w = Symbol("w", positive=True)
b = Symbol("b", positive=True)
theta = Symbol("theta", positive=True)
nColL4Val = 2048
wVal = 40
mVal = 32
kVal = 200
thetaVal = 20
numCellsInUnion = n*m*(1-pow(1-w/(n*m), k))
numColsInUnion = n*(1-pow(1-w/n, k))
numCellsPerColumn = numCellsInUnion / numColsInUnion
print "numColsInUnion: ", numColsInUnion.subs(n, nColL4Val).subs(w, wVal).subs(k,kVal).evalf()
print "numCellsPerColumn: ", numCellsPerColumn.subs(n, nColL4Val).subs(w, wVal).subs(k,kVal).subs(m, mVal).evalf()
In [ ]:
print falseMatch
In [ ]: