This page lists the quantities that every TorchPP model computes and the conventions behind them. Other pages link here instead of repeating these definitions. For a step-by-step derivation of each quantity, read the introduction first.
MVEventData.T_obs, default
Two times recur below. The window start
| Symbol | Meaning | Method |
|---|---|---|
| conditional intensity of type |
intensity(t, ts) |
|
cumulative intensity, T_low, T
|
cumulative_intensity(T, ts, T_low) |
|
| survival: no event in |
survival_time(t, ts) |
|
| next-event CDF | cdf_time(t, ts) |
|
| joint next-event density | density_joint(t, ts) |
|
| time-marginal density | density_time(t, ts) |
|
| type given the time | prob_mark_given_time(t, ts) |
|
| type marginal | prob_mark(ts) |
Density-based models (IntensityFree) define log=True by default.
Integrals that start at an event use the right limit
For a non-terminating sequence the log-likelihood is
where likelihood(ts) returns it per
sequence with shape (B,), and loss(ts) is its negative.
In terminating mode (terminating=True), each type occurs at most once. After type
The origin regime is the has_origin field of the data's TokenRoles (next section).
-
has_origin=Falseis the default and is common for benchmarks with an arbitrary time origin. The first event is the origin. It and any events tied with it are conditioned on, not scored, and the window starts at$t_s = t_1$ . -
has_origin=Truemeans that sequences start at a real origin$t=0$ (e.g. admission or birth). Every event is scored and the window starts at$t_s = 0$ . Transformer-encoder models prepend a learned<bos>embedding for the empty history. This embedding is internal to the encoder, never part of the data, and does not change$D$ .
Likelihoods are comparable within one regime but not across the two.
TokenRoles collects how time 0 and each event type are treated.
from torchpp import TokenRoles
roles = TokenRoles(has_origin=False, context_types=(), ignored_types=())has_originsets whether time 0 is a real origin (previous section).context_typesare types that are read as history but never predicted. They are not scored, not integrated, never sampled, and may repeat in terminating mode. All other types are predictable. They are scored in the positive term, integrated in the survival and, in terminating mode, part of the competing-risks set.ignored_typesare types that are excluded from the evaluation targets only. They stay in the history and in the training likelihood.
One TokenRoles object is passed through the library.
- A dataset declares its defaults as the class attribute
default_token_roles. A run overrides the type lists withdataset.context_typesanddataset.ignored_types, anddataset.token_rolesis the result. create_model(..., token_roles=dataset.token_roles)(ortoken_roles=on any model class) builds the model with these roles.model.token_rolesreturns them, and checkpoints store them (context types as themodel.predictable_maskbuffer).evaluate_tpp(model, sequences)usesmodel.token_roles, androles=may change onlyignored_types.
The scored events are the events whose density enters the likelihood. These are the real
events of predictable types, without the first event and the events tied with it when there
is no origin. model.num_scored_events(ts) counts them per sequence. Every "per event" number
uses this count: the training loss, the validation log-likelihood and the test
ll_per_event. The next-event evaluation predicts exactly these events (see
Metrics).
Next-event predictions start at the forecast origin sample draws events after time_mean and time_quantile
return inf and sample stops.
Public methods take and return times in the data's native units. Internally each model
works in scaled units model.time_scale, which create_model sets to
the mean inter-event time of the training data (default 1). Densities therefore carry a