【问题标题】:Calibration Asymmetric laplace distribution function校准非对称拉普拉斯分布函数
【发布时间】:2021-03-03 00:27:24
【问题描述】:

我正在尝试将我的数据拟合到此链接 https://en.wikipedia.org/wiki/Asymmetric_Laplace_distribution 中定义的非对称拉普拉斯分布函数。不幸的是,我找不到使用 python 的方法。我试图进行继承,但似乎它不起作用。请问有人有解决办法吗

'''data=np.array([0.936,0.942,0.968,0.981,1.006,1.011,0.996,0.992,0.979,0.976,0.977,0.978,0.987,1.029,1.078,1.188,1.251,1.263,1.284,1.238,1.253,1.219,1.148,1.068,0.971,0.950,0.944,0.941,0.939,0.934,0.947,0,958,1.002,1.043,1.074,1.096,1.095,1.102,1.091,1.074,1.084,1.070,1.060,1.065,1.061,1.045,1.056,1.090,1,121,1.167,1.194,1.196,1.129,1.107,1.114,1.154,1.182,1.144,1.078,0.947,0.872,0.811,0.771,0.756,0.755,0.793,0.837,0.870,0.888,0.859,0.846,0.828,0.808,0.848,0.857,0.891,0.947,0.949,0.963,0.942,0.947,0.922,0.932,0.936,0.922,0.946,0.951,0.978,1.019,1.042,1.054,1.088,1.072,1.080,1.061,1.028,1.028,1.012,1.006,1.040,1.089,1.141,1.156,1.104,1.051,0.995,1.014,1.046,1.058,1.066,1.087,1.129,1.176,1.184,1.107,1.044,1.000,1.004,1.028,1.041,1.008,0.967,0.948,0.923,0.932,0.954,0.958,0.977,1.008,1.024,1.035,1.038,1.008,0.958,0.889,0.815,0.763,0.738,0.804,0.900,0.980,1.052,1.041,.999,0.942,0.928,0.919,0.917,0.950,0.935,0.926,0.923,0.918,0.938,0.946,0.976,1.016,1.041,1.097,1.075,1.050,1.026,0.984,1.000,1.014,1.023,1.022,1.001,0.978,0.969,0.942,0.939,0.933,0.930,0.926,0.919,0.911,0.897,0.904,0.906,0.910,])

class A_Laplace(scipy.stats.rv_continuous):
     def pdf(self, x, location, scale, asym):
            return coef * np.where(x < location,
  np.exp((scale / asym) * (x - location)),
  np.exp(-scale * asym * (x - location))
) 

instance=A_Laplace()
instance.fit(data) 

【问题讨论】:

  • 你能发布你的代码吗?你试过什么?
  • 我刚刚将代码添加到我的问题中。谢谢
  • 如果您发布您的数据,我们可以试一试
  • 我已经发布了数据。实际上,当我使用 instance.fit 时,它给了我一个错误。提前感谢您的帮助

标签: python statistics distribution data-fitting calibration


【解决方案1】:

我相信你必须实现 _pdf 方法以及参数检查。

顺带一提,一些(未经测试!)代码

import numpy as np
from scipy.stats import rv_continuous

class A_Laplace(rv_continuous):
    def _argcheck(self, *params):
        """Should truly check parameters"""
        return True

    def _pdf(self, x, m, λ, κ):
        return np.where(x < m, np.exp((λ/κ) * (x - m)), np.exp(-(λ*κ) * (x - m)))*λ/(κ+1.0/κ)

添加一些绘图代码

ald = A_Laplace()

x = np.linspace(-3.0, 3.0, 101)

q = ald.pdf(x, 0.0, 1., 2.)

plt.plot(x, q, 'r-')
plt.show()

生成的图表就像在 Wiki 中一样

【讨论】:

    猜你喜欢
    • 2014-07-16
    • 1970-01-01
    • 2018-02-26
    • 2021-10-17
    • 2019-09-03
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    相关资源
    最近更新 更多