class DNN::Models::Sequential
Attributes
stack[R]
Public Class Methods
new(stack = [])
click to toggle source
@param [Array] stack All layers possessed by the model.
Calls superclass method
DNN::Models::Model::new
# File lib/dnn/core/models.rb, line 675 def initialize(stack = []) super() @stack = LayersList.new stack.each do |layer| add(layer) end end
Public Instance Methods
add(layer)
click to toggle source
Add layer to the model. @param [DNN::Layers::Layer | DNN::Models::Chain] layer Layer or Chain
to add to the model. @return [DNN::Models::Model] Return self.
# File lib/dnn/core/models.rb, line 686 def add(layer) if layer.is_a?(Layers::MergeLayer) raise TypeError, "layer: #{layer.class.name} should not be a DNN::Layers::MergeLayer class." end unless layer.is_a?(Layers::Layer) || layer.is_a?(Chain) raise TypeError, "layer: #{layer.class.name} is not an instance of the DNN::Layers::Layer class or DNN::Models::Chain class." end @stack << layer self end
Also aliased as: <<
forward(x)
click to toggle source
# File lib/dnn/core/models.rb, line 720 def forward(x) @stack.each do |layer| x = layer.(x) end x end
insert(index, layer)
click to toggle source
Insert layer to the model by index position. @param [DNN::Layers::Layer | DNN::Models::Chain] layer Layer or Chain
to add to the model. @return [DNN::Models::Model] Return self.
# File lib/dnn/core/models.rb, line 702 def insert(index, layer) if layer.is_a?(Layers::MergeLayer) raise TypeError, "layer: #{layer.class.name} should not be a DNN::Layers::MergeLayer class." end unless layer.is_a?(Layers::Layer) || layer.is_a?(Chain) raise TypeError, "layer: #{layer.class.name} is not an instance of the DNN::Layers::Layer class or DNN::Models::Chain class." end @stack.insert(index, layer) self end
remove(layer)
click to toggle source
Remove layer to the model. @param [DNN::Layers::Layer | DNN::Models::Chain] layer Layer to remove to the model. @return [Boolean] Return true if success for remove layer.
# File lib/dnn/core/models.rb, line 716 def remove(layer) @stack.delete(layer) ? true : false end