u(x,T) & =&h(x,m)+\displaystyle\int_{\mathbb{R}^{n}}\frac{\partial}{\partial m}h(\xi,m)(x)m(\xi)d\xi.
\end{array}
\right.$$

We can then write $$\begin{array}{rcl}
    &&\displaystyle\frac{d}{d\theta}J(\hat{v}(\cdot)+\theta v(\cdot))|_{\theta=0}\\
    &=&\mathbb{E} \displaystyle\int_{0}^{T}\bigg[\int_{\mathbb{R}^{n}}\frac{\partial f}{\partial v}(x,m(t),\hat{v}(x,t))v(x)m(x)dx\\
    &&\qquad\qquad+\displaystyle\int_{\mathbb{R}^{n}}\tilde{m}(x,t)\Big[-\partial_{t}u+(\mathcal{A}u-\frac{1}{2}\beta^{2}\Delta u+\beta^{2}\text{div} B)-Du . g(x,m,\hat{v}(x))\\
    &&\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad-\displaystyle\int_{\mathbb{R}^{n}}Du(\xi)\frac{\partial}{\partial m}g(\xi,m,\hat{v}(\xi))(x)m(\xi)d\xi\Big]dx\bigg]dt\\
    &&\qquad+\mathbb{E}\displaystyle\int_{\mathbb{R}^{n}}u(x,T)\tilde{m}(x,T) dx.
\end{array}$$

But $$\partial_{t}\int_{\mathbb{R}^{n}}u(x,t)\tilde{m}(x,t)dx=\int_{\mathbb{R}^{n}}\partial_{t}u(x,t)\tilde{m}(x,t)dx+\int_{\mathbb{R}^{n}}\partial_{t}\tilde{m}(x,t)u(x,t)dx+\beta^{2}\int_{\mathbb{R}^{n}}D\tilde{m}(x,t)B(x,t)dx,$$ therefore $$\partial_{t}\int_{\mathbb{R}^{n}}u(x,t)\tilde{m}(x,t)dx-\int_{\mathbb{R}^{n}}\partial_{t}u(x,t)\tilde{m}(x,t)dx+\beta^{2}\int_{\mathbb{R}^{n}}\text{div}\: B(x,t)\,\tilde{m}(x,t)dx=\int_{\mathbb{R}^{n}}\partial_{t}\tilde{m}(x,t)u(x,t)dx,$$ which implies $$\begin{array}{rcl}
    &&\displaystyle\frac{d}{d\theta}J(\hat{v}(\cdot)+\theta v(\cdot))|_{\theta=0}\\
    &=& \mathbb{E} \displaystyle\int_{0}^{T}\int_{\mathbb{R}^{n}}\frac{\partial f}{\partial v}(x,m(t),\hat{v}(x,t))v(x)m(x)dxdt\\
    &&\qquad+\mathbb{E} \displaystyle\int_{0}^{T}\int_{\mathbb{R}^{n}}u(x,t)\Big[\partial_{t}\tilde{m}(x,t)+(\mathcal{A}^{*}\tilde{m}-\frac{1}{2}\beta^{2}\Delta\tilde{m}+\text{div}(g(x,m(t),\hat{v}(x,t))\tilde{m}))dt\\
    &&\qquad+\text{div}\,(m(x)\displaystyle\int_{\mathbb{R}^{n}}\frac{\partial g(x,m,\hat{v}(x))}{\partial m}(\xi)\tilde{m}(\xi)d\xi)\: dt\Big]dx.
\end{array}$$

From (\[eq:3.4-2\]) we obtain $$\begin{array}{rcl}
    &&\displaystyle\frac{d}{d\theta}J(\hat{v}(\cdot)+\theta v(\cdot))|_{\theta=0}\\
    &=&\mathbb{E} \displaystyle\int_{0}^{T}\int_{\mathbb{R}^{n}}\frac{\partial f}{\partial v}(x,m(t),\hat{v}(x,t))v(x)m(x)dxdt\\
    &&\qquad- \mathbb{E} \displaystyle\int_{0}^{T}\int_{\mathbb{R}^{n}}  u(x,t)\text{div (}\frac{\partial g}{\partial v}(x,m,\hat{v}(x))v(x)m(x))dxdt\\
    &=&\mathbb{E} \displaystyle\int_{0}^{T}\int_{\mathbb{R}^{n}}(\frac{\partial f}{\partial v}(x,m(t),\hat{v}(x,t))v(x)+Du\frac{\partial g}{\partial v}(x,m,\hat{v}(x,t))v(x))m(x)dxdt,
\end{array}$$ and since $v$ is arbitrary, for if the support of $m$ is $\mathbb{R}^n$, $\hat{v}(x,t)$ satisfies (because of optimality) $$\frac{\partial f}{\partial v}(x,m(t),\hat{v}(x,t))+Du\frac{\partial g}{\partial v}(x,m,\hat{v}(x,t))=0,$$ and therefore $\hat{v}(x,t)=\hat{v}(x,m(t),Du(x,t))$.

One obtains immediately that the pair $(u(x,t),m(x,t))$ is a solution of the system of stochastic HJB-FP equations (\[eq:3.7-1\]).

STOCHASTIC MEAN FIELD GAMES
===========================

GENERAL COMMENTS
----------------

How to obtain a system of coupled HJB-FP equations in the case of stochastic mean field games? In the deterministic case, see Section \[sub:MEAN-FIELD-GAMES\], the idea was to consider $m(t)$ as a parameter, and to solve a standard stochastic control problem. For this problem, one can use standard Dynamic Programming to obtain the HJB equation, depending on the parameter $m(t).$ One expresses next the fixed point property, namely that $m(t)$ is the probability density 