- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些时间数据(一天中的几个小时)。我想对这些数据进行冯·米塞斯分布拟合,并找到周期平均值。如何在 python 中使用 scipy 执行此操作?
例如:
from scipy.stats import vonmises
data = [1, 2, 22, 23]
A = vonmises.fit(data)
我不确定如何使用拟合或均值或区间方法获得该数据的分布(可能是区间)和周期平均值。
最佳答案
在查找 VM 发行版方面做得很好。这就是战斗的一半。但除非我误会了 scipy.stats.vonmises docs 中的公式,该公式假设数据以 0 为中心,但情况可能并非如此。所以我们应该构建自己的虚拟机发行版。对于我们的 Vm 分布,我们将确保它在 24 小时范围内具有周期性,而不是传统的 2pi 范围。请参阅下面的代码和注释。另外,我假设您的数据是您看到某些事件发生的时间,如果情况并非如此,您将需要重新调整。
from scipy.optimize import curve_fit
import numpy as np
from matplotlib import pyplot as plt
# Define the von mises kernel density estimator
def circular_von_mises_kde(x,mu,sigma):
# Adjust data to take it to range of 2pi
x = [(hr)*2*np.pi/24 for hr in x]
mu*=2*np.pi/24
sigma*=2*np.pi/24
# Compute kappa for vm kde
kappa = 1/sigma**2
return np.exp((kappa)*np.cos((x-mu)))/(2*np.pi*i0(kappa))
# Assuming your data is occurences of some event at the given hour of the day
frequencies= np.zeros((24))
frequencies[data]=1
hr_data = np.linspace(1,24, 24)
fit_params, cov = curve_fit(circular_von_mises_kde, hr_data, data_to_fit, bounds=(0,24))
plt.plot(hr_data, frequencies, 'k.',label='Raw data')
plt.plot(np.linspace(1,25, 1000), circular_von_mises_kde(np.linspace(1,25, 1000), *fit_params), 'r-',label='Von Mises Fit')
plt.legend()
plt.xlabel('Hours (0-24)')
plt.show()
print('The predicted mean is {mu} and the standard deviation is {sigma}'.format( mu=round(fit_params[0],3), sigma=round(fit_params[1], 3)))
Click to see the result of the above code* 需要注意的是,您可能需要更大的数据集来进行适当的拟合并真正建立人口趋势。
关于python - 如何通过Von Mises分布求周期间隔和周期均值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50693921/
在过去的几天里,我一直在尝试使用 python 绘制圆形数据,方法是构建一个范围从 0 到 2pi 的圆形直方图并拟合 Von Mises 分布。我真正想要实现的是: 具有拟合 Von-Mises 分
我有一个角分布,我想将 von Mises 分布的混合拟合到它 我该怎么做? 我在 R 中找到一个实现,Fit a mixture of von Mises distributions in R 我还
我正在尝试找出定义包裹在半圆上的 von-Mises 分布的最佳方法(我用它来绘制不同浓度的无方向线)。我目前正在使用 SciPy 的 vonmises.rvs()。本质上,我希望能够输入 pi/2
我有一组角度数据,我想将它们拟合到两个冯·米塞斯分布的混合中。如下所示,数据聚集在大约 0 和 ±π 处,因此这种情况需要具有周期性边界。 我尝试使用 movMF 包来拟合这些数据的分布,但它似乎正在
我正在手动计算 Von Mises 分布的参数,并想与 Scipy Von Mises 拟合函数进行比较。 我从拟合函数中得到不一致的结果。 我的两个数据集是 d1 = [0.8pi,0.9pi] 和
我试图找到周期/包裹正态分布 (von Mises) 的均值、方差和置信区间,但在一个时间间隔内(而不是传统的 pi 区间)。我查看了堆栈溢出的解决方案here ,它很接近,但我不确定这正是我正在寻找
我正在尝试拟合 von Mises 分布,来自 scipy ( http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.vonm
迁移到 Rails 3 后,一些 RSpec 测试失败了 例子: Controller : class ProfilesController [:en, :en], :formats=>[:html]
我是一名优秀的程序员,十分优秀!