Suppose a function $f(x): \mathbb R^d \mapsto \mathbb R^D$, and its stochastic approximator, $g(x; W): \mathbb R^d \mapsto \mathbb R^D$. Here $W$ is some random variable. Then $g(x; W)$ is unbiased in the sense that
$$\mathbb E\_W [g(x;W)] = f(x),$$
for any $x$.


I think the following two are not equal, but how to prove it?
$$\mathbb E\_W\left[\frac{dg(x;W)}{dx}\right] \text{ vs. } \frac{df(x)}{dx}.$$



Expected gradient vs. gradient of expectation
Indeed, the equality will not hold in general. For counterexamples, see [this](https://mathoverflow.net/a/105773/36721) or [this](https://mathoverflow.net/a/172898/36721).


For sufficient conditions for the equality when $d=1$, see e.g. [Folland, Theorem 2.27](http://home.ustc.edu.cn/%7Eluke2001/pdf/realfolland.pdf) or the more general [Lemma 2.3](https://projecteuclid.org/journals/annals-of-probability/volume-43/issue-5/Exact-Rosenthal-type-bounds/10.1214/14-AOP942.full). This immediately extends to any $d$ if the derivatives are understood in the [Gateaux](https://en.wikipedia.org/wiki/Gateaux_derivative) sense.
As seen from the discussion of Theorem 2.27 in [Folland](http://home.ustc.edu.cn/%7Eluke2001/pdf/realfolland.pdf), the extension to $d>1$ is somewhat more problematic if the derivatives are understood in the [Fréchet](https://en.wikipedia.org/wiki/Fr%C3%A9chet_derivative) sense. [This answer](https://mathoverflow.net/a/105775/36721) may also be of interest to you.


