class VAMPNet

class deeptime.decomposition.deep.VAMPNet(lobe: ~torch.nn.modules.module.Module, lobe_timelagged: ~typing.Optional[~torch.nn.modules.module.Module] = None, device=None, optimizer: ~typing.Union[str, ~typing.Callable] = 'Adam', learning_rate: float = 0.0005, score_method: str = 'VAMP2', score_mode: str = 'regularize', epsilon: float = 1e-06, dtype=<class 'numpy.float32'>)

Implementation of VAMPNets. [1] These networks try to find an optimal featurization of data based on a VAMP score [2] by using neural networks as featurizing transforms which are equipped with a loss that is the negative VAMP score. This estimator is also a transformer and can be used to transform data into the optimized space. From there it can either be used to estimate Markov state models via making assignment probabilities crisp (in case of softmax output distributions) or to estimate the Koopman operator using the VAMP estimator.

Parameters:
  • lobe (torch.nn.Module) – A neural network module which maps input data to some (potentially) lower-dimensional space.

  • lobe_timelagged (torch.nn.Module, optional, default=None) – Neural network module for timelagged data, in case of None the lobes are shared (structure and weights).

  • device (torch device, default=None) – The device on which the torch modules are executed.

  • optimizer (str or Callable, default='Adam') – An optimizer which can either be provided in terms of a class reference (like torch.optim.Adam) or a string (like ‘Adam’). Defaults to Adam.

  • learning_rate (float, default=5e-4) – The learning rate of the optimizer.

  • score_method (str, default='VAMP2') – The scoring method which is used for optimization.

  • score_mode (str, default='regularize') – The mode under which inverses of positive semi-definite matrices are estimated. Per default, the matrices are perturbed by a small constant added to the diagonal. This makes sure that eigenvalues are not too small. For a complete list of modes, see sym_inverse().

  • epsilon (float, default=1e-6) – The strength of the regularization under which matrices are inverted. Meaning depends on the score_mode, see sym_inverse().

  • dtype (dtype, default=np.float32) – The data type of the modules and incoming data.

References

Attributes

device

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

dtype

The data type under which the estimator operates.

epsilon

Regularization parameter for matrix inverses.

has_model

Property reporting whether this estimator contains an estimated model.

learning_rate

Sets or yields a learning rate.

lobe

The instantaneous lobe of the VAMPNet.

lobe_timelagged

The timelagged lobe of the VAMPNet.

model

Shortcut to fetch_model().

optimizer

The optimizer that is used.

score_method

Property which steers the scoring behavior of this estimator.

train_scores

The collected train scores.

validation_scores

The collected validation scores.

Methods

fetch_model()

Yields the current model.

fit(data_loader[, n_epochs, ...])

Fits a VampNet 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.

partial_fit(data[, train_score_callback])

Performs a partial fit on data.

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.

validate(validation_data)

Evaluates the currently set lobe(s) on validation data and returns the value of the configured score.

__call__(*args, **kwargs)

Call self as a function.

fetch_model() VAMPNetModel

Yields the current model.

fit(data_loader: DataLoader, n_epochs=1, validation_loader=None, train_score_callback: Optional[Callable[[int, Tensor], None]] = None, validation_score_callback: Optional[Callable[[int, Tensor], None]] = None, progress=None, **kwargs)

Fits a VampNet on data.

Parameters:
  • data_loader (torch.utils.data.DataLoader) – The data to use for training. Should yield a tuple of batches representing instantaneous and time-lagged samples.

  • n_epochs (int, default=1) – The number of epochs (i.e., passes through the training data) to use for training.

  • validation_loader (torch.utils.data.DataLoader, optional, default=None) – Validation data, should also be yielded as a two-element tuple.

  • train_score_callback (callable, optional, default=None) – Callback function which is invoked after each batch and gets as arguments the current training step as well as the score (as torch Tensor).

  • validation_score_callback (callable, optional, default=None) – Callback function for validation data. Is invoked after each epoch if validation data is given and the callback function is not None. Same as the train callback, this gets the ‘step’ as well as the score.

  • progress (context manager, optional, default=None) – Progress bar (eg tqdm), defaults to None.

  • **kwargs – Optional keyword arguments for scikit-learn compatibility

Returns:

self – Reference to self.

Return type:

VAMPNet

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

partial_fit(data, train_score_callback: Optional[Callable[[int, Tensor], None]] = None)

Performs a partial fit on data. This does not perform any batching.

Parameters:
  • data (tuple or list of length 2, containing instantaneous and timelagged data) – The data to train the lobe(s) on.

  • train_score_callback (callable, optional, default=None) – An optional callback function which is evaluated after partial fit, containing the current step of the training (only meaningful during a fit()) and the current score as torch Tensor.

Returns:

self – Reference to self.

Return type:

VAMPNet

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

validate(validation_data: Tuple[Tensor]) Tensor

Evaluates the currently set lobe(s) on validation data and returns the value of the configured score.

Parameters:

validation_data (Tuple of torch Tensor containing instantaneous and timelagged data) – The validation data.

Returns:

score – The value of the score.

Return type:

torch.Tensor

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 epsilon: float

Regularization parameter for matrix inverses.

Getter:

Gets the currently set parameter.

Setter:

Sets a new parameter. Must be non-negative.

Type:

float

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 lobe: Module

The instantaneous lobe of the VAMPNet.

Getter:

Gets the instantaneous lobe.

Setter:

Sets a new lobe.

Type:

torch.nn.Module

property lobe_timelagged: Module

The timelagged lobe of the VAMPNet.

Getter:

Gets the timelagged lobe. Can be the same a the instantaneous lobe.

Setter:

Sets a new lobe. Can be None, in which case the instantaneous lobe is shared.

Type:

torch.nn.Module

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 score_method: str

Property which steers the scoring behavior of this estimator.

Getter:

Gets the current score.

Setter:

Sets the score to use.

Type:

str

property train_scores: ndarray

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

Type:

(T, 2) ndarray

property validation_scores: ndarray

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

Type:

(T, 2) ndarray