Module: Nimbus::LossFunctions

Defined in:
lib/nimbus/loss_functions.rb

Class Method Summary collapse

Class Method Details

.average(ids, value_table) ⇒ Object



6
7
8
# File 'lib/nimbus/loss_functions.rb', line 6

def average(ids, value_table)
  ids.inject(0.0){|sum, i| sum + value_table[i]} / ids.size
end

.mean_squared_error(ids, value_table, mean = nil) ⇒ Object



10
11
12
13
# File 'lib/nimbus/loss_functions.rb', line 10

def mean_squared_error(ids, value_table, mean = nil)
  mean ||= self.average ids, value_table
  ids.inject(0.0){|sum, i| sum + ((value_table[i] - mean)**2) }
end

.quadratic_loss(ids, value_table, mean = nil) ⇒ Object



15
16
17
# File 'lib/nimbus/loss_functions.rb', line 15

def quadratic_loss(ids, value_table, mean = nil)
  self.mean_squared_error(ids, value_table, mean) / ids.size
end