使用scipy.stats.rv_continuous从正弦偏斜的von mises分布中随机采样

时间:2019-10-25 07:33:54

标签: python scipy

我想从正弦倾斜的冯·米斯分布中随机抽样。
scipy.stats.vonmises
正弦倾斜的冯·米斯:(1 +λ* sin(data-mu))*(冯·米斯分布)

我尝试使用scipy.stats.rv_continuous进行自定义分发。
但是,我不知道如何解决该错误。
我的代码的坏处是什么?
非常感谢您能对此提供帮助。
预先谢谢你。

以下是我的代码。

import numpy as np
import scipy.special as sc
from scipy import stats    

class skewvonmises_gen(stats.rv_continuous):
    def _pdf(self, x, mu, kappa, skewness):
        return (1 + skewness * np.sin(x-mu)) * (np.exp(kappa * np.cos(x-mu)) / (2*np.pi*sc.i0(kappa)))
    def _argcheck(self, mu, kappa, skewness):
        return (-np.pi <= mu <= np.pi) & (kappa > 0) & (-1 <= skewness <= 1)

skewvonmises = skewvonmises_gen(name="skewvonmises")
skewvonmises.rvs(mu=0, kappa=1, skewness=0, size=1)

这将返回以下错误。

C:\Users\username\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py:1686: IntegrationWarning: The integral is probably divergent, or slowly convergent.
  return integrate.quad(self._pdf, _a, x, args=args)[0]
C:\Users\username\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py:1686: IntegrationWarning: The maximum number of subdivisions (50) has been achieved.
  If increasing the limit yields no improvement it is advised to analyze 
  the integrand in order to determine the difficulties.  If the position of a 
  local difficulty can be determined (singularity, discontinuity) one will 
  probably gain from splitting up the interval and calling the integrator 
  on the subranges.  Perhaps a special-purpose integrator should be used.
  return integrate.quad(self._pdf, _a, x, args=args)[0]

0 个答案:

没有答案