class TreeThinking::BinaryTree
Constants
- Node
Attributes
name[R]
tree[RW]
Public Class Methods
new(name: nil)
click to toggle source
# File lib/tree_thinking/binary_tree.rb, line 8 def initialize(name: nil) @name = name end
Public Instance Methods
call(answer_vector)
click to toggle source
# File lib/tree_thinking/binary_tree.rb, line 12 def call(answer_vector) node = self.tree while node.probablity.nil? do node = node.results.fetch(decision(node, answer_vector)) end node.probablity end
Private Instance Methods
decision(node, answer_vector)
click to toggle source
# File lib/tree_thinking/binary_tree.rb, line 24 def decision(node, answer_vector) case node.operator when '=' then answer_vector[node.feature_idx] == node.threshold when '>' then answer_vector[node.feature_idx] > node.threshold when '<' then answer_vector[node.feature_idx] < node.threshold when '>=' then answer_vector[node.feature_idx] >= node.threshold when '<=' then answer_vector[node.feature_idx] <= node.threshold else answer_vector[node.feature_idx] <= node.threshold end end