Class: BinaryDecisionTree::Node
- Inherits:
-
Object
- Object
- BinaryDecisionTree::Node
- Defined in:
- lib/binary_decision_tree/node.rb
Instance Attribute Summary collapse
-
#decision ⇒ Object
nil, 0, or 1.
-
#slot ⇒ Object
readonly
bit position.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
-
#initialize(tree, slot, decision: nil) ⇒ Node
constructor
A new instance of Node.
- #leaf? ⇒ Boolean
- #left ⇒ Object
- #left_position ⇒ Object
- #right ⇒ Object
- #right_position ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(tree, slot, decision: nil) ⇒ Node
Returns a new instance of Node.
7 8 9 10 11 |
# File 'lib/binary_decision_tree/node.rb', line 7 def initialize(tree, slot, decision: nil) @tree = tree @slot = slot @decision = decision end |
Instance Attribute Details
#decision ⇒ Object
nil, 0, or 1
2 3 4 |
# File 'lib/binary_decision_tree/node.rb', line 2 def decision @decision end |
#slot ⇒ Object (readonly)
bit position
4 5 6 |
# File 'lib/binary_decision_tree/node.rb', line 4 def slot @slot end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
5 6 7 |
# File 'lib/binary_decision_tree/node.rb', line 5 def tree @tree end |
Instance Method Details
#leaf? ⇒ Boolean
24 25 26 |
# File 'lib/binary_decision_tree/node.rb', line 24 def leaf? left.nil? && right.nil? end |
#left ⇒ Object
36 37 38 |
# File 'lib/binary_decision_tree/node.rb', line 36 def left tree.at(left_position) end |
#left_position ⇒ Object
28 29 30 |
# File 'lib/binary_decision_tree/node.rb', line 28 def left_position slot * 2 end |
#right ⇒ Object
40 41 42 |
# File 'lib/binary_decision_tree/node.rb', line 40 def right tree.at(right_position) end |
#right_position ⇒ Object
32 33 34 |
# File 'lib/binary_decision_tree/node.rb', line 32 def right_position left_position + 1 end |
#value ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/binary_decision_tree/node.rb', line 13 def value case decision when 0 left.nil? ? left_position : left.value when 1 right.nil? ? right_position : right.value else nil end end |