Class: RubyZero::Core::Functions::Sigmoid
- Inherits:
-
Function
- Object
- Function
- RubyZero::Core::Functions::Sigmoid
show all
- Defined in:
- lib/rubyzero/core/functions/activations.rb
Instance Attribute Summary
Attributes inherited from Function
#inputs, #output
Instance Method Summary
collapse
Methods inherited from Function
#call, #initialize, #inspect, plot
Instance Method Details
#backward(dy) ⇒ Object
19
20
21
22
|
# File 'lib/rubyzero/core/functions/activations.rb', line 19
def backward(dy)
x = @inputs[0]
return [ F.sigmoid(self.forward(x)) * (x.ones_like - F.sigmoid(self.forward(x))) * dy ]
end
|
#forward(x) ⇒ Object
14
15
16
17
18
|
# File 'lib/rubyzero/core/functions/activations.rb', line 14
def forward(x)
nmath = x.device.caluculator::NMath
data = 1.0 / (1.0 + nmath.exp(-x.data))
return RubyZero::Core::Tensor.new(data)
end
|