class Newral::Data::ClusterSet

Attributes

clusters[RW]

Public Class Methods

new( cluster_labels: [], clusters: nil ) click to toggle source
# 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

Public Instance Methods

[]( label ) click to toggle source
# 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() click to toggle source
# File lib/newral/data/cluster_set.rb, line 18
def cluster_array
  @clusters.values
end
clusters_count() click to toggle source
# 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() click to toggle source
# File lib/newral/data/cluster_set.rb, line 22
def update_centers
  @clusters.each do |key,cluster| 
    cluster.update_center
  end 
end