class TreeThinking::BinaryTreeFactory
Attributes
tree[R]
Public Class Methods
from_yaml(path)
click to toggle source
# File lib/tree_thinking/binary_tree_factory.rb, line 7 def self.from_yaml(path) new(YAML.load(File.read(path))).build! end
new(tree)
click to toggle source
# File lib/tree_thinking/binary_tree_factory.rb, line 11 def initialize(tree) @tree = tree end
Public Instance Methods
build!()
click to toggle source
# File lib/tree_thinking/binary_tree_factory.rb, line 15 def build! btree = BinaryTree.new(name: tree['class_name']) btree.tree = nodify(tree['tree']) btree end
Private Instance Methods
nodify(attrs)
click to toggle source
# File lib/tree_thinking/binary_tree_factory.rb, line 23 def nodify(attrs) BinaryTree::Node.new( attrs['feature_idx'], attrs['op'], attrs['thr'], attrs['prob'], Hash[attrs.fetch('results', {}).map do |return_val, child_node| [return_val, nodify(child_node)] end] ) end