Derivative of a nested function under integral I recently came across the following problem. It should be simple but cannot really find the exact tools to solve it. Suppose there is a given probability density function f(x) defined over the real line. Now, I would like to find a perturbation function g(x) for which the distance between f(x) and f(g(x)) is minimized. Clearly, g(x) should be an identity function but I was wondering if it is possible to show it analytically. 
Let us for instance take a Kullback-Leibler divergence between f(g(x)) and f(x), i.e.
$$
D_{KL}(f(g(x)),f(x)) = \int f(g(x))\ln \left(\frac{f(g(x))}{f(x)}\right)dx
$$
Do you know how to show analytically the minimization of $D_{KL}$ with respect to g(x)? Or more specifically, how to calculate
$$
\frac{d}{dg(x)} D_{KL}(f(g(x)),f(x))
$$
 A: There are two ways to look at the problem. 


*

*The first one, as @stochasticboy321 mentioned, is that you already know the value of the minimum of the divergence, which is 0. Consequently, the solutions to the problem are the functions $g$ such that $D_{KL}(f(g(x)),f(x))=0$. A sufficient condition for this to hold is that $f(g(x))= f(x),~\forall x$. This does hold when $g$ is the identity function, but that is by no means the only possible solution. If you consider a symmetric distribution about $a$, such as a normal distribution with mean $a$, the transformation $g(x) = 2a -x$ will also work. 

*It seems however that you are interested in actually carrying out the optimization procedure. So let's assume we do not know that the minimum is 0. We are then trying to minimize the following functional:
$$ J(g):=\int f(g(x))\ln\left(\frac{f(g(x))}{f(x)}\right)dx.$$
subject to the constraint that $\int f(g(x)) dx =1 $ since the Kullback-Leibler divergence is defined for distribution functions.
This puts us in the realm of the Calculus of Variations. Nevertheless, I think that deriving the necessary conditions for optimality would not yield much more information and you would probably end up with the same sufficient condition, that is: $f(g(x))=f(x),~\forall x$.

