summaryrefslogtreecommitdiff
path: root/kmeans
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-06-10 14:48:34 +0200
committerPatrick Simianer <p@simianer.de>2015-06-10 14:48:34 +0200
commit8151031373c08ccd714a99f50783eafcb54d2010 (patch)
tree1bcf6e78392978f4ae972a5dcc936a4c266f3d78 /kmeans
parente137509a77e3a8c12af32852ebba893dacb53f85 (diff)
undo unfortunate variable naming: cfg -> conf!
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