Linear

class torch_rc.nn.Linear(in_features: int, out_features: int)[source]

A linear readout layer that can be used with the torch_rc optimizers.

This layer is mostly identical to PyTorch’s Linear layer, except that this one by default does not require gradients for its parameters.

This layer applies the following linear transformation to the data: \(y = xA^T + b\).

Since the parameters are set up to not require gradients, to tune them you should use one of the gradient-free optimizers from torch_rc.optim, such as the Ridge optimizers.

Parameters
  • in_features – number of features in the input

  • out_features – number of features in the output

Shape
  • Input\((N, *, H_{in})\) where \(*\) means any number of additional dimensions and \(H_{in} = \text{in_features}\)

  • Output\((N, *, H_{out})\) where all but the last dimension are the same shape as the input and \(H_{out} = \text{out_features}\).

Variables
  • weight – the weights of the module of shape \((\text{out_features}, \text{in_features})\). The values are initialized from an empty tensor.

  • bias – the bias of the module of shape \((\text{out_features})\). The values are initialized from an empty tensor.

Examples:

>>> m = torch_rc.nn.Linear(20, 30)
>>> input = torch.randn(128, 20)
>>> output = m(input)
>>> print(output.size())
torch.Size([128, 30])
forward(x)[source]
Parameters

x – tensor of shape (N, *, in_features) where * means any number of additional dimensions.

Returns

tensor of shape (N, *, out_features) where all but the last dimension are the same shape as the input.