discotime.models.components module

class discotime.models.components.Block(*, n_hidden_units: int, add_skip_connection: bool = True, activation_function: ~typing.Type[~torch.nn.modules.module.Module] = <class 'torch.nn.modules.activation.SiLU'>, batch_normalization: bool = True, dropout_rate: float | None = None)[source]

Bases: Module

Neural network building block for the Net class.

Parameters:
  • n_hidden_units – number of units in each hidden layer.

  • add_skip_connection – Defaults to True.

  • activation_function – Defaults to nn.SiLU.

  • batch_normalization – Should batch normalization be performed? Defaults to True.

  • dropout_rate – dropout_rate is being passed along to nn.Dropout(). If None, then dropout is not being used. Defaults to None.

forward(x: Tensor) Tensor[source]
discotime.models.components.negative_log_likelihood(logits: Tensor, time: Tensor, event: Tensor) Tensor[source]

Negative log-likelihood for logistic hazard model with competing risks.

The hazards are expected to be given as logits scale, i.e. they should not have been passed through torch.log_softmax() or similar.

An implementation of equation (8.6) from Tutz and Schmid [1], inspired by the one in pycox following Kvamme et. al. [2]

Parameters:

[1]: Tutz, Gerhard, and Matthias Schmid. Modeling discrete time-to-event data. New York: Springer, 2016.

[2]: Kvamme, Håvard, Ørnulf Borgan, and Ida Scheel. “Time-to-event prediction with neural networks and Cox regression.” arXiv preprint arXiv:1907.00825 (2019).