## distributions.Count


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


Usage

``` python
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](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `zm`, `zt`, [logarithmic](distributions.Count.md#prospicio.distributions.Count.logarithmic), `mixed`, `neymana` and `dfreq`. Make one with a static constructor; every aggregation function takes it like any other count.


## Examples

``` python
>>> from prospicio.distributions import Count, Poisson
>>> n = Count.zero_truncated(Poisson(2.0))
>>> n.pmf(0)
```

0.0

``` python
>>> pig = Count.mixed_poisson(10.0, 0.5, mixing="inverse_gaussian")
>>> round(pig.variance(), 9)
```

35.0


## Methods

| Name | Description |
|----|----|
| [bernoulli()](#bernoulli) | A Bernoulli count, one claim with probability [p](models.Elpd.md#prospicio.models.Elpd.p) in `[0, 1)`, |
| [cdf()](#cdf) | `P(N <= k)`. |
| [compound_poisson()](#compound_poisson) | A Poisson([rate](pricing.CasualtyProfile.md#prospicio.pricing.CasualtyProfile.rate)) number of clusters, each a `secondary` count: |
| [empirical()](#empirical) | An empirical count, `P(N = k) = probs[k]`. |
| [fixed()](#fixed) | A fixed count, `N = n`, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s [fixed](distributions.Count.md#prospicio.distributions.Count.fixed). |
| [geometric()](#geometric) | A geometric count on `0, 1, ...` with this mean, a negative |
| [gig()](#gig) | The generalized inverse Gaussian a Sichel mixing solved, as a dict |
| [logarithmic()](#logarithmic) | The logarithmic count on `1, 2, ...`: |
| [mean()](#mean) | Mean of the claim count. |
| [mixed_poisson()](#mixed_poisson) | A Poisson count whose mean is `mean * theta`, with the mixing |
| [panjer_ab()](#panjer_ab) | `(a, b)` of the `(a, b, 1)` class, or `None` when Panjer's |
| [pmf()](#pmf) | `P(N = k)`. |
| [quantile()](#quantile) | Smallest [k](models.TargetEncoding.md#prospicio.models.TargetEncoding.k) with `P(N <= k) >= p`. |
| [renewal()](#renewal) | The number of claims by `horizon` when the waits between claims |
| [sample()](#sample) | [n](pricing.TrendFit.md#prospicio.pricing.TrendFit.n) claim counts from stream `stream` of the generator keyed by |
| [variance()](#variance) | Variance of the claim count. |
| [zero_modified()](#zero_modified) | The base count with `P(N = 0) = p0`; the other probabilities are |
| [zero_truncated()](#zero_truncated) | The base count conditioned on at least one claim. |

------------------------------------------------------------------------


#### bernoulli()


A Bernoulli count, one claim with probability [p](models.Elpd.md#prospicio.models.Elpd.p) in `[0, 1)`,


Usage

``` python
bernoulli(p)
```


[aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s [bernoulli](distributions.Count.md#prospicio.distributions.Count.bernoulli).


##### Parameters


`p: float`  


##### Returns


`Count`  


##### Raises


`ValueError`  
If [p](models.Elpd.md#prospicio.models.Elpd.p) is outside `[0, 1)`.


------------------------------------------------------------------------


#### cdf()


`P(N <= k)`.


Usage

``` python
cdf(k)
```


##### Parameters


`k: int`  


##### Returns


`float`  


------------------------------------------------------------------------


#### compound_poisson()


A Poisson([rate](pricing.CasualtyProfile.md#prospicio.pricing.CasualtyProfile.rate)) number of clusters, each a `secondary` count:


Usage

``` python
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

``` python
empirical(probs)
```


##### Parameters


`probs: list of float`  
Non-negative, summing to 1.


##### Returns


`Count`  


------------------------------------------------------------------------


#### fixed()


A fixed count, `N = n`, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s [fixed](distributions.Count.md#prospicio.distributions.Count.fixed).


Usage

``` python
fixed(n)
```


##### Parameters


`n: int or float`  
A whole number of claims; `2.5` is refused, as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate) 2.1.0 refuses a fractional fixed count.


##### Returns


`Count`  


##### Examples

``` python
>>> 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

``` python
geometric(mean)
```


binomial with `r = 1`, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s [geometric](distributions.Count.md#prospicio.distributions.Count.geometric).


##### Parameters


`mean: float`  


##### Returns


`Count`  


##### Raises


`ValueError`  
If [mean](esg.Cir.md#prospicio.esg.Cir.mean) is not finite and positive.


##### Examples

``` python
>>> 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

``` python
gig()
```


with [shape](reserving.Triangle.md#prospicio.reserving.Triangle.shape), [omega](reserving.ClarkFit.md#prospicio.reserving.ClarkFit.omega) and `eta` ([aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s [lam](models.ElasticNet.md#prospicio.models.ElasticNet.lam), `mu / beta` and [mu](distributions.Normal.md#prospicio.distributions.Normal.mu)); `None` for any other count.


##### Returns


`dict or None`  


------------------------------------------------------------------------


#### logarithmic()


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


Usage

``` python
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

``` python
mean()
```


##### Returns


`float`  


------------------------------------------------------------------------


#### mixed_poisson()


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


Usage

``` python
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](distributions.Tweedie.md#prospicio.distributions.Tweedie.cv); variance `mean + mean**2 cv**2`.


##### Parameters


`mean: float`  

`cv: float`  
Coefficient of variation of [theta](models.TwoPartFit.md#prospicio.models.TwoPartFit.theta), fixed part included.

`mixing: (gamma, inverse_gaussian, beta, sichel, sichel_skewness, sichel_gamma, sichel_ig) = ``"gamma"`  
The distribution of [G](distributions.TemperedStable.md#prospicio.distributions.TemperedStable.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](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s: `"beta"`, the Poisson mean `max` times a beta variable (`mixed beta cv max`); `"sichel"`, the generalized inverse Gaussian with the given [shape](reserving.Triangle.md#prospicio.reserving.Triangle.shape) (`mixed sichel cv shape`; `-0.5` is the inverse Gaussian) or, with [skewness](distributions.Discrete.md#prospicio.distributions.Discrete.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](models.TwoPartFit.md#prospicio.models.TwoPartFit.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

``` python
panjer_ab()
```


recursion does not apply (use FFT).


##### Returns


`tuple of (float, float) or None`  


------------------------------------------------------------------------


#### pmf()


`P(N = k)`.


Usage

``` python
pmf(k)
```


##### Parameters


`k: int`  


##### Returns


`float`  


------------------------------------------------------------------------


#### quantile()


Smallest [k](models.TargetEncoding.md#prospicio.models.TargetEncoding.k) with `P(N <= k) >= p`.


Usage

``` python
quantile(p)
```


##### Parameters


`p: float`  


##### Returns


`int`  


------------------------------------------------------------------------


#### renewal()


The number of claims by `horizon` when the waits between claims


Usage

``` python
renewal(wait, horizon, *, step=None, points=None, closed=False)
```


are independent draws from `wait`: a renewal (Sparre Andersen) count, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.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](aggregate.Clash.md#prospicio.aggregate.Clash.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](aggregate.Clash.md#prospicio.aggregate.Clash.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](aggregate.GridSize.md#prospicio.aggregate.GridSize.points).

`points: int = None`  
The wait grid's number of points.

`closed: bool = ``False`  
With [step](esg.Scenarios.md#prospicio.esg.Scenarios.step): whether waits summing to exactly `horizon` count in full (waits on the grid's lattice), not half.


##### Returns


`Count`  


##### Examples

``` python
>>> 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

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

1.0

------------------------------------------------------------------------


#### sample()


[n](pricing.TrendFit.md#prospicio.pricing.TrendFit.n) claim counts from stream `stream` of the generator keyed by


Usage

``` python
sample(n, seed, stream=0)
```


[seed](aggregate.EventSet.md#prospicio.aggregate.EventSet.seed).


##### Parameters


`n: int`  

`seed: int`  

`stream: int = ``0`  


##### Returns


`list of int`  


------------------------------------------------------------------------


#### variance()


Variance of the claim count.


Usage

``` python
variance()
```


##### Returns


`float`  


------------------------------------------------------------------------


#### zero_modified()


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


Usage

``` python
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

``` python
zero_truncated(base)
```


##### Parameters


`base: (Poisson, NegativeBinomial, Binomial or Count)`  


##### Returns


`Count`
