easy_tpp.model.torch_model.torch_nhp
Classes
|
LSTM Cell in Neural Hawkes Process, NeurIPS'17. |
|
Torch implementation of The Neural Hawkes Process: A Neurally Self-Modulating Multivariate Point Process, NeurIPS 2017, https://arxiv.org/abs/1612.09328. |
- class easy_tpp.model.torch_model.torch_nhp.ContTimeLSTMCell(hidden_dim, beta=1.0)[source]
LSTM Cell in Neural Hawkes Process, NeurIPS’17.
- __init__(hidden_dim, beta=1.0)[source]
Initialize the continuous LSTM cell.
- Parameters:
hidden_dim (int) – dim of hidden state.
beta (float, optional) – beta in nn.Softplus. Defaults to 1.0.
- init_dense_layer(hidden_dim, bias, beta)[source]
Initialize linear layers given Equations (5a-6c) in the paper.
- Parameters:
hidden_dim (int) – dim of hidden state.
bias (bool) – whether to use bias term in nn.Linear.
beta (float) – beta in nn.Softplus.
- forward(x_i, hidden_i_minus, cell_i_minus, cell_bar_i_minus_1)[source]
Update the continuous-time LSTM cell.
- Parameters:
x_i (tensor) – event embedding vector at t_i.
hidden_i_minus (tensor) – hidden state at t_i-
cell_i_minus (tensor) – cell state at t_i-
cell_bar_i_minus_1 (tensor) – cell bar state at t_{i-1}
- Returns:
cell state, cell bar state, decay and output at t_i
- Return type:
list
- decay(cell_i, cell_bar_i, gate_decay, gate_output, dtime)[source]
Cell and hidden state decay according to Equation (7).
- Parameters:
cell_i (tensor) – cell state at t_i.
cell_bar_i (tensor) – cell bar state at t_i.
gate_decay (tensor) – gate decay state at t_i.
gate_output (tensor) – gate output state at t_i.
dtime (tensor) – delta time to decay.
- Returns:
list of cell and hidden state tensors after the decay.
- Return type:
list
- class easy_tpp.model.torch_model.torch_nhp.NHP(model_config)[source]
Torch implementation of The Neural Hawkes Process: A Neurally Self-Modulating Multivariate Point Process, NeurIPS 2017, https://arxiv.org/abs/1612.09328.
- __init__(model_config)[source]
Initialize the NHP model.
- Parameters:
model_config (EasyTPP.ModelConfig) – config of model specs.
- init_state(batch_size)[source]
Initialize hidden and cell states.
- Parameters:
batch_size (int) – size of batch data.
- Returns:
list of hidden states, cell states and cell bar states.
- Return type:
list
- forward(batch, **kwargs)[source]
Call the model.
- Parameters:
batch (tuple, list) – batch input.
- Returns:
- hidden states, [batch_size, seq_len, hidden_dim], states right before the event happens;
stacked decay states, [batch_size, max_seq_length, 4, hidden_dim], states right after the event happens.
- Return type:
list
- loglike_loss(batch)[source]
Compute the loglike loss.
- Parameters:
batch (list) – batch input.
- Returns:
loglike loss, num events.
- Return type:
list
- compute_states_at_sample_times(decay_states, sample_dtimes)[source]
Compute the states at sampling times.
- Parameters:
decay_states (tensor) – states right after the events.
sample_dtimes (tensor) – delta times in sampling.
- Returns:
hiddens states at sampling times.
- Return type:
tensor
- compute_intensities_at_sample_times(time_seqs, time_delta_seqs, type_seqs, sample_dtimes, **kwargs)[source]
Compute the intensity at sampled times, not only event times.
- Parameters:
time_seqs (tensor) – [batch_size, seq_len], times seqs.
time_delta_seqs (tensor) – [batch_size, seq_len], time delta seqs.
type_seqs (tensor) – [batch_size, seq_len], event type seqs.
sample_dtimes (tensor) – [batch_size, seq_len, num_sample], sampled inter-event timestamps.
- Returns:
- [batch_size, num_times, num_mc_sample, num_event_types],
intensity at each timestamp for each event type.
- Return type:
tensor