Class: RubyBrain::Layer
- Inherits:
-
Object
- Object
- RubyBrain::Layer
- Defined in:
- lib/ruby_brain/layer.rb
Instance Attribute Summary collapse
-
#input_weights ⇒ Object
Returns the value of attribute input_weights.
-
#next_node_order_index ⇒ Object
readonly
Returns the value of attribute next_node_order_index.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#output_weights ⇒ Object
Returns the value of attribute output_weights.
Instance Method Summary collapse
- #append(node) ⇒ Object
- #backward_outputs(inputs) ⇒ Object
- #each_node ⇒ Object
- #forward_outputs(inputs = []) ⇒ Object
-
#initialize ⇒ Layer
constructor
A new instance of Layer.
- #num_nodes ⇒ Object
Constructor Details
#initialize ⇒ Layer
Returns a new instance of Layer.
6 7 8 9 |
# File 'lib/ruby_brain/layer.rb', line 6 def initialize @nodes = [] @next_node_order_index = 0 end |
Instance Attribute Details
#input_weights ⇒ Object
Returns the value of attribute input_weights.
3 4 5 |
# File 'lib/ruby_brain/layer.rb', line 3 def input_weights @input_weights end |
#next_node_order_index ⇒ Object (readonly)
Returns the value of attribute next_node_order_index.
4 5 6 |
# File 'lib/ruby_brain/layer.rb', line 4 def next_node_order_index @next_node_order_index end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
4 5 6 |
# File 'lib/ruby_brain/layer.rb', line 4 def nodes @nodes end |
#output_weights ⇒ Object
Returns the value of attribute output_weights.
3 4 5 |
# File 'lib/ruby_brain/layer.rb', line 3 def output_weights @output_weights end |
Instance Method Details
#append(node) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ruby_brain/layer.rb', line 11 def append(node) node.order_index = @next_node_order_index node.left_side_weights = @input_weights node.right_side_weights = @output_weights @nodes << node @next_node_order_index += 1 end |
#backward_outputs(inputs) ⇒ Object
33 34 35 |
# File 'lib/ruby_brain/layer.rb', line 33 def backward_outputs(inputs) @nodes.map { |node| node.output_of_backward_calc(inputs) }.compact end |
#each_node ⇒ Object
23 24 25 26 27 |
# File 'lib/ruby_brain/layer.rb', line 23 def each_node @nodes.each do |node| yield node end end |
#forward_outputs(inputs = []) ⇒ Object
29 30 31 |
# File 'lib/ruby_brain/layer.rb', line 29 def forward_outputs(inputs=[]) @nodes.map { |node| node.output_of_forward_calc(inputs) } end |
#num_nodes ⇒ Object
19 20 21 |
# File 'lib/ruby_brain/layer.rb', line 19 def num_nodes @nodes.size end |