Simulation#

easy_tpp.simulation provides numpy-only PoissonProcess(rates), HawkesProcess(mu, alpha, beta), and SelfCorrectingProcess(mu, alpha). All parameters have K types. For Hawkes, rows of alpha are target types and columns are source types; kernels are alpha[k,j] * beta[k,j] * exp(-beta[k,j] * dt). Thus alpha is the branching matrix and must have spectral radius strictly below one. beta is positive and either scalar or K-by-K. Self-correcting intensities are exp(mu[k] * t - alpha[k] * N(t-)), where N counts all types. Its mu and alpha are nonnegative K-vectors. All processes start with empty history at time zero; Hawkes does not start in its stationary distribution.

import numpy as np
from easy_tpp.simulation import HawkesProcess, write_splits

process = HawkesProcess(
    mu=[0.5, 0.8], alpha=[[0.2, 0.1], [0.1, 0.3]], beta=1.5)
sequences = process.simulate(
    t_end=100., num_sequences=1000, rng=np.random.default_rng(42))
times, types = sequences[0]  # numpy arrays, no dummy initial event
full_window_ll = process.loglik(times, types, t_end=100.)
last_event_ll = process.loglik(times, types)  # t_end=None
average_ll = process.loglik_per_event(times, types)
records = process.to_records(sequences)  # preserves K even if types are absent
write_splits(records, 'simulated', splits={'train': .8, 'dev': .1, 'test': .1})

Point train_dir, valid_dir, and test_dir at simulated/train.json, simulated/dev.json, and simulated/test.json with data_format: json, source: json, and num_event_types: 2. Each file is JSON lines, one sequence per line. Splits are consecutive without shuffling; integer counts summing to the record count are also supported. Fraction rounding remainder goes to the last split. Empty splits produce empty files, which should not be passed to the loader. Empty event sequences are retained by export. The standalone to_records(sequences, dim_process=None) can infer K from observed marks; use the process method or explicit K to retain absent types.

simulate(t_end, num_sequences, rng, max_events=None) accepts a numpy Generator or seed. max_events returns a capped prefix: do not treat its unobserved tail as a complete observation through the original t_end. HawkesProcess.intensity(t, (times, types)) evaluates the left-limit intensity and excludes events exactly at t.

loglik returns the total marked point-process log likelihood, including the compensator from zero through t_end. Omitting t_end uses the last event time (zero for empty input), without a survival term after it. loglik_per_event divides this total by the supplied event count, without changing its sign, and raises for empty input. This follows the per-event averaging convention of EasyTPP’s reported loglike and its last-event window. It scores every supplied event from zero. EasyTPP model losses may instead condition on the first event and count only subsequent scored events; match the scored events and conditioning before comparing numerical values. In particular, BaseModel counts nonzero event log terms, so a zero log intensity can also affect that denominator. Exported records do not store t_end; keep it separately for full-window likelihood comparisons.

See Simulation API for the simulator API.