# Can an artificial neural network convert from cartesian coordinates to polar coordinates?

Given cartesian coordinates $x$ and $y$ as input, can a neural network output $r$ and $\theta$, the equivalent polar coordinates?

This would seem to require an approximation of the pythagorean theorem (which requires approximations of $x^2$ and $\sqrt{x}$) and $\sin$, $\cos$, or $\tan$ approximations. Is this possible?

If so, how many hidden layers would it take? I'm using an LSTM.

• I've no idea if it's possible or not but why would you want to do it that way? – David Richerby Dec 24 '15 at 8:59
• @DavidRicherby, what I'm really hoping to do is get the ANN to reason about 2D space in order to control an agent, e.g. calculate distances from friendlies/enemies/obstacles, output where to head and which angle to face, etc. If I give the network these vectors in polar coordinates, my understanding is it won't be able to average them (like if it wants to recognize safe zones or danger zones for example), so I'm planning to use cartesian coordinates. But using cartesian coordinates, can it calculate something like distance from a danger zone? And can it output an angle to face? – Ken Dec 24 '15 at 9:29
• So why not give it both Cartesian and polar co-ordinates? (Or is the point if your question essentially whether it's necessary to give both or whether it would be able to figure out and act on one, based on being given the other?) – David Richerby Dec 24 '15 at 9:35
• @DavidRicherby, even if I give the network both cartesian and polar coordinates, if it finds a danger zone by averaging some cartesian coordinates will it be able to calculate the distance to it (for "danger level" recognition)? Secondly, if it subtracts the target agent's velocity vector from its own velocity vector (in cartesian coordinates) for example, will it be able to output the angle to face to fire at the moving target? Perhaps I can circumvent the second problem by expecting cartesian coordinates as output and taking the angle of the resulting vector myself – Ken Dec 24 '15 at 9:53
• @DavidRicherby, in fact, I'm not sure there's much it could do with the polar coordinate inputs. Even to just calculate if the agent is being flanked it needs to use modulus, which an ANN cannot do, as far as I'm aware. Come to think of it, could it even calculate whether it's being flanked via cartesian coordinates? – Ken Dec 24 '15 at 10:05

i dont know if this answers your question (or at least part of it)

According to the Universal approximation theorem for ANNs, it is possible (at least within a region of interest).

The question about how many hidden layers (and architecture) an ANN should have, is, AFAIK, an open problem, in the sense that there is no result to determine architecture and/or number of layers wrt specific final results (partly, this is due to the non-constructive proof of the above result), although you might want to see here and here.

Here is a review on methods to fix number of hidden layers in ANNs during the past 20 years: Review on Methods to Fix Number of Hidden Neurons in Neural Networks

Most ANNs are built by a trial and error process.

update (just an idea)

By modeling the transformations from cartesian to polar (and approximating square roots,..) as a discrete system, maybe one can transfer this design into ANN model (but i wont pursue this further right now)

From what I learned from my teacher at UCSD, Prof. Sebald, a 3 layer neural network is a universal function approximator. The first layer draws lines in the sand (hyperplanes). It performs dichotomies. The second layer does AND'ing and OR'ing of those half-planes into convex sets (DeMoivre Theorem stuff). The 3rd layer forms inclusions/exclusions of convex sets at which point you can represent any time of non-convex shape. So honestly, this question is not about whether or not it's possible. It's about the difficulty. That expresses itself in terms of a) the domain of convergence where a neural network is able to get close to the right answer (generalization capability) and b) how big the network has to be. And finally, there ends up being far more in-fighting between the nodes of a neural network that is shallow and wide... When the neural network has no more free parameters than the inherent dimension of the data, it becomes very hard to train. So the huge success of deep learning is about a) adding many more parameters (ie layers) to give a lot more capacity to the problem than is inherently needed and b) then regularize by adding a complexity-penalty (Lagrange multiplier) to each parameter. So that every parameter in the network has to add more performance than the complexity penalty costs. That way it sorts the parameters so that the highest-value ones stay and the lowest-value ones are driven out of the network.