Class: ML::Learner::PocketLearner
- Inherits:
-
PerceptronLearner
- Object
- PerceptronLearner
- ML::Learner::PocketLearner
- Defined in:
- lib/method/pocket.rb
Overview
Implementation of pocket learning algorithm
Instance Attribute Summary
Attributes included from LinearToolbox
Instance Method Summary collapse
-
#train!(data, iteration = 1000) ⇒ Object
Train with supervised data.
Methods inherited from PerceptronLearner
Methods included from LinearToolbox
Methods included from Toolbox
Constructor Details
This class inherits a constructor from ML::Learner::PerceptronLearner
Instance Method Details
#train!(data, iteration = 1000) ⇒ Object
Train with supervised data
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/method/pocket.rb', line 9 def train! data, iteration = 1000 pool = data.to_a best_error, pocket = 1.0/0, nil iteration.times do # update pocket error = classify_error pool if error < best_error error = best_error pocket = current_vector.dup end break if best_error == 0 # the random order order = (1...(pool.size)).to_a.shuffle for i in order dat, result = pool[i] aug_data = Matrix.column_vector(dat) if wrongly_classify aug_data, result update_vector aug_data, result break end end end end |