class TVAE

class deeptime.decomposition.deep.TVAE(encoder: Module, decoder: Module, optimizer='Adam', learning_rate: float = 0.0005, beta: float = 1.0)

The time-lagged variational autoencoder. For a description of the arguments please see TAE. The one additional argument is beta, which is the KLD-weight during optimization.

See also

TAE, TVAEModel

Attributes

device

The device on which the estimator's PyTorch module(s) are operating.

dtype

The data type under which the estimator operates.

has_model

Property reporting whether this estimator contains an estimated model.

learning_rate

Sets or yields a learning rate.

model

Shortcut to fetch_model().

optimizer

The optimizer that is used.

train_losses

The collected train scores.

validation_losses

The collected validation scores.

Methods

evaluate_loss(x, y)

Evaluates the reconstruction loss and latent regularization loss, returns the sum.

fetch_model()

Yields a new instance of TVAEModel.

fit(data_loader[, n_epochs, validation_loader])

Fits the encoder and decoder based on data.

fit_fetch(data, **kwargs)

Fits the internal model on data and subsequently fetches it in one call.

fit_transform(data[, fit_options, ...])

Fits a model which simultaneously functions as transformer and subsequently transforms the input data.

get_params([deep])

Get the parameters.

set_params(**params)

Set the parameters of this estimator.

setup_optimizer(kind, parameters)

Initializes a new optimizer on a list of parameters.

transform(data, **kwargs)

Transforms data with the encapsulated model.

__call__(*args, **kwargs)

Call self as a function.

evaluate_loss(x: Tensor, y: Tensor)

Evaluates the reconstruction loss and latent regularization loss, returns the sum.

Parameters:
  • x (torch.nn.Tensor) – Input tensor to be passed through the network.

  • y (torch.nn.Tensor) – Tensor which x is compared against.

Returns:

loss – The loss.

Return type:

torch.nn.Tensor

fetch_model() TVAEModel

Yields a new instance of TVAEModel.

Warning

The model can be subject to side-effects in case fit() is called multiple times, as no deep copy is performed of encoder and decoder networks.

Returns:

model – The model.

Return type:

TVAEModel

fit(data_loader: DataLoader, n_epochs: int = 5, validation_loader: Optional[DataLoader] = None, **kwargs)

Fits the encoder and decoder based on data. Note that a call to fit does not reset the weights in the networks that are currently in encoder and decoder.

Parameters:
  • data_loader (DataLoader) – Data loader which yields batches of instantaneous and time-lagged data.

  • n_epochs (int, default=5) – Number of epochs to train for.

  • validation_loader (DataLoader, optional, default=MNone) – Data loader which yields batches of instantaneous and time-lagged data for validation purposes. Can be left None, in which case no validation is performed.

  • **kwargs – Ignored kw.

Returns:

self – Reference to self.

Return type:

TAE

fit_fetch(data, **kwargs)

Fits the internal model on data and subsequently fetches it in one call.

Parameters:
  • data (array_like) – Data that is used to fit the model.

  • **kwargs – Additional arguments to fit().

Returns:

The estimated model.

Return type:

model

fit_transform(data, fit_options=None, transform_options=None)

Fits a model which simultaneously functions as transformer and subsequently transforms the input data. The estimated model can be accessed by calling fetch_model().

Parameters:
  • data (array_like) – The input data.

  • fit_options (dict, optional, default=None) – Optional keyword arguments passed on to the fit method.

  • transform_options (dict, optional, default=None) – Optional keyword arguments passed on to the transform method.

Returns:

output – Transformed data.

Return type:

array_like

get_params(deep=False)

Get the parameters.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

object

setup_optimizer(kind: Union[str, Callable], parameters: List)

Initializes a new optimizer on a list of parameters.

Parameters:
  • kind (str or Callable) – The optimizer.

  • parameters (list of parameters) – The parameters

transform(data, **kwargs)

Transforms data with the encapsulated model.

Parameters:
  • data (array_like) – Input data

  • **kwargs – Optional arguments.

Returns:

output – Transformed data.

Return type:

array_like

property device

The device on which the estimator’s PyTorch module(s) are operating.

property dtype

The data type under which the estimator operates.

Getter:

Gets the currently set data type.

Setter:

Sets a new data type, must be one of np.float32, np.float64

Type:

numpy data type type

property has_model: bool

Property reporting whether this estimator contains an estimated model. This assumes that the model is initialized with None otherwise.

Type:

bool

property learning_rate

Sets or yields a learning rate. Note that setup_optimizer() should be called on update to propagate the changes.

Type:

float

property model

Shortcut to fetch_model().

property optimizer: Optional[Optimizer]

The optimizer that is used.

Getter:

Gets the currently configured optimizer.

Setter:

Sets a new optimizer based on optimizer name (string) or optimizer class (class reference).

Type:

torch.optim.Optimizer

property train_losses: ndarray

The collected train scores. First dimension contains the step, second dimension the score. Initially empty.

Type:

(T, 2) ndarray

property validation_losses: ndarray

The collected validation scores. First dimension contains the step, second dimension the score. Initially empty.

Type:

(T, 2) ndarray