I am running MCMC sampling to determine an angular parameter resulting in several thousand samples. The angle is restricted to $[0,\pi]$ as we cannot distinguish $\alpha$ and $\alpha+\pi$. For distributions close to 0° and 180° I am running in the problem of determining an appropriate location parameter of the distribution. I attached an example histogram: Example histogram. While the histogram is clipped to $[0,\pi]$, the data could actually be mirrored at $\pi$ so that there would be a smooth distribution located around $\pi$.
My first guess was to do MLE of the $\pi$-periodic Von Mises distribution: $p(x|\mu,k)=\frac{1}{\pi I_0(x)}\exp(k\cos(2(x-\mu))$
The log likelihood yields for a set of $N$ observations $\ln p=-N\ln \pi-N\ln(I_0(k))+k\sum_i\cos(2(x_i-\mu))$
Next, we try to find the extrema:
$\frac{\partial\ln p}{\partial \mu}=2k\sum_i\sin(2(x_i-\mu))=0$
With the identities $\sin(2x)=2\sin x\cos x$, usual addition theorems and $\cos^2(x)-\sin^2(x)=\cos(2x)$ I ended up with $\mu=\frac{1}{2}\arctan\left(\frac{\sum_i\sin(2x_i)}{\sum_i\cos(2x_i)}\right)$. To project $\mu$ into the range $[0,\pi]$, I shift it via $\mu=\mu+\frac{\pi}{2}$.
For a well behaved case with mean angle far from the boundaries, this works fine: Histogram, mean in red. For the example histogram with a mean close to the boundaires this results in $\mu=89^{\circ}$: Histogram with mean. I had expected something like $179^{\circ}$ resulting in a distribution similar to this plot of the $\pi$-periodic Von Mises dist.: Von Mises with $\mu\approx179^{\circ}$
Does anyone have an idea how to resolve this?
Another problem is the determination of $k$ for a very peaky distribution when a good location parameter is available. I determine $k$ via root-finding in Python, but for high $k$ the Bessel functions just become $\infty$ or too large to handle them in scipy's implementation.