Python circle fitting to data points less sensitive to random noise

curve-fitting, data-fitting, geometry, python

Solution

Replying to your final question

Is there a way to optimize least deltas but not the least squares of delta in Python?

Yes, pick an optimization method (for example downhill simplex implemented in `scipy.optimize.fmin`) and use the sum of absolute deviations as a merit function. Your dataset is small, I suppose that any general purpose optimization method will converge quickly. (In case of non-linear least squares fitting it is also possible to use general purpose optimization algorithm, but it's more common to use the Levenberg-Marquardt algorithm which minimizes sums of squares.)

If you are interested when minimizing absolute deviations instead of squares has theoretical justification see Numerical Recipes, chapter Robust Estimation.

From practical side, the sum of absolute deviations may not have unique minimum. In the trivial case of two points, say, (0,5) and (1,9) and constant function y=a, any value of a between 5 and 9 gives the same sum (4). There is no such problem when deviations are squared.

If minimizing absolute deviations would not work, you may consider heuristic procedure to identify and remove outliers. Such as RANSAC or ROUT.

Problem

I have a set of measured radii (t+epsilon+error) at an equally spaced angles. The model is circle of radius (R) with center at (r, Alpha) with added small noise and some random error values which are much bigger than noise. The problem is to find the center of the circle model (r,Alpha) and the radius of the circle (R). But it should not be too much sensitive to random error (in below data points at 7 and 14). Some radii could be missing therefore the simple mean would not work here. I tried least square optimization but it significantly reacts on error. Is there a way to optimize least deltas but not the least squares of delta in Python? ``` Model: n=36 R=100 r=10 Alpha=2*Pi/6 Data points: [95.85, 92.66, 94.14, 90.56, 88.08, 87.63, 88.12, 152.92, 90.75, 90.73, 93.93, 92.66, 92.67, 97.24, 65.40, 97.67, 103.66, 104.43, 105.25, 106.17, 105.01, 108.52, 109.33, 108.17, 107.10, 106.93, 111.25, 109.99, 107.23, 107.18, 108.30, 101.81, 99.47, 97.97, 96.05, 95.29] ```

Original source