Class: FpGrowth::Miner::PatternBaseExtractor
- Inherits:
-
Object
- Object
- FpGrowth::Miner::PatternBaseExtractor
- Defined in:
- lib/fpgrowth/miner/pattern_base_extractor.rb
Instance Method Summary collapse
-
#down_to_top_traversal(current_branch = @current_branch, vertical_cursor = @vertical_cursor) ⇒ Object
Method accountable of reading the upper part of the branch.
-
#down_to_top_traversal_step(current_branch = @current_branch, vertical_cursor = @vertical_cursor) ⇒ Object
Method wich represent a step of the vertical down_to_top_traversal.
- #execute ⇒ Object
-
#horizontal_traversal(horizontal_cursor = @horizontal_cursor) ⇒ Object
Method accountable of horizontal tree traversal.
-
#horizontal_traversal_step(horizontal_cursor = @horizontal_cursor) ⇒ Object
Method accountable of treating each branch.
-
#initialize(tree = FpTree::FpTree.new(), item) ⇒ PatternBaseExtractor
constructor
A new instance of PatternBaseExtractor.
-
#test_conditionnal_item(item) ⇒ Object
fonction qui sert uniquement pour les tests.
- #test_current_branch(current_branch) ⇒ Object
- #test_min_support(min_support) ⇒ Object
- #test_patterns(patterns = []) ⇒ Object
- #test_tree(tree = FpTree::FpTree.new()) ⇒ Object
- #vertical_cursor(vertical_cursor) ⇒ Object
Constructor Details
#initialize(tree = FpTree::FpTree.new(), item) ⇒ PatternBaseExtractor
Returns a new instance of PatternBaseExtractor.
8 9 10 11 12 13 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 8 def initialize(tree=FpTree::FpTree.new() , item) @tree = tree @horizontal_cursor = tree.heads[item] @conditional_item = item @patterns=[] end |
Instance Method Details
#down_to_top_traversal(current_branch = @current_branch, vertical_cursor = @vertical_cursor) ⇒ Object
Method accountable of reading the upper part of the branch
Each step, it makes a new node with the same item, but with minimum support Then the new node is added to a list Finally, the list is reversed
52 53 54 55 56 57 58 59 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 52 def down_to_top_traversal(current_branch=@current_branch, vertical_cursor=@vertical_cursor) @vertical_cursor = vertical_cursor while @vertical_cursor != nil and @vertical_cursor.item != nil down_to_top_traversal_step(current_branch) @vertical_cursor = @vertical_cursor.parent end current_branch.reverse! end |
#down_to_top_traversal_step(current_branch = @current_branch, vertical_cursor = @vertical_cursor) ⇒ Object
Method wich represent a step of the vertical down_to_top_traversal
It just gather items
65 66 67 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 65 def down_to_top_traversal_step(current_branch=@current_branch, vertical_cursor=@vertical_cursor) current_branch << vertical_cursor.item end |
#execute ⇒ Object
15 16 17 18 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 15 def execute() horizontal_traversal() return @patterns end |
#horizontal_traversal(horizontal_cursor = @horizontal_cursor) ⇒ Object
Method accountable of horizontal tree traversal
22 23 24 25 26 27 28 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 22 def horizontal_traversal(horizontal_cursor=@horizontal_cursor) @horizontal_cursor=horizontal_cursor while @horizontal_cursor != nil horizontal_traversal_step() @horizontal_cursor = @horizontal_cursor.lateral end end |
#horizontal_traversal_step(horizontal_cursor = @horizontal_cursor) ⇒ Object
Method accountable of treating each branch
Make a copy of the item branch and append it to tree
To achieve it, it make a list of the upper nodes Then build a Pattern
37 38 39 40 41 42 43 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 37 def horizontal_traversal_step(horizontal_cursor=@horizontal_cursor) @min_support = horizontal_cursor.support @current_branch = [] @vertical_cursor = horizontal_cursor.parent @current_branch = down_to_top_traversal() @patterns << Pattern.new(@current_branch, @min_support) end |
#test_conditionnal_item(item) ⇒ Object
fonction qui sert uniquement pour les tests
71 72 73 74 75 76 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 71 def test_conditionnal_item(item ) if item == @conditional_item then return true end return false end |
#test_current_branch(current_branch) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 99 def test_current_branch (current_branch) if current_branch == @current_branch then return true end return false end |
#test_min_support(min_support) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 92 def test_min_support( min_support ) if min_support == @min_support then return true end return false end |
#test_patterns(patterns = []) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 78 def test_patterns(patterns = []) if patterns == @patterns then return true end return false end |
#test_tree(tree = FpTree::FpTree.new()) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 85 def test_tree(tree = FpTree::FpTree.new() ) if tree.threshold == @tree.threshold and tree.root == @tree.root then return true end return false end |
#vertical_cursor(vertical_cursor) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/fpgrowth/miner/pattern_base_extractor.rb', line 106 def vertical_cursor (vertical_cursor) if vertical_cursor == @vertical_cursor then return true end return false end |