Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add K distribution #19

Closed
ShaofengZou opened this issue May 23, 2022 · 4 comments
Closed

Add K distribution #19

ShaofengZou opened this issue May 23, 2022 · 4 comments

Comments

@ShaofengZou
Copy link

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.

@erdogant
Copy link
Owner

thanks! But with with K-distribution you refer to the compound of two gammas? Which library would you recommend to look at?

@ShaofengZou
Copy link
Author

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:
image

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!

@erdogant
Copy link
Owner

erdogant commented Dec 2, 2022

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.

@erdogant
Copy link
Owner

Closing this one. Let me know if something is missing or needs to be changed regarding the "k" distribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants