Class: Carmenere::Algorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/carmenere/algorithm.rb

Direct Known Subclasses

KMeans::Algorithm, SingleLinkage::Algorithm

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(k, nodes) ⇒ Algorithm

Returns a new instance of Algorithm.



9
10
11
12
13
14
15
16
17
18
# File 'lib/carmenere/algorithm.rb', line 9

def initialize k, nodes
  @k = k
  @nodes = Set.new(nodes).freeze
  @clusters = Set.new(@nodes.map{ |n| Cluster.new([n]) })
  @distance_matrix = @nodes.each.with_object({}) do |i, row|
    row[i] = @nodes.each.with_object({}) do |j, col|
      col[j] = i.distance(j) if i != j
    end
  end
end

Instance Attribute Details

#distance_matrixObject (readonly)

Returns the value of attribute distance_matrix.



7
8
9
# File 'lib/carmenere/algorithm.rb', line 7

def distance_matrix
  @distance_matrix
end

#nodesObject (readonly)

Returns the value of attribute nodes.



5
6
7
# File 'lib/carmenere/algorithm.rb', line 5

def nodes
  @nodes
end

Instance Method Details

#runObject

If a block is provided, it should yield each iteration of the clusters, otherwise, just returns the final state of the space.

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/carmenere/algorithm.rb', line 22

def run
  raise NotImplementedError.new
end