Class: MachineLearningWorkbench::Compressor::DecayingLearningRateVQ
- Inherits:
-
VectorQuantization
- Object
- VectorQuantization
- MachineLearningWorkbench::Compressor::DecayingLearningRateVQ
- Defined in:
- lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb
Overview
VQ with per-centroid decaying learning rates. Optimized for online training.
Constant Summary
Constants inherited from VectorQuantization
Instance Attribute Summary collapse
-
#decay_rate ⇒ Object
readonly
Returns the value of attribute decay_rate.
-
#lrate_min ⇒ Object
readonly
Returns the value of attribute lrate_min.
-
#lrate_min_den ⇒ Object
readonly
Returns the value of attribute lrate_min_den.
Attributes inherited from VectorQuantization
#centrs, #dims, #encoding_type, #init_centr_vrange, #ncentrs, #ncodes, #ntrains, #rng, #simil_type, #utility, #vrange
Instance Method Summary collapse
-
#check_lrate(lrate) ⇒ Object
Overloading lrate check from original VQ.
-
#initialize(**opts) ⇒ DecayingLearningRateVQ
constructor
A new instance of DecayingLearningRateVQ.
-
#lrate(centr_idx, min_den: lrate_min_den, lower_bound: lrate_min, decay: decay_rate) ⇒ Object
Decaying per-centroid learning rate.
-
#train_one(vec) ⇒ Integer
Train on one vector.
Methods inherited from VectorQuantization
#encode, #init_centrs, #most_similar_centr, #new_centr, #reconstr_error, #reconstruction, #similarities, #train
Constructor Details
#initialize(**opts) ⇒ DecayingLearningRateVQ
Returns a new instance of DecayingLearningRateVQ.
8 9 10 11 12 13 14 |
# File 'lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb', line 8 def initialize **opts puts "Ignoring learning rate: `lrate: #{opts[:lrate]}`" if opts[:lrate] @lrate_min = opts.delete(:lrate_min) || 0.001 @lrate_min_den = opts.delete(:lrate_min_den) || 1 @decay_rate = opts.delete(:decay_rate) || 1 super **opts.merge({lrate: nil}) end |
Instance Attribute Details
#decay_rate ⇒ Object (readonly)
Returns the value of attribute decay_rate.
6 7 8 |
# File 'lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb', line 6 def decay_rate @decay_rate end |
#lrate_min ⇒ Object (readonly)
Returns the value of attribute lrate_min.
6 7 8 |
# File 'lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb', line 6 def lrate_min @lrate_min end |
#lrate_min_den ⇒ Object (readonly)
Returns the value of attribute lrate_min_den.
6 7 8 |
# File 'lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb', line 6 def lrate_min_den @lrate_min_den end |
Instance Method Details
#check_lrate(lrate) ⇒ Object
Overloading lrate check from original VQ
17 |
# File 'lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb', line 17 def check_lrate lrate; nil; end |
#lrate(centr_idx, min_den: lrate_min_den, lower_bound: lrate_min, decay: decay_rate) ⇒ Object
nicely overloads the ‘attr_reader` of parent class
Decaying per-centroid learning rate.
23 24 25 26 |
# File 'lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb', line 23 def lrate centr_idx, min_den: lrate_min_den, lower_bound: lrate_min, decay: decay_rate [1.0/(ntrains[centr_idx]*decay+min_den), lower_bound].max .tap { |l| puts "centr: #{centr_idx}, ntrains: #{ntrains[centr_idx]}, lrate: #{l}" } end |
#train_one(vec) ⇒ Integer
Train on one vector
30 31 32 33 34 |
# File 'lib/machine_learning_workbench/compressor/decaying_learning_rate_vq.rb', line 30 def train_one vec trg_idx, _simil = most_similar_centr(vec) centrs[trg_idx] = centrs[trg_idx] * (1-lrate(trg_idx)) + vec * lrate(trg_idx) trg_idx end |