Class: Chainer::Functions::Activation::LeakyReLUGrad

Inherits:
Chainer::FunctionNode show all
Defined in:
lib/chainer/functions/activation/leaky_relu.rb

Instance Attribute Summary

Attributes inherited from Chainer::FunctionNode

#inputs, #outputs, #rank

Instance Method Summary collapse

Methods inherited from Chainer::FunctionNode

#apply, #backward_accumulate, #forward_cpu, #get_retained_inputs, #get_retained_outputs, #label, #output_data, #retain_inputs, #retain_outputs, #unchain

Constructor Details

#initialize(x, y, slope) ⇒ LeakyReLUGrad

Returns a new instance of LeakyReLUGrad.



66
67
68
69
70
# File 'lib/chainer/functions/activation/leaky_relu.rb', line 66

def initialize(x, y, slope)
  @x = x
  @y = y
  @slope = slope
end

Instance Method Details

#backward(indexes, grad_outputs) ⇒ Object



83
84
85
# File 'lib/chainer/functions/activation/leaky_relu.rb', line 83

def backward(indexes, grad_outputs)
  LeakyReLUGrad.new(@x, @y, @slope).apply(grad_outputs)
end

#forward(inputs) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/chainer/functions/activation/leaky_relu.rb', line 72

def forward(inputs)
  gy, = inputs
  gy = gy.dup
  if @slope >= 0
    gy[@y < 0] *= @slope
  else
    gy[@x < 0] *= @slope
  end
  [gy]
end