MathGroup Archive 2001

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

Search the Archive

Help optimizing a slow integral

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28740] Help optimizing a slow integral
  • From: Chris Johnson <cjohnson at shell.faradic.net>
  • Date: Fri, 11 May 2001 03:38:56 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I have the following functions and definitions:

opts = {MinRecursion -> 3, MaxRecursion -> 20};

Needs["Statistics`ContinuousDistributions`"];

low = {1.099425, 1.20904, 1.32989, 1.46313};

high = {1.14795, 1.31107, 1.44351, 1.588769};

fn1[low_, high_, a_, b_] := Min[low[[a]], b^a] + 
    0.97*Max[b^t - high[[a]], 0]; 

fn2[a_, m_, s_, opts_] := 
  Log[NIntegrate[fn1[low, high, a, b]*PDF[LogNormalDistribution[
         m - a*(s^2/2), s], b], {b, 0, Infinity}, opts]/0.97]/a;

which I wrote to calculate a mean for a function.

My first problem is that the integral often throws off errors, but gives
results that are at least reasonable to what I expect.  Try, for example, 
 
fn2[2, .2, .1, opts]

I've come to grips with these errors messages, especially, after getting
rid of many of them by adding the options into the integral.  If anyone
has suggestions as to a better solution I'd be all ears.

But my real question is how could I make this faster, or at least
understand the timing.  In particular, I want to integrate my expectation
function over varying paremeters for the distribution.  Again, another
example...

In[40]:=
Timing[NIntegrate[m-fn2[2,m,s,opts],{m,.1,.2},{s,.15,.2}]/(.1  .05)]

Out[40]=
{9.133 Second,0.00667356}

In[43]:=
NIntegrate[m-fn2[2,m,s,opts],{m,.2,.22},{s,.1,.11}]/(.02*.01)//Timing
Out[43]=
{21.3 Second,0.0144371}

In[44]:=
NIntegrate[m-fn2[2,m,s,opts],{m,.2,.22},{s,.2,.21}]/(.02*.01)//Timing
Out[44]=
{2.955 Second,0.00893668}

Note the more I increase the lower bound of the s parameter, the integral
speeds up exponentially.  Why?  I was hoping to consider much wider bands,
and even add more complexity by including a distribution for the m and s
variables, but time is killing me.  For one run I actually allowed to
finish, it took a half hour.

I tried to use UnitStep to create the functions without Min and Max, but
that didn't seem to help.  Any speed demons out there want to give
suggestions?

Thanks for any help,

Chris



  • Prev by Date: Peculiar behavior of DiscreteDelta
  • Next by Date: Re: Options[] in Mathematica 4.1
  • Previous by thread: Re: Peculiar behavior of DiscreteDelta
  • Next by thread: Summary of list of bits responses