X-DataInitiative / tick

Module for statistical learning, with a particular emphasis on time-dependent modelling
https://x-datainitiative.github.io/tick/
BSD 3-Clause "New" or "Revised" License
480 stars 105 forks source link

Hawkes cumulants - Tensorflow v1 #505

Closed claudio-ICL closed 1 year ago

claudio-ICL commented 1 year ago

This PR proposes to break the class HawkesCumulantMatching in a base class with the general interface, and a derived class that implements the methods of the interface using tensorflow. A second derived class that will implement the same methods with pytorch is also prototyped. Moreover, this PR tries to migrate HawkesCumulantMatching to tensorflow v2 minimising the required changes: I used tf.compat.v1. Tests of the inference methodology are re-activated (no longer skipped by default).

claudio-ICL commented 1 year ago

Hi @Mbompr

I am trying to adapt the code of HawkesCumulantMatching to tensorflow v2. There are some tests that fail however, because the numerical precision is not achieved. I was wondering whether you can explain how the expected values were produced?

Mbompr commented 1 year ago

If I remember correctly, these values have been obtained by making the algorithm run. I think that if the new values are close enough, we can simply replace them. Maybe the optimization loop has changed with TF2.

claudio-ICL commented 1 year ago

If I remember correctly, these values have been obtained by making the algorithm run. I think that if the new values are close enough, we can simply replace them. Maybe the optimization loop has changed with TF2.

Understood. So, they are not ground truth. From a first run with v2 I get somewhat similar values, but the precision of 6 decimal places is certainly lost.

image (1)

Mbompr commented 1 year ago

I think it makes sense to change the values in the test within the PR then

claudio-ICL commented 1 year ago

If I remember correctly, these values have been obtained by making the algorithm run. I think that if the new values are close enough, we can simply replace them. Maybe the optimization loop has changed with TF2.

Understood. So, they are not ground truth. From a first run with v2 I get somewhat similar values, but the precision of 6 decimal places is certainly lost.

I am thinking whether it would be more appropriate to design a test as follows:

  1. Instantiate a parametric class (e.g. exponential) with given coefficients, and compute exact L1 norms of kernels.
  2. Generate timestamps from simulation.
  3. Calibrate HawkesCumulantMatching on the simulated timestamps.
  4. Compare calibrated adjacency with exact L1 norms.
Mbompr commented 1 year ago

I agree that makes more sense. But I find it hard to suggest something big when I had been lazy before 😬

claudio-ICL commented 1 year ago

Hi @PhilipDeegan , Do you think we can merge this?

claudio-ICL commented 1 year ago

@PhilipDeegan I believe that this PR is ready to merge. Would it be possible to do it today?