Python中Pareto分布的Plot-PDF

2024-10-06 13:50:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个特别的Pareto distribution。比如说,

Pareto(beta=0.00317985, alpha=0.147365, gamma=1.0283)

我从this answer中得到,现在我想在matplotlib中绘制一个概率密度函数(PDF)的图。所以我相信x轴都是正实数,y轴是一样的

我如何准确地获取适当的PDF信息并进行打印以编程方式获取数学PDF函数或坐标是此问题的一项要求。


更新:

drawPDF方法返回一个包含PDF坐标的图形对象。但是,我不知道如何以编程方式访问这些坐标。我当然不想将对象转换为字符串,也不想使用正则表达式提取信息:

In [45]: pdfg = distribution.drawPDF()

In [46]: pdfg
Out[46]: class=Graph name=pdf as a function of X0 implementation=class=GraphImplementation name=pdf as a function of X0 title= xTitle=X0 yTitle=PDF axes=ON grid=ON legendposition=topright legendFontSize=1
 drawables=[class=Drawable name=Unnamed implementation=class=Curve name=Unnamed derived from class=DrawableImplementation name=Unnamed legend=X0 PDF data=class=Sample name=Unnamed implementation=class=Sam
pleImplementation name=Unnamed size=129 dimension=2 data=[[-1610.7,0],[-1575.83,0],[-1540.96,0],[-1506.09,0],[-1471.22,0],[-1436.35,0],[-1401.48,0],[-1366.61,0],...,[-1331.7,6.95394e-06],[2852.57,6.85646e-06]] color
=red fillStyle=solid lineStyle=solid pointStyle=none lineWidth=2]

Tags: 对象namein信息pdf编程方式implementation
1条回答
网友
1楼 · 发布于 2024-10-06 13:50:09

我假设您希望执行不同的任务:

  1. 绘制PDF文件的步骤
  2. 在单个点计算PDF
  3. 为一系列值计算PDF

每个需求都需要不同的脚本。请让我详细介绍一下

我首先创建Pareto发行版:

import openturns as ot
import numpy as np
beta = 0.00317985
alpha = 0.147365
gamma = 1.0283
distribution = ot.Pareto(beta, alpha, gamma)
print("distribution", distribution)

要绘制PDF,请使用drawPDF()方法。这将创建一个ot.Graph,可以直接在Jupyter笔记本或IPython中查看。我们可以使用View强制创建绘图:

import openturns.viewer as otv
graph = distribution.drawPDF()
otv.View(graph)

该图显示:

PDF of Pareto distribution

要在单个点计算PDF,请使用computePDF(x),其中xot.Point()。这也可以是Pythonlisttuple或1D numpyarray,因为转换由OpenTURNS自动管理:

x = 500.0
y = distribution.computePDF(x)
print("y=", y)

前面的脚本打印:

y= 5.0659235352823877e-05

为了计算一系列值的PDF,我们可以使用computePDF(x),其中x是ot.Sample()。这也可以是列表的Pythonlist或2D numpyarray,因为转换是由OpenTURNS自动管理的

x = ot.Sample([[v] for v in np.linspace(0.0, 1000.0)])
y = distribution.computePDF(x)
print("y=", y)

前面的脚本打印:

y= 
 0 : [ 0           ]
 1 : [ 0.00210511  ]
 [...]
 49 : [ 2.28431e-05 ]

相关问题 更多 >