开发者

Follow up to: TransformedDistribution in Mathematica

I have a follow up question to Sasha's answer of my earlier question at TransformedDistribution in Mathematica.

As I already accepted the answer a while back, I thought it made sense to ask this as a new question.

As part of the answer Sasha defined 2 functions:

LogNormalStableCDF[{alpha_, beta_, gamma_, sigma_, delta_}, x_Real] := 
 Block[{u}, 
  NExpectation[
   CDF[StableDistribution[alpha, beta, gamma, sigma], (x - delta)/u], 
   u \[Distributed] LogNormalDistribution[Log[gamma], sigma]]]

LogNormalStablePDF[{alpha_, beta_, gamma_, sigma_, delta_}, x_Real] := 
 Block[{u}, 
  NExpectation[
   PDF[StableDistribution[alpha, beta, gamma, sigma], (x - delta)/u]/u, 
   u \[Distributed] LogNormalDistribution[Log[gamma], sigma]]]

The PDF function seems to work fine:

Plot[LogNormalStablePDF[{1.5, 1, 1, 0.5, 1}, x], {x, -4, 6}, 
 PlotRange -> All]

But if I try to plot the CDF variation:

Plot[LogNormalStableCDF[{1.5, 1, 1, 0.5, 1}, x], {x, -4, 6}, 
 PlotRange -> All]

The evaluation doesn't seem to ever finish.

I've done something similar with the following - substituting a NormalDistribution for the StableDistribution above:

LogNormalNormalCDF[{gamma_, sigma_, delta_}, x_Real] := 
 Block[{u},
  NExpectation[CDF[NormalDistribution[0, Sqrt[2]], (x - delta)/u], 
   u \[Distributed] LogNormalDistribution[Log[gamma], sigma]]]

LogNormalNormalPDF[{gamma_, sigma_, delta_}, x_Real] := 
 Block[{u}, 
  NExpectation[PDF[NormalDistribution[0, Sqrt[2]], (x - delta)/u]/u, 
   u \[Distributed] LogNormalDistribution[Log[gamma], sigma]]]

The plots of both the CDF and PDF versions work fine.

Plot[LogNormalNormalPDF[{0.01, 0.4, 0.0003}, x], {x, -0.10, 0.10}, PlotRange -> All]
Plot[LogNormalNormalCDF[{0.01, 0.4, 0.0003}, x], {x, -0.10, 0.10}, PlotRange -> All]

This has me puzzled. Clearly the general approach works in the LogNormalNormalCDF case. Also, the LogNormalStablePDF and LogNormalStableCDF are almost identical. In fact from the code itself, the CDF version seems to have to do less than the PDF version.

So, I hoped someone could:

  1. explain why the LogNormalStableCDF doesn't appear to work (at least in what I consider a reasonable time, I'll try running it over night and see if it ever completes the evaluation) and

  2. suggest a way for th开发者_开发问答e get LogNormalStableCDF to work more quickly.

Many thanks, J.


The new distribution functionality has amazing potential, but its newness shows. There are several bugs that I and others have encountered and that hopefully will be dealt with in following bugfixes. However, this seems to be not one of them.

In this case the problem is the definition of variable x as real while providing the plot range in the form of integers. So when Plot starts it tries the end points for which the function returns unevaluated because there's no match. Removing Real from the definition makes it work.

The second function works because the plot range is provided with machine precision numbers.

Be prepared to wait a bit, because the function evaluates pretty slow. In fact, you have to curb MaxRecursion a bit, because Plot gets too enthusiastic and adds way too much points here (maybe due to small scale inaccuracies):

Plot[LogNormalStableCDF[{1.5, 1, 1, 0.5, 1}, x], {x, -4, 6}, 
 PlotRange -> All, PlotPoints -> 10, MaxRecursion -> 4]

yields

Follow up to: TransformedDistribution in Mathematica

It took about 9 minutes to generate and as you can see, it took a lot of points on the flanks of the graph.

Follow up to: TransformedDistribution in Mathematica

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜