Class: Mjai::Manue::DangerEstimator::DecisionTree

Inherits:
Object
  • Object
show all
Defined in:
lib/mjai/manue/danger_estimator.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DecisionTree

Returns a new instance of DecisionTree.



424
425
426
# File 'lib/mjai/manue/danger_estimator.rb', line 424

def initialize(path)
  @root = open(path, "rb"){ |f| Marshal.load(f) }
end

Instance Method Details

#estimate_prob(scene, pai) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/mjai/manue/danger_estimator.rb', line 428

def estimate_prob(scene, pai)
  feature_vector = scene.feature_vector(pai.remove_red())
  p [pai, DangerEstimator.feature_vector_to_str(feature_vector)]
  node = @root
  while node.feature_name
    if DangerEstimator.get_feature_value(feature_vector, node.feature_name)
      node = node.positive
    else
      node = node.negative
    end
  end
  return node.average_prob
end