滤波器入门-04(正态分布)

回顾:在滤波器入门-03中学习了离散贝叶斯滤波器,并在一个估计宠物狗的实际案例上进行了代码实践,在最后分析了它的一些缺点:多峰、离散、计算量受问题规模和估计精度影响较大,本节将通过引入正态分布来解决这些痛点。

We desire a unimodal, continuous way to represent probabilities that models how the real world works, and that is computationally efficient to calculate.Gaussian distributions provide all of these features.

本节复习下数理统计中的相关概念(严谨的概念和性质请参考相关专业书籍,此处是感性理解):

  • 随机变量:This combination of values and associated probabilities is called a random variable.(是个变量)
  • 样本空间:The range of values is called the sample space. Space is a mathematical term which means a set with structure.(不唯一,但是样本空间内的元素间的交集必须为空集,并集为全集)
  • 概率分布:The probability distribution gives the probability for the random variable to take any value in a sample space.(和为1)
  • 随机变量的期望值:概率加权值之和
  • 随机变量的方差:取平方是为防止正负抵消,无法反应真实离散程度,相比取绝对值对偏离均值的数值反应敏感,可以更真实的反应数据的分布离散程度,例【6,−2,−3,-1】,【3,−3,−3,3】绝对值度量二者相同均为12/4=3,平方值度量前者为3.5,但是当存在异常值时平方的度量可能会放大其干扰无法反映真实的离散程度

  • 标准差:方差的算数平方根,对于正态分布有3σ(68%,95%,99.7%)原则如下图

alt

  • 高斯分布(正态分布): *A Gaussian is a continuous probability distribution that is completely described with two parameters, the mean (μ) and the variance (). It is defined as:

:*alt

该分布的一些良好的性质: A remarkable property of Gaussian random variables is that the sum of two independent Gaussian random variables is also normally distributed!The product is not Gaussian, but proportional to a Gaussian.There we can say that the result of multipying two Gaussian distributions is a Gaussian function (recall function in this context means that the property that the values sum to one is not guaranteed).This is a key reason why Kalman filters are computationally feasible.

两个高斯随机变量乘积后的均值方差计算公式如下,(和结果就是二者相加即可):

采用高斯分布计算后验概率与不采用代码计算流程对比如下:

xs = np.arange(0, 10, .01)

def mean_var(p):
    x = np.arange(len(p))
    mean = np.sum(p * x,dtype=float)
    var = np.sum((x - mean)**2 * p)
    return mean, var

mean, var = mean_var(posterior)
gaussian(xs, mean, var, normed=False)
#--------------------------------------------
def normalize(p):
    return p / sum(p)

def update(likelihood, prior):
    return normalize(likelihood * prior)#此处需要计算的次数与问题求解规模相关

prior =      normalize(np.array([4, 2, 0, 7, 2, 12, 35, 20, 3, 2]))
likelihood = normalize(np.array([3, 4, 1, 4, 2, 38, 20, 18, 1, 16]))
posterior = update(likelihood, prior)

alt

此例中数组仅有10个数字,但当有数百万个数字时,计算量将迅速上升,而采用高斯分布则只需按照乘积公式计算即可(3次乘法+2次除法)。尽管高斯分布有很好的性质,但它也存在局限性。

  • 它的范围是在正负无穷,但实际情况是部分场景的值只在固定范围内有效。
  • However, a probability distribution can be asymmetrical around the mean.The measure of this is called skew.
  • The tails can be shortened, fatter, thinner, or otherwise shaped differently from an exponential distribution.The measure of this is called kurtosis.

学习链接:https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python

全部评论

相关推荐

07-24 11:54
门头沟学院 Java
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务