-
Notifications
You must be signed in to change notification settings - Fork 0
/
NnwSmootherLlr-test.lua
51 lines (41 loc) · 1.26 KB
/
NnwSmootherLlr-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
-- NnwSmootherLlr-test.lua
-- unit test
require 'all'
test = {}
tester = Tester()
function test.one()
-- this is a very weak tests, it checks for completion
-- figuring out a problem to solve by hand seems complicated
local v, isVerbose = makeVerbose(false, 'test.one')
local nObs = 10
local nDims = 2
local xs = torch.Tensor(nObs, nDims)
local ys = torch.Tensor(nObs)
for i = 1, nObs do
ys[i] = 100 * i
for d = 1, nDims do
xs[i][d] = 10 * i + d
end
end
-- build the cache
local nShards = 1
local chatty = isVerbose
local nncb = Nncachebuilder(xs, nShards)
local filePathPrefix = '/tmp/NnwSmootherLlr-test-'
nncb:createShard(1, filePathPrefix, chatty)
Nncachebuilder.mergeShards(nShards, filePathPrefix, chatty)
local nncache = Nncache.loadUsingPrefix(filePathPrefix)
local visible = torch.Tensor(nObs):fill(1)
local llr =
NnwSmootherLlr(xs, ys, visible, nncache, 'epanechnikov quadratic')
local queryIndex = 5
local params = {}
params.k = 5
params.regularizer = 1e-7
local ok, estimate = llr:estimate(queryIndex, params)
v('estimate', estimate)
tester:assert(ok)
tester:assertgt(estimate, 0)
end -- test.one
tester:add(test)
tester:run(true) -- true ==> verbose