API reference guide#
LossModel
#
- class Frequency(dist, par, threshold=0)[source]#
Frequency component of the loss models underlying the collective risk model.
- Parameters:
dist (
str
) – name of the frequency distribution.par (
dict
) – parameters of the frequency distribution.threshold (
int
orfloat
) – analysis threshold where the frequency model refers (optional). Default is 0, i.e. the ‘ground up’ or reporting threshold frequency. See pag. 323 in Parodi, P. (2014). Pricing in general insurance (first ed.).
- abp0g0(fj)[source]#
Parameters of the frequency distribution according to the (a, b, k) parametrization, the probability generating function computed in zero given the discrete severity probs, and the probability of the distribution in zero.
- Parameters:
fj (
numpy.ndarray
) – discretized severity distribution probabilities.- Returns:
a, b, probability in zero and aggregate cost probability in zero.
- Return type:
tuple
- class Layer(cover=inf, deductible=0, aggr_cover=inf, aggr_deductible=0, n_reinst=None, reinst_percentage=0, maintenance_limit=0, share=1, basis='regular', retention=True)[source]#
Policy structure non-proportional layer.
- Parameters:
deductible (
int
orfloat
) – each-and-every-loss (non-ranking) deductible, also referred to as retention or priority (default value is 0).cover (
int
orfloat
) – each-and-every-loss cover, also referred to as limit (default value is infinity). Cover plus deductible is the upper priority or severity ‘exit point’.aggr_deductible (
int
orfloat
) – aggregate deductible (default value is 0).aggr_cover (
int
orfloat
) – aggregate cover, also referred to as aggregate limit (default is infinity).n_reinst (
int
) – Number of reinstatements. When reinstatements are free (percentage = 0), an alternative parametrization is aggregate cover = (number of reinstatement + 1) * cover. E.g. When the number of reinstatements = 0, the aggregate cover is equal to the cover, when number of reinstatements is infinity there is no aggregate cover (the aggregate cover is infinity).reinst_percentage (
int
orfloat
ornp.array
) – percentage of reinstatements layers, a value in [0, 1]. Default value is 0, i.e. the reinstatement layer is free.maintenance_limit (
int
orfloat
) – maintenance limit, sometimes referred to as residual maintenance deductible or residual each-and-every-loss deductible (default is 0). Non-zero maintenance deductible applies to first layer only.share (
float
) – Partecipation share of the layer (default is 1).basis (
str
) – layer basis (default is ‘regular’). One of ‘regular’, ‘drop-down’, ‘stretch-down’.retention (
bool
) – True if the layer represents a retention layer, i.e. it receives losses below the (lowest) deductible and above the overall limit. Relevant only if the Layer is in aLayerTower
.
- class LayerTower(*args)[source]#
Policy structure tower of non-proportional layers.
- Parameters:
**args – See below
- Keyword Arguments:
args (
Layers
) – Layer tower elements.
- class LossModel(severity, frequency, policystructure=<gemact.lossmodel.PolicyStructure object>, aggr_loss_dist_method=None, n_sim=10000, tilt=False, tilt_value=0, random_state=None, qmc_sequence='sobol', n_aggr_dist_nodes=20000, sev_discr_method='localmoments', n_sev_discr_nodes=None, sev_discr_step=None)[source]#
Loss model for (re)insurance costing and risk modeling using a collective risk model framework.
- Parameters:
severity (
Severity
) – severity model.frequency (
Frequency
) – frequency model.policystructure (
PolicyStructure
) – policy structure.aggr_loss_dist_method (
str
) – computational method to approximate the aggregate loss distribution. One of Fast Fourier Transform (‘fft’), Panjer recursion (‘recursion’), Monte Carlo simulation (‘mc’) and quasi-Monte Carlo (‘qmc’).n_sim (
int
) – number of simulations of Monte Carlo (‘mc’) and of quasi-Monte Carlo (‘qmc’) methods for the aggregate loss distribution approximation.tilt (
bool
) – whether tilting of fft is present or not (default is 0).tilt_value (
float
) – tilting parameter value of fft method for the aggregate loss distribution approximation.random_state (
int
) – random state for the random number generator in mc and qmc.qmc_sequence (
str
) – type of quasi-Monte Carlo low-discrepancy sequence. One of Halton - van der Corput (‘halton’), Latin hypercube (‘lhs’), and Sobol (‘sobol’). Optional (default is ‘sobol’).n_aggr_dist_nodes (
int
) – number of nodes in the approximated aggregate loss distribution. It cannot be lower than 256.sev_discr_method (
str
) – severity discretization method. One of ‘massdispersal’, ‘localmoments’, ‘upperdiscretization’, ‘lowerdiscretization’.n_sev_discr_nodes (
int
) – number of nodes of the discretized severity (optional).sev_discr_step (
float
) – severity discretization step.
- cdf(x, idx=0)[source]#
Aggregate loss distribution cumulative distribution function.
- Parameters:
x (
float
orint
ornumpy.ndarray
) – quantiles where the cumulative distribution function is evaluated.idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.
- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- coeff_variation(idx=0, use_dist=True)[source]#
Coefficient of variation (CoV) of the aggregate loss.
- Parameters:
idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.use_dist (
bool
) – If True, the CoV is calculated from the (approximated) aggregate loss distributon. If False, the CoV is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.
- Returns:
CoV of the aggregate loss.
- Return type:
numpy.float64
- costing()[source]#
Actuarial costing (also referred to as risk costing) of (re)insurance covers, such as quota share, excess-of-loss (including reinstatements or aggregate conditions) and stop loss.
- Returns:
Void
- Return type:
None
- dist_calculate(aggr_loss_dist_method=None, n_aggr_dist_nodes=None, n_sim=None, random_state=None, qmc_sequence=None, sev_discr_method=None, sev_discr_step=None, n_sev_discr_nodes=None, tilt=None, tilt_value=None)[source]#
Approximate the aggregate loss distributions of each policystructure layer. Distributions can be accessed via the
dist
property, which is a list ofdistributions.PWC
objects, each one representing a aggregate loss distribution.- Parameters:
aggr_loss_dist_method (
str
) – computational method to approximate the aggregate loss distribution. One of Fast Fourier Transform (‘fft’), Panjer recursion (‘recursion’), Monte Carlo simulation (‘mc’) and quasi-Monte Carlo (‘qmc’).n_aggr_dist_nodes (
int
) – number of nodes in the approximated aggregate loss distribution. Remark: before application of eventual aggregate conditions.n_sim (
int
) – number of simulations of Monte Carlo (‘mc’) and quasi-Monte Carlo (‘qmc’) methods for the aggregate loss distribution approximation.random_state (
int
) – random state for the random number generator in Monte Carlo (‘mc’) and quasi-Monte Carlo (‘qmc’), optional.qmc_sequence (
str
) – type of quasi-Monte Carlo low-discrepancy sequence. One of Halton - van der Corput (‘halton’), Latin hypercube (‘lhs’), and Sobol (‘sobol’). Optional (default is ‘sobol’).sev_discr_method (
str
) – severity discretization method, optional (default is ‘localmoments’).sev_discr_step (
float
) – severity discretization step.n_sev_discr_nodes (
int
) – number of nodes of the discretized severity.tilt (
bool
) – whether tilting of fft is present or not, optional (default is 0).tilt_value (
float
) – tilting parameter value of fft method for the aggregate loss distribution approximation, optional.
- Returns:
void
- Return type:
None
- mean(idx=0, use_dist=True)[source]#
Mean of the aggregate loss.
- Parameters:
idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.use_dist (
bool
) – If True, the mean is calculated from the (approximated) aggregate loss distributon. If False, the mean is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.
- Returns:
mean of the aggregate loss.
- Return type:
numpy.float64
- moment(central=False, n=1, idx=0)[source]#
Approximated aggregate loss distribution moment of order n. It is based on
dist
property.- Parameters:
central (
bool
) –True
if the moment is central,False
if the moment is raw.n (
int
) – order of the moment, optional (default is 1).idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.
- Returns:
moment of order n.
- Return type:
numpy.float64
- plot_dist_cdf(idx=0, log_x_scale=False, log_y_scale=False, **kwargs)[source]#
Plot the cumulative distribution function of the aggregate loss distribution.
- Parameters:
idx (
int
) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.log_x_scale (
bool
) – ifTrue
the x-axis scale is logarithmic (optional).log_y_scale (
bool
) – ifTrue
the y-axis scale is logarithmic (optional).**kwargs – Additional parameters as those for
matplotlib.axes.Axes.step
.
- Returns:
plot of the cdf.
- Return type:
matplotlib.figure.Figure
- ppf(q, idx=0)[source]#
Aggregate loss distribution percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
ornumpy.ndarray
) – probability.idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.
- Returns:
quantile.
- Return type:
numpy.float64
ornumpy.ndarray
- print_aggr_loss_method_specs(idx=0)[source]#
Print information of the aggregate loss distribution approximation for a given layer (specified via its index).
- Parameters:
idx (
int
) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.- Returns:
Void
- Return type:
None
- print_costing_specs(idx=0)[source]#
Print costing information of a given layer (specified via its index).
- Parameters:
idx (
int
) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.- Returns:
Void
- Return type:
None
- print_policy_layer_specs(idx=0)[source]#
Print policy structure information of a given layer (specified via its index).
- Parameters:
idx (
int
) – index corresponding to the policystructure layer of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.- Returns:
Void
- Return type:
None
- rvs(size=1, random_state=None, idx=0)[source]#
Random variates generator function.
- Parameters:
size (
int
) – random variates sample size, optional (default is 1).random_state (
int
) – random state for the random number generator, optional (no default).idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x, idx=0)[source]#
Aggregate loss distribution survival function.
- Parameters:
x (
float
orint
ornumpy.ndarray
) – quantiles where the survival functionis evaluated.idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.
- Returns:
survival function.
- Return type:
numpy.float64
ornumpy.ndarray
- skewness(idx=0, use_dist=True)[source]#
Skewness of the aggregate loss.
- Parameters:
idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.use_dist (
bool
) – If True, the skewness is calculated from the (approximated) aggregate loss distributon. If False, the skewness is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.
- Returns:
skewness of the aggregate loss.
- Return type:
numpy.float64
- std(idx=0, use_dist=True)[source]#
Standard deviation of the aggregate loss.
- Parameters:
idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.use_dist (
bool
) – If True, the mean is calculated from the (approximated) aggregate loss distributon. If False, the mean is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.
- Returns:
standard deviation of the aggregate loss.
- Return type:
numpy.float64
- var(idx=0, use_dist=True)[source]#
Variance of the aggregate loss.
- Parameters:
idx (
int
) – list index corresponding to the layer loss distribution of interest (default is 0). See ‘index_to_layer_name’ and ‘layer_name_to_index’ PolicyStructure methods.use_dist (
bool
) – If True, the mean is calculated from the (approximated) aggregate loss distributon. If False, the mean is computed from the underlying frequency-severity loss model. The latter is possible only if there are no aggregate conditions in the layer of interest.
- Returns:
variance of the aggregate loss.
- Return type:
numpy.float64
- class PolicyStructure(layers=None)[source]#
Policy structure component of a loss model.
- Parameters:
layers (
Layer
,LayerTower
,list
) – Non-proportional layer (default is infinity-xs-0 layer).
- class Severity(dist, par)[source]#
Severity component of the loss models underlying the collective risk model. Severity model is always considered to start at (the relative) 0, i.e. the reporting threshold.
- Parameters:
dist (
str
) – name of the frequency distribution.par (
dict
) – parameters of the frequency distribution.
- censored_coeff_variation(cover, deductible)[source]#
Coefficient of variation (CoV) of the transformed severity min(max(x - u, 0), v).
- Parameters:
cover (
int
,float
) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.deductible (
int
,float
) – deductible, also referred to as retention or priority.
- Returns:
CoV of the transformed severity.
- Return type:
numpy.float
- censored_mean(cover, deductible)[source]#
Mean of the transformed severity min(max(x - u, 0), v). Also referred to as the stop-loss transformation function.
- Parameters:
cover (
int
,float
) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.deductible (
int
,float
) – deductible, also referred to as retention or priority.
- Returns:
mean of the transformed severity.
- Return type:
numpy.float
- censored_skewness(cover, deductible)[source]#
Skewness of the transformed severity min(max(x - u, 0), v).
- Parameters:
cover (
int
,float
) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.deductible (
int
,float
) – deductible, also referred to as retention or priority.
- Returns:
skewness of the transformed severity.
- Return type:
numpy.float
- censored_std(cover, deductible)[source]#
Standard deviation of the transformed severity min(max(x - u, 0), v).
- Parameters:
cover (
int
,float
) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.deductible (
int
,float
) – deductible, also referred to as retention or priority.
- Returns:
standard deviation of the transformed severity.
- Return type:
numpy.float
- censored_var(cover, deductible)[source]#
Variance of the transformed severity min(max(x - d, 0), c).
- Parameters:
cover (
int
,float
) – cover, also referred to as limit. cover plus deductible is the upper priority or severity ‘exit point’.deductible (
int
,float
) – deductible, also referred to as retention or priority.
- Returns:
variance of the transformed severity.
- Return type:
numpy.float
- discretize(discr_method, n_discr_nodes, discr_step, deductible=0)[source]#
Severity discretization according to the discretization method selected by the user.
- Parameters:
deductible (
int
orfloat
) – deductible, also referred to as retention or priority.discr_method (
str
) – severity discretization method. One of ‘massdispersal’, ‘localmoments’, ‘upperdiscretization’, ‘lowerdiscretization’.discr_step (
float
) – severity discretization step.n_discr_nodes (
int
) – number of nodes of the discretized severity. Optional, default is 0.
- Returns:
discrete severity, nodes sequence and discrete probabilities.
- Return type:
dict
- excess_frequency(x, base_frequency=100)[source]#
Expected excess frequency function, i.e. expected frequency in excess of a given threshold.
- Parameters:
x (
float
) – value where excess frequency is evaluated.base_frequency (
int
,float
) – frequency at origin (default is 100). Optional.
- Returns:
excess frequency.
- Return type:
numpy.float
orfloat
- plot_discr_sev_cdf(discr_method, n_discr_nodes, discr_step, deductible, log_x_scale=False, log_y_scale=False, **kwargs)[source]#
Plot the cumulative distribution function of the discretized severity distribution.
- Parameters:
discr_method (
str
) – severity discretization method. One of ‘massdispersal’, ‘localmoments’, ‘upperdiscretization’, ‘lowerdiscretization’.n_discr_nodes (
int
) – number of nodes of the discretized severity.discr_step (
float
) – severity discretization step.deductible (
int
orfloat
) – deductible, also referred to as retention or priority.log_x_scale (
bool
) – ifTrue
the x-axis scale is logarithmic (optional).log_y_scale (
bool
) – ifTrue
the y-axis scale is logarithmic (optional).**kwargs – Additional parameters as those for
matplotlib.axes.Axes.step
.
- Returns:
plot of the cdf.
- Return type:
matplotlib.figure.Figure
Risk costing#
GEMAct costing model is based on the collective risk theory. The aggregate loss \(X\), also referred to as aggregate claim cost, is
where the following assumptions hold:
\(N\) is a random variable taking values in \(\mathbb{N}_0\) representing the claim frequency.
\(\left\{ Z_i\right\}_{i \in \mathbb{N}}\) is a sequence of i.i.d non-negative random variables independent of \(N\); \(Z\) is the random variable representing the individual (claim) loss.
Equation (1) is often referred to as the frequency-severity loss model representation. This can encompass common coverage modifiers present in (re)insurance contracts. More specifically, we consider:
For \(a \in [0, 1]\), the function \(Q_a\) apportioning the aggregate loss amount:
\[Q_a (X)= a X.\]
For \(c,d \geq 0\), the function \(L_{c, d}\) applied to the individual claim loss:
(2)#\[L_{c, d} (Z_i) = \min \left\{\max \left\{0, Z_i-d\right\}, c\right\}. %, \qquad c,d \geq 0.\]Herein, for each and every loss, the excess to a deductible \(d\) (sometimes referred to as priority) is considered up to a cover or limit \(c\). Similarly to the individual loss \(Z_i\), Formula (2) can be applied to the aggregate loss \(X\).
The expected value of the aggregate loss constitutes the building block of an insurance tariff. Listed below are some examples of basic reinsurance contracts whose pure premium can be computed with GEMAct.
The Quota Share (QS), where a share \(a\) of the aggregate loss ceded to the reinsurance (along with the respective premium) and the remaining part is retained:
\[\text{P}^{QS} = \mathbb{E}\left[ Q_a \left( X \right)\right].\]
The Excess-of-loss (XL), where the insurer cedes to the reinsurer each and every loss exceeding a deductible \(d\), up to an agreed limit or cover \(c\), with \(c,d \geq 0\):
\[\text{P}^{XL} = \mathbb{E}\left[ \sum_{i=1}^{N} L_{c,d} (Z_i) \right].\]
The Stop Loss (SL), where the reinsurer covers the aggregate loss exceedance of a (aggregate) deductible \(v\), up to a (aggregate) limit or cover \(u\), with \(u,v \geq 0\):
\[\text{P}^{SL} = \mathbb{E}\left[ L_{u, v} (X) \right].\]
The Excess-of-loss with reinstatements (RS) (Sundt [Sun91]). Assuming the aggregate cover \(u\) is equal to \((K + 1) c `, with :math:`K \in \mathbb{Z}^+\):
(3)#\[\text{P}^{RS} = \frac{\mathbb{E}\left[ L_{u, v} (X) \right]}{1+\frac{1}{c} \sum_{k=1}^K l_k \mathbb{E}\left[ L_{c, (k-1)c+v}(X) \right]}.\]Where \(K\) is the number of reinstatement layers and \(l_k \in [0, 1]\) is the reinstatement premium percentage, with \(k=1, \ldots, K\). When \(l_k = 0\), the \(k\)-th resinstatement is said to be free.
The following table gives the correspondence between the LossModel
class attributes and our costing model as presented below.
Costing model notation |
Parametrization in |
---|---|
\(d\) |
deductible |
\(c\) |
cover |
\(v\) |
aggr_deductible |
\(u\) |
aggr_cover |
\(K\) |
n_reinst |
\(c_{k}\) |
reinst_percentage |
\(\alpha\) |
share |
For additional information the reader can refer to Klugman and Panjer [KP19], Sundt [Sun91]. Further details on the computational methods to approximate the aggregate loss distribution can be found in Klugman and Panjer [KP19], and Embrechts and Frei [EF08].
Example#
Below is an example of costing an XL contract with reinstatements:
from gemact.lossmodel import Frequency, Severity, PolicyStructure, LossModel
lossmodel_RS = LossModel(
frequency=Frequency(
dist='poisson',
par={'mu': 1.5}
),
severity=Severity(
par= {'loc': 0,
'scale': 83.34,
'c': 0.834},
dist='genpareto'
),
policystructure=PolicyStructure(
layers=Layer(
cover=100,
deductible=0,
aggr_deductible=100,
reinst_share=0.5,
n_reinst=2
)
),
aggr_loss_dist_method='fft',
sev_discr_method='massdispersal',
n_aggr_dist_nodes=int(100000)
)
lossmodel_RS.print_costing_specs()
Severity discretization#
When passing from a continuous distribution to an arithmetic distribution, it is important to preserve the distribution properties, either locally or globally. Given a bandiwith (or discretization step) \(h\) and a number of nodes \(M\), in Klugman and Panjer [KP19] the method of mass dispersal and the method of local moments matching work as follows.
Method of mass dispersal
Method of local moments matching
The following approach is applied to preserve the global mean of the distribution.
In addition to these two methods, our package also provides the methods of upper and lower discretizations.
Example#
An example of code to implement severity discretization is given below:
from gemact.lossmodel import Severity
import numpy as np
severity=Severity(
par= {'loc': 0, 'scale': 83.34, 'c': 0.834},
dist='genpareto'
)
massdispersal = severity.discretize(
discr_method='massdispersal',
n_discr_nodes=50000,
discr_step=.01,
deductible=0
)
localmoments = severity.discretize(
discr_method='localmoments',
n_discr_nodes=50000,
discr_step=.01,
deductible=0
)
meanMD = np.sum(massdispersal['sev_nodes'] * massdispersal['fj'])
meanLM = np.sum(localmoments['sev_nodes'] * localmoments['fj'])
print('Original mean: ', severity.model.mean())
print('Mean (mass dispersal): ', meanMD)
print('Mean (local moments): ', meanLM)
LossReserve
#
- class AggregateData(incremental_payments, cased_payments, payments_number, open_claims_number, reported_claims, cumulative_payments=None)[source]#
Triangular data sets.
- Parameters:
cumulative_payments (
numpy.ndarray
) – cumulative payments triangle.incremental_payments (
numpy.ndarray
) – incremental payments triangle.cased_payments (
numpy.ndarray
) – cased payments triangle.payments_number (
numpy.ndarray
) – number of paid claims.open_claims_number (
numpy.ndarray
) – number of open claims.reported_claims (
numpy.ndarray
) – number of reported claims by accident period. Data must be provided from old to recent.
- class LossReserve(data, reservingmodel, custom_alphas=None, custom_ss=None, ntr_sim=1000, random_state=None)[source]#
Claims loss reserving. The available reserving models are the deterministic Fisher-Lange and the collective risk model. Input company data must be
numpy.ndarray
data on numbers and payments must be in triangular form: two-dimensionalnumpy.ndarray
with shape (I, J) where I=J.- Parameters:
ntr_sim (
int
) – Number of simulated triangles in the c.r.m reserving method.random_state (
int
) – Simulation seed to make the c.r.m reserving method results reproducible.custom_alphas (
numpy.ndarray
) – optional, custom values for the alpha parameters.custom_ss (
numpy.ndarray
) – optional, custom values for the settlement speed.
- cdf(x)[source]#
Aggregate loss reserve cumulative density function. This is only available for stochastic methods.
- Parameters:
x (
float
ornumpy.ndarray
) – quantile.- Returns:
probability.
- Return type:
numpy.float64
ornumpy.ndarray
- mean(use_dist=False)[source]#
Mean of the loss reserve. Depending on the selected reserving method, it returns either the attribute crm_reserve or fl_reserve.
- Parameters:
use_dist (
bool
) – parameter that sets whether or not the approximate distribution should be used. Default False.- Returns:
mean of the loss reserve.
- Return type:
numpy.float64
- plot_ss_fl(start_=0)[source]#
Plot the settlement speed vector for each accident period.
- Parameters:
start (
int
) – starting accident period from which to plot.
- ppf(q)[source]#
Aggregate loss reserve percent point function, a.k.a. the quantile function. This is only available for stochastic methods.
- Parameters:
q (
float
ornumpy.ndarray
) – probability.- Returns:
quantile.
- Return type:
numpy.float64
ornumpy.ndarray
- print_loss_reserve()[source]#
Table with claims reserve results. When the stochastic reserve according to the collective risk model is computed the results are compared with the Fisher-Lange.
- sf(x)[source]#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness(use_dist=True)[source]#
Skewness of the loss reserve (not available for claims reserving with the fisher lange).
- Returns:
skewness of the loss reserve.
- Return type:
numpy.float64
- std(use_dist=True)[source]#
Standard deviation of the loss reserve (not available for claims reserving with the fisher lange).
- Parameters:
use_dist (
bool
) – parameter that sets whether or not the approximate distribution should be used. Default False.- Returns:
standard deviation of the loss reserve.
- Return type:
numpy.float64
- var(use_dist=True)[source]#
Variance of the loss reserve (not available for claims reserving with the fisher lange).
- Parameters:
use_dist (
bool
) – parameter that sets whether or not the approximate distribution should be used. Default False.- Returns:
Variance of the loss reserve.
- Return type:
numpy.float64
- class ReservingModel(tail=False, reserving_method='fisher_lange', claims_inflation=None, mixing_fq_par=None, mixing_sev_par=None, czj=None)[source]#
Reserving model assumptions.
- Parameters:
tail (
bool
) – True when the tail estimate is required else false (optional). Default False.reserving_method (
str
) – one of the reserving methods supported by the GemAct package.claims_inflation (
numpy.ndarray
) – claims inflation. In case no tail is present and the triangular data IxJ matrices, claims_inflation must be J-1 dimensional. When a tail estimate is required, it must be J dimensional. In case no tail is present it must be J-1 dimensional.czj (
numpy.ndarray
) – severity coefficient of variation by development period. It is set to None in case the crm is selected as reserving method. When a tail estimate is required, it must be J dimensional. In case no tail is present it must be J-1 dimensional.mixing_fq_par (
dict
) – Mixing frequency parameters.mixing_sev_par (
dict
) – Mixing severity parameters.
Claims reserving#
GEMAct provides a software implementation of average cost methods for claims reserving based on the collective risk model framework.
The methods implemented are the Fisher-Lange in Fisher et al. [FLB99] the collective risk model for claims reserving in Ricotta and Clemente [RC16].
It allows for tail estimates and assumes the triangular inputs to be provided as a numpy.ndarray
with two equal dimensions (I,J)
, where I=J
.
The aim of average cost methods is to model incremental payments as in equation (11).
where \(n_{i,j}\) is the number of payments in the cell \(i,j\) and \(m_{i,j}\) is the average cost in the cell \(i,j\).
Example#
It is possible to use the module gemdata
to test GEMAct average cost methods:
from gemact import gemdata
ip_ = gemdata.incremental_payments
in_ = gemdata.incurred_number
cp_ = gemdata.cased_payments
cn_= gemdata.cased_number
reported_ = gemdata.reported_claims
claims_inflation = gemdata.claims_inflation
An example of Fisher-Lange implementation:
from gemact.lossreserve import AggregateData, ReservingModel
from gemact import gemdata
ip_ = gemdata.incremental_payments
in_ = gemdata.incurred_number
cp_ = gemdata.cased_payments
cn_= gemdata.cased_number
reported_ = gemdata.reported_claims
claims_inflation = gemdata.claims_inflation
ad = AggregateData(
incremental_payments=ip_,
cased_payments=cp_,
cased_number=cn_,
reported_claims=reported_,
incurred_number=in_
)
rm = ReservingModel(
tail=True,
reserving_method="fisher_lange",
claims_inflation=claims_inflation
)
lm = gemact.LossReserve(
data=ad,
reservingmodel=rm
)
Observe the CRM for reserving requires different model assumptions:
from gemact import gemdata
ip_ = gemdata.incremental_payments
in_ = gemdata.incurred_number
cp_ = gemdata.cased_payments
cn_= gemdata.cased_number
reported_ = gemdata.reported_claims
claims_inflation = gemdata.claims_inflation
from gemact.lossreserve import AggregateData, ReservingModel, LossReserve
ad = AggregateData(
incremental_payments=ip_,
cased_payments=cp_,
cased_number=cn_,
reported_claims=reported_,
incurred_number=in_)
mixing_fq_par = {'a': 1 / .08 ** 2, # mix frequency
'scale': .08 ** 2}
mixing_sev_par = {'a': 1 / .08 ** 2, 'scale': .08 ** 2} # mix severity
czj = gemdata.czj
claims_inflation= gemdata.claims_inflation
rm = ReservingModel(tail=True,
reserving_method="crm",
claims_inflation=claims_inflation,
mixing_fq_par=mixing_fq_par,
mixing_sev_par=mixing_sev_par,
czj=czj)
#Loss reserving: instance lr
lm = LossReserve(data=ad,
reservingmodel=rm)
LossAggregation
#
- class LossAggregation(copula, margins, n_sim=None, random_state=None, n_iter=7, tol=0.0001)[source]#
Class representing the sum of positive random variables. Dependence structure is specified by a copula.
- Parameters:
copula (
Copula
) – name of the copula that describes the dependence structure.margins (
Margins
) – list of the marginal distributions.n_sim (
int
) – number of Monte Carlo simulations (optional). IfNone
the simulation is skipped.random_state (
int
) – random state for the random number generator (optional).n_iter (
int
) – number of AEP algorithm iterations (optional).tol (
float
) – tolerance threshold for AEP ppf, maximum allowed absolute difference between cumulative probability values (optional).
- cdf(x, method='mc', n_iter=None)[source]#
Cumulative distribution function of the random variable sum. If
method
is Monte Carlo (‘mc’) the function relies on the approximated distribution calculated viadist_calculate
method when the object is initiated (accessed via thedist
property). Ifmethod
is AEP (‘aep’) the function is evaluated pointwise, on-the-fly, regardless of thedist
property.- Parameters:
x (
float
) – quantiles where the cumulative distribution function are evaluated.method (
string
) – method to approximate the cdf of the sum of the random variables. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).n_iter (
int
) – number of AEP algorithm iterations (optional).
- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, u, v)[source]#
Non-central moment of order n of the transformed random variable min(max(x - u, 0), v). When n = 1 it is the so-called stop loss transformation function.
- Parameters:
u (
int
,float
,numpy.float
ornumpy.ndarray
) – lower censoring point.v (
int
,float
,numpy.float
ornumpy.ndarray
) – difference between the upper and the lower censoring points, i.e. v + u is the upper censoring point.n (
int
) – moment order.
- Returns:
censored raw moment of order n.
- Return type:
numpy.float
ornumpy.ndarray
- dist_calculate(n_sim=None, random_state=None)[source]#
Approximate the distribution of the sum of random variable with a given dependence structure by executing a Monte Carlo simulation. The resulting distribution can be accessed via the
dist
property, which is adistributions.PWC
object.- Parameters:
n_sim (
int
) – number of simulations of Monte Carlo simulation (optional).random_state (
int
) – random state for the random number generator (optional).
- Returns:
Void.
- Return type:
None
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
int
,float
,numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- mean()[source]#
Mean of the random variable sum. It is based on Monte Carlo simulation results, i.e.
dist
property.- Returns:
mean.
- Return type:
numpy.float64
- moment(central=False, n=1)[source]#
Moment of order n of the random variable sum. It is based on Monte Carlo simulation results, i.e.
dist
property.- Parameters:
central (
bool
) –True
if the moment is central,False
if the moment is raw.n (
int
) – order of the moment, optional (default is 1).
- Returns:
moment of order n.
- Return type:
numpy.float64
- plot_cdf(log_x_scale=False, log_y_scale=False, **kwargs)[source]#
Plot the cumulative distribution function of the random variable sum. It is based on Monte Carlo simulation results, i.e.
dist
property.- Parameters:
log_x_scale (
bool
) – ifTrue
the x-axis scale is logarithmic (optional).log_y_scale (
bool
) – ifTrue
the y-axis scale is logarithmic (optional).**kwargs – Additional parameters as those for
matplotlib.axes.Axes.step
.
- Returns:
plot of the cdf.
- Return type:
matplotlib.figure.Figure
- ppf(q, method='mc', n_iter=None, tol=0.0001)[source]#
Percent point function, a.k.a. the quantile function, of the random variable sum. Inverse of cumulative distribution function. If
method
is Monte Carlo (‘mc’) the function relies on the approximated distribution calculated viadist_calculate
method when the object is initiated (accessed via thedist
property). Ifmethod
is AEP (‘aep’) the function is evaluated pointwise, on-the-fly, regardless of thedist
property. It adopts thescipy.optimize.brentq
optimizer.- Parameters:
q (
float
,numpy.ndarray
,numpy.floating
) – probabilities where point function is evaluated.method (
string
) – method to approximate the ppf of the sum of the random variables. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).n_iter (
int
) – number of AEP algorithm iterations (optional).tol (
float
) – tolerance threshold, maximum allowed absolute difference between cumulative probability values (optional).
- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None, method='mc', n_iter=None, tol=None)[source]#
Random variates generator function. If
method
is Monte Carlo (‘mc’) the function use inverse transform sampling via copula, margins and then apply the sum. Ifmethod
is AEP (‘aep’) the function use the inverse transform sampling via ‘aep’ ppf. The latter option is time demanding.- Parameters:
size (
int
) – random variates sample size (default is 1).random_state (
int
) – random state for the random number generator.method (
string
) – method to execute the generator of random variates. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).n_iter (
int
) – number of AEP algorithm iterations (optional).tol (
float
) – tolerance threshold, maximum allowed absolute difference between cumulative probability values (optional).
- Returns:
Random variates.
- Return type:
numpy.float64
ornumpy.ndarray
- sf(x, method='mc', n_iter=None)[source]#
Survival function of the random variable sum. If
method
is Monte Carlo (‘mc’) the function relies on the approximated distribution calculated viadist_calculate
method when the object is initiated (accessed via thedist
property). Ifmethod
is AEP (‘aep’) the function is evaluated pointwise, on-the-fly, regardless of thedist
property.- Parameters:
x (
float
) – quantiles where the survival function are evaluated.method (
string
) – method to approximate the survival function of the sum of the random variables. One of AEP (‘aep’) and Monte Carlo simulation (‘mc’).n_iter (
int
) – number of AEP algorithm iterations (optional).
- Returns:
survival function.
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()[source]#
Skewness of the random variable sum. It is based on Monte Carlo simulation results, i.e.
dist
property.- Returns:
skewness.
- Return type:
numpy.float64
Loss aggregation#
The probability in equation (12) can be approximated iteratively via the AEP algorithm, which is implemented for the first time in the GEMAct package, under the following assumptions:
Assuming:
\(𝑋=(X_i, \ldots, X_d)\) vector of strictly positive random components.
The joint c.d.f. \(H(x_1,…,x_d )=P\left[ X_1 +\ldots +X_d \right]\) is known or it can be computed numerically.
Refer to Arbenz et al. [AEP11] for an extensive explanation on the AEP algorithm. It is possible to use a MC simulation for comparison.
Example#
Example code under a clayton assumption:
from gemact.lossaggregation import LossAggregation, Copula, Margins
lossaggregation = LossAggregation(
margins=Margins(
dist=['genpareto', 'lognormal'],
par=[{'loc': 0, 'scale': 1/.9, 'c': 1/.9}, {'loc': 0, 'scale': 10, 'shape': 1.5}],
),
copula=Copula(
dist='frank',
par={'par': 1.2, 'dim': 2}
),
n_sim=500000,
random_state=10,
n_iter=8
)
s = 300 # arbitrary value
p_aep = lossaggregation.cdf(x=s, method='aep')
print('P(X1+X2 <= s) = ', p_aep)
p_mc = lossaggregation.cdf(x=s, method='mc')
print('P(X1+X2 <= s) = ', p_mc)
The distributions
module#
Poisson
#
- class Poisson(loc=0, **kwargs)[source]#
Poisson distribution. Wrapper to scipy poisson distribution (
scipy.stats._discrete_distns.poisson_gen
) Refer to :py:class:’~_DiscreteDistribution’ for additional details.- Parameters:
loc (
int
, optional) – location parameter (default=0), to shift the support of the distribution.**kwargs – See below
- Keyword Arguments:
mu (
numpy.float64
) – Poisson distribution parameter mu (rate).
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated.- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a more detailed explanation refer to SciPy Poisson distribution documentation, see Virtanen et al. [VGO+20].
Given \(\mu \geq 0\) and \(k \geq 0\).
Example code on the usage of the Poisson class:
from gemact import distributions
import numpy as np
mu = 4
dist = distributions.Poisson(mu=mu)
seq = np.arange(0,20)
nsim = int(1e+05)
# Compute the mean via pmf
mean = np.sum(dist.pmf(seq)*seq)
variance = np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Theoretical mean', dist.mean())
print('Variance', variance)
print('Theoretical variance', dist.var())
#compare with simulations
print('Simulated mean', np.mean(dist.rvs(nsim)))
print('Simulated variance', np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Poisson:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~Poisson(mu=4)')
#cdf
plt.step(np.arange(-2,20), dist.cdf(np.arange(-2,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~ Poisson(mu=4)')
Binom
#
- class Binom(loc=0, **kwargs)[source]#
Binomial distribution. Wrapper to scipy binomial distribution (
scipy.stats._discrete_distns.binom_gen
). Refer to :py:class:’~_DiscreteDistribution’ for additional details.- Parameters:
loc (
int
, optional) – location parameter (default=0), to shift the support of the distribution.**kwargs – See below
- Keyword Arguments:
n (
int
) – Number of trials.p (
float
) – Probability of a success, parameter of the binomial distribution.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a more detailed explanation refer to SciPy Binomial distribution documentation, see Virtanen et al. [VGO+20].
for \(k \in\{0,1, \ldots, n\}, 0 \leq p \leq 1\)
Example code on the usage of the Binom class:
from gemact import distributions
import numpy as np
n = 10
p = 0.5
dist = distributions.Binom(n=n, p=p)
seq = np.arange(0,20)
nsim = int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Theoretical mean',dist.mean())
print('Variance',variance)
print('Theoretical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Poisson:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~Binom(n=10,p=0.5)')
#cdf
plt.step(np.arange(-2,20),dist.cdf(np.arange(-2,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~Binom(n=10,p=0.5)')
Geom
#
- class Geom(loc=0, **kwargs)[source]#
Geometric distribution. Wrapper to scipy geometric distribution (
scipy.stats._discrete_distns.geom_gen
). Refer to :py:class:’~_DiscreteDistribution’ for additional details.- Parameters:
loc (
int
, optional) – location parameter (default=0), to shift the support of the distribution.**kwargs – See below
- Keyword Arguments:
p (
float
) – Probability parameter of the geometric distribution.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a more detailed explanation refer to the SciPy Geometric distribution documentation, see Virtanen et al. [VGO+20]..
for \(k \geq 1,0<p \leq 1\)
Example code on the usage of the Geom class:
from gemact import distributions
import numpy as np
p=0.8
dist=distributions.Geom(p=p)
seq=np.arange(0,100,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Theoretical mean',dist.mean())
print('Variance',variance)
print('Theoretical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Geom:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~Geom(p=0.8)')
#cdf
plt.step(np.arange(-2,20),dist.cdf(np.arange(-2,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~Geom(p=0.8)')
NegBinom
#
- class NegBinom(loc=0, **kwargs)[source]#
Negative Binomial distribution. Wrapper to scipy negative binomial distribution (
scipy.stats._discrete_distns.nbinom_gen
). Refer to :py:class:’~_DiscreteDistribution’ for additional details.- Parameters:
loc (
int
, optional) – location parameter (default=0), to shift the support of the distribution.**kwargs – See below
- Keyword Arguments:
n (
int
) – Size parameter of the negative binomial distribution.p (
float
) – Probability parameter of the negative binomial distribution.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated.- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a more detailed explanation refer to the SciPy Negative Binomial documentation, see Virtanen et al. [VGO+20].
for \(k \geq 0,0<p \leq 1\)
Example code on the usage of the NegBinom class:
from gemact import distributions
import numpy as np
n = 10
p = .5
dist = distributions.NegBinom(n=n, p=p)
seq = np.arange(0,100,.001)
nsim = int(1e+05)
# Compute the mean via pmf
mean = np.sum(dist.pmf(seq)*seq)
variance = np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean', mean)
print('Theoretical mean', dist.mean())
print('Variance', variance)
print('Theoretical variance', dist.var())
#compare with simulations
print('Simulated mean', np.mean(dist.rvs(nsim)))
print('Simulated variance', np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a NegBinom:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~NegBinom(n=10,p=0.8)')
#cdf
plt.step(np.arange(-2,20),dist.cdf(np.arange(-2,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~NegBinom(n=10,p=0.8)')
Logser
#
- class Logser(loc=0, **kwargs)[source]#
Logarithmic (Log-Series, Series) discrete distribution. Wrapper to scipy logser distribution (
scipy.stats._discrete_distns.logser_gen
) Refer to :py:class:’~_DiscreteDistribution’ for additional details.- Parameters:
loc (
int
, optional) – location parameter (default=0), to shift the support of the distribution.**kwargs – See below
- Keyword Arguments:
p (
float
) – Probability parameter of the logser distribution.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated.- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a more detailed explanation refer to the SciPy Logarithmic distribution documentation, see Virtanen et al. [VGO+20].
Given \(0 < p < 1\) and \(k \geq 1\).
Example code on the usage of the Logser class:
from gemact import distributions
import numpy as np
dist=distributions.Logser(p=.5)
seq=np.arange(0,30,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Logser:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~Logser(p=.5)')
#cdf
plt.step(np.arange(0,20),dist.cdf(np.arange(0,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~Logser(p=.5)')
ZTPoisson
#
- class ZTPoisson(loc=0, **kwargs)[source]#
Zero-truncated Poisson distribution. Poisson distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution:
scipy.stats._discrete_distns.poisson_gen
- Parameters:
loc (
int
, optional) – location parameter (default=0), to shift the support of the distribution.**kwargs – See below
- Keyword Arguments:
mu (
numpy.float64
) – Zero-truncated Poisson distribution parameter mu (rate).
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
float
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)[source]#
Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.int
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a Poisson distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Truncated poisson is defined in equation (18).
Example code on the usage of the ZTPoisson class:
from gemact import distributions
import numpy as np
mu=2
dist=distributions.ZTpoisson(mu=mu)
seq=np.arange(0,30,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZTPoisson:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZTPoisson(mu=2)')
#cdf
plt.step(np.arange(0,20),dist.cdf(np.arange(0,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZTPoisson(mu=2)')
ZMPoisson
#
- class ZMPoisson(loc=0, maxdiff=0.95, **kwargs)[source]#
Zero-modified Poisson distribution. Discrete mixture between a degenerate distribution at zero and a non-modified Poisson distribution. scipy reference non-zero-modified distribution:
scipy.stats._discrete_distns.poisson_gen
- Parameters:
loc (
int
, optional) – location parameter (default=0).maxdiff (
float
, optional) – threshold to determine which method to generate random variates (default=0.95).**kwargs – See below
- Keyword Arguments:
mu (
numpy.float64
) – Zero-modified Poisson distribution rate parameter.p0m (
numpy.float64
) – Zero-modified Poisson mixing parameter. Resulting probability mass in zero.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a Poisson distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Truncated poisson is defined in equation (19)
Example code on the usage of the ZMPoisson class:
from gemact import distributions
import numpy as np
mu=2
p0m=0.1
dist=distributions.ZMPoisson(mu=mu,p0m=p0m)
seq=np.arange(0,30,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZMPoisson:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZMPoisson(mu=2,p0m=.1)')
#cdf
plt.step(np.arange(0,20),dist.cdf(np.arange(0,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZMPoisson(mu=2,p0m=.1)')
ZTBinom
#
- class ZTBinom(**kwargs)[source]#
Zero-truncated binomial distribution. Binomial distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution:
scipy.stats._discrete_distns.binom_gen
.- Parameters:
**kwargs – See below
- Keyword Arguments:
n (
int
) – Zero-truncated binomial distribution size parameter n.p (
float
) – Zero-truncated binomial distribution probability parameter p.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)[source]#
Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.int
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a binomial distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Truncated binomial is defined in equation (20).
Example code on the usage of the ZTBinom class:
from gemact import distributions
import numpy as np
n=10
p=.2
dist=distributions.ZTBinom(n=n, p=p)
seq=np.arange(0,30,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZTBinom:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZTBinom(n=10 p=.2)')
#cdf
plt.step(np.arange(0,20),dist.cdf(np.arange(0,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZTBinom(n=10 p=.2)')
ZMBinom
#
- class ZMBinom(**kwargs)[source]#
Zero-modified binomial distribution. Discrete mixture between a degenerate distribution at zero and a non-modified binomial distribution. scipy reference non-zero-modified distribution:
scipy.stats._discrete_distns.binom_gen
.- Parameters:
**kwargs – See below
- Keyword Arguments:
n (
numpy.float64
) – Zero-modified binomial distribution size parameter n.p (
numpy.float64
) – Zero-modified binomial distribution probability parameter p.p0m (
numpy.float64
) – Zero-modified binomial mixing parameter.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural lograithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a binomial distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Truncated binomial is defined in equation (21)
Example code on the usage of the ZMBinom class:
from gemact import distributions
import numpy as np
n=10
p=.2
p0m=.05
dist=distributions.ZMBinom(n=n,p=p,p0m=p0m)
seq=np.arange(0,100,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZMPoisson:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZMBinom(n=10,p=.5,p0m=.05)')
#cdf
plt.step(np.arange(0,20),dist.cdf(np.arange(0,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZMBinom(n=10,p=.5,p0m=.05)')
ZTGeom
#
- class ZTGeom(**kwargs)[source]#
Zero-truncated geometric distribution. Geometric distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution:
scipy.stats._discrete_distns.geom_gen
- Parameters:
**kwargs – See below
- Keyword Arguments:
p (
numpy.float64
) – Zero-truncated geometric distribution probability parameter p.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)[source]#
Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.int
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a geometric distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Truncated geometric is defined in equation (22).
Example code on the usage of the ZTGeom class:
from gemact import distributions
import numpy as np
p=.2
dist=distributions.ZTGeom(p=p)
seq=np.arange(0,100,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZTGeom:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZTGeom(p=.2)')
#cdf
plt.step(np.arange(0,20),dist.cdf(np.arange(0,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZTGeom(p=.2)')
ZMGeom
#
- class ZMGeom(**kwargs)[source]#
Zero-modified geometric distribution. Discrete mixture between a degenerate distribution at zero and a non-modified geometric distribution. scipy reference non-zero-modified distribution: scipy.stats._discrete_distns.geom_gen`
- Parameters:
**kwargs – See below
- Keyword Arguments:
p (
numpy.float64
) – Zero-modified geometric distribution probability parameter p.p0m (
numpy.float64
) – Zero-modified geometric mixing parameter.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a geometric distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Modified geometric is defined in equation (23).
Example code on the usage of the ZMGeom class:
from gemact import distributions
import numpy as np
p=.2
p0m=.01
dist=distributions.ZMGeom(p=p,p0m=p0m)
seq=np.arange(0,100,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZMGeom:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZMGeom(p=.2,p0m=.01)')
#cdf
plt.step(np.arange(0,20),dist.cdf(np.arange(0,20)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZMGeom(p=.2,p0m=.01)')
ZTNegBinom
#
- class ZTNegBinom(**kwargs)[source]#
Zero-truncated negative binomial distribution. Negative binomial distribution with no mass (truncated) in 0. scipy reference non-zero-truncated distribution:
scipy.stats._discrete_distns.nbinom_gen
.- Parameters:
**kwargs – See below
- Keyword Arguments:
n (
int
) – Zero-truncated negative binomial distribution size parameter n.p (
numpy.float64
) – Zero-truncated negative binomial distribution probability parameter p.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)[source]#
Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.int
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a negative binomial distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Truncated negative binomial is defined in equation (24).
Example code on the usage of the ZTNegBinom class:
from gemact import distributions
import numpy as np
p=.2
n=10
dist=distributions.ZTNegBinom(p=p,n=n)
seq=np.arange(0,100,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZTNbinom:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZTNegBinom(p=.2,n=10)')
#cdf
plt.step(np.arange(0,100),dist.cdf(np.arange(0,100)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZTNegBinom(p=.2,n=10)')
ZMNegBinom
#
- class ZMNegBinom(**kwargs)[source]#
Zero-modified negative binomial distribution. Discrete mixture between a degenerate distribution at zero and a non-modified negative binomial distribution. scipy reference non-zero-modified distribution:
scipy.stats._discrete_distns.nbinom_gen
.- Parameters:
**kwargs – See below
- Keyword Arguments:
n (
int
) – Zero-modified negative binomial distribution size parameter n.p (
numpy.float64
) – Zero-modified negative binomial distribution probability parameter p.p0m (
numpy.float64
) – Zero-modified negative binomial mixing parameter.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (int) – quantile where the cumulative distribution function is evaluated.
- Returns:
cumulative distribution function.
- Return type:
numpy.float64 or numpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pgf(f)[source]#
Probability generating function. It computes the probability generating function of the random variable given the (a, b, k) parametrization.
- Parameters:
f (
numpy array
) – point where the function is evaluated- Returns:
probability generated in f.
- Return type:
numpy.ndarray
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a negative binomial distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Modified negative binomial is defined in equation (25).
Example code on the usage of the ZMNegBinom class:
from gemact import distributions
import numpy as np
p=.2
n=100
p0M=.2
dist=distributions.ZMNegBinom(n=50,
p=.8,
p0m=.01)
seq=np.arange(0,100,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZMNbinom:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZMNegBinom(p=.2,n=10)')
#cdf
plt.step(np.arange(0,100),dist.cdf(np.arange(0,100)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZMNegBinom(p=.2,n=10)')
ZMLogser
#
- class ZMLogser(**kwargs)[source]#
Zero-modified (discrete) logarithmic (log-series) distribution. Discrete mixture between a degenerate distribution at zero and a non-modified logarithmic distribution. scipy reference non-zero-modified distribution:
scipy.stats._discrete_distns.logser_gen
- Parameters:
**kwargs – See below
- Keyword Arguments:
p (
numpy.float64
) – ZM discrete logarithmic distribution probability parameter p.p0m (
numpy.float64
) – ZM discrete logarithmic mixing parameter.
- abk()[source]#
Function returning (a, b, k) parametrization.
- Returns:
a, b, probability in zero
- Return type:
numpy.array
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpmf(x)[source]#
Natural logarithm of the probability mass function.
- Parameters:
x (
int
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- par_deductible_adjuster(nu)[source]#
Parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- par_deductible_reverter(nu)[source]#
Undo parameter correction in case of deductible.
- Parameters:
nu (
float
) – severity model survival function at the deductible.- Returns:
Void
- Return type:
None
- pmf(x)[source]#
Probability mass function.
- Parameters:
x (
int
) – quantile where probability mass function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
Parametrization#
Let \(P(z)\) denote the probability generating function of a logarithmic distribution.
\(p_{0}\) is \(p_{0}=P[z=0]\).
The probability generating function of a Zero-Modified logarithmic is defined in equation (26).
Example code on the usage of the ZMLogser class:
from gemact import distributions
import numpy as np
p=.2
p0m=.01
dist=distributions.ZMlogser(p=p,p0m=p0m)
seq=np.arange(0,100,.001)
nsim=int(1e+05)
# Compute the mean via pmf
mean=np.sum(dist.pmf(seq)*seq)
variance=np.sum(dist.pmf(seq)*(seq-mean)**2)
print('Mean',mean)
print('Variance',variance)
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a ZMlogser:
import matplotlib.pyplot as plt
#pmf
plt.vlines(x=seq, ymin=0, ymax=dist.pmf(seq))
plt.title('Probability mass function, ~ZMlogser(p=.2, p0m=.01)')
#cdf
plt.step(np.arange(0,10),dist.cdf(np.arange(0,10)),'-', where='pre')
plt.title('Cumulative distribution function, ~ZMlogser(p=.2, p0m=.01)')
Gamma
#
- class Gamma(loc=0, scale=1.0, **kwargs)[source]#
Gamma distribution. When a is an integer it reduces to an Erlang distribution. When a=1 it reduces to an Exponential distribution. Wrapper to scipy gamma distribution (
scipy.stats._continuous_distns.gamma_gen
).- Parameters:
scale (
float
) – scale parameter (inverse of the rate parameter).loc (
float
) – location parameter.**kwargs – See below
- Keyword Arguments:
a (
int
orfloat
) – shape parameter a.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)[source]#
Partial moment of order n.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy Gamma distribution documentation, see Virtanen et al. [VGO+20].
Given \(f(x, a)=\frac{x^{a-1} e^{-x}}{\Gamma(a)}\) and \(x \geq 0, a>0\). \(\Gamma(a)\) refers to the gamma function.
Example code on the usage of the Gamma class:
from gemact import distributions
import numpy as np
a=2
b=5
dist=distributions.Gamma(a=a,
beta=b)
seq=np.arange(0,100,.1)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Gamma:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Gamma(a=2, beta=5)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Gamma(a=2, beta=5)')
Exponential
#
- class Exponential(loc=0, theta=1)[source]#
Expontential distribution. scipy reference distribution:
scipy.stats._continuous_distns.expon_gen
- Parameters:
theta (
float
) – exponential distribution theta parameter.loc (
float
) – location parameter
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
numpy.ndarray
) – the cumulative distribution function will be computed in x.- Returns:
cumulative distribution function
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()[source]#
(Differential) entropy of the RV.
- Returns:
(differential) entropy.
- Return type:
numpy.float64
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(x)[source]#
Inverse survival function (inverse of sf).
- Parameters:
x (
numpy.ndarray
) – point where the inverse of the survival function is evaluated.- Returns:
inverse of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
) – point where the natural logarithm of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)[source]#
Natural logarithm of the probability density function.
- Parameters:
x (
numpy.ndarray
) – the log of the probability function will be computed in x.- Returns:
logpdf
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)[source]#
Natural logarithm of the survival function.
- Parameters:
x (
int
) – point where the natural logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)[source]#
Partial moment of order n.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)[source]#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability density function is evaluated.- Returns:
probability density function
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)[source]#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)[source]#
Random variates.
- Parameters:
size (
int
) – random variates sample size (default is 1).random_state (
int
) – random state for the random number generator.
- Returns:
Random variates.
- Return type:
numpy.float64
ornumpy.ndarray
- sf(x)[source]#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
) – point where the survival is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()[source]#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
numpy.float64
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
Parametrization#
Given \(\theta \geq 0\).
Example code on the usage of the Exponential class:
from gemact import distributions
import numpy as np
theta=.1
dist=distributions.Exponential(theta=theta)
seq=np.arange(0,200,.1)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of an Exponential:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Gamma(a=2, beta=5)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Gamma(a=2, beta=5)')
InvGauss
#
- class InvGauss(loc=0.0, scale=1.0, **kwargs)[source]#
Wrapper to scipy inverse gaussian distribution.
scipy.stats._continuous_distns.invgauss_gen object
- Parameters:
scale (
float
) – scale parameter.loc (
float
) – location parameter.**kwargs – See below
- Keyword Arguments:
mu (
int
orfloat
) – shape parameter mu.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy InvGauss distribution documentation, see Virtanen et al. [VGO+20].
InvGamma
#
- class InvGamma(loc=0, scale=1, **kwargs)[source]#
Wrapper to scipy inverse gamma distribution.
scipy.stats._continuous_distns.invgamma_gen object
- Parameters:
scale (
float
) – scale parameter.loc (
float
) – location parameter.**kwargs – See below
- Keyword Arguments:
a (
int
orfloat
) – shape parameter a.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy Inverse Gamma distribution documentation, see Virtanen et al. [VGO+20]. Virtanen et al. [VGO+20].
Given \(x>=0, a>0 `. :math:\)Gamma(a)` refers to the gamma function.
GenPareto
#
- class GenPareto(loc=0, scale=1.0, **kwargs)[source]#
Wrapper to scipy genpareto distribution. When c (i.e. shape) = 0, it reduces to an Exponential distribution. When c (i.e. shape) = -1, it reduces to a uniform distribution. When the correct parametrization is adopted, it is possible to fit all the Pareto types. scipy reference distribution:
scipy.stats._continuous_distns.genpareto_gen
.- Parameters:
scale (
float
) – scale parameter.loc (
float
) – location parameter.**kwargs – See below
- Keyword Arguments:
c (
int
orfloat
) – shape parameter.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy documentation, see Virtanen et al. [VGO+20].
Given \(x \geq 0\) if \(c \geq 0\). \(0 \leq x \leq-1 / c if c<0\).
Example code on the usage of the GenPareto class:
from gemact import distributions
import numpy as np
c=.4
loc=0
scale=0.25
dist=distributions.Genpareto(c=c,
loc=loc,
scale=scale)
seq=np.arange(0,100,.1)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a GenPareto:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=50,
density=True)
plt.title('Probability density function, ~GenPareto(a=2, beta=5)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~GenPareto(a=2, beta=5)')
Pareto2
#
- class Pareto2(min=0, scale=1, **kwargs)[source]#
Pareto TypeII distribution. This is a Genpareto distribution with parameter loc = min; scale = scale/shape and c = 1/shape. See
scipy.stats._continuous_distns.genpareto
.- Parameters:
min (
float
) – location parameter.scale (
float
) – scale parameter.**kwargs – See below
- Keyword Arguments:
- shape (
int
orfloat
) – shape parameter.
- shape (
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
Given \(x>m,-\infty<m<\infty, 1/s>0 p>0\).
Example code on the usage of the Pareto2 class:
from gemact import distributions
import numpy as np
s=2
dist=distributions.Pareto2(s=.9)
seq=np.arange(0,100,.1)
nsim=int(1e+08)
Pareto1
#
- class Pareto1(min=0, **kwargs)[source]#
Single-parameter Pareto distribution. This is a Pareto II distribution with parameter scale = min.
scipy.stats._continuous_distns.genpareto
- Parameters:
min (
float
) – pareto 1 location parameter.**kwargs – See below
- Keyword Arguments:
- shape (
int
orfloat
) – shape parameter.
- shape (
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Lognormal
#
- class Lognormal(scale=1.0, **kwargs)[source]#
Lognormal distribution. The more common parametrization lognormal(mu, sigma), where mu and sigma are the parameter of the underlying Normal distribution, is equivalent to lognormal(log(scale), shape). scipy reference distribution:
scipy.stats._continuous_distns.lognorm_gen
- Parameters:
scale (
float
) – lognormal scale parameter. The natural logarithm of scale is the mean of the underlying Normal distribution.**kwargs – See below
- Keyword Arguments:
shape (
int
orfloat
) – shape parameter. It corresponds to the standard deviation of the underlying Normal distribution.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)[source]#
Partial moment of order n.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy Lognormal distribution documentation, see Virtanen et al. [VGO+20].
Given \(x>0, s>0\).
Example code on the usage of the Lognormal class:
from gemact import distributions
import numpy as np
s=2
dist=distributions.Lognorm(s=s)
seq=np.arange(0,100,.1)
nsim=int(1e+08)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a LogNorm:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=20,
density=True)
plt.title('Probability density function, ~LogNormal(s=2)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~LogNormal(s=2)')
Burr12
#
- class Burr12(loc=0, scale=1, **kwargs)[source]#
Burr distribution, also referred to as the Burr Type XII, Singh–Maddala distribution. When d=1, this is a Fisk distribution. When c=d, this is a Paralogistic distribution. scipy reference distribution:
scipy.stats._continuous_distns.burr_gen object
- Parameters:
scale (
float
) – burr scale parameter.loc (
float
) – burr location parameter.**kwargs – See below
- Keyword Arguments:
c (
int
orfloat
) – shape parameter c.d (
int
orfloat
) – shape parameter d.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the Scipy Burr12 distribution documentation , see Virtanen et al. [VGO+20].
Given \(x>=0 and c, d>0\).
Example code on the usage of the Burr12 class:
from gemact import distributions
import numpy as np
c=2
d=3
dist=distributions.Burr12(c=c,
d=d)
seq=np.arange(0,100,.1)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Burr12:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Burr12(c=c,d=d)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Burr12(c=c,d=d)')
Paralogistic
#
- class Paralogistic(loc=0, scale=1, **kwargs)[source]#
Paralogistic distribution. This is a Burr12 distribution with same parameters.
scipy.stats._continuous_distns.burr12
- Parameters:
scale (
float
) – paralogistic scale parameter.loc (
float
) – paralogistic location parameter.**kwargs – See below
- Keyword Arguments:
a (
int
orfloat
) – distribution parameter a.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
Given \(x>=0 and a >0\).
Example code on the usage of the Paralogistic class:
from gemact import distributions
import numpy as np
a=2
dist=distributions.Paralogistic(a=a)
seq=np.arange(0,100,.1)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Burr12:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Paralogistic(a=a)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Paralogistic(a=a)')
Dagum
#
- class Dagum(loc=0, scale=1, **kwargs)[source]#
Wrapper to scipy mielke distribution. It is referred to the Inverse Burr, Mielke Beta-Kappa. When d=s, this is an inverse paralogistic.
scipy.stats._continuous_distns.mielke
- Parameters:
scale (
float
) – dagum scale parameter.loc (
float
) – dagum location parameter.**kwargs – See below
- Keyword Arguments:
d (
int
orfloat
) – shape parameter d.s (
int
orfloat
) – shape parameter s.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy Dagum distribution documentation ,see Virtanen et al. [VGO+20].
Given \(x>0\) , \(k,s>0\).
Example code on the usage of the Dagum class:
from gemact import distributions
import numpy as np
d=2
s=4.2
dist=distributions.Dagum(d=d,
s=s)
seq=np.arange(0,3,.001)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Dagum:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Dagum(d=4,s=2)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Dagum(d=c,s=4.2)')
Inverse Paralogistic
#
- class InvParalogistic(loc=0, scale=1, **kwargs)[source]#
Inverse paralogistic distribution. This is a Dagum distribution with same parameters.
scipy.stats._continuous_distns.mielke
- Parameters:
scale (
float
) – inverse paralogistic scale parameter.loc (
float
) – inverse paralogistic location parameter.**kwargs – See below
- Keyword Arguments:
- b (
int
orfloat
) – distribution parameter b.
- b (
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
Given \(x>0\) , \(b>0\).
Example code on the usage of the InvParalogistic class:
from gemact import distributions
import numpy as np
b=2
dist=distributions.InvParalogistic(b=b)
seq=np.arange(0,3,.001)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Dagum:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~InvParalogistic(b=2)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~InvParalogistic(b=2)')
Weibull
#
- class Weibull(loc=0, scale=1, **kwargs)[source]#
Wrapper to scipy Weibull (Weibull_min) distribution.
scipy.stats._continuous_distns.weibull_min_gen object
- Parameters:
scale (
float
) – scale parameter.loc (
float
) – location parameter.**kwargs – See below
- Keyword Arguments:
c (
int
orfloat
) – shape parameter c.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy Weibull distribution documentation , see Virtanen et al. [VGO+20].
Given \(x>0\) , \(c>0\).
Example code on the usage of the Weibull class:
from gemact import distributions
import numpy as np
c=2.2
dist=distributions.Weibull_min(c=c)
seq=np.arange(0,3,.001)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Weibull_min:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Weibull_min(s=2.2)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Invweibull(c=7.2)')
InvWeibull
#
- class InvWeibull(loc=0, scale=1, **kwargs)[source]#
Wrapper to scipy inverse Weibull distribution.
scipy.stats._continuous_distns.invweibull_gen object
- Parameters:
scale (
float
) – scale parameter.loc (
float
) – location parameter.**kwargs – See below
- Keyword Arguments:
c (
int
orfloat
) – shape parameter c.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the`Scipy Inverse Weibull distribution documentation <https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.invweibull.html>`_ Virtanen et al. [VGO+20] .
Given \(x>0\) , \(c>0\).
Example code on the usage of the InvWeibull class:
from gemact import distributions
import numpy as np
c=7.2
dist=distributions.Invweibull(c=c)
seq=np.arange(0,3,.001)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Invweibull:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Invweibull(c=7.2)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Invweibull(c=7.2)')
Beta
#
- class Beta(loc=0, scale=1, **kwargs)[source]#
Wrapper to scipy beta distribution.
scipy.stats._continuous_distns.beta_gen
- Parameters:
scale (
float
) – beta scale parameter.loc (
float
) – beta location parameter.**kwargs – See below
- Keyword Arguments:
a (
int
orfloat
) – shape parameter a.b (
int
orfloat
) – shape parameter b.
- cdf(x)#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- entropy()#
(Differential) entropy of the random variable.
- Returns:
entropy
- Return type:
numpy.ndarray
- expect(func, lb=None, ub=None, conditional=False)#
Expected value of a function (of one argument) with respect to the distribution.
- Parameters:
func (
callable
, optional) – function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.lb (
float
, optional) – Lower bound for integration. Default is set to the support of the distribution.ub (
float
, optional) – Upper bound for integration. Default is set to the support of the distribution.conditional (
bool
, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.
- Returns:
the calculated expected value.
- Return type:
float
- fit(data)#
Return estimates of shape (if applicable), location, and scale parameters from data. The default estimation method is Maximum Likelihood Estimation (MLE), but Method of Moments (MM) is also available. Refer to
scipy.stats.rv_continuous.fit
- Parameters:
data (array_like) – data to use in estimating the distribution parameters.
- Returns:
parameter_tuple. Estimates for any shape parameters (if applicable), followed by those for location and scale.
- Return type:
tuple of floats
- interval(alpha)#
Endpoints of the range that contains fraction alpha [0, 1] of the distribution.
- Parameters:
alpha (
float
) – fraction alpha- Returns:
Endpoints
- Return type:
tuple
- isf(q)#
Inverse survival function (inverse of sf).
- Parameters:
q (
float
) – level at which the inverse survival function is evaluated.- Returns:
inverse survival function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- kurtosis()#
Excess kurtosis.
- Returns:
Excess kurtosis.
- Return type:
float
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where log of the cumulative distribution function is evaluated.- Returns:
natural logarithm of the cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)#
Natural logarithm of the probability denisty function.
- Parameters:
x (
float
) – quantile where the (natural) probability mass function logarithm is evaluated.- Returns:
natural logarithm of the probability mass function
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)#
Natural logarithm of the survival function.
- Parameters:
x (
int
orfloat
) – quantile where the logarithm of the survival function is evaluated.- Returns:
natural logarithm of the survival function
- Return type:
numpy.float64
ornumpy.ndarray
- mean()#
Mean of the distribution.
- Returns:
mean.
- Return type:
float
- median()#
Median of the distribution.
- Returns:
median.
- Return type:
float
- moment(n)#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)#
Non-central partial moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability denisty function is evaluated.- Returns:
probability density function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)#
Random variates generator function.
- Parameters:
size (
int
, optional) – random variates sample size (default is 1).random_state (
int
, optional) – random state for the random number generator (default=None).
- Returns:
random variates.
- Return type:
numpy.int
ornumpy.ndarray
- sf(x)#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- skewness()#
Skewness (third standardized moment).
- Returns:
skewness.
- Return type:
float
- stats(moments='mv')#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) function.
- Parameters:
moments (string, optional) – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
- truncated_moment(n, low, up)#
Non-central truncated moment of order n. General method for continuous distributions, overridden by distribution specific implementation if available.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower truncation point.up (
int
,float
) – upper truncation point.
- Returns:
raw truncated moment of order n.
- Return type:
float
- var()#
Variance of the distribution.
- Returns:
variance.
- Return type:
float
Parametrization#
For a better explanation refer to the SciPy Beta distribution documentation, Virtanen et al. [VGO+20] .
Given \(0<=x<=1, a>0, b>0\) , \(\Gamma\) is the gamma function.
Example code on the usage of the Beta class:
from gemact import distributions
import numpy as np
a=2
b=5
dist=distributions.Beta(a=a,
b=b)
seq=np.arange(0,1,.001)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a Beta:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~Beta(a=2,b=5)')
#cdf
plt.plot(seq,dist.cdf(seq))
plt.title('Cumulative distribution function, ~Beta(a=2,b=5)')
Loggamma
#
- class LogGamma(scale=1.0, **kwargs)[source]#
Log Gamma distribution. Random variable whose logarithm transformation is Gamma distributed. Parameters (
a
andscale
) refer to the underlying log-transformed random variable. Remark: distribution form and parametrization differ from <scipy.stats._continuous_distns.loggamma_gen object>- Parameters:
scale (
float
) – scale parameter (inverse of the rate parameter).**kwargs – See below
- Keyword Arguments:
a (
int
orfloat
) – shape parameter a.
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the cumulative distribution function is evaluated.- Returns:
cumulative distribution function.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)[source]#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- isf(q)[source]#
Inverse survival function (inverse of sf).
- Parameters:
q – Inverse survival function computed in q.
- Returns:
inverse sf
- Return type:
numpy.float64
ornumpy.ndarray
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
float
) – natural logarithm of the cumulative distribution function computed in x.- Returns:
natural logarithm of the cumulative distribution function in x.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)[source]#
Natural logarithm of the probability distribution function.
- Parameters:
x (
float
) – natural logarithm of the probability distribution function computed in x.- Returns:
natural logarithm of the probability distribution function computed in x.
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)[source]#
Natural logarithm of the survival function.
- Parameters:
x (
float
) – natural logarithm of the survival function computed in x.- Returns:
natural logarithm of the survival function in x
- Return type:
numpy.float64
ornumpy.ndarray
- moment(n)[source]#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)[source]#
Non-central partial moment of order n.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)[source]#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability density function is evaluated.- Returns:
probability mass function.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)[source]#
Percent point function, a.k.a. the quantile function, inverse of the cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)[source]#
Random variates.
- Parameters:
size (
int
) – random variates sample size (default is 1).random_state (
int
) – random state for the random number generator.
- Returns:
Random variates.
- Return type:
numpy.float64
ornumpy.ndarray
- sf(x)[source]#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
int
orfloat
) – quantile where the survival function is evaluated.- Returns:
survival function
- Return type:
numpy.float64
ornumpy.ndarray
- stats(moments='mv')[source]#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
- Parameters:
moments – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()[source]#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
float
Parametrization#
where \(x>0, \alpha>0, \lambda >0\) and \(\Gamma(\alpha)\) is the Gamma function.
GenBeta
#
- class GenBeta(shape1, shape2, shape3, scale=1.0)[source]#
Generalized Beta (GB) distribution, also refer to as Generalized Beta of the second kind, or the Generalized Beta Prime distribution. If X is a GB distributed r.v., its cumulative distribution function can be expressed as:
Pr[X <= x] = Pr[Y <= (x/scale)^shape3], 0 < x < scale,
where Y has a Beta distribution, with parameters shape1 and shape2. Refer to Appendix A of Klugman, Panjer & Willmot, Loss Models, Wiley.
- cdf(x)[source]#
Cumulative distribution function.
- Parameters:
x (
float
) – cumulative distribution function will be computed in x.- Returns:
cumulative distribution function in x.
- Return type:
numpy.float64
ornumpy.ndarray
- censored_moment(n, d, c)[source]#
Non-central moment of order n of the transformed random variable min(max(x - d, 0), c). When n = 1 it is the so-called stop loss transformation function.
- Parameters:
d (
int
,float
) – deductible, or attachment point.c (
int
,float
) – cover, deductible + cover is the detachment point.n (
int
) – moment order.
- Returns:
raw moment of order n.
- Return type:
float
- isf(q)[source]#
Inverse survival function (inverse of sf).
- Parameters:
q – Inverse survival function computed in q.
- Returns:
inverse sf
- Return type:
numpy.float64
ornumpy.ndarray
- lev(v)[source]#
Limited expected value, i.e. expected value of the function min(x, v).
- Parameters:
v (
numpy.float
ornumpy.ndarray
) – values with respect to the minimum.- Returns:
expected value of the minimum function.
- Return type:
numpy.float
ornumpy.ndarray
- logcdf(x)[source]#
Natural logarithm of the cumulative distribution function.
- Parameters:
x (
float
) – natural logarithm of the cumulative distribution function computed in x.- Returns:
natural logarithm of the cumulative distribution function in x.
- Return type:
numpy.float64
ornumpy.ndarray
- logpdf(x)[source]#
Natural logarithm of the probability distribution function.
- Parameters:
x (
float
) – natural logarithm of the probability distribution function computed in x.- Returns:
natural logarithm of the probability distribution function computed in x.
- Return type:
numpy.float64
ornumpy.ndarray
- logsf(x)[source]#
Natural logarithm of the survival function.
- Parameters:
x (
float
) – natural logarithm of the survival function computed in x.- Returns:
natural logarithm of the survival function in x
- Return type:
numpy.float64
ornumpy.ndarray
- moment(n)[source]#
Non-central moment of order n.
- Parameters:
n (
int
) – moment order.- Returns:
raw moment of order n.
- Return type:
float
- partial_moment(n, low, up)[source]#
Non-central partial moment of order n.
- Parameters:
n (
int
) – moment order.low (
int
,float
) – lower limit of the partial moment.up (
int
,float
) – upper limit of the partial moment.
- Returns:
raw partial moment of order n.
- Return type:
float
- pdf(x)[source]#
Probability density function.
- Parameters:
x (
numpy.ndarray
,list
,float
,int
) – quantile where probability density function is evaluated.- Returns:
probability density function in x.
- Return type:
numpy.float64
ornumpy.ndarray
- ppf(q)[source]#
Percent point function, a.k.a. the quantile function, inverse of cumulative distribution function.
- Parameters:
q (
float
) – level at which the percent point function is evaluated.- Returns:
percent point function.
- Return type:
numpy.float64
ornumpy.int
ornumpy.ndarray
- rvs(size=1, random_state=None)[source]#
Random variates.
- Parameters:
size (
int
) – random variates sample size (default is 1).random_state (
int
) – random state for the random number generator.
- Returns:
Random variates.
- Return type:
numpy.float64
ornumpy.ndarray
- sf(x)[source]#
Survival function, 1 - cumulative distribution function.
- Parameters:
x (
float
) – survival function will be computed in x.- Returns:
survival function in x
- Return type:
numpy.float64
ornumpy.ndarray
- stats(moments='mv')[source]#
Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
- Parameters:
moments – moments to be returned.
- Returns:
moments.
- Return type:
tuple
- std()[source]#
Standard deviation of the distribution.
- Returns:
standard deviation.
- Return type:
numpy.float64
Parametrization#
Given \(0<=x<=scale, shape_1>0, shape_2>0\) , \(\Gamma\) is the gamma function.
Example code on the usage of the GenBeta class:
from gemact import distributions
import numpy as np
shape1=1
shape2=2
shape3=3
scale=4
dist=GenBeta(shape1=shape1,
shape2=shape2,
shape3=shape3,
scale=scale)
seq=np.arange(0,1,.001)
nsim=int(1e+05)
print('Theorical mean',dist.mean())
print('Theorical variance',dist.var())
#compare with simulations
print('Simulated mean',np.mean(dist.rvs(nsim)))
print('Simulated variance',np.var(dist.rvs(nsim)))
Then, use matplotlib
library to show the pmf and the cdf of a GenBeta:
import matplotlib.pyplot as plt
#pmf
plt.hist(dist.rvs(nsim),
bins=100,
density=True)
plt.title('Probability density function, ~GenBeta(shape1=1,shape2=2,shape3=3,scale=4)')
#cdf
plt.plot(np.arange(-1,8,.001),dist.cdf(np.arange(-1,8,.001)))
plt.title('Cumulative distribution function, ~GenBeta(shape1=1,shape2=2,shape3=3,scale=4)')
The copulas
module#
Guide to copulas
ClaytonCopula
#
- class ClaytonCopula(par, dim)[source]#
Clayton copula.
- Parameters:
par (
float
) – copula parameter.dim (
int
) – copula dimension.
Parametrization#
Clayton copula cumulative density function:
Given \(u_{k} \in[0,1], k=1, \ldots, d\) , \(\delta > 0\) .
Example code on the usage of the ClaytonCopula class:
from gemact import copulas
clayton_c=copulas.ClaytonCopula(par=1.4,
dim=2)
clayton_c.rvs(size=100,
random_state= 42)
FrankCopula
#
- class FrankCopula(par, dim)[source]#
Frank copula.
- Parameters:
par (
float
) – copula parameter.dim (
int
) – copula dimension.
Parametrization#
Frank copula cumulative density function:
Given \(u_{k} \in[0,1], k=1, \ldots, d\) , \(\delta >= 0\) .
Example code on the usage of the FrankCopula class:
from gemact import copulas
frank_c=copulas.FrankCopula(par=1.4,
dim=2)
frank_c.rvs(size=100,
random_state= 42)
GumbelCopula
#
- class GumbelCopula(par, dim)[source]#
Gumbel copula.
- Parameters:
par (
float
) – copula parameter.dim (
int
) – copula dimension.
Parametrization#
Gumbel copula cumulative density function:
Given \(u_{k} \in[0,1], k=1, \ldots, d\) , \(\delta >= 1\) .
Example code on the usage of the GumbelCopula class:
from gemact import copulas
gumbel_c=copulas.GumbelCopula(par=1.4,
dim=2)
gumbel_c.rvs(size=100,
random_state= 42)
GaussCopula
#
- class GaussCopula(corr)[source]#
Gaussian copula.
- Parameters:
corr (
numpy.ndarray
) – Correlation matrix.
Parametrization#
Gauss copula cumulative density function is based on the scipy function multivariate_normal. For a better explanation refer to the SciPy Multivariate Normal documentation, Virtanen et al. [VGO+20] .
Example code on the usage of the GaussCopula class:
from gemact import copulas
corr_mx=np.array([[1,.4],[.4,1]])
gauss_c=copulas.GaussCopula(corr=corr_mx)
gauss_c.rvs(size=100,
random_state= 42)
TCopula
#
- class TCopula(corr, df)[source]#
Student t copula.
- Parameters:
corr (
numpy.ndarray
) – Correlation matrix.df (
int
) – Degree of freedom.
- cdf(x, tolerance=0.0001, n_iterations=30)[source]#
Cumulative distribution function.
- Parameters:
x (
numpy.ndarray
) – quantile where the cumulative distribution function is evaluated. Array with shape (n, d) where n is the number of data points and d the dimension.tolerance (
float
, optional) – tolerance threshold of approximation (default is 1e-4).n_iterations (
int
, optional) – number of iteration (default is 30).
- Returns:
Cumulative distribution function in x.
- Return type:
numpy.ndarray
Parametrization#
T copula cumulative density function:
Given \(u_{k} \in[0,1], k=1, \ldots, d\). \(t_{v}^{-1}\) is the inverse student’s t function and \(\boldsymbol{t}_{v, C}\) is the cumulative distribution function of the multivariate student’s t distribution with a given mean and correlation matrix C. Degrees of freedom \(v>0\) .
Example code on the usage of the TCopula class:
from gemact import copulas
corr_mx=np.array([[1,.4],[.4,1]])
t_c=copulas.TCopula(corr=corr_mx,
df=5)
t_c.rvs(size=100,
random_state= 42)
Independence Copula
#
- class IndependenceCopula(dim)[source]#
The product (independence) copula.
- Parameters:
dim (
int
) – copula dimension.
Parametrization#
Independence Copula.
Given \(u_{k} \in[0,1], k=1, \ldots, d\).
Example code on the usage of the IndependentCopula class:
from gemact import copulas
i_c = copulas.IndependentCopula(dim=2)
i_c.rvs(1,random_state=42)
Fréchet–Hoeffding Lower Bound
#
- class FHLowerCopula[source]#
Fréchet–Hoeffding lower bound bidimensional copula.
Parametrization#
The Fréchet–Hoeffding Lower Bound Copula.
Given \(u_{k} \in[0,1], k=1, 2\).
Example code on the usage of the FHLowerCopula class:
from gemact import copulas
fhl_c = copulas.FHLowerCopula
fhl_c.rvs(10,
random_state=42)
Fréchet–Hoeffding Upper Bound
#
- class FHUpperCopula(dim)[source]#
Fréchet–Hoeffding upper bound copula.
Parametrization#
The Fréchet–Hoeffding Upper Bound Copula.
Given \(u_{k} \in[0,1], k=1, 2\).
Example code on the usage of the FHUpperCopula class:
from gemact import copulas
fhu_c = copulas.FHUpperCopula
fhu_c.rvs(10,
random_state=42)
References#
Philipp Arbenz, Paul Embrechts, and Giovanni Puccetti. The aep algorithm for the fast computation of the distribution of the sum of dependent random variables. Bernoulli, 17:562–591, 2011.
P. Embrechts and M. Frei. Panjer recursion versus fft for compound distributions. Mathematical Methods of Operations Research, 2008.
Wayne H. Fisher, Jeffrey T. Lange, and John Balcarek. Loss reserve testing: a report year approach. 1999.
Alessandro Ricotta and Gian Paolo Clemente. An extension of collective risk model for stochastic claim reserving. 2016.
Nino Savelli and Gian Paolo Clemente. Lezioni di matematica attuariale delle assicurazioni danni. EDUCatt-Ente per il diritto allo studio universitario dell'Università Cattolica, 2014. ISBN 9788867807048. URL: http://hdl.handle.net/10807/67154.
B. Sundt. On excess of loss reinsurance with reinstatements. Insurance: Mathematics and Economics, 1991.
Pauli Virtanen, Ralf Gommers, Travis E. Oliphant, Matt Haberland, Tyler Reddy, David Cournapeau, Evgeni Burovski, Pearu Peterson, Warren Weckesser, Jonathan Bright, Stéfan J. van der Walt, Matthew Brett, Joshua Wilson, K. Jarrod Millman, Nikolay Mayorov, Andrew R. J. Nelson, Eric Jones, Robert Kern, Eric Larson, C J Carey, İlhan Polat, Yu Feng, Eric W. Moore, Jake VanderPlas, Denis Laxalde, Josef Perktold, Robert Cimrman, Ian Henriksen, E. A. Quintero, Charles R. Harris, Anne M. Archibald, Antônio H. Ribeiro, Fabian Pedregosa, Paul van Mulbregt, and SciPy 1.0 Contributors. SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python. Nature Methods, 17:261–272, 2020. doi:10.1038/s41592-019-0686-2.