summaryrefslogtreecommitdiff
path: root/fast_test.rb
blob: 23f7edfc13cfb8751174b79e7582a97ff349a846 (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
#!/usr/bin/env ruby

require 'zipf'

STDERR.write "testing...\n"
test = []
test_f = ReadFile.new ARGV[0]
n = 0
errors = 0
w = SparseVector.from_kv ReadFile.new(ARGV[1]).read, "\t", "\n"
while i = test_f.gets
  x = SparseVector.from_kv(i.strip, '=', ' ')
  m = w.dot(x)
  if m <= 0.0
    errors += 1
    puts -1
  else
    puts 1
  end
  n += 1
  STDERR.write "#{n}\n" if n%1000==0
end
STDERR.write " test set size = #{n}\n"

STDERR.write "accuracy = #{(n-errors)/n.to_f}\n"