annotate doc/v2_planning/API_optimization.txt @ 1183:bc1b445e22fa

API_coding_style: Added code example to explain the point about the number of spaces after a period
author Olivier Delalleau <delallea@iro>
date Fri, 17 Sep 2010 16:51:09 -0400
parents 14aa0a5bb661
children 4ea46ef9822a
rev   line source
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
1 Optimization API
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
2 ================
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
3
1069
16ea3e5c5a7a api_optimization: Couple questions
Olivier Delalleau <delallea@iro>
parents: 1065
diff changeset
4 Members: Bergstra, Lamblin, Delalleau, Glorot, Breuleux, Bordes
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
5 Leader: Bergstra
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
6
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
7
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
8 Description
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
9 -----------
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
10
1065
2bbc464d6ed0 typo in doc
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1064
diff changeset
11 This API is for iterative optimization algorithms, such as:
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
12
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
13 - stochastic gradient descent (incl. momentum, annealing)
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
14 - delta bar delta
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
15 - conjugate methods
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
16 - L-BFGS
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
17 - "Hessian Free"
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
18 - SGD-QN
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
19 - TONGA
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
20
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
21 The API includes an iterative interface based on Theano, and a one-shot
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
22 interface similar to SciPy and MATLAB that is based on Python and Numpy, that
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
23 only uses Theano for the implementation.
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
24
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
25
1100
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
26 Theano Interface
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
27 -----------------
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
28
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
29 The theano interface to optimization algorithms is to ask for a dictionary of
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
30 updates that can be used in theano.function. Implementations of iterative
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
31 optimization algorithms should be global functions with a signature like
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
32 'iterative_optimizer'.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
33
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
34 def iterative_optimizer(parameters,
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
35 cost=None,
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
36 gradients=None,
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
37 stop=None,
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
38 updates=None,
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
39 **kwargs):
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
40 """
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
41 :param parameters: list or tuple of Theano variables
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
42 that we want to optimize iteratively. If we're minimizing f(x), then
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
43 together, these variables represent 'x'. Typically these are shared
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
44 variables and their values are the initial values for the minimization
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
45 algorithm.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
46
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
47 :param cost: scalar-valued Theano variable that computes an exact or noisy estimate of
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
48 cost (what are the conditions on the noise?). Some algorithms might
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
49 need an exact cost, some algorithms might ignore the cost if the
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
50 gradients are given.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
51
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
52 :param gradients: list or tuple of Theano variables representing the gradients on
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
53 the corresponding parameters. These default to tensor.grad(cost,
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
54 parameters).
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
55
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
56 :param stop: a shared variable (scalar integer) that (if provided) will be
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
57 updated to say when the iterative minimization algorithm has finished
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
58 (1) or requires more iterations (0).
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
59
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
60 :param updates: a dictionary to update with the (var, new_value) items
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
61 associated with the iterative algorithm. The default is a new empty
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
62 dictionary. A KeyError is raised in case of key collisions.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
63
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
64 :param kwargs: algorithm-dependent arguments
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
65
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
66 :returns: a dictionary mapping each parameter to an expression that it
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
67 should take in order to carry out the optimization procedure.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
68
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
69 If all the parameters are shared variables, then this dictionary may be
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
70 passed as the ``updates`` argument to theano.function.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
71
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
72 There may be more key,value pairs in the dictionary corresponding to
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
73 internal variables that are part of the optimization algorithm.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
74
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
75 """
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
76
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
77
1100
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
78 Numpy Interface
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
79 ---------------
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
80
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
81 The numpy interface to optimization algorithms is supposed to mimick
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
82 scipy's. Its arguments are numpy arrays, and functions that manipulate numpy
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
83 arrays.
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
84
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
85 def minimize(x0, f, df, opt_algo, **kwargs):
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
86 """
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
87 Return a point x_new with the same type as x0 that minimizes function `f`
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
88 with derivative `df`.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
89
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
90 This is supposed to provide an interface similar to scipy's minimize
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
91 routines, or MATLAB's.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
92
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
93 :type x0: numpy ndarray or list of numpy ndarrays.
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
94 :param x0: starting point for minimization
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
95
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
96 :type f: python callable mapping something like x0 to a scalar
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
97 :param f: function to minimize
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
98
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
99 :type df: python callable mapping something like x0 to the derivative of f at that point
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
100 :param df: derivative of `f`
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
101
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
102 :param opt_algo: one of the functions that implements the
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
103 `iterative_optimizer` interface.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
104
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
105 :param kwargs: passed through to `opt_algo`
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
106
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
107 """
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
108
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
109
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
110 There is also a numpy-based wrapper to the iterative algorithms.
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
111 This can be more useful than minimize() because it doesn't hog program
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
112 control. Technically minimize() is probably implemented using this
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
113 minimize_iterator interface.
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
114
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
115 class minimize_iterator(object):
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
116 """
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
117 Attributes
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
118 - x - the current best estimate of the minimum
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
119 - f - the function being minimized
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
120 - df - f's derivative function
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
121 - opt_algo - the optimization algorithm at work (a serializable, callable
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
122 object with the signature of iterative_optimizer above).
1100
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
123
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
124 """
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
125 def __init__(self, x0, f, df, opt_algo, **kwargs):
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
126 """Initialize state (arguments as in minimize())
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
127 """
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
128 def __iter__(self):
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
129 return self
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
130 def next(self):
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
131 """Take a step of minimization and return self raises StopIteration when
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
132 the algorithm is finished with minimization
1064
a41cc29cee26 v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
133
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
134 """
1100
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
135
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
136
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
137 Examples
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
138 --------
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
139
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
140 Simple stochastic gradient descent could be called like this:
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
141
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
142 sgd([p], gradients=[g], step_size=.1)
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
143
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
144 and this would return
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
145
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
146 {p:p-.1*g}
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
147
1100
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
148
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
149 Simple stochastic gradient descent with extra updates:
153cf820a975 v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1069
diff changeset
150
1149
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
151 sgd([p], gradients=[g], updates={a:b}, step_size=.1)
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
152
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
153 will return
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
154
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
155 {a:b, p:p-.1*g}
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
156
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
157
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
158 If the parameters collide with keys in a given updates dictionary an exception
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
159 will be raised:
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
160
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
161 sgd([p], gradients=[g], updates={p:b}, step_size=.1)
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
162
7c5dc11c850a cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents: 1108
diff changeset
163 will raise a KeyError.