tempor.models.ts_ode module¶
Time series ODE model implementations.
-
class tempor.models.ts_ode.CDEFunc(n_units_in: int, n_units_hidden: int, n_layers_hidden: int =
1, nonlin: Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax] ='relu', dropout: float =0, device: Any =device(type='cpu'))[source]¶ Bases:
ModuleCDEFunc computes \(f_\theta for the CDE model : z_t = z_0 + \int_0^t f_\theta(z_s) dX_s\).
- Parameters:¶
- n_units_in : int¶
Number of input units.
Number of hidden units.
Number of hidden layers. Defaults to
1.- nonlin : Nonlin, optional¶
Nonlinearity to use in NN. Available options:
Nonlin. Defaults to"relu".- dropout : float, optional¶
Dropout value. If
0, the dropout is not used. Defaults to0.- device : Any, optional¶
PyTorch device to use. Defaults to
DEVICE.
-
class tempor.models.ts_ode.ODEFunc(n_units_hidden: int, n_layers_hidden: int =
1, nonlin: Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax] ='relu', dropout: float =0, device: Any =device(type='cpu'))[source]¶ Bases:
ModuleODEFunc computes \(f_\theta for the ODE model : z_t = z_0 + \int_0^t f_\theta(z_s) dX_s\).
- Parameters:¶
Number of hidden units.
Number of hidden layers. Defaults to
1.- nonlin : Nonlin, optional¶
Nonlinearity to use in NN. Available options:
Nonlin. Defaults to"relu".- dropout : float, optional¶
Dropout value. If
0, the dropout is not used. Defaults to0.- device : Any, optional¶
PyTorch device to use. Defaults to
DEVICE.
-
class tempor.models.ts_ode.ReverseGRUEncoder(n_units_in: int, n_units_latent: int, n_units_hidden: int, device: Any =
device(type='cpu'))[source]¶ Bases:
ModuleModel (encoder and Laplace representation func). Encodes observed trajectory into latent vector.
-
class tempor.models.ts_ode.LaplaceFunc(s_dim: int, n_units_out: int, n_units_latent: int, n_units_hidden: int =
64, device: Any =device(type='cpu'))[source]¶ Bases:
ModuleSphereSurfaceModel :
C^{b+k} -> C^{bxd}- in Riemann Sphere Coords :b dim sreconstruction terms,kis latent encoding dimension,dis output dimension.
-
class tempor.models.ts_ode.NeuralODE(task_type: Literal[classification] | Literal[regression], n_static_units_in: int, n_temporal_units_in: int, output_shape: list[int], n_units_hidden: int =
100, n_layers_hidden: int =1, nonlin: Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax] ='relu', nonlin_out: list[tuple[Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax], int]] | None =None, dropout: float =0, backend: Literal[ode] | Literal[cde] | Literal[laplace] ='cde', atol: float =0.01, rtol: float =0.01, interpolation: Literal[cubic] | Literal[linear] ='cubic', ilt_reconstruction_terms: int =33, ilt_algorithm: Literal[fourier] | Literal[dehoog] | Literal[cme] | Literal[fixed_tablot] | Literal[stehfest] ='fourier', lr: float =0.001, weight_decay: float =0.001, n_iter: int =1000, batch_size: int =500, n_iter_print: int =100, random_state: int =0, patience: int =10, n_iter_min: int =100, clipping_value: int =1, train_ratio: float =0.8, device: Any =device(type='cpu'), dataloader_sampler: Sampler | None =None)[source]¶ Bases:
ModuleThe model that computes the integral in: \(z_t = z_0 + \int_0^t f_\theta(z_s) dX_s\).
Neural ODEs are a new family of deep neural network models. Instead of specifying a discrete sequence of hidden layers, we parameterize the derivative of the hidden state using a neural network. The output of the network is computed using a blackbox differential equation solver. These are continuous-depth models that have constant memory cost, adapt their evaluation strategy to each input, and can explicitly trade numerical precision for speed.
- Parameters:¶
- task_type : ModelTaskType¶
The type of the problem. Available options:
ModelTaskType.- n_static_units_in : int¶
Number of features in the static tensor.
- n_temporal_units_in : int¶
Number of features in the temporal tensor.
- output_shape : List[int]¶
Shape of the output tensor.
Number of hidden units in each layer. Defaults to
100.Number of hidden layers. Defaults to
1.- nonlin : Nonlin, optional¶
Nonlinearity to use in NN. Available options:
Nonlin. Defaults to"relu".- nonlin_out : Optional[List[Tuple[Nonlin, int]]], optional¶
List of activations for the output. Example
[("tanh", 1), ("softmax", 3)]- means the output layer will apply"tanh"for the first unit, and"softmax"for the following 3 units in the output. Defaults toNone.- dropout : float, optional¶
Dropout value. If
0, the dropout is not used. Defaults to0.- backend : ODEBackend, optional¶
Which solver to use:
"cde","ode","laplace". Defaults to"cde".- atol : float, optional¶
Specific to
"ode"and"cde"backends. Absolute tolerance for solution. Defaults to1e-2.- rtol : float, optional¶
Specific to
"ode"and"cde"backends. Relative tolerance for solution. Defaults to1e-2.- interpolation : Interpolation, optional¶
Specific to
"ode"and"cde"backends."cubic"or"linear". Defaults to"cubic".- ilt_reconstruction_terms : int, optional¶
Specific to
"laplace"backend. Number of ILT reconstruction terms, i.e. the number of complex \(s\) points inlaplace_rep_functo reconstruct a single time point. Defaults to33.- ilt_algorithm : ILTAlgorithm, optional¶
Specific to
"laplace"backend. Inverse Laplace transform algorithm to use. Available are {fourier,dehoog,cme,fixed_tablot,stehfest}. Defaults to"fourier".- lr : float, optional¶
Learning rate for optimizer. Defaults to
1e-3.- weight_decay : float, optional¶
l2 (ridge) penalty for the weights. Defaults to
1e-3.- n_iter : int, optional¶
Maximum number of iterations. Defaults to
1000.- batch_size : int, optional¶
Batch size. Defaults to
500.- n_iter_print : int, optional¶
Number of iterations after which to print updates and check the validation loss. Defaults to
100.- random_state : int, optional¶
Random_state used. Defaults to
0.- patience : int, optional¶
Number of iterations to wait before early stopping after decrease in validation loss. Defaults to
10.- n_iter_min : int, optional¶
Minimum number of iterations to go through before starting early stopping. Defaults to
100.- clipping_value : int, optional¶
Gradients clipping value. Defaults to
1.- train_ratio : float, optional¶
Train/test split ratio. Defaults to
0.8.- device : Any, optional¶
PyTorch device to use. Defaults to
DEVICE.- dataloader_sampler : Optional[sampler.Sampler], optional¶
Custom data sampler for training. Defaults to
None.
- forward(static_data: Tensor, temporal_data: Tensor, observation_times: Tensor) Tensor[source]¶
Forward pass.
- predict(static_data: list | ndarray | Tensor, temporal_data: list | ndarray | Tensor, observation_times: list | ndarray | Tensor) ndarray[source]¶
Make predictions.
- predict_proba(static_data: list | ndarray | Tensor, temporal_data: list | ndarray | Tensor, observation_times: list | ndarray | Tensor) ndarray[source]¶
Predict probabilities.
- score(static_data: list | ndarray | Tensor, temporal_data: list | ndarray | Tensor, observation_times: list | ndarray | Tensor, outcome: list | ndarray) float[source]¶
Compute default score.