From 1002f7ec94271e5a52f4ad68cdb495895c97c37b Mon Sep 17 00:00:00 2001 From: Sai Revanth <132150745+SaiRevanth25@users.noreply.github.com> Date: Sat, 8 Jun 2024 04:19:05 +0530 Subject: [PATCH] [ENH] Log Laplace Distribution (#374) Towards #22, Implements Log Laplace Distribution --- docs/source/api_reference/distributions.rst | 1 + skpro/distributions/__init__.py | 2 + skpro/distributions/loglaplace.py | 79 +++++++++++++++++++++ 3 files changed, 82 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..390dc7a18 --- /dev/null +++ b/skpro/distributions/loglaplace.py @@ -0,0 +1,79 @@ +# 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}, \quad 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]