Class: DNN::Layers::Connection
- Inherits:
-
TrainableLayer
- Object
- Layer
- TrainableLayer
- DNN::Layers::Connection
- Defined in:
- lib/dnn/core/layers/basic_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 TrainableLayer
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 TrainableLayer
Methods inherited from Layer
#build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash, #load_hash
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.
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 194 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, Xumo::SFloat[0]) @bias = use_bias ? Param.new(nil, Xumo::SFloat[0]) : nil end |
Instance Attribute Details
#bias ⇒ Object (readonly)
Returns the value of attribute bias.
183 184 185 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 183 def bias @bias end |
#bias_initializer ⇒ Object (readonly)
Returns the value of attribute bias_initializer.
185 186 187 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 185 def bias_initializer @bias_initializer end |
#bias_regularizer ⇒ Object (readonly)
Returns the value of attribute bias_regularizer.
187 188 189 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 187 def bias_regularizer @bias_regularizer end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
182 183 184 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 182 def weight @weight end |
#weight_initializer ⇒ Object (readonly)
Returns the value of attribute weight_initializer.
184 185 186 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 184 def weight_initializer @weight_initializer end |
#weight_regularizer ⇒ Object (readonly)
Returns the value of attribute weight_regularizer.
186 187 188 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 186 def weight_regularizer @weight_regularizer end |
Instance Method Details
#get_params ⇒ Object
228 229 230 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 228 def get_params { weight: @weight, bias: @bias } end |
#regularizers ⇒ Object
208 209 210 211 212 213 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 208 def regularizers regularizers = [] regularizers << @weight_regularizer if @weight_regularizer regularizers << @bias_regularizer if @bias_regularizer regularizers end |
#to_hash(merge_hash) ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 220 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.
216 217 218 |
# File 'lib/dnn/core/layers/basic_layers.rb', line 216 def use_bias @bias ? true : false end |