Class: AdaBoost::WeakClassifier
- Inherits:
-
Object
- Object
- AdaBoost::WeakClassifier
- Defined in:
- lib/adaboost/weak_classifier.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#error ⇒ Object
Returns the value of attribute error.
-
#feature_number ⇒ Object
readonly
Returns the value of attribute feature_number.
-
#split ⇒ Object
readonly
Returns the value of attribute split.
Instance Method Summary collapse
- #classify(sample) ⇒ Object
- #classify_with_alpha(sample) ⇒ Object
- #compute_alpha ⇒ Object
- #increase_error(amount) ⇒ Object
-
#initialize(feature_number, split, alpha = 0.0, error = 0.0) ⇒ WeakClassifier
constructor
A new instance of WeakClassifier.
Constructor Details
#initialize(feature_number, split, alpha = 0.0, error = 0.0) ⇒ WeakClassifier
Returns a new instance of WeakClassifier.
8 9 10 11 12 13 |
# File 'lib/adaboost/weak_classifier.rb', line 8 def initialize(feature_number, split, alpha = 0.0, error = 0.0) @feature_number = feature_number @split = split @error = error @alpha = alpha end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
6 7 8 |
# File 'lib/adaboost/weak_classifier.rb', line 6 def alpha @alpha end |
#error ⇒ Object
Returns the value of attribute error.
5 6 7 |
# File 'lib/adaboost/weak_classifier.rb', line 5 def error @error end |
#feature_number ⇒ Object (readonly)
Returns the value of attribute feature_number.
6 7 8 |
# File 'lib/adaboost/weak_classifier.rb', line 6 def feature_number @feature_number end |
#split ⇒ Object (readonly)
Returns the value of attribute split.
6 7 8 |
# File 'lib/adaboost/weak_classifier.rb', line 6 def split @split end |
Instance Method Details
#classify(sample) ⇒ Object
19 20 21 |
# File 'lib/adaboost/weak_classifier.rb', line 19 def classify(sample) sample[@feature_number] > @split ? 1 : -1 end |
#classify_with_alpha(sample) ⇒ Object
23 24 25 |
# File 'lib/adaboost/weak_classifier.rb', line 23 def classify_with_alpha(sample) return classify(sample) * @alpha end |
#compute_alpha ⇒ Object
15 16 17 |
# File 'lib/adaboost/weak_classifier.rb', line 15 def compute_alpha @alpha = 0.5 * Math.log((1.0 - @error) / @error) end |
#increase_error(amount) ⇒ Object
27 28 29 |
# File 'lib/adaboost/weak_classifier.rb', line 27 def increase_error(amount) @error += amount end |