-
Notifications
You must be signed in to change notification settings - Fork 119
ENH: Add rosenbrock functional, see #600 #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| class RosenbrockFunctional(Functional): | ||
|
|
||
| """The famous Rosenbrock funciton on ``R^n``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
funciton
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the word "famous", "well-known" is more adequate.
| >>> import odl | ||
| >>> r2 = odl.rn(2) | ||
| >>> functional = RosenbrockFunctional(r2) | ||
| >>> functional([1, 1]) # optimum is 0 at [0, 0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The optimum is at [1, 1].
|
|
||
| class RosenbrockFunctional(Functional): | ||
|
|
||
| """The famous Rosenbrock funciton on ``R^n``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Rosenbrock function seems to have two different versions. Should we clarify this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should, but the first one is not feasible for a general implementation since it only works for spaces of even dimension. I'll write this in the notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also typo "funciton"
kohr-h
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some details to fix
odl/solvers/functional/__init__.py
Outdated
| __all__ += default_functionals.__all__ | ||
|
|
||
| from . import example_functionals | ||
| __all__ += ('example_functionals',) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of the restructuring effort in #52: I find these names very long, especially since they repeat the word "functional" while lying in the functional subpackage. They could easily be abbreviated to ..._funcs.
| # You should have received a copy of the GNU General Public License | ||
| # along with ODL. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| """Example functions used in optimization.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functionals
|
|
||
| class RosenbrockFunctional(Functional): | ||
|
|
||
| """The famous Rosenbrock funciton on ``R^n``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the word "famous", "well-known" is more adequate.
| \sum_{i=1}^{n - 1} c (x_{i+1} - x_i^2)^2 + (1 - x_i)^2 | ||
|
|
||
| Where :math:`c` is a constant usually set to 100 which determines how ill- | ||
| posed the function should be. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is not ill-posed, rather the minimization problem. Alternatively, you could write "ill-behaved" in quotation marks.
| space : `FnBase` | ||
| Domain of the functional. | ||
| scale : positive float, optional | ||
| The scale ``c`` in the functional, determines how ill posed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment about "ill-posed".
This style "Main clause, main clause without subject" reads poorly in general. Here it's trivially possible to improve the flow of the sentence by writing "... in the functional determining how ill-...".
| if not isinstance(space, FnBase): | ||
| raise ValueError('`space` must be a `FnBase`') | ||
| if space.size < 2: | ||
| raise ValueError('`space` must be at least two dimensional') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two-dimensional
| raise ValueError('`space` must be a `FnBase`') | ||
| if space.size < 2: | ||
| raise ValueError('`space` must be at least two dimensional') | ||
| super().__init__(space=space, linear=False, grad_lipschitz=np.nan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No estimate for the Lipschitz constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's infinite on all of R^n since the function is Quartic.
Edit: Should probably say infinity then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I keep forgetting that we're on the whole space.
| def derivative(self, x): | ||
| """The derivative of the gradient. | ||
|
|
||
| This is also known as the hessian. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hessian
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formula in math at some place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even worse than the gradient, for these things I think it's better to just let users read the code (it is readily available) if they are interested. Easier to maintain as well.
Adding it would only be helpfull (imo) if we also added a deriviation of the result, which would take way too much space.
| result = 0 | ||
| for i in range(0, self.domain.size - 1): | ||
| result += self.scale * ((x[i + 1] - x[i] ** 2) ** 2 + | ||
| (x[i] - 1) ** 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be vectorized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most common case will be R2 and such, there it only makes this harder to read and slower, I doubt it's worth it. Any performance gains would be in improving the hessian to be more diagonal.
| Where :math:`c` is a constant usually set to 100 which determines how ill- | ||
| posed the function should be. | ||
| It has a minimum at :math:`x = [1, \\dots, 1]`, independent of :math:`c`. | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formula for the gradient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a mess and I doubt anyone would read it, users can open the code if they are truly interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
dad8c4e to
08d9d02
Compare
|
Updated according to comments and rebased. |
kohr-h
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good, one final request before merge.
|
|
||
| """The well-known Rosenbrock function on ``R^n``. | ||
|
|
||
| This function is usually used as a test problem in smooth optimization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a link to Wikipedia here.
08d9d02 to
304a75c
Compare
|
Merge after CI |
Minor yet probably useful addition. We could add more examples if we want.