EasyTemporalPointProcess icon indicating copy to clipboard operation
EasyTemporalPointProcess copied to clipboard

Calculation of NHP's log-likelihood

Open HaochenWang1243 opened this issue 5 months ago • 3 comments

Hi. I have doubts on how the code calculates NHP's log-likelihood, which is specified by equation (8) in the NHP paper: Screenshot 2024-09-18 at 14 54 42

The former part of equation (8) is the sum of individual-type log intensities at all event occurrences. In the compute_loglikelihood method in torch_basemodel.py, however, I saw the type dimension (last dimension) of lambda_at_event is summed: https://github.com/ant-research/EasyTemporalPointProcess/blob/01551fb7c7adb3553d33fa1aab0266d139a80aea/easy_tpp/model/torch_model/torch_basemodel.py#L104 which doesn't seem to comply with equation (8) shown above. FYI, the caller of this method in NHP is https://github.com/ant-research/EasyTemporalPointProcess/blob/01551fb7c7adb3553d33fa1aab0266d139a80aea/easy_tpp/model/torch_model/torch_nhp.py#L265 where lambda_at_event has shape [batch_size, num_times=max_len-1, num_event_types], as the comments mentioned.

The latter part of equation (8), according to Algorithm 1 of the NHP paper: Screenshot 2024-09-18 at 15 40 10 is calculated by uniformly sampling the intensity function over the whole time frame of the event sequence. In the code, however, it seems like the sampling is done by drawing equidistant samples in each inter-event interval: https://github.com/ant-research/EasyTemporalPointProcess/blob/01551fb7c7adb3553d33fa1aab0266d139a80aea/easy_tpp/model/torch_model/torch_nhp.py#L255 which, I imagine, can give quite different results from uniform sampling for event sequences of large inter-event-time variance.

Maybe I'm missing something. Thank you for your help.

HaochenWang1243 avatar Sep 18 '24 23:09 HaochenWang1243