distfit
distfit copied to clipboard
Add K distribution
What a really awesome repository !
By the way, K distribution is widely used in the filed of Radar and sonar. It is necessary to estimate the parameters of the K distribution.
Please consider adding this distribution if possible.
thanks! But with with K-distribution you refer to the compound of two gammas? Which library would you recommend to look at?
Sorry, I haven't found any suitable library about K-distribution. And i am a little confused about the definition about K distritbution. In some paper, the K distritbuion is defined as $p(x)=\frac{2 b}{\Gamma(v)}\left(\frac{b x}{2}\right)^{v} K_{v-1}(b x)$. [1][2] While in other paper, the K distribution id defined as $f_{X}(x ; b, v)=\frac{2 b}{\Gamma(v)}(\sqrt{b x})^{v-1} K_{v-1}(2 \sqrt{b x})$. [3][4]
I have code for estimating the parameters of the K distribution of the first formula using the estimation of moments.
Here is the code:
from scipy.special import gamma
from scipy.special import kv as besselk
def k_distribution(x, v, mu):
f_k = 2 / (mu*gamma(v)) * (x / (2*mu))**v * besselk(v-1,x / mu)
return f_k
def k_estimate(data):
x_2= np.mean(data**2)
x_4 = np.mean(data**4)
v = (x_4/(2*(x_2)**2) - 1 )**(-1)
mu = 0.5*np.sqrt(x_2/v)
return v, mu
Here is the reference: [1] Rangaswamy M, Weiner D, Ozturk A. Computer generation of correlated non-Gaussian radar clutter[J]. IEEE Transactions on Aerospace and Electronic Systems, 1995, 31(1): 106-116. [2] Lamont-Smith T. Translation to the normal distribution for radar clutter[J]. IEE Proceedings-Radar, Sonar and Navigation, 2000, 147(1): 17-22. [3] https://en.wikipedia.org/wiki/K-distribution [4] Redding N J. Estimating the parameters of the K distribution in the intensity domain[J]. 1999.
Hope can help you a little and solve my confusion.
Thanks!
It took a while but I created a first implementation of the K-distribution based on your input. You can test the new functionality as following:
Install from github source:
install git+https://github.com/erdogant/distfit
Example:
import numpy as np
from distfit import distfit
X = np.random.normal(0, 2, 1000)
y = [-8, -6, 0, 1, 2, 3, 4, 5, 6]
dist = distfit(distr=['k','t','expon', 't', 'gamma', 'lognorm'])
results = dist.fit_transform(X)
dist.plot()
dist.plot_summary()
In order to test this, it would be great to have data for which we already know it is K-distributed.
Closing this one. Let me know if something is missing or needs to be changed regarding the "k" distribution.