Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.1K Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Why is FindMinimum running out of memory?

Posted 10 years ago

Hello all,

The attached notebook and data file demonstrate a problem with FindMinimum. The data is a set of points which to a great extent lie on a circle. The calculation attempts to find the center of the circle by locating the point which is most nearly equidistant from the data points. The method used is to construct a function which accepts a candidate point as an argument, and returns the standard deviation of the computed list of distances from the candidate to each of the data points. The rationale is that the point with the smallest standard deviation of distances is central.

There are a lot of data points, so the calculation of each function value is lengthy, and requires a reasonable amount of memory. But FindMinimum sees a simple function which accepts two numbers and returns a third. That's all. However, as FindMinimum executes memory as reported by Task Manager grows steadily until it consumes all 8GB available and Windows asks to shut down the kernel.

Can any of you tell me what is consuming all this memory? (To execute, put the CSV file in the same directory as the notebook.)

Thanks and kind regards, David

Attachments:
POSTED BY: David Keith
4 Replies

I guess the issue with memory leak is from continuously created large expression during the optimization process. You may try the StepMonitor to show the internal step. My best estimate is that when the function takes the derivative and hessian matrix of the huge expression, things just grow exponentially.

 FindMinimum[Exp[x] + 1/x, {x, 1},  StepMonitor :> Print["Step to x = ", x]] 
POSTED BY: Shenghui Yang
Posted 10 years ago
POSTED BY: David Keith
POSTED BY: Shenghui Yang

If you rewrite the equation of the a circle at {x0,y0} with radius R0 in the following form:

x^2 + y^2 = (x0^2 + y0^2 -R0^2)  + (2* x0) * x  +(2*y0) * y  (* z = c + a * x + b * y *)

where {x,y} are points on the circumference. You can use the linear model fit to find the circle

In[23]:= (reg={2 #1,2 #2,#2^2+#1^2}&@@@points)//Short
Out[23]//Short= {{124,1042,275285},{132,1030,269581},{132,1044,276840},<<50295>>,{1756,1016,1028948},{1760,968,1008656}}

In[28]:= lm=LinearModelFit[reg,{1,x,y},{x,y}]
Out[28]= FittedModel[-323255.+471.705 x+501.105 y]

Best model fit by least square:

In[25]:= bf=lm["BestFitParameters"]
Out[25]= {-323255.,471.705,501.105}
In[26]:= exp=(x-#2)^2+(y-#3)^2-#1-#2^2-#3^2&@@bf
Out[26]= -150357.+(-471.705+x)^2+(-501.105+y)^2

The code is modified from this stack exchange page

POSTED BY: Shenghui Yang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard