distributions.Count
A claim count from one of the families beyond the Poisson, negative
Usage
distributions.Count()binomial and binomial: zero-modified and zero-truncated counts, the logarithmic, mixed Poisson counts (negative binomial, Delaporte, Poisson-inverse Gaussian and its shifted version), Poisson-stopped sums (Neyman type A, Pólya-Aeppli) and empirical counts. These are aggregate’s zm, zt, logarithmic, mixed, neymana and dfreq. Make one with a static constructor; every aggregation function takes it like any other count.
Examples
>>> from prospicio.distributions import Count, Poisson
>>> n = Count.zero_truncated(Poisson(2.0))
>>> n.pmf(0)0.0
>>> pig = Count.mixed_poisson(10.0, 0.5, mixing="inverse_gaussian")
>>> round(pig.variance(), 9)35.0
Methods
| Name | Description |
|---|---|
| bernoulli() |
A Bernoulli count, one claim with probability p in [0, 1),
|
| cdf() |
P(N <= k).
|
| compound_poisson() |
A Poisson(rate) number of clusters, each a secondary count:
|
| empirical() |
An empirical count, P(N = k) = probs[k].
|
| fixed() |
A fixed count, N = n, aggregate’s fixed.
|
| geometric() |
A geometric count on 0, 1, ... with this mean, a negative
|
| gig() | The generalized inverse Gaussian a Sichel mixing solved, as a dict |
| logarithmic() |
The logarithmic count on 1, 2, ...:
|
| mean() | Mean of the claim count. |
| mixed_poisson() |
A Poisson count whose mean is mean * theta, with the mixing
|
| panjer_ab() |
(a, b) of the (a, b, 1) class, or None when Panjer’s
|
| pmf() |
P(N = k).
|
| quantile() |
Smallest k with P(N <= k) >= p.
|
| renewal() |
The number of claims by horizon when the waits between claims
|
| sample() |
n claim counts from stream stream of the generator keyed by
|
| variance() | Variance of the claim count. |
| zero_modified() |
The base count with P(N = 0) = p0; the other probabilities are
|
| zero_truncated() | The base count conditioned on at least one claim. |
bernoulli()
A Bernoulli count, one claim with probability p in [0, 1),
Usage
bernoulli(p)Parameters
p: float
Returns
Count
Raises
ValueError-
If p is outside
[0, 1).
cdf()
P(N <= k).
Usage
cdf(k)Parameters
k: int
Returns
float
compound_poisson()
A Poisson(rate) number of clusters, each a secondary count:
Usage
compound_poisson(rate, secondary)Poisson secondaries give the Neyman type A.
Parameters
rate: floatsecondary: (Poisson, NegativeBinomial, Binomial or Count)
Returns
Count
empirical()
An empirical count, P(N = k) = probs[k].
Usage
empirical(probs)Parameters
probs: list of float- Non-negative, summing to 1.
Returns
Count
fixed()
Usage
fixed(n)Parameters
n: int or float-
A whole number of claims;
2.5is refused, as aggregate 2.1.0 refuses a fractional fixed count.
Returns
Count
Examples
>>> from prospicio.distributions import Count
>>> n = Count.fixed(3)
>>> n.mean(), n.variance()(3.0, 0.0)
geometric()
A geometric count on 0, 1, ... with this mean, a negative
Usage
geometric(mean)Parameters
mean: float
Returns
Count
Raises
ValueError- If mean is not finite and positive.
Examples
>>> from prospicio.distributions import Count
>>> round(Count.geometric(3.0).pmf(0), 12)0.25
gig()
The generalized inverse Gaussian a Sichel mixing solved, as a dict
Usage
gig()Returns
dict or None
logarithmic()
The logarithmic count on 1, 2, ...:
Usage
logarithmic(p)P(N = k) = -p**k / (k log(1 - p)).
Parameters
p: float-
In
(0, 1).
Returns
Count
mean()
Mean of the claim count.
Usage
mean()Returns
float
mixed_poisson()
A Poisson count whose mean is mean * theta, with the mixing
Usage
mixed_poisson(
mean,
cv,
mixing="gamma",
shift=0.0,
*,
max=None,
shape=None,
skewness=None,
f=None
)variable theta = shift + (1 - shift) G of mean 1 and coefficient of variation cv; variance mean + mean**2 cv**2.
Parameters
mean: floatcv: float-
Coefficient of variation of theta, fixed part included.
mixing: (gamma, inverse_gaussian, beta, sichel, sichel_skewness, sichel_gamma, sichel_ig) = "gamma"-
The distribution of G. Gamma gives the negative binomial (
shift = 0) or the Delaporte; inverse Gaussian the Poisson-inverse Gaussian or its shifted version. The others take no shift, as aggregate’s:"beta", the Poisson meanmaxtimes a beta variable (mixed beta cv max);"sichel", the generalized inverse Gaussian with the given shape (mixed sichel cv shape;-0.5is the inverse Gaussian) or, with skewness instead, the shape that gives that skewness (also named"sichel_skewness");"ig"is"inverse_gaussian";"sichel_gamma"and"sichel_ig", the generalized inverse Gaussian with the skewness of the Delaporte’s or the shifted inverse Gaussian’s mixing with fixed partf(mixed sichel.gamma cv f,mixed sichel.ig cv f). shift: float = 0.0-
The fixed part of theta, in
[0, 1). max: float = None-
The beta mixing’s largest Poisson mean, above
mean (1 + cv**2). shape: float = None-
The Sichel shape.
skewness: float = None-
The Sichel mixing’s skewness, for
"sichel"without a shape. f: float = None-
The fixed part matched by
"sichel_gamma"and"sichel_ig".
Returns
Count
panjer_ab()
(a, b) of the (a, b, 1) class, or None when Panjer’s
Usage
panjer_ab()recursion does not apply (use FFT).
Returns
tuple of (float, float) or None
pmf()
P(N = k).
Usage
pmf(k)Parameters
k: int
Returns
float
quantile()
Smallest k with P(N <= k) >= p.
Usage
quantile(p)Parameters
p: float
Returns
int
renewal()
The number of claims by horizon when the waits between claims
Usage
renewal(wait, horizon, *, step=None, points=None, closed=False)are independent draws from wait: a renewal (Sparre Andersen) count, aggregate’s years ... wait ... frequency. Exponential waits give the Poisson.
The wait is put on a grid and the count read off by FFT; waits of zero arrive in clusters, and waits whose probabilities sum to less than 1 end the process. The grid is aggregate’s by default.
Parameters
wait: distribution or tuple of (list of float, list of float)-
The wait’s distribution, or its values and their probabilities (aggregate’s
dwait), which may sum to less than 1. horizon: float-
The period, in the wait’s units.
step: float = None-
The wait grid’s step; give it with points.
points: int = None-
The wait grid’s number of points.
closed: bool = False-
With step: whether waits summing to exactly
horizoncount in full (waits on the grid’s lattice), not half.
Returns
Count
Examples
>>> from prospicio.distributions import Count, Gamma
>>> n = Count.renewal(Gamma(2.0, 1.0), 5.0)
>>> round(n.pmf(0), 6) # the first wait is beyond 5: 6 e^-50.040428
>>> round(Count.renewal(([1.0], [1.0]), 3.0).pmf(3), 12) # waits of 1 by 31.0
sample()
n claim counts from stream stream of the generator keyed by
Usage
sample(n, seed, stream=0)seed.
Parameters
n: intseed: intstream: int = 0
Returns
list of int
variance()
Variance of the claim count.
Usage
variance()Returns
float
zero_modified()
The base count with P(N = 0) = p0; the other probabilities are
Usage
zero_modified(base, p0)scaled to sum to 1 - p0.
Parameters
base: (Poisson, NegativeBinomial, Binomial or Count)p0: float-
In
[0, 1).
Returns
Count
zero_truncated()
The base count conditioned on at least one claim.
Usage
zero_truncated(base)Parameters
base: (Poisson, NegativeBinomial, Binomial or Count)
Returns
Count