3 import torch.legacy.optim
as optim
4 from pprint
import pprint
7 def rosenbrock(tensor):
9 return (1 - x) ** 2 + 100 * (y - x ** 2) ** 2
12 def drosenbrock(tensor):
14 return torch.DoubleTensor((-400 * x * (y - x ** 2) - 2 * (1 - x), 200 * (y - x ** 2)))
17 'adadelta': optim.adadelta,
18 'adagrad': optim.adagrad,
20 'adamax': optim.adamax,
24 'rmsprop': optim.rmsprop,
30 with open(
'tests.json',
'r') as f: 31 tests = json.loads(f.read()) 34 print(test[
'algorithm'] +
'\t')
35 algorithm = algorithms[test[
'algorithm']]
36 for config
in test[
'config']:
37 print(
'================================================================================\t')
38 params = torch.DoubleTensor((1.5, 1.5))
40 algorithm(
lambda x: (rosenbrock(x), drosenbrock(x)), params, config)
41 print(
'{:.8f}\t{:.8f}\t'.format(params[0], params[1]))