From a766983d167c5eb700ff9aaf0ba7e1c4e97a9cf3 Mon Sep 17 00:00:00 2001 From: txh18 Date: Mon, 16 Nov 2015 22:48:08 +0800 Subject: coding style changes --- nerv/layer/affine.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'nerv/layer/affine.lua') diff --git a/nerv/layer/affine.lua b/nerv/layer/affine.lua index c24af16..c5084c4 100644 --- a/nerv/layer/affine.lua +++ b/nerv/layer/affine.lua @@ -19,29 +19,29 @@ end function MatrixParam:update(gradient) local gconf = self.gconf - if (gconf.momentum > 0) then + if gconf.momentum > 0 then self.correction:add(self.correction, gradient, gconf.momentum, 1.0) -- momentum gain - local mmt_gain = 1.0 / (1.0 - gconf.momentum); + local mmt_gain = 1.0 / (1.0 - gconf.momentum) local n = self.gconf.batch_size * mmt_gain -- perform update - self.trans:add(self.trans, self.correction, 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, -gconf.lrate/n) + self.trans:add(self.trans, self.correction, 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, - gconf.lrate / n) else - self.trans:add(self.trans, gradient, 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, -gconf.lrate/gconf.batch_size) + self.trans:add(self.trans, gradient, 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, - gconf.lrate / gconf.batch_size) end end function MatrixParam:updateEI(err, input) local gconf = self.gconf - if (gconf.momentum > 0) then + if gconf.momentum > 0 then self.correction:mul(input, err, 1.0, gconf.momentum, 'T', 'N') -- momentum gain - local mmt_gain = 1.0 / (1.0 - gconf.momentum); + local mmt_gain = 1.0 / (1.0 - gconf.momentum) local n = self.gconf.batch_size * mmt_gain -- perform update - self.trans:add(self.trans, self.correction, 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, -gconf.lrate/n) + self.trans:add(self.trans, self.correction, 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, - gconf.lrate / n) else - self.trans:mul(input, err, -gconf.lrate/gconf.batch_size, 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, 'T', 'N') + self.trans:mul(input, err, - gconf.lrate / gconf.batch_size, 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, 'T', 'N') end end @@ -92,20 +92,20 @@ function AffineLayer:batch_resize(batch_size) end function AffineLayer:update(bp_err, input, output) - if (self.direct_update == true) then + if self.direct_update == true then local gconf = self.gconf - if (gconf.momentum > 0) then + if gconf.momentum > 0 then self.ltp.correction:mul(input[1], bp_err[1], 1.0, gconf.momentum, 'T', 'N') self.bp.correction:add(self.bp.correction, bp_err[1]:colsum(), gconf.momentum, 1) -- momentum gain - local mmt_gain = 1.0 / (1.0 - gconf.momentum); + local mmt_gain = 1.0 / (1.0 - gconf.momentum) local n = self.gconf.batch_size * mmt_gain -- perform update - self.ltp.trans:add(self.ltp.trans, self.ltp.correction, 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, -gconf.lrate / n) - self.bp.trans:add(self.bp.trans, self.bp.correction, 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, -gconf.lrate / n) + self.ltp.trans:add(self.ltp.trans, self.ltp.correction, 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, - gconf.lrate / n) + self.bp.trans:add(self.bp.trans, self.bp.correction, 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, - gconf.lrate / n) else - self.ltp.trans:mul(input[1], bp_err[1], -gconf.lrate / gconf.batch_size, 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, 'T', 'N') - self.bp.trans:add(self.bp.trans, bp_err[1]:colsum(), 1.0-gconf.lrate*gconf.wcost/gconf.batch_size, -gconf.lrate / gconf.batch_size) + self.ltp.trans:mul(input[1], bp_err[1], - gconf.lrate / gconf.batch_size, 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, 'T', 'N') + self.bp.trans:add(self.bp.trans, bp_err[1]:colsum(), 1.0 - gconf.lrate * gconf.wcost / gconf.batch_size, - gconf.lrate / gconf.batch_size) end else self.ltp:updateEI(bp_err[1], input[1]) -- cgit v1.2.3