-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from lake4790k/async
sharedRmsProp and async nature params
- Loading branch information
Showing
5 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function optim.sharedRmsProp(opfunc, x, config, state) | ||
-- Get state | ||
local config = config or {} | ||
local state = state or config | ||
local lr = config.learningRate or 1e-2 | ||
local momentum = config.momentum or 0.95 | ||
local epsilon = config.epsilon or 0.01 | ||
|
||
-- Evaluate f(x) and df/dx | ||
local fx, dfdx = opfunc(x) | ||
|
||
-- Initialise storage | ||
if not state.g then | ||
state.g = torch.Tensor():typeAs(x):resizeAs(dfdx):zero() | ||
end | ||
|
||
if not state.tmp then | ||
state.tmp = torch.Tensor():typeAs(x):resizeAs(dfdx) | ||
end | ||
|
||
state.g:mul(momentum):addcmul(1 - momentum, dfdx, dfdx) | ||
state.tmp:copy(state.g):add(epsilon):sqrt() | ||
|
||
-- Update x = x - lr x df/dx / tmp | ||
x:addcdiv(-lr, dfdx, state.tmp) | ||
|
||
-- Return x*, f(x) before optimisation | ||
return x, {fx} | ||
end |