Mercurial > pylearn
annotate doc/v2_planning/API_optimization.txt @ 1186:f111f8c2a280
Update after sept. 17th meeting
author | Pascal Lamblin <lamblinp@iro.umontreal.ca> |
---|---|
date | Fri, 17 Sep 2010 17:07:52 -0400 |
parents | 4ea46ef9822a |
children | 073c2fab7bcd |
rev | line source |
---|---|
1185
4ea46ef9822a
small fix to make the API_optimization show on the web.
Frederic Bastien <nouiz@nouiz.org>
parents:
1182
diff
changeset
|
1 .. _v2planning_optimization: |
4ea46ef9822a
small fix to make the API_optimization show on the web.
Frederic Bastien <nouiz@nouiz.org>
parents:
1182
diff
changeset
|
2 |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
3 Optimization API |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
4 ================ |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
5 |
1069
16ea3e5c5a7a
api_optimization: Couple questions
Olivier Delalleau <delallea@iro>
parents:
1065
diff
changeset
|
6 Members: Bergstra, Lamblin, Delalleau, Glorot, Breuleux, Bordes |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
7 Leader: Bergstra |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
8 |
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 Description |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
11 ----------- |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
12 |
1065 | 13 This API is for iterative optimization algorithms, such as: |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
14 |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
15 - stochastic gradient descent (incl. momentum, annealing) |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
16 - delta bar delta |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
17 - conjugate methods |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
18 - L-BFGS |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
19 - "Hessian Free" |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
20 - SGD-QN |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
21 - TONGA |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
22 |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
23 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
|
24 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
|
25 only uses Theano for the implementation. |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
26 |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
27 |
1100
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
28 Theano Interface |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
29 ----------------- |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
30 |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 'iterative_optimizer'. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
35 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
36 def iterative_optimizer(parameters, |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
37 cost=None, |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
38 gradients=None, |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
39 stop=None, |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
40 updates=None, |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
41 **kwargs): |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
42 """ |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
43 :param parameters: list or tuple of Theano variables |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
44 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
|
45 together, these variables represent 'x'. Typically these are shared |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
46 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
|
47 algorithm. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
48 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
49 :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
|
50 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
|
51 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
|
52 gradients are given. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
53 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
54 :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
|
55 the corresponding parameters. These default to tensor.grad(cost, |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
56 parameters). |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
57 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
58 :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
|
59 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
|
60 (1) or requires more iterations (0). |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
61 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
62 :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
|
63 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
|
64 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
|
65 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
66 :param kwargs: algorithm-dependent arguments |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
67 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
68 :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
|
69 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
|
70 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
71 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
|
72 passed as the ``updates`` argument to theano.function. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
73 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
74 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
|
75 internal variables that are part of the optimization algorithm. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
76 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
77 """ |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
78 |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
79 |
1100
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
80 Numpy Interface |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
81 --------------- |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
82 |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
83 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
|
84 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
|
85 arrays. |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
86 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
87 def minimize(x0, f, df, opt_algo, **kwargs): |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
88 """ |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
89 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
|
90 with derivative `df`. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
91 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
92 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
|
93 routines, or MATLAB's. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
94 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
95 :type x0: numpy ndarray or list of numpy ndarrays. |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
96 :param x0: starting point for minimization |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
97 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
98 :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
|
99 :param f: function to minimize |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
100 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
101 :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
|
102 :param df: derivative of `f` |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
103 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
104 :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
|
105 `iterative_optimizer` interface. |
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 :param kwargs: passed through to `opt_algo` |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
108 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
109 """ |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
110 |
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
111 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
112 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
|
113 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
|
114 control. Technically minimize() is probably implemented using this |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
115 minimize_iterator interface. |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
116 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
117 class minimize_iterator(object): |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
118 """ |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
119 Attributes |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
120 - x - the current best estimate of the minimum |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
121 - f - the function being minimized |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
122 - df - f's derivative function |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
123 - 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
|
124 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
|
125 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
126 """ |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
127 def __init__(self, x0, f, df, opt_algo, **kwargs): |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
128 """Initialize state (arguments as in minimize()) |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
129 """ |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
130 def __iter__(self): |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
131 return self |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
132 def next(self): |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
133 """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
|
134 the algorithm is finished with minimization |
1064
a41cc29cee26
v2planning optimization - API draft
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
135 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
136 """ |
1100
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
137 |
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 Examples |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
140 -------- |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
141 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
142 Simple stochastic gradient descent could be called like this: |
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 sgd([p], gradients=[g], step_size=.1) |
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 and this would return |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
147 |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
148 {p:p-.1*g} |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
149 |
1100
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
150 |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
151 Simple stochastic gradient descent with extra updates: |
153cf820a975
v2planning - updates to api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1069
diff
changeset
|
152 |
1149
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
153 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
|
154 |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
155 will return |
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 {a:b, p:p-.1*g} |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
158 |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
159 |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
160 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
|
161 will be raised: |
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 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
|
164 |
7c5dc11c850a
cleaning up api_optimization
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
1108
diff
changeset
|
165 will raise a KeyError. |