发布于2023-01-21 10:42 阅读(82) 评论(0) 点赞(14) 收藏(5)
正态分布,最早由棣莫弗在二项分布的渐近公式中得到,而真正奠定正态分布地位的,却是高斯对测量误差的研究。测量是人类与自然界交互中必不可少的环节,测量误差的普遍性,确立了正态分布作用范围的广泛性,或许正因如此,正态分布才又被称为Gauss分布。
np.random
中提供了高斯分布、对数高斯分布、标准高斯分布以及逆高斯分布的一元随机数生成器,此外还有多元正态分布生成器。
其中,正态分布、对数正态分布以及逆高斯分布的概率密度函数如下表
normal([loc, scale]) | 1 2 π σ 2 exp [ − ( x − μ ) 2 2 σ 2 ] \frac{1}{\sqrt{2\pi\sigma^2}}\exp[-\frac{(x-\mu)^2}{2\sigma^2}] 2πσ2 1exp[−2σ2(x−μ)2] | 正态分布 |
lognormal([mean, sigma]) | 1 σ x 2 π e − ( ln ( x ) − x ) 2 2 σ 2 \frac{1}{\sigma x\sqrt{2\pi}}e^{-\frac{(\ln(x)-x)^2}{2\sigma^2}} σx2π 1e−2σ2(ln(x)−x)2 | 对数正态分布 |
wald(mean, scale) | λ 2 π x 3 exp [ − λ ( x − μ ) 2 2 μ 2 x ] \sqrt{\frac{\lambda}{2\pi x^3}}\exp[-\frac{\lambda(x-\mu)^2}{2\mu^2x}] 2πx3λ exp[−2μ2xλ(x−μ)2] | 逆高斯分布 |
逆高斯分布的说法容易引发歧义,实际上,逆高斯分布和高斯分布相当于布朗运动研究中的两个视角。在布朗运动中,高斯分布描述的是某一固定时刻距离的分布;而逆高斯分布则是达到固定距离所需时间的分布。
从分布的形式来看,当 λ \lambda λ趋近于无穷大时,逆高斯分布趋向于高斯分布。
特别地,当 μ = λ = 1 \mu=\lambda=1 μ=λ=1时,逆高斯分布又被称为Wald分布,其概率密度函数表达式为
p ( x ) = 1 2 π x 3 exp [ − ( x − 1 ) 2 2 x ] p(x)=\sqrt{\frac{1}{2\pi x^3}}\exp[-\frac{(x-1)^2}{2x}] p(x)=2πx31 exp[−2x(x−1)2]
接下来绘制一下高斯分布和逆高斯分布。
import numpy as np
import matplotlib.pyplot as plt
labels = ["Gaussian distribution",
"Inverse Gaussian distribution"]
dists = [np.random.normal,
np.random.wald]
fig = plt.figure()
for i in range(2):
ax = fig.add_subplot(1,2,i+1)
xs = dists[i](2,1,size=1000)
ax.set_title(labels[i])
plt.hist(xs,100)
plt.show()
效果如下
多元高斯分布的主要参数仍为期望和方差,但所谓多元分布,在坐标层面的表现就是坐标轴的个数,也就是向量维度。所以N个元素对应N维向量,也就有N个期望;而方差则进化为了协方差矩阵,下面可以画个图演示一下
mean = [0, 0] cov = [[0, 1], [10, 0]] x, y = np.random.multivariate_normal(mean, cov, 5000).T def scatter_hist(x, y, ax_histx, ax_histy): ax_histx.tick_params(axis="x", labelbottom=False) ax_histy.tick_params(axis="y", labelleft=False) binwidth = 0.25 xymax = max(np.max(np.abs(x)), np.max(np.abs(y))) lim = (int(xymax/0.25) + 1) * 0.25 bins = np.arange(-lim, lim + binwidth, binwidth) ax_histx.hist(x, bins=bins) ax_histy.hist(y, bins=bins, orientation='horizontal') fig = plt.figure() gs = fig.add_gridspec(2, 2, width_ratios=(4, 1), height_ratios=(1, 4)) ax = fig.add_subplot(gs[1, 0]) ax.scatter(x, y, marker='x') ax_histx = fig.add_subplot(gs[0, 0], sharex=ax) ax_histy = fig.add_subplot(gs[1, 1], sharey=ax) scatter_hist(x, y, ax_histx, ax_histy) plt.show()
效果如下
原文链接:https://blog.csdn.net/m0_37816922/article/details/128051178
作者:丸子
链接:https://www.pythonheidong.com/blog/article/1885275/f3b08ed741237d17f17a/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!