2

I have a set of image data and I'm trying to train a neural network to predict a value in degrees as an output inside a range of [-180. 180). I don't like the idea of the large discontinuity between -180 and 180 (or equivalently 0 and 360) for essentially the same value, and I do not want to use categorization to solve this problem (like used here - although note that I am NOT doing image orientation correction) as this is a somewhat precise bearing angle.

One idea I had is to map the value in degrees onto trigonometric functions like sine and cosine that are continuous around 0 degrees. However, arcsine and arccosine are only defined between -90 and 90 degrees, so the inverse won't work for all angles. I could use some combination of arcsine and arccosine to get all possible degree values that could make sine or cosine output a certain value in my desired range, but then I would need to project onto both sine and cosine to uniquely identify my desired value in degrees as there are two possibilities for each.

This method seems like too much effort for a conceptually simple problem. Is there a better way that I can preprocess my values in degrees to make them more suitable for regression?

I'm using Python, so if there's some library function that can do this that's great, but the problem is more general.

Alex Wulff
  • 2,039
  • 3
  • 18
  • 29
  • What do you mean large discontinuity between -180 and 180 for essentially the same value? – Gaussian Prior Dec 28 '20 at 16:16
  • 1
    @GaussianPrior a bearing of 180 and -180 are equivalent – Alex Wulff Dec 28 '20 at 16:28
  • Oh so for your task -180 and 180 are equivalent but a and -a for a in (0, 180) are not. Then good thinking about using sine and cosine functions. Interesting problem, cannot come up with anything at the moment! Sorry :/ – Gaussian Prior Dec 28 '20 at 16:36

2 Answers2

0

Speaking about trigonometric functions to solve the discontinuity problem, might it be useful to look at versine instead? Versine can handle 180 degrees angle, not 90 degrees as cosine and sine

dexpiper
  • 91
  • 7
0
import numpy as np
import matplotlib.pyplot as plt

You could use complex numbers. Ie if you have a bunch of angles (in radians):

angles=np.arange(0,2*np.pi,0.01)

Can generate complex numbers from them:

cmplx=\
np.cos(angles)+1j*np.sin(angles)

Of course they'll all lie in a circle:

plt.figure(figsize=(5,5))
plt.scatter(cmplx.real,cmplx.imag)

enter image description here

No discontinuity!


I don't think you can have a mapping using real numbers only. I am not sure, but I think Showing that f:(0,2π]→S1 is not a homeomorphism and Show that unit circle is compact? are related.

zabop
  • 6,750
  • 3
  • 39
  • 84
  • This is the one - thanks! I don't know why it escaped me to think in two dimensions about this clearly two-dimensional problem... – Alex Wulff Dec 30 '20 at 16:00