From 6e4395dfd486b5bac386c81a5448b2cc151ba54c Mon Sep 17 00:00:00 2001 From: SaiRevanth25 Date: Thu, 6 Jun 2024 21:55:55 +0530 Subject: [PATCH 1/4] initial_commit --- docs/source/api_reference/distributions.rst | 1 + skpro/distributions/__init__.py | 2 + skpro/distributions/loglaplace.py | 77 +++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 skpro/distributions/loglaplace.py diff --git a/docs/source/api_reference/distributions.rst b/docs/source/api_reference/distributions.rst index bffcda485..842a2f399 100644 --- a/docs/source/api_reference/distributions.rst +++ b/docs/source/api_reference/distributions.rst @@ -45,6 +45,7 @@ Continuous support HalfNormal Laplace Logistic + LogLaplace Normal TDistribution Weibull diff --git a/skpro/distributions/__init__.py b/skpro/distributions/__init__.py index 2f5a317b9..e61498c80 100644 --- a/skpro/distributions/__init__.py +++ b/skpro/distributions/__init__.py @@ -17,6 +17,7 @@ "IID", "Laplace", "Logistic", + "LogLaplace", "LogNormal", "Mixture", "Normal", @@ -44,6 +45,7 @@ from skpro.distributions.halfnormal import HalfNormal from skpro.distributions.laplace import Laplace from skpro.distributions.logistic import Logistic +from skpro.distributions.loglaplace import LogLaplace from skpro.distributions.lognormal import LogNormal from skpro.distributions.mixture import Mixture from skpro.distributions.normal import Normal diff --git a/skpro/distributions/loglaplace.py b/skpro/distributions/loglaplace.py new file mode 100644 index 000000000..6b3c2d112 --- /dev/null +++ b/skpro/distributions/loglaplace.py @@ -0,0 +1,77 @@ +# copyright: skpro developers, BSD-3-Clause License (see LICENSE file) +"""Log-Laplace probability distribution.""" + +__author__ = ["SaiRevanth25"] + +import pandas as pd +from scipy.stats import loglaplace, rv_continuous + +from skpro.distributions.adapters.scipy import _ScipyAdapter + + +class LogLaplace(_ScipyAdapter): + r"""Log-Laplace distribution. + + This distribution is univariate, without correlation between dimensions + for the array-valued case. + + The log-Laplace distribution is a continuous probability distribution obtained by + taking the logarithm of the Laplace distribution, commonly used in finance and + hydrology due to its heavy tails and asymmetry. + + The log-Laplace distribution is parametrized by the scale parameter + :math:`\c`, such that the pdf is + + .. math:: f(x) = \frac{c}{2} x^{c-1}, 0= 1 + + The scale parameter :math:`c` is represented by the parameter ``c``. + + Parameters + ---------- + scale : float or array of float (1D or 2D), must be positive + scale parameter of the log-Laplace distribution + index : pd.Index, optional, default = RangeIndex + columns : pd.Index, optional, default = RangeIndex + + Example + ------- + >>> from skpro.distributions.loglaplace import LogLaplace + + >>> ll = LogLaplace(scale=1) + """ + + _tags = { + "capabilities:approx": ["pdfnorm"], + "capabilities:exact": ["mean", "var", "pdf", "log_pdf", "cdf", "ppf"], + "distr:measuretype": "continuous", + "distr:paramtype": "parametric", + "broadcast_init": "on", + } + + def __init__(self, scale, index=None, columns=None): + self.scale = scale + + super().__init__(index=index, columns=columns) + + def _get_scipy_object(self) -> rv_continuous: + return loglaplace + + def _get_scipy_param(self): + scale = self._bc_params["scale"] + return [scale], {} + + @classmethod + def get_test_params(cls, parameter_set="default"): + """Return testing parameter settings for the estimator.""" + # array case examples + params1 = {"scale": [[1, 2], [3, 4]]} + params2 = { + "scale": 1, + "index": pd.Index([1, 2, 5]), + "columns": pd.Index(["a", "b"]), + } + # scalar case examples + params3 = {"scale": 2} + return [params1, params2, params3] From c5535c0e4a81a1b4f5258648692a207b8218b9af Mon Sep 17 00:00:00 2001 From: SaiRevanth25 Date: Thu, 6 Jun 2024 22:12:01 +0530 Subject: [PATCH 2/4] parmeter --- skpro/distributions/loglaplace.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/skpro/distributions/loglaplace.py b/skpro/distributions/loglaplace.py index 6b3c2d112..47666f02c 100644 --- a/skpro/distributions/loglaplace.py +++ b/skpro/distributions/loglaplace.py @@ -19,18 +19,18 @@ class LogLaplace(_ScipyAdapter): taking the logarithm of the Laplace distribution, commonly used in finance and hydrology due to its heavy tails and asymmetry. - The log-Laplace distribution is parametrized by the scale parameter - :math:`\c`, such that the pdf is + The log-Laplace distribution is parametrized by the shape parameter + :math:`\shape`, such that the pdf is .. math:: f(x) = \frac{c}{2} x^{c-1}, 0= 1 - The scale parameter :math:`c` is represented by the parameter ``c``. + The shape parameter :math:`shape` is represented by the parameter ``c`` Parameters ---------- - scale : float or array of float (1D or 2D), must be positive + shape : float or array of float (1D or 2D), must be positive scale parameter of the log-Laplace distribution index : pd.Index, optional, default = RangeIndex columns : pd.Index, optional, default = RangeIndex @@ -39,7 +39,7 @@ class LogLaplace(_ScipyAdapter): ------- >>> from skpro.distributions.loglaplace import LogLaplace - >>> ll = LogLaplace(scale=1) + >>> ll = LogLaplace(shape=1) """ _tags = { @@ -50,8 +50,8 @@ class LogLaplace(_ScipyAdapter): "broadcast_init": "on", } - def __init__(self, scale, index=None, columns=None): - self.scale = scale + def __init__(self, shape, index=None, columns=None): + self.shape = shape super().__init__(index=index, columns=columns) @@ -59,19 +59,19 @@ def _get_scipy_object(self) -> rv_continuous: return loglaplace def _get_scipy_param(self): - scale = self._bc_params["scale"] - return [scale], {} + shape = self._bc_params["shape"] + return [shape], {} @classmethod def get_test_params(cls, parameter_set="default"): """Return testing parameter settings for the estimator.""" # array case examples - params1 = {"scale": [[1, 2], [3, 4]]} + params1 = {"shape": [[1, 2], [3, 4]]} params2 = { - "scale": 1, + "shape": 1, "index": pd.Index([1, 2, 5]), "columns": pd.Index(["a", "b"]), } # scalar case examples - params3 = {"scale": 2} + params3 = {"shape": 2} return [params1, params2, params3] From 7dcc18ae6533c940672f2c4dfd75893caea7aafb Mon Sep 17 00:00:00 2001 From: SaiRevanth25 Date: Thu, 6 Jun 2024 22:24:44 +0530 Subject: [PATCH 3/4] restored_changes --- skpro/distributions/loglaplace.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/skpro/distributions/loglaplace.py b/skpro/distributions/loglaplace.py index 47666f02c..6b3c2d112 100644 --- a/skpro/distributions/loglaplace.py +++ b/skpro/distributions/loglaplace.py @@ -19,18 +19,18 @@ class LogLaplace(_ScipyAdapter): taking the logarithm of the Laplace distribution, commonly used in finance and hydrology due to its heavy tails and asymmetry. - The log-Laplace distribution is parametrized by the shape parameter - :math:`\shape`, such that the pdf is + The log-Laplace distribution is parametrized by the scale parameter + :math:`\c`, such that the pdf is .. math:: f(x) = \frac{c}{2} x^{c-1}, 0= 1 - The shape parameter :math:`shape` is represented by the parameter ``c`` + The scale parameter :math:`c` is represented by the parameter ``c``. Parameters ---------- - shape : float or array of float (1D or 2D), must be positive + scale : float or array of float (1D or 2D), must be positive scale parameter of the log-Laplace distribution index : pd.Index, optional, default = RangeIndex columns : pd.Index, optional, default = RangeIndex @@ -39,7 +39,7 @@ class LogLaplace(_ScipyAdapter): ------- >>> from skpro.distributions.loglaplace import LogLaplace - >>> ll = LogLaplace(shape=1) + >>> ll = LogLaplace(scale=1) """ _tags = { @@ -50,8 +50,8 @@ class LogLaplace(_ScipyAdapter): "broadcast_init": "on", } - def __init__(self, shape, index=None, columns=None): - self.shape = shape + def __init__(self, scale, index=None, columns=None): + self.scale = scale super().__init__(index=index, columns=columns) @@ -59,19 +59,19 @@ def _get_scipy_object(self) -> rv_continuous: return loglaplace def _get_scipy_param(self): - shape = self._bc_params["shape"] - return [shape], {} + scale = self._bc_params["scale"] + return [scale], {} @classmethod def get_test_params(cls, parameter_set="default"): """Return testing parameter settings for the estimator.""" # array case examples - params1 = {"shape": [[1, 2], [3, 4]]} + params1 = {"scale": [[1, 2], [3, 4]]} params2 = { - "shape": 1, + "scale": 1, "index": pd.Index([1, 2, 5]), "columns": pd.Index(["a", "b"]), } # scalar case examples - params3 = {"shape": 2} + params3 = {"scale": 2} return [params1, params2, params3] From 880c9f4fdc55b663f425b4396ad9ab4f12eb4a0a Mon Sep 17 00:00:00 2001 From: SaiRevanth25 Date: Fri, 7 Jun 2024 18:16:01 +0530 Subject: [PATCH 4/4] doc_string --- skpro/distributions/loglaplace.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/skpro/distributions/loglaplace.py b/skpro/distributions/loglaplace.py index 6b3c2d112..390dc7a18 100644 --- a/skpro/distributions/loglaplace.py +++ b/skpro/distributions/loglaplace.py @@ -22,9 +22,11 @@ class LogLaplace(_ScipyAdapter): The log-Laplace distribution is parametrized by the scale parameter :math:`\c`, such that the pdf is - .. math:: f(x) = \frac{c}{2} x^{c-1}, 0= 1 + + .. math:: f(x) = \frac{c}{2} x^{-c-1}, \quad x >= 1 The scale parameter :math:`c` is represented by the parameter ``c``.