Sha256: ac30ebbaa2d0a99b6b7e829e70588a8bc3c46b6050bdb08284949679e2aa18d2
Contents?: true
Size: 1.66 KB
Versions: 12
Compression:
Stored size: 1.66 KB
Contents
# Author:: Sergio Fierens # License:: MPL 1.1 # Project:: ai4r # Url:: http://ai4r.rubyforge.org/ # # You can redistribute it and/or modify it under the terms of # the Mozilla Public License version 1.1 as published by the # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt require File.dirname(__FILE__) + '/../data/parameterizable' module Ai4r module Clusterers # 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. class Clusterer include Ai4r::Data::Parameterizable # Build a new clusterer, using data examples found in data_set. # Data items will be clustered in "number_of_clusters" different # clusters. def build(data_set, number_of_clusters) raise NotImplementedError end # Classifies the given data item, returning the cluster it belongs to. def eval(data_item) raise NotImplementedError end protected # Usefull as a defult distance function for clustering algorithms 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 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 end end end
Version data entries
12 entries across 12 versions & 3 rubygems