Mathematica 中的变换分布
我开发了一些代码来从 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 Center → TransformedDistribution:
\[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用转换分布的方法很好,但由于分布的
PDF
不以封闭形式存在,因此PDF[TransformedDistribution[..],x]
不是可行的方法,对于每个x
将应用符号求解器。最好对你的发行版进行修改以得到 pdf 格式。令 X 为 LogNormal-Stable 随机变量。那么But
X==U*V + delta
因此X<=x
转换为V<=(x-delta)/U
。这给出了关于
x
的微分,我们得到PDF
:使用它,这里是图
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 everyx
a symbolic solver will be applied. It is better to massage your distribution to arrive at pdf. Let X be LogNormal-Stable random variate. ThenBut
X==U*V + delta
henceX<=x
translates intoV<=(x-delta)/U
. This givesDifferentiating with respect to
x
we getPDF
:Using this, here is the plot