Mathematica 中的变换分布

发布于 2024-10-20 03:32:49 字数 2485 浏览 1 评论 0原文

我开发了一些代码来从 LogNormalDistribution 和 StableDistribution 的乘积生成随机变量:

LNStableRV[{\[Alpha]_, \[Beta]_, \[Gamma]_, \[Sigma]_, \[Delta]_},

n_] := Module[{LNRV, SDRV, LNSRV},
  LNRV = RandomVariate[LogNormalDistribution[Log[\[Gamma]], \[Sigma]],
     n];
  SDRV = RandomVariate[
    StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]], n];
  LNRV * SDRV + \[Delta]
  ]

(* Note the delta serves as a location parameter *)

我认为这很好用:

LNStableRV[{1.5, 1, 1, 0.5, 1}, 50000];
Histogram[%, Automatic, "ProbabilityDensity",
          PlotRange -> {{-4, 6}, All}, ImageSize -> 250]
ListPlot[%%, Joined -> True, PlotRange -> All]

现在我想创建一个 TransformedDistribution 沿着同样的路线,这样我就可以在这个自定义分布上使用 PDF[]、CDF[] 等,并轻松地进行绘图和其他分析。

文档中心中的示例推断→TransformedDistribution

\[ScriptCapitalD] =
  TransformedDistribution[
   u v, {u \[Distributed] ExponentialDistribution[1/2],
    v \[Distributed] ExponentialDistribution[1/3]}];

我尝试过这个:

LogNormalStableDistribution[\[Alpha]_, \[Beta]_, \[Gamma]_, \
\[Sigma]_, \[Delta]_] := Module[{u, v},
   TransformedDistribution[
    u * v + \[Delta], {u \[Distributed]
      LogNormalDistribution[Log[\[Gamma]], \[Sigma]],
     v \[Distributed]
      StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]]}]
   ];

\[ScriptCapitalD] = LogNormalStableDistribution[1.5, 1, 1, 0.5, 1]

这给了我这个:

TransformedDistribution[
 1 + \[FormalX]1 \[FormalX]2, {\[FormalX]1 \[Distributed]
   LogNormalDistribution[0, 0.5], \[FormalX]2 \[Distributed]
   StableDistribution[1, 1.5, 1, 1, 0.5]}]

但是当我尝试绘制分布的PDF时,它似乎永远不会完成(当然我没有让它运行超过一分钟或两分钟):

Plot[PDF[\[ScriptCapitalD], x], {x, -4, 6}] (* This should plot over the same range as the Histogram above *)

所以,有一些问题:

我的函数 LogNormalStableDistribution[] 做这种事情有意义吗?

如果是的话,我:

  • 只需要让 Plot[] 运行 更长?
  • 以某种方式改变它?
  • 我该怎么做才能做到 跑得更快?

如果不是:

  • 我需要以不同的方式处理这个问题吗?
  • 使用混合分布?
  • 使用其他东西

I have developed some code to generate random variates from the product of a LogNormalDistribution and a StableDistribution:

LNStableRV[{\[Alpha]_, \[Beta]_, \[Gamma]_, \[Sigma]_, \[Delta]_},

n_] := Module[{LNRV, SDRV, LNSRV},
  LNRV = RandomVariate[LogNormalDistribution[Log[\[Gamma]], \[Sigma]],
     n];
  SDRV = RandomVariate[
    StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]], n];
  LNRV * SDRV + \[Delta]
  ]

(* Note the delta serves as a location parameter *)

I think this works fine:

LNStableRV[{1.5, 1, 1, 0.5, 1}, 50000];
Histogram[%, Automatic, "ProbabilityDensity",
          PlotRange -> {{-4, 6}, All}, ImageSize -> 250]
ListPlot[%%, Joined -> True, PlotRange -> All]

Now I'd like to create a TransformedDistribution along the same lines so that I can use PDF[], CDF[], etc. on this custom distribution and easily do plots and other analysis.

Extrapolating from an example in Documentation CenterTransformedDistribution:

\[ScriptCapitalD] =
  TransformedDistribution[
   u v, {u \[Distributed] ExponentialDistribution[1/2],
    v \[Distributed] ExponentialDistribution[1/3]}];

I've tried this:

LogNormalStableDistribution[\[Alpha]_, \[Beta]_, \[Gamma]_, \
\[Sigma]_, \[Delta]_] := Module[{u, v},
   TransformedDistribution[
    u * v + \[Delta], {u \[Distributed]
      LogNormalDistribution[Log[\[Gamma]], \[Sigma]],
     v \[Distributed]
      StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]]}]
   ];

\[ScriptCapitalD] = LogNormalStableDistribution[1.5, 1, 1, 0.5, 1]

Which gives me this:

TransformedDistribution[
 1 + \[FormalX]1 \[FormalX]2, {\[FormalX]1 \[Distributed]
   LogNormalDistribution[0, 0.5], \[FormalX]2 \[Distributed]
   StableDistribution[1, 1.5, 1, 1, 0.5]}]

But when I try to plot a PDF of the distribution it never seems to finish (granted I haven't let it run more than a minute or 2):

Plot[PDF[\[ScriptCapitalD], x], {x, -4, 6}] (* This should plot over the same range as the Histogram above *)

So, some questions:

Does my function LogNormalStableDistribution[] make sense to do this kind of thing?

If yes do I:

  • Just need to let the Plot[] run
    longer?
  • Change it somehow?
  • What can I do to make it
    run faster?

If not:

  • Do I need to approach this in a different way?
  • Use MixtureDistribution?
  • Use something else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2024-10-27 03:32:49

您使用转换分布的方法很好,但由于分布的 PDF 不以封闭形式存在,因此 PDF[TransformedDistribution[..],x] 不是可行的方法,对于每个 x 将应用符号求解器。最好对你的发行版进行修改以得到 pdf 格式。令 X 为 LogNormal-Stable 随机变量。那么

CDF[LogNormalStableDistribution[params], x] == Probability[X <= x] 

But X==U*V + delta 因此 X<=x 转换为 V<=(x-delta)/U。这给出了

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

关于 x 的微分,我们得到 PDF

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

使用它,这里是图

在此处输入图像描述

Your approach using transformed distribution is just fine, but since distribution's PDF does not exist in closed form, PDF[TransformedDistribution[..],x] is not the way to go, as for every x a symbolic solver will be applied. It is better to massage your distribution to arrive at pdf. Let X be LogNormal-Stable random variate. Then

CDF[LogNormalStableDistribution[params], x] == Probability[X <= x] 

But X==U*V + delta hence X<=x translates into V<=(x-delta)/U. This gives

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

Differentiating with respect to x we get PDF:

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

Using this, here is the plot

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文