-
-
Notifications
You must be signed in to change notification settings - Fork 9
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 mode method to more distribution classes #636
base: main
Are you sure you want to change the base?
Conversation
@rohanbabbar04 These need to be changed if we are opting to send a tuple for multimodal purposes. |
@aloctavodia Issues have been updated for discrete_weibull; I will use minimize_scale from scipy.optimize since direct calculation for mode in discrete_weibull isn't feasible. For the rest, the mode is calculated as provided in Wikipedia or some reliable sources. |
@@ -107,6 +107,14 @@ def skewness(self): | |||
def kurtosis(self): | |||
return num_kurtosis(self) | |||
|
|||
def mode(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimization routines should be inside optimization module, as they can be potentially reused. The 100 is a magic number, maybe a better option is to use self.ppf(0.9999) or similar. I tried with a couple of examples and the mode is not always right,
@@ -1,6 +1,7 @@ | |||
import numba as nb | |||
import numpy as np | |||
from scipy.stats import skew | |||
from scipy.special import erfcinv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an erfcinv
function implemented in the special submodule
@@ -101,6 +102,14 @@ def entropy(self): | |||
logpdf = self.logpdf(x_values) | |||
return -np.trapz(np.exp(logpdf) * logpdf, x_values) | |||
|
|||
def mode(self): | |||
tau = self.nu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why renamming the variable? I get nan for some combinations of parameters like pz.ExGaussian(0, 1, 10)
@@ -149,6 +149,37 @@ def kurtosis(self): | |||
pdf = self.pdf(x_values) | |||
return np.trapz(((x_values - mean) / std) ** 4 * pdf, x_values) - 3 | |||
|
|||
def mode(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the optimization module. Do you have a reference for this method? It seems to work fine for the values I manually checked. Maybe you can check how the mode is numerically computed here https://github.com/bgctw/logitnorm
@@ -150,6 +150,21 @@ def kurtosis(self): | |||
* ((delta * np.sqrt(2 / np.pi)) ** 4 / (1 - 2 * (delta**2) / np.pi) ** 2) | |||
) | |||
|
|||
def mode(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives the wrong results for large absolute values of alpha. Not sure about the proper fix, but maybe it could be enough to ensure the mode is no smaller than mu (for positive values of alpha) and no larger than mu (for negative values of alpha)
Co-authored-by: Osvaldo A Martin <[email protected]>
Description
This PR targeted #604 and work is in progress.
Implemented Modes