Class: Newral::Data::ClusterSet
- Inherits:
-
Object
- Object
- Newral::Data::ClusterSet
- Defined in:
- lib/newral/data/cluster_set.rb
Instance Attribute Summary collapse
-
#clusters ⇒ Object
Returns the value of attribute clusters.
Instance Method Summary collapse
- #[](label) ⇒ Object
- #cluster_array ⇒ Object
- #clusters_count ⇒ Object
-
#initialize(cluster_labels: [], clusters: nil) ⇒ ClusterSet
constructor
A new instance of ClusterSet.
- #update_centers ⇒ Object
Constructor Details
#initialize(cluster_labels: [], clusters: nil) ⇒ ClusterSet
Returns a new instance of ClusterSet.
5 6 7 8 9 10 11 12 |
# File 'lib/newral/data/cluster_set.rb', line 5 def initialize( cluster_labels: [], clusters: nil ) if clusters idx = 0 @clusters = clusters.inject({}){ |h,cluster| cluster.label = "cluster_#{ idx }";h[cluster.label] = cluster;idx=idx+1; h } else @clusters = cluster_labels.inject({}){ |h,label| h[label] = Cluster.new(label: label); h } end end |
Instance Attribute Details
#clusters ⇒ Object
Returns the value of attribute clusters.
4 5 6 |
# File 'lib/newral/data/cluster_set.rb', line 4 def clusters @clusters end |
Instance Method Details
#[](label) ⇒ Object
14 15 16 |
# File 'lib/newral/data/cluster_set.rb', line 14 def []( label ) label.kind_of?(String) || label.kind_of?(Symbol) ? @clusters[ label ] : cluster_array[ label ] end |
#cluster_array ⇒ Object
18 19 20 |
# File 'lib/newral/data/cluster_set.rb', line 18 def cluster_array @clusters.values end |
#clusters_count ⇒ Object
28 29 30 31 32 33 |
# File 'lib/newral/data/cluster_set.rb', line 28 def clusters_count @clusters.inject({}) do |h,cluster| h[cluster[0]] = cluster[1].points.size h end end |
#update_centers ⇒ Object
22 23 24 25 26 |
# File 'lib/newral/data/cluster_set.rb', line 22 def update_centers @clusters.each do |key,cluster| cluster.update_center end end |