class CooCoo::ActivationFunctions::LeakyReLU
Attributes
negative_coeff[RW]
positive_coeff[RW]
Public Class Methods
new(pos = 1.0, neg = 0.0001)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 163 def initialize(pos = 1.0, neg = 0.0001) @positive_coeff = pos.to_f @negative_coeff = neg.to_f end
Public Instance Methods
==(other)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 201 def ==(other) other.kind_of?(self.class) && positive_coeff == other.positive_coeff && negative_coeff == other.negative_coeff end
call(x)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 171 def call(x) pos = x > 0 if pos.kind_of?(FalseClass) x * @negative_coeff elsif pos.kind_of?(TrueClass) x * @positive_coeff else neg = x <= 0 (x * pos * @positive_coeff) + (x * neg * @negative_coeff) end end
derivative(x, y = nil)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 184 def derivative(x, y = nil) y ||= call(x) pos = y > 0 if pos.kind_of?(FalseClass) @negative_coeff elsif pos.kind_of?(TrueClass) @positive_coeff else neg = y <= 0 (pos * @positive_coeff) + (neg * @negative_coeff) end end
initial_weights(num_inputs, size)
click to toggle source
# File lib/coo-coo/activation_functions.rb, line 197 def initial_weights(num_inputs, size) CooCoo::Vector.rand(num_inputs * size) * (2.0 / (num_inputs * size).to_f).sqrt end