I am trying to compute the expectation of $g(s,x)=s \ln \sigma(x)+(1-s)\ln(1-\sigma(x))$ with respect to the normal distribution $\mathcal{N}(x;m,v)$, where we have $\sigma(x)=\frac{1}{1+e^{-x}}$. If we define $$\langle g(s,x)\rangle\_q=\int\mathcal{N}(x;m,v)g(s,x)\mathrm{d}x$$


I would like to re-derive the formula which is given in section 5.1, paragraph 3 of [this paper](https://papers.nips.cc/paper/4407-non-conjugate-variational-message-passing-for-multinomial-and-binary-regression.pdf)
$$\frac{\mathrm{d}\langle g(s,x)\rangle\_q}{\mathrm{d}v}=\frac{-1}{2v}(\big(\langle x\sigma(x)\rangle\_q-m\langle\sigma(x)\rangle\_q\big)$$
$$\frac{\mathrm{d}\langle g(s,x)\rangle\_q}{\mathrm{d}m}=s-\langle\sigma(x)\rangle\_q.$$
 where $q$ is the normal distribution. Does this derivation come from the direct partial differentiation of integrand with respect to $v$ and $m$? Could anybody suggest a way to re-derive these two equations?



The expectation of binary logistics regression with respect to Gaussian distribution
Notice that $g(s,x)=(s-1)x+\ln\sigma(x)$. So 
$$\langle g(s,x)\rangle\_q=(s-1)m+\langle \ln\sigma(x)\rangle\_q$$
and the entire $s$-dependence is trivial. Now for the second identity we perform a partial integration (noting that, since ${\cal N}$ is a function of $x-m$, one has $\partial{\cal N}/\partial m=-\partial {\cal N}/\partial x$),
$$\frac{\mathrm{d}\langle g(s,x)\rangle\_q}{\mathrm{d}m}=s-1+\left\langle\frac{d}{dx}\ln\sigma(x)\right\rangle\_q=s-1+\left\langle\frac{1}{1+e^x}\right\rangle\_q=s-\left\langle\sigma(x)\right\rangle\_q.$$


For the first identity it is convenient to change variables from $x$ to $y=(x-m)/\sqrt v$, so that we can replace ${\cal N}(x,m,v)$ by ${\cal N}(y,0,1)$ and $\sigma(x)$ by $\sigma(m+y\sqrt v)$. Then we carry out the derivative of $\ln\sigma$ with respect to $v$,
$$\frac{\mathrm{d}\langle g(s,y)\rangle\_q}{\mathrm{d}v}=\left\langle\frac{y}{2 \sqrt{v}} \left(e^{m+y\sqrt{v} }+1\right)^{-1}\right\rangle\_q=\left\langle\frac{y}{2 \sqrt{v}} \left(1-\sigma(m+y\sqrt v)\right)\right\rangle\_q$$
$$=\left\langle\frac{x-m}{2 v} \left(1-\sigma(x)\right)\right\rangle\_q=\frac{1}{2v}\langle (m-x)\sigma(x)\rangle\_q,$$
in agreement with the first equation in the OP.


