Class: Chainer::Functions::Activation::Tanh
- Inherits:
-
Chainer::FunctionNode
- Object
- Chainer::FunctionNode
- Chainer::Functions::Activation::Tanh
- Defined in:
- lib/chainer/functions/activation/tanh.rb
Overview
Hyperbolic tangent function.
Instance Attribute Summary
Attributes inherited from Chainer::FunctionNode
Class Method Summary collapse
-
.tanh(x) ⇒ Chainer::Variable
Elementwise hyperbolic tangent function.
Instance Method Summary collapse
Methods inherited from Chainer::FunctionNode
#apply, #backward_accumulate, #forward_cpu, #get_retained_inputs, #get_retained_outputs, #initialize, #label, #output_data, #retain_inputs, #retain_outputs, #unchain
Constructor Details
This class inherits a constructor from Chainer::FunctionNode
Class Method Details
.tanh(x) ⇒ Chainer::Variable
Elementwise hyperbolic tangent function.
$$ f(x)=\tanh(x). $$
23 24 25 |
# File 'lib/chainer/functions/activation/tanh.rb', line 23 def self.tanh(x) self.new.apply([x]).first end |
Instance Method Details
#backward(indexes, grad_outputs) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chainer/functions/activation/tanh.rb', line 35 def backward(indexes, grad_outputs) if @use_cudnn x = get_retained_inputs.first.data else x = nil end y = get_retained_outputs.first gy = grad_outputs.first TanhGrad.new(x).apply([y, gy]) end |
#forward(x) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/chainer/functions/activation/tanh.rb', line 27 def forward(x) xm = Chainer.get_array_module(x[0]) y = Utils::Array.force_array(xm::NMath.tanh(x[0])) retain_outputs([0]) @use_cudnn = false [y] end |