MathGroup Archive 2012

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

Search the Archive

Re: Clearing all variables and definitions: i.e. "resetting" mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128308] Re: Clearing all variables and definitions: i.e. "resetting" mathematica
  • From: dgolber at aol.com
  • Date: Sat, 6 Oct 2012 01:49:12 -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: <k466qu$a8e$1@smc.vnet.net>

About CleanSlate[]:

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.  Then FindMinimum fits the curve to the data by minimizing "error".

Look at the "memory in use" numbers and the call to CleanSlate.  Before the first call to FindMinimum, the memory in use is about 1 MB.  At this point the CleanSlate utility is loaded, and so this is the state that CleanSlate should return to.

Then FindMinimum is called for the first time.  The memory in use builds up to about 25 MB and does not lessen after FindMinimum exits.

Then CleanSlate[] is called.  It does not find that 25 MB!  The second call to FindMinimum starts with 25 MB ... and stays with 25 MB of memory in use.

Is there any documentation of CleanSlate[]?  My system _has_  CleanSlate[], but it's not described in any of the Help stuff.

(My complaints about mathematica (mine is V4) begin with:  the system doesn't follow elementary documentation rules: What are all the inputs, what are all the outputs ...simple stuff like that ...)

Thanks for whatever help you can give ...

Dave 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]:=
<< Utilities`CleanSlate`
In[13]:=
Print["Before first call, memory usage = ", MemoryInUse[]];
>From In[13]:=
"Before first call, memory usage = "\[InvisibleSpace]1175320
In[14]:=
count = 0;
ret = FindMinimum[error[y, w],
      {y, 20.0, 21.0}, {w, 1.0, 1.1}];
Print[ret];
>From In[14]:=
"count= "\[InvisibleSpace]0\[InvisibleSpace]"   memory in use = "\
\[InvisibleSpace]1189904
>From In[14]:=
"Building prev"
>From In[14]:=
"prev built"
>From In[14]:=
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[14]:=
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[14]:=
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[14]:=
General::"stop": "Further output of \!\(FindMinimum :: \"fmgz\"\) will be \
suppressed during this calculation."
>From In[14]:=
"count= "\[InvisibleSpace]100\[InvisibleSpace]"   memory in use = "\
\[InvisibleSpace]19091072
>From In[14]:=
"count= "\[InvisibleSpace]200\[InvisibleSpace]"   memory in use = "\
\[InvisibleSpace]24690792
>From In[14]:=
{0.00263245, {y -> 19.414, w -> 1.10807}}
In[17]:=
Print["After call, memory usage = ", MemoryInUse[]];

>From In[17]:=
"After call, memory usage = "\[InvisibleSpace]24867112
In[18]:=
CleanSlate[]
>From In[18]:=
"  (CleanSlate) Contexts purged: "\[InvisibleSpace]{"Global`"}
>From In[18]:=
"  (CleanSlate) Approximate kernel memory recovered: "\[InvisibleSpace]"9 Kb"
Out[0]=
{"CleanSlate`", "Global`", "System`"}
In[1]:=
Print["Before second call, memory usage = ", MemoryInUse[]];
>From In[1]:=
"Before second call, memory usage = "\[InvisibleSpace]24857528
In[2]:=
count = 0;
ret = FindMinimum[error[y, w],
      {y, 20.0, 21.0}, {w, 1.0, 1.1}];
Print[ret];
>From In[2]:=
"count= "\[InvisibleSpace]0\[InvisibleSpace]"   memory in use = "\
\[InvisibleSpace]24863144
>From In[2]:=
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[2]:=
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[2]:=
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[2]:=
General::"stop": "Further output of \!\(FindMinimum :: \"fmgz\"\) will be \
suppressed during this calculation."
>From In[2]:=
"count= "\[InvisibleSpace]100\[InvisibleSpace]"   memory in use = "\
\[InvisibleSpace]24972840
>From In[2]:=
"count= "\[InvisibleSpace]200\[InvisibleSpace]"   memory in use = "\
\[InvisibleSpace]24971248
>From In[2]:=
{0.00263245, {y -> 19.414, w -> 1.10807}}
In[5]:=
Print["After call, memory usage = ", MemoryInUse[]];

>From In[5]:=
"After call, memory usage = "\[InvisibleSpace]24995784




  • Prev by Date: Re: Animations in Graphs
  • Next by Date: Re: problem with DSolve and spheroidal harmonics
  • Previous by thread: Re: Kernel exits
  • Next by thread: Re: Clearing all variables and definitions: i.e. "resetting" mathematica