aboutsummaryrefslogtreecommitdiff
path: root/layer/combiner.lua
diff options
context:
space:
mode:
authorcloudygoose <[email protected]>2015-06-21 10:50:46 +0800
committercloudygoose <[email protected]>2015-06-21 10:50:46 +0800
commitad2c4013dec71667d6bbd5e9a249df2085208507 (patch)
tree474c536ff4a7d757bb61915a1bfc7a073f40d09f /layer/combiner.lua
parent839d938df0d83ec311c5d1299923c667adff6a87 (diff)
parentf3f4e74eb4dbb8829e5ee136ba4b0c0a7938b551 (diff)
Merge upstream 'parameter update big-change'.
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'layer/combiner.lua')
-rw-r--r--layer/combiner.lua26
1 files changed, 15 insertions, 11 deletions
diff --git a/layer/combiner.lua b/layer/combiner.lua
index 75e47e2..7bd7617 100644
--- a/layer/combiner.lua
+++ b/layer/combiner.lua
@@ -7,9 +7,15 @@ function CombinerLayer:__init(id, global_conf, layer_conf)
self.dim_out = layer_conf.dim_out
self.gconf = global_conf
self:check_dim_len(#self.lambda, -1)
+ if #self.dim_in < 1 then
+ nerv.error("no input specified")
+ end
+ if #self.dim_out < 1 then
+ nerv.error("no output specified")
+ end
end
-function CombinerLayer:init()
+function CombinerLayer:init(batch_size)
local dim = self.dim_in[1]
for i = 2, #self.dim_in do
if self.dim_in[i] ~= dim then
@@ -21,6 +27,7 @@ function CombinerLayer:init()
nerv.error("mismatching dimensions of inputs/outputs")
end
end
+ self.sum = self.gconf.cumat_type(batch_size, dim)
end
function CombinerLayer:update(bp_err, input, output)
@@ -32,24 +39,21 @@ function CombinerLayer:propagate(input, output)
output[1]:add(output[1], input[i], 1.0, self.lambda[i])
end
for i = 2, #self.dim_out do
- output[i]:copy_fromd(output[1])
+ output[i]:copy_fromd(output[1])
end
end
-function CombinerLayer:back_propagate(next_bp_err, bp_err, input, output)
- local sum = bp_err[1]:create()
- sum:fill(0)
- for i = 1, #self.dim_out do
+function CombinerLayer:back_propagate(bp_err, next_bp_err, input, output)
+ local sum = self.sum
+ sum:copy_fromd(bp_err[1])
+ for i = 2, #self.dim_out do
sum:add(sum, bp_err[i], 1.0, 1.0)
end
for i = 1, #self.dim_in do
- local scale = nerv.CuMatrixFloat(sum:nrow(), 1)
- scale:fill(self.lambda[i])
- next_bp_err[i]:copy_fromd(sum)
- next_bp_err[i]:scale_rows_by_col(scale)
+ next_bp_err[i]:add(next_bp_err[i], sum, 0.0, self.lambda[i])
end
end
function CombinerLayer:get_params()
- return {}
+ return nerv.ParamRepo({})
end