Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13156 > unrolled thread
| Started by | JCW <Please.No.EMail@comcast.net> |
|---|---|
| First post | 2013-01-16 06:38 +0000 |
| Last post | 2013-01-18 05:50 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
NonlinearModelFit Problem JCW <Please.No.EMail@comcast.net> - 2013-01-16 06:38 +0000
Re: NonlinearModelFit Problem Frank K <fkampas@gmail.com> - 2013-01-17 04:15 +0000
Re: NonlinearModelFit Problem JCW <Please.No.EMail@comcast.net> - 2013-01-18 05:50 +0000
Re: NonlinearModelFit Problem Ray Koopman <koopman@sfu.ca> - 2013-01-18 05:50 +0000
| From | JCW <Please.No.EMail@comcast.net> |
|---|---|
| Date | 2013-01-16 06:38 +0000 |
| Subject | NonlinearModelFit Problem |
| Message-ID | <kd5htd$jja$1@smc.vnet.net> |
I hope I'm doing something obviously stupid, but I can't figure it
out. I'm trying to fit a list of points [x, z, y] (in a cartesian
coordinate system) that very closely approximate a shallow sphereical
cap. The cap was generated by cutting an approximate sphere with a
plane approximately parallel to the x-z plane so that the cap is
apprximately symmetrical around the y-axis. Thus the cap can be
expressed conveniently as y[x,z], but only less accurately as y[r],
where r = Sqrt[x^2 + z^2], because the original sphere's center was
not exactly on the y-axis. I have very good guesses for the center
location and the radius of curvature; I want more accurate values for
these parameters from the fit.
The following expression incorporating all of the degrees of freedom
will not converge but wanders off toward very large values of all
parameters:
nlm = NonlinearModelFit[distortedNodeLocations,
-Sqrt[fitRadiusOfCurvature^2 - (x - fitxOffset)^2 -
(z - fitzOffset)^2] + fityOffset + radiusOfCurvature +
originalOffset, {{fitRadiusOfCurvature,
radiusOfCurvature}, {fitxOffset, 0.}, {fityOffset, 0.},
{fitzOffset, 0.}}, {x, z}, AccuracyGoal -> 8,
PrecisionGoal -> 12, MaxIterations -> 1000]
(originalOffset is just a constant that forces the spherical cap to
cut the y-axis where I wnat.) In trying to diagnose the problem, I
eventually converted the data l1st to the form, [r, y] (r as defined
above) and successfully fitted it with a simple two-parameter model
(neglecting fitxOffset and fitzOffset):
nlm = NonlinearModelFit[radialFitData,
-Sqrt[fitRadiusOfCurvature^2 - r^2] + fityOffset +
radiusOfCurvature + originalOffset,
{{fitRadiusOfCurvature, radiusOfCurvature},
{fityOffset, 0.}}, r, AccuracyGoal -> 15]
The above model converges very well, yields reasonable values for
fitRadiusOfCurvature and fityOffset, and gives a very low RMS
residual. BUT when I try to fit what should be an essentially
identical model to the original data list, the convergence fails as
describe above for the full model:
nlm = NonlinearModelFit[distortedNodeLocations,
-Sqrt[fitRadiusOfCurvature^2 - x^2 - z^2] + fityOffset +
radiusOfCurvature + originalOffset,
{{fitRadiusOfCurvature, radiusOfCurvature},
{fityOffset, 0.}}, {x, z}, AccuracyGoal -> 8,
PrecisionGoal -> 12, MaxIterations -> 1000]
Even more puzzling, if I constrain the two parameters closely to the
guesses in the above fit, the constrained RMS residual is very much
larger that that obtained when fitting the [r, y] data.
I haven't tried using FindFit yet, as the help files imply that it
uses the same fitting engine. Any suggestions would be greatly
appreciated. -- jclarkw
[toc] | [next] | [standalone]
| From | Frank K <fkampas@gmail.com> |
|---|---|
| Date | 2013-01-17 04:15 +0000 |
| Message-ID | <kd7tt0$q48$1@smc.vnet.net> |
| In reply to | #13156 |
I suggest you use FindMinimum and minimize the sum of the square of the distances of your points from the spherical cap as a function of the parameters describing the cap.
[toc] | [prev] | [next] | [standalone]
| From | JCW <Please.No.EMail@comcast.net> |
|---|---|
| Date | 2013-01-18 05:50 +0000 |
| Message-ID | <kdanqd$3dk$1@smc.vnet.net> |
| In reply to | #13184 |
On Jan 16, 11:15 pm, Frank K <fkam...@gmail.com> wrote: > I suggest you use FindMinimum...< Frank -- FindMinimum works for me! I have no idea why (any background would be most welcome), but in any case it's useful to get a direct look at the function that's actually being minimized. It doesn't have very clean minimum, more like a steep valley with a slight dip in the bottom. Thanks much! -- JCW
[toc] | [prev] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2013-01-18 05:50 +0000 |
| Message-ID | <kdanqi$3dm$1@smc.vnet.net> |
| In reply to | #13184 |
On Jan 16, 8:15 pm, Frank K <fkam...@gmail.com> wrote:
> I suggest you use FindMinimum and minimize the sum of the
> square of the distances of your points from the spherical
> cap as a function of the parameters describing the cap.
That will give the centroid of the data, which could be quite far
from the center of the sphere. I would try something like this.
The initial guess is a closed-form solution for the center that
minimizes the variance of the squared distances of the points from
the center. Then FindMinimum minimizes the variance of the distances
of the points from the center.
data = {{x1,y1,z1},...,{xn,yn,zn}}; m = Mean@data
guess = m + .5 Total[#^2].PseudoInverse[#]&[Transpose@data - m]
Clear[x,y,z]; FindMinimum[
Variance[Norm[#-{x,y,z}]&/@data], Transpose@{{x,y,z},guess}]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web