compute_ridge_matrices#
- torchdyno.optim.ridge_regression.compute_ridge_matrices(loader, preprocess_fn=None, weights=None, skip_first_n=0, device=None)[source]#
Computes the matrices A and B for incremental ridge regression. For each batch in the loader, it applies the preprocess_fn on the x sample, resizes it to (n_samples, hidden_size), and computes the values of A and B.
- Parameters:
loader (DataLoader) – torch loader
preprocess_fn (Optional[Callable], optional) – function to be applied to the x sample before computing the matrices. Defaults to None.
weights (Optional[List[float]], optional) – list of weights to be applied to each sample in the batch. 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:
- the matrices A of shape
[label_size x hidden_size] and B of shape [hidden_size x hidden_size].
- Return type:
Tuple[Tensor, Tensor]