Class: Neuro::Display::NetworkDrawer
- Inherits:
-
Object
- Object
- Neuro::Display::NetworkDrawer
- Includes:
- Draw
- Defined in:
- lib/neuro/display.rb
Constant Summary
Constants included from Draw
Draw::HEIGHT, Draw::LAYERS, Draw::WIDTH, Draw::XGAP, Draw::YGAP
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #draw(input, output) ⇒ Object
-
#initialize(root, network) ⇒ NetworkDrawer
constructor
A new instance of NetworkDrawer.
Methods included from Draw
Constructor Details
#initialize(root, network) ⇒ NetworkDrawer
Returns a new instance of NetworkDrawer.
204 205 206 207 |
# File 'lib/neuro/display.rb', line 204 def initialize(root, network) @root, @network = root, network @width, @height = 800, 600 end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
209 210 211 |
# File 'lib/neuro/display.rb', line 209 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
209 210 211 |
# File 'lib/neuro/display.rb', line 209 def width @width end |
Instance Method Details
#draw(input, output) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/neuro/display.rb', line 211 def draw(input, output) nh = @network.to_h layers = [ :input_layer, :hidden_layer, :output_layer ] sizes = [ :input_size, :hidden_size, :output_size ].map { |x| nh[x] } max = sizes.max offsets = {} layers.zip(sizes) do |layer, size| offsets[layer] = (max - size) / 2.0 end layers.zip(sizes) do |layer, size| size.times do |i| Edges.new(@root, nh, layer, i, offsets) end end max_position = -1 layers.zip(sizes) do |layer, size| size.times do |i| node = Node.new(@root, nh, layer, i, offsets) max_position = [ max_position, node.position[1] ].max end end @height = max_position + YGAP * 2 input.each_with_index do |iv, i| Input.new(@root, iv, i, offsets) end output.each_with_index do |ov, i| Output.new(@root, ov, i, offsets) end self end |