Parent

Included Modules

Files

Ai4r::Clusterers::Clusterer

The purpose of this class is to define a common API for Clusterers. All methods in this class (other than eval) must be implemented in subclasses.

Public Instance Methods

build(data_set, number_of_clusters) click to toggle source

Build a new clusterer, using data examples found in data_set. Data items will be clustered in "number_of_clusters" different clusters.

# File lib/ai4r/clusterers/clusterer.rb, line 25
def build(data_set, number_of_clusters)
  raise NotImplementedError
end
eval(data_item) click to toggle source

Classifies the given data item, returning the cluster it belongs to.

# File lib/ai4r/clusterers/clusterer.rb, line 30
def eval(data_item)
  raise NotImplementedError
end

Protected Instance Methods

euclidean_distance(a, b) click to toggle source

Usefull as a defult distance function for clustering algorithms

# File lib/ai4r/clusterers/clusterer.rb, line 36
def euclidean_distance(a, b)        
  dist = 0.0
  a.each_index do |index|
    if a[index].is_a?(Numeric) && b[index].is_a?(Numeric)
      dist = dist + ((a[index]-b[index])*(a[index]-b[index]))
    end
  end
  return dist
end
get_min_index(array) click to toggle source
# File lib/ai4r/clusterers/clusterer.rb, line 46
def get_min_index(array)
  min = array.first
  index = 0
  array.each_index do |i|
    x = array[i]
    if x < min
      min = x
      index = i
    end
  end
  return index
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.