Module: Ai4r::Clusterers::ClusterTree
- Included in:
- AverageLinkage, CentroidLinkage, CompleteLinkage, MedianLinkage, SingleLinkage, WardLinkage, WardLinkageHierarchical, WeightedAverageLinkage
- Defined in:
- lib/ai4r/clusterers/cluster_tree.rb
Overview
Mixin to capture merge steps during agglomerative clustering. Stores intermediate clusters in cluster_tree. Optional depth limits how many last merges are recorded.
Instance Attribute Summary collapse
-
#cluster_tree ⇒ Object
readonly
Returns the value of attribute cluster_tree.
Instance Method Summary collapse
- #build(data_set, number_of_clusters = 1, **options) ⇒ Object
- #initialize(depth = nil, *args) ⇒ Object
Instance Attribute Details
#cluster_tree ⇒ Object (readonly)
Returns the value of attribute cluster_tree.
9 10 11 |
# File 'lib/ai4r/clusterers/cluster_tree.rb', line 9 def cluster_tree @cluster_tree end |
Instance Method Details
#build(data_set, number_of_clusters = 1, **options) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ai4r/clusterers/cluster_tree.rb', line 25 def build(data_set, number_of_clusters = 1, **) @total_merges = data_set.data_items.length - number_of_clusters super @cluster_tree << clusters @cluster_tree.reverse! self end |
#initialize(depth = nil, *args) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ai4r/clusterers/cluster_tree.rb', line 14 def initialize(depth = nil, *args) @cluster_tree = [] @depth = depth @merges_so_far = 0 super(*args) end |