Module: Ai4r::Clusterers::ClusterTree

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

Instance Method Summary collapse

Instance Attribute Details

#cluster_treeObject (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

Parameters:

  • data_set (Object)
  • number_of_clusters (Object) (defaults to: 1)
  • *options (Object)

Returns:

  • (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, **options)
  @total_merges = data_set.data_items.length - number_of_clusters
  super
  @cluster_tree << clusters
  @cluster_tree.reverse!
  self
end

#initialize(depth = nil, *args) ⇒ Object

Parameters:

  • depth (Object) (defaults to: nil)
  • args (Object)

Returns:

  • (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