Skip to content

base

DeepEstimator(module, loss_fn='mse', optimizer_fn='sgd', lr=0.001, device='cpu', seed=42, **kwargs)

Bases: Estimator

Abstract base class that implements basic functionality of River-compatible PyTorch wrappers.

PARAMETER DESCRIPTION
module

Torch Module that builds the autoencoder to be wrapped. The Module should accept parameter n_features so that the returned model's input shape can be determined based on the number of features in the initial training example.

TYPE: Type[Module]

loss_fn

Loss function to be used for training the wrapped model. Can be a loss function provided by torch.nn.functional or one of the following: 'mse', 'l1', 'cross_entropy', 'binary_crossentropy', 'smooth_l1', 'kl_div'.

TYPE: Union[str, Callable] DEFAULT: 'mse'

optimizer_fn

Optimizer to be used for training the wrapped model. Can be an optimizer class provided by torch.optim or one of the following: "adam", "adam_w", "sgd", "rmsprop", "lbfgs".

TYPE: Union[str, Callable] DEFAULT: 'sgd'

lr

Learning rate of the optimizer.

TYPE: float DEFAULT: 0.001

device

Device to run the wrapped model on. Can be "cpu" or "cuda".

TYPE: str DEFAULT: 'cpu'

seed

Random seed to be used for training the wrapped model.

TYPE: int DEFAULT: 42

**kwargs

Parameters to be passed to the Module or the optimizer.

DEFAULT: {}

clone(new_params={}, include_attributes=False)

Clones the estimator.

PARAMETER DESCRIPTION
new_params

New parameters to be passed to the cloned estimator.

TYPE: dict DEFAULT: {}

include_attributes

If True, the attributes of the estimator will be copied to the cloned estimator. This is useful when the estimator is a transformer and the attributes are the learned parameters.

DEFAULT: False

RETURNS DESCRIPTION
DeepEstimator

The cloned estimator.

draw()

Draws the wrapped model.

initialize_module(**kwargs)

PARAMETER DESCRIPTION
module

The instance or class or callable to be initialized, e.g. self.module.

kwargs

The keyword arguments to initialize the instance or class. Can be an empty dict.

TYPE: dict DEFAULT: {}

RETURNS DESCRIPTION
instance

The initialized component.

learn_one(x, y, **kwargs) abstractmethod

Performs one step of training with a single example.

PARAMETER DESCRIPTION
x

Input example.

TYPE: dict

y

Target value.

TYPE: Optional[Any]

RETURNS DESCRIPTION
DeepEstimator

The estimator itself.

RollingDeepEstimator(module, loss_fn='mse', optimizer_fn='sgd', lr=0.001, device='cpu', seed=42, window_size=10, append_predict=False, **kwargs)

Bases: DeepEstimator

Abstract base class that implements basic functionality of River-compatible PyTorch wrappers including a rolling window to allow the model to make predictions based on multiple previous examples.

PARAMETER DESCRIPTION
module

Torch Module that builds the autoencoder to be wrapped. The Module should accept parameter n_features so that the returned model's input shape can be determined based on the number of features in the initial training example.

TYPE: Type[Module]

loss_fn

Loss function to be used for training the wrapped model. Can be a loss function provided by torch.nn.functional or one of the following: 'mse', 'l1', 'cross_entropy', 'binary_crossentropy', 'smooth_l1', 'kl_div'.

TYPE: Union[str, Callable] DEFAULT: 'mse'

optimizer_fn

Optimizer to be used for training the wrapped model. Can be an optimizer class provided by torch.optim or one of the following: "adam", "adam_w", "sgd", "rmsprop", "lbfgs".

TYPE: Union[str, Callable] DEFAULT: 'sgd'

lr

Learning rate of the optimizer.

TYPE: float DEFAULT: 0.001

device

Device to run the wrapped model on. Can be "cpu" or "cuda".

TYPE: str DEFAULT: 'cpu'

seed

Random seed to be used for training the wrapped model.

TYPE: int DEFAULT: 42

window_size

Size of the rolling window used for storing previous examples.

TYPE: int DEFAULT: 10

append_predict

Whether to append inputs passed for prediction to the rolling window.

TYPE: bool DEFAULT: False

**kwargs

Parameters to be passed to the Module or the optimizer.

DEFAULT: {}