Class: RNN

Inherits:
NN
  • Object
show all
Defined in:
lib/neuroevo/nn.rb

Instance Attribute Summary

Attributes inherited from NN

#act_fn, #layers, #state, #struct

Instance Method Summary collapse

Methods inherited from NN

act_fn, #activate, #bias, #deep_reset, #init_random, #initialize, #layer_col_sizes, #layer_shapes, lecun_hyperbolic, #load_weights, logistic, #nlayers, #nneurs, #nweights, #nweights_per_layer, #out, #reset_state, sigmoid, #sym, #weights

Constructor Details

This class inherits a constructor from NN

Instance Method Details

#activate_layer(nlay) ⇒ Object

_layer


200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/neuroevo/nn.rb', line 200

def activate_layer nlay #_layer
  # NOTE: current layer index corresponds to index of next state!
  previous = nlay     # index of previous layer (inputs)
  current = nlay + 1  # index of current layer (outputs)
  # Copy the level's last-time activation to the input (previous state)
  # NOTE: ranges in NMatrix#[] not reliable! gotta loop :(
  nneurs(current).times do |i| # for each activations to copy
    # Copy output from last-time activation to recurrency in previous state
    @state[previous][0, nneurs(previous) + i] = state[current][0, i]
  end
  act_fn.call( state[previous].dot layers[nlay] )
end

#layer_row_sizesObject

Recurrent Neural Network


191
192
193
194
195
196
197
198
# File 'lib/neuroevo/nn.rb', line 191

def layer_row_sizes
  # each row holds the inputs for the next level: previous level's
  # activations (or inputs), this level's last activations
  # (recursion) and bias
  @layer_row_sizes ||= struct.each_cons(2).collect do |prev, rec|
    prev + rec +1
  end
end