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, min_support = @min_support) ⇒ 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.new, item) ⇒ PatternBaseExtractor
constructor
A new instance of PatternBaseExtractor.
Constructor Details
#initialize(tree = 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.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() @vertical_cursor = @vertical_cursor.parent end current_branch.reverse! end |
#down_to_top_traversal_step(current_branch = @current_branch, vertical_cursor = @vertical_cursor, min_support = @min_support) ⇒ 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, min_support=@min_support) 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 |