summaryrefslogtreecommitdiff
path: root/kmeans
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-11-12 13:57:07 +0100
committerPatrick Simianer <p@simianer.de>2015-11-12 13:57:07 +0100
commit5c2833c505dda0d1646b8f8c1e62abd391f0401e (patch)
tree0259c7c2bdb531c09587a744869848d87f4bbd9e /kmeans
parentef282dbe4fef1b0ae0c8544f0bb84ba674c68de7 (diff)
parent8151031373c08ccd714a99f50783eafcb54d2010 (diff)
Merge branch 'master' of github.com:pks/scripts
Diffstat (limited to 'kmeans')
-rwxr-xr-xkmeans18
1 files changed, 9 insertions, 9 deletions
diff --git a/kmeans b/kmeans
index 201864b..c1684ee 100755
--- a/kmeans
+++ b/kmeans
@@ -57,7 +57,7 @@ def update assignment, data
end
def main
- cfg = Trollop::options do
+ conf = Trollop::options do
opt :k, "k", :type => :int, :required => true
opt :input, "input: one feature vector per line", :type => :string, :required => true
opt :max_iterations, "max. number of iterations", :type => :int, :default => 100
@@ -65,26 +65,26 @@ def main
opt :init, "centroid initialization (1: sample k features vectors, 2: k-times do sample k feature and build mean)", :type => :int, :short => '-j', :default => 2
end
# data is 'ID f1=v1 f2=v2'
- data = read_data cfg[:input]
- k = cfg[:k]
+ data = read_data conf[:input]
+ k = conf[:k]
centroids = nil
- if cfg[:init] == 1
+ if conf[:init] == 1
centroids = rand_init(data, k)
else
centroids = rand_means_init(data, k)
end
STDERR.write "\n k #{k}\n"
- STDERR.write " input #{cfg[:input]}\n"
- STDERR.write "iterations #{cfg[:max_iterations]}\n"
- STDERR.write "max no ch. #{cfg[:max_no_change]}\n"
- STDERR.write " init #{cfg[:init]}\n\n"
+ STDERR.write " input #{conf[:input]}\n"
+ STDERR.write "iterations #{conf[:max_iterations]}\n"
+ STDERR.write "max no ch. #{conf[:max_no_change]}\n"
+ STDERR.write " init #{conf[:init]}\n\n"
assignment = nil
prev_stats = []
stats = []
no_change = 0
max_no_change = 5
STDERR.write "expected cluster sz=#{data.size/k.to_f}\n\n"
- 0.upto(cfg[:max_iterations]) do |i|
+ 0.upto(conf[:max_iterations]) do |i|
s = "iteration #{i}"
STDERR.write "#{s}\n#{'-'*s.size}\n"
assignment = assign centroids, data