Class: Torch::NN::SelfOrganizedMap::Descent::Monotonic
- Defined in:
- lib/torch/som/descent/monotonic.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #call(step_number = nil) ⇒ Object
-
#initialize(initial:, iterations:) ⇒ Monotonic
constructor
A new instance of Monotonic.
Constructor Details
#initialize(initial:, iterations:) ⇒ Monotonic
Returns a new instance of Monotonic.
8 9 10 11 12 13 14 15 |
# File 'lib/torch/som/descent/monotonic.rb', line 8 def initialize(initial:, iterations:) raise ArgumentError, "Iterations number must be a positive integer" unless iterations.is_a?(Integer) && iterations > 0 @iterations = iterations raise ArgumentError, "Initial value must be a positive integer" unless initial.is_a?(Numeric) && initial > 0 @initial = initial @step_number = 0 end |
Instance Method Details
#call(step_number = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/torch/som/descent/monotonic.rb', line 17 def call(step_number = nil) if step_number raise ArgumentError, "Step number must be an integer >= 0" unless step_number.is_a?(Integer) && step_number >= 0 @step_number = step_number end res = @initial * (1.0 - @step_number.to_f / @iterations) @step_number += 1 if @step_number < @iterations res end |