How to differentiate function related to bloom filters?

102 Views Asked by At

I am trying to understand a scribe note on choosing the right number of hash functions $k$ for a bloomfilter of size $n$ and $m$ elements. The following is stated:

Suppose we are given the ratio $\frac{m}{n}$ and want to optimize the number $k$. If $$g=\ln(f)=k\ln(1-e^{-kn/m})$$ and we let $p=e^{-kn/m}$. Then the derivative of $g$ is: $$\frac{dg}{dk}=\ln(1-p)+\frac{kn}{m}\cdot\frac{p}{1-p}$$ This confuses me because when I try to differentiate $g$ I get the following: $$\begin{equation} \frac{dg}{dk}=\ln(1-p)+\frac{1}{1-e^{-km/n}} \cdot \frac{e^{-km/n} \cdot m-kn}{m^2} \end{equation}$$

Link to equation (on page 2): http://people.math.gatech.edu/~randall/AlgsF09/bloomfilters.pdf

2

There are 2 best solutions below

17
On BEST ANSWER

This is because you also have to differentiate $p$ as it depends on $k$. It goes like this: first note $$ \frac{d}{dk} p = \frac d{dk} e^{-kn/m} =-\frac{n}{m} e^{-kn/m} =-\frac{n}{m}p$$ Then applying product rule and chain rule, \begin{align} \frac{dg}{dk} = \frac{d}{dk}(k(\ln(1-p)) &=\ln(1-p) + k\frac{d}{dk}(\ln (1-p))\\ &=\ln(1-p) + k\frac{\frac{d}{dk}(1-p)}{1-p}\\ &=\ln(1-p) + k\frac{0-\frac{dp}{dk}}{1-p}\\ &=\ln(1-p) + k \frac{-\left(-\frac nmp\right)}{1-p}\\ &=\ln(1-p)+\frac{kn}m\cdot\frac{p}{1-p} \end{align}

3
On

$$g=k\ln(1-e^{-kn/m})$$ and

$$\frac{dg}{dk}=\ln(1-e^{-kn/m})+k\frac{\dfrac nme^{-kn/m}}{1-e^{-kn/m}}=\ln(1-p)+\frac{kn}m\frac{p}{1-p}.$$

I don't see any problem.


You can also work this out as follows:

$$\frac{dp}{dk}=-\frac nm p$$

and

$$\frac{d(k\log(1-p)}{dk}=\log(1-p)-k\frac{\dfrac{dp}{dk}}{1-p} \\=\log(1-p)+\frac{kn}m\frac{p}{1-p}.$$