I have an expression, arising from a KL divergence between some conditional distributions that I want to minimise, similar to
$$\frac{\partial}{\partial a} \mathbb{E}_x\left[ \log \left( a + \frac{(x-\mu)^2}{2\sigma^2} \right) -\frac{a}{b} \right] = 0, \quad\text{where}\;x \sim \mathcal{N}\left( \mu,\sigma^2 \right).$$
As the minimisation is with respect to $a$, and $x$ is independent of both $a$ and $b$, if I'm not dead wrong I can swap the integral and the derivative to get
$$\mathbb{E}_x\left[ \frac{1}{a + \frac{(x-\mu)^2}{2\sigma^2} }-\frac{1}{b} \right] = 0$$
and hence I sort of know that if $a^* = b - \frac{(x-\mu)^2}{2\sigma^2} $ the term inside the expectation would be always $0$ and so would be its expected value.
This is however a far from useful result to me as I'd like to have a solution which is independent of (or rather averaged with respect to) $x$ and that's why there is the expectation in the first place!
If for some trick I were to have that I can compute this solution and then compute its expectation (which is trivially $a^{**} = b-\frac{1}{2}$ ) I'd be very happy, but I see no way of getting there or to any similar (or very different but still usable) result.
Is it possible for someone more knowledgeable?
For reference and to give the complete picture this arises from the first term in
$$KL\left(P(x,y) | Q(x,y) \right) = \mathbb{E}_x\left[ KL\left(P(y|x) | Q(y|x) \right)\right] + KL\left(P(x) | Q(x) \right)$$
where I was able to solve the second term already and $a$ and $b$ are parameters of $Q(y|x)$ and $P(y|x)$ respectively.
Help!
I first tried dealing with the
$$ \mathbb{E}_z \left[ \frac{1}{a+z^2/2} \right] $$
with $z\sim \mathcal{N}\left(0,1\right)$ expectation. As mentioned in the comments contour integration doesn't help because of the exponential on the numerator if this integral.
The closest I can get to a solution is by defining $$H(j) = \int \frac{\left(2\pi\right)^{-\frac{1}{2}}e^{-\frac{z^2}{2}}}{a+\frac{z^2}{2}}e^{j\left(a+\frac{z^2}{2}\right)} dz$$
so that in $H'(j)$ the denominator vanishes. I can then go back from there and compute $H(0)$ to obtain back my result.
Thie doesn't help though as the result I obtain is
$$ \sqrt{\frac{\pi}{a}}e^a\left[1-\Phi\left(\sqrt{a}\right)\right]$$
$\Phi(x)$ being the standard Normal CDF ,which is again not analytical with respect to $a$ and thus I still cannot minimise by hand.
I finally decided that I'll just take a step back, expand $\log\left(a+\frac{z^2}{2}\right)$ as
$$ \log(a) + \log\left(1+\frac{z^2}{2a}\right) \approx \log(a) + \frac{z^2}{2a} -\frac{\left(\frac{z^2}{2a}\right)^2}{2} + \frac{\left(\frac{z^2}{2a}\right)^3}{3} - \dots $$
since I have the freedom to take $a>>1$ and truncate after a few terms. From there taking both the expectation with respect to $z$ and the derivative with respect to $a$ is trivial and the optimisation task is duable, even thought the result will of course be an approximation.