Persistency metrics¶
The operational outputs of a fitted intensity λ(t): the expected wait until the next event, the probability of an event in a horizon and the expected count, with posterior_metric turning any of them into posterior samples and quantiles. Needs the population extra for kernels without a closed-form compensator. Tier V.
persistency
¶
Persistency metrics (implementation in plumax.population._src.persistency).
expected_count
¶
expected_count(intensity: str | Module, t: ArrayLike, horizon: float, *, nodes_per_day: int = NODES_PER_DAY, **theta: Any) -> Float[Array, '']
Expected number of events in the horizon, E[N(t, t + h)] = Λ(t, t + h).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensity
|
str | Module
|
A registry name or a kernel instance. |
required |
t
|
ArrayLike
|
Start time t [days]. |
required |
horizon
|
float
|
Horizon h > 0 [days], a concrete number since it sets the node count. |
required |
nodes_per_day
|
int
|
Quadrature density for kernels without a closed form. |
NODES_PER_DAY
|
**theta
|
Any
|
Kernel parameters, when |
{}
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
The expected count. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For the Weibull renewal hazard, or parameters with an instance. |
Examples:
>>> import jax.numpy as jnp
>>> count = expected_count("constant", 3.0, 2.0, lambda_0=1.5)
>>> bool(jnp.allclose(count, 3.0))
True
A diurnal cycle integrates to its mean over a whole day:
>>> count = expected_count(
... "diurnal", 0.0, 1.0, lambda_0=2.0, amplitude=0.5, phase_hours=14.0
... )
>>> bool(jnp.allclose(count, 2.0))
True
Source code in src/plumax/population/_src/persistency.py
expected_wait_time
¶
expected_wait_time(intensity: str | Module, t: ArrayLike, *, n_cells: int = 2048, nodes_per_cell: int = 9, **theta: Any) -> Float[Array, '']
Expected wait until the next event, E[Δt | t] = ∫₀^∞ exp(−Λ(t, t + s)) ds.
Exactly 1/λ₀ for :class:~plumax.population.intensity.ConstantIntensity, whatever
t is.
Algorithm
- Lay out a survival grid: s = 0, then
n_cellslog-spaced cells up toMAX_WAIT, so the first cells resolve short waits and the last ones long waits at a fixed cost. - Accumulate Λ(t, t + s) cell by cell with Simpson's rule.
- Trapezoid the survival function S(s) = exp(−Λ(t, t + s)) over the grid.
- Close the tail beyond s_max with the mean rate λ̄ of the last decade, ∫ S ds ≈ S(s_max) / λ̄, which is exact for a constant rate.
Late cells outgrow a diurnal cycle, which is safe because S only has weight out there when λ is small enough that the ripple in Λ is small too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensity
|
str | Module
|
A registry name or a kernel instance. |
required |
t
|
ArrayLike
|
Start time t [days]. |
required |
n_cells
|
int
|
Log-spaced cells of the survival grid. |
2048
|
nodes_per_cell
|
int
|
Simpson nodes of Λ inside one cell (odd). |
9
|
**theta
|
Any
|
Kernel parameters, when |
{}
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
The expected wait [days]; infinite for λ ≡ 0. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For the Weibull renewal hazard, or parameters with an instance. |
Examples:
The memoryless wait of a constant rate:
>>> import jax.numpy as jnp
>>> wait = expected_wait_time("constant", 7.0, lambda_0=4.0)
>>> bool(jnp.allclose(wait, 0.25))
True
A diurnal source is quicker to emit near its 14:00 peak than at 02:00:
>>> diurnal = dict(lambda_0=4.0, amplitude=3.6, phase_hours=8.0)
>>> at_peak = expected_wait_time("diurnal", 14.0 / 24.0, **diurnal)
>>> at_trough = expected_wait_time("diurnal", 2.0 / 24.0, **diurnal)
>>> bool(at_peak < at_trough)
True
Source code in src/plumax/population/_src/persistency.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
occurrence_probability
¶
occurrence_probability(intensity: str | Module, t: ArrayLike, horizon: float, *, nodes_per_day: int = NODES_PER_DAY, **theta: Any) -> Float[Array, '']
Probability of at least one event, P(N(t, t + h) ≥ 1) = 1 − exp(−Λ(t, t + h)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensity
|
str | Module
|
A registry name or a kernel instance. |
required |
t
|
ArrayLike
|
Start time t [days]. |
required |
horizon
|
float
|
Horizon h > 0 [days], a concrete number since it sets the node count. |
required |
nodes_per_day
|
int
|
Quadrature density for kernels without a closed form. |
NODES_PER_DAY
|
**theta
|
Any
|
Kernel parameters, when |
{}
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
The probability. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For the Weibull renewal hazard, or parameters with an instance. |
Examples:
>>> import jax.numpy as jnp
>>> probability = occurrence_probability("constant", 0.0, 2.0, lambda_0=0.5)
>>> bool(jnp.allclose(probability, 1.0 - jnp.exp(-1.0)))
True
Source code in src/plumax/population/_src/persistency.py
posterior_metric
¶
posterior_metric(metric: Callable[..., Array], posterior: PoissonRatePosterior | InhomogeneousIntensityPosterior | TMTPPPosterior, *args: Any, quantiles: Sequence[float] = (0.05, 0.5, 0.95), rate_scale: float = 1.0, covariates: Callable[[Array], Array] | None = None, num_samples: int = 1000, key: PRNGKeyArray | None = None, **metric_kwargs: Any) -> dict[str, Array]
Posterior samples of a persistency metric, and their quantiles.
m⁽ᵉ⁾ = m(λ⁽ᵉ⁾, …) for each draw λ⁽ᵉ⁾ of the intensity, vmapped over the draws.
The two rate posteriors of :mod:~plumax.population.point_process are per unit of
their exposure, and their time and area units are the caller's, so rate_scale
turns them into events day⁻¹ (the area, times the time unit per day, when the
exposure was area × duration).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Callable[..., Array]
|
|
required |
posterior
|
PoissonRatePosterior | InhomogeneousIntensityPosterior | TMTPPPosterior
|
The fitted posterior. |
required |
*args
|
Any
|
The metric's positional arguments after the intensity. |
()
|
quantiles
|
Sequence[float]
|
Quantile levels to report. |
(0.05, 0.5, 0.95)
|
rate_scale
|
float
|
Multiplier from the posterior's rate to events day⁻¹, for
:class: |
1.0
|
covariates
|
Callable[[Array], Array] | None
|
z(t), the covariates of an
:class: |
None
|
num_samples
|
int
|
Draws from a Gamma posterior (the others carry their draws). |
1000
|
key
|
PRNGKeyArray | None
|
PRNG key of a Gamma posterior. |
None
|
**metric_kwargs
|
Any
|
The metric's keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Without |
Examples:
Wait time under a Gamma posterior on a constant rate:
>>> import jax
>>> from plumax.population.point_process import PoissonRatePosterior
>>> posterior = PoissonRatePosterior(
... alpha=201.0, beta=100.0, n_events=200, exposure=100.0
... )
>>> result = posterior_metric(
... expected_wait_time, posterior, 0.0, key=jax.random.PRNGKey(0)
... )
>>> result["samples"].shape
(1000,)
>>> bool(result["quantiles"][0] < 0.5 < result["quantiles"][2])
True
Source code in src/plumax/population/_src/persistency.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |