tick.hawkes.
HawkesEM
(kernel_support=None, kernel_size=10, kernel_discretization=None, tol=1e-05, max_iter=100, print_every=10, record_every=10, verbose=False, n_threads=1)[source]¶This class is used for performing non parametric estimation of multi-dimensional Hawkes processes based on expectation maximization algorithm.
Hawkes processes are point processes defined by the intensity:
where
\(D\) is the number of nodes
\(\mu_i\) are the baseline intensities
\(\phi_{ij}\) are the kernels
kernel_support : float
, default=`None`
The support size common to all the kernels. Might be
None
ifkernel_discretization
is set
kernel_size : int
, default=10
Number of discretizations of the kernel
kernel_discretization : np.ndarray
, default=None
Explicit discretization of the kernel. If set, it will override
kernel_support
andkernel_size
values.
tol : float
, default=1e-5
The tolerance of the solver (iterations stop when the stopping criterion is below it). If not reached the solver does
max_iter
iterations
max_iter : int
, default=100
Maximum number of iterations of the solver
verbose : bool
, default=False
If
True
, we verbose things, otherwise the solver does not print anything (but records information in history anyway)
print_every : int
, default=10
Print history information when
n_iter
(iteration number) is a multiple ofprint_every
record_every : int
, default=10
Record history information when
n_iter
(iteration number) is a multiple ofrecord_every
n_threads : int
, default=1
Number of threads used for parallel computation.
if
int <= 0
: the number of physical cores available on the CPUotherwise the desired number of threads
n_nodes : int
Number of nodes of the estimated Hawkes process
n_realizations : int
Number of given realizations
kernel : np.array
shape=(n_nodes, n_nodes, kernel_size)
The estimated kernels
baseline : np.array
shape=(n_nodes)
The estimated baseline
References
Lewis, E., & Mohler, G. (2011). A nonparametric EM algorithm for multiscale Hawkes processes. preprint, 1-16.
The n-dimensional extension of this algorithm can be found in the latex documentation.
__init__
(kernel_support=None, kernel_size=10, kernel_discretization=None, tol=1e-05, max_iter=100, print_every=10, record_every=10, verbose=False, n_threads=1)[source]¶Initialize self. See help(type(self)) for accurate signature.
fit
(events, end_times=None, baseline_start=None, kernel_start=None)[source]¶Fit the model according to the given training data.
events : list
of list
of np.ndarray
List of Hawkes processes realizations. Each realization of the Hawkes process is a list of n_node for each component of the Hawkes. Namely
events[i][j]
contains a one-dimensionalnumpy.array
of the events’ timestamps of component j of realization i. If only one realization is given, it will be wrapped into a list
end_times : np.ndarray
or float
, default = None
List of end time of all hawkes processes that will be given to the model. If None, it will be set to each realization’s latest time. If only one realization is provided, then a float can be given.
baseline_start : None
or np.ndarray
, shape=(n_nodes), default=None
Used to force start values for baseline parameter If
None
starts with uniform 1 values
kernel_start : None
or np.ndarray
, shape=(n_nodes, n_nodes, kernel_size), default=None
Used to force start values for kernel parameter If
None
starts with random values
get_history
(key=None)¶Returns history of the solver
key : str
, default=None
If
None
all history is returned as adict
If
str
, name of the history element to retrieve
output : list
or dict
If
key
is None orkey
is not in history then output is a dict containing history of all keysIf
key
is the name of an element in the history, output is alist
containing the history of this element
get_kernel_norms
()[source]¶Computes kernel norms. This makes our learner compliant with
tick.plot.plot_hawkes_kernel_norms
API
norms : np.ndarray
, shape=(n_nodes, n_nodes)
2d array in which each entry i, j corresponds to the norm of kernel i, j
get_kernel_supports
()[source]¶Computes kernel support. This makes our learner compliant with
tick.plot.plot_hawkes_kernels
API
output : np.ndarray
, shape=(n_nodes, n_nodes)
2d array in which each entry i, j corresponds to the support of kernel i, j
get_kernel_values
(i, j, abscissa_array)[source]¶Computes value of the specified kernel on given time values. This
makes our learner compliant with tick.plot.plot_hawkes_kernels
API
i : int
First index of the kernel
j : int
Second index of the kernel
abscissa_array : np.ndarray
, shape=(n_points, )
1d array containing all the times at which this kernel will computes it value
output : np.ndarray
, shape=(n_points, )
1d array containing the values of the specified kernels at the given times.
objective
(coeffs, loss: float = None)[source]¶Compute the objective minimized by the solver at coeffs
coeffs : numpy.ndarray
, shape=(n_coeffs,)
The objective is computed at this point
loss : float
, default=`None`
Gives the value of the loss if already known (allows to avoid its computation in some cases)
output : float
Value of the objective at given
coeffs
score
(events=None, end_times=None, baseline=None, kernel=None)[source]¶Compute score metric Score metric is log likelihood (the higher the better)
events : list
of list
of np.ndarray
, default = None
List of Hawkes processes realizations used to measure score. Each realization of the Hawkes process is a list of n_node for each component of the Hawkes. Namely
events[i][j]
contains a one-dimensionalnumpy.array
of the events’ timestamps of component j of realization i. If only one realization is given, it will be wrapped into a list If None, events given while fitting model will be used
end_times : np.ndarray
or float
, default = None
List of end time of all hawkes processes used to measure score. If None, it will be set to each realization’s latest time. If only one realization is provided, then a float can be given.
baseline : np.ndarray
, shape=(n_nodes, ), default = None
Baseline vector for which the score is measured If
None
baseline obtained during fitting is used
kernel : None
or np.ndarray
, shape=(n_nodes, n_nodes, kernel_size), default=None
Used to force start values for kernel parameter If
None
kernel obtained during fitting is used
likelihood : double
Computed log likelihood value
tick.hawkes.HawkesEM
¶