Skip to content

Commit

Permalink
removed periodicity from MaxNorm
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-leonard committed Apr 7, 2015
1 parent f66f947 commit 267f5e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion model/layer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function Layer:maxNorm(max_out_norm, max_in_norm)
if param:dim() == 2 then
if max_out_norm then
-- rows feed into output neurons
param:renorm(1, 2, max_out_norm)
param:renorm(2, 1, max_out_norm)
end
if max_in_norm then
-- cols feed out from input neurons
Expand Down
24 changes: 8 additions & 16 deletions visitor/maxnorm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function MaxNorm:__init(config)
config = config or {}
assert(torch.type(config) == 'table' and not config[1],
"Constructor requires key-value arguments")
local args, max_out_norm, max_in_norm, period, name = xlua.unpack(
local args, max_out_norm, max_in_norm, name = xlua.unpack(
{config},
'MaxNorm',
'Hard constraint on the upper bound of the norm of output ' ..
Expand All @@ -23,15 +23,11 @@ function MaxNorm:__init(config)
help='max norm of output neuron weights'},
{arg='max_in_norm', type='number',
help='max norm of input neuron weights'},
{arg='period', type='number', default=1,
help='Every period batches, the norm is constrained'},
{arg='name', type='string', default='maxnorm',
help='identifies visitor in reports.'}
)
self._max_out_norm = max_out_norm
self._max_in_norm = max_in_norm
self._period = period
self._iter = 0
config.include = config.include or {}
table.insert(config.include, 'hasParams')
config.exclude = config.exclude or {}
Expand All @@ -41,17 +37,13 @@ function MaxNorm:__init(config)
end

function MaxNorm:_visitModel(model)
self._iter = self._iter + 1
if self._iter == self._period then
if model.maxNorm then
model:maxNorm(self._max_out_norm, self._max_in_norm)
else
if not model.mvstate[self:id():name()].warned then
print("Warning: MaxNorm not implemented for model " ..
torch.typename(model) .. ". Ignoring model-visitor pair")
model.mvstate[self:id():name()].warned = true
end
if model.maxNorm then
model:maxNorm(self._max_out_norm, self._max_in_norm)
else
if not model.mvstate[self:id():name()].warned then
print("Warning: MaxNorm not implemented for model " ..
torch.typename(model) .. ". Ignoring model-visitor pair")
model.mvstate[self:id():name()].warned = true
end
self._iter = 0
end
end

0 comments on commit 267f5e2

Please sign in to comment.