Class: BinaryDecisionTree::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/binary_decision_tree/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth, node_class: Node) ⇒ Tree

Returns a new instance of Tree.



5
6
7
8
# File 'lib/binary_decision_tree/tree.rb', line 5

def initialize(depth, node_class: Node)
  @depth = depth
  @nodes = Array.new(size) {|i| i == 0 ? nil : node_class.new(self, i)}
end

Instance Attribute Details

#depthObject (readonly)

Returns the value of attribute depth.



3
4
5
# File 'lib/binary_decision_tree/tree.rb', line 3

def depth
  @depth
end

Instance Method Details

#at(position) ⇒ Object



14
15
16
# File 'lib/binary_decision_tree/tree.rb', line 14

def at(position)
  @nodes[position]
end

#rootObject



10
11
12
# File 'lib/binary_decision_tree/tree.rb', line 10

def root
  @nodes[1]
end

#sizeObject



18
19
20
# File 'lib/binary_decision_tree/tree.rb', line 18

def size
  2**depth
end