Class: Perceptron::Unit
- Inherits:
-
Object
- Object
- Perceptron::Unit
- Defined in:
- lib/perceptron/unit.rb
Instance Attribute Summary collapse
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(features_number, weight = Weight.new(features_number)) ⇒ Unit
constructor
A new instance of Unit.
- #predict(vector) ⇒ Object
- #train(hash) ⇒ Object
Constructor Details
Instance Attribute Details
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
4 5 6 |
# File 'lib/perceptron/unit.rb', line 4 def weight @weight end |
Instance Method Details
#predict(vector) ⇒ Object
10 11 12 |
# File 'lib/perceptron/unit.rb', line 10 def predict(vector) scalar_product(@weight.vector, vector) > 0 ? 1 : 0 end |
#train(hash) ⇒ Object
14 15 16 |
# File 'lib/perceptron/unit.rb', line 14 def train(hash) learn(hash) unless calculate_error(hash).zero? end |