Intensity-Free Learning of Temporal Point Processes

Oleksandr Shchur, Marin Biloš, Stephan Günnemann

Introduction

Visits to hospitals, purchases in e-commerce systems, financial transactions, posts in social media — various forms of human activity can be represented as discrete events happening at irregular intervals. The framework of temporal point processes is a natural choice for modeling such data. By combining temporal point process models with deep learning, we can design algorithms able to learn complex behavior from real-world data.

Designing such models, however, usually involves trade-offs along the following dimensions: flexibility (can the model approximate any distribution?), efficiency (can the likelihood function be evaluated in closed form?), and ease of use (is sampling and computing summary statistics easy?). Existing methods (Du et al., 2016; Mei & Eisner, 2017; Omi et al., 2019) that are defined in terms of the conditional intensity function typically fall short in at least one of these categories.

Instead of modeling the intensity function, we suggest treating the problem of learning in temporal point processes as an instance of conditional density estimation. By using tools from neural density estimation (Bishop, 1994; Rezende & Mohamed, 2015), we can develop methods that have all of the above properties. To summarize, our contributions are the following:

We connect the fields of temporal point processes and neural density estimation. We show how normalizing flows can be used to define flexible and theoretically sound models for learning in temporal point processes.

We propose a simple mixture model that performs on par with the state-of-the-art methods. Thanks to its simplicity, the model permits closed-form sampling and moment computation.

We show through a wide range of experiments how the proposed models can be used for prediction, conditional generation, sequence embedding and training with missing data.

Background

Learning temporal point processes. Conditional intensity functions provide a convenient way to specify point processes with a simple predefined behavior, such as self-exciting (Hawkes, 1971) and self-correcting (Isham & Westcott, 1979) processes. Intensity parametrization is also commonly used when learning a model from the data: Given a parametric intensity function λθ∗(t)\lambda^{*}_{{\bm{\theta}}}(t) and a sequence of observations T{\mathcal{T}}, the parameters θ{\bm{\theta}} can be estimated by maximizing the log-likelihood: θ∗=arg max⁡θ∑ilog⁡pθ∗(τi)=arg max⁡θ[∑ilog⁡λθ∗(ti)−∫0tNλθ∗(s)ds]{\bm{\theta}}^{*}=\operatorname*{arg\,max}_{{\bm{\theta}}}\sum_{i}\log p^{*}_{{\bm{\theta}}}(\tau_{i})=\operatorname*{arg\,max}_{{\bm{\theta}}}\left[\sum_{i}\log\lambda^{*}_{{\bm{\theta}}}(t_{i})-\int_{0}^{t_{N}}\lambda^{*}_{{\bm{\theta}}}(s)ds\right].

The main challenge of such intensity-based approaches lies in choosing a good parametric form for λθ∗(t)\lambda^{*}_{{\bm{\theta}}}(t). This usually involves the following trade-off: For a ”simple” intensity function (Du et al., 2016; Huang et al., 2019), the integral Λ∗(τi):=∫0τiλ∗(ti−1+s)ds\Lambda^{*}(\tau_{i}):=\int_{0}^{\tau_{i}}\lambda^{*}(t_{i-1}+s)ds has a closed form, which makes the log-likelihood easy to compute. However, such models usually have limited expressiveness. A more sophisticated intensity function (Mei & Eisner, 2017) can better capture the dynamics of the system, but computing log-likelihood will require approximating the integral using Monte Carlo.

Recently, Omi et al. (2019) proposed fully neural network intensity function (FullyNN) — a flexible, yet computationally tractable model for TPPs. The key idea of their approach is to model the cumulative conditional intensity function Λ∗(τi)\Lambda^{*}(\tau_{i}) using a neural network, which allows to efficiently compute the log-likelihood. Still, in its current state, the model has downsides: it doesn’t define a valid PDF, sampling is expensive, and the expectation cannot be computed in closed formA more detailed discussion of the FullyNN model follows in Section 4 and Appendix C..

This work. We show that the drawbacks of the existing approaches can be remedied by looking at the problem of learning in TPPs from a different angle. Instead of modeling the conditional intensity λ∗(t)\lambda^{*}(t), we suggest to directly learn the conditional distribution p∗(τ)p^{*}(\tau). Modeling distributions with neural networks is a well-researched topic, that, surprisingly, is not usually discussed in the context of TPPs. By adopting this alternative point of view, we are able to develop new theoretically sound and effective methods (Section 3), as well as better understand the existing approaches (Section 4).

Models

We develop several approaches for modeling the distribution of inter-event times. First, we assume for simplicity that each inter-event time τi\tau_{i} is conditionally independent of the history, given the model parameters (that is, p∗(τi)=p(τi)p^{*}(\tau_{i})=p(\tau_{i})). In Section 3.1, we show how state-of-the-art neural density estimation methods based on normalizing flows can be used to model p(τi)p(\tau_{i}). Then in Section 3.2, we propose a simple mixture model that can match the performance of the more sophisticated flow-based models, while also addressing some of their shortcomings. Finally, we discuss how to make p(τi)p(\tau_{i}) depend on the history Hti\mathcal{H}_{t_{i}} in Section 3.3.

where a,w,s,μ{\bm{a}},{\bm{w}},{\bm{s}},{\bm{\mu}} are the transformation parameters, KK is the number of components, RR is the polynomial degree, and σ(x)=1/(1+e−x)\sigma(x)=1/(1+e^{-x}). We denote the two variants of the model based on fDSFf^{DSF} and fSOSf^{SOS} building blocks as DSFlow and SOSFlow respectively. Finally, after stacking multiple gm−1=fθmg_{m}^{-1}=f_{{\bm{\theta}}_{m}}, we apply a sigmoid transformation g1−1=σg_{1}^{-1}=\sigma to convert z2z_{2} into z1∈(0,1)z_{1}\in(0,1).

This raises the question: Can we design a model for p(τ)p(\tau) that is as expressive as the flow-based models, but in which sampling and computing moments is easy and can be done in closed form?

2 Modeling p​(τ)𝑝𝜏p(\tau) with mixture distributions

Model definition. While mixture models are commonly used for clustering, they can also be used for density estimation. Mixtures work especially well in low dimensions (McLachlan & Peel, 2004), which is the case in TPPs, where we model the distribution of one-dimensional inter-event times τ\tau. Since the inter-event times τ\tau are positive, we choose to use a mixture of log-normal distributions to model p(τ)p(\tau). The PDF of a log-normal mixture is defined as

where w{\bm{w}} are the mixture weights, μ{\bm{\mu}} are the mixture means, and s{\bm{s}} are the standard deviations. Because of its simplicity, the log-normal mixture model has a number of attractive properties.

Sampling. While flow-based models from Section 3.1 require iterative root-finding algorithms to generate samples, sampling from a mixture model can be done in closed form:

where z{\bm{z}} is a one-hot vector of size KK. In some applications, such as reinforcement learning (Upadhyay et al., 2018), we might be interested in computing gradients of the samples w.r.t. the model parameters. The samples τ\tau drawn using the procedure above are differentiable with respect to the means μ{\bm{\mu}} and scales s{\bm{s}}. By using the Gumbel-softmax trick (Jang et al., 2017) when sampling z{\bm{z}}, we can obtain gradients w.r.t. all the model parameters (Appendix D.6). Such reparametrization gradients have lower variance and are easier to implement than the score function estimators typically used in other works (Mohamed et al., 2019). Other flexible models (such as multi-layer flow models from Section 3.1) do not permit sampling through reparametrization, and thus are not well-suited for the above-mentioned scenario. In Section 5.4, we show how reparametrization sampling can also be used to train with missing data by performing imputation on the fly.

3 Incorporating the conditional information

Conditioning on additional features. The distribution of the time until the next event might depend on factors other than the history. For instance, distribution of arrival times of customers in a restaurant depends on the day of the week. As another example, if we are modeling user behavior in an online system, we can obtain a different distribution p∗(τ)p^{*}(\tau) for each user by conditioning on their metadata. We denote such side information as a vector yi{\bm{y}}_{i}. Such information is different from marks (Rasmussen, 2011), since (a) the metadata may be shared for the entire sequence and (b) yi{\bm{y}}_{i} only influences the distribution p∗(τi∣yi)p^{*}(\tau_{i}|{\bm{y}}_{i}), not the objective function.

In some scenarios, we might be interested in learning from multiple event sequences. In such case, we can assign each sequence Tj{\mathcal{T}}_{j} a learnable sequence embedding vector ej{\bm{e}}_{j}. By optimizing ej{\bm{e}}_{j}, the model can learn to distinguish between sequences that come from different distributions. The learned embeddings can then be used for visualization, clustering or other downstream tasks.

Obtaining the parameters. We model the conditional dependence of the distribution p∗(τi)p^{*}(\tau_{i}) on all of the above factors in the following way. The history embedding hi{\bm{h}}_{i}, metadata yi{\bm{y}}_{i} and sequence embedding ej{\bm{e}}_{j} are concatenated into a context vector ci=[hi∣∣yi∣∣ej]{\bm{c}}_{i}=[{\bm{h}}_{i}||{\bm{y}}_{i}||{\bm{e}}_{j}]. Then, we obtain the parameters of the distribution p∗(τi)p^{*}(\tau_{i}) as an affine function of ci{\bm{c}}_{i}. For example, for the mixture model we have

4 Discussion

This results shows that, in principle, the mixture distribution is as expressive as the flow-based models. Since we are modeling the conditional density, we additionally need to assume for all of the above models that the RNN can encode all the relevant information into the history embedding hi{\bm{h}}_{i}. This can be accomplished by invoking the universal approximation theorems for RNNs (Siegelmann & Sontag, 1992; Schäfer & Zimmermann, 2006).

Note that this result, like other UA theorems of this kind (Cybenko, 1989; Daniels & Velikova, 2010), does not provide any practical guarantees on the obtained approximation quality, and doesn’t say how to learn the model parameters. Still, UA intuitively seems like a desirable property of a distribution. This intuition is supported by experimental results. In Section 5.1, we show that models with the UA property consistently outperform the less flexible ones.

Intensity function. For both flow-based and mixture models, the conditional cumulative distribution function (CDF) F∗(τ)F^{*}(\tau) and the PDF p∗(τ)p^{*}(\tau) are readily available. This means we can easily compute the respective intensity functions (see Appendix A). However, we should still ask whether we lose anything by modeling p∗(τ)p^{*}(\tau) instead of λ∗(t)\lambda^{*}(t). The main arguments in favor of modeling the intensity function in traditional models (e.g. self-exciting process) are that it’s intuitive, easy to specify and reusable (Upadhyay & Rodriguez, 2019).

“Intensity function is intuitive, while the conditional density is not.” — While it’s true that in simple models (e.g. in self-exciting or self-correcting processes) the dependence of λ∗(t)\lambda^{*}(t) on the history is intuitive and interpretable, modern RNN-based intensity functions (as in Du et al. (2016); Mei & Eisner (2017); Omi et al. (2019)) cannot be easily understood by humans. In this sense, our proposed models are as intuitive and interpretable as other existing intensity-based neural network models.

“λ∗(t)\lambda^{*}(t) is easy to specify, since it only has to be positive. On the other hand, p∗(τ)p^{*}(\tau) must integrate to one.” — As we saw, by using either normalizing flows or a mixture distribution, we automatically enforce that the PDF integrates to one, without sacrificing the flexibility of our model.

“Reusability: If we merge two independent point processes with intensitites λ1∗(t)\lambda^{*}_{1}(t) and λ2∗(t)\lambda^{*}_{2}(t), the merged process has intensity λ∗(t)=λ1∗(t)+λ2∗(t)\lambda^{*}(t)=\lambda^{*}_{1}(t)+\lambda^{*}_{2}(t).” — An equivalent result exists for the CDFs F1∗(τ)F^{*}_{1}(\tau) and F2∗(τ)F^{*}_{2}(\tau) of the two independent processes. The CDF of the merged process is obtained as F∗(τ)=F1∗(τ)+F2∗(τ)−F1∗(τ)F2∗(τ)F^{*}(\tau)=F^{*}_{1}(\tau)+F^{*}_{2}(\tau)-F^{*}_{1}(\tau)F^{*}_{2}(\tau) (derivation in Appendix A).

As we just showed, modeling p∗(τ)p^{*}(\tau) instead of λ∗(t)\lambda^{*}(t) does not impose any limitation on our approach. Moreover, a mixture distribution is flexible, easy to sample from and has well-defined moments, which favorably compares it to other intensity-based deep learning models.

Related work

Neural temporal point processes. Fitting simple TPP models (e.g. self-exciting (Hawkes, 1971) or self-correcting (Isham & Westcott, 1979) processes) to real-world data may lead to poor results because of model misspecification. Multiple recent works address this issue by proposing more flexible neural-network-based point process models. These neural models are usually defined in terms of the conditional intensity function. For example, Mei & Eisner (2017) propose a novel RNN architecture that can model sophisticated intensity functions. This flexibility comes at the cost of inability to evaluate the likelihood in closed form, and thus requiring Monte Carlo integration.

Du et al. (2016) suggest using an RNN to encode the event history into a vector hi{\bm{h}}_{i}. The history embedding hi{\bm{h}}_{i} is then used to define the conditional intensity, for example, using the constant intensity model λ∗(ti)=exp⁡(vThi+b)\lambda^{*}(t_{i})=\exp({\bm{v}}^{T}{\bm{h}}_{i}+b) (Li et al., 2018; Huang et al., 2019) or the more flexible exponential intensity model λ∗(ti)=exp⁡(w(ti−ti−1)+vThi+b)\lambda^{*}(t_{i})=\exp(w(t_{i}-t_{i-1})+{\bm{v}}^{T}{\bm{h}}_{i}+b) (Du et al., 2016; Upadhyay et al., 2018). By considering the conditional distribution p∗(τ)p^{*}(\tau) of the two models, we can better understand their properties. Constant intensity corresponds to an exponential distribution, and exponential intensity corresponds to a Gompertz distribution (see Appendix B). Clearly, these unimodal distributions cannot match the flexibility of a mixture model (as can be seen in Figure 8).

Several works used mixtures of kernels to parametrize the conditional intensity function (Taddy et al., 2012; Tabibian et al., 2017; Okawa et al., 2019). Such models can only capture self-exciting influence from past events. Moreover, these models do not permit computing expectation and drawing samples in closed form. Recently, Biloš et al. (2019) and Türkmen et al. (2019) proposed neural models for learning marked TPPs. These models focus on event type prediction and share the limitations of other neural intensity-based approaches. Other recent works consider alternatives to the maximum likelihood objective for training TPPs. Examples include noise-contrastive estimation (Guo et al., 2018), Wasserstein distance (Xiao et al., 2017; 2018; Yan et al., 2018), and reinforcement learning (Li et al., 2018; Upadhyay et al., 2018). This line of research is orthogonal to our contribution, and the models proposed in our work can be combined with the above-mentioned training procedures.

Neural density estimation. There exist two popular paradigms for learning flexible probability distributions using neural networks: In mixture density networks (Bishop, 1994), a neural net directly produces the distribution parameters; in normalizing flows (Tabak & Turner, 2013; Rezende & Mohamed, 2015), we obtain a complex distribution by transforming a simple one. Both mixture models (Schuster, 2000; Eirola & Lendasse, 2013; Graves, 2013) and normalizing flows (Oord et al., 2016; Ziegler & Rush, 2019) have been applied for modeling sequential data. However, surprisingly, none of the existing works make the connection and consider these approaches in the context of TPPs.

Experiments

We evaluate the proposed models on the established task of event time prediction (with and without marks) in Sections 5.1 and 5.2. In the remaining experiments, we show how the log-normal mixture model can be used for incorporating extra conditional information, training with missing data and learning sequence embeddings. We use 6 real-world datasets containing event data from various domains: Wikipedia (article edits), MOOC (user interaction with online course system), Reddit (posts in social media) (Kumar et al., 2019), Stack Overflow (badges received by users), LastFM (music playback) (Du et al., 2016), and Yelp (check-ins to restaurants). We also generate 5 synthetic datasets (Poisson, Renewal, Self-correcting, Hawkes1, Hawkes2), as described in Omi et al. (2019). Detailed descriptions and summary statistics of all the datasets are provided in Appendix E.

Setup. We consider two normalizing flow models, SOSFlow and DSFlow (Equation 1), as well a log-normal mixture model (Equation 2), denoted as LogNormMix. As baselines, we consider RMTPP (i.e. Gompertz distribution / exponential intensity from Du et al. (2016)) and FullyNN model by Omi et al. (2019). Additionally, we use a single log-normal distribution (denoted LogNormal) to highlight the benefits of the mixture model. For all models, an RNN encodes the history into a vector hi{\bm{h}}_{i}. The parameters of p∗(τ)p^{*}(\tau) are then obtained using hi{\bm{h}}_{i} (Equation 3). We exclude the NeuralHawkes model from our comparison, since it is known to be inferior to RMTPP in time prediction (Mei & Eisner, 2017), and, unlike other models, doesn’t have a closed-form likelihood.

Each dataset consists of multiple sequences of event times. The task is to predict the time τi\tau_{i} until the next event given the history Hti\mathcal{H}_{t_{i}}. For each dataset, we use 60% of the sequences for training, 20% for validation and 20% for testing. We train all models by minimizing the negative log-likelihood (NLL) of the inter-event times in the training set. To ensure a fair comparison, we try multiple hyperparameter configurations for each model and select the best configuration using the validation set. Finally, we report the NLL loss of each model on the test set. All results are averaged over 10 train/validation/test splits. Details about the implementation, training process and hyperparameter ranges are provided in Appendix D. For each real-world dataset, we report the difference between the NLL loss of each method and the LogNormMix model (Figure 3). We report the differences, since scores of all models can be shifted arbitrarily by scaling the data. Absolute scores (not differences) in a tabular format, as well as results for synthetic datasets are provided in Appendix F.1.

Results. Simple unimodal distributions (Gompertz/RMTPP, LogNormal) are always dominated by the more flexible models with the universal approximation property (LogNormMix, DSFlow, SOSFlow, FullyNN). Among the simple models, LogNormal provides a much better fit to the data than RMTPP/Gompertz. The distribution of inter-event times in real-world data often has heavy tails, and the Gompertz distributions fails to capture this behavior. We observe that the two proposed models, LogNormMix and DSFlow consistently achieve the best loss values.

2 Learning with marks

Setup. We apply the models for learning in marked temporal point processes. Marks are known to improve performance of simpler models (Du et al., 2016), we want to establish whether our proposed models work well in this setting. We use the same setup as in the previous section, except for two differences. The RNN takes a tuple (τi,mi)(\tau_{i},m_{i}) as input at each time step, where mim_{i} is the mark. Moreover, the loss function now includes a term for predicting the next mark: L(θ)=−∑i[log⁡pθ∗(τi)+log⁡pθ∗(mi)]{\mathcal{L}}({\bm{\theta}})=-\sum_{i}\left[\log p^{*}_{{\bm{\theta}}}(\tau_{i})+\log p^{*}_{{\bm{\theta}}}(m_{i})\right] (implementation details in Appendix F.2).

Results. Figure 3 (right) shows the time NLL loss (i.e. −∑ilog⁡p∗(τi)-\sum_{i}\log p^{*}(\tau_{i})) for Reddit and MOOC datasets. LogNormMix shows dominant performance in the marked case, just like in the previous experiment. Like before, we provide the results in tabular format, as well as report the marks NLL loss in Appendix F.

3 Learning with additional conditional information

Setup. We investigate whether the additional conditional information (Section 3.3) can improve performance of the model. In the Yelp dataset, the task is predict the time τ\tau until the next check-in for a given restaurant. We postulate that the distribution p∗(τ)p^{*}(\tau) is different, depending on whether it’s a weekday and whether it’s an evening hour, and encode this information as a vector yi{\bm{y}}_{i}. We consider 4 variants of the LogNormMix model, that either use or don’t use yi{\bm{y}}_{i} and the history embedding hi{\bm{h}}_{i}.

Results. Figure 7 shows the test set loss for 4 variants of the model. We see that additional conditional information boosts performance of the LogNormMix model, regardless of whether the history embedding is used.

4 Missing data imputation

In practical scenarios, one often has to deal with missing data. For example, we may know that records were not kept for a period of time, or that the data is unusable for some reason. Since TPPs are a generative model, they provide a principled way to handle the missing data through imputation.

Setup. We are given several sequences generated by a Hawkes process, where some parts are known to be missing. We consider 3 strategies for learning from such a partially observed sequence: (a) ignore the gaps, maximize log-likelihood of observed inter-event times (b) fill the gaps with the average τ\tau estimated from observed data, maximize log-likelihood of observed data, and (c) fill the gaps with samples generated by the model, maximize the expected log-likelihood of the observed points. The setup is demonstrated in Figure 4. Note that in case (c) the expected value depends on the parameters of the distribution, hence we need to perform sampling with reparametrization to optimize such loss. A more detailed description of the setup is given in Appendix F.4.

Results. The 3 model variants are trained on the partially-observed sequence. Figure 4 shows the NLL of the fully observed sequence (not seen by any model at training time) produced by each strategy. We see that strategies (a) and (b) overfit the partially observed sequence. In contrast, strategy (c) generalizes and learns the true underlying distribution. The ability of the LogNormMix model to draw samples with reparametrization was crucial to enable such training procedure.

5 Sequence embedding

Different sequences in the dataset might be generated by different processes, and exhibit different distribution of inter-event times. We can ”help” the model distinguish between them by assigning a trainable embedding vector ej{\bm{e}}_{j} to each sequence jj in the dataset. It seems intuitive that embedding vectors learned this way should capture some notion of similarity between sequences.

Learned sequence embeddings. We learn a sequence embedding for each of the sequences in the synthetic datasets (along with other model parameters). We visualize the learned embeddings using t-SNE (Maaten & Hinton, 2008) in Figure 7 colored by the true class. As we see, the model learns to differentiate between sequences from different distributions in a completely unsupervised way.

Generation. We fit the LogNormMix model to two sequences (from self-correcting and renewal processes), and, respectively, learn two embedding vectors eSC{\bm{e}}_{SC} and eRN{\bm{e}}_{RN}. After training, we generate 3 sequences from the model, using eSC{\bm{e}}_{SC}, \nicefrac12(eSC+eRN)\nicefrac{{1}}{{2}}({\bm{e}}_{SC}+{\bm{e}}_{RN}) and eRN{\bm{e}}_{RN} as sequence embeddings. Additionally, we plot the learned conditional intensity function of our model for each generated sequence (Figure 7). The model learns to map the sequence embeddings to very different distributions.

Conclusions

We use tools from neural density estimation to design new models for learning in TPPs. We show that a simple mixture model is competitive with state-of-the-art normalizing flows methods, as well as convincingly outperforms other existing approaches. By looking at learning in TPPs from a different perspective, we were able to address the shortcomings of existing intensity-based approaches, such as insufficient flexibility, lack of closed-form likelihoods and inability to generate samples analytically. We hope this alternative viewpoint will inspire new developments in the field of TPPs.

Acknowledgments

This research was supported by the German Federal Ministry of Education and Research (BMBF), grant no. 01IS18036B, and the Software Campus Project Deep-RENT. The authors of this work take full responsibilities for its content.

References

Appendix A Intensity function of flow and mixture models

CDF and conditional intensity function of proposed models. The cumulative distribution function (CDF) of a normalizing flow model can be obtained in the following way. If zz has a CDF Q(z)Q(z) and τ=g(z)\tau=g(z), then the CDF F(τ)F(\tau) of τ\tau is obtained as

Since for both SOSFlow and DSFlow we can evaluate g−1g^{-1} in closed form, F(τ)F(\tau) is easy to compute.

For the log-normal mixture model, CDF is by definition equal to

where Φ(⋅)\Phi(\cdot) is the CDF of a standard normal distribution.

Given the conditional PDF and CDF, we can compute the conditional intensity λ∗(t)\lambda^{*}(t) and the cumulative intensity Λ∗(τ)\Lambda^{*}(\tau) for each model as

where ti−1t_{i-1} is the arrival time of most recent event before tt (Rasmussen, 2011).

Merging two independent processes. We replicate the setup from Upadhyay & Rodriguez (2019) and consider what happens if we merge two independent TPPs with intensity functions λ1∗(t)\lambda^{*}_{1}(t) and λ2∗(t)\lambda^{*}_{2}(t) (and respectively, cumulative intensity functions Λ1∗(τ)\Lambda^{*}_{1}(\tau) and Λ2∗(τ)\Lambda^{*}_{2}(\tau)). According to Upadhyay & Rodriguez (2019), the intensity function of the new process is λ∗(t)=λ1∗(t)+λ2∗(t)\lambda^{*}(t)=\lambda^{*}_{1}(t)+\lambda^{*}_{2}(t). Therefore, the cumulative intensity function of the new process is

Using the previous result, we can obtain the CDF of the merged process as

The PDF of the merged process is obtained by simply differentiating the CDF w.r.t. τ\tau.

This means that by using either normalizing flows or mixture distributions, and thus directly modeling PDF / CDF, we are not losing any benefits of the intensity parametrization.

Appendix B Discussion of constant & exponential intensity models

Exponential intensity model as Gompertz distribution. PDF of a Gompertz distribution (Wienke, 2010) is defined as

By setting α=exp⁡(d)\alpha=\exp(d) and β=w\beta=w we see that the exponential intensity model is equivalent to a Gompertz distribution.

Discussion. Figure 8 shows densities that can be represented by exponential and Gompertz distributions. Even though the history embedding hi{\bm{h}}_{i} produced by an RNN may capture rich information, the resulting distribution p∗(τi)p^{*}(\tau_{i}) for both models has very limited flexibility, is unimodal and light-tailed. In contrast, a flow-based or a mixture model is significantly more flexible and can approximate any density.

Appendix C Discussion of the FullyNN model

The main idea of the approach by Omi et al. (2019) is to model the integrated conditional intensity function

using a feedforward neural network with non-negative weights

FullyNN as a normalizing flow

Let z∼Exponential⁡(1)z\sim\operatorname{Exponential}(1), that is

We can now use the change of variables formula to obtain the conditional CDF and PDF of τ\tau.

Alternatively, we can obtain the conditional intensity as

and use the fact that p∗(τi)=λ∗(ti−1+τi)exp⁡(−∫0τiλ∗(ti−1+s)ds)p^{*}(\tau_{i})=\lambda^{*}(t_{i-1}+\tau_{i})\exp\left(-\int_{0}^{\tau_{i}}\lambda^{*}(t_{i-1}+s)ds\right).

Both approaches lead to the same conclusion

Similarly to other flow-based models, sampling from the FullyNN model cannot be done exactly and requires a numerical approximation.

Shortcomings of the FullyNN model

The PDF defined by the FullyNN model doesn’t integrate to 1.

Therefore, the PDF doesn’t integrate to 1.

The FullyNN model assigns a non-zero amount of probability mass to the (−∞,0)(-\infty,0) interval, which violates the assumption that inter-event times are strictly positive.

Since the inter-event times τ\tau are assumed to be strictly positive almost surely, it must hold that Prob⁡(τ≤0)=F∗(0)=0\operatorname{Prob}(\tau\leq 0)=F^{*}(0)=0, or equivalently Λ∗(0)=0\Lambda^{*}(0)=0. However, we can see that

which means that the FullyNN model permits negative inter-event times.

Appendix D Implementation details

We implement SOSFlow, DSFlow and LogNormMix, together with baselines: RMTPP (Gompertz distribution), exponential distribution and a FullyNN model. All of them share the same pipeline, from the data preprocessing to the parameter tuning and model selection, differing only in the way we calculate p∗(τ)p^{*}(\tau). This way we ensure a fair evaluation. Our implementation uses Pytorch.https://pytorch.org/ (Paszke et al., 2017)

As illustrated in Section 3.3 we generate the parameters θ{\bm{\theta}} of the distribution p∗(τi)p^{*}(\tau_{i}) from [hi∣∣yi∣∣ej][{\bm{h}}_{i}||{\bm{y}}_{i}||{\bm{e}}_{j}] using an affine layer. We apply a transformation of the parameters to enforce the constraints, if necessary.

All decoders are implemented using a common framework relying on normalizing flows. By defining the base distribution q(z)q(z) and the inverse transformation (g1−1∘⋯∘gM−1)(g_{1}^{-1}\circ\cdots\circ g_{M}^{-1}) we can evaluate the PDF p∗(τ)p^{*}(\tau) at any τ\tau, which allows us to train with maximum likelihood (Section 3.1).

D.2 Log-normal mixture

By using the affine transformation z2=az1+bz_{2}=az_{1}+b before the exp⁡\exp transformation, we obtain a better initialization, and thus faster convergence. This is similar to the batch normalization flow layer (Dinh et al., 2017), except that b=1N∑i=1Nlog⁡τib=\frac{1}{N}\sum_{i=1}^{N}\log\tau_{i} and a=1N∑i=1N(log⁡τi−b)a=\sqrt{\frac{1}{N}\sum_{i=1}^{N}(\log\tau_{i}-b)} are estimated using the entire dataset, not using batches.

Forward direction samples a value from a Gaussian mixture, applies an affine transformation and applies exp⁡\exp. In the bacward direction we apply log-transformation to an observed data, center it with an affine layer and compute the density under the Gaussian mixture.

D.3 Baselines

We implement FullyNN model (Omi et al., 2019) as described in Appendix C, using the official implementation as a referencehttps://github.com/omitakahiro/NeuralNetworkPointProcess. The model uses feed-forward neural network with non-negative weights (enforced by clipping values at after every gradient step). Output of the network is a cumulative intensity function Λ∗(τ)\Lambda^{*}(\tau) from which we can easily get intensity function λ∗(τ)\lambda^{*}(\tau) as a derivative w.r.t. τ\tau using automatic differentiation in Pytorch. We get the PDF as p∗(τ)=λ∗(τ)exp⁡(−Λ∗(τ))p^{*}(\tau)=\lambda^{*}(\tau)\exp(-\Lambda^{*}(\tau)).

We implement RMTPP / Gompertz distribution (Du et al., 2016)https://github.com/musically-ut/tf_rmtpp and the exponential distribution (Upadhyay et al., 2018) models as described in Appendix B.

D.4 Deep sigmoidal flow

A single layer of DSFlow model is defined as

We define p(τ)p(\tau) through the inverse transformation (g1−1∘⋯∘gM−1)(g_{1}^{-1}\circ\cdots\circ g_{M}^{-1}), as described in Section 3.1.

We use the the batch normalization flow layer (Dinh et al., 2017) between every pair of consecutive layers, which significantly speeds up convergence.

D.5 Sum-of-squares polynomial flow

A single layer of SOSFlow model is defined as

We define p(τ)p(\tau) by through the inverse transformation (g1−1∘⋯∘gM−1)(g_{1}^{-1}\circ\cdots\circ g_{M}^{-1}), as described in Section 3.1.

Same as for DSFlow, we use the the batch normalization flow layer between every pair of consecutive layers. When implementing SOSFlow, we used Pyrohttps://pyro.ai/ (Bingham et al., 2018) for reference.

D.6 Reparametrization sampling

The gradients obtained by the Straight-Through Gumbel Estimator are slightly biased, which in practice doesn’t have a significant effect on the model’s performance. There exist alternatives (Tucker et al., 2017; Grathwohl et al., 2018) that provide unbiased gradients, but are more expensive to compute.

Appendix E Dataset statistics

Synthetic data is generated according to Omi et al. (2019) using well known point processes. We sample 6464 sequences for each process, each sequence containing 10241024 events.

Poisson. Conditional intensity function for a homogeneous (or stationary) Poisson point process is given as λ∗(t)=1\lambda^{*}(t)=1. Constant intensity corresponds to exponential distribution.

Renewal. A stationary process defined by a log-normal probability density function p(τ)p(\tau), where we set the parameters to be μ=1.0\mu=1.0 and σ=6.0\sigma=6.0. Sequences appear clustered.

Self-correcting. Unlike the previous two, this point process depends on the history and is defined by a conditional intensity function λ∗(t)=exp⁡(t−∑ti<t1)\lambda^{*}(t)=\exp(t-\sum_{t_{i}<t}1). After every new event the intensity suddenly drops, inhibiting the future points. The resulting point patterns appear regular.

Hawkes. We use a self-exciting point process with a conditional intensity function given as λ∗(t)=μ+∑ti<t∑j=1Mαjβjexp⁡(−βj(t−ti))\lambda^{*}(t)=\mu+\sum_{t_{i}<t}\sum_{j=1}^{M}\alpha_{j}\beta_{j}\exp(-\beta_{j}(t-t_{i})). As per Omi et al. (2019), we create two different datasets: Hawkes1 with M=1M=1, μ=0.02\mu=0.02, α1=0.8\alpha_{1}=0.8 and β1=1.0\beta_{1}=1.0; and Hawkes2 with M=2M=2, μ=0.2\mu=0.2, α1=0.4\alpha_{1}=0.4, β1=1.0\beta_{1}=1.0, α2=0.4\alpha_{2}=0.4 and β2=20\beta_{2}=20. For the imputation experiment we use Hawkes1 to generate the data and remove some of the events.

E.2 Real-world data

In addition we use real-world datasets that are described bellow. Table 2 shows their summary. All datasets have a large amount of unique sequences and the number of events per sequence varies a lot. Using marked temporal point processes to predict the type of an event is feasible for some datasets (e.g. when the number of classes is low), and is meaningless for other.

LastFM.Celma (2010) The dataset contains sequences of songs that selected users listen over time. Artists are used as an event type.

Reddit.https://github.com/srijankr/jodie/(Kumar et al., 2019) On this social network website users submit posts to subreddits. In the dataset, most active subreddits are selected, and posts from the most active users on those subreddits are recodered. Each sequence corresponds to a list of submissions a user makes. The data contains 984984 unique subreddits that we use as classes in mark prediction.

Stack Overflow.https://archive.org/details/stackexchange preprocessed according to Du et al. (2016) Users of a question-answering website get rewards (called badges) over time for participation. A sequence contains a list of rewards for each user. Only the most active users are selected and only those badges that users can get more than once.

MOOC.footnote 8 Contains the interaction of students with an online course system. An interaction is an event and can be of various types (9797 unique types), e.g. watching a video, solving a quiz etc.

Wikipedia.footnote 8 A sequence corresponds to edits of a Wikipedia page. The dataset contains most edited pages and users that have an activity (number of edits) above a certain threshold.

Yelp.https://www.yelp.com/dataset/challenge We use the data from the review forum and consider the reviews for the 300 most visited restaurants in Toronto. Each restaurant then has a corresponding sequence of reviews over time.

Appendix F Additional discussion of the experiments

Detailed setup. Each dataset consists of multiple sequences of inter-event times. We consider 10 train/validation/test splits of the sequences (of sizes 60%/20%/20%60\%/20\%/20\%). We train all model parameters by minimizing the negative log-likelihood (NLL) of the training sequences, defined as Ltime(θ)=−1N∑i=1Nlog⁡pθ∗(τi){\mathcal{L}}_{time}({\bm{\theta}})=-\frac{1}{N}\sum_{i=1}^{N}\log p^{*}_{{\bm{\theta}}}(\tau_{i}). After splitting the data into the 3 sets, we break down long training sequences into sequences of length at most 128. Optimization is performed using Adam (Kingma & Ba, 2015) with learning rate 10−310^{-3}. We perform training using mini-batches of 64 sequences. We train for up to 2000 epochs (1 epoch = 1 full pass through all the training sequences). For all models, we compute the validation loss at every epoch. If there is no improvement for 100 epochs, we stop optimization and revert to the model parameters with the lowest validation loss.

We select hyperparameter configuration for each model that achieves the lowest average loss on the validation set. For each model, we consider different values of L2L_{2} regularization strength C∈{0,10−5,10−3}C\in\{0,10^{-5},10^{-3}\}. Additionally, for SOSFlow we tune the number of transformation layers M∈{1,2,3}M\in\{1,2,3\} and for DSFlow M∈{1,2,3,5,10}M\in\{1,2,3,5,10\}. We have chosen the values of K such that the mixture model has approximately the same number of parameters as a 1-layer DSFlow or a 1-layer FullyNN model. More specifically, we set K=64K=64 for LogNormMix, DSFlow and FullyNN. We found all these models to be rather robust to the choice of KK, as can be seen in Table 3 for LogNormMix. For SOSFlow we used K=4K=4 and R=3R=3, resulting in a polynomial of degree 7 (per each layer). Higher values of RR led to unstable training, even when using batch normalization.

Additional discussion. In this experiment, we only condition the distribution p∗(τi)p^{*}(\tau_{i}) on the history embedding hi{\bm{h}}_{i}. We don’t learn sequence embeddings ej{\bm{e}}_{j} since they can only be learned for the training sequences, and not fore the validation/test sets.

There are two important aspects related to the NLL loss values that we report. First, the absolute loss values can be arbitrarily shifted by rescaling the data. Assume, that we have a distribution p(τ)p(\tau) that models the distribution of τ\tau. Now assume that we are interested in the distribution q(x)q(x) of x=aτx=a\tau (for a>0a>0). Using the change of variables formula, we obtain log⁡q(x)=log⁡p(τ)+log⁡a\log q(x)=\log p(\tau)+\log a. This means that by simply scaling the data we can arbitrarily offset the log-likelihood score that we obtain. Therefore, the absolute values of of the (negative) log-likelihood L{\mathcal{L}} for different models are of little interest — all that matters are the differences between them.

The loss values are dependent on the train/val/test split. Assume that model 1 achieves loss values L1={1.0,3.0}{\mathcal{L}}_{1}=\{1.0,3.0\} on two train/val/test splits, and model 2 achieves L2={2.0,4.0}{\mathcal{L}}_{2}=\{2.0,4.0\} on the same splits. If we first aggregate the scores and report the average L^1=2.0±1.0\hat{{\mathcal{L}}}_{1}=2.0\pm 1.0, L^2=3.0±1.0\hat{{\mathcal{L}}}_{2}=3.0\pm 1.0, it may seem that the difference between the two models is not significant. However, if we first compute the differences and then aggregate (L2−L1)=1.0±0.0({\mathcal{L}}_{2}-{\mathcal{L}}_{1})=1.0\pm 0.0 we see a different picture. Therefore, we use the latter strategy in Figure 3. For completeness, we also report the numbers obtained using the first strategy in Table 4.

As a baseline, we also considered the constant intensity / exponential distribution model (Upadhyay et al., 2018). However, we excluded the results for it from Figure 3, since it consistently achieved the worst loss values and had high variance. We still include the results for the constant intensity model in Table 4. We also performed all the experiments on the synthetic datasets (Appendix E.1). The results are shown in Table 5, together with NLL scores under the true model. We see that LogNormMix and DSFlow, besides achieving the best results, recover the true distribution.

Finally, in Figure 9 we plot the conditional distribution p(τ∣H)p(\tau|\mathcal{H}) with models trained on Yelp dataset. The events represent check-ins into a specific restaurant. Since check-ins mostly happen during the opening hours, the inter-event time is likely to be on the same day (0h), next day (24h), the day after (48h), etc. LogNormMix can fully recover this behavior from data while others either cannot learn multimodal distributions (e.g. RMTPP) or struggle to capture it (e.g. FullyNN).

F.2 Learning with marks

Detailed setup. We use the same setup as in Section F.1, except two differences. For learning in a marked temporal point process, we mimic the architecture from Du et al. (2016). The RNN takes a tuple (τi,mi)(\tau_{i},m_{i}) as input at each time step, where mim_{i} is the mark. Moreover, the loss function now includes a term for predicting the next mark: Ltotal(θ)=−1N∑i=1N[log⁡pθ∗(τi)+log⁡pθ∗(mi)]{\mathcal{L}}_{total}({\bm{\theta}})=-\frac{1}{N}\sum_{i=1}^{N}\left[\log p^{*}_{{\bm{\theta}}}(\tau_{i})+\log p^{*}_{{\bm{\theta}}}(m_{i})\right].

The next mark mim_{i} at time tit_{i} is predicted using a categorical distribution p∗(mi)p^{*}(m_{i}). The distribution is parametrized by the vector πi{\bm{\pi}}_{i}, where πi,c\pi_{i,c} is the probability of event mi=cm_{i}=c. We obtain πi{\bm{\pi}}_{i} using the history embedding hi{\bm{h}}_{i} passed through a feedforward neural network

where Vπ(1),Vπ(2)bπ(1),bπ(2){\bm{V}}^{(1)}_{{\bm{\pi}}},{\bm{V}}^{(2)}_{{\bm{\pi}}}{\bm{b}}_{{\bm{\pi}}}^{(1)},{\bm{b}}_{{\bm{\pi}}}^{(2)} are the parameters of the neural network.

Additional discussion. In Figure 3 (right) we reported the differences in time NLL between different models Ltime(θ)=−1N∑i=1Nlog⁡pθ∗(τi){\mathcal{L}}_{time}({\bm{\theta}})=-\frac{1}{N}\sum_{i=1}^{N}\log p^{*}_{{\bm{\theta}}}(\tau_{i}). In Table 6 we additionally provide the total NLL Ltotal(θ)=−1N∑i=1N[log⁡pθ∗(τi)+log⁡pθ∗(mi)]{\mathcal{L}}_{total}({\bm{\theta}})=-\frac{1}{N}\sum_{i=1}^{N}\left[\log p^{*}_{{\bm{\theta}}}(\tau_{i})+\log p^{*}_{{\bm{\theta}}}(m_{i})\right] averaged over multiple splits.

Using marks as input to the RNN improves time prediction quality for all the models. However, since we assume that the marks are conditionally independent of the time given the history (as was done in earlier works), all models have similar mark prediction accuracy.

F.3 Learning with additional conditional information

Detailed setup. In the Yelp dataset, the task is to predict the time τi\tau_{i} until the next customer check-in, given the history of check-ins up until the current time ti−1t_{i-1}. We want to verify our intuition that the distribution p∗(τi)p^{*}(\tau_{i}) depends on the current time ti−1t_{i-1}. For example, p∗(τi)p^{*}(\tau_{i}) might be different depending on whether it’s a weekday and / or it’s an evening hour. Unfortunately, a model that processes the history with an RNN cannot easily obtain this information. Therefore, we provide this information directly as a context vector yi{\bm{y}}_{i} when modeling p∗(τi)p^{*}(\tau_{i}).

The first entry of context vector yi∈{0,1}2{\bm{y}}_{i}\in\{0,1\}^{2} indicates whether the previous event ti−1t_{i-1} took place on a weekday or a weekend, and the second entry indicates whether ti−1t_{i-1} was in the 5PM–11PM time window. To each of the four possibilities we assign a learnable 64-dimensional embedding vector. The distribution of p∗(τi)p^{*}(\tau_{i}) until the next event depends on the embedding vector of the time stamp ti−1t_{i-1} of the most recent event.

F.4 Missing data imputation

Detailed setup. The dataset for the experiment is generated as a two step process: 1) We generate a sequence of 100100 events from the model used for Hawkes1 dataset (Appendix E.1) resulting in a sequence of arrival times {t1,…tN}\{t_{1},\dots t_{N}\}, 2) We choose random tit_{i} and remove all the events that fall inside the interval [ti,ti+k][t_{i},t_{i+k}] where kk is selected such that the interval length is approximately tN/3t_{N}/3.

We consider three strategies for learning with missing data (shown in Figure 4 (left)):

No imputation. The missing block spans the time interval [ti,ti+k][t_{i},t_{i+k}]. We simply ignore the missing data, i.e. training objective Ltime{\mathcal{L}}_{time} will include an inter-event time τ=ti+k−ti\tau=t_{i+k}-t_{i}.

Sampling . The RNN encodes the history up to and including tit_{i} and produces hi{\bm{h}}_{i} that we use to define the distribution p∗(τ∣hi)p^{*}(\tau|{\bm{h}}_{i}). We draw a sample τj(imp)\tau_{j}^{(imp)} form this distribution and feed it into the RNN. We keep repeating this procedure until the samples get past the point ti+kt_{i+k}. The imputed inter-event times τj(imp)\tau^{(imp)}_{j} are affecting the hidden state of the RNN (thus influencing the likelihood of future observed inter-event times τi(obs)\tau^{(obs)}_{i}).

F.5 Sequence embedding

Detailed setup. When learning sequence embeddings, we train the model as described in Appendix F.1, besides one difference. First, we pre-train the sequence embeddings ej{\bm{e}}_{j} by disabling the history embedding hi{\bm{h}}_{i} and optimizing −1N∑ilog⁡pθ(τi∣ej)-\frac{1}{N}\sum_{i}\log p_{{\bm{\theta}}}(\tau_{i}|{\bm{e}}_{j}). Afterwards, we enable the history and minimize −1N∑ilog⁡pθ(τi∣ej,hi)-\frac{1}{N}\sum_{i}\log p_{{\bm{\theta}}}(\tau_{i}|{\bm{e}}_{j},{\bm{h}}_{i}).

In Figure 7 the top row shows samples generated using eSC{\bm{e}}_{SC}, embedding of a self-correcting sequence, the bottom row was generated using eSC{\bm{e}}_{SC}, embedding of a renewal sequence, and the middle row was generated using \nicefrac12(eSC+eRN)\nicefrac{{1}}{{2}}({\bm{e}}_{SC}+{\bm{e}}_{RN}), an average of the two embeddings.