aboutsummaryrefslogtreecommitdiff
path: root/nerv/layer/bias.lua
blob: d3c7cdbb5caa96b28c4bcc80fdf61cb62263f892 (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
local BiasLayer = nerv.class("nerv.BiasLayer", "nerv.Layer")

function BiasLayer:__init(id, global_conf, layer_conf)
    nerv.Layer.__init(self, id, global_conf, layer_conf)
    self:check_dim_len(1, 1)
    self:bind_params()
end

function BiasLayer:bind_params()
    self.bias = self:find_param("bias", self.lconf, self.gconf,
                                nerv.BiasParam,
                                {1, self.dim_out[1]},
                                nerv.Param.gen_zero)
    if self.lconf.no_update_all then
        self.bias.no_update = true
    end
end

function BiasLayer:init()
    if self.dim_in[1] ~= self.bias.trans:ncol() then
        nerv.error("mismatching dimensions of input and bias parameter")
    end
    if self.dim_out[1] ~= self.bias.trans:ncol() then
        nerv.error("mismatching dimensions of output and bias parameter")
    end
end

function BiasLayer:batch_resize(batch_size)
    -- do nothing
end

function BiasLayer:propagate(input, output)
    output[1]:copy_from(input[1])
    output[1]:add_row(self.bias.trans, 1.0)
end

function BiasLayer:get_params()
    return nerv.ParamRepo({self.bias}, self.loc_type)
end

function BiasLayer:back_propagate()
end

function BiasLayer:update()
end