diff options
author | txh18 <cloudygooseg@gmail.com> | 2015-11-16 22:48:08 +0800 |
---|---|---|
committer | txh18 <cloudygooseg@gmail.com> | 2015-11-16 22:48:08 +0800 |
commit | a766983d167c5eb700ff9aaf0ba7e1c4e97a9cf3 (patch) | |
tree | 69c0059394bda89e059284780c15f823cb15d21f /nerv/layer/affine.lua | |
parent | e2c4cb5f535ca43353f77f69214bad44f680ff81 (diff) |
coding style changes
Diffstat (limited to 'nerv/layer/affine.lua')
-rw-r--r-- | nerv/layer/affine.lua | 30 |
1 files changed, 15 insertions, 15 deletions
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]) |