Slow mathematica program help
- To: mathgroup at smc.vnet.net
- Subject: [mg31023] Slow mathematica program help
- From: Ben Ridenhour <bridenho at bio.indiana.edu>
- Date: Wed, 3 Oct 2001 02:49:10 -0400 (EDT)
- Organization: Indiana University
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
I'm running the simulation that I have below, but it takes an extremely
long time to do only 100 loops. First of all, I notice with each
progressive loop the time Mathematica takes to process the loop gets
exceedingly longer. How can I cure this? Also, I tried doing NIntegrate
with the default method (MultiDimensional), but this seemed to produce
erroneous results. I therefore switched to Method->DoubleExponential,
which seems to produce the expected results but is much slower. Is there
anything to do about this? Any help speeding this up would be greatly
appreciated-- I've tried compiling functions etc... and nothing has seemed
to help, but perhaps I am doing it in the wrong way.
Ben Ridenhour
<<Statistics`DataManipulation`
data={};
vardata={};
Meanx=0;
Meany=1;
Varx=5;
Vary=5;
For[gen=0,gen<100,gen++,
Gaussx=(2 Pi Varx)^(-0.5) Exp[-(x-Meanx)^2/(2 Varx)];
Gaussy=(2 Pi Vary)^(-0.5) Exp[-(y-Meany)^2/(2 Vary)];
Wx=1/(1+Exp[.2(y-x)]);
Wy=1/(1+Exp[-.2(y-x)]);
Wbarx=NIntegrate[Gaussx Gaussy Wx,
{x,-Infinity,Infinity},
{y,-Infinity,Infinity},
Method->DoubleExponential];
Wbary=NIntegrate[Gaussx Gaussy Wy,
{x,-Infinity,Infinity},
{y,-Infinity,Infinity},
Method->DoubleExponential];
data=Append[data,{Meanx,Meany}];
vardata=Append[vardata,{Varx,Vary}];
Meanx=1/Wbarx NIntegrate[x Gaussx Gaussy Wx,
{x,-Infinity,Infinity},
{y,-Infinity,Infinity},
Method->DoubleExponential];
Meany=1/Wbary NIntegrate[y Gaussx Gaussy Wy,
{x,-Infinity,Infinity},
{y,-Infinity,Infinity},
Method->DoubleExponential];
Varx=1/Wbarx NIntegrate[(x-Meanx)^2 Gaussx Gaussy Wx,
{x,-Infinity,Infinity},
{y,-Infinity,Infinity},
Method->DoubleExponential];
Vary=1/Wbary NIntegrate[(y-Meany)^2 Gaussx Gaussy Wy,
{x,-Infinity,Infinity},
{y,-Infinity,Infinity},
Method->DoubleExponential];
];
data=Append[data,{Meanx,Meany}];
vardata=Append[vardata,{Varx,Vary}];
data >> 100genmeandata;
vardata >> 100genvardata;