Skip to content

Conversation

@adler-j
Copy link
Member

@adler-j adler-j commented Sep 22, 2016

Minor yet probably useful addition. We could add more examples if we want.


class RosenbrockFunctional(Functional):

"""The famous Rosenbrock funciton on ``R^n``.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funciton

Copy link
Member

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]
Copy link
Member

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``.
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also typo "funciton"

Copy link
Member

@kohr-h kohr-h left a 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

__all__ += default_functionals.__all__

from . import example_functionals
__all__ += ('example_functionals',)
Copy link
Member

@kohr-h kohr-h Sep 23, 2016

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."""
Copy link
Member

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``.
Copy link
Member

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.
Copy link
Member

@kohr-h kohr-h Sep 23, 2016

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
Copy link
Member

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')
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member Author

@adler-j adler-j Sep 23, 2016

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

Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hessian

Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be vectorized

Copy link
Member Author

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`.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formula for the gradient?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@adler-j adler-j force-pushed the issue-600__example_functionals branch from dad8c4e to 08d9d02 Compare September 23, 2016 10:32
@adler-j
Copy link
Member Author

adler-j commented Sep 23, 2016

Updated according to comments and rebased.

@adler-j adler-j added the merge? label Sep 23, 2016
Copy link
Member

@kohr-h kohr-h left a 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.
Copy link
Member

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.

@adler-j adler-j force-pushed the issue-600__example_functionals branch from 08d9d02 to 304a75c Compare September 23, 2016 13:39
@adler-j
Copy link
Member Author

adler-j commented Sep 23, 2016

Merge after CI

@adler-j adler-j merged commit 3eedd39 into master Sep 23, 2016
@adler-j adler-j deleted the issue-600__example_functionals branch September 23, 2016 14:09
@kohr-h kohr-h mentioned this pull request Oct 14, 2016
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants