# The absolution value of the normal distribution |N(μ, σ2)|

Let’s start with an interesting question. If I split a normal distribution in half and find the center for each half and then subtract the left center from the center of the right half what will I get? Surprisingly, I have run into this problem twice in my daily work and I thought it would make an interesting blog post. The first time I had to solve this problem was when I was implementing this paper. The analytical form of this solution is relatively easy to derive, but we will end up doing some simplifications. $\int_{0}^{\infty} x . \tfrac{2}{\sigma \sqrt{2 \pi }}e^{- \tfrac{(x-\mu )^2}{2\sigma ^2}} dx - \int_{- \infty}^{0} x . \tfrac{2}{\sigma \sqrt{2 \pi }}e^{- \tfrac{(x-\mu )^2}{2\sigma ^2}} dx$

The 2 in the numerator for $\tfrac{2}{\sigma \sqrt{2 \pi }}$ is there to transfrom the half-normal distribution into a proper probability distribution that adds up to one. The expression can now be simplified to $= 4 \int_{0}^{\infty} x . \tfrac{1}{\sigma \sqrt{2 \pi }}e^{- \tfrac{(x-\mu )^2}{2\sigma ^2}} dx$

mu and sigma are constant parameters therefore $= 4 . \tfrac{1}{\sigma \sqrt{2 \pi }} \int_{0}^{\infty} x e^{- \tfrac{(x-\mu )^2}{2\sigma ^2}} dx$

There is no analytical solution for this (you would end up with the error function). However, we can easily realize that mu is not going to change the results and the expression will have the same value for any arbitrary value of mu. We can basically transfer the two half-normal distributions along the x axis such that the final normal distribution is zero-mean. For an standard normal (mu =0 , sigma = 1), we arrive at the following expression that is easily solvable. $= 4 . \tfrac{1}{\sqrt{2 \pi }} \int_{0}^{\infty} x e^{- \tfrac{x^2}{2}} dx$

This expression will result in $= 2 \sqrt{\tfrac{2}{\pi}}\left [ -e^{\tfrac{-x^2}{2}} \right ]_{0}^{\infty} = 2 \sqrt{\tfrac{2}{\pi}}$

It is therefore easy to show that for any other normal distribution with sigma = σ the expression for the mean will be as the following: $= 2 \sigma \sqrt{\tfrac{2}{\pi}}$

I usually evaluate my analytical solution with a little simulation code. The following code, although not optimized for performance, can show us that the analytical solution is correct.

The output of this little code is as follows. And it is sufficiently close to 1.595769, the theoretical value.

The absolute value of the normal distribution follows a distribution called the half-normal distribution. Using the same method, it is easy to show that the mean value for the half-normal distribution is $= \sigma \sqrt{\tfrac{2}{\pi}}$