class TAE

class deeptime.decomposition.deep.TAE(encoder: Module, decoder: Module, optimizer='Adam', learning_rate=0.0003, device='cpu')

Time-lagged autoencoder. [1]

Parameters:
  • encoder (torch.nn.Module) – Encoder module.

  • decoder (torch.nn.Module) – Decoder module, its input features should be compatible with the encoder’s output features.

  • optimizer (str or callable, default='Adam') – The optimizer to use, defaults to Adam. If given as string, can be one of ‘Adam’, ‘SGD’, ‘RMSProp’. In case of a callable, the callable should take a params parameter list and a lr learning rate, yielding an optimizer instance based on that.

  • learning_rate (float, default=3e-4) – The learning rate that is used for the optimizer. Defaults to the Karpathy learning rate.

References

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 loss based on input tensors.

fetch_model()

Yields a new instance of TAEModel.

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 loss based on input tensors.

Parameters:
  • x (torch.Tensor) – The tensor that is passed through encoder and decoder networks.

  • y (torch.Tensor) – The tensor the forward pass is compared against.

Returns:

loss – The loss.

Return type:

torch.Tensor

fetch_model() TAEModel

Yields a new instance of TAEModel.

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:

TAEModel

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