aboutsummaryrefslogtreecommitdiff
path: root/layer/init.lua
blob: 4881cb7cd334f0e1058d79e3c6358aaec406565f (plain) (blame)
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
57
58
59
-- The following methods must be implemented to let a layer work properly

local Param = nerv.class('nerv.Param')

function nerv.Param:__init(id, global_conf)
    self.id = id
    self.gconf = global_conf
end

function nerv.Param:get_info()
    return self.info
end

function nerv.Param:set_info(info)
    self.info = info
end

function nerv.Param:read(pfhandle)
    nerv.error_method_not_implemented()
end

function nerv.Param:write(pfhandle)
    nerv.error_method_not_implemented()
end

local Layer = nerv.class('nerv.Layer')

function nerv.Layer:__init(id, global_conf, ...)
    nerv.error_method_not_implemented()
end

function nerv.Layer:init(id)
    nerv.error_method_not_implemented()
end

function nerv.Layer:update(bp_err, input, output)
    nerv.error_method_not_implemented()
end

function nerv.Layer:propagate(input, output)
    nerv.error_method_not_implemented()
end

function nerv.Layer:back_propagate(next_bp_err, bp_err, input, output)
    nerv.error_method_not_implemented()
end

function nerv.Layer:check_dim_len(len_in, len_out)
    local expected_in = table.getn(self.dim_in)
    local expected_out = table.getn(self.dim_out)
    if len_in > 0 and expected_in ~= len_in then
        nerv.error("layer %s expects %d inputs, %d given",
                    self.id, len_in, expected_in)
    end
    if len_out > 0 and expected_out ~= len_out then
        nerv.error("layer %s expects %d outputs, %d given",
                    self.id, len_out, expected_out)
    end
end