bluemath_tk.distributions package

Submodules

bluemath_tk.distributions.copula module

bluemath_tk.distributions.gev module

class bluemath_tk.distributions.gev.GEV[source]

Bases: BaseDistribution

Generalized Extreme Value (GEV) distribution class.

This class contains all the methods assocaited to the GEV distribution.

name[source]

The complete name of the distribution (GEV).

Type:

str

nparams[source]

Number of GEV parameters.

Type:

int

param_names[source]

Names of GEV parameters (location, scale, shape).

Type:

List[str]

pdf(x, loc, scale, shape)[source]

Probability density function.

cdf(x, loc, scale, shape)[source]

Cumulative distribution function

qf(p, loc, scale, shape)[source]

Quantile function

sf(x, loc, scale, shape)[source]

Survival function

nll(data, loc, scale, shape)[source]

Negative Log-Likelihood function

fit(data)[source]

Fit distribution to data (NOT IMPLEMENTED).

random(size, loc, scale, shape)[source]

Generates random values from GEV distribution.

mean(loc, scale, shape)[source]

Mean of GEV distribution.

median(loc, scale, shape)[source]

Median of GEV distribution.

variance(loc, scale, shape)[source]

Variance of GEV distribution.

std(loc, scale, shape)[source]

Standard deviation of GEV distribution.

stats(loc, scale, shape)[source]

Summary statistics of GEV distribution.

Notes

  • This class is designed to obtain all the properties associated to the GEV distribution.

Examples

>>> from bluemath_tk.distributions.gev import GEV
>>> gev_pdf = GEV.pdf(x, loc=0, scale=1, shape=0.1)
>>> gev_cdf = GEV.cdf(x, loc=0, scale=1, shape=0.1)
>>> gev_qf = GEV.qf(p, loc=0, scale=1, shape=0.1)
static cdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Cumulative distribution function

Parameters:
  • x (np.ndarray) – Values to compute their probability

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

p – Probability

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static fit(data: ndarray, **kwargs) FitResult[source]

Fit GEV distribution

Parameters:
  • data (np.ndarray) – Data to fit the GEV distribution

  • **kwargs (dict, optional) – Additional keyword arguments for the fitting function. These can include options like method, bounds, etc. See fit_dist for more details. If not provided, default fitting options will be used.

Returns:

Result of the fit containing the parameters loc, scale, shape, success status, and negative log-likelihood value.

Return type:

FitResult

static mean(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Mean

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

mean – Mean value of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static median(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Median

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

median – Median value of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static name() str[source]
static nll(data: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Negative Log-Likelihood function

Parameters:
  • data (np.ndarray) – Data to compute the Negative Log-Likelihood value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

nll – Negative Log-Likelihood value

Return type:

float

static nparams() int[source]

Number of parameters of GEV

static param_names() List[str][source]

Name of parameters of GEV

static pdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Probability density function

Parameters:
  • x (np.ndarray) – Values to compute the probability density value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

pdf – Probability density function values

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static qf(p: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Quantile function (Inverse of Cumulative Distribution Function)

Parameters:
  • p (np.ndarray) – Probabilities to compute their quantile

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

q – Quantile value

Return type:

np.ndarray

Raises:
  • ValueError – If probabilities are not in the range (0, 1).

  • ValueError – If scale is not greater than 0.

static random(size: int, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0, random_state: int = None) ndarray[source]

Generates random values from GEV distribution

Parameters:
  • size (int) – Number of random values to generate

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

  • random_state (np.random.RandomState, optional) – Random state for reproducibility. If None, do not use random stat.

Returns:

x – Random values from GEV distribution

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static sf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Survival function (1-Cumulative Distribution Function)

Parameters:
  • x (np.ndarray) – Values to compute their survival function value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

sp – Survival function value

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static stats(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) Dict[str, float][source]

Summary statistics

Return summary statistics including mean, std, variance, etc.

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

stats – Summary statistics of GEV distribution with the given parameters

Return type:

dict

Raises:

ValueError – If scale is not greater than 0.

static std(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Standard deviation

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

std – Standard Deviation of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static variance(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Variance

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

var – Variance of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

bluemath_tk.distributions.gpd module

class bluemath_tk.distributions.gpd.GPD[source]

Bases: BaseDistribution

Generalized Pareto Distribution (GPD) class.

This class contains all the methods assocaited to the GPD distribution.

name[source]

The complete name of the distribution (GPD).

Type:

str

nparams[source]

Number of GPD parameters.

Type:

int

param_names[source]

Names of the GPD parameters (threshold, scale, shape).

Type:

List[str]

pdf(x, loc, scale, shape)[source]

Probability density function.

cdf(x, loc, scale, shape)[source]

Cumulative distribution function

qf(p, loc, scale, shape)[source]

Quantile function

sf(x, loc, scale, shape)[source]

Survival function

nll(data, loc, scale, shape)[source]

Negative Log-Likelihood function

fit(data)[source]

Fit distribution to data (NOT IMPLEMENTED).

random(size, loc, scale, shape)[source]

Generates random values from GPD distribution.

mean(loc, scale, shape)[source]

Mean of GPD distribution.

median(loc, scale, shape)[source]

Median of GPD distribution.

variance(loc, scale, shape)[source]

Variance of GPD distribution.

std(loc, scale, shape)[source]

Standard deviation of GPD distribution.

stats(loc, scale, shape)[source]

Summary statistics of GPD distribution.

Notes

  • This class is designed to obtain all the properties associated to the GPD distribution.

Examples

>>> from bluemath_tk.distributions.gpd import GPD
>>> gpd_pdf = GPD.pdf(x, loc=0, scale=1, shape=0.1)
>>> gpd_cdf = GPD.cdf(x, loc=0, scale=1, shape=0.1)
>>> gpd_qf = GPD.qf(p, loc=0, scale=1, shape=0.1)
static cdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Cumulative distribution function

Parameters:
  • x (np.ndarray) – Values to compute their probability

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

p – Probability

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static fit(data: ndarray, **kwargs) FitResult[source]

Fit GEV distribution

Parameters:
  • data (np.ndarray) – Data to fit the GEV distribution

  • **kwargs (dict, optional) – Additional keyword arguments for the fitting function. These can include options like method, bounds, etc. See fit_dist for more details. If not provided, default fitting options will be used.

Returns:

Result of the fit containing the parameters loc, scale, shape, success status, and negative log-likelihood value.

Return type:

FitResult

static mean(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Mean

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

mean – Mean value of GEV with the given parameters

Return type:

np.ndarray

Raises:
  • ValueError – If scale is not greater than 0.

  • Warning – If shape is greater than or equal to 1, mean is not defined. In this case, it returns infinity.

static median(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Median

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

median – Median value of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static name() str[source]
static nll(data: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Negative Log-Likelihood function

Parameters:
  • data (np.ndarray) – Data to compute the Negative Log-Likelihood value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

nll – Negative Log-Likelihood value

Return type:

float

static nparams() int[source]

Number of parameters of GPD

static param_names() List[str][source]

Name of parameters of GPD

static pdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Probability density function

Parameters:
  • x (np.ndarray) – Values to compute the probability density value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

pdf – Probability density function values

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static qf(p: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Quantile function (Inverse of Cumulative Distribution Function)

Parameters:
  • p (np.ndarray) – Probabilities to compute their quantile

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

q – Quantile value

Return type:

np.ndarray

Raises:
  • ValueError – If probabilities are not in the range (0, 1).

  • ValueError – If scale is not greater than 0.

static random(size: int, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0, random_state: int = None) ndarray[source]

Generates random values from GPD distribution

Parameters:
  • size (int) – Number of random values to generate

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

  • random_state (np.random.RandomState, optional) – Random state for reproducibility. If None, do not use random stat.

Returns:

x – Random values from GEV distribution

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static sf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Survival function (1-Cumulative Distribution Function)

Parameters:
  • x (np.ndarray) – Values to compute their survival function value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

sp – Survival function value

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static stats(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) Dict[str, float][source]

Summary statistics

Return summary statistics including mean, std, variance, etc.

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

stats – Summary statistics of GEV distribution with the given parameters

Return type:

dict

Raises:

ValueError – If scale is not greater than 0.

static std(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Standard deviation

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

std – Standard Deviation of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static variance(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Variance

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

var – Variance of GEV with the given parameters

Return type:

np.ndarray

Raises:
  • ValueError – If scale is not greater than 0.

  • Warning – If shape is greater than or equal to 172, mean is not defined. In this case, it returns infinity.

bluemath_tk.distributions.poisson module

bluemath_tk.distributions.pot module

Module contents

Project: BlueMath_tk Sub-Module: distributions Author: GeoOcean Research Group, Universidad de Cantabria Repository: https://github.com/GeoOcean/BlueMath_tk.git Status: Under development (Working)

class bluemath_tk.distributions.GEV[source]

Bases: BaseDistribution

Generalized Extreme Value (GEV) distribution class.

This class contains all the methods assocaited to the GEV distribution.

name[source]

The complete name of the distribution (GEV).

Type:

str

nparams[source]

Number of GEV parameters.

Type:

int

param_names[source]

Names of GEV parameters (location, scale, shape).

Type:

List[str]

pdf(x, loc, scale, shape)[source]

Probability density function.

cdf(x, loc, scale, shape)[source]

Cumulative distribution function

qf(p, loc, scale, shape)[source]

Quantile function

sf(x, loc, scale, shape)[source]

Survival function

nll(data, loc, scale, shape)[source]

Negative Log-Likelihood function

fit(data)[source]

Fit distribution to data (NOT IMPLEMENTED).

random(size, loc, scale, shape)[source]

Generates random values from GEV distribution.

mean(loc, scale, shape)[source]

Mean of GEV distribution.

median(loc, scale, shape)[source]

Median of GEV distribution.

variance(loc, scale, shape)[source]

Variance of GEV distribution.

std(loc, scale, shape)[source]

Standard deviation of GEV distribution.

stats(loc, scale, shape)[source]

Summary statistics of GEV distribution.

Notes

  • This class is designed to obtain all the properties associated to the GEV distribution.

Examples

>>> from bluemath_tk.distributions.gev import GEV
>>> gev_pdf = GEV.pdf(x, loc=0, scale=1, shape=0.1)
>>> gev_cdf = GEV.cdf(x, loc=0, scale=1, shape=0.1)
>>> gev_qf = GEV.qf(p, loc=0, scale=1, shape=0.1)
static cdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Cumulative distribution function

Parameters:
  • x (np.ndarray) – Values to compute their probability

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

p – Probability

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static fit(data: ndarray, **kwargs) FitResult[source]

Fit GEV distribution

Parameters:
  • data (np.ndarray) – Data to fit the GEV distribution

  • **kwargs (dict, optional) – Additional keyword arguments for the fitting function. These can include options like method, bounds, etc. See fit_dist for more details. If not provided, default fitting options will be used.

Returns:

Result of the fit containing the parameters loc, scale, shape, success status, and negative log-likelihood value.

Return type:

FitResult

static mean(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Mean

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

mean – Mean value of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static median(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Median

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

median – Median value of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static name() str[source]
static nll(data: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Negative Log-Likelihood function

Parameters:
  • data (np.ndarray) – Data to compute the Negative Log-Likelihood value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

nll – Negative Log-Likelihood value

Return type:

float

static nparams() int[source]

Number of parameters of GEV

static param_names() List[str][source]

Name of parameters of GEV

static pdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Probability density function

Parameters:
  • x (np.ndarray) – Values to compute the probability density value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

pdf – Probability density function values

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static qf(p: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Quantile function (Inverse of Cumulative Distribution Function)

Parameters:
  • p (np.ndarray) – Probabilities to compute their quantile

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

q – Quantile value

Return type:

np.ndarray

Raises:
  • ValueError – If probabilities are not in the range (0, 1).

  • ValueError – If scale is not greater than 0.

static random(size: int, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0, random_state: int = None) ndarray[source]

Generates random values from GEV distribution

Parameters:
  • size (int) – Number of random values to generate

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

  • random_state (np.random.RandomState, optional) – Random state for reproducibility. If None, do not use random stat.

Returns:

x – Random values from GEV distribution

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static sf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Survival function (1-Cumulative Distribution Function)

Parameters:
  • x (np.ndarray) – Values to compute their survival function value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

sp – Survival function value

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static stats(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) Dict[str, float][source]

Summary statistics

Return summary statistics including mean, std, variance, etc.

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

stats – Summary statistics of GEV distribution with the given parameters

Return type:

dict

Raises:

ValueError – If scale is not greater than 0.

static std(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Standard deviation

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

std – Standard Deviation of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static variance(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Variance

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

var – Variance of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

class bluemath_tk.distributions.GPD[source]

Bases: BaseDistribution

Generalized Pareto Distribution (GPD) class.

This class contains all the methods assocaited to the GPD distribution.

name[source]

The complete name of the distribution (GPD).

Type:

str

nparams[source]

Number of GPD parameters.

Type:

int

param_names[source]

Names of the GPD parameters (threshold, scale, shape).

Type:

List[str]

pdf(x, loc, scale, shape)[source]

Probability density function.

cdf(x, loc, scale, shape)[source]

Cumulative distribution function

qf(p, loc, scale, shape)[source]

Quantile function

sf(x, loc, scale, shape)[source]

Survival function

nll(data, loc, scale, shape)[source]

Negative Log-Likelihood function

fit(data)[source]

Fit distribution to data (NOT IMPLEMENTED).

random(size, loc, scale, shape)[source]

Generates random values from GPD distribution.

mean(loc, scale, shape)[source]

Mean of GPD distribution.

median(loc, scale, shape)[source]

Median of GPD distribution.

variance(loc, scale, shape)[source]

Variance of GPD distribution.

std(loc, scale, shape)[source]

Standard deviation of GPD distribution.

stats(loc, scale, shape)[source]

Summary statistics of GPD distribution.

Notes

  • This class is designed to obtain all the properties associated to the GPD distribution.

Examples

>>> from bluemath_tk.distributions.gpd import GPD
>>> gpd_pdf = GPD.pdf(x, loc=0, scale=1, shape=0.1)
>>> gpd_cdf = GPD.cdf(x, loc=0, scale=1, shape=0.1)
>>> gpd_qf = GPD.qf(p, loc=0, scale=1, shape=0.1)
static cdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Cumulative distribution function

Parameters:
  • x (np.ndarray) – Values to compute their probability

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

p – Probability

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static fit(data: ndarray, **kwargs) FitResult[source]

Fit GEV distribution

Parameters:
  • data (np.ndarray) – Data to fit the GEV distribution

  • **kwargs (dict, optional) – Additional keyword arguments for the fitting function. These can include options like method, bounds, etc. See fit_dist for more details. If not provided, default fitting options will be used.

Returns:

Result of the fit containing the parameters loc, scale, shape, success status, and negative log-likelihood value.

Return type:

FitResult

static mean(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Mean

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

mean – Mean value of GEV with the given parameters

Return type:

np.ndarray

Raises:
  • ValueError – If scale is not greater than 0.

  • Warning – If shape is greater than or equal to 1, mean is not defined. In this case, it returns infinity.

static median(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Median

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

median – Median value of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static name() str[source]
static nll(data: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Negative Log-Likelihood function

Parameters:
  • data (np.ndarray) – Data to compute the Negative Log-Likelihood value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

nll – Negative Log-Likelihood value

Return type:

float

static nparams() int[source]

Number of parameters of GPD

static param_names() List[str][source]

Name of parameters of GPD

static pdf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Probability density function

Parameters:
  • x (np.ndarray) – Values to compute the probability density value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

pdf – Probability density function values

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static qf(p: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Quantile function (Inverse of Cumulative Distribution Function)

Parameters:
  • p (np.ndarray) – Probabilities to compute their quantile

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

q – Quantile value

Return type:

np.ndarray

Raises:
  • ValueError – If probabilities are not in the range (0, 1).

  • ValueError – If scale is not greater than 0.

static random(size: int, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0, random_state: int = None) ndarray[source]

Generates random values from GPD distribution

Parameters:
  • size (int) – Number of random values to generate

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

  • random_state (np.random.RandomState, optional) – Random state for reproducibility. If None, do not use random stat.

Returns:

x – Random values from GEV distribution

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static sf(x: ndarray, loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) ndarray[source]

Survival function (1-Cumulative Distribution Function)

Parameters:
  • x (np.ndarray) – Values to compute their survival function value

  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

sp – Survival function value

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static stats(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) Dict[str, float][source]

Summary statistics

Return summary statistics including mean, std, variance, etc.

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

stats – Summary statistics of GEV distribution with the given parameters

Return type:

dict

Raises:

ValueError – If scale is not greater than 0.

static std(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Standard deviation

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

std – Standard Deviation of GEV with the given parameters

Return type:

np.ndarray

Raises:

ValueError – If scale is not greater than 0.

static variance(loc: float = 0.0, scale: float = 1.0, shape: float = 0.0) float[source]

Variance

Parameters:
  • loc (float, default=0.0) – Location parameter

  • scale (float, default = 1.0) – Scale parameter. Must be greater than 0.

  • shape (float, default = 0.0) – Shape parameter.

Returns:

var – Variance of GEV with the given parameters

Return type:

np.ndarray

Raises:
  • ValueError – If scale is not greater than 0.

  • Warning – If shape is greater than or equal to 172, mean is not defined. In this case, it returns infinity.