## distributions.invert_chf()


A law's distribution on a grid, by inverting its characteristic


Usage


``` python
distributions.invert_chf(
    law,
    *,
    log2=16,
    step=None,
    x_min=None,
    bucket_sizing_p=Ellipsis,
    tilt=None
)
```


function: [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `AggregateCHF` (`chfagg`).

The characteristic function is sampled on the FFT's frequency grid, times `sinc(t step / 2)`, and inverted once, so bucket [k](models.TargetEncoding.md#prospicio.models.TargetEncoding.k) holds the probability within half a step of `x_min + k * step`. With [step](esg.Scenarios.md#prospicio.esg.Scenarios.step) left out, the window is sized from the law's tails (Chernoff bounds) to leave `1 - bucket_sizing_p` of the mass outside, half on each side, and the step is rounded up to 1, 2, 4, 5 or 8 times a power of ten (a power of two below 1); when the dropped frequencies are above 1e-6 the step moves down that ladder while that helps. A Tweedie's mass at 0 is inverted apart, so it does not ring.

A stable law with one power tail ([beta](risk.Gpd.md#prospicio.risk.Gpd.beta) 1 or -1) is inverted along the line `Im s = theta` ([tilt](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.tilt)), where the integrand decays like `exp(-theta x) f(x)`: what wraps is the damped tail, and the mass beyond the window is left out and reported in [outside_above](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.outside_above) (or added to the first bucket and reported in [outside_below](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.outside_below) for a left tail). The automatic tilt balances the damped wrap against the round-off the tilt amplifies, and caps the step.


## Parameters


`law: (`\
`    Normal,`\
`    Gamma,`\
`    Exponential,`\
`    InverseGaussian,`\
`    Tweedie,`\
`    Affine,`\
`    Stable,`\
`    NormalInverseGaussian,`\
`    VarianceGamma,`\
`    TemperedStable,`\
`    TweediePower or callable,`\
`)`  
A law with a closed-form characteristic function (an [Affine](distributions.Affine.md#prospicio.distributions.Affine) of one of them), or your own characteristic function: a callable of a list of real frequencies [t](distributions.Pareto.md#prospicio.distributions.Pareto.t) returning `E exp(i t X)` at each, complex. Your own function needs [step](esg.Scenarios.md#prospicio.esg.Scenarios.step) and [x_min](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.x_min), since it says nothing of the law's tails.

`log2: int = ``16`  
The grid has `2 ** log2` buckets, 1 to 28.

`step: float = None`  
The bucket; sized from the tails when left out.

`x_min: float = None`  
The grid's first point, with [step](esg.Scenarios.md#prospicio.esg.Scenarios.step); placed from the tails when left out. A given [x_min](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.x_min) fixes the grid, so it is inverted untilted: `tilt=True` falls back to no tilt (a heavy tail wraps onto the window, and the report's tilt is 0), and a number [tilt](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.tilt) is refused.

`bucket_sizing_p: float = ``0.99999`  
The mass the window covers when it is sized from the tails.

`tilt: bool or float = ``True`  
`True`: a law with one power tail at the automatic tilt, a stable law with two split into its halves and each tilted, every other law untilted; no tilt when [x_min](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.x_min) is given. `False`: never tilt (a heavy tail wraps). A number `tau >= 0`: exactly [tau](esg.Svensson.md#prospicio.esg.Svensson.tau) e-folds of damping across the window, for a stable law only, and not with [x_min](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.x_min).


## Returns


`ChfDistribution`  


## Raises


`ValueError`  
If an option is out of range, [x_min](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.x_min) is given without [step](esg.Scenarios.md#prospicio.esg.Scenarios.step), your own function is given without both, or it returns a value that is not finite; a number [tilt](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.tilt) on a law with no power tail, with [x_min](distributions.ChfDistribution.md#prospicio.distributions.ChfDistribution.x_min) given, or on a window (a [step](esg.Scenarios.md#prospicio.esg.Scenarios.step) that puts it on the body) whose light side below it the tilt would magnify past round-off.


## Examples

``` python
>>> from prospicio.distributions import Gamma, invert_chf
>>> d = invert_chf(Gamma(4.0, 25.0), log2=12)
>>> d.step, d.x_min, round(d.mean(), 6)
```

(0.25, 0.0, 100.0)
