Message Boards Message Boards

0
|
3737 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Memory problem in Mathematica 10

Posted 10 years ago

This is a memory problem posted at stack Exchange with no answers and I also have faced it recently.So I copy the problem and post here for help.

"I'm having a problem with memory. I'm doing nonliner fits of several data lists to a system of differential equations. When I evaluate the "Do" cycle the memory grows with the iteration step up to my RAM memory (8GB). I tried to Clear the functions "sol" and "modelSIR" in each iteration, but even so the kernel keeps everything in memory. What is event more strange is that I ran this in Mathematica 9 and everything was ok. Now I'm running it in Mathematica 10. " The example code is:

DataANotTruncadaShifted[[1]] = {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6,0}, {7, 1}, {8, 4}, {9, 6}, {10, 4}, {11, 5}, {12, 4}, {13, 6}, {14, 11}, {15, 6},{16, 9}, {17, 15}, {18, 18}, {19, 24}, {20, 5},{21, 9}, {22, 8}, {23, 15}, {24, 12}, {25, 12}, {26, 8}, {27, 6}, {28, 0}, {29, 0}, {30, 1}, {31, 0}, {32, 0}, {33, 8}, {34,3}, {35, 6}, {36, 1}, {37, 1}, {38, 1}, {39, 0}, {40, 0},{41, 0}, {42, 0}, {43, 0},{44, 0}, {45, 0}, {46, 0}, {47, 0}, {48, 0}, {49, 0}, {50, 0}, {51, 0}};


AList = Table[{}, {i, 1, 18}];
gamaList = Table[{}, {i, 1, 18}];
t0List = Table[{}, {i, 1, 18}];


Do[
Clear[sol, modelSIR];

sol = ParametricNDSolveValue[
{
beta[t] == (1000*gama)/(1000 - 1) + A*1/(1 + Exp[-(t - t0)/1]),
s'[t] == -((beta[t]*s[t]*i[t])/1000),
i'[t] == (beta[t]*s[t]*i[t])/1000 - gama*i[t],
r'[t] == gama*i[t],
s[0] == 1000 - 1, i[0] == 1, r[0] == 0}, {s, i, r}, {t, 0, 53}, {A, gama, t0}];
modelSIR[A_, gama_, t0_][t_] := Through[sol[A, gama, t0][[2]][t],List]/;And@@NumericQ/@{A,gama,t0,t};


fit = NonlinearModelFit[DataANotTruncadaShifted[[n]], {modelSIR[A, gama, t0][t],0.1 < A < 5, 1 < gama < 5, 0 < t0 < 40}, {A, gama, t0}, t, MaxIterations -> 200, Method -> {"NMinimize"}];


Afit = fit[[1]][[2]][[1]][[2]];
gamafit = fit[[1]][[2]][[2]][[2]];
t0fit = fit[[1]][[2]][[3]][[2]];

AList[[n]] = Afit;
gamaList[[n]] = gamafit;
t0List[[n]] = t0fit;

, {n, {1, 3, 4}}]

I hope to know why the same fit code induce different memory occupy situation and how to solve the problem in version 10. Thanks!

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

Group Abstract Group Abstract