Class: CooCoo::LinearLayer

Inherits:
Object show all
Defined in:
lib/coo-coo/linear_layer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size, activation_function = CooCoo::ActivationFunctions::Identity.instance) ⇒ LinearLayer

Returns a new instance of LinearLayer.



12
13
14
15
# File 'lib/coo-coo/linear_layer.rb', line 12

def initialize(size, activation_function = CooCoo::ActivationFunctions::Identity.instance)
  @size = size
  @activation_function = activation_function
end

Instance Attribute Details

#activation_functionObject

Returns the value of attribute activation_function.



9
10
11
# File 'lib/coo-coo/linear_layer.rb', line 9

def activation_function
  @activation_function
end

#sizeObject (readonly)

Returns the value of attribute size.



10
11
12
# File 'lib/coo-coo/linear_layer.rb', line 10

def size
  @size
end

Class Method Details

.from_hash(h, network = nil) ⇒ Object



55
56
57
# File 'lib/coo-coo/linear_layer.rb', line 55

def self.from_hash(h, network = nil)
  new(h[:size], ActivationFunctions.from_name(h[:f]))
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
44
45
46
# File 'lib/coo-coo/linear_layer.rb', line 41

def ==(other)
  other.kind_of?(self.class) &&
    num_inputs == other.num_inputs &&
    size == other.size &&
    activation_function == other.activation_function
end

#adjust_weights!(deltas) ⇒ Object



33
34
35
# File 'lib/coo-coo/linear_layer.rb', line 33

def adjust_weights!(deltas)
  self
end

#backprop(input, output, errors, hidden_state) ⇒ Object



25
26
27
# File 'lib/coo-coo/linear_layer.rb', line 25

def backprop(input, output, errors, hidden_state)
  [ errors * @activation_function.derivative(input, output), hidden_state ]
end

#forward(input, hidden_state) ⇒ Object



21
22
23
# File 'lib/coo-coo/linear_layer.rb', line 21

def forward(input, hidden_state)
  [ @activation_function.call(input), hidden_state ]
end

#num_inputsObject



17
18
19
# File 'lib/coo-coo/linear_layer.rb', line 17

def num_inputs
  size
end

#to_hash(network = nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/coo-coo/linear_layer.rb', line 48

def to_hash(network = nil)
  { type: self.class.name,
    size: size,
    f: @activation_function.name
  }
end

#transfer_error(deltas) ⇒ Object



29
30
31
# File 'lib/coo-coo/linear_layer.rb', line 29

def transfer_error(deltas)
  deltas
end

#weight_deltas(inputs, deltas) ⇒ Object



37
38
39
# File 'lib/coo-coo/linear_layer.rb', line 37

def weight_deltas(inputs, deltas)
  deltas
end