Class: Neuronet::Scale
- Inherits:
-
Object
- Object
- Neuronet::Scale
- Defined in:
- lib/neuronet.rb
Overview
Scales the problem
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
A new instance of Scale.
- #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
Returns a new instance of Scale.
230 231 232 233 234 |
# File 'lib/neuronet.rb', line 230 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.
227 228 229 |
# File 'lib/neuronet.rb', line 227 def center @center end |
#init=(value) ⇒ Object (writeonly)
Sets the attribute init
228 229 230 |
# File 'lib/neuronet.rb', line 228 def init=(value) @init = value end |
#spread ⇒ Object
Returns the value of attribute spread.
227 228 229 |
# File 'lib/neuronet.rb', line 227 def spread @spread end |
Instance Method Details
#mapped(inputs) ⇒ Object Also known as: mapped_input, mapped_output
258 259 260 261 |
# File 'lib/neuronet.rb', line 258 def mapped(inputs) factor = 1.0 / (@factor*@spread) inputs.map{|value| factor*(value - @center)} end |
#set(inputs) ⇒ Object
252 253 254 255 256 |
# File 'lib/neuronet.rb', line 252 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.
248 249 250 |
# File 'lib/neuronet.rb', line 248 def set_center(inputs) @center = (@max + @min) / 2.0 end |
#set_init(inputs) ⇒ Object
236 237 238 |
# File 'lib/neuronet.rb', line 236 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.
242 243 244 |
# File 'lib/neuronet.rb', line 242 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.
267 268 269 270 |
# File 'lib/neuronet.rb', line 267 def unmapped(outputs) factor = @factor*@spread outputs.map{|value| factor*value + @center} end |