Skip to content

Commit

Permalink
Update pareto.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sukjingitsit authored Jun 20, 2024
1 parent 479b7f7 commit 0312baf
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions skpro/distributions/pareto.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
class Pareto(BaseDistribution):
r"""Pareto distribution (skpro native).
The scale :math:`x_m` is represented by the parameter ``xm``,
The scale is represented by the parameter ``scale``,
and the Pareto index (or shape parameter) :math:`\alpha`
by the parameter ``alpha``.
Parameters
----------
xm : float or array of float (1D or 2D), must be positive
scale : float or array of float (1D or 2D), must be positive
scale of the Pareto distribution
alpha : float or array of float (1D or 2D), must be positive
shape of the Pareto distribution
Expand All @@ -29,7 +29,7 @@ class Pareto(BaseDistribution):
-------
>>> from skpro.distributions.pareto import Pareto
>>> n = Pareto(xm=[[1, 1.5], [2, 2.5], [3, 4]], alpha=3)
>>> n = Pareto(scale=[[1, 1.5], [2, 2.5], [3, 4]], alpha=3)
"""

_tags = {
Expand All @@ -40,8 +40,8 @@ class Pareto(BaseDistribution):
"broadcast_init": "on",
}

def __init__(self, xm, alpha, index=None, columns=None):
self.xm = xm
def __init__(self, scale, alpha, index=None, columns=None):
self.scale = scale
self.alpha = alpha

super().__init__(index=index, columns=columns)
Expand All @@ -55,8 +55,8 @@ def _mean(self):
expected value of distribution (entry-wise)
"""
alpha = self._bc_params["alpha"]
xm = self._bc_params["xm"]
mean = np.where(alpha <= 1, np.infty, xm**alpha / (alpha - 1))
scale = self._bc_params["scale"]
mean = np.where(alpha <= 1, np.infty, scale**alpha / (alpha - 1))
return mean

def _var(self):
Expand All @@ -68,9 +68,9 @@ def _var(self):
variance of the distribution (entry-wise)
"""
alpha = self._bc_params["alpha"]
xm = self._bc_params["xm"]
scale = self._bc_params["scale"]
var = np.where(
alpha <= 2, np.infty, xm**2 * alpha / ((alpha - 2) * (alpha - 1) ** 2)
alpha <= 2, np.infty, scale**2 * alpha / ((alpha - 2) * (alpha - 1) ** 2)
)
return var

Expand All @@ -88,8 +88,8 @@ def _pdf(self, x):
pdf values at the given points
"""
alpha = self._bc_params["alpha"]
xm = self._bc_params["xm"]
pdf_arr = alpha * np.power(xm, alpha)
scale = self._bc_params["scale"]
pdf_arr = alpha * np.power(scale, alpha)
pdf_arr /= np.power(x, alpha + 1)
return pdf_arr

Expand All @@ -107,8 +107,8 @@ def _log_pdf(self, x):
log pdf values at the given points
"""
alpha = self._bc_params["alpha"]
xm = self._bc_params["xm"]
return np.log(alpha / x) + alpha * np.log(xm / x)
scale = self._bc_params["scale"]
return np.log(alpha / x) + alpha * np.log(scale / x)

def _cdf(self, x):
"""Cumulative distribution function.
Expand All @@ -124,8 +124,8 @@ def _cdf(self, x):
cdf values at the given points
"""
alpha = self._bc_params["alpha"]
xm = self._bc_params["xm"]
cdf_arr = np.where(x < xm, 0, 1 - np.power(xm / x, alpha))
scale = self._bc_params["scale"]
cdf_arr = np.where(x < scale, 0, 1 - np.power(scale / x, alpha))
return cdf_arr

def _ppf(self, p):
Expand All @@ -142,20 +142,20 @@ def _ppf(self, p):
ppf values at the given points
"""
alpha = self._bc_params["alpha"]
xm = self._bc_params["xm"]
return xm / np.power(1 - p, 1 / alpha)
scale = self._bc_params["scale"]
return scale / np.power(1 - p, 1 / alpha)

@classmethod
def get_test_params(cls, parameter_set="default"):
"""Return testing parameter settings for the estimator."""
# array case examples
params1 = {"xm": [[1, 1.5], [2, 3], [4, 5]], "alpha": 3}
params1 = {"scale": [[1, 1.5], [2, 3], [4, 5]], "alpha": 3}
params2 = {
"xm": 1,
"scale": 1,
"alpha": 3,
"index": pd.Index([1, 2, 5]),
"columns": pd.Index(["a", "b"]),
}
# scalar case examples
params3 = {"xm": 1, "alpha": 2}
params3 = {"scale": 1, "alpha": 2}
return [params1, params2, params3]

0 comments on commit 0312baf

Please sign in to comment.