MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Kernel exits

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128306] Re: Kernel exits
  • From: dgolber at aol.com
  • Date: Sat, 6 Oct 2012 01:48:32 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k2s2re$dq5$1@smc.vnet.net>

Mathematica 4 running on Windows XP.

The notebook below begins with $HistoryLength=0.  It fits a 2-parameter curve (a simple Bezier curve) to some data.

The module "error" finds the total sum-of-squares of distances from the data points to a curve.  The main cell (not a module) uses FindMinimum to vary the curve parameters to minimize the error.

There are lots of printings of MemoryInUse.  We see MemoryInUse quickly build up and then not change much.

After a (large) number of repetitions, the kernel exits. 

Note that at the first call, the memory in use builds up from about 1 Mbyte to about 25 Mbyte, and stays at about 25 Mbyte, even though FindMinimum has exited and then begun a new invocation.  It seems pretty clear that FindMinimum has taken some meory and not given it back when it exits.

What is going on?

Thank you
David Golber


In[1]:=
$HistoryLength = 0;
In[2]:=
dsq[p_, q_] := Module[{v}, v = p - q; Return[v.v]];
In[3]:=
data = {{-1.`, 0.07271879311326668`},
{-0.9795918367346939`, 0.40795711960412273`},
{-0.9591836734693877`, 0.7493968681691019`},
{-0.9387755102040817`, 1.0969831944328101`},
{-0.9183673469387755`, 1.4455797049857155`},
{-0.8979591836734694`, 1.7933577858764531`},
{-0.8775510204081632`, 2.1407781653548907`},
{-0.8571428571428571`, 2.4892086871775314`},
{-0.8367346938775511`, 2.835059096420477`},
{-0.8163265306122449`, 3.1747813234745452`},
{-0.7959183673469388`, 3.5099065199869566`},
{-0.7755102040816326`, 3.838416824535938`},
{-0.7551020408163265`, 4.160416099694797`},
{-0.7346938775510204`, 4.476709556785695`},
{-0.7142857142857143`, 4.784664350286133`},
{-0.6938775510204082`, 5.087323728777496`},
{-0.673469387755102`, 5.38696253472903`},
{-0.6530612244897959`, 5.6798465046806585`},
{-0.6326530612244898`, 5.964713365415807`},
{-0.6122448979591837`, 6.238632239548857`},
{-0.5918367346938775`, 6.501620953518743`},
{-0.5714285714285714`, 6.75656172280596`},
{-0.5510204081632653`, 7.002600506634537`},
{-0.5306122448979592`, 7.239968897142224`},
{-0.5102040816326531`, 7.467505798949419`},
{-0.4897959183673469`, 7.688899842449843`},
{-0.46938775510204084`, 7.895548159341792`},
{-0.4489795918367347`, 8.097377347460679`},
{-0.42857142857142855`, 8.2893341746341`},
{-0.40816326530612246`, 8.476144299078989`},
{-0.3877551020408163`, 8.652889973777224`},
{-0.3673469387755102`, 8.817374903757845`},
{-0.3469387755102041`, 8.976924242334949`},
{-0.32653061224489793`, 9.119591134252524`},
{-0.30612244897959184`, 9.248576791309134`},
{-0.2857142857142857`, 9.369588023769005`},
{-0.2653061224489796`, 9.482297547178607`},
{-0.24489795918367346`, 9.589139190122037`},
{-0.22448979591836735`, 9.689364983113595`},
{-0.20408163265306123`, 9.781452292825708`},
{-0.1836734693877551`, 9.860153881813591`},
{-0.16326530612244897`, 9.923011791745626`},
{-0.14285714285714285`, 9.976018300997982`},
{-0.12244897959183673`, 10.02452888876957`},
{-0.10204081632653061`, 10.070756998999077`},
{-0.08163265306122448`, 10.114970754465642`},
{-0.061224489795918366`, 10.15451548515944`},
{-0.04081632653061224`, 10.18522338591307`},
{-0.02040816326530612`, 10.202365464896314`},
{0.`, 10.208468465393292`},
{0.02040816326530612`, 10.202365464896314`},
{0.04081632653061224`, 10.18522338591307`},
{0.061224489795918366`, 10.15451548515944`},
{0.08163265306122448`, 10.114970754465642`},
{0.10204081632653061`, 10.070756998999077`},
{0.12244897959183673`, 10.02452888876957`},
{0.14285714285714285`, 9.976018300997982`},
{0.16326530612244897`, 9.923011791745626`},
{0.1836734693877551`, 9.860153881813591`},
{0.20408163265306123`, 9.781452292825708`},
{0.22448979591836735`, 9.689364983113595`},
{0.24489795918367346`, 9.589139190122037`},
{0.2653061224489796`, 9.482297547178607`},
{0.2857142857142857`, 9.369588023769005`},
{0.30612244897959184`, 9.248576791309134`},
{0.32653061224489793`, 9.119591134252524`},
{0.3469387755102041`, 8.976924242334949`},
{0.3673469387755102`, 8.817374903757845`},
{0.3877551020408163`, 8.652889973777224`},
{0.40816326530612246`, 8.476144299078989`},
{0.42857142857142855`, 8.2893341746341`},
{0.4489795918367347`, 8.097377347460679`},
{0.46938775510204084`, 7.895548159341792`},
{0.4897959183673469`, 7.688899842449843`},
{0.5102040816326531`, 7.467505798949419`},
{0.5306122448979592`, 7.239968897142224`},
{0.5510204081632653`, 7.002600506634537`},
{0.5714285714285714`, 6.75656172280596`},
{0.5918367346938775`, 6.501620953518743`},
{0.6122448979591837`, 6.238632239548857`},
{0.6326530612244898`, 5.964713365415807`},
{0.6530612244897959`, 5.6798465046806585`},
{0.673469387755102`, 5.38696253472903`},
{0.6938775510204082`, 5.087323728777496`},
{0.7142857142857143`, 4.784664350286133`},
{0.7346938775510204`, 4.476709556785695`},
{0.7551020408163265`, 4.160416099694797`},
{0.7755102040816326`, 3.838416824535938`},
{0.7959183673469388`, 3.5099065199869566`},
{0.8163265306122449`, 3.1747813234745452`},
{0.8367346938775511`, 2.835059096420477`},
{0.8571428571428571`, 2.4892086871775314`},
{0.8775510204081632`, 2.1407781653548907`},
{0.8979591836734694`, 1.7933577858764531`},
{0.9183673469387755`, 1.4455797049857155`},
{0.9387755102040817`, 1.0969831944328101`},
{0.9591836734693877`, 0.7493968681691019`},
{0.9795918367346939`, 0.40795711960412273`},
{1.`, 0.07271879311326668`}};
In[4]:=
bez[n_, i_, t_] := Binomial[n, i]((1 - t)^(i))( t^(n - i));
In[5]:=
t =.
In[6]:=
b1[t_] = bez[2, 2, t];
In[7]:=
b2[t_] = bez[2, 1, t];
In[8]:=
b3[t_] = bez[2, 0, t];
In[9]:=
Remove[t, y, w]
In[10]:=
curve[t_, y_, w_] = (b1[t]{-1, 0} + w b2[t]{0, y} + b3[t]{1, 0})/(b1[t] +=
 w b2[t] + b3[t]);
In[11]:=
error[y_, w_] :=
    Module[
      {i, j, dist, least, sum, ret, t, numStarts = 50},
      If[Mod[count, 100] == 0, Print["count= ", count, "   memory in use = ", MemoryInUse[]]];
      count = count + 1;
      If[ValueQ[prev] == False || Length[prev] != Length[data],
        Print["Building prev"];
        prev = Table[Infinity, {Length[data]}];
        For[i = 1, i <= Length[data], i++,
          least = Infinity;
          For[j = -numStarts, j <= numStarts - 1, j++,
            dist = dsq[data[[i]], curve[j/numStarts, y, w]];
            If[dist < least,
              least = dist;
              prev[[i]] = N[j/numStarts];
              ]; (* If this is a better values *)
            ]; (* Loop over  j *)
          ]; (* Loop over data *)
        Print["prev built"];
        ];
      sum = 0;
      For[i = 1, i <= Length[data], i++,
        ret = FindMinimum[dsq[data[[i]], curve[t, y, w]], {t, prev[[i]]}];
        prev[[i]] = t /. ret[[2]];
        sum = sum + ret[[1]];
        ];
      Return[sum];
      ];
>From In[11]:=
General::"spell1": "Possible spelling error: new symbol name \"\!\(sum\)\" is \
similar to existing symbol \"\!\(Sum\)\"."
>From In[11]:=
General::"spell1": "Possible spelling error: new symbol name \"\!\(count\)\" \
is similar to existing symbol \"\!\(Count\)\"."
In[12]:=
For[nnn = 1, nnn <= 1000, nnn++,
    Print["Beginning iteration ", nnn];
    Print["Before call, memory usage = ", MemoryInUse[]];
    count = 0;
    ret = FindMinimum[error[y, w],
        {y, 20.0, 21.0},
{w, 1.0, 1.1}];
    Print["After call, memory usage = ", MemoryInUse[]];
    ];
>From In[12]:=
"Beginning iteration 1
>From In[12]:=
"Before call, memory usage = 1154680
>From In[12]:=
"count= 0   memory in use =  1168080
>From In[12]:=
"Building prev"
>From In[12]:=
"prev built"
>From In[12]:=
FindMinimum::"fmgz": "Encountered a vanishing gradient. The result returned\
may not be a minimum; it may be a maximum or a saddle point."
>From In[12]:=
FindMinimum::"fmgz": "Encountered a vanishing gradient. The result returned\
may not be a minimum; it may be a maximum or a saddle point."
>From In[12]:=
FindMinimum::"fmgz": "Encountered a vanishing gradient. The result returned\
may not be a minimum; it may be a maximum or a saddle point."
>From In[12]:=
General::"stop": "Further output of \!\(FindMinimum :: \"fmgz\"\) will be \
suppressed during this calculation."
>From In[12]:=
"count= 100   memory in use =  19057872
>From In[12]:=
"count= 200   memory in use =  24714864
>From In[12]:=
"After call, memory usage = 24862696
>From In[12]:=
"Beginning iteration 2
>From In[12]:=
"Before call, memory usage = 24862696
>From In[12]:=
"count= 0   memory in use =  24867136
>From In[12]:=
"count= 100   memory in use =  24912784
>From In[12]:=
"count= 200   memory in use =  24900696
>From In[12]:=
"After call, memory usage = 24899312
>From In[12]:=
"Beginning iteration 3
>From In[12]:=
"Before call, memory usage = 24899312
>From In[12]:=
"count= 0   memory in use =  24903760
>From In[12]:=
"count= 100   memory in use =  25028288
>From In[12]:=
"count= 200   memory in use =  24895624
>From In[12]:=
"After call, memory usage = 24914392
>From In[12]:=
"Beginning iteration 4
>From In[12]:=
"Before call, memory usage = 24914392
>From In[12]:=
"count= 0   memory in use =  24918824
>From In[12]:=
"count= 100   memory in use =  24981728
>From In[12]:=
"count= 200   memory in use =  24982880
>From In[12]:=
"After call, memory usage = 24977592
>From In[12]:=
"Beginning iteration 5
>From In[12]:=
"Before call, memory usage = 24977592
>From In[12]:=
"count= 0   memory in use =  24982096
>From In[12]:=
"count= 100   memory in use =  24930888
>From In[12]:=
"count= 200   memory in use =  24991360
>From In[12]:=
"After call, memory usage = 24904504
>From In[12]:=
"Beginning iteration 6
>From In[12]:=
"Before call, memory usage = 24904504
>From In[12]:=
"count= 0   memory in use =  24908976
>From In[12]:=
"count= 100   memory in use =  24927792
>From In[12]:=
"count= 200   memory in use =  25038344
>From In[12]:=
"After call, memory usage = 25023960
>From In[12]:=
"Beginning iteration 7
>From In[12]:=
"Before call, memory usage = 25023960
>From In[12]:=
"count= 0   memory in use =  25028384
>From In[12]:=
"count= 100   memory in use =  24973640
>From In[12]:=
"count= 200   memory in use =  24955000
>From In[12]:=
"After call, memory usage = 24945136
>From In[12]:=
"Beginning iteration 8
>From In[12]:=
"Before call, memory usage = 24945136
>From In[12]:=
"count= 0   memory in use =  24949576
>From In[12]:=
"count= 100   memory in use =  24885728
>From In[12]:=
"count= 200   memory in use =  24941544
>From In[12]:=
"After call, memory usage = 24918472
>From In[12]:=
"Beginning iteration 9
>From In[12]:=
"Before call, memory usage = 24918472
>From In[12]:=
"count= 0   memory in use =  24922920
>From In[12]:=
"count= 100   memory in use =  24926696
>From In[12]:=
"count= 200   memory in use =  24858472
>From In[12]:=
"After call, memory usage = 24868864
>From In[12]:=
"Beginning iteration 10
>From In[12]:=
"Before call, memory usage = 24868864
>From In[12]:=
"count= 0   memory in use =  24873360
>From In[12]:=
"count= 100   memory in use =  24963496
>From In[12]:=
"count= 200   memory in use =  25066768
>From In[12]:=
"After call, memory usage = 25033928
>From In[12]:=
"Beginning iteration 11
>From In[12]:=
"Before call, memory usage = 25033928
>From In[12]:=
"count= 0   memory in use =  25038400
>From In[12]:=
"count= 100   memory in use =  24931376
>From In[12]:=
"count= 200   memory in use =  24881632
>From In[12]:=
"After call, memory usage = 24814768
>From In[12]:=

<<< Much similar deleted >

>From In[12]:=
"Beginning iteration 711
>From In[12]:=
"Before call, memory usage = 24844568
>From In[12]:=
"count= 0   memory in use =  24849072
>From In[12]:=
"count= 100   memory in use =  24976984
>From In[12]:=
"count= 200   memory in use =  24951568
>From In[12]:=
"After call, memory usage = 24949632
>From In[12]:=
"Beginning iteration 712
>From In[12]:=
"Before call, memory usage = 24949632
>From In[12]:=
"count= 0   memory in use =  24954096
>From In[12]:=
"count= 100   memory in use =  24880688
>From In[12]:=
"count= 200   memory in use =  24945376
>From In[12]:=
"After call, memory usage = 24891664
>From In[12]:=
"Beginning iteration 713
>From In[12]:=
"Before call, memory usage = 24891664
>From In[12]:=
"count= 0   memory in use =  24896144
>From In[12]:=
"count= 100   memory in use =  24820512

<This ran over night.
When I looked it in the morning, it had stopped, kernel had exited.
The above was the last line of output.
>







  • Prev by Date: Re: Problem in solving nonlinear Differential Equation
  • Next by Date: Re: Animations in Graphs
  • Previous by thread: Re: Problem in solving nonlinear Differential Equation
  • Next by thread: Re: Clearing all variables and definitions: i.e. "resetting" mathematica