fit_and_validate_readout#

torchdyno.optim.ridge_regression.fit_and_validate_readout(train_loader, eval_loader, l2_values, score_fn, mode, weights=None, preprocess_fn=None, skip_first_n=0, device=None)[source]#

Applies the ridge regression on the training data with all the given l2 values, and returns the best configuration after evaluating the linear transformations on the validation data.

Parameters:
  • train_loader (DataLoader) – DataLoader of the training data.

  • eval_loader (DataLoader) – DataLoader of the validation data.

  • l2_values (List[float]) – List of all the candidate L2 values.

  • score_fn (Callable[[Tensor, Tensor], float]) – a Callable which, if applied to the predicted y_pred and the ground-truth y_true, returns the desired metric.

  • mode (Literal['min', 'max']) – whether the best result is the minimum or the maximum given the metric.

  • weights (Optional[List[float]], optional) – list of weights to be applied to each sample in the batch. Defaults to None.

  • preprocess_fn (Optional[Callable], optional) – a transformation to be applied to X before the linear transformation. Useful whenever this function is called to learn a Readout of a ESN. Defaults to None.

  • skip_first_n (Optional[int], optional) – number of samples to skip in each batch of the train_loader. Defaults to None.

  • device (Optional[str], optional) – the device on which the function is executed. If None, the function is executed on a CUDA device if available, on CPU otherwise. Defaults to None.

Returns:

a Tuple containing the best linear

transformation, the corrisponding l2 value, metric value, ridge matrice B and ridge matrix B.

Return type:

Tuple[Tensor, float, float, Tensor, Tensor]