Baseline hazards¶
The families a generator can sample from, and the protocol any object must satisfy to be used as one. See the baseline hazards guide for how to pass them.
baseline
¶
Baseline hazard families.
A survival time is drawn by inverting the cumulative hazard: draw
:math:E \sim \mathrm{Exponential}(1) and solve :math:H_0(t) = E / e^{\eta}
for :math:t. Every generator in this package that samples a continuous time
does exactly that, differing only in which :math:H_0 it uses.
This module makes that the explicit contract. A baseline hazard is anything
implementing :class:BaselineHazard, so a simulator written against the
protocol works with any shape, rather than growing a separate entry point per
family.
All implementations are frozen dataclasses that validate their parameters on construction, and every method accepts either a scalar or a NumPy array.
Examples:
>>> from gen_surv.baseline import WeibullBaseline
>>> baseline = WeibullBaseline(shape=2.0, scale=1.5)
>>> value = baseline.cumulative_hazard(3.0)
>>> round(baseline.inverse_cumulative_hazard(value), 10)
3.0
BaselineHazard
¶
Bases: Protocol
The interface a baseline hazard must provide to be sampled from.
Three methods, of which the last two are the ones sampling needs:
:meth:cumulative_hazard to evaluate :math:H_0(t), and
:meth:inverse_cumulative_hazard to solve :math:H_0(t) = v for
:math:t. They must be mutual inverses wherever :math:H_0 is finite and
strictly increasing.
ExponentialBaseline
dataclass
¶
Constant hazard: :math:h_0(t) = \lambda.
The memoryless case. Waiting times are exponential, so on a multi-event process it makes no difference whether the clock runs forward or resets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
The constant hazard, positive. |
1.0
|
WeibullBaseline
dataclass
¶
Monotone hazard: :math:H_0(t) = (t/\sigma)^{\rho}.
Falling for shape < 1, constant at 1, rising above it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
The Weibull shape :math: |
1.0
|
scale
|
float
|
The Weibull scale :math: |
1.0
|
GompertzBaseline
dataclass
¶
Exponentially changing hazard: :math:h_0(t) = a e^{bt}.
A negative shape is allowed and gives a declining hazard whose total is
finite, :math:a/|b|. Beyond that total the inverse is inf: the event
never happens, which is the point of the family rather than a failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
The hazard at time zero, :math: |
1.0
|
shape
|
float
|
The exponential rate of change, :math: |
0.1
|
total_hazard
property
¶
The limit of :math:H_0(t), finite only for a declining hazard.
LogLogisticBaseline
dataclass
¶
Unimodal hazard: :math:H_0(t) = \log(1 + (t/\sigma)^{\rho}).
The hazard rises to a peak and then decays, which no other family here does. Not a proportional-hazards family in its own right, but a perfectly good baseline to scale by a linear predictor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
The shape :math: |
1.0
|
scale
|
float
|
The scale :math: |
1.0
|
PiecewiseConstantBaseline
dataclass
¶
PiecewiseConstantBaseline(
breakpoints: Sequence[float] = (),
hazard_rates: Sequence[float] = (1.0,),
)
Constant within intervals, jumping between them.
There is always one more rate than there are breakpoints: k breakpoints
cut the timeline into k + 1 pieces, the last one open-ended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
breakpoints
|
Sequence[float]
|
Strictly increasing positive times at which the hazard changes. |
()
|
hazard_rates
|
Sequence[float]
|
One positive rate per interval, |
(1.0,)
|