简体   繁体   English

绘制截断正态分布

[英]Plotting truncated normal distribution

I am trying to plot a truncated Gaussian distribution (using scipy) with a mean of 0.5 , and a standard distribution of 1.0 . 我正在尝试绘制平均值为0.5且标准分布为1.0截断的高斯分布(使用scipy) The distribution is truncated to be only in the interval (0,1) . 分布被截短为仅在时间间隔(0,1)

x = np.linspace(0,1,100)
dist=truncnorm(a=0,b=1,loc=0.5, scale = 1.0)
plt.plot(x, dist.pdf(x), 'k-', lw=2, label='normalised truncated Gaussian')

However I get this instead: 但是我得到了这个:

在此处输入图片说明

Everything after x=0.5 seems normal but below that you get a sudden dip to zero. x=0.5之后的所有内容似乎都很正常,但在此之下,您会突然下降到零。 However the distribution should only be zero outside of (0,1) . 但是,分布应仅在(0,1)之外为零。 What is going on and how do I fix it? 怎么回事,如何解决?

You are telling it to plot that way with loc which shifts the plot. 您正在告诉它使用loc这种绘制,从而使绘图移动。

dist=truncnorm(a=0,b=1,loc=0.5, scale = 1.0) should be dist=truncnorm(a=0,b=1, scale = 1.0) to get the standard plot. dist=truncnorm(a=0,b=1,loc=0.5, scale = 1.0)应该是dist=truncnorm(a=0,b=1, scale = 1.0)以获取标准图。

From the source code on truncnorm(): 从truncnorm()的源代码中

For a uniform distribution MLE, the location is the minimum of the data, and the scale is the maximum minus the minimum. 对于均匀分布MLE,位置是数据的最小值,小数位数是最大值减去最小值。 (Line 6570) (6570行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM