Class: BinaryDecisionTree::Tree
- Inherits:
-
Object
- Object
- BinaryDecisionTree::Tree
- Defined in:
- lib/binary_decision_tree/tree.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
Instance Method Summary collapse
- #at(position) ⇒ Object
-
#initialize(depth) ⇒ Tree
constructor
A new instance of Tree.
- #root ⇒ Object
Constructor Details
#initialize(depth) ⇒ Tree
Returns a new instance of Tree.
4 5 6 7 |
# File 'lib/binary_decision_tree/tree.rb', line 4 def initialize(depth) @depth = depth @nodes = Array.new(2**depth) {|i| i == 0 ? nil : Node.new(self, i)} end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
2 3 4 |
# File 'lib/binary_decision_tree/tree.rb', line 2 def depth @depth end |
Instance Method Details
#at(position) ⇒ Object
13 14 15 |
# File 'lib/binary_decision_tree/tree.rb', line 13 def at(position) @nodes[position] end |
#root ⇒ Object
9 10 11 |
# File 'lib/binary_decision_tree/tree.rb', line 9 def root @nodes[1] end |