Skip to main content

distributions.Count

A claim count from one of the families beyond the Poisson, negative

Usage

Source

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

Source

bernoulli(p)
Parameters
p: float
Returns
Count
Raises
ValueError
If p is outside [0, 1).

cdf()

P(N <= k).

Usage

Source

cdf(k)
Parameters
k: int
Returns
float

compound_poisson()

A Poisson(rate) number of clusters, each a secondary count:

Usage

Source

compound_poisson(rate, secondary)

Poisson secondaries give the Neyman type A.

Parameters
rate: float
secondary: (Poisson, NegativeBinomial, Binomial or Count)
Returns
Count

empirical()

An empirical count, P(N = k) = probs[k].

Usage

Source

empirical(probs)
Parameters
probs: list of float
Non-negative, summing to 1.
Returns
Count

fixed()

A fixed count, N = n, aggregate’s fixed.

Usage

Source

fixed(n)
Parameters
n: int or float
A whole number of claims; 2.5 is 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

Source

geometric(mean)

binomial with r = 1, aggregate’s geometric.

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

Source

gig()

with shape, omega and eta (aggregate’s lam, mu / beta and mu); None for any other count.

Returns
dict or None

logarithmic()

The logarithmic count on 1, 2, ...:

Usage

Source

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

Source

mean()
Returns
float

mixed_poisson()

A Poisson count whose mean is mean * theta, with the mixing

Usage

Source

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: float
cv: 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 mean max times a beta variable (mixed beta cv max); "sichel", the generalized inverse Gaussian with the given shape (mixed sichel cv shape; -0.5 is 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 part f (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

Source

panjer_ab()

recursion does not apply (use FFT).

Returns
tuple of (float, float) or None

pmf()

P(N = k).

Usage

Source

pmf(k)
Parameters
k: int
Returns
float

quantile()

Smallest k with P(N <= k) >= p.

Usage

Source

quantile(p)
Parameters
p: float
Returns
int

renewal()

The number of claims by horizon when the waits between claims

Usage

Source

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 horizon count 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^-5

0.040428

>>> round(Count.renewal(([1.0], [1.0]), 3.0).pmf(3), 12)  # waits of 1 by 3

1.0


sample()

n claim counts from stream stream of the generator keyed by

Usage

Source

sample(n, seed, stream=0)

seed.

Parameters
n: int
seed: int
stream: int = 0
Returns
list of int

variance()

Variance of the claim count.

Usage

Source

variance()
Returns
float

zero_modified()

The base count with P(N = 0) = p0; the other probabilities are

Usage

Source

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

Source

zero_truncated(base)
Parameters
base: (Poisson, NegativeBinomial, Binomial or Count)
Returns
Count