跟进:Mathematica中的TransformedDistribution [英] Follow up to: TransformedDistribution in Mathematica

查看:132
本文介绍了跟进:Mathematica中的TransformedDistribution的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mathematica中的TransformedDistribution 中对Sasha的问题有一个后续问题。 / p>

前一段时间我已经接受了答案,所以我认为将此问题作为一个新问题是很有意义的。



作为答案的一部分,Sasha定义了2个函数:

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

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

PDF函数n似乎可以正常工作:

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

但是,如果我尝试绘制CDF变化:

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

评估似乎从未结束。



我做了以下类似的事情-用NormalDistribution替换上面的StableDistribution:

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

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

CDF和PDF版本的绘图都可以正常工作。

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

这让我感到困惑。显然,一般方法适用于LogNormalNormalCDF情况。另外,LogNormalStablePDF和LogNormalStableCDF几乎相同。实际上,从代码本身来看,CDF版本似乎要比PDF版本少。



所以,我希望有人可以:


  1. 解释为什么LogNormalStableCDF似乎不起作用(至少在我认为合理的时间内,我将尝试将其整夜运行,以查看其是否完成了评估)和


  2. 建议让LogNormalStableCDF更快地工作。


非常感谢,
J。

解决方案

新的分发功能具有惊人的潜力,但它的新颖性也得到了证明。我和其他人遇到了几个错误,希望在以后的错误修复中可以解决。但是,这似乎不是其中之一。



在这种情况下,问题是变量x的定义为实数,同时以整数形式提供了绘图范围。因此,当 Plot 启动时,它将尝试函数未返回的终点,因为没有匹配项。从定义中删除Real使其起作用。



第二个函数起作用是因为绘图范围带有机器精度数字。



准备稍等一下,因为该函数的求值速度很慢。实际上,您必须稍微限制 MaxRecursion ,因为 Plot 太热情了,在这里添加了太多点(可能是由于小规模的误差所致):

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

收益率





生成和花费大约9分钟的时间如您所见,在图形的侧面花了很多点。




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 the 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

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

这篇关于跟进:Mathematica中的TransformedDistribution的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆