Class: DNN::Layers::Connection
- Inherits:
-
HasParamLayer
- Object
- Layer
- HasParamLayer
- DNN::Layers::Connection
- Defined in:
- lib/dnn/core/layers.rb
Overview
It is a superclass of all connection layers.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bias ⇒ Object
readonly
Returns the value of attribute bias.
-
#bias_initializer ⇒ Object
readonly
Returns the value of attribute bias_initializer.
-
#bias_regularizer ⇒ Object
readonly
Returns the value of attribute bias_regularizer.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
-
#weight_initializer ⇒ Object
readonly
Returns the value of attribute weight_initializer.
-
#weight_regularizer ⇒ Object
readonly
Returns the value of attribute weight_regularizer.
Attributes inherited from HasParamLayer
Attributes inherited from Layer
Instance Method Summary collapse
- #get_params ⇒ Object
-
#initialize(weight_initializer: Initializers::RandomNormal.new, bias_initializer: Initializers::Zeros.new, weight_regularizer: nil, bias_regularizer: nil, use_bias: true) ⇒ Connection
constructor
A new instance of Connection.
- #regularizers ⇒ Object
- #to_hash(merge_hash) ⇒ Object
-
#use_bias ⇒ Boolean
Return whether to use bias.
Methods inherited from Layer
#backward, #build, #built?, #call, call, #forward, #output_shape
Constructor Details
#initialize(weight_initializer: Initializers::RandomNormal.new, bias_initializer: Initializers::Zeros.new, weight_regularizer: nil, bias_regularizer: nil, use_bias: true) ⇒ Connection
Returns a new instance of Connection.
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/dnn/core/layers.rb', line 147 def initialize(weight_initializer: Initializers::RandomNormal.new, bias_initializer: Initializers::Zeros.new, weight_regularizer: nil, bias_regularizer: nil, use_bias: true) super() @weight_initializer = weight_initializer @bias_initializer = bias_initializer @weight_regularizer = weight_regularizer @bias_regularizer = bias_regularizer @weight = Param.new(nil, 0) @bias = use_bias ? Param.new(nil, 0) : nil end |
Instance Attribute Details
#bias ⇒ Object (readonly)
Returns the value of attribute bias.
136 137 138 |
# File 'lib/dnn/core/layers.rb', line 136 def bias @bias end |
#bias_initializer ⇒ Object (readonly)
Returns the value of attribute bias_initializer.
138 139 140 |
# File 'lib/dnn/core/layers.rb', line 138 def bias_initializer @bias_initializer end |
#bias_regularizer ⇒ Object (readonly)
Returns the value of attribute bias_regularizer.
140 141 142 |
# File 'lib/dnn/core/layers.rb', line 140 def bias_regularizer @bias_regularizer end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
135 136 137 |
# File 'lib/dnn/core/layers.rb', line 135 def weight @weight end |
#weight_initializer ⇒ Object (readonly)
Returns the value of attribute weight_initializer.
137 138 139 |
# File 'lib/dnn/core/layers.rb', line 137 def weight_initializer @weight_initializer end |
#weight_regularizer ⇒ Object (readonly)
Returns the value of attribute weight_regularizer.
139 140 141 |
# File 'lib/dnn/core/layers.rb', line 139 def weight_regularizer @weight_regularizer end |
Instance Method Details
#get_params ⇒ Object
181 182 183 |
# File 'lib/dnn/core/layers.rb', line 181 def get_params { weight: @weight, bias: @bias } end |
#regularizers ⇒ Object
161 162 163 164 165 166 |
# File 'lib/dnn/core/layers.rb', line 161 def regularizers regularizers = [] regularizers << @weight_regularizer if @weight_regularizer regularizers << @bias_regularizer if @bias_regularizer regularizers end |
#to_hash(merge_hash) ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/dnn/core/layers.rb', line 173 def to_hash(merge_hash) super({ weight_initializer: @weight_initializer.to_hash, bias_initializer: @bias_initializer.to_hash, weight_regularizer: @weight_regularizer&.to_hash, bias_regularizer: @bias_regularizer&.to_hash, use_bias: use_bias }.merge(merge_hash)) end |
#use_bias ⇒ Boolean
Return whether to use bias.
169 170 171 |
# File 'lib/dnn/core/layers.rb', line 169 def use_bias @bias ? true : false end |