Robust Estimation of Sphere
Show older comments
Hi,
I have a point cloud file which represents a sphere. I want to find out the center and the radius of that sphere using some kind of robust estimation (M-estimation, for example). Can someone please help me regarding this?
Thanks in advance.
Zereen
2 Comments
Walter Roberson
on 9 Oct 2011
When you say "estimation", do you mean you want to do it without examining all of the data points?
Zereen
on 9 Oct 2011
Answers (1)
the cyclist
on 9 Oct 2011
0 votes
Zereen, I am not aware of any way to do this "out of the box", and I did not find anything in the File Exchange. Do you have the Statistics Toolbox? If so, I think you could probably do something close to what you want by using the nlinfit() function, along with the 'Robust' option. Read "doc nlinfit" for details.
12 Comments
Zereen
on 9 Oct 2011
Zereen
on 11 Oct 2011
Sean de Wolski
on 11 Oct 2011
you probably have something like
(magic(5))^rand(5);
and actually want
magic(5).^rand(5)
note the .^ means element by element power as opposed to m(atrix)power
Zereen
on 11 Oct 2011
Zereen
on 11 Oct 2011
the cyclist
on 12 Oct 2011
Are you able to upload the txt file somewhere?
Zereen
on 12 Oct 2011
the cyclist
on 12 Oct 2011
If you breakpoint immediately after your call to nlinfit(), you'll notice that the residual is all zeros at the first iteration, so it has found a solution. The reason it has found a solution is that you have defined the second and third input arguments (y and @hModfun) to be identical. In other words, your fitting function and your empirical data are the same, so the fit is perfect. You have misspecified the inputs.
The basic problem is that your definition of "y" should be purely from your data, but you have included the fitting parameter in there as well. I haven't thought carefully enough about this yet to know how to fix it.
Zereen
on 12 Oct 2011
the cyclist
on 13 Oct 2011
I think your problem boils down to this. This is going to be a bit pedantic, but that is mostly so I get the logic straight in my own head.
You have a series of (x,y,z), which lie on the surface of a sphere, except there is noise so they are not perfect. Given that series, you want to estimate the center and radius of the sphere. Theoretically (i.e. the fit), the radius is a fixed value, r_fit = r0. Empirically, the radius is r_empirical = sqrt((x-x0).^2+(y-y0).^2+(z-z0).^2).
So, in MATLAB you would LIKE to be able to write that as
>> nlinfit (x, sqrt((x-x0).^2+(y-y0).^2+(z-z0).^2), r0, beta0, options); % Won't work.
But you can't (I think), because that mixes the fitting parameters into both the empirical and the fitted part of nlinfit(). However, I believe that it is OK to instead do that fit by subtracting the "r_empirical" term from both pieces, getting
>> nlinfit (x, 0,r0-sqrt((x-x0).^2+(y-y0).^2+(z-z0).^2), beta0, options); % Almost there.
Getting the syntax right, and using your function handle, I think the following does that:
>> [par_out, residual, J, sigma] = nlinfit (x, zeros(size(X)),@hModfun, beta0, options)
I am not 100% sure that that is theoretically correct, but it does give a solution that is very close to your least-squares answer, so I have some confidence in its correctness.
Zereen
on 13 Oct 2011
the cyclist
on 13 Oct 2011
One other comment. One thing that made this tricky is that your (x,y,z) data do not contain clear explanatory and response variables, which would normally be the case when fitting data. It really is more of an optimization problem, but we mashed it into a "fitting framework" to make use of the ability to use robust fitting. (Maybe there was a way to do that via something in the Optimization Toolbox, but I don't know.)
An alternative way to have done the fit would be to say that you have a z_fit and a z_empirical, with (x,y) being the explanatory. However, that puts z on a different footing than (x,y), which I didn't think made sense. But it is also a little odd that "r" is the response variable, given (x,y,z). I am not sure how theoretically strong my suggestions were. Let the buyer beware.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!