myozka / RMTPP-pytorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RMTPP-pytorch

Material in this file:

  Introduction
  Preparation and How to Run Code
  Model Description
  Result
  Acknowledgement and Reference

Introduction

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)

Preparation and How to Run the Code

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.

  1. To run the program on your computer, please make sure that you have the following files and packages being downloaded.
  1. 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

  2. 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".

Model Description

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+b 
We extract the inter-event duration from the time tj by making
 dj = tj - tj-1, and d0 = 0 
Then, 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.

Model Test Results

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:
Hawkes
Comparing to the results on the paper: Hawkes


Test on Self-correcting:
self-correcting
Comparing to the results on the paper: Self-correcting

Acknowledgement

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.

About


Languages

Language:Python 100.0%