class CooCoo::Recurrence::Backend
Attributes
recurrence_layer[R]
Public Class Methods
from_hash(h, network)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 84 def self.from_hash(h, network) frontend = network.layers[h.fetch(:recurrence_layer)] raise ArgumentError.new("Frontend not found") unless frontend layer = self.new(frontend, h.fetch(:outputs), h.fetch(:recurrent_size)). update_from_hash!(h) frontend.backend = layer layer end
new(recurrence_layer, outputs, recurrent_outputs)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 11 def initialize(recurrence_layer, outputs, recurrent_outputs) @recurrence_layer = recurrence_layer @outputs = outputs @recurrent_size = recurrent_outputs end
Public Instance Methods
==(other)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 71 def ==(other) other.kind_of?(self.class) && size = other.size && recurrence_layer == other.recurrence_layer && recurrent_size == other.recurrent_size end
activation_function()
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 29 def activation_function nil end
adjust_weights!(deltas)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 55 def adjust_weights!(deltas) self end
backprop(input, output, errors, hidden_state)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 41 def backprop(input, output, errors, hidden_state) layer_state = hidden_state[@recurrence_layer] rec_errors = (layer_state && layer_state.pop) || CooCoo::Vector.zeros(recurrent_size) return errors.append(rec_errors), hidden_state end
forward(inputs, hidden_state)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 33 def forward(inputs, hidden_state) hidden_state ||= Hash.new hidden_state[self] ||= Array.new hidden_state[self].push(inputs[size, recurrent_size]) return inputs[0, size], hidden_state end
num_inputs()
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 17 def num_inputs size + recurrent_size end
recurrent_size()
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 25 def recurrent_size @recurrent_size end
size()
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 21 def size @outputs end
to_hash(network = nil)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 63 def to_hash(network = nil) { type: self.class.name, outputs: @outputs, recurrent_size: @recurrent_size, recurrence_layer: network && network.layer_index(@recurrence_layer) } end
transfer_error(deltas)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 47 def transfer_error(deltas) deltas end
update_from_hash!(h)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 78 def update_from_hash!(h) @outputs = h.fetch(:outputs) @recurrent_size = h.fetch(:recurrent_size) self end
update_weights!(inputs, deltas)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 51 def update_weights!(inputs, deltas) self end
weight_deltas(inputs, deltas)
click to toggle source
# File lib/coo-coo/recurrence/backend.rb, line 59 def weight_deltas(inputs, deltas) inputs * deltas end