Class: KMeans::Agent
Instance Attribute Summary collapse
-
#centroids ⇒ Object
readonly
The centroids used for the clustering.
-
#k ⇒ Object
readonly
The number of clusters we’re after.
-
#max ⇒ Object
readonly
The maximum number of iterations allowed.
-
#num_iterations ⇒ Object
readonly
The number of iterations used.
-
#online ⇒ Object
readonly
Whether we’re interested in keeping the results after processing.
Class Method Summary collapse
-
.rebase(*node_list) ⇒ Object
Only works if the agent was processed as an online algorithm.
Instance Method Summary collapse
-
#nodes ⇒ Object
All the affectd nodes.
-
#process(opts = {}, *node_list) ⇒ Object
Example: KMeans::Agent.call(3, [1,2,1], [2,1,3], …) KMeans::Agent.call(:k => 3, :centroids => [[1,2,3],,[3,4,2]], [1,2,1], [2,1,3], …).
- #rebase(*node_list) ⇒ Object
Instance Attribute Details
#centroids ⇒ Object (readonly)
The centroids used for the clustering
22 23 24 |
# File 'lib/kmeans/agent.rb', line 22 def centroids @centroids end |
#k ⇒ Object (readonly)
The number of clusters we’re after
15 16 17 |
# File 'lib/kmeans/agent.rb', line 15 def k @k end |
#max ⇒ Object (readonly)
The maximum number of iterations allowed
25 26 27 |
# File 'lib/kmeans/agent.rb', line 25 def max @max end |
#num_iterations ⇒ Object (readonly)
The number of iterations used
28 29 30 |
# File 'lib/kmeans/agent.rb', line 28 def num_iterations @num_iterations end |
#online ⇒ Object (readonly)
Whether we’re interested in keeping the results after processing. To re-process: Agent.rebase(*new_node_list)
19 20 21 |
# File 'lib/kmeans/agent.rb', line 19 def online @online end |
Class Method Details
.rebase(*node_list) ⇒ Object
Only works if the agent was processed as an online algorithm
8 9 10 11 |
# File 'lib/kmeans/agent.rb', line 8 def rebase(*node_list) return false unless @@agent @@agent.rebase(*node_list) end |
Instance Method Details
#nodes ⇒ Object
All the affectd nodes
31 32 33 |
# File 'lib/kmeans/agent.rb', line 31 def nodes Node.nodes end |
#process(opts = {}, *node_list) ⇒ Object
Example: KMeans::Agent.call(3, [1,2,1], [2,1,3], …) KMeans::Agent.call(:k => 3, :centroids => [[1,2,3],,[3,4,2]], [1,2,1], [2,1,3], …)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kmeans/agent.rb', line 38 def process(opts={}, *node_list) unless self.online Node.clear_nodes! @centroids = nil end @scaling = opts.fetch(:scaling, false) if opts.is_a?(Hash) Node.add_nodes(*node_list) if opts.is_a?(Hash) @k = opts[:k] @centroids = opts.fetch(:centroids, false) @online = opts.fetch(:online, false) @max = opts.fetch(:max, 10_000) else @k = opts end stabilize_centroids @@agent = self if self.online self end |