Introduction
Preparation and How to Run Code
Model Description
Result
Acknowledgement and Reference
This repository is the implementation of model described in paper Du, Nan, et al. “Recurrent Marked Temporal Point Processes.” by pytorch. This repository also use the same data as the data used in the paper. The rest of this section is a recap of the paper.
Discrete events with different types, which is defined as Marked Temporal Point Process, is usually generated in real life setting. Some past events may increase or decrease the occurrence probability of other kinds of event in the future. For example, in health care system having some type of medicines may cause a lower probability of some specific disease, and in social media like twitter some tweets may cause an increasing number of tweets of the same topic in a short time. The Recurrent Marked Temporal Point Process (RMTPP) model is robust to predict the next event time and next event type. That is, given a stream of past event times t and past event types k of form
{(k1, t1), (k2, t2), … (kn, tn)}, where 1,2,n represents the 1st, 2nd, nth event, it can predict the next type and type
(kn+1, tn+1)
You can run the code on your own computer or on python notebooks like Google Colab, Anaconda Jupyter Notebook. It is recommended to run the script on google colab (https://colab.research.google.com/) or similar python notebooks if you do not have a dedicated GPU on your computer.
- To run the program on your computer, please make sure that you have the following files and packages being downloaded.
- Python3: you can download through the link here: https://www.python.org/
- Numpy: you can dowload it through command
pip install numpy
- Scikit-Learn: you can download it through command
pip install sklearn
- Scipy: you can download it through command
pip install scipy
- Pytorch: pytorch installation is more complicated than the package described above. You can go to https://pytorch.org/get-started/locally/ for more information. If you still cannot install it on windows computer through pip, you can download Anaconda first and then download the pytorch through method described here: https://dziganto.github.io/data%20science/python/anaconda/Creating-Conda-Environments/
-
You can also run the code on Google Colab. You first need to connect this repository to Colab by the following code:
!git clone https://github.com/Hongrui24/RMTPP-pytorch
Then cd to this directory by!cd RMTPP-pytorch
-
To train the model, you can type the following for guide:
!python train.py --help
Sample command line can be!python train.py --lr 0.03 --epochs 500 --data hawkes
To test the trained model, you can type the following for guide:!python test.py --help
Sample command line can be!python test.py --data hawkes
After done the test, you can find the result plots in the same file named by "result.png".
This is a recap of the model described in the paper:
This model is trained by Backpropogation Through Time (BPTT) method. That is, for each event stream {(kj, tj)} we take b consecutive events as input into the model, and unroll the model for b steps through time. However, we will use the whole history of event stream to make prediction for hawkes and self-correcting.
We input the jth event (kj, tj) into the jth layer of the model. The event type, which is in one-hot representation, is embeded into a single value.
yj = We·kj+bWe extract the inter-event duration from the time tj by making
dj = tj - tj-1, and d0 = 0Then, we feed the type value and inter-event duration into the jth layer of the RNN cell. In order to prevent the dying relu problem, all weights are initialized with positive values. We update the hidden layer of the RNN by
hj = relu(Wy·yj + Wt·dj+Wh·hj-1 + b)Then, we get the predict event type probability through softmax method. We can also get the time intensity and conditional density of time by
λ*(t) = exp(V·ht + wdt + bias)
f(t) = exp(V·ht + wdt + bias + (exp(V·ht+ bias)-exp(V·ht + w*dt + bias)/w)For training process, we minimize the negative log likelihood of the time, and we use the expectation to predict the next time.
We test our model with the data used in the paper's generative experiments of predicting Hawkes and Self-correcting. The results show that the model implemented by pytorch is able to get the similar result as the result described in the paper after the model is trained with 500 epochs with 0.03 learning rate. In each of the picture below the graphs are prediction on inter-event duration, intensity, and Root-Mean-Squared-Error accordingly.
Test on Hawkes:
Comparing to the results on the paper:
Test on Self-correcting:
Comparing to the results on the paper:
The model is built by Hongrui Lyu, supervised by of Hyunouk Ko and Xiaoming Huo. This repository is built upon the model described in paper Du, Nan, et al. “Recurrent Marked Temporal Point Processes.”. We also use a similar pytorch implementation by Yunxuan Xiao to debug the model.