Class: Neuronet::Scale
- Inherits:
-
Object
- Object
- Neuronet::Scale
- Defined in:
- lib/neuronet.rb
Overview
Neuronet::Scale is a class to help scale problems to fit within a network’s “field of view”. Given a list of values, it finds the minimum and maximum values and establishes a mapping to a scaled set of numbers between minus one and one (-1,1).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#center ⇒ Object
Returns the value of attribute center.
-
#init ⇒ Object
writeonly
Sets the attribute init.
-
#spread ⇒ Object
Returns the value of attribute spread.
Instance Method Summary collapse
-
#initialize(factor = 1.0, center = nil, spread = nil) ⇒ Scale
constructor
If the value of center is provided, then that value will be used instead of calculating it from the values passed to method set.
- #mapped(inputs) ⇒ Object (also: #mapped_input, #mapped_output)
- #set(inputs) ⇒ Object
-
#set_center(inputs) ⇒ Object
In this case, inputs is unused, but it’s there for the general case.
- #set_init(inputs) ⇒ Object
-
#set_spread(inputs) ⇒ Object
In this case, inputs is unused, but it’s there for the general case.
-
#unmapped(outputs) ⇒ Object
(also: #unmapped_input, #unmapped_output)
Note that it could also unmap inputs, but outputs is typically what’s being transformed back.
Constructor Details
#initialize(factor = 1.0, center = nil, spread = nil) ⇒ Scale
If the value of center is provided, then that value will be used instead of calculating it from the values passed to method set. Likewise, if spread is provided, that value of spread will be used. The attribute @init flags if there is a initiation phase to the calculation of @spread and @center. For Scale, @init is true and the initiation phase calculates the intermediate values @min and @max (the minimum and maximum values in the data set). It’s possible for subclasses of Scale, such as Gaussian, to not have this initiation phase.
329 330 331 332 333 |
# File 'lib/neuronet.rb', line 329 def initialize(factor=1.0,center=nil,spread=nil) @factor,@center,@spread = factor,center,spread @centered, @spreaded = center.nil?, spread.nil? @init = true end |
Instance Attribute Details
#center ⇒ Object
Returns the value of attribute center.
317 318 319 |
# File 'lib/neuronet.rb', line 317 def center @center end |
#init=(value) ⇒ Object (writeonly)
Sets the attribute init
318 319 320 |
# File 'lib/neuronet.rb', line 318 def init=(value) @init = value end |
#spread ⇒ Object
Returns the value of attribute spread.
317 318 319 |
# File 'lib/neuronet.rb', line 317 def spread @spread end |
Instance Method Details
#mapped(inputs) ⇒ Object Also known as: mapped_input, mapped_output
357 358 359 360 |
# File 'lib/neuronet.rb', line 357 def mapped(inputs) factor = 1.0 / (@factor*@spread) inputs.map{|value| factor*(value - @center)} end |
#set(inputs) ⇒ Object
351 352 353 354 355 |
# File 'lib/neuronet.rb', line 351 def set(inputs) set_init(inputs) if @init set_center(inputs) if @centered set_spread(inputs) if @spreaded end |
#set_center(inputs) ⇒ Object
In this case, inputs is unused, but it’s there for the general case.
347 348 349 |
# File 'lib/neuronet.rb', line 347 def set_center(inputs) @center = (@max + @min) / 2.0 end |
#set_init(inputs) ⇒ Object
335 336 337 |
# File 'lib/neuronet.rb', line 335 def set_init(inputs) @min, @max = inputs.minmax end |
#set_spread(inputs) ⇒ Object
In this case, inputs is unused, but it’s there for the general case.
341 342 343 |
# File 'lib/neuronet.rb', line 341 def set_spread(inputs) @spread = (@max - @min) / 2.0 end |
#unmapped(outputs) ⇒ Object Also known as: unmapped_input, unmapped_output
Note that it could also unmap inputs, but outputs is typically what’s being transformed back.
366 367 368 369 |
# File 'lib/neuronet.rb', line 366 def unmapped(outputs) factor = @factor*@spread outputs.map{|value| factor*value + @center} end |