-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNnwEstimatorAvg-test.lua
56 lines (44 loc) · 1.14 KB
/
NnwEstimatorAvg-test.lua
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- NnwEstimatorAvg-test.lua
-- unit tests for class NnwEstimatorAvg
require 'all'
tests = {}
tester = Tester()
function makeExample()
local nsamples = 10
local ndims = 3
local xs = torch.Tensor(nsamples, ndims)
local ys = torch.Tensor(nsamples)
for i = 1, nsamples do
for d = 1, ndims do
xs[i][d] = i
ys[i] = i * 10
end
end
return nsamples, ndims, xs, ys
end -- makeExample
function tests.estimator()
--if true then return end
local v = makeVerbose(false, 'tests.estimator')
local nSamples, nDims, xs, ys = makeExample()
local query = torch.Tensor(nDims):fill(3)
local function test(k, expected)
--v('xs', xs)
local knn = NnwEstimatorAvg(xs, ys)
v('knn', knn)
local ok, estimate = knn:estimate(query, k)
v('ok,estimate', ok, estimate)
tester:assert(ok)
tester:asserteq(expected, estimate)
end
-- see lab book for 2012-10-18 for calculations
test(1, 30)
test(3, 30)
test(5, 30)
test(6, 35)
test(7, 40)
test(8, 45)
test(9, 50)
test(10, 55)
end -- KnnEstimator
tester:add(tests)
tester:run(true) -- true ==> verbose