mixle.stats.processes.hawkes_process module¶
Evaluate, estimate, and sample from a univariate Hawkes process with an exponential kernel.
Defines HawkesProcessDistribution, HawkesProcessSampler, HawkesProcessAccumulatorFactory, HawkesProcessAccumulator, HawkesProcessEstimator, and HawkesProcessDataEncoder.
A Hawkes process is a self-exciting temporal point process: every event transiently raises the
intensity of future events. With the exponential triggering kernel g(s) = alpha * exp(-beta s)
the conditional intensity given the history is
lambda(t) = mu + sum_{t_j < t} alpha * exp(-beta (t - t_j)),
with background rate mu > 0, excitation jump alpha >= 0, and decay rate beta > 0. The
branching ratio alpha / beta is the expected number of direct offspring per event; the process
is sub-critical (stationary) when alpha < beta.
Data type: each observation is a 1-D array/list of event times, sorted, lying in the fixed window
[0, window]. The exact log-likelihood of one realization t_1 < ... < t_n is the standard
point-process log-likelihood sum_i log lambda(t_i) - integral_0^window lambda(s) ds:
sum_i log(mu + alpha R_i) - mu*window - (alpha/beta) sum_i (1 - exp(-beta (window - t_i))),
where R_i = sum_{j<i} exp(-beta (t_i - t_j)) obeys the O(n) recursion
R_i = exp(-beta (t_i - t_{i-1})) (R_{i-1} + 1) (R_1 = 0).
Fitting retains the weighted realizations and maximizes this exact finite-window
likelihood, including the edge-dependent integrated-kernel term. This is not
the common edge-free branching approximation: a Poisson boundary fit
(alpha=0) and an unconstrained finite-window supercritical fit are both
representable.
Reference: Hawkes, ‘Spectra of some self-exciting and mutually exciting point processes’, Biometrika (1971).
- class HawkesProcessStatistics(realizations, weights, window)[source]
Bases:
NamedTupleVersioned weighted event evidence for exact finite-window fitting.
- weights: ndarray
Alias for field number 1
- window: float
Alias for field number 2
- property schema_version: int
Return the serialized-statistic schema version.
- class HawkesProcessDistribution(mu, alpha, beta, window, name=None, keys=None, max_events=_DEFAULT_MAX_EVENTS)[source]
Bases:
SequenceEncodableProbabilityDistributionUnivariate Hawkes process with an exponential excitation kernel on a fixed window.
- Parameters:
- intensity(t, times, marks=None)[source]
Conditional rate
lambda(t) = mu + alpha sum_{t_i < t} exp(-beta (t - t_i))given the history.timesis the event history;marksis accepted forTemporalPointProcesssignature parity (the univariate Hawkes process is unmarked) and is ignored.
- expected_count(t_start, t_end, times, marks=None)[source]
Compensator
integral_{t_start}^{t_end} lambda(s) dsof the intensity given the history.marksis accepted for signature parity and ignored (the univariate process is unmarked).
- density(x)[source]
Probability density of one realization
x(a sequence of event times).
- log_density(x)[source]
Exact log-likelihood of one realization (a strictly increasing event-time sequence in
[0, window]).The conditional intensity is defined over the strict history
t_j < t(see the class docstring), so a realization with a tied timestamp pair (t_j == t_iforj != i) is not a validt_1 < ... < t_nhistory – like any other malformed ordering, it scores-infrather than silently letting one of the tied events excite the other.
- seq_log_density(x)[source]
Vectorized exact log-likelihood over a padded
(num_realizations, max_len)time matrix.
- sampler(seed=None)[source]
Return a HawkesProcessSampler (Ogata thinning) for this distribution.
- Parameters:
seed (int | None)
- Return type:
HawkesProcessSampler
- estimator(pseudo_count=None)[source]
Return a HawkesProcessEstimator over the same observation window.
- Parameters:
pseudo_count (float | None)
- Return type:
HawkesProcessEstimator
- dist_to_encoder()[source]
Returns a HawkesProcessDataEncoder bound to this window.
- Return type:
HawkesProcessDataEncoder
- class HawkesProcessSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw realizations on
[0, window]by Ogata’s thinning algorithm.- Parameters:
dist (HawkesProcessDistribution)
seed (int | None)
- class HawkesProcessAccumulator(window, name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorRetain validated weighted realizations for exact finite-window MLE.
- update(x, weight, estimate)[source]
Store one validated weighted realization.
- initialize(x, weight, rng)[source]
Store one validated weighted realization during initialization.
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Store validated encoded realizations and aligned weights.
- seq_initialize(x, weights, rng)[source]
Store validated encoded realizations during initialization.
- combine(suff_stat)[source]
Merge validated serialized Hawkes evidence.
- Parameters:
suff_stat (Any)
- Return type:
HawkesProcessAccumulator
- value()[source]
Return owned, versioned weighted realization evidence.
- Return type:
HawkesProcessStatistics
- from_value(x)[source]
Restore validated serialized Hawkes evidence.
- Parameters:
x (Any)
- Return type:
HawkesProcessAccumulator
- scale(c)[source]
Scale realization weights by a finite non-negative constant.
- Parameters:
c (float)
- Return type:
HawkesProcessAccumulator
- key_merge(stats_dict)[source]
Merge this evidence under its shared parameter key.
- key_replace(stats_dict)[source]
Replace this evidence from its shared parameter key.
- acc_to_encoder()[source]
Return an encoder that pads event-time realizations for this window.
- Return type:
HawkesProcessDataEncoder
- class HawkesProcessAccumulatorFactory(window, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for HawkesProcessAccumulator.
- make()[source]
Create an empty Hawkes process accumulator.
- Return type:
HawkesProcessAccumulator
- class HawkesProcessEstimator(window, name=None, keys=None, max_events=_DEFAULT_MAX_EVENTS)[source]
Bases:
ParameterEstimatorExact weighted finite-window maximum-likelihood estimator.
- accumulator_factory()[source]
Return a factory for Hawkes EM sufficient-statistic accumulators.
- Return type:
HawkesProcessAccumulatorFactory
- class HawkesProcessDataEncoder(window)[source]
Bases:
DataSequenceEncoderEncode realizations (event-time arrays) into a padded
(num_realizations, max_len)matrix.- Parameters:
window (float)
- seq_encode(x)[source]
Encode event-time realizations as padded times, lengths, and window.
- Raises:
ValueError – If any realization has a non-finite, out-of-window, or non-strictly-increasing time (including a tied timestamp pair) – the conditional intensity is only defined over the strict history
t_j < t, sot_j == t_iis not a valid history.- Parameters:
- Return type: