# Which pdf to choose for the prior of an angle?

I have a system in which one uncertain variable is a direction in two dimensions. If I want to define a prior for this, is there an elegant way to reflect the fact that the parameter space dimension for this variable is circular (i.e., the distance between 359.9 degrees and 0.0 degrees is less than 359.9 degrees and 300.00 degrees)?

I can think of some janky solutions with coding (reflecting values outside the bound of 0 and 360 back to the other end), but is there a space in which this solution is more elegant? And which prior should I use if I want to reflect e.g. a quasi-Gaussian preference for a certain direction?

• Can you define a prior on a two-dimensional space, and then add a constraint that $x^2+y^2=1$ (or put in a penalty that sharply increases as $(x^2+y^2-1)^2$ increases? – Acccumulation Jan 17 at 5:29
• Do you care about the direction? In other words, is 90 degrees vs 270 degrees and 0 vs 180 degrees just a matter of preference, or does it actually make a difference functionally? – jkm Jan 17 at 12:21
• No, I don't care about the direction, in as far as I can define the orientation of my polar coordinate system however I like. – J.Galt Jan 17 at 15:11

You may want t consider the von Mises distribution, aka Tikhonov distribution, and plays the role similar to the normal distribution in 1D statistics:

$$p(\theta ; \alpha, \theta_0 ) = \frac{ e^{\alpha \cos (\theta -\theta_0)}} {2 \pi I_0(\alpha)}$$

For $$\alpha=0$$ it is uniform, for $$\alpha >> 1$$ the distribution is sharply peaked at $$\theta_0$$

The most obvious thing to do here would be to express the variable in polar coordinates and impose a prior on the angle and displacement. That is, you express your point $$(x,y)$$ as a vector $$(\theta,r)$$ where:

\begin{aligned} x &= r \cos \theta, \\[4pt] y &= r \sin \theta. \\[4pt] \end{aligned}

You can then impose a prior on $$0 \leqslant \theta < 2 \pi$$ and $$r \geqslant 0$$, and this will create an implicit distribution on the vector $$(x,y)$$. In the absence of information about the angle, you could use the non-informative uniform prior $$\theta \sim \text{U}(0, 2 \pi)$$ for the angle, and then choose an appropriate prior for the displacement $$r$$.

• Thank you for the comment! For my purposes, $r$ is not imporant - we can set it to unity. Your response seems similar to the option I considered, but an important property it's missing is that $\theta$ does not 'wrap around'. – J.Galt Jan 16 at 12:05
• I'm not sure what you mean when you say it doesn't "wrap around". The total angle in the circle is $2 \pi$ radians, so the range of the parameter $\theta$ traverses every possible angle. If you really wanted to, you could set its range higher, to allow it to go around the circle multiple times, but this does not change things. – Ben - Reinstate Monica Jan 16 at 13:17
• What I mean by this is that if I have, for example, a gradient-based optimizer, it is important that the algorithm realizes that moving higher beyond 360 puts you back on the line from zero (and, of course, vice-versa). If I simply extend the range from $0$ to $2\pi$ to, say, $-18\pi$ and $20\pi$, it's critical that both the inferred prior and posterior reflect that $p(\theta-2\pi)=p(\theta)=p(\theta+2\pi)=p(\theta+4\pi)=...$. In other words, I don't want to define my pdf on a line but on a ring. I'd like to avoid the slightly inelegant method of 'fusing' the line into a ring, if possible. – J.Galt Jan 16 at 13:25
• That should happen automatically from the equations for $x$ and $y$. You can see that substitution of $\theta = 0$ or $\theta = 2 \pi$ (for a fixed $r$) give the same coordinates. That happens automatically when you use polar coordinates. – Ben - Reinstate Monica Jan 16 at 13:34
• That's of course true, but not quite what I wanted to get at. For the purpose of defining a pdf, for example, how do I translate this information onto the parameter space dimension of $-\infty<\theta<\infty$? I could, for example, create an infinite Gaussian mixture, each Gaussian mean spaced by $2\pi$, but if I want to analytically infer the posterior, my likelihood would equally have to be infinitely repeating, and so would the posterior. There has to be a more elegant way of conveying the information that my parameter space dimension $\theta$ is circular. – J.Galt Jan 16 at 13:44

If you have a prior for the angle, I'd use it as the reference. E.g. I'd rotate all data so that the prior is at $$180^{\circ}$$ and measure all angles on the scale $$[0^{\circ}, 360^{\circ})$$.

I see no elegant solution to measuring distance between two angles, $$\phi$$ and $$\psi$$. I'd calculate the differences $$(\phi - \psi)$$ and $$(((\phi + 180^{\circ}) \mod 360^{\circ}) - ((\psi + 180^{\circ}) \mod 360^{\circ}) )$$ and take the one with the smaller absolute value.

Regarding the distribution to use, if the variance is sufficiently small, I see no reason not to use Gaussian. If the small probabilities at the tails disturb you, you can try beta distribution (properly scaled, so that it covers your angle range), with $$\alpha = \beta \ge 1$$. For $$\alpha = \beta = 1$$ you'd get the uniform distribution. However, if your variance is large, so that the the process which generates the angles can generate values $$> 360^{\circ}$$ and $$< 0^{\circ}$$ with a non-negligible probability, then you are in trouble. You can wrap the Gaussian distribution so that its support is $$[0, 360)^{\circ}$$, but its PDF is not too handy (having an infinite sum of $$\cosh$$'s as a term, if I did my algebra correctly). The curve resembles a raised Gaussian:

but mathematically it is different.

• Thank you for the response! That's indeed a possible workaround if my prior has a strong preference towards one side. – J.Galt Jan 16 at 13:49
• There's no need to rotate or to reduce both angles separately. The distance between two angles $x$ and $y$ (measured in degrees) is $|(x-y+180)\operatorname{mod} 360 - 180)|.$ This is the angular version of the absolute value function for real numbers. Your "infinite sum of cosh's" is a Jacobi theta function: see the comment thread at stats.stackexchange.com/questions/443875. – whuber Jan 16 at 19:04
• @whuber: Without rotation, how would the distribution look like? I mean, you could have modulo transformation in the argument of the PDF, but would't that be equivalent to data rotation? The point is, if we want the angles to be in $[0, 360)$, the PDF outside this range should be $0$ or negligible. The easiest way to achieve it is to have its mode in the middle of the interval. – Igor F. Jan 17 at 8:34
• There's no data rotation in this formula: it literally is the angular distance. Working modulo 360 handles any potential problems with being "outside this range," because that's mathematically impossible. – whuber Jan 17 at 13:47
• @whuber: I get that. My question was on the form of the distribution, and I was implicitly thinking of something like the beta distribution, as I referred to in my answer. If you don't rotate the data, and the mode of the angle distribution is not 180, then either your beta distribution cannot be symmetrical anymore, or you need to apply modulo in its argument, thus "rotating" the distribution itself. But now that Dave suggested the von Mises distribution I consider this question obsolete. – Igor F. Jan 17 at 14:04