class CooCoo::ActivationFunctions::ReLU

Public Instance Methods

call(x) click to toggle source
# File lib/coo-coo/activation_functions.rb, line 131
def call(x)
  t = x > 0
  if t.kind_of?(FalseClass)
    0.0
  elsif t.kind_of?(TrueClass)
    x
  else
    x * t
  end
end
derivative(x, y = nil) click to toggle source
# File lib/coo-coo/activation_functions.rb, line 142
def derivative(x, y = nil)
  y ||= call(x)
  t = y > 0
  if t.kind_of?(FalseClass)
    0.0
  elsif t.kind_of?(TrueClass)
    1.0
  else
    t
  end
end
initial_weights(num_inputs, size) click to toggle source
# File lib/coo-coo/activation_functions.rb, line 154
def initial_weights(num_inputs, size)
  CooCoo::Vector.rand(num_inputs * size) * (2.0 / (num_inputs * size).to_f).sqrt
end