blob: 03c0cd4c5ed03d101a92f1d29a7ab4d2a3f905d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/usr/bin/env ruby
require 'zipf'
STDERR.write "reading test data...\n"
test = []
test_f = ReadFile.new ARGV[0]
threshold = ARGV[2].to_f
signals = ReadFile.new(ARGV[1]).readlines_strip.map{|i| (i.to_f)>=threshold}
n = 0
while i = test_f.gets
test << SparseVector.from_kv(i.strip, '=', ' ')
n += 1
STDERR.write "#{n}\n" if n%1000==0
end
STDERR.write " test set size = #{test.size}\n"
errors = 0
w = SparseVector.from_kv ReadFile.new(ARGV[1]).read, "\t", "\n"
test.each { |x|
m = w.dot(x)
if m <= 0.0
errors += 1
puts -1
else
puts 1
end
}
STDERR.write "accuracy = #{(test.size-errors)/test.size.to_f}\n"
|