Class: Daimond::NN::Linear
Instance Attribute Summary collapse
-
#bias ⇒ Object
readonly
Returns the value of attribute bias.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #forward(input) ⇒ Object
-
#initialize(in_features, out_features) ⇒ Linear
constructor
A new instance of Linear.
Methods inherited from Module
#call, #load, #parameters, #save, #zero_grad
Constructor Details
#initialize(in_features, out_features) ⇒ Linear
Returns a new instance of Linear.
6 7 8 9 10 11 12 |
# File 'lib/daimond/nn/linear.rb', line 6 def initialize(in_features, out_features) super() # Простая инициализация: small random values @weight = Tensor.new(Numo::DFloat.new(in_features, out_features).rand_norm * 0.01) @bias = Tensor.zeros(out_features) @parameters = [@weight, @bias] end |
Instance Attribute Details
#bias ⇒ Object (readonly)
Returns the value of attribute bias.
19 20 21 |
# File 'lib/daimond/nn/linear.rb', line 19 def bias @bias end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
19 20 21 |
# File 'lib/daimond/nn/linear.rb', line 19 def weight @weight end |
Instance Method Details
#forward(input) ⇒ Object
14 15 16 17 |
# File 'lib/daimond/nn/linear.rb', line 14 def forward(input) # Теперь возвращаем Tensor с поддержкой autograd! input.dot(@weight) + @bias end |