How to find a function that minimize the following expectation
Solution 1:
For a fixed $y$, \begin{align} \int |x-m| f_{X\mid Y}(x\mid y)\, dx&=\int_{-\infty}^{m}(m-x)f_{X\mid Y}(x\mid y)\, dx \\ &\quad+\int_{m}^{\infty}(x-m)f_{X\mid Y}(x\mid y)\, dx. \end{align} Differentiating the RHS w.r.t. $m$ and equating to zero yields $$ \int_{-\infty}^{m^*}f_{X\mid Y}(x\mid y)\, dx=\int_{m^*}^{\infty}f_{X\mid Y}(x\mid y)\, dx, $$ or $$ F_{X\mid Y}(m^*\mid y)=1-F_{X\mid Y}(m^*\mid y). $$ That is $m^*$ is the conditional median of $X$ given $Y$.