Class: Neuronet::ScaledNetwork

Inherits:
FeedForward show all
Defined in:
lib/neuronet/scaled_network.rb

Overview

ScaledNetwork is a subclass of FeedForwardNetwork. It automatically scales the problem given to it by using a Scale type instance set in @distribution. The attribute, @distribution, is set to Neuronet::Gaussian.new by default, but one can change this to Scale, LogNormal, or one’s own custom mapper.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FeedForward

#average_mju, #expected_mju, #expected_mju!, #pair, #pairs, #to_s, #update

Constructor Details

#initialize(layers, distribution: Gaussian.new, reset: false) ⇒ ScaledNetwork

Returns a new instance of ScaledNetwork.



13
14
15
16
17
# File 'lib/neuronet/scaled_network.rb', line 13

def initialize(layers, distribution: Gaussian.new, reset: false)
  super(layers)
  @distribution = distribution
  @reset        = reset
end

Instance Attribute Details

#distributionObject

Returns the value of attribute distribution.



11
12
13
# File 'lib/neuronet/scaled_network.rb', line 11

def distribution
  @distribution
end

#resetObject

Returns the value of attribute reset.



11
12
13
# File 'lib/neuronet/scaled_network.rb', line 11

def reset
  @reset
end

Instance Method Details

#*(_other) ⇒ Object



37
38
39
# File 'lib/neuronet/scaled_network.rb', line 37

def *(_other)
  @distribution.unmapped_output(super)
end

#inputObject



29
30
31
# File 'lib/neuronet/scaled_network.rb', line 29

def input
  @distribution.unmapped_input(super)
end

#inspectObject



45
46
47
48
# File 'lib/neuronet/scaled_network.rb', line 45

def inspect
  distribution = @distribution.class.to_s.split(':').last
  "#distribution:#{distribution} #reset:#{@reset}\n" + super
end

#outputObject



33
34
35
# File 'lib/neuronet/scaled_network.rb', line 33

def output
  @distribution.unmapped_output(super)
end

#set(input) ⇒ Object

ScaledNetwork set works just like FeedForwardNetwork’s set method, but calls @distribution.set(values) first if @reset is true. Sometimes you’ll want to set the distribution with the entire data set, and then there will be times you’ll want to reset the distribution with each input.



24
25
26
27
# File 'lib/neuronet/scaled_network.rb', line 24

def set(input)
  @distribution.reset(input) if @reset
  super(@distribution.mapped_input(input))
end

#train(target, mju = expected_mju) ⇒ Object



41
42
43
# File 'lib/neuronet/scaled_network.rb', line 41

def train(target, mju = expected_mju)
  super(@distribution.mapped_output(target), mju)
end