RidgeIncrementalRegression

class torch_rc.optim.RidgeIncrementalRegression(params: Iterable, l2_reg: float = 1)[source]

Implements an incremental Ridge regression algorithm.

The input examples and target values can be provided in batches so that it is not needed to hold the whole dataset in memory all at the same time.

Parameters
  • params – iterable of parameters to optimize. Since this algorithm can only be used to train linear layers, the number of parameters should be exactly 2 (one for the weights and one for the biases).

  • l2_reg – regularization strength. Must be a positive floating point number.

fit_apply()[source]

Updates the parameters with the solution of the optimization problem.

fit_step(input, expected)[source]

Provides to the optimizer pairs of inputs and expected outputs.

Note

Calling this method does not update the parameters of your model. Instead, it is updated only an internal state of the optimizer. Whenever you want to update the parameters of the model, call the fit_apply() method. In general, you will call fit_step() multiple times before finally calling fit_apply().

Parameters
  • input – input tensor of shape (batch, n_features)

  • expected – target tensor of shape (batch, n_targets)