Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nn_linear

Linear module


Description

Applies a linear transformation to the incoming data: y = xA^T + b

Usage

nn_linear(in_features, out_features, bias = TRUE)

Arguments

in_features

size of each input sample

out_features

size of each output sample

bias

If set to FALSE, the layer will not learn an additive bias. Default: TRUE

Shape

  • Input: (N, *, H_in) where * means any number of additional dimensions and H_in = in_features.

  • Output: (N, *, H_out) where all but the last dimension are the same shape as the input and :math:H_out = out_features.

Attributes

  • weight: the learnable weights of the module of shape (out_features, in_features). The values are initialized from U(-√{k}, √{k})s, where k = \frac{1}{\mbox{in\_features}}

  • bias: the learnable bias of the module of shape (\mbox{out\_features}). If bias is TRUE, the values are initialized from \mathcal{U}(-√{k}, √{k}) where k = \frac{1}{\mbox{in\_features}}

Examples

if (torch_is_installed()) {
m <- nn_linear(20, 30)
input <- torch_randn(128, 20)
output <- m(input)
print(output$size())

}

torch

Tensors and Neural Networks with 'GPU' Acceleration

v0.3.0
MIT + file LICENSE
Authors
Daniel Falbel [aut, cre, cph], Javier Luraschi [aut], Dmitriy Selivanov [ctb], Athos Damiani [ctb], Christophe Regouby [ctb], Krzysztof Joachimiak [ctb], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.