class GeneValidator::PairCluster
Attributes
objects[RW]
a hash map containing the pair (object, no_occurences)
Public Class Methods
new(objects)
click to toggle source
# File lib/genevalidator/clusterization.rb, line 63 def initialize(objects) @objects = objects end
Public Instance Methods
add(cluster)
click to toggle source
Merges the current cluster with the one given as parameter clusters
vector of Cluster
objects
# File lib/genevalidator/clusterization.rb, line 144 def add(cluster) cluster.objects.each do |elem| objects[elem[0]] = elem[1] end end
density()
click to toggle source
Returns the density of the cluster: how many values it contains
# File lib/genevalidator/clusterization.rb, line 91 def density d = 0 objects.each do |elem| d += elem[1] end d end
distance(cluster, method = 0)
click to toggle source
Returns the euclidian distance between the current cluster and the one given as parameter Params: cluster
: Cluster
object method
: 0 or 1 method = 0: do not into condseideration duplicate values method = 1: average linkage clusterization
# File lib/genevalidator/clusterization.rb, line 106 def distance(cluster, method = 0) d = 0 norm = 0 cluster.objects.each do |elem1| objects.each do |elem2| if method == 1 d += elem1[1] * elem2[1] * (elem1[0] - elem2[0]).abs norm += elem1[1] * elem2[1] else d += (elem1[0] - elem2[0]).abs norm = cluster.objects.length * objects.length end end end # group average distance d /= (norm + 0.0) end
mean()
click to toggle source
Returns the weighted mean value of the cluster
# File lib/genevalidator/clusterization.rb, line 75 def mean mean = Pair.new(0, 0) weight = 0 objects.each do |object, n| (1..n).each do |_i| mean + object weight += 1 end end mean / weight mean end
print()
click to toggle source
# File lib/genevalidator/clusterization.rb, line 67 def print objects.each do |elem| warn "(#{elem[0].x},#{elem[0].y}): #{elem[1]}" end end
wss(objects = nil)
click to toggle source
Returns within cluster sum of squares
# File lib/genevalidator/clusterization.rb, line 128 def wss(objects = nil) if objects.nil? objects = @objects.map { |x| Array.new(x[1], x[0]) }.flatten end cluster_mean = mean ss = 0 objects.each do |object| ss += (cluster_mean - object) * (cluster_mean - object) end ss end