Class: Sabina::Layer::BaseLayer
- Inherits:
-
Object
- Object
- Sabina::Layer::BaseLayer
- Defined in:
- lib/sabina/layer/base_layer.rb
Direct Known Subclasses
AEHiddenLayer, AEInputLayer, AEOutputLayer, MPHiddenLayer, MPInputLayer, MPOutputLayer
Instance Attribute Summary collapse
-
#b ⇒ Object
Returns the value of attribute b.
-
#I ⇒ Object
Returns the value of attribute I.
-
#J ⇒ Object
Returns the value of attribute J.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#W ⇒ Object
Returns the value of attribute W.
Instance Method Summary collapse
-
#activate(u_ary) ⇒ Object
An activation function.
-
#activate_(u_ary) ⇒ Object
Differentiation of activation function.
-
#init_weight ⇒ Object
Initialize the weights of this layer.
-
#initialize(size) ⇒ BaseLayer
constructor
A new instance of BaseLayer.
Constructor Details
#initialize(size) ⇒ BaseLayer
Returns a new instance of BaseLayer.
6 7 8 9 10 |
# File 'lib/sabina/layer/base_layer.rb', line 6 def initialize(size) @size = size @f = ->(x){ 1.0 / (1.0 + Math.exp(-x)) } @f_ = ->(x){ @f[x]*(1.0 - @f[x]) } end |
Instance Attribute Details
#b ⇒ Object
Returns the value of attribute b.
4 5 6 |
# File 'lib/sabina/layer/base_layer.rb', line 4 def b @b end |
#I ⇒ Object
Returns the value of attribute I.
4 5 6 |
# File 'lib/sabina/layer/base_layer.rb', line 4 def I @I end |
#J ⇒ Object
Returns the value of attribute J.
4 5 6 |
# File 'lib/sabina/layer/base_layer.rb', line 4 def J @J end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/sabina/layer/base_layer.rb', line 3 def size @size end |
#W ⇒ Object
Returns the value of attribute W.
4 5 6 |
# File 'lib/sabina/layer/base_layer.rb', line 4 def W @W end |
Instance Method Details
#activate(u_ary) ⇒ Object
An activation function
24 25 26 |
# File 'lib/sabina/layer/base_layer.rb', line 24 def activate(u_ary) u_ary.map { |u| @f[u] } end |
#activate_(u_ary) ⇒ Object
Differentiation of activation function
29 30 31 |
# File 'lib/sabina/layer/base_layer.rb', line 29 def activate_(u_ary) u_ary.map { |u| @f_[u] } end |
#init_weight ⇒ Object
Initialize the weights of this layer.
13 14 15 16 17 18 19 20 21 |
# File 'lib/sabina/layer/base_layer.rb', line 13 def init_weight # (J, 1) @b = Matrix.columns([Array.new(@size) { 0.0 }]) # (J, I) @W = Array.new(@J) do Array.new(@I) { Sabina::Utils.box_muller } end.tap { |ary| break Matrix[*ary] } end |