Class: RubyBrain::Layer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_brain/layer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLayer

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_weightsObject

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_indexObject (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

#nodesObject (readonly)

Returns the value of attribute nodes.



4
5
6
# File 'lib/ruby_brain/layer.rb', line 4

def nodes
  @nodes
end

#output_weightsObject

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_nodeObject



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_nodesObject



19
20
21
# File 'lib/ruby_brain/layer.rb', line 19

def num_nodes
  @nodes.size
end