aboutsummaryrefslogtreecommitdiff
path: root/layer/bias.lua
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-06-02 12:51:18 +0800
committerDeterminant <[email protected]>2015-06-02 12:51:18 +0800
commit0d3d8f4afdc38726b8ed933dbfcb85e759145c43 (patch)
treed0ea9b021e710b9ac8aea4bbcd56922f3fe1f1fe /layer/bias.lua
parentbf05d75bf173e1a496a277c76593537dc9cdb28a (diff)
add preprocessing layers and change layer constructor interface
Diffstat (limited to 'layer/bias.lua')
-rw-r--r--layer/bias.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/layer/bias.lua b/layer/bias.lua
new file mode 100644
index 0000000..6ddfe11
--- /dev/null
+++ b/layer/bias.lua
@@ -0,0 +1,24 @@
+local BiasLayer = nerv.class("nerv.BiasLayer", "nerv.Layer")
+
+function BiasLayer:__init(id, global_conf, layer_conf)
+ self.id = id
+ self.gconf = global_conf
+ self.bias = layer_conf.bias
+ self.dim_in = layer_conf.dim_in
+ self.dim_out = layer_conf.dim_out
+ self:check_dim_len(1, 1)
+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:propagate(input, output)
+ output[1]:copy_fromd(input[1])
+ output[1]:add_row(self.bias.trans, 1.0)
+end