Skip to content

Commit

Permalink
adds doublewell objective
Browse files Browse the repository at this point in the history
  • Loading branch information
Niru Maheswaranathan committed Jun 30, 2017
1 parent 7271989 commit c09f1b4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion descent/objectives.py
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from functools import wraps

__all__ = ['rosenbrock', 'sphere', 'matyas', 'beale', 'booth', 'mccormick',
__all__ = ['doublewell', 'rosenbrock', 'sphere', 'matyas', 'beale', 'booth', 'mccormick',
'camel', 'michalewicz', 'bohachevsky1', 'zakharov', 'dixon_price']


Expand Down Expand Up @@ -40,6 +40,17 @@ def param_init():
return decorator


@objective(xstar=(0,), param_scales=(10,))
def doublewell(theta):
"""Pointwise minimum of two quadratic bowls"""
k0, k1, depth = 0.01, 100, 0.5
shallow = 0.5 * k0 * theta ** 2 + depth
deep = 0.5 * k1 * theta ** 2
obj = np.minimum(shallow, deep)
grad = np.where(deep < shallow, k0 * theta, k1 * theta)
return obj, grad


@objective(xstar=(1, 1))
def rosenbrock(theta):
"""Objective and gradient for the rosenbrock function"""
Expand Down

0 comments on commit c09f1b4

Please sign in to comment.