Solved – Fit Hawkes process to 1d data using python package TICK

fittinggoodness of fithawkes-processpoint-processpython

How can one fit the 1-dimensional Hawkes process with exponential kernel to
the experimental 1d dataset (t1,t2,t3…tn) and check the goodness-of-fit
via tick python3 package?
I found on official webpage that

This module proposes a comprehensive set of tools for the inference
and the simulation of Hawkes processes, with both parametric and
non-parametric estimation techniques and flexible tools for
simulation.

But I didn't found there any example how to fit the Hawkes process to the real (non-simulated) 1d temporal data.

Best Answer

the tick module only allows you to estimate your Hawkes process for a fixed value of the decay $\beta$ for an exponential kernel $\phi(t) = \alpha \beta \exp (-\beta t)$. This is because estimating jointly $\alpha$ and $\beta$ leeds to non convex, poorly scalable algorithms.

However, you can try several values for $\beta$ and keep the one that gives you the best score. Here is an example of this procedure on a finance dataset.

import numpy as np
from tick.dataset import fetch_hawkes_bund_data
from tick.hawkes import HawkesExpKern
from tick.plot import plot_hawkes_kernel_norms

timestamps_list = fetch_hawkes_bund_data()

best_score = -1e100
decay_candidates = np.logspace(0, 6, 20)
for i, decay in enumerate(decay_candidates):
    hawkes_learner = HawkesExpKern(decay, verbose=False, max_iter=10000,
                                   tol=1e-10)
    hawkes_learner.fit(timestamps_list)

    hawkes_score = hawkes_learner.score()
    if hawkes_score > best_score:
        print('obtained {}\n with {}\n'.format(hawkes_score, decay))
        best_hawkes = hawkes_learner
        best_score = hawkes_score

plot_hawkes_kernel_norms(best_hawkes, show=True)
Related Question