本文介绍了可以在Mathematica中扩展PDF,CDF,FindDistributionParameters等的功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用Mathematica的新统计和数据分析功能进行越来越多的工作。

I've started doing more and more work with the new Mathematica statistics and data analysis features.

我在星期二参加了使用Mathematica进行统计和数据分析在线研讨会(精彩的演讲,我强烈推荐),但是我遇到了一些问题希望这个论坛上的某个人可以花点时间考虑。

I attended the "Statistics & Data Analysis with Mathematica" online seminar on Tuesday (great presentation, I highly recommend it) but I've run into some problems that I hope someone on this forum might have a few moments to consider.

我创建了一个相当广泛的笔记本来简化我的数据分析,称为 AnalysisNotebook。它输出一系列的图表和数据,包括:直方图, PDF CDF 图,QQ图,要研究的图尾部拟合,假设检验数据等。

I've created a rather extensive notebook to streamline my data analysis, call it "AnalysisNotebook". It outputs an extensive series of charts and data including: histograms, PDF and CDF plots, Q-Q plots, plots to study tail fit, hypothesis test data, etc.

只要我继续使用Mathematica的现成发行版,此方法就很好用,并且对于简单的<$ c $对于这些Mathematica,c> MixtureDistribution 甚至 ParameterMixtureDistribution s都可以算出时刻,而 PDF CDF FindDistributionParameters 等,将混合物分成几部分。

This works great as long as I stay with Mathematica's off-the-shelf distributions and probably works fine for simple MixtureDistributions and even ParameterMixtureDistributions as for these Mathematica can likely figure out the moments and PDF and CDF, FindDistributionParameters, etc by breaking the mixtures down into pieces.

尝试定义甚至使用简单的 TransformedDistribution

I run into trouble when I attempt to define and use even a simple TransformedDistribution i.e.,

LogNormalNormalDistribution[Gamma_, Sigma_, Delta_] := 
  TransformedDistribution[ u*v + Delta, 
   {Distributed[ u, LogNormalDistribution[ Log[Gamma], Sigma] ],  
    Distributed[ v, NormalDistribution[0, Sqrt[2]]}
   ];

我想按照这种变换分布来做很多事情。我感谢类似这样的挑战(我在这个论坛上已经学到了一些东西-谢谢大家):

I'd like to do a lot of things along the lines of such Transformed Distributions. I appreciate the challenge something like this presents (some of which I've learned on this forum - thank you all):


  • 他们可能不会有封闭的表格;

  • PDF CDF 计算可能需要插值,工作-arounds或自定义方法;

  • FindDistributionParameters DistributionFitTest 知道如何处理这种事情。

  • They may not have closed forms;
  • PDF and CDF calculation may need interpolation, work-arounds, or custom approaches;
  • FindDistributionParameters and DistributionFitTest won't know how to deal with this kind of thing.

基本上,人们想要使用的标准东西真的/不可以

Basically the standard things one would want to use really don't/can't work and one can't fairly expect them to do so.

一个人可以编写自定义代码来完成这些事情(同样,这个论坛对我有很大帮助),但是随后将自定义替代方案的所有复杂性纳入我的AnalysisNotebook中,这似乎很愚蠢。 AnalysisNotebook将随每个新的自定义函数一起增长。

One can write custom code to do these sorts of things (again this forum has helped me a lot), but then incorporating all of the complexity of custom alternatives into my AnalysisNotebook, just seems silly. The AnalysisNotebook would grow with each new custom function.

如果我可以编写 PDF的自定义版本,这将极大地帮助我。

It would help me immensely in this effort if I could write my custom versions of PDF, CDF, FindDistributionParameters, DistributionFitTest and anything else I might need to standards that the more general built in versions would simply call seamlessly. This way, something like my AnalysisNotebook could remain simple and uncluttered, a standard component in my tool box. I could spend my time working on the math rather than plumbing, if you take my meaning.

要弄清楚我的意思,类似于如何定义版本的为了执行不同的功能(使用不同数量的参数或其他类型的情境感知),Mathematica必须对使用分布作为参数的函数执行类似的操作,以了解对特定内置分布使用哪种解决方案。我希望能够添加或扩展 PDF [] CDF [] FindDistributionParameters [] DistributionFitTest [] 以及该级别的相关功能-为自定义发行版及其所需的支持代码添加功能,

To clarify what I mean by this, similar to how one can define versions of a function to do different things (use different numbers of arguments or other kinds of situational awareness), Mathematica must do something similar for the functions that use distributions as arguments to know which solution to use for a particular built-in distribution. I want the ability to add or extend the functionality of PDF[], CDF[], FindDistributionParameters[], DistributionFitTest[] and related functions at that level -- to add functionality for custom distributions and their required supporting code, which the built in functions would/could call seamlessly.

也许只是一个梦想,但是如果有人知道我可以采用这种方法,我将非常感谢您的反馈。

Perhaps just a dream, but if anyone knows of any way I could approach this, I'd very much appreciate your feedback.

编辑-我遇到的这类问题:

以下代码永远不会完成执行

The following code never completes execution

r1 = RandomVariate[LogNormalNormalDistribution[0.01, 0.4, 0.0003], 1000];
FindDistributionParameters[r1, LogNormalNormalDistribution[gamma, sigma, delta]]

要解决此问题我写了以下函数

To work around this I wrote the following function

myLNNFit[data_] := Module[{costFunction, moments}, 
    moments = Moment[EmpiricalDistribution[data], #] & /@ Range[5]; 
    costFunction[gamma_, sigma_, delta_] = 
    Sqrt@Total[((Moment[LogNormalNormalDistribution[gamma, sigma, delta],#]&/@Range[5]) - moments)^2]; 
    NMinimize[{costFunction[gamma, sigma, delta], gamma > 0, sigma > 0}, {gamma, sigma, delta}] ]

此功能本身可以正常工作,但不能

This works fine by itself, but doesn't play well with everything else.

推荐答案

您可以使用 TagSet 指定要与定义关联的符号。即使 PDF 受保护的,这也使您可以定义分布的 PDF $ c>。这是一个简单的例子。请注意, TriangleWave 是内置符号,而 TriangleDistribution 是我刚刚编写的。失败:

You can use TagSet to specify the symbol to which you want to associate a definition. This lets you define the PDF of a distribution even though PDF is Protected. Here's a trivial example. Note that TriangleWave is a built-in symbol, and TriangleDistribution is something I just made up. This fails:

PDF[TriangleDistribution[x_]] := TriangleWave[x]

这有效:

TriangleDistribution /: PDF[TriangleDistribution[x_]] := TriangleWave[x]

现在您可以做到:

Plot[PDF[TriangleDistribution[x]], {x, 0, 1}]

这篇关于可以在Mathematica中扩展PDF,CDF,FindDistributionParameters等的功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:24