Class: FpGrowth::FpTree::BonzaiSecateur
- Inherits:
-
Object
- Object
- FpGrowth::FpTree::BonzaiSecateur
- Defined in:
- lib/fpgrowth/fp_tree/bonzai_secateur.rb
Instance Method Summary collapse
- #execute(hardness = @hardness, fp_tree = @fp_tree.clone) ⇒ Object
- #execute!(hardness = @hardness) ⇒ Object
-
#initialize(fp_tree, hardness = 20) ⇒ BonzaiSecateur
constructor
A new instance of BonzaiSecateur.
- #traverse(fp_tree, cursor = fp_tree.root, deepness = 0) ⇒ Object
Constructor Details
#initialize(fp_tree, hardness = 20) ⇒ BonzaiSecateur
Returns a new instance of BonzaiSecateur.
5 6 7 8 |
# File 'lib/fpgrowth/fp_tree/bonzai_secateur.rb', line 5 def initialize(fp_tree, hardness=20) @fp_tree=fp_tree @hardness=hardness end |
Instance Method Details
#execute(hardness = @hardness, fp_tree = @fp_tree.clone) ⇒ Object
10 11 12 13 |
# File 'lib/fpgrowth/fp_tree/bonzai_secateur.rb', line 10 def execute(hardness=@hardness, fp_tree=@fp_tree.clone) traverse(fp_tree) return fp_tree end |
#execute!(hardness = @hardness) ⇒ Object
15 16 17 |
# File 'lib/fpgrowth/fp_tree/bonzai_secateur.rb', line 15 def execute!(hardness=@hardness) return execute(hardness, @fp_tree) end |
#traverse(fp_tree, cursor = fp_tree.root, deepness = 0) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/fpgrowth/fp_tree/bonzai_secateur.rb', line 19 def traverse(fp_tree, cursor = fp_tree.root, deepness=0) children = cursor.children.clone threshold = cursor.support.to_f / 100 * (@hardness + deepness) children.each { |child| fp_tree.cut_branch(child) if child.support < threshold } cursor.children.each { |child| traverse(fp_tree, child, deepness + 1) } end |