numericalalgorithmsgroup / dfols

Python-based Derivative-Free Optimizer for Least-Squares
https://numericalalgorithmsgroup.github.io/dfols/
GNU General Public License v3.0
41 stars 15 forks source link

x0 close to bounds #6

Closed lindonroberts closed 4 years ago

lindonroberts commented 5 years ago

Can avoid perturbing x0 if it is too close to the bounds? In random initial directions, treat indices 'close to bound' (compared to rhobeg) as at the boundary - a similar logic is already used in initial coordinate directions.

Alternatively, show more information to make perturbation clear: ` indices=np.arange(0,len(x0)) idx = (xl < x0) & (x0 <= xl + rhobeg) printValues=False # if find values need adjusting this will be True if np.any(idx): printValues=True warnings.warn(f"x0 too close to lower bound, adjusting {indices[idx]}", RuntimeWarning) x0[idx] = xl[idx] + rhobeg

idx = (x0 <= xl)
if np.any(idx):
    printValues=True
    warnings.warn(f"x0 below lower bound, adjusting {indices[idx]}", RuntimeWarning)
x0[idx] = xl[idx]

idx = (xu - rhobeg <= x0) & (x0 < xu)
if np.any(idx):
    printValues=True
    warnings.warn(f"x0 too close to upper bound, adjusting {indices[idx]}", RuntimeWarning)
x0[idx] = xu[idx] - rhobeg

idx = (x0 >= xu)
if np.any(idx):
    printValues=True
    warnings.warn(f"x0 above upper bound, adjusting {indices[idx]}", RuntimeWarning)`

And at the end, raise another RuntimeWarning with the adjusted x0: warnings.warn(f"Adjusted: x0: {x0}",RuntimeWarning)